OpenTyrian: refactoring, fixed launch from game center.

git-svn-id: svn://kolibrios.org@9770 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2022-04-15 22:29:16 +00:00
parent bfe9af6494
commit 56fdad78b4
14 changed files with 58 additions and 105 deletions

View File

@ -67,7 +67,6 @@ CFLAGS += -Wall \
-Wextra \
-Wno-missing-field-initializers
CFLAGS += -O2
CFLAGS += -DuSDL_Delay=SDL_Delay
LDFLAGS :=
LDLIBS :=

View File

@ -1,50 +0,0 @@
#include <SDL.h>
#include <stdlib.h>
#include <string.h>
#define asm_inline __asm__ __volatile__
#pragma pack(push,1)
typedef union{
unsigned val;
struct{
short h;
short w;
};
}ksys_screen_t;
#pragma pack(pop)
static inline
void _ksys_change_window(int new_x, int new_y, int new_w, int new_h)
{
asm_inline(
"int $0x40"
::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
);
}
static inline
ksys_screen_t _ksys_screen_size()
{
ksys_screen_t size;
asm_inline(
"int $0x40"
:"=a"(size)
:"a"(14)
:"memory"
);
return size;
}
void uSDL_SetWinCenter(unsigned w, unsigned h){
ksys_screen_t screen_size= _ksys_screen_size();
int new_x = screen_size.w/2-w/2;
int new_y = screen_size.h/2-h/2;
_ksys_change_window(new_x, new_y, -1, -1);
}
void uSDL_Delay(unsigned ms){
SDL_Delay(ms);
}

View File

@ -8,7 +8,7 @@ tup.include(HELPERDIR .. "/use_gcc.lua")
tup.include(HELPERDIR .. "/use_newlib.lua")
--use_dynamic_stack() -- default 64K are not sufficient
tup.include(HELPERDIR .. "/use_sdl_newlib.lua")
CFLAGS = CFLAGS .. [[ -UWIN32 -U_WIN32 -U__WIN32__ -D_KOLIBRI -DTYRIAN_DIR="\"."\" -DSDL_strlcpy=strncpy -D_GNU_SOURCE=1 -D_REENTRANT -DNDEBUG -Wno-missing-field-initializers ]]
CFLAGS = CFLAGS .. [[ -DTYRIAN_DIR="\"."\" -D_GNU_SOURCE=1 -D_REENTRANT -DNDEBUG -Wno-missing-field-initializers ]]
LDFLAGS = LDFLAGS .. " --subsystem native"
@ -69,7 +69,6 @@ compile_gcc{
"./SDL/joystick_stub.c",
"./SDL/SDL_wave.c",
"./SDL/SDL_audiocvt.c",
"./SDL/uSDL.c",
}
link_gcc("opentyrian")

View File

@ -631,7 +631,7 @@ static void JE_introScreen( void )
while (!newkey)
{
service_SDL_events(false);
uSDL_Delay(16);
SDL_Delay(16);
}
fade_black(15);
@ -684,7 +684,7 @@ static enum de_mode_t JE_modeSelect( void )
newkey = false;
do {
service_SDL_events(false);
uSDL_Delay(16);
SDL_Delay(16);
} while(!newkey);
/* See what was pressed */
@ -1297,7 +1297,7 @@ static void JE_helpScreen( void )
do /* wait until user hits a key */
{
service_SDL_events(true);
uSDL_Delay(16);
SDL_Delay(16);
}
while (!newkey);
@ -1320,7 +1320,7 @@ static void JE_pauseScreen( void )
do /* wait until user hits a key */
{
service_SDL_events(true);
uSDL_Delay(16);
SDL_Delay(16);
}
while (!newkey);

View File

@ -1592,7 +1592,7 @@ void JE_itemScreen( void )
network_update();
network_check();
uSDL_Delay(16);
SDL_Delay(16);
}
network_state_reset();
@ -1606,7 +1606,7 @@ void JE_itemScreen( void )
JE_showVGA();
network_check();
uSDL_Delay(16);
SDL_Delay(16);
}
}
#endif
@ -2507,7 +2507,7 @@ void JE_scaleInPicture( SDL_Surface *dst, const SDL_Surface *src )
JE_scaleBitmap(dst, src, 160 - i, 0, 160 + i - 1, 100 + roundf(i * 0.625f) - 1);
JE_showVGA();
uSDL_Delay(1);
SDL_Delay(1);
}
}

View File

@ -61,7 +61,7 @@ void wait_input( JE_boolean keyboard, JE_boolean mouse, JE_boolean joystick )
service_SDL_events(false);
while (!((keyboard && keydown) || (mouse && mousedown) || (joystick && joydown)))
{
uSDL_Delay(SDL_POLL_INTERVAL);
SDL_Delay(SDL_POLL_INTERVAL);
push_joysticks_as_keyboard();
service_SDL_events(false);
@ -77,7 +77,7 @@ void wait_noinput( JE_boolean keyboard, JE_boolean mouse, JE_boolean joystick )
service_SDL_events(false);
while ((keyboard && keydown) || (mouse && mousedown) || (joystick && joydown))
{
uSDL_Delay(SDL_POLL_INTERVAL);
SDL_Delay(SDL_POLL_INTERVAL);
poll_joysticks();
service_SDL_events(false);

View File

@ -159,7 +159,7 @@ void JE_outCharGlow( JE_word x, JE_word y, const char *s )
if (levelWarningDisplay)
JE_updateWarning(VGAScreen);
uSDL_Delay(16);
SDL_Delay(16);
}
while (!(delaycount() == 0 || ESCPressed));
@ -803,7 +803,7 @@ void JE_nextEpisode( void )
{
NETWORK_KEEP_ALIVE();
uSDL_Delay(16);
SDL_Delay(16);
} while (!JE_anyButton());
}
@ -1066,7 +1066,7 @@ void JE_doInGameSetup( void )
network_update();
network_check();
uSDL_Delay(16);
SDL_Delay(16);
}
}
#endif
@ -1133,7 +1133,7 @@ void JE_doInGameSetup( void )
network_update();
network_check();
uSDL_Delay(16);
SDL_Delay(16);
}
} else {
/*
@ -1150,7 +1150,7 @@ void JE_doInGameSetup( void )
service_SDL_events(false);
network_check();
uSDL_Delay(16);
SDL_Delay(16);
}
VGAScreen = temp_surface; /* side-effect of game_screen */
@ -2853,7 +2853,7 @@ void JE_pauseGame( void )
network_update();
network_check();
uSDL_Delay(16);
SDL_Delay(16);
}
}
#endif
@ -2905,7 +2905,7 @@ void JE_pauseGame( void )
service_SDL_events(false);
network_check();
uSDL_Delay(16);
SDL_Delay(16);
}
}
#endif

View File

@ -514,7 +514,7 @@ bool network_state_update( void )
}
if (network_check() == 0)
uSDL_Delay(1);
SDL_Delay(1);
}
if (network_delay > 1)
@ -625,7 +625,7 @@ connect_reset:
network_update();
network_check();
uSDL_Delay(16);
SDL_Delay(16);
}
connect_again:
@ -671,7 +671,7 @@ connect_again:
if (SDL_GetTicks() - last_out_tick > NET_RETRY)
goto connect_reset;
uSDL_Delay(16);
SDL_Delay(16);
}
// send another packet since sometimes the network syncs without both connect packets exchanged
@ -724,14 +724,14 @@ void network_tyrian_halt( unsigned int err, bool attempt_sync )
service_SDL_events(false);
network_check();
uSDL_Delay(16);
SDL_Delay(16);
}
}
if (err)
{
while (!JE_anyButton())
uSDL_Delay(16);
SDL_Delay(16);
}
fade_black(10);

View File

@ -76,14 +76,14 @@ void wait_delay( void )
{
Sint32 delay = target - SDL_GetTicks();
if (delay > 0)
uSDL_Delay(delay);
SDL_Delay(delay);
}
void service_wait_delay( void )
{
while (SDL_GetTicks() < target)
{
uSDL_Delay(SDL_GetTicks() - target > SDL_POLL_INTERVAL ? SDL_POLL_INTERVAL : SDL_GetTicks() - target);
SDL_Delay(SDL_GetTicks() - target > SDL_POLL_INTERVAL ? SDL_POLL_INTERVAL : SDL_GetTicks() - target);
service_SDL_events(false);
}
}
@ -93,7 +93,7 @@ void wait_delayorinput( JE_boolean keyboard, JE_boolean mouse, JE_boolean joysti
service_SDL_events(true);
while (SDL_GetTicks() < target && !((keyboard && keydown) || (mouse && mousedown) || (joystick && joydown)))
{
uSDL_Delay(SDL_GetTicks() - target > SDL_POLL_INTERVAL ? SDL_POLL_INTERVAL : SDL_GetTicks() - target);
SDL_Delay(SDL_GetTicks() - target > SDL_POLL_INTERVAL ? SDL_POLL_INTERVAL : SDL_GetTicks() - target);
push_joysticks_as_keyboard();
service_SDL_events(false);
}

View File

@ -55,6 +55,12 @@
#include <string.h>
#include <time.h>
#ifdef _KOLIBRI
#include <sys/ksys.h>
#include <libgen.h>
#endif
const char *opentyrian_str = "OpenTyrian";
const char *opentyrian_version = OPENTYRIAN_VERSION;
@ -280,6 +286,10 @@ int main( int argc, char *argv[] )
printf("This is free software, and you are welcome to redistribute it\n");
printf("under certain conditions. See the file GPL.txt for details.\n\n");
#ifdef _KOLIBRI
_ksys_setcwd(dirname(argv[0]));
#endif
if (SDL_Init(0))
{
printf("Failed to initialize SDL: %s\n", SDL_GetError());

View File

@ -60,10 +60,10 @@ extern const char *opentyrian_str;
extern const char *opentyrian_version;
void opentyrian_menu( void );
#ifdef _KOLIBRI
extern void uSDL_SetWinCenter(uint w, uint h);
extern void uSDL_Delay(uint ms);
#endif
//#ifdef _KOLIBRI
//extern void uSDL_SetWinCenter(uint w, uint h);
//extern void SDL_Delay(uint ms);
//#endif
#endif /* OPENTYR_H */

View File

@ -84,7 +84,7 @@ void JE_textMenuWait( JE_word *waitTime, JE_boolean doGamma )
NETWORK_KEEP_ALIVE();
uSDL_Delay(16);
SDL_Delay(16);
if (*waitTime > 0)
{

View File

@ -3260,7 +3260,7 @@ bool JE_titleScreen( JE_boolean animate )
network_update();
network_check();
uSDL_Delay(16);
SDL_Delay(16);
}
JE_initEpisode(SDLNet_Read16(&packet_in[0]->data[4]));
@ -3282,7 +3282,7 @@ bool JE_titleScreen( JE_boolean animate )
JE_showVGA();
network_check();
uSDL_Delay(16);
SDL_Delay(16);
}
}
else

View File

@ -115,11 +115,6 @@ bool init_scaler( unsigned int new_scaler, bool fullscreen )
w = surface->w;
h = surface->h;
#ifdef _KOLIBRI
uSDL_SetWinCenter(w,h);
#endif
//bpp = surface->format->BitsPerPixel;
printf("initialized video: %dx%dx%d %s\n", w, h, bpp, fullscreen ? "fullscreen" : "windowed");
scaler = new_scaler;