From 3514722a74b32715b5a1c8e2d8d5e8d338c3129c Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 9 May 2010 08:51:25 +0000 Subject: [PATCH] fix input when using vsync git-svn-id: https://svn.eduke32.com/eduke32@1634 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/Makefile | 2 +- polymer/eduke32/build/Makefile | 2 +- polymer/eduke32/build/src/osd.c | 41 ++++++++++++------------- polymer/eduke32/build/src/polymost.c | 9 +++--- polymer/eduke32/build/src/rawinput.c | 2 +- polymer/eduke32/build/src/winlayer.c | 12 ++++---- polymer/eduke32/source/game.c | 36 +++++++++------------- polymer/eduke32/source/gamestructures.c | 4 +-- 8 files changed, 49 insertions(+), 59 deletions(-) diff --git a/polymer/eduke32/Makefile b/polymer/eduke32/Makefile index 07a67d65b..c0bac1371 100644 --- a/polymer/eduke32/Makefile +++ b/polymer/eduke32/Makefile @@ -81,7 +81,7 @@ ifeq (4,$(GCC_MAJOR)) endif endif ifeq (5,$(GCC_MINOR)) - debug += -flto +# debug += -flto endif endif endif diff --git a/polymer/eduke32/build/Makefile b/polymer/eduke32/build/Makefile index 285605356..fa570f47c 100644 --- a/polymer/eduke32/build/Makefile +++ b/polymer/eduke32/build/Makefile @@ -103,7 +103,7 @@ ifeq (4,$(GCC_MAJOR)) endif endif ifeq (5,$(GCC_MINOR)) - debug += -flto +# debug += -flto endif endif endif diff --git a/polymer/eduke32/build/src/osd.c b/polymer/eduke32/build/src/osd.c index e3d7d29d0..78b79d4f3 100644 --- a/polymer/eduke32/build/src/osd.c +++ b/polymer/eduke32/build/src/osd.c @@ -1469,9 +1469,7 @@ void OSD_DispatchQueued(void) osdexeccount=0; for (; cmd>=0; cmd--) - { OSD_Dispatch((const char *)osdhistorybuf[cmd]); - } } @@ -1576,36 +1574,30 @@ static char *strtoken(char *s, char **ptrptr, int32_t *restart) int32_t OSD_Dispatch(const char *cmd) { char *workbuf, *wp, *wtp, *state; - char *parms[MAXPARMS]; - int32_t numparms, restart = 0; - osdfuncparm_t ofp; - symbol_t *symb; - //int32_t i; + int32_t restart = 0; workbuf = state = Bstrdup(cmd); if (!workbuf) return -1; do { - numparms = 0; + int32_t numparms = 0; + symbol_t *symb; + osdfuncparm_t ofp; + char *parms[MAXPARMS]; + Bmemset(parms, 0, sizeof(parms)); - wp = strtoken(state, &wtp, &restart); - if (!wp) + + if ((wp = strtoken(state, &wtp, &restart)) == NULL) { state = wtp; continue; } - if (wp[0] == '/' && wp[1] == '/') // cheap hack + if ((symb = findexactsymbol(wp)) == NULL) { - Bfree(workbuf); - return -1; - } - - symb = findexactsymbol(wp); - if (!symb) - { - OSD_Printf(OSDTEXT_RED "Error: \"%s\" is not a valid command or cvar\n", wp); + if (wp[0] != '/' || wp[1] != '/') // cheap hack for comments in cfgs + OSD_Printf(OSDTEXT_RED "\"%s\" is not a valid command or cvar\n", wp); Bfree(workbuf); return -1; } @@ -1619,10 +1611,14 @@ int32_t OSD_Dispatch(const char *cmd) ofp.numparms = numparms; ofp.parms = (const char **)parms; ofp.raw = cmd; - if (symb->func == OSD_ALIAS) - OSD_Dispatch(symb->help); - else if (symb->func != OSD_UNALIASED) + + switch((intptr_t)symb->func) { + case (intptr_t)OSD_ALIAS: + OSD_Dispatch(symb->help); + case (intptr_t)OSD_UNALIASED: + break; + default: switch (symb->func(&ofp)) { case OSDCMD_OK: @@ -1631,6 +1627,7 @@ int32_t OSD_Dispatch(const char *cmd) OSD_Printf("%s\n", symb->help); break; } + break; } state = wtp; diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index 242603e68..10697e2de 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -183,7 +183,7 @@ int32_t r_fullbrights = 1; // texture downsizing // is medium quality a good default? int32_t r_downsize = 1; -int32_t r_downsizevar = 1; +int32_t r_downsizevar = -1; // used for fogcalc float fogresult, fogcol[4], fogtable[4*MAXPALOOKUPS]; @@ -5916,14 +5916,15 @@ static int32_t osdcmd_cvar_set_polymost(const osdfuncparm_t *parm) } else if (!Bstrcasecmp(parm->name, "r_downsize")) { - if (r_downsize != r_downsizevar) + if (r_downsize != r_downsizevar && r_downsizevar != -1) { invalidatecache(); resetvideomode(); if (setgamemode(fullscreen,xdim,ydim,bpp)) OSD_Printf("restartvid: Reset failed...\n"); } - r_downsize = r_downsizevar; + else r_downsizevar = r_downsize; + return r; } else if (!Bstrcasecmp(parm->name, "r_textureanisotropy")) @@ -5962,7 +5963,7 @@ void polymost_initosdfuncs(void) { "r_animsmoothing","r_animsmoothing: enable/disable model animation smoothing",(void *)&r_animsmoothing, CVAR_BOOL, 0, 1 }, { "r_modelocclusionchecking","r_modelocclusionchecking: enable/disable hack to cull \"obstructed\" models",(void *)&r_modelocclusionchecking, CVAR_INT, 0, 2 }, { "r_detailmapping","r_detailmapping: enable/disable detail mapping",(void *)&r_detailmapping, CVAR_BOOL, 0, 1 }, - { "r_downsize","r_downsize: controls downsizing factor for hires textures",(void *)&r_downsizevar, CVAR_INT|CVAR_FUNCPTR, 0, 5 }, + { "r_downsize","r_downsize: controls downsizing factor for hires textures",(void *)&r_downsize, CVAR_INT|CVAR_FUNCPTR, 0, 5 }, { "r_fullbrights","r_fullbrights: enable/disable fullbright textures",(void *)&r_fullbrights, CVAR_BOOL, 0, 1 }, { "r_glowmapping","r_glowmapping: enable/disable glow mapping",(void *)&r_glowmapping, CVAR_BOOL, 0, 1 }, /* diff --git a/polymer/eduke32/build/src/rawinput.c b/polymer/eduke32/build/src/rawinput.c index 3e312ed7a..5527fb724 100644 --- a/polymer/eduke32/build/src/rawinput.c +++ b/polymer/eduke32/build/src/rawinput.c @@ -80,7 +80,7 @@ static inline void RI_ProcessMouse(const RAWMOUSE* rmouse) static inline void RI_ProcessKeyboard(const RAWKEYBOARD* rkbd) { uint8_t key = rkbd->MakeCode, VKey = rkbd->VKey; - uint8_t buf[2], i; + uint8_t buf[2]; // for some reason rkbd->MakeCode is wrong for these // even though rkbd->VKey is right... diff --git a/polymer/eduke32/build/src/winlayer.c b/polymer/eduke32/build/src/winlayer.c index 402965c67..06bd0c426 100644 --- a/polymer/eduke32/build/src/winlayer.c +++ b/polymer/eduke32/build/src/winlayer.c @@ -1606,12 +1606,12 @@ inline void sampletimer(void) if (!timerfreq) return; QueryPerformanceCounter((LARGE_INTEGER*)&i); - n = (int32_t)(i*timerticspersec / timerfreq) - timerlastsample; - if (n>0) - { - totalclock += n; - timerlastsample += n; - } + n = (int32_t)((i*timerticspersec / timerfreq) - timerlastsample); + + if (n <= 0) return; + + totalclock += n; + timerlastsample += n; if (usertimercallback) for (; n>0; n--) usertimercallback(); } diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 708864884..015fb683a 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -2241,23 +2241,6 @@ void Net_UpdateClients(void) void faketimerhandler(void) { - int32_t i; - - if (g_quickExit == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && KB_KeyPressed(sc_Delete)) - { - g_quickExit = 1; - G_GameExit("Quick Exit."); - } - - sampletimer(); - MUSIC_Update(); - - if ((totalclock < ototalclock+TICSPERFRAME) || (ready2send == 0)) return; - ototalclock += TICSPERFRAME; - - Net_GetPackets(); - - g_player[myconnectindex].movefifoend++; } extern int32_t cacnum; @@ -11808,7 +11791,7 @@ MAIN_LOOP_RESTART: do //main loop { - static uint32_t nextrender = 0, next = 0; + static uint32_t nextrender = 0, framewaiting = 0; uint32_t j; if (handleevents() && quitevent) @@ -11818,6 +11801,8 @@ MAIN_LOOP_RESTART: } sampletimer(); + MUSIC_Update(); + Net_GetPackets(); // only allow binds to function if the player is actually in a game (not in a menu, typing, et cetera) or demo bindsenabled = g_player[myconnectindex].ps->gm & (MODE_GAME|MODE_DEMO); @@ -11852,7 +11837,14 @@ MAIN_LOOP_RESTART: } */ - do faketimerhandler(); + do + { + sampletimer(); + + if ((totalclock < ototalclock+TICSPERFRAME) || (ready2send == 0)) return; + ototalclock += TICSPERFRAME; + g_player[myconnectindex].movefifoend++; + } while (!(g_player[myconnectindex].ps->gm & (MODE_MENU|MODE_DEMO)) && totalclock >= ototalclock+TICSPERFRAME); } @@ -11883,9 +11875,9 @@ MAIN_LOOP_RESTART: g_multiMapState = NULL; } - if (next) + if (framewaiting) { - next--; + framewaiting--; if (ud.statusbarmode == 1 && (ud.statusbarscale == 100 || !getrendermode())) { ud.statusbarmode = 0; @@ -11915,7 +11907,7 @@ MAIN_LOOP_RESTART: G_DrawBackground(); S_Update(); - next++; + framewaiting++; } if (g_player[myconnectindex].ps->gm&MODE_DEMO) diff --git a/polymer/eduke32/source/gamestructures.c b/polymer/eduke32/source/gamestructures.c index 54a28dcdb..f0893d2c2 100644 --- a/polymer/eduke32/source/gamestructures.c +++ b/polymer/eduke32/source/gamestructures.c @@ -1453,7 +1453,7 @@ static void __fastcall VM_GetPlayer(register int32_t lVar1, register int32_t lLa case PLAYER_FALLING_COUNTER: Gv_SetVar(lVar2, g_player[iPlayer].ps->falling_counter, vm.g_i, vm.g_p); return; case PLAYER_GOTWEAPON: - Gv_SetVar(lVar2, g_player[iPlayer].ps->gotweapon & (1<gotweapon & (1<refresh_inventory, vm.g_i, vm.g_p); return; case PLAYER_TOGGLE_KEY_FLAG: @@ -3710,7 +3710,7 @@ static int32_t __fastcall VM_AccessPlayerX(int32_t iPlayer, int32_t lLabelID, in case PLAYER_FALLING_COUNTER: return g_player[iPlayer].ps->falling_counter; case PLAYER_GOTWEAPON: - return g_player[iPlayer].ps->gotweapon & (1<gotweapon & (1<refresh_inventory; case PLAYER_TOGGLE_KEY_FLAG: