From cf55e54faaa28a558cb9d4245b0ff47adcf3c8a1 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sat, 13 May 2017 03:46:00 +0200 Subject: [PATCH] fix damage indicator overflow after fastforward break up shiftgametime() time jumps into 5-second jumps and five 1-second jumps for the last five seconds rename respawnoffset to lastdeath (because that's what it is) rename clientside nextmillis to skipmillis (because that's what it does) --- source/src/bot/bot.cpp | 4 ++-- source/src/client.cpp | 4 ++-- source/src/clientgame.cpp | 10 +++++----- source/src/cube.h | 2 +- source/src/entity.h | 7 +++---- source/src/main.cpp | 8 +++++--- source/src/physics.cpp | 2 +- source/src/renderhud.cpp | 2 +- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/source/src/bot/bot.cpp b/source/src/bot/bot.cpp index 626d5e46..1fa0c83d 100644 --- a/source/src/bot/bot.cpp +++ b/source/src/bot/bot.cpp @@ -94,12 +94,12 @@ void CBot::Think() // Bot is dead? if (m_pMyEnt->state == CS_DEAD) { - if(lastmillis-m_pMyEnt->respawnoffset<1200) + if(lastmillis-m_pMyEnt->lastdeath<1200) { m_pMyEnt->move = 0; moveplayer(m_pMyEnt, 1, true); } - else if (!m_arena && lastmillis-m_pMyEnt->respawnoffset>5000) Spawn(); + else if (!m_arena && lastmillis-m_pMyEnt->lastdeath>5000) Spawn(); SendBotInfo(); return; } diff --git a/source/src/client.cpp b/source/src/client.cpp index 8acb7bc8..b754127a 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -853,11 +853,11 @@ void shiftgametime(int newmillis) if(!curdemofile || !curdemofile[0]) return; watchingdemo = false; callvote(SA_MAP, curdemofile, "-1", "0"); - nextmillis = newmillis; + skipmillis = newmillis; } else { - nextmillis = newmillis - gamemillis; + skipmillis = newmillis - gamemillis; } } diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 7e2ffa27..5e597023 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -27,7 +27,7 @@ struct serverstate servstate = { 0 }; playerent *player1 = newplayerent(); // our client vector players; // other clients -int lastmillis = 0, totalmillis = 0, nextmillis = 0; +int lastmillis = 0, totalmillis = 0, skipmillis = 0; int lasthit = 0; int curtime = 0; string clientmap = ""; @@ -371,7 +371,7 @@ void deathstate(playerent *pl) { pl->state = CS_DEAD; pl->spectatemode = SM_DEATHCAM; - pl->respawnoffset = pl->lastpain = lastmillis; + pl->lastdeath = pl->lastpain = lastmillis; pl->move = pl->strafe = 0; pl->pitch = pl->roll = pl->movroll = pl->effroll = 0; pl->attacking = false; @@ -562,7 +562,7 @@ void showrespawntimer() else if(player1->state==CS_DEAD && m_flags && (!player1->isspectating() || player1->spectatemode==SM_DEATHCAM)) { int secs = 5; - showhudtimer(secs, player1->respawnoffset, "READY!", lastspawnattempt >= arenaintermission && lastmillis < lastspawnattempt+100); + showhudtimer(secs, player1->lastdeath, "READY!", lastspawnattempt >= arenaintermission && lastmillis < lastspawnattempt+100); } } @@ -784,7 +784,7 @@ bool tryrespawn() } else { - int respawnmillis = player1->respawnoffset+(m_arena ? 0 : (m_flags ? 5000 : 2000)); + int respawnmillis = player1->lastdeath + (m_arena ? 0 : (m_flags ? 5000 : 2000)); if(lastmillis>respawnmillis) { player1->attacking = false; @@ -850,7 +850,7 @@ COMMANDF(burstshots, "si", (char *gun, int *shots) void dodamage(int damage, playerent *pl, playerent *actor, int gun, bool gib, bool local) { if(pl->state != CS_ALIVE || intermission) return; - pl->respawnoffset = pl->lastpain = lastmillis; + pl->lastpain = lastmillis; // could the author of the FIXME below please elaborate what's to fix?! (ft:2011mar28) // I suppose someone wanted to play the hitsound for player1 or spectated player (lucas:2011may22) playerent *h = player1->isspectating() && player1->followplayercn >= 0 && (player1->spectatemode == SM_FOLLOW1ST || player1->spectatemode == SM_FOLLOW3RD || player1->spectatemode == SM_FOLLOW3RD_TRANSPARENT) ? getclient(player1->followplayercn) : NULL; diff --git a/source/src/cube.h b/source/src/cube.h index 8e2d8e56..71c87a92 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -40,7 +40,7 @@ extern int unsavededits; extern vector ents; // map entities extern vector eh_ents; // edithide entities extern vec worldpos, camup, camright, camdir; // current target of the crosshair in the world -extern int lastmillis, totalmillis, nextmillis; // last time +extern int lastmillis, totalmillis, skipmillis; // last time extern int curtime; // current frame time extern int interm; extern int gamemode, nextmode; diff --git a/source/src/entity.h b/source/src/entity.h index 855ee009..19dce4d1 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -422,7 +422,7 @@ public: enet_uint32 address; int lifesequence; // sequence id for each respawn, used in damage test int frags, flagscore, deaths, points, tks; - int lastaction, lastmove, lastpain, lastvoicecom; + int lastaction, lastmove, lastpain, lastvoicecom, lastdeath; int clientrole; bool attacking; string name; @@ -431,7 +431,6 @@ public: int nextweapon; // weapon we switch to int spectatemode, followplayercn; int eardamagemillis; - int respawnoffset; float maxroll, maxrolleffect, movroll, effroll; // roll added by movement and damage bool allowmove() { return state!=CS_DEAD || spectatemode==SM_FLY; } @@ -449,8 +448,8 @@ public: bool ignored, muted; - playerent() : curskin(0), clientnum(-1), lastupdate(0), plag(0), ping(0), address(0), lifesequence(0), frags(0), flagscore(0), deaths(0), points(0), tks(0), lastpain(0), lastvoicecom(0), clientrole(CR_DEFAULT), - team(TEAM_SPECT), spectatemode(SM_NONE), eardamagemillis(0), respawnoffset(0), maxroll(ROLLMOVDEF), maxrolleffect(ROLLEFFDEF), movroll(0), effroll(0), + playerent() : curskin(0), clientnum(-1), lastupdate(0), plag(0), ping(0), address(0), lifesequence(0), frags(0), flagscore(0), deaths(0), points(0), tks(0), lastpain(0), lastvoicecom(0), lastdeath(0), clientrole(CR_DEFAULT), + team(TEAM_SPECT), spectatemode(SM_NONE), eardamagemillis(0), maxroll(ROLLMOVDEF), maxrolleffect(ROLLEFFDEF), movroll(0), effroll(0), prevweaponsel(NULL), weaponsel(NULL), nextweaponsel(NULL), primweap(NULL), nextprimweap(NULL), lastattackweapon(NULL), smoothmillis(-1), head(-1, -1, -1), ignored(false), muted(false) diff --git a/source/src/main.cpp b/source/src/main.cpp index 4d81cf48..12d57dc2 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -1284,10 +1284,12 @@ int main(int argc, char **argv) int scaledtime = elapsed*gamespeed + timeerr; curtime = scaledtime/100; timeerr = scaledtime%100; - if(nextmillis && watchingdemo) + if(!watchingdemo) skipmillis = 0; + if(skipmillis && watchingdemo) { - curtime += nextmillis; - nextmillis = 0; + int skipmillisnow = skipmillis > 5000 ? skipmillis - 5000 : min(1000, skipmillis); + curtime += skipmillisnow; + skipmillis -= skipmillisnow; } if(paused) curtime = 0; } diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 825c1927..14ffa14d 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -868,7 +868,7 @@ void jumpn(bool on) wason = on; if(player1->isspectating()) { - if(lastmillis - player1->respawnoffset > 1000 && on) togglespect(); + if(lastmillis - player1->lastdeath > 1000 && on) togglespect(); } } diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index 4ca781b3..90115cab 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -703,7 +703,7 @@ void damageblend(int n, void *p) { if(!damagescreen) return; if(lastmillis > damageblendmillis || damageblendplayer != p) damageblendmillis = lastmillis; - damageblendmillis += n*damagescreenfactor; + damageblendmillis = min(damageblendmillis + n * damagescreenfactor, lastmillis + 3999); damageblendplayer = p; }