From a2339b7a668ec14aade5bf7771fa466eb6c59cf3 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Tue, 2 Jul 2019 17:30:31 -0400 Subject: [PATCH 01/67] Merge branch 'thinkerlists' into 'master' Separate thinkers into different lists See merge request STJr/SRB2Internal!219 Ashnal: tons of compile errors to fix --- src/d_clisrv.c | 11 +- src/d_netcmd.c | 5 +- src/dehacked.c | 6 +- src/g_game.c | 14 +- src/hardware/hw_light.c | 8 +- src/lua_maplib.c | 12 - src/lua_script.c | 20 +- src/lua_thinkerlib.c | 14 +- src/m_cheat.c | 5 +- src/p_ceilng.c | 4 +- src/p_enemy.c | 768 +---------------------------- src/p_floor.c | 17 +- src/p_inter.c | 18 +- src/p_lights.c | 10 +- src/p_local.h | 20 +- src/p_map.c | 2 +- src/p_mobj.c | 51 +- src/p_polyobj.c | 109 ++--- src/p_saveg.c | 1026 ++++++++++++++++++++------------------- src/p_setup.c | 14 +- src/p_slopes.c | 624 ++++++++++-------------- src/p_slopes.h | 46 +- src/p_spec.c | 99 ++-- src/p_tick.c | 58 ++- src/p_user.c | 107 +--- src/r_data.c | 5 +- src/r_defs.h | 39 +- src/st_stuff.c | 4 +- 28 files changed, 1036 insertions(+), 2080 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1dc2c1420..39b64c127 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4778,19 +4778,14 @@ static INT16 Consistancy(void) ret += P_GetRandSeed(); #ifdef MOBJCONSISTANCY - if (!thinkercap.next) + if (!thlist[THINK_MOBJ].next) { DEBFILE(va("Consistancy = %u\n", ret)); return ret; } - if (gamestate == GS_LEVEL) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - mo = (mobj_t *)th; + mo = (mobj_t *)th; if (mo->flags & (MF_SPECIAL | MF_SOLID | MF_PUSHABLE | MF_BOSS | MF_MISSILE | MF_SPRING | MF_MONITOR | MF_FIRE | MF_ENEMY | MF_PAIN | MF_STICKY)) { diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 0bb87556d..0d3967c3d 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5376,9 +5376,8 @@ static void Command_Archivetest_f(void) // assign mobjnum i = 1; - for (th = thinkercap.next; th != &thinkercap; th = th->next) - if (th->function.acp1 == (actionf_p1)P_MobjThinker) - ((mobj_t *)th)->mobjnum = i++; + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + ((mobj_t *)th)->mobjnum = i++; // allocate buffer buf = save_p = ZZ_Alloc(1024); diff --git a/src/dehacked.c b/src/dehacked.c index b311a860c..2a6407345 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8796,10 +8796,8 @@ struct { #ifdef ESLOPE // Slope flags - {"SL_NOPHYSICS",SL_NOPHYSICS}, // Don't do momentum adjustment with this slope - {"SL_NODYNAMIC",SL_NODYNAMIC}, // Slope will never need to move during the level, so don't fuss with recalculating it - {"SL_ANCHORVERTEX",SL_ANCHORVERTEX},// Slope is using a Slope Vertex Thing to anchor its position - {"SL_VERTEXSLOPE",SL_VERTEXSLOPE}, // Slope is built from three Slope Vertex Things + {"SL_NOPHYSICS",SL_NOPHYSICS}, + {"SL_DYNAMIC",SL_DYNAMIC}, #endif // Angles diff --git a/src/g_game.c b/src/g_game.c index 10bd76acc..6dc675d8f 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3096,11 +3096,8 @@ void G_ChangePlayerReferences(mobj_t *oldmo, mobj_t *newmo) I_Assert((oldmo != NULL) && (newmo != NULL)); // scan all thinkers - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (!(mo2->flags & MF_MISSILE)) @@ -5542,10 +5539,8 @@ void G_ConsGhostTic(INT32 playernum) demo_p += sizeof(angle_t); // angle, unnecessary for cons. mobj = NULL; - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; mobj = (mobj_t *)th; if (mobj->type == (mobjtype_t)type && mobj->x == x && mobj->y == y && mobj->z == z) break; @@ -7973,11 +7968,8 @@ void G_DoPlayMetal(void) metalbuffer = metal_p = W_CacheLumpNum(l, PU_STATIC); // find metal sonic - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo = (mobj_t *)th; if (mo->type == MT_METALSONIC_RACE) break; diff --git a/src/hardware/hw_light.c b/src/hardware/hw_light.c index ee0cca745..f342e9f07 100644 --- a/src/hardware/hw_light.c +++ b/src/hardware/hw_light.c @@ -1317,12 +1317,8 @@ static void HWR_SearchLightsInMobjs(void) //mobj_t * mobj; // search in the list of thinkers - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - // a mobj ? - if (th->function.acp1 == (actionf_p1)P_MobjThinker) - HWR_AddMobjLights((mobj_t *)th); - } + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + HWR_AddMobjLights((mobj_t *)th); } #endif diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 19292b3d6..947c8892a 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -217,8 +217,6 @@ enum slope_e { slope_normal, slope_zangle, slope_xydirection, - slope_sourceline, - slope_refpos, slope_flags }; @@ -230,8 +228,6 @@ static const char *const slope_opt[] = { "normal", "zangle", "xydirection", - "sourceline", - "refpos", "flags", NULL}; @@ -1285,12 +1281,6 @@ static int slope_get(lua_State *L) case slope_xydirection: // xydirection lua_pushangle(L, slope->xydirection); return 1; - case slope_sourceline: // source linedef - LUA_PushUserdata(L, slope->sourceline, META_LINE); - return 1; - case slope_refpos: // refpos - lua_pushinteger(L, slope->refpos); - return 1; case slope_flags: // flags lua_pushinteger(L, slope->flags); return 1; @@ -1314,11 +1304,9 @@ static int slope_set(lua_State *L) switch(field) // todo: reorganize this shit { case slope_valid: // valid - case slope_sourceline: // sourceline case slope_d: // d case slope_flags: // flags case slope_normal: // normal - case slope_refpos: // refpos default: return luaL_error(L, "pslope_t field " LUA_QS " cannot be set.", slope_opt[field]); case slope_o: { // o diff --git a/src/lua_script.c b/src/lua_script.c index 28f02ca37..ef6faf600 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -413,9 +413,9 @@ void LUA_InvalidateLevel(void) size_t i; if (!gL) return; - - for (th = thinkercap.next; th && th != &thinkercap; th = th->next) - LUA_InvalidateUserdata(th); + for (i = 0; i < NUM_THINKERLISTS; i++) + for (th = thlist[i].next; th && th != &thlist[i]; th = th->next) + LUA_InvalidateUserdata(th); LUA_InvalidateMapthings(); @@ -1026,16 +1026,15 @@ void LUA_Archive(void) ArchiveExtVars(&players[i], "player"); } - if (gamestate == GS_LEVEL) - { - for (th = thinkercap.next; th != &thinkercap; th = th->next) + //if (gamestate == GS_LEVEL) + for (i = 0; i < NUM_THINKERLISTS; i++) + for (th = thlist[i].next; th != &thlist[i]; th = th->next) if (th->function.acp1 == (actionf_p1)P_MobjThinker) { // archive function will determine when to skip mobjs, // and write mobjnum in otherwise. ArchiveExtVars(th, "mobj"); } - } WRITEUINT32(save_p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. LUAh_NetArchiveHook(NetArchive); // call the NetArchive hook in archive mode @@ -1063,9 +1062,10 @@ void LUA_UnArchive(void) do { mobjnum = READUINT32(save_p); // read a mobjnum - for (th = thinkercap.next; th != &thinkercap; th = th->next) - if (th->function.acp1 == (actionf_p1)P_MobjThinker - && ((mobj_t *)th)->mobjnum == mobjnum) // find matching mobj + for (i = 0; i < NUM_THINKERLISTS; i++) + for (th = thlist[i].next; th != &thlist[i]; th = th->next) + if (th->function.acp1 == (actionf_p1)P_MobjThinker + && ((mobj_t *)th)->mobjnum == mobjnum) // find matching mobj UnArchiveExtVars(th); // apply variables } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. diff --git a/src/lua_thinkerlib.c b/src/lua_thinkerlib.c index ae859d46e..f961a8111 100644 --- a/src/lua_thinkerlib.c +++ b/src/lua_thinkerlib.c @@ -18,7 +18,7 @@ #define META_ITERATIONSTATE "iteration state" -static const char *const iter_opt[] = { +/*static const char *const iter_opt[] = { "all", "mobj", NULL}; @@ -26,7 +26,7 @@ static const char *const iter_opt[] = { static const actionf_p1 iter_funcs[] = { NULL, (actionf_p1)P_MobjThinker -}; +};*/ struct iterationState { actionf_p1 filter; @@ -58,7 +58,7 @@ static int lib_iterateThinkers(lua_State *L) lua_settop(L, 2); if (lua_isnil(L, 2)) - th = &thinkercap; + th = &thlist[THINK_MOBJ]; else if (lua_isuserdata(L, 2)) { if (lua_islightuserdata(L, 2)) @@ -88,11 +88,11 @@ static int lib_iterateThinkers(lua_State *L) if (!next) return luaL_error(L, "next thinker invalidated during iteration"); - for (; next != &thinkercap; next = next->next) + for (; next != &thlist[THINK_MOBJ]; next = next->next) if (!it->filter || next->function.acp1 == it->filter) { push_thinker(next); - if (next->next != &thinkercap) + if (next->next != &thlist[THINK_MOBJ]) { push_thinker(next->next); it->next = luaL_ref(L, LUA_REGISTRYINDEX); @@ -111,7 +111,7 @@ static int lib_startIterate(lua_State *L) luaL_getmetatable(L, META_ITERATIONSTATE); lua_setmetatable(L, -2); - it->filter = iter_funcs[luaL_checkoption(L, 1, "mobj", iter_opt)]; + it->filter = (actionf_p1)P_MobjThinker; //iter_funcs[luaL_checkoption(L, 1, "mobj", iter_opt)]; it->next = LUA_REFNIL; return 2; } @@ -129,7 +129,7 @@ int LUA_ThinkerLib(lua_State *L) lua_pushcfunction(L, lib_iterateThinkers); lua_pushcclosure(L, lib_startIterate, 1); lua_setfield(L, -2, "iterate"); - lua_setglobal(L, "thinkers"); + lua_setglobal(L, "mobjs"); return 0; } diff --git a/src/m_cheat.c b/src/m_cheat.c index e7e877ada..3bf18c981 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -912,11 +912,8 @@ static mapthing_t *OP_CreateNewMapThing(player_t *player, UINT16 type, boolean c thinker_t *th; mobj_t *mo; - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo = (mobj_t *)th; // get offset from mt, which points to old mapthings, then add new location if (mo->spawnpoint) diff --git a/src/p_ceilng.c b/src/p_ceilng.c index 757edebae..5395f618c 100644 --- a/src/p_ceilng.c +++ b/src/p_ceilng.c @@ -409,7 +409,7 @@ INT32 EV_DoCeiling(line_t *line, ceiling_e type) // new door thinker rtn = 1; ceiling = Z_Calloc(sizeof (*ceiling), PU_LEVSPEC, NULL); - P_AddThinker(&ceiling->thinker); + P_AddThinker(THINK_MAIN, &ceiling->thinker); sec->ceilingdata = ceiling; ceiling->thinker.function.acp1 = (actionf_p1)T_MoveCeiling; ceiling->sector = sec; @@ -629,7 +629,7 @@ INT32 EV_DoCrush(line_t *line, ceiling_e type) // new door thinker rtn = 1; ceiling = Z_Calloc(sizeof (*ceiling), PU_LEVSPEC, NULL); - P_AddThinker(&ceiling->thinker); + P_AddThinker(THINK_MAIN, &ceiling->thinker); sec->ceilingdata = ceiling; ceiling->thinker.function.acp1 = (actionf_p1)T_CrushCeiling; ceiling->sector = sec; diff --git a/src/p_enemy.c b/src/p_enemy.c index 1795a304b..ccdf23e01 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -25,6 +25,8 @@ #include "lua_hook.h" #include "k_kart.h" // SRB2kart +#include "p_user.c" + #ifdef HW3SOUND #include "hardware/hw3sound.h" #endif @@ -2745,11 +2747,8 @@ void A_BossDeath(mobj_t *mo) // scan the remaining thinkers to see // if all bosses are dead - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2 != mo && (mo2->flags & MF_BOSS) && mo2->health > 0) goto bossjustdie; // other boss not dead - just go straight to dying! @@ -2804,7 +2803,7 @@ bossjustdie: // Flee! Flee! Find a point to escape to! If none, just shoot upward! // scan the thinkers to find the runaway point - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; @@ -5437,11 +5436,8 @@ void A_RingExplode(mobj_t *actor) S_StartSound(actor, sfx_prloop); - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2 == actor) // Don't explode yourself! Endless loop! @@ -7073,11 +7069,8 @@ void A_Boss3Path(mobj_t *actor) // scan the thinkers // to find a point that matches // the number - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && mo2->spawnpoint->angle == actor->threshold) { @@ -7463,11 +7456,8 @@ void A_FindTarget(mobj_t *actor) CONS_Debug(DBG_GAMELOGIC, "A_FindTarget called from object type %d, var1: %d, var2: %d\n", actor->type, locvar1, locvar2); // scan the thinkers - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == (mobjtype_t)locvar1) @@ -7528,11 +7518,8 @@ void A_FindTracer(mobj_t *actor) CONS_Debug(DBG_GAMELOGIC, "A_FindTracer called from object type %d, var1: %d, var2: %d\n", actor->type, locvar1, locvar2); // scan the thinkers - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == (mobjtype_t)locvar1) @@ -8091,11 +8078,8 @@ void A_RemoteAction(mobj_t *actor) fixed_t dist1 = 0, dist2 = 0; // scan the thinkers - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == (mobjtype_t)locvar1) @@ -8662,738 +8646,6 @@ void A_LightningFollowPlayer(mobj_t *actor) } } -// A_FZBoomFlash: -// Flash everyone close enough to the boom -void A_FZBoomFlash(mobj_t *actor) -{ - UINT8 i; -#ifdef HAVE_BLUA - if (LUA_CallAction("A_FZBoomFlash", actor)) - return; -#endif - for (i = 0; i < MAXPLAYERS; i++) - { - fixed_t dist; - if (!playeringame[i] || !players[i].mo) - continue; - dist = P_AproxDistance(P_AproxDistance(actor->x-players[i].mo->x, actor->y-players[i].mo->y), actor->z-players[i].mo->z); - if (dist < 1536<x + (P_RandomRange(-rad, rad)*actor->scale), actor->y + (P_RandomRange(-rad, rad)*actor->scale), - actor->z + (P_RandomRange(0, 72)*actor->scale), MT_THOK); - - P_SetMobjState(smoke, S_FZEROSMOKE1); - smoke->tics += P_RandomRange(-3, 4); - smoke->scale = actor->scale*3; - } - return; -} - -// A_RandomShadowFrame -// Gives a random sprite for the Mayonaka static shadows. Dumb and simple. -void A_RandomShadowFrame(mobj_t *actor) -{ - mobj_t *fire; - mobj_t *fake; -#ifdef HAVE_BLUA - if (LUA_CallAction("A_RandomShadowFrame", (actor))) - return; -#endif - - if (!actor->extravalue1) // Hack that spawns thoks that look like random shadows. Otherwise the state would overwrite our frame and that's a pain. - { - fake = P_SpawnMobj(actor->x, actor->y, actor->z, MT_THOK); - fake->sprite = SPR_ENM1; - fake->frame = P_RandomRange(0, 6); - P_SetScale(fake, FRACUNIT*3/2); - fake->scale = FRACUNIT*3/2; - fake->destscale = FRACUNIT*3/2; - fake->angle = actor->angle; - fake->tics = -1; - actor->flags2 |= MF2_DONTDRAW; - actor->extravalue1 = 1; - } - - P_SetScale(actor, FRACUNIT*3/2); - - // I have NO CLUE how to hardcode all of that fancy Linedef Executor shit so the fire spinout will be done by these entities directly. - if (P_LookForPlayers(actor, false, false, 380<target && !actor->target->player->powers[pw_flashing] - && !actor->target->player->kartstuff[k_invincibilitytimer] - && !actor->target->player->kartstuff[k_growshrinktimer] - && !actor->target->player->kartstuff[k_spinouttimer] - && P_IsObjectOnGround(actor->target) - && actor->z == actor->target->z) - { - P_DamageMobj(actor->target, actor, actor, 1); - P_InstaThrust(actor->target, actor->angle, 16<target->x, actor->target->y, actor->target->z, MT_THOK); - P_SetMobjStateNF(fire, S_QUICKBOOM1); - P_SetScale(fire, 4<color = SKINCOLOR_KETCHUP; - S_StartSound(actor->target, sfx_fire2); - } - } - return; -} - -// A_RoamingShadowThinker -// Thinker for Midnight Channel's Roaming Shadows: -void A_RoamingShadowThinker(mobj_t *actor) -{ - mobj_t *wind; - -#ifdef HAVE_BLUA - if (LUA_CallAction("A_RoamingShadowThinker", (actor))) - return; -#endif - // extravalue1 replaces "movetimer" - // extravalue2 replaces "stoptimer" - - P_SetScale(actor, FRACUNIT*3/2); - if (!actor->extravalue2) - { - P_InstaThrust(actor, actor->angle, 8<extravalue1 = ((actor->extravalue1) ? (actor->extravalue1-1) : (TICRATE*5+1)); // deplete timer if set, set to 5 ticrate otherwise. - if (actor->extravalue1 == 1) // if timer reaches 1, do a u-turn. - { - actor->extravalue1 = 0; - actor->extravalue2 = 60; - } - // Search for and attack Players venturing too close in front of us. - - if (P_LookForPlayers(actor, false, false, 256<target && !actor->target->player->powers[pw_flashing] - && !actor->target->player->kartstuff[k_invincibilitytimer] - && !actor->target->player->kartstuff[k_growshrinktimer] - && !actor->target->player->kartstuff[k_spinouttimer]) - { - // send them flying and spawn the WIND! - P_InstaThrust(actor->target, 0, 0); - P_DamageMobj(actor->target, actor, actor, 1); - P_SetObjectMomZ(actor->target, 16<target, sfx_wind1); - - // Spawn the WIND: - wind = P_SpawnMobj(actor->target->x, actor->target->y, actor->target->z, MT_THOK); // Opaque layer: - P_SetMobjState(wind, S_GARU1); - P_SetScale(wind, FRACUNIT*3/2); - wind = P_SpawnMobj(actor->target->x, actor->target->y, actor->target->z, MT_THOK); // Translucent layer: - P_SetMobjState(wind, S_TGARU0); - P_SetScale(wind, FRACUNIT*3/2); - wind->destscale = 30<angle += ANG1*3; - actor->extravalue2--; - } - return; -} - -// A_MayonakaArrow -// Used for the arrow sprite animations in Mayonaka. It's only extra visual bullshit to make em more random. - -void A_MayonakaArrow(mobj_t *actor) -{ - INT32 flip = 0; - INT32 iswarning; -#ifdef HAVE_BLUA - if (LUA_CallAction("A_MayonakaArrow", (actor))) - return; -#endif - - iswarning = actor->spawnpoint->options & MTF_OBJECTSPECIAL; // is our object a warning sign? - // "animtimer" is replaced by "extravalue1" here. - actor->extravalue1 = ((actor->extravalue1) ? (actor->extravalue1+1) : (P_RandomRange(0, (iswarning) ? (TICRATE/2) : TICRATE*3))); - flip = ((actor->spawnpoint->options & 1) ? (3) : (0)); // flip adds 3 frames, which is the flipped version of the sign. - // special warning behavior: - if (iswarning) - flip = 6; - - actor->frame = flip + actor->extravalue2*3; - - if (actor->extravalue1 >= TICRATE*7/2) - { - actor->extravalue1 = 0; // reset to 0 and start a new cycle. - // special behavior for warning sign; swap from warning to sneaker & reverse - if (iswarning) - actor->extravalue2 = (actor->extravalue2) ? (0) : (1); - } - else if (actor->extravalue1 > TICRATE*7/2 -4) - actor->frame = flip+2; - else if (actor->extravalue1 > TICRATE*3 && leveltime%2 > 0) - actor->frame = flip+1; - - actor->frame |= FF_PAPERSPRITE; - actor->momz = 0; - return; -} - -// A_MementosTPParticles -// Mementos teleporters particles effects. Short and simple. - -void A_MementosTPParticles(mobj_t *actor) -{ - mobj_t *particle; - mobj_t *mo2; - int i = 0; - thinker_t *th; - -#ifdef HAVE_BLUA - if (LUA_CallAction("A_MementosTPParticles", (actor))) - return; -#endif - - for (; i<4; i++) - { - particle = P_SpawnMobj(actor->x + (P_RandomRange(-256, 256)<y + (P_RandomRange(-256, 256)<z + (P_RandomRange(48, 256)<frame = 0; - particle->color = ((i%2) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); - particle->destscale = 1; - P_HomingAttack(particle, actor); - } - - // Although this is mostly used to spawn particles, we will also save the OTHER teleport inside actor->target. That way teleporting doesn't require a thinker iteration. - // Doesn't seem like much given the small amount of mobjs this map has but heh. - if (!actor->target) - { - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - mo2 = (mobj_t *)th; - if (mo2->type == MT_MEMENTOSTP && mo2 != actor) - { - P_SetTarget(&actor->target, mo2); // The main target we're pursing. - break; - } - } - } -} - -// A_ReaperThinker -// Mementos's Reaper's thinker. A huge pain in the Derek Bum to translate from Lua to this shite if you ask me. - -void A_ReaperThinker(mobj_t *actor) -{ - mobj_t *particle; // particles to spawn - int i = 0; // for loops - angle_t an = ANGLE_22h; // Reminder that angle constants suck. - - //Waypoint stuff: - mobj_t *mo2; - thinker_t *th; - - //Player targetting stuff: - UINT32 maxscore = 0; // we target the player with the highest score so yeah there you go. - player_t *player; // used as a shortcut in a loop. - mobj_t *targetplayermo = NULL; // the player mo we can eventually target, or whatever. - - -#ifdef HAVE_BLUA - if (LUA_CallAction("A_ReaperThinker", (actor))) - return; -#endif - - // We don't have custom variables or whatever so we'll do with whatever the fuck we have left. - - if (actor->health == 1000) // if health is 1000, set it to a small scale and have it start growing with destscale. Then set the health to uh, not 1000. - { - actor->scale = 1; - actor->destscale = 2<scalespeed = FRACUNIT/24; // Should take a bit less than 2 seconds to fully grow. - S_StartSound(NULL, sfx_chain); - actor->health--; // now we have 999 health, so that above won't happen again. Awesome. - } - - if (actor->scale < 2<x + (P_RandomRange(-60, 60)<y + (P_RandomRange(-60, 60)<z, MT_THOK); - particle->momz = 20<color = ((i%2 !=0) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); - particle->frame = 0; - P_SetScale(particle, FRACUNIT/2); - } - - // Spawn particles in some edgy circle or w/e. - - if (leveltime%5 != 0) // spawn the thing under that every tic. - return; - - i=0; - for (; i<15; i++) // spawn in a circle formation or w/e. - { - particle = P_SpawnMobj(actor->x, actor->y, actor->z, MT_THOK); - particle->momz = 20<color = ((i%2 !=0) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); - particle->frame = 0; - P_SetScale(particle, FRACUNIT/2); - P_InstaThrust(particle, an*i, 30<flags = MF_NOGRAVITY|MF_PAIN|MF_SPECIAL|MF_NOCLIP|MF_NOCLIPHEIGHT; // set our flags to be a damaging thing. - // Handle animation: - if (!(leveltime%5)) - actor->extravalue2 = (actor->extravalue2 < 9) ? (actor->extravalue2+1) : (0); // Ghetto animation, but hey it works for what it's worth - - // Chain sfx - if (!S_SoundPlaying(actor, sfx_chain)) - S_StartSound(actor, sfx_chain); - - actor->frame = actor->extravalue2; // yes i'm that bad at maths don't @ me. - - if (!actor->target) - { - if (actor->hnext) - { - P_SetTarget(&actor->target, actor->hnext); // Default back to last waypoint. - return; - } - - // We have no target and oughta find one, so let's scan through thinkers for a waypoint of angle 0, or something. - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - mo2 = (mobj_t *)th; - - if (mo2->type != MT_REAPERWAYPOINT) - continue; - if (mo2->spawnpoint->angle != 0) - continue; - - P_SetTarget(&actor->target, mo2); // The main target we're pursing. - P_SetTarget(&actor->hnext, mo2); // The last waypoint we hit. We will default back to that if a player goes out of our range! - actor->extravalue1 = 0; // This will store the angle of the last waypoint we touched. This will essentially be useful later on. - if (!actor->tracer) // If we already have a tracer (Waypoint #0), don't do anything. - { - P_SetTarget(&actor->tracer, mo2); // Because our target might be a player OR a waypoint, we need some sort of fallback option. This will always be waypoint 0. - break; - } - } - } - else // Awesome, we now have a target. - { - // Follow target: - P_InstaThrust(actor, R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y), 20<angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y); - - // The player we should target if it's near us: - for (i=0; imo && player->kartstuff[k_bumper] && player->score >= maxscore) - { - targetplayermo = player->mo; - maxscore = player->score; - } - } - - // Try to target that player: - if (targetplayermo) - { - if (P_LookForPlayers(actor, false, false, 1024<target == targetplayermo && actor->target && !actor->target->player->powers[pw_flashing] - && !actor->target->player->kartstuff[k_invincibilitytimer] - && !actor->target->player->kartstuff[k_growshrinktimer] - && !actor->target->player->kartstuff[k_spinouttimer])) - P_SetTarget(&actor->target, actor->hnext); - // if the above isn't correct, then we should go back to targetting waypoints or something. - } - } - - // Waypoint behavior. - if (actor->target->type == MT_REAPERWAYPOINT) - { - - if (R_PointToDist2(actor->x, actor->y, actor->target->x, actor->target->y) < 22<target, NULL); // remove target so we can default back to first waypoint if things go ham. - - // If we reach close to a waypoint, then we should go to the NEXT one. - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - mo2 = (mobj_t *)th; - - if (mo2->type != MT_REAPERWAYPOINT) - continue; - if (mo2->spawnpoint->angle != actor->extravalue1+1) - continue; - - P_SetTarget(&actor->target, mo2); // The main target we're pursing. - P_SetTarget(&actor->hnext, mo2); // The last waypoint we hit. We will default back to that if a player goes out of our range! - actor->extravalue1++; // This will store the angle of the last waypoint we touched. This will essentially be useful later on. - break; - } - } - - - if (!actor->target) // If we have no target, revert back to waypoint 0. - { - actor->extravalue1 = 0; - P_SetTarget(&actor->target, actor->tracer); - } - } - else // if our target ISN'T a waypoint, then it can only be a player. - { - if (!P_CheckSight(actor, actor->target) || R_PointToDist2(actor->x, actor->y, actor->target->x, actor->target->y) > 1024<target, actor->hnext); - } - } -} - -void A_FlameParticle(mobj_t *actor) -{ - fixed_t rad = actor->radius>>FRACBITS, hei = actor->radius>>FRACBITS; - mobj_t *par; -#ifdef HAVE_BLUA - if (LUA_CallAction("A_FlameParticle", actor)) - return; -#endif - - par = P_SpawnMobj( - actor->x + (P_RandomRange(-rad, rad)<y + (P_RandomRange(-rad, rad)<z + (P_RandomRange(hei/2, hei)<info->painchance); - par->momz = actor->scale<<1; -} - -//} - -// Function: A_OrbitNights -// -// Description: Used by Chaos Emeralds to orbit around Nights (aka Super Sonic.) -// -// var1 = Angle adjustment (aka orbit speed) -// var2 = Lower four bits: height offset, Upper 4 bits = set if object is Nightopian Helper -// -void A_OrbitNights(mobj_t* actor) -{ - INT32 ofs = (var2 & 0xFFFF); - boolean ishelper = (var2 & 0xFFFF0000); -#ifdef HAVE_BLUA - if (LUA_CallAction("A_OrbitNights", actor)) - return; -#endif - - if (!actor->target || !actor->target->player || - !actor->target->tracer || !actor->target->player->nightstime - // Also remove this object if they no longer have a NiGHTS helper - || (ishelper && !actor->target->player->powers[pw_nights_helper])) - { - P_RemoveMobj(actor); - return; - } - else - { - actor->extravalue1 += var1; - P_UnsetThingPosition(actor); - { - const angle_t fa = (angle_t)actor->extravalue1 >> ANGLETOFINESHIFT; - const angle_t ofa = ((angle_t)actor->extravalue1 + (ofs*ANG1)) >> ANGLETOFINESHIFT; - - const fixed_t fc = FixedMul(FINECOSINE(fa),FixedMul(32*FRACUNIT, actor->scale)); - const fixed_t fh = FixedMul(FINECOSINE(ofa),FixedMul(20*FRACUNIT, actor->scale)); - const fixed_t fs = FixedMul(FINESINE(fa),FixedMul(32*FRACUNIT, actor->scale)); - - actor->x = actor->target->tracer->x + fc; - actor->y = actor->target->tracer->y + fs; - actor->z = actor->target->tracer->z + fh + FixedMul(16*FRACUNIT, actor->scale); - - // Semi-lazy hack - actor->angle = (angle_t)actor->extravalue1 + ANGLE_90; - } - P_SetThingPosition(actor); - } -} - -// Function: A_GhostMe -// -// Description: Spawns a "ghost" mobj of this actor, ala spindash trails and the minus's digging "trails" -// -// var1 = unused -// var2 = unused -// -void A_GhostMe(mobj_t *actor) -{ -#ifdef HAVE_BLUA - if (LUA_CallAction("A_GhostMe", actor)) - return; -#endif - P_SpawnGhostMobj(actor); -} - -// Function: A_SetObjectState -// -// Description: Changes the state of an object's target/tracer. -// -// var1 = state number -// var2: -// 0 = target -// 1 = tracer -// -void A_SetObjectState(mobj_t *actor) -{ - INT32 locvar1 = var1; - INT32 locvar2 = var2; - mobj_t *target; -#ifdef HAVE_BLUA - if (LUA_CallAction("A_SetObjectState", actor)) - return; -#endif - - if ((!locvar2 && !actor->target) || (locvar2 && !actor->tracer)) - { - if (cv_debug) - CONS_Printf("A_SetObjectState: No target to change state!\n"); - return; - } - - if (!locvar2) // target - target = actor->target; - else // tracer - target = actor->tracer; - - if (target->health > 0) - { - if (!target->player) - P_SetMobjState(target, locvar1); - else - P_SetPlayerMobjState(target, locvar1); - } -} - -// Function: A_SetObjectTypeState -// -// Description: Changes the state of all active objects of a certain type in a certain range of the actor. -// -// var1 = state number -// var2: -// lower 16 bits = type -// upper 16 bits = range (if == 0, across whole map) -// -void A_SetObjectTypeState(mobj_t *actor) -{ - INT32 locvar1 = var1; - INT32 locvar2 = var2; - const UINT16 loc2lw = (UINT16)(locvar2 & 65535); - const UINT16 loc2up = (UINT16)(locvar2 >> 16); - - thinker_t *th; - mobj_t *mo2; - fixed_t dist = 0; - -#ifdef HAVE_BLUA - if (LUA_CallAction("A_SetObjectTypeState", actor)) - return; -#endif - - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - mo2 = (mobj_t *)th; - - if (mo2->type == (mobjtype_t)loc2lw) - { - dist = P_AproxDistance(mo2->x - actor->x, mo2->y - actor->y); - - if (mo2->health > 0) - { - if (loc2up == 0) - P_SetMobjState(mo2, locvar1); - else - { - if (dist <= FixedMul(loc2up*FRACUNIT, actor->scale)) - P_SetMobjState(mo2, locvar1); - } - } - } - } -} - -// Function: A_KnockBack -// -// Description: Knocks back the object's target at its current speed. -// -// var1: -// 0 = target -// 1 = tracer -// var2 = unused -// -void A_KnockBack(mobj_t *actor) -{ - INT32 locvar1 = var1; - mobj_t *target; -#ifdef HAVE_BLUA - if (LUA_CallAction("A_KnockBack", actor)) - return; -#endif - - if (!locvar1) - target = actor->target; - else - target = actor->tracer; - - if (!target) - { - if(cv_debug) - CONS_Printf("A_KnockBack: No target!\n"); - return; - } - - target->momx *= -1; - target->momy *= -1; -} - -// Function: A_PushAway -// -// Description: Pushes an object's target away from the calling object. -// -// var1 = amount of force -// var2: -// lower 16 bits = If 1, xy momentum is lost. If 0, xy momentum is kept -// upper 16 bits = 0 - target, 1 - tracer -// -void A_PushAway(mobj_t *actor) -{ - INT32 locvar1 = var1; - INT32 locvar2 = var2; - mobj_t *target; // target - angle_t an; // actor to target angle -#ifdef HAVE_BLUA - if (LUA_CallAction("A_PushAway", actor)) - return; -#endif - - if ((!(locvar2 >> 16) && !actor->target) || ((locvar2 >> 16) && !actor->tracer)) - return; - - if (!locvar1) - CONS_Printf("A_Thrust: Var1 not specified!\n"); - - if (!(locvar2 >> 16)) // target - target = actor->target; - else // tracer - target = actor->tracer; - - an = R_PointToAngle2(actor->x, actor->y, target->x, target->y); - - if (locvar2 & 65535) - P_InstaThrust(target, an, FixedMul(locvar1*FRACUNIT, actor->scale)); - else - P_Thrust(target, an, FixedMul(locvar1*FRACUNIT, actor->scale)); -} - -// Function: A_RingDrain -// -// Description: Drain targeted player's rings. -// -// var1 = ammount of drained rings -// var2 = unused -// -void A_RingDrain(mobj_t *actor) -{ - INT32 locvar1 = var1; - player_t *player; -#ifdef HAVE_BLUA - if (LUA_CallAction("A_RingDrain", actor)) - return; -#endif - - if (!actor->target || !actor->target->player) - { - if(cv_debug) - CONS_Printf("A_RingDrain: No player targeted!\n"); - return; - } - - player = actor->target->player; - P_GivePlayerRings(player, -min(locvar1, player->mo->health-1)); -} - -// Function: A_SplitShot -// -// Description: Shoots 2 missiles that hit next to the player. -// -// var1 = target x-y-offset -// var2: -// lower 16 bits = missile type -// upper 16 bits = height offset -// -void A_SplitShot(mobj_t *actor) -{ - INT32 locvar1 = var1; - INT32 locvar2 = var2; - const UINT16 loc2lw = (UINT16)(locvar2 & 65535); - const UINT16 loc2up = (UINT16)(locvar2 >> 16); - const fixed_t offs = (fixed_t)(locvar1*FRACUNIT); - const fixed_t hoffs = (fixed_t)(loc2up*FRACUNIT); -#ifdef HAVE_BLUA - if (LUA_CallAction("A_SplitShot", actor)) - return; -#endif - - A_FaceTarget(actor); - { - const angle_t an = (actor->angle + ANGLE_90) >> ANGLETOFINESHIFT; - const fixed_t fasin = FINESINE(an); - const fixed_t facos = FINECOSINE(an); - fixed_t xs = FixedMul(facos,FixedMul(offs, actor->scale)); - fixed_t ys = FixedMul(fasin,FixedMul(offs, actor->scale)); - fixed_t z; - - if (actor->eflags & MFE_VERTICALFLIP) - z = actor->z + actor->height - FixedMul(hoffs, actor->scale); - else - z = actor->z + FixedMul(hoffs, actor->scale); - - P_SpawnPointMissile(actor, actor->target->x+xs, actor->target->y+ys, actor->target->z, loc2lw, actor->x, actor->y, z); - P_SpawnPointMissile(actor, actor->target->x-xs, actor->target->y-ys, actor->target->z, loc2lw, actor->x, actor->y, z); - } -} - // Function: A_MissileSplit // // Description: If the object is a missile it will create a new missile with an alternate flight path owned by the one who shot the former missile. @@ -9866,7 +9118,7 @@ void A_CheckThingCount(mobj_t *actor) return; #endif - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; diff --git a/src/p_floor.c b/src/p_floor.c index ccbfd6eae..352f8d79f 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -1975,11 +1975,8 @@ void T_ThwompSector(levelspecthink_t *thwomp) if (!rover || (rover->flags & FF_EXISTS)) { // scan the thinkers to find players! - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo = (mobj_t *)th; if (mo->type == MT_PLAYER && mo->health && mo->player && !mo->player->spectator && mo->z <= thwomp->sector->ceilingheight @@ -2675,7 +2672,7 @@ INT32 EV_DoFloor(line_t *line, floor_e floortype) // new floor thinker rtn = 1; dofloor = Z_Calloc(sizeof (*dofloor), PU_LEVSPEC, NULL); - P_AddThinker(&dofloor->thinker); + P_AddThinker(THINK_MAIN, &dofloor->thinker); // make sure another floor thinker won't get started over this one sec->floordata = dofloor; @@ -2896,7 +2893,7 @@ INT32 EV_DoElevator(line_t *line, elevator_e elevtype, boolean customspeed) // create and initialize new elevator thinker rtn = 1; elevator = Z_Calloc(sizeof (*elevator), PU_LEVSPEC, NULL); - P_AddThinker(&elevator->thinker); + P_AddThinker(THINK_MAIN, &elevator->thinker); sec->floordata = elevator; sec->ceilingdata = elevator; elevator->thinker.function.acp1 = (actionf_p1)T_MoveElevator; @@ -3078,7 +3075,7 @@ INT32 EV_BounceSector(sector_t *sec, fixed_t momz, line_t *sourceline) return 0; bouncer = Z_Calloc(sizeof (*bouncer), PU_LEVSPEC, NULL); - P_AddThinker(&bouncer->thinker); + P_AddThinker(THINK_MAIN, &bouncer->thinker); sec->ceilingdata = bouncer; bouncer->thinker.function.acp1 = (actionf_p1)T_BounceCheese; @@ -3112,7 +3109,7 @@ INT32 EV_DoContinuousFall(sector_t *sec, sector_t *backsector, fixed_t spd, bool // create and initialize new thinker faller = Z_Calloc(sizeof (*faller), PU_LEVSPEC, NULL); - P_AddThinker(&faller->thinker); + P_AddThinker(THINK_MAIN, &faller->thinker); faller->thinker.function.acp1 = (actionf_p1)T_ContinuousFalling; // set up the fields @@ -3161,7 +3158,7 @@ INT32 EV_StartCrumble(sector_t *sec, ffloor_t *rover, boolean floating, // create and initialize new elevator thinker elevator = Z_Calloc(sizeof (*elevator), PU_LEVSPEC, NULL); - P_AddThinker(&elevator->thinker); + P_AddThinker(THINK_MAIN, &elevator->thinker); elevator->thinker.function.acp1 = (actionf_p1)T_StartCrumble; // Does this crumbler return? @@ -3235,7 +3232,7 @@ INT32 EV_MarioBlock(sector_t *sec, sector_t *roversector, fixed_t topheight, mob // create and initialize new elevator thinker block = Z_Calloc(sizeof (*block), PU_LEVSPEC, NULL); - P_AddThinker(&block->thinker); + P_AddThinker(THINK_MAIN, &block->thinker); sec->floordata = block; sec->ceilingdata = block; block->thinker.function.acp1 = (actionf_p1)T_MarioBlock; diff --git a/src/p_inter.c b/src/p_inter.c index a910445da..09589c880 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -27,6 +27,7 @@ #include "m_misc.h" #include "v_video.h" // video flags for CEchos #include "k_kart.h" // SRB2kart +#include "p_local.h" // CTF player names #define CTFTEAMCODE(pl) pl->ctfteam ? (pl->ctfteam == 1 ? "\x85" : "\x84") : "" @@ -995,11 +996,8 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) count = 1; // scan the remaining thinkers - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2 == special) @@ -1045,11 +1043,8 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) // Now we RE-scan all the thinkers to find close objects to pull // in from the paraloop. Isn't this just so efficient? - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (P_AproxDistance(P_AproxDistance(mo2->x - x, mo2->y - y), mo2->z - z) > gatherradius) @@ -1414,11 +1409,8 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) EV_DoElevator(&junk, bridgeFall, false); // scan the remaining thinkers to find koopa - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_KOOPA) { @@ -2545,7 +2537,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) // scan the thinkers to make sure all the old pinch dummies are gone on death // this can happen if the boss was hurt earlier than expected - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; diff --git a/src/p_lights.c b/src/p_lights.c index 2da38d1dc..e7f74957b 100644 --- a/src/p_lights.c +++ b/src/p_lights.c @@ -76,7 +76,7 @@ fireflicker_t *P_SpawnAdjustableFireFlicker(sector_t *minsector, sector_t *maxse P_RemoveLighting(maxsector); // out with the old, in with the new flick = Z_Calloc(sizeof (*flick), PU_LEVSPEC, NULL); - P_AddThinker(&flick->thinker); + P_AddThinker(THINK_MAIN, &flick->thinker); flick->thinker.function.acp1 = (actionf_p1)T_FireFlicker; flick->sector = maxsector; @@ -155,7 +155,7 @@ void P_SpawnLightningFlash(sector_t *sector) flash = Z_Calloc(sizeof (*flash), PU_LEVSPEC, NULL); - P_AddThinker(&flash->thinker); + P_AddThinker(THINK_MAIN, &flash->thinker); flash->thinker.function.acp1 = (actionf_p1)T_LightningFlash; flash->sector = sector; @@ -214,7 +214,7 @@ strobe_t *P_SpawnAdjustableStrobeFlash(sector_t *minsector, sector_t *maxsector, P_RemoveLighting(maxsector); // out with the old, in with the new flash = Z_Calloc(sizeof (*flash), PU_LEVSPEC, NULL); - P_AddThinker(&flash->thinker); + P_AddThinker(THINK_MAIN, &flash->thinker); flash->sector = maxsector; flash->darktime = darktime; @@ -289,7 +289,7 @@ glow_t *P_SpawnAdjustableGlowingLight(sector_t *minsector, sector_t *maxsector, P_RemoveLighting(maxsector); // out with the old, in with the new g = Z_Calloc(sizeof (*g), PU_LEVSPEC, NULL); - P_AddThinker(&g->thinker); + P_AddThinker(THINK_MAIN, &g->thinker); g->sector = maxsector; g->minlight = minsector->lightlevel; @@ -350,7 +350,7 @@ void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed) ll->thinker.function.acp1 = (actionf_p1)T_LightFade; sector->lightingdata = ll; // set it to the lightlevel_t - P_AddThinker(&ll->thinker); // add thinker + P_AddThinker(THINK_MAIN, &ll->thinker); // add thinker ll->sector = sector; ll->destlevel = destvalue; diff --git a/src/p_local.h b/src/p_local.h index 0d0ddc89b..f0e530ef4 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -60,15 +60,21 @@ #define mariomode (maptol & TOL_MARIO) #define twodlevel (maptol & TOL_2D) -// -// P_TICK -// - -// both the head and tail of the thinker list -extern thinker_t thinkercap; +typedef enum{ + THINK_LIMBO, + THINK_POLYOBJ, + THINK_MAIN, + THINK_MOBJ, +#ifdef ESLOPE + THINK_DYNSLOPE, +#endif + THINK_PRECIP, + NUM_THINKERLISTS +} thinklistnum_t; /**< Thinker lists. */ +extern thinker_t thlist[]; void P_InitThinkers(void); -void P_AddThinker(thinker_t *thinker); +void P_AddThinker(const thinklistnum_t n, thinker_t *thinker); void P_RemoveThinker(thinker_t *thinker); // diff --git a/src/p_map.c b/src/p_map.c index d9b723650..126d6c95e 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -3994,7 +3994,7 @@ static boolean PIT_ChangeSector(mobj_t *thing, boolean realcrush) thinker_t *think; elevator_t *crumbler; - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MAIN].next; think != &thlist[THINK_MAIN]; think = think->next) { if (think->function.acp1 != (actionf_p1)T_StartCrumble) continue; diff --git a/src/p_mobj.c b/src/p_mobj.c index f7f2afe34..85731a062 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -421,11 +421,8 @@ boolean P_WeaponOrPanel(mobjtype_t type) spawnpoints[i] = NULL; } - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 != (actionf_p1)P_MobjThinker) - continue; // not a mobj thinker - mo = (mobj_t *)think; if (mo->type == MT_EMERALDSPAWN) @@ -3498,11 +3495,8 @@ void P_DestroyRobots(void) mobj_t *mo; thinker_t *think; - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 != (actionf_p1)P_MobjThinker) - continue; // not a mobj thinker - mo = (mobj_t *)think; if (mo->health <= 0 || !(mo->flags & MF_ENEMY || mo->flags & MF_BOSS)) continue; // not a valid enemy @@ -4305,11 +4299,8 @@ static void P_Boss3Thinker(mobj_t *mobj) // scan the thinkers to make sure all the old pinch dummies are gone before making new ones // this can happen if the boss was hurt earlier than expected - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == (mobjtype_t)mobj->info->mass && mo2->tracer == mobj) { @@ -4396,11 +4387,8 @@ static void P_Boss3Thinker(mobj_t *mobj) // scan the thinkers // to find a point that matches // the number - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && mo2->spawnpoint->angle == mobj->threshold) { @@ -5017,11 +5005,8 @@ static void P_Boss7Thinker(mobj_t *mobj) closestdist = 16384*FRACUNIT; // Just in case... // Find waypoint he is closest to - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint) { @@ -5072,11 +5057,8 @@ static void P_Boss7Thinker(mobj_t *mobj) // scan the thinkers to find // the waypoint to use - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && (mo2->spawnpoint->options & 7) == waypointNum) { @@ -5195,11 +5177,8 @@ static void P_Boss9Thinker(mobj_t *mobj) // Run through the thinkers ONCE and find all of the MT_BOSS9GATHERPOINT in the map. // Build a hoop linked list of 'em! - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS9GATHERPOINT) { @@ -5629,11 +5608,8 @@ mobj_t *P_GetClosestAxis(mobj_t *source) fixed_t dist1, dist2 = 0; // scan the thinkers to find the closest axis point - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_AXIS) @@ -10124,7 +10100,7 @@ mobj_t *P_SpawnShadowMobj(mobj_t * caster) mobj->eflags |= MFE_ONGROUND; if (!(mobj->flags & MF_NOTHINK)) - P_AddThinker(&mobj->thinker); + P_AddThinker(THINK_MOBJ, &mobj->thinker); // Call action functions when the state is set if (st->action.acp1 && (mobj->flags & MF_RUNSPAWNFUNC)) @@ -10198,7 +10174,7 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype mobj->momz = mobjinfo[type].speed; mobj->thinker.function.acp1 = (actionf_p1)P_NullPrecipThinker; - P_AddThinker(&mobj->thinker); + P_AddThinker(THINK_PRECIP, &mobj->thinker); CalculatePrecipFloor(mobj); @@ -10344,7 +10320,7 @@ void P_RemoveMobj(mobj_t *mobj) else { // Add thinker just to delay removing it until refrences are gone. mobj->flags &= ~MF_NOTHINK; - P_AddThinker((thinker_t *)mobj); + P_AddThinker(THINK_MOBJ, (thinker_t *)mobj); #ifdef SCRAMBLE_REMOVED // Invalidate mobj_t data to cause crashes if accessed! memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); @@ -11767,11 +11743,8 @@ ML_NOCLIMB : Direction not controllable mobj->health = (mthing->angle / 360) + 1; // See if other starposts exist in this level that have the same value. - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2 == mobj) diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 03fb10d0f..22477ff5d 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -142,16 +142,6 @@ FUNCINLINE static ATTRINLINE void Polyobj_vecSub2(vertex_t *dst, vertex_t *v1, v dst->y = v1->y - v2->y; } -// Add the polyobject's thinker to the thinker list -// Unlike P_AddThinker, this adds it to the front of the list instead of the back, so that carrying physics can work right. -Red -FUNCINLINE static ATTRINLINE void PolyObj_AddThinker(thinker_t *th) -{ - thinkercap.next->prev = th; - th->next = thinkercap.next; - th->prev = &thinkercap; - thinkercap.next = th; -} - // // P_PointInsidePolyobj // @@ -1504,31 +1494,28 @@ void Polyobj_InitLevel(void) // run down the thinker list, count the number of spawn points, and save // the mobj_t pointers on a queue for use below. - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_MobjThinker) + mobj_t *mo = (mobj_t *)th; + + if (mo->info->doomednum == POLYOBJ_SPAWN_DOOMEDNUM || + mo->info->doomednum == POLYOBJ_SPAWNCRUSH_DOOMEDNUM) { - mobj_t *mo = (mobj_t *)th; + ++numPolyObjects; - if (mo->info->doomednum == POLYOBJ_SPAWN_DOOMEDNUM || - mo->info->doomednum == POLYOBJ_SPAWNCRUSH_DOOMEDNUM) - { - ++numPolyObjects; + qitem = malloc(sizeof(mobjqitem_t)); + memset(qitem, 0, sizeof(mobjqitem_t)); + qitem->mo = mo; + M_QueueInsert(&(qitem->mqitem), &spawnqueue); + } + else if (mo->info->doomednum == POLYOBJ_ANCHOR_DOOMEDNUM) + { + ++numAnchors; - qitem = malloc(sizeof(mobjqitem_t)); - memset(qitem, 0, sizeof(mobjqitem_t)); - qitem->mo = mo; - M_QueueInsert(&(qitem->mqitem), &spawnqueue); - } - else if (mo->info->doomednum == POLYOBJ_ANCHOR_DOOMEDNUM) - { - ++numAnchors; - - qitem = malloc(sizeof(mobjqitem_t)); - memset(qitem, 0, sizeof(mobjqitem_t)); - qitem->mo = mo; - M_QueueInsert(&(qitem->mqitem), &anchorqueue); - } + qitem = malloc(sizeof(mobjqitem_t)); + memset(qitem, 0, sizeof(mobjqitem_t)); + qitem->mo = mo; + M_QueueInsert(&(qitem->mqitem), &anchorqueue); } } @@ -1639,7 +1626,7 @@ void T_PolyObjRotate(polyrotate_t *th) #else { CONS_Debug(DBG_POLYOBJ, "T_PolyObjRotate: thinker with invalid id %d removed.\n", th->polyObjNum); - P_RemoveThinkerDelayed(&th->thinker); + P_RemoveThinker(&th->thinker); return; } #endif @@ -1724,7 +1711,7 @@ void T_PolyObjMove(polymove_t *th) #else { CONS_Debug(DBG_POLYOBJ, "T_PolyObjMove: thinker with invalid id %d removed.\n", th->polyObjNum); - P_RemoveThinkerDelayed(&th->thinker); + P_RemoveThinker(&th->thinker); return; } #endif @@ -1797,7 +1784,7 @@ void T_PolyObjWaypoint(polywaypoint_t *th) #else { CONS_Debug(DBG_POLYOBJ, "T_PolyObjWaypoint: thinker with invalid id %d removed.", th->polyObjNum); - P_RemoveThinkerDelayed(&th->thinker); + P_RemoveThinker(&th->thinker); return; } #endif @@ -1808,11 +1795,8 @@ void T_PolyObjWaypoint(polywaypoint_t *th) // Find out target first. // We redo this each tic to make savegame compatibility easier. - for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) + for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { - if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) @@ -1889,11 +1873,8 @@ void T_PolyObjWaypoint(polywaypoint_t *th) CONS_Debug(DBG_POLYOBJ, "Looking for next waypoint...\n"); // Find next waypoint - for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) + for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { - if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) @@ -1928,11 +1909,8 @@ void T_PolyObjWaypoint(polywaypoint_t *th) th->stophere = true; } - for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) + for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { - if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) @@ -1965,11 +1943,8 @@ void T_PolyObjWaypoint(polywaypoint_t *th) if (!th->continuous) th->comeback = false; - for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) + for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { - if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) @@ -2071,7 +2046,7 @@ void T_PolyDoorSlide(polyslidedoor_t *th) #else { CONS_Debug(DBG_POLYOBJ, "T_PolyDoorSlide: thinker with invalid id %d removed.\n", th->polyObjNum); - P_RemoveThinkerDelayed(&th->thinker); + P_RemoveThinker(&th->thinker); return; } #endif @@ -2176,7 +2151,7 @@ void T_PolyDoorSwing(polyswingdoor_t *th) #else { CONS_Debug(DBG_POLYOBJ, "T_PolyDoorSwing: thinker with invalid id %d removed.\n", th->polyObjNum); - P_RemoveThinkerDelayed(&th->thinker); + P_RemoveThinker(&th->thinker); return; } #endif @@ -2274,8 +2249,8 @@ void T_PolyObjDisplace(polydisplace_t *th) I_Error("T_PolyDoorSwing: thinker has invalid id %d\n", th->polyObjNum); #else { - CONS_Debug(DBG_POLYOBJ, "T_PolyDoorSwing: thinker with invalid id %d removed.\n", th->polyObjNum); - P_RemoveThinkerDelayed(&th->thinker); + CONS_Debug(DBG_POLYOBJ, "T_PolyObjDisplace: thinker with invalid id %d removed.\n", th->polyObjNum); + P_RemoveThinker(&th->thinker); return; } #endif @@ -2333,7 +2308,7 @@ INT32 EV_DoPolyObjRotate(polyrotdata_t *prdata) // create a new thinker th = Z_Malloc(sizeof(polyrotate_t), PU_LEVSPEC, NULL); th->thinker.function.acp1 = (actionf_p1)T_PolyObjRotate; - PolyObj_AddThinker(&th->thinker); + P_AddThinker(THINK_POLYOBJ, &th->thinker); po->thinker = &th->thinker; // set fields @@ -2398,7 +2373,7 @@ INT32 EV_DoPolyObjMove(polymovedata_t *pmdata) // create a new thinker th = Z_Malloc(sizeof(polymove_t), PU_LEVSPEC, NULL); th->thinker.function.acp1 = (actionf_p1)T_PolyObjMove; - PolyObj_AddThinker(&th->thinker); + P_AddThinker(THINK_POLYOBJ, &th->thinker); po->thinker = &th->thinker; // set fields @@ -2459,7 +2434,7 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) // create a new thinker th = Z_Malloc(sizeof(polywaypoint_t), PU_LEVSPEC, NULL); th->thinker.function.acp1 = (actionf_p1)T_PolyObjWaypoint; - PolyObj_AddThinker(&th->thinker); + P_AddThinker(THINK_POLYOBJ, &th->thinker); po->thinker = &th->thinker; // set fields @@ -2477,11 +2452,8 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) th->stophere = false; // Find the first waypoint we need to use - for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) + for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { - if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) @@ -2548,11 +2520,8 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) // Find the actual target movement waypoint target = first; - /*for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) + /*for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { - if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) @@ -2605,7 +2574,7 @@ static void Polyobj_doSlideDoor(polyobj_t *po, polydoordata_t *doordata) // allocate and add a new slide door thinker th = Z_Malloc(sizeof(polyslidedoor_t), PU_LEVSPEC, NULL); th->thinker.function.acp1 = (actionf_p1)T_PolyDoorSlide; - PolyObj_AddThinker(&th->thinker); + P_AddThinker(THINK_POLYOBJ, &th->thinker); // point the polyobject to this thinker po->thinker = &th->thinker; @@ -2653,7 +2622,7 @@ static void Polyobj_doSwingDoor(polyobj_t *po, polydoordata_t *doordata) // allocate and add a new swing door thinker th = Z_Malloc(sizeof(polyswingdoor_t), PU_LEVSPEC, NULL); th->thinker.function.acp1 = (actionf_p1)T_PolyDoorSwing; - PolyObj_AddThinker(&th->thinker); + P_AddThinker(THINK_POLYOBJ, &th->thinker); // point the polyobject to this thinker po->thinker = &th->thinker; @@ -2735,7 +2704,7 @@ INT32 EV_DoPolyObjDisplace(polydisplacedata_t *prdata) // create a new thinker th = Z_Malloc(sizeof(polydisplace_t), PU_LEVSPEC, NULL); th->thinker.function.acp1 = (actionf_p1)T_PolyObjDisplace; - PolyObj_AddThinker(&th->thinker); + P_AddThinker(THINK_POLYOBJ, &th->thinker); po->thinker = &th->thinker; // set fields @@ -2772,7 +2741,7 @@ void T_PolyObjFlag(polymove_t *th) #else { CONS_Debug(DBG_POLYOBJ, "T_PolyObjFlag: thinker with invalid id %d removed.\n", th->polyObjNum); - P_RemoveThinkerDelayed(&th->thinker); + P_RemoveThinker(&th->thinker); return; } #endif @@ -2836,7 +2805,7 @@ INT32 EV_DoPolyObjFlag(line_t *pfdata) // create a new thinker th = Z_Malloc(sizeof(polymove_t), PU_LEVSPEC, NULL); th->thinker.function.acp1 = (actionf_p1)T_PolyObjFlag; - PolyObj_AddThinker(&th->thinker); + P_AddThinker(THINK_POLYOBJ, &th->thinker); po->thinker = &th->thinker; // set fields diff --git a/src/p_saveg.c b/src/p_saveg.c index 7d2e9a307..712773cbc 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1021,6 +1021,14 @@ static inline UINT32 SavePlayer(const player_t *player) return 0xFFFFFFFF; } +#ifdef ESLOPE +static UINT32 SaveSlope(const pslope_t *slope) +{ + if (slope) return (UINT32)(slope->id); + return 0xFFFFFFFF; +} +#endif // ESLOPE + // // SaveMobjThinker // @@ -1683,211 +1691,216 @@ static inline void SaveWhatThinker(const thinker_t *th, const UINT8 type) static void P_NetArchiveThinkers(void) { const thinker_t *th; - UINT32 numsaved = 0; + UINT32 i; WRITEUINT32(save_p, ARCHIVEBLOCK_THINKERS); - // save off the current thinkers - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (i = 0; i < NUM_THINKERLISTS; i++) { - if (!(th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed - || th->function.acp1 == (actionf_p1)P_NullPrecipThinker)) - numsaved++; + UINT32 numsaved = 0; - if (th->function.acp1 == (actionf_p1)P_MobjThinker) + // save off the current thinkers + for (th = thlist[i].next; th != &thlist[i]; th = th->next) { - SaveMobjThinker(th, tc_mobj); - continue; - } -#ifdef PARANOIA - else if (th->function.acp1 == (actionf_p1)P_NullPrecipThinker); -#endif - else if (th->function.acp1 == (actionf_p1)T_MoveCeiling) - { - SaveCeilingThinker(th, tc_ceiling); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_CrushCeiling) - { - SaveCeilingThinker(th, tc_crushceiling); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_MoveFloor) - { - SaveFloormoveThinker(th, tc_floor); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_LightningFlash) - { - SaveLightflashThinker(th, tc_flash); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_StrobeFlash) - { - SaveStrobeThinker(th, tc_strobe); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_Glow) - { - SaveGlowThinker(th, tc_glow); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_FireFlicker) - { - SaveFireflickerThinker(th, tc_fireflicker); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_MoveElevator) - { - SaveElevatorThinker(th, tc_elevator); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_ContinuousFalling) - { - SaveSpecialLevelThinker(th, tc_continuousfalling); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_ThwompSector) - { - SaveSpecialLevelThinker(th, tc_thwomp); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_NoEnemiesSector) - { - SaveSpecialLevelThinker(th, tc_noenemies); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_EachTimeThinker) - { - SaveSpecialLevelThinker(th, tc_eachtime); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_RaiseSector) - { - SaveSpecialLevelThinker(th, tc_raisesector); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_CameraScanner) - { - SaveElevatorThinker(th, tc_camerascanner); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_Scroll) - { - SaveScrollThinker(th, tc_scroll); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_Friction) - { - SaveFrictionThinker(th, tc_friction); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_Pusher) - { - SavePusherThinker(th, tc_pusher); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_BounceCheese) - { - SaveSpecialLevelThinker(th, tc_bouncecheese); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_StartCrumble) - { - SaveElevatorThinker(th, tc_startcrumble); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_MarioBlock) - { - SaveSpecialLevelThinker(th, tc_marioblock); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_MarioBlockChecker) - { - SaveSpecialLevelThinker(th, tc_marioblockchecker); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_SpikeSector) - { - SaveSpecialLevelThinker(th, tc_spikesector); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_FloatSector) - { - SaveSpecialLevelThinker(th, tc_floatsector); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_BridgeThinker) - { - SaveSpecialLevelThinker(th, tc_bridgethinker); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_LaserFlash) - { - SaveLaserThinker(th, tc_laserflash); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_LightFade) - { - SaveLightlevelThinker(th, tc_lightfade); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_ExecutorDelay) - { - SaveExecutorThinker(th, tc_executor); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_Disappear) - { - SaveDisappearThinker(th, tc_disappear); - continue; - } + if (!(th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed + || th->function.acp1 == (actionf_p1)P_NullPrecipThinker)) + numsaved++; + + if (th->function.acp1 == (actionf_p1)P_MobjThinker) + { + SaveMobjThinker(th, tc_mobj); + continue; + } + #ifdef PARANOIA + else if (th->function.acp1 == (actionf_p1)P_NullPrecipThinker); + #endif + else if (th->function.acp1 == (actionf_p1)T_MoveCeiling) + { + SaveCeilingThinker(th, tc_ceiling); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_CrushCeiling) + { + SaveCeilingThinker(th, tc_crushceiling); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_MoveFloor) + { + SaveFloormoveThinker(th, tc_floor); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_LightningFlash) + { + SaveLightflashThinker(th, tc_flash); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_StrobeFlash) + { + SaveStrobeThinker(th, tc_strobe); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_Glow) + { + SaveGlowThinker(th, tc_glow); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_FireFlicker) + { + SaveFireflickerThinker(th, tc_fireflicker); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_MoveElevator) + { + SaveElevatorThinker(th, tc_elevator); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_ContinuousFalling) + { + SaveSpecialLevelThinker(th, tc_continuousfalling); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_ThwompSector) + { + SaveSpecialLevelThinker(th, tc_thwomp); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_NoEnemiesSector) + { + SaveSpecialLevelThinker(th, tc_noenemies); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_EachTimeThinker) + { + SaveSpecialLevelThinker(th, tc_eachtime); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_RaiseSector) + { + SaveSpecialLevelThinker(th, tc_raisesector); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_CameraScanner) + { + SaveElevatorThinker(th, tc_camerascanner); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_Scroll) + { + SaveScrollThinker(th, tc_scroll); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_Friction) + { + SaveFrictionThinker(th, tc_friction); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_Pusher) + { + SavePusherThinker(th, tc_pusher); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_BounceCheese) + { + SaveSpecialLevelThinker(th, tc_bouncecheese); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_StartCrumble) + { + SaveElevatorThinker(th, tc_startcrumble); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_MarioBlock) + { + SaveSpecialLevelThinker(th, tc_marioblock); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_MarioBlockChecker) + { + SaveSpecialLevelThinker(th, tc_marioblockchecker); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_SpikeSector) + { + SaveSpecialLevelThinker(th, tc_spikesector); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_FloatSector) + { + SaveSpecialLevelThinker(th, tc_floatsector); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_BridgeThinker) + { + SaveSpecialLevelThinker(th, tc_bridgethinker); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_LaserFlash) + { + SaveLaserThinker(th, tc_laserflash); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_LightFade) + { + SaveLightlevelThinker(th, tc_lightfade); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_ExecutorDelay) + { + SaveExecutorThinker(th, tc_executor); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_Disappear) + { + SaveDisappearThinker(th, tc_disappear); + continue; + } #ifdef POLYOBJECTS - else if (th->function.acp1 == (actionf_p1)T_PolyObjRotate) - { - SavePolyrotatetThinker(th, tc_polyrotate); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_PolyObjMove) - { - SavePolymoveThinker(th, tc_polymove); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_PolyObjWaypoint) - { - SavePolywaypointThinker(th, tc_polywaypoint); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_PolyDoorSlide) - { - SavePolyslidedoorThinker(th, tc_polyslidedoor); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_PolyDoorSwing) - { - SavePolyswingdoorThinker(th, tc_polyswingdoor); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_PolyObjFlag) - { - SavePolymoveThinker(th, tc_polyflag); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_PolyObjDisplace) - { - SavePolydisplaceThinker(th, tc_polydisplace); - continue; - } + else if (th->function.acp1 == (actionf_p1)T_PolyObjRotate) + { + SavePolyrotatetThinker(th, tc_polyrotate); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_PolyObjMove) + { + SavePolymoveThinker(th, tc_polymove); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_PolyObjWaypoint) + { + SavePolywaypointThinker(th, tc_polywaypoint); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_PolyDoorSlide) + { + SavePolyslidedoorThinker(th, tc_polyslidedoor); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_PolyDoorSwing) + { + SavePolyswingdoorThinker(th, tc_polyswingdoor); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_PolyObjFlag) + { + SavePolymoveThinker(th, tc_polyflag); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_PolyObjDisplace) + { + SavePolydisplaceThinker(th, tc_polydisplace); + continue; + } #endif #ifdef PARANOIA - else if (th->function.acv != P_RemoveThinkerDelayed) // wait garbage collection - I_Error("unknown thinker type %p", th->function.acp1); + else if (th->function.acv != P_RemoveThinkerDelayed) // wait garbage collection + I_Error("unknown thinker type %p", th->function.acp1); #endif + } + + CONS_Debug(DBG_NETPLAY, "%u thinkers saved\n", numsaved); + + WRITEUINT8(save_p, tc_end); } - - CONS_Debug(DBG_NETPLAY, "%u thinkers saved\n", numsaved); - - WRITEUINT8(save_p, tc_end); } // Now save the pointers, tracer and target, but at load time we must @@ -1899,11 +1912,8 @@ mobj_t *P_FindNewPosition(UINT32 oldposition) thinker_t *th; mobj_t *mobj; - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mobj = (mobj_t *)th; if (mobj->mobjnum == oldposition) return mobj; @@ -1936,12 +1946,26 @@ static inline player_t *LoadPlayer(UINT32 player) return &players[player]; } +#ifdef ESLOPE +static inline pslope_t *LoadSlope(UINT32 slopeid) +{ + pslope_t *p = slopelist; + if (slopeid > slopecount) return NULL; + do + { + if (p->id == slopeid) + return p; + } while ((p = p->next)); + return NULL; +} +#endif // ESLOPE + // // LoadMobjThinker // // Loads a mobj_t from a save game // -static void LoadMobjThinker(actionf_p1 thinker) +static thinker_t* LoadMobjThinker(actionf_p1 thinker) { thinker_t *next; mobj_t *mobj; @@ -1969,7 +1993,7 @@ static void LoadMobjThinker(actionf_p1 thinker) if (mapthings[spawnpointnum].type == 1705 || mapthings[spawnpointnum].type == 1713) // NiGHTS Hoop special case { P_SpawnHoopsAndRings(&mapthings[spawnpointnum]); - return; + return NULL; } mobj = Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL); @@ -2173,12 +2197,12 @@ static void LoadMobjThinker(actionf_p1 thinker) mobj->player->viewz = mobj->player->mo->z + mobj->player->viewheight; } - P_AddThinker(&mobj->thinker); - if (diff2 & MD2_WAYPOINTCAP) P_SetTarget(&waypointcap, mobj); mobj->info = (mobjinfo_t *)next; // temporarily, set when leave this function + + return &mobj->thinker; } // @@ -2192,7 +2216,7 @@ static void LoadMobjThinker(actionf_p1 thinker) // 2 - Ceiling Only // 3 - Both // -static void LoadSpecialLevelThinker(actionf_p1 thinker, UINT8 floorOrCeiling) +static thinker_t* LoadSpecialLevelThinker(actionf_p1 thinker, UINT8 floorOrCeiling) { levelspecthink_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); size_t i; @@ -2213,7 +2237,7 @@ static void LoadSpecialLevelThinker(actionf_p1 thinker, UINT8 floorOrCeiling) ht->sector->floordata = ht; } - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2221,7 +2245,7 @@ static void LoadSpecialLevelThinker(actionf_p1 thinker, UINT8 floorOrCeiling) // // Loads a ceiling_t from a save game // -static void LoadCeilingThinker(actionf_p1 thinker) +static thinker_t* LoadCeilingThinker(actionf_p1 thinker) { ceiling_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2242,7 +2266,7 @@ static void LoadCeilingThinker(actionf_p1 thinker) ht->sourceline = READFIXED(save_p); if (ht->sector) ht->sector->ceilingdata = ht; - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2250,7 +2274,7 @@ static void LoadCeilingThinker(actionf_p1 thinker) // // Loads a floormove_t from a save game // -static void LoadFloormoveThinker(actionf_p1 thinker) +static thinker_t* LoadFloormoveThinker(actionf_p1 thinker) { floormove_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2266,7 +2290,7 @@ static void LoadFloormoveThinker(actionf_p1 thinker) ht->delaytimer = READFIXED(save_p); if (ht->sector) ht->sector->floordata = ht; - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2274,7 +2298,7 @@ static void LoadFloormoveThinker(actionf_p1 thinker) // // Loads a lightflash_t from a save game // -static void LoadLightflashThinker(actionf_p1 thinker) +static thinker_t* LoadLightflashThinker(actionf_p1 thinker) { lightflash_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2283,7 +2307,7 @@ static void LoadLightflashThinker(actionf_p1 thinker) ht->minlight = READINT32(save_p); if (ht->sector) ht->sector->lightingdata = ht; - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2291,7 +2315,7 @@ static void LoadLightflashThinker(actionf_p1 thinker) // // Loads a strobe_t from a save game // -static void LoadStrobeThinker(actionf_p1 thinker) +static thinker_t* LoadStrobeThinker(actionf_p1 thinker) { strobe_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2303,7 +2327,7 @@ static void LoadStrobeThinker(actionf_p1 thinker) ht->brighttime = READINT32(save_p); if (ht->sector) ht->sector->lightingdata = ht; - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2311,7 +2335,7 @@ static void LoadStrobeThinker(actionf_p1 thinker) // // Loads a glow_t from a save game // -static void LoadGlowThinker(actionf_p1 thinker) +static thinker_t* LoadGlowThinker(actionf_p1 thinker) { glow_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2322,14 +2346,14 @@ static void LoadGlowThinker(actionf_p1 thinker) ht->speed = READINT32(save_p); if (ht->sector) ht->sector->lightingdata = ht; - P_AddThinker(&ht->thinker); + return &ht->thinker; } // // LoadFireflickerThinker // // Loads a fireflicker_t from a save game // -static void LoadFireflickerThinker(actionf_p1 thinker) +static thinker_t* LoadFireflickerThinker(actionf_p1 thinker) { fireflicker_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2340,14 +2364,14 @@ static void LoadFireflickerThinker(actionf_p1 thinker) ht->minlight = READINT32(save_p); if (ht->sector) ht->sector->lightingdata = ht; - P_AddThinker(&ht->thinker); + return &ht->thinker; } // // LoadElevatorThinker // // Loads a elevator_t from a save game // -static void LoadElevatorThinker(actionf_p1 thinker, UINT8 floorOrCeiling) +static thinker_t* LoadElevatorThinker(actionf_p1 thinker, UINT8 floorOrCeiling) { elevator_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2377,7 +2401,7 @@ static void LoadElevatorThinker(actionf_p1 thinker, UINT8 floorOrCeiling) ht->sector->floordata = ht; } - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2385,7 +2409,7 @@ static void LoadElevatorThinker(actionf_p1 thinker, UINT8 floorOrCeiling) // // Loads a scroll_t from a save game // -static void LoadScrollThinker(actionf_p1 thinker) +static thinker_t* LoadScrollThinker(actionf_p1 thinker) { scroll_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2399,7 +2423,7 @@ static void LoadScrollThinker(actionf_p1 thinker) ht->accel = READINT32(save_p); ht->exclusive = READINT32(save_p); ht->type = READUINT8(save_p); - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2407,7 +2431,7 @@ static void LoadScrollThinker(actionf_p1 thinker) // // Loads a friction_t from a save game // -static inline void LoadFrictionThinker(actionf_p1 thinker) +static inline thinker_t* LoadFrictionThinker(actionf_p1 thinker) { friction_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2416,7 +2440,7 @@ static inline void LoadFrictionThinker(actionf_p1 thinker) ht->affectee = READINT32(save_p); ht->referrer = READINT32(save_p); ht->roverfriction = READUINT8(save_p); - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2424,7 +2448,7 @@ static inline void LoadFrictionThinker(actionf_p1 thinker) // // Loads a pusher_t from a save game // -static void LoadPusherThinker(actionf_p1 thinker) +static thinker_t* LoadPusherThinker(actionf_p1 thinker) { pusher_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2442,7 +2466,7 @@ static void LoadPusherThinker(actionf_p1 thinker) ht->exclusive = READINT32(save_p); ht->slider = READINT32(save_p); ht->source = P_GetPushThing(ht->affectee); - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2450,7 +2474,7 @@ static void LoadPusherThinker(actionf_p1 thinker) // // Loads a laserthink_t from a save game // -static inline void LoadLaserThinker(actionf_p1 thinker) +static inline thinker_t* LoadLaserThinker(actionf_p1 thinker) { laserthink_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ffloor_t *rover = NULL; @@ -2462,7 +2486,7 @@ static inline void LoadLaserThinker(actionf_p1 thinker) if (rover->secnum == (size_t)(ht->sec - sectors) && rover->master == ht->sourceline) ht->ffloor = rover; - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2470,7 +2494,7 @@ static inline void LoadLaserThinker(actionf_p1 thinker) // // Loads a lightlevel_t from a save game // -static inline void LoadLightlevelThinker(actionf_p1 thinker) +static inline thinker_t* LoadLightlevelThinker(actionf_p1 thinker) { lightlevel_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2479,7 +2503,7 @@ static inline void LoadLightlevelThinker(actionf_p1 thinker) ht->speed = READINT32(save_p); if (ht->sector) ht->sector->lightingdata = ht; - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2487,7 +2511,7 @@ static inline void LoadLightlevelThinker(actionf_p1 thinker) // // Loads a executor_t from a save game // -static inline void LoadExecutorThinker(actionf_p1 thinker) +static inline thinker_t* LoadExecutorThinker(actionf_p1 thinker) { executor_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2495,7 +2519,7 @@ static inline void LoadExecutorThinker(actionf_p1 thinker) ht->caller = LoadMobj(READUINT32(save_p)); ht->sector = LoadSector(READUINT32(save_p)); ht->timer = READINT32(save_p); - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2503,7 +2527,7 @@ static inline void LoadExecutorThinker(actionf_p1 thinker) // // Loads a disappear_t thinker // -static inline void LoadDisappearThinker(actionf_p1 thinker) +static inline thinker_t* LoadDisappearThinker(actionf_p1 thinker) { disappear_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2514,7 +2538,7 @@ static inline void LoadDisappearThinker(actionf_p1 thinker) ht->affectee = READINT32(save_p); ht->sourceline = READINT32(save_p); ht->exists = READINT32(save_p); - P_AddThinker(&ht->thinker); + return &ht->thinker; } #ifdef POLYOBJECTS @@ -2524,14 +2548,14 @@ static inline void LoadDisappearThinker(actionf_p1 thinker) // // Loads a polyrotate_t thinker // -static inline void LoadPolyrotatetThinker(actionf_p1 thinker) +static inline thinker_t* LoadPolyrotatetThinker(actionf_p1 thinker) { polyrotate_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; ht->polyObjNum = READINT32(save_p); ht->speed = READINT32(save_p); ht->distance = READINT32(save_p); - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2539,7 +2563,7 @@ static inline void LoadPolyrotatetThinker(actionf_p1 thinker) // // Loads a polymovet_t thinker // -static void LoadPolymoveThinker(actionf_p1 thinker) +static thinker_t* LoadPolymoveThinker(actionf_p1 thinker) { polymove_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2549,7 +2573,7 @@ static void LoadPolymoveThinker(actionf_p1 thinker) ht->momy = READFIXED(save_p); ht->distance = READINT32(save_p); ht->angle = READANGLE(save_p); - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2557,7 +2581,7 @@ static void LoadPolymoveThinker(actionf_p1 thinker) // // Loads a polywaypoint_t thinker // -static inline void LoadPolywaypointThinker(actionf_p1 thinker) +static inline thinker_t* LoadPolywaypointThinker(actionf_p1 thinker) { polywaypoint_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2573,7 +2597,7 @@ static inline void LoadPolywaypointThinker(actionf_p1 thinker) ht->diffx = READFIXED(save_p); ht->diffy = READFIXED(save_p); ht->diffz = READFIXED(save_p); - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2581,7 +2605,7 @@ static inline void LoadPolywaypointThinker(actionf_p1 thinker) // // loads a polyslidedoor_t thinker // -static inline void LoadPolyslidedoorThinker(actionf_p1 thinker) +static inline thinker_t* LoadPolyslidedoorThinker(actionf_p1 thinker) { polyslidedoor_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2598,7 +2622,7 @@ static inline void LoadPolyslidedoorThinker(actionf_p1 thinker) ht->momx = READFIXED(save_p); ht->momy = READFIXED(save_p); ht->closing = READUINT8(save_p); - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2606,7 +2630,7 @@ static inline void LoadPolyslidedoorThinker(actionf_p1 thinker) // // Loads a polyswingdoor_t thinker // -static inline void LoadPolyswingdoorThinker(actionf_p1 thinker) +static inline thinker_t* LoadPolyswingdoorThinker(actionf_p1 thinker) { polyswingdoor_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2618,7 +2642,7 @@ static inline void LoadPolyswingdoorThinker(actionf_p1 thinker) ht->initDistance = READINT32(save_p); ht->distance = READINT32(save_p); ht->closing = READUINT8(save_p); - P_AddThinker(&ht->thinker); + return &ht->thinker; } // @@ -2626,7 +2650,7 @@ static inline void LoadPolyswingdoorThinker(actionf_p1 thinker) // // Loads a polydisplace_t thinker // -static inline void LoadPolydisplaceThinker(actionf_p1 thinker) +static inline thinker_t* LoadPolydisplaceThinker(actionf_p1 thinker) { polydisplace_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2635,7 +2659,7 @@ static inline void LoadPolydisplaceThinker(actionf_p1 thinker) ht->dx = READFIXED(save_p); ht->dy = READFIXED(save_p); ht->oldHeights = READFIXED(save_p); - P_AddThinker(&ht->thinker); + return &ht->thinker; } #endif @@ -2668,15 +2692,18 @@ static void P_NetUnArchiveThinkers(void) I_Error("Bad $$$.sav at archive block Thinkers"); // remove all the current thinkers - currentthinker = thinkercap.next; - for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = next) + for (i = 0; i < NUM_THINKERLISTS; i++) { - next = currentthinker->next; + currentthinker = thlist[i].next; + for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; currentthinker = next) + { + next = currentthinker->next; - if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) - P_RemoveSavegameMobj((mobj_t *)currentthinker); // item isn't saved, don't remove it - else - Z_Free(currentthinker); + if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) + P_RemoveSavegameMobj((mobj_t *)currentthinker); // item isn't saved, don't remove it + else + Z_Free(currentthinker); + } } // we don't want the removed mobjs to come back @@ -2690,182 +2717,188 @@ static void P_NetUnArchiveThinkers(void) } // read in saved thinkers - for (;;) + for (i = 0; i < NUM_THINKERLISTS; i++) { - tclass = READUINT8(save_p); - - if (tclass == tc_end) - break; // leave the saved thinker reading loop - numloaded++; - - switch (tclass) + for (;;) { - case tc_mobj: - LoadMobjThinker((actionf_p1)P_MobjThinker); - break; + thinker_t* th; + tclass = READUINT8(save_p); - case tc_ceiling: - LoadCeilingThinker((actionf_p1)T_MoveCeiling); - break; + if (tclass == tc_end) + break; // leave the saved thinker reading loop + numloaded++; - case tc_crushceiling: - LoadCeilingThinker((actionf_p1)T_CrushCeiling); - break; - - case tc_floor: - LoadFloormoveThinker((actionf_p1)T_MoveFloor); - break; - - case tc_flash: - LoadLightflashThinker((actionf_p1)T_LightningFlash); - break; - - case tc_strobe: - LoadStrobeThinker((actionf_p1)T_StrobeFlash); - break; - - case tc_glow: - LoadGlowThinker((actionf_p1)T_Glow); - break; - - case tc_fireflicker: - LoadFireflickerThinker((actionf_p1)T_FireFlicker); - break; - - case tc_elevator: - LoadElevatorThinker((actionf_p1)T_MoveElevator, 3); - break; - - case tc_continuousfalling: - LoadSpecialLevelThinker((actionf_p1)T_ContinuousFalling, 3); - break; - - case tc_thwomp: - LoadSpecialLevelThinker((actionf_p1)T_ThwompSector, 3); - break; - - case tc_noenemies: - LoadSpecialLevelThinker((actionf_p1)T_NoEnemiesSector, 0); - break; - - case tc_eachtime: - LoadSpecialLevelThinker((actionf_p1)T_EachTimeThinker, 0); - break; - - case tc_raisesector: - LoadSpecialLevelThinker((actionf_p1)T_RaiseSector, 0); - break; - - /// \todo rewrite all the code that uses an elevator_t but isn't an elevator - /// \note working on it! - case tc_camerascanner: - LoadElevatorThinker((actionf_p1)T_CameraScanner, 0); - break; - - case tc_bouncecheese: - LoadSpecialLevelThinker((actionf_p1)T_BounceCheese, 2); - break; - - case tc_startcrumble: - LoadElevatorThinker((actionf_p1)T_StartCrumble, 1); - break; - - case tc_marioblock: - LoadSpecialLevelThinker((actionf_p1)T_MarioBlock, 3); - break; - - case tc_marioblockchecker: - LoadSpecialLevelThinker((actionf_p1)T_MarioBlockChecker, 0); - break; - - case tc_spikesector: - LoadSpecialLevelThinker((actionf_p1)T_SpikeSector, 0); - break; - - case tc_floatsector: - LoadSpecialLevelThinker((actionf_p1)T_FloatSector, 0); - break; - - case tc_bridgethinker: - LoadSpecialLevelThinker((actionf_p1)T_BridgeThinker, 3); - break; - - case tc_laserflash: - LoadLaserThinker((actionf_p1)T_LaserFlash); - break; - - case tc_lightfade: - LoadLightlevelThinker((actionf_p1)T_LightFade); - break; - - case tc_executor: - LoadExecutorThinker((actionf_p1)T_ExecutorDelay); - restoreNum = true; - break; - - case tc_disappear: - LoadDisappearThinker((actionf_p1)T_Disappear); - break; -#ifdef POLYOBJECTS - case tc_polyrotate: - LoadPolyrotatetThinker((actionf_p1)T_PolyObjRotate); - break; - - case tc_polymove: - LoadPolymoveThinker((actionf_p1)T_PolyObjMove); - break; - - case tc_polywaypoint: - LoadPolywaypointThinker((actionf_p1)T_PolyObjWaypoint); - break; - - case tc_polyslidedoor: - LoadPolyslidedoorThinker((actionf_p1)T_PolyDoorSlide); - break; - - case tc_polyswingdoor: - LoadPolyswingdoorThinker((actionf_p1)T_PolyDoorSwing); - break; - - case tc_polyflag: - LoadPolymoveThinker((actionf_p1)T_PolyObjFlag); - break; - - case tc_polydisplace: - LoadPolydisplaceThinker((actionf_p1)T_PolyObjDisplace); - break; -#endif - case tc_scroll: - LoadScrollThinker((actionf_p1)T_Scroll); - break; - - case tc_friction: - LoadFrictionThinker((actionf_p1)T_Friction); - break; - - case tc_pusher: - LoadPusherThinker((actionf_p1)T_Pusher); - break; - - default: - I_Error("P_UnarchiveSpecials: Unknown tclass %d in savegame", tclass); - } - } - - CONS_Debug(DBG_NETPLAY, "%u thinkers loaded\n", numloaded); - - if (restoreNum) - { - executor_t *delay = NULL; - UINT32 mobjnum; - for (currentthinker = thinkercap.next; currentthinker != &thinkercap; - currentthinker = currentthinker->next) - { - if (currentthinker->function.acp1 == (actionf_p1)T_ExecutorDelay) + switch (tclass) { - delay = (void *)currentthinker; - if ((mobjnum = (UINT32)(size_t)delay->caller)) - delay->caller = P_FindNewPosition(mobjnum); + case tc_mobj: + th = LoadMobjThinker((actionf_p1)P_MobjThinker); + break; + + case tc_ceiling: + th = LoadCeilingThinker((actionf_p1)T_MoveCeiling); + break; + + case tc_crushceiling: + th = LoadCeilingThinker((actionf_p1)T_CrushCeiling); + break; + + case tc_floor: + th = LoadFloormoveThinker((actionf_p1)T_MoveFloor); + break; + + case tc_flash: + th = LoadLightflashThinker((actionf_p1)T_LightningFlash); + break; + + case tc_strobe: + th = LoadStrobeThinker((actionf_p1)T_StrobeFlash); + break; + + case tc_glow: + th = LoadGlowThinker((actionf_p1)T_Glow); + break; + + case tc_fireflicker: + th = LoadFireflickerThinker((actionf_p1)T_FireFlicker); + break; + + case tc_elevator: + th = LoadElevatorThinker((actionf_p1)T_MoveElevator, 3); + break; + + case tc_continuousfalling: + th = LoadSpecialLevelThinker((actionf_p1)T_ContinuousFalling, 3); + break; + + case tc_thwomp: + th = LoadSpecialLevelThinker((actionf_p1)T_ThwompSector, 3); + break; + + case tc_noenemies: + th = LoadSpecialLevelThinker((actionf_p1)T_NoEnemiesSector, 0); + break; + + case tc_eachtime: + th = LoadSpecialLevelThinker((actionf_p1)T_EachTimeThinker, 0); + break; + + case tc_raisesector: + th = LoadSpecialLevelThinker((actionf_p1)T_RaiseSector, 0); + break; + + /// \todo rewrite all the code that uses an elevator_t but isn't an elevator + /// \note working on it! + case tc_camerascanner: + th = LoadElevatorThinker((actionf_p1)T_CameraScanner, 0); + break; + + case tc_bouncecheese: + th = LoadSpecialLevelThinker((actionf_p1)T_BounceCheese, 2); + break; + + case tc_startcrumble: + th = LoadElevatorThinker((actionf_p1)T_StartCrumble, 1); + break; + + case tc_marioblock: + th = LoadSpecialLevelThinker((actionf_p1)T_MarioBlock, 3); + break; + + case tc_marioblockchecker: + th = LoadSpecialLevelThinker((actionf_p1)T_MarioBlockChecker, 0); + break; + + case tc_spikesector: + th = LoadSpecialLevelThinker((actionf_p1)T_SpikeSector, 0); + break; + + case tc_floatsector: + th = LoadSpecialLevelThinker((actionf_p1)T_FloatSector, 0); + break; + + case tc_bridgethinker: + th = LoadSpecialLevelThinker((actionf_p1)T_BridgeThinker, 3); + break; + + case tc_laserflash: + th = LoadLaserThinker((actionf_p1)T_LaserFlash); + break; + + case tc_lightfade: + th = LoadLightlevelThinker((actionf_p1)T_LightFade); + break; + + case tc_executor: + th = LoadExecutorThinker((actionf_p1)T_ExecutorDelay); + restoreNum = true; + break; + + case tc_disappear: + LoadDisappearThinker((actionf_p1)T_Disappear); + break; +#ifdef POLYOBJECTS + case tc_polyrotate: + th = LoadPolyrotatetThinker((actionf_p1)T_PolyObjRotate); + break; + + case tc_polymove: + th = LoadPolymoveThinker((actionf_p1)T_PolyObjMove); + break; + + case tc_polywaypoint: + th = LoadPolywaypointThinker((actionf_p1)T_PolyObjWaypoint); + break; + + case tc_polyslidedoor: + th = LoadPolyslidedoorThinker((actionf_p1)T_PolyDoorSlide); + break; + + case tc_polyswingdoor: + th = LoadPolyswingdoorThinker((actionf_p1)T_PolyDoorSwing); + break; + + case tc_polyflag: + th = LoadPolymoveThinker((actionf_p1)T_PolyObjFlag); + break; + + case tc_polydisplace: + LoadPolydisplaceThinker((actionf_p1)T_PolyObjDisplace); + break; +#endif + case tc_scroll: + th = LoadScrollThinker((actionf_p1)T_Scroll); + break; + + case tc_friction: + th = LoadFrictionThinker((actionf_p1)T_Friction); + break; + + case tc_pusher: + th = LoadPusherThinker((actionf_p1)T_Pusher); + break; + + default: + I_Error("P_UnarchiveSpecials: Unknown tclass %d in savegame", tclass); + } + if (th) + P_AddThinker(i, th); + } + + CONS_Debug(DBG_NETPLAY, "%u thinkers loaded\n", numloaded); + + if (restoreNum) + { + executor_t *delay = NULL; + UINT32 mobjnum; + for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; + currentthinker = currentthinker->next) + { + if (currentthinker->function.acp1 == (actionf_p1)T_ExecutorDelay) + { + delay = (void *)currentthinker; + if ((mobjnum = (UINT32)(size_t)delay->caller)) + delay->caller = P_FindNewPosition(mobjnum); + } } } } @@ -2974,14 +3007,11 @@ static inline void P_FinishMobjs(void) mobj_t *mobj; // put info field there real value - for (currentthinker = thinkercap.next; currentthinker != &thinkercap; + for (currentthinker = thlist[THINK_MOBJ].next; currentthinker != &thlist[THINK_MOBJ]; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) - { - mobj = (mobj_t *)currentthinker; - mobj->info = &mobjinfo[mobj->type]; - } + mobj = (mobj_t *)currentthinker; + mobj->info = &mobjinfo[mobj->type]; } } @@ -2992,72 +3022,69 @@ static void P_RelinkPointers(void) UINT32 temp; // use info field (value = oldposition) to relink mobjs - for (currentthinker = thinkercap.next; currentthinker != &thinkercap; + for (currentthinker = thlist[THINK_MOBJ].next; currentthinker != &thlist[THINK_MOBJ]; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) + mobj = (mobj_t *)currentthinker; + + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; + + if (mobj->tracer) { - mobj = (mobj_t *)currentthinker; - - if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) - continue; - - if (mobj->tracer) - { - temp = (UINT32)(size_t)mobj->tracer; - mobj->tracer = NULL; - if (!P_SetTarget(&mobj->tracer, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "tracer not found on %d\n", mobj->type); - } - if (mobj->target) - { - temp = (UINT32)(size_t)mobj->target; - mobj->target = NULL; - if (!P_SetTarget(&mobj->target, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "target not found on %d\n", mobj->type); - } - if (mobj->hnext) - { - temp = (UINT32)(size_t)mobj->hnext; - mobj->hnext = NULL; - if (!(mobj->hnext = P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "hnext not found on %d\n", mobj->type); - } - if (mobj->hprev) - { - temp = (UINT32)(size_t)mobj->hprev; - mobj->hprev = NULL; - if (!(mobj->hprev = P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "hprev not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->capsule) - { - temp = (UINT32)(size_t)mobj->player->capsule; - mobj->player->capsule = NULL; - if (!P_SetTarget(&mobj->player->capsule, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "capsule not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->axis1) - { - temp = (UINT32)(size_t)mobj->player->axis1; - mobj->player->axis1 = NULL; - if (!P_SetTarget(&mobj->player->axis1, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "axis1 not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->axis2) - { - temp = (UINT32)(size_t)mobj->player->axis2; - mobj->player->axis2 = NULL; - if (!P_SetTarget(&mobj->player->axis2, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "axis2 not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->awayviewmobj) - { - temp = (UINT32)(size_t)mobj->player->awayviewmobj; - mobj->player->awayviewmobj = NULL; - if (!P_SetTarget(&mobj->player->awayviewmobj, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "awayviewmobj not found on %d\n", mobj->type); - } + temp = (UINT32)(size_t)mobj->tracer; + mobj->tracer = NULL; + if (!P_SetTarget(&mobj->tracer, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "tracer not found on %d\n", mobj->type); + } + if (mobj->target) + { + temp = (UINT32)(size_t)mobj->target; + mobj->target = NULL; + if (!P_SetTarget(&mobj->target, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "target not found on %d\n", mobj->type); + } + if (mobj->hnext) + { + temp = (UINT32)(size_t)mobj->hnext; + mobj->hnext = NULL; + if (!(mobj->hnext = P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "hnext not found on %d\n", mobj->type); + } + if (mobj->hprev) + { + temp = (UINT32)(size_t)mobj->hprev; + mobj->hprev = NULL; + if (!(mobj->hprev = P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "hprev not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->capsule) + { + temp = (UINT32)(size_t)mobj->player->capsule; + mobj->player->capsule = NULL; + if (!P_SetTarget(&mobj->player->capsule, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "capsule not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->axis1) + { + temp = (UINT32)(size_t)mobj->player->axis1; + mobj->player->axis1 = NULL; + if (!P_SetTarget(&mobj->player->axis1, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "axis1 not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->axis2) + { + temp = (UINT32)(size_t)mobj->player->axis2; + mobj->player->axis2 = NULL; + if (!P_SetTarget(&mobj->player->axis2, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "axis2 not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->awayviewmobj) + { + temp = (UINT32)(size_t)mobj->player->awayviewmobj; + mobj->player->awayviewmobj = NULL; + if (!P_SetTarget(&mobj->player->awayviewmobj, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "awayviewmobj not found on %d\n", mobj->type); } } } @@ -3427,18 +3454,13 @@ void P_SaveNetGame(void) P_NetArchiveMisc(); // Assign the mobjnumber for pointer tracking - if (gamestate == GS_LEVEL) + //if (gamestate == GS_LEVEL) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 == (actionf_p1)P_MobjThinker) - { - mobj = (mobj_t *)th; - if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) - continue; - mobj->mobjnum = i++; - } - } + mobj = (mobj_t *)th; + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; + mobj->mobjnum = i++; } P_NetArchivePlayers(); diff --git a/src/p_setup.c b/src/p_setup.c index bf13971b3..ed2fd35f9 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -832,12 +832,9 @@ void P_ReloadRings(void) mapthing_t *hoopsToRespawn[4096]; mapthing_t *mt = mapthings; - // scan the thinkers to find rings/wings/hoops to unset - for (th = thinkercap.next; th != &thinkercap; th = th->next) + // scan the thinkers to find rings/spheres/hoops to unset + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo = (mobj_t *)th; if (mo->type == MT_HOOPCENTER) @@ -2414,11 +2411,8 @@ void P_LoadThingsOnly(void) mobj_t *mo; thinker_t *think; - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 != (actionf_p1)P_MobjThinker) - continue; // not a mobj thinker - mo = (mobj_t *)think; if (mo) @@ -3067,7 +3061,7 @@ boolean P_SetupLevel(boolean skipprecip) } #ifdef ESLOPE - P_ResetDynamicSlopes(); + P_ResetDynamicSlopes(fromnetsave); #endif P_LoadThings(); diff --git a/src/p_slopes.c b/src/p_slopes.c index 76af7bfde..fc690972d 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -25,68 +25,66 @@ #ifdef ESLOPE -static pslope_t *slopelist = NULL; -static UINT16 slopecount = 0; +pslope_t *slopelist = NULL; +UINT16 slopecount = 0; // Calculate line normal void P_CalculateSlopeNormal(pslope_t *slope) { slope->normal.z = FINECOSINE(slope->zangle>>ANGLETOFINESHIFT); - slope->normal.x = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), -slope->d.x); - slope->normal.y = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), -slope->d.y); + slope->normal.x = FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.x); + slope->normal.y = FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.y); } -// With a vertex slope that has its vertices set, configure relevant slope info -static void P_ReconfigureVertexSlope(pslope_t *slope) +/// Setup slope via 3 vertexes. +static void ReconfigureViaVertexes (pslope_t *slope, const vector3_t v1, const vector3_t v2, const vector3_t v3) { vector3_t vec1, vec2; - // Set slope normal - vec1.x = (slope->vertices[1]->x - slope->vertices[0]->x) << FRACBITS; - vec1.y = (slope->vertices[1]->y - slope->vertices[0]->y) << FRACBITS; - vec1.z = (slope->vertices[1]->z - slope->vertices[0]->z) << FRACBITS; + // Set origin. + FV3_Copy(&slope->o, &v1); - vec2.x = (slope->vertices[2]->x - slope->vertices[0]->x) << FRACBITS; - vec2.y = (slope->vertices[2]->y - slope->vertices[0]->y) << FRACBITS; - vec2.z = (slope->vertices[2]->z - slope->vertices[0]->z) << FRACBITS; + // Get slope's normal. + FV3_SubEx(&v2, &v1, &vec1); + FV3_SubEx(&v3, &v1, &vec2); - // ugggggggh fixed-point maaaaaaath - slope->extent = max( - max(max(abs(vec1.x), abs(vec1.y)), abs(vec1.z)), - max(max(abs(vec2.x), abs(vec2.y)), abs(vec2.z)) - ) >> (FRACBITS+5); - vec1.x /= slope->extent; - vec1.y /= slope->extent; - vec1.z /= slope->extent; - vec2.x /= slope->extent; - vec2.y /= slope->extent; - vec2.z /= slope->extent; + // Set some defaults for a non-sloped "slope" + if (vec1.z == 0 && vec2.z == 0) + { + /// \todo Fix fully flat cases. - FV3_Cross(&vec1, &vec2, &slope->normal); - - slope->extent = R_PointToDist2(0, 0, R_PointToDist2(0, 0, slope->normal.x, slope->normal.y), slope->normal.z); - if (slope->normal.z < 0) - slope->extent = -slope->extent; - - slope->normal.x = FixedDiv(slope->normal.x, slope->extent); - slope->normal.y = FixedDiv(slope->normal.y, slope->extent); - slope->normal.z = FixedDiv(slope->normal.z, slope->extent); - - // Set origin - slope->o.x = slope->vertices[0]->x << FRACBITS; - slope->o.y = slope->vertices[0]->y << FRACBITS; - slope->o.z = slope->vertices[0]->z << FRACBITS; - - if (slope->normal.x == 0 && slope->normal.y == 0) { // Set some defaults for a non-sloped "slope" slope->zangle = slope->xydirection = 0; slope->zdelta = slope->d.x = slope->d.y = 0; - } else { + } + else + { + /// \note Using fixed point for vectorial products easily leads to overflows so we work around by downscaling them. + fixed_t m = max( + max(max(abs(vec1.x), abs(vec1.y)), abs(vec1.z)), + max(max(abs(vec2.x), abs(vec2.y)), abs(vec2.z)) + ) >> 5; // shifting right by 5 is good enough. + + FV3_Cross( + FV3_Divide(&vec1, m), + FV3_Divide(&vec2, m), + &slope->normal + ); + + // NOTE: FV3_Magnitude() doesn't work properly in some cases, and chaining FixedHypot() seems to give worse results. + m = R_PointToDist2(0, 0, R_PointToDist2(0, 0, slope->normal.x, slope->normal.y), slope->normal.z); + + // Invert normal if it's facing down. + if (slope->normal.z < 0) + m = -m; + + FV3_Divide(&slope->normal, m); + // Get direction vector - slope->extent = R_PointToDist2(0, 0, slope->normal.x, slope->normal.y); - slope->d.x = -FixedDiv(slope->normal.x, slope->extent); - slope->d.y = -FixedDiv(slope->normal.y, slope->extent); + m = FixedHypot(slope->normal.x, slope->normal.y); + slope->d.x = -FixedDiv(slope->normal.x, m); + slope->d.y = -FixedDiv(slope->normal.y, m); // Z delta - slope->zdelta = FixedDiv(slope->extent, slope->normal.z); + slope->zdelta = FixedDiv(m, slope->normal.z); // Get angles slope->xydirection = R_PointToAngle2(0, 0, slope->d.x, slope->d.y)+ANGLE_180; @@ -94,88 +92,95 @@ static void P_ReconfigureVertexSlope(pslope_t *slope) } } -// Recalculate dynamic slopes -void P_RunDynamicSlopes(void) { - pslope_t *slope; +/// Recalculate dynamic slopes. +void T_DynamicSlopeLine (dynplanethink_t* th) +{ + pslope_t* slope = th->slope; + line_t* srcline = th->sourceline; - for (slope = slopelist; slope; slope = slope->next) { - fixed_t zdelta; + fixed_t zdelta; - if (slope->flags & SL_NODYNAMIC) - continue; + switch(th->type) { + case DP_FRONTFLOOR: + zdelta = srcline->backsector->floorheight - srcline->frontsector->floorheight; + slope->o.z = srcline->frontsector->floorheight; + break; - switch(slope->refpos) { - case 1: // front floor - zdelta = slope->sourceline->backsector->floorheight - slope->sourceline->frontsector->floorheight; - slope->o.z = slope->sourceline->frontsector->floorheight; - break; - case 2: // front ceiling - zdelta = slope->sourceline->backsector->ceilingheight - slope->sourceline->frontsector->ceilingheight; - slope->o.z = slope->sourceline->frontsector->ceilingheight; - break; - case 3: // back floor - zdelta = slope->sourceline->frontsector->floorheight - slope->sourceline->backsector->floorheight; - slope->o.z = slope->sourceline->backsector->floorheight; - break; - case 4: // back ceiling - zdelta = slope->sourceline->frontsector->ceilingheight - slope->sourceline->backsector->ceilingheight; - slope->o.z = slope->sourceline->backsector->ceilingheight; - break; - case 5: // vertices - { - mapthing_t *mt; - size_t i; - INT32 l; - line_t *line; + case DP_FRONTCEIL: + zdelta = srcline->backsector->ceilingheight - srcline->frontsector->ceilingheight; + slope->o.z = srcline->frontsector->ceilingheight; + break; - for (i = 0; i < 3; i++) { - mt = slope->vertices[i]; - l = P_FindSpecialLineFromTag(799, mt->angle, -1); - if (l != -1) { - line = &lines[l]; - mt->z = line->frontsector->floorheight >> FRACBITS; - } - } + case DP_BACKFLOOR: + zdelta = srcline->frontsector->floorheight - srcline->backsector->floorheight; + slope->o.z = srcline->backsector->floorheight; + break; - P_ReconfigureVertexSlope(slope); - } - continue; // TODO + case DP_BACKCEIL: + zdelta = srcline->frontsector->ceilingheight - srcline->backsector->ceilingheight; + slope->o.z = srcline->backsector->ceilingheight; + break; - default: - I_Error("P_RunDynamicSlopes: slope has invalid type!"); - } + default: + return; + } - if (slope->zdelta != FixedDiv(zdelta, slope->extent)) { - slope->zdelta = FixedDiv(zdelta, slope->extent); - slope->zangle = R_PointToAngle2(0, 0, slope->extent, -zdelta); - P_CalculateSlopeNormal(slope); - } + if (slope->zdelta != FixedDiv(zdelta, th->extent)) { + slope->zdelta = FixedDiv(zdelta, th->extent); + slope->zangle = R_PointToAngle2(0, 0, th->extent, -zdelta); + P_CalculateSlopeNormal(slope); } } -// -// P_MakeSlope -// -// Alocates and fill the contents of a slope structure. -// -static pslope_t *P_MakeSlope(const vector3_t *o, const vector2_t *d, - const fixed_t zdelta, UINT8 flags) +/// Mapthing-defined +void T_DynamicSlopeVert (dynplanethink_t* th) { - pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL); - memset(ret, 0, sizeof(*ret)); + pslope_t* slope = th->slope; - ret->o.x = o->x; - ret->o.y = o->y; - ret->o.z = o->z; + size_t i; + INT32 l; - ret->d.x = d->x; - ret->d.y = d->y; + for (i = 0; i < 3; i++) { + l = P_FindSpecialLineFromTag(799, th->tags[i], -1); + if (l != -1) { + th->vex[i].z = lines[l].frontsector->floorheight; + } + else + th->vex[i].z = 0; + } - ret->zdelta = zdelta; + ReconfigureViaVertexes(slope, th->vex[0], th->vex[1], th->vex[2]); +} +static inline void P_AddDynSlopeThinker (pslope_t* slope, dynplanetype_t type, line_t* sourceline, fixed_t extent, const INT16 tags[3], const vector3_t vx[3]) +{ + dynplanethink_t* th = Z_Calloc(sizeof (*th), PU_LEVSPEC, NULL); + switch (type) + { + case DP_VERTEX: + th->thinker.function.acp1 = (actionf_p1)T_DynamicSlopeVert; + memcpy(th->tags, tags, sizeof(th->tags)); + memcpy(th->vex, vx, sizeof(th->vex)); + break; + default: + th->thinker.function.acp1 = (actionf_p1)T_DynamicSlopeLine; + th->sourceline = sourceline; + th->extent = extent; + } + + th->slope = slope; + th->type = type; + + P_AddThinker(THINK_DYNSLOPE, &th->thinker); +} + + +/// Create a new slope and add it to the slope list. +static inline pslope_t* Slope_Add (const UINT8 flags) +{ + pslope_t *ret = Z_Calloc(sizeof(pslope_t), PU_LEVEL, NULL); ret->flags = flags; - // Add to the slope list ret->next = slopelist; slopelist = ret; @@ -185,13 +190,24 @@ static pslope_t *P_MakeSlope(const vector3_t *o, const vector2_t *d, return ret; } -// -// P_GetExtent -// -// Returns the distance to the first line within the sector that -// is intersected by a line parallel to the plane normal with the point (ox, oy) -// -static fixed_t P_GetExtent(sector_t *sector, line_t *line) +/// Alocates and fill the contents of a slope structure. +static pslope_t *MakeViaVectors(const vector3_t *o, const vector2_t *d, + const fixed_t zdelta, UINT8 flags) +{ + pslope_t *ret = Slope_Add(flags); + + FV3_Copy(&ret->o, o); + FV2_Copy(&ret->d, d); + + ret->zdelta = zdelta; + + ret->flags = flags; + + return ret; +} + +/// Get furthest perpendicular distance from all vertexes in a sector for a given line. +static fixed_t GetExtent(sector_t *sector, line_t *line) { // ZDoom code reference: v3float_t = vertex_t fixed_t fardist = -FRACUNIT; @@ -224,14 +240,8 @@ static fixed_t P_GetExtent(sector_t *sector, line_t *line) return fardist; } - -// -// P_SpawnSlope_Line -// -// Creates one or more slopes based on the given line type and front/back -// sectors. -// -void P_SpawnSlope_Line(int linenum) +/// Creates one or more slopes based on the given line type and front/back sectors. +static void line_SpawnViaLine(const int linenum, const boolean spawnthinker) { // With dynamic slopes, it's fine to just leave this function as normal, // because checking to see if a slope had changed will waste more memory than @@ -251,10 +261,8 @@ void P_SpawnSlope_Line(int linenum) UINT8 flags = 0; // Slope flags if (line->flags & ML_NOSONIC) flags |= SL_NOPHYSICS; - if (!(line->flags & ML_NOTAILS)) - flags |= SL_NODYNAMIC; - if (line->flags & ML_NOKNUX) - flags |= SL_ANCHORVERTEX; + if (line->flags & ML_NOTAILS) + flags |= SL_DYNAMIC; if(!frontfloor && !backfloor && !frontceil && !backceil) { @@ -274,6 +282,7 @@ void P_SpawnSlope_Line(int linenum) ny = -FixedDiv(line->dx, len); } + // Set origin to line's center. origin.x = line->v1->x + (line->v2->x - line->v1->x)/2; origin.y = line->v1->y + (line->v2->y - line->v1->y)/2; @@ -286,7 +295,7 @@ void P_SpawnSlope_Line(int linenum) direction.x = nx; direction.y = ny; - extent = P_GetExtent(line->frontsector, line); + extent = GetExtent(line->frontsector, line); if(extent < 0) { @@ -304,104 +313,43 @@ void P_SpawnSlope_Line(int linenum) if(frontfloor) { - fixed_t highest, lowest; - size_t l; point.z = line->frontsector->floorheight; // Startz dz = FixedDiv(origin.z - point.z, extent); // Destinationz // In P_SpawnSlopeLine the origin is the centerpoint of the sourcelinedef fslope = line->frontsector->f_slope = - P_MakeSlope(&point, &direction, dz, flags); - - // Set up some shit - fslope->extent = extent; - fslope->refpos = 1; + MakeViaVectors(&point, &direction, dz, flags); // Now remember that f_slope IS a vector // fslope->o = origin 3D point 1 of the vector // fslope->d = destination 3D point 2 of the vector // fslope->normal is a 3D line perpendicular to the 3D vector - // Sync the linedata of the line that started this slope - // TODO: Anything special for control sector based slopes later? - fslope->sourceline = line; - - // To find the real highz/lowz of a slope, you need to check all the vertexes - // in the slope's sector with P_GetZAt to get the REAL lowz & highz - // Although these slopes are set by floorheights the ANGLE is what a slope is, - // so technically any slope can extend on forever (they are just bound by sectors) - // *You can use sourceline as a reference to see if two slopes really are the same - - // Default points for high and low - highest = point.z > origin.z ? point.z : origin.z; - lowest = point.z < origin.z ? point.z : origin.z; - - // Now check to see what the REAL high and low points of the slope inside the sector - // TODO: Is this really needed outside of FOFs? -Red - - for (l = 0; l < line->frontsector->linecount; l++) - { - fixed_t height = P_GetZAt(line->frontsector->f_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y); - - if (height > highest) - highest = height; - - if (height < lowest) - lowest = height; - } - - // Sets extra clipping data for the frontsector's slope - fslope->highz = highest; - fslope->lowz = lowest; - fslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z); fslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y); P_CalculateSlopeNormal(fslope); + + if (spawnthinker && (flags & SL_DYNAMIC)) + P_AddDynSlopeThinker(fslope, DP_FRONTFLOOR, line, extent, NULL, NULL); } if(frontceil) { - fixed_t highest, lowest; - size_t l; origin.z = line->backsector->ceilingheight; point.z = line->frontsector->ceilingheight; dz = FixedDiv(origin.z - point.z, extent); cslope = line->frontsector->c_slope = - P_MakeSlope(&point, &direction, dz, flags); - - // Set up some shit - cslope->extent = extent; - cslope->refpos = 2; - - // Sync the linedata of the line that started this slope - // TODO: Anything special for control sector based slopes later? - cslope->sourceline = line; - - // Remember the way the slope is formed - highest = point.z > origin.z ? point.z : origin.z; - lowest = point.z < origin.z ? point.z : origin.z; - - for (l = 0; l < line->frontsector->linecount; l++) - { - fixed_t height = P_GetZAt(line->frontsector->c_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y); - - if (height > highest) - highest = height; - - if (height < lowest) - lowest = height; - } - - // This line special sets extra clipping data for the frontsector's slope - cslope->highz = highest; - cslope->lowz = lowest; + MakeViaVectors(&point, &direction, dz, flags); cslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z); cslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y); P_CalculateSlopeNormal(cslope); + + if (spawnthinker && (flags & SL_DYNAMIC)) + P_AddDynSlopeThinker(cslope, DP_FRONTCEIL, line, extent, NULL, NULL); } } if(backfloor || backceil) @@ -413,7 +361,7 @@ void P_SpawnSlope_Line(int linenum) direction.x = -nx; direction.y = -ny; - extent = P_GetExtent(line->backsector, line); + extent = GetExtent(line->backsector, line); if(extent < 0) { @@ -429,88 +377,36 @@ void P_SpawnSlope_Line(int linenum) if(backfloor) { - fixed_t highest, lowest; - size_t l; point.z = line->backsector->floorheight; dz = FixedDiv(origin.z - point.z, extent); fslope = line->backsector->f_slope = - P_MakeSlope(&point, &direction, dz, flags); - - // Set up some shit - fslope->extent = extent; - fslope->refpos = 3; - - // Sync the linedata of the line that started this slope - // TODO: Anything special for control sector based slopes later? - fslope->sourceline = line; - - // Remember the way the slope is formed - highest = point.z > origin.z ? point.z : origin.z; - lowest = point.z < origin.z ? point.z : origin.z; - - for (l = 0; l < line->backsector->linecount; l++) - { - fixed_t height = P_GetZAt(line->backsector->f_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y); - - if (height > highest) - highest = height; - - if (height < lowest) - lowest = height; - } - - // This line special sets extra clipping data for the frontsector's slope - fslope->highz = highest; - fslope->lowz = lowest; + MakeViaVectors(&point, &direction, dz, flags); fslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z); fslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y); P_CalculateSlopeNormal(fslope); + + if (spawnthinker && (flags & SL_DYNAMIC)) + P_AddDynSlopeThinker(fslope, DP_BACKFLOOR, line, extent, NULL, NULL); } if(backceil) { - fixed_t highest, lowest; - size_t l; origin.z = line->frontsector->ceilingheight; point.z = line->backsector->ceilingheight; dz = FixedDiv(origin.z - point.z, extent); cslope = line->backsector->c_slope = - P_MakeSlope(&point, &direction, dz, flags); - - // Set up some shit - cslope->extent = extent; - cslope->refpos = 4; - - // Sync the linedata of the line that started this slope - // TODO: Anything special for control sector based slopes later? - cslope->sourceline = line; - - // Remember the way the slope is formed - highest = point.z > origin.z ? point.z : origin.z; - lowest = point.z < origin.z ? point.z : origin.z; - - for (l = 0; l < line->backsector->linecount; l++) - { - fixed_t height = P_GetZAt(line->backsector->c_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y); - - if (height > highest) - highest = height; - - if (height < lowest) - lowest = height; - } - - // This line special sets extra clipping data for the backsector's slope - cslope->highz = highest; - cslope->lowz = lowest; + MakeViaVectors(&point, &direction, dz, flags); cslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z); cslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y); P_CalculateSlopeNormal(cslope); + + if (spawnthinker && (flags & SL_DYNAMIC)) + P_AddDynSlopeThinker(cslope, DP_BACKCEIL, line, extent, NULL, NULL); } } @@ -518,63 +414,99 @@ void P_SpawnSlope_Line(int linenum) return; } -// -// P_NewVertexSlope -// -// Creates a new slope from three vertices with the specified IDs -// -static pslope_t *P_NewVertexSlope(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flags) +/// Creates a new slope from three mapthings with the specified IDs +static pslope_t *MakeViaMapthings(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flags, const boolean spawnthinker) { size_t i; - mapthing_t *mt = mapthings; + mapthing_t* mt = mapthings; + mapthing_t* vertices[3] = {0}; + INT16 tags[3] = {tag1, tag2, tag3}; - pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL); - memset(ret, 0, sizeof(*ret)); - - // Start by setting flags - ret->flags = flags; - - // Now set up the vertex list - ret->vertices = Z_Malloc(3*sizeof(mapthing_t), PU_LEVEL, NULL); - memset(ret->vertices, 0, 3*sizeof(mapthing_t)); + vector3_t vx[3]; + pslope_t* ret = Slope_Add(flags); // And... look for the vertices in question. for (i = 0; i < nummapthings; i++, mt++) { if (mt->type != 750) // Haha, I'm hijacking the old Chaos Spawn thingtype for something! continue; - if (!ret->vertices[0] && mt->angle == tag1) - ret->vertices[0] = mt; - else if (!ret->vertices[1] && mt->angle == tag2) - ret->vertices[1] = mt; - else if (!ret->vertices[2] && mt->angle == tag3) - ret->vertices[2] = mt; + if (!vertices[0] && mt->angle == tag1) + vertices[0] = mt; + else if (!vertices[1] && mt->angle == tag2) + vertices[1] = mt; + else if (!vertices[2] && mt->angle == tag3) + vertices[2] = mt; } // Now set heights for each vertex, because they haven't been set yet for (i = 0; i < 3; i++) { - mt = ret->vertices[i]; + mt = vertices[i]; if (!mt) // If a vertex wasn't found, it's game over. There's nothing you can do to recover (except maybe try and kill the slope instead - TODO?) - I_Error("P_NewVertexSlope: Slope vertex %s (for linedef tag %d) not found!", sizeu1(i), tag1); + I_Error("MakeViaMapthings: Slope vertex %s (for linedef tag %d) not found!", sizeu1(i), tag1); + vx[i].x = mt->x << FRACBITS; + vx[i].y = mt->y << FRACBITS; if (mt->extrainfo) - mt->z = mt->options; + vx[i].z = mt->options << FRACBITS; else - mt->z = (R_PointInSubsector(mt->x << FRACBITS, mt->y << FRACBITS)->sector->floorheight >> FRACBITS) + (mt->options >> ZSHIFT); + vx[i].z = (R_PointInSubsector(mt->x << FRACBITS, mt->y << FRACBITS)->sector->floorheight) + ((mt->options >> ZSHIFT) << FRACBITS); } - P_ReconfigureVertexSlope(ret); - ret->refpos = 5; + ReconfigureViaVertexes(ret, vx[0], vx[1], vx[2]); - // Add to the slope list - ret->next = slopelist; - slopelist = ret; - - slopecount++; - ret->id = slopecount; + if (spawnthinker && (flags & SL_DYNAMIC)) + P_AddDynSlopeThinker(ret, DP_VERTEX, NULL, 0, tags, vx); return ret; } +/// Create vertex based slopes. +static void line_SpawnViaVertexes(const int linenum, const boolean spawnthinker) +{ + line_t *line = lines + linenum; + side_t *side; + pslope_t **slopetoset; + UINT16 tag1, tag2, tag3; + + UINT8 flags = 0; + if (line->flags & ML_NOSONIC) + flags |= SL_NOPHYSICS; + if (line->flags & ML_NOTAILS) + flags |= SL_DYNAMIC; + + switch(line->special) + { + case 704: + slopetoset = &line->frontsector->f_slope; + side = &sides[line->sidenum[0]]; + break; + case 705: + slopetoset = &line->frontsector->c_slope; + side = &sides[line->sidenum[0]]; + break; + case 714: + slopetoset = &line->backsector->f_slope; + side = &sides[line->sidenum[1]]; + break; + case 715: + slopetoset = &line->backsector->c_slope; + side = &sides[line->sidenum[1]]; + default: + return; + } + + if (line->flags & ML_NOKNUX) + { + tag1 = line->tag; + tag2 = side->textureoffset >> FRACBITS; + tag3 = side->rowoffset >> FRACBITS; + } + else + tag1 = tag2 = tag3 = line->tag; + + *slopetoset = MakeViaMapthings(tag1, tag2, tag3, flags, spawnthinker); + + side->sector->hasslope = true; +} // @@ -615,56 +547,20 @@ pslope_t *P_SlopeById(UINT16 id) return ret; } -// Reset the dynamic slopes pointer, and read all of the fancy schmancy slopes -void P_ResetDynamicSlopes(void) { +/// Reset slopes and read them from special lines. +void P_ResetDynamicSlopes(const UINT32 fromsave) { size_t i; -#ifdef ESLOPE_TYPESHIM // Rewrite old specials to new ones, and give a console warning - boolean warned = false; -#endif + + boolean spawnthinkers = !(boolean)fromsave; slopelist = NULL; slopecount = 0; - // We'll handle copy slopes later, after all the tag lists have been made. - // Yes, this means copied slopes won't affect things' spawning heights. Too bad for you. + /// Generates line special-defined slopes. for (i = 0; i < numlines; i++) { switch (lines[i].special) { -#ifdef ESLOPE_TYPESHIM // Rewrite old specials to new ones, and give a console warning -#define WARNME if (!warned) {warned = true; CONS_Alert(CONS_WARNING, "This level uses old slope specials.\nA conversion will be needed before 2.2's release.\n");} - case 386: - case 387: - case 388: - lines[i].special += 700-386; - WARNME - P_SpawnSlope_Line(i); - break; - - case 389: - case 390: - case 391: - case 392: - lines[i].special += 710-389; - WARNME - P_SpawnSlope_Line(i); - break; - - case 393: - lines[i].special = 703; - WARNME - P_SpawnSlope_Line(i); - break; - - case 394: - case 395: - case 396: - lines[i].special += 720-394; - WARNME - break; - -#endif - case 700: case 701: case 702: @@ -673,63 +569,35 @@ void P_ResetDynamicSlopes(void) { case 711: case 712: case 713: - P_SpawnSlope_Line(i); + line_SpawnViaLine(i, spawnthinkers); break; case 704: case 705: case 714: case 715: - { - pslope_t **slopetoset; - size_t which = lines[i].special; - - UINT8 flags = SL_VERTEXSLOPE; - if (lines[i].flags & ML_NOSONIC) - flags |= SL_NOPHYSICS; - if (!(lines[i].flags & ML_NOTAILS)) - flags |= SL_NODYNAMIC; - - if (which == 704) - { - slopetoset = &lines[i].frontsector->f_slope; - which = 0; - } - else if (which == 705) - { - slopetoset = &lines[i].frontsector->c_slope; - which = 0; - } - else if (which == 714) - { - slopetoset = &lines[i].backsector->f_slope; - which = 1; - } - else // 715 - { - slopetoset = &lines[i].backsector->c_slope; - which = 1; - } - - if (lines[i].flags & ML_NOKNUX) - *slopetoset = P_NewVertexSlope(lines[i].tag, sides[lines[i].sidenum[which]].textureoffset >> FRACBITS, - sides[lines[i].sidenum[which]].rowoffset >> FRACBITS, flags); - else - *slopetoset = P_NewVertexSlope(lines[i].tag, lines[i].tag, lines[i].tag, flags); - - sides[lines[i].sidenum[which]].sector->hasslope = true; - } + line_SpawnViaVertexes(i, spawnthinkers); break; default: break; } } + + /// Copies slopes from tagged sectors via line specials. + /// \note Doesn't actually copy, but instead they share the same pointers. + for (i = 0; i < numlines; i++) + switch (lines[i].special) + { + case 720: + case 721: + case 722: + P_CopySectorSlope(&lines[i]); + default: + break; + } } - - - // ============================================================================ // // Various utilities related to slopes diff --git a/src/p_slopes.h b/src/p_slopes.h index 708a9107d..b674a0cf5 100644 --- a/src/p_slopes.h +++ b/src/p_slopes.h @@ -13,14 +13,17 @@ #ifndef P_SLOPES_H__ #define P_SLOPES_H__ +#include "m_fixed.h" // Vectors + #ifdef ESLOPE + +extern pslope_t *slopelist; +extern UINT16 slopecount; + +void P_LinkSlopeThinkers (void); + void P_CalculateSlopeNormal(pslope_t *slope); -void P_ResetDynamicSlopes(void); -void P_RunDynamicSlopes(void); -// P_SpawnSlope_Line -// Creates one or more slopes based on the given line type and front/back -// sectors. -void P_SpawnSlope_Line(int linenum); +void P_ResetDynamicSlopes(const UINT32 fromsave); // // P_CopySectorSlope @@ -41,7 +44,34 @@ void P_SlopeLaunch(mobj_t *mo); void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope); void P_ButteredSlope(mobj_t *mo); -#endif -// EOF +/// Dynamic plane type enum for the thinker. Will have a different functionality depending on this. +typedef enum { + DP_FRONTFLOOR, + DP_FRONTCEIL, + DP_BACKFLOOR, + DP_BACKCEIL, + DP_VERTEX +} dynplanetype_t; + +/// Permit slopes to be dynamically altered through a thinker. +typedef struct +{ + thinker_t thinker; + + pslope_t* slope; + dynplanetype_t type; + + // Used by line slopes. + line_t* sourceline; + fixed_t extent; + + // Used by mapthing vertex slopes. + INT16 tags[3]; + vector3_t vex[3]; +} dynplanethink_t; + +void T_DynamicSlopeLine (dynplanethink_t* th); +void T_DynamicSlopeVert (dynplanethink_t* th); #endif // #ifdef ESLOPE +#endif // #ifndef P_SLOPES_H__ diff --git a/src/p_spec.c b/src/p_spec.c index a08bdbc34..b11a7e69b 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1594,7 +1594,7 @@ static void P_AddExecutorDelay(line_t *line, mobj_t *mobj, sector_t *sector) e->sector = sector; e->timer = (line->backsector->ceilingheight>>FRACBITS)+(line->backsector->floorheight>>FRACBITS); P_SetTarget(&e->caller, mobj); // Use P_SetTarget to make sure the mobj doesn't get freed while we're delaying. - P_AddThinker(&e->thinker); + P_AddThinker(THINK_MAIN, &e->thinker); } /** Used by P_LinedefExecute to check a trigger linedef's conditions @@ -2058,7 +2058,7 @@ void P_SwitchWeather(INT32 weathernum) thinker_t *think; precipmobj_t *precipmobj; - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MAIN].next; think != &thlist[THINK_MAIN]; think = think->next) { if (think->function.acp1 != (actionf_p1)P_NullPrecipThinker) continue; // not a precipmobj thinker @@ -2074,7 +2074,7 @@ void P_SwitchWeather(INT32 weathernum) precipmobj_t *precipmobj; state_t *st; - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MAIN].next; think != &thlist[THINK_MAIN]; think = think->next) { if (think->function.acp1 != (actionf_p1)P_NullPrecipThinker) continue; // not a precipmobj thinker @@ -2934,7 +2934,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) scroll_t *scroller; thinker_t *th; - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MAIN].next; th != &thlist[THINK_MAIN]; th = th->next) { if (th->function.acp1 != (actionf_p1)T_Scroll) continue; @@ -3273,11 +3273,8 @@ void P_SetupSignExit(player_t *player) // didn't find any signposts in the exit sector. // spin all signposts in the level then. - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 != (actionf_p1)P_MobjThinker) - continue; // not a mobj thinker - thing = (mobj_t *)think; if (thing->type != MT_SIGN) continue; @@ -3322,11 +3319,8 @@ boolean P_IsFlagAtBase(mobjtype_t flag) mobj_t *mo; INT32 specialnum = 0; - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 != (actionf_p1)P_MobjThinker) - continue; // not a mobj thinker - mo = (mobj_t *)think; if (mo->type != flag) @@ -3763,11 +3757,8 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers // Find the center of the Eggtrap and release all the pretty animals! // The chimps are my friends.. heeheeheheehehee..... - LouisJM - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_EGGTRAP) P_KillMobj(mo2, NULL, player->mo); @@ -4100,11 +4091,8 @@ DoneSection2: // scan the thinkers // to find the first waypoint - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_TUBEWAYPOINT && mo2->threshold == sequence @@ -4176,11 +4164,8 @@ DoneSection2: // scan the thinkers // to find the last waypoint - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_TUBEWAYPOINT && mo2->threshold == sequence) @@ -4391,11 +4376,8 @@ DoneSection2: // scan the thinkers // to find the first waypoint - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) @@ -4429,11 +4411,8 @@ DoneSection2: } // Find waypoint before this one (waypointlow) - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) @@ -4456,11 +4435,8 @@ DoneSection2: } // Find waypoint after this one (waypointhigh) - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) @@ -4978,11 +4954,6 @@ void P_UpdateSpecials(void) // POINT LIMIT P_CheckPointLimit(); -#ifdef ESLOPE - // Dynamic slopeness - P_RunDynamicSlopes(); -#endif - // ANIMATE TEXTURES for (anim = anims; anim < lastanim; anim++) { @@ -5151,7 +5122,7 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f // Just initialise both of these to placate the compiler. i = 0; - th = thinkercap.next; + th = thlist[THINK_MAIN].next; for(;;) { @@ -5161,7 +5132,7 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f th = secthinkers[sec2num].thinkers[i]; else break; } - else if (th == &thinkercap) + else if (th == &thlist[THINK_MAIN]) break; // Should this FOF have spikeness? @@ -5250,7 +5221,7 @@ static void P_AddSpikeThinker(sector_t *sec, INT32 referrer) // create and initialize new thinker spikes = Z_Calloc(sizeof (*spikes), PU_LEVSPEC, NULL); - P_AddThinker(&spikes->thinker); + P_AddThinker(THINK_MAIN, &spikes->thinker); spikes->thinker.function.acp1 = (actionf_p1)T_SpikeSector; @@ -5272,7 +5243,7 @@ static void P_AddFloatThinker(sector_t *sec, INT32 tag, line_t *sourceline) // create and initialize new thinker floater = Z_Calloc(sizeof (*floater), PU_LEVSPEC, NULL); - P_AddThinker(&floater->thinker); + P_AddThinker(THINK_MAIN, &floater->thinker); floater->thinker.function.acp1 = (actionf_p1)T_FloatSector; @@ -5296,7 +5267,7 @@ static inline void P_AddBridgeThinker(line_t *sourceline, sector_t *sec) // create an initialize new thinker bridge = Z_Calloc(sizeof (*bridge), PU_LEVSPEC, NULL); - P_AddThinker(&bridge->thinker); + P_AddThinker(THINK_MAIN, &bridge->thinker); bridge->thinker.function.acp1 = (actionf_p1)T_BridgeThinker; @@ -5330,7 +5301,7 @@ static void P_AddBlockThinker(sector_t *sec, line_t *sourceline) // create and initialize new elevator thinker block = Z_Calloc(sizeof (*block), PU_LEVSPEC, NULL); - P_AddThinker(&block->thinker); + P_AddThinker(THINK_MAIN, &block->thinker); block->thinker.function.acp1 = (actionf_p1)T_MarioBlockChecker; block->sourceline = sourceline; @@ -5359,7 +5330,7 @@ static void P_AddRaiseThinker(sector_t *sec, line_t *sourceline) levelspecthink_t *raise; raise = Z_Calloc(sizeof (*raise), PU_LEVSPEC, NULL); - P_AddThinker(&raise->thinker); + P_AddThinker(THINK_MAIN, &raise->thinker); raise->thinker.function.acp1 = (actionf_p1)T_RaiseSector; @@ -5398,7 +5369,7 @@ static void P_AddOldAirbob(sector_t *sec, line_t *sourceline, boolean noadjust) levelspecthink_t *airbob; airbob = Z_Calloc(sizeof (*airbob), PU_LEVSPEC, NULL); - P_AddThinker(&airbob->thinker); + P_AddThinker(THINK_MAIN, &airbob->thinker); airbob->thinker.function.acp1 = (actionf_p1)T_RaiseSector; @@ -5459,7 +5430,7 @@ static inline void P_AddThwompThinker(sector_t *sec, sector_t *actionsector, lin // create and initialize new elevator thinker thwomp = Z_Calloc(sizeof (*thwomp), PU_LEVSPEC, NULL); - P_AddThinker(&thwomp->thinker); + P_AddThinker(THINK_MAIN, &thwomp->thinker); thwomp->thinker.function.acp1 = (actionf_p1)T_ThwompSector; @@ -5495,7 +5466,7 @@ static inline void P_AddNoEnemiesThinker(sector_t *sec, line_t *sourceline) // create and initialize new thinker nobaddies = Z_Calloc(sizeof (*nobaddies), PU_LEVSPEC, NULL); - P_AddThinker(&nobaddies->thinker); + P_AddThinker(THINK_MAIN, &nobaddies->thinker); nobaddies->thinker.function.acp1 = (actionf_p1)T_NoEnemiesSector; @@ -5517,7 +5488,7 @@ static inline void P_AddEachTimeThinker(sector_t *sec, line_t *sourceline) // create and initialize new thinker eachtime = Z_Calloc(sizeof (*eachtime), PU_LEVSPEC, NULL); - P_AddThinker(&eachtime->thinker); + P_AddThinker(THINK_MAIN, &eachtime->thinker); eachtime->thinker.function.acp1 = (actionf_p1)T_EachTimeThinker; @@ -5539,7 +5510,7 @@ static inline void P_AddCameraScanner(sector_t *sourcesec, sector_t *actionsecto // create and initialize new elevator thinker elevator = Z_Calloc(sizeof (*elevator), PU_LEVSPEC, NULL); - P_AddThinker(&elevator->thinker); + P_AddThinker(THINK_MAIN, &elevator->thinker); elevator->thinker.function.acp1 = (actionf_p1)T_CameraScanner; elevator->type = elevateBounce; @@ -5633,7 +5604,7 @@ static inline void EV_AddLaserThinker(sector_t *sec, sector_t *sec2, line_t *lin flash = Z_Calloc(sizeof (*flash), PU_LEVSPEC, NULL); - P_AddThinker(&flash->thinker); + P_AddThinker(THINK_MAIN, &flash->thinker); flash->thinker.function.acp1 = (actionf_p1)T_LaserFlash; flash->ffloor = ffloor; @@ -5762,7 +5733,7 @@ void P_SpawnSpecials(INT32 fromnetsave) secthinkers = Z_Calloc(numsectors * sizeof(thinkerlist_t), PU_STATIC, NULL); // Firstly, find out how many there are in each sector - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MAIN].next; th != &thlist[THINK_MAIN]; th = th->next) { if (th->function.acp1 == (actionf_p1)T_SpikeSector) secthinkers[((levelspecthink_t *)th)->sector - sectors].count++; @@ -5782,7 +5753,7 @@ void P_SpawnSpecials(INT32 fromnetsave) } // Finally, populate the lists. - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MAIN].next; th != &thlist[THINK_MAIN]; th = th->next) { size_t secnum = (size_t)-1; @@ -6677,14 +6648,6 @@ void P_SpawnSpecials(INT32 fromnetsave) sectors[s].midmap = lines[i].frontsector->midmap; break; -#ifdef ESLOPE // Slope copy specials. Handled here for sanity. - case 720: - case 721: - case 722: - P_CopySectorSlope(&lines[i]); - break; -#endif - default: break; } @@ -7040,7 +7003,7 @@ static void Add_Scroller(INT32 type, fixed_t dx, fixed_t dy, INT32 control, INT3 if ((s->control = control) != -1) s->last_height = sectors[control].floorheight + sectors[control].ceilingheight; s->affectee = affectee; - P_AddThinker(&s->thinker); + P_AddThinker(THINK_MAIN, &s->thinker); } /** Adds a wall scroller. @@ -7199,7 +7162,7 @@ static void Add_MasterDisappearer(tic_t appeartime, tic_t disappeartime, tic_t o d->exists = true; d->timer = 1; - P_AddThinker(&d->thinker); + P_AddThinker(THINK_MAIN, &d->thinker); } /** Makes a FOF appear/disappear @@ -7293,7 +7256,7 @@ static void Add_Friction(INT32 friction, INT32 movefactor, INT32 affectee, INT32 else f->roverfriction = false; - P_AddThinker(&f->thinker); + P_AddThinker(THINK_MAIN, &f->thinker); } /** Applies friction to all things in a sector. @@ -7481,7 +7444,7 @@ static void Add_Pusher(pushertype_e type, fixed_t x_mag, fixed_t y_mag, mobj_t * p->z = p->source->z; } p->affectee = affectee; - P_AddThinker(&p->thinker); + P_AddThinker(THINK_MAIN, &p->thinker); } diff --git a/src/p_tick.c b/src/p_tick.c index 2502c7213..009b9b6a3 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -37,8 +37,8 @@ tic_t leveltime; // but the first element must be thinker_t. // -// Both the head and tail of the thinker list. -thinker_t thinkercap; +// The entries will behave like both the head and tail of the lists. +thinker_t thlist[NUM_THINKERLISTS]; void Command_Numthinkers_f(void) { @@ -104,7 +104,7 @@ void Command_Numthinkers_f(void) return; } - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MAIN].next; think != &thlist[THINK_MAIN]; think = think->next) { if (think->function.acp1 != action) continue; @@ -141,11 +141,8 @@ void Command_CountMobjs_f(void) count = 0; - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (((mobj_t *)th)->type == i) count++; } @@ -161,11 +158,8 @@ void Command_CountMobjs_f(void) { count = 0; - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (((mobj_t *)th)->type == i) count++; } @@ -180,20 +174,18 @@ void Command_CountMobjs_f(void) // void P_InitThinkers(void) { - thinkercap.prev = thinkercap.next = &thinkercap; - waypointcap = NULL; + UINT8 i; + for (i = 0; i < NUM_THINKERLISTS; i++) + thlist[i].prev = thlist[i].next = &thlist[i]; } -// -// P_AddThinker // Adds a new thinker at the end of the list. -// -void P_AddThinker(thinker_t *thinker) +void P_AddThinker(const thinklistnum_t n, thinker_t *thinker) { - thinkercap.prev->next = thinker; - thinker->next = &thinkercap; - thinker->prev = thinkercap.prev; - thinkercap.prev = thinker; + thlist[n].prev->next = thinker; + thinker->next = &thlist[n]; + thinker->prev = thlist[n].prev; + thlist[n].prev = thinker; thinker->references = 0; // killough 11/98: init reference counter to 0 } @@ -248,10 +240,23 @@ void P_RemoveThinkerDelayed(void *pthinker) // void P_RemoveThinker(thinker_t *thinker) { + thinker_t *next = thinker->next; #ifdef HAVE_BLUA LUA_InvalidateUserdata(thinker); #endif thinker->function.acp1 = P_RemoveThinkerDelayed; + + if (currentthinker == thinker) + currentthinker = thinker->prev; + + // Remove thinker from its current list. + (next->prev = thinker->prev)->next = next; + + // Now add it to the limbo list + thlist[THINK_LIMBO].prev->next = thinker; + thinker->next = &thlist[THINK_LIMBO]; + thinker->prev = thlist[THINK_LIMBO].prev; + thlist[THINK_LIMBO].prev = thinker; } /* @@ -299,11 +304,16 @@ if ((*mop = targ) != NULL) // Set new target and if non-NULL, increase its count // static inline void P_RunThinkers(void) { - for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) + size_t i; + for (i = 0; i < NUM_THINKERLISTS; i++) { - if (currentthinker->function.acp1) - currentthinker->function.acp1(currentthinker); + for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; currentthinker = currentthinker->next) + { + if (currentthinker->function.acp1) + currentthinker->function.acp1(currentthinker); + } } + } // diff --git a/src/p_user.c b/src/p_user.c index ced8b2da0..b1dc9fae6 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -356,11 +356,8 @@ void P_ResetScore(player_t *player) // scan the thinkers // to find the egg capsule with the lowest mare - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_EGGCAPSULE && mo2->health > 0) @@ -457,11 +454,8 @@ UINT8 P_FindHighestLap(void) // scan the thinkers // to find the closest axis point - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_AXIS) @@ -508,11 +502,8 @@ static mobj_t *P_FindAxis(INT32 mare, INT32 axisnum) // scan the thinkers // to find the closest axis point - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; // Axis things are only at beginning of list. @@ -541,11 +532,8 @@ static mobj_t *P_FindAxisTransfer(INT32 mare, INT32 axisnum, mobjtype_t type) // scan the thinkers // to find the closest axis point - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; // Axis things are only at beginning of list. @@ -580,11 +568,8 @@ void P_TransferToAxis(player_t *player, INT32 axisnum) // scan the thinkers // to find the closest axis point - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_AXIS) @@ -679,11 +664,8 @@ static void P_DeNightserizePlayer(player_t *player) } // Check to see if the player should be killed. - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (!(mo2->type == MT_NIGHTSDRONE)) continue; @@ -1593,11 +1575,8 @@ void P_SpawnShieldOrb(player_t *player) } // blaze through the thinkers to see if an orb already exists! - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - shieldobj = (mobj_t *)th; if (shieldobj->type == orbtype && shieldobj->target == player->mo) @@ -2813,7 +2792,7 @@ static void P_DoClimbing(player_t *player) // SRB2kart - unused angle_t sideangle; fixed_t dx, dy; - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MAIN].next; think != &thlist[THINK_MAIN]; think = think->next) { if (think->function.acp1 != (actionf_p1)T_Scroll) continue; @@ -3706,11 +3685,8 @@ void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range) if (player->powers[pw_super]) // increase range when super range *= 2; - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2 == player->mo) @@ -4388,11 +4364,8 @@ static void P_NightsTransferPoints(player_t *player, fixed_t xspeed, fixed_t rad fixed_t truexspeed = xspeed*(!(player->pflags & PF_TRANSFERTOCLOSEST) && player->mo->target->flags2 & MF2_AMBUSH ? -1 : 1); // Find next waypoint - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)th; // Axis things are only at beginning of list. @@ -4424,11 +4397,8 @@ static void P_NightsTransferPoints(player_t *player, fixed_t xspeed, fixed_t rad // Look for a wrapper point. if (!transfer1) { - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)th; // Axis things are only at beginning of list. @@ -4452,11 +4422,8 @@ static void P_NightsTransferPoints(player_t *player, fixed_t xspeed, fixed_t rad } if (!transfer2) { - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)th; // Axis things are only at beginning of list. @@ -4999,11 +4966,8 @@ static void P_NiGHTSMovement(player_t *player) // scan the thinkers // to find the closest axis point - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_AXIS) @@ -5718,11 +5682,8 @@ static void P_MovePlayer(player_t *player) thinker_t *th; mobj_t *mo2; - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_EGGCAPSULE @@ -6535,11 +6496,8 @@ static void P_DoZoomTube(player_t *player) CONS_Debug(DBG_GAMELOGIC, "Looking for next waypoint...\n"); // Find next waypoint - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) @@ -6677,11 +6635,8 @@ static void P_DoRopeHang(player_t *player) // SRB2kart - unused. CONS_Debug(DBG_GAMELOGIC, "Looking for next waypoint...\n"); // Find next waypoint - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) @@ -6702,11 +6657,8 @@ static void P_DoRopeHang(player_t *player) // SRB2kart - unused. CONS_Debug(DBG_GAMELOGIC, "Next waypoint not found, wrapping to start...\n"); // Wrap around back to first waypoint - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) @@ -6772,11 +6724,8 @@ static void P_NukeAllPlayers(player_t *player) mobj_t *mo; thinker_t *think; - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 != (actionf_p1)P_MobjThinker) - continue; // not a mobj thinker - mo = (mobj_t *)think; if (!mo->player) @@ -6822,11 +6771,8 @@ void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius) } } - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 != (actionf_p1)P_MobjThinker) - continue; // not a mobj thinker - mo = (mobj_t *)think; if (!(mo->flags & MF_SHOOTABLE) && !(mo->type == MT_EGGGUARD || mo->type == MT_MINUS @@ -6902,11 +6848,8 @@ boolean P_LookForEnemies(player_t *player) mobj_t *closestmo = NULL; angle_t an; - for (think = thinkercap.next; think != &thinkercap; think = think->next) + for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 != (actionf_p1)P_MobjThinker) - continue; // not a mobj thinker - mo = (mobj_t *)think; if (!(mo->flags & (MF_ENEMY|MF_BOSS|MF_MONITOR|MF_SPRING))) continue; // not a valid enemy @@ -7027,11 +6970,8 @@ void P_FindEmerald(void) // scan the remaining thinkers // to find all emeralds - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (mo2->type == MT_EMERHUNT) { @@ -8355,11 +8295,8 @@ void P_PlayerThink(player_t *player) fixed_t y = player->mo->y; fixed_t z = player->mo->z; - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mo2 = (mobj_t *)th; if (!(mo2->type == MT_NIGHTSWING || mo2->type == MT_RING || mo2->type == MT_COIN diff --git a/src/r_data.c b/src/r_data.c index 7fb11855f..dbfc56a4e 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1653,9 +1653,8 @@ void R_PrecacheLevel(void) spritepresent = calloc(numsprites, sizeof (*spritepresent)); if (spritepresent == NULL) I_Error("%s: Out of memory looking up sprites", "R_PrecacheLevel"); - for (th = thinkercap.next; th != &thinkercap; th = th->next) - if (th->function.acp1 == (actionf_p1)P_MobjThinker) - spritepresent[((mobj_t *)th)->sprite] = 1; + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + spritepresent[((mobj_t *)th)->sprite] = 1; spritememory = 0; for (i = 0; i < numsprites; i++) diff --git a/src/r_defs.h b/src/r_defs.h index 52a3be80e..5cb5c43f1 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -228,46 +228,27 @@ typedef struct linechain_s // Slopes #ifdef ESLOPE typedef enum { - SL_NOPHYSICS = 1, // Don't do momentum adjustment with this slope - SL_NODYNAMIC = 1<<1, // Slope will never need to move during the level, so don't fuss with recalculating it - SL_ANCHORVERTEX = 1<<2, // Slope is using a Slope Vertex Thing to anchor its position - SL_VERTEXSLOPE = 1<<3, // Slope is built from three Slope Vertex Things + SL_NOPHYSICS = 1, /// This plane will have no physics applied besides the positioning. + SL_DYNAMIC = 1<<1, /// This plane slope will be assigned a thinker to make it dynamic. } slopeflags_t; typedef struct pslope_s { UINT16 id; // The number of the slope, mostly used for netgame syncing purposes + struct pslope_s *next; // Make a linked list of dynamic slopes, for easy reference later - // --- Information used in clipping/projection --- - // Origin vector for the plane - vector3_t o; + // The plane's definition. + vector3_t o; /// Plane origin. + vector3_t normal; /// Plane normal. - // 2-Dimentional vector (x, y) normalized. Used to determine distance from - // the origin in 2d mapspace. (Basically a thrust of FRACUNIT in xydirection angle) - vector2_t d; - - // The rate at which z changes based on distance from the origin plane. - fixed_t zdelta; - - // The normal of the slope; will always point upward, and thus be inverted on ceilings. I think it's only needed for physics? -Red - vector3_t normal; - - // For comparing when a slope should be rendered - fixed_t lowz; - fixed_t highz; + vector2_t d; /// Precomputed normalized projection of the normal over XY. + fixed_t zdelta; /// Precomputed Z unit increase per XY unit. // This values only check and must be updated if the slope itself is modified - angle_t zangle; // Angle of the plane going up from the ground (not mesured in degrees) - angle_t xydirection; // The direction the slope is facing (north, west, south, etc.) - - struct line_s *sourceline; // The line that generated the slope - fixed_t extent; // Distance value used for recalculating zdelta - UINT8 refpos; // 1=front floor 2=front ceiling 3=back floor 4=back ceiling (used for dynamic sloping) + angle_t zangle; /// Precomputed angle of the plane going up from the ground (not measured in degrees). + angle_t xydirection;/// Precomputed angle of the normal's projection on the XY plane. UINT8 flags; // Slope options - mapthing_t **vertices; // List should be three long for slopes made by vertex things, or one long for slopes using one vertex thing to anchor - - struct pslope_s *next; // Make a linked list of dynamic slopes, for easy reference later } pslope_t; #endif diff --git a/src/st_stuff.c b/src/st_stuff.c index 50bac3eef..372822f51 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -1762,10 +1762,8 @@ static void ST_doItemFinderIconsAndSound(void) // SRB2kart - unused. return; // Scan thinkers to find emblem mobj with these ids - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_EMBLEM) From e11fec14082616ba40975aa05a53682220ee5056 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Thu, 13 Feb 2020 21:07:16 -0500 Subject: [PATCH 02/67] Removed p_user.c include I'm a C noob, moving on --- src/p_enemy.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/p_enemy.c b/src/p_enemy.c index ccdf23e01..1e055cc9d 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -25,8 +25,6 @@ #include "lua_hook.h" #include "k_kart.h" // SRB2kart -#include "p_user.c" - #ifdef HW3SOUND #include "hardware/hw3sound.h" #endif From 3957c04a9b2baf1226b92d05aabcaf653dba6068 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 14 Jul 2019 10:52:56 -0400 Subject: [PATCH 03/67] Merge branch 'thinkerlists-fix' into 'master' Thinkerlists fix Closes #161 See merge request STJr/SRB2Internal!253 --- src/d_clisrv.c | 8 +- src/d_netcmd.c | 3 +- src/g_game.c | 13 +- src/hardware/hw_light.c | 93 ++++--- src/lua_blockmaplib.c | 2 + src/lua_mobjlib.c | 11 +- src/lua_playerlib.c | 34 ++- src/lua_script.c | 31 ++- src/m_cheat.c | 8 +- src/p_enemy.c | 55 +++- src/p_floor.c | 28 +- src/p_inter.c | 63 +++++ src/p_local.h | 4 +- src/p_maputl.c | 3 + src/p_mobj.c | 124 +++++---- src/p_polyobj.c | 171 +++++++------ src/p_saveg.c | 51 ++-- src/p_setup.c | 11 +- src/p_spec.c | 78 ++++-- src/p_tick.c | 86 ++++--- src/p_tick.h | 2 +- src/p_user.c | 553 +++++++++++++++++++++++++++++----------- src/r_data.c | 3 +- src/st_stuff.c | 30 ++- 24 files changed, 1008 insertions(+), 457 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 39b64c127..82d82ef94 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4778,13 +4778,11 @@ static INT16 Consistancy(void) ret += P_GetRandSeed(); #ifdef MOBJCONSISTANCY - if (!thlist[THINK_MOBJ].next) - { - DEBFILE(va("Consistancy = %u\n", ret)); - return ret; - } for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo = (mobj_t *)th; if (mo->flags & (MF_SPECIAL | MF_SOLID | MF_PUSHABLE | MF_BOSS | MF_MISSILE | MF_SPRING | MF_MONITOR | MF_FIRE | MF_ENEMY | MF_PAIN | MF_STICKY)) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 0d3967c3d..6eb3f320a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5377,7 +5377,8 @@ static void Command_Archivetest_f(void) // assign mobjnum i = 1; for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) - ((mobj_t *)th)->mobjnum = i++; + if (th->function.acp1 != (actionf_p1)P_RemoveThinkerDelayed) + ((mobj_t *)th)->mobjnum = i++; // allocate buffer buf = save_p = ZZ_Alloc(1024); diff --git a/src/g_game.c b/src/g_game.c index 6dc675d8f..04982e5ca 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3098,6 +3098,9 @@ void G_ChangePlayerReferences(mobj_t *oldmo, mobj_t *newmo) // scan all thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (!(mo2->flags & MF_MISSILE)) @@ -5541,12 +5544,13 @@ void G_ConsGhostTic(INT32 playernum) mobj = NULL; for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; mobj = (mobj_t *)th; if (mobj->type == (mobjtype_t)type && mobj->x == x && mobj->y == y && mobj->z == z) break; - mobj = NULL; // wasn't this one, keep searching. } - if (mobj && mobj->health != health) // Wasn't damaged?! This is desync! Fix it! + if (th != &thlist[THINK_MOBJ] && mobj->health != health) // Wasn't damaged?! This is desync! Fix it! { if (demosynced) CONS_Alert(CONS_WARNING, M_GetText("Demo playback has desynced!\n")); @@ -7970,11 +7974,14 @@ void G_DoPlayMetal(void) // find metal sonic for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo = (mobj_t *)th; if (mo->type == MT_METALSONIC_RACE) break; } - if (!mo) + if (th == &thlist[THINK_MOBJ]) { CONS_Alert(CONS_ERROR, M_GetText("Failed to find bot entity.\n")); Z_Free(metalbuffer); diff --git a/src/hardware/hw_light.c b/src/hardware/hw_light.c index f342e9f07..c26843e25 100644 --- a/src/hardware/hw_light.c +++ b/src/hardware/hw_light.c @@ -755,6 +755,14 @@ void HWR_WallLighting(FOutVector *wlVerts) FSurfaceInfo Surf; float dist_p2d, d[4], s; + if (!dynlights->mo[j]) + continue; + if (P_MobjWasRemoved(dynlights->mo[j])) + { + P_SetTarget(&dynlights->mo[j], NULL); + continue; + } + // check bounding box first if (SphereTouchBBox3D(&wlVerts[2], &wlVerts[0], &LIGHT_POS(j), DL_RADIUS(j))==false) continue; @@ -805,8 +813,6 @@ void HWR_WallLighting(FOutVector *wlVerts) #ifdef DL_HIGH_QUALITY Surf.FlatColor.s.alpha = (UINT8)((1-dist_p2d/DL_SQRRADIUS(j))*Surf.FlatColor.s.alpha); #endif - if (!dynlights->mo[j]->state) - return; // next state is null so fade out with alpha if (dynlights->mo[j]->state->nextstate == S_NULL) Surf.FlatColor.s.alpha = (UINT8)(((float)dynlights->mo[j]->tics/(float)dynlights->mo[j]->state->tics)*Surf.FlatColor.s.alpha); @@ -837,6 +843,14 @@ void HWR_PlaneLighting(FOutVector *clVerts, int nrClipVerts) FSurfaceInfo Surf; float dist_p2d, s; + if (!dynlights->mo[j]) + continue; + if (P_MobjWasRemoved(dynlights->mo[j])) + { + P_SetTarget(&dynlights->mo[j], NULL); + continue; + } + // BP: The kickass Optimization: check if light touch bounding box if (SphereTouchBBox3D(&p1, &p2, &dynlights->position[j], DL_RADIUS(j))==false) continue; @@ -868,8 +882,6 @@ void HWR_PlaneLighting(FOutVector *clVerts, int nrClipVerts) #ifdef DL_HIGH_QUALITY Surf.FlatColor.s.alpha = (unsigned char)((1 - dist_p2d/DL_SQRRADIUS(j))*Surf.FlatColor.s.alpha); #endif - if (!dynlights->mo[j]->state) - return; // next state is null so fade out with alpha if ((dynlights->mo[j]->state->nextstate == S_NULL)) Surf.FlatColor.s.alpha = (unsigned char)(((float)dynlights->mo[j]->tics/(float)dynlights->mo[j]->state->tics)*Surf.FlatColor.s.alpha); @@ -1000,6 +1012,14 @@ void HWR_DrawCoronas(void) if (!(p_lspr->type & CORONA_SPR)) continue; + if (!dynlights->mo[j]) + continue; + if (P_MobjWasRemoved(dynlights->mo[j])) + { + P_SetTarget(&dynlights->mo[j], NULL); + continue; + } + transform(&cx,&cy,&cz); // more realistique corona ! @@ -1061,7 +1081,8 @@ void HWR_DrawCoronas(void) // -------------------------------------------------------------------------- void HWR_ResetLights(void) { - dynlights->nb = 0; + while (dynlights->nb) + P_SetTarget(&dynlights->mo[--dynlights->nb], NULL); } // -------------------------------------------------------------------------- @@ -1092,24 +1113,25 @@ void HWR_DL_AddLight(gr_vissprite_t *spr, GLPatch_t *patch) return; #endif + if (dynlights->nb >= DL_MAX_LIGHT) + return; + // check if sprite contain dynamic light p_lspr = t_lspr[spr->mobj->sprite]; - if ((p_lspr->type&DYNLIGHT_SPR) - && ((p_lspr->type != LIGHT_SPR) || cv_grstaticlighting.value) - && (dynlights->nb < DL_MAX_LIGHT) + if (!(p_lspr->type & DYNLIGHT_SPR)) + return; + if ((p_lspr->type != LIGHT_SPR) || cv_grstaticlighting.value) + return; - && spr->mobj->state) - { - LIGHT_POS(dynlights->nb).x = FIXED_TO_FLOAT(spr->mobj->x); - LIGHT_POS(dynlights->nb).y = FIXED_TO_FLOAT(spr->mobj->z)+FIXED_TO_FLOAT(spr->mobj->height>>1)+p_lspr->light_yoffset; - LIGHT_POS(dynlights->nb).z = FIXED_TO_FLOAT(spr->mobj->y); + LIGHT_POS(dynlights->nb).x = FIXED_TO_FLOAT(spr->mobj->x); + LIGHT_POS(dynlights->nb).y = FIXED_TO_FLOAT(spr->mobj->z)+FIXED_TO_FLOAT(spr->mobj->height>>1)+p_lspr->light_yoffset; + LIGHT_POS(dynlights->nb).z = FIXED_TO_FLOAT(spr->mobj->y); - P_SetTarget(&dynlights->mo[dynlights->nb], spr->mobj); + P_SetTarget(&dynlights->mo[dynlights->nb], spr->mobj); - dynlights->p_lspr[dynlights->nb] = p_lspr; + dynlights->p_lspr[dynlights->nb] = p_lspr; - dynlights->nb++; - } + dynlights->nb++; } static GLPatch_t lightmappatch; @@ -1263,6 +1285,14 @@ static void HWR_CheckSubsector(size_t num, fixed_t *bbox) // if (CircleTouchBBox(&p1, &p2, &LIGHT_POS(lightnum), DL_RADIUS(lightnum))==false) // continue; + if (!dynlights->mo[lightnum]) + continue; + if (P_MobjWasRemoved(dynlights->mo[lightnum])) + { + P_SetTarget(&dynlights->mo[lightnum], NULL); + continue; + } + count = sub->numlines; // how many linedefs line = &segs[sub->firstline]; // first line seg while (count--) @@ -1280,18 +1310,20 @@ static void HWR_CheckSubsector(size_t num, fixed_t *bbox) // -------------------------------------------------------------------------- static void HWR_AddMobjLights(mobj_t *thing) { - if (t_lspr[thing->sprite]->type & CORONA_SPR) - { - LIGHT_POS(dynlights->nb).x = FIXED_TO_FLOAT(thing->x); - LIGHT_POS(dynlights->nb).y = FIXED_TO_FLOAT(thing->z) + t_lspr[thing->sprite]->light_yoffset; - LIGHT_POS(dynlights->nb).z = FIXED_TO_FLOAT(thing->y); + if (dynlights->nb >= DL_MAX_LIGHT) + return; + if (!(t_lspr[thing->sprite]->type & CORONA_SPR)) + return; - dynlights->p_lspr[dynlights->nb] = t_lspr[thing->sprite]; + LIGHT_POS(dynlights->nb).x = FIXED_TO_FLOAT(thing->x); + LIGHT_POS(dynlights->nb).y = FIXED_TO_FLOAT(thing->z) + t_lspr[thing->sprite]->light_yoffset; + LIGHT_POS(dynlights->nb).z = FIXED_TO_FLOAT(thing->y); - dynlights->nb++; - if (dynlights->nb > DL_MAX_LIGHT) - dynlights->nb = DL_MAX_LIGHT; - } + P_SetTarget(&dynlights->mo[dynlights->nb], thing); + + dynlights->p_lspr[dynlights->nb] = t_lspr[thing->sprite]; + + dynlights->nb++; } //Hurdler: The goal of this function is to walk through all the bsp starting @@ -1318,7 +1350,8 @@ static void HWR_SearchLightsInMobjs(void) // search in the list of thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) - HWR_AddMobjLights((mobj_t *)th); + if (th->function.acp1 != (actionf_p1)P_RemoveThinkerDelayed) + HWR_AddMobjLights((mobj_t *)th); } #endif @@ -1330,7 +1363,7 @@ void HWR_CreateStaticLightmaps(int bspnum) #ifdef STATICLIGHT CONS_Debug(DBG_RENDER, "HWR_CreateStaticLightmaps\n"); - dynlights->nb = 0; + HWR_ResetLights(); // First: Searching for lights // BP: if i was you, I will make it in create mobj since mobj can be create @@ -1341,8 +1374,6 @@ void HWR_CreateStaticLightmaps(int bspnum) // Second: Build all lightmap for walls covered by lights validcount++; // to be sure HWR_ComputeLightMapsInBSPNode(bspnum, NULL); - - dynlights->nb = 0; #else (void)bspnum; #endif diff --git a/src/lua_blockmaplib.c b/src/lua_blockmaplib.c index dabbdd9f6..2383bb32e 100644 --- a/src/lua_blockmaplib.c +++ b/src/lua_blockmaplib.c @@ -54,10 +54,12 @@ static UINT8 lib_searchBlockmap_Objects(lua_State *L, INT32 x, INT32 y, mobj_t * CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); lua_pop(gL, 1); blockfuncerror = true; + P_SetTarget(&bnext, NULL); return 0; // *shrugs* } if (!lua_isnil(gL, -1)) { // if nil, continue + P_SetTarget(&bnext, NULL); if (lua_toboolean(gL, -1)) return 2; // stop whole search else diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index dfb344e34..72e445afa 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -260,10 +260,19 @@ static int mobj_get(lua_State *L) // bprev -- same deal as sprev above, but for the blockmap. return UNIMPLEMENTED; case mobj_hnext: + if (mo->hnext && P_MobjWasRemoved(mo->hnext)) + { // don't put invalid mobj back into Lua. + P_SetTarget(&mo->hnext, NULL); + return 0; + } LUA_PushUserdata(L, mo->hnext, META_MOBJ); break; case mobj_hprev: - // implimented differently from sprev and bprev because SSNTails. + if (mo->hprev && P_MobjWasRemoved(mo->hprev)) + { // don't put invalid mobj back into Lua. + P_SetTarget(&mo->hprev, NULL); + return 0; + } LUA_PushUserdata(L, mo->hprev, META_MOBJ); break; case mobj_type: diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 3cca1f91f..090e384be 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -405,6 +405,26 @@ static int player_set(lua_State *L) // else if (fastcmp(field,"charflags")) plr->charflags = (UINT32)luaL_checkinteger(L, 3); + else if (fastcmp(field,"thokitem")) + plr->thokitem = luaL_checkinteger(L, 3); + else if (fastcmp(field,"spinitem")) + plr->spinitem = luaL_checkinteger(L, 3); + else if (fastcmp(field,"revitem")) + plr->revitem = luaL_checkinteger(L, 3); + else if (fastcmp(field,"followitem")) + plr->followitem = luaL_checkinteger(L, 3); + else if (fastcmp(field,"actionspd")) + plr->actionspd = (INT32)luaL_checkinteger(L, 3); + else if (fastcmp(field,"mindash")) + plr->mindash = (INT32)luaL_checkinteger(L, 3); + else if (fastcmp(field,"maxdash")) + plr->maxdash = (INT32)luaL_checkinteger(L, 3); + else if (fastcmp(field,"jumpfactor")) + plr->jumpfactor = (INT32)luaL_checkinteger(L, 3); + else if (fastcmp(field,"height")) + plr->height = luaL_checkfixed(L, 3); + else if (fastcmp(field,"spinheight")) + plr->spinheight = luaL_checkfixed(L, 3); else if (fastcmp(field,"lives")) plr->lives = (SINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"continues")) @@ -476,9 +496,19 @@ static int player_set(lua_State *L) else if (fastcmp(field,"old_angle_pos")) plr->old_angle_pos = luaL_checkangle(L, 3); else if (fastcmp(field,"axis1")) - P_SetTarget(&plr->axis1, *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ))); + { + mobj_t *mo = NULL; + if (!lua_isnil(L, 3)) + mo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); + P_SetTarget(&plr->axis1, mo); + } else if (fastcmp(field,"axis2")) - P_SetTarget(&plr->axis2, *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ))); + { + mobj_t *mo = NULL; + if (!lua_isnil(L, 3)) + mo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); + P_SetTarget(&plr->axis2, mo); + } else if (fastcmp(field,"bumpertime")) plr->bumpertime = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"flyangle")) diff --git a/src/lua_script.c b/src/lua_script.c index ef6faf600..ee2f56c97 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1027,14 +1027,16 @@ void LUA_Archive(void) } //if (gamestate == GS_LEVEL) - for (i = 0; i < NUM_THINKERLISTS; i++) - for (th = thlist[i].next; th != &thlist[i]; th = th->next) - if (th->function.acp1 == (actionf_p1)P_MobjThinker) - { - // archive function will determine when to skip mobjs, - // and write mobjnum in otherwise. - ArchiveExtVars(th, "mobj"); - } + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + // archive function will determine when to skip mobjs, + // and write mobjnum in otherwise. + ArchiveExtVars(th, "mobj"); + } + WRITEUINT32(save_p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. LUAh_NetArchiveHook(NetArchive); // call the NetArchive hook in archive mode @@ -1062,11 +1064,14 @@ void LUA_UnArchive(void) do { mobjnum = READUINT32(save_p); // read a mobjnum - for (i = 0; i < NUM_THINKERLISTS; i++) - for (th = thlist[i].next; th != &thlist[i]; th = th->next) - if (th->function.acp1 == (actionf_p1)P_MobjThinker - && ((mobj_t *)th)->mobjnum == mobjnum) // find matching mobj - UnArchiveExtVars(th); // apply variables + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj + continue; + UnArchiveExtVars(th); // apply variables + } } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. LUAh_NetArchiveHook(NetUnArchive); // call the NetArchive hook in unarchive mode diff --git a/src/m_cheat.c b/src/m_cheat.c index 3bf18c981..2f53ffbfc 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -914,10 +914,14 @@ static mapthing_t *OP_CreateNewMapThing(player_t *player, UINT16 type, boolean c for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo = (mobj_t *)th; // get offset from mt, which points to old mapthings, then add new location - if (mo->spawnpoint) - mo->spawnpoint = (mo->spawnpoint - mt) + mapthings; + if (!mo->spawnpoint) + continue; + mo->spawnpoint = (mo->spawnpoint - mt) + mapthings; } } diff --git a/src/p_enemy.c b/src/p_enemy.c index 1e055cc9d..09a476a08 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -2149,7 +2149,7 @@ void A_Boss1Laser(mobj_t *actor) if (z - floorz < mobjinfo[MT_EGGMOBILE_FIRE].height>>1) { point = P_SpawnMobj(x, y, floorz+1, MT_EGGMOBILE_FIRE); - point->target = actor; + P_SetTarget(&point->target, actor); point->destscale = 3*FRACUNIT; point->scalespeed = FRACUNIT>>2; point->fuse = TICRATE; @@ -2530,10 +2530,11 @@ void A_1upThinker(mobj_t *actor) if (closestplayer == -1 || skins[players[closestplayer].skin].spritedef.numframes <= states[S_PLAY_BOX1].frame) { // Closest player not found (no players in game?? may be empty dedicated server!), or does not have correct sprite. - actor->frame = 0; - if (actor->tracer) { - P_RemoveMobj(actor->tracer); - actor->tracer = NULL; + if (actor->tracer) + { + mobj_t *tracer = actor->tracer; + P_SetTarget(&actor->tracer, NULL); + P_RemoveMobj(tracer); } return; } @@ -2747,6 +2748,9 @@ void A_BossDeath(mobj_t *mo) // if all bosses are dead for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2 != mo && (mo2->flags & MF_BOSS) && mo2->health > 0) goto bossjustdie; // other boss not dead - just go straight to dying! @@ -2799,12 +2803,12 @@ bossjustdie: P_SetTarget(&mo->target, NULL); - // Flee! Flee! Find a point to escape to! If none, just shoot upward! - // scan the thinkers to find the runaway point - for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; + // Flee! Flee! Find a point to escape to! If none, just shoot upward! + // scan the thinkers to find the runaway point + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; mo2 = (mobj_t *)th; @@ -5436,6 +5440,9 @@ void A_RingExplode(mobj_t *actor) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2 == actor) // Don't explode yourself! Endless loop! @@ -6532,7 +6539,7 @@ void A_Boss2PogoTarget(mobj_t *actor) if (actor->info->missilestate) // spawn the pogo stick collision box { mobj_t *pogo = P_SpawnMobj(actor->x, actor->y, actor->z - mobjinfo[actor->info->missilestate].height, (mobjtype_t)actor->info->missilestate); - pogo->target = actor; + P_SetTarget(&pogo->target, actor); } actor->reactiontime = 1; @@ -7072,6 +7079,19 @@ void A_Boss3Path(mobj_t *actor) mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && mo2->spawnpoint->angle == actor->threshold) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + if (mo2->type != MT_BOSS3WAYPOINT) + continue; + if (!mo2->spawnpoint) + continue; + if (mo2->spawnpoint->angle != actor->threshold) + continue; + if (mo2->spawnpoint->extrainfo != actor->cusval) + continue; + P_SetTarget(&actor->target, mo2); break; } @@ -7456,6 +7476,9 @@ void A_FindTarget(mobj_t *actor) // scan the thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type == (mobjtype_t)locvar1) @@ -7518,6 +7541,9 @@ void A_FindTracer(mobj_t *actor) // scan the thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type == (mobjtype_t)locvar1) @@ -8078,6 +8104,9 @@ void A_RemoteAction(mobj_t *actor) // scan the thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type == (mobjtype_t)locvar1) @@ -9118,7 +9147,7 @@ void A_CheckThingCount(mobj_t *actor) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) continue; mo2 = (mobj_t *)th; diff --git a/src/p_floor.c b/src/p_floor.c index 352f8d79f..4231d0ad6 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -1974,17 +1974,25 @@ void T_ThwompSector(levelspecthink_t *thwomp) // scan the thinkers to find players! if (!rover || (rover->flags & FF_EXISTS)) { - // scan the thinkers to find players! - for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + UINT8 i; + // scan the players to find victims! + for (i = 0; i < MAXPLAYERS; i++) { - mo = (mobj_t *)th; - if (mo->type == MT_PLAYER && mo->health && mo->player && !mo->player->spectator - && mo->z <= thwomp->sector->ceilingheight - && P_AproxDistance(thwompx - mo->x, thwompy - mo->y) <= 96*FRACUNIT) - { - thwomp->direction = -1; - break; - } + if (!playeringame[i]) + continue; + if (players[i].spectator) + continue; + if (!players[i].mo) + continue; + if (!players[i].mo->health) + continue; + if (players[i].mo->z > thwomp->sector->ceilingheight) + continue; + if (P_AproxDistance(thwompx - players[i].mo->x, thwompy - players[i].mo->y) > 96 * FRACUNIT) + continue; + + thwomp->direction = -1; + break; } }*/ diff --git a/src/p_inter.c b/src/p_inter.c index 09589c880..404b4b38f 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -949,6 +949,60 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) if (toucher->tracer && toucher->tracer->target && toucher->tracer->target->type == MT_GOTEMERALD) { + mobj_t *orbittarget = special->target ? special->target : special; + mobj_t *hnext = orbittarget->hnext, *anchorpoint = NULL, *anchorpoint2 = NULL; + mobj_t *mo2; + thinker_t *th; + + // The player might have two Ideyas: toucher->tracer and toucher->tracer->hnext + // so handle their anchorpoints accordingly. + // scan the thinkers to find the corresponding anchorpoint + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + + if (mo2->type != MT_IDEYAANCHOR) + continue; + + if (mo2->health == toucher->tracer->health) // do ideya numberes match? + anchorpoint = mo2; + else if (toucher->tracer->hnext && mo2->health == toucher->tracer->hnext->health) + anchorpoint2 = mo2; + + if ((!toucher->tracer->hnext && anchorpoint) + || (toucher->tracer->hnext && anchorpoint && anchorpoint2)) + break; + } + + if (anchorpoint) + { + toucher->tracer->flags |= MF_GRENADEBOUNCE; // custom radius factors + toucher->tracer->threshold = 8 << 20; // X factor 0, Y factor 0, Z factor 8 + } + + if (anchorpoint2) + { + toucher->tracer->hnext->flags |= MF_GRENADEBOUNCE; // custom radius factors + toucher->tracer->hnext->threshold = 8 << 20; // X factor 0, Y factor 0, Z factor 8 + } + + P_SetTarget(&orbittarget->hnext, toucher->tracer); + if (!orbittarget->hnext->hnext) + P_SetTarget(&orbittarget->hnext->hnext, hnext); // Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo. + else + P_SetTarget(&orbittarget->hnext->hnext->target, anchorpoint2 ? anchorpoint2 : orbittarget); + P_SetTarget(&orbittarget->hnext->target, anchorpoint ? anchorpoint : orbittarget); + P_SetTarget(&toucher->tracer, NULL); + + if (hnext) + { + orbittarget->hnext->extravalue1 = (angle_t)(hnext->extravalue1 - 72*ANG1); + if (orbittarget->hnext->extravalue1 > hnext->extravalue1) + orbittarget->hnext->extravalue1 -= (72*ANG1)/orbittarget->hnext->extravalue1; + } } else // Make sure that SOMEONE has the emerald, at least! { @@ -998,6 +1052,9 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) // scan the remaining thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2 == special) @@ -1045,6 +1102,9 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) // in from the paraloop. Isn't this just so efficient? for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (P_AproxDistance(P_AproxDistance(mo2->x - x, mo2->y - y), mo2->z - z) > gatherradius) @@ -1411,6 +1471,9 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) // scan the remaining thinkers to find koopa for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type == MT_KOOPA) { diff --git a/src/p_local.h b/src/p_local.h index f0e530ef4..e44137449 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -60,8 +60,8 @@ #define mariomode (maptol & TOL_MARIO) #define twodlevel (maptol & TOL_2D) -typedef enum{ - THINK_LIMBO, +typedef enum +{ THINK_POLYOBJ, THINK_MAIN, THINK_MOBJ, diff --git a/src/p_maputl.c b/src/p_maputl.c index 355c58db8..425aa60fb 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -1093,7 +1093,10 @@ boolean P_BlockThingsIterator(INT32 x, INT32 y, boolean (*func)(mobj_t *)) { P_SetTarget(&bnext, mobj->bnext); // We want to note our reference to bnext here incase it is MF_NOTHINK and gets removed! if (!func(mobj)) + { + P_SetTarget(&bnext, NULL); return false; + } if (P_MobjWasRemoved(tmthing) // func just popped our tmthing, cannot continue. || (bnext && P_MobjWasRemoved(bnext))) // func just broke blockmap chain, cannot continue. { diff --git a/src/p_mobj.c b/src/p_mobj.c index 85731a062..4cfcebc1b 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -423,6 +423,9 @@ boolean P_WeaponOrPanel(mobjtype_t type) for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { + if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo = (mobj_t *)think; if (mo->type == MT_EMERALDSPAWN) @@ -3497,6 +3500,9 @@ void P_DestroyRobots(void) for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { + if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo = (mobj_t *)think; if (mo->health <= 0 || !(mo->flags & MF_ENEMY || mo->flags & MF_BOSS)) continue; // not a valid enemy @@ -4301,6 +4307,9 @@ static void P_Boss3Thinker(mobj_t *mobj) // this can happen if the boss was hurt earlier than expected for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type == (mobjtype_t)mobj->info->mass && mo2->tracer == mobj) { @@ -4392,7 +4401,20 @@ static void P_Boss3Thinker(mobj_t *mobj) mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && mo2->spawnpoint->angle == mobj->threshold) { - P_SetTarget(&mobj->target, mo2); + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + if (mo2->type != MT_BOSS3WAYPOINT) + continue; + if (!mo2->spawnpoint) + continue; + if (mo2->spawnpoint->angle != mobj->threshold) + continue; + if (mo2->spawnpoint->extrainfo != mobj->cusval) + continue; + + P_SetTarget(&mobj->tracer, mo2); break; } } @@ -4631,8 +4653,8 @@ static void P_Boss4Thinker(mobj_t *mobj) P_SetTarget(&seg->target, mobj); for (i = 0; i < 9; i++) { - seg->hnext = P_SpawnMobj(mobj->x, mobj->y, z, MT_EGGMOBILE4_MACE); - seg->hnext->hprev = seg; + P_SetTarget(&seg->hnext, P_SpawnMobj(mobj->x, mobj->y, z, MT_EGGMOBILE4_MACE)); + P_SetTarget(&seg->hnext->hprev, seg); seg = seg->hnext; } } @@ -5007,6 +5029,9 @@ static void P_Boss7Thinker(mobj_t *mobj) // Find waypoint he is closest to for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint) { @@ -5059,6 +5084,9 @@ static void P_Boss7Thinker(mobj_t *mobj) // the waypoint to use for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && (mo2->spawnpoint->options & 7) == waypointNum) { @@ -5179,14 +5207,17 @@ static void P_Boss9Thinker(mobj_t *mobj) // Build a hoop linked list of 'em! for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS9GATHERPOINT) { if (last) - last->hnext = mo2; + P_SetTarget(&last->hnext, mo2); else - mobj->hnext = mo2; - mo2->hprev = last; + P_SetTarget(&mobj->hnext, mo2); + P_SetTarget(&mo2->hprev, last); last = mo2; } } @@ -5610,6 +5641,9 @@ mobj_t *P_GetClosestAxis(mobj_t *source) // scan the thinkers to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type == MT_AXIS) @@ -6135,12 +6169,14 @@ static void P_RemoveOverlay(mobj_t *thing) { mobj_t *mo; for (mo = overlaycap; mo; mo = mo->hnext) - if (mo->hnext == thing) - { - P_SetTarget(&mo->hnext, thing->hnext); - P_SetTarget(&thing->hnext, NULL); - return; - } + { + if (mo->hnext != thing) + continue; + + P_SetTarget(&mo->hnext, thing->hnext); + P_SetTarget(&thing->hnext, NULL); + return; + } } void P_RunShadows(void) @@ -9989,7 +10025,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) } if (!(mobj->flags & MF_NOTHINK)) - P_AddThinker(&mobj->thinker); + P_AddThinker(THINK_MOBJ, &mobj->thinker); // Call action functions when the state is set if (st->action.acp1 && (mobj->flags & MF_RUNSPAWNFUNC)) @@ -10305,37 +10341,28 @@ void P_RemoveMobj(mobj_t *mobj) } } - // free block // DBG: set everything in mobj_t to 0xFF instead of leaving it. debug memory error. - if (mobj->flags & MF_NOTHINK && !mobj->thinker.next) +#ifdef SCRAMBLE_REMOVED + // Invalidate mobj_t data to cause crashes if accessed! + memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); +#endif + + // free block + if (!mobj->thinker.next) { // Uh-oh, the mobj doesn't think, P_RemoveThinker would never go through! + INT32 prevreferences; if (!mobj->thinker.references) { -#ifdef SCRAMBLE_REMOVED - // Invalidate mobj_t data to cause crashes if accessed! - memset(mobj, 0xff, sizeof(mobj_t)); -#endif - Z_Free(mobj); // No refrences? Can be removed immediately! :D - } - else - { // Add thinker just to delay removing it until refrences are gone. - mobj->flags &= ~MF_NOTHINK; - P_AddThinker(THINK_MOBJ, (thinker_t *)mobj); -#ifdef SCRAMBLE_REMOVED - // Invalidate mobj_t data to cause crashes if accessed! - memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); -#endif - P_RemoveThinker((thinker_t *)mobj); + Z_Free(mobj); // No refrrences? Can be removed immediately! :D + return; } + + prevreferences = mobj->thinker.references; + P_AddThinker(THINK_MOBJ, (thinker_t *)mobj); + mobj->thinker.references = prevreferences; } - else - { -#ifdef SCRAMBLE_REMOVED - // Invalidate mobj_t data to cause crashes if accessed! - memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); -#endif - P_RemoveThinker((thinker_t *)mobj); - } + + P_RemoveThinker((thinker_t *)mobj); } // This does not need to be added to Lua. @@ -10593,7 +10620,7 @@ void P_RespawnSpecials(void) { thinker_t *th; - for (th = thinkercap.next; th != &thinkercap; th = th->next) + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { mobj_t *box; mobj_t *newmobj; @@ -11745,6 +11772,9 @@ ML_NOCLIMB : Direction not controllable // See if other starposts exist in this level that have the same value. for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2 == mobj) @@ -12020,7 +12050,7 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) //mobj->hprev->hnext = mobj; } else - mobj->hprev = mobj->hnext = NULL; + P_SetTarget(&mobj->hprev, P_SetTarget(&mobj->hnext, NULL)); nextmobj = mobj; } @@ -12046,11 +12076,9 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - mobj->hnext = NULL; + P_SetTarget(&mobj->hnext, NULL); P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); - //mobj->hprev = nextmobj; - //mobj->hprev->hnext = mobj; nextmobj = mobj; } @@ -12075,11 +12103,9 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - mobj->hnext = NULL; + P_SetTarget(&mobj->hnext, NULL); P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); - //mobj->hprev = nextmobj; - //mobj->hprev->hnext = mobj; nextmobj = mobj; } @@ -12168,7 +12194,7 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) //mobj->hprev->hnext = mobj; } else - mobj->hprev = mobj->hnext = NULL; + P_SetTarget(&mobj->hprev, P_SetTarget(&mobj->hnext, NULL)); nextmobj = mobj; } @@ -12205,11 +12231,9 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - mobj->hnext = NULL; + P_SetTarget(&mobj->hnext, NULL); P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); - //mobj->hprev = nextmobj; - //mobj->hprev->hnext = mobj; nextmobj = mobj; } diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 22477ff5d..25a7122ad 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1496,6 +1496,9 @@ void Polyobj_InitLevel(void) // the mobj_t pointers on a queue for use below. for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mobj_t *mo = (mobj_t *)th; if (mo->info->doomednum == POLYOBJ_SPAWN_DOOMEDNUM || @@ -1797,6 +1800,9 @@ void T_PolyObjWaypoint(polywaypoint_t *th) // We redo this each tic to make savegame compatibility easier. for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { + if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) @@ -1875,28 +1881,31 @@ void T_PolyObjWaypoint(polywaypoint_t *th) // Find next waypoint for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { + if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == th->sequence) + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) { - if (th->direction == -1) + if (mo2->health == target->health - 1) { - if (mo2->health == target->health - 1) - { - waypoint = mo2; - break; - } + waypoint = mo2; + break; } - else + } + else + { + if (mo2->health == target->health + 1) { - if (mo2->health == target->health + 1) - { - waypoint = mo2; - break; - } + waypoint = mo2; + break; } } } @@ -1911,27 +1920,30 @@ void T_PolyObjWaypoint(polywaypoint_t *th) for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { + if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == th->sequence) + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) { - if (th->direction == -1) + if (waypoint == NULL) + waypoint = mo2; + else if (mo2->health > waypoint->health) + waypoint = mo2; + } + else + { + if (mo2->health == 0) { - if (waypoint == NULL) - waypoint = mo2; - else if (mo2->health > waypoint->health) - waypoint = mo2; - } - else - { - if (mo2->health == 0) - { - waypoint = mo2; - break; - } + waypoint = mo2; + break; } } } @@ -1945,28 +1957,31 @@ void T_PolyObjWaypoint(polywaypoint_t *th) for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { + if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == th->sequence) + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) { - if (th->direction == -1) + if (mo2->health == target->health - 1) { - if (mo2->health == target->health - 1) - { - waypoint = mo2; - break; - } + waypoint = mo2; + break; } - else + } + else + { + if (mo2->health == target->health + 1) { - if (mo2->health == target->health + 1) - { - waypoint = mo2; - break; - } + waypoint = mo2; + break; } } } @@ -2454,36 +2469,39 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) // Find the first waypoint we need to use for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { + if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == th->sequence) + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) // highest waypoint # { - if (th->direction == -1) // highest waypoint # + if (mo2->health == 0) + last = mo2; + else { - if (mo2->health == 0) - last = mo2; - else - { - if (first == NULL) - first = mo2; - else if (mo2->health > first->health) - first = mo2; - } - } - else // waypoint 0 - { - if (mo2->health == 0) + if (first == NULL) first = mo2; - else - { - if (last == NULL) - last = mo2; - else if (mo2->health > last->health) - last = mo2; - } + else if (mo2->health > first->health) + first = mo2; + } + } + else // waypoint 0 + { + if (mo2->health == 0) + first = mo2; + else + { + if (last == NULL) + last = mo2; + else if (mo2->health > last->health) + last = mo2; } } } @@ -2522,28 +2540,31 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) target = first; /*for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next) { + if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == th->sequence) + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) // highest waypoint # { - if (th->direction == -1) // highest waypoint # + if (mo2->health == first->health - 1) { - if (mo2->health == first->health - 1) - { - target = mo2; - break; - } + target = mo2; + break; } - else // waypoint 0 + } + else // waypoint 0 + { + if (mo2->health == first->health + 1) { - if (mo2->health == first->health + 1) - { - target = mo2; - break; - } + target = mo2; + break; } } }*/ diff --git a/src/p_saveg.c b/src/p_saveg.c index 712773cbc..a544b5c1e 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1698,7 +1698,6 @@ static void P_NetArchiveThinkers(void) for (i = 0; i < NUM_THINKERLISTS; i++) { UINT32 numsaved = 0; - // save off the current thinkers for (th = thlist[i].next; th != &thlist[i]; th = th->next) { @@ -1892,12 +1891,12 @@ static void P_NetArchiveThinkers(void) } #endif #ifdef PARANOIA - else if (th->function.acv != P_RemoveThinkerDelayed) // wait garbage collection + else if (th->function.acp1 != P_RemoveThinkerDelayed) // wait garbage collection I_Error("unknown thinker type %p", th->function.acp1); #endif } - CONS_Debug(DBG_NETPLAY, "%u thinkers saved\n", numsaved); + CONS_Debug(DBG_NETPLAY, "%u thinkers saved in list %d\n", numsaved, i); WRITEUINT8(save_p, tc_end); } @@ -1914,9 +1913,14 @@ mobj_t *P_FindNewPosition(UINT32 oldposition) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mobj = (mobj_t *)th; - if (mobj->mobjnum == oldposition) - return mobj; + if (mobj->mobjnum != oldposition) + continue; + + return mobj; } CONS_Debug(DBG_GAMELOGIC, "mobj not found\n"); return NULL; @@ -2884,22 +2888,22 @@ static void P_NetUnArchiveThinkers(void) P_AddThinker(i, th); } - CONS_Debug(DBG_NETPLAY, "%u thinkers loaded\n", numloaded); + CONS_Debug(DBG_NETPLAY, "%u thinkers loaded in list %d\n", numloaded, i); + } - if (restoreNum) + if (restoreNum) + { + executor_t *delay = NULL; + UINT32 mobjnum; + for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; + currentthinker = currentthinker->next) { - executor_t *delay = NULL; - UINT32 mobjnum; - for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; - currentthinker = currentthinker->next) - { - if (currentthinker->function.acp1 == (actionf_p1)T_ExecutorDelay) - { - delay = (void *)currentthinker; - if ((mobjnum = (UINT32)(size_t)delay->caller)) - delay->caller = P_FindNewPosition(mobjnum); - } - } + if (currentthinker->function.acp1 != (actionf_p1)T_ExecutorDelay) + continue; + delay = (void *)currentthinker; + if (!(mobjnum = (UINT32)(size_t)delay->caller)) + continue; + delay->caller = P_FindNewPosition(mobjnum); } } } @@ -3010,6 +3014,9 @@ static inline void P_FinishMobjs(void) for (currentthinker = thlist[THINK_MOBJ].next; currentthinker != &thlist[THINK_MOBJ]; currentthinker = currentthinker->next) { + if (currentthinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mobj = (mobj_t *)currentthinker; mobj->info = &mobjinfo[mobj->type]; } @@ -3025,6 +3032,9 @@ static void P_RelinkPointers(void) for (currentthinker = thlist[THINK_MOBJ].next; currentthinker != &thlist[THINK_MOBJ]; currentthinker = currentthinker->next) { + if (currentthinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mobj = (mobj_t *)currentthinker; if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) @@ -3457,6 +3467,9 @@ void P_SaveNetGame(void) //if (gamestate == GS_LEVEL) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mobj = (mobj_t *)th; if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) continue; diff --git a/src/p_setup.c b/src/p_setup.c index ed2fd35f9..aac08d6be 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -835,6 +835,9 @@ void P_ReloadRings(void) // scan the thinkers to find rings/spheres/hoops to unset for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo = (mobj_t *)th; if (mo->type == MT_HOOPCENTER) @@ -2408,15 +2411,13 @@ static void P_LevelInitStuff(void) void P_LoadThingsOnly(void) { // Search through all the thinkers. - mobj_t *mo; thinker_t *think; for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - mo = (mobj_t *)think; - - if (mo) - P_RemoveMobj(mo); + if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + P_RemoveMobj((mobj_t *)think); } P_LevelInitStuff(); diff --git a/src/p_spec.c b/src/p_spec.c index b11a7e69b..bd6c2e79d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2058,7 +2058,7 @@ void P_SwitchWeather(INT32 weathernum) thinker_t *think; precipmobj_t *precipmobj; - for (think = thlist[THINK_MAIN].next; think != &thlist[THINK_MAIN]; think = think->next) + for (think = thlist[THINK_PRECIP].next; think != &thlist[THINK_PRECIP]; think = think->next) { if (think->function.acp1 != (actionf_p1)P_NullPrecipThinker) continue; // not a precipmobj thinker @@ -2074,7 +2074,7 @@ void P_SwitchWeather(INT32 weathernum) precipmobj_t *precipmobj; state_t *st; - for (think = thlist[THINK_MAIN].next; think != &thlist[THINK_MAIN]; think = think->next) + for (think = thlist[THINK_PRECIP].next; think != &thlist[THINK_PRECIP]; think = think->next) { if (think->function.acp1 != (actionf_p1)P_NullPrecipThinker) continue; // not a precipmobj thinker @@ -3275,6 +3275,9 @@ void P_SetupSignExit(player_t *player) // spin all signposts in the level then. for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { + if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + thing = (mobj_t *)think; if (thing->type != MT_SIGN) continue; @@ -3317,20 +3320,18 @@ boolean P_IsFlagAtBase(mobjtype_t flag) { thinker_t *think; mobj_t *mo; - INT32 specialnum = 0; + INT32 specialnum = (flag == MT_REDFLAG) ? 3 : 4; for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { + if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo = (mobj_t *)think; if (mo->type != flag) continue; - if (mo->type == MT_REDFLAG) - specialnum = 3; - else if (mo->type == MT_BLUEFLAG) - specialnum = 4; - if (GETSECSPECIAL(mo->subsector->sector->special, 4) == specialnum) return true; else if (mo->subsector->sector->ffloors) // Check the 3D floors @@ -3345,9 +3346,11 @@ boolean P_IsFlagAtBase(mobjtype_t flag) if (GETSECSPECIAL(rover->master->frontsector->special, 4) != specialnum) continue; - if (mo->z <= P_GetSpecialTopZ(mo, sectors + rover->secnum, mo->subsector->sector) - && mo->z >= P_GetSpecialBottomZ(mo, sectors + rover->secnum, mo->subsector->sector)) - return true; + if (!(mo->z <= P_GetSpecialTopZ(mo, sectors + rover->secnum, mo->subsector->sector) + && mo->z >= P_GetSpecialBottomZ(mo, sectors + rover->secnum, mo->subsector->sector))) + continue; + + return true; } } } @@ -3759,9 +3762,12 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers // The chimps are my friends.. heeheeheheehehee..... - LouisJM for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; mo2 = (mobj_t *)th; - if (mo2->type == MT_EGGTRAP) - P_KillMobj(mo2, NULL, player->mo); + if (mo2->type != MT_EGGTRAP) + continue; + P_KillMobj(mo2, NULL, player->mo, 0); } // clear the special so you can't push the button twice. @@ -4093,14 +4099,20 @@ DoneSection2: // to find the first waypoint for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; - if (mo2->type == MT_TUBEWAYPOINT && mo2->threshold == sequence - && mo2->health == 0) - { - waypoint = mo2; - break; - } + if (mo2->type != MT_TUBEWAYPOINT) + continue; + if (mo2->threshold != sequence) + continue; + if (mo2->health != 0) + continue; + + waypoint = mo2; + break; } if (!waypoint) @@ -4166,15 +4178,20 @@ DoneSection2: // to find the last waypoint for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; - if (mo2->type == MT_TUBEWAYPOINT && mo2->threshold == sequence) - { - if (!waypoint) - waypoint = mo2; - else if (mo2->health > waypoint->health) - waypoint = mo2; - } + if (mo2->type != MT_TUBEWAYPOINT) + continue; + if (mo2->threshold != sequence) + continue; + + if (!waypoint) + waypoint = mo2; + else if (mo2->health > waypoint->health) + waypoint = mo2; } if (!waypoint) @@ -4378,6 +4395,9 @@ DoneSection2: // to find the first waypoint for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) @@ -4413,6 +4433,9 @@ DoneSection2: // Find waypoint before this one (waypointlow) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) @@ -4437,6 +4460,9 @@ DoneSection2: // Find waypoint after this one (waypointhigh) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) diff --git a/src/p_tick.c b/src/p_tick.c index 009b9b6a3..e6fffb417 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -46,6 +46,9 @@ void Command_Numthinkers_f(void) INT32 count = 0; actionf_p1 action; thinker_t *think; + thinklistnum_t start = 0; + thinklistnum_t end = NUM_THINKERLISTS - 1; + thinklistnum_t i; if (gamestate != GS_LEVEL) { @@ -72,6 +75,7 @@ void Command_Numthinkers_f(void) switch (num) { case 1: + start = end = THINK_MOBJ; action = (actionf_p1)P_MobjThinker; CONS_Printf(M_GetText("Number of %s: "), "P_MobjThinker"); break; @@ -84,14 +88,17 @@ void Command_Numthinkers_f(void) CONS_Printf(M_GetText("Number of %s: "), "P_SnowThinker"); break;*/ case 2: + start = end = THINK_PRECIP; action = (actionf_p1)P_NullPrecipThinker; CONS_Printf(M_GetText("Number of %s: "), "P_NullPrecipThinker"); break; case 3: + start = end = THINK_MAIN; action = (actionf_p1)T_Friction; CONS_Printf(M_GetText("Number of %s: "), "T_Friction"); break; case 4: + start = end = THINK_MAIN; action = (actionf_p1)T_Pusher; CONS_Printf(M_GetText("Number of %s: "), "T_Pusher"); break; @@ -104,12 +111,15 @@ void Command_Numthinkers_f(void) return; } - for (think = thlist[THINK_MAIN].next; think != &thlist[THINK_MAIN]; think = think->next) + for (i = start; i <= end; i++) { - if (think->function.acp1 != action) - continue; + for (think = thlist[i].next; think != &thlist[i]; think = think->next) + { + if (think->function.acp1 != action) + continue; - count++; + count++; + } } CONS_Printf("%d\n", count); @@ -143,6 +153,9 @@ void Command_CountMobjs_f(void) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + if (((mobj_t *)th)->type == i) count++; } @@ -160,6 +173,9 @@ void Command_CountMobjs_f(void) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + if (((mobj_t *)th)->type == i) count++; } @@ -182,6 +198,10 @@ void P_InitThinkers(void) // Adds a new thinker at the end of the list. void P_AddThinker(const thinklistnum_t n, thinker_t *thinker) { +#ifdef PARANOIA + I_Assert(n >= 0 && n < NUM_THINKERLISTS); +#endif + thlist[n].prev->next = thinker; thinker->next = &thlist[n]; thinker->prev = thlist[n].prev; @@ -208,22 +228,33 @@ static thinker_t *currentthinker; // remove it, and set currentthinker to one node preceeding it, so // that the next step in P_RunThinkers() will get its successor. // -void P_RemoveThinkerDelayed(void *pthinker) +void P_RemoveThinkerDelayed(thinker_t *thinker) { - thinker_t *thinker = pthinker; - if (!thinker->references) + thinker_t *next; +#ifdef PARANOIA +#define BEENAROUNDBIT (0x40000000) // has to be sufficiently high that it's unlikely to happen in regular gameplay. If you change this, pay attention to the bit pattern of INT32_MIN. + if (thinker->references & ~BEENAROUNDBIT) { - { - /* Remove from main thinker list */ - thinker_t *next = thinker->next; - /* Note that currentthinker is guaranteed to point to us, - * and since we're freeing our memory, we had better change that. So - * point it to thinker->prev, so the iterator will correctly move on to - * thinker->prev->next = thinker->next */ - (next->prev = currentthinker = thinker->prev)->next = next; - } - Z_Free(thinker); + if (thinker->references & BEENAROUNDBIT) // Usually gets cleared up in one frame; what's going on here, then? + CONS_Printf("Number of potentially faulty references: %d\n", (thinker->references & ~BEENAROUNDBIT)); + thinker->references |= BEENAROUNDBIT; + return; } +#undef BEENAROUNDBIT +#else + if (thinker->references) + return; +#endif + + /* Remove from main thinker list */ + next = thinker->next; + /* Note that currentthinker is guaranteed to point to us, + * and since we're freeing our memory, we had better change that. So + * point it to thinker->prev, so the iterator will correctly move on to + * thinker->prev->next = thinker->next */ + (next->prev = currentthinker = thinker->prev)->next = next; + + Z_Free(thinker); } // @@ -240,23 +271,10 @@ void P_RemoveThinkerDelayed(void *pthinker) // void P_RemoveThinker(thinker_t *thinker) { - thinker_t *next = thinker->next; #ifdef HAVE_BLUA LUA_InvalidateUserdata(thinker); #endif - thinker->function.acp1 = P_RemoveThinkerDelayed; - - if (currentthinker == thinker) - currentthinker = thinker->prev; - - // Remove thinker from its current list. - (next->prev = thinker->prev)->next = next; - - // Now add it to the limbo list - thlist[THINK_LIMBO].prev->next = thinker; - thinker->next = &thlist[THINK_LIMBO]; - thinker->prev = thlist[THINK_LIMBO].prev; - thlist[THINK_LIMBO].prev = thinker; + thinker->function.acp1 = (actionf_p1)P_RemoveThinkerDelayed; } /* @@ -309,8 +327,10 @@ static inline void P_RunThinkers(void) { for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1) - currentthinker->function.acp1(currentthinker); +#ifdef PARANOIA + I_Assert(currentthinker->function.acp1 != NULL) +#endif + currentthinker->function.acp1(currentthinker); } } diff --git a/src/p_tick.h b/src/p_tick.h index 169c54c8e..8551ccc76 100644 --- a/src/p_tick.h +++ b/src/p_tick.h @@ -27,7 +27,7 @@ void Command_CountMobjs_f(void); void P_Ticker(boolean run); void P_PreTicker(INT32 frames); void P_DoTeamscrambling(void); -void P_RemoveThinkerDelayed(void *pthinker); //killed +void P_RemoveThinkerDelayed(thinker_t *thinker); //killed mobj_t *P_SetTarget(mobj_t **mo, mobj_t *target); // killough 11/98 #endif diff --git a/src/p_user.c b/src/p_user.c index b1dc9fae6..4f3011a65 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -358,9 +358,16 @@ void P_ResetScore(player_t *player) // to find the egg capsule with the lowest mare for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; - if (mo2->type == MT_EGGCAPSULE && mo2->health > 0) + if (mo2->type != MT_EGGCAPSULE) + continue; + if (mo2->health <= 0) + continue; + { const UINT8 threshold = (UINT8)mo2->threshold; if (mare == 255) @@ -456,29 +463,32 @@ UINT8 P_FindHighestLap(void) // to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; - if (mo2->type == MT_AXIS) - { - if (mo2->threshold == mare) - { - if (closestaxis == NULL) - { - closestaxis = mo2; - lowestaxisnum = mo2->health; - dist2 = R_PointToDist2(player->mo->x, player->mo->y, mo2->x, mo2->y)-mo2->radius; - } - else if (mo2->health < lowestaxisnum) - { - dist1 = R_PointToDist2(player->mo->x, player->mo->y, mo2->x, mo2->y)-mo2->radius; + if (mo2->type != MT_AXIS) + continue; - if (dist1 < dist2) - { - closestaxis = mo2; - lowestaxisnum = mo2->health; - dist2 = dist1; - } - } + if (mo2->threshold != mare) + continue; + + if (closestaxis == NULL) + { + closestaxis = mo2; + lowestaxisnum = mo2->health; + dist2 = R_PointToDist2(player->mo->x, player->mo->y, mo2->x, mo2->y) - mo2->radius; + } + else if (mo2->health < lowestaxisnum) + { + dist1 = R_PointToDist2(player->mo->x, player->mo->y, mo2->x, mo2->y) - mo2->radius; + + if (dist1 < dist2) + { + closestaxis = mo2; + lowestaxisnum = mo2->health; + dist2 = dist1; } } } @@ -504,17 +514,22 @@ static mobj_t *P_FindAxis(INT32 mare, INT32 axisnum) // to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; // Axis things are only at beginning of list. if (!(mo2->flags2 & MF2_AXIS)) return NULL; - if (mo2->type == MT_AXIS) - { - if (mo2->health == axisnum && mo2->threshold == mare) - return mo2; - } + if (mo2->type != MT_AXIS) + continue; + if (mo2->health != axisnum) + continue; + if (mo2->threshold != mare) + continue; + return mo2; } return NULL; @@ -534,17 +549,22 @@ static mobj_t *P_FindAxisTransfer(INT32 mare, INT32 axisnum, mobjtype_t type) // to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; // Axis things are only at beginning of list. if (!(mo2->flags2 & MF2_AXIS)) return NULL; - if (mo2->type == type) - { - if (mo2->health == axisnum && mo2->threshold == mare) - return mo2; - } + if (mo2->type != type) + continue; + if (mo2->health != axisnum) + continue; + if (mo2->threshold != mare) + continue; + return mo2; } return NULL; @@ -570,27 +590,31 @@ void P_TransferToAxis(player_t *player, INT32 axisnum) // to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; - if (mo2->type == MT_AXIS) - { - if (mo2->health == axisnum && mo2->threshold == mare) - { - if (closestaxis == NULL) - { - closestaxis = mo2; - dist2 = R_PointToDist2(player->mo->x, player->mo->y, mo2->x, mo2->y)-mo2->radius; - } - else - { - dist1 = R_PointToDist2(player->mo->x, player->mo->y, mo2->x, mo2->y)-mo2->radius; + if (mo2->type != MT_AXIS) + continue; + if (mo2->health != axisnum) + continue; + if (mo2->threshold != mare) + continue; - if (dist1 < dist2) - { - closestaxis = mo2; - dist2 = dist1; - } - } + if (closestaxis == NULL) + { + closestaxis = mo2; + dist2 = R_PointToDist2(player->mo->x, player->mo->y, mo2->x, mo2->y) - mo2->radius; + } + else + { + dist1 = R_PointToDist2(player->mo->x, player->mo->y, mo2->x, mo2->y) - mo2->radius; + + if (dist1 < dist2) + { + closestaxis = mo2; + dist2 = dist1; } } } @@ -666,6 +690,9 @@ static void P_DeNightserizePlayer(player_t *player) // Check to see if the player should be killed. for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (!(mo2->type == MT_NIGHTSDRONE)) continue; @@ -1577,6 +1604,9 @@ void P_SpawnShieldOrb(player_t *player) // blaze through the thinkers to see if an orb already exists! for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + shieldobj = (mobj_t *)th; if (shieldobj->type == orbtype && shieldobj->target == player->mo) @@ -3272,7 +3302,8 @@ static void P_DoTeeter(player_t *player) // SRB2kart - unused. if (teeter) // only bother with objects as a last resort if you were already teetering { mobj_t *oldtmthing = tmthing; - tmthing = teeterer = player->mo; + teeterer = player->mo; + P_SetTarget(&tmthing, teeterer); teeterxl = teeterxh = player->mo->x; teeteryl = teeteryh = player->mo->y; couldteeter = false; @@ -3286,7 +3317,7 @@ static void P_DoTeeter(player_t *player) // SRB2kart - unused. } teeterdone: teeter = solidteeter; - tmthing = oldtmthing; // restore old tmthing, goodness knows what the game does with this before mobj thinkers + P_SetTarget(&tmthing, oldtmthing); // restore old tmthing, goodness knows what the game does with this before mobj thinkers } } if (teeter) @@ -3599,11 +3630,177 @@ static void P_DoSpinDash(player_t *player, ticcmd_t *cmd) // SRB2kart - unused. #endif ) && !(player->pflags & PF_USEDOWN) && !(player->pflags & PF_SPINNING)) { - player->pflags |= PF_SPINNING; - //P_SetPlayerMobjState(player->mo, S_PLAY_ATK1); - if (!player->spectator) - S_StartSound(player->mo, sfx_spin); - player->pflags |= PF_USEDOWN; + case CA2_SPINDASH: // Spinning and Spindashing + // Start revving + if ((cmd->buttons & BT_USE) && player->speed < FixedMul(5<mo->scale) + && !player->mo->momz && onground && !(player->pflags & (PF_USEDOWN|PF_SPINNING)) + && canstand) + { + player->mo->momx = player->cmomx; + player->mo->momy = player->cmomy; + player->pflags |= (PF_USEDOWN|PF_STARTDASH|PF_SPINNING); + player->dashspeed = player->mindash; + P_SetPlayerMobjState(player->mo, S_PLAY_SPINDASH); + if (!player->spectator) + S_StartSound(player->mo, sfx_s3kab); // Make the rev sound! Previously sfx_spndsh. + } + // Revving + else if ((cmd->buttons & BT_USE) && (player->pflags & PF_STARTDASH)) + { + if (player->dashspeed < player->maxdash) + { +#define chargecalculation (6*(player->dashspeed - player->mindash))/(player->maxdash - player->mindash) + fixed_t soundcalculation = chargecalculation; + player->dashspeed += FRACUNIT; + if (!player->spectator && soundcalculation != chargecalculation) + S_StartSound(player->mo, sfx_s3kab); // Make the rev sound! Previously sfx_spndsh. +#undef chargecalculation + } + if (player->revitem && !(leveltime % 5)) // Now spawn the color thok circle. + { + P_SpawnSpinMobj(player, player->revitem); + if (demorecording) + G_GhostAddRev(); + } + } + + // If not moving up or down, and travelling faster than a speed of five while not holding + // down the spin button and not spinning. + // AKA Just go into a spin on the ground, you idiot. ;) + else if ((cmd->buttons & BT_USE || ((twodlevel || (player->mo->flags2 & MF2_TWOD)) && cmd->forwardmove < -20)) + && !player->climbing && !player->mo->momz && onground && (player->speed > FixedMul(5<mo->scale) + || !canstand) && !(player->pflags & (PF_USEDOWN|PF_SPINNING))) + { + player->pflags |= (PF_USEDOWN|PF_SPINNING); + P_SetPlayerMobjState(player->mo, S_PLAY_ROLL); + if (!player->spectator) + S_StartSound(player->mo, sfx_spin); + } + else + // Catapult the player from a spindash rev! + if (onground && !(player->pflags & PF_USEDOWN) && (player->pflags & PF_STARTDASH) && (player->pflags & PF_SPINNING)) + { + player->pflags &= ~PF_STARTDASH; + if (player->powers[pw_carry] == CR_BRAKGOOP) + player->dashspeed = 0; + + if (!((gametype == GT_RACE || gametype == GT_COMPETITION) && leveltime < 4*TICRATE)) + { + if (player->dashspeed) + { + P_SetPlayerMobjState(player->mo, S_PLAY_ROLL); + P_InstaThrust(player->mo, player->mo->angle, (player->speed = FixedMul(player->dashspeed, player->mo->scale))); // catapult forward ho!! + } + else + { + P_SetPlayerMobjState(player->mo, S_PLAY_STND); + player->pflags &= ~PF_SPINNING; + } + + if (!player->spectator) + S_StartSound(player->mo, sfx_zoom); + } + + player->dashspeed = 0; + } + break; + case CA2_GUNSLINGER: + if (!player->mo->momz && onground && !player->weapondelay && canstand) + { + if (player->speed > FixedMul(10<mo->scale)) + {} + else + { + mobj_t *lockon = P_LookForEnemies(player, false, true); + if (lockon) + { + if (P_IsLocalPlayer(player)) // Only display it on your own view. + { + mobj_t *visual = P_SpawnMobj(lockon->x, lockon->y, lockon->z, MT_LOCKON); // positioning, flip handled in P_SceneryThinker + P_SetTarget(&visual->target, lockon); + } + } + if ((cmd->buttons & BT_USE) && !(player->pflags & PF_USEDOWN)) + { + mobj_t *bullet; + + P_SetPlayerMobjState(player->mo, S_PLAY_FIRE); + +#define zpos(posmo) (posmo->z + (posmo->height - mobjinfo[player->revitem].height)/2) + if (lockon) + { + player->mo->angle = R_PointToAngle2(player->mo->x, player->mo->y, lockon->x, lockon->y); + bullet = P_SpawnPointMissile(player->mo, lockon->x, lockon->y, zpos(lockon), player->revitem, player->mo->x, player->mo->y, zpos(player->mo)); + if (!demoplayback || P_AnalogMove(player)) + { + if (player == &players[consoleplayer]) + localangle = player->mo->angle; + else if (player == &players[secondarydisplayplayer]) + localangle2 = player->mo->angle; + } + } + else + { + bullet = P_SpawnPointMissile(player->mo, player->mo->x + P_ReturnThrustX(NULL, player->mo->angle, FRACUNIT), player->mo->y + P_ReturnThrustY(NULL, player->mo->angle, FRACUNIT), zpos(player->mo), player->revitem, player->mo->x, player->mo->y, zpos(player->mo)); + if (bullet) + { + bullet->flags &= ~MF_NOGRAVITY; + bullet->momx >>= 1; + bullet->momy >>= 1; + } + } + player->drawangle = player->mo->angle; +#undef zpos + + P_SetTarget(&player->mo->tracer, NULL); + player->mo->momx >>= 1; + player->mo->momy >>= 1; + player->pflags |= PF_USEDOWN; + P_SetWeaponDelay(player, TICRATE/2); + } + } + } + break; + case CA2_MELEE: // Melee attack + if (player->panim != PA_ABILITY2 && (cmd->buttons & BT_USE) + && !player->mo->momz && onground && !(player->pflags & PF_USEDOWN) + && canstand) + { + P_ResetPlayer(player); + player->pflags |= PF_THOKKED; +#if 0 + if ((player->charability == CA_TWINSPIN) && (player->speed > FixedMul(player->runspeed, player->mo->scale))) + { + P_DoJump(player, false); + player->pflags &= ~PF_STARTJUMP; + player->mo->momz = FixedMul(player->mo->momz, 3*FRACUNIT/2); // NOT 1.5 times the jump height, but 2.25 times. + P_SetPlayerMobjState(player->mo, S_PLAY_TWINSPIN); + S_StartSound(player->mo, sfx_s3k8b); + } + else +#endif + { + player->mo->z += P_MobjFlip(player->mo); + P_SetObjectMomZ(player->mo, player->mindash, false); + if (player->mo->eflags & MFE_UNDERWATER) + player->mo->momz >>= 1; +#if 0 + if (FixedMul(player->speed, FINECOSINE(((player->mo->angle - R_PointToAngle2(0, 0, player->rmomx, player->rmomy)) >> ANGLETOFINESHIFT) & FINEMASK)) < FixedMul(player->maxdash, player->mo->scale)) +#else + if (player->speed < FixedMul(player->maxdash, player->mo->scale)) +#endif + { + player->drawangle = player->mo->angle; + P_InstaThrust(player->mo, player->mo->angle, FixedMul(player->maxdash, player->mo->scale)); + } + player->mo->momx += player->cmomx; + player->mo->momy += player->cmomy; + P_SetPlayerMobjState(player->mo, S_PLAY_MELEE); + S_StartSound(player->mo, sfx_s3k42); + } + player->pflags |= PF_USEDOWN; + } + break; } } @@ -3687,6 +3884,9 @@ void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2 == player->mo) @@ -4366,29 +4566,32 @@ static void P_NightsTransferPoints(player_t *player, fixed_t xspeed, fixed_t rad // Find next waypoint for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; // Axis things are only at beginning of list. if (!(mo2->flags2 & MF2_AXIS)) break; + if (!(mo2->type == MT_AXISTRANSFER || mo2->type == MT_AXISTRANSFERLINE)) + continue; + if (mo2->threshold != sequence) + continue; - if ((mo2->type == MT_AXISTRANSFER || mo2->type == MT_AXISTRANSFERLINE) - && mo2->threshold == sequence) + if (player->pflags & PF_TRANSFERTOCLOSEST) { - if (player->pflags & PF_TRANSFERTOCLOSEST) - { - if (mo2->health == player->axis1->health) - transfer1 = mo2; - else if (mo2->health == player->axis2->health) - transfer2 = mo2; - } - else - { - if (mo2->health == player->mo->target->health) - transfer1 = mo2; - else if (mo2->health == player->mo->target->health + 1) - transfer2 = mo2; - } + if (mo2->health == player->axis1->health) + transfer1 = mo2; + else if (mo2->health == player->axis2->health) + transfer2 = mo2; + } + else + { + if (mo2->health == player->mo->target->health) + transfer1 = mo2; + else if (mo2->health == player->mo->target->health + 1) + transfer2 = mo2; } } @@ -4399,24 +4602,28 @@ static void P_NightsTransferPoints(player_t *player, fixed_t xspeed, fixed_t rad { for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; // Axis things are only at beginning of list. if (!(mo2->flags2 & MF2_AXIS)) break; + if (!(mo2->type == MT_AXISTRANSFER || mo2->type == MT_AXISTRANSFERLINE)) + continue; + if (mo2->threshold != sequence) + continue; - if (mo2->threshold == sequence && (mo2->type == MT_AXISTRANSFER || mo2->type == MT_AXISTRANSFERLINE)) + if (!transfer1) { - if (!transfer1) - { - transfer1 = mo2; - transfer1last = true; - } - else if (mo2->health > transfer1->health) - { - transfer1 = mo2; - transfer1last = true; - } + transfer1 = mo2; + transfer1last = true; + } + else if (mo2->health > transfer1->health) + { + transfer1 = mo2; + transfer1last = true; } } } @@ -4424,24 +4631,28 @@ static void P_NightsTransferPoints(player_t *player, fixed_t xspeed, fixed_t rad { for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; // Axis things are only at beginning of list. if (!(mo2->flags2 & MF2_AXIS)) break; + if (!(mo2->type == MT_AXISTRANSFER || mo2->type == MT_AXISTRANSFERLINE)) + continue; + if (mo2->threshold != sequence) + continue; - if (mo2->threshold == sequence && (mo2->type == MT_AXISTRANSFER || mo2->type == MT_AXISTRANSFERLINE)) + if (!transfer2) { - if (!transfer2) - { - transfer2 = mo2; - transfer2last = true; - } - else if (mo2->health > transfer2->health) - { - transfer2 = mo2; - transfer2last = true; - } + transfer2 = mo2; + transfer2last = true; + } + else if (mo2->health > transfer2->health) + { + transfer2 = mo2; + transfer2last = true; } } } @@ -4968,31 +5179,32 @@ static void P_NiGHTSMovement(player_t *player) // to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; - if (mo2->type == MT_AXIS) - { - if (mo2->threshold == player->mare) - { - if (closestaxis == NULL) - { - closestaxis = mo2; - dist2 = R_PointToDist2(newx, newy, mo2->x, mo2->y)-mo2->radius; - } - else - { - dist1 = R_PointToDist2(newx, newy, mo2->x, mo2->y)-mo2->radius; + if (mo2->type != MT_AXIS) + continue; + if (mo2->threshold != player->mare) + continue; - if (dist1 < dist2) - { - closestaxis = mo2; - dist2 = dist1; - } - } + if (closestaxis == NULL) + { + closestaxis = mo2; + dist2 = R_PointToDist2(newx, newy, mo2->x, mo2->y) - mo2->radius; + } + else + { + dist1 = R_PointToDist2(newx, newy, mo2->x, mo2->y) - mo2->radius; + + if (dist1 < dist2) + { + closestaxis = mo2; + dist2 = dist1; } } } - P_SetTarget(&player->mo->target, closestaxis); } @@ -5684,6 +5896,9 @@ static void P_MovePlayer(player_t *player) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type == MT_EGGCAPSULE @@ -6240,7 +6455,20 @@ static void P_MovePlayer(player_t *player) /* // SRB2kart - what's a shield? Never heard of it. Never happened. Nope. if (cmd->buttons & BT_BRAKE) // Spin button effects { - if (player->pflags & PF_JUMPED) // If the player is jumping + mobj_t *lockon = NULL; + if (!player->powers[pw_super] && player->powers[pw_shield] == SH_ATTRACT && !(player->pflags & PF_THOKKED)) + { + if ((lockon = P_LookForEnemies(player, false, false))) + { + if (P_IsLocalPlayer(player)) // Only display it on your own view. + { + mobj_t *visual = P_SpawnMobj(lockon->x, lockon->y, lockon->z, MT_LOCKON); // positioning, flip handled in P_SceneryThinker + P_SetTarget(&visual->target, lockon); + P_SetMobjStateNF(visual, visual->info->spawnstate+1); + } + } + } + if (cmd->buttons & BT_USE) // Spin button effects { if (!(player->pflags & PF_USEDOWN)) // If the player is not holding down BT_BRAKE { @@ -6498,20 +6726,25 @@ static void P_DoZoomTube(player_t *player) // Find next waypoint for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == sequence) - { - if ((reverse && mo2->health == player->mo->tracer->health - 1) - || (!reverse && mo2->health == player->mo->tracer->health + 1)) - { - waypoint = mo2; - break; - } - } + if (mo2->threshold != sequence) + continue; + + if (reverse && mo2->health != player->mo->tracer->health - 1) + continue; + + if (!reverse && mo2->health != player->mo->tracer->health + 1) + continue; + + waypoint = mo2; + break; } if (waypoint) @@ -6637,19 +6870,22 @@ static void P_DoRopeHang(player_t *player) // SRB2kart - unused. // Find next waypoint for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == sequence) - { - if (mo2->health == player->mo->tracer->health + 1) - { - waypoint = mo2; - break; - } - } + if (mo2->threshold != sequence) + continue; + + if (mo2->health != player->mo->tracer->health + 1) + continue; + + waypoint = mo2; + break; } if (!(player->mo->tracer->flags & MF_SLIDEME) && !waypoint) @@ -6659,19 +6895,22 @@ static void P_DoRopeHang(player_t *player) // SRB2kart - unused. // Wrap around back to first waypoint for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == sequence) - { - if (mo2->health == 0) - { - waypoint = mo2; - break; - } - } + if (mo2->threshold != sequence) + continue; + + if (mo2->health != 0) + continue; + + waypoint = mo2; + break; } } @@ -6722,22 +6961,22 @@ static void P_DoRopeHang(player_t *player) // SRB2kart - unused. static void P_NukeAllPlayers(player_t *player) { mobj_t *mo; - thinker_t *think; + UINT8 i; - for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) + for (i = 0; i < MAXPLAYERS; i++) { - mo = (mobj_t *)think; - - if (!mo->player) + if (!playeringame[i]) + continue; + if (players[i].spectator) + continue; + if (!players[i].mo) + continue; + if (players[i].mo == player->mo) + continue; + if (players[i].mo->health <= 0) continue; - if (mo->health <= 0) // dead - continue; - - if (mo == player->mo) - continue; - - P_DamageMobj(mo, player->mo, player->mo, 1); + P_DamageMobj(players[i].mo, player->mo, player->mo, 1, 0); } CONS_Printf(M_GetText("%s caused a world of pain.\n"), player_names[player-players]); @@ -6773,6 +7012,9 @@ void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius) for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { + if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo = (mobj_t *)think; if (!(mo->flags & MF_SHOOTABLE) && !(mo->type == MT_EGGGUARD || mo->type == MT_MINUS @@ -6850,6 +7092,9 @@ boolean P_LookForEnemies(player_t *player) for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { + if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo = (mobj_t *)think; if (!(mo->flags & (MF_ENEMY|MF_BOSS|MF_MONITOR|MF_SPRING))) continue; // not a valid enemy @@ -6972,6 +7217,9 @@ void P_FindEmerald(void) // to find all emeralds for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (mo2->type == MT_EMERHUNT) { @@ -8297,6 +8545,9 @@ void P_PlayerThink(player_t *player) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; if (!(mo2->type == MT_NIGHTSWING || mo2->type == MT_RING || mo2->type == MT_COIN diff --git a/src/r_data.c b/src/r_data.c index dbfc56a4e..e34576dba 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1654,7 +1654,8 @@ void R_PrecacheLevel(void) if (spritepresent == NULL) I_Error("%s: Out of memory looking up sprites", "R_PrecacheLevel"); for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) - spritepresent[((mobj_t *)th)->sprite] = 1; + if (th->function.acp1 != (actionf_p1)P_RemoveThinkerDelayed) + spritepresent[((mobj_t *)th)->sprite] = 1; spritememory = 0; for (i = 0; i < numsprites; i++) diff --git a/src/st_stuff.c b/src/st_stuff.c index 372822f51..11fcd1be9 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -1764,27 +1764,31 @@ static void ST_doItemFinderIconsAndSound(void) // SRB2kart - unused. // Scan thinkers to find emblem mobj with these ids for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + mo2 = (mobj_t *)th; - if (mo2->type == MT_EMBLEM) + if (mo2->type != MT_EMBLEM) + continue; + + if (!(mo2->flags & MF_SPECIAL)) + continue; + + for (i = 0; i < stemblems; ++i) { - if (!(mo2->flags & MF_SPECIAL)) - continue; - - for (i = 0; i < stemblems; ++i) + if (mo2->health == emblems[i] + 1) { - if (mo2->health == emblems[i]+1) - { - soffset = (i * 20) - ((stemblems-1) * 10); + soffset = (i * 20) - ((stemblems - 1) * 10); - newinterval = ST_drawEmeraldHuntIcon(mo2, itemhoming, soffset); - if (newinterval && (!interval || newinterval < interval)) - interval = newinterval; + newinterval = ST_drawEmeraldHuntIcon(mo2, itemhoming, soffset); + if (newinterval && (!interval || newinterval < interval)) + interval = newinterval; - break; - } + break; } } + } if (!(P_AutoPause() || paused) && interval > 0 && leveltime && leveltime % interval == 0) From 9ce1e0b0bc1184288a5fd33cc84c3cb67a3dff4d Mon Sep 17 00:00:00 2001 From: Ashnal Date: Thu, 13 Feb 2020 22:17:19 -0500 Subject: [PATCH 04/67] Fixed my bruh moment Re-added a number of cuntion in p_enemy.c that I deleted --- src/lua_playerlib.c | 20 -- src/p_enemy.c | 730 ++++++++++++++++++++++++++++++++++++++++++++ src/p_spec.c | 2 +- 3 files changed, 731 insertions(+), 21 deletions(-) diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 090e384be..c1606f855 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -405,26 +405,6 @@ static int player_set(lua_State *L) // else if (fastcmp(field,"charflags")) plr->charflags = (UINT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"thokitem")) - plr->thokitem = luaL_checkinteger(L, 3); - else if (fastcmp(field,"spinitem")) - plr->spinitem = luaL_checkinteger(L, 3); - else if (fastcmp(field,"revitem")) - plr->revitem = luaL_checkinteger(L, 3); - else if (fastcmp(field,"followitem")) - plr->followitem = luaL_checkinteger(L, 3); - else if (fastcmp(field,"actionspd")) - plr->actionspd = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"mindash")) - plr->mindash = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"maxdash")) - plr->maxdash = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"jumpfactor")) - plr->jumpfactor = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"height")) - plr->height = luaL_checkfixed(L, 3); - else if (fastcmp(field,"spinheight")) - plr->spinheight = luaL_checkfixed(L, 3); else if (fastcmp(field,"lives")) plr->lives = (SINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"continues")) diff --git a/src/p_enemy.c b/src/p_enemy.c index 09a476a08..ee5a34876 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -8673,6 +8673,736 @@ void A_LightningFollowPlayer(mobj_t *actor) } } +// A_FZBoomFlash: +// Flash everyone close enough to the boom +void A_FZBoomFlash(mobj_t *actor) +{ + UINT8 i; +#ifdef HAVE_BLUA + if (LUA_CallAction("A_FZBoomFlash", actor)) + return; +#endif + for (i = 0; i < MAXPLAYERS; i++) + { + fixed_t dist; + if (!playeringame[i] || !players[i].mo) + continue; + dist = P_AproxDistance(P_AproxDistance(actor->x-players[i].mo->x, actor->y-players[i].mo->y), actor->z-players[i].mo->z); + if (dist < 1536<x + (P_RandomRange(-rad, rad)*actor->scale), actor->y + (P_RandomRange(-rad, rad)*actor->scale), + actor->z + (P_RandomRange(0, 72)*actor->scale), MT_THOK); + + P_SetMobjState(smoke, S_FZEROSMOKE1); + smoke->tics += P_RandomRange(-3, 4); + smoke->scale = actor->scale*3; + } + return; +} + +// A_RandomShadowFrame +// Gives a random sprite for the Mayonaka static shadows. Dumb and simple. +void A_RandomShadowFrame(mobj_t *actor) +{ + mobj_t *fire; + mobj_t *fake; +#ifdef HAVE_BLUA + if (LUA_CallAction("A_RandomShadowFrame", (actor))) + return; +#endif + + if (!actor->extravalue1) // Hack that spawns thoks that look like random shadows. Otherwise the state would overwrite our frame and that's a pain. + { + fake = P_SpawnMobj(actor->x, actor->y, actor->z, MT_THOK); + fake->sprite = SPR_ENM1; + fake->frame = P_RandomRange(0, 6); + P_SetScale(fake, FRACUNIT*3/2); + fake->scale = FRACUNIT*3/2; + fake->destscale = FRACUNIT*3/2; + fake->angle = actor->angle; + fake->tics = -1; + actor->flags2 |= MF2_DONTDRAW; + actor->extravalue1 = 1; + } + + P_SetScale(actor, FRACUNIT*3/2); + + // I have NO CLUE how to hardcode all of that fancy Linedef Executor shit so the fire spinout will be done by these entities directly. + if (P_LookForPlayers(actor, false, false, 380<target && !actor->target->player->powers[pw_flashing] + && !actor->target->player->kartstuff[k_invincibilitytimer] + && !actor->target->player->kartstuff[k_growshrinktimer] + && !actor->target->player->kartstuff[k_spinouttimer] + && P_IsObjectOnGround(actor->target) + && actor->z == actor->target->z) + { + P_DamageMobj(actor->target, actor, actor, 1); + P_InstaThrust(actor->target, actor->angle, 16<target->x, actor->target->y, actor->target->z, MT_THOK); + P_SetMobjStateNF(fire, S_QUICKBOOM1); + P_SetScale(fire, 4<color = SKINCOLOR_KETCHUP; + S_StartSound(actor->target, sfx_fire2); + } + } + return; +} + +// A_RoamingShadowThinker +// Thinker for Midnight Channel's Roaming Shadows: +void A_RoamingShadowThinker(mobj_t *actor) +{ + mobj_t *wind; + +#ifdef HAVE_BLUA + if (LUA_CallAction("A_RoamingShadowThinker", (actor))) + return; +#endif + // extravalue1 replaces "movetimer" + // extravalue2 replaces "stoptimer" + + P_SetScale(actor, FRACUNIT*3/2); + if (!actor->extravalue2) + { + P_InstaThrust(actor, actor->angle, 8<extravalue1 = ((actor->extravalue1) ? (actor->extravalue1-1) : (TICRATE*5+1)); // deplete timer if set, set to 5 ticrate otherwise. + if (actor->extravalue1 == 1) // if timer reaches 1, do a u-turn. + { + actor->extravalue1 = 0; + actor->extravalue2 = 60; + } + // Search for and attack Players venturing too close in front of us. + + if (P_LookForPlayers(actor, false, false, 256<target && !actor->target->player->powers[pw_flashing] + && !actor->target->player->kartstuff[k_invincibilitytimer] + && !actor->target->player->kartstuff[k_growshrinktimer] + && !actor->target->player->kartstuff[k_spinouttimer]) + { + // send them flying and spawn the WIND! + P_InstaThrust(actor->target, 0, 0); + P_DamageMobj(actor->target, actor, actor, 1); + P_SetObjectMomZ(actor->target, 16<target, sfx_wind1); + + // Spawn the WIND: + wind = P_SpawnMobj(actor->target->x, actor->target->y, actor->target->z, MT_THOK); // Opaque layer: + P_SetMobjState(wind, S_GARU1); + P_SetScale(wind, FRACUNIT*3/2); + wind = P_SpawnMobj(actor->target->x, actor->target->y, actor->target->z, MT_THOK); // Translucent layer: + P_SetMobjState(wind, S_TGARU0); + P_SetScale(wind, FRACUNIT*3/2); + wind->destscale = 30<angle += ANG1*3; + actor->extravalue2--; + } + return; +} + +// A_MayonakaArrow +// Used for the arrow sprite animations in Mayonaka. It's only extra visual bullshit to make em more random. + +void A_MayonakaArrow(mobj_t *actor) +{ + INT32 flip = 0; + INT32 iswarning; +#ifdef HAVE_BLUA + if (LUA_CallAction("A_MayonakaArrow", (actor))) + return; +#endif + + iswarning = actor->spawnpoint->options & MTF_OBJECTSPECIAL; // is our object a warning sign? + // "animtimer" is replaced by "extravalue1" here. + actor->extravalue1 = ((actor->extravalue1) ? (actor->extravalue1+1) : (P_RandomRange(0, (iswarning) ? (TICRATE/2) : TICRATE*3))); + flip = ((actor->spawnpoint->options & 1) ? (3) : (0)); // flip adds 3 frames, which is the flipped version of the sign. + // special warning behavior: + if (iswarning) + flip = 6; + + actor->frame = flip + actor->extravalue2*3; + + if (actor->extravalue1 >= TICRATE*7/2) + { + actor->extravalue1 = 0; // reset to 0 and start a new cycle. + // special behavior for warning sign; swap from warning to sneaker & reverse + if (iswarning) + actor->extravalue2 = (actor->extravalue2) ? (0) : (1); + } + else if (actor->extravalue1 > TICRATE*7/2 -4) + actor->frame = flip+2; + else if (actor->extravalue1 > TICRATE*3 && leveltime%2 > 0) + actor->frame = flip+1; + + actor->frame |= FF_PAPERSPRITE; + actor->momz = 0; + return; +} + +// A_MementosTPParticles +// Mementos teleporters particles effects. Short and simple. + +void A_MementosTPParticles(mobj_t *actor) +{ + mobj_t *particle; + mobj_t *mo2; + int i = 0; + thinker_t *th; + +#ifdef HAVE_BLUA + if (LUA_CallAction("A_MementosTPParticles", (actor))) + return; +#endif + + for (; i<4; i++) + { + particle = P_SpawnMobj(actor->x + (P_RandomRange(-256, 256)<y + (P_RandomRange(-256, 256)<z + (P_RandomRange(48, 256)<frame = 0; + particle->color = ((i%2) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); + particle->destscale = 1; + P_HomingAttack(particle, actor); + } + + // Although this is mostly used to spawn particles, we will also save the OTHER teleport inside actor->target. That way teleporting doesn't require a thinker iteration. + // Doesn't seem like much given the small amount of mobjs this map has but heh. + if (!actor->target) + { + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + if (mo2->type == MT_MEMENTOSTP && mo2 != actor) + { + P_SetTarget(&actor->target, mo2); // The main target we're pursing. + break; + } + } + } +} + +// A_ReaperThinker +// Mementos's Reaper's thinker. A huge pain in the Derek Bum to translate from Lua to this shite if you ask me. + +void A_ReaperThinker(mobj_t *actor) +{ + mobj_t *particle; // particles to spawn + int i = 0; // for loops + angle_t an = ANGLE_22h; // Reminder that angle constants suck. + + //Waypoint stuff: + mobj_t *mo2; + thinker_t *th; + + //Player targetting stuff: + UINT32 maxscore = 0; // we target the player with the highest score so yeah there you go. + player_t *player; // used as a shortcut in a loop. + mobj_t *targetplayermo = NULL; // the player mo we can eventually target, or whatever. + + +#ifdef HAVE_BLUA + if (LUA_CallAction("A_ReaperThinker", (actor))) + return; +#endif + + // We don't have custom variables or whatever so we'll do with whatever the fuck we have left. + + if (actor->health == 1000) // if health is 1000, set it to a small scale and have it start growing with destscale. Then set the health to uh, not 1000. + { + actor->scale = 1; + actor->destscale = 2<scalespeed = FRACUNIT/24; // Should take a bit less than 2 seconds to fully grow. + S_StartSound(NULL, sfx_chain); + actor->health--; // now we have 999 health, so that above won't happen again. Awesome. + } + + if (actor->scale < 2<x + (P_RandomRange(-60, 60)<y + (P_RandomRange(-60, 60)<z, MT_THOK); + particle->momz = 20<color = ((i%2 !=0) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); + particle->frame = 0; + P_SetScale(particle, FRACUNIT/2); + } + + // Spawn particles in some edgy circle or w/e. + + if (leveltime%5 != 0) // spawn the thing under that every tic. + return; + + i=0; + for (; i<15; i++) // spawn in a circle formation or w/e. + { + particle = P_SpawnMobj(actor->x, actor->y, actor->z, MT_THOK); + particle->momz = 20<color = ((i%2 !=0) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); + particle->frame = 0; + P_SetScale(particle, FRACUNIT/2); + P_InstaThrust(particle, an*i, 30<flags = MF_NOGRAVITY|MF_PAIN|MF_SPECIAL|MF_NOCLIP|MF_NOCLIPHEIGHT; // set our flags to be a damaging thing. + // Handle animation: + if (!(leveltime%5)) + actor->extravalue2 = (actor->extravalue2 < 9) ? (actor->extravalue2+1) : (0); // Ghetto animation, but hey it works for what it's worth + + // Chain sfx + if (!S_SoundPlaying(actor, sfx_chain)) + S_StartSound(actor, sfx_chain); + + actor->frame = actor->extravalue2; // yes i'm that bad at maths don't @ me. + + if (!actor->target) + { + if (actor->hnext) + { + P_SetTarget(&actor->target, actor->hnext); // Default back to last waypoint. + return; + } + + // We have no target and oughta find one, so let's scan through thinkers for a waypoint of angle 0, or something. + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + + if (mo2->type != MT_REAPERWAYPOINT) + continue; + if (mo2->spawnpoint->angle != 0) + continue; + + P_SetTarget(&actor->target, mo2); // The main target we're pursing. + P_SetTarget(&actor->hnext, mo2); // The last waypoint we hit. We will default back to that if a player goes out of our range! + actor->extravalue1 = 0; // This will store the angle of the last waypoint we touched. This will essentially be useful later on. + if (!actor->tracer) // If we already have a tracer (Waypoint #0), don't do anything. + { + P_SetTarget(&actor->tracer, mo2); // Because our target might be a player OR a waypoint, we need some sort of fallback option. This will always be waypoint 0. + break; + } + } + } + else // Awesome, we now have a target. + { + // Follow target: + P_InstaThrust(actor, R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y), 20<angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y); + + // The player we should target if it's near us: + for (i=0; imo && player->kartstuff[k_bumper] && player->score >= maxscore) + { + targetplayermo = player->mo; + maxscore = player->score; + } + } + + // Try to target that player: + if (targetplayermo) + { + if (P_LookForPlayers(actor, false, false, 1024<target == targetplayermo && actor->target && !actor->target->player->powers[pw_flashing] + && !actor->target->player->kartstuff[k_invincibilitytimer] + && !actor->target->player->kartstuff[k_growshrinktimer] + && !actor->target->player->kartstuff[k_spinouttimer])) + P_SetTarget(&actor->target, actor->hnext); + // if the above isn't correct, then we should go back to targetting waypoints or something. + } + } + + // Waypoint behavior. + if (actor->target->type == MT_REAPERWAYPOINT) + { + + if (R_PointToDist2(actor->x, actor->y, actor->target->x, actor->target->y) < 22<target, NULL); // remove target so we can default back to first waypoint if things go ham. + + // If we reach close to a waypoint, then we should go to the NEXT one. + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + + if (mo2->type != MT_REAPERWAYPOINT) + continue; + if (mo2->spawnpoint->angle != actor->extravalue1+1) + continue; + + P_SetTarget(&actor->target, mo2); // The main target we're pursing. + P_SetTarget(&actor->hnext, mo2); // The last waypoint we hit. We will default back to that if a player goes out of our range! + actor->extravalue1++; // This will store the angle of the last waypoint we touched. This will essentially be useful later on. + break; + } + } + + + if (!actor->target) // If we have no target, revert back to waypoint 0. + { + actor->extravalue1 = 0; + P_SetTarget(&actor->target, actor->tracer); + } + } + else // if our target ISN'T a waypoint, then it can only be a player. + { + if (!P_CheckSight(actor, actor->target) || R_PointToDist2(actor->x, actor->y, actor->target->x, actor->target->y) > 1024<target, actor->hnext); + } + } +} + +void A_FlameParticle(mobj_t *actor) +{ + fixed_t rad = actor->radius>>FRACBITS, hei = actor->radius>>FRACBITS; + mobj_t *par; +#ifdef HAVE_BLUA + if (LUA_CallAction("A_FlameParticle", actor)) + return; +#endif + + par = P_SpawnMobj( + actor->x + (P_RandomRange(-rad, rad)<y + (P_RandomRange(-rad, rad)<z + (P_RandomRange(hei/2, hei)<info->painchance); + par->momz = actor->scale<<1; +} + +// Function: A_OrbitNights +// +// Description: Used by Chaos Emeralds to orbit around Nights (aka Super Sonic.) +// +// var1 = Angle adjustment (aka orbit speed) +// var2 = Lower four bits: height offset, Upper 4 bits = set if object is Nightopian Helper +// +void A_OrbitNights(mobj_t* actor) +{ + INT32 ofs = (var2 & 0xFFFF); + boolean ishelper = (var2 & 0xFFFF0000); +#ifdef HAVE_BLUA + if (LUA_CallAction("A_OrbitNights", actor)) + return; +#endif + + if (!actor->target || !actor->target->player || + !actor->target->tracer || !actor->target->player->nightstime + // Also remove this object if they no longer have a NiGHTS helper + || (ishelper && !actor->target->player->powers[pw_nights_helper])) + { + P_RemoveMobj(actor); + return; + } + else + { + actor->extravalue1 += var1; + P_UnsetThingPosition(actor); + { + const angle_t fa = (angle_t)actor->extravalue1 >> ANGLETOFINESHIFT; + const angle_t ofa = ((angle_t)actor->extravalue1 + (ofs*ANG1)) >> ANGLETOFINESHIFT; + + const fixed_t fc = FixedMul(FINECOSINE(fa),FixedMul(32*FRACUNIT, actor->scale)); + const fixed_t fh = FixedMul(FINECOSINE(ofa),FixedMul(20*FRACUNIT, actor->scale)); + const fixed_t fs = FixedMul(FINESINE(fa),FixedMul(32*FRACUNIT, actor->scale)); + + actor->x = actor->target->tracer->x + fc; + actor->y = actor->target->tracer->y + fs; + actor->z = actor->target->tracer->z + fh + FixedMul(16*FRACUNIT, actor->scale); + + // Semi-lazy hack + actor->angle = (angle_t)actor->extravalue1 + ANGLE_90; + } + P_SetThingPosition(actor); + } +} + +// Function: A_GhostMe +// +// Description: Spawns a "ghost" mobj of this actor, ala spindash trails and the minus's digging "trails" +// +// var1 = unused +// var2 = unused +// +void A_GhostMe(mobj_t *actor) +{ +#ifdef HAVE_BLUA + if (LUA_CallAction("A_GhostMe", actor)) + return; +#endif + P_SpawnGhostMobj(actor); +} + +// Function: A_SetObjectState +// +// Description: Changes the state of an object's target/tracer. +// +// var1 = state number +// var2: +// 0 = target +// 1 = tracer +// +void A_SetObjectState(mobj_t *actor) +{ + INT32 locvar1 = var1; + INT32 locvar2 = var2; + mobj_t *target; +#ifdef HAVE_BLUA + if (LUA_CallAction("A_SetObjectState", actor)) + return; +#endif + + if ((!locvar2 && !actor->target) || (locvar2 && !actor->tracer)) + { + if (cv_debug) + CONS_Printf("A_SetObjectState: No target to change state!\n"); + return; + } + + if (!locvar2) // target + target = actor->target; + else // tracer + target = actor->tracer; + + if (target->health > 0) + { + if (!target->player) + P_SetMobjState(target, locvar1); + else + P_SetPlayerMobjState(target, locvar1); + } +} + +// Function: A_SetObjectTypeState +// +// Description: Changes the state of all active objects of a certain type in a certain range of the actor. +// +// var1 = state number +// var2: +// lower 16 bits = type +// upper 16 bits = range (if == 0, across whole map) +// +void A_SetObjectTypeState(mobj_t *actor) +{ + INT32 locvar1 = var1; + INT32 locvar2 = var2; + const UINT16 loc2lw = (UINT16)(locvar2 & 65535); + const UINT16 loc2up = (UINT16)(locvar2 >> 16); + + thinker_t *th; + mobj_t *mo2; + fixed_t dist = 0; + +#ifdef HAVE_BLUA + if (LUA_CallAction("A_SetObjectTypeState", actor)) + return; +#endif + + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + + if (mo2->type == (mobjtype_t)loc2lw) + { + dist = P_AproxDistance(mo2->x - actor->x, mo2->y - actor->y); + + if (mo2->health > 0) + { + if (loc2up == 0) + P_SetMobjState(mo2, locvar1); + else + { + if (dist <= FixedMul(loc2up*FRACUNIT, actor->scale)) + P_SetMobjState(mo2, locvar1); + } + } + } + } +} + +// Function: A_KnockBack +// +// Description: Knocks back the object's target at its current speed. +// +// var1: +// 0 = target +// 1 = tracer +// var2 = unused +// +void A_KnockBack(mobj_t *actor) +{ + INT32 locvar1 = var1; + mobj_t *target; +#ifdef HAVE_BLUA + if (LUA_CallAction("A_KnockBack", actor)) + return; +#endif + + if (!locvar1) + target = actor->target; + else + target = actor->tracer; + + if (!target) + { + if(cv_debug) + CONS_Printf("A_KnockBack: No target!\n"); + return; + } + + target->momx *= -1; + target->momy *= -1; +} + +// Function: A_PushAway +// +// Description: Pushes an object's target away from the calling object. +// +// var1 = amount of force +// var2: +// lower 16 bits = If 1, xy momentum is lost. If 0, xy momentum is kept +// upper 16 bits = 0 - target, 1 - tracer +// +void A_PushAway(mobj_t *actor) +{ + INT32 locvar1 = var1; + INT32 locvar2 = var2; + mobj_t *target; // target + angle_t an; // actor to target angle +#ifdef HAVE_BLUA + if (LUA_CallAction("A_PushAway", actor)) + return; +#endif + + if ((!(locvar2 >> 16) && !actor->target) || ((locvar2 >> 16) && !actor->tracer)) + return; + + if (!locvar1) + CONS_Printf("A_Thrust: Var1 not specified!\n"); + + if (!(locvar2 >> 16)) // target + target = actor->target; + else // tracer + target = actor->tracer; + + an = R_PointToAngle2(actor->x, actor->y, target->x, target->y); + + if (locvar2 & 65535) + P_InstaThrust(target, an, FixedMul(locvar1*FRACUNIT, actor->scale)); + else + P_Thrust(target, an, FixedMul(locvar1*FRACUNIT, actor->scale)); +} + +// Function: A_RingDrain +// +// Description: Drain targeted player's rings. +// +// var1 = ammount of drained rings +// var2 = unused +// +void A_RingDrain(mobj_t *actor) +{ + INT32 locvar1 = var1; + player_t *player; +#ifdef HAVE_BLUA + if (LUA_CallAction("A_RingDrain", actor)) + return; +#endif + + if (!actor->target || !actor->target->player) + { + if(cv_debug) + CONS_Printf("A_RingDrain: No player targeted!\n"); + return; + } + + player = actor->target->player; + P_GivePlayerRings(player, -min(locvar1, player->mo->health-1)); +} + +// Function: A_SplitShot +// +// Description: Shoots 2 missiles that hit next to the player. +// +// var1 = target x-y-offset +// var2: +// lower 16 bits = missile type +// upper 16 bits = height offset +// +void A_SplitShot(mobj_t *actor) +{ + INT32 locvar1 = var1; + INT32 locvar2 = var2; + const UINT16 loc2lw = (UINT16)(locvar2 & 65535); + const UINT16 loc2up = (UINT16)(locvar2 >> 16); + const fixed_t offs = (fixed_t)(locvar1*FRACUNIT); + const fixed_t hoffs = (fixed_t)(loc2up*FRACUNIT); +#ifdef HAVE_BLUA + if (LUA_CallAction("A_SplitShot", actor)) + return; +#endif + + A_FaceTarget(actor); + { + const angle_t an = (actor->angle + ANGLE_90) >> ANGLETOFINESHIFT; + const fixed_t fasin = FINESINE(an); + const fixed_t facos = FINECOSINE(an); + fixed_t xs = FixedMul(facos,FixedMul(offs, actor->scale)); + fixed_t ys = FixedMul(fasin,FixedMul(offs, actor->scale)); + fixed_t z; + + if (actor->eflags & MFE_VERTICALFLIP) + z = actor->z + actor->height - FixedMul(hoffs, actor->scale); + else + z = actor->z + FixedMul(hoffs, actor->scale); + + P_SpawnPointMissile(actor, actor->target->x+xs, actor->target->y+ys, actor->target->z, loc2lw, actor->x, actor->y, z); + P_SpawnPointMissile(actor, actor->target->x-xs, actor->target->y-ys, actor->target->z, loc2lw, actor->x, actor->y, z); + } +} + // Function: A_MissileSplit // // Description: If the object is a missile it will create a new missile with an alternate flight path owned by the one who shot the former missile. diff --git a/src/p_spec.c b/src/p_spec.c index bd6c2e79d..95b6f7764 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3767,7 +3767,7 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers mo2 = (mobj_t *)th; if (mo2->type != MT_EGGTRAP) continue; - P_KillMobj(mo2, NULL, player->mo, 0); + P_KillMobj(mo2, NULL, player->mo); } // clear the special so you can't push the button twice. From f7fb8a1897751b486b43108311fe80f512e9ecc6 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Thu, 13 Feb 2020 23:06:28 -0500 Subject: [PATCH 05/67] FIxed a couple missing th = --- src/p_saveg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index a544b5c1e..4ce6327b3 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2838,7 +2838,7 @@ static void P_NetUnArchiveThinkers(void) break; case tc_disappear: - LoadDisappearThinker((actionf_p1)T_Disappear); + th = LoadDisappearThinker((actionf_p1)T_Disappear); break; #ifdef POLYOBJECTS case tc_polyrotate: @@ -2866,7 +2866,7 @@ static void P_NetUnArchiveThinkers(void) break; case tc_polydisplace: - LoadPolydisplaceThinker((actionf_p1)T_PolyObjDisplace); + th = LoadPolydisplaceThinker((actionf_p1)T_PolyObjDisplace); break; #endif case tc_scroll: @@ -2882,7 +2882,7 @@ static void P_NetUnArchiveThinkers(void) break; default: - I_Error("P_UnarchiveSpecials: Unknown tclass %d in savegame", tclass); + CONS_Alert(CONS_ERROR, "Found mobj with unknown map thing type NULL\n"); } if (th) P_AddThinker(i, th); @@ -2896,7 +2896,7 @@ static void P_NetUnArchiveThinkers(void) executor_t *delay = NULL; UINT32 mobjnum; for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; - currentthinker = currentthinker->next) + currentthinker = currentthinker->next) { if (currentthinker->function.acp1 != (actionf_p1)T_ExecutorDelay) continue; From 607e0468efb33559dd42dd512ebe98efbc171ce1 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Sat, 19 Oct 2019 13:34:28 -0400 Subject: [PATCH 06/67] Merge branch 'thinkerlists_oops' into 'master' Fixed a netgame crash that was caused by a closing brace being in the wrong place :v See merge request STJr/SRB2Internal!395 --- src/p_saveg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 4ce6327b3..93a080295 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2895,8 +2895,8 @@ static void P_NetUnArchiveThinkers(void) { executor_t *delay = NULL; UINT32 mobjnum; - for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; - currentthinker = currentthinker->next) + for (currentthinker = thlist[THINK_MAIN].next; currentthinker != &thlist[THINK_MAIN]; + currentthinker = currentthinker->next) { if (currentthinker->function.acp1 != (actionf_p1)T_ExecutorDelay) continue; From e3050c64bc73d3d2f2be453f6de65e79dc7e6048 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Sat, 15 Feb 2020 20:20:35 -0500 Subject: [PATCH 07/67] Fix crash on level loading --- src/p_tick.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/p_tick.c b/src/p_tick.c index e6fffb417..2a3cf0cc8 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -193,6 +193,8 @@ void P_InitThinkers(void) UINT8 i; for (i = 0; i < NUM_THINKERLISTS; i++) thlist[i].prev = thlist[i].next = &thlist[i]; + + waypointcap = NULL; //Hack transplant } // Adds a new thinker at the end of the list. @@ -328,7 +330,7 @@ static inline void P_RunThinkers(void) for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; currentthinker = currentthinker->next) { #ifdef PARANOIA - I_Assert(currentthinker->function.acp1 != NULL) + I_Assert(currentthinker->function.acp1 != NULL); #endif currentthinker->function.acp1(currentthinker); } From 76f9907288cdfef9c4be26a05141312cea71cb3a Mon Sep 17 00:00:00 2001 From: Ashnal Date: Sat, 15 Feb 2020 20:34:23 -0500 Subject: [PATCH 08/67] Fix debug build crash This was tryign to =check the thinker list on the titlescreen befoire any thinkers exist --- src/d_clisrv.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 82d82ef94..1e6904a4f 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4778,12 +4778,14 @@ static INT16 Consistancy(void) ret += P_GetRandSeed(); #ifdef MOBJCONSISTANCY - for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + if (gamestate == GS_LEVEL) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; - mo = (mobj_t *)th; + mo = (mobj_t *)th; if (mo->flags & (MF_SPECIAL | MF_SOLID | MF_PUSHABLE | MF_BOSS | MF_MISSILE | MF_SPRING | MF_MONITOR | MF_FIRE | MF_ENEMY | MF_PAIN | MF_STICKY)) { @@ -4884,6 +4886,7 @@ static INT16 Consistancy(void) ret -= mo->sprite; ret += mo->frame; } + } } #endif From 9f9c81696d3f8c3eb9152936de02144e15554962 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Sun, 16 Feb 2020 13:45:02 -0500 Subject: [PATCH 09/67] Fixing slopes that got messed up during merge Copy slope got changes in 2.2 and somehow made it into here --- src/dehacked.c | 6 +- src/p_setup.c | 2 +- src/p_slopes.c | 624 ++++++++++++++++++++++++++++++------------------- src/p_slopes.h | 46 +--- src/p_spec.c | 8 + src/r_defs.h | 39 +++- 6 files changed, 428 insertions(+), 297 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 2a6407345..b311a860c 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8796,8 +8796,10 @@ struct { #ifdef ESLOPE // Slope flags - {"SL_NOPHYSICS",SL_NOPHYSICS}, - {"SL_DYNAMIC",SL_DYNAMIC}, + {"SL_NOPHYSICS",SL_NOPHYSICS}, // Don't do momentum adjustment with this slope + {"SL_NODYNAMIC",SL_NODYNAMIC}, // Slope will never need to move during the level, so don't fuss with recalculating it + {"SL_ANCHORVERTEX",SL_ANCHORVERTEX},// Slope is using a Slope Vertex Thing to anchor its position + {"SL_VERTEXSLOPE",SL_VERTEXSLOPE}, // Slope is built from three Slope Vertex Things #endif // Angles diff --git a/src/p_setup.c b/src/p_setup.c index aac08d6be..2332261aa 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3062,7 +3062,7 @@ boolean P_SetupLevel(boolean skipprecip) } #ifdef ESLOPE - P_ResetDynamicSlopes(fromnetsave); + P_ResetDynamicSlopes(); #endif P_LoadThings(); diff --git a/src/p_slopes.c b/src/p_slopes.c index fc690972d..76af7bfde 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -25,66 +25,68 @@ #ifdef ESLOPE -pslope_t *slopelist = NULL; -UINT16 slopecount = 0; +static pslope_t *slopelist = NULL; +static UINT16 slopecount = 0; // Calculate line normal void P_CalculateSlopeNormal(pslope_t *slope) { slope->normal.z = FINECOSINE(slope->zangle>>ANGLETOFINESHIFT); - slope->normal.x = FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.x); - slope->normal.y = FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.y); + slope->normal.x = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), -slope->d.x); + slope->normal.y = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), -slope->d.y); } -/// Setup slope via 3 vertexes. -static void ReconfigureViaVertexes (pslope_t *slope, const vector3_t v1, const vector3_t v2, const vector3_t v3) +// With a vertex slope that has its vertices set, configure relevant slope info +static void P_ReconfigureVertexSlope(pslope_t *slope) { vector3_t vec1, vec2; - // Set origin. - FV3_Copy(&slope->o, &v1); + // Set slope normal + vec1.x = (slope->vertices[1]->x - slope->vertices[0]->x) << FRACBITS; + vec1.y = (slope->vertices[1]->y - slope->vertices[0]->y) << FRACBITS; + vec1.z = (slope->vertices[1]->z - slope->vertices[0]->z) << FRACBITS; - // Get slope's normal. - FV3_SubEx(&v2, &v1, &vec1); - FV3_SubEx(&v3, &v1, &vec2); + vec2.x = (slope->vertices[2]->x - slope->vertices[0]->x) << FRACBITS; + vec2.y = (slope->vertices[2]->y - slope->vertices[0]->y) << FRACBITS; + vec2.z = (slope->vertices[2]->z - slope->vertices[0]->z) << FRACBITS; - // Set some defaults for a non-sloped "slope" - if (vec1.z == 0 && vec2.z == 0) - { - /// \todo Fix fully flat cases. + // ugggggggh fixed-point maaaaaaath + slope->extent = max( + max(max(abs(vec1.x), abs(vec1.y)), abs(vec1.z)), + max(max(abs(vec2.x), abs(vec2.y)), abs(vec2.z)) + ) >> (FRACBITS+5); + vec1.x /= slope->extent; + vec1.y /= slope->extent; + vec1.z /= slope->extent; + vec2.x /= slope->extent; + vec2.y /= slope->extent; + vec2.z /= slope->extent; + FV3_Cross(&vec1, &vec2, &slope->normal); + + slope->extent = R_PointToDist2(0, 0, R_PointToDist2(0, 0, slope->normal.x, slope->normal.y), slope->normal.z); + if (slope->normal.z < 0) + slope->extent = -slope->extent; + + slope->normal.x = FixedDiv(slope->normal.x, slope->extent); + slope->normal.y = FixedDiv(slope->normal.y, slope->extent); + slope->normal.z = FixedDiv(slope->normal.z, slope->extent); + + // Set origin + slope->o.x = slope->vertices[0]->x << FRACBITS; + slope->o.y = slope->vertices[0]->y << FRACBITS; + slope->o.z = slope->vertices[0]->z << FRACBITS; + + if (slope->normal.x == 0 && slope->normal.y == 0) { // Set some defaults for a non-sloped "slope" slope->zangle = slope->xydirection = 0; slope->zdelta = slope->d.x = slope->d.y = 0; - } - else - { - /// \note Using fixed point for vectorial products easily leads to overflows so we work around by downscaling them. - fixed_t m = max( - max(max(abs(vec1.x), abs(vec1.y)), abs(vec1.z)), - max(max(abs(vec2.x), abs(vec2.y)), abs(vec2.z)) - ) >> 5; // shifting right by 5 is good enough. - - FV3_Cross( - FV3_Divide(&vec1, m), - FV3_Divide(&vec2, m), - &slope->normal - ); - - // NOTE: FV3_Magnitude() doesn't work properly in some cases, and chaining FixedHypot() seems to give worse results. - m = R_PointToDist2(0, 0, R_PointToDist2(0, 0, slope->normal.x, slope->normal.y), slope->normal.z); - - // Invert normal if it's facing down. - if (slope->normal.z < 0) - m = -m; - - FV3_Divide(&slope->normal, m); - + } else { // Get direction vector - m = FixedHypot(slope->normal.x, slope->normal.y); - slope->d.x = -FixedDiv(slope->normal.x, m); - slope->d.y = -FixedDiv(slope->normal.y, m); + slope->extent = R_PointToDist2(0, 0, slope->normal.x, slope->normal.y); + slope->d.x = -FixedDiv(slope->normal.x, slope->extent); + slope->d.y = -FixedDiv(slope->normal.y, slope->extent); // Z delta - slope->zdelta = FixedDiv(m, slope->normal.z); + slope->zdelta = FixedDiv(slope->extent, slope->normal.z); // Get angles slope->xydirection = R_PointToAngle2(0, 0, slope->d.x, slope->d.y)+ANGLE_180; @@ -92,95 +94,88 @@ static void ReconfigureViaVertexes (pslope_t *slope, const vector3_t v1, const v } } -/// Recalculate dynamic slopes. -void T_DynamicSlopeLine (dynplanethink_t* th) -{ - pslope_t* slope = th->slope; - line_t* srcline = th->sourceline; +// Recalculate dynamic slopes +void P_RunDynamicSlopes(void) { + pslope_t *slope; - fixed_t zdelta; + for (slope = slopelist; slope; slope = slope->next) { + fixed_t zdelta; - switch(th->type) { - case DP_FRONTFLOOR: - zdelta = srcline->backsector->floorheight - srcline->frontsector->floorheight; - slope->o.z = srcline->frontsector->floorheight; - break; + if (slope->flags & SL_NODYNAMIC) + continue; - case DP_FRONTCEIL: - zdelta = srcline->backsector->ceilingheight - srcline->frontsector->ceilingheight; - slope->o.z = srcline->frontsector->ceilingheight; - break; + switch(slope->refpos) { + case 1: // front floor + zdelta = slope->sourceline->backsector->floorheight - slope->sourceline->frontsector->floorheight; + slope->o.z = slope->sourceline->frontsector->floorheight; + break; + case 2: // front ceiling + zdelta = slope->sourceline->backsector->ceilingheight - slope->sourceline->frontsector->ceilingheight; + slope->o.z = slope->sourceline->frontsector->ceilingheight; + break; + case 3: // back floor + zdelta = slope->sourceline->frontsector->floorheight - slope->sourceline->backsector->floorheight; + slope->o.z = slope->sourceline->backsector->floorheight; + break; + case 4: // back ceiling + zdelta = slope->sourceline->frontsector->ceilingheight - slope->sourceline->backsector->ceilingheight; + slope->o.z = slope->sourceline->backsector->ceilingheight; + break; + case 5: // vertices + { + mapthing_t *mt; + size_t i; + INT32 l; + line_t *line; - case DP_BACKFLOOR: - zdelta = srcline->frontsector->floorheight - srcline->backsector->floorheight; - slope->o.z = srcline->backsector->floorheight; - break; + for (i = 0; i < 3; i++) { + mt = slope->vertices[i]; + l = P_FindSpecialLineFromTag(799, mt->angle, -1); + if (l != -1) { + line = &lines[l]; + mt->z = line->frontsector->floorheight >> FRACBITS; + } + } - case DP_BACKCEIL: - zdelta = srcline->frontsector->ceilingheight - srcline->backsector->ceilingheight; - slope->o.z = srcline->backsector->ceilingheight; - break; + P_ReconfigureVertexSlope(slope); + } + continue; // TODO - default: - return; - } - - if (slope->zdelta != FixedDiv(zdelta, th->extent)) { - slope->zdelta = FixedDiv(zdelta, th->extent); - slope->zangle = R_PointToAngle2(0, 0, th->extent, -zdelta); - P_CalculateSlopeNormal(slope); - } -} - -/// Mapthing-defined -void T_DynamicSlopeVert (dynplanethink_t* th) -{ - pslope_t* slope = th->slope; - - size_t i; - INT32 l; - - for (i = 0; i < 3; i++) { - l = P_FindSpecialLineFromTag(799, th->tags[i], -1); - if (l != -1) { - th->vex[i].z = lines[l].frontsector->floorheight; + default: + I_Error("P_RunDynamicSlopes: slope has invalid type!"); } - else - th->vex[i].z = 0; - } - ReconfigureViaVertexes(slope, th->vex[0], th->vex[1], th->vex[2]); + if (slope->zdelta != FixedDiv(zdelta, slope->extent)) { + slope->zdelta = FixedDiv(zdelta, slope->extent); + slope->zangle = R_PointToAngle2(0, 0, slope->extent, -zdelta); + P_CalculateSlopeNormal(slope); + } + } } -static inline void P_AddDynSlopeThinker (pslope_t* slope, dynplanetype_t type, line_t* sourceline, fixed_t extent, const INT16 tags[3], const vector3_t vx[3]) +// +// P_MakeSlope +// +// Alocates and fill the contents of a slope structure. +// +static pslope_t *P_MakeSlope(const vector3_t *o, const vector2_t *d, + const fixed_t zdelta, UINT8 flags) { - dynplanethink_t* th = Z_Calloc(sizeof (*th), PU_LEVSPEC, NULL); - switch (type) - { - case DP_VERTEX: - th->thinker.function.acp1 = (actionf_p1)T_DynamicSlopeVert; - memcpy(th->tags, tags, sizeof(th->tags)); - memcpy(th->vex, vx, sizeof(th->vex)); - break; - default: - th->thinker.function.acp1 = (actionf_p1)T_DynamicSlopeLine; - th->sourceline = sourceline; - th->extent = extent; - } + pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL); + memset(ret, 0, sizeof(*ret)); - th->slope = slope; - th->type = type; + ret->o.x = o->x; + ret->o.y = o->y; + ret->o.z = o->z; - P_AddThinker(THINK_DYNSLOPE, &th->thinker); -} + ret->d.x = d->x; + ret->d.y = d->y; + ret->zdelta = zdelta; -/// Create a new slope and add it to the slope list. -static inline pslope_t* Slope_Add (const UINT8 flags) -{ - pslope_t *ret = Z_Calloc(sizeof(pslope_t), PU_LEVEL, NULL); ret->flags = flags; + // Add to the slope list ret->next = slopelist; slopelist = ret; @@ -190,24 +185,13 @@ static inline pslope_t* Slope_Add (const UINT8 flags) return ret; } -/// Alocates and fill the contents of a slope structure. -static pslope_t *MakeViaVectors(const vector3_t *o, const vector2_t *d, - const fixed_t zdelta, UINT8 flags) -{ - pslope_t *ret = Slope_Add(flags); - - FV3_Copy(&ret->o, o); - FV2_Copy(&ret->d, d); - - ret->zdelta = zdelta; - - ret->flags = flags; - - return ret; -} - -/// Get furthest perpendicular distance from all vertexes in a sector for a given line. -static fixed_t GetExtent(sector_t *sector, line_t *line) +// +// P_GetExtent +// +// Returns the distance to the first line within the sector that +// is intersected by a line parallel to the plane normal with the point (ox, oy) +// +static fixed_t P_GetExtent(sector_t *sector, line_t *line) { // ZDoom code reference: v3float_t = vertex_t fixed_t fardist = -FRACUNIT; @@ -240,8 +224,14 @@ static fixed_t GetExtent(sector_t *sector, line_t *line) return fardist; } -/// Creates one or more slopes based on the given line type and front/back sectors. -static void line_SpawnViaLine(const int linenum, const boolean spawnthinker) + +// +// P_SpawnSlope_Line +// +// Creates one or more slopes based on the given line type and front/back +// sectors. +// +void P_SpawnSlope_Line(int linenum) { // With dynamic slopes, it's fine to just leave this function as normal, // because checking to see if a slope had changed will waste more memory than @@ -261,8 +251,10 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker) UINT8 flags = 0; // Slope flags if (line->flags & ML_NOSONIC) flags |= SL_NOPHYSICS; - if (line->flags & ML_NOTAILS) - flags |= SL_DYNAMIC; + if (!(line->flags & ML_NOTAILS)) + flags |= SL_NODYNAMIC; + if (line->flags & ML_NOKNUX) + flags |= SL_ANCHORVERTEX; if(!frontfloor && !backfloor && !frontceil && !backceil) { @@ -282,7 +274,6 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker) ny = -FixedDiv(line->dx, len); } - // Set origin to line's center. origin.x = line->v1->x + (line->v2->x - line->v1->x)/2; origin.y = line->v1->y + (line->v2->y - line->v1->y)/2; @@ -295,7 +286,7 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker) direction.x = nx; direction.y = ny; - extent = GetExtent(line->frontsector, line); + extent = P_GetExtent(line->frontsector, line); if(extent < 0) { @@ -313,43 +304,104 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker) if(frontfloor) { + fixed_t highest, lowest; + size_t l; point.z = line->frontsector->floorheight; // Startz dz = FixedDiv(origin.z - point.z, extent); // Destinationz // In P_SpawnSlopeLine the origin is the centerpoint of the sourcelinedef fslope = line->frontsector->f_slope = - MakeViaVectors(&point, &direction, dz, flags); + P_MakeSlope(&point, &direction, dz, flags); + + // Set up some shit + fslope->extent = extent; + fslope->refpos = 1; // Now remember that f_slope IS a vector // fslope->o = origin 3D point 1 of the vector // fslope->d = destination 3D point 2 of the vector // fslope->normal is a 3D line perpendicular to the 3D vector + // Sync the linedata of the line that started this slope + // TODO: Anything special for control sector based slopes later? + fslope->sourceline = line; + + // To find the real highz/lowz of a slope, you need to check all the vertexes + // in the slope's sector with P_GetZAt to get the REAL lowz & highz + // Although these slopes are set by floorheights the ANGLE is what a slope is, + // so technically any slope can extend on forever (they are just bound by sectors) + // *You can use sourceline as a reference to see if two slopes really are the same + + // Default points for high and low + highest = point.z > origin.z ? point.z : origin.z; + lowest = point.z < origin.z ? point.z : origin.z; + + // Now check to see what the REAL high and low points of the slope inside the sector + // TODO: Is this really needed outside of FOFs? -Red + + for (l = 0; l < line->frontsector->linecount; l++) + { + fixed_t height = P_GetZAt(line->frontsector->f_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y); + + if (height > highest) + highest = height; + + if (height < lowest) + lowest = height; + } + + // Sets extra clipping data for the frontsector's slope + fslope->highz = highest; + fslope->lowz = lowest; + fslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z); fslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y); P_CalculateSlopeNormal(fslope); - - if (spawnthinker && (flags & SL_DYNAMIC)) - P_AddDynSlopeThinker(fslope, DP_FRONTFLOOR, line, extent, NULL, NULL); } if(frontceil) { + fixed_t highest, lowest; + size_t l; origin.z = line->backsector->ceilingheight; point.z = line->frontsector->ceilingheight; dz = FixedDiv(origin.z - point.z, extent); cslope = line->frontsector->c_slope = - MakeViaVectors(&point, &direction, dz, flags); + P_MakeSlope(&point, &direction, dz, flags); + + // Set up some shit + cslope->extent = extent; + cslope->refpos = 2; + + // Sync the linedata of the line that started this slope + // TODO: Anything special for control sector based slopes later? + cslope->sourceline = line; + + // Remember the way the slope is formed + highest = point.z > origin.z ? point.z : origin.z; + lowest = point.z < origin.z ? point.z : origin.z; + + for (l = 0; l < line->frontsector->linecount; l++) + { + fixed_t height = P_GetZAt(line->frontsector->c_slope, line->frontsector->lines[l]->v1->x, line->frontsector->lines[l]->v1->y); + + if (height > highest) + highest = height; + + if (height < lowest) + lowest = height; + } + + // This line special sets extra clipping data for the frontsector's slope + cslope->highz = highest; + cslope->lowz = lowest; cslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z); cslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y); P_CalculateSlopeNormal(cslope); - - if (spawnthinker && (flags & SL_DYNAMIC)) - P_AddDynSlopeThinker(cslope, DP_FRONTCEIL, line, extent, NULL, NULL); } } if(backfloor || backceil) @@ -361,7 +413,7 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker) direction.x = -nx; direction.y = -ny; - extent = GetExtent(line->backsector, line); + extent = P_GetExtent(line->backsector, line); if(extent < 0) { @@ -377,36 +429,88 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker) if(backfloor) { + fixed_t highest, lowest; + size_t l; point.z = line->backsector->floorheight; dz = FixedDiv(origin.z - point.z, extent); fslope = line->backsector->f_slope = - MakeViaVectors(&point, &direction, dz, flags); + P_MakeSlope(&point, &direction, dz, flags); + + // Set up some shit + fslope->extent = extent; + fslope->refpos = 3; + + // Sync the linedata of the line that started this slope + // TODO: Anything special for control sector based slopes later? + fslope->sourceline = line; + + // Remember the way the slope is formed + highest = point.z > origin.z ? point.z : origin.z; + lowest = point.z < origin.z ? point.z : origin.z; + + for (l = 0; l < line->backsector->linecount; l++) + { + fixed_t height = P_GetZAt(line->backsector->f_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y); + + if (height > highest) + highest = height; + + if (height < lowest) + lowest = height; + } + + // This line special sets extra clipping data for the frontsector's slope + fslope->highz = highest; + fslope->lowz = lowest; fslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z); fslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y); P_CalculateSlopeNormal(fslope); - - if (spawnthinker && (flags & SL_DYNAMIC)) - P_AddDynSlopeThinker(fslope, DP_BACKFLOOR, line, extent, NULL, NULL); } if(backceil) { + fixed_t highest, lowest; + size_t l; origin.z = line->frontsector->ceilingheight; point.z = line->backsector->ceilingheight; dz = FixedDiv(origin.z - point.z, extent); cslope = line->backsector->c_slope = - MakeViaVectors(&point, &direction, dz, flags); + P_MakeSlope(&point, &direction, dz, flags); + + // Set up some shit + cslope->extent = extent; + cslope->refpos = 4; + + // Sync the linedata of the line that started this slope + // TODO: Anything special for control sector based slopes later? + cslope->sourceline = line; + + // Remember the way the slope is formed + highest = point.z > origin.z ? point.z : origin.z; + lowest = point.z < origin.z ? point.z : origin.z; + + for (l = 0; l < line->backsector->linecount; l++) + { + fixed_t height = P_GetZAt(line->backsector->c_slope, line->backsector->lines[l]->v1->x, line->backsector->lines[l]->v1->y); + + if (height > highest) + highest = height; + + if (height < lowest) + lowest = height; + } + + // This line special sets extra clipping data for the backsector's slope + cslope->highz = highest; + cslope->lowz = lowest; cslope->zangle = R_PointToAngle2(0, origin.z, extent, point.z); cslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y); P_CalculateSlopeNormal(cslope); - - if (spawnthinker && (flags & SL_DYNAMIC)) - P_AddDynSlopeThinker(cslope, DP_BACKCEIL, line, extent, NULL, NULL); } } @@ -414,99 +518,63 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker) return; } -/// Creates a new slope from three mapthings with the specified IDs -static pslope_t *MakeViaMapthings(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flags, const boolean spawnthinker) +// +// P_NewVertexSlope +// +// Creates a new slope from three vertices with the specified IDs +// +static pslope_t *P_NewVertexSlope(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flags) { size_t i; - mapthing_t* mt = mapthings; - mapthing_t* vertices[3] = {0}; - INT16 tags[3] = {tag1, tag2, tag3}; + mapthing_t *mt = mapthings; - vector3_t vx[3]; - pslope_t* ret = Slope_Add(flags); + pslope_t *ret = Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL); + memset(ret, 0, sizeof(*ret)); + + // Start by setting flags + ret->flags = flags; + + // Now set up the vertex list + ret->vertices = Z_Malloc(3*sizeof(mapthing_t), PU_LEVEL, NULL); + memset(ret->vertices, 0, 3*sizeof(mapthing_t)); // And... look for the vertices in question. for (i = 0; i < nummapthings; i++, mt++) { if (mt->type != 750) // Haha, I'm hijacking the old Chaos Spawn thingtype for something! continue; - if (!vertices[0] && mt->angle == tag1) - vertices[0] = mt; - else if (!vertices[1] && mt->angle == tag2) - vertices[1] = mt; - else if (!vertices[2] && mt->angle == tag3) - vertices[2] = mt; + if (!ret->vertices[0] && mt->angle == tag1) + ret->vertices[0] = mt; + else if (!ret->vertices[1] && mt->angle == tag2) + ret->vertices[1] = mt; + else if (!ret->vertices[2] && mt->angle == tag3) + ret->vertices[2] = mt; } // Now set heights for each vertex, because they haven't been set yet for (i = 0; i < 3; i++) { - mt = vertices[i]; + mt = ret->vertices[i]; if (!mt) // If a vertex wasn't found, it's game over. There's nothing you can do to recover (except maybe try and kill the slope instead - TODO?) - I_Error("MakeViaMapthings: Slope vertex %s (for linedef tag %d) not found!", sizeu1(i), tag1); - vx[i].x = mt->x << FRACBITS; - vx[i].y = mt->y << FRACBITS; + I_Error("P_NewVertexSlope: Slope vertex %s (for linedef tag %d) not found!", sizeu1(i), tag1); if (mt->extrainfo) - vx[i].z = mt->options << FRACBITS; + mt->z = mt->options; else - vx[i].z = (R_PointInSubsector(mt->x << FRACBITS, mt->y << FRACBITS)->sector->floorheight) + ((mt->options >> ZSHIFT) << FRACBITS); + mt->z = (R_PointInSubsector(mt->x << FRACBITS, mt->y << FRACBITS)->sector->floorheight >> FRACBITS) + (mt->options >> ZSHIFT); } - ReconfigureViaVertexes(ret, vx[0], vx[1], vx[2]); + P_ReconfigureVertexSlope(ret); + ret->refpos = 5; - if (spawnthinker && (flags & SL_DYNAMIC)) - P_AddDynSlopeThinker(ret, DP_VERTEX, NULL, 0, tags, vx); + // Add to the slope list + ret->next = slopelist; + slopelist = ret; + + slopecount++; + ret->id = slopecount; return ret; } -/// Create vertex based slopes. -static void line_SpawnViaVertexes(const int linenum, const boolean spawnthinker) -{ - line_t *line = lines + linenum; - side_t *side; - pslope_t **slopetoset; - UINT16 tag1, tag2, tag3; - - UINT8 flags = 0; - if (line->flags & ML_NOSONIC) - flags |= SL_NOPHYSICS; - if (line->flags & ML_NOTAILS) - flags |= SL_DYNAMIC; - - switch(line->special) - { - case 704: - slopetoset = &line->frontsector->f_slope; - side = &sides[line->sidenum[0]]; - break; - case 705: - slopetoset = &line->frontsector->c_slope; - side = &sides[line->sidenum[0]]; - break; - case 714: - slopetoset = &line->backsector->f_slope; - side = &sides[line->sidenum[1]]; - break; - case 715: - slopetoset = &line->backsector->c_slope; - side = &sides[line->sidenum[1]]; - default: - return; - } - - if (line->flags & ML_NOKNUX) - { - tag1 = line->tag; - tag2 = side->textureoffset >> FRACBITS; - tag3 = side->rowoffset >> FRACBITS; - } - else - tag1 = tag2 = tag3 = line->tag; - - *slopetoset = MakeViaMapthings(tag1, tag2, tag3, flags, spawnthinker); - - side->sector->hasslope = true; -} // @@ -547,20 +615,56 @@ pslope_t *P_SlopeById(UINT16 id) return ret; } -/// Reset slopes and read them from special lines. -void P_ResetDynamicSlopes(const UINT32 fromsave) { +// Reset the dynamic slopes pointer, and read all of the fancy schmancy slopes +void P_ResetDynamicSlopes(void) { size_t i; - - boolean spawnthinkers = !(boolean)fromsave; +#ifdef ESLOPE_TYPESHIM // Rewrite old specials to new ones, and give a console warning + boolean warned = false; +#endif slopelist = NULL; slopecount = 0; - /// Generates line special-defined slopes. + // We'll handle copy slopes later, after all the tag lists have been made. + // Yes, this means copied slopes won't affect things' spawning heights. Too bad for you. for (i = 0; i < numlines; i++) { switch (lines[i].special) { +#ifdef ESLOPE_TYPESHIM // Rewrite old specials to new ones, and give a console warning +#define WARNME if (!warned) {warned = true; CONS_Alert(CONS_WARNING, "This level uses old slope specials.\nA conversion will be needed before 2.2's release.\n");} + case 386: + case 387: + case 388: + lines[i].special += 700-386; + WARNME + P_SpawnSlope_Line(i); + break; + + case 389: + case 390: + case 391: + case 392: + lines[i].special += 710-389; + WARNME + P_SpawnSlope_Line(i); + break; + + case 393: + lines[i].special = 703; + WARNME + P_SpawnSlope_Line(i); + break; + + case 394: + case 395: + case 396: + lines[i].special += 720-394; + WARNME + break; + +#endif + case 700: case 701: case 702: @@ -569,35 +673,63 @@ void P_ResetDynamicSlopes(const UINT32 fromsave) { case 711: case 712: case 713: - line_SpawnViaLine(i, spawnthinkers); + P_SpawnSlope_Line(i); break; case 704: case 705: case 714: case 715: - line_SpawnViaVertexes(i, spawnthinkers); + { + pslope_t **slopetoset; + size_t which = lines[i].special; + + UINT8 flags = SL_VERTEXSLOPE; + if (lines[i].flags & ML_NOSONIC) + flags |= SL_NOPHYSICS; + if (!(lines[i].flags & ML_NOTAILS)) + flags |= SL_NODYNAMIC; + + if (which == 704) + { + slopetoset = &lines[i].frontsector->f_slope; + which = 0; + } + else if (which == 705) + { + slopetoset = &lines[i].frontsector->c_slope; + which = 0; + } + else if (which == 714) + { + slopetoset = &lines[i].backsector->f_slope; + which = 1; + } + else // 715 + { + slopetoset = &lines[i].backsector->c_slope; + which = 1; + } + + if (lines[i].flags & ML_NOKNUX) + *slopetoset = P_NewVertexSlope(lines[i].tag, sides[lines[i].sidenum[which]].textureoffset >> FRACBITS, + sides[lines[i].sidenum[which]].rowoffset >> FRACBITS, flags); + else + *slopetoset = P_NewVertexSlope(lines[i].tag, lines[i].tag, lines[i].tag, flags); + + sides[lines[i].sidenum[which]].sector->hasslope = true; + } break; default: break; } } - - /// Copies slopes from tagged sectors via line specials. - /// \note Doesn't actually copy, but instead they share the same pointers. - for (i = 0; i < numlines; i++) - switch (lines[i].special) - { - case 720: - case 721: - case 722: - P_CopySectorSlope(&lines[i]); - default: - break; - } } + + + // ============================================================================ // // Various utilities related to slopes diff --git a/src/p_slopes.h b/src/p_slopes.h index b674a0cf5..708a9107d 100644 --- a/src/p_slopes.h +++ b/src/p_slopes.h @@ -13,17 +13,14 @@ #ifndef P_SLOPES_H__ #define P_SLOPES_H__ -#include "m_fixed.h" // Vectors - #ifdef ESLOPE - -extern pslope_t *slopelist; -extern UINT16 slopecount; - -void P_LinkSlopeThinkers (void); - void P_CalculateSlopeNormal(pslope_t *slope); -void P_ResetDynamicSlopes(const UINT32 fromsave); +void P_ResetDynamicSlopes(void); +void P_RunDynamicSlopes(void); +// P_SpawnSlope_Line +// Creates one or more slopes based on the given line type and front/back +// sectors. +void P_SpawnSlope_Line(int linenum); // // P_CopySectorSlope @@ -44,34 +41,7 @@ void P_SlopeLaunch(mobj_t *mo); void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope); void P_ButteredSlope(mobj_t *mo); +#endif -/// Dynamic plane type enum for the thinker. Will have a different functionality depending on this. -typedef enum { - DP_FRONTFLOOR, - DP_FRONTCEIL, - DP_BACKFLOOR, - DP_BACKCEIL, - DP_VERTEX -} dynplanetype_t; - -/// Permit slopes to be dynamically altered through a thinker. -typedef struct -{ - thinker_t thinker; - - pslope_t* slope; - dynplanetype_t type; - - // Used by line slopes. - line_t* sourceline; - fixed_t extent; - - // Used by mapthing vertex slopes. - INT16 tags[3]; - vector3_t vex[3]; -} dynplanethink_t; - -void T_DynamicSlopeLine (dynplanethink_t* th); -void T_DynamicSlopeVert (dynplanethink_t* th); +// EOF #endif // #ifdef ESLOPE -#endif // #ifndef P_SLOPES_H__ diff --git a/src/p_spec.c b/src/p_spec.c index 95b6f7764..140e0f968 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -6674,6 +6674,14 @@ void P_SpawnSpecials(INT32 fromnetsave) sectors[s].midmap = lines[i].frontsector->midmap; break; + #ifdef ESLOPE // Slope copy specials. Handled here for sanity. + case 720: + case 721: + case 722: + P_CopySectorSlope(&lines[i]); + break; + #endif + default: break; } diff --git a/src/r_defs.h b/src/r_defs.h index 5cb5c43f1..52a3be80e 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -228,27 +228,46 @@ typedef struct linechain_s // Slopes #ifdef ESLOPE typedef enum { - SL_NOPHYSICS = 1, /// This plane will have no physics applied besides the positioning. - SL_DYNAMIC = 1<<1, /// This plane slope will be assigned a thinker to make it dynamic. + SL_NOPHYSICS = 1, // Don't do momentum adjustment with this slope + SL_NODYNAMIC = 1<<1, // Slope will never need to move during the level, so don't fuss with recalculating it + SL_ANCHORVERTEX = 1<<2, // Slope is using a Slope Vertex Thing to anchor its position + SL_VERTEXSLOPE = 1<<3, // Slope is built from three Slope Vertex Things } slopeflags_t; typedef struct pslope_s { UINT16 id; // The number of the slope, mostly used for netgame syncing purposes - struct pslope_s *next; // Make a linked list of dynamic slopes, for easy reference later - // The plane's definition. - vector3_t o; /// Plane origin. - vector3_t normal; /// Plane normal. + // --- Information used in clipping/projection --- + // Origin vector for the plane + vector3_t o; - vector2_t d; /// Precomputed normalized projection of the normal over XY. - fixed_t zdelta; /// Precomputed Z unit increase per XY unit. + // 2-Dimentional vector (x, y) normalized. Used to determine distance from + // the origin in 2d mapspace. (Basically a thrust of FRACUNIT in xydirection angle) + vector2_t d; + + // The rate at which z changes based on distance from the origin plane. + fixed_t zdelta; + + // The normal of the slope; will always point upward, and thus be inverted on ceilings. I think it's only needed for physics? -Red + vector3_t normal; + + // For comparing when a slope should be rendered + fixed_t lowz; + fixed_t highz; // This values only check and must be updated if the slope itself is modified - angle_t zangle; /// Precomputed angle of the plane going up from the ground (not measured in degrees). - angle_t xydirection;/// Precomputed angle of the normal's projection on the XY plane. + angle_t zangle; // Angle of the plane going up from the ground (not mesured in degrees) + angle_t xydirection; // The direction the slope is facing (north, west, south, etc.) + + struct line_s *sourceline; // The line that generated the slope + fixed_t extent; // Distance value used for recalculating zdelta + UINT8 refpos; // 1=front floor 2=front ceiling 3=back floor 4=back ceiling (used for dynamic sloping) UINT8 flags; // Slope options + mapthing_t **vertices; // List should be three long for slopes made by vertex things, or one long for slopes using one vertex thing to anchor + + struct pslope_s *next; // Make a linked list of dynamic slopes, for easy reference later } pslope_t; #endif From d0da83e5cb88cc57f8cff9f70c78626c145d06e8 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Sun, 16 Feb 2020 15:59:41 -0500 Subject: [PATCH 10/67] Remove 2.2 LoadSlope and SaveSlope --- src/p_saveg.c | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 93a080295..9791f0350 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1021,14 +1021,6 @@ static inline UINT32 SavePlayer(const player_t *player) return 0xFFFFFFFF; } -#ifdef ESLOPE -static UINT32 SaveSlope(const pslope_t *slope) -{ - if (slope) return (UINT32)(slope->id); - return 0xFFFFFFFF; -} -#endif // ESLOPE - // // SaveMobjThinker // @@ -1950,20 +1942,6 @@ static inline player_t *LoadPlayer(UINT32 player) return &players[player]; } -#ifdef ESLOPE -static inline pslope_t *LoadSlope(UINT32 slopeid) -{ - pslope_t *p = slopelist; - if (slopeid > slopecount) return NULL; - do - { - if (p->id == slopeid) - return p; - } while ((p = p->next)); - return NULL; -} -#endif // ESLOPE - // // LoadMobjThinker // From eb631e1b0981244d654251902677d5d2b56d5ce2 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Sun, 16 Feb 2020 19:44:28 -0500 Subject: [PATCH 11/67] Fixes loading net savegames on 1.1 servers Still need to fix server save code to align with this --- src/p_saveg.c | 264 ++++++++++++++++++++++++++------------------------ 1 file changed, 135 insertions(+), 129 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 9791f0350..1e7ffefe2 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2699,176 +2699,182 @@ static void P_NetUnArchiveThinkers(void) } // read in saved thinkers - for (i = 0; i < NUM_THINKERLISTS; i++) + for (;;) { - for (;;) + thinklistnum_t thinkerlist = THINK_MAIN; + thinker_t* th; + tclass = READUINT8(save_p); + + if (tclass == tc_end) + break; // leave the saved thinker reading loop + numloaded++; + + switch (tclass) { - thinker_t* th; - tclass = READUINT8(save_p); + case tc_mobj: + th = LoadMobjThinker((actionf_p1)P_MobjThinker); + thinkerlist = THINK_MOBJ; + break; - if (tclass == tc_end) - break; // leave the saved thinker reading loop - numloaded++; + case tc_ceiling: + th = LoadCeilingThinker((actionf_p1)T_MoveCeiling); + break; - switch (tclass) - { - case tc_mobj: - th = LoadMobjThinker((actionf_p1)P_MobjThinker); - break; + case tc_crushceiling: + th = LoadCeilingThinker((actionf_p1)T_CrushCeiling); + break; - case tc_ceiling: - th = LoadCeilingThinker((actionf_p1)T_MoveCeiling); - break; + case tc_floor: + th = LoadFloormoveThinker((actionf_p1)T_MoveFloor); + break; - case tc_crushceiling: - th = LoadCeilingThinker((actionf_p1)T_CrushCeiling); - break; + case tc_flash: + th = LoadLightflashThinker((actionf_p1)T_LightningFlash); + break; - case tc_floor: - th = LoadFloormoveThinker((actionf_p1)T_MoveFloor); - break; + case tc_strobe: + th = LoadStrobeThinker((actionf_p1)T_StrobeFlash); + break; - case tc_flash: - th = LoadLightflashThinker((actionf_p1)T_LightningFlash); - break; + case tc_glow: + th = LoadGlowThinker((actionf_p1)T_Glow); + break; - case tc_strobe: - th = LoadStrobeThinker((actionf_p1)T_StrobeFlash); - break; + case tc_fireflicker: + th = LoadFireflickerThinker((actionf_p1)T_FireFlicker); + break; - case tc_glow: - th = LoadGlowThinker((actionf_p1)T_Glow); - break; + case tc_elevator: + th = LoadElevatorThinker((actionf_p1)T_MoveElevator, 3); + break; - case tc_fireflicker: - th = LoadFireflickerThinker((actionf_p1)T_FireFlicker); - break; + case tc_continuousfalling: + th = LoadSpecialLevelThinker((actionf_p1)T_ContinuousFalling, 3); + break; - case tc_elevator: - th = LoadElevatorThinker((actionf_p1)T_MoveElevator, 3); - break; + case tc_thwomp: + th = LoadSpecialLevelThinker((actionf_p1)T_ThwompSector, 3); + break; - case tc_continuousfalling: - th = LoadSpecialLevelThinker((actionf_p1)T_ContinuousFalling, 3); - break; + case tc_noenemies: + th = LoadSpecialLevelThinker((actionf_p1)T_NoEnemiesSector, 0); + break; - case tc_thwomp: - th = LoadSpecialLevelThinker((actionf_p1)T_ThwompSector, 3); - break; + case tc_eachtime: + th = LoadSpecialLevelThinker((actionf_p1)T_EachTimeThinker, 0); + break; - case tc_noenemies: - th = LoadSpecialLevelThinker((actionf_p1)T_NoEnemiesSector, 0); - break; + case tc_raisesector: + th = LoadSpecialLevelThinker((actionf_p1)T_RaiseSector, 0); + break; - case tc_eachtime: - th = LoadSpecialLevelThinker((actionf_p1)T_EachTimeThinker, 0); - break; + /// \todo rewrite all the code that uses an elevator_t but isn't an elevator + /// \note working on it! + case tc_camerascanner: + th = LoadElevatorThinker((actionf_p1)T_CameraScanner, 0); + break; - case tc_raisesector: - th = LoadSpecialLevelThinker((actionf_p1)T_RaiseSector, 0); - break; + case tc_bouncecheese: + th = LoadSpecialLevelThinker((actionf_p1)T_BounceCheese, 2); + break; - /// \todo rewrite all the code that uses an elevator_t but isn't an elevator - /// \note working on it! - case tc_camerascanner: - th = LoadElevatorThinker((actionf_p1)T_CameraScanner, 0); - break; + case tc_startcrumble: + th = LoadElevatorThinker((actionf_p1)T_StartCrumble, 1); + break; - case tc_bouncecheese: - th = LoadSpecialLevelThinker((actionf_p1)T_BounceCheese, 2); - break; + case tc_marioblock: + th = LoadSpecialLevelThinker((actionf_p1)T_MarioBlock, 3); + break; - case tc_startcrumble: - th = LoadElevatorThinker((actionf_p1)T_StartCrumble, 1); - break; + case tc_marioblockchecker: + th = LoadSpecialLevelThinker((actionf_p1)T_MarioBlockChecker, 0); + break; - case tc_marioblock: - th = LoadSpecialLevelThinker((actionf_p1)T_MarioBlock, 3); - break; + case tc_spikesector: + th = LoadSpecialLevelThinker((actionf_p1)T_SpikeSector, 0); + break; - case tc_marioblockchecker: - th = LoadSpecialLevelThinker((actionf_p1)T_MarioBlockChecker, 0); - break; + case tc_floatsector: + th = LoadSpecialLevelThinker((actionf_p1)T_FloatSector, 0); + break; - case tc_spikesector: - th = LoadSpecialLevelThinker((actionf_p1)T_SpikeSector, 0); - break; + case tc_bridgethinker: + th = LoadSpecialLevelThinker((actionf_p1)T_BridgeThinker, 3); + break; - case tc_floatsector: - th = LoadSpecialLevelThinker((actionf_p1)T_FloatSector, 0); - break; + case tc_laserflash: + th = LoadLaserThinker((actionf_p1)T_LaserFlash); + break; - case tc_bridgethinker: - th = LoadSpecialLevelThinker((actionf_p1)T_BridgeThinker, 3); - break; + case tc_lightfade: + th = LoadLightlevelThinker((actionf_p1)T_LightFade); + break; - case tc_laserflash: - th = LoadLaserThinker((actionf_p1)T_LaserFlash); - break; + case tc_executor: + th = LoadExecutorThinker((actionf_p1)T_ExecutorDelay); + restoreNum = true; + break; - case tc_lightfade: - th = LoadLightlevelThinker((actionf_p1)T_LightFade); - break; - - case tc_executor: - th = LoadExecutorThinker((actionf_p1)T_ExecutorDelay); - restoreNum = true; - break; - - case tc_disappear: - th = LoadDisappearThinker((actionf_p1)T_Disappear); - break; + case tc_disappear: + th = LoadDisappearThinker((actionf_p1)T_Disappear); + break; #ifdef POLYOBJECTS - case tc_polyrotate: - th = LoadPolyrotatetThinker((actionf_p1)T_PolyObjRotate); - break; + case tc_polyrotate: + th = LoadPolyrotatetThinker((actionf_p1)T_PolyObjRotate); + thinkerlist = THINK_POLYOBJ; + break; - case tc_polymove: - th = LoadPolymoveThinker((actionf_p1)T_PolyObjMove); - break; + case tc_polymove: + th = LoadPolymoveThinker((actionf_p1)T_PolyObjMove); + thinkerlist = THINK_POLYOBJ; + break; - case tc_polywaypoint: - th = LoadPolywaypointThinker((actionf_p1)T_PolyObjWaypoint); - break; + case tc_polywaypoint: + th = LoadPolywaypointThinker((actionf_p1)T_PolyObjWaypoint); + thinkerlist = THINK_POLYOBJ; + break; - case tc_polyslidedoor: - th = LoadPolyslidedoorThinker((actionf_p1)T_PolyDoorSlide); - break; + case tc_polyslidedoor: + th = LoadPolyslidedoorThinker((actionf_p1)T_PolyDoorSlide); + thinkerlist = THINK_POLYOBJ; + break; - case tc_polyswingdoor: - th = LoadPolyswingdoorThinker((actionf_p1)T_PolyDoorSwing); - break; + case tc_polyswingdoor: + th = LoadPolyswingdoorThinker((actionf_p1)T_PolyDoorSwing); + thinkerlist = THINK_POLYOBJ; + break; - case tc_polyflag: - th = LoadPolymoveThinker((actionf_p1)T_PolyObjFlag); - break; + case tc_polyflag: + th = LoadPolymoveThinker((actionf_p1)T_PolyObjFlag); + thinkerlist = THINK_POLYOBJ; + break; - case tc_polydisplace: - th = LoadPolydisplaceThinker((actionf_p1)T_PolyObjDisplace); - break; + case tc_polydisplace: + th = LoadPolydisplaceThinker((actionf_p1)T_PolyObjDisplace); + thinkerlist = THINK_POLYOBJ; + break; #endif - case tc_scroll: - th = LoadScrollThinker((actionf_p1)T_Scroll); - break; + case tc_scroll: + th = LoadScrollThinker((actionf_p1)T_Scroll); + break; - case tc_friction: - th = LoadFrictionThinker((actionf_p1)T_Friction); - break; + case tc_friction: + th = LoadFrictionThinker((actionf_p1)T_Friction); + break; - case tc_pusher: - th = LoadPusherThinker((actionf_p1)T_Pusher); - break; + case tc_pusher: + th = LoadPusherThinker((actionf_p1)T_Pusher); + break; - default: - CONS_Alert(CONS_ERROR, "Found mobj with unknown map thing type NULL\n"); - } - if (th) - P_AddThinker(i, th); + default: + CONS_Alert(CONS_ERROR, "Found mobj with unknown map thing type NULL\n"); } - - CONS_Debug(DBG_NETPLAY, "%u thinkers loaded in list %d\n", numloaded, i); + if (th) + P_AddThinker(thinkerlist, th); } + CONS_Debug(DBG_NETPLAY, "%u thinkers loaded in list %d\n", numloaded, i); + if (restoreNum) { executor_t *delay = NULL; From 7c7d0ba9c368066c38912823260466513518a2f5 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Mon, 17 Feb 2020 00:07:04 -0500 Subject: [PATCH 12/67] gitignore --- .gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index 3090417dd..f4141918c 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,11 @@ Win32_LIB_ASM_Release /.vs /debian /assets/debian +.vscode +SRB2Kart64 +SRB2Kart32 +**/*.gif +**/*.dat +**/*.wad +**/*.pk3 +**/*.exe \ No newline at end of file From a6e48de9a307b52407ad3238c3d5ce8f15c0fba8 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 11 Dec 2019 20:26:01 +0000 Subject: [PATCH 13/67] Basic WIP tic rewind code with: * artificial lag * rewind command ... profit! --- src/d_clisrv.c | 50 +++++++++++++++++++++++++++++++++++- src/d_main.c | 2 ++ src/d_netcmd.c | 51 +++++++++++++++++++++++++++++++++++++ src/i_tcp.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++- src/p_saveg.c | 13 +++++----- src/p_saveg.h | 2 +- src/sdl/i_video.c | 4 +++ 7 files changed, 177 insertions(+), 9 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1e6904a4f..05caad542 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -144,6 +144,12 @@ char connectedservername[MAXSERVERNAME]; /// \todo WORK! boolean acceptnewnode = true; +// Horrid LXShadow stuff +ticcmd_t localTicBuffer[BACKUPTICS][MAXPLAYERS]; +UINT8 localStateBuffer[BACKUPTICS][1024 * 768]; +boolean rewindingWow = false; +int rewindingTarget = 0; + // engine // Must be a power of two @@ -1711,7 +1717,7 @@ static void CL_LoadReceivedSavegame(void) automapactive = false; // load a base level - if (P_LoadNetGame()) + if (P_LoadNetGame(false)) { CON_LogMessage(va(M_GetText("Map is now \"%s"), G_BuildMapName(gamemap))); if (strlen(mapheaderinfo[gamemap-1]->lvlttl) > 0) @@ -5209,6 +5215,9 @@ static void SV_Maketic(void) maketic++; } +int stepAheadTics = 5; +int simulatedTics = 5; + void TryRunTics(tic_t realtics) { // the machine has lagged but it is not so bad @@ -5270,6 +5279,36 @@ void TryRunTics(tic_t realtics) if (advancedemo) D_StartTitle(); else + { + if (gamestate == GS_LEVEL) + { + // record game state for rewinding + for (int i = 0; i < 32; i++) + { + localTicBuffer[gametic % BACKUPTICS][i] = netcmds[gametic % BACKUPTICS][i]; + } + save_p = localStateBuffer[gametic % BACKUPTICS]; + P_SaveNetGame(); + } + + angle_t oldAngle = localangle; + INT32 oldAiming = localaiming; + if (rewindingWow) { + // do a rewind + save_p = localStateBuffer[(gametic - rewindingTarget + BACKUPTICS) % BACKUPTICS]; + P_LoadNetGame(true); + + for (int i = 0; i < MAXPLAYERS; i++) { + for (int j = 0; j < rewindingTarget; j++) { + netcmds[(gametic - rewindingTarget + j + BACKUPTICS) % BACKUPTICS][i] = localTicBuffer[(gametic - rewindingTarget + j + BACKUPTICS) % BACKUPTICS][i]; + } + } + + // execute the tics up to that point todo + gametic -= rewindingTarget; + } + + // run the count * tics while (neededtic > gametic) { @@ -5284,6 +5323,15 @@ void TryRunTics(tic_t realtics) if (client && gamestate == GS_LEVEL && leveltime > 3 && neededtic <= gametic + cv_netticbuffer.value) break; } + + if (rewindingWow) { + // restore camera stuff because that's local anyways~ + localangle = oldAngle; + localaiming = oldAiming; + + rewindingWow = false; + } + } } else { diff --git a/src/d_main.c b/src/d_main.c index 467976c17..c2f868c61 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -604,6 +604,8 @@ static void D_Display(void) tic_t rendergametic; +void FlushAwfulDelayBuffers(); + void D_SRB2Loop(void) { tic_t oldentertics = 0, entertic = 0, realtics = 0, rendertimeout = INFTICS; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 6eb3f320a..0d0d64fa3 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -116,6 +116,9 @@ static void KartSpeed_OnChange(void); static void KartEncore_OnChange(void); static void KartComeback_OnChange(void); static void KartEliminateLast_OnChange(void); +static void Command_Savestate(void); +static void Command_Loadstate(void); +static void Command_Rewind(void); #ifdef NETGAME_DEVMODE static void Fishcake_OnChange(void); @@ -611,6 +614,11 @@ void D_RegisterServerCommands(void) #endif #endif + // experimental load/save game state for possible rewinding in netgames + COM_AddCommand("savestate", Command_Savestate); + COM_AddCommand("loadstate", Command_Loadstate); + COM_AddCommand("rewind", Command_Rewind); + // for master server connection AddMServCommands(); @@ -712,6 +720,49 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_dummyconsvar); } +// ========================================================================= +// Louis' nasty test bed +// ========================================================================= +#include "p_saveg.h" +UINT8* savedState = NULL; + +static void Command_Savestate(void) +{ + CONS_Printf("Saving game state!\n"); + + savedState = (UINT8 *)malloc(1024*768 /* lol, 1998 screen resolution */); + if (!savedState) + { + CONS_Alert(CONS_ERROR, M_GetText("Wtf this machine is weak\n")); + return; + } + + // Leave room for the uncompressed length. + save_p = savedState; + + P_SaveNetGame(); +} + +static void Command_Loadstate(void) +{ + save_p = savedState; + + P_LoadNetGame(true); + + // try and execute 10 ticcmds... + + CONS_Printf("Loading game state!\n"); +} + +extern boolean rewindingWow; +extern int rewindingTarget; + +static void Command_Rewind(void) +{ + rewindingWow = true; + rewindingTarget = COM_Argc() > 1 ? atoi(COM_Argv(1)) : 0; +} + // ========================================================================= // CLIENT STARTUP // ========================================================================= diff --git a/src/i_tcp.c b/src/i_tcp.c index fb0e5852d..e85df1e39 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -713,6 +713,48 @@ static boolean SOCK_CanGet(void) #endif #ifndef NONET +typedef struct { + boolean inUse; + + UINT8* data; + int dataLength; + + int time; + SOCKET_TYPE socket; + mysockaddr_t sockaddr; +} DelayBuffer; + +#define NUMDELAYPACKETS 200 +DelayBuffer delayPackets[NUMDELAYPACKETS]; +int delayAmount = 100; + +void FlushAwfulDelayBuffers() +{ + int time = I_GetTime(); + + socklen_t d4 = (socklen_t)sizeof(struct sockaddr_in); +#ifdef HAVE_IPV6 + socklen_t d6 = (socklen_t)sizeof(struct sockaddr_in6); +#endif + socklen_t d, da = (socklen_t)sizeof(mysockaddr_t); + + for (int i = 0; i < NUMDELAYPACKETS; i++) { + if (delayPackets[i].inUse && time - delayPackets[i].time >= delayAmount / TICRATE) { + switch (delayPackets[i].sockaddr.any.sa_family) + { + case AF_INET: d = d4; break; + #ifdef HAVE_IPV6 + case AF_INET6: d = d6; break; + #endif + default: d = da; break; + } + + sendto(delayPackets[i].socket, (char *)delayPackets[i].data, delayPackets[i].dataLength, 0, &delayPackets[i].sockaddr.any, d); + delayPackets[i].inUse = false; + } + } +} + static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr) { socklen_t d4 = (socklen_t)sizeof(struct sockaddr_in); @@ -730,7 +772,27 @@ static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr default: d = da; break; } - return sendto(socket, (char *)&doomcom->data, doomcom->datalength, 0, &sockaddr->any, d); + // LX: add a nasty experimental packet delay! + boolean writtenPacket = false; + int time = I_GetTime(); + for (int i = 0; i < NUMDELAYPACKETS; i++) { + if (!delayPackets[i].inUse) { + delayPackets[i].data = malloc(doomcom->datalength); + delayPackets[i].dataLength = doomcom->datalength; + delayPackets[i].socket = socket; + delayPackets[i].sockaddr = *sockaddr; + delayPackets[i].time = time; + delayPackets[i].inUse = true; + memcpy(delayPackets[i].data, doomcom->data, doomcom->datalength); + + break; + } + } + + // Send delayed packets + + return doomcom->datalength; + //return sendto(socket, (char *)&doomcom->data, doomcom->datalength, 0, &sockaddr->any, d); } static void SOCK_Send(void) diff --git a/src/p_saveg.c b/src/p_saveg.c index 1e7ffefe2..eba1c61a5 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -740,7 +740,7 @@ static void P_NetArchiveWorld(void) // // P_NetUnArchiveWorld // -static void P_NetUnArchiveWorld(void) +static void P_NetUnArchiveWorld(boolean preserveLevel) { UINT16 i; line_t *li; @@ -3321,10 +3321,11 @@ static void P_NetArchiveMisc(void) WRITEUINT8(save_p, 0x2e); } -static inline boolean P_NetUnArchiveMisc(void) +static inline boolean P_NetUnArchiveMisc(boolean preserveLevel) { UINT32 pig; INT32 i; + INT16 oldMap = gamemap; if (READUINT32(save_p) != ARCHIVEBLOCK_MISC) I_Error("Bad $$$.sav at archive block Misc"); @@ -3355,7 +3356,7 @@ static inline boolean P_NetUnArchiveMisc(void) encoremode = (boolean)READUINT8(save_p); - if (!P_SetupLevel(true)) + if ((!preserveLevel || (gamemap != oldMap)) && !P_SetupLevel(true)) return false; // get the time @@ -3499,15 +3500,15 @@ boolean P_LoadGame(INT16 mapoverride) return true; } -boolean P_LoadNetGame(void) +boolean P_LoadNetGame(boolean preserveLevel) { CV_LoadNetVars(&save_p); - if (!P_NetUnArchiveMisc()) + if (!P_NetUnArchiveMisc(preserveLevel)) return false; P_NetUnArchivePlayers(); if (gamestate == GS_LEVEL) { - P_NetUnArchiveWorld(); + P_NetUnArchiveWorld(preserveLevel); #ifdef POLYOBJECTS P_UnArchivePolyObjects(); #endif diff --git a/src/p_saveg.h b/src/p_saveg.h index 0992f1185..0896384d6 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -24,7 +24,7 @@ void P_SaveGame(void); void P_SaveNetGame(void); boolean P_LoadGame(INT16 mapoverride); -boolean P_LoadNetGame(void); +boolean P_LoadNetGame(boolean preserveLevel); mobj_t *P_FindNewPosition(UINT32 oldposition); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 42e0a917f..1d9362293 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1294,8 +1294,12 @@ void I_StartupMouse(void) // // I_OsPolling // +void FlushAwfulDelayBuffers(); + void I_OsPolling(void) { + FlushAwfulDelayBuffers(); + if (consolevent) I_GetConsoleEvents(); if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) From 8d6ca2646daf2747d337ad75a205244ae5dbc05a Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 11 Dec 2019 23:27:55 +0000 Subject: [PATCH 14/67] Final modifications before removing recording stuff --- src/d_clisrv.c | 102 ++++++++++++++++++++++++++++++++++++++-------- src/d_main.c | 2 +- src/d_netcmd.c | 41 +++++++++++++++++-- src/d_netcmd.h | 5 +++ src/i_tcp.c | 64 ++++++++++++----------------- src/sdl/i_video.c | 24 ++++++++++- 6 files changed, 177 insertions(+), 61 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 05caad542..0bb126a0b 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -145,8 +145,13 @@ char connectedservername[MAXSERVERNAME]; boolean acceptnewnode = true; // Horrid LXShadow stuff -ticcmd_t localTicBuffer[BACKUPTICS][MAXPLAYERS]; -UINT8 localStateBuffer[BACKUPTICS][1024 * 768]; +UINT8 gameStateBuffer[BACKUPTICS][1024 * 768]; +ticcmd_t gameTicBuffer[BACKUPTICS][MAXPLAYERS]; + +UINT8 simulatedStateBuffer[BACKUPTICS][1024 * 768]; +ticcmd_t simulatedTicBuffer[BACKUPTICS]; + +boolean gameStateBufferIsValid[BACKUPTICS]; boolean rewindingWow = false; int rewindingTarget = 0; @@ -5274,42 +5279,76 @@ void TryRunTics(tic_t realtics) return; } - if (neededtic > gametic) + // record the actual local controls + tic_t realTic = I_GetTime(); + boolean canSimulate = (gamestate == GS_LEVEL) && cv_simulate.value; + tic_t ticsToUpdate = neededtic - gametic; + static tic_t minDiff = 99, maxDiff = 0; + + // record the actual local controls for this frame + simulatedTicBuffer[realTic % BACKUPTICS] = localcmds; + + if (neededtic - gametic < minDiff) + minDiff = neededtic - gametic; + if (neededtic - gametic > maxDiff) + maxDiff = neededtic - gametic; + + if ((realTic % 35) == 0) + { + CONS_Printf("mindif %d maxdif %d\n", minDiff, maxDiff); + maxDiff = 0; + minDiff = 99; + } + + if (neededtic > gametic && !resynch_local_inprogress) { if (advancedemo) D_StartTitle(); else { - if (gamestate == GS_LEVEL) + + // REAL UPDATE PHASE + // Revert to the real state, if the real state exists + if (canSimulate) { // record game state for rewinding for (int i = 0; i < 32; i++) { - localTicBuffer[gametic % BACKUPTICS][i] = netcmds[gametic % BACKUPTICS][i]; + gameTicBuffer[gametic % BACKUPTICS][i] = netcmds[gametic % BACKUPTICS][i]; } - save_p = localStateBuffer[gametic % BACKUPTICS]; - P_SaveNetGame(); + //save_p = gameStateBuffer[gametic % BACKUPTICS]; + //P_SaveNetGame(); } angle_t oldAngle = localangle; INT32 oldAiming = localaiming; if (rewindingWow) { // do a rewind - save_p = localStateBuffer[(gametic - rewindingTarget + BACKUPTICS) % BACKUPTICS]; + save_p = gameStateBuffer[(gametic - rewindingTarget + BACKUPTICS) % BACKUPTICS]; P_LoadNetGame(true); for (int i = 0; i < MAXPLAYERS; i++) { for (int j = 0; j < rewindingTarget; j++) { - netcmds[(gametic - rewindingTarget + j + BACKUPTICS) % BACKUPTICS][i] = localTicBuffer[(gametic - rewindingTarget + j + BACKUPTICS) % BACKUPTICS][i]; + netcmds[(gametic - rewindingTarget + j + BACKUPTICS) % BACKUPTICS][i] = gameTicBuffer[(gametic - rewindingTarget + j + BACKUPTICS) % BACKUPTICS][i]; } } // execute the tics up to that point todo gametic -= rewindingTarget; + + // no more rewind plz + rewindingWow = false; } + if (canSimulate) { + if (gameStateBufferIsValid[gametic % BACKUPTICS]) { + // load the real state + save_p = gameStateBuffer[gametic % BACKUPTICS]; + P_LoadNetGame(true); + } + } - // run the count * tics + // run the tics up to the real game tic while (neededtic > gametic) { DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic)); @@ -5317,20 +5356,49 @@ void TryRunTics(tic_t realtics) G_Ticker((gametic % NEWTICRATERATIO) == 0); ExtraDataTicker(); gametic++; + consistancy[gametic%BACKUPTICS] = Consistancy(); + + if (canSimulate) { + // store this real state + save_p = gameStateBuffer[gametic % BACKUPTICS]; + P_SaveNetGame(); + gameStateBufferIsValid[gametic % BACKUPTICS] = true; + } + // Leave a certain amount of tics present in the net buffer as long as we've ran at least one tic this frame. - if (client && gamestate == GS_LEVEL && leveltime > 3 && neededtic <= gametic + cv_netticbuffer.value) - break; + //if (client && gamestate == GS_LEVEL && leveltime > 3 && neededtic <= gametic + cv_netticbuffer.value) + // break; } - if (rewindingWow) { - // restore camera stuff because that's local anyways~ - localangle = oldAngle; - localaiming = oldAiming; + // run the simulated state from here + if (canSimulate) { + for (int i = 0; i < cv_simulatetics.value; i++) { + // control other players + for (int j = 0; j < MAXPLAYERS; j++) { + if (playeringame[j] && j != consoleplayer) { + // just use their last control for now + netcmds[gametic % BACKUPTICS][j] = netcmds[(gametic - 1 + BACKUPTICS) % BACKUPTICS][j]; + } + } - rewindingWow = false; + // control self + netcmds[gametic % BACKUPTICS][consoleplayer] = simulatedTicBuffer[(realTic - cv_simulatetics.value + i + BACKUPTICS + 1) % BACKUPTICS]; + G_Ticker(true); // tic a bunch of times lol see what happens lolol + } } + + // clear gamestate buffer if we're no longer able to simulate, or things will break. + if (!canSimulate) { + for (int i = 0; i < BACKUPTICS; i++) { + gameStateBufferIsValid[i] = false; + } + } + + // restore camera stuff because that's local anyways~ + localangle = oldAngle; + localaiming = oldAiming; } } else diff --git a/src/d_main.c b/src/d_main.c index c2f868c61..658e08086 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -604,7 +604,7 @@ static void D_Display(void) tic_t rendergametic; -void FlushAwfulDelayBuffers(); +void SOCK_FlushDelayBuffers(); void D_SRB2Loop(void) { diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 0d0d64fa3..12cf3dca6 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -471,6 +471,25 @@ boolean forceresetplayers = false; boolean deferencoremode = false; UINT8 splitscreen = 0; boolean circuitmap = true; // SRB2kart +consvar_t cv_simulate = { "simulate", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL }; + +static CV_PossibleValue_t simulateTics_cons_t[] = { {0, "MIN"}, {BACKUPTICS / 2, "MAX"}, {0, NULL} }; +consvar_t cv_simulatetics = { "simulatetics", "0", 0, simulateTics_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; + +static CV_PossibleValue_t netdelay_cons_t[] = { {0, "MIN"}, {250, "MAX"}, {0, NULL} }; +consvar_t cv_netdelay = { "netdelay", "0", 0, netdelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; + +static CV_PossibleValue_t netjitter_cons_t[] = { {0, "MIN"}, {5, "MAX"}, {0, NULL} }; +consvar_t cv_netjitter = { "netjitter", "0", 0, netdelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; + +char timedemo_name[256]; +boolean timedemo_csv; +char timedemo_csv_id[256]; +boolean timedemo_quit; + +INT16 gametype = GT_COOP; +boolean splitscreen = false; +boolean circuitmap = false; INT32 adminplayers[MAXPLAYERS]; /// \warning Keep this up-to-date if you add/remove/rename net text commands @@ -619,6 +638,11 @@ void D_RegisterServerCommands(void) COM_AddCommand("loadstate", Command_Loadstate); COM_AddCommand("rewind", Command_Rewind); + CV_RegisterVar(&cv_simulate); + CV_RegisterVar(&cv_simulatetics); + CV_RegisterVar(&cv_netdelay); + CV_RegisterVar(&cv_netjitter); + // for master server connection AddMServCommands(); @@ -4793,19 +4817,28 @@ static void TimeLimit_OnChange(void) if (cv_timelimit.value != 0) { - CONS_Printf(M_GetText("Levels will end after %d minute%s.\n"),cv_timelimit.value,cv_timelimit.value == 1 ? "" : "s"); // Graue 11-17-2003 - timelimitintics = cv_timelimit.value * 60 * TICRATE; + UINT32 newtimelimit = cv_timelimit.value * 60 * TICRATE; //add hidetime for tag too! if (G_TagGametype()) - timelimitintics += hidetime * TICRATE; + newtimelimit += hidetime * TICRATE; + + if (newtimelimit != timelimitintics) + { + CONS_Printf(M_GetText("Levels will end after %d minute%s.\n"), cv_timelimit.value, cv_timelimit.value == 1 ? "" : "s"); // Graue 11-17-2003 + + timelimitintics = newtimelimit; // ...and slightly modified by LX 12-11-2019 <3 + } // Note the deliberate absence of any code preventing // pointlimit and timelimit from being set simultaneously. // Some people might like to use them together. It works. } - else if (netgame || multiplayer) + else if ((netgame || multiplayer) && timelimitintics > 0) + { + timelimitintics = 0; CONS_Printf(M_GetText("Time limit disabled\n")); + } } /** Adjusts certain settings to match a changed gametype. diff --git a/src/d_netcmd.h b/src/d_netcmd.h index e6c327abf..304d678b8 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -147,6 +147,11 @@ extern consvar_t cv_maxping; extern consvar_t cv_pingtimeout; extern consvar_t cv_showping; +extern consvar_t cv_simulate; +extern consvar_t cv_simulatetics; +extern consvar_t cv_netdelay; +extern consvar_t cv_netjitter; + extern consvar_t cv_skipmapcheck; extern consvar_t cv_sleep; diff --git a/src/i_tcp.c b/src/i_tcp.c index e85df1e39..e77e2ac22 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -722,34 +722,19 @@ typedef struct { int time; SOCKET_TYPE socket; mysockaddr_t sockaddr; + int sockaddr_size; } DelayBuffer; #define NUMDELAYPACKETS 200 DelayBuffer delayPackets[NUMDELAYPACKETS]; -int delayAmount = 100; -void FlushAwfulDelayBuffers() +void SOCK_FlushDelayBuffers() { int time = I_GetTime(); - socklen_t d4 = (socklen_t)sizeof(struct sockaddr_in); -#ifdef HAVE_IPV6 - socklen_t d6 = (socklen_t)sizeof(struct sockaddr_in6); -#endif - socklen_t d, da = (socklen_t)sizeof(mysockaddr_t); - for (int i = 0; i < NUMDELAYPACKETS; i++) { - if (delayPackets[i].inUse && time - delayPackets[i].time >= delayAmount / TICRATE) { - switch (delayPackets[i].sockaddr.any.sa_family) - { - case AF_INET: d = d4; break; - #ifdef HAVE_IPV6 - case AF_INET6: d = d6; break; - #endif - default: d = da; break; - } - - sendto(delayPackets[i].socket, (char *)delayPackets[i].data, delayPackets[i].dataLength, 0, &delayPackets[i].sockaddr.any, d); + if (delayPackets[i].inUse && (time - delayPackets[i].time) * 1000 / TICRATE >= cv_netdelay.value) { + sendto(delayPackets[i].socket, (char *)delayPackets[i].data, delayPackets[i].dataLength, 0, &delayPackets[i].sockaddr.any, delayPackets[i].sockaddr_size); delayPackets[i].inUse = false; } } @@ -772,27 +757,32 @@ static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr default: d = da; break; } - // LX: add a nasty experimental packet delay! - boolean writtenPacket = false; - int time = I_GetTime(); - for (int i = 0; i < NUMDELAYPACKETS; i++) { - if (!delayPackets[i].inUse) { - delayPackets[i].data = malloc(doomcom->datalength); - delayPackets[i].dataLength = doomcom->datalength; - delayPackets[i].socket = socket; - delayPackets[i].sockaddr = *sockaddr; - delayPackets[i].time = time; - delayPackets[i].inUse = true; - memcpy(delayPackets[i].data, doomcom->data, doomcom->datalength); + if (cv_netdelay.value > 0 || cv_netjitter.value > 0) { + // add a nasty packet delay for testing! + boolean writtenPacket = false; + int time = I_GetTime(); + for (int i = 0; i < NUMDELAYPACKETS; i++) { + if (!delayPackets[i].inUse) { + delayPackets[i].data = malloc(doomcom->datalength); + delayPackets[i].dataLength = doomcom->datalength; + delayPackets[i].socket = socket; + delayPackets[i].sockaddr = *sockaddr; + delayPackets[i].time = time + (rand() % (cv_netjitter.value + 1)); + delayPackets[i].sockaddr_size = d; + delayPackets[i].inUse = true; + memcpy(delayPackets[i].data, doomcom->data, doomcom->datalength); - break; + break; + } } + + return doomcom->datalength; + } + else + { + // send it now like a normal human netcode + return sendto(socket, (char *)&doomcom->data, doomcom->datalength, 0, &sockaddr->any, d); } - - // Send delayed packets - - return doomcom->datalength; - //return sendto(socket, (char *)&doomcom->data, doomcom->datalength, 0, &sockaddr->any, d); } static void SOCK_Send(void) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 1d9362293..9e375b3f4 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -194,17 +194,37 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) } else // windowed mode { + int xoffset = 0, yoffset = 0, arg; + if (wasfullscreen) { wasfullscreen = SDL_FALSE; SDL_SetWindowFullscreen(window, 0); } + // Reposition window only in windowed mode SDL_SetWindowSize(window, width, height); SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)), SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)) ); + + // Offset the window w/ command line parameters, useful for multiplayer testing via batch files + if (arg = M_CheckParm("-winxoff")) + { + xoffset = atoi(arg + 1 < myargc ? myargv[arg + 1] : "0"); + } + if (arg = M_CheckParm("-winyoff")) + { + yoffset = atoi(arg + 1 < myargc ? myargv[arg + 1] : "0"); + } + + if (xoffset || yoffset) + { + int x, y; + SDL_GetWindowPosition(window, &x, &y); + SDL_SetWindowPosition(window, x + xoffset, y + yoffset); + } } } else @@ -1294,11 +1314,11 @@ void I_StartupMouse(void) // // I_OsPolling // -void FlushAwfulDelayBuffers(); +void SOCK_FlushDelayBuffers(); void I_OsPolling(void) { - FlushAwfulDelayBuffers(); + SOCK_FlushDelayBuffers(); if (consolevent) I_GetConsoleEvents(); From f7838192788b695923dc47d996d7c68f4fb62126 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 15 Dec 2019 00:11:09 +0000 Subject: [PATCH 15/67] Combined smoothing and simulation; almost ready to test it Todo fix a memory leak in the level load and also fix level consistency issues. --- srb2-vc10.sln | 36 ++++-- src/d_clisrv.c | 288 +++++++++++++++++++++++++++++++++------------- src/d_main.c | 25 +++- src/d_net.c | 3 + src/i_tcp.c | 4 +- src/i_tcp.h | 3 + src/screen.c | 2 +- src/sdl/i_video.c | 6 +- 8 files changed, 268 insertions(+), 99 deletions(-) diff --git a/srb2-vc10.sln b/srb2-vc10.sln index b4415bfc0..94625fbb0 100644 --- a/srb2-vc10.sln +++ b/srb2-vc10.sln @@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "s_openal", "src\hardware\s_ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Srb2Win", "src\sdl\Srb2SDL-vc10.vcxproj", "{61BA7D3C-F77D-4D31-B718-1177FE482CF2}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Srb2DebugServer", "Srb2DebugServer\Srb2DebugServer.vcxproj", "{2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM = Debug|ARM @@ -39,8 +41,8 @@ Global {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|ARM.Build.0 = Release|ARM {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|ARM64.ActiveCfg = Release|ARM64 {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|ARM64.Build.0 = Release|ARM64 - {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.ActiveCfg = Release|Win32 - {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.Build.0 = Release|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.ActiveCfg = Debug|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.Build.0 = Debug|Win32 {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|x64.ActiveCfg = Release|x64 {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|x64.Build.0 = Release|x64 {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Debug|ARM.ActiveCfg = Debug|ARM @@ -55,8 +57,8 @@ Global {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|ARM.Build.0 = Release|ARM {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|ARM64.ActiveCfg = Release|ARM64 {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|ARM64.Build.0 = Release|ARM64 - {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.ActiveCfg = Release|Win32 - {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.Build.0 = Release|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.ActiveCfg = Debug|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.Build.0 = Debug|Win32 {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|x64.ActiveCfg = Release|x64 {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|x64.Build.0 = Release|x64 {51137D5C-4E81-4955-AACF-EA3092006051}.Debug|ARM.ActiveCfg = Debug|ARM @@ -71,8 +73,8 @@ Global {51137D5C-4E81-4955-AACF-EA3092006051}.Release|ARM.Build.0 = Release|ARM {51137D5C-4E81-4955-AACF-EA3092006051}.Release|ARM64.ActiveCfg = Release|ARM64 {51137D5C-4E81-4955-AACF-EA3092006051}.Release|ARM64.Build.0 = Release|ARM64 - {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.ActiveCfg = Release|Win32 - {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.Build.0 = Release|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.ActiveCfg = Debug|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.Build.0 = Debug|Win32 {51137D5C-4E81-4955-AACF-EA3092006051}.Release|x64.ActiveCfg = Release|x64 {51137D5C-4E81-4955-AACF-EA3092006051}.Release|x64.Build.0 = Release|x64 {73A5729C-7323-41D4-AB48-8A03C9F81603}.Debug|ARM.ActiveCfg = Debug|ARM @@ -87,8 +89,8 @@ Global {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|ARM.Build.0 = Release|ARM {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|ARM64.ActiveCfg = Release|ARM64 {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|ARM64.Build.0 = Release|ARM64 - {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.ActiveCfg = Release|Win32 - {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.Build.0 = Release|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.ActiveCfg = Debug|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.Build.0 = Debug|Win32 {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|x64.ActiveCfg = Release|x64 {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|x64.Build.0 = Release|x64 {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Debug|ARM.ActiveCfg = Debug|ARM @@ -97,7 +99,7 @@ Global {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Debug|x64.ActiveCfg = Debug|x64 {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|ARM.ActiveCfg = Release|ARM {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|ARM64.ActiveCfg = Release|ARM64 - {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|Win32.ActiveCfg = Release|Win32 + {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|Win32.ActiveCfg = Debug|Win32 {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|x64.ActiveCfg = Release|x64 {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|ARM.ActiveCfg = Debug|ARM {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|ARM.Build.0 = Debug|ARM @@ -111,10 +113,22 @@ Global {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|ARM.Build.0 = Release|ARM {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|ARM64.ActiveCfg = Release|ARM64 {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|ARM64.Build.0 = Release|ARM64 - {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.ActiveCfg = Release|Win32 - {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.Build.0 = Release|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.ActiveCfg = Debug|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.Build.0 = Debug|Win32 {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|x64.ActiveCfg = Release|x64 {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|x64.Build.0 = Release|x64 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Debug|ARM.ActiveCfg = Debug|Win32 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Debug|ARM64.ActiveCfg = Debug|Win32 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Debug|Win32.ActiveCfg = Debug|Win32 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Debug|Win32.Build.0 = Debug|Win32 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Debug|x64.ActiveCfg = Debug|x64 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Debug|x64.Build.0 = Debug|x64 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Release|ARM.ActiveCfg = Release|Win32 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Release|ARM64.ActiveCfg = Release|Win32 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Release|Win32.ActiveCfg = Release|Win32 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Release|Win32.Build.0 = Release|Win32 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Release|x64.ActiveCfg = Release|x64 + {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 0bb126a0b..bc88519db 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3368,6 +3368,8 @@ static inline void SV_GenContext(void) } } +void SOCK_FlushDelayBuffers(boolean); + // // D_QuitNetGame // Called before quitting to leave a net game @@ -3402,6 +3404,9 @@ void D_QuitNetGame(void) HSendPacket(servernode, true, 0, 0); } + // don't wait + SOCK_FlushDelayBuffers(true); + D_CloseConnection(); ClearAdminPlayers(); @@ -5220,8 +5225,25 @@ static void SV_Maketic(void) maketic++; } -int stepAheadTics = 5; -int simulatedTics = 5; +extern tic_t rendergametic; + +tic_t liveTic; +tic_t simTic; +tic_t smoothedTic; + +int netJitter; +int estimatedRTT; +int maxLiveTicOffset; +int minLiveTicOffset; +int smoothingDelay; + +#define MAXOFFSETHISTORY 35 +int ticTimeOffsetHistory[MAXOFFSETHISTORY]; + +void MakeNetDebugString(); +void RefreshNetDetections(); +boolean FindMatchingTics(int* liveTicOut, int* gameTicOut); +boolean CompareTiccmd(const ticcmd_t* a, const ticcmd_t* b); void TryRunTics(tic_t realtics) { @@ -5280,69 +5302,28 @@ void TryRunTics(tic_t realtics) } // record the actual local controls - tic_t realTic = I_GetTime(); - boolean canSimulate = (gamestate == GS_LEVEL) && cv_simulate.value; - tic_t ticsToUpdate = neededtic - gametic; - static tic_t minDiff = 99, maxDiff = 0; + boolean canSimulate = (gamestate == GS_LEVEL) && cv_simulate.value && !server; + tic_t numNewTics = neededtic - gametic; + static int controlDelay = -1; // record the actual local controls for this frame - simulatedTicBuffer[realTic % BACKUPTICS] = localcmds; + liveTic = I_GetTime(); + simulatedTicBuffer[liveTic % BACKUPTICS] = localcmds; - if (neededtic - gametic < minDiff) - minDiff = neededtic - gametic; - if (neededtic - gametic > maxDiff) - maxDiff = neededtic - gametic; - - if ((realTic % 35) == 0) - { - CONS_Printf("mindif %d maxdif %d\n", minDiff, maxDiff); - maxDiff = 0; - minDiff = 99; - } + // preserve camera changes + angle_t oldAngle = localangle; + INT32 oldAiming = localaiming; + // Run the real game as received from the server if (neededtic > gametic && !resynch_local_inprogress) { if (advancedemo) D_StartTitle(); else { - - // REAL UPDATE PHASE - // Revert to the real state, if the real state exists - if (canSimulate) - { - // record game state for rewinding - for (int i = 0; i < 32; i++) - { - gameTicBuffer[gametic % BACKUPTICS][i] = netcmds[gametic % BACKUPTICS][i]; - } - //save_p = gameStateBuffer[gametic % BACKUPTICS]; - //P_SaveNetGame(); - } - - angle_t oldAngle = localangle; - INT32 oldAiming = localaiming; - if (rewindingWow) { - // do a rewind - save_p = gameStateBuffer[(gametic - rewindingTarget + BACKUPTICS) % BACKUPTICS]; - P_LoadNetGame(true); - - for (int i = 0; i < MAXPLAYERS; i++) { - for (int j = 0; j < rewindingTarget; j++) { - netcmds[(gametic - rewindingTarget + j + BACKUPTICS) % BACKUPTICS][i] = gameTicBuffer[(gametic - rewindingTarget + j + BACKUPTICS) % BACKUPTICS][i]; - } - } - - // execute the tics up to that point todo - gametic -= rewindingTarget; - - // no more rewind plz - rewindingWow = false; - } - + // Load the real state if it exists if (canSimulate) { if (gameStateBufferIsValid[gametic % BACKUPTICS]) { - // load the real state save_p = gameStateBuffer[gametic % BACKUPTICS]; P_LoadNetGame(true); } @@ -5361,44 +5342,123 @@ void TryRunTics(tic_t realtics) if (canSimulate) { + // store this real state save_p = gameStateBuffer[gametic % BACKUPTICS]; P_SaveNetGame(); + gameStateBufferIsValid[gametic % BACKUPTICS] = true; + + // store the ticcmds used during this game tic + gameTicBuffer[gametic % BACKUPTICS][consoleplayer] = netcmds[(gametic-1) % BACKUPTICS][consoleplayer]; } // Leave a certain amount of tics present in the net buffer as long as we've ran at least one tic this frame. //if (client && gamestate == GS_LEVEL && leveltime > 3 && neededtic <= gametic + cv_netticbuffer.value) // break; } + } + } - // run the simulated state from here - if (canSimulate) { - for (int i = 0; i < cv_simulatetics.value; i++) { - // control other players - for (int j = 0; j < MAXPLAYERS; j++) { - if (playeringame[j] && j != consoleplayer) { - // just use their last control for now - netcmds[gametic % BACKUPTICS][j] = netcmds[(gametic - 1 + BACKUPTICS) % BACKUPTICS][j]; - } - } + // Overview for the new programmer and the programmer who isn't new, but doesn't have a clue what his code does becuase he didn't comment it ;) + /* + gametic is always the real tic as received from the server, plus one. the simulator does not change this! + smoothedTic is the time that we are using as a basis to cancel out jitter. this may be slightly <= gametic. + liveTic is the real time of the game from startup, used to record our commands + simTic is the time that we've simulated to, plus one. if this == gametic, we haven't simulated any - // control self - netcmds[gametic % BACKUPTICS][consoleplayer] = simulatedTicBuffer[(realTic - cv_simulatetics.value + i + BACKUPTICS + 1) % BACKUPTICS]; - G_Ticker(true); // tic a bunch of times lol see what happens lolol + gameStateBuffer[gametic] is the game state before 'gametic' executes + */ + + // Simulate the game locally + if (canSimulate) + { + int numToSimulate = 0; + boolean enableSmoothing = true; + + // run the simulated state + // find the latest available real state + // sometimes we will go backwards to buffer the updates + if (enableSmoothing) { + smoothedTic = liveTic - maxLiveTicOffset - 1; + + if (gameStateBufferIsValid[(smoothedTic + BACKUPTICS) % BACKUPTICS] && smoothedTic != gametic) + { + save_p = gameStateBuffer[(smoothedTic + BACKUPTICS) % BACKUPTICS]; + P_LoadNetGame(true); + } + } + else + { + smoothedTic = gametic; + } + + // this must be done after smoothedTic is set + RefreshNetDetections(); + + numToSimulate = cv_simulatetics.value; + + // simulate the rest o da future + for (int i = 0; i < numToSimulate; i++) { + // control other players + for (int j = 0; j < MAXPLAYERS; j++) { + if (playeringame[j] && j != consoleplayer) { + // just use their last control for now + netcmds[gametic % BACKUPTICS][j] = netcmds[(gametic - 1 + BACKUPTICS) % BACKUPTICS][j]; } } - // clear gamestate buffer if we're no longer able to simulate, or things will break. - if (!canSimulate) { - for (int i = 0; i < BACKUPTICS; i++) { - gameStateBufferIsValid[i] = false; - } - } + // control self + netcmds[gametic % BACKUPTICS][consoleplayer] = simulatedTicBuffer[(liveTic - estimatedRTT + i + BACKUPTICS + 1) % BACKUPTICS]; + G_Ticker(true); // tic a bunch of times lol see what happens lolol + } - // restore camera stuff because that's local anyways~ - localangle = oldAngle; - localaiming = oldAiming; + simTic = gametic + numToSimulate; + rendergametic = 0; // hack to make sure game doesn't jitter + + // restore local camera stuff because that's local anyways~ + localangle = oldAngle; + localaiming = oldAiming; + } + else + { + // clear gamestate buffer if we're no longer able to simulate, or things will break. + for (int i = 0; i < BACKUPTICS; i++) { + gameStateBufferIsValid[i] = false; + } + + simTic = gametic; + smoothedTic = gametic; + } + + // we're gonna need more debugs... + MakeNetDebugString(); +} + +void RefreshNetDetections() +{ + // Refresh the time offset between real time and server time + minLiveTicOffset = INT_MAX; + maxLiveTicOffset = INT_MIN; + + ticTimeOffsetHistory[liveTic % MAXOFFSETHISTORY] = (int)liveTic - (int)gametic; + + // Find the net jitter based on the last 20 frames + for (int i = 0; i < MAXOFFSETHISTORY; i++) + { + minLiveTicOffset = min(minLiveTicOffset, ticTimeOffsetHistory[i]); + maxLiveTicOffset = max(maxLiveTicOffset, ticTimeOffsetHistory[i]); + } + + netJitter = min(5, maxLiveTicOffset - minLiveTicOffset); + + // Match tics + if (!(gametic % 35)) + { + int matchingLiveTic, matchingGameTic; + if (FindMatchingTics(&matchingLiveTic, &matchingGameTic) && matchingLiveTic - matchingGameTic < 15) + { + estimatedRTT = matchingLiveTic - matchingGameTic; } } else @@ -5407,14 +5467,80 @@ void TryRunTics(tic_t realtics) } } +char netDebugText[10000]; -/* Ping Update except better: - We call this once per second and check for people's pings. If their ping happens to be too high, we increment some timer and kick them out. - If they're not lagging, decrement the timer by 1. Of course, reset all of this if they leave. +void MakeNetDebugString() +{ + int matchingLiveTic, matchingGameTic; + boolean hasMatchedTics = FindMatchingTics(&matchingLiveTic, &matchingGameTic); - Why do we do that? Well, I'm a person with unfortunately sometimes unstable internet and happen to keep getting kicked very unconveniently for very short high spikes. (700+ ms) - Because my spikes are so high, the average ping is exponentially higher too (700s really add up...!) which leads me to getting kicked for a short burst of spiking. - With this change here, this doesn't happen anymore as it checks if my ping has been CONSISTENTLY bad for long enough before killing me. + if (!hasMatchedTics) { + matchingLiveTic = matchingGameTic = -1; + } + + netDebugText[0] = 0; + + for (int i = 15; i >= 0; i--) + { + if ((tic_t)i >= simTic - gametic) { + // show tics and matches + sprintf(&netDebugText[strlen(netDebugText)], + "srv: %d%slcl: %d%s\n", + gametic - i, + (i == matchingGameTic ? "<" : " "), + liveTic - i, + (i == matchingLiveTic ? "<" : " ")); + } + else { + sprintf(&netDebugText[strlen(netDebugText)], + "____ %d_lcl: %d%s\n", + simTic, + //(i == matchingGameTic ? "<" : " "), + liveTic - i, + (i == matchingLiveTic ? "<" : " ")); + } + } + + sprintf(&netDebugText[strlen(netDebugText)], "\n\nJitter: %d", netJitter); + if (hasMatchedTics) { + sprintf(&netDebugText[strlen(netDebugText)], "\nPing: %d", matchingLiveTic - matchingGameTic); + } +} + +// startTic and endTics are tics going back in time from the current liveTic +boolean FindMatchingTics(int* liveTicOut, int* gameTicOut) { + int latestGameTic = INT_MAX; + + for (int i = 0; i < BACKUPTICS; i++) { + // display estimated matching frames + for (int j = 0; j < BACKUPTICS - 1; j++) { + // if this and the previous tic were different (interesting delta), and this matches some point in the tic buffer, say wow and use that towel + if (!CompareTiccmd(&simulatedTicBuffer[(liveTic - i + BACKUPTICS) % BACKUPTICS], &simulatedTicBuffer[(liveTic - i - 1 + BACKUPTICS) % BACKUPTICS]) + && CompareTiccmd(&simulatedTicBuffer[(liveTic - i + BACKUPTICS) % BACKUPTICS], &gameTicBuffer[(smoothedTic - j + BACKUPTICS) % BACKUPTICS][consoleplayer]) + && CompareTiccmd(&simulatedTicBuffer[(liveTic - i - 1 + BACKUPTICS) % BACKUPTICS], &gameTicBuffer[(smoothedTic - j - 1 + BACKUPTICS) % BACKUPTICS][consoleplayer])) + { + if (j < latestGameTic && i >= j) { // i >= j: uses >= because gameTicBuffer[gametic] is actually the controls used in the -last- tic + latestGameTic = j; + *liveTicOut = i; + *gameTicOut = j; + } + } + } + } + + return (latestGameTic != INT_MAX); +} + +boolean CompareTiccmd(const ticcmd_t* a, const ticcmd_t* b) +{ + return a->aiming == b->aiming && (a->angleturn&~TICCMD_RECEIVED) == (b->angleturn&~TICCMD_RECEIVED) && a->buttons == b->buttons + && a->forwardmove == b->forwardmove && a->sidemove == b->sidemove; +} + +/* +Ping Update except better: +We call this once per second and check for people's pings. If their ping happens to be too high, we increment some timer and kick them out. +If they're not lagging, decrement the timer by 1. Of course, reset all of this if they leave. */ static INT32 pingtimeout[MAXPLAYERS]; diff --git a/src/d_main.c b/src/d_main.c index 658e08086..4db455687 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -153,6 +153,8 @@ char srb2path[256] = "."; boolean usehome = true; const char *pandf = "%s" PATHSEP "%s"; +extern char netDebugText[10000]; + // // EVENT HANDLING // @@ -590,6 +592,27 @@ static void D_Display(void) snprintf(s, sizeof s - 1, "SysMiss %.2f%%", lostpercent); V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-10, V_YELLOWMAP, s); } + + if (netDebugText[0] != 0) + { + const char* str = netDebugText; + int y = 0; + + while (str != NULL) + { + char temp[1024]; + const char* nextStr = strstr(str + 1, "\n"); + int len = nextStr ? nextStr - str : strlen(str); + + strncpy(temp, str, len); + temp[len] = 0; + + V_DrawRightAlignedSmallString(BASEVIDWIDTH, y, V_YELLOWMAP, temp); + + y += 5; + str = nextStr; + } + } if (cv_shittyscreen.value) V_DrawVhsEffect(cv_shittyscreen.value == 2); @@ -604,8 +627,6 @@ static void D_Display(void) tic_t rendergametic; -void SOCK_FlushDelayBuffers(); - void D_SRB2Loop(void) { tic_t oldentertics = 0, entertic = 0, realtics = 0, rendertimeout = INFTICS; diff --git a/src/d_net.c b/src/d_net.c index 94b11d518..173cebe3f 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -1452,6 +1452,9 @@ void D_CloseConnection(void) for (i = 0; i < MAXNETNODES; i++) Net_CloseConnection(i|FORCECLOSE); + // don't delay this! + SOCK_FlushDelayBuffers(true); + InitAck(); if (I_NetCloseSocket) diff --git a/src/i_tcp.c b/src/i_tcp.c index e77e2ac22..c0f02ae87 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -728,12 +728,12 @@ typedef struct { #define NUMDELAYPACKETS 200 DelayBuffer delayPackets[NUMDELAYPACKETS]; -void SOCK_FlushDelayBuffers() +void SOCK_FlushDelayBuffers(boolean flushImmediate) { int time = I_GetTime(); for (int i = 0; i < NUMDELAYPACKETS; i++) { - if (delayPackets[i].inUse && (time - delayPackets[i].time) * 1000 / TICRATE >= cv_netdelay.value) { + if (delayPackets[i].inUse && ((time - delayPackets[i].time) * 1000 / TICRATE >= cv_netdelay.value || flushImmediate)) { sendto(delayPackets[i].socket, (char *)delayPackets[i].data, delayPackets[i].dataLength, 0, &delayPackets[i].sockaddr.any, delayPackets[i].sockaddr_size); delayPackets[i].inUse = false; } diff --git a/src/i_tcp.h b/src/i_tcp.h index 06680cd9b..483c1d241 100644 --- a/src/i_tcp.h +++ b/src/i_tcp.h @@ -28,4 +28,7 @@ boolean I_InitTcpNetwork(void); boolean I_InitTcpDriver(void); void I_ShutdownTcpDriver(void); +// for debug delayed networking +void SOCK_FlushDelayBuffers(boolean); + #endif diff --git a/src/screen.c b/src/screen.c index 4cb8bac5d..80cf8da3b 100644 --- a/src/screen.c +++ b/src/screen.c @@ -409,7 +409,7 @@ void SCR_DisplayTicRate(void) tic_t totaltics = 0; const UINT8 *ticcntcolor = NULL; - for (i = lasttic + 1; i < TICRATE+lasttic && i < ontic; ++i) + for (i = lasttic + 1; i < TICRATE + lasttic && i < ontic; ++i) fpsgraph[i % TICRATE] = false; fpsgraph[ontic % TICRATE] = true; diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 9e375b3f4..66481cc99 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1314,11 +1314,13 @@ void I_StartupMouse(void) // // I_OsPolling // -void SOCK_FlushDelayBuffers(); +void SOCK_FlushDelayBuffers(boolean flush); void I_OsPolling(void) { - SOCK_FlushDelayBuffers(); + SDL_Keymod mod; + + SOCK_FlushDelayBuffers(false); if (consolevent) I_GetConsoleEvents(); From a5a43ec7a960adbabb59d2bd73cec34808b394c2 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 15 Dec 2019 12:35:10 +0000 Subject: [PATCH 16/67] FIXED mobj_t LOADING MEMORY LEAK - this may still be in the live version too. Keeping some debugging stuff in here until everything's confirmed working Next steps: syncing platforms so they don't cfail --- src/d_clisrv.c | 20 ++++++++++++------- src/d_netcmd.c | 36 ++++++++++++++++++++++++++++++++++ src/p_saveg.c | 52 ++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 91 insertions(+), 17 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index bc88519db..9f7d96ca1 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5302,10 +5302,18 @@ void TryRunTics(tic_t realtics) } // record the actual local controls - boolean canSimulate = (gamestate == GS_LEVEL) && cv_simulate.value && !server; + boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= 10 && (cv_simulate.value && !server); + boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 10; tic_t numNewTics = neededtic - gametic; static int controlDelay = -1; + if (recordingStates && rewindingWow && rewindingTarget > 0) + { + save_p = gameStateBuffer[(gametic - rewindingTarget) % BACKUPTICS]; + P_LoadNetGame(true); + rewindingWow = false; + } + // record the actual local controls for this frame liveTic = I_GetTime(); simulatedTicBuffer[liveTic % BACKUPTICS] = localcmds; @@ -5340,9 +5348,7 @@ void TryRunTics(tic_t realtics) consistancy[gametic%BACKUPTICS] = Consistancy(); - - if (canSimulate) { - + if (recordingStates) { // store this real state save_p = gameStateBuffer[gametic % BACKUPTICS]; P_SaveNetGame(); @@ -5396,7 +5402,7 @@ void TryRunTics(tic_t realtics) // this must be done after smoothedTic is set RefreshNetDetections(); - numToSimulate = cv_simulatetics.value; + numToSimulate = estimatedRTT;//cv_simulatetics.value; // simulate the rest o da future for (int i = 0; i < numToSimulate; i++) { @@ -5404,7 +5410,7 @@ void TryRunTics(tic_t realtics) for (int j = 0; j < MAXPLAYERS; j++) { if (playeringame[j] && j != consoleplayer) { // just use their last control for now - netcmds[gametic % BACKUPTICS][j] = netcmds[(gametic - 1 + BACKUPTICS) % BACKUPTICS][j]; + netcmds[gametic % BACKUPTICS][j] = netcmds[(min(smoothedTic + i + 1, gametic) - 1 + BACKUPTICS) % BACKUPTICS][j]; } } @@ -5480,7 +5486,7 @@ void MakeNetDebugString() netDebugText[0] = 0; - for (int i = 15; i >= 0; i--) + for (int i = 8; i >= 0; i--) { if ((tic_t)i >= simTic - gametic) { // show tics and matches diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 12cf3dca6..a9a31442f 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -119,6 +119,7 @@ static void KartEliminateLast_OnChange(void); static void Command_Savestate(void); static void Command_Loadstate(void); static void Command_Rewind(void); +static void Command_Saveloadtest(void); #ifdef NETGAME_DEVMODE static void Fishcake_OnChange(void); @@ -637,6 +638,7 @@ void D_RegisterServerCommands(void) COM_AddCommand("savestate", Command_Savestate); COM_AddCommand("loadstate", Command_Loadstate); COM_AddCommand("rewind", Command_Rewind); + COM_AddCommand("saveloadtest", Command_Saveloadtest); CV_RegisterVar(&cv_simulate); CV_RegisterVar(&cv_simulatetics); @@ -780,6 +782,7 @@ static void Command_Loadstate(void) extern boolean rewindingWow; extern int rewindingTarget; +extern boolean memleak; static void Command_Rewind(void) { @@ -787,6 +790,39 @@ static void Command_Rewind(void) rewindingTarget = COM_Argc() > 1 ? atoi(COM_Argv(1)) : 0; } +void MemShow() { + Z_CheckHeap(-1); + CONS_Printf("\x82%s", M_GetText("Memory Info\n")); + CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TotalUsage() >> 10)); + CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC) >> 10)); + CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND) >> 10)); + CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC) >> 10)); + CONS_Printf(M_GetText("Locked cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_CACHE) >> 10)); + CONS_Printf(M_GetText("Level : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVEL) >> 10)); + CONS_Printf(M_GetText("Special thinker : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVSPEC) >> 10)); + CONS_Printf(M_GetText("All purgable : %7s KB\n"), + sizeu1(Z_TagsUsage(PU_PURGELEVEL, INT32_MAX) >> 10)); +} + +char buffer[1024 * 768]; +static void Command_Saveloadtest(void) +{ + memleak = true; + + MemShow(); + + for (int i = 0; i < 100; i++) { + save_p = buffer; + P_SaveNetGame(); + save_p = buffer; + P_LoadNetGame(true); + } + + MemShow(); + + memleak = false; +} + // ========================================================================= // CLIENT STARTUP // ========================================================================= diff --git a/src/p_saveg.c b/src/p_saveg.c index eba1c61a5..13cb55b47 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -46,6 +46,8 @@ UINT8 *save_p; #define ARCHIVEBLOCK_THINKERS 0x7F37037C #define ARCHIVEBLOCK_SPECIALS 0x7F228378 +boolean memleak = false; + // Note: This cannot be bigger // than an UINT16 typedef enum @@ -493,6 +495,7 @@ static void P_NetArchiveWorld(void) UINT8 *put; // reload the map just to see difference + UINT8* wadData = NULL; mapsector_t *ms; mapsidedef_t *msd; maplinedef_t *mld; @@ -504,22 +507,21 @@ static void P_NetArchiveWorld(void) if (W_IsLumpWad(lastloadedmaplumpnum)) // welp it's a map wad in a pk3 { // HACK: Open wad file rather quickly so we can get the data from the relevant lumps - UINT8 *wadData = W_CacheLumpNum(lastloadedmaplumpnum, PU_STATIC); + wadData = W_CacheLumpNum(lastloadedmaplumpnum, PU_STATIC); filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs); #define retrieve_mapdata(d, f)\ - d = Z_Malloc((f)->size, PU_CACHE, NULL); \ - M_Memcpy(d, wadData + (f)->filepos, (f)->size) + d = (void*)(wadData + (f)->filepos); + retrieve_mapdata(ms, fileinfo + ML_SECTORS); retrieve_mapdata(mld, fileinfo + ML_LINEDEFS); retrieve_mapdata(msd, fileinfo + ML_SIDEDEFS); #undef retrieve_mapdata - Z_Free(wadData); // we're done with this now } else // phew it's just a WAD { - ms = W_CacheLumpNum(lastloadedmaplumpnum+ML_SECTORS, PU_CACHE); - mld = W_CacheLumpNum(lastloadedmaplumpnum+ML_LINEDEFS, PU_CACHE); - msd = W_CacheLumpNum(lastloadedmaplumpnum+ML_SIDEDEFS, PU_CACHE); + ms = W_CacheLumpNum(lastloadedmaplumpnum+ML_SECTORS, PU_CACHE); + mld = W_CacheLumpNum(lastloadedmaplumpnum+ML_LINEDEFS, PU_CACHE); + msd = W_CacheLumpNum(lastloadedmaplumpnum+ML_SIDEDEFS, PU_CACHE); } for (i = 0; i < numsectors; i++, ss++, ms++) @@ -734,6 +736,12 @@ static void P_NetArchiveWorld(void) WRITEUINT16(put, 0xffff); R_ClearTextureNumCache(false); + if (wadData) + { + // memory leak fix + Z_Free(wadData); + } + save_p = put; } @@ -2674,6 +2682,23 @@ static void P_NetUnArchiveThinkers(void) I_Error("Bad $$$.sav at archive block Thinkers"); // remove all the current thinkers + /*thinker_t* debugThinkerLists[NUM_THINKERLISTS][1024]; + mobj_t* debugMobjLists[NUM_THINKERLISTS][1024]; + int numDebugThinkers[NUM_THINKERLISTS]; + + for (i = 0; i < NUM_THINKERLISTS; i++) { + int count = 0; + thinker_t* test; + thinker_t* testNext; + for (test = thlist[i].next; test != &thlist[i]; test = testNext) { + testNext = test->next; + debugThinkerLists[i][count] = test; + debugMobjLists[i][count] = (mobj_t*)test; + count++; + } + numDebugThinkers[i] = count; + }*/ + for (i = 0; i < NUM_THINKERLISTS; i++) { currentthinker = thlist[i].next; @@ -2681,16 +2706,22 @@ static void P_NetUnArchiveThinkers(void) { next = currentthinker->next; + currentthinker->references = 0; + if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) P_RemoveSavegameMobj((mobj_t *)currentthinker); // item isn't saved, don't remove it - else + else { + currentthinker->prev->next = currentthinker->next; + currentthinker->next->prev = currentthinker->prev; Z_Free(currentthinker); + } } } // we don't want the removed mobjs to come back iquetail = iquehead = 0; - P_InitThinkers(); + + //P_InitThinkers(); caused a memory leak with delayed-removed mobjs // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity for (i = 0; i < numsectors; i++) @@ -2880,7 +2911,7 @@ static void P_NetUnArchiveThinkers(void) executor_t *delay = NULL; UINT32 mobjnum; for (currentthinker = thlist[THINK_MAIN].next; currentthinker != &thlist[THINK_MAIN]; - currentthinker = currentthinker->next) + currentthinker = currentthinker->next) { if (currentthinker->function.acp1 != (actionf_p1)T_ExecutorDelay) continue; @@ -3505,6 +3536,7 @@ boolean P_LoadNetGame(boolean preserveLevel) CV_LoadNetVars(&save_p); if (!P_NetUnArchiveMisc(preserveLevel)) return false; + P_NetUnArchivePlayers(); if (gamestate == GS_LEVEL) { From 0b315a8364f59436c11d58ae0b63132dbc88fa53 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 15 Dec 2019 14:50:39 +0000 Subject: [PATCH 17/67] Fixed sectors not always rewinding correctly (save states only saved sectors that changed, so if a sector returned to its original point it would not save its state) --- src/d_clisrv.c | 25 ++++++++--- src/p_saveg.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 8 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 9f7d96ca1..28e27dee0 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5307,10 +5307,23 @@ void TryRunTics(tic_t realtics) tic_t numNewTics = neededtic - gametic; static int controlDelay = -1; + // preserve camera changes + angle_t oldAngle = localangle; + INT32 oldAiming = localaiming; + if (recordingStates && rewindingWow && rewindingTarget > 0) { save_p = gameStateBuffer[(gametic - rewindingTarget) % BACKUPTICS]; P_LoadNetGame(true); + + for (int i = 0; i < rewindingTarget; i++) { + netcmds[gametic%BACKUPTICS][consoleplayer] = gameTicBuffer[gametic - rewindingTarget + i % BACKUPTICS][consoleplayer]; + G_Ticker(true); + } + + localaiming = oldAiming; + localangle = oldAngle; + rewindingWow = false; } @@ -5318,10 +5331,6 @@ void TryRunTics(tic_t realtics) liveTic = I_GetTime(); simulatedTicBuffer[liveTic % BACKUPTICS] = localcmds; - // preserve camera changes - angle_t oldAngle = localangle; - INT32 oldAiming = localaiming; - // Run the real game as received from the server if (neededtic > gametic && !resynch_local_inprogress) { @@ -5333,7 +5342,10 @@ void TryRunTics(tic_t realtics) if (canSimulate) { if (gameStateBufferIsValid[gametic % BACKUPTICS]) { save_p = gameStateBuffer[gametic % BACKUPTICS]; + + gametic--; P_LoadNetGame(true); + gametic++; } } @@ -5402,7 +5414,7 @@ void TryRunTics(tic_t realtics) // this must be done after smoothedTic is set RefreshNetDetections(); - numToSimulate = estimatedRTT;//cv_simulatetics.value; + numToSimulate = min(estimatedRTT, cv_simulatetics.value);//cv_simulatetics.value; // simulate the rest o da future for (int i = 0; i < numToSimulate; i++) { @@ -5426,7 +5438,8 @@ void TryRunTics(tic_t realtics) localangle = oldAngle; localaiming = oldAiming; } - else + + if (!recordingStates) { // clear gamestate buffer if we're no longer able to simulate, or things will break. for (int i = 0; i < BACKUPTICS; i++) { diff --git a/src/p_saveg.c b/src/p_saveg.c index 13cb55b47..d9e27a46b 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -483,6 +483,99 @@ static void P_NetUnArchivePlayers(void) #define LD_S2BOTTEX 0x04 #define LD_S2MIDTEX 0x08 +// +// ResetSectors +// Resets the sectors in the level to their original state +// +static void ResetSectors(void) +{ + UINT8* wadData = NULL; + const mapsector_t *ms; + const mapsidedef_t *msd; + const maplinedef_t *mld; + sector_t *ss; + line_t* li; + side_t* si; + + if (W_IsLumpWad(lastloadedmaplumpnum)) // welp it's a map wad in a pk3 + { // HACK: Open wad file rather quickly so we can get the data from the relevant lumps + wadData = W_CacheLumpNum(lastloadedmaplumpnum, PU_STATIC); + filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs); +#define retrieve_mapdata(d, f)\ + d = (void*)(wadData + (f)->filepos); + + retrieve_mapdata(ms, fileinfo + ML_SECTORS); + retrieve_mapdata(mld, fileinfo + ML_LINEDEFS); + retrieve_mapdata(msd, fileinfo + ML_SIDEDEFS); +#undef retrieve_mapdata + } + else // phew it's just a WAD + { + ms = W_CacheLumpNum(lastloadedmaplumpnum + ML_SECTORS, PU_CACHE); + mld = W_CacheLumpNum(lastloadedmaplumpnum + ML_LINEDEFS, PU_CACHE); + msd = W_CacheLumpNum(lastloadedmaplumpnum + ML_SIDEDEFS, PU_CACHE); + } + + // reset every sector + // commented out lines are eh lines + // we really should do them properly, but they take effort and only have a visual effect + for (ss = sectors; ss < §ors[numsectors]; ss++, ms++) { + ss->floorheight = ms->floorheight<ceilingheight = ms->ceilingheight<floorpic = P_AddLevelFlatRuntime((char *)get); + //ss->ceilingpic = P_AddLevelFlatRuntime((char *)get); + ss->lightlevel = ms->lightlevel; + ss->special = ms->special; + + ss->floor_xoffs = ss->spawn_flr_xoffs; + ss->floor_yoffs = ss->spawn_flr_yoffs; + ss->ceiling_xoffs = ss->spawn_ceil_xoffs; + ss->ceiling_yoffs = ss->spawn_ceil_yoffs; + ss->floorpic_angle = ss->spawn_flrpic_angle; + ss->ceilingpic_angle = ss->spawn_ceilpic_angle; + ss->tag = ms->tag; // DON'T use P_ChangeSectorTag + ss->firsttag = ss->spawn_firsttag; + ss->nexttag = ss->spawn_nexttag; + //ss->extra_colormap = GetNetColormapFromList(READUINT32(get)); + + ffloor_t* floor = ss->ffloors; + + while (floor != NULL) + { + floor->flags = floor->spawnflags; + floor->alpha = floor->spawnalpha; + + floor = floor->next; + } + } + + for (li = lines; li < &lines[numlines]; li++, mld++) + { + li->special = mld->special; + if (SHORT(li->special) == 321 || SHORT(li->special) == 322) { + li->callcount = 0; + } + + si = &sides[li->sidenum[0]]; + //si->textureoffset = si->; + //si->toptexture = READINT32(get); + //si->bottomtexture = READINT32(get); + //si->midtexture = READINT32(get); + + si = &sides[li->sidenum[1]]; + //si->textureoffset = READFIXED(get); + //si->toptexture = READINT32(get); + //si->bottomtexture = READINT32(get); + //si->midtexture = READINT32(get); + } + + if (wadData) + { + Z_Free(wadData); + } +} + // // P_NetArchiveWorld // @@ -755,10 +848,28 @@ static void P_NetUnArchiveWorld(boolean preserveLevel) side_t *si; UINT8 *get; UINT8 diff, diff2; + UINT32 num_ffloors; if (READUINT32(save_p) != ARCHIVEBLOCK_WORLD) I_Error("Bad $$$.sav at archive block World"); + // initialize colormap vars because paranoia + ClearNetColormaps(); + + if (preserveLevel) { + // when we save, we only save sectors that differ from their initial state + // so if we don't reset our sectors before loading, some sector changes might not be reverted becuase they were identical to their original state when saved and thus omitted + ResetSectors(); + } + + // count the level's ffloors so that colormap loading can have an upper limit + for (i = 0; i < numsectors; i++) + { + ffloor_t *rover; + for (rover = sectors[i].ffloors; rover; rover = rover->next) + num_ffloors++; + } + get = save_p; for (;;) @@ -2682,7 +2793,7 @@ static void P_NetUnArchiveThinkers(void) I_Error("Bad $$$.sav at archive block Thinkers"); // remove all the current thinkers - /*thinker_t* debugThinkerLists[NUM_THINKERLISTS][1024]; + thinker_t* debugThinkerLists[NUM_THINKERLISTS][1024]; mobj_t* debugMobjLists[NUM_THINKERLISTS][1024]; int numDebugThinkers[NUM_THINKERLISTS]; @@ -2697,7 +2808,7 @@ static void P_NetUnArchiveThinkers(void) count++; } numDebugThinkers[i] = count; - }*/ + } for (i = 0; i < NUM_THINKERLISTS; i++) { From 4fb02a21756d2cf8a8ca92d46c927fb2c90b0cd1 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 15 Dec 2019 16:51:05 +0000 Subject: [PATCH 18/67] Platform cfails fixed! (savegames now store platform momentum) --- src/d_clisrv.c | 87 ++++++++++++++++++++++++++++++++++---------------- src/d_netcmd.c | 6 +++- src/d_netcmd.h | 1 + src/p_saveg.c | 3 ++ 4 files changed, 69 insertions(+), 28 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 28e27dee0..16b4a4a4f 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5237,11 +5237,14 @@ int maxLiveTicOffset; int minLiveTicOffset; int smoothingDelay; +int platformHeight[BACKUPTICS]; + #define MAXOFFSETHISTORY 35 int ticTimeOffsetHistory[MAXOFFSETHISTORY]; void MakeNetDebugString(); void RefreshNetDetections(); +static void PerformDebugRewinds(); boolean FindMatchingTics(int* liveTicOut, int* gameTicOut); boolean CompareTiccmd(const ticcmd_t* a, const ticcmd_t* b); @@ -5306,27 +5309,20 @@ void TryRunTics(tic_t realtics) boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 10; tic_t numNewTics = neededtic - gametic; static int controlDelay = -1; + boolean preserveSoundDisabled = sound_disabled; - // preserve camera changes - angle_t oldAngle = localangle; - INT32 oldAiming = localaiming; + // preserve camera changes while we play with simulations/rewinds + angle_t preservedAngle = localangle; + INT32 preservedAiming = localaiming; - if (recordingStates && rewindingWow && rewindingTarget > 0) + if (recordingStates) { - save_p = gameStateBuffer[(gametic - rewindingTarget) % BACKUPTICS]; - P_LoadNetGame(true); - - for (int i = 0; i < rewindingTarget; i++) { - netcmds[gametic%BACKUPTICS][consoleplayer] = gameTicBuffer[gametic - rewindingTarget + i % BACKUPTICS][consoleplayer]; - G_Ticker(true); - } - - localaiming = oldAiming; - localangle = oldAngle; - - rewindingWow = false; + PerformDebugRewinds(); } + localangle = preservedAngle; + localaiming = preservedAiming; + // record the actual local controls for this frame liveTic = I_GetTime(); simulatedTicBuffer[liveTic % BACKUPTICS] = localcmds; @@ -5341,11 +5337,12 @@ void TryRunTics(tic_t realtics) // Load the real state if it exists if (canSimulate) { if (gameStateBufferIsValid[gametic % BACKUPTICS]) { - save_p = gameStateBuffer[gametic % BACKUPTICS]; + sound_disabled = true; - gametic--; + save_p = gameStateBuffer[gametic % BACKUPTICS]; P_LoadNetGame(true); - gametic++; + + sound_disabled = preserveSoundDisabled; } } @@ -5394,6 +5391,8 @@ void TryRunTics(tic_t realtics) int numToSimulate = 0; boolean enableSmoothing = true; + sound_disabled = true; + // run the simulated state // find the latest available real state // sometimes we will go backwards to buffer the updates @@ -5422,12 +5421,12 @@ void TryRunTics(tic_t realtics) for (int j = 0; j < MAXPLAYERS; j++) { if (playeringame[j] && j != consoleplayer) { // just use their last control for now - netcmds[gametic % BACKUPTICS][j] = netcmds[(min(smoothedTic + i + 1, gametic) - 1 + BACKUPTICS) % BACKUPTICS][j]; + netcmds[gametic % BACKUPTICS][j] = gameTicBuffer[(min(smoothedTic + i, gametic) + BACKUPTICS) % BACKUPTICS][j]; } } // control self - netcmds[gametic % BACKUPTICS][consoleplayer] = simulatedTicBuffer[(liveTic - estimatedRTT + i + BACKUPTICS + 1) % BACKUPTICS]; + netcmds[gametic % BACKUPTICS][consoleplayer] = simulatedTicBuffer[(liveTic - estimatedRTT + i + 1 + BACKUPTICS) % BACKUPTICS]; G_Ticker(true); // tic a bunch of times lol see what happens lolol } @@ -5435,8 +5434,10 @@ void TryRunTics(tic_t realtics) rendergametic = 0; // hack to make sure game doesn't jitter // restore local camera stuff because that's local anyways~ - localangle = oldAngle; - localaiming = oldAiming; + localangle = preservedAngle; + localaiming = preservedAiming; + + sound_disabled = preserveSoundDisabled; } if (!recordingStates) @@ -5486,6 +5487,38 @@ void RefreshNetDetections() } } +static void PerformDebugRewinds() { + if (rewindingWow && rewindingTarget > 0) + { + save_p = gameStateBuffer[(gametic - rewindingTarget) % BACKUPTICS]; + P_LoadNetGame(true); + + for (int i = 0; i < rewindingTarget; i++) { + netcmds[gametic%BACKUPTICS][consoleplayer] = gameTicBuffer[gametic - rewindingTarget + i % BACKUPTICS][consoleplayer]; + G_Ticker(true); + } + + rewindingWow = false; + } + + if (!server && gameStateBufferIsValid[gametic % BACKUPTICS] && cv_debugsimulaterewind.value > 0 && players[consoleplayer].mo) { +/* sector_t initial = *((elevator_t*)thlist[1].next)->sector; + mobj_t initialPlayer = *players[consoleplayer].mo;*/ + + for (int i = 0; i < cv_debugsimulaterewind.value; i++) { + G_Ticker(true); + } + + save_p = gameStateBuffer[gametic % BACKUPTICS]; + P_LoadNetGame(true); + + /*sector_t current = *((elevator_t*)thlist[1].next)->sector; + mobj_t currentPlayer = *players[consoleplayer].mo;*/ + + // consistency debug checks go here + } +} + char netDebugText[10000]; void MakeNetDebugString() @@ -5504,19 +5537,19 @@ void MakeNetDebugString() if ((tic_t)i >= simTic - gametic) { // show tics and matches sprintf(&netDebugText[strlen(netDebugText)], - "srv: %d%slcl: %d%s\n", + "srv: %d%slcl: %d%s %d\n", gametic - i, (i == matchingGameTic ? "<" : " "), liveTic - i, - (i == matchingLiveTic ? "<" : " ")); + (i == matchingLiveTic ? "<" : " "), platformHeight[(gametic - i) % BACKUPTICS]); } else { sprintf(&netDebugText[strlen(netDebugText)], - "____ %d_lcl: %d%s\n", + "____ %d_lcl: %d%s %d\n", simTic, //(i == matchingGameTic ? "<" : " "), liveTic - i, - (i == matchingLiveTic ? "<" : " ")); + (i == matchingLiveTic ? "<" : " "), platformHeight[gametic % BACKUPTICS]); } } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index a9a31442f..d4d70e2a0 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -483,6 +483,9 @@ consvar_t cv_netdelay = { "netdelay", "0", 0, netdelay_cons_t, NULL, 0, NULL, NU static CV_PossibleValue_t netjitter_cons_t[] = { {0, "MIN"}, {5, "MAX"}, {0, NULL} }; consvar_t cv_netjitter = { "netjitter", "0", 0, netdelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +static CV_PossibleValue_t debugsimulaterewind_cons_t[] = { {0, "MIN"}, {BACKUPTICS - 1, "MAX"}, {0, NULL} }; +consvar_t cv_debugsimulaterewind = { "debugsimulaterewind", "0", 0, debugsimulaterewind_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; + char timedemo_name[256]; boolean timedemo_csv; char timedemo_csv_id[256]; @@ -644,6 +647,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_simulatetics); CV_RegisterVar(&cv_netdelay); CV_RegisterVar(&cv_netjitter); + CV_RegisterVar(&cv_debugsimulaterewind); // for master server connection AddMServCommands(); @@ -804,7 +808,7 @@ void MemShow() { sizeu1(Z_TagsUsage(PU_PURGELEVEL, INT32_MAX) >> 10)); } -char buffer[1024 * 768]; +static char buffer[1024 * 768]; static void Command_Saveloadtest(void) { memleak = true; diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 304d678b8..3bed1039a 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -151,6 +151,7 @@ extern consvar_t cv_simulate; extern consvar_t cv_simulatetics; extern consvar_t cv_netdelay; extern consvar_t cv_netjitter; +extern consvar_t cv_debugsimulaterewind; extern consvar_t cv_skipmapcheck; diff --git a/src/p_saveg.c b/src/p_saveg.c index d9e27a46b..f22c33bcb 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1071,6 +1071,7 @@ typedef enum #ifdef ESLOPE , MD2_SLOPE = 1<<11 #endif + MD2_PMOM = 1<<14 } mobj_diff2_t; typedef enum @@ -1239,6 +1240,8 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) diff |= MD_DSCALE; if (mobj->scalespeed != mapobjectscale/12) diff2 |= MD2_SCALESPEED; + if (mobj->pmomz != 0) + diff2 |= MD2_PMOM; if (mobj == redflag) diff |= MD_REDFLAG; From 75a4614acc6a08e5e228d6215098c8777938b38c Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 15 Dec 2019 17:08:51 +0000 Subject: [PATCH 19/67] Console now only shows messages during real game tics Fixed game tic buffer not holding other players' tics --- src/console.c | 3 ++- src/console.h | 3 +++ src/d_clisrv.c | 20 ++++++++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/console.c b/src/console.c index 28958089b..956f65d65 100644 --- a/src/console.c +++ b/src/console.c @@ -49,6 +49,7 @@ static boolean con_started = false; // console has been initialised boolean con_startup = false; // true at game startup, screen need refreshing static boolean con_forcepic = true; // at startup toggle console translucency when first off boolean con_recalc; // set true when screen size has changed + boolean con_muted = false; static tic_t con_tick; // console ticker for anim or blinking prompt cursor // con_scrollup should use time (currenttime - lasttime).. @@ -1163,7 +1164,7 @@ static void CON_Print(char *msg) INT32 controlchars = 0; // for color changing char color = '\x80'; // keep color across lines - if (msg == NULL) + if (msg == NULL || con_muted) return; if (*msg == '\3') // chat text, makes ding sound diff --git a/src/console.h b/src/console.h index 11621746c..734ae0dcb 100644 --- a/src/console.h +++ b/src/console.h @@ -26,6 +26,9 @@ extern boolean con_recalc; extern boolean con_startup; +// no messages will be printed while the console is muted +extern boolean con_muted; + // top clip value for view render: do not draw part of view hidden by console extern INT32 con_clipviewtop; diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 16b4a4a4f..b93be5699 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5365,7 +5365,9 @@ void TryRunTics(tic_t realtics) gameStateBufferIsValid[gametic % BACKUPTICS] = true; // store the ticcmds used during this game tic - gameTicBuffer[gametic % BACKUPTICS][consoleplayer] = netcmds[(gametic-1) % BACKUPTICS][consoleplayer]; + for (int i = 0; i < MAXPLAYERS; i++) { + gameTicBuffer[gametic % BACKUPTICS][i] = netcmds[(gametic - 1) % BACKUPTICS][i]; + } } // Leave a certain amount of tics present in the net buffer as long as we've ran at least one tic this frame. @@ -5392,6 +5394,7 @@ void TryRunTics(tic_t realtics) boolean enableSmoothing = true; sound_disabled = true; + con_muted = true; // run the simulated state // find the latest available real state @@ -5421,12 +5424,20 @@ void TryRunTics(tic_t realtics) for (int j = 0; j < MAXPLAYERS; j++) { if (playeringame[j] && j != consoleplayer) { // just use their last control for now - netcmds[gametic % BACKUPTICS][j] = gameTicBuffer[(min(smoothedTic + i, gametic) + BACKUPTICS) % BACKUPTICS][j]; + netcmds[gametic % BACKUPTICS][j] = gameTicBuffer[(min(smoothedTic + i + 1, gametic) + BACKUPTICS) % BACKUPTICS][j]; } } - // control self - netcmds[gametic % BACKUPTICS][consoleplayer] = simulatedTicBuffer[(liveTic - estimatedRTT + i + 1 + BACKUPTICS) % BACKUPTICS]; + // control the local player + if (smoothedTic + i < gametic) { + // we have a tiny bit more info we can glean + netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(smoothedTic + i + 1) % BACKUPTICS][consoleplayer]; + } + else + { + netcmds[gametic % BACKUPTICS][consoleplayer] = simulatedTicBuffer[(liveTic - estimatedRTT + i + 1 + BACKUPTICS) % BACKUPTICS]; + } + G_Ticker(true); // tic a bunch of times lol see what happens lolol } @@ -5438,6 +5449,7 @@ void TryRunTics(tic_t realtics) localaiming = preservedAiming; sound_disabled = preserveSoundDisabled; + con_muted = false; } if (!recordingStates) From f596bf07d5739b4e6b235bef92217aba45ffc3ed Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 15 Dec 2019 17:18:23 +0000 Subject: [PATCH 20/67] Increased ping limit a bit Time for playtesting <3 --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index b93be5699..64c708627 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5488,7 +5488,7 @@ void RefreshNetDetections() if (!(gametic % 35)) { int matchingLiveTic, matchingGameTic; - if (FindMatchingTics(&matchingLiveTic, &matchingGameTic) && matchingLiveTic - matchingGameTic < 15) + if (FindMatchingTics(&matchingLiveTic, &matchingGameTic) && matchingLiveTic - matchingGameTic < BACKUPTICS - 2) { estimatedRTT = matchingLiveTic - matchingGameTic; } From 8d3a9abda3101e9dd7bdd2dc250eef2b14050188 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 15 Dec 2019 17:26:11 +0000 Subject: [PATCH 21/67] Only show point limit change when it's actually different --- src/d_netcmd.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index d4d70e2a0..9519bb5c1 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4790,6 +4790,8 @@ void ItemFinder_OnChange(void) * \sa cv_pointlimit, TimeLimit_OnChange * \author Graue */ +static int lastpointlimit; + static void PointLimit_OnChange(void) { // Don't allow pointlimit in Single Player/Co-Op/Race! @@ -4800,15 +4802,20 @@ static void PointLimit_OnChange(void) return; } - if (cv_pointlimit.value) + if (cv_pointlimit.value != lastpointlimit) { - CONS_Printf(M_GetText("Levels will end after %s scores %d point%s.\n"), - G_GametypeHasTeams() ? M_GetText("a team") : M_GetText("someone"), - cv_pointlimit.value, - cv_pointlimit.value > 1 ? "s" : ""); + if (cv_pointlimit.value) + { + CONS_Printf(M_GetText("Levels will end after %s scores %d point%s.\n"), + G_GametypeHasTeams() ? M_GetText("a team") : M_GetText("someone"), + cv_pointlimit.value, + cv_pointlimit.value > 1 ? "s" : ""); + } + else if (netgame || multiplayer) + CONS_Printf(M_GetText("Point limit disabled\n")); } - else if (netgame || multiplayer) - CONS_Printf(M_GetText("Point limit disabled\n")); + + lastpointlimit = cv_pointlimit.value; } static void NumLaps_OnChange(void) From 2cec2a513569d4158ed94a7076e1c955625b50d0 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 15 Dec 2019 21:45:09 +0000 Subject: [PATCH 22/67] Fixed precipitation crash Might be more useful to ignore precipitation altogether in loads. Will see to this. --- src/d_clisrv.c | 29 ++++++------- src/d_netcmd.c | 10 ++--- src/d_netcmd.h | 1 + src/p_saveg.c | 109 +++++++++++++++++++++++++++++++++++++------------ 4 files changed, 103 insertions(+), 46 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 64c708627..9631d1236 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5305,23 +5305,21 @@ void TryRunTics(tic_t realtics) } // record the actual local controls - boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= 10 && (cv_simulate.value && !server); - boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 10; - tic_t numNewTics = neededtic - gametic; - static int controlDelay = -1; + boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= 10 && gametic >= BACKUPTICS && (cv_simulate.value && !server); + boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 10 && gametic >= BACKUPTICS; boolean preserveSoundDisabled = sound_disabled; // preserve camera changes while we play with simulations/rewinds - angle_t preservedAngle = localangle; - INT32 preservedAiming = localaiming; + angle_t preservedAngle = localangle[0]; + INT32 preservedAiming = localaiming[0]; if (recordingStates) { PerformDebugRewinds(); } - localangle = preservedAngle; - localaiming = preservedAiming; + localangle[0] = preservedAngle; + localaiming[0] = preservedAiming; // record the actual local controls for this frame liveTic = I_GetTime(); @@ -5391,15 +5389,14 @@ void TryRunTics(tic_t realtics) if (canSimulate) { int numToSimulate = 0; - boolean enableSmoothing = true; sound_disabled = true; - con_muted = true; + //con_muted = true; // run the simulated state // find the latest available real state // sometimes we will go backwards to buffer the updates - if (enableSmoothing) { + if (cv_netsmoothing.value) { smoothedTic = liveTic - maxLiveTicOffset - 1; if (gameStateBufferIsValid[(smoothedTic + BACKUPTICS) % BACKUPTICS] && smoothedTic != gametic) @@ -5442,14 +5439,14 @@ void TryRunTics(tic_t realtics) } simTic = gametic + numToSimulate; - rendergametic = 0; // hack to make sure game doesn't jitter + //rendergametic = 0; // hack to make sure game doesn't jitter // restore local camera stuff because that's local anyways~ - localangle = preservedAngle; - localaiming = preservedAiming; + localangle[0] = preservedAngle; + localaiming[0] = preservedAiming; sound_disabled = preserveSoundDisabled; - con_muted = false; + //con_muted = false; } if (!recordingStates) @@ -5513,7 +5510,7 @@ static void PerformDebugRewinds() { rewindingWow = false; } - if (!server && gameStateBufferIsValid[gametic % BACKUPTICS] && cv_debugsimulaterewind.value > 0 && players[consoleplayer].mo) { + if (gameStateBufferIsValid[gametic % BACKUPTICS] && cv_debugsimulaterewind.value > 0 && players[consoleplayer].mo) { /* sector_t initial = *((elevator_t*)thlist[1].next)->sector; mobj_t initialPlayer = *players[consoleplayer].mo;*/ diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 9519bb5c1..5fb87abaf 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -483,6 +483,8 @@ consvar_t cv_netdelay = { "netdelay", "0", 0, netdelay_cons_t, NULL, 0, NULL, NU static CV_PossibleValue_t netjitter_cons_t[] = { {0, "MIN"}, {5, "MAX"}, {0, NULL} }; consvar_t cv_netjitter = { "netjitter", "0", 0, netdelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_netsmoothing = { "netsmoothing", "0", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; + static CV_PossibleValue_t debugsimulaterewind_cons_t[] = { {0, "MIN"}, {BACKUPTICS - 1, "MAX"}, {0, NULL} }; consvar_t cv_debugsimulaterewind = { "debugsimulaterewind", "0", 0, debugsimulaterewind_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; @@ -491,9 +493,6 @@ boolean timedemo_csv; char timedemo_csv_id[256]; boolean timedemo_quit; -INT16 gametype = GT_COOP; -boolean splitscreen = false; -boolean circuitmap = false; INT32 adminplayers[MAXPLAYERS]; /// \warning Keep this up-to-date if you add/remove/rename net text commands @@ -647,6 +646,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_simulatetics); CV_RegisterVar(&cv_netdelay); CV_RegisterVar(&cv_netjitter); + CV_RegisterVar(&cv_netsmoothing); CV_RegisterVar(&cv_debugsimulaterewind); // for master server connection @@ -797,7 +797,7 @@ static void Command_Rewind(void) void MemShow() { Z_CheckHeap(-1); CONS_Printf("\x82%s", M_GetText("Memory Info\n")); - CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TotalUsage() >> 10)); + CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TagsUsage(0, INT32_MAX)>>10)); CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC) >> 10)); CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND) >> 10)); CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC) >> 10)); @@ -815,7 +815,7 @@ static void Command_Saveloadtest(void) MemShow(); - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 2; i++) { save_p = buffer; P_SaveNetGame(); save_p = buffer; diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 3bed1039a..edac15d43 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -151,6 +151,7 @@ extern consvar_t cv_simulate; extern consvar_t cv_simulatetics; extern consvar_t cv_netdelay; extern consvar_t cv_netjitter; +extern consvar_t cv_netsmoothing; extern consvar_t cv_debugsimulaterewind; extern consvar_t cv_skipmapcheck; diff --git a/src/p_saveg.c b/src/p_saveg.c index f22c33bcb..589f23a10 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -854,7 +854,7 @@ static void P_NetUnArchiveWorld(boolean preserveLevel) I_Error("Bad $$$.sav at archive block World"); // initialize colormap vars because paranoia - ClearNetColormaps(); + R_ClearColormaps(); if (preserveLevel) { // when we save, we only save sectors that differ from their initial state @@ -1071,7 +1071,7 @@ typedef enum #ifdef ESLOPE , MD2_SLOPE = 1<<11 #endif - MD2_PMOM = 1<<14 +// MD2_PMOM = 1<<14 } mobj_diff2_t; typedef enum @@ -1240,8 +1240,8 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) diff |= MD_DSCALE; if (mobj->scalespeed != mapobjectscale/12) diff2 |= MD2_SCALESPEED; - if (mobj->pmomz != 0) - diff2 |= MD2_PMOM; + //if (mobj->pmomz != 0) + // diff2 |= MD2_PMOM; if (mobj == redflag) diff |= MD_REDFLAG; @@ -2780,26 +2780,13 @@ static inline void LoadWhatThinker(actionf_p1 thinker) } */ -// -// P_NetUnArchiveThinkers -// -static void P_NetUnArchiveThinkers(void) -{ - thinker_t *currentthinker; - thinker_t *next; - UINT8 tclass; - UINT8 restoreNum = false; - UINT32 i; - UINT32 numloaded = 0; - - if (READUINT32(save_p) != ARCHIVEBLOCK_THINKERS) - I_Error("Bad $$$.sav at archive block Thinkers"); - - // remove all the current thinkers - thinker_t* debugThinkerLists[NUM_THINKERLISTS][1024]; - mobj_t* debugMobjLists[NUM_THINKERLISTS][1024]; - int numDebugThinkers[NUM_THINKERLISTS]; +// debug lists for the confused programmer +thinker_t* debugThinkerLists[NUM_THINKERLISTS][4096]; +mobj_t* debugMobjLists[NUM_THINKERLISTS][4096]; +int numDebugThinkers[NUM_THINKERLISTS]; +static void CollectDebugObjectList(void) { + int i; for (i = 0; i < NUM_THINKERLISTS; i++) { int count = 0; thinker_t* test; @@ -2812,9 +2799,48 @@ static void P_NetUnArchiveThinkers(void) } numDebugThinkers[i] = count; } +} +// +// P_NetUnArchiveThinkers +// +static void P_NetUnArchiveThinkers(void) +{ + thinker_t *currentthinker; + thinker_t *next; + mobj_t* currentmobj; + UINT8 tclass; + UINT8 restoreNum = false; + UINT32 i; + UINT32 numloaded = 0; + int skyviewid = -1; + int skycenterid = -1; + + if (READUINT32(save_p) != ARCHIVEBLOCK_THINKERS) + I_Error("Bad $$$.sav at archive block Thinkers"); + + /* + // preserve sky box index + for (i = 0; i < 16; i++) + { + if (skyboxmo[0] && skyboxmo[0] == skyboxviewpnts[i]) + skyviewid = i; // save id just in case + if (skyboxmo[1] && skyboxmo[1] == skyboxcenterpnts[i]) + skycenterid = i; // save id just in case + } + */ + + // providing debug lists for frustrated programmer + CollectDebugObjectList(); + + // remove all the current thinkers for (i = 0; i < NUM_THINKERLISTS; i++) { + /*if (i == THINK_PRECIP) + { + continue; // ignore precipitation + }*/ + currentthinker = thlist[i].next; for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; currentthinker = next) { @@ -2824,7 +2850,10 @@ static void P_NetUnArchiveThinkers(void) if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) P_RemoveSavegameMobj((mobj_t *)currentthinker); // item isn't saved, don't remove it + else if (currentthinker->function.acp1 == (actionf_p1)P_NullPrecipThinker) + P_RemovePrecipMobj((precipmobj_t*)currentthinker); else { + // remove it manually, bye! currentthinker->prev->next = currentthinker->next; currentthinker->next->prev = currentthinker->prev; Z_Free(currentthinker); @@ -2835,8 +2864,6 @@ static void P_NetUnArchiveThinkers(void) // we don't want the removed mobjs to come back iquetail = iquehead = 0; - //P_InitThinkers(); caused a memory leak with delayed-removed mobjs - // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity for (i = 0; i < numsectors; i++) { @@ -3019,6 +3046,7 @@ static void P_NetUnArchiveThinkers(void) } CONS_Debug(DBG_NETPLAY, "%u thinkers loaded in list %d\n", numloaded, i); + CollectDebugObjectList(); if (restoreNum) { @@ -3035,6 +3063,37 @@ static void P_NetUnArchiveThinkers(void) delay->caller = P_FindNewPosition(mobjnum); } } + + // restore skyboxes, if applicable + for (i = 0; i < sizeof(skyboxmo) / sizeof(skyboxmo[0]); i++) + skyboxmo[i] = NULL; + + /* + for (i = 0; i < sizeof(skyboxcenterpnts) / sizeof(skyboxcenterpnts[0]); i++) + { + skyboxcenterpnts[i] = NULL; + skyboxviewpnts[i] = NULL; + } + + + for (currentmobj = (mobj_t*)thlist[THINK_MOBJ].next; currentmobj != (mobj_t*)&thlist[THINK_MOBJ]; currentmobj = (mobj_t*)currentmobj->thinker.next) + { + if (currentmobj->type == MT_SKYBOX) + { + if ((currentmobj->extravalue2 >> 16) == 1) + { + skyboxcenterpnts[currentmobj->extravalue2 & 0xFFFF] = currentmobj; + } + else + { + skyboxviewpnts[currentmobj->extravalue2 & 0xFFFF] = currentmobj; + } + } + } + + skyboxmo[0] = skyboxviewpnts[(skyviewid >= 0) ? skyviewid : 0]; + skyboxmo[1] = skyboxcenterpnts[(skycenterid >= 0) ? skycenterid : 0]; + */ } /////////////////////////////////////////////////////////////////////////////// From 6bc4102dfd86d707623c6384bbfc26fc78fd83de Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 15 Dec 2019 22:05:33 +0000 Subject: [PATCH 23/67] Added artificial lag spikes Next step is to try and encode cool info into ticcmds so we can match them accurately --- src/d_netcmd.c | 3 +++ src/d_netcmd.h | 1 + src/i_tcp.c | 16 +++++++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 5fb87abaf..b903ef0b3 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -485,6 +485,8 @@ consvar_t cv_netjitter = { "netjitter", "0", 0, netdelay_cons_t, NULL, 0, NULL, consvar_t cv_netsmoothing = { "netsmoothing", "0", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_netspikes = { "netspikes", "0", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; + static CV_PossibleValue_t debugsimulaterewind_cons_t[] = { {0, "MIN"}, {BACKUPTICS - 1, "MAX"}, {0, NULL} }; consvar_t cv_debugsimulaterewind = { "debugsimulaterewind", "0", 0, debugsimulaterewind_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; @@ -647,6 +649,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_netdelay); CV_RegisterVar(&cv_netjitter); CV_RegisterVar(&cv_netsmoothing); + CV_RegisterVar(&cv_netspikes); CV_RegisterVar(&cv_debugsimulaterewind); // for master server connection diff --git a/src/d_netcmd.h b/src/d_netcmd.h index edac15d43..044d23582 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -152,6 +152,7 @@ extern consvar_t cv_simulatetics; extern consvar_t cv_netdelay; extern consvar_t cv_netjitter; extern consvar_t cv_netsmoothing; +extern consvar_t cv_netspikes; extern consvar_t cv_debugsimulaterewind; extern consvar_t cv_skipmapcheck; diff --git a/src/i_tcp.c b/src/i_tcp.c index c0f02ae87..3c3b03524 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -727,6 +727,8 @@ typedef struct { #define NUMDELAYPACKETS 200 DelayBuffer delayPackets[NUMDELAYPACKETS]; +tic_t nextSpikeTime = 0; +tic_t nextSpikeDuration = 0; void SOCK_FlushDelayBuffers(boolean flushImmediate) { @@ -747,6 +749,7 @@ static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr socklen_t d6 = (socklen_t)sizeof(struct sockaddr_in6); #endif socklen_t d, da = (socklen_t)sizeof(mysockaddr_t); + tic_t time = I_GetTime(); switch (sockaddr->any.sa_family) { @@ -757,17 +760,24 @@ static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr default: d = da; break; } - if (cv_netdelay.value > 0 || cv_netjitter.value > 0) { + if (cv_netspikes.value && time >= nextSpikeTime + nextSpikeDuration) + { + nextSpikeTime = time + (rand() % 35) + 1 * TICRATE; + nextSpikeDuration = (rand() % 10) + 1; + } + + if (cv_netdelay.value > 0 || cv_netjitter.value > 0 || (cv_netspikes.value && time >= nextSpikeTime)) { // add a nasty packet delay for testing! boolean writtenPacket = false; - int time = I_GetTime(); + int addSpike = (cv_netspikes.value && time >= nextSpikeTime) ? nextSpikeDuration : 0; + for (int i = 0; i < NUMDELAYPACKETS; i++) { if (!delayPackets[i].inUse) { delayPackets[i].data = malloc(doomcom->datalength); delayPackets[i].dataLength = doomcom->datalength; delayPackets[i].socket = socket; delayPackets[i].sockaddr = *sockaddr; - delayPackets[i].time = time + (rand() % (cv_netjitter.value + 1)); + delayPackets[i].time = time + (rand() % (cv_netjitter.value + 1)) + addSpike; delayPackets[i].sockaddr_size = d; delayPackets[i].inUse = true; memcpy(delayPackets[i].data, doomcom->data, doomcom->datalength); From f8a0eefa1add39cd1e079117b3c4a00b10a66b39 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 16 Dec 2019 00:51:56 +0000 Subject: [PATCH 24/67] New time-encoding-based synchronisation (a LOT better!) --- src/d_clisrv.c | 101 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 31 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 9631d1236..63b83d4db 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -76,6 +76,16 @@ #define MAX_REASONLENGTH 30 #define FORCECLOSE 0x8000 +// How many time bits to encode into ticcmds (aiming and angle components, respectively) +#define ENCODE_TICCMD_TIMES +#define TICCMD_TIMEBITS_AIMING 3 +#define TICCMD_TIMEBITS_ANGLE 2 +#define TICCMD_TIMEMASK_AIMING (~(0xFFFFFFFF<aiming = (ticcmd->aiming & ~TICCMD_TIMEMASK_AIMING) | (time & TICCMD_TIMEMASK_AIMING); + ticcmd->angleturn = (ticcmd->angleturn & ~(TICCMD_TIMEMASK_ANGLE<<1)) | (((time>>TICCMD_TIMEBITS_AIMING) & TICCMD_TIMEMASK_ANGLE) << 1); // <<1 due to TICCMD_RECEIVED :/ +#endif +} + +tic_t DecodeTiccmdTime(const ticcmd_t* ticcmd) +{ +#ifdef ENCODE_TICCMD_TIMES + return (ticcmd->aiming & TICCMD_TIMEMASK_AIMING) + (((ticcmd->angleturn & (TICCMD_TIMEMASK_ANGLE<<1)) >> 1) << TICCMD_TIMEBITS_AIMING); +#else + return 0; +#endif +} + // // TryRunTics // @@ -5158,6 +5188,8 @@ static void Local_Maketic(INT32 realtics) } } + EncodeTiccmdTime(&localcmds, I_GetTime()); + localcmds.angleturn |= TICCMD_RECEIVED; } @@ -5237,13 +5269,11 @@ int maxLiveTicOffset; int minLiveTicOffset; int smoothingDelay; -int platformHeight[BACKUPTICS]; - #define MAXOFFSETHISTORY 35 int ticTimeOffsetHistory[MAXOFFSETHISTORY]; void MakeNetDebugString(); -void RefreshNetDetections(); +void DetermineNetConditions(); static void PerformDebugRewinds(); boolean FindMatchingTics(int* liveTicOut, int* gameTicOut); boolean CompareTiccmd(const ticcmd_t* a, const ticcmd_t* b); @@ -5308,6 +5338,7 @@ void TryRunTics(tic_t realtics) boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= 10 && gametic >= BACKUPTICS && (cv_simulate.value && !server); boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 10 && gametic >= BACKUPTICS; boolean preserveSoundDisabled = sound_disabled; + int numNewTics = neededtic - gametic; // preserve camera changes while we play with simulations/rewinds angle_t preservedAngle = localangle[0]; @@ -5352,6 +5383,7 @@ void TryRunTics(tic_t realtics) G_Ticker((gametic % NEWTICRATERATIO) == 0); ExtraDataTicker(); gametic++; + simTic = gametic; consistancy[gametic%BACKUPTICS] = Consistancy(); @@ -5380,7 +5412,7 @@ void TryRunTics(tic_t realtics) gametic is always the real tic as received from the server, plus one. the simulator does not change this! smoothedTic is the time that we are using as a basis to cancel out jitter. this may be slightly <= gametic. liveTic is the real time of the game from startup, used to record our commands - simTic is the time that we've simulated to, plus one. if this == gametic, we haven't simulated any + simTic is the gametic we've simulated to. if this == gametic, we haven't simulated any gameStateBuffer[gametic] is the game state before 'gametic' executes */ @@ -5388,8 +5420,6 @@ void TryRunTics(tic_t realtics) // Simulate the game locally if (canSimulate) { - int numToSimulate = 0; - sound_disabled = true; //con_muted = true; @@ -5404,6 +5434,8 @@ void TryRunTics(tic_t realtics) save_p = gameStateBuffer[(smoothedTic + BACKUPTICS) % BACKUPTICS]; P_LoadNetGame(true); } + + simTic = smoothedTic; } else { @@ -5411,9 +5443,17 @@ void TryRunTics(tic_t realtics) } // this must be done after smoothedTic is set - RefreshNetDetections(); + DetermineNetConditions(); - numToSimulate = min(estimatedRTT, cv_simulatetics.value);//cv_simulatetics.value; + int targetSimTic = min(gametic + estimatedRTT, smoothedTic + cv_simulatetics.value); + + if (targetSimTic - simTic > MAXSIMULATIONS) + { + // don't simulate more than MAXSIMULATIONS + simTic = targetSimTic - MAXSIMULATIONS; + } + + int numToSimulate = targetSimTic - simTic; // simulate the rest o da future for (int i = 0; i < numToSimulate; i++) { @@ -5426,19 +5466,19 @@ void TryRunTics(tic_t realtics) } // control the local player - if (smoothedTic + i < gametic) { + if (simTic + i < gametic) { // we have a tiny bit more info we can glean - netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(smoothedTic + i + 1) % BACKUPTICS][consoleplayer]; + netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(simTic + i + 1) % BACKUPTICS][consoleplayer]; } else { - netcmds[gametic % BACKUPTICS][consoleplayer] = simulatedTicBuffer[(liveTic - estimatedRTT + i + 1 + BACKUPTICS) % BACKUPTICS]; + netcmds[gametic % BACKUPTICS][consoleplayer] = simulatedTicBuffer[(liveTic - numToSimulate + i + 1 + BACKUPTICS) % BACKUPTICS]; } G_Ticker(true); // tic a bunch of times lol see what happens lolol } - simTic = gametic + numToSimulate; + simTic = targetSimTic; //rendergametic = 0; // hack to make sure game doesn't jitter // restore local camera stuff because that's local anyways~ @@ -5464,7 +5504,7 @@ void TryRunTics(tic_t realtics) MakeNetDebugString(); } -void RefreshNetDetections() +void DetermineNetConditions() { // Refresh the time offset between real time and server time minLiveTicOffset = INT_MAX; @@ -5482,6 +5522,7 @@ void RefreshNetDetections() netJitter = min(5, maxLiveTicOffset - minLiveTicOffset); // Match tics +#ifndef ENCODE_TICCMD_TIMES if (!(gametic % 35)) { int matchingLiveTic, matchingGameTic; @@ -5490,10 +5531,16 @@ void RefreshNetDetections() estimatedRTT = matchingLiveTic - matchingGameTic; } } - else +#else + for (int j = 1; j < TICCMD_TIME_SIZE; j++) { - hu_stopped = true; + if (CompareTiccmd(&gameTicBuffer[gametic % BACKUPTICS][consoleplayer], &simulatedTicBuffer[(liveTic - j + BACKUPTICS) % BACKUPTICS])) + { + estimatedRTT = j; + break; + } } +#endif } static void PerformDebugRewinds() { @@ -5532,40 +5579,32 @@ char netDebugText[10000]; void MakeNetDebugString() { - int matchingLiveTic, matchingGameTic; - boolean hasMatchedTics = FindMatchingTics(&matchingLiveTic, &matchingGameTic); - - if (!hasMatchedTics) { - matchingLiveTic = matchingGameTic = -1; - } - netDebugText[0] = 0; - for (int i = 8; i >= 0; i--) + for (int i = 10; i >= 0; i--) { if ((tic_t)i >= simTic - gametic) { // show tics and matches sprintf(&netDebugText[strlen(netDebugText)], - "srv: %d%slcl: %d%s %d\n", + "srv: %d%slcl: %d%s\n", gametic - i, - (i == matchingGameTic ? "<" : " "), + (i == gametic ? "<" : " "), liveTic - i, - (i == matchingLiveTic ? "<" : " "), platformHeight[(gametic - i) % BACKUPTICS]); + (i == estimatedRTT ? "<" : " ")); } else { sprintf(&netDebugText[strlen(netDebugText)], - "____ %d_lcl: %d%s %d\n", + "____ %d_lcl: %d%s\n", simTic, //(i == matchingGameTic ? "<" : " "), liveTic - i, - (i == matchingLiveTic ? "<" : " "), platformHeight[gametic % BACKUPTICS]); + (i == estimatedRTT ? "<" : " ")); } } sprintf(&netDebugText[strlen(netDebugText)], "\n\nJitter: %d", netJitter); - if (hasMatchedTics) { - sprintf(&netDebugText[strlen(netDebugText)], "\nPing: %d", matchingLiveTic - matchingGameTic); - } + sprintf(&netDebugText[strlen(netDebugText)], "\nEstPing: %d", estimatedRTT); + sprintf(&netDebugText[strlen(netDebugText)], "\nSim-T: %d", simTic - gametic); } // startTic and endTics are tics going back in time from the current liveTic From 47e3616b4aea91804d57cfcebdde04667cc9aeca Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 16 Dec 2019 03:16:46 +0000 Subject: [PATCH 25/67] Hopefully? fixed CTF issues --- src/d_clisrv.c | 39 +++++++++++++++++++++++++++++++++++++-- src/p_inter.c | 2 +- src/p_mobj.c | 2 ++ src/p_saveg.c | 4 ++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 63b83d4db..6453c1999 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5335,8 +5335,9 @@ void TryRunTics(tic_t realtics) } // record the actual local controls - boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= 10 && gametic >= BACKUPTICS && (cv_simulate.value && !server); - boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 10 && gametic >= BACKUPTICS; + static boolean didSimulate = false; + boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= BACKUPTICS && gametic >= BACKUPTICS && (cv_simulate.value && !server); + boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= BACKUPTICS && gametic >= BACKUPTICS; boolean preserveSoundDisabled = sound_disabled; int numNewTics = neededtic - gametic; @@ -5344,6 +5345,24 @@ void TryRunTics(tic_t realtics) angle_t preservedAngle = localangle[0]; INT32 preservedAiming = localaiming[0]; + if (didSimulate && !canSimulate) + { + // we've stopped simulating for a while, so restore the original state before continuing + if (gameStateBufferIsValid[gametic % BACKUPTICS]) { + sound_disabled = true; + + save_p = gameStateBuffer[gametic % BACKUPTICS]; + P_LoadNetGame(true); + + sound_disabled = preserveSoundDisabled; + } + + // clear previous states + for (int i = 0; i < BACKUPTICS; i++) { + gameStateBufferIsValid[i] = false; + } + } + if (recordingStates) { PerformDebugRewinds(); @@ -5500,6 +5519,8 @@ void TryRunTics(tic_t realtics) smoothedTic = gametic; } + didSimulate = simTic != gametic || smoothedTic != gametic; + // we're gonna need more debugs... MakeNetDebugString(); } @@ -5561,6 +5582,13 @@ static void PerformDebugRewinds() { /* sector_t initial = *((elevator_t*)thlist[1].next)->sector; mobj_t initialPlayer = *players[consoleplayer].mo;*/ + int xyz = 0; + mapthing_t spawnpoint; + if (redflag) { + xyz = redflag->spawnpoint->x + redflag->spawnpoint->y + redflag->spawnpoint->z; + spawnpoint = *(redflag->spawnpoint); + } + for (int i = 0; i < cv_debugsimulaterewind.value; i++) { G_Ticker(true); } @@ -5568,6 +5596,13 @@ static void PerformDebugRewinds() { save_p = gameStateBuffer[gametic % BACKUPTICS]; P_LoadNetGame(true); + if (redflag) { + if (redflag->spawnpoint->x + redflag->spawnpoint->y + redflag->spawnpoint->z != xyz && xyz != 0) + { + CONS_Printf("Flag consistency error!\n"); + } + } + /*sector_t current = *((elevator_t*)thlist[1].next)->sector; mobj_t currentPlayer = *players[consoleplayer].mo;*/ diff --git a/src/p_inter.c b/src/p_inter.c index 404b4b38f..9f08f9560 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -924,7 +924,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) if (player->powers[pw_super]) return; - player->gotflag |= flagflag; + player->gotflag |= flagflag; // >:( CONS_Printf(M_GetText("%s picked up the %c%s%c!\n"), plname, flagcolor, flagtext, 0x80); (*flagmobj) = NULL; // code for dealing with abilities is handled elsewhere now diff --git a/src/p_mobj.c b/src/p_mobj.c index 4cfcebc1b..177fed973 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -9194,6 +9194,8 @@ void P_MobjThinker(mobj_t *mobj) blueflag = flagmo; } + + CONS_Printf("Flag respawning at %d,%d,%d type %d\n", mobj->spawnpoint->x, mobj->spawnpoint->y, mobj->spawnpoint->z, mobj->spawnpoint->type); } P_RemoveMobj(mobj); return; diff --git a/src/p_saveg.c b/src/p_saveg.c index 589f23a10..94f4e19be 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2870,6 +2870,10 @@ static void P_NetUnArchiveThinkers(void) sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = NULL; } + // clear flags (necessary for level-preserving loads) + redflag = NULL; + blueflag = NULL; + // read in saved thinkers for (;;) { From f3fea02e778f5b83dbd209b1e00096838a22b797 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 16 Dec 2019 12:20:40 +0000 Subject: [PATCH 26/67] Removed flag spawning message. next steps: fix sounds --- src/p_mobj.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 177fed973..4cfcebc1b 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -9194,8 +9194,6 @@ void P_MobjThinker(mobj_t *mobj) blueflag = flagmo; } - - CONS_Printf("Flag respawning at %d,%d,%d type %d\n", mobj->spawnpoint->x, mobj->spawnpoint->y, mobj->spawnpoint->z, mobj->spawnpoint->type); } P_RemoveMobj(mobj); return; From 7c0c584c06f4cd46edaa0e28af48c050eb4896ec Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 16 Dec 2019 13:29:51 +0000 Subject: [PATCH 27/67] Added detachable sounds, not the cleanest solution to the sound problem, but sufficient for now --- srb2-vc10.sln | 22 ++++++++-------- src/p_local.h | 2 +- src/p_mobj.c | 12 +++++++-- src/p_saveg.c | 6 ++--- src/s_sound.c | 69 ++++++++++++++++++++++++++++++++++++++++----------- src/s_sound.h | 38 ++++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 31 deletions(-) diff --git a/srb2-vc10.sln b/srb2-vc10.sln index 94625fbb0..763cdc350 100644 --- a/srb2-vc10.sln +++ b/srb2-vc10.sln @@ -41,8 +41,8 @@ Global {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|ARM.Build.0 = Release|ARM {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|ARM64.ActiveCfg = Release|ARM64 {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|ARM64.Build.0 = Release|ARM64 - {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.ActiveCfg = Debug|Win32 - {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.Build.0 = Debug|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.ActiveCfg = Release|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.Build.0 = Release|Win32 {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|x64.ActiveCfg = Release|x64 {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|x64.Build.0 = Release|x64 {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Debug|ARM.ActiveCfg = Debug|ARM @@ -57,8 +57,8 @@ Global {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|ARM.Build.0 = Release|ARM {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|ARM64.ActiveCfg = Release|ARM64 {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|ARM64.Build.0 = Release|ARM64 - {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.ActiveCfg = Debug|Win32 - {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.Build.0 = Debug|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.ActiveCfg = Release|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.Build.0 = Release|Win32 {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|x64.ActiveCfg = Release|x64 {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|x64.Build.0 = Release|x64 {51137D5C-4E81-4955-AACF-EA3092006051}.Debug|ARM.ActiveCfg = Debug|ARM @@ -73,8 +73,8 @@ Global {51137D5C-4E81-4955-AACF-EA3092006051}.Release|ARM.Build.0 = Release|ARM {51137D5C-4E81-4955-AACF-EA3092006051}.Release|ARM64.ActiveCfg = Release|ARM64 {51137D5C-4E81-4955-AACF-EA3092006051}.Release|ARM64.Build.0 = Release|ARM64 - {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.ActiveCfg = Debug|Win32 - {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.Build.0 = Debug|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.ActiveCfg = Release|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.Build.0 = Release|Win32 {51137D5C-4E81-4955-AACF-EA3092006051}.Release|x64.ActiveCfg = Release|x64 {51137D5C-4E81-4955-AACF-EA3092006051}.Release|x64.Build.0 = Release|x64 {73A5729C-7323-41D4-AB48-8A03C9F81603}.Debug|ARM.ActiveCfg = Debug|ARM @@ -89,8 +89,8 @@ Global {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|ARM.Build.0 = Release|ARM {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|ARM64.ActiveCfg = Release|ARM64 {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|ARM64.Build.0 = Release|ARM64 - {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.ActiveCfg = Debug|Win32 - {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.Build.0 = Debug|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.ActiveCfg = Release|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.Build.0 = Release|Win32 {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|x64.ActiveCfg = Release|x64 {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|x64.Build.0 = Release|x64 {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Debug|ARM.ActiveCfg = Debug|ARM @@ -99,7 +99,7 @@ Global {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Debug|x64.ActiveCfg = Debug|x64 {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|ARM.ActiveCfg = Release|ARM {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|ARM64.ActiveCfg = Release|ARM64 - {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|Win32.ActiveCfg = Debug|Win32 + {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|Win32.ActiveCfg = Release|Win32 {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|x64.ActiveCfg = Release|x64 {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|ARM.ActiveCfg = Debug|ARM {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|ARM.Build.0 = Debug|ARM @@ -113,8 +113,8 @@ Global {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|ARM.Build.0 = Release|ARM {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|ARM64.ActiveCfg = Release|ARM64 {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|ARM64.Build.0 = Release|ARM64 - {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.ActiveCfg = Debug|Win32 - {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.Build.0 = Debug|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.ActiveCfg = Release|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.Build.0 = Release|Win32 {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|x64.ActiveCfg = Release|x64 {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|x64.Build.0 = Release|x64 {2C3C45EC-A621-4845-AAEB-9CB82A6D32B4}.Debug|ARM.ActiveCfg = Debug|Win32 diff --git a/src/p_local.h b/src/p_local.h index e44137449..3c8395e10 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -228,7 +228,7 @@ void P_PrecipitationEffects(void); void P_RemoveMobj(mobj_t *th); boolean P_MobjWasRemoved(mobj_t *th); -void P_RemoveSavegameMobj(mobj_t *th); +void P_RemoveSavegameMobj(mobj_t *th, boolean preserveLevel); boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state); boolean P_SetMobjState(mobj_t *mobj, statenum_t state); //void P_RunShields(void); diff --git a/src/p_mobj.c b/src/p_mobj.c index 4cfcebc1b..8bf5282c7 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10390,7 +10390,7 @@ void P_RemovePrecipMobj(precipmobj_t *mobj) } // Clearing out stuff for savegames -void P_RemoveSavegameMobj(mobj_t *mobj) +void P_RemoveSavegameMobj(mobj_t *mobj, boolean preserveLevel) { // unlink from sector and block lists P_UnsetThingPosition(mobj); @@ -10403,7 +10403,15 @@ void P_RemoveSavegameMobj(mobj_t *mobj) } // stop any playing sound - S_StopSound(mobj); + if (!preserveLevel) + { + S_StopSound(mobj); + } + else + { + // detach any playing sounds from this mobj, but don't destroy them as they might still be there + S_DetachChannelsFromOrigin(mobj); + } // free block P_RemoveThinker((thinker_t *)mobj); diff --git a/src/p_saveg.c b/src/p_saveg.c index 94f4e19be..4bb2a86f9 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2804,7 +2804,7 @@ static void CollectDebugObjectList(void) { // // P_NetUnArchiveThinkers // -static void P_NetUnArchiveThinkers(void) +static void P_NetUnArchiveThinkers(boolean preserveLevel) { thinker_t *currentthinker; thinker_t *next; @@ -2849,7 +2849,7 @@ static void P_NetUnArchiveThinkers(void) currentthinker->references = 0; if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) - P_RemoveSavegameMobj((mobj_t *)currentthinker); // item isn't saved, don't remove it + P_RemoveSavegameMobj((mobj_t *)currentthinker, preserveLevel); // item isn't saved, don't remove it else if (currentthinker->function.acp1 == (actionf_p1)P_NullPrecipThinker) P_RemovePrecipMobj((precipmobj_t*)currentthinker); else { @@ -3721,7 +3721,7 @@ boolean P_LoadNetGame(boolean preserveLevel) #ifdef POLYOBJECTS P_UnArchivePolyObjects(); #endif - P_NetUnArchiveThinkers(); + P_NetUnArchiveThinkers(preserveLevel); P_NetUnArchiveSpecials(); P_RelinkPointers(); P_FinishMobjs(); diff --git a/src/s_sound.c b/src/s_sound.c index 21b668f28..f1a9d5f3b 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -46,7 +46,7 @@ extern INT32 msg_id; // 3D Sound Interface #include "hardware/hw3sound.h" #else -static INT32 S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 *vol, INT32 *sep, INT32 *pitch, sfxinfo_t *sfxinfo); +static INT32 S_AdjustSoundParams(const mobj_t *listener, fixed_t x, fixed_t y, fixed_t z, INT32 *vol, INT32 *sep, INT32 *pitch, sfxinfo_t *sfxinfo); #endif CV_PossibleValue_t soundvolume_cons_t[] = {{0, "MIN"}, {31, "MAX"}, {0, NULL}}; @@ -248,6 +248,7 @@ static INT32 S_getChannel(const void *origin, sfxinfo_t *sfxinfo) // channel is decided to be cnum. c->sfxinfo = sfxinfo; c->origin = origin; + c->isdetached = false; return cnum; } @@ -583,7 +584,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) if (origin && origin != listenmobj2) { INT32 rc; - rc = S_AdjustSoundParams(listenmobj2, origin, &volume, &sep, &pitch, sfx); + rc = S_AdjustSoundParams(listenmobj2, origin->x, origin->y, origin->z, &volume, &sep, &pitch, sfx); if (!rc) goto dontplay; // Maybe the other player can hear it... @@ -749,7 +750,7 @@ dontplay4: if (origin && origin != listenmobj) { INT32 rc; - rc = S_AdjustSoundParams(listenmobj, origin, &volume, &sep, &pitch, sfx); + rc = S_AdjustSoundParams(listenmobj, origin->x, origin->y, origin->z, &volume, &sep, &pitch, sfx); if (!rc) return; @@ -1053,6 +1054,8 @@ void S_UpdateSounds(void) { if (I_SoundIsPlaying(c->handle)) { + boolean isspatial = c->origin || c->isdetached; + // initialize parameters volume = 255; // 8 bits internal volume precision pitch = NORM_PITCH; @@ -1063,11 +1066,28 @@ void S_UpdateSounds(void) // check non-local sounds for distance clipping // or modify their params - if (c->origin && ((c->origin != players[consoleplayer].mo) + if (isspatial && + (c->origin && ((c->origin != players[consoleplayer].mo) || (splitscreen && c->origin != players[displayplayers[1]].mo) || (splitscreen > 1 && c->origin != players[displayplayers[2]].mo) - || (splitscreen > 2 && c->origin != players[displayplayers[3]].mo))) + || (splitscreen > 2 && c->origin != players[displayplayers[3]].mo)))) { + fixed_t x, y, z; + const mobj_t *soundmobj = c->origin; + + if (c->isdetached) + { + x = c->detachedx; + y = c->detachedy; + z = c->detachedz; + } + else + { + x = soundmobj->x; + y = soundmobj->y; + z = soundmobj->z; + } + // Whomever is closer gets the sound, but only in splitscreen. if (splitscreen) { @@ -1102,25 +1122,25 @@ void S_UpdateSounds(void) if (p == 1) { // Player 2 gets the sound - audible = S_AdjustSoundParams(listenmobj2, c->origin, &volume, &sep, &pitch, + audible = S_AdjustSoundParams(listenmobj2, x, y, z, &volume, &sep, &pitch, c->sfxinfo); } else if (p == 2) { // Player 3 gets the sound - audible = S_AdjustSoundParams(listenmobj3, c->origin, &volume, &sep, &pitch, + audible = S_AdjustSoundParams(listenmobj3, x, y, z, &volume, &sep, &pitch, c->sfxinfo); } else if (p == 3) { // Player 4 gets the sound - audible = S_AdjustSoundParams(listenmobj4, c->origin, &volume, &sep, &pitch, + audible = S_AdjustSoundParams(listenmobj4, x, y, z, &volume, &sep, &pitch, c->sfxinfo); } else { // Player 1 gets the sound - audible = S_AdjustSoundParams(listenmobj, c->origin, &volume, &sep, &pitch, + audible = S_AdjustSoundParams(listenmobj, x, y, z, &volume, &sep, &pitch, c->sfxinfo); } @@ -1133,7 +1153,7 @@ void S_UpdateSounds(void) else if (listenmobj && !splitscreen) { // In the case of a single player, he or she always should get updated sound. - audible = S_AdjustSoundParams(listenmobj, c->origin, &volume, &sep, &pitch, + audible = S_AdjustSoundParams(listenmobj, x, y, z, &volume, &sep, &pitch, c->sfxinfo); if (audible) @@ -1203,6 +1223,28 @@ static void S_StopChannel(INT32 cnum) } } +// +// S_DetachChannelFromSource +// +// Detaches a sound channel from the object it came from, leaving it loose +// +void S_DetachChannelsFromOrigin(void* origin) +{ + int i; + mobj_t* originmobj = (mobj_t*)origin; + for (i = 0; i < numofchannels; i++) + { + if (channels[i].origin == origin) + { + channels[i].origin = NULL; + channels[i].isdetached = true; + channels[i].detachedx = originmobj->x; + channels[i].detachedy = originmobj->y; + channels[i].detachedz = originmobj->z; + } + } +} + // // S_CalculateSoundDistance // @@ -1237,7 +1279,7 @@ fixed_t S_CalculateSoundDistance(fixed_t sx1, fixed_t sy1, fixed_t sz1, fixed_t // If the sound is not audible, returns a 0. // Otherwise, modifies parameters and returns 1. // -INT32 S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 *vol, INT32 *sep, INT32 *pitch, +INT32 S_AdjustSoundParams(const mobj_t *listener, fixed_t x, fixed_t y, fixed_t z, INT32 *vol, INT32 *sep, INT32 *pitch, sfxinfo_t *sfxinfo) { fixed_t approx_dist; @@ -1318,8 +1360,7 @@ INT32 S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 *v } else { - approx_dist = S_CalculateSoundDistance(listensource.x, listensource.y, listensource.z, - source->x, source->y, source->z); + approx_dist = S_CalculateSoundDistance(listensource.x, listensource.y, listensource.z, x, y, z); } // Ring loss, deaths, etc, should all be heard louder. @@ -1337,7 +1378,7 @@ INT32 S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 *v return 0; // angle of source to listener - angle = R_PointToAngle2(listensource.x, listensource.y, source->x, source->y); + angle = R_PointToAngle2(listensource.x, listensource.y, x, y); if (angle > listensource.angle) angle = angle - listensource.angle; diff --git a/src/s_sound.h b/src/s_sound.h index 2a904faff..0d8cbaddd 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -74,6 +74,40 @@ typedef struct { angle_t angle; } listener_t; +typedef struct +{ + // sound information (if null, channel avail.) + sfxinfo_t *sfxinfo; + + // origin of sound + const void *origin; + + // handle of the sound being played + INT32 handle; + + // whether the sound is detached from its source (sound panning should not be changed) + boolean isdetached; + + // positioning for detached sounds + fixed_t detachedx, detachedy, detachedz; + +} channel_t; + +typedef struct { + channel_t *c; + sfxinfo_t *s; + UINT16 t; + UINT8 b; +} caption_t; + +#define NUMCAPTIONS 8 +#define MAXCAPTIONTICS (2*TICRATE) +#define CAPTIONFADETICS 20 + +extern caption_t closedcaptions[NUMCAPTIONS]; +void S_StartCaption(sfxenum_t sfx_id, INT32 cnum, UINT16 lifespan); +void S_ResetCaptions(void); + // register sound vars and commands at game startup void S_RegisterSoundStuff(void); @@ -107,6 +141,10 @@ void S_StartSoundAtVolume(const void *origin, sfxenum_t sound_id, INT32 volume); // Stop sound for thing at void S_StopSound(void *origin); +// Detaches a sound from an object, leaving it in the air at the object's original position +void S_DetachChannelsFromOrigin(void* origin); + + // // Music Status // From 2a69fa8f4566e5cf172d05a522bb1ddf0467465b Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 16 Dec 2019 15:20:12 +0000 Subject: [PATCH 28/67] Added some benchmarking for the save/loads. playtest time? --- src/d_clisrv.c | 107 ++++++++++++++++++++++++--------------------- src/d_main.c | 2 +- src/i_system.h | 4 ++ src/p_saveg.c | 46 +++++++++++++++++++ src/p_saveg.h | 27 +++++++----- src/sdl/i_system.c | 43 +++++++++++++++++- 6 files changed, 167 insertions(+), 62 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 6453c1999..0241efa20 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -92,6 +92,7 @@ boolean nodownload = false; static boolean serverrunning = false; INT32 serverplayer = 0; char motd[254], server_context[8]; // Message of the Day, Unique Context (even without Mumble support) +char netDebugText[10000]; // Server specific vars UINT8 playernode[MAXPLAYERS]; @@ -154,14 +155,13 @@ char connectedservername[MAXSERVERNAME]; /// \todo WORK! boolean acceptnewnode = true; -// Horrid LXShadow stuff -UINT8 gameStateBuffer[BACKUPTICS][1024 * 768]; -ticcmd_t gameTicBuffer[BACKUPTICS][MAXPLAYERS]; - -UINT8 simulatedStateBuffer[BACKUPTICS][1024 * 768]; -ticcmd_t simulatedTicBuffer[BACKUPTICS]; - +// Net simulation stuff +savestate_t gameStateBuffer[BACKUPTICS]; boolean gameStateBufferIsValid[BACKUPTICS]; + +ticcmd_t gameTicBuffer[BACKUPTICS][MAXPLAYERS]; +ticcmd_t localTicBuffer[BACKUPTICS]; + boolean rewindingWow = false; int rewindingTarget = 0; @@ -5268,6 +5268,12 @@ int estimatedRTT; int maxLiveTicOffset; int minLiveTicOffset; int smoothingDelay; +UINT64 saveTime = 0; +UINT64 loadTime = 0; +int numSaves = 0; +int numLoads = 0; +boolean newSaveTic = false; +boolean newLoadTic = false; #define MAXOFFSETHISTORY 35 int ticTimeOffsetHistory[MAXOFFSETHISTORY]; @@ -5336,8 +5342,8 @@ void TryRunTics(tic_t realtics) // record the actual local controls static boolean didSimulate = false; - boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= BACKUPTICS && gametic >= BACKUPTICS && (cv_simulate.value && !server); - boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= BACKUPTICS && gametic >= BACKUPTICS; + boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= BACKUPTICS && gametic >= BACKUPTICS && (cv_simulate.value && !server) && !resynch_local_inprogress; + boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 1 && gametic >= BACKUPTICS; boolean preserveSoundDisabled = sound_disabled; int numNewTics = neededtic - gametic; @@ -5347,17 +5353,12 @@ void TryRunTics(tic_t realtics) if (didSimulate && !canSimulate) { - // we've stopped simulating for a while, so restore the original state before continuing + // if simulation stops, there is no guarantee our buffers are valid anymore if (gameStateBufferIsValid[gametic % BACKUPTICS]) { - sound_disabled = true; - - save_p = gameStateBuffer[gametic % BACKUPTICS]; - P_LoadNetGame(true); - - sound_disabled = preserveSoundDisabled; + P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); } - // clear previous states + // invalidate previous states for (int i = 0; i < BACKUPTICS; i++) { gameStateBufferIsValid[i] = false; } @@ -5373,7 +5374,11 @@ void TryRunTics(tic_t realtics) // record the actual local controls for this frame liveTic = I_GetTime(); - simulatedTicBuffer[liveTic % BACKUPTICS] = localcmds; + newSaveTic = newLoadTic = true; + + for (tic_t i = 0; i < realtics; i++) { + localTicBuffer[(liveTic - i) % BACKUPTICS] = localcmds; + } // Run the real game as received from the server if (neededtic > gametic && !resynch_local_inprogress) @@ -5383,15 +5388,8 @@ void TryRunTics(tic_t realtics) else { // Load the real state if it exists - if (canSimulate) { - if (gameStateBufferIsValid[gametic % BACKUPTICS]) { - sound_disabled = true; - - save_p = gameStateBuffer[gametic % BACKUPTICS]; - P_LoadNetGame(true); - - sound_disabled = preserveSoundDisabled; - } + if (canSimulate && gameStateBufferIsValid[gametic % BACKUPTICS]) { + P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); } // run the tics up to the real game tic @@ -5399,6 +5397,9 @@ void TryRunTics(tic_t realtics) { DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic)); + localangle = preservedAngle; + localaiming = preservedAiming; + G_Ticker((gametic % NEWTICRATERATIO) == 0); ExtraDataTicker(); gametic++; @@ -5406,10 +5407,12 @@ void TryRunTics(tic_t realtics) consistancy[gametic%BACKUPTICS] = Consistancy(); + preservedAngle = localangle; + preservedAiming = localaiming; + if (recordingStates) { // store this real state - save_p = gameStateBuffer[gametic % BACKUPTICS]; - P_SaveNetGame(); + P_SaveGameState(&gameStateBuffer[gametic % BACKUPTICS]); gameStateBufferIsValid[gametic % BACKUPTICS] = true; @@ -5450,8 +5453,7 @@ void TryRunTics(tic_t realtics) if (gameStateBufferIsValid[(smoothedTic + BACKUPTICS) % BACKUPTICS] && smoothedTic != gametic) { - save_p = gameStateBuffer[(smoothedTic + BACKUPTICS) % BACKUPTICS]; - P_LoadNetGame(true); + P_LoadGameState(&gameStateBuffer[(smoothedTic + BACKUPTICS) % BACKUPTICS]); } simTic = smoothedTic; @@ -5475,6 +5477,9 @@ void TryRunTics(tic_t realtics) int numToSimulate = targetSimTic - simTic; // simulate the rest o da future + localangle = preservedAngle; + localaiming = preservedAiming; + for (int i = 0; i < numToSimulate; i++) { // control other players for (int j = 0; j < MAXPLAYERS; j++) { @@ -5491,10 +5496,13 @@ void TryRunTics(tic_t realtics) } else { - netcmds[gametic % BACKUPTICS][consoleplayer] = simulatedTicBuffer[(liveTic - numToSimulate + i + 1 + BACKUPTICS) % BACKUPTICS]; + netcmds[gametic % BACKUPTICS][consoleplayer] = localTicBuffer[(liveTic - numToSimulate + i + 1 + BACKUPTICS) % BACKUPTICS]; } G_Ticker(true); // tic a bunch of times lol see what happens lolol + + preservedAngle = localangle; // game simulations may lock the view angle + preservedAiming = localaiming; } simTic = targetSimTic; @@ -5555,7 +5563,7 @@ void DetermineNetConditions() #else for (int j = 1; j < TICCMD_TIME_SIZE; j++) { - if (CompareTiccmd(&gameTicBuffer[gametic % BACKUPTICS][consoleplayer], &simulatedTicBuffer[(liveTic - j + BACKUPTICS) % BACKUPTICS])) + if (CompareTiccmd(&gameTicBuffer[gametic % BACKUPTICS][consoleplayer], &localTicBuffer[(liveTic - j + BACKUPTICS) % BACKUPTICS])) { estimatedRTT = j; break; @@ -5567,9 +5575,8 @@ void DetermineNetConditions() static void PerformDebugRewinds() { if (rewindingWow && rewindingTarget > 0) { - save_p = gameStateBuffer[(gametic - rewindingTarget) % BACKUPTICS]; - P_LoadNetGame(true); - + P_LoadGameState(&gameStateBuffer[(gametic - rewindingTarget) % BACKUPTICS]); + for (int i = 0; i < rewindingTarget; i++) { netcmds[gametic%BACKUPTICS][consoleplayer] = gameTicBuffer[gametic - rewindingTarget + i % BACKUPTICS][consoleplayer]; G_Ticker(true); @@ -5593,9 +5600,8 @@ static void PerformDebugRewinds() { G_Ticker(true); } - save_p = gameStateBuffer[gametic % BACKUPTICS]; - P_LoadNetGame(true); - + P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); + if (redflag) { if (redflag->spawnpoint->x + redflag->spawnpoint->y + redflag->spawnpoint->z != xyz && xyz != 0) { @@ -5610,8 +5616,6 @@ static void PerformDebugRewinds() { } } -char netDebugText[10000]; - void MakeNetDebugString() { netDebugText[0] = 0; @@ -5621,18 +5625,18 @@ void MakeNetDebugString() if ((tic_t)i >= simTic - gametic) { // show tics and matches sprintf(&netDebugText[strlen(netDebugText)], - "srv: %d%slcl: %d%s\n", - gametic - i, + "srv: %02d%slcl: %02d%s\n", + DecodeTiccmdTime(&(gameTicBuffer[(gametic - i) % BACKUPTICS][consoleplayer])), (i == gametic ? "<" : " "), - liveTic - i, + (liveTic - i) & (TICCMD_TIME_SIZE-1), (i == estimatedRTT ? "<" : " ")); } else { sprintf(&netDebugText[strlen(netDebugText)], - "____ %d_lcl: %d%s\n", - simTic, + "____ %02d_lcl: %02d%s\n", + 0, //(i == matchingGameTic ? "<" : " "), - liveTic - i, + (liveTic - i) & (TICCMD_TIME_SIZE - 1), (i == estimatedRTT ? "<" : " ")); } } @@ -5640,6 +5644,9 @@ void MakeNetDebugString() sprintf(&netDebugText[strlen(netDebugText)], "\n\nJitter: %d", netJitter); sprintf(&netDebugText[strlen(netDebugText)], "\nEstPing: %d", estimatedRTT); sprintf(&netDebugText[strlen(netDebugText)], "\nSim-T: %d", simTic - gametic); + sprintf(&netDebugText[strlen(netDebugText)], "\nLive: %d", liveTic); + sprintf(&netDebugText[strlen(netDebugText)], "\nSaveT/LoadT: %llu/%llu", saveTime, loadTime); + sprintf(&netDebugText[strlen(netDebugText)], "\nSaveN/LoadN: %i/%i", numSaves, numLoads); } // startTic and endTics are tics going back in time from the current liveTic @@ -5650,9 +5657,9 @@ boolean FindMatchingTics(int* liveTicOut, int* gameTicOut) { // display estimated matching frames for (int j = 0; j < BACKUPTICS - 1; j++) { // if this and the previous tic were different (interesting delta), and this matches some point in the tic buffer, say wow and use that towel - if (!CompareTiccmd(&simulatedTicBuffer[(liveTic - i + BACKUPTICS) % BACKUPTICS], &simulatedTicBuffer[(liveTic - i - 1 + BACKUPTICS) % BACKUPTICS]) - && CompareTiccmd(&simulatedTicBuffer[(liveTic - i + BACKUPTICS) % BACKUPTICS], &gameTicBuffer[(smoothedTic - j + BACKUPTICS) % BACKUPTICS][consoleplayer]) - && CompareTiccmd(&simulatedTicBuffer[(liveTic - i - 1 + BACKUPTICS) % BACKUPTICS], &gameTicBuffer[(smoothedTic - j - 1 + BACKUPTICS) % BACKUPTICS][consoleplayer])) + if (!CompareTiccmd(&localTicBuffer[(liveTic - i + BACKUPTICS) % BACKUPTICS], &localTicBuffer[(liveTic - i - 1 + BACKUPTICS) % BACKUPTICS]) + && CompareTiccmd(&localTicBuffer[(liveTic - i + BACKUPTICS) % BACKUPTICS], &gameTicBuffer[(smoothedTic - j + BACKUPTICS) % BACKUPTICS][consoleplayer]) + && CompareTiccmd(&localTicBuffer[(liveTic - i - 1 + BACKUPTICS) % BACKUPTICS], &gameTicBuffer[(smoothedTic - j - 1 + BACKUPTICS) % BACKUPTICS][consoleplayer])) { if (j < latestGameTic && i >= j) { // i >= j: uses >= because gameTicBuffer[gametic] is actually the controls used in the -last- tic latestGameTic = j; diff --git a/src/d_main.c b/src/d_main.c index 4db455687..75aac6894 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -610,7 +610,7 @@ static void D_Display(void) V_DrawRightAlignedSmallString(BASEVIDWIDTH, y, V_YELLOWMAP, temp); y += 5; - str = nextStr; + str = nextStr ? nextStr + 1 : NULL; } } diff --git a/src/i_system.h b/src/i_system.h index d1708fe5a..ff8e2fae9 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -46,6 +46,10 @@ UINT32 I_GetFreeMem(UINT32 *total); */ tic_t I_GetTime(void); +/** \brief Gets the current time in microseconds +*/ +UINT64 I_GetTimeUs(void); + /** \brief The I_Sleep function \return void diff --git a/src/p_saveg.c b/src/p_saveg.c index 4bb2a86f9..7fbbb09c9 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3639,6 +3639,16 @@ static inline boolean P_NetUnArchiveMisc(boolean preserveLevel) return true; } + +extern UINT64 saveTime; +extern int numSaves; +extern UINT64 loadTime; +extern int numLoads; +extern boolean newSaveTic; +extern boolean newLoadTic; + +UINT64 I_GetTimeUs(void); + void P_SaveGame(void) { P_ArchiveMisc(); @@ -3686,6 +3696,23 @@ void P_SaveNetGame(void) WRITEUINT8(save_p, 0x1d); // consistency marker } +void P_SaveGameState(savestate_t* savestate) +{ + if (newSaveTic) + { + saveTime = 0; + numSaves = 0; + } + + UINT64 time = I_GetTimeUs(); + + save_p = savestate->buffer; + P_SaveNetGame(); + + saveTime += I_GetTimeUs() - time; + numSaves++; +} + boolean P_LoadGame(INT16 mapoverride) { if (gamestate == GS_INTERMISSION) @@ -3741,3 +3768,22 @@ boolean P_LoadNetGame(boolean preserveLevel) return READUINT8(save_p) == 0x1d; } + +boolean P_LoadGameState(const savestate_t* savestate) +{ + if (newLoadTic) + { + loadTime = 0; + numLoads = 0; + } + + UINT64 time = I_GetTimeUs(); + + save_p = ((unsigned char*)savestate->buffer); + P_LoadNetGame(true); + + loadTime += I_GetTimeUs() - time; + numLoads++; + + return true; +} \ No newline at end of file diff --git a/src/p_saveg.h b/src/p_saveg.h index 0896384d6..d67d91280 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -18,16 +18,6 @@ #pragma interface #endif -// Persistent storage/archiving. -// These are the load / save game routines. - -void P_SaveGame(void); -void P_SaveNetGame(void); -boolean P_LoadGame(INT16 mapoverride); -boolean P_LoadNetGame(boolean preserveLevel); - -mobj_t *P_FindNewPosition(UINT32 oldposition); - typedef struct { UINT8 skincolor; @@ -40,6 +30,23 @@ typedef struct UINT16 emeralds; } savedata_t; +typedef struct +{ + UINT8 buffer[1024 * 768]; +} savestate_t; + +// Persistent storage/archiving. +// These are the load / save game routines. + +void P_SaveGame(void); +void P_SaveNetGame(void); +void P_SaveGameState(savestate_t* savestate); +boolean P_LoadGame(INT16 mapoverride); +boolean P_LoadNetGame(boolean preserveLevel); +boolean P_LoadGameState(const savestate_t* savestate); + +mobj_t *P_FindNewPosition(UINT32 oldposition); + extern savedata_t savedata; extern UINT8 *save_p; diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index c0fca64da..a34a7b726 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2908,6 +2908,7 @@ ticcmd_t *I_BaseTiccmd4(void) static HMODULE winmm = NULL; static DWORD starttickcount = 0; // hack for win2k time bug static p_timeGetTime pfntimeGetTime = NULL; +static LARGE_INTEGER basetime = { {0, 0} }; // --------- // I_GetTime @@ -2923,7 +2924,6 @@ tic_t I_GetTime(void) if (!starttickcount) // high precision timer { LARGE_INTEGER currtime; // use only LowPart if high resolution counter is not available - static LARGE_INTEGER basetime = {{0, 0}}; // use this if High Resolution timer is found static LARGE_INTEGER frequency; @@ -2955,6 +2955,47 @@ tic_t I_GetTime(void) return newtics; } + +// I_GetTime +// Wow I remember Windows NT +// Anyway this returns the time passed in microseconds if applicable. Useful for benchmarking +UINT64 I_GetTimeUs(void) +{ + UINT64 timeUs; + + if (!starttickcount) // high precision timer + { + LARGE_INTEGER currtime; // use only LowPart if high resolution counter is not available + + // use this if High Resolution timer is found + static LARGE_INTEGER frequency; + + if (!basetime.LowPart) + { + if (!QueryPerformanceFrequency(&frequency)) + frequency.QuadPart = 0; + else + QueryPerformanceCounter(&basetime); + } + + if (frequency.LowPart && QueryPerformanceCounter(&currtime)) + { + timeUs = (INT32)((currtime.QuadPart - basetime.QuadPart) * 1000000 / frequency.QuadPart); + } + else if (pfntimeGetTime) + { + currtime.LowPart = pfntimeGetTime(); + if (!basetime.LowPart) + basetime.LowPart = currtime.LowPart; + timeUs = (currtime.LowPart - basetime.LowPart) * 1000; + } + } + else + timeUs = (GetTickCount() - starttickcount) * 1000; + + return timeUs; +} + static void I_ShutdownTimer(void) { pfntimeGetTime = NULL; From 55752f3d68cf1c4aaaa3174ed05b4f78581cfbd4 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 16 Dec 2019 23:01:49 +0000 Subject: [PATCH 29/67] WIP new faster state save/load code - but locking it off for now to playtest --- src/d_clisrv.c | 21 +- src/d_netcmd.c | 8 +- src/p_mobj.c | 3 + src/p_mobj.h | 5 + src/p_saveg.c | 515 ++++++++++++++++++++++++++++++++++++++++++++++++- src/p_saveg.h | 2 +- 6 files changed, 533 insertions(+), 21 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 0241efa20..9ae17b79a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5516,13 +5516,8 @@ void TryRunTics(tic_t realtics) //con_muted = false; } - if (!recordingStates) + if (!canSimulate) { - // clear gamestate buffer if we're no longer able to simulate, or things will break. - for (int i = 0; i < BACKUPTICS; i++) { - gameStateBufferIsValid[i] = false; - } - simTic = gametic; smoothedTic = gametic; } @@ -5573,7 +5568,7 @@ void DetermineNetConditions() } static void PerformDebugRewinds() { - if (rewindingWow && rewindingTarget > 0) + if (rewindingWow && rewindingTarget > 0 && gameStateBufferIsValid[(gametic - rewindingTarget) % BACKUPTICS]) { P_LoadGameState(&gameStateBuffer[(gametic - rewindingTarget) % BACKUPTICS]); @@ -5583,6 +5578,8 @@ static void PerformDebugRewinds() { } rewindingWow = false; + + CONS_Printf("Rewinding\n"); } if (gameStateBufferIsValid[gametic % BACKUPTICS] && cv_debugsimulaterewind.value > 0 && players[consoleplayer].mo) { @@ -5616,6 +5613,9 @@ static void PerformDebugRewinds() { } } +extern UINT32 saveTimes[12]; +extern UINT32 loadTimes[12]; + void MakeNetDebugString() { netDebugText[0] = 0; @@ -5645,8 +5645,13 @@ void MakeNetDebugString() sprintf(&netDebugText[strlen(netDebugText)], "\nEstPing: %d", estimatedRTT); sprintf(&netDebugText[strlen(netDebugText)], "\nSim-T: %d", simTic - gametic); sprintf(&netDebugText[strlen(netDebugText)], "\nLive: %d", liveTic); - sprintf(&netDebugText[strlen(netDebugText)], "\nSaveT/LoadT: %llu/%llu", saveTime, loadTime); sprintf(&netDebugText[strlen(netDebugText)], "\nSaveN/LoadN: %i/%i", numSaves, numLoads); + + for (int i = 1; i < 11; i++) + { + sprintf(&netDebugText[strlen(netDebugText)], "\n[%i] %i/%i", i, saveTimes[i] - saveTimes[i - 1], loadTimes[i] - loadTimes[i - 1]); + + } } // startTic and endTics are tics going back in time from the current liveTic diff --git a/src/d_netcmd.c b/src/d_netcmd.c index b903ef0b3..2ed2a016d 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -811,7 +811,7 @@ void MemShow() { sizeu1(Z_TagsUsage(PU_PURGELEVEL, INT32_MAX) >> 10)); } -static char buffer[1024 * 768]; +static savestate_t save; static void Command_Saveloadtest(void) { memleak = true; @@ -819,10 +819,8 @@ static void Command_Saveloadtest(void) MemShow(); for (int i = 0; i < 2; i++) { - save_p = buffer; - P_SaveNetGame(); - save_p = buffer; - P_LoadNetGame(true); + P_SaveGameState(&save); + P_LoadGameState(&save); } MemShow(); diff --git a/src/p_mobj.c b/src/p_mobj.c index 8bf5282c7..47a625ac4 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -50,6 +50,8 @@ static mobj_t *overlaycap = NULL; static mobj_t *shadowcap = NULL; mobj_t *waypointcap = NULL; +UINT32 globalmobjnum = 0; // this should never overflow, but 4 billion would be an impressive number to reach. \todo ensure this never happens + void P_InitCachedActions(void) { actioncachehead.prev = actioncachehead.next = &actioncachehead; @@ -9625,6 +9627,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) mobj->thinker.function.acp1 = (actionf_p1)P_MobjThinker; mobj->type = type; mobj->info = info; + mobj->localmobjnum = globalmobjnum++; mobj->x = x; mobj->y = y; diff --git a/src/p_mobj.h b/src/p_mobj.h index dfc8fc738..702e01a96 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -354,6 +354,7 @@ typedef struct mobj_s fixed_t waterbottom; // bottom of the water FOF the mobj is in UINT32 mobjnum; // A unique number for this mobj. Used for restoring pointers on save games. + UINT32 localmobjnum; // A unique number for this mobj stored locally for association when restoring savestates fixed_t scale; fixed_t destscale; @@ -464,6 +465,10 @@ void P_SetScale(mobj_t *mobj, fixed_t newscale); void P_XYMovement(mobj_t *mo); void P_EmeraldManager(void); +extern INT32 modulothing; + +extern UINT32 globalmobjnum; + #define MAXHUNTEMERALDS 64 extern mapthing_t *huntemeralds[MAXHUNTEMERALDS]; extern INT32 numhuntemeralds; diff --git a/src/p_saveg.c b/src/p_saveg.c index 7fbbb09c9..5a4c64d8a 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -48,6 +48,9 @@ UINT8 *save_p; boolean memleak = false; +UINT32 saveTimes[12]; +UINT32 loadTimes[12]; + // Note: This cannot be bigger // than an UINT16 typedef enum @@ -576,6 +579,50 @@ static void ResetSectors(void) } } +// +// P_LocalArchiveWorld +// Archives the world's state locally, regardless of differences from original state +// Faster than NetArchiveWorld +// +static void P_LocalArchiveWorld(void) +{ + UINT8* put; + + // paranoia something something + ClearNetColormaps(); + + WRITEUINT32(save_p, ARCHIVEBLOCK_WORLD); + put = save_p; + + WRITEUINT32(put, numsectors * sizeof(sectors[0])); + + // dump all sector memory into the data + memcpy(put, sectors, numsectors * sizeof(sectors[0])); + put += numsectors * sizeof(sectors[0]); + + // there will be probably be code here that corrects all the broken pointers and stuff eventually + // once the programmer realises that everything's screwed during the next playtest ;) + + UINT32 wow = put - save_p; + save_p = put; +} + +static void P_LocalUnArchiveWorld(void) +{ + UINT8* get = save_p; + + if (READUINT32(get) != ARCHIVEBLOCK_WORLD) + { + I_Error("Bad SaveState at archive block World"); + } + + UINT32 size = READUINT32(get); + memcpy(sectors, get, numsectors * sizeof(sectors[0])); + get += numsectors * sizeof(sectors[0]); + + save_p = get; +} + // // P_NetArchiveWorld // @@ -1016,7 +1063,8 @@ static void P_NetUnArchiveWorld(boolean preserveLevel) } // -// Thinkers +// Thinkers // you're welcomers <3 +// // typedef enum @@ -1117,6 +1165,66 @@ typedef enum tc_end } specials_e; +typedef struct +{ + actionf_p1 action; + UINT16 size; +} specialdef_t; + +// special function/data size associations +#define A(x) (actionf_p1)x +static const specialdef_t specialDefs[] = +{ + A(P_MobjThinker), sizeof (mobj_t), // tc_mobj + A(T_MoveCeiling), sizeof(ceiling_t), // tc_ceiling + A(T_MoveFloor), sizeof (floormove_t), // tc_floor + A(T_LightningFlash), sizeof(lightflash_t), // tc_flash + A(T_StrobeFlash), sizeof(strobe_t), // tc_strobe + A(T_Glow), sizeof (glow_t), // tc_glow + A(T_FireFlicker), sizeof (fireflicker_t), // tc_fireflicker + A(T_ThwompSector), sizeof(levelspecthink_t), // tc_thwomp + A(T_CameraScanner), sizeof(elevator_t), // tc_camerascanner + A(T_MoveElevator), sizeof (elevator_t), // tc_elevator + A(T_ContinuousFalling), sizeof (levelspecthink_t), // tc_contunousfalling + A(T_BounceCheese), sizeof(levelspecthink_t), // tc_bouncecheese + A(T_StartCrumble), sizeof(elevator_t), // tc_startcrumble + A(T_MarioBlock), sizeof(levelspecthink_t), // tc_marioblock + A(T_MarioBlockChecker), sizeof(levelspecthink_t), // tc_marioblockchecker + A(T_SpikeSector), sizeof(levelspecthink_t), // tc_spikesector + A(T_FloatSector), sizeof(levelspecthink_t), // tc_floatsector + A(T_BridgeThinker), sizeof(levelspecthink_t), // tc_bridgethinker + A(T_CrushCeiling), sizeof(ceiling_t), // tc_crushceiling + A(T_Scroll), sizeof(scroll_t), // tc_scroll + A(T_Friction), sizeof(friction_t), // tc_friction + A(T_Pusher), sizeof(pusher_t), // tc_pusher + A(T_LaserFlash), sizeof(laserthink_t), // tc_laserflash + A(T_LightFade), sizeof(lightlevel_t), // tc_lightfade + A(T_ExecutorDelay), sizeof(executor_t), // tc_executor + A(T_RaiseSector), sizeof(levelspecthink_t), // tc_raisesector + A(T_NoEnemiesSector), sizeof(levelspecthink_t), // tc_noenemies + A(T_EachTimeThinker), sizeof(levelspecthink_t), // tc_eachtime + A(T_Disappear), sizeof (disappear_t), // tc_disappear + A(T_Fade), sizeof (fade_t), // tc_fade + A(T_FadeColormap), sizeof (fadecolormap_t), // tc_fade + A(T_PlaneDisplace), sizeof (planedisplace_t), // tc_planedisplace +#ifdef ESLOPE + A(T_DynamicSlopeLine), sizeof(dynplanethink_t), // tc_dynslopeline + A(T_DynamicSlopeVert), sizeof(dynplanethink_t), // tc_dynslopevert +#endif +#ifdef POLYOBJECTS + A(T_PolyObjRotate), sizeof (polyrotate_t), // tc_polyrotate + A(T_PolyObjMove), sizeof (polymove_t), // tc_polymove + A(T_PolyObjWaypoint), sizeof (polywaypoint_t), // tc_polywaypoint + A(T_PolyDoorSlide), sizeof (polyslidedoor_t), // tc_polyslidedoor + A(T_PolyDoorSwing), sizeof (polyswingdoor_t), // tc_polyswingdoor + A(T_PolyObjFlag), sizeof (polymove_t), // tc_polyflag + A(T_PolyObjDisplace), sizeof (polydisplace_t), // tc_polydisplace + A(T_PolyObjRotDisplace), sizeof (polyrotdisplace_t), // tc_polyrotdisplace + A(T_PolyObjFade), sizeof (polyfade_t), // tc_polyfade +#endif +}; +#undef A + static inline UINT32 SaveMobjnum(const mobj_t *mobj) { if (mobj) return mobj->mobjnum; @@ -1798,6 +1906,42 @@ static inline void SaveWhatThinker(const thinker_t *th, const UINT8 type) } */ + +// +// P_LocalArchiveThinkers +// Archives the world's thinkers locally. Used for within-level savestates +// +static void P_LocalArchiveThinkers(void) +{ + int i, j; + const thinker_t* thinker; + UINT8* original = save_p; + WRITEUINT32(save_p, ARCHIVEBLOCK_THINKERS); + + for (i = 0; i < NUM_THINKERLISTS; i++) + { + for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = thinker->next) + { + actionf_p1 acp1 = thinker->function.acp1; + + // find the associated special def + for (j = 0; j < sizeof(specialDefs) / sizeof(specialDefs[0]); j++) + { + if (acp1 == specialDefs[j].action) + break; + } + + if (j == sizeof(specialDefs) / sizeof(specialDefs[0])) + continue; + + WRITEUINT8(save_p, j); + WRITEMEM(save_p, thinker, specialDefs[j].size); + } + + WRITEUINT8(save_p, 0xFF); // next list (or end) + } +} + // // P_NetArchiveThinkers // @@ -2801,6 +2945,247 @@ static void CollectDebugObjectList(void) { } } +static void P_LocalUnArchiveThinkers() +{ + thinker_t *thinker; + mobj_t* currentmobj; + UINT8 tclass; + UINT8 restoreExecutors = false; + INT32 i, j, list; + int skyviewid = -1; + int skycenterid = -1; + thinker_t newthinkers[NUM_THINKERLISTS] = { 0 }; + static thinker_t* thinkersbytype[tc_end][16384]; + static UINT8 thinkerlistbytype[tc_end][16384]; + static int numthinkersbytype[tc_end]; + + if (READUINT32(save_p) != ARCHIVEBLOCK_THINKERS) + I_Error("Bad SaveState at archive block Thinkers"); + + // preserve sky box indexes + for (i = 0; i < 16; i++) + { + if (skyboxmo[0] && skyboxmo[0] == skyboxviewpnts[i]) + skyviewid = i; // save id just in case + if (skyboxmo[1] && skyboxmo[1] == skyboxcenterpnts[i]) + skycenterid = i; // save id just in case + } + + // sort objects by type + for (i = 0; i < tc_end; i++) { + numthinkersbytype[i] = 0; + } + + for (i = 0; i < NUM_THINKERLISTS; i++) + { + newthinkers[i].next = &newthinkers[i]; + newthinkers[i].prev = &newthinkers[i]; + + for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = thinker->next) + { + for (j = 0; j < tc_end; j++) + { + if (thinker->function.acp1 == specialDefs[j].action) + { + thinkersbytype[j][numthinkersbytype[j]] = thinker; + thinkerlistbytype[j][numthinkersbytype[j]] = i; + numthinkersbytype[j]++; + break; + } + } + } + } + + // remove from item respawn queues + iquetail = iquehead = 0; + + // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity + //for (i = 0; i < (int)numsectors; i++) + //{ + // sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = sectors[i].fadecolormapdata = NULL; + //} + + // clear flag references + redflag = NULL; + blueflag = NULL; + + CollectDebugObjectList(); + + // read in saved thinkers + for (list = 0; list < NUM_THINKERLISTS; list++) + { + for (;;) + { + tclass = READUINT8(save_p); + + if (tclass == 0xFF) + break; // next list + + thinker_t* newthinker = NULL; + thinker_t* oldthinker = NULL; + + if (numthinkersbytype[tclass] > 0) + { + for (j = numthinkersbytype[tclass] - 1; j >= 0; j--) + { + UINT8 thinkerlist = thinkerlistbytype[tclass][j]; + + if (thinkerlist != list) + { + continue; // don't replace something from a different list actually it doesn't matter lol + } + + newthinker = thinkersbytype[tclass][j]; + oldthinker = newthinker; + numthinkersbytype[tclass]--; + + for (int k = j; k < numthinkersbytype[tclass]; k++) + { + thinkersbytype[tclass][k] = thinkersbytype[tclass][k + 1]; + thinkerlistbytype[tclass][k] = thinkerlistbytype[tclass][k + 1]; + } + break; + } + } + + if (newthinker == NULL) + { + // couldn't replace one, we gotta create it... + if (tclass == tc_mobj) + { + newthinker = Z_Calloc(specialDefs[tclass].size, PU_LEVEL, NULL); + } + else + { + newthinker = Z_Malloc(specialDefs[tclass].size, PU_LEVSPEC, NULL); + } + } + + if (oldthinker) + { + // remove it from the old list + oldthinker->prev->next = oldthinker->next; + oldthinker->next->prev = oldthinker->prev; + + if (tclass == tc_mobj) + P_UnsetThingPosition((mobj_t*)oldthinker); + } + + // read in the data + READMEM(save_p, newthinker, specialDefs[tclass].size); + + // set special-specific info + if (tclass == tc_mobj) + { + mobj_t* mobj = (mobj_t*)newthinker; + if (mobj->type == MT_REDFLAG) + { + redflag = mobj; + rflagpoint = mobj->spawnpoint; + } + + if (mobj->type == MT_BLUEFLAG) + { + blueflag = mobj; + bflagpoint = mobj->spawnpoint; + } + + if (mobj->player && mobj->type == MT_PLAYER) + { + mobj->player->mo = mobj; + } + } + + // relink into the list + newthinker->prev = newthinkers[list].prev; + newthinker->next = &newthinkers[list]; + newthinker->prev->next = newthinker; + newthinker->next->prev = newthinker; + + if (tclass == tc_mobj) + P_SetThingPosition((mobj_t*)newthinker); + } + } + + CollectDebugObjectList(); + + // delete everything remaining in the list that hasn't been linked + for (i = 0; i < NUM_THINKERLISTS; i++) + { + thinker_t* next; + + for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = next) + { + next = thinker->next; + + thinker->references = 0; + + if (thinker->function.acp1 == (actionf_p1)P_MobjThinker) + P_RemoveSavegameMobj((mobj_t *)thinker, true); // item isn't saved, don't remove it + else if (thinker->function.acp1 == (actionf_p1)P_NullPrecipThinker) + P_RemovePrecipMobj((precipmobj_t*)thinker); + else { + // remove it manually, bye! + thinker->prev->next = thinker->next; + thinker->next->prev = thinker->prev; + Z_Free(thinker); + } + } + + // connect the new linker list to the old linker list + newthinkers[i].prev->next = thlist[i].next; + thlist[i].next->prev = newthinkers[i].prev; + + thlist[i].next = newthinkers[i].next; + newthinkers[i].next->prev = &thlist[i]; + } + + CollectDebugObjectList(); + + if (restoreExecutors) + { + executor_t *delay = NULL; + UINT32 mobjnum; + for (thinker = thlist[THINK_MAIN].next; thinker != &thlist[THINK_MAIN]; + thinker = thinker->next) + { + if (thinker->function.acp1 != (actionf_p1)T_ExecutorDelay) + continue; + delay = (void *)thinker; + if (!(mobjnum = (UINT32)(size_t)delay->caller)) + continue; + delay->caller = P_FindNewPosition(mobjnum); + } + } + + // restore skyboxes, if applicable + for (i = 0; i < sizeof(skyboxmo) / sizeof(skyboxmo[0]); i++) + skyboxmo[i] = NULL; + for (i = 0; i < sizeof(skyboxcenterpnts) / sizeof(skyboxcenterpnts[0]); i++) + { + skyboxcenterpnts[i] = NULL; + skyboxviewpnts[i] = NULL; + } + + for (currentmobj = (mobj_t*)thlist[THINK_MOBJ].next; currentmobj != (mobj_t*)&thlist[THINK_MOBJ]; currentmobj = (mobj_t*)currentmobj->thinker.next) + { + if (currentmobj->type == MT_SKYBOX) + { + if ((currentmobj->extravalue2 >> 16) == 1) + { + skyboxcenterpnts[currentmobj->extravalue2 & 0xFFFF] = currentmobj; + } + else + { + skyboxviewpnts[currentmobj->extravalue2 & 0xFFFF] = currentmobj; + } + } + } + + skyboxmo[0] = skyboxviewpnts[(skyviewid >= 0) ? skyviewid : 0]; + skyboxmo[1] = skyboxcenterpnts[(skycenterid >= 0) ? skycenterid : 0]; +} + // // P_NetUnArchiveThinkers // @@ -2836,11 +3221,6 @@ static void P_NetUnArchiveThinkers(boolean preserveLevel) // remove all the current thinkers for (i = 0; i < NUM_THINKERLISTS; i++) { - /*if (i == THINK_PRECIP) - { - continue; // ignore precipitation - }*/ - currentthinker = thlist[i].next; for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; currentthinker = next) { @@ -3664,7 +4044,10 @@ void P_SaveNetGame(void) INT32 i = 1; // don't start from 0, it'd be confused with a blank pointer otherwise CV_SaveNetVars(&save_p, false); + + saveTimes[0] = I_GetTimeUs(); P_NetArchiveMisc(); + saveTimes[1] = I_GetTimeUs(); // Assign the mobjnumber for pointer tracking //if (gamestate == GS_LEVEL) @@ -3680,17 +4063,24 @@ void P_SaveNetGame(void) } P_NetArchivePlayers(); + saveTimes[2] = I_GetTimeUs(); if (gamestate == GS_LEVEL) { P_NetArchiveWorld(); + saveTimes[3] = I_GetTimeUs(); #ifdef POLYOBJECTS P_ArchivePolyObjects(); + saveTimes[4] = I_GetTimeUs(); #endif P_NetArchiveThinkers(); + saveTimes[5] = I_GetTimeUs(); P_NetArchiveSpecials(); + saveTimes[6] = I_GetTimeUs(); } #ifdef HAVE_BLUA + saveTimes[8] = saveTimes[9] = 0; LUA_Archive(); + saveTimes[10] = I_GetTimeUs(); #endif WRITEUINT8(save_p, 0x1d); // consistency marker @@ -3708,6 +4098,58 @@ void P_SaveGameState(savestate_t* savestate) save_p = savestate->buffer; P_SaveNetGame(); + return; + + WRITEUINT32(save_p, globalmobjnum); + + P_LocalArchiveThinkers(); + return; + + thinker_t *th; + mobj_t *mobj; + INT32 i = 1; // don't start from 0, it'd be confused with a blank pointer otherwise + + CV_SaveNetVars(&save_p); + + saveTimes[0] = I_GetTimeUs(); + P_NetArchiveMisc(); + saveTimes[1] = I_GetTimeUs(); + + // Assign the mobjnumber for pointer tracking + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mobj = (mobj_t *)th; + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; + mobj->mobjnum = i++; + } + + P_NetArchivePlayers(); + saveTimes[2] = I_GetTimeUs(); + if (gamestate == GS_LEVEL) + { + P_NetArchiveWorld(); + saveTimes[3] = I_GetTimeUs(); +#ifdef POLYOBJECTS + P_ArchivePolyObjects(); + saveTimes[4] = I_GetTimeUs(); +#endif + P_LocalArchiveThinkers(); + //P_NetArchiveThinkers(); + saveTimes[5] = I_GetTimeUs(); + P_NetArchiveSpecials(); + saveTimes[6] = I_GetTimeUs(); + } +#ifdef HAVE_BLUA + saveTimes[8] = saveTimes[9] = 0; + LUA_Archive(); + saveTimes[10] = I_GetTimeUs(); +#endif + + P_ArchiveLuabanksAndConsistency(); saveTime += I_GetTimeUs() - time; numSaves++; @@ -3738,23 +4180,33 @@ boolean P_LoadGame(INT16 mapoverride) boolean P_LoadNetGame(boolean preserveLevel) { CV_LoadNetVars(&save_p); + loadTimes[0] = I_GetTimeUs(); if (!P_NetUnArchiveMisc(preserveLevel)) return false; + loadTimes[1] = I_GetTimeUs(); P_NetUnArchivePlayers(); + loadTimes[2] = I_GetTimeUs(); if (gamestate == GS_LEVEL) { P_NetUnArchiveWorld(preserveLevel); + loadTimes[3] = I_GetTimeUs(); #ifdef POLYOBJECTS P_UnArchivePolyObjects(); + loadTimes[4] = I_GetTimeUs(); #endif P_NetUnArchiveThinkers(preserveLevel); + loadTimes[5] = I_GetTimeUs(); P_NetUnArchiveSpecials(); + loadTimes[6] = I_GetTimeUs(); P_RelinkPointers(); + loadTimes[7] = I_GetTimeUs(); P_FinishMobjs(); + loadTimes[8] = I_GetTimeUs(); } #ifdef HAVE_BLUA LUA_UnArchive(); + loadTimes[10] = I_GetTimeUs(); #endif // This is stupid and hacky, but maybe it'll work! @@ -3780,7 +4232,56 @@ boolean P_LoadGameState(const savestate_t* savestate) UINT64 time = I_GetTimeUs(); save_p = ((unsigned char*)savestate->buffer); - P_LoadNetGame(true); + return P_LoadNetGame(true); + + globalmobjnum = READUINT32(save_p); + + P_LocalUnArchiveThinkers(); + return true; + + CV_LoadNetVars(&save_p); + loadTimes[0] = I_GetTimeUs(); + if (!P_NetUnArchiveMisc(true)) + return false; + + loadTimes[1] = I_GetTimeUs(); + P_NetUnArchivePlayers(); + loadTimes[2] = I_GetTimeUs(); + if (gamestate == GS_LEVEL) + { + P_NetUnArchiveWorld(true); + loadTimes[3] = I_GetTimeUs(); +#ifdef POLYOBJECTS + P_UnArchivePolyObjects(); + loadTimes[4] = I_GetTimeUs(); +#endif + P_NetUnArchiveThinkers(true); + loadTimes[5] = I_GetTimeUs(); + P_NetUnArchiveSpecials(); + loadTimes[6] = I_GetTimeUs(); + P_NetUnArchiveColormaps(); + loadTimes[7] = I_GetTimeUs(); + P_RelinkPointers(); + loadTimes[8] = I_GetTimeUs(); + P_FinishMobjs(); + loadTimes[9] = I_GetTimeUs(); + } +#ifdef HAVE_BLUA + LUA_UnArchive(); + loadTimes[10] = I_GetTimeUs(); +#endif + + // This is stupid and hacky, but maybe it'll work! + P_SetRandSeed(P_GetInitSeed()); + + // The precipitation would normally be spawned in P_SetupLevel, which is called by + // P_NetUnArchiveMisc above. However, that would place it up before P_NetUnArchiveThinkers, + // so the thinkers would be deleted later. Therefore, P_SetupLevel will *not* spawn + // precipitation when loading a netgame save. Instead, precip has to be spawned here. + // This is done in P_NetUnArchiveSpecials now. + + P_UnArchiveLuabanksAndConsistency(); + loadTime += I_GetTimeUs() - time; numLoads++; diff --git a/src/p_saveg.h b/src/p_saveg.h index d67d91280..7aba45188 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -32,7 +32,7 @@ typedef struct typedef struct { - UINT8 buffer[1024 * 768]; + UINT8 buffer[4 * 1024 * 1024]; // 4 megs per frame should do } savestate_t; // Persistent storage/archiving. From 5284ba6935f6ce955abedd79f95261cafbb688c9 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 17 Dec 2019 20:11:04 +0000 Subject: [PATCH 30/67] Added steadyplayer aim compensation --- src/d_clisrv.c | 283 ++++++++++++++++++++++++++++++++++++++++++++----- src/d_main.c | 4 +- src/d_netcmd.c | 9 +- src/d_netcmd.h | 3 +- src/doomstat.h | 2 + src/g_game.c | 2 + 6 files changed, 270 insertions(+), 33 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 9ae17b79a..f4bfb82e4 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -84,7 +84,7 @@ #define TICCMD_TIMEMASK_ANGLE (~(0xFFFFFFFF<u.clientpak.cmd, &localcmds, 1); + ticcmd_t adjustedCmd = localcmds; + AdjustSimulatedTiccmdInputs(&adjustedCmd); // adjust ticcmds for simulations + + G_MoveTiccmd(&netbuffer->u.clientpak.cmd, &adjustedCmd, 1); netbuffer->u.clientpak.consistancy = SHORT(consistancy[gametic%BACKUPTICS]); if (splitscreen || botingame) // Send a special packet with 2 cmd for splitscreen @@ -5165,6 +5179,174 @@ tic_t DecodeTiccmdTime(const ticcmd_t* ticcmd) #endif } +angle_t FixedAngleBetween(fixed_t srcX, fixed_t srcY, fixed_t destX, fixed_t destY) +{ + return atan2(FIXED_TO_FLOAT(srcY - destY), FIXED_TO_FLOAT(srcX - destX)) * 0xFFFFFFFF / (2.0f*3.14159f) + 0x80000000; +} + +fixed_t FixedLength(fixed_t x, fixed_t y, fixed_t z) +{ + return FLOAT_TO_FIXED(sqrt(FIXED_TO_FLOAT(x) * FIXED_TO_FLOAT(x) + FIXED_TO_FLOAT(y) * FIXED_TO_FLOAT(y) + FIXED_TO_FLOAT(z) * FIXED_TO_FLOAT(z))); +} + +fixed_t FixedLength2(fixed_t x, fixed_t y) +{ + return FLOAT_TO_FIXED(sqrt(FIXED_TO_FLOAT(x) * FIXED_TO_FLOAT(x) + FIXED_TO_FLOAT(y) * FIXED_TO_FLOAT(y))); +} + +fixed_t FixedDistance(fixed_t aX, fixed_t aY, fixed_t aZ, fixed_t bX, fixed_t bY, fixed_t bZ) +{ + return FixedLength(bX - aX, bY - aY, bZ - aZ); +} + +fixed_t FixedDistance2(fixed_t aX, fixed_t aY, fixed_t bX, fixed_t bY) +{ + return FixedLength2(bX - aX, bY - aY); +} + +static ticcmd_t lastCmds; + +void CorrectPlayerTargeting(ticcmd_t* cmds) +{ + if (!players[consoleplayer].mo || !cv_netsteadyplayers.value || simtic == gametic) + { + return; + } + + boolean hasPressedAttack = (cmds->buttons & BT_ATTACK) && (!(lastCmds.buttons & BT_ATTACK) + || (players[consoleplayer].currentweapon == WEP_AUTO && players[consoleplayer].rings > 0)); + + if (hasPressedAttack) + { + // find the most likely targeted player by measuring the angle between them + steadyplayer_t* mostLikelyPlayer = NULL; + SHORT smallestDifference = 0x8000; + SHORT smallestVDifference = 0x8000; + fixed_t dist = 0; + mobj_t* myself = players[consoleplayer].mo; + + for (int i = 0; i < MAXPLAYERS; i++) + { + steadyplayer_t* player = &steadyplayers[i]; + if (playeringame[i] && players[i].mo && i != consoleplayer) + { + SHORT difference = (SHORT)(FixedAngleBetween(myself->x, myself->y, player->gamex, player->gamey)>>FRACBITS) - cmds->angleturn; + SHORT vDifference = -(SHORT)(FixedAngleBetween(0, player->gamez, + FixedDistance2(player->gamex, player->gamey, myself->x, myself->y), myself->z)>>FRACBITS) - cmds->aiming; + + if (abs(difference) + abs(vDifference) < abs(smallestDifference) + abs(smallestVDifference)) + { + smallestDifference = difference; + smallestVDifference = vDifference; + mostLikelyPlayer = &steadyplayers[i]; + } + } + } + + if (mostLikelyPlayer != NULL) + { + if (players[consoleplayer].currentweapon == WEP_RAIL) + { + // rail rings are simple: offset the aim towards the player's new position compared to their old one + SHORT extraDifference = (SHORT)(FixedAngleBetween(myself->x, myself->y, mostLikelyPlayer->simx, mostLikelyPlayer->simy) >> FRACBITS) + - cmds->angleturn; + SHORT extraVDifference = -(SHORT)(FixedAngleBetween(0, mostLikelyPlayer->simz, + FixedDistance2(mostLikelyPlayer->simx, mostLikelyPlayer->simy, myself->x, myself->y), myself->z) >> FRACBITS) - cmds->aiming; + float distanceRatio = FIXED_TO_FLOAT(FixedDiv(FixedDistance(myself->x, myself->y, myself->z, mostLikelyPlayer->simx, mostLikelyPlayer->simy, mostLikelyPlayer->simz), + FixedDistance(myself->x, myself->y, myself->z, mostLikelyPlayer->gamex, mostLikelyPlayer->gamey, mostLikelyPlayer->gamez))); + + // distanceRatio increases/reduces the player's accuracy based on the distance change + + cmds->angleturn += extraDifference - smallestDifference / distanceRatio; + cmds->aiming += extraVDifference - smallestVDifference / distanceRatio; + } + else + { + // other rings are a bit more complex, we want to guess where the enemy will be and use that angle offset instead. + // calculate the player's new position and try to aim towards that + int ringSpeed = mobjinfo[MT_REDRING].speed>>FRACBITS; + fixed_t ringRadius = -(60<gamex, enemyY = mostLikelyPlayer->gamey, enemyZ = mostLikelyPlayer->gamez; + tic_t wowtic = gametic; // owo + fixed_t originalDistance = FixedDistance(myself->x, myself->y, myself->z, enemyX, enemyY, enemyZ); + fixed_t currentDistance = originalDistance; + SHORT difference = 0; + SHORT vDifference = 0; + + while (ringRadius < currentDistance) + { + // move the enemy + if (wowtic < simtic) + { + enemyX = mostLikelyPlayer->histx[wowtic - gametic]; // we have a simulation for this! + enemyY = mostLikelyPlayer->histy[wowtic - gametic]; + enemyZ = mostLikelyPlayer->histz[wowtic - gametic]; + } + else + { + // we don't have a simulation for this so just extrapolate the player's previous position + enemyX += mostLikelyPlayer->histx[simtic - gametic] - mostLikelyPlayer->histx[simtic - gametic - 1]; + enemyY += mostLikelyPlayer->histy[simtic - gametic] - mostLikelyPlayer->histy[simtic - gametic - 1]; + enemyZ += mostLikelyPlayer->histz[simtic - gametic] - mostLikelyPlayer->histz[simtic - gametic - 1]; + } + + currentDistance = FixedDistance(myself->x, myself->y, myself->z, enemyX, enemyY, enemyZ); + + // if we had no lag, would the ring have reached the enemy by now? + if (ringRadius + (60<= currentDistance && difference == 0 && vDifference == 0) + { + // capture the player's current angle offset/accuracy here + difference = (SHORT)(FixedAngleBetween(myself->x, myself->y, enemyX, enemyY) >> FRACBITS) - cmds->angleturn; + vDifference = -(SHORT)(FixedAngleBetween(0, enemyZ, + FixedDistance2(enemyX, enemyY, myself->x, myself->y), myself->z) >> FRACBITS) - cmds->aiming; + } + + ringRadius += 60<angleturn = (SHORT)(FixedAngleBetween(myself->x, myself->y, enemyX, enemyY)>>FRACBITS) - FixedDiv(difference, distanceRatio); + cmds->aiming = -(SHORT)(FixedAngleBetween(0, enemyZ, FixedDistance2(enemyX, enemyY, myself->x, myself->y), myself->z) >> FRACBITS) - FixedDiv(vDifference, distanceRatio); + } + } + } +} + +static void AdjustSimulatedTiccmdInputs(ticcmd_t* cmds) +{ + if (server || simtic == gametic) + { + return; + } + + SHORT oldAngle = cmds->angleturn; + + if (gamestate == GS_LEVEL && cv_netsteadyplayers.value) + { + CorrectPlayerTargeting(cmds); + } + + if (cmds->angleturn != oldAngle) + { + // If the target angle is different, readjust movements to go towards it + angle_t difference = (cmds->angleturn - oldAngle) << 16; + char oldSidemove = cmds->sidemove, oldForwardmove = cmds->forwardmove; + + cmds->sidemove = (FixedMul((fixed_t)(oldSidemove<>ANGLETOFINESHIFT)) + + FixedMul((fixed_t)(oldForwardmove<>ANGLETOFINESHIFT))) >> FRACBITS; + cmds->forwardmove = (FixedMul((fixed_t)(oldSidemove<>ANGLETOFINESHIFT)) + + FixedMul((fixed_t)(oldForwardmove<>ANGLETOFINESHIFT))) >> FRACBITS; + + cmds->sidemove = min(max(cmds->sidemove, -50), 50); + cmds->forwardmove = min(max(cmds->forwardmove, -50), 50); + } + + lastCmds = *cmds; +} + // // TryRunTics // @@ -5260,8 +5442,6 @@ static void SV_Maketic(void) extern tic_t rendergametic; tic_t liveTic; -tic_t simTic; -tic_t smoothedTic; int netJitter; int estimatedRTT; @@ -5376,9 +5556,8 @@ void TryRunTics(tic_t realtics) liveTic = I_GetTime(); newSaveTic = newLoadTic = true; - for (tic_t i = 0; i < realtics; i++) { + for (tic_t i = 0; i < realtics; i++) localTicBuffer[(liveTic - i) % BACKUPTICS] = localcmds; - } // Run the real game as received from the server if (neededtic > gametic && !resynch_local_inprogress) @@ -5403,7 +5582,7 @@ void TryRunTics(tic_t realtics) G_Ticker((gametic % NEWTICRATERATIO) == 0); ExtraDataTicker(); gametic++; - simTic = gametic; + simtic = gametic; consistancy[gametic%BACKUPTICS] = Consistancy(); @@ -5417,9 +5596,8 @@ void TryRunTics(tic_t realtics) gameStateBufferIsValid[gametic % BACKUPTICS] = true; // store the ticcmds used during this game tic - for (int i = 0; i < MAXPLAYERS; i++) { + for (int i = 0; i < MAXPLAYERS; i++) gameTicBuffer[gametic % BACKUPTICS][i] = netcmds[(gametic - 1) % BACKUPTICS][i]; - } } // Leave a certain amount of tics present in the net buffer as long as we've ran at least one tic this frame. @@ -5435,7 +5613,6 @@ void TryRunTics(tic_t realtics) smoothedTic is the time that we are using as a basis to cancel out jitter. this may be slightly <= gametic. liveTic is the real time of the game from startup, used to record our commands simTic is the gametic we've simulated to. if this == gametic, we haven't simulated any - gameStateBuffer[gametic] is the game state before 'gametic' executes */ @@ -5456,7 +5633,7 @@ void TryRunTics(tic_t realtics) P_LoadGameState(&gameStateBuffer[(smoothedTic + BACKUPTICS) % BACKUPTICS]); } - simTic = smoothedTic; + simtic = smoothedTic; } else { @@ -5468,18 +5645,40 @@ void TryRunTics(tic_t realtics) int targetSimTic = min(gametic + estimatedRTT, smoothedTic + cv_simulatetics.value); - if (targetSimTic - simTic > MAXSIMULATIONS) - { - // don't simulate more than MAXSIMULATIONS - simTic = targetSimTic - MAXSIMULATIONS; - } + // don't simulate more than MAXSIMULATIONS + if (targetSimTic - simtic > MAXSIMULATIONS) + simtic = targetSimTic - MAXSIMULATIONS; - int numToSimulate = targetSimTic - simTic; + int numToSimulate = targetSimTic - simtic; // simulate the rest o da future localangle = preservedAngle; localaiming = preservedAiming; + if (cv_netsteadyplayers.value && simtic == smoothedTic) + { + // if steady players is enabled, record their real game position and their simulated position + for (int i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i] && players[i].mo && i != consoleplayer) + { + if (simtic == smoothedTic) // this is their real position + { + steadyplayers[i].gamex = steadyplayers[i].simx = steadyplayers[i].histx[0] = players[i].mo->x; + steadyplayers[i].gamey = steadyplayers[i].simy = steadyplayers[i].histy[0] = players[i].mo->y; + steadyplayers[i].gamez = steadyplayers[i].simz = steadyplayers[i].histz[0] = players[i].mo->z; + } + else + { + // restore the players' simulated position before simulating more + players[i].mo->x = steadyplayers[i].simx; + players[i].mo->y = steadyplayers[i].simy; + players[i].mo->z = steadyplayers[i].simz; + } + } + } + } + for (int i = 0; i < numToSimulate; i++) { // control other players for (int j = 0; j < MAXPLAYERS; j++) { @@ -5490,9 +5689,9 @@ void TryRunTics(tic_t realtics) } // control the local player - if (simTic + i < gametic) { + if (simtic + i < gametic) { // we have a tiny bit more info we can glean - netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(simTic + i + 1) % BACKUPTICS][consoleplayer]; + netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(simtic + i + 1) % BACKUPTICS][consoleplayer]; } else { @@ -5501,11 +5700,40 @@ void TryRunTics(tic_t realtics) G_Ticker(true); // tic a bunch of times lol see what happens lolol + // record simulated players' positions + if (cv_netsteadyplayers.value) + { + for (int j = 0; j < MAXPLAYERS; j++) + { + if (playeringame[j] && players[j].mo && j != consoleplayer) + { + // Update steadyplayers' simulated positions and move their game positions to their known one + steadyplayers[j].simx = steadyplayers[j].histx[simtic - smoothedTic + i + 1] = players[j].mo->x; + steadyplayers[j].simy = steadyplayers[j].histy[simtic - smoothedTic + i + 1] = players[j].mo->y; + steadyplayers[j].simz = steadyplayers[j].histz[simtic - smoothedTic + i + 1] = players[j].mo->z; + } + } + } + preservedAngle = localangle; // game simulations may lock the view angle preservedAiming = localaiming; } - simTic = targetSimTic; + if (cv_netsteadyplayers.value) + { + for (int j = 0; j < MAXPLAYERS; j++) + { + if (playeringame[j] && players[j].mo && j != consoleplayer) + { + // Set the player's positions to the last known real game position + players[j].mo->x = steadyplayers[j].gamex; + players[j].mo->y = steadyplayers[j].gamey; + players[j].mo->z = steadyplayers[j].gamez; + } + } + } + + simtic = targetSimTic; //rendergametic = 0; // hack to make sure game doesn't jitter // restore local camera stuff because that's local anyways~ @@ -5518,11 +5746,11 @@ void TryRunTics(tic_t realtics) if (!canSimulate) { - simTic = gametic; + simtic = gametic; smoothedTic = gametic; } - didSimulate = simTic != gametic || smoothedTic != gametic; + didSimulate = simtic != gametic || smoothedTic != gametic; // we're gonna need more debugs... MakeNetDebugString(); @@ -5622,7 +5850,7 @@ void MakeNetDebugString() for (int i = 10; i >= 0; i--) { - if ((tic_t)i >= simTic - gametic) { + if ((tic_t)i >= simtic - gametic) { // show tics and matches sprintf(&netDebugText[strlen(netDebugText)], "srv: %02d%slcl: %02d%s\n", @@ -5643,15 +5871,14 @@ void MakeNetDebugString() sprintf(&netDebugText[strlen(netDebugText)], "\n\nJitter: %d", netJitter); sprintf(&netDebugText[strlen(netDebugText)], "\nEstPing: %d", estimatedRTT); - sprintf(&netDebugText[strlen(netDebugText)], "\nSim-T: %d", simTic - gametic); + sprintf(&netDebugText[strlen(netDebugText)], "\nSim-T: %d", simtic - gametic); sprintf(&netDebugText[strlen(netDebugText)], "\nLive: %d", liveTic); - sprintf(&netDebugText[strlen(netDebugText)], "\nSaveN/LoadN: %i/%i", numSaves, numLoads); + /*sprintf(&netDebugText[strlen(netDebugText)], "\nSaveN/LoadN: %i/%i", numSaves, numLoads); for (int i = 1; i < 11; i++) { sprintf(&netDebugText[strlen(netDebugText)], "\n[%i] %i/%i", i, saveTimes[i] - saveTimes[i - 1], loadTimes[i] - loadTimes[i - 1]); - - } + }*/ } // startTic and endTics are tics going back in time from the current liveTic diff --git a/src/d_main.c b/src/d_main.c index 75aac6894..d9b3b4e38 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -592,8 +592,8 @@ static void D_Display(void) snprintf(s, sizeof s - 1, "SysMiss %.2f%%", lostpercent); V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-10, V_YELLOWMAP, s); } - - if (netDebugText[0] != 0) + + if (cv_netsimstat.value && netDebugText[0] != 0) { const char* str = netDebugText; int y = 0; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 2ed2a016d..f5e42d578 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -436,6 +436,7 @@ consvar_t cv_allowexitlevel = {"allowexitlevel", "No", CV_NETVAR, CV_YesNo, NULL consvar_t cv_killingdead = {"killingdead", "Off", CV_NETVAR|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_netsimstat = { "netsimstat", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; consvar_t cv_netstat = {"netstat", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // show bandwidth statistics static CV_PossibleValue_t nettimeout_cons_t[] = {{TICRATE/7, "MIN"}, {60*TICRATE, "MAX"}, {0, NULL}}; consvar_t cv_nettimeout = {"nettimeout", "105", CV_CALL|CV_SAVE, nettimeout_cons_t, NetTimeout_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -483,13 +484,15 @@ consvar_t cv_netdelay = { "netdelay", "0", 0, netdelay_cons_t, NULL, 0, NULL, NU static CV_PossibleValue_t netjitter_cons_t[] = { {0, "MIN"}, {5, "MAX"}, {0, NULL} }; consvar_t cv_netjitter = { "netjitter", "0", 0, netdelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; -consvar_t cv_netsmoothing = { "netsmoothing", "0", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_netsmoothing = { "netsmoothing", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; -consvar_t cv_netspikes = { "netspikes", "0", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_netspikes = { "netspikes", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; static CV_PossibleValue_t debugsimulaterewind_cons_t[] = { {0, "MIN"}, {BACKUPTICS - 1, "MAX"}, {0, NULL} }; consvar_t cv_debugsimulaterewind = { "debugsimulaterewind", "0", 0, debugsimulaterewind_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_netsteadyplayers = { "netsteadyplayers", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; + char timedemo_name[256]; boolean timedemo_csv; char timedemo_csv_id[256]; @@ -650,6 +653,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_netjitter); CV_RegisterVar(&cv_netsmoothing); CV_RegisterVar(&cv_netspikes); + CV_RegisterVar(&cv_netsteadyplayers); CV_RegisterVar(&cv_debugsimulaterewind); // for master server connection @@ -930,6 +934,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_rollingdemos); CV_RegisterVar(&cv_netstat); CV_RegisterVar(&cv_netticbuffer); + CV_RegisterVar(&cv_netsimstat); #ifdef NETGAME_DEVMODE CV_RegisterVar(&cv_fishcake); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 044d23582..6534d8e0b 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -83,6 +83,7 @@ extern consvar_t cv_teamscramble; extern consvar_t cv_scrambleonchange; extern consvar_t cv_netstat; +extern consvar_t cv_netsimstat; #ifdef WALLSPLATS extern consvar_t cv_splats; #endif @@ -153,8 +154,8 @@ extern consvar_t cv_netdelay; extern consvar_t cv_netjitter; extern consvar_t cv_netsmoothing; extern consvar_t cv_netspikes; +extern consvar_t cv_netsteadyplayers; extern consvar_t cv_debugsimulaterewind; - extern consvar_t cv_skipmapcheck; extern consvar_t cv_sleep; diff --git a/src/doomstat.h b/src/doomstat.h index 1f855da27..03b97b17b 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -500,6 +500,8 @@ extern UINT32 timesBeatenWithEmeralds; // WAD, partly set at startup time. extern tic_t gametic; +extern tic_t simtic; // current tic at simulation, if applicable (if no simulation happened, this=gametic) +extern tic_t smoothedTic; // current game tic when smoothing is enabled (\todo: could cause problems if the game objects care about gametic) #define localgametic leveltime // Player spawn spots. diff --git a/src/g_game.c b/src/g_game.c index 04982e5ca..b0f18d98e 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -116,6 +116,8 @@ INT32 consoleplayer; // player taking events and displaying INT32 displayplayers[MAXSPLITSCREENPLAYERS]; // view being displayed tic_t gametic; +tic_t simtic; // simulated tic +tic_t smoothedTic; tic_t levelstarttic; // gametic at level start UINT32 totalrings; // for intermission INT16 lastmap; // last level you were at (returning from special stages) From 697f6994c9fd2fb40429dbb868b3f377dcafcc9d Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 17 Dec 2019 23:12:10 +0000 Subject: [PATCH 31/67] Steadyplayers is now variable (now refers to how many tics behind the simulation the other players can be) Also cleaned up a little --- src/d_clisrv.c | 356 +++++++++++++++++++++---------------------------- src/d_clisrv.h | 12 ++ src/d_main.c | 4 + src/d_netcmd.c | 3 +- src/p_saveg.c | 9 +- 5 files changed, 178 insertions(+), 206 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f4bfb82e4..c49b0b3b9 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -76,16 +76,6 @@ #define MAX_REASONLENGTH 30 #define FORCECLOSE 0x8000 -// How many time bits to encode into ticcmds (aiming and angle components, respectively) -#define ENCODE_TICCMD_TIMES -#define TICCMD_TIMEBITS_AIMING 3 -#define TICCMD_TIMEBITS_ANGLE 2 -#define TICCMD_TIMEMASK_AIMING (~(0xFFFFFFFF<buttons & BT_ATTACK) && (!(lastCmds.buttons & BT_ATTACK) || (players[consoleplayer].currentweapon == WEP_AUTO && players[consoleplayer].rings > 0)); @@ -5224,15 +5211,17 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) SHORT smallestVDifference = 0x8000; fixed_t dist = 0; mobj_t* myself = players[consoleplayer].mo; + int gameHist = max((int)(simtic-gametic) - cv_netsteadyplayers.value, 0); // current hist time that the players have been positioned at on the screen + int simHist = simtic - gametic; // max simulated hist time for (int i = 0; i < MAXPLAYERS; i++) { steadyplayer_t* player = &steadyplayers[i]; if (playeringame[i] && players[i].mo && i != consoleplayer) { - SHORT difference = (SHORT)(FixedAngleBetween(myself->x, myself->y, player->gamex, player->gamey)>>FRACBITS) - cmds->angleturn; - SHORT vDifference = -(SHORT)(FixedAngleBetween(0, player->gamez, - FixedDistance2(player->gamex, player->gamey, myself->x, myself->y), myself->z)>>FRACBITS) - cmds->aiming; + fixed_t curX = player->histx[gameHist], curY = player->histy[gameHist], curZ = player->histz[gameHist]; + SHORT difference = (SHORT)(FixedAngleBetween(myself->x, myself->y, curX, curY)>>FRACBITS) - cmds->angleturn; + SHORT vDifference = -(SHORT)(FixedAngleBetween(0, curZ, FixedDistance2(curX, curY, myself->x, myself->y), myself->z)>>FRACBITS) - cmds->aiming; if (abs(difference) + abs(vDifference) < abs(smallestDifference) + abs(smallestVDifference)) { @@ -5245,20 +5234,18 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) if (mostLikelyPlayer != NULL) { + fixed_t curX = mostLikelyPlayer->histx[gameHist], curY = mostLikelyPlayer->histy[gameHist], curZ = mostLikelyPlayer->histz[gameHist]; + fixed_t simX = mostLikelyPlayer->histx[simHist], simY = mostLikelyPlayer->histy[simHist], simZ = mostLikelyPlayer->histz[simHist]; + if (players[consoleplayer].currentweapon == WEP_RAIL) { // rail rings are simple: offset the aim towards the player's new position compared to their old one - SHORT extraDifference = (SHORT)(FixedAngleBetween(myself->x, myself->y, mostLikelyPlayer->simx, mostLikelyPlayer->simy) >> FRACBITS) - - cmds->angleturn; - SHORT extraVDifference = -(SHORT)(FixedAngleBetween(0, mostLikelyPlayer->simz, - FixedDistance2(mostLikelyPlayer->simx, mostLikelyPlayer->simy, myself->x, myself->y), myself->z) >> FRACBITS) - cmds->aiming; - float distanceRatio = FIXED_TO_FLOAT(FixedDiv(FixedDistance(myself->x, myself->y, myself->z, mostLikelyPlayer->simx, mostLikelyPlayer->simy, mostLikelyPlayer->simz), - FixedDistance(myself->x, myself->y, myself->z, mostLikelyPlayer->gamex, mostLikelyPlayer->gamey, mostLikelyPlayer->gamez))); + // distanceRatio increases/reduces the player's accuracy based on the distance change (e.g. big close Sonic to little faraway Sonic) + fixed_t distanceRatio = FixedDiv(FixedDistance(myself->x, myself->y, myself->z, simX, simY, simZ), FixedDistance(myself->x, myself->y, myself->z, curX, curY, curZ)); - // distanceRatio increases/reduces the player's accuracy based on the distance change - - cmds->angleturn += extraDifference - smallestDifference / distanceRatio; - cmds->aiming += extraVDifference - smallestVDifference / distanceRatio; + cmds->angleturn = (SHORT)(FixedAngleBetween(myself->x, myself->y, simX, simY) >> FRACBITS) - FixedDiv(smallestDifference, distanceRatio); + cmds->aiming = -(SHORT)(FixedAngleBetween(0, simZ, FixedDistance2(simX, simY, myself->x, myself->y), myself->z) >> FRACBITS) - + FixedDiv(smallestVDifference, distanceRatio); } else { @@ -5266,8 +5253,8 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) // calculate the player's new position and try to aim towards that int ringSpeed = mobjinfo[MT_REDRING].speed>>FRACBITS; fixed_t ringRadius = -(60<gamex, enemyY = mostLikelyPlayer->gamey, enemyZ = mostLikelyPlayer->gamez; - tic_t wowtic = gametic; // owo + fixed_t enemyX = curX, enemyY = curY, enemyZ = curZ; + tic_t wowtic = min(gametic, simtic - cv_netsteadyplayers.value); fixed_t originalDistance = FixedDistance(myself->x, myself->y, myself->z, enemyX, enemyY, enemyZ); fixed_t currentDistance = originalDistance; SHORT difference = 0; @@ -5284,7 +5271,7 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) } else { - // we don't have a simulation for this so just extrapolate the player's previous position + // we ran out of simulations so just extrapolate the player's previous position enemyX += mostLikelyPlayer->histx[simtic - gametic] - mostLikelyPlayer->histx[simtic - gametic - 1]; enemyY += mostLikelyPlayer->histy[simtic - gametic] - mostLikelyPlayer->histy[simtic - gametic - 1]; enemyZ += mostLikelyPlayer->histz[simtic - gametic] - mostLikelyPlayer->histz[simtic - gametic - 1]; @@ -5318,20 +5305,16 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) static void AdjustSimulatedTiccmdInputs(ticcmd_t* cmds) { if (server || simtic == gametic) - { return; - } SHORT oldAngle = cmds->angleturn; if (gamestate == GS_LEVEL && cv_netsteadyplayers.value) - { CorrectPlayerTargeting(cmds); - } if (cmds->angleturn != oldAngle) { - // If the target angle is different, readjust movements to go towards it + // If the aiming angles are different, readjust movements to go towards the player's original intended direction angle_t difference = (cmds->angleturn - oldAngle) << 16; char oldSidemove = cmds->sidemove, oldForwardmove = cmds->forwardmove; @@ -5439,8 +5422,15 @@ static void SV_Maketic(void) maketic++; } -extern tic_t rendergametic; - +// Overview for the new programmer and the programmer who probably isn't new, but doesn't have a clue what his code does becuase he didn't comment it ;) +// oh dayum did I just get called out by my old comment +/* +gametic is always the real tic as received from the server, plus one. the simulator does not change this! +smoothedTic is the time that we are using as a basis to cancel out jitter. this may be slightly <= gametic. +liveTic is the real time of the game from startup, used to record our commands +simTic is the gametic we've simulated to. if this == gametic, we haven't simulated any +gameStateBuffer[gametic] is the game state before 'gametic' executes +*/ tic_t liveTic; int netJitter; @@ -5524,33 +5514,19 @@ void TryRunTics(tic_t realtics) static boolean didSimulate = false; boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= BACKUPTICS && gametic >= BACKUPTICS && (cv_simulate.value && !server) && !resynch_local_inprogress; boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 1 && gametic >= BACKUPTICS; - boolean preserveSoundDisabled = sound_disabled; - int numNewTics = neededtic - gametic; - - // preserve camera changes while we play with simulations/rewinds - angle_t preservedAngle = localangle[0]; - INT32 preservedAiming = localaiming[0]; if (didSimulate && !canSimulate) { - // if simulation stops, there is no guarantee our buffers are valid anymore - if (gameStateBufferIsValid[gametic % BACKUPTICS]) { + // if simulation stopped, there is no guarantee our buffers are valid anymore + if (gameStateBufferIsValid[gametic % BACKUPTICS]) P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); - } // invalidate previous states - for (int i = 0; i < BACKUPTICS; i++) { + for (int i = 0; i < BACKUPTICS; i++) gameStateBufferIsValid[i] = false; - } } - if (recordingStates) - { - PerformDebugRewinds(); - } - - localangle[0] = preservedAngle; - localaiming[0] = preservedAiming; + PerformDebugRewinds(); // record the actual local controls for this frame liveTic = I_GetTime(); @@ -5567,29 +5543,23 @@ void TryRunTics(tic_t realtics) else { // Load the real state if it exists - if (canSimulate && gameStateBufferIsValid[gametic % BACKUPTICS]) { + if (canSimulate && gameStateBufferIsValid[gametic % BACKUPTICS]) P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); - } // run the tics up to the real game tic while (neededtic > gametic) { DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic)); - localangle = preservedAngle; - localaiming = preservedAiming; - G_Ticker((gametic % NEWTICRATERATIO) == 0); ExtraDataTicker(); gametic++; - simtic = gametic; + simtic = gametic; // game state is reset, we wanna resimulate from here consistancy[gametic%BACKUPTICS] = Consistancy(); - preservedAngle = localangle; - preservedAiming = localaiming; - - if (recordingStates) { + if (recordingStates) + { // store this real state P_SaveGameState(&gameStateBuffer[gametic % BACKUPTICS]); @@ -5607,146 +5577,26 @@ void TryRunTics(tic_t realtics) } } - // Overview for the new programmer and the programmer who isn't new, but doesn't have a clue what his code does becuase he didn't comment it ;) - /* - gametic is always the real tic as received from the server, plus one. the simulator does not change this! - smoothedTic is the time that we are using as a basis to cancel out jitter. this may be slightly <= gametic. - liveTic is the real time of the game from startup, used to record our commands - simTic is the gametic we've simulated to. if this == gametic, we haven't simulated any - gameStateBuffer[gametic] is the game state before 'gametic' executes - */ + // Smooth out the game state according to the network + // \todo rather than re-loading an older state, we could just buffer the tics instead of running them above + if (cv_netsmoothing.value) + { + smoothedTic = liveTic - maxLiveTicOffset - 1; + + if (gameStateBufferIsValid[(smoothedTic + BACKUPTICS) % BACKUPTICS] && smoothedTic != gametic) + P_LoadGameState(&gameStateBuffer[(smoothedTic + BACKUPTICS) % BACKUPTICS]); + + simtic = smoothedTic; + } + else + smoothedTic = gametic; // Simulate the game locally if (canSimulate) + RunSimulations(); + else { - sound_disabled = true; - //con_muted = true; - - // run the simulated state - // find the latest available real state - // sometimes we will go backwards to buffer the updates - if (cv_netsmoothing.value) { - smoothedTic = liveTic - maxLiveTicOffset - 1; - - if (gameStateBufferIsValid[(smoothedTic + BACKUPTICS) % BACKUPTICS] && smoothedTic != gametic) - { - P_LoadGameState(&gameStateBuffer[(smoothedTic + BACKUPTICS) % BACKUPTICS]); - } - - simtic = smoothedTic; - } - else - { - smoothedTic = gametic; - } - - // this must be done after smoothedTic is set - DetermineNetConditions(); - - int targetSimTic = min(gametic + estimatedRTT, smoothedTic + cv_simulatetics.value); - - // don't simulate more than MAXSIMULATIONS - if (targetSimTic - simtic > MAXSIMULATIONS) - simtic = targetSimTic - MAXSIMULATIONS; - - int numToSimulate = targetSimTic - simtic; - - // simulate the rest o da future - localangle = preservedAngle; - localaiming = preservedAiming; - - if (cv_netsteadyplayers.value && simtic == smoothedTic) - { - // if steady players is enabled, record their real game position and their simulated position - for (int i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i] && players[i].mo && i != consoleplayer) - { - if (simtic == smoothedTic) // this is their real position - { - steadyplayers[i].gamex = steadyplayers[i].simx = steadyplayers[i].histx[0] = players[i].mo->x; - steadyplayers[i].gamey = steadyplayers[i].simy = steadyplayers[i].histy[0] = players[i].mo->y; - steadyplayers[i].gamez = steadyplayers[i].simz = steadyplayers[i].histz[0] = players[i].mo->z; - } - else - { - // restore the players' simulated position before simulating more - players[i].mo->x = steadyplayers[i].simx; - players[i].mo->y = steadyplayers[i].simy; - players[i].mo->z = steadyplayers[i].simz; - } - } - } - } - - for (int i = 0; i < numToSimulate; i++) { - // control other players - for (int j = 0; j < MAXPLAYERS; j++) { - if (playeringame[j] && j != consoleplayer) { - // just use their last control for now - netcmds[gametic % BACKUPTICS][j] = gameTicBuffer[(min(smoothedTic + i + 1, gametic) + BACKUPTICS) % BACKUPTICS][j]; - } - } - - // control the local player - if (simtic + i < gametic) { - // we have a tiny bit more info we can glean - netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(simtic + i + 1) % BACKUPTICS][consoleplayer]; - } - else - { - netcmds[gametic % BACKUPTICS][consoleplayer] = localTicBuffer[(liveTic - numToSimulate + i + 1 + BACKUPTICS) % BACKUPTICS]; - } - - G_Ticker(true); // tic a bunch of times lol see what happens lolol - - // record simulated players' positions - if (cv_netsteadyplayers.value) - { - for (int j = 0; j < MAXPLAYERS; j++) - { - if (playeringame[j] && players[j].mo && j != consoleplayer) - { - // Update steadyplayers' simulated positions and move their game positions to their known one - steadyplayers[j].simx = steadyplayers[j].histx[simtic - smoothedTic + i + 1] = players[j].mo->x; - steadyplayers[j].simy = steadyplayers[j].histy[simtic - smoothedTic + i + 1] = players[j].mo->y; - steadyplayers[j].simz = steadyplayers[j].histz[simtic - smoothedTic + i + 1] = players[j].mo->z; - } - } - } - - preservedAngle = localangle; // game simulations may lock the view angle - preservedAiming = localaiming; - } - - if (cv_netsteadyplayers.value) - { - for (int j = 0; j < MAXPLAYERS; j++) - { - if (playeringame[j] && players[j].mo && j != consoleplayer) - { - // Set the player's positions to the last known real game position - players[j].mo->x = steadyplayers[j].gamex; - players[j].mo->y = steadyplayers[j].gamey; - players[j].mo->z = steadyplayers[j].gamez; - } - } - } - - simtic = targetSimTic; - //rendergametic = 0; // hack to make sure game doesn't jitter - - // restore local camera stuff because that's local anyways~ - localangle[0] = preservedAngle; - localaiming[0] = preservedAiming; - - sound_disabled = preserveSoundDisabled; - //con_muted = false; - } - - if (!canSimulate) - { - simtic = gametic; + simtic = gametic; // just use the real tic smoothedTic = gametic; } @@ -5756,6 +5606,103 @@ void TryRunTics(tic_t realtics) MakeNetDebugString(); } +static void RunSimulations() +{ + boolean preserveSoundDisabled = sound_disabled; + + sound_disabled = true; + con_muted = true; + + // this must be done after smoothedTic is set + DetermineNetConditions(); + + int targetSimTic = min(gametic + estimatedRTT, smoothedTic + cv_simulatetics.value); + + // don't simulate more than MAXSIMULATIONS + if (targetSimTic - simtic > MAXSIMULATIONS) + simtic = targetSimTic - MAXSIMULATIONS; + + // if steady players is enabled, record their real game position and their simulated position + if (cv_netsteadyplayers.value) + { + for (int i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i] && players[i].mo && i != consoleplayer) + { + if (simtic == smoothedTic) // this is their real position + { + steadyplayers[i].histx[0] = players[i].mo->x; + steadyplayers[i].histy[0] = players[i].mo->y; + steadyplayers[i].histz[0] = players[i].mo->z; + } + else + { + // restore the players' simulated position before simulating more + players[i].mo->x = steadyplayers[i].histx[simtic-smoothedTic]; + players[i].mo->y = steadyplayers[i].histy[simtic-smoothedTic]; + players[i].mo->z = steadyplayers[i].histz[simtic-smoothedTic]; + } + } + } + } + + // simulate the rest o da future + int numToSimulate = targetSimTic - simtic; + for (int i = 0; i < numToSimulate; i++) + { + // control other players (just use their previous control for now) + for (int j = 0; j < MAXPLAYERS; j++) + { + if (playeringame[j] && j != consoleplayer) + netcmds[gametic % BACKUPTICS][j] = gameTicBuffer[(min(smoothedTic + i + 1, gametic) + BACKUPTICS) % BACKUPTICS][j]; + } + + // control the local player + if (simtic + i < gametic) // game is smoothed, take tics from the _actual_ received state + netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(simtic + i + 1) % BACKUPTICS][consoleplayer]; + else + netcmds[gametic % BACKUPTICS][consoleplayer] = localTicBuffer[(liveTic - numToSimulate + i + 1 + BACKUPTICS) % BACKUPTICS]; + + G_Ticker(true); // tic a bunch of times lol see what happens lolol + + // record simulated players' positions + if (cv_netsteadyplayers.value) + { + for (int j = 0; j < MAXPLAYERS; j++) + { + if (playeringame[j] && players[j].mo && j != consoleplayer) + { + // Update steadyplayers' simulated positions and move their game positions to their known one + steadyplayers[j].histx[simtic - smoothedTic + i + 1] = players[j].mo->x; + steadyplayers[j].histy[simtic - smoothedTic + i + 1] = players[j].mo->y; + steadyplayers[j].histz[simtic - smoothedTic + i + 1] = players[j].mo->z; + } + } + } + } + + if (cv_netsteadyplayers.value) + { + int histIndex = max((int)(targetSimTic - smoothedTic) - cv_netsteadyplayers.value, 0); // up to cv_netsteadyplayers.value behind the simulation + for (int j = 0; j < MAXPLAYERS; j++) + { + if (playeringame[j] && players[j].mo && j != consoleplayer) + { + // Set the player's positions to the last known real game position + players[j].mo->x = steadyplayers[j].histx[histIndex]; + players[j].mo->y = steadyplayers[j].histy[histIndex]; + players[j].mo->z = steadyplayers[j].histz[histIndex]; + } + } + } + + simtic = targetSimTic; + rendergametic = simtic; // hack to make sure game doesn't jitter + + sound_disabled = preserveSoundDisabled; + con_muted = false; +} + void DetermineNetConditions() { // Refresh the time offset between real time and server time @@ -5795,7 +5742,8 @@ void DetermineNetConditions() #endif } -static void PerformDebugRewinds() { +static void PerformDebugRewinds() +{ if (rewindingWow && rewindingTarget > 0 && gameStateBufferIsValid[(gametic - rewindingTarget) % BACKUPTICS]) { P_LoadGameState(&gameStateBuffer[(gametic - rewindingTarget) % BACKUPTICS]); diff --git a/src/d_clisrv.h b/src/d_clisrv.h index e7879d582..c5e471a2b 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -38,6 +38,18 @@ // Networking and tick handling related. #define BACKUPTICS 32 #define MAXTEXTCMD 256 + +// How many time bits to encode into ticcmds (aiming and angle components, respectively) +#define ENCODE_TICCMD_TIMES +#define TICCMD_TIMEBITS_AIMING 3 +#define TICCMD_TIMEBITS_ANGLE 2 +#define TICCMD_TIMEMASK_AIMING (~(0xFFFFFFFF< displayplayers (hear sounds from viewpoint) S_UpdateSounds(); // move positional sounds diff --git a/src/d_netcmd.c b/src/d_netcmd.c index f5e42d578..a7244f126 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -491,7 +491,8 @@ consvar_t cv_netspikes = { "netspikes", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, static CV_PossibleValue_t debugsimulaterewind_cons_t[] = { {0, "MIN"}, {BACKUPTICS - 1, "MAX"}, {0, NULL} }; consvar_t cv_debugsimulaterewind = { "debugsimulaterewind", "0", 0, debugsimulaterewind_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; -consvar_t cv_netsteadyplayers = { "netsteadyplayers", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; +static CV_PossibleValue_t netsteadyplayers_cons_t[] = { {0, "MIN"}, {MAXSIMULATIONS - 1, "MAX"}, {0, NULL} }; +consvar_t cv_netsteadyplayers = { "netsteadyplayers", "0", 0, netsteadyplayers_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; char timedemo_name[256]; boolean timedemo_csv; diff --git a/src/p_saveg.c b/src/p_saveg.c index 5a4c64d8a..0d8d6efa8 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -4230,9 +4230,16 @@ boolean P_LoadGameState(const savestate_t* savestate) } UINT64 time = I_GetTimeUs(); + angle_t preserveAngle = localangle; + INT32 preserveAiming = localaiming; save_p = ((unsigned char*)savestate->buffer); - return P_LoadNetGame(true); + P_LoadNetGame(true); + + localangle = preserveAngle; + localaiming = preserveAiming; + + return true; globalmobjnum = READUINT32(save_p); From 9930675c939338c250d94f4859007d1858929863 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 18 Dec 2019 02:22:19 +0000 Subject: [PATCH 32/67] Added experimental time fudge (for better sync with server tics) + Smoothened out simulations slightly --- src/d_clisrv.c | 107 +++++++++++++++++++++++++++++++++++++-------- src/d_main.c | 4 -- src/d_netcmd.c | 4 ++ src/d_netcmd.h | 2 + src/sdl/i_system.c | 31 +++++++++++-- 5 files changed, 121 insertions(+), 27 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index c49b0b3b9..dc44d9a9f 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5433,8 +5433,11 @@ gameStateBuffer[gametic] is the game state before 'gametic' executes */ tic_t liveTic; -int netJitter; +int serverJitter; +int rttJitter; int estimatedRTT; +int minRTT; +int maxRTT; int maxLiveTicOffset; int minLiveTicOffset; int smoothingDelay; @@ -5616,7 +5619,21 @@ static void RunSimulations() // this must be done after smoothedTic is set DetermineNetConditions(); - int targetSimTic = min(gametic + estimatedRTT, smoothedTic + cv_simulatetics.value); + int tastyFudge = 0; + // hack: don't treat duplicate tics as extra round-trip time + for (int j = 0; j < 2; j++) + { + if (CompareTiccmd(&gameTicBuffer[gametic % BACKUPTICS][consoleplayer], &gameTicBuffer[(gametic - j) % BACKUPTICS][consoleplayer])) + { + tastyFudge++; + } + else + { + break; + } + } + + int targetSimTic = min(gametic + estimatedRTT - tastyFudge, smoothedTic + cv_simulatetics.value); // don't simulate more than MAXSIMULATIONS if (targetSimTic - simtic > MAXSIMULATIONS) @@ -5661,7 +5678,7 @@ static void RunSimulations() if (simtic + i < gametic) // game is smoothed, take tics from the _actual_ received state netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(simtic + i + 1) % BACKUPTICS][consoleplayer]; else - netcmds[gametic % BACKUPTICS][consoleplayer] = localTicBuffer[(liveTic - numToSimulate + i + 1 + BACKUPTICS) % BACKUPTICS]; + netcmds[gametic % BACKUPTICS][consoleplayer] = localTicBuffer[(liveTic - estimatedRTT + i + 1 + BACKUPTICS) % BACKUPTICS]; G_Ticker(true); // tic a bunch of times lol see what happens lolol @@ -5696,13 +5713,20 @@ static void RunSimulations() } } - simtic = targetSimTic; - rendergametic = simtic; // hack to make sure game doesn't jitter + if (simtic != targetSimTic) + { + rendergametic = gametic; + simtic = targetSimTic; + } sound_disabled = preserveSoundDisabled; con_muted = false; } +int rttBuffer[70]; +int rttBufferIndex = 0; +int rttBufferMax = 70; + void DetermineNetConditions() { // Refresh the time offset between real time and server time @@ -5718,9 +5742,9 @@ void DetermineNetConditions() maxLiveTicOffset = max(maxLiveTicOffset, ticTimeOffsetHistory[i]); } - netJitter = min(5, maxLiveTicOffset - minLiveTicOffset); + serverJitter = min(5, maxLiveTicOffset - minLiveTicOffset); - // Match tics + // Estimate the RTT (once used awkward tic matching stuff, now uses sneaky encoded angles) #ifndef ENCODE_TICCMD_TIMES if (!(gametic % 35)) { @@ -5731,7 +5755,7 @@ void DetermineNetConditions() } } #else - for (int j = 1; j < TICCMD_TIME_SIZE; j++) + for (int j = 1; j < TICCMD_TIME_SIZE - 1; j++) { if (CompareTiccmd(&gameTicBuffer[gametic % BACKUPTICS][consoleplayer], &localTicBuffer[(liveTic - j + BACKUPTICS) % BACKUPTICS])) { @@ -5740,6 +5764,21 @@ void DetermineNetConditions() } } #endif + + // estimate RTT jitter + minRTT = INT_MAX; + maxRTT = INT_MIN; + + rttBuffer[rttBufferIndex] = estimatedRTT; + rttBufferIndex = (rttBufferIndex + 1) % rttBufferMax; + + for (int i = 0; i < rttBufferMax; i++) + { + minRTT = min(minRTT, rttBuffer[i]); + maxRTT = max(maxRTT, rttBuffer[i]); + } + + rttJitter = maxRTT - minRTT; } static void PerformDebugRewinds() @@ -5796,31 +5835,61 @@ void MakeNetDebugString() { netDebugText[0] = 0; - for (int i = 10; i >= 0; i--) + for (int i = min(maxRTT + 4, 16); i >= 0; i--) { - if ((tic_t)i >= simtic - gametic) { + if (simtic - (tic_t)i <= gametic) { + char missed[2] = "+"; + + if (DecodeTiccmdTime(&(gameTicBuffer[(simtic - i) % BACKUPTICS][consoleplayer])) != + (DecodeTiccmdTime(&(gameTicBuffer[(simtic - i - 1) % BACKUPTICS][consoleplayer])) + 1) % TICCMD_TIME_SIZE) + missed[0] = 'X'; // missed tic + // show tics and matches sprintf(&netDebugText[strlen(netDebugText)], - "srv: %02d%slcl: %02d%s\n", - DecodeTiccmdTime(&(gameTicBuffer[(gametic - i) % BACKUPTICS][consoleplayer])), - (i == gametic ? "<" : " "), - (liveTic - i) & (TICCMD_TIME_SIZE-1), - (i == estimatedRTT ? "<" : " ")); + "%s srv: %02d%slcl: %02d%s\n", + missed, + DecodeTiccmdTime(&(gameTicBuffer[(simtic - i) % BACKUPTICS][consoleplayer])), + (i == gametic ? "<" : " "), + (liveTic - i) & (TICCMD_TIME_SIZE-1), + (i == estimatedRTT ? "<" : " ")); } else { sprintf(&netDebugText[strlen(netDebugText)], "____ %02d_lcl: %02d%s\n", 0, //(i == matchingGameTic ? "<" : " "), - (liveTic - i) & (TICCMD_TIME_SIZE - 1), + DecodeTiccmdTime(&localTicBuffer[(liveTic - i) % BACKUPTICS]), (i == estimatedRTT ? "<" : " ")); } } - sprintf(&netDebugText[strlen(netDebugText)], "\n\nJitter: %d", netJitter); - sprintf(&netDebugText[strlen(netDebugText)], "\nEstPing: %d", estimatedRTT); - sprintf(&netDebugText[strlen(netDebugText)], "\nSim-T: %d", simtic - gametic); + static tic_t lastSim = 0; + sprintf(&netDebugText[strlen(netDebugText)], "\n\nJitter: %d", serverJitter); + sprintf(&netDebugText[strlen(netDebugText)], "\nEstRTT: %d", estimatedRTT); + sprintf(&netDebugText[strlen(netDebugText)], "\nGame: %d", gametic); + sprintf(&netDebugText[strlen(netDebugText)], "\nSim: %d", simtic); + sprintf(&netDebugText[strlen(netDebugText)], "\nSim-Game: %d", simtic - gametic); + sprintf(&netDebugText[strlen(netDebugText)], "\nSimDelta: %d", simtic - lastSim); sprintf(&netDebugText[strlen(netDebugText)], "\nLive: %d", liveTic); + lastSim = simtic; + + unsigned int rtts[20] = { 0 }; + for (int i = 0; i < rttBufferMax; i++) + { + if (rttBuffer[i] < 20) + { + rtts[rttBuffer[i]]++; + } + } + + for (int i = 0; i < 20; i++) + { + if (rtts[i] > 0) + { + sprintf(&netDebugText[strlen(netDebugText)], "\nRTT %i: %i", i, rtts[i] * 100 / rttBufferMax); + } + } + /*sprintf(&netDebugText[strlen(netDebugText)], "\nSaveN/LoadN: %i/%i", numSaves, numLoads); for (int i = 1; i < 11; i++) diff --git a/src/d_main.c b/src/d_main.c index 39508a3a2..d9b3b4e38 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -729,10 +729,6 @@ void D_SRB2Loop(void) if (takescreenshot) // Only take screenshots after drawing. M_DoScreenShot(); } - else - { - CONS_Printf("Skip draw\n"); - } // consoleplayer -> displayplayers (hear sounds from viewpoint) S_UpdateSounds(); // move positional sounds diff --git a/src/d_netcmd.c b/src/d_netcmd.c index a7244f126..5c5dcba03 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -494,6 +494,9 @@ consvar_t cv_debugsimulaterewind = { "debugsimulaterewind", "0", 0, debugsimulat static CV_PossibleValue_t netsteadyplayers_cons_t[] = { {0, "MIN"}, {MAXSIMULATIONS - 1, "MAX"}, {0, NULL} }; consvar_t cv_netsteadyplayers = { "netsteadyplayers", "0", 0, netsteadyplayers_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +static CV_PossibleValue_t timefudge_cons_t[] = { {0, "MIN"}, {100, "MAX"}, {0, NULL} }; +consvar_t cv_timefudge = { "timefudge", "0", 0, timefudge_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; + char timedemo_name[256]; boolean timedemo_csv; char timedemo_csv_id[256]; @@ -656,6 +659,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_netspikes); CV_RegisterVar(&cv_netsteadyplayers); CV_RegisterVar(&cv_debugsimulaterewind); + CV_RegisterVar(&cv_timefudge); // for master server connection AddMServCommands(); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 6534d8e0b..3fa8477ea 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -156,6 +156,8 @@ extern consvar_t cv_netsmoothing; extern consvar_t cv_netspikes; extern consvar_t cv_netsteadyplayers; extern consvar_t cv_debugsimulaterewind; +extern consvar_t cv_timefudge; + extern consvar_t cv_skipmapcheck; extern consvar_t cv_sleep; diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index a34a7b726..60f9dba13 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2909,6 +2909,9 @@ static HMODULE winmm = NULL; static DWORD starttickcount = 0; // hack for win2k time bug static p_timeGetTime pfntimeGetTime = NULL; static LARGE_INTEGER basetime = { {0, 0} }; +static int lastTimeFudge; + +extern consvar_t cv_timefudge; // --------- // I_GetTime @@ -2917,18 +2920,38 @@ static LARGE_INTEGER basetime = { {0, 0} }; // but lower precision on Windows NT // --------- + tic_t I_GetTime(void) { tic_t newtics = 0; + // use this if High Resolution timer is found + static LARGE_INTEGER frequency; + + if (cv_timefudge.value != lastTimeFudge) + { + long long int hello = basetime.QuadPart; + long long int bye = starttickcount; + // fudge the timer to sync better with online games + if (frequency.QuadPart) + { + basetime.QuadPart = (basetime.QuadPart / (frequency.QuadPart / TICRATE) * (frequency.QuadPart / TICRATE)) -frequency.QuadPart * cv_timefudge.value / 100 / TICRATE; + basetime.QuadPart -= frequency.QuadPart / TICRATE; // never go back in time if timefudge reduces + } + if (starttickcount) + { + starttickcount = starttickcount / (1000 / TICRATE) * (1000 / TICRATE);// -cv_timefudge.value * 1000 / TICRATE / 100; + starttickcount -= 1000 / TICRATE; + } + + lastTimeFudge = cv_timefudge.value; + } + if (!starttickcount) // high precision timer { LARGE_INTEGER currtime; // use only LowPart if high resolution counter is not available - // use this if High Resolution timer is found - static LARGE_INTEGER frequency; - - if (!basetime.LowPart) + if (!basetime.QuadPart) { if (!QueryPerformanceFrequency(&frequency)) frequency.QuadPart = 0; From 6a4dc84a1fbf22ea41372be8850d746bab2079e3 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 20 Dec 2019 13:35:02 +0000 Subject: [PATCH 33/67] Committing this change as I'm about to dive into save/load code But I can't remember what this change did and whether it worked lol (probably an attempted bugfix for low-ping simulations breaking) #usefulcommitmessages --- src/d_clisrv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index dc44d9a9f..66f42f230 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5664,7 +5664,7 @@ static void RunSimulations() } // simulate the rest o da future - int numToSimulate = targetSimTic - simtic; + int numToSimulate = targetSimTic - (int)simtic; for (int i = 0; i < numToSimulate; i++) { // control other players (just use their previous control for now) @@ -5713,7 +5713,7 @@ static void RunSimulations() } } - if (simtic != targetSimTic) + if ((int)simtic < targetSimTic) { rendergametic = gametic; simtic = targetSimTic; From 178a59d3a1b29c65d96fed8ec50ab01143a625a1 Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 21 Dec 2019 01:17:52 +0000 Subject: [PATCH 34/67] Patched together some new save-load code, very messy, much faster though --- src/d_clisrv.c | 30 +- src/d_clisrv.h | 3 + src/p_saveg.c | 770 ++++++++++++++++++++++++++++++++++--------------- src/p_setup.c | 7 + 4 files changed, 552 insertions(+), 258 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 66f42f230..ba985b45c 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5441,10 +5441,8 @@ int maxRTT; int maxLiveTicOffset; int minLiveTicOffset; int smoothingDelay; -UINT64 saveTime = 0; -UINT64 loadTime = 0; -int numSaves = 0; -int numLoads = 0; +UINT64 saveStateBenchmark = 0; +UINT64 loadStateBenchmark = 0; boolean newSaveTic = false; boolean newLoadTic = false; @@ -5525,8 +5523,7 @@ void TryRunTics(tic_t realtics) P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); // invalidate previous states - for (int i = 0; i < BACKUPTICS; i++) - gameStateBufferIsValid[i] = false; + InvalidateSavestates(); } PerformDebugRewinds(); @@ -5723,6 +5720,12 @@ static void RunSimulations() con_muted = false; } +void InvalidateSavestates() +{ + for (int i = 0; i < MAXSIMULATIONS; i++) + gameStateBufferIsValid[i] = false; +} + int rttBuffer[70]; int rttBufferIndex = 0; int rttBufferMax = 70; @@ -5787,7 +5790,8 @@ static void PerformDebugRewinds() { P_LoadGameState(&gameStateBuffer[(gametic - rewindingTarget) % BACKUPTICS]); - for (int i = 0; i < rewindingTarget; i++) { + for (int i = 0; i < rewindingTarget; i++) + { netcmds[gametic%BACKUPTICS][consoleplayer] = gameTicBuffer[gametic - rewindingTarget + i % BACKUPTICS][consoleplayer]; G_Ticker(true); } @@ -5871,31 +5875,21 @@ void MakeNetDebugString() sprintf(&netDebugText[strlen(netDebugText)], "\nSim-Game: %d", simtic - gametic); sprintf(&netDebugText[strlen(netDebugText)], "\nSimDelta: %d", simtic - lastSim); sprintf(&netDebugText[strlen(netDebugText)], "\nLive: %d", liveTic); + sprintf(&netDebugText[strlen(netDebugText)], "\nTime save/load: %.2f/%.2f", (float)saveStateBenchmark/1000.0f, (float)loadStateBenchmark/1000.0f); lastSim = simtic; unsigned int rtts[20] = { 0 }; for (int i = 0; i < rttBufferMax; i++) { if (rttBuffer[i] < 20) - { rtts[rttBuffer[i]]++; - } } for (int i = 0; i < 20; i++) { if (rtts[i] > 0) - { sprintf(&netDebugText[strlen(netDebugText)], "\nRTT %i: %i", i, rtts[i] * 100 / rttBufferMax); - } } - - /*sprintf(&netDebugText[strlen(netDebugText)], "\nSaveN/LoadN: %i/%i", numSaves, numLoads); - - for (int i = 1; i < 11; i++) - { - sprintf(&netDebugText[strlen(netDebugText)], "\n[%i] %i/%i", i, saveTimes[i] - saveTimes[i - 1], loadTimes[i] - loadTimes[i - 1]); - }*/ } // startTic and endTics are tics going back in time from the current liveTic diff --git a/src/d_clisrv.h b/src/d_clisrv.h index c5e471a2b..347f49b65 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -592,6 +592,9 @@ void D_QuitNetGame(void); //? How many ticks to run? void TryRunTics(tic_t realtic); +// Invalidates save states used in simulations +void InvalidateSavestates(); + // extra data for lmps // these functions scare me. they contain magic. /*boolean AddLmpExtradata(UINT8 **demo_p, INT32 playernum); diff --git a/src/p_saveg.c b/src/p_saveg.c index 0d8d6efa8..ac60fd679 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -442,7 +442,259 @@ static void P_NetUnArchivePlayers(void) // SRB2kart players[i].kartspeed = READUINT8(save_p); players[i].kartweight = READUINT8(save_p); - // + } +} + +static void P_LocalArchivePlayers(void) +{ + int i; + + WRITEUINT32(save_p, ARCHIVEBLOCK_PLAYERS); + + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i]) + continue; + + WRITEMEM(save_p, &players[i], sizeof(player_t)); + } +} + +static void P_LocalUnArchivePlayers(void) +{ + int i; + + if (READUINT32(save_p) != ARCHIVEBLOCK_PLAYERS) + I_Error("Bad savestate at archive block Players"); + + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i]) + continue; + + READMEM(save_p, &players[i], sizeof(player_t)); + + players[i].capsule = NULL; + players[i].axis1 = NULL; + players[i].axis2 = NULL; + players[i].awayviewmobj = NULL; + players[i].followmobj = NULL; + players[i].drone = NULL; + } +} + +/// +/// Colormaps +/// + +static extracolormap_t *net_colormaps = NULL; +static UINT32 num_net_colormaps = 0; +static UINT32 num_ffloors = 0; // for loading + +// Copypasta from r_data.c AddColormapToList +// But also check for equality and return the matching index +static UINT32 CheckAddNetColormapToList(extracolormap_t *extra_colormap) +{ + extracolormap_t *exc, *exc_prev = NULL; + UINT32 i = 0; + + if (!net_colormaps) + { + net_colormaps = R_CopyColormap(extra_colormap, false); + net_colormaps->next = 0; + net_colormaps->prev = 0; + num_net_colormaps = i+1; + return i; + } + + for (exc = net_colormaps; exc; exc_prev = exc, exc = exc->next) + { + if (R_CheckEqualColormaps(exc, extra_colormap, true, true, true)) + return i; + i++; + } + + exc_prev->next = R_CopyColormap(extra_colormap, false); + extra_colormap->prev = exc_prev; + extra_colormap->next = 0; + + num_net_colormaps = i+1; + return i; +} + +static extracolormap_t *GetNetColormapFromList(UINT32 index) +{ + // For loading, we have to be tricky: + // We load the sectors BEFORE knowing the colormap values + // So if an index doesn't exist, fill our list with dummy colormaps + // until we get the index we want + // Then when we load the color data, we set up the dummy colormaps + + extracolormap_t *exc, *last_exc = NULL; + UINT32 i = 0; + + if (!net_colormaps) // initialize our list + net_colormaps = R_CreateDefaultColormap(false); + + for (exc = net_colormaps; exc; last_exc = exc, exc = exc->next) + { + if (i++ == index) + return exc; + } + + + // LET'S HOPE that index is a sane value, because we create up to [index] + // entries in net_colormaps. At this point, we don't know + // what the total colormap count is + if (index >= numsectors*3 + num_ffloors) + // if every sector had a unique colormap change AND a fade color thinker which has two colormap entries + // AND every ffloor had a fade FOF thinker with one colormap entry + I_Error("Colormap %d from server is too high for sectors %d", index, (UINT32)numsectors); + + // our index doesn't exist, so just make the entry + for (; i <= index; i++) + { + exc = R_CreateDefaultColormap(false); + if (last_exc) + last_exc->next = exc; + exc->prev = last_exc; + exc->next = NULL; + last_exc = exc; + } + return exc; +} + +static void ClearNetColormaps(void) +{ + // We're actually Z_Freeing each entry here, + // so don't call this in P_NetUnArchiveColormaps (where entries will be used in-game) + extracolormap_t *exc, *exc_next; + + for (exc = net_colormaps; exc; exc = exc_next) + { + exc_next = exc->next; + Z_Free(exc); + } + num_net_colormaps = 0; + num_ffloors = 0; + net_colormaps = NULL; +} + +static void P_NetArchiveColormaps(void) +{ + // We save and then we clean up our colormap mess + extracolormap_t *exc, *exc_next; + UINT32 i = 0; + WRITEUINT32(save_p, num_net_colormaps); // save for safety + + for (exc = net_colormaps; i < num_net_colormaps; i++, exc = exc_next) + { + // We must save num_net_colormaps worth of data + // So fill non-existent entries with default. + if (!exc) + exc = R_CreateDefaultColormap(false); + + WRITEUINT8(save_p, exc->fadestart); + WRITEUINT8(save_p, exc->fadeend); + WRITEUINT8(save_p, exc->fog); + + WRITEINT32(save_p, exc->rgba); + WRITEINT32(save_p, exc->fadergba); + +#ifdef EXTRACOLORMAPLUMPS + WRITESTRINGN(save_p, exc->lumpname, 9); +#endif + + exc_next = exc->next; + Z_Free(exc); // don't need anymore + } + + num_net_colormaps = 0; + num_ffloors = 0; + net_colormaps = NULL; +} + +static void P_NetUnArchiveColormaps(void) +{ + // When we reach this point, we already populated our list with + // dummy colormaps. Now that we are loading the color data, + // set up the dummies. + extracolormap_t *exc, *existing_exc, *exc_next = NULL; + UINT32 i = 0; + + num_net_colormaps = READUINT32(save_p); + + for (exc = net_colormaps; i < num_net_colormaps; i++, exc = exc_next) + { + UINT8 fadestart, fadeend, fog; + INT32 rgba, fadergba; +#ifdef EXTRACOLORMAPLUMPS + char lumpname[9]; +#endif + + fadestart = READUINT8(save_p); + fadeend = READUINT8(save_p); + fog = READUINT8(save_p); + + rgba = READINT32(save_p); + fadergba = READINT32(save_p); + +#ifdef EXTRACOLORMAPLUMPS + READSTRINGN(save_p, lumpname, 9); + + if (lumpname[0]) + { + if (!exc) + // no point making a new entry since nothing points to it, + // but we needed to read the data so now continue + continue; + + exc_next = exc->next; // this gets overwritten during our operations here, so get it now + existing_exc = R_ColormapForName(lumpname); + *exc = *existing_exc; + R_AddColormapToList(exc); // see HACK note below on why we're adding duplicates + continue; + } +#endif + + if (!exc) + // no point making a new entry since nothing points to it, + // but we needed to read the data so now continue + continue; + + exc_next = exc->next; // this gets overwritten during our operations here, so get it now + + exc->fadestart = fadestart; + exc->fadeend = fadeend; + exc->fog = fog; + + exc->rgba = rgba; + exc->fadergba = fadergba; + +#ifdef EXTRACOLORMAPLUMPS + exc->lump = LUMPERROR; + exc->lumpname[0] = 0; +#endif + + existing_exc = R_GetColormapFromListByValues(rgba, fadergba, fadestart, fadeend, fog); + + if (existing_exc) + exc->colormap = existing_exc->colormap; + else + // CONS_Debug(DBG_RENDER, "Creating Colormap: rgba(%d,%d,%d,%d) fadergba(%d,%d,%d,%d)\n", + // R_GetRgbaR(rgba), R_GetRgbaG(rgba), R_GetRgbaB(rgba), R_GetRgbaA(rgba), + // R_GetRgbaR(fadergba), R_GetRgbaG(fadergba), R_GetRgbaB(fadergba), R_GetRgbaA(fadergba)); + exc->colormap = R_CreateLightTable(exc); + + // HACK: If this dummy is a duplicate, we're going to add it + // to the extra_colormaps list anyway. I think this is faster + // than going through every loaded sector and correcting their + // colormap address to the pre-existing one, PER net_colormap entry + R_AddColormapToList(exc); + + if (i < num_net_colormaps-1 && !exc_next) + exc_next = R_CreateDefaultColormap(false); + } for (j = 0; j < MAXPREDICTTICS; j++) { @@ -616,10 +868,31 @@ static void P_LocalUnArchiveWorld(void) I_Error("Bad SaveState at archive block World"); } + // preserve certain local variables + sector_t* preservedSectors = Z_Malloc(numsectors * sizeof(sector_t), PU_CACHE, NULL); + + memcpy(preservedSectors, sectors, numsectors * sizeof(sector_t)); + UINT32 size = READUINT32(get); memcpy(sectors, get, numsectors * sizeof(sectors[0])); get += numsectors * sizeof(sectors[0]); + for (size_t i = 0; i < numsectors; i++) + { + sectors[i].thinglist = preservedSectors[i].thinglist; + sectors[i].touching_thinglist = preservedSectors[i].touching_thinglist; + sectors[i].preciplist = preservedSectors[i].preciplist; + sectors[i].touching_preciplist = preservedSectors[i].touching_preciplist; + + // restore preserved local stuff (tbh I don't really know what this is lol) + sectors[i].lightlist = preservedSectors[i].lightlist; + sectors[i].numlights = preservedSectors[i].numlights; + sectors[i].attached = preservedSectors[i].attached; + sectors[i].attachedsolid = preservedSectors[i].attachedsolid; + } + + Z_Free(preservedSectors); + save_p = get; } @@ -1063,7 +1336,7 @@ static void P_NetUnArchiveWorld(boolean preserveLevel) } // -// Thinkers // you're welcomers <3 +// Thinkers // you're welcomers // // @@ -1165,62 +1438,73 @@ typedef enum tc_end } specials_e; +typedef enum +{ + ST_FLOORDATA = 1, + ST_CEILDATA = 2, + ST_LIGHTDATA = 4, + ST_FADEMAPDATA = 8 +} sectortarget_e; + typedef struct { actionf_p1 action; UINT16 size; + UINT32 sectorPointer; + UINT8 sectorTargets; } specialdef_t; // special function/data size associations -#define A(x) (actionf_p1)x +#define NOSECTOR(func, type) (actionf_p1)func, sizeof(type), 0, 0 +#define WITHSECTOR(func, type, targets) (actionf_p1)func, sizeof(type), (UINT32)&((type*)NULL)->sector, targets static const specialdef_t specialDefs[] = { - A(P_MobjThinker), sizeof (mobj_t), // tc_mobj - A(T_MoveCeiling), sizeof(ceiling_t), // tc_ceiling - A(T_MoveFloor), sizeof (floormove_t), // tc_floor - A(T_LightningFlash), sizeof(lightflash_t), // tc_flash - A(T_StrobeFlash), sizeof(strobe_t), // tc_strobe - A(T_Glow), sizeof (glow_t), // tc_glow - A(T_FireFlicker), sizeof (fireflicker_t), // tc_fireflicker - A(T_ThwompSector), sizeof(levelspecthink_t), // tc_thwomp - A(T_CameraScanner), sizeof(elevator_t), // tc_camerascanner - A(T_MoveElevator), sizeof (elevator_t), // tc_elevator - A(T_ContinuousFalling), sizeof (levelspecthink_t), // tc_contunousfalling - A(T_BounceCheese), sizeof(levelspecthink_t), // tc_bouncecheese - A(T_StartCrumble), sizeof(elevator_t), // tc_startcrumble - A(T_MarioBlock), sizeof(levelspecthink_t), // tc_marioblock - A(T_MarioBlockChecker), sizeof(levelspecthink_t), // tc_marioblockchecker - A(T_SpikeSector), sizeof(levelspecthink_t), // tc_spikesector - A(T_FloatSector), sizeof(levelspecthink_t), // tc_floatsector - A(T_BridgeThinker), sizeof(levelspecthink_t), // tc_bridgethinker - A(T_CrushCeiling), sizeof(ceiling_t), // tc_crushceiling - A(T_Scroll), sizeof(scroll_t), // tc_scroll - A(T_Friction), sizeof(friction_t), // tc_friction - A(T_Pusher), sizeof(pusher_t), // tc_pusher - A(T_LaserFlash), sizeof(laserthink_t), // tc_laserflash - A(T_LightFade), sizeof(lightlevel_t), // tc_lightfade - A(T_ExecutorDelay), sizeof(executor_t), // tc_executor - A(T_RaiseSector), sizeof(levelspecthink_t), // tc_raisesector - A(T_NoEnemiesSector), sizeof(levelspecthink_t), // tc_noenemies - A(T_EachTimeThinker), sizeof(levelspecthink_t), // tc_eachtime - A(T_Disappear), sizeof (disappear_t), // tc_disappear - A(T_Fade), sizeof (fade_t), // tc_fade - A(T_FadeColormap), sizeof (fadecolormap_t), // tc_fade - A(T_PlaneDisplace), sizeof (planedisplace_t), // tc_planedisplace + NOSECTOR(P_MobjThinker, mobj_t), // tc_mobj + WITHSECTOR(T_MoveCeiling, ceiling_t, ST_CEILDATA), // tc_ceiling + WITHSECTOR(T_MoveFloor, floormove_t, ST_FLOORDATA), // tc_floor + WITHSECTOR(T_LightningFlash, lightflash_t, ST_LIGHTDATA), // tc_flash + WITHSECTOR(T_StrobeFlash, strobe_t, ST_LIGHTDATA), // tc_strobe + WITHSECTOR(T_Glow, glow_t, ST_LIGHTDATA), // tc_glow + WITHSECTOR(T_FireFlicker, fireflicker_t, ST_LIGHTDATA), // tc_fireflicker + WITHSECTOR(T_ThwompSector, levelspecthink_t, ST_FLOORDATA | ST_CEILDATA), // tc_thwomp + NOSECTOR(T_CameraScanner, elevator_t), // tc_camerascanner + WITHSECTOR(T_MoveElevator, elevator_t, ST_CEILDATA | ST_FLOORDATA), // tc_elevator + WITHSECTOR(T_MoveElevator, levelspecthink_t, ST_CEILDATA | ST_FLOORDATA), // tc_contunousfalling + WITHSECTOR(T_BounceCheese, levelspecthink_t, ST_CEILDATA), // tc_bouncecheese + WITHSECTOR(T_StartCrumble, elevator_t, ST_FLOORDATA), // tc_startcrumble + WITHSECTOR(T_MarioBlock, levelspecthink_t, ST_FLOORDATA | ST_CEILDATA), // tc_marioblock + NOSECTOR(T_MarioBlockChecker, levelspecthink_t), // tc_marioblockchecker + NOSECTOR(T_SpikeSector, levelspecthink_t), // tc_spikesector + NOSECTOR(T_FloatSector, levelspecthink_t), // tc_floatsector + WITHSECTOR(T_BridgeThinker, levelspecthink_t, ST_CEILDATA | ST_FLOORDATA), // tc_bridgethinker + WITHSECTOR(T_CrushCeiling, ceiling_t, ST_CEILDATA), // tc_crushceiling + NOSECTOR(T_Scroll, scroll_t), // tc_scroll + NOSECTOR(T_Friction, friction_t), // tc_friction + NOSECTOR(T_Pusher, pusher_t), // tc_pusher + NOSECTOR(T_LaserFlash, laserthink_t), // tc_laserflash + WITHSECTOR(T_LightFade, lightlevel_t, ST_LIGHTDATA), // tc_lightfade + NOSECTOR(T_ExecutorDelay, executor_t), // tc_executor + NOSECTOR(T_RaiseSector, levelspecthink_t), // tc_raisesector + NOSECTOR(T_NoEnemiesSector, levelspecthink_t), // tc_noenemies + NOSECTOR(T_EachTimeThinker, levelspecthink_t), // tc_eachtime + NOSECTOR(T_Disappear, disappear_t), // tc_disappear + NOSECTOR(T_Fade, fade_t), // tc_fade + WITHSECTOR(T_FadeColormap, fadecolormap_t, ST_FADEMAPDATA), // tc_fade + NOSECTOR(T_PlaneDisplace, planedisplace_t), // tc_planedisplace #ifdef ESLOPE - A(T_DynamicSlopeLine), sizeof(dynplanethink_t), // tc_dynslopeline - A(T_DynamicSlopeVert), sizeof(dynplanethink_t), // tc_dynslopevert + NOSECTOR(T_DynamicSlopeLine, dynplanethink_t), // tc_dynslopeline + NOSECTOR(T_DynamicSlopeVert, dynplanethink_t), // tc_dynslopevert #endif #ifdef POLYOBJECTS - A(T_PolyObjRotate), sizeof (polyrotate_t), // tc_polyrotate - A(T_PolyObjMove), sizeof (polymove_t), // tc_polymove - A(T_PolyObjWaypoint), sizeof (polywaypoint_t), // tc_polywaypoint - A(T_PolyDoorSlide), sizeof (polyslidedoor_t), // tc_polyslidedoor - A(T_PolyDoorSwing), sizeof (polyswingdoor_t), // tc_polyswingdoor - A(T_PolyObjFlag), sizeof (polymove_t), // tc_polyflag - A(T_PolyObjDisplace), sizeof (polydisplace_t), // tc_polydisplace - A(T_PolyObjRotDisplace), sizeof (polyrotdisplace_t), // tc_polyrotdisplace - A(T_PolyObjFade), sizeof (polyfade_t), // tc_polyfade + NOSECTOR(T_PolyObjRotate, polyrotate_t), // tc_polyrotate + NOSECTOR(T_PolyObjMove, polymove_t), // tc_polymove + NOSECTOR(T_PolyObjWaypoint, polywaypoint_t), // tc_polywaypoint + NOSECTOR(T_PolyDoorSlide, polyslidedoor_t), // tc_polyslidedoor + NOSECTOR(T_PolyDoorSwing, polyswingdoor_t), // tc_polyswingdoor + NOSECTOR(T_PolyObjFlag, polymove_t), // tc_polyflag + NOSECTOR(T_PolyObjDisplace, polydisplace_t), // tc_polydisplace + NOSECTOR(T_PolyObjRotDisplace, polyrotdisplace_t), // tc_polyrotdisplace + NOSECTOR(T_PolyObjFade, polyfade_t), // tc_polyfade #endif }; #undef A @@ -1915,6 +2199,7 @@ static void P_LocalArchiveThinkers(void) { int i, j; const thinker_t* thinker; + mobj_t* savedMobj; UINT8* original = save_p; WRITEUINT32(save_p, ARCHIVEBLOCK_THINKERS); @@ -1936,7 +2221,29 @@ static void P_LocalArchiveThinkers(void) WRITEUINT8(save_p, j); WRITEMEM(save_p, thinker, specialDefs[j].size); + + // relink saved pointers with saved mobjnums +#define RELINK(var) if (var != NULL) var = (mobj_t*)(var->mobjnum) + if (j == tc_mobj) + { + savedMobj = &((mobj_t*)save_p)[-1]; + RELINK(savedMobj->tracer); + RELINK(savedMobj->target); + RELINK(savedMobj->hnext); + RELINK(savedMobj->hprev); + + if (savedMobj->player) + { + RELINK(savedMobj->player->capsule); + RELINK(savedMobj->player->axis1); + RELINK(savedMobj->player->axis2); + RELINK(savedMobj->player->awayviewmobj); + RELINK(savedMobj->player->followmobj); + RELINK(savedMobj->player->drone); + } + } } +#undef RELINK WRITEUINT8(save_p, 0xFF); // next list (or end) } @@ -2948,7 +3255,7 @@ static void CollectDebugObjectList(void) { static void P_LocalUnArchiveThinkers() { thinker_t *thinker; - mobj_t* currentmobj; + mobj_t* mobj; UINT8 tclass; UINT8 restoreExecutors = false; INT32 i, j, list; @@ -2958,6 +3265,9 @@ static void P_LocalUnArchiveThinkers() static thinker_t* thinkersbytype[tc_end][16384]; static UINT8 thinkerlistbytype[tc_end][16384]; static int numthinkersbytype[tc_end]; + static mobj_t* mobjByNum[16384]; + + memset(mobjByNum, 0, sizeof(mobjByNum)); if (READUINT32(save_p) != ARCHIVEBLOCK_THINKERS) I_Error("Bad SaveState at archive block Thinkers"); @@ -2972,9 +3282,8 @@ static void P_LocalUnArchiveThinkers() } // sort objects by type - for (i = 0; i < tc_end; i++) { + for (i = 0; i < tc_end; i++) numthinkersbytype[i] = 0; - } for (i = 0; i < NUM_THINKERLISTS; i++) { @@ -3000,29 +3309,23 @@ static void P_LocalUnArchiveThinkers() iquetail = iquehead = 0; // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity - //for (i = 0; i < (int)numsectors; i++) - //{ - // sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = sectors[i].fadecolormapdata = NULL; - //} - - // clear flag references - redflag = NULL; - blueflag = NULL; - - CollectDebugObjectList(); + for (i = 0; i < (int)numsectors; i++) + sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = sectors[i].fadecolormapdata = NULL; // read in saved thinkers for (list = 0; list < NUM_THINKERLISTS; list++) { for (;;) { + msecnode_t* preserveTouchingSectorlist = NULL; + sector_t* preserveSubsector = NULL; + tclass = READUINT8(save_p); if (tclass == 0xFF) break; // next list thinker_t* newthinker = NULL; - thinker_t* oldthinker = NULL; if (numthinkersbytype[tclass] > 0) { @@ -3031,72 +3334,106 @@ static void P_LocalUnArchiveThinkers() UINT8 thinkerlist = thinkerlistbytype[tclass][j]; if (thinkerlist != list) - { continue; // don't replace something from a different list actually it doesn't matter lol - } + // we found an object to replace! newthinker = thinkersbytype[tclass][j]; - oldthinker = newthinker; numthinkersbytype[tclass]--; + if (tclass == tc_mobj) + { + P_UnsetThingPosition((mobj_t*)newthinker); + if (sector_list != NULL) { + P_DelSeclist(sector_list); + sector_list = NULL; + } + } + + // allocate it to the new object for (int k = j; k < numthinkersbytype[tclass]; k++) { thinkersbytype[tclass][k] = thinkersbytype[tclass][k + 1]; thinkerlistbytype[tclass][k] = thinkerlistbytype[tclass][k + 1]; } + + // unlink it from the old list + newthinker->prev->next = newthinker->next; + newthinker->next->prev = newthinker->prev; break; } } if (newthinker == NULL) { - // couldn't replace one, we gotta create it... + // we couldn't find an object to replace so we gotta create it if (tclass == tc_mobj) - { newthinker = Z_Calloc(specialDefs[tclass].size, PU_LEVEL, NULL); - } else - { newthinker = Z_Malloc(specialDefs[tclass].size, PU_LEVSPEC, NULL); - } } - if (oldthinker) - { - // remove it from the old list - oldthinker->prev->next = oldthinker->next; - oldthinker->next->prev = oldthinker->prev; - - if (tclass == tc_mobj) - P_UnsetThingPosition((mobj_t*)oldthinker); - } + // preserve vital positioning stuff (cleanup...) + mobj_t preserveMobj; + if (tclass == tc_mobj) + preserveMobj = *(mobj_t*)newthinker; // read in the data READMEM(save_p, newthinker, specialDefs[tclass].size); - // set special-specific info - if (tclass == tc_mobj) - { - mobj_t* mobj = (mobj_t*)newthinker; - if (mobj->type == MT_REDFLAG) - { - redflag = mobj; - rflagpoint = mobj->spawnpoint; - } + newthinker->references = 0; // we'll sort this later - if (mobj->type == MT_BLUEFLAG) + // set special-specific info + switch (tclass) + { + case tc_mobj: { - blueflag = mobj; - bflagpoint = mobj->spawnpoint; - } - - if (mobj->player && mobj->type == MT_PLAYER) - { - mobj->player->mo = mobj; + mobj_t* mobj = (mobj_t*)newthinker; + if (mobj->type == MT_REDFLAG) + { + redflag = mobj; + rflagpoint = mobj->spawnpoint; + } + + if (mobj->type == MT_BLUEFLAG) + { + blueflag = mobj; + bflagpoint = mobj->spawnpoint; + } + + if (mobj->player && mobj->type == MT_PLAYER) + mobj->player->mo = mobj; + + // clear sector links etc + mobj->bnext = NULL; + mobj->bprev = NULL; + mobj->snext = preserveMobj.snext; + mobj->sprev = preserveMobj.sprev; + mobj->subsector = preserveMobj.subsector; + mobj->touching_sectorlist = preserveMobj.touching_sectorlist; + mobjByNum[mobj->mobjnum] = mobj; + break; // i dream of a programming language where breaking is the default and fallthrough is the optional (and so much more rarely used) specifier } + case tc_executor: + restoreExecutors = true; + break; } - // relink into the list + // make special-specific sector connections + if (specialDefs[tclass].sectorTargets) + { + sector_t* target = *(sector_t**)((UINT8*)newthinker + specialDefs[tclass].sectorPointer); + + if (specialDefs[tclass].sectorTargets & ST_CEILDATA) + target->ceilingdata = newthinker; + if (specialDefs[tclass].sectorTargets & ST_FLOORDATA) + target->floordata = newthinker; + if (specialDefs[tclass].sectorTargets & ST_LIGHTDATA) + target->lightingdata = newthinker; + if (specialDefs[tclass].sectorTargets & ST_FADEMAPDATA) + target->fadecolormapdata = newthinker; + } + + // relink into the new thinker list newthinker->prev = newthinkers[list].prev; newthinker->next = &newthinkers[list]; newthinker->prev->next = newthinker; @@ -3107,8 +3444,6 @@ static void P_LocalUnArchiveThinkers() } } - CollectDebugObjectList(); - // delete everything remaining in the list that hasn't been linked for (i = 0; i < NUM_THINKERLISTS; i++) { @@ -3121,11 +3456,12 @@ static void P_LocalUnArchiveThinkers() thinker->references = 0; if (thinker->function.acp1 == (actionf_p1)P_MobjThinker) - P_RemoveSavegameMobj((mobj_t *)thinker, true); // item isn't saved, don't remove it + P_RemoveSavegameMobj((mobj_t *)thinker, true); else if (thinker->function.acp1 == (actionf_p1)P_NullPrecipThinker) - P_RemovePrecipMobj((precipmobj_t*)thinker); - else { - // remove it manually, bye! + P_RemovePrecipMobj((precipmobj_t*)thinker); // i bet this is gonna break :D + else + { + // we can remove this thinker manually, bye! thinker->prev->next = thinker->next; thinker->next->prev = thinker->prev; Z_Free(thinker); @@ -3140,25 +3476,49 @@ static void P_LocalUnArchiveThinkers() newthinkers[i].next->prev = &thlist[i]; } - CollectDebugObjectList(); - + // restore execution stuff I guess lol if (restoreExecutors) { executor_t *delay = NULL; UINT32 mobjnum; - for (thinker = thlist[THINK_MAIN].next; thinker != &thlist[THINK_MAIN]; - thinker = thinker->next) + for (thinker = thlist[THINK_MAIN].next; thinker != &thlist[THINK_MAIN]; thinker = thinker->next) { if (thinker->function.acp1 != (actionf_p1)T_ExecutorDelay) continue; delay = (void *)thinker; if (!(mobjnum = (UINT32)(size_t)delay->caller)) continue; - delay->caller = P_FindNewPosition(mobjnum); + delay->caller = mobjByNum[mobjnum]; } } - // restore skyboxes, if applicable + // restore pointers +#define RELINK(var) if (var) { UINT32 index = (UINT32)var; var = NULL; P_SetTarget(&var, mobjByNum[index]); } + for (thinker = thlist[THINK_MOBJ].next; thinker != &thlist[THINK_MOBJ]; thinker = thinker->next) + { + if (thinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mobj = (mobj_t*)thinker; + + RELINK(mobj->tracer); + RELINK(mobj->target); + RELINK(mobj->hnext); + RELINK(mobj->hprev); + + if (mobj->player) + { + RELINK(mobj->player->capsule); + RELINK(mobj->player->axis1); + RELINK(mobj->player->axis2); + RELINK(mobj->player->awayviewmobj); + RELINK(mobj->player->followmobj); + RELINK(mobj->player->drone); + } + } +#undef RELINK + + // restore skyboxes if applicable for (i = 0; i < sizeof(skyboxmo) / sizeof(skyboxmo[0]); i++) skyboxmo[i] = NULL; for (i = 0; i < sizeof(skyboxcenterpnts) / sizeof(skyboxcenterpnts[0]); i++) @@ -3167,18 +3527,14 @@ static void P_LocalUnArchiveThinkers() skyboxviewpnts[i] = NULL; } - for (currentmobj = (mobj_t*)thlist[THINK_MOBJ].next; currentmobj != (mobj_t*)&thlist[THINK_MOBJ]; currentmobj = (mobj_t*)currentmobj->thinker.next) + for (mobj = (mobj_t*)thlist[THINK_MOBJ].next; mobj != (mobj_t*)&thlist[THINK_MOBJ]; mobj = (mobj_t*)mobj->thinker.next) { - if (currentmobj->type == MT_SKYBOX) + if (mobj->type == MT_SKYBOX) { - if ((currentmobj->extravalue2 >> 16) == 1) - { - skyboxcenterpnts[currentmobj->extravalue2 & 0xFFFF] = currentmobj; - } + if ((mobj->extravalue2 >> 16) == 1) + skyboxcenterpnts[mobj->extravalue2 & 0xFFFF] = mobj; else - { - skyboxviewpnts[currentmobj->extravalue2 & 0xFFFF] = currentmobj; - } + skyboxviewpnts[mobj->extravalue2 & 0xFFFF] = mobj; } } @@ -3215,9 +3571,6 @@ static void P_NetUnArchiveThinkers(boolean preserveLevel) } */ - // providing debug lists for frustrated programmer - CollectDebugObjectList(); - // remove all the current thinkers for (i = 0; i < NUM_THINKERLISTS; i++) { @@ -3429,9 +3782,6 @@ static void P_NetUnArchiveThinkers(boolean preserveLevel) P_AddThinker(thinkerlist, th); } - CONS_Debug(DBG_NETPLAY, "%u thinkers loaded in list %d\n", numloaded, i); - CollectDebugObjectList(); - if (restoreNum) { executor_t *delay = NULL; @@ -4086,75 +4436,6 @@ void P_SaveNetGame(void) WRITEUINT8(save_p, 0x1d); // consistency marker } -void P_SaveGameState(savestate_t* savestate) -{ - if (newSaveTic) - { - saveTime = 0; - numSaves = 0; - } - - UINT64 time = I_GetTimeUs(); - - save_p = savestate->buffer; - P_SaveNetGame(); - return; - - WRITEUINT32(save_p, globalmobjnum); - - P_LocalArchiveThinkers(); - return; - - thinker_t *th; - mobj_t *mobj; - INT32 i = 1; // don't start from 0, it'd be confused with a blank pointer otherwise - - CV_SaveNetVars(&save_p); - - saveTimes[0] = I_GetTimeUs(); - P_NetArchiveMisc(); - saveTimes[1] = I_GetTimeUs(); - - // Assign the mobjnumber for pointer tracking - for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) - { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - - mobj = (mobj_t *)th; - if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) - continue; - mobj->mobjnum = i++; - } - - P_NetArchivePlayers(); - saveTimes[2] = I_GetTimeUs(); - if (gamestate == GS_LEVEL) - { - P_NetArchiveWorld(); - saveTimes[3] = I_GetTimeUs(); -#ifdef POLYOBJECTS - P_ArchivePolyObjects(); - saveTimes[4] = I_GetTimeUs(); -#endif - P_LocalArchiveThinkers(); - //P_NetArchiveThinkers(); - saveTimes[5] = I_GetTimeUs(); - P_NetArchiveSpecials(); - saveTimes[6] = I_GetTimeUs(); - } -#ifdef HAVE_BLUA - saveTimes[8] = saveTimes[9] = 0; - LUA_Archive(); - saveTimes[10] = I_GetTimeUs(); -#endif - - P_ArchiveLuabanksAndConsistency(); - - saveTime += I_GetTimeUs() - time; - numSaves++; -} - boolean P_LoadGame(INT16 mapoverride) { if (gamestate == GS_INTERMISSION) @@ -4221,77 +4502,86 @@ boolean P_LoadNetGame(boolean preserveLevel) return READUINT8(save_p) == 0x1d; } -boolean P_LoadGameState(const savestate_t* savestate) +extern UINT64 saveStateBenchmark; +extern UINT64 loadStateBenchmark; + +// P_SaveGameState is a within-level-only mechanism for saving the game state. It must not be used cross level. Used for simulation backtracking. +// It uses a mixture of existing NetArchive functions and faster LocalArchive functions to do the job +void P_SaveGameState(savestate_t* savestate) { - if (newLoadTic) + mobj_t* mobj; + thinker_t* th; + int i = 0; + + UINT64 time = I_GetTimeUs(); + + save_p = savestate->buffer; + + WRITEUINT32(save_p, globalmobjnum); + + CV_SaveNetVars(&save_p); + + // assign mobj nums for pointer relinking + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - loadTime = 0; - numLoads = 0; + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mobj = (mobj_t *)th; + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; + mobj->mobjnum = i++; } + P_NetArchiveMisc(); + P_LocalArchivePlayers(); + P_NetArchiveSpecials(); + P_LocalArchiveWorld(); +#ifdef POLYOBJECTS + P_ArchivePolyObjects(); +#endif + P_LocalArchiveThinkers(); +#ifdef HAVE_BLUA + LUA_Archive(); +#endif + + P_ArchiveLuabanksAndConsistency(); + + saveStateBenchmark = I_GetTimeUs() - time; +} + +// P_LoadGameState is a within-level-only mechanism for loading the game state. It must not be used cross level. Used for simulation backtracking. +// It uses a mixture of existing NetUnArchive functions and faster LocalUnArchive functions to do the job +boolean P_LoadGameState(const savestate_t* savestate) +{ UINT64 time = I_GetTimeUs(); angle_t preserveAngle = localangle; INT32 preserveAiming = localaiming; - + save_p = ((unsigned char*)savestate->buffer); - P_LoadNetGame(true); - - localangle = preserveAngle; - localaiming = preserveAiming; - - return true; globalmobjnum = READUINT32(save_p); - P_LocalUnArchiveThinkers(); - return true; - CV_LoadNetVars(&save_p); - loadTimes[0] = I_GetTimeUs(); - if (!P_NetUnArchiveMisc(true)) - return false; - loadTimes[1] = I_GetTimeUs(); - P_NetUnArchivePlayers(); - loadTimes[2] = I_GetTimeUs(); - if (gamestate == GS_LEVEL) - { - P_NetUnArchiveWorld(true); - loadTimes[3] = I_GetTimeUs(); + P_NetUnArchiveMisc(true); + P_LocalUnArchivePlayers(); + P_NetUnArchiveSpecials(); + P_LocalUnArchiveWorld(); #ifdef POLYOBJECTS - P_UnArchivePolyObjects(); - loadTimes[4] = I_GetTimeUs(); + P_UnArchivePolyObjects(); #endif - P_NetUnArchiveThinkers(true); - loadTimes[5] = I_GetTimeUs(); - P_NetUnArchiveSpecials(); - loadTimes[6] = I_GetTimeUs(); - P_NetUnArchiveColormaps(); - loadTimes[7] = I_GetTimeUs(); - P_RelinkPointers(); - loadTimes[8] = I_GetTimeUs(); - P_FinishMobjs(); - loadTimes[9] = I_GetTimeUs(); - } + P_LocalUnArchiveThinkers(); + #ifdef HAVE_BLUA LUA_UnArchive(); - loadTimes[10] = I_GetTimeUs(); #endif - // This is stupid and hacky, but maybe it'll work! + // This is stupid and hacky _squared_, but it's in the net load code and it says it might work, so I guess it might work! P_SetRandSeed(P_GetInitSeed()); - // The precipitation would normally be spawned in P_SetupLevel, which is called by - // P_NetUnArchiveMisc above. However, that would place it up before P_NetUnArchiveThinkers, - // so the thinkers would be deleted later. Therefore, P_SetupLevel will *not* spawn - // precipitation when loading a netgame save. Instead, precip has to be spawned here. - // This is done in P_NetUnArchiveSpecials now. - P_UnArchiveLuabanksAndConsistency(); - - loadTime += I_GetTimeUs() - time; - numLoads++; - + loadStateBenchmark = I_GetTimeUs() - time; return true; } \ No newline at end of file diff --git a/src/p_setup.c b/src/p_setup.c index 2332261aa..dff5fa805 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2788,6 +2788,13 @@ boolean P_SetupLevel(boolean skipprecip) CON_Drawer(); // let the user know what we are going to do I_FinishUpdate(); // page flip or blit buffer + // Reset the palette + if (rendermode != render_none) + V_SetPaletteLump("PLAYPAL"); + + // Invalidate simulation save states + InvalidateSavestates(); + // Initialize sector node list. P_Initsecnode(); From 961e08ab756717ab76502d25f1fb894b004be7f3 Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 21 Dec 2019 04:02:18 +0000 Subject: [PATCH 35/67] Added quick and dirty auto time fudge finger! Smooth gameplay here we come! --- src/d_clisrv.c | 211 ++++++++++++++++++++++++++++++--------------- src/d_clisrv.h | 16 ++++ src/d_netcmd.c | 12 +++ src/p_saveg.c | 25 +++--- src/sdl/i_system.c | 38 ++++---- 5 files changed, 202 insertions(+), 100 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ba985b45c..076d033aa 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -152,14 +152,11 @@ boolean gameStateBufferIsValid[BACKUPTICS]; ticcmd_t gameTicBuffer[BACKUPTICS][MAXPLAYERS]; ticcmd_t localTicBuffer[BACKUPTICS]; +boolean issimulation = false; + boolean rewindingWow = false; int rewindingTarget = 0; -typedef struct -{ - // stores historical simulated positions where 0 is the real game position and simtic-gametic is the latest simulated position - fixed_t histx[MAXSIMULATIONS+1], histy[MAXSIMULATIONS+1], histz[MAXSIMULATIONS+1]; -} steadyplayer_t; steadyplayer_t steadyplayers[MAXPLAYERS]; void EncodeTiccmdTime(ticcmd_t* ticcmd, tic_t time); @@ -5446,6 +5443,15 @@ UINT64 loadStateBenchmark = 0; boolean newSaveTic = false; boolean newLoadTic = false; +#define MAXAUTOFUDGERTT 20 + +boolean autotimefudge = true; +UINT8 autotimefudgetime = 0; +UINT16 autotimefudgesamples = 0; +UINT16 autotimefudgedata[MAXAUTOFUDGERTT]; +float autotimefudgemeans[10]; +float autotimefudgedeviations[10]; + #define MAXOFFSETHISTORY 35 int ticTimeOffsetHistory[MAXOFFSETHISTORY]; @@ -5608,10 +5614,10 @@ void TryRunTics(tic_t realtics) static void RunSimulations() { + if (!gameStateBufferIsValid[gametic % BACKUPTICS]) + return; // do not simulate if we cannot guarantee a recovery + boolean preserveSoundDisabled = sound_disabled; - - sound_disabled = true; - con_muted = true; // this must be done after smoothedTic is set DetermineNetConditions(); @@ -5621,13 +5627,9 @@ static void RunSimulations() for (int j = 0; j < 2; j++) { if (CompareTiccmd(&gameTicBuffer[gametic % BACKUPTICS][consoleplayer], &gameTicBuffer[(gametic - j) % BACKUPTICS][consoleplayer])) - { tastyFudge++; - } else - { break; - } } int targetSimTic = min(gametic + estimatedRTT - tastyFudge, smoothedTic + cv_simulatetics.value); @@ -5636,88 +5638,88 @@ static void RunSimulations() if (targetSimTic - simtic > MAXSIMULATIONS) simtic = targetSimTic - MAXSIMULATIONS; - // if steady players is enabled, record their real game position and their simulated position - if (cv_netsteadyplayers.value) + // record steadyplayers' real game position and their simulated position + for (int i = 0; i < MAXPLAYERS; i++) { - for (int i = 0; i < MAXPLAYERS; i++) + if (playeringame[i] && players[i].mo && i != consoleplayer) { - if (playeringame[i] && players[i].mo && i != consoleplayer) + if (simtic == smoothedTic) // this is their real position { - if (simtic == smoothedTic) // this is their real position - { - steadyplayers[i].histx[0] = players[i].mo->x; - steadyplayers[i].histy[0] = players[i].mo->y; - steadyplayers[i].histz[0] = players[i].mo->z; - } - else - { - // restore the players' simulated position before simulating more - players[i].mo->x = steadyplayers[i].histx[simtic-smoothedTic]; - players[i].mo->y = steadyplayers[i].histy[simtic-smoothedTic]; - players[i].mo->z = steadyplayers[i].histz[simtic-smoothedTic]; - } + steadyplayers[i].histx[0] = players[i].mo->x; + steadyplayers[i].histy[0] = players[i].mo->y; + steadyplayers[i].histz[0] = players[i].mo->z; + } + else + { + // restore the players' simulated position before simulating more + players[i].mo->x = steadyplayers[i].histx[simtic-smoothedTic]; + players[i].mo->y = steadyplayers[i].histy[simtic-smoothedTic]; + players[i].mo->z = steadyplayers[i].histz[simtic-smoothedTic]; } } } // simulate the rest o da future int numToSimulate = targetSimTic - (int)simtic; + + issimulation = true; + sound_disabled = true; + con_muted = true; + for (int i = 0; i < numToSimulate; i++) { // control other players (just use their previous control for now) for (int j = 0; j < MAXPLAYERS; j++) { if (playeringame[j] && j != consoleplayer) - netcmds[gametic % BACKUPTICS][j] = gameTicBuffer[(min(smoothedTic + i + 1, gametic) + BACKUPTICS) % BACKUPTICS][j]; + netcmds[gametic % BACKUPTICS][j] = gameTicBuffer[(min(simtic + 1, gametic) + BACKUPTICS) % BACKUPTICS][j]; } // control the local player if (simtic + i < gametic) // game is smoothed, take tics from the _actual_ received state - netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(simtic + i + 1) % BACKUPTICS][consoleplayer]; + netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(simtic + 1) % BACKUPTICS][consoleplayer]; else netcmds[gametic % BACKUPTICS][consoleplayer] = localTicBuffer[(liveTic - estimatedRTT + i + 1 + BACKUPTICS) % BACKUPTICS]; G_Ticker(true); // tic a bunch of times lol see what happens lolol + simtic++; // record simulated players' positions - if (cv_netsteadyplayers.value) - { - for (int j = 0; j < MAXPLAYERS; j++) - { - if (playeringame[j] && players[j].mo && j != consoleplayer) - { - // Update steadyplayers' simulated positions and move their game positions to their known one - steadyplayers[j].histx[simtic - smoothedTic + i + 1] = players[j].mo->x; - steadyplayers[j].histy[simtic - smoothedTic + i + 1] = players[j].mo->y; - steadyplayers[j].histz[simtic - smoothedTic + i + 1] = players[j].mo->z; - } - } - } - } - - if (cv_netsteadyplayers.value) - { - int histIndex = max((int)(targetSimTic - smoothedTic) - cv_netsteadyplayers.value, 0); // up to cv_netsteadyplayers.value behind the simulation for (int j = 0; j < MAXPLAYERS; j++) { if (playeringame[j] && players[j].mo && j != consoleplayer) { - // Set the player's positions to the last known real game position - players[j].mo->x = steadyplayers[j].histx[histIndex]; - players[j].mo->y = steadyplayers[j].histy[histIndex]; - players[j].mo->z = steadyplayers[j].histz[histIndex]; + // Update steadyplayers' simulated positions and move their game positions to their known one + steadyplayers[j].histx[simtic - smoothedTic + 1] = players[j].mo->x; + steadyplayers[j].histy[simtic - smoothedTic + 1] = players[j].mo->y; + steadyplayers[j].histz[simtic - smoothedTic + 1] = players[j].mo->z; } } } - if ((int)simtic < targetSimTic) - { - rendergametic = gametic; - simtic = targetSimTic; - } - + issimulation = false; sound_disabled = preserveSoundDisabled; con_muted = false; + + // Finalise steadyplayers + int histIndex = max((int)(simtic - smoothedTic) - cv_netsteadyplayers.value, 0); // up to cv_netsteadyplayers.value behind the simulation + for (int j = 0; j < MAXPLAYERS; j++) + { + if (playeringame[j] && players[j].mo && j != consoleplayer) + { + // Record the final simulated position and error + steadyplayers[j].finalx = players[j].mo->x; + steadyplayers[j].finaly = players[j].mo->y; + steadyplayers[j].finalz = players[j].mo->z; + + // Set the player's positions to the preferred simulation index (or perhaps just their original position) + players[j].mo->x = steadyplayers[j].histx[histIndex]; + players[j].mo->y = steadyplayers[j].histy[histIndex]; + players[j].mo->z = steadyplayers[j].histz[histIndex]; + } + } + + rendergametic = gametic; } void InvalidateSavestates() @@ -5782,6 +5784,78 @@ void DetermineNetConditions() } rttJitter = maxRTT - minRTT; + + // auto time fudge + int maxautotimefudgesamples = 25; + static int numignoredtimefudgesamples = 5; + if (autotimefudge) + { + CV_SetValue(&cv_timefudge, autotimefudgetime); + + if (estimatedRTT < MAXAUTOFUDGERTT) + { + if (numignoredtimefudgesamples > 0) + numignoredtimefudgesamples--; + else + { + autotimefudgedata[estimatedRTT]++; + autotimefudgesamples++; + } + } + + if (autotimefudgesamples > maxautotimefudgesamples) + { + // calculate standard deviation of this time fudge + float mean = 0; + for (int i = 0; i < MAXAUTOFUDGERTT; i++) + { + mean += autotimefudgedata[i] * i; + } + mean /= maxautotimefudgesamples; + + float differences = 0; + for (int i = 0; i < MAXAUTOFUDGERTT; i++) + { + if (autotimefudgedata[i] > 0) + differences += ((i - mean) * (i - mean)) * autotimefudgedata[i]; + } + differences /= maxautotimefudgesamples; + + autotimefudgemeans[autotimefudgetime / 10] = mean; + autotimefudgedeviations[autotimefudgetime / 10] = differences; + + CONS_Printf("Fudge %d tested: mean %f deviation %f\n", autotimefudgetime, mean, differences); + + // reset and test the next time fudge + autotimefudgetime = (autotimefudgetime + 10) % 100; + autotimefudgesamples = 0; + numignoredtimefudgesamples = maxRTT + 2; + + for (int i = 0; i < MAXAUTOFUDGERTT; i++) + autotimefudgedata[i] = 0; + + if (autotimefudgetime == 0) + { + // best time is where the deviation is minimal; this can be achieved by going halfway from the worst point + int worstFudgeTime = 0; + float worstDeviation = 0.0f; + + for (int i = 0; i < 10; i++) + { + if (autotimefudgedeviations[i] > worstDeviation) + { + worstDeviation = autotimefudgedeviations[i]; + worstFudgeTime = i * 10; + } + } + + CONS_Printf("Auto timefudge: Setting time fudge to %d\n", (worstFudgeTime + 50) % 100); + autotimefudge = false; + + CV_SetValue(&cv_timefudge, (worstFudgeTime + 50) % 100); + } + } + } } static void PerformDebugRewinds() @@ -5792,13 +5866,11 @@ static void PerformDebugRewinds() for (int i = 0; i < rewindingTarget; i++) { - netcmds[gametic%BACKUPTICS][consoleplayer] = gameTicBuffer[gametic - rewindingTarget + i % BACKUPTICS][consoleplayer]; + netcmds[gametic%BACKUPTICS][consoleplayer] = gameTicBuffer[(gametic - rewindingTarget + i) % BACKUPTICS][consoleplayer]; G_Ticker(true); } rewindingWow = false; - - CONS_Printf("Rewinding\n"); } if (gameStateBufferIsValid[gametic % BACKUPTICS] && cv_debugsimulaterewind.value > 0 && players[consoleplayer].mo) { @@ -5812,18 +5884,19 @@ static void PerformDebugRewinds() spawnpoint = *(redflag->spawnpoint); } - for (int i = 0; i < cv_debugsimulaterewind.value; i++) { + short consis = Consistancy(); + + for (int i = 0; i < cv_debugsimulaterewind.value; i++) G_Ticker(true); - } P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); - - if (redflag) { + + if (Consistancy() != consis) + CONS_Printf("General consistency error...\n"); + + if (redflag) if (redflag->spawnpoint->x + redflag->spawnpoint->y + redflag->spawnpoint->z != xyz && xyz != 0) - { CONS_Printf("Flag consistency error!\n"); - } - } /*sector_t current = *((elevator_t*)thlist[1].next)->sector; mobj_t currentPlayer = *players[consoleplayer].mo;*/ diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 347f49b65..ef712d315 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -533,6 +533,19 @@ typedef enum } kickreason_t; +// Player movement histories for simulated gamestates +typedef struct +{ + // stores historical simulated positions where 0 is the real game position and simtic-gametic is the latest simulated position + fixed_t histx[MAXSIMULATIONS + 1], histy[MAXSIMULATIONS + 1], histz[MAXSIMULATIONS + 1]; + + // stores the final simulated position for each simulated gametic + fixed_t finalx, finaly, finalz; + + // difference between the position we simulated to during this update compared to the last one + fixed_t error; +} steadyplayer_t; + extern boolean server; #define client (!server) extern boolean dedicated; // For dedicated server @@ -541,6 +554,9 @@ extern boolean acceptnewnode; extern SINT8 servernode; extern char connectedservername[MAXSERVERNAME]; +extern boolean issimulation; // whether the currently executed tic is part of a simulated gamestate +extern steadyplayer_t steadyplayers[MAXPLAYERS]; + void Command_Ping_f(void); extern tic_t connectiontimeout; extern tic_t jointimeout; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 5c5dcba03..ed6580b82 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -120,6 +120,7 @@ static void Command_Savestate(void); static void Command_Loadstate(void); static void Command_Rewind(void); static void Command_Saveloadtest(void); +static void Command_Autotimefudge(void); #ifdef NETGAME_DEVMODE static void Fishcake_OnChange(void); @@ -650,6 +651,7 @@ void D_RegisterServerCommands(void) COM_AddCommand("loadstate", Command_Loadstate); COM_AddCommand("rewind", Command_Rewind); COM_AddCommand("saveloadtest", Command_Saveloadtest); + COM_AddCommand("autotimefudge", Command_Autotimefudge); CV_RegisterVar(&cv_simulate); CV_RegisterVar(&cv_simulatetics); @@ -837,6 +839,16 @@ static void Command_Saveloadtest(void) memleak = false; } +extern boolean autotimefudge; +static void Command_Autotimefudge(void) +{ + if (!autotimefudge) + { + CONS_Printf("Searching for the best time fudge...\n"); + autotimefudge = true; + } +} + // ========================================================================= // CLIENT STARTUP // ========================================================================= diff --git a/src/p_saveg.c b/src/p_saveg.c index ac60fd679..34294d183 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -847,15 +847,12 @@ static void P_LocalArchiveWorld(void) put = save_p; WRITEUINT32(put, numsectors * sizeof(sectors[0])); + WRITEUINT32(put, numlines * sizeof(lines[0])); // dump all sector memory into the data - memcpy(put, sectors, numsectors * sizeof(sectors[0])); - put += numsectors * sizeof(sectors[0]); + WRITEMEM(put, sectors, numsectors * sizeof(sectors[0])); + WRITEMEM(put, lines, numlines * sizeof(lines[0])); - // there will be probably be code here that corrects all the broken pointers and stuff eventually - // once the programmer realises that everything's screwed during the next playtest ;) - - UINT32 wow = put - save_p; save_p = put; } @@ -873,9 +870,10 @@ static void P_LocalUnArchiveWorld(void) memcpy(preservedSectors, sectors, numsectors * sizeof(sector_t)); - UINT32 size = READUINT32(get); - memcpy(sectors, get, numsectors * sizeof(sectors[0])); - get += numsectors * sizeof(sectors[0]); + UINT32 sectorSize = READUINT32(get); + UINT32 lineSize = READUINT32(get); + READMEM(get, sectors, numsectors * sizeof(sectors[0])); + READMEM(get, lines, numlines * sizeof(lines[0])); for (size_t i = 0; i < numsectors; i++) { @@ -3252,6 +3250,8 @@ static void CollectDebugObjectList(void) { } } +void S_DetachChannelsFromOrigin(void* origin); + static void P_LocalUnArchiveThinkers() { thinker_t *thinker; @@ -3349,6 +3349,9 @@ static void P_LocalUnArchiveThinkers() } } + // detach any playing sounds from this object if we can (still need to work on doing this properly!) + S_DetachChannelsFromOrigin((mobj_t*)newthinker); + // allocate it to the new object for (int k = j; k < numthinkersbytype[tclass]; k++) { @@ -4535,12 +4538,12 @@ void P_SaveGameState(savestate_t* savestate) P_NetArchiveMisc(); P_LocalArchivePlayers(); - P_NetArchiveSpecials(); P_LocalArchiveWorld(); #ifdef POLYOBJECTS P_ArchivePolyObjects(); #endif P_LocalArchiveThinkers(); + P_NetArchiveSpecials(); #ifdef HAVE_BLUA LUA_Archive(); #endif @@ -4566,12 +4569,12 @@ boolean P_LoadGameState(const savestate_t* savestate) P_NetUnArchiveMisc(true); P_LocalUnArchivePlayers(); - P_NetUnArchiveSpecials(); P_LocalUnArchiveWorld(); #ifdef POLYOBJECTS P_UnArchivePolyObjects(); #endif P_LocalUnArchiveThinkers(); + P_NetUnArchiveSpecials(); #ifdef HAVE_BLUA LUA_UnArchive(); diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 60f9dba13..11dd06fe1 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2909,7 +2909,7 @@ static HMODULE winmm = NULL; static DWORD starttickcount = 0; // hack for win2k time bug static p_timeGetTime pfntimeGetTime = NULL; static LARGE_INTEGER basetime = { {0, 0} }; -static int lastTimeFudge; +static int lastTimeFudge = -1; extern consvar_t cv_timefudge; @@ -2928,25 +2928,6 @@ tic_t I_GetTime(void) // use this if High Resolution timer is found static LARGE_INTEGER frequency; - if (cv_timefudge.value != lastTimeFudge) - { - long long int hello = basetime.QuadPart; - long long int bye = starttickcount; - // fudge the timer to sync better with online games - if (frequency.QuadPart) - { - basetime.QuadPart = (basetime.QuadPart / (frequency.QuadPart / TICRATE) * (frequency.QuadPart / TICRATE)) -frequency.QuadPart * cv_timefudge.value / 100 / TICRATE; - basetime.QuadPart -= frequency.QuadPart / TICRATE; // never go back in time if timefudge reduces - } - if (starttickcount) - { - starttickcount = starttickcount / (1000 / TICRATE) * (1000 / TICRATE);// -cv_timefudge.value * 1000 / TICRATE / 100; - starttickcount -= 1000 / TICRATE; - } - - lastTimeFudge = cv_timefudge.value; - } - if (!starttickcount) // high precision timer { LARGE_INTEGER currtime; // use only LowPart if high resolution counter is not available @@ -2975,6 +2956,23 @@ tic_t I_GetTime(void) else newtics = (GetTickCount() - starttickcount)/(1000/NEWTICRATE); + // fudge the timer to sync better with online games + if (cv_timefudge.value != lastTimeFudge) + { + if (frequency.QuadPart) + { + basetime.QuadPart = (basetime.QuadPart / (frequency.QuadPart / TICRATE) * (frequency.QuadPart / TICRATE)) - frequency.QuadPart * cv_timefudge.value / 100 / TICRATE; + basetime.QuadPart -= frequency.QuadPart / TICRATE; // never go back in time if timefudge reduces + } + if (starttickcount) + { + starttickcount = (starttickcount / (1000 / TICRATE) * (1000 / TICRATE)) - 1000 * cv_timefudge.value / 100 / TICRATE; + starttickcount -= 1000 / TICRATE; + } + + lastTimeFudge = cv_timefudge.value; + } + return newtics; } From 499177c4b9ba471d94e2b4ad7c4810ffc4286979 Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 21 Dec 2019 14:34:45 +0000 Subject: [PATCH 36/67] Improved ghost trails! --- src/d_clisrv.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 076d033aa..d10a4f6f2 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5690,9 +5690,9 @@ static void RunSimulations() if (playeringame[j] && players[j].mo && j != consoleplayer) { // Update steadyplayers' simulated positions and move their game positions to their known one - steadyplayers[j].histx[simtic - smoothedTic + 1] = players[j].mo->x; - steadyplayers[j].histy[simtic - smoothedTic + 1] = players[j].mo->y; - steadyplayers[j].histz[simtic - smoothedTic + 1] = players[j].mo->z; + steadyplayers[j].histx[simtic - smoothedTic] = players[j].mo->x; + steadyplayers[j].histy[simtic - smoothedTic] = players[j].mo->y; + steadyplayers[j].histz[simtic - smoothedTic] = players[j].mo->z; } } } @@ -5707,6 +5707,25 @@ static void RunSimulations() { if (playeringame[j] && players[j].mo && j != consoleplayer) { + // If there is a big discrepency between the player's current position and their last one, spawn a trail showing their movements + fixed_t distance = max(abs(steadyplayers[j].finalx - players[j].mo->x), + max(abs(steadyplayers[j].finaly - players[j].mo->y), + abs(steadyplayers[j].finalz - players[j].mo->z))); + + // If player is changing direction quickly in a net simulation, create a ghost trail + if (distance > players[j].maxdash) + { + for (int i = 0; i < histIndex; i++) + { + mobj_t* ghost = P_SpawnGhostMobj(players[j].mo); + + ghost->x = steadyplayers[j].histx[i]; + ghost->y = steadyplayers[j].histy[i]; + ghost->z = steadyplayers[j].histz[i]; + ghost->fuse = i - (ghost->fuse - histIndex); + } + } + // Record the final simulated position and error steadyplayers[j].finalx = players[j].mo->x; steadyplayers[j].finaly = players[j].mo->y; @@ -5719,6 +5738,22 @@ static void RunSimulations() } } + // move steadyplayer shields + if (cv_netsteadyplayers.value) + { + mobj_t* mobj; + + for (mobj = (mobj_t*)thlist[THINK_MOBJ].next; mobj != (mobj_t*)&thlist[THINK_MOBJ]; mobj = (mobj_t*)mobj->thinker.next) + { + if (mobj->flags2 & MF2_SHIELD && mobj->target != NULL && mobj->target->player != NULL && mobj->target != players[consoleplayer].mo) + { + mobj->x = steadyplayers[mobj->target->player - players].histx[histIndex]; + mobj->y = steadyplayers[mobj->target->player - players].histy[histIndex]; + mobj->z = steadyplayers[mobj->target->player - players].histz[histIndex]; + } + } + } + rendergametic = gametic; } @@ -5824,7 +5859,7 @@ void DetermineNetConditions() autotimefudgemeans[autotimefudgetime / 10] = mean; autotimefudgedeviations[autotimefudgetime / 10] = differences; - CONS_Printf("Fudge %d tested: mean %f deviation %f\n", autotimefudgetime, mean, differences); + CONS_Printf("Fudge %d: mean %f deviation %f\n", autotimefudgetime, mean, differences); // reset and test the next time fudge autotimefudgetime = (autotimefudgetime + 10) % 100; From 37cd0a596e303b5bfe49bfda37559b82fbf6de7a Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 21 Dec 2019 16:00:39 +0000 Subject: [PATCH 37/67] Fixed crash bug Further improved player trails --- src/d_clisrv.c | 27 +++++++++++++++++---------- src/d_netcmd.c | 2 +- src/p_saveg.c | 46 ++++++++++++++++++++++------------------------ 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index d10a4f6f2..64953b434 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5445,7 +5445,7 @@ boolean newLoadTic = false; #define MAXAUTOFUDGERTT 20 -boolean autotimefudge = true; +boolean autotimefudge; UINT8 autotimefudgetime = 0; UINT16 autotimefudgesamples = 0; UINT16 autotimefudgedata[MAXAUTOFUDGERTT]; @@ -5708,21 +5708,28 @@ static void RunSimulations() if (playeringame[j] && players[j].mo && j != consoleplayer) { // If there is a big discrepency between the player's current position and their last one, spawn a trail showing their movements - fixed_t distance = max(abs(steadyplayers[j].finalx - players[j].mo->x), - max(abs(steadyplayers[j].finaly - players[j].mo->y), - abs(steadyplayers[j].finalz - players[j].mo->z))); + fixed_t distance = max(abs(steadyplayers[j].finalx - steadyplayers[j].histx[histIndex]), + max(abs(steadyplayers[j].finaly - steadyplayers[j].histy[histIndex]), + abs(steadyplayers[j].finalz - steadyplayers[j].histz[histIndex]))); + fixed_t stepDistance = 60 << FRACBITS; // distance between trail steps // If player is changing direction quickly in a net simulation, create a ghost trail - if (distance > players[j].maxdash) + if (distance > stepDistance) { - for (int i = 0; i < histIndex; i++) + fixed_t numSteps = FixedDiv(distance, stepDistance) & ~FRACMASK; + fixed_t currentStep; // between 0 and 1 + fixed_t step = FixedDiv(1<x = steadyplayers[j].histx[i]; - ghost->y = steadyplayers[j].histy[i]; - ghost->z = steadyplayers[j].histz[i]; - ghost->fuse = i - (ghost->fuse - histIndex); + ghost->x = steadyplayers[j].finalx + FixedMul(steadyplayers[j].histx[histIndex] - steadyplayers[j].finalx, currentStep); + ghost->y = steadyplayers[j].finaly + FixedMul(steadyplayers[j].histy[histIndex] - steadyplayers[j].finaly, currentStep); + ghost->z = steadyplayers[j].finalz + FixedMul(steadyplayers[j].histz[histIndex] - steadyplayers[j].finalz, currentStep); + ghost->fuse = ghost->fuse + i - (numSteps>>FRACBITS); + i++; } } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index ed6580b82..9a03bd0d7 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -476,7 +476,7 @@ UINT8 splitscreen = 0; boolean circuitmap = true; // SRB2kart consvar_t cv_simulate = { "simulate", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL }; -static CV_PossibleValue_t simulateTics_cons_t[] = { {0, "MIN"}, {BACKUPTICS / 2, "MAX"}, {0, NULL} }; +static CV_PossibleValue_t simulateTics_cons_t[] = { {0, "MIN"}, {MAXSIMULATIONS - 1, "MAX"}, {0, NULL} }; consvar_t cv_simulatetics = { "simulatetics", "0", 0, simulateTics_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; static CV_PossibleValue_t netdelay_cons_t[] = { {0, "MIN"}, {250, "MAX"}, {0, NULL} }; diff --git a/src/p_saveg.c b/src/p_saveg.c index 34294d183..13f3c676c 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -457,6 +457,17 @@ static void P_LocalArchivePlayers(void) continue; WRITEMEM(save_p, &players[i], sizeof(player_t)); + + player_t* player = &((player_t*)save_p)[-1]; + +#define RELINK(var) if (var != NULL) var = (mobj_t*)var->mobjnum + RELINK(player->capsule); + RELINK(player->axis1); + RELINK(player->axis2); + RELINK(player->awayviewmobj); + RELINK(player->followmobj); + RELINK(player->drone); +#undef RELINK } } @@ -473,13 +484,6 @@ static void P_LocalUnArchivePlayers(void) continue; READMEM(save_p, &players[i], sizeof(player_t)); - - players[i].capsule = NULL; - players[i].axis1 = NULL; - players[i].axis2 = NULL; - players[i].awayviewmobj = NULL; - players[i].followmobj = NULL; - players[i].drone = NULL; } } @@ -2229,16 +2233,6 @@ static void P_LocalArchiveThinkers(void) RELINK(savedMobj->target); RELINK(savedMobj->hnext); RELINK(savedMobj->hprev); - - if (savedMobj->player) - { - RELINK(savedMobj->player->capsule); - RELINK(savedMobj->player->axis1); - RELINK(savedMobj->player->axis2); - RELINK(savedMobj->player->awayviewmobj); - RELINK(savedMobj->player->followmobj); - RELINK(savedMobj->player->drone); - } } } #undef RELINK @@ -3508,15 +3502,19 @@ static void P_LocalUnArchiveThinkers() RELINK(mobj->target); RELINK(mobj->hnext); RELINK(mobj->hprev); + } - if (mobj->player) + // restore player pointers (the above doesn't always seem to work perhaps because playeringame is false? + for (int i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) { - RELINK(mobj->player->capsule); - RELINK(mobj->player->axis1); - RELINK(mobj->player->axis2); - RELINK(mobj->player->awayviewmobj); - RELINK(mobj->player->followmobj); - RELINK(mobj->player->drone); + RELINK(players[i].capsule); + RELINK(players[i].axis1); + RELINK(players[i].axis2); + RELINK(players[i].awayviewmobj); + RELINK(players[i].followmobj); + RELINK(players[i].drone); } } #undef RELINK From 0644ecd0c3070c053641bb5e0d501669813f5e1d Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 22 Dec 2019 02:00:12 +0000 Subject: [PATCH 38/67] Various stability fixes, trail improvements --- src/d_clisrv.c | 177 ++++++++++++++++++++++++++++--------------------- src/d_clisrv.h | 4 +- src/d_netcmd.c | 4 ++ src/d_netcmd.h | 1 + src/p_saveg.c | 40 +++++------ 5 files changed, 125 insertions(+), 101 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 64953b434..328f234bb 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4114,9 +4114,8 @@ static void HandlePacketFromAwayNode(SINT8 node) if (client) { - maketic = gametic = neededtic = (tic_t)LONG(netbuffer->u.servercfg.gametic); - if ((gametype = netbuffer->u.servercfg.gametype) >= NUMGAMETYPES) - I_Error("Bad gametype in cliserv!"); + maketic = gametic = simtic = neededtic = (tic_t)LONG(netbuffer->u.servercfg.gametic); + gametype = netbuffer->u.servercfg.gametype; modifiedgame = netbuffer->u.servercfg.modifiedgame; for (j = 0; j < MAXPLAYERS; j++) adminplayers[j] = netbuffer->u.servercfg.adminplayers[j]; @@ -5451,6 +5450,7 @@ UINT16 autotimefudgesamples = 0; UINT16 autotimefudgedata[MAXAUTOFUDGERTT]; float autotimefudgemeans[10]; float autotimefudgedeviations[10]; +int autotimefudgeattempts = 0; #define MAXOFFSETHISTORY 35 int ticTimeOffsetHistory[MAXOFFSETHISTORY]; @@ -5518,17 +5518,19 @@ void TryRunTics(tic_t realtics) } // record the actual local controls - static boolean didSimulate = false; - boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= BACKUPTICS && gametic >= BACKUPTICS && (cv_simulate.value && !server) && !resynch_local_inprogress; boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 1 && gametic >= BACKUPTICS; + boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= BACKUPTICS && gametic >= BACKUPTICS && (cv_simulate.value && !server) && !resynch_local_inprogress; - if (didSimulate && !canSimulate) + if (simtic > gametic && !canSimulate) { - // if simulation stopped, there is no guarantee our buffers are valid anymore + // if we can't simulate anymore, we ought to reload and invalidate the savestates if (gameStateBufferIsValid[gametic % BACKUPTICS]) P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); + else + CONS_Printf("Problem: game state buffer inaccessible! (simtic %d gametic %d)\n", simtic, gametic); - // invalidate previous states + simtic = gametic; + CONS_Printf("Clearing savestates due to !canSim\n"); InvalidateSavestates(); } @@ -5549,8 +5551,10 @@ void TryRunTics(tic_t realtics) else { // Load the real state if it exists - if (canSimulate && gameStateBufferIsValid[gametic % BACKUPTICS]) + if (simtic != gametic && gameStateBufferIsValid[gametic % BACKUPTICS]) P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); + else if (simtic != gametic && !gameStateBufferIsValid[gametic % BACKUPTICS]) + CONS_Printf("Problem: game state buffer inaccessible but a simulation happened!!\n"); // run the tics up to the real game tic while (neededtic > gametic) @@ -5597,30 +5601,27 @@ void TryRunTics(tic_t realtics) else smoothedTic = gametic; + // collect net condition data + DetermineNetConditions(); + // Simulate the game locally if (canSimulate) RunSimulations(); - else - { - simtic = gametic; // just use the real tic - smoothedTic = gametic; - } - - didSimulate = simtic != gametic || smoothedTic != gametic; // we're gonna need more debugs... MakeNetDebugString(); } +UINT64 simStartTime; +UINT64 simEndTime; + static void RunSimulations() { if (!gameStateBufferIsValid[gametic % BACKUPTICS]) return; // do not simulate if we cannot guarantee a recovery boolean preserveSoundDisabled = sound_disabled; - - // this must be done after smoothedTic is set - DetermineNetConditions(); + static int lastsimtic = 0; int tastyFudge = 0; // hack: don't treat duplicate tics as extra round-trip time @@ -5632,11 +5633,8 @@ static void RunSimulations() break; } - int targetSimTic = min(gametic + estimatedRTT - tastyFudge, smoothedTic + cv_simulatetics.value); - - // don't simulate more than MAXSIMULATIONS - if (targetSimTic - simtic > MAXSIMULATIONS) - simtic = targetSimTic - MAXSIMULATIONS; + int targetSimTic = min(min(gametic + estimatedRTT - tastyFudge, smoothedTic + cv_simulatetics.value), simtic + MAXSIMULATIONS); + int numToSimulate = targetSimTic - (int)simtic; // record steadyplayers' real game position and their simulated position for (int i = 0; i < MAXPLAYERS; i++) @@ -5660,12 +5658,12 @@ static void RunSimulations() } // simulate the rest o da future - int numToSimulate = targetSimTic - (int)simtic; - issimulation = true; sound_disabled = true; con_muted = true; + simStartTime = I_GetTimeUs(); + for (int i = 0; i < numToSimulate; i++) { // control other players (just use their previous control for now) @@ -5702,70 +5700,94 @@ static void RunSimulations() con_muted = false; // Finalise steadyplayers - int histIndex = max((int)(simtic - smoothedTic) - cv_netsteadyplayers.value, 0); // up to cv_netsteadyplayers.value behind the simulation - for (int j = 0; j < MAXPLAYERS; j++) + if (numToSimulate > 0) { - if (playeringame[j] && players[j].mo && j != consoleplayer) + int histIndex = max((int)(simtic - smoothedTic) - cv_netsteadyplayers.value, 0); // up to cv_netsteadyplayers.value behind the simulation + for (int j = 0; j < MAXPLAYERS; j++) { - // If there is a big discrepency between the player's current position and their last one, spawn a trail showing their movements - fixed_t distance = max(abs(steadyplayers[j].finalx - steadyplayers[j].histx[histIndex]), - max(abs(steadyplayers[j].finaly - steadyplayers[j].histy[histIndex]), - abs(steadyplayers[j].finalz - steadyplayers[j].histz[histIndex]))); - fixed_t stepDistance = 60 << FRACBITS; // distance between trail steps - - // If player is changing direction quickly in a net simulation, create a ghost trail - if (distance > stepDistance) + if (playeringame[j] && players[j].mo && j != consoleplayer && !players[j].spectator) { - fixed_t numSteps = FixedDiv(distance, stepDistance) & ~FRACMASK; - fixed_t currentStep; // between 0 and 1 - fixed_t step = FixedDiv(1<x = steadyplayers[j].histx[histIndex]; + players[j].mo->y = steadyplayers[j].histy[histIndex]; + players[j].mo->z = steadyplayers[j].histz[histIndex]; - for (currentStep = step; currentStep < (1<x = steadyplayers[j].finalx + FixedMul(steadyplayers[j].histx[histIndex] - steadyplayers[j].finalx, currentStep); - ghost->y = steadyplayers[j].finaly + FixedMul(steadyplayers[j].histy[histIndex] - steadyplayers[j].finaly, currentStep); - ghost->z = steadyplayers[j].finalz + FixedMul(steadyplayers[j].histz[histIndex] - steadyplayers[j].finalz, currentStep); - ghost->fuse = ghost->fuse + i - (numSteps>>FRACBITS); - i++; + // Generate trails + if (cv_nettrails.value) + { + int trailLifetime = cv_nettrails.value; + + for (int s = 0; s < trailLifetime; s++) + { + // If there is a big discrepency between the player's current position and their last one, spawn a trail showing their movements + fixed_t prevx = steadyplayers[j].simx[(simtic - s - 1) % BACKUPTICS], prevy = steadyplayers[j].simy[(simtic - s - 1) % BACKUPTICS], + prevz = steadyplayers[j].simz[(simtic - s - 1) % BACKUPTICS]; + fixed_t curx = steadyplayers[j].simx[(simtic - s) % BACKUPTICS], cury = steadyplayers[j].simy[(simtic - s) % BACKUPTICS], + curz = steadyplayers[j].simz[(simtic - s) % BACKUPTICS]; + fixed_t distance = max(abs(curx - prevx), max(abs(cury - prevy), abs(curz - prevz))); + fixed_t stepDistance = 90 << FRACBITS; // distance between trail steps + fixed_t activationDistance = 60 << FRACBITS; // distance between trail steps + + // If player is changing direction quickly in a net simulation, create a ghost trail + if (distance > activationDistance) + { + fixed_t numSteps = FixedDiv(distance, stepDistance) & ~FRACMASK; + fixed_t currentStep; // between 0 and 1 + fixed_t step = FixedDiv(1 << FRACBITS, numSteps + 1); + + for (currentStep = step; currentStep < (1 << FRACBITS); currentStep += step) + { + mobj_t* ghost = P_SpawnGhostMobj(players[j].mo); + + ghost->x = prevx + FixedMul(curx - prevx, currentStep); + ghost->y = prevy + FixedMul(cury - prevy, currentStep); + ghost->z = prevz + FixedMul(curz - prevz, currentStep); + ghost->frame = (ghost->frame & FF_TRANSMASK) | ((6 - s) << FF_TRANSSHIFT); + ghost->fuse = 1; + } + } + } } } - - // Record the final simulated position and error - steadyplayers[j].finalx = players[j].mo->x; - steadyplayers[j].finaly = players[j].mo->y; - steadyplayers[j].finalz = players[j].mo->z; - - // Set the player's positions to the preferred simulation index (or perhaps just their original position) - players[j].mo->x = steadyplayers[j].histx[histIndex]; - players[j].mo->y = steadyplayers[j].histy[histIndex]; - players[j].mo->z = steadyplayers[j].histz[histIndex]; } - } - // move steadyplayer shields - if (cv_netsteadyplayers.value) - { - mobj_t* mobj; - - for (mobj = (mobj_t*)thlist[THINK_MOBJ].next; mobj != (mobj_t*)&thlist[THINK_MOBJ]; mobj = (mobj_t*)mobj->thinker.next) + // move steadyplayer shields + if (cv_netsteadyplayers.value) { - if (mobj->flags2 & MF2_SHIELD && mobj->target != NULL && mobj->target->player != NULL && mobj->target != players[consoleplayer].mo) + mobj_t* mobj; + + for (mobj = (mobj_t*)thlist[THINK_MOBJ].next; mobj != (mobj_t*)&thlist[THINK_MOBJ]; mobj = (mobj_t*)mobj->thinker.next) { - mobj->x = steadyplayers[mobj->target->player - players].histx[histIndex]; - mobj->y = steadyplayers[mobj->target->player - players].histy[histIndex]; - mobj->z = steadyplayers[mobj->target->player - players].histz[histIndex]; + if (mobj->flags2 & MF2_SHIELD && mobj->target != NULL && mobj->target->player != NULL && mobj->target != players[consoleplayer].mo) + { + mobj->x = steadyplayers[mobj->target->player - players].histx[histIndex]; + mobj->y = steadyplayers[mobj->target->player - players].histy[histIndex]; + mobj->z = steadyplayers[mobj->target->player - players].histz[histIndex]; + } } } } + simEndTime = I_GetTimeUs(); + + lastsimtic = simtic; rendergametic = gametic; } void InvalidateSavestates() { + if (simtic > gametic) + CONS_Printf("Warning: Savestates were invalidated during a simulation!!\n"); + for (int i = 0; i < MAXSIMULATIONS; i++) gameStateBufferIsValid[i] = false; } @@ -5828,7 +5850,7 @@ void DetermineNetConditions() rttJitter = maxRTT - minRTT; // auto time fudge - int maxautotimefudgesamples = 25; + int maxautotimefudgesamples = 10; static int numignoredtimefudgesamples = 5; if (autotimefudge) { @@ -5845,7 +5867,7 @@ void DetermineNetConditions() } } - if (autotimefudgesamples > maxautotimefudgesamples) + if (autotimefudgesamples >= maxautotimefudgesamples) { // calculate standard deviation of this time fudge float mean = 0; @@ -5869,16 +5891,21 @@ void DetermineNetConditions() CONS_Printf("Fudge %d: mean %f deviation %f\n", autotimefudgetime, mean, differences); // reset and test the next time fudge - autotimefudgetime = (autotimefudgetime + 10) % 100; autotimefudgesamples = 0; numignoredtimefudgesamples = maxRTT + 2; for (int i = 0; i < MAXAUTOFUDGERTT; i++) autotimefudgedata[i] = 0; - if (autotimefudgetime == 0) + if (differences < 2.0f) + autotimefudgetime = autotimefudgetime + 10; + else + CONS_Printf("Retrying...\n"); // too much deviation, try again + + if (autotimefudgetime >= 100) { - // best time is where the deviation is minimal; this can be achieved by going halfway from the worst point + // done! + // the best time is where the deviation is minimal; this can be achieved by going halfway from the worst point int worstFudgeTime = 0; float worstDeviation = 0.0f; @@ -5991,6 +6018,8 @@ void MakeNetDebugString() sprintf(&netDebugText[strlen(netDebugText)], "\nSimDelta: %d", simtic - lastSim); sprintf(&netDebugText[strlen(netDebugText)], "\nLive: %d", liveTic); sprintf(&netDebugText[strlen(netDebugText)], "\nTime save/load: %.2f/%.2f", (float)saveStateBenchmark/1000.0f, (float)loadStateBenchmark/1000.0f); + sprintf(&netDebugText[strlen(netDebugText)], "\nTotal +ms: %d", (int)((simEndTime - simStartTime + saveStateBenchmark + loadStateBenchmark) / 1000)); + sprintf(&netDebugText[strlen(netDebugText)], "\nseed: %d", P_GetRandSeed()); lastSim = simtic; unsigned int rtts[20] = { 0 }; diff --git a/src/d_clisrv.h b/src/d_clisrv.h index ef712d315..0661046f1 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -540,10 +540,8 @@ typedef struct fixed_t histx[MAXSIMULATIONS + 1], histy[MAXSIMULATIONS + 1], histz[MAXSIMULATIONS + 1]; // stores the final simulated position for each simulated gametic - fixed_t finalx, finaly, finalz; + fixed_t simx[BACKUPTICS], simy[BACKUPTICS], simz[BACKUPTICS]; - // difference between the position we simulated to during this update compared to the last one - fixed_t error; } steadyplayer_t; extern boolean server; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 9a03bd0d7..704e23027 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -498,6 +498,9 @@ consvar_t cv_netsteadyplayers = { "netsteadyplayers", "0", 0, netsteadyplayers_c static CV_PossibleValue_t timefudge_cons_t[] = { {0, "MIN"}, {100, "MAX"}, {0, NULL} }; consvar_t cv_timefudge = { "timefudge", "0", 0, timefudge_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +static CV_PossibleValue_t nettrails_cons_t[] = { {0, "MIN"}, {5, "MAX"}, {0, NULL} }; +consvar_t cv_nettrails = { "nettrails", "1", 0, nettrails_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; + char timedemo_name[256]; boolean timedemo_csv; char timedemo_csv_id[256]; @@ -662,6 +665,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_netsteadyplayers); CV_RegisterVar(&cv_debugsimulaterewind); CV_RegisterVar(&cv_timefudge); + CV_RegisterVar(&cv_nettrails); // for master server connection AddMServCommands(); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 3fa8477ea..b2c192fd1 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -157,6 +157,7 @@ extern consvar_t cv_netspikes; extern consvar_t cv_netsteadyplayers; extern consvar_t cv_debugsimulaterewind; extern consvar_t cv_timefudge; +extern consvar_t cv_nettrails; extern consvar_t cv_skipmapcheck; diff --git a/src/p_saveg.c b/src/p_saveg.c index 13f3c676c..f79731cf9 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3269,11 +3269,14 @@ static void P_LocalUnArchiveThinkers() // preserve sky box indexes for (i = 0; i < 16; i++) { - if (skyboxmo[0] && skyboxmo[0] == skyboxviewpnts[i]) + if (skyboxmo[0] == skyboxviewpnts[i]) skyviewid = i; // save id just in case - if (skyboxmo[1] && skyboxmo[1] == skyboxcenterpnts[i]) + if (skyboxmo[1] == skyboxcenterpnts[i]) skycenterid = i; // save id just in case + skyboxviewpnts[i] = NULL; + skyboxcenterpnts[i] = NULL; } + skyboxmo[0] = skyboxmo[1] = NULL; // sort objects by type for (i = 0; i < tc_end; i++) @@ -3397,6 +3400,14 @@ static void P_LocalUnArchiveThinkers() bflagpoint = mobj->spawnpoint; } + if (mobj->type == MT_SKYBOX) + { + if ((mobj->extravalue2 >> 16) == 1) + skyboxcenterpnts[mobj->extravalue2 & 0xFFFF] = mobj; + else + skyboxviewpnts[mobj->extravalue2 & 0xFFFF] = mobj; + } + if (mobj->player && mobj->type == MT_PLAYER) mobj->player->mo = mobj; @@ -3519,26 +3530,7 @@ static void P_LocalUnArchiveThinkers() } #undef RELINK - // restore skyboxes if applicable - for (i = 0; i < sizeof(skyboxmo) / sizeof(skyboxmo[0]); i++) - skyboxmo[i] = NULL; - for (i = 0; i < sizeof(skyboxcenterpnts) / sizeof(skyboxcenterpnts[0]); i++) - { - skyboxcenterpnts[i] = NULL; - skyboxviewpnts[i] = NULL; - } - - for (mobj = (mobj_t*)thlist[THINK_MOBJ].next; mobj != (mobj_t*)&thlist[THINK_MOBJ]; mobj = (mobj_t*)mobj->thinker.next) - { - if (mobj->type == MT_SKYBOX) - { - if ((mobj->extravalue2 >> 16) == 1) - skyboxcenterpnts[mobj->extravalue2 & 0xFFFF] = mobj; - else - skyboxviewpnts[mobj->extravalue2 & 0xFFFF] = mobj; - } - } - + // restore skyboxes skyboxmo[0] = skyboxviewpnts[(skyviewid >= 0) ? skyviewid : 0]; skyboxmo[1] = skyboxcenterpnts[(skycenterid >= 0) ? skycenterid : 0]; } @@ -4512,7 +4504,7 @@ void P_SaveGameState(savestate_t* savestate) { mobj_t* mobj; thinker_t* th; - int i = 0; + int i = 1; UINT64 time = I_GetTimeUs(); @@ -4579,7 +4571,7 @@ boolean P_LoadGameState(const savestate_t* savestate) #endif // This is stupid and hacky _squared_, but it's in the net load code and it says it might work, so I guess it might work! - P_SetRandSeed(P_GetInitSeed()); + //P_SetRandSeed(P_GetInitSeed()); P_UnArchiveLuabanksAndConsistency(); From 7fd123d60427f39482f7038bfaf20f486f32c45f Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 22 Dec 2019 12:13:32 +0000 Subject: [PATCH 39/67] Sounds now play instantly (even if they're incorrect) Added ringsling delay for when steadyplayers are enabled The simulation was always one tic behind! OOPS! --- src/d_clisrv.c | 14 ++++++++++---- src/d_netcmd.c | 3 +++ src/d_netcmd.h | 1 + src/p_local.h | 1 + src/p_mobj.c | 15 +++++++++++++++ src/p_saveg.c | 8 -------- src/s_sound.c | 13 +++++++++---- 7 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 328f234bb..e438bf965 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5439,8 +5439,6 @@ int minLiveTicOffset; int smoothingDelay; UINT64 saveStateBenchmark = 0; UINT64 loadStateBenchmark = 0; -boolean newSaveTic = false; -boolean newLoadTic = false; #define MAXAUTOFUDGERTT 20 @@ -5520,6 +5518,7 @@ void TryRunTics(tic_t realtics) // record the actual local controls boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 1 && gametic >= BACKUPTICS; boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= BACKUPTICS && gametic >= BACKUPTICS && (cv_simulate.value && !server) && !resynch_local_inprogress; + boolean preserveSoundDisabled = sound_disabled; if (simtic > gametic && !canSimulate) { @@ -5534,11 +5533,13 @@ void TryRunTics(tic_t realtics) InvalidateSavestates(); } + if (canSimulate) + sound_disabled = true; + PerformDebugRewinds(); // record the actual local controls for this frame liveTic = I_GetTime(); - newSaveTic = newLoadTic = true; for (tic_t i = 0; i < realtics; i++) localTicBuffer[(liveTic - i) % BACKUPTICS] = localcmds; @@ -5606,7 +5607,10 @@ void TryRunTics(tic_t realtics) // Simulate the game locally if (canSimulate) + { RunSimulations(); + sound_disabled = preserveSoundDisabled; + } // we're gonna need more debugs... MakeNetDebugString(); @@ -5625,7 +5629,7 @@ static void RunSimulations() int tastyFudge = 0; // hack: don't treat duplicate tics as extra round-trip time - for (int j = 0; j < 2; j++) + for (int j = 1; j < 3; j++) { if (CompareTiccmd(&gameTicBuffer[gametic % BACKUPTICS][consoleplayer], &gameTicBuffer[(gametic - j) % BACKUPTICS][consoleplayer])) tastyFudge++; @@ -5679,6 +5683,8 @@ static void RunSimulations() else netcmds[gametic % BACKUPTICS][consoleplayer] = localTicBuffer[(liveTic - estimatedRTT + i + 1 + BACKUPTICS) % BACKUPTICS]; + sound_disabled = (i != numToSimulate - 1); + G_Ticker(true); // tic a bunch of times lol see what happens lolol simtic++; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 704e23027..3d88c9024 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -501,6 +501,8 @@ consvar_t cv_timefudge = { "timefudge", "0", 0, timefudge_cons_t, NULL, 0, NULL, static CV_PossibleValue_t nettrails_cons_t[] = { {0, "MIN"}, {5, "MAX"}, {0, NULL} }; consvar_t cv_nettrails = { "nettrails", "1", 0, nettrails_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_netslingdelay = { "netslingdelay", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; + char timedemo_name[256]; boolean timedemo_csv; char timedemo_csv_id[256]; @@ -666,6 +668,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_debugsimulaterewind); CV_RegisterVar(&cv_timefudge); CV_RegisterVar(&cv_nettrails); + CV_RegisterVar(&cv_netslingdelay); // for master server connection AddMServCommands(); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index b2c192fd1..fffba87d7 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -158,6 +158,7 @@ extern consvar_t cv_netsteadyplayers; extern consvar_t cv_debugsimulaterewind; extern consvar_t cv_timefudge; extern consvar_t cv_nettrails; +extern consvar_t cv_netslingdelay; extern consvar_t cv_skipmapcheck; diff --git a/src/p_local.h b/src/p_local.h index 3c8395e10..ccb5f8b3d 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -273,6 +273,7 @@ void P_ColorTeamMissile(mobj_t *missile, player_t *source); SINT8 P_MobjFlip(mobj_t *mobj); fixed_t P_GetMobjGravity(mobj_t *mo); FUNCMATH boolean P_WeaponOrPanel(mobjtype_t type); +FUNCMATH boolean P_IsProjectile(mobjtype_t type); boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled); diff --git a/src/p_mobj.c b/src/p_mobj.c index 47a625ac4..759eee0b2 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -397,6 +397,12 @@ boolean P_WeaponOrPanel(mobjtype_t type) return false; } +boolean P_IsProjectile(mobjtype_t type) +{ + return type == MT_THROWNBOUNCE || type == MT_THROWNINFINITY || type == MT_THROWNAUTOMATIC || type == MT_THROWNSCATTER + || type == MT_THROWNEXPLOSION || type == MT_THROWNGRENADE || type == MT_REDRING; +} + // // P_EmeraldManager // @@ -6360,6 +6366,15 @@ void P_MobjThinker(mobj_t *mobj) if (mobj->flags & MF_NOTHINK) return; + if ((mobj->flags & MF_BOSS) && mobj->spawnpoint && (bossdisabled & (1<spawnpoint->extrainfo))) + return; + + if (cv_netslingdelay.value && P_IsProjectile(mobj->type) && issimulation && (tic_t)cv_netsteadyplayers.value > simtic-gametic && mobj->target == players[consoleplayer].mo) + { + // don't simulate ring weapons if netslingdelay is positive + mobj->momx = mobj->momy = mobj->momz = 0; + } + // Remove dead target/tracer. if (mobj->target && P_MobjWasRemoved(mobj->target)) P_SetTarget(&mobj->target, NULL); diff --git a/src/p_saveg.c b/src/p_saveg.c index f79731cf9..88993ef4f 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -4362,14 +4362,6 @@ static inline boolean P_NetUnArchiveMisc(boolean preserveLevel) return true; } - -extern UINT64 saveTime; -extern int numSaves; -extern UINT64 loadTime; -extern int numLoads; -extern boolean newSaveTic; -extern boolean newLoadTic; - UINT64 I_GetTimeUs(void); void P_SaveGame(void) diff --git a/src/s_sound.c b/src/s_sound.c index f1a9d5f3b..936e3ced9 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1236,11 +1236,16 @@ void S_DetachChannelsFromOrigin(void* origin) { if (channels[i].origin == origin) { + // small hack: player-made sounds should stay hearable + if (channels[i].origin != players[displayplayer].mo) + { + channels[i].isdetached = true; + channels[i].detachedx = originmobj->x; + channels[i].detachedy = originmobj->y; + channels[i].detachedz = originmobj->z; + } + channels[i].origin = NULL; - channels[i].isdetached = true; - channels[i].detachedx = originmobj->x; - channels[i].detachedy = originmobj->y; - channels[i].detachedz = originmobj->z; } } } From a8eb9b2485a8c8e5ab3134fa44f6b49e61ae26c1 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 22 Dec 2019 15:13:58 +0000 Subject: [PATCH 40/67] Polyobjects are now synced with gratuitous awkwardness Fixed executor crash During savestates, console vars will be stealthy --- src/command.c | 6 +- src/command.h | 2 +- src/d_clisrv.c | 2 +- src/d_netcmd.c | 2 + src/g_game.c | 2 +- src/p_polyobj.c | 5 ++ src/p_polyobj.h | 4 + src/p_saveg.c | 192 +++++++++++++++++++++++++++++++++++------------- src/p_saveg.h | 2 +- 9 files changed, 160 insertions(+), 57 deletions(-) diff --git a/src/command.c b/src/command.c index 3eebe32d1..354d984b8 100644 --- a/src/command.c +++ b/src/command.c @@ -1364,6 +1364,7 @@ badinput: // static boolean serverloading = false; +static boolean serverloadingstealth = false; static void Got_NetVar(UINT8 **p, INT32 playernum) { @@ -1391,7 +1392,7 @@ static void Got_NetVar(UINT8 **p, INT32 playernum) cvar = CV_FindNetVar(netid); svalue = (char *)*p; SKIPSTRING(*p); - stealth = READUINT8(*p); + stealth = READUINT8(*p) || (serverloading && serverloadingstealth); if (!cvar) { @@ -1448,13 +1449,14 @@ void CV_SaveNetVars(UINT8 **p, boolean isdemorecording) WRITEUINT16(count_p, count); } -void CV_LoadNetVars(UINT8 **p) +void CV_LoadNetVars(UINT8 **p, boolean onlyIfChanged) { consvar_t *cvar; UINT16 count; // prevent "invalid command received" serverloading = true; + serverloadingstealth = onlyIfChanged; for (cvar = consvar_vars; cvar; cvar = cvar->next) if (cvar->flags & CV_NETVAR) diff --git a/src/command.h b/src/command.h index 6b5d513ef..2ef276fe0 100644 --- a/src/command.h +++ b/src/command.h @@ -165,7 +165,7 @@ void CV_SaveVariables(FILE *f); // load/save gamesate (load and save option and for network join in game) void CV_SaveNetVars(UINT8 **p, boolean isdemorecording); -void CV_LoadNetVars(UINT8 **p); +void CV_LoadNetVars(UINT8 **p, boolean onlyIfChanged); // reset cheat netvars after cheats is deactivated void CV_ResetCheatNetVars(void); diff --git a/src/d_clisrv.c b/src/d_clisrv.c index e438bf965..0d5705e31 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4151,7 +4151,7 @@ static void HandlePacketFromAwayNode(SINT8 node) scp = netbuffer->u.servercfg.varlengthinputs; CV_LoadPlayerNames(&scp); - CV_LoadNetVars(&scp); + CV_LoadNetVars(&scp, false); #ifdef JOININGAME /// \note Wait. What if a Lua script uses some global custom variables synched with the NetVars hook? /// Shouldn't them be downloaded even at intermission time? diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 3d88c9024..80c63ed01 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -847,12 +847,14 @@ static void Command_Saveloadtest(void) } extern boolean autotimefudge; +extern UINT8 autotimefudgetime; static void Command_Autotimefudge(void) { if (!autotimefudge) { CONS_Printf("Searching for the best time fudge...\n"); autotimefudge = true; + autotimefudgetime = 0; } } diff --git a/src/g_game.c b/src/g_game.c index b0f18d98e..284a69ba5 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -7357,7 +7357,7 @@ void G_DoPlayDemo(char *defdemoname) #endif // net var data - CV_LoadNetVars(&demo_p); + CV_LoadNetVars(&demo_p, false); // Sigh ... it's an empty demo. if (*demo_p == DEMOMARKER) diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 25a7122ad..b08bdb6a7 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1538,6 +1538,11 @@ void Polyobj_InitLevel(void) qitem = (mobjqitem_t *)M_QueueIterator(&spawnqueue); Polyobj_spawnPolyObj(i, qitem->mo, qitem->mo->spawnpoint->angle); + + PolyObjects[i].origx = qitem->mo->x; + PolyObjects[i].origy = qitem->mo->y; + PolyObjects[i].origz = qitem->mo->z; + PolyObjects[i].origangle = qitem->mo->spawnpoint->angle; } // move polyobjects to spawn points diff --git a/src/p_polyobj.h b/src/p_polyobj.h index 60e996cae..ee8ff6e45 100644 --- a/src/p_polyobj.h +++ b/src/p_polyobj.h @@ -104,6 +104,10 @@ typedef struct polyobj_s // these are saved for netgames, so do not let Lua touch these! INT32 spawnflags; // Flags the polyobject originally spawned with + INT32 spawntrans; // Translucency the polyobject originally spawned with + + fixed_t origx, origy, origz; + INT16 origangle; } polyobj_t; // diff --git a/src/p_saveg.c b/src/p_saveg.c index 88993ef4f..991d24013 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2202,6 +2202,7 @@ static void P_LocalArchiveThinkers(void) int i, j; const thinker_t* thinker; mobj_t* savedMobj; + executor_t* savedExecutor; UINT8* original = save_p; WRITEUINT32(save_p, ARCHIVEBLOCK_THINKERS); @@ -2234,6 +2235,12 @@ static void P_LocalArchiveThinkers(void) RELINK(savedMobj->hnext); RELINK(savedMobj->hprev); } + + if (j == tc_executor) + { + savedExecutor = &((executor_t*)save_p)[-1]; + RELINK(savedExecutor->caller); + } } #undef RELINK @@ -3246,6 +3253,15 @@ static void CollectDebugObjectList(void) { void S_DetachChannelsFromOrigin(void* origin); +typedef struct +{ + mobj_t* mobj; + int thinkerListIndex; +} mobjloclink_t; + +#define HASHLOC(x, y, z) (((((x<<3)^(y>>6)*(z>>3)+(x>>15))^(y<<20)-(z>>17)+(x>>6))^x) & 0x7FFF) +#define MAXNUMMOBJSBYLOC 5 + static void P_LocalUnArchiveThinkers() { thinker_t *thinker; @@ -3257,11 +3273,15 @@ static void P_LocalUnArchiveThinkers() int skycenterid = -1; thinker_t newthinkers[NUM_THINKERLISTS] = { 0 }; static thinker_t* thinkersbytype[tc_end][16384]; - static UINT8 thinkerlistbytype[tc_end][16384]; static int numthinkersbytype[tc_end]; + static mobjloclink_t mobjByLoc[32768][MAXNUMMOBJSBYLOC]; + static int numMobjsByLoc[32768]; static mobj_t* mobjByNum[16384]; memset(mobjByNum, 0, sizeof(mobjByNum)); + memset(mobjByLoc, 0, sizeof(mobjByLoc)); + memset(numMobjsByLoc, 0, sizeof(numMobjsByLoc)); + memset(numthinkersbytype, 0, sizeof(numthinkersbytype)); if (READUINT32(save_p) != ARCHIVEBLOCK_THINKERS) I_Error("Bad SaveState at archive block Thinkers"); @@ -3278,10 +3298,7 @@ static void P_LocalUnArchiveThinkers() } skyboxmo[0] = skyboxmo[1] = NULL; - // sort objects by type - for (i = 0; i < tc_end; i++) - numthinkersbytype[i] = 0; - + // sort thinkers into maps to speed up replacement searches for (i = 0; i < NUM_THINKERLISTS; i++) { newthinkers[i].next = &newthinkers[i]; @@ -3289,14 +3306,27 @@ static void P_LocalUnArchiveThinkers() for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = thinker->next) { + if (thinker->function.acp1 == P_RemoveThinkerDelayed) + continue; for (j = 0; j < tc_end; j++) { if (thinker->function.acp1 == specialDefs[j].action) - { - thinkersbytype[j][numthinkersbytype[j]] = thinker; - thinkerlistbytype[j][numthinkersbytype[j]] = i; - numthinkersbytype[j]++; break; + } + + // insert the thinker into the appropriate maps + thinkersbytype[j][numthinkersbytype[j]] = thinker; + numthinkersbytype[j]++; + + if (thinker->function.acp1 == P_MobjThinker) + { + UINT16 locHash = HASHLOC(((mobj_t*)thinker)->x, ((mobj_t*)thinker)->y, ((mobj_t*)thinker)->z); + + if (numMobjsByLoc[locHash] < MAXNUMMOBJSBYLOC) + { + mobjByLoc[locHash][numMobjsByLoc[locHash]].mobj = (mobj_t*)thinker; + mobjByLoc[locHash][numMobjsByLoc[locHash]].thinkerListIndex = numthinkersbytype[j] - 1; + numMobjsByLoc[locHash]++; } } } @@ -3323,47 +3353,69 @@ static void P_LocalUnArchiveThinkers() break; // next list thinker_t* newthinker = NULL; + boolean preservePositions = false; - if (numthinkersbytype[tclass] > 0) + // find the existing thinker(s) at the same position, if possible + if (tclass == tc_mobj) + { + mobj_t* savedMobj = (mobj_t*)save_p; + UINT16 locHash = HASHLOC(savedMobj->x, savedMobj->y, savedMobj->z); + + for (i = 0; i < numMobjsByLoc[locHash]; i++) + { + if (mobjByLoc[locHash][i].mobj->x == savedMobj->x && mobjByLoc[locHash][i].mobj->y == savedMobj->y && mobjByLoc[locHash][i].mobj->z == savedMobj->z && + (mobjByLoc[locHash][i].mobj->flags & (MF_NOSECTOR | MF_NOBLOCKMAP)) == (savedMobj->flags & (MF_NOSECTOR | MF_NOBLOCKMAP))) + { + newthinker = (thinker_t*)mobjByLoc[locHash][i].mobj; + thinkersbytype[tc_mobj][mobjByLoc[locHash][i].thinkerListIndex] = NULL; + mobjByLoc[locHash][i] = mobjByLoc[locHash][numMobjsByLoc[locHash] - 1]; + numMobjsByLoc[locHash]--; + preservePositions = true; + break; + } + } + } + + // if that didn't work, find an existing thinker of the same type + if (newthinker == NULL && numthinkersbytype[tclass] > 0) { for (j = numthinkersbytype[tclass] - 1; j >= 0; j--) { - UINT8 thinkerlist = thinkerlistbytype[tclass][j]; - - if (thinkerlist != list) - continue; // don't replace something from a different list actually it doesn't matter lol + if (thinkersbytype[tclass][j] == NULL) + { + numthinkersbytype[tclass]--; + continue; + } // we found an object to replace! newthinker = thinkersbytype[tclass][j]; numthinkersbytype[tclass]--; - - if (tclass == tc_mobj) - { - P_UnsetThingPosition((mobj_t*)newthinker); - if (sector_list != NULL) { - P_DelSeclist(sector_list); - sector_list = NULL; - } - } - - // detach any playing sounds from this object if we can (still need to work on doing this properly!) - S_DetachChannelsFromOrigin((mobj_t*)newthinker); - - // allocate it to the new object - for (int k = j; k < numthinkersbytype[tclass]; k++) - { - thinkersbytype[tclass][k] = thinkersbytype[tclass][k + 1]; - thinkerlistbytype[tclass][k] = thinkerlistbytype[tclass][k + 1]; - } - - // unlink it from the old list - newthinker->prev->next = newthinker->next; - newthinker->next->prev = newthinker->prev; break; } } - if (newthinker == NULL) + if (newthinker != NULL) + { + // we found a thinker! we just need to set it up to be replaced + if (tclass == tc_mobj && !preservePositions) + { + // remove it from its old position + P_UnsetThingPosition((mobj_t*)newthinker); + if (sector_list != NULL) + { + P_DelSeclist(sector_list); + sector_list = NULL; + } + } + + // detach any playing sounds from this object if we can (still need to work on doing this properly!) + S_DetachChannelsFromOrigin((mobj_t*)newthinker); + + // unlink it from the old list + newthinker->prev->next = newthinker->next; + newthinker->next->prev = newthinker->prev; + } + else { // we couldn't find an object to replace so we gotta create it if (tclass == tc_mobj) @@ -3373,9 +3425,9 @@ static void P_LocalUnArchiveThinkers() } // preserve vital positioning stuff (cleanup...) - mobj_t preserveMobj; + mobj_t preservedMobj; if (tclass == tc_mobj) - preserveMobj = *(mobj_t*)newthinker; + preservedMobj = *(mobj_t*)newthinker; // read in the data READMEM(save_p, newthinker, specialDefs[tclass].size); @@ -3414,10 +3466,10 @@ static void P_LocalUnArchiveThinkers() // clear sector links etc mobj->bnext = NULL; mobj->bprev = NULL; - mobj->snext = preserveMobj.snext; - mobj->sprev = preserveMobj.sprev; - mobj->subsector = preserveMobj.subsector; - mobj->touching_sectorlist = preserveMobj.touching_sectorlist; + mobj->snext = preservedMobj.snext; + mobj->sprev = preservedMobj.sprev; + mobj->subsector = preservedMobj.subsector; + mobj->touching_sectorlist = preservedMobj.touching_sectorlist; mobjByNum[mobj->mobjnum] = mobj; break; // i dream of a programming language where breaking is the default and fallthrough is the optional (and so much more rarely used) specifier } @@ -3448,7 +3500,15 @@ static void P_LocalUnArchiveThinkers() newthinker->next->prev = newthinker; if (tclass == tc_mobj) - P_SetThingPosition((mobj_t*)newthinker); + { + if (!preservePositions) + P_SetThingPosition((mobj_t*)newthinker); + else + { + ((mobj_t*)newthinker)->bnext = preservedMobj.bnext; + ((mobj_t*)newthinker)->bprev = preservedMobj.bprev; + } + } } } @@ -3885,7 +3945,7 @@ static inline void P_UnArchivePolyObj(polyobj_t *po) return; // rotate and translate polyobject - Polyobj_MoveOnLoad(po, angle, x, y); + Polyobj_MoveOnLoad(po, angle + (po->origangle - po->angle), x + (po->origx - po->spawnSpot.x), y + (po->origy - po->spawnSpot.y)); } static inline void P_ArchivePolyObjects(void) @@ -3916,6 +3976,36 @@ static inline void P_UnArchivePolyObjects(void) for (i = 0; i < numSavedPolys; ++i) P_UnArchivePolyObj(&PolyObjects[i]); } + +static void P_LocalArchivePolyObjects(void) +{ + P_ArchivePolyObjects(); + /*WRITEUINT32(save_p, ARCHIVEBLOCK_POBJS); + + WRITEINT32(save_p, numPolyObjects); + + WRITEMEM(save_p, PolyObjects, numPolyObjects * sizeof(PolyObjects[0]));*/ +} + +static void P_LocalUnArchivePolyObjects(void) +{ + P_UnArchivePolyObjects(); + /*if (READUINT32(save_p) != ARCHIVEBLOCK_POBJS) + I_Error("Bad savestate at archive block polyobjects"); + + numPolyObjects = READINT32(save_p); + + READMEM(save_p, PolyObjects, numPolyObjects * sizeof(PolyObjects[0])); + + bmap_freelist = NULL; + + for (int i = 0; i < numPolyObjects; i++) + { + PolyObjects[i].thinker = NULL; + PolyObjects[i].linked = false; + Polyobj_linkToBlockmap(&PolyObjects[i]); + }*/ +} #endif // // P_FinishMobjs @@ -4445,7 +4535,7 @@ boolean P_LoadGame(INT16 mapoverride) boolean P_LoadNetGame(boolean preserveLevel) { - CV_LoadNetVars(&save_p); + CV_LoadNetVars(&save_p, false); loadTimes[0] = I_GetTimeUs(); if (!P_NetUnArchiveMisc(preserveLevel)) return false; @@ -4522,7 +4612,7 @@ void P_SaveGameState(savestate_t* savestate) P_LocalArchivePlayers(); P_LocalArchiveWorld(); #ifdef POLYOBJECTS - P_ArchivePolyObjects(); + P_LocalArchivePolyObjects(); #endif P_LocalArchiveThinkers(); P_NetArchiveSpecials(); @@ -4547,13 +4637,13 @@ boolean P_LoadGameState(const savestate_t* savestate) globalmobjnum = READUINT32(save_p); - CV_LoadNetVars(&save_p); + CV_LoadNetVars(&save_p, true); P_NetUnArchiveMisc(true); P_LocalUnArchivePlayers(); P_LocalUnArchiveWorld(); #ifdef POLYOBJECTS - P_UnArchivePolyObjects(); + P_LocalUnArchivePolyObjects(); #endif P_LocalUnArchiveThinkers(); P_NetUnArchiveSpecials(); @@ -4566,7 +4656,7 @@ boolean P_LoadGameState(const savestate_t* savestate) //P_SetRandSeed(P_GetInitSeed()); P_UnArchiveLuabanksAndConsistency(); - loadStateBenchmark = I_GetTimeUs() - time; + return true; } \ No newline at end of file diff --git a/src/p_saveg.h b/src/p_saveg.h index 7aba45188..24ca4821f 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -32,7 +32,7 @@ typedef struct typedef struct { - UINT8 buffer[4 * 1024 * 1024]; // 4 megs per frame should do + UINT8 buffer[16 * 1024 * 1024]; // 16 megs per frame should do } savestate_t; // Persistent storage/archiving. From a7b5df6793c55cd8fd3f28b9ff12dd4ff3bdad9f Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 22 Dec 2019 18:40:43 +0000 Subject: [PATCH 41/67] Stability fixes for steadyplayers Rail rings can now be delayed --- src/d_clisrv.c | 109 ++++++++++++++++++++++++++++++++++--------------- src/doomstat.h | 1 + src/g_game.c | 1 + src/p_enemy.c | 8 ++++ src/p_mobj.c | 6 --- src/p_saveg.c | 11 ++++- src/p_user.c | 14 +++++-- 7 files changed, 105 insertions(+), 45 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 0d5705e31..688c5191e 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5305,7 +5305,7 @@ static void AdjustSimulatedTiccmdInputs(ticcmd_t* cmds) SHORT oldAngle = cmds->angleturn; - if (gamestate == GS_LEVEL && cv_netsteadyplayers.value) + if (gamestate == GS_LEVEL && cv_netsteadyplayers.value && !cv_netslingdelay.value) CorrectPlayerTargeting(cmds); if (cmds->angleturn != oldAngle) @@ -5553,7 +5553,14 @@ void TryRunTics(tic_t realtics) { // Load the real state if it exists if (simtic != gametic && gameStateBufferIsValid[gametic % BACKUPTICS]) + { P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); + + if (Consistancy() != consistancy[gametic%BACKUPTICS]) + { + CONS_Printf("oops, consistency error, even I got that one!\n"); + } + } else if (simtic != gametic && !gameStateBufferIsValid[gametic % BACKUPTICS]) CONS_Printf("Problem: game state buffer inaccessible but a simulation happened!!\n"); @@ -5637,26 +5644,35 @@ static void RunSimulations() break; } - int targetSimTic = min(min(gametic + estimatedRTT - tastyFudge, smoothedTic + cv_simulatetics.value), simtic + MAXSIMULATIONS); - int numToSimulate = targetSimTic - (int)simtic; + int nextTargetSimTic = min(min(gametic + estimatedRTT - tastyFudge, smoothedTic + cv_simulatetics.value), simtic + MAXSIMULATIONS); + + if (nextTargetSimTic >= 0) + targetsimtic = nextTargetSimTic; + + int numToSimulate = targetsimtic - simtic; // record steadyplayers' real game position and their simulated position - for (int i = 0; i < MAXPLAYERS; i++) + if (numToSimulate > 0) { - if (playeringame[i] && players[i].mo && i != consoleplayer) + for (int i = 0; i < MAXPLAYERS; i++) { - if (simtic == smoothedTic) // this is their real position + if (playeringame[i] && players[i].mo && i != consoleplayer) { - steadyplayers[i].histx[0] = players[i].mo->x; - steadyplayers[i].histy[0] = players[i].mo->y; - steadyplayers[i].histz[0] = players[i].mo->z; - } - else - { - // restore the players' simulated position before simulating more - players[i].mo->x = steadyplayers[i].histx[simtic-smoothedTic]; - players[i].mo->y = steadyplayers[i].histy[simtic-smoothedTic]; - players[i].mo->z = steadyplayers[i].histz[simtic-smoothedTic]; + if (simtic == smoothedTic) // this is their real position + { + steadyplayers[i].histx[0] = players[i].mo->x; + steadyplayers[i].histy[0] = players[i].mo->y; + steadyplayers[i].histz[0] = players[i].mo->z; + } + else + { + P_UnsetThingPosition(players[i].mo); + // restore the players' simulated position before simulating more + players[i].mo->x = steadyplayers[i].histx[simtic - smoothedTic]; + players[i].mo->y = steadyplayers[i].histy[simtic - smoothedTic]; + players[i].mo->z = steadyplayers[i].histz[simtic - smoothedTic]; + P_SetThingPosition(players[i].mo); + } } } } @@ -5693,7 +5709,7 @@ static void RunSimulations() { if (playeringame[j] && players[j].mo && j != consoleplayer) { - // Update steadyplayers' simulated positions and move their game positions to their known one + // Update steadyplayers' simulated positions steadyplayers[j].histx[simtic - smoothedTic] = players[j].mo->x; steadyplayers[j].histy[simtic - smoothedTic] = players[j].mo->y; steadyplayers[j].histz[simtic - smoothedTic] = players[j].mo->z; @@ -5709,22 +5725,24 @@ static void RunSimulations() if (numToSimulate > 0) { int histIndex = max((int)(simtic - smoothedTic) - cv_netsteadyplayers.value, 0); // up to cv_netsteadyplayers.value behind the simulation - for (int j = 0; j < MAXPLAYERS; j++) + for (int i = 0; i < MAXPLAYERS; i++) { - if (playeringame[j] && players[j].mo && j != consoleplayer && !players[j].spectator) + if (playeringame[i] && players[i].mo && i != consoleplayer && !players[i].spectator) { // Set the player's positions to the preferred simulation index (or perhaps just their original position) // and store it in simx/simy/simz too for trails - players[j].mo->x = steadyplayers[j].histx[histIndex]; - players[j].mo->y = steadyplayers[j].histy[histIndex]; - players[j].mo->z = steadyplayers[j].histz[histIndex]; + P_UnsetThingPosition(players[i].mo); + players[i].mo->x = steadyplayers[i].histx[histIndex]; + players[i].mo->y = steadyplayers[i].histy[histIndex]; + players[i].mo->z = steadyplayers[i].histz[histIndex]; + P_SetThingPosition(players[i].mo); // fill any holes in the simulation history (due to frame skips) - for (int k = (int)max(lastsimtic + 1, (int)simtic - 5); k <= (int)simtic; k++) + for (int j = (int)max(lastsimtic + 1, (int)simtic - 5); j <= (int)simtic; j++) { - steadyplayers[j].simx[k % BACKUPTICS] = steadyplayers[j].histx[histIndex]; - steadyplayers[j].simy[k % BACKUPTICS] = steadyplayers[j].histy[histIndex]; - steadyplayers[j].simz[k % BACKUPTICS] = steadyplayers[j].histz[histIndex]; + steadyplayers[i].simx[j % BACKUPTICS] = steadyplayers[i].histx[histIndex]; + steadyplayers[i].simy[j % BACKUPTICS] = steadyplayers[i].histy[histIndex]; + steadyplayers[i].simz[j % BACKUPTICS] = steadyplayers[i].histz[histIndex]; } // Generate trails @@ -5735,12 +5753,12 @@ static void RunSimulations() for (int s = 0; s < trailLifetime; s++) { // If there is a big discrepency between the player's current position and their last one, spawn a trail showing their movements - fixed_t prevx = steadyplayers[j].simx[(simtic - s - 1) % BACKUPTICS], prevy = steadyplayers[j].simy[(simtic - s - 1) % BACKUPTICS], - prevz = steadyplayers[j].simz[(simtic - s - 1) % BACKUPTICS]; - fixed_t curx = steadyplayers[j].simx[(simtic - s) % BACKUPTICS], cury = steadyplayers[j].simy[(simtic - s) % BACKUPTICS], - curz = steadyplayers[j].simz[(simtic - s) % BACKUPTICS]; + fixed_t prevx = steadyplayers[i].simx[(simtic - s - 1) % BACKUPTICS], prevy = steadyplayers[i].simy[(simtic - s - 1) % BACKUPTICS], + prevz = steadyplayers[i].simz[(simtic - s - 1) % BACKUPTICS]; + fixed_t curx = steadyplayers[i].simx[(simtic - s) % BACKUPTICS], cury = steadyplayers[i].simy[(simtic - s) % BACKUPTICS], + curz = steadyplayers[i].simz[(simtic - s) % BACKUPTICS]; fixed_t distance = max(abs(curx - prevx), max(abs(cury - prevy), abs(curz - prevz))); - fixed_t stepDistance = 90 << FRACBITS; // distance between trail steps + fixed_t stepDistance = 60 << FRACBITS; // distance between trail steps fixed_t activationDistance = 60 << FRACBITS; // distance between trail steps // If player is changing direction quickly in a net simulation, create a ghost trail @@ -5752,7 +5770,7 @@ static void RunSimulations() for (currentStep = step; currentStep < (1 << FRACBITS); currentStep += step) { - mobj_t* ghost = P_SpawnGhostMobj(players[j].mo); + mobj_t* ghost = P_SpawnGhostMobj(players[i].mo); ghost->x = prevx + FixedMul(curx - prevx, currentStep); ghost->y = prevy + FixedMul(cury - prevy, currentStep); @@ -5766,10 +5784,23 @@ static void RunSimulations() } } - // move steadyplayer shields + // move steadyplayer shields and signs if (cv_netsteadyplayers.value) { mobj_t* mobj; + player_t* redflagplayer = NULL; + player_t* blueflagplayer = NULL; + + for (int i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + { + if (players[i].gotflag & GF_REDFLAG) + redflagplayer = &players[i]; + if (players[i].gotflag & GF_BLUEFLAG) + blueflagplayer = &players[i]; + } + } for (mobj = (mobj_t*)thlist[THINK_MOBJ].next; mobj != (mobj_t*)&thlist[THINK_MOBJ]; mobj = (mobj_t*)mobj->thinker.next) { @@ -5779,6 +5810,18 @@ static void RunSimulations() mobj->y = steadyplayers[mobj->target->player - players].histy[histIndex]; mobj->z = steadyplayers[mobj->target->player - players].histz[histIndex]; } + else if (mobj->type == MT_BLUEFLAG && blueflagplayer) + { + mobj->x += steadyplayers[blueflagplayer - players].histx[histIndex] - blueflagplayer->mo->x; + mobj->y += steadyplayers[blueflagplayer - players].histy[histIndex] - blueflagplayer->mo->y; + mobj->z += steadyplayers[blueflagplayer - players].histz[histIndex] - blueflagplayer->mo->z; + } + else if (mobj->type == MT_REDFLAG && redflagplayer) + { + mobj->x += steadyplayers[redflagplayer - players].histx[histIndex] - redflagplayer->mo->x; + mobj->y += steadyplayers[redflagplayer - players].histy[histIndex] - redflagplayer->mo->y; + mobj->z += steadyplayers[redflagplayer - players].histz[histIndex] - redflagplayer->mo->z; + } } } } diff --git a/src/doomstat.h b/src/doomstat.h index 03b97b17b..fd0792864 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -501,6 +501,7 @@ extern UINT32 timesBeatenWithEmeralds; extern tic_t gametic; extern tic_t simtic; // current tic at simulation, if applicable (if no simulation happened, this=gametic) +extern tic_t targetsimtic; // the target sim tic, if applicable extern tic_t smoothedTic; // current game tic when smoothing is enabled (\todo: could cause problems if the game objects care about gametic) #define localgametic leveltime diff --git a/src/g_game.c b/src/g_game.c index 284a69ba5..0639e1cae 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -117,6 +117,7 @@ INT32 displayplayers[MAXSPLITSCREENPLAYERS]; // view being displayed tic_t gametic; tic_t simtic; // simulated tic +tic_t targetsimtic; // target simulated tic tic_t smoothedTic; tic_t levelstarttic; // gametic at level start UINT32 totalrings; // for intermission diff --git a/src/p_enemy.c b/src/p_enemy.c index ee5a34876..7b80d248e 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -3769,6 +3769,14 @@ void A_ThrownRing(mobj_t *actor) INT32 stop; player_t *player; fixed_t dist; + + if (cv_netslingdelay.value && issimulation && (tic_t)cv_netsteadyplayers.value > simtic - gametic && actor->target == players[consoleplayer].mo) + { + // don't simulate ring weapons if netslingdelay is positive + actor->momx = actor->momy = actor->momz = 0; + return; + } + #ifdef HAVE_BLUA if (LUA_CallAction("A_ThrownRing", actor)) return; diff --git a/src/p_mobj.c b/src/p_mobj.c index 759eee0b2..ae06db7c9 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6369,12 +6369,6 @@ void P_MobjThinker(mobj_t *mobj) if ((mobj->flags & MF_BOSS) && mobj->spawnpoint && (bossdisabled & (1<spawnpoint->extrainfo))) return; - if (cv_netslingdelay.value && P_IsProjectile(mobj->type) && issimulation && (tic_t)cv_netsteadyplayers.value > simtic-gametic && mobj->target == players[consoleplayer].mo) - { - // don't simulate ring weapons if netslingdelay is positive - mobj->momx = mobj->momy = mobj->momz = 0; - } - // Remove dead target/tracer. if (mobj->target && P_MobjWasRemoved(mobj->target)) P_SetTarget(&mobj->target, NULL); diff --git a/src/p_saveg.c b/src/p_saveg.c index 991d24013..713300728 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3259,8 +3259,8 @@ typedef struct int thinkerListIndex; } mobjloclink_t; -#define HASHLOC(x, y, z) (((((x<<3)^(y>>6)*(z>>3)+(x>>15))^(y<<20)-(z>>17)+(x>>6))^x) & 0x7FFF) -#define MAXNUMMOBJSBYLOC 5 +#define HASHLOC(x, y, z) (((x>>4)-(y>>8)+(z>>12)-(x>>16)+(y>>20)-(z>>24)+(x>>28)-(y>>24)+(z>>20)-(x>>16)+(y>>8)-(z>>4)) & 0x7FFF) +#define MAXNUMMOBJSBYLOC 15 static void P_LocalUnArchiveThinkers() { @@ -3283,6 +3283,9 @@ static void P_LocalUnArchiveThinkers() memset(numMobjsByLoc, 0, sizeof(numMobjsByLoc)); memset(numthinkersbytype, 0, sizeof(numthinkersbytype)); + int hashHits = 0; + int hashMisses = 0; + if (READUINT32(save_p) != ARCHIVEBLOCK_THINKERS) I_Error("Bad SaveState at archive block Thinkers"); @@ -3371,9 +3374,13 @@ static void P_LocalUnArchiveThinkers() mobjByLoc[locHash][i] = mobjByLoc[locHash][numMobjsByLoc[locHash] - 1]; numMobjsByLoc[locHash]--; preservePositions = true; + hashHits++; break; } } + + if (newthinker == NULL) + hashMisses++; } // if that didn't work, find an existing thinker of the same type diff --git a/src/p_user.c b/src/p_user.c index 4f3011a65..7011168e6 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3376,10 +3376,16 @@ static void P_DoFiring(player_t *player, ticcmd_t *cmd) // SRB2kart - unused. mobj_t *mo = NULL; player->pflags |= PF_ATTACKDOWN; - //if (cmd->buttons & BT_FIRENORMAL) // No powers, just a regular ring. - // goto firenormal; //code repetition sucks. - // Bounce ring - if (player->currentweapon == WEP_BOUNCE && player->powers[pw_bouncering]) + if (mo) + { + if (mo->flags & MF_MISSILE && mo->flags2 & MF2_RAILRING) + { + if (cv_netslingdelay.value && issimulation && (tic_t)cv_netsteadyplayers.value > simtic - gametic && mo->target == players[consoleplayer].mo) + // don't fire it yet + return; + + const boolean nblockmap = !(mo->flags & MF_NOBLOCKMAP); + for (i = 0; i < 256; i++) { if (player->health <= 1) return; From afe57f1d0501ad97e147b57e810ff10837cc39ba Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 22 Dec 2019 20:00:18 +0000 Subject: [PATCH 42/67] Local sound effects play during simulations, other sound effects play during gametic --- src/d_clisrv.c | 16 ++-------------- src/s_sound.c | 5 ++++- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 688c5191e..bc7e5079f 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5518,7 +5518,6 @@ void TryRunTics(tic_t realtics) // record the actual local controls boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 1 && gametic >= BACKUPTICS; boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= BACKUPTICS && gametic >= BACKUPTICS && (cv_simulate.value && !server) && !resynch_local_inprogress; - boolean preserveSoundDisabled = sound_disabled; if (simtic > gametic && !canSimulate) { @@ -5533,9 +5532,6 @@ void TryRunTics(tic_t realtics) InvalidateSavestates(); } - if (canSimulate) - sound_disabled = true; - PerformDebugRewinds(); // record the actual local controls for this frame @@ -5557,9 +5553,7 @@ void TryRunTics(tic_t realtics) P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); if (Consistancy() != consistancy[gametic%BACKUPTICS]) - { CONS_Printf("oops, consistency error, even I got that one!\n"); - } } else if (simtic != gametic && !gameStateBufferIsValid[gametic % BACKUPTICS]) CONS_Printf("Problem: game state buffer inaccessible but a simulation happened!!\n"); @@ -5569,6 +5563,8 @@ void TryRunTics(tic_t realtics) { DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic)); + targetsimtic = gametic + 1; + G_Ticker((gametic % NEWTICRATERATIO) == 0); ExtraDataTicker(); gametic++; @@ -5614,10 +5610,7 @@ void TryRunTics(tic_t realtics) // Simulate the game locally if (canSimulate) - { RunSimulations(); - sound_disabled = preserveSoundDisabled; - } // we're gonna need more debugs... MakeNetDebugString(); @@ -5631,7 +5624,6 @@ static void RunSimulations() if (!gameStateBufferIsValid[gametic % BACKUPTICS]) return; // do not simulate if we cannot guarantee a recovery - boolean preserveSoundDisabled = sound_disabled; static int lastsimtic = 0; int tastyFudge = 0; @@ -5679,7 +5671,6 @@ static void RunSimulations() // simulate the rest o da future issimulation = true; - sound_disabled = true; con_muted = true; simStartTime = I_GetTimeUs(); @@ -5699,8 +5690,6 @@ static void RunSimulations() else netcmds[gametic % BACKUPTICS][consoleplayer] = localTicBuffer[(liveTic - estimatedRTT + i + 1 + BACKUPTICS) % BACKUPTICS]; - sound_disabled = (i != numToSimulate - 1); - G_Ticker(true); // tic a bunch of times lol see what happens lolol simtic++; @@ -5718,7 +5707,6 @@ static void RunSimulations() } issimulation = false; - sound_disabled = preserveSoundDisabled; con_muted = false; // Finalise steadyplayers diff --git a/src/s_sound.c b/src/s_sound.c index 936e3ced9..c391a91f4 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -451,6 +451,9 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) if (sound_disabled || !sound_started) return; + if (((simtic != targetsimtic - 1 && origin == listenmobj) || (origin != listenmobj && issimulation))) // local player sounds play immediately during simulations + return; + // Don't want a sound? Okay then... if (sfx_id == sfx_None) return; @@ -1237,7 +1240,7 @@ void S_DetachChannelsFromOrigin(void* origin) if (channels[i].origin == origin) { // small hack: player-made sounds should stay hearable - if (channels[i].origin != players[displayplayer].mo) + if (originmobj->player != &players[displayplayer]) { channels[i].isdetached = true; channels[i].detachedx = originmobj->x; From cf0475dd94f2ec1df4e953b815807a68d66fc58e Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 22 Dec 2019 21:54:03 +0000 Subject: [PATCH 43/67] Refined steadyplayer delayed rings --- src/d_clisrv.c | 29 ++++++++++++++--------------- src/p_enemy.c | 4 ++-- src/p_mobj.c | 8 ++++++++ src/p_user.c | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index bc7e5079f..3938226e7 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5779,6 +5779,14 @@ static void RunSimulations() player_t* redflagplayer = NULL; player_t* blueflagplayer = NULL; +#define ADJUSTPOSITION(obj, player) do { \ + P_UnsetThingPosition(obj); \ + obj->x += steadyplayers[player].histx[histIndex] - steadyplayers[player].histx[simtic - gametic]; \ + obj->y += steadyplayers[player].histy[histIndex] - steadyplayers[player].histy[simtic - gametic]; \ + obj->z += steadyplayers[player].histz[histIndex] - steadyplayers[player].histz[simtic - gametic]; \ + P_SetThingPosition(obj); \ +} while(0) + for (int i = 0; i < MAXPLAYERS; i++) { if (playeringame[i]) @@ -5788,28 +5796,19 @@ static void RunSimulations() if (players[i].gotflag & GF_BLUEFLAG) blueflagplayer = &players[i]; } + + if (players[i].followmobj) + ADJUSTPOSITION(players[i].followmobj, i); } for (mobj = (mobj_t*)thlist[THINK_MOBJ].next; mobj != (mobj_t*)&thlist[THINK_MOBJ]; mobj = (mobj_t*)mobj->thinker.next) { if (mobj->flags2 & MF2_SHIELD && mobj->target != NULL && mobj->target->player != NULL && mobj->target != players[consoleplayer].mo) - { - mobj->x = steadyplayers[mobj->target->player - players].histx[histIndex]; - mobj->y = steadyplayers[mobj->target->player - players].histy[histIndex]; - mobj->z = steadyplayers[mobj->target->player - players].histz[histIndex]; - } + ADJUSTPOSITION(mobj, mobj->target->player - players); else if (mobj->type == MT_BLUEFLAG && blueflagplayer) - { - mobj->x += steadyplayers[blueflagplayer - players].histx[histIndex] - blueflagplayer->mo->x; - mobj->y += steadyplayers[blueflagplayer - players].histy[histIndex] - blueflagplayer->mo->y; - mobj->z += steadyplayers[blueflagplayer - players].histz[histIndex] - blueflagplayer->mo->z; - } + ADJUSTPOSITION(mobj, blueflagplayer - players); else if (mobj->type == MT_REDFLAG && redflagplayer) - { - mobj->x += steadyplayers[redflagplayer - players].histx[histIndex] - redflagplayer->mo->x; - mobj->y += steadyplayers[redflagplayer - players].histy[histIndex] - redflagplayer->mo->y; - mobj->z += steadyplayers[redflagplayer - players].histz[histIndex] - redflagplayer->mo->z; - } + ADJUSTPOSITION(mobj, redflagplayer - players); } } } diff --git a/src/p_enemy.c b/src/p_enemy.c index 7b80d248e..e49a3baad 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -3770,9 +3770,9 @@ void A_ThrownRing(mobj_t *actor) player_t *player; fixed_t dist; - if (cv_netslingdelay.value && issimulation && (tic_t)cv_netsteadyplayers.value > simtic - gametic && actor->target == players[consoleplayer].mo) + if (cv_netslingdelay.value && issimulation && (tic_t)cv_netsteadyplayers.value >= targetsimtic - simtic && actor->target == players[consoleplayer].mo) { - // don't simulate ring weapons if netslingdelay is positive + // don't move ring weapons during simulation if netslingdelay is positive actor->momx = actor->momy = actor->momz = 0; return; } diff --git a/src/p_mobj.c b/src/p_mobj.c index ae06db7c9..e25073010 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -12884,6 +12884,7 @@ mobj_t *P_SPMAngle(mobj_t *source, mobjtype_t type, angle_t angle, UINT8 allowai angle_t an; fixed_t x, y, z, slope = 0; + // angle at which you fire, is player angle an = angle; @@ -12900,6 +12901,13 @@ mobj_t *P_SPMAngle(mobj_t *source, mobjtype_t type, angle_t angle, UINT8 allowai th = P_SpawnMobj(x, y, z, type); + if (cv_netslingdelay.value && issimulation && (tic_t)cv_netsteadyplayers.value >= targetsimtic - simtic && source == players[consoleplayer].mo) + { + z = 0x80000000; // don't make rings appear when using netslingdelay + th->flags |= MF_NOTHINK; + th->sprite = SPR_NULL; + } + if (source->eflags & MFE_VERTICALFLIP) th->flags2 |= MF2_OBJECTFLIP; diff --git a/src/p_user.c b/src/p_user.c index 7011168e6..4e22c9e97 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3380,7 +3380,7 @@ static void P_DoFiring(player_t *player, ticcmd_t *cmd) // SRB2kart - unused. { if (mo->flags & MF_MISSILE && mo->flags2 & MF2_RAILRING) { - if (cv_netslingdelay.value && issimulation && (tic_t)cv_netsteadyplayers.value > simtic - gametic && mo->target == players[consoleplayer].mo) + if (cv_netslingdelay.value && issimulation && (tic_t)cv_netsteadyplayers.value >= targetsimtic - simtic && mo->target == players[consoleplayer].mo) // don't fire it yet return; From 9c0f9b0637e72049eb47443882f3bda341a59ef4 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 23 Dec 2019 00:23:37 +0000 Subject: [PATCH 44/67] Fixed Linux compiler errors (hopefully lol) --- src/d_clisrv.c | 29 +++++------------------------ src/d_main.c | 2 +- src/sdl/i_system.c | 9 +++++++++ 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 3938226e7..445edcac7 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5203,8 +5203,8 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) { // find the most likely targeted player by measuring the angle between them steadyplayer_t* mostLikelyPlayer = NULL; - SHORT smallestDifference = 0x8000; - SHORT smallestVDifference = 0x8000; + INT16 smallestDifference = 0x8000; + INT16 smallestVDifference = 0x8000; fixed_t dist = 0; mobj_t* myself = players[consoleplayer].mo; int gameHist = max((int)(simtic-gametic) - cv_netsteadyplayers.value, 0); // current hist time that the players have been positioned at on the screen @@ -5216,8 +5216,8 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) if (playeringame[i] && players[i].mo && i != consoleplayer) { fixed_t curX = player->histx[gameHist], curY = player->histy[gameHist], curZ = player->histz[gameHist]; - SHORT difference = (SHORT)(FixedAngleBetween(myself->x, myself->y, curX, curY)>>FRACBITS) - cmds->angleturn; - SHORT vDifference = -(SHORT)(FixedAngleBetween(0, curZ, FixedDistance2(curX, curY, myself->x, myself->y), myself->z)>>FRACBITS) - cmds->aiming; + INT16 difference = (INT16)(FixedAngleBetween(myself->x, myself->y, curX, curY)>>FRACBITS) - cmds->angleturn; + INT16 vDifference = -(INT16)(FixedAngleBetween(0, curZ, FixedDistance2(curX, curY, myself->x, myself->y), myself->z)>>FRACBITS) - cmds->aiming; if (abs(difference) + abs(vDifference) < abs(smallestDifference) + abs(smallestVDifference)) { @@ -5303,7 +5303,7 @@ static void AdjustSimulatedTiccmdInputs(ticcmd_t* cmds) if (server || simtic == gametic) return; - SHORT oldAngle = cmds->angleturn; + INT16 oldAngle = cmds->angleturn; if (gamestate == GS_LEVEL && cv_netsteadyplayers.value && !cv_netslingdelay.value) CorrectPlayerTargeting(cmds); @@ -5979,16 +5979,6 @@ static void PerformDebugRewinds() } if (gameStateBufferIsValid[gametic % BACKUPTICS] && cv_debugsimulaterewind.value > 0 && players[consoleplayer].mo) { -/* sector_t initial = *((elevator_t*)thlist[1].next)->sector; - mobj_t initialPlayer = *players[consoleplayer].mo;*/ - - int xyz = 0; - mapthing_t spawnpoint; - if (redflag) { - xyz = redflag->spawnpoint->x + redflag->spawnpoint->y + redflag->spawnpoint->z; - spawnpoint = *(redflag->spawnpoint); - } - short consis = Consistancy(); for (int i = 0; i < cv_debugsimulaterewind.value; i++) @@ -5998,15 +5988,6 @@ static void PerformDebugRewinds() if (Consistancy() != consis) CONS_Printf("General consistency error...\n"); - - if (redflag) - if (redflag->spawnpoint->x + redflag->spawnpoint->y + redflag->spawnpoint->z != xyz && xyz != 0) - CONS_Printf("Flag consistency error!\n"); - - /*sector_t current = *((elevator_t*)thlist[1].next)->sector; - mobj_t currentPlayer = *players[consoleplayer].mo;*/ - - // consistency debug checks go here } } diff --git a/src/d_main.c b/src/d_main.c index d9b3b4e38..f1ecc3c82 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -604,7 +604,7 @@ static void D_Display(void) const char* nextStr = strstr(str + 1, "\n"); int len = nextStr ? nextStr - str : strlen(str); - strncpy(temp, str, len); + memcpy(temp, str, len); temp[len] = 0; V_DrawRightAlignedSmallString(BASEVIDWIDTH, y, V_YELLOWMAP, temp); diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 11dd06fe1..9445613ba 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -3042,6 +3042,15 @@ tic_t I_GetTime (void) if (!basetime) basetime = ticks; + // fudge the timer for better netgame sync + if (cv_timefudge.value != lastTimeFudge) + { + basetime = (basetime / (1000 / TICRATE) * (1000 / TICRATE)) - 1000 * cv_timefudge.value / 100 / TICRATE; + basetime -= 1000 / TICRATE; + + lastTimeFudge = cv_timefudge.value; + } + ticks -= basetime; ticks = (ticks*TICRATE); From 007094e6d201149d620e3b365d5a77a062fbc080 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 23 Dec 2019 00:27:30 +0000 Subject: [PATCH 45/67] More Linux fixes?? --- src/sdl/i_system.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 9445613ba..7f84c36f1 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2904,14 +2904,14 @@ ticcmd_t *I_BaseTiccmd4(void) return &emptycmd4; } +static int lastTimeFudge = -1; +extern consvar_t cv_timefudge; + #if defined (_WIN32) static HMODULE winmm = NULL; static DWORD starttickcount = 0; // hack for win2k time bug static p_timeGetTime pfntimeGetTime = NULL; static LARGE_INTEGER basetime = { {0, 0} }; -static int lastTimeFudge = -1; - -extern consvar_t cv_timefudge; // --------- // I_GetTime @@ -3059,6 +3059,11 @@ tic_t I_GetTime (void) return (tic_t)ticks; } + +UINT64 I_GetTimeUs(void) +{ + return (SDL_GetTicks() - basetime) * 1000; +} #endif // From acf1254494cafb846ed3d2b4ecdc2bb8f5671468 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 23 Dec 2019 00:33:29 +0000 Subject: [PATCH 46/67] Lol trying to fix all the Linux issues without a Linux compiler --- src/d_clisrv.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 445edcac7..acd0e5d46 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5205,7 +5205,6 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) steadyplayer_t* mostLikelyPlayer = NULL; INT16 smallestDifference = 0x8000; INT16 smallestVDifference = 0x8000; - fixed_t dist = 0; mobj_t* myself = players[consoleplayer].mo; int gameHist = max((int)(simtic-gametic) - cv_netsteadyplayers.value, 0); // current hist time that the players have been positioned at on the screen int simHist = simtic - gametic; // max simulated hist time @@ -5239,8 +5238,8 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) // distanceRatio increases/reduces the player's accuracy based on the distance change (e.g. big close Sonic to little faraway Sonic) fixed_t distanceRatio = FixedDiv(FixedDistance(myself->x, myself->y, myself->z, simX, simY, simZ), FixedDistance(myself->x, myself->y, myself->z, curX, curY, curZ)); - cmds->angleturn = (SHORT)(FixedAngleBetween(myself->x, myself->y, simX, simY) >> FRACBITS) - FixedDiv(smallestDifference, distanceRatio); - cmds->aiming = -(SHORT)(FixedAngleBetween(0, simZ, FixedDistance2(simX, simY, myself->x, myself->y), myself->z) >> FRACBITS) - + cmds->angleturn = (INT16)(FixedAngleBetween(myself->x, myself->y, simX, simY) >> FRACBITS) - FixedDiv(smallestDifference, distanceRatio); + cmds->aiming = -(INT16)(FixedAngleBetween(0, simZ, FixedDistance2(simX, simY, myself->x, myself->y), myself->z) >> FRACBITS) - FixedDiv(smallestVDifference, distanceRatio); } else @@ -5253,8 +5252,8 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) tic_t wowtic = min(gametic, simtic - cv_netsteadyplayers.value); fixed_t originalDistance = FixedDistance(myself->x, myself->y, myself->z, enemyX, enemyY, enemyZ); fixed_t currentDistance = originalDistance; - SHORT difference = 0; - SHORT vDifference = 0; + INT16 difference = 0; + INT16 vDifference = 0; while (ringRadius < currentDistance) { @@ -5279,8 +5278,8 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) if (ringRadius + (60<= currentDistance && difference == 0 && vDifference == 0) { // capture the player's current angle offset/accuracy here - difference = (SHORT)(FixedAngleBetween(myself->x, myself->y, enemyX, enemyY) >> FRACBITS) - cmds->angleturn; - vDifference = -(SHORT)(FixedAngleBetween(0, enemyZ, + difference = (INT16)(FixedAngleBetween(myself->x, myself->y, enemyX, enemyY) >> FRACBITS) - cmds->angleturn; + vDifference = -(INT16)(FixedAngleBetween(0, enemyZ, FixedDistance2(enemyX, enemyY, myself->x, myself->y), myself->z) >> FRACBITS) - cmds->aiming; } From 1e2ddebced29f78773cd11d3f513d79c21de5047 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 23 Dec 2019 00:42:21 +0000 Subject: [PATCH 47/67] Last couple of Linux fixes hopefully --- src/d_clisrv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index acd0e5d46..be9e0ef91 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5246,7 +5246,7 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) { // other rings are a bit more complex, we want to guess where the enemy will be and use that angle offset instead. // calculate the player's new position and try to aim towards that - int ringSpeed = mobjinfo[MT_REDRING].speed>>FRACBITS; + fixed_t ringSpeed = mobjinfo[MT_REDRING].speed>>FRACBITS; fixed_t ringRadius = -(60<x, myself->y), myself->z) >> FRACBITS) - cmds->aiming; } - ringRadius += 60<angleturn = (SHORT)(FixedAngleBetween(myself->x, myself->y, enemyX, enemyY)>>FRACBITS) - FixedDiv(difference, distanceRatio); - cmds->aiming = -(SHORT)(FixedAngleBetween(0, enemyZ, FixedDistance2(enemyX, enemyY, myself->x, myself->y), myself->z) >> FRACBITS) - FixedDiv(vDifference, distanceRatio); + cmds->angleturn = (INT16)(FixedAngleBetween(myself->x, myself->y, enemyX, enemyY)>>FRACBITS) - FixedDiv(difference, distanceRatio); + cmds->aiming = -(INT16)(FixedAngleBetween(0, enemyZ, FixedDistance2(enemyX, enemyY, myself->x, myself->y), myself->z) >> FRACBITS) - FixedDiv(vDifference, distanceRatio); } } } From 0ddbaeb2a2655eccef307cc1531744b8f3c6bacf Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 23 Dec 2019 00:42:50 +0000 Subject: [PATCH 48/67] One more thing to unbreak --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index be9e0ef91..2e4cdf668 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5246,7 +5246,7 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) { // other rings are a bit more complex, we want to guess where the enemy will be and use that angle offset instead. // calculate the player's new position and try to aim towards that - fixed_t ringSpeed = mobjinfo[MT_REDRING].speed>>FRACBITS; + fixed_t ringSpeed = mobjinfo[MT_REDRING].speed; fixed_t ringRadius = -(60< Date: Mon, 23 Dec 2019 00:45:22 +0000 Subject: [PATCH 49/67] HEY YOU MISSED A SPOT --- src/sdl/i_system.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 7f84c36f1..55fbe095f 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -3034,10 +3034,11 @@ static void I_ShutdownTimer(void) // I_GetTime // returns time in 1/TICRATE second tics // +static Uint64 basetime = 0; + tic_t I_GetTime (void) { - static Uint64 basetime = 0; - Uint64 ticks = SDL_GetTicks(); + Uint64 ticks = SDL_GetTicks(); if (!basetime) basetime = ticks; From 13d4f9e7d719a05e337edb4c971333a057435ff1 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 17 Jan 2020 19:54:12 +0000 Subject: [PATCH 50/67] * Fixed chasecam during simulations! --- src/p_saveg.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/p_saveg.c b/src/p_saveg.c index 713300728..642f20ea6 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -4436,6 +4436,36 @@ static inline boolean P_NetUnArchiveMisc(boolean preserveLevel) // SRB2kart numgotboxes = READINT32(save_p); + // Is it paused? + if (READUINT8(save_p) == 0x2f) + paused = true; + + return true; +} + +static inline void P_LocalArchiveCameras() +{ + WRITEMEM(save_p, &camera, sizeof(camera)); + WRITEMEM(save_p, &camera2, sizeof(camera2)); +} + +static inline void P_LocalUnArchiveCameras() +{ + boolean chase1 = camera.chase; + boolean chase2 = camera2.chase; + + // this makes things easy! + READMEM(save_p, &camera, sizeof(camera)); + READMEM(save_p, &camera2, sizeof(camera2)); + + // chase is changed outside of tics, so preserve this + camera.chase = chase1; + camera2.chase = chase2; +} + +static inline void P_ArchiveLuabanksAndConsistency(void) +{ + UINT8 i, banksinuse = NUM_LUABANKS; gamespeed = READUINT8(save_p); franticitems = (boolean)READUINT8(save_p); @@ -4623,6 +4653,8 @@ void P_SaveGameState(savestate_t* savestate) #endif P_LocalArchiveThinkers(); P_NetArchiveSpecials(); + P_LocalArchiveCameras(); + #ifdef HAVE_BLUA LUA_Archive(); #endif @@ -4654,6 +4686,7 @@ boolean P_LoadGameState(const savestate_t* savestate) #endif P_LocalUnArchiveThinkers(); P_NetUnArchiveSpecials(); + P_LocalUnArchiveCameras(); #ifdef HAVE_BLUA LUA_UnArchive(); From 2f57137d114809c653065d4cf0f9e4275fe08575 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 17 Jan 2020 23:27:17 +0000 Subject: [PATCH 51/67] * New time fudge * Some timer fixes --- src/d_clisrv.c | 92 +++------------------------------------------- src/d_netcmd.c | 67 ++++++++++++++++++++++++++++++--- src/sdl/i_system.c | 21 ++++++++--- 3 files changed, 82 insertions(+), 98 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 2e4cdf668..1ea770a2f 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5438,16 +5438,7 @@ int minLiveTicOffset; int smoothingDelay; UINT64 saveStateBenchmark = 0; UINT64 loadStateBenchmark = 0; - -#define MAXAUTOFUDGERTT 20 - -boolean autotimefudge; -UINT8 autotimefudgetime = 0; -UINT16 autotimefudgesamples = 0; -UINT16 autotimefudgedata[MAXAUTOFUDGERTT]; -float autotimefudgemeans[10]; -float autotimefudgedeviations[10]; -int autotimefudgeattempts = 0; +int netUpdateFudge; // our last net update fudge #define MAXOFFSETHISTORY 35 int ticTimeOffsetHistory[MAXOFFSETHISTORY]; @@ -5479,6 +5470,10 @@ void TryRunTics(tic_t realtics) D_MapChange(-1, 0, encoremode, false, 2, false, fromlevelselect); // finish the map change } + // Get packets from the server + unsigned long long int frame = (I_GetTimeUs() * NEWTICRATE / 1000000); + netUpdateFudge = (I_GetTimeUs() - frame * 1000000 / NEWTICRATE) * 100 * NEWTICRATE / 1000000; // record the timefudge where the net update typically occurs + NetUpdate(); if (demo.playback) @@ -5883,83 +5878,6 @@ void DetermineNetConditions() } rttJitter = maxRTT - minRTT; - - // auto time fudge - int maxautotimefudgesamples = 10; - static int numignoredtimefudgesamples = 5; - if (autotimefudge) - { - CV_SetValue(&cv_timefudge, autotimefudgetime); - - if (estimatedRTT < MAXAUTOFUDGERTT) - { - if (numignoredtimefudgesamples > 0) - numignoredtimefudgesamples--; - else - { - autotimefudgedata[estimatedRTT]++; - autotimefudgesamples++; - } - } - - if (autotimefudgesamples >= maxautotimefudgesamples) - { - // calculate standard deviation of this time fudge - float mean = 0; - for (int i = 0; i < MAXAUTOFUDGERTT; i++) - { - mean += autotimefudgedata[i] * i; - } - mean /= maxautotimefudgesamples; - - float differences = 0; - for (int i = 0; i < MAXAUTOFUDGERTT; i++) - { - if (autotimefudgedata[i] > 0) - differences += ((i - mean) * (i - mean)) * autotimefudgedata[i]; - } - differences /= maxautotimefudgesamples; - - autotimefudgemeans[autotimefudgetime / 10] = mean; - autotimefudgedeviations[autotimefudgetime / 10] = differences; - - CONS_Printf("Fudge %d: mean %f deviation %f\n", autotimefudgetime, mean, differences); - - // reset and test the next time fudge - autotimefudgesamples = 0; - numignoredtimefudgesamples = maxRTT + 2; - - for (int i = 0; i < MAXAUTOFUDGERTT; i++) - autotimefudgedata[i] = 0; - - if (differences < 2.0f) - autotimefudgetime = autotimefudgetime + 10; - else - CONS_Printf("Retrying...\n"); // too much deviation, try again - - if (autotimefudgetime >= 100) - { - // done! - // the best time is where the deviation is minimal; this can be achieved by going halfway from the worst point - int worstFudgeTime = 0; - float worstDeviation = 0.0f; - - for (int i = 0; i < 10; i++) - { - if (autotimefudgedeviations[i] > worstDeviation) - { - worstDeviation = autotimefudgedeviations[i]; - worstFudgeTime = i * 10; - } - } - - CONS_Printf("Auto timefudge: Setting time fudge to %d\n", (worstFudgeTime + 50) % 100); - autotimefudge = false; - - CV_SetValue(&cv_timefudge, (worstFudgeTime + 50) % 100); - } - } - } } static void PerformDebugRewinds() diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 80c63ed01..49ded26e2 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -846,15 +846,70 @@ static void Command_Saveloadtest(void) memleak = false; } -extern boolean autotimefudge; -extern UINT8 autotimefudgetime; +#include "i_net.h" + +extern int netUpdateFudge; static void Command_Autotimefudge(void) { - if (!autotimefudge) + UINT64 startTime = I_GetTimeUs(); + static UINT64 packetTimeFudge[512]; + int numReceivedPackets = 0; + int numSampleTics = 14; + int i; + + if (server) { - CONS_Printf("Searching for the best time fudge...\n"); - autotimefudge = true; - autotimefudgetime = 0; + CONS_Printf("Servers do not need a time fudge! Heck, why are you hosting with this exe anyway? You don't need to ;)\n"); + return; + } + + // New experimental version! Run a precise while loop that picks up packets instantly + while (I_GetTimeUs() - startTime < ((UINT64)numSampleTics * 1000000 / NEWTICRATE)) + { + I_NetGet(); + if (doomcom->remotenode != -1 && I_GetTimeUs() - startTime > (unsigned long long)2*1000000/NEWTICRATE) // wait a couple frames before recording + { + unsigned long long frame = I_GetTimeUs() * NEWTICRATE / 1000000; + packetTimeFudge[numReceivedPackets++] = (I_GetTimeUs() - frame * 1000000 / NEWTICRATE) * 100 * NEWTICRATE / 1000000 + - netUpdateFudge; // gets the time fudge offset (0-100) + } + } + + if (numReceivedPackets > 0) + { + int minOffset = 100, maxOffset = 0, averageOffset = 0; + int newTimeFudge; + int estimatedRange; + + for (i = 0; i < numReceivedPackets; i++) + { + minOffset = min(minOffset, packetTimeFudge[i]); + maxOffset = max(maxOffset, packetTimeFudge[i]); + } + + if (maxOffset - minOffset > 50) + { + // say maxOffset = 90 and minOffset = 20, we want the average to be 30... + maxOffset = maxOffset - 100; + + if (minOffset > maxOffset) + { + int swap = maxOffset; + maxOffset = minOffset; + minOffset = swap; + } + } + + estimatedRange = maxOffset - minOffset; + averageOffset = (maxOffset + minOffset) / 2; + + CONS_Printf("%i packets, min: %d max: %d avg: %d est. range: %d (mynetupdate: %i)\n", numReceivedPackets, minOffset, maxOffset, averageOffset, + estimatedRange, netUpdateFudge); + + newTimeFudge = (cv_timefudge.value + averageOffset + 50) % 100; + CONS_Printf("New time fudge: %i%%\n", newTimeFudge); + + CV_SetValue(&cv_timefudge, newTimeFudge); } } diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 55fbe095f..533c6661b 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2956,18 +2956,29 @@ tic_t I_GetTime(void) else newtics = (GetTickCount() - starttickcount)/(1000/NEWTICRATE); - // fudge the timer to sync better with online games if (cv_timefudge.value != lastTimeFudge) { if (frequency.QuadPart) { - basetime.QuadPart = (basetime.QuadPart / (frequency.QuadPart / TICRATE) * (frequency.QuadPart / TICRATE)) - frequency.QuadPart * cv_timefudge.value / 100 / TICRATE; - basetime.QuadPart -= frequency.QuadPart / TICRATE; // never go back in time if timefudge reduces + unsigned long long frame = basetime.QuadPart * NEWTICRATE / frequency.QuadPart; + + if (cv_timefudge.value > lastTimeFudge) + { + frame--; // do not allow the same tic to play twice + } + + basetime.QuadPart = frame * frequency.QuadPart / NEWTICRATE + frequency.QuadPart * cv_timefudge.value / TICRATE / 100; } if (starttickcount) { - starttickcount = (starttickcount / (1000 / TICRATE) * (1000 / TICRATE)) - 1000 * cv_timefudge.value / 100 / TICRATE; - starttickcount -= 1000 / TICRATE; + unsigned long long frame = starttickcount * NEWTICRATE / 1000; + + if (cv_timefudge.value > lastTimeFudge) + { + frame--; // do not allow the same tic to play twice + } + + starttickcount = (DWORD)(frame * 1000 / NEWTICRATE + 1000 * cv_timefudge.value / TICRATE / 100); } lastTimeFudge = cv_timefudge.value; From 0c864503a39997b0aab235fcc792f957097e18ca Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 17 Jan 2020 23:30:57 +0000 Subject: [PATCH 52/67] * and better time fudges for Linux, hopefully --- src/sdl/i_system.c | 1034 +++----------------------------------------- 1 file changed, 65 insertions(+), 969 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 533c6661b..e5b4e1b66 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -5,7 +5,7 @@ // // Copyright (C) 1993-1996 by id Software, Inc. // Portions Copyright (C) 1998-2000 by DooM Legacy Team. -// Copyright (C) 2014-2018 by Sonic Team Junior. +// Copyright (C) 2014-2019 by Sonic Team Junior. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -131,26 +131,25 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #include #endif -// Locations for searching the srb2.srb +// Locations for searching the srb2.pk3 #if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) -#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2Kart" -#define DEFAULTWADLOCATION2 "/usr/local/games/SRB2Kart" -#define DEFAULTWADLOCATION3 "/usr/share/games/SRB2Kart" -#define DEFAULTWADLOCATION4 "/usr/games/SRB2Kart" +#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2" +#define DEFAULTWADLOCATION2 "/usr/local/games/SRB2" +#define DEFAULTWADLOCATION3 "/usr/share/games/SRB2" +#define DEFAULTWADLOCATION4 "/usr/games/SRB2" #define DEFAULTSEARCHPATH1 "/usr/local/games" #define DEFAULTSEARCHPATH2 "/usr/games" #define DEFAULTSEARCHPATH3 "/usr/local" #elif defined (_WIN32) -#define DEFAULTWADLOCATION1 "c:\\games\\srb2kart" -#define DEFAULTWADLOCATION2 "\\games\\srb2kart" +#define DEFAULTWADLOCATION1 "c:\\games\\srb2" +#define DEFAULTWADLOCATION2 "\\games\\srb2" #define DEFAULTSEARCHPATH1 "c:\\games" #define DEFAULTSEARCHPATH2 "\\games" #endif /** \brief WAD file to look for */ -#define WADKEYWORD1 "srb2.srb" -#define WADKEYWORD2 "srb2.wad" +#define WADKEYWORD1 "srb2.pk3" /** \brief holds wad path */ static char returnWadPath[256]; @@ -216,26 +215,10 @@ SDLJoyInfo_t JoyInfo; */ static INT32 joystick2_started = 0; -/** \brief SDL info about joystick 2 +/** \brief SDL inof about joystick 2 */ SDLJoyInfo_t JoyInfo2; -/** \brief Third joystick up and running -*/ -static INT32 joystick3_started = 0; - -/** \brief SDL info about joystick 3 -*/ -SDLJoyInfo_t JoyInfo3; - -/** \brief Fourth joystick up and running -*/ -static INT32 joystick4_started = 0; - -/** \brief SDL info about joystick 4 -*/ -SDLJoyInfo_t JoyInfo4; - #ifdef HAVE_TERMIOS static INT32 fdmouse2 = -1; static INT32 mouse2_started = 0; @@ -547,7 +530,7 @@ static void Impl_HandleKeyboardConsoleEvent(KEY_EVENT_RECORD evt, HANDLE co) break; case VK_RETURN: entering_con_command = false; - // Fall through. + /* FALLTHRU */ default: event.data1 = MapVirtualKey(evt.wVirtualKeyCode,2); // convert in to char } @@ -625,7 +608,7 @@ static void I_StartupConsole(void) if (gotConsole) { - SetConsoleTitleA("SRB2Kart Console"); + SetConsoleTitleA("SRB2 Console"); consolevent = SDL_TRUE; } @@ -693,7 +676,7 @@ void I_StartupKeyboard (void) void I_OutputMsg(const char *fmt, ...) { size_t len; - XBOXSTATIC char txt[8192]; + char txt[8192]; va_list argptr; va_start(argptr,fmt); @@ -844,18 +827,6 @@ void I_JoyScale2(void) JoyInfo2.scale = Joystick2.bGamepadStyle?1:cv_joyscale2.value; } -void I_JoyScale3(void) -{ - Joystick3.bGamepadStyle = cv_joyscale3.value==0; - JoyInfo3.scale = Joystick3.bGamepadStyle?1:cv_joyscale3.value; -} - -void I_JoyScale4(void) -{ - Joystick4.bGamepadStyle = cv_joyscale4.value==0; - JoyInfo4.scale = Joystick4.bGamepadStyle?1:cv_joyscale4.value; -} - // Cheat to get the device index for a joystick handle INT32 I_GetJoystickDeviceIndex(SDL_Joystick *dev) { @@ -866,210 +837,13 @@ INT32 I_GetJoystickDeviceIndex(SDL_Joystick *dev) SDL_Joystick *test = SDL_JoystickOpen(i); if (test && test == dev) return i; - else if (JoyInfo.dev != test && JoyInfo2.dev != test && JoyInfo3.dev != test && JoyInfo4.dev != test) + else if (JoyInfo.dev != test && JoyInfo2.dev != test) SDL_JoystickClose(test); } return -1; } -// Misleading function: updates device indices for all players BUT the one specified. -// Necessary for SDL_JOYDEVICEADDED events -void I_UpdateJoystickDeviceIndices(INT32 player) -{ - if (player != 1) // This is a fucking mess. - { - ////////////////////////////// - // update joystick 1's device index - ////////////////////////////// - - if (JoyInfo.dev) - cv_usejoystick.value = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; - // is cv_usejoystick used? - else if (// don't check JoyInfo or cv_usejoystick; we're currently operating on those - atoi(cv_usejoystick.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick2.value - && atoi(cv_usejoystick.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick3.value - && atoi(cv_usejoystick.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick4.value) - cv_usejoystick.value = atoi(cv_usejoystick.string); - // is cv_usejoystick2 used? - else if ( // don't check JoyInfo or cv_usejoystick; we're currently operating on those - atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick2.value - && atoi(cv_usejoystick2.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick3.value - && atoi(cv_usejoystick2.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick4.value) - cv_usejoystick.value = atoi(cv_usejoystick2.string); - // is cv_usejoystick3 used? - else if (// don't check JoyInfo or cv_usejoystick; we're currently operating on those - atoi(cv_usejoystick3.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick2.value - && atoi(cv_usejoystick3.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick3.value - && atoi(cv_usejoystick3.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick4.value) - cv_usejoystick.value = atoi(cv_usejoystick3.string); - // is cv_usejoystick4 used? - else if (// don't check JoyInfo or cv_usejoystick; we're currently operating on those - atoi(cv_usejoystick4.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick2.value - && atoi(cv_usejoystick4.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick3.value - && atoi(cv_usejoystick4.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick4.value) - cv_usejoystick.value = atoi(cv_usejoystick4.string); - else // we tried... - cv_usejoystick.value = 0; - } - - if (player != 2) - { - ////////////////////////////// - // update joystick 2's device index - ////////////////////////////// - - if (JoyInfo2.dev) - cv_usejoystick2.value = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; - // is cv_usejoystick2 used? - else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick.value - // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those - && atoi(cv_usejoystick2.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick3.value - && atoi(cv_usejoystick2.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick4.value) - cv_usejoystick2.value = atoi(cv_usejoystick2.string); - // is cv_usejoystick used? - else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick.value - // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those - && atoi(cv_usejoystick.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick3.value - && atoi(cv_usejoystick.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick4.value) - cv_usejoystick2.value = atoi(cv_usejoystick.string); - // is cv_usejoystick3 used? - else if (atoi(cv_usejoystick3.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick.value - // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those - && atoi(cv_usejoystick3.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick3.value - && atoi(cv_usejoystick3.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick4.value) - cv_usejoystick2.value = atoi(cv_usejoystick3.string); - // is cv_usejoystick4 used? - else if (atoi(cv_usejoystick4.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick.value - // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those - && atoi(cv_usejoystick4.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick3.value - && atoi(cv_usejoystick4.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick4.value) - cv_usejoystick2.value = atoi(cv_usejoystick4.string); - else // we tried... - cv_usejoystick2.value = 0; - } - - if (player != 3) - { - ////////////////////////////// - // update joystick 3's device index - ////////////////////////////// - - if (JoyInfo3.dev) - cv_usejoystick3.value = I_GetJoystickDeviceIndex(JoyInfo3.dev) + 1; - // is cv_usejoystick3 used? - else if (atoi(cv_usejoystick3.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick.value - && atoi(cv_usejoystick3.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick2.value - // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those - && atoi(cv_usejoystick3.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick4.value) - cv_usejoystick3.value = atoi(cv_usejoystick3.string); - // is cv_usejoystick used? - else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick.value - && atoi(cv_usejoystick.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick2.value - // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those - && atoi(cv_usejoystick.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick4.value) - cv_usejoystick3.value = atoi(cv_usejoystick.string); - // is cv_usejoystick2 used? - else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick.value - && atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick2.value - // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those - && atoi(cv_usejoystick2.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick4.value) - cv_usejoystick3.value = atoi(cv_usejoystick2.string); - // is cv_usejoystick4 used? - else if (atoi(cv_usejoystick4.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick.value - && atoi(cv_usejoystick4.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick2.value - // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those - && atoi(cv_usejoystick4.string) != JoyInfo4.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick4.value) - cv_usejoystick3.value = atoi(cv_usejoystick4.string); - else // we tried... - cv_usejoystick3.value = 0; - } - - if (player != 4) - { - ////////////////////////////// - // update joystick 4's device index - ////////////////////////////// - - if (JoyInfo4.dev) - cv_usejoystick4.value = I_GetJoystickDeviceIndex(JoyInfo4.dev) + 1; - // is cv_usejoystick4 used? - else if (atoi(cv_usejoystick4.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick.value - && atoi(cv_usejoystick4.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick2.value - && atoi(cv_usejoystick4.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick4.string) != cv_usejoystick3.value) - // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those - cv_usejoystick4.value = atoi(cv_usejoystick4.string); - // is cv_usejoystick used? - else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick.value - && atoi(cv_usejoystick.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick2.value - && atoi(cv_usejoystick.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick3.value) - // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those - cv_usejoystick4.value = atoi(cv_usejoystick.string); - // is cv_usejoystick2 used? - else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick.value - && atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick2.value - && atoi(cv_usejoystick2.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick3.value) - // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those - cv_usejoystick4.value = atoi(cv_usejoystick2.string); - // is cv_usejoystick3 used? - else if (atoi(cv_usejoystick3.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick.value - && atoi(cv_usejoystick3.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick2.value - && atoi(cv_usejoystick3.string) != JoyInfo3.oldjoy - && atoi(cv_usejoystick3.string) != cv_usejoystick3.value) - // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those - cv_usejoystick4.value = atoi(cv_usejoystick3.string); - else // we tried... - cv_usejoystick4.value = 0; - } -} - /** \brief Joystick 1 buttons states */ static UINT64 lastjoybuttons = 0; @@ -1612,548 +1386,6 @@ static int joy_open2(int joyindex) } } -//Joystick3 - -/** \brief Joystick 3 buttons states -*/ -static UINT64 lastjoy3buttons = 0; - -/** \brief Joystick 3 hats state -*/ -static UINT64 lastjoy3hats = 0; - -/** \brief Shuts down joystick 3 - - -\return void -*/ -void I_ShutdownJoystick3(void) -{ - INT32 i; - event_t event; - event.type = ev_keyup; - event.data2 = 0; - event.data3 = 0; - - lastjoy3buttons = lastjoy3hats = 0; - - // emulate the up of all joystick buttons - for (i = 0; i < JOYBUTTONS; i++) - { - event.data1 = KEY_3JOY1 + i; - D_PostEvent(&event); - } - - // emulate the up of all joystick hats - for (i = 0; i < JOYHATS*4; i++) - { - event.data1 = KEY_3HAT1 + i; - D_PostEvent(&event); - } - - // reset joystick position - event.type = ev_joystick3; - for (i = 0; i < JOYAXISSET; i++) - { - event.data1 = i; - D_PostEvent(&event); - } - - joystick3_started = 0; - JoyReset(&JoyInfo3); - - // don't shutdown the subsystem here, because hotplugging -} - -void I_GetJoystick3Events(void) -{ - static event_t event = {0,0,0,0}; - INT32 i = 0; - UINT64 joyhats = 0; -#if 0 - INT64 joybuttons = 0; -#endif - INT32 axisx, axisy; - - if (!joystick3_started) - return; - - if (!JoyInfo3.dev) //I_ShutdownJoystick3(); - return; - - -#if 0 - //faB: look for as much buttons as g_input code supports, - // we don't use the others - for (i = JoyInfo3.buttons - 1; i >= 0; i--) - { - joybuttons <<= 1; - if (SDL_JoystickGetButton(JoyInfo3.dev,i)) - joybuttons |= 1; - } - - if (joybuttons != lastjoy3buttons) - { - INT64 j = 1; // keep only bits that changed since last time - INT64 newbuttons = joybuttons ^ lastjoy3buttons; - lastjoy3buttons = joybuttons; - - for (i = 0; i < JOYBUTTONS; i++, j <<= 1) - { - if (newbuttons & j) // button changed state? - { - if (joybuttons & j) - event.type = ev_keydown; - else - event.type = ev_keyup; - event.data1 = KEY_3JOY1 + i; - D_PostEvent(&event); - } - } - } -#endif - - for (i = JoyInfo3.hats - 1; i >= 0; i--) - { - Uint8 hat = SDL_JoystickGetHat(JoyInfo3.dev, i); - - if (hat & SDL_HAT_UP ) joyhats|=(UINT64)0x1<<(0 + 4*i); - if (hat & SDL_HAT_DOWN ) joyhats|=(UINT64)0x1<<(1 + 4*i); - if (hat & SDL_HAT_LEFT ) joyhats|=(UINT64)0x1<<(2 + 4*i); - if (hat & SDL_HAT_RIGHT) joyhats|=(UINT64)0x1<<(3 + 4*i); - } - - if (joyhats != lastjoy3hats) - { - INT64 j = 1; // keep only bits that changed since last time - INT64 newhats = joyhats ^ lastjoy3hats; - lastjoy3hats = joyhats; - - for (i = 0; i < JOYHATS*4; i++, j <<= 1) - { - if (newhats & j) // hat changed state? - { - if (joyhats & j) - event.type = ev_keydown; - else - event.type = ev_keyup; - event.data1 = KEY_3HAT1 + i; - D_PostEvent(&event); - } - } - } - - // send joystick axis positions - event.type = ev_joystick3; - - for (i = JOYAXISSET - 1; i >= 0; i--) - { - event.data1 = i; - if (i*2 + 1 <= JoyInfo3.axises) - axisx = SDL_JoystickGetAxis(JoyInfo3.dev, i*2 + 0); - else axisx = 0; - if (i*2 + 2 <= JoyInfo3.axises) - axisy = SDL_JoystickGetAxis(JoyInfo3.dev, i*2 + 1); - else axisy = 0; - - // -32768 to 32767 - axisx = axisx/32; - axisy = axisy/32; - - if (Joystick3.bGamepadStyle) - { - // gamepad control type, on or off, live or die - if (axisx < -(JOYAXISRANGE/2)) - event.data2 = -1; - else if (axisx > (JOYAXISRANGE/2)) - event.data2 = 1; - else - event.data2 = 0; - if (axisy < -(JOYAXISRANGE/2)) - event.data3 = -1; - else if (axisy > (JOYAXISRANGE/2)) - event.data3 = 1; - else - event.data3 = 0; - } - else - { - - axisx = JoyInfo3.scale?((axisx/JoyInfo3.scale)*JoyInfo3.scale):axisx; - axisy = JoyInfo3.scale?((axisy/JoyInfo3.scale)*JoyInfo3.scale):axisy; - -#ifdef SDL_JDEADZONE - if (-SDL_JDEADZONE <= axisx && axisx <= SDL_JDEADZONE) axisx = 0; - if (-SDL_JDEADZONE <= axisy && axisy <= SDL_JDEADZONE) axisy = 0; -#endif - - // analog control style , just send the raw data - event.data2 = axisx; // x axis - event.data3 = axisy; // y axis - } - D_PostEvent(&event); - } - -} - -/** \brief Open joystick handle - - \param fname name of joystick - - \return axises - - -*/ -static int joy_open3(int joyindex) -{ - SDL_Joystick *newdev = NULL; - int num_joy = 0; - - if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) - { - CONS_Printf(M_GetText("Joystick subsystem not started\n")); - return -1; - } - - if (joyindex <= 0) - return -1; - - num_joy = SDL_NumJoysticks(); - - if (num_joy == 0) - { - CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); - return -1; - } - - newdev = SDL_JoystickOpen(joyindex - 1); - - // Handle the edge case where the device <-> joystick index assignment can change due to hotplugging - // This indexing is SDL's responsibility and there's not much we can do about it. - // - // Example: - // 1. Plug Controller A -> Index 0 opened - // 2. Plug Controller B -> Index 1 opened - // 3. Unplug Controller A -> Index 0 closed, Index 1 active - // 4. Unplug Controller B -> Index 0 inactive, Index 1 closed - // 5. Plug Controller B -> Index 0 opened - // 6. Plug Controller A -> Index 0 REPLACED, opened as Controller A; Index 1 is now Controller B - if (JoyInfo3.dev) - { - if (JoyInfo3.dev == newdev // same device, nothing to do - || (newdev == NULL && SDL_JoystickGetAttached(JoyInfo3.dev))) // we failed, but already have a working device - return JoyInfo.axises; - // Else, we're changing devices, so send neutral joy events - CONS_Debug(DBG_GAMELOGIC, "Joystick3 device is changing; resetting events...\n"); - I_ShutdownJoystick3(); - } - - JoyInfo3.dev = newdev; - - if (JoyInfo3.dev == NULL) - { - CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick3: couldn't open device - %s\n"), SDL_GetError()); - return -1; - } - else - { - CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick3: %s\n"), SDL_JoystickName(JoyInfo3.dev)); - JoyInfo3.axises = SDL_JoystickNumAxes(JoyInfo3.dev); - if (JoyInfo3.axises > JOYAXISSET * 2) - JoyInfo3.axises = JOYAXISSET * 2; - /* if (joyaxes<2) - { - I_OutputMsg("Not enought axes?\n"); - return 0; - }*/ - - JoyInfo3.buttons = SDL_JoystickNumButtons(JoyInfo3.dev); - if (JoyInfo3.buttons > JOYBUTTONS) - JoyInfo3.buttons = JOYBUTTONS; - - JoyInfo3.hats = SDL_JoystickNumHats(JoyInfo3.dev); - if (JoyInfo3.hats > JOYHATS) - JoyInfo3.hats = JOYHATS; - - JoyInfo3.balls = SDL_JoystickNumBalls(JoyInfo3.dev); - - //Joystick.bGamepadStyle = !stricmp(SDL_JoystickName(JoyInfo3.dev), "pad"); - - return JoyInfo3.axises; - } -} - -//Joystick4 - -/** \brief Joystick 4 buttons states -*/ -static UINT64 lastjoy4buttons = 0; - -/** \brief Joystick 4 hats state -*/ -static UINT64 lastjoy4hats = 0; - -/** \brief Shuts down joystick 4 - - -\return void -*/ -void I_ShutdownJoystick4(void) -{ - INT32 i; - event_t event; - event.type = ev_keyup; - event.data2 = 0; - event.data3 = 0; - - lastjoy4buttons = lastjoy4hats = 0; - - // emulate the up of all joystick buttons - for (i = 0; i < JOYBUTTONS; i++) - { - event.data1 = KEY_4JOY1 + i; - D_PostEvent(&event); - } - - // emulate the up of all joystick hats - for (i = 0; i < JOYHATS*4; i++) - { - event.data1 = KEY_4HAT1 + i; - D_PostEvent(&event); - } - - // reset joystick position - event.type = ev_joystick4; - for (i = 0; i < JOYAXISSET; i++) - { - event.data1 = i; - D_PostEvent(&event); - } - - joystick4_started = 0; - JoyReset(&JoyInfo4); - - // don't shutdown the subsystem here, because hotplugging -} - -void I_GetJoystick4Events(void) -{ - static event_t event = {0,0,0,0}; - INT32 i = 0; - UINT64 joyhats = 0; -#if 0 - INT64 joybuttons = 0; -#endif - INT32 axisx, axisy; - - if (!joystick4_started) - return; - - if (!JoyInfo4.dev) //I_ShutdownJoystick4(); - return; - - -#if 0 - //faB: look for as much buttons as g_input code supports, - // we don't use the others - for (i = JoyInfo4.buttons - 1; i >= 0; i--) - { - joybuttons <<= 1; - if (SDL_JoystickGetButton(JoyInfo4.dev,i)) - joybuttons |= 1; - } - - if (joybuttons != lastjoy4buttons) - { - INT64 j = 1; // keep only bits that changed since last time - INT64 newbuttons = joybuttons ^ lastjoy4buttons; - lastjoy4buttons = joybuttons; - - for (i = 0; i < JOYBUTTONS; i++, j <<= 1) - { - if (newbuttons & j) // button changed state? - { - if (joybuttons & j) - event.type = ev_keydown; - else - event.type = ev_keyup; - event.data1 = KEY_4JOY1 + i; - D_PostEvent(&event); - } - } - } -#endif - - for (i = JoyInfo4.hats - 1; i >= 0; i--) - { - Uint8 hat = SDL_JoystickGetHat(JoyInfo4.dev, i); - - if (hat & SDL_HAT_UP ) joyhats|=(UINT64)0x1<<(0 + 4*i); - if (hat & SDL_HAT_DOWN ) joyhats|=(UINT64)0x1<<(1 + 4*i); - if (hat & SDL_HAT_LEFT ) joyhats|=(UINT64)0x1<<(2 + 4*i); - if (hat & SDL_HAT_RIGHT) joyhats|=(UINT64)0x1<<(3 + 4*i); - } - - if (joyhats != lastjoy4hats) - { - INT64 j = 1; // keep only bits that changed since last time - INT64 newhats = joyhats ^ lastjoy4hats; - lastjoy4hats = joyhats; - - for (i = 0; i < JOYHATS*4; i++, j <<= 1) - { - if (newhats & j) // hat changed state? - { - if (joyhats & j) - event.type = ev_keydown; - else - event.type = ev_keyup; - event.data1 = KEY_4HAT1 + i; - D_PostEvent(&event); - } - } - } - - // send joystick axis positions - event.type = ev_joystick4; - - for (i = JOYAXISSET - 1; i >= 0; i--) - { - event.data1 = i; - if (i*2 + 1 <= JoyInfo4.axises) - axisx = SDL_JoystickGetAxis(JoyInfo4.dev, i*2 + 0); - else axisx = 0; - if (i*2 + 2 <= JoyInfo4.axises) - axisy = SDL_JoystickGetAxis(JoyInfo4.dev, i*2 + 1); - else axisy = 0; - - // -32768 to 32767 - axisx = axisx/32; - axisy = axisy/32; - - if (Joystick4.bGamepadStyle) - { - // gamepad control type, on or off, live or die - if (axisx < -(JOYAXISRANGE/2)) - event.data2 = -1; - else if (axisx > (JOYAXISRANGE/2)) - event.data2 = 1; - else - event.data2 = 0; - if (axisy < -(JOYAXISRANGE/2)) - event.data3 = -1; - else if (axisy > (JOYAXISRANGE/2)) - event.data3 = 1; - else - event.data3 = 0; - } - else - { - - axisx = JoyInfo4.scale?((axisx/JoyInfo4.scale)*JoyInfo4.scale):axisx; - axisy = JoyInfo4.scale?((axisy/JoyInfo4.scale)*JoyInfo4.scale):axisy; - -#ifdef SDL_JDEADZONE - if (-SDL_JDEADZONE <= axisx && axisx <= SDL_JDEADZONE) axisx = 0; - if (-SDL_JDEADZONE <= axisy && axisy <= SDL_JDEADZONE) axisy = 0; -#endif - - // analog control style , just send the raw data - event.data2 = axisx; // x axis - event.data3 = axisy; // y axis - } - D_PostEvent(&event); - } - -} - -/** \brief Open joystick handle - - \param fname name of joystick - - \return axises - - -*/ -static int joy_open4(int joyindex) -{ - SDL_Joystick *newdev = NULL; - int num_joy = 0; - - if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) - { - CONS_Printf(M_GetText("Joystick subsystem not started\n")); - return -1; - } - - if (joyindex <= 0) - return -1; - - num_joy = SDL_NumJoysticks(); - - if (num_joy == 0) - { - CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); - return -1; - } - - newdev = SDL_JoystickOpen(joyindex - 1); - - // Handle the edge case where the device <-> joystick index assignment can change due to hotplugging - // This indexing is SDL's responsibility and there's not much we can do about it. - // - // Example: - // 1. Plug Controller A -> Index 0 opened - // 2. Plug Controller B -> Index 1 opened - // 3. Unplug Controller A -> Index 0 closed, Index 1 active - // 4. Unplug Controller B -> Index 0 inactive, Index 1 closed - // 5. Plug Controller B -> Index 0 opened - // 6. Plug Controller A -> Index 0 REPLACED, opened as Controller A; Index 1 is now Controller B - if (JoyInfo4.dev) - { - if (JoyInfo4.dev == newdev // same device, nothing to do - || (newdev == NULL && SDL_JoystickGetAttached(JoyInfo4.dev))) // we failed, but already have a working device - return JoyInfo.axises; - // Else, we're changing devices, so send neutral joy events - CONS_Debug(DBG_GAMELOGIC, "Joystick4 device is changing; resetting events...\n"); - I_ShutdownJoystick4(); - } - - JoyInfo4.dev = newdev; - - if (JoyInfo4.dev == NULL) - { - CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick4: couldn't open device - %s\n"), SDL_GetError()); - return -1; - } - else - { - CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick4: %s\n"), SDL_JoystickName(JoyInfo4.dev)); - JoyInfo4.axises = SDL_JoystickNumAxes(JoyInfo4.dev); - if (JoyInfo4.axises > JOYAXISSET * 2) - JoyInfo4.axises = JOYAXISSET * 2; - /* if (joyaxes<2) - { - I_OutputMsg("Not enought axes?\n"); - return 0; - }*/ - - JoyInfo4.buttons = SDL_JoystickNumButtons(JoyInfo4.dev); - if (JoyInfo4.buttons > JOYBUTTONS) - JoyInfo4.buttons = JOYBUTTONS; - - JoyInfo4.hats = SDL_JoystickNumHats(JoyInfo4.dev); - if (JoyInfo4.hats > JOYHATS) - JoyInfo4.hats = JOYHATS; - - JoyInfo4.balls = SDL_JoystickNumBalls(JoyInfo4.dev); - - //Joystick.bGamepadStyle = !stricmp(SDL_JoystickName(JoyInfo4.dev), "pad"); - - return JoyInfo4.axises; - } -} - // // I_InitJoystick // @@ -2162,7 +1394,6 @@ void I_InitJoystick(void) SDL_Joystick *newjoy = NULL; //I_ShutdownJoystick(); - //SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); if (M_CheckParm("-nojoy")) return; @@ -2186,7 +1417,7 @@ void I_InitJoystick(void) if (cv_usejoystick.value) newjoy = SDL_JoystickOpen(cv_usejoystick.value-1); - if (newjoy && (JoyInfo2.dev == newjoy || JoyInfo3.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device + if (newjoy && JoyInfo2.dev == newjoy) // don't override an active device cv_usejoystick.value = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; else if (newjoy && joy_open(cv_usejoystick.value) != -1) { @@ -2203,7 +1434,7 @@ void I_InitJoystick(void) joystick_started = 0; } - if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy) SDL_JoystickClose(newjoy); } @@ -2212,13 +1443,19 @@ void I_InitJoystick2(void) SDL_Joystick *newjoy = NULL; //I_ShutdownJoystick2(); - //SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); if (M_CheckParm("-nojoy")) return; + if (M_CheckParm("-noxinput")) + SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + + if (M_CheckParm("-nohidapi")) + SDL_SetHintWithPriority("SDL_JOYSTICK_HIDAPI", "0", SDL_HINT_OVERRIDE); + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { CONS_Printf("I_InitJoystick2()...\n"); + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) { CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); @@ -2229,7 +1466,7 @@ void I_InitJoystick2(void) if (cv_usejoystick2.value) newjoy = SDL_JoystickOpen(cv_usejoystick2.value-1); - if (newjoy && (JoyInfo.dev == newjoy || JoyInfo3.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device + if (newjoy && JoyInfo.dev == newjoy) // don't override an active device cv_usejoystick2.value = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; else if (newjoy && joy_open2(cv_usejoystick2.value) != -1) { @@ -2246,93 +1483,7 @@ void I_InitJoystick2(void) joystick2_started = 0; } - if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) - SDL_JoystickClose(newjoy); -} - -void I_InitJoystick3(void) -{ - SDL_Joystick *newjoy = NULL; - - //I_ShutdownJoystick3(); - //SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); - if (M_CheckParm("-nojoy")) - return; - - if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) - { - CONS_Printf("I_InitJoystick3()...\n"); - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) - { - CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); - return; - } - } - - if (cv_usejoystick3.value) - newjoy = SDL_JoystickOpen(cv_usejoystick3.value - 1); - - if (newjoy && (JoyInfo.dev == newjoy || JoyInfo2.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device - cv_usejoystick3.value = I_GetJoystickDeviceIndex(JoyInfo3.dev) + 1; - else if (newjoy && joy_open3(cv_usejoystick3.value) != -1) - { - // SDL's device indexes are unstable, so cv_usejoystick may not match - // the actual device index. So let's cheat a bit and find the device's current index. - JoyInfo3.oldjoy = I_GetJoystickDeviceIndex(JoyInfo3.dev) + 1; - joystick3_started = 1; - } - else - { - if (JoyInfo3.oldjoy) - I_ShutdownJoystick3(); - cv_usejoystick3.value = 0; - joystick3_started = 0; - } - - if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) - SDL_JoystickClose(newjoy); -} - -void I_InitJoystick4(void) -{ - SDL_Joystick *newjoy = NULL; - - //I_ShutdownJoystick4(); - //SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); - if (M_CheckParm("-nojoy")) - return; - - if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) - { - CONS_Printf("I_InitJoystick4()...\n"); - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) - { - CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); - return; - } - } - - if (cv_usejoystick4.value) - newjoy = SDL_JoystickOpen(cv_usejoystick4.value - 1); - - if (newjoy && (JoyInfo.dev == newjoy || JoyInfo2.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device - cv_usejoystick4.value = I_GetJoystickDeviceIndex(JoyInfo4.dev) + 1; - else if (newjoy && joy_open4(cv_usejoystick4.value) != -1) - { - // SDL's device indexes are unstable, so cv_usejoystick may not match - // the actual device index. So let's cheat a bit and find the device's current index. - JoyInfo4.oldjoy = I_GetJoystickDeviceIndex(JoyInfo4.dev) + 1; - joystick4_started = 1; - } - else - { - if (JoyInfo4.oldjoy) - I_ShutdownJoystick4(); - cv_usejoystick4.value = 0; - joystick4_started = 0; - } - - if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy) SDL_JoystickClose(newjoy); } @@ -2343,8 +1494,6 @@ static void I_ShutdownInput(void) // Note these methods are internal to this file, not called elsewhere. I_ShutdownJoystick(); I_ShutdownJoystick2(); - I_ShutdownJoystick3(); - I_ShutdownJoystick4(); if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) { @@ -2362,7 +1511,7 @@ INT32 I_NumJoys(void) return numjoy; } -static char joyname[255]; // MAX_PATH; joystick name is straight from the driver +static char joyname[255]; // joystick name is straight from the driver const char *I_GetJoyName(INT32 joyindex) { @@ -2450,8 +1599,8 @@ void I_UpdateMumble(const mobj_t *mobj, const listener_t listener) return; if(mumble->uiVersion != 2) { - wcsncpy(mumble->name, L"SRB2Kart "VERSIONSTRINGW, 256); - wcsncpy(mumble->description, L"Sonic Robo Blast 2 Kart with integrated Mumble Link support.", 2048); + wcsncpy(mumble->name, L"SRB2 "VERSIONSTRINGW, 256); + wcsncpy(mumble->description, L"Sonic Robo Blast 2 with integrated Mumble Link support.", 2048); mumble->uiVersion = 2; } mumble->uiTick++; @@ -2854,20 +2003,6 @@ void I_Tactile2(FFType pFFType, const JoyFF_t *FFEffect) (void)FFEffect; } -void I_Tactile3(FFType pFFType, const JoyFF_t *FFEffect) -{ - // UNUSED. - (void)pFFType; - (void)FFEffect; -} - -void I_Tactile4(FFType pFFType, const JoyFF_t *FFEffect) -{ - // UNUSED. - (void)pFFType; - (void)FFEffect; -} - /** \brief empty ticcmd for player 1 */ static ticcmd_t emptycmd; @@ -2886,24 +2021,6 @@ ticcmd_t *I_BaseTiccmd2(void) return &emptycmd2; } -/** \brief empty ticcmd for player 3 -*/ -static ticcmd_t emptycmd3; - -ticcmd_t *I_BaseTiccmd3(void) -{ - return &emptycmd3; -} - -/** \brief empty ticcmd for player 4 -*/ -static ticcmd_t emptycmd4; - -ticcmd_t *I_BaseTiccmd4(void) -{ - return &emptycmd4; -} - static int lastTimeFudge = -1; extern consvar_t cv_timefudge; @@ -2912,6 +2029,7 @@ static HMODULE winmm = NULL; static DWORD starttickcount = 0; // hack for win2k time bug static p_timeGetTime pfntimeGetTime = NULL; static LARGE_INTEGER basetime = { {0, 0} }; +static LARGE_INTEGER frequency; // use this if High Resolution timer is found // --------- // I_GetTime @@ -2925,9 +2043,6 @@ tic_t I_GetTime(void) { tic_t newtics = 0; - // use this if High Resolution timer is found - static LARGE_INTEGER frequency; - if (!starttickcount) // high precision timer { LARGE_INTEGER currtime; // use only LowPart if high resolution counter is not available @@ -2942,20 +2057,24 @@ tic_t I_GetTime(void) if (frequency.LowPart && QueryPerformanceCounter(&currtime)) { - newtics = (INT32)((currtime.QuadPart - basetime.QuadPart) * NEWTICRATE - / frequency.QuadPart); + newtics = (INT32)((currtime.QuadPart - basetime.QuadPart) * NEWTICRATE / frequency.QuadPart); } else if (pfntimeGetTime) { currtime.LowPart = pfntimeGetTime(); if (!basetime.LowPart) basetime.LowPart = currtime.LowPart; - newtics = ((currtime.LowPart - basetime.LowPart)/(1000/NEWTICRATE)); + newtics = (UINT32)((UINT64)(currtime.LowPart - basetime.LowPart)*NEWTICRATE/1000); } } else - newtics = (GetTickCount() - starttickcount)/(1000/NEWTICRATE); + newtics = (UINT32)((UINT64)(GetTickCount() - starttickcount)*NEWTICRATE/1000); + // ADVICE TO OFFICIAL SRB2 DEV TEAM: in the official branch, some of the above lines of code divide by (1000/NEWTICRATE) when it could multiply by 1000 first and preserve precision. + // I recommend changing this because the QueryPerformanceCounter version in fact already does that, making an inconsistent result between timer types. + // If the server and client are using different timer types, this will cause jutter. + // It also messes with SRB2netplus's timer fudge, meaning that for a truly accurate timerfudge it needs to know which timer the server is using... + // Fudge the timer to sync better with online games. Uses multiply-first approach (more accurate) if (cv_timefudge.value != lastTimeFudge) { if (frequency.QuadPart) @@ -2999,9 +2118,6 @@ UINT64 I_GetTimeUs(void) { LARGE_INTEGER currtime; // use only LowPart if high resolution counter is not available - // use this if High Resolution timer is found - static LARGE_INTEGER frequency; - if (!basetime.LowPart) { if (!QueryPerformanceFrequency(&frequency)) @@ -3033,7 +2149,7 @@ static void I_ShutdownTimer(void) pfntimeGetTime = NULL; if (winmm) { - p_timeEndPeriod pfntimeEndPeriod = (p_timeEndPeriod)GetProcAddress(winmm, "timeEndPeriod"); + p_timeEndPeriod pfntimeEndPeriod = (p_timeEndPeriod)(LPVOID)GetProcAddress(winmm, "timeEndPeriod"); if (pfntimeEndPeriod) pfntimeEndPeriod(1); FreeLibrary(winmm); @@ -3057,9 +2173,14 @@ tic_t I_GetTime (void) // fudge the timer for better netgame sync if (cv_timefudge.value != lastTimeFudge) { - basetime = (basetime / (1000 / TICRATE) * (1000 / TICRATE)) - 1000 * cv_timefudge.value / 100 / TICRATE; - basetime -= 1000 / TICRATE; + Uint64 frame = basetime * NEWTICRATE / 1000; + if (cv_timefudge.value > lastTimeFudge) + { + frame--; // do not allow the same tic to play twice + } + + basetime = (Uint64)(frame * 1000 / NEWTICRATE + 1000 * cv_timefudge.value / NEWTICRATE / 100); lastTimeFudge = cv_timefudge.value; } @@ -3093,10 +2214,10 @@ void I_StartupTimer(void) winmm = LoadLibraryA("winmm.dll"); if (winmm) { - p_timeEndPeriod pfntimeBeginPeriod = (p_timeEndPeriod)GetProcAddress(winmm, "timeBeginPeriod"); + p_timeEndPeriod pfntimeBeginPeriod = (p_timeEndPeriod)(LPVOID)GetProcAddress(winmm, "timeBeginPeriod"); if (pfntimeBeginPeriod) pfntimeBeginPeriod(1); - pfntimeGetTime = (p_timeGetTime)GetProcAddress(winmm, "timeGetTime"); + pfntimeGetTime = (p_timeGetTime)(LPVOID)GetProcAddress(winmm, "timeGetTime"); } I_AddExitFunc(I_ShutdownTimer); #endif @@ -3106,7 +2227,7 @@ void I_StartupTimer(void) void I_Sleep(void) { - if (cv_sleep.value > 0) + if (cv_sleep.value != -1) SDL_Delay(cv_sleep.value); } @@ -3145,14 +2266,14 @@ void I_Quit(void) #ifndef NONET D_SaveBan(); // save the ban list #endif - G_SaveGameData(false); // Tails 12-08-2002 + G_SaveGameData(); // Tails 12-08-2002 //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. - if (demo.recording) + if (demorecording) G_CheckDemoStatus(); if (metalrecording) - G_StopMetalRecording(); + G_StopMetalRecording(false); D_QuitNetGame(); I_ShutdownMusic(); @@ -3230,7 +2351,7 @@ void I_Error(const char *error, ...) if (errorcount == 9) { M_SaveConfig(NULL); - G_SaveGameData(false); + G_SaveGameData(); } if (errorcount > 20) { @@ -3241,7 +2362,7 @@ void I_Error(const char *error, ...) // which should fail gracefully if it can't put a message box up // on the target system SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "SRB2Kart "VERSIONSTRING" Recursive Error", + "SRB2 "VERSIONSTRING" Recursive Error", buffer, NULL); W_Shutdown(); @@ -3264,13 +2385,13 @@ void I_Error(const char *error, ...) #ifndef NONET D_SaveBan(); // save the ban list #endif - G_SaveGameData(false); // Tails 12-08-2002 + G_SaveGameData(); // Tails 12-08-2002 // Shutdown. Here might be other errors. - if (demo.recording) + if (demorecording) G_CheckDemoStatus(); if (metalrecording) - G_StopMetalRecording(); + G_StopMetalRecording(false); D_QuitNetGame(); I_ShutdownMusic(); @@ -3286,7 +2407,7 @@ void I_Error(const char *error, ...) // which should fail gracefully if it can't put a message box up // on the target system SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "SRB2Kart "VERSIONSTRING" Error", + "SRB2 "VERSIONSTRING" Error", buffer, NULL); // Note that SDL_ShowSimpleMessageBox does *not* require SDL to be // initialized at the time, so calling it after SDL_Quit() is @@ -3395,7 +2516,7 @@ void I_GetDiskFreeSpace(INT64 *freespace) if (!testwin95) { - pfnGetDiskFreeSpaceEx = (p_GetDiskFreeSpaceExA)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetDiskFreeSpaceExA"); + pfnGetDiskFreeSpaceEx = (p_GetDiskFreeSpaceExA)(LPVOID)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetDiskFreeSpaceExA"); testwin95 = true; } if (pfnGetDiskFreeSpaceEx) @@ -3419,7 +2540,7 @@ void I_GetDiskFreeSpace(INT64 *freespace) char *I_GetUserName(void) { - static char username[MAXPLAYERNAME]; + static char username[MAXPLAYERNAME+1]; char *p; #ifdef _WIN32 DWORD i = MAXPLAYERNAME; @@ -3456,7 +2577,7 @@ char *I_GetUserName(void) INT32 I_mkdir(const char *dirname, INT32 unixright) { //[segabor] -#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) || defined (__CYGWIN__) || defined (__OS2__) +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) || defined (__CYGWIN__) return mkdir(dirname, unixright); #elif defined (_WIN32) UNREFERENCED_PARAMETER(unixright); /// \todo should implement ntright under nt... @@ -3550,14 +2671,6 @@ static boolean isWadPathOk(const char *path) return true; } - sprintf(wad3path, pandf, path, WADKEYWORD2); - - if (FIL_ReadFileOK(wad3path)) - { - free(wad3path); - return true; - } - free(wad3path); return false; } @@ -3575,7 +2688,7 @@ static void pathonly(char *s) } } -/** \brief search for srb2.srb in the given path +/** \brief search for srb2.pk3 in the given path \param searchDir starting path @@ -3596,19 +2709,12 @@ static const char *searchWad(const char *searchDir) return tempsw; } - strcpy(tempsw, WADKEYWORD2); - fstemp = filesearch(tempsw, searchDir, NULL, true, 20); - if (fstemp == FS_FOUND) - { - pathonly(tempsw); - return tempsw; - } return NULL; } -/** \brief go through all possible paths and look for srb2.srb +/** \brief go through all possible paths and look for srb2.pk3 - \return path to srb2.srb if any + \return path to srb2.pk3 if any */ static const char *locateWad(void) { @@ -3737,7 +2843,7 @@ const char *I_LocateWad(void) if (waddir) { - // change to the directory where we found srb2.srb + // change to the directory where we found srb2.pk3 #if defined (_WIN32) SetCurrentDirectoryA(waddir); #else @@ -3828,16 +2934,6 @@ UINT32 I_GetFreeMem(UINT32 *total) if (total) *total = (UINT32)info.dwTotalPhys; return (UINT32)info.dwAvailPhys; -#elif defined (__OS2__) - UINT32 pr_arena; - - if (total) - DosQuerySysInfo( QSV_TOTPHYSMEM, QSV_TOTPHYSMEM, - (PVOID) total, sizeof (UINT32)); - DosQuerySysInfo( QSV_MAXPRMEM, QSV_MAXPRMEM, - (PVOID) &pr_arena, sizeof (UINT32)); - - return pr_arena; #elif defined (__linux__) /* Linux */ char buf[1024]; @@ -3915,7 +3011,7 @@ const CPUInfoFlags *I_CPUInfo(void) #if defined (_WIN32) static CPUInfoFlags WIN_CPUInfo; SYSTEM_INFO SI; - p_IsProcessorFeaturePresent pfnCPUID = (p_IsProcessorFeaturePresent)GetProcAddress(GetModuleHandleA("kernel32.dll"), "IsProcessorFeaturePresent"); + p_IsProcessorFeaturePresent pfnCPUID = (p_IsProcessorFeaturePresent)(LPVOID)GetProcAddress(GetModuleHandleA("kernel32.dll"), "IsProcessorFeaturePresent"); ZeroMemory(&WIN_CPUInfo,sizeof (WIN_CPUInfo)); if (pfnCPUID) From 65b157cac0700062f65cb23856b83de0367e2864 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 17 Jan 2020 23:42:05 +0000 Subject: [PATCH 53/67] * Added recommended simulate tics, so it should be safe to keep simulatetics at MAX without spike lag teleporting you. --- src/d_clisrv.c | 11 ++++++++++- src/d_netcmd.c | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1ea770a2f..63a117df0 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5435,6 +5435,7 @@ int minRTT; int maxRTT; int maxLiveTicOffset; int minLiveTicOffset; +int recommendedSimulateTics = 0; // simulateTics recommendation based on the last known 'stable' RTT (range <= 2). Used for avoiding spike lag future-past-teleports. int smoothingDelay; UINT64 saveStateBenchmark = 0; UINT64 loadStateBenchmark = 0; @@ -5630,7 +5631,8 @@ static void RunSimulations() break; } - int nextTargetSimTic = min(min(gametic + estimatedRTT - tastyFudge, smoothedTic + cv_simulatetics.value), simtic + MAXSIMULATIONS); + int numDesiredSimulateTics = min(recommendedSimulateTics, cv_simulatetics.value); + int nextTargetSimTic = min(min(gametic + estimatedRTT - tastyFudge, smoothedTic + numDesiredSimulateTics), simtic + MAXSIMULATIONS); if (nextTargetSimTic >= 0) targetsimtic = nextTargetSimTic; @@ -5878,6 +5880,13 @@ void DetermineNetConditions() } rttJitter = maxRTT - minRTT; + + // stable server conditions? (but not just a big lag spike?) + if (rttJitter <= 2 && maxRTT < BACKUPTICS - 1) + { + // we know roughly how much we should simulate then! + recommendedSimulateTics = maxRTT + 1; + } } static void PerformDebugRewinds() diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 49ded26e2..a37c4aaf4 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -477,7 +477,7 @@ boolean circuitmap = true; // SRB2kart consvar_t cv_simulate = { "simulate", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL }; static CV_PossibleValue_t simulateTics_cons_t[] = { {0, "MIN"}, {MAXSIMULATIONS - 1, "MAX"}, {0, NULL} }; -consvar_t cv_simulatetics = { "simulatetics", "0", 0, simulateTics_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_simulatetics = { "simulatetics", "MAX", 0, simulateTics_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; static CV_PossibleValue_t netdelay_cons_t[] = { {0, "MIN"}, {250, "MAX"}, {0, NULL} }; consvar_t cv_netdelay = { "netdelay", "0", 0, netdelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; @@ -499,7 +499,7 @@ static CV_PossibleValue_t timefudge_cons_t[] = { {0, "MIN"}, {100, "MAX"}, {0, N consvar_t cv_timefudge = { "timefudge", "0", 0, timefudge_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; static CV_PossibleValue_t nettrails_cons_t[] = { {0, "MIN"}, {5, "MAX"}, {0, NULL} }; -consvar_t cv_nettrails = { "nettrails", "1", 0, nettrails_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_nettrails = { "nettrails", "5", 0, nettrails_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; consvar_t cv_netslingdelay = { "netslingdelay", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; From 586cb358baf776a1ec6a4846deb86ec6733d0003 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 17 Jan 2020 23:43:26 +0000 Subject: [PATCH 54/67] * Snarky timefudge message should now only appear in the correct conditions ;) --- .../projects/visualc10/libpng.vcxproj | 20 +++++++++---------- libs/zlib/projects/visualc10/zlib.vcxproj | 20 +++++++++---------- src/d_netcmd.c | 5 ++++- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/libs/libpng-src/projects/visualc10/libpng.vcxproj b/libs/libpng-src/projects/visualc10/libpng.vcxproj index eaa3d4ffb..550db395f 100644 --- a/libs/libpng-src/projects/visualc10/libpng.vcxproj +++ b/libs/libpng-src/projects/visualc10/libpng.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -37,51 +37,51 @@ {72B01ACA-7A1A-4F7B-ACEF-2607299CF052} libpng - 10.0.16299.0 + 10.0 StaticLibrary false - v140 + v142 StaticLibrary false - v141 + v142 true StaticLibrary false - v140 + v142 StaticLibrary false - v141 + v142 true StaticLibrary false - v140 + v142 StaticLibrary false - v141 + v142 true StaticLibrary false - v140 + v142 StaticLibrary false - v141 + v142 true diff --git a/libs/zlib/projects/visualc10/zlib.vcxproj b/libs/zlib/projects/visualc10/zlib.vcxproj index a7055ddb8..e648e2ef0 100644 --- a/libs/zlib/projects/visualc10/zlib.vcxproj +++ b/libs/zlib/projects/visualc10/zlib.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -37,51 +37,51 @@ {73A5729C-7323-41D4-AB48-8A03C9F81603} zlib - 10.0.16299.0 + 10.0 StaticLibrary false - v140 + v142 StaticLibrary false - v141 + v142 true StaticLibrary false - v140 + v142 StaticLibrary false - v141 + v142 true StaticLibrary false - v140 + v142 true StaticLibrary false - v141 + v142 StaticLibrary false - v140 + v142 StaticLibrary false - v141 + v142 true diff --git a/src/d_netcmd.c b/src/d_netcmd.c index a37c4aaf4..792f3941e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -859,7 +859,10 @@ static void Command_Autotimefudge(void) if (server) { - CONS_Printf("Servers do not need a time fudge! Heck, why are you hosting with this exe anyway? You don't need to ;)\n"); + if (netgame) + { + CONS_Printf("Servers do not need a time fudge! Heck, why are you hosting with this exe anyway? You don't need to ;)\n"); + } return; } From c5f569eedc128c9e452fcbdff3638e27589d7e65 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 24 Jan 2020 00:11:36 +0000 Subject: [PATCH 55/67] Adding experimental distance culling Also fix or partially MF_NOTHINK errors (crab enemy) **MAY BE UNSTABLE** - fixed some things, probably broke some others, the save/load code is a nightmare! --- src/d_clisrv.c | 37 +++++++- src/d_netcmd.c | 4 + src/d_netcmd.h | 1 + src/p_mobj.h | 2 + src/p_saveg.c | 249 ++++++++++++++++++++++++++++++++++++------------- src/p_tick.c | 3 + 6 files changed, 228 insertions(+), 68 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 63a117df0..7d60a871c 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5639,9 +5639,9 @@ static void RunSimulations() int numToSimulate = targetsimtic - simtic; - // record steadyplayers' real game position and their simulated position - if (numToSimulate > 0) + if (numToSimulate > 0) // only touch objects if we're definitely going to simulate and rewind! { + // record steadyplayers' real game position and their simulated position for (int i = 0; i < MAXPLAYERS; i++) { if (playeringame[i] && players[i].mo && i != consoleplayer) @@ -5663,6 +5663,39 @@ static void RunSimulations() } } } + + // and cull distant thinkers if enabled + if (cv_simulateculldistance.value > 0) + { + thinker_t* current; + fixed_t minDistance = cv_simulateculldistance.value << FRACBITS; + mobj_t* playerMos[MAXPLAYERS]; + int numPlayers = 0; + int i; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i] && players[i].mo) + { + playerMos[numPlayers++] = players[i].mo; + } + } + + for (current = thlist[THINK_MOBJ].next; current != &thlist[THINK_MOBJ]; current = current->next) + { + for (i = 0; i < numPlayers; i++) + { + if (P_AproxDistance(playerMos[i]->x - ((mobj_t*)current)->x, playerMos[i]->y - ((mobj_t*)current)->y) < minDistance) + break; + } + + if (i == numPlayers) + { + // cull this mobj + ((mobj_t*)current)->isculled = true; + } + } + } } // simulate the rest o da future diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 792f3941e..7a9d50794 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -479,6 +479,9 @@ consvar_t cv_simulate = { "simulate", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0 static CV_PossibleValue_t simulateTics_cons_t[] = { {0, "MIN"}, {MAXSIMULATIONS - 1, "MAX"}, {0, NULL} }; consvar_t cv_simulatetics = { "simulatetics", "MAX", 0, simulateTics_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +static CV_PossibleValue_t simulateculldistance_cons_t[] = { {0, "MIN"}, {10000, "MAX"}, {0, NULL} }; +consvar_t cv_simulateculldistance = { "simulateculldistance", "MIN", 0, simulateculldistance_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; + static CV_PossibleValue_t netdelay_cons_t[] = { {0, "MIN"}, {250, "MAX"}, {0, NULL} }; consvar_t cv_netdelay = { "netdelay", "0", 0, netdelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; @@ -660,6 +663,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_simulate); CV_RegisterVar(&cv_simulatetics); + CV_RegisterVar(&cv_simulateculldistance); CV_RegisterVar(&cv_netdelay); CV_RegisterVar(&cv_netjitter); CV_RegisterVar(&cv_netsmoothing); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index fffba87d7..9c5b6cae0 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -150,6 +150,7 @@ extern consvar_t cv_showping; extern consvar_t cv_simulate; extern consvar_t cv_simulatetics; +extern consvar_t cv_simulateculldistance; extern consvar_t cv_netdelay; extern consvar_t cv_netjitter; extern consvar_t cv_netsmoothing; diff --git a/src/p_mobj.h b/src/p_mobj.h index 702e01a96..a2051c968 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -375,6 +375,8 @@ typedef struct mobj_s boolean colorized; // Whether the mobj uses the rainbow colormap + boolean isculled; // Whether the mobj is being culled during simulations + // WARNING: New fields must be added separately to savegame and Lua. } mobj_t; diff --git a/src/p_saveg.c b/src/p_saveg.c index 642f20ea6..d7ceef50d 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -886,6 +886,11 @@ static void P_LocalUnArchiveWorld(void) sectors[i].preciplist = preservedSectors[i].preciplist; sectors[i].touching_preciplist = preservedSectors[i].touching_preciplist; + if (sectors[i].thinglist == (mobj_t*)0xDDDDDDDD) + { + continue; + } + // restore preserved local stuff (tbh I don't really know what this is lol) sectors[i].lightlist = preservedSectors[i].lightlist; sectors[i].numlights = preservedSectors[i].numlights; @@ -2193,61 +2198,6 @@ static inline void SaveWhatThinker(const thinker_t *th, const UINT8 type) */ -// -// P_LocalArchiveThinkers -// Archives the world's thinkers locally. Used for within-level savestates -// -static void P_LocalArchiveThinkers(void) -{ - int i, j; - const thinker_t* thinker; - mobj_t* savedMobj; - executor_t* savedExecutor; - UINT8* original = save_p; - WRITEUINT32(save_p, ARCHIVEBLOCK_THINKERS); - - for (i = 0; i < NUM_THINKERLISTS; i++) - { - for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = thinker->next) - { - actionf_p1 acp1 = thinker->function.acp1; - - // find the associated special def - for (j = 0; j < sizeof(specialDefs) / sizeof(specialDefs[0]); j++) - { - if (acp1 == specialDefs[j].action) - break; - } - - if (j == sizeof(specialDefs) / sizeof(specialDefs[0])) - continue; - - WRITEUINT8(save_p, j); - WRITEMEM(save_p, thinker, specialDefs[j].size); - - // relink saved pointers with saved mobjnums -#define RELINK(var) if (var != NULL) var = (mobj_t*)(var->mobjnum) - if (j == tc_mobj) - { - savedMobj = &((mobj_t*)save_p)[-1]; - RELINK(savedMobj->tracer); - RELINK(savedMobj->target); - RELINK(savedMobj->hnext); - RELINK(savedMobj->hprev); - } - - if (j == tc_executor) - { - savedExecutor = &((executor_t*)save_p)[-1]; - RELINK(savedExecutor->caller); - } - } -#undef RELINK - - WRITEUINT8(save_p, 0xFF); // next list (or end) - } -} - // // P_NetArchiveThinkers // @@ -3262,6 +3212,92 @@ typedef struct #define HASHLOC(x, y, z) (((x>>4)-(y>>8)+(z>>12)-(x>>16)+(y>>20)-(z>>24)+(x>>28)-(y>>24)+(z>>20)-(x>>16)+(y>>8)-(z>>4)) & 0x7FFF) #define MAXNUMMOBJSBYLOC 15 + + +// +// P_LocalArchiveThinkers +// Archives the world's thinkers locally. Used for within-level savestates +// +static void P_LocalArchiveThinkers(void) +{ + int i, j; + size_t s; + const thinker_t* thinker; + mobj_t* savedMobj; + executor_t* savedExecutor; + UINT8* original = save_p; + WRITEUINT32(save_p, ARCHIVEBLOCK_THINKERS); + + for (i = 0; i < NUM_THINKERLISTS; i++) + { +#define RELINK(var) if (var != NULL) var = (mobj_t*)(var->mobjnum) + for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = thinker->next) + { + actionf_p1 acp1 = thinker->function.acp1; + + // find the associated special def + for (j = 0; j < sizeof(specialDefs) / sizeof(specialDefs[0]); j++) + { + if (acp1 == specialDefs[j].action) + break; + } + + if (j == sizeof(specialDefs) / sizeof(specialDefs[0])) + continue; + + WRITEUINT8(save_p, j); + WRITEMEM(save_p, thinker, specialDefs[j].size); + + // relink saved pointers with saved mobjnums + if (j == tc_mobj) + { + savedMobj = &((mobj_t*)save_p)[-1]; + RELINK(savedMobj->tracer); + RELINK(savedMobj->target); + RELINK(savedMobj->hnext); + RELINK(savedMobj->hprev); + } + + if (j == tc_executor) + { + savedExecutor = &((executor_t*)save_p)[-1]; + RELINK(savedExecutor->caller); + } + } + + WRITEUINT8(save_p, 0xFF); // next list (or end) + } + + // now write the nothinkers... + // turns out that MF_NOTHINKs aren't in thinker lists lol.... + // makes sense, but doesn't make life easier. I just wanted an object list. Ah well. + for (s = 0; s < numsectors; s++) + { + mobj_t* thing = sectors[s].thinglist; + + while (thing) + { + if (thing->flags & MF_NOTHINK) + { + // archive this thing + WRITEUINT8(save_p, tc_mobj); + WRITEMEM(save_p, thing, specialDefs[tc_mobj].size); + + savedMobj = &((mobj_t*)save_p)[-1]; + RELINK(savedMobj->tracer); + RELINK(savedMobj->target); + RELINK(savedMobj->hnext); + RELINK(savedMobj->hprev); + + } + thing = thing->snext; + } + } +#undef RELINK + + WRITEUINT8(save_p, 0xFF); +} + static void P_LocalUnArchiveThinkers() { thinker_t *thinker; @@ -3269,8 +3305,8 @@ static void P_LocalUnArchiveThinkers() UINT8 tclass; UINT8 restoreExecutors = false; INT32 i, j, list; - int skyviewid = -1; - int skycenterid = -1; + int skyviewid = 0; + int skycenterid = 0; thinker_t newthinkers[NUM_THINKERLISTS] = { 0 }; static thinker_t* thinkersbytype[tc_end][16384]; static int numthinkersbytype[tc_end]; @@ -3340,8 +3376,24 @@ static void P_LocalUnArchiveThinkers() // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity for (i = 0; i < (int)numsectors; i++) + { + mobj_t* thing = sectors[i].thinglist, *next; sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = sectors[i].fadecolormapdata = NULL; + // clear nothinkers too + while (thing) + { + next = thing->snext; + if (thing->flags & MF_NOTHINK) + { + thing->thinker.references = 0; // hope this is ok... + P_RemoveMobj(thing); + } + + thing = next; + } + } + // read in saved thinkers for (list = 0; list < NUM_THINKERLISTS; list++) { @@ -3418,9 +3470,12 @@ static void P_LocalUnArchiveThinkers() // detach any playing sounds from this object if we can (still need to work on doing this properly!) S_DetachChannelsFromOrigin((mobj_t*)newthinker); - // unlink it from the old list - newthinker->prev->next = newthinker->next; - newthinker->next->prev = newthinker->prev; + // unlink it from the old list (if it's not a nothinker) + if (!(tclass == tc_mobj && (((mobj_t*)newthinker)->flags & MF_NOTHINK))) + { + newthinker->prev->next = newthinker->next; + newthinker->next->prev = newthinker->prev; + } } else { @@ -3447,6 +3502,8 @@ static void P_LocalUnArchiveThinkers() case tc_mobj: { mobj_t* mobj = (mobj_t*)newthinker; + + // link global and player pointers if (mobj->type == MT_REDFLAG) { redflag = mobj; @@ -3501,10 +3558,13 @@ static void P_LocalUnArchiveThinkers() } // relink into the new thinker list - newthinker->prev = newthinkers[list].prev; - newthinker->next = &newthinkers[list]; - newthinker->prev->next = newthinker; - newthinker->next->prev = newthinker; + if (!(tclass == tc_mobj && (((mobj_t*)newthinker)->flags & MF_NOTHINK))) + { + newthinker->prev = newthinkers[list].prev; + newthinker->next = &newthinkers[list]; + newthinker->prev->next = newthinker; + newthinker->next->prev = newthinker; + } if (tclass == tc_mobj) { @@ -3519,6 +3579,29 @@ static void P_LocalUnArchiveThinkers() } } + // collect nothinkers as well + for (;;) + { + tclass = READUINT8(save_p); + + if (tclass == 0xFF) + break; // next list + + mobj = Z_Calloc(sizeof(mobj_t), PU_LEVEL, NULL); + READMEM(save_p, mobj, specialDefs[tclass].size); + + mobjByNum[mobj->mobjnum] = mobj; + mobj->bnext = NULL; + mobj->bprev = NULL; + mobj->snext = NULL; + mobj->sprev = NULL; + mobj->subsector = NULL; + mobj->touching_sectorlist = NULL; + P_SetThingPosition(mobj); + + // we just spawner a nothinker so it doesn't go in a thinker list, let it run wild?? + } + // delete everything remaining in the list that hasn't been linked for (i = 0; i < NUM_THINKERLISTS; i++) { @@ -3582,6 +3665,25 @@ static void P_LocalUnArchiveThinkers() RELINK(mobj->hprev); } + // and for nothinkers + for (i = 0; i < (int)numsectors; i++) + { + mobj_t* thing = sectors[i].thinglist; + + while (thing) + { + if (thing->flags & MF_NOTHINK) + { + RELINK(thing->tracer); + RELINK(thing->target); + RELINK(thing->hnext); + RELINK(thing->hprev); + } + + thing = thing->snext; + } + } + // restore player pointers (the above doesn't always seem to work perhaps because playeringame is false? for (int i = 0; i < MAXPLAYERS; i++) { @@ -4623,7 +4725,8 @@ void P_SaveGameState(savestate_t* savestate) { mobj_t* mobj; thinker_t* th; - int i = 1; + size_t s = 0; + int mobjnum = 1; UINT64 time = I_GetTimeUs(); @@ -4642,7 +4745,21 @@ void P_SaveGameState(savestate_t* savestate) mobj = (mobj_t *)th; if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) continue; - mobj->mobjnum = i++; + mobj->mobjnum = mobjnum++; + } + // including nothinkers... + for (s = 0; s < numsectors; s++) + { + mobj_t* thing = sectors[s].thinglist; + + while (thing) + { + if (thing->flags & MF_NOTHINK) + { + thing->mobjnum = mobjnum++; + } + thing = thing->snext; + } } P_NetArchiveMisc(); diff --git a/src/p_tick.c b/src/p_tick.c index 2a3cf0cc8..69a4ef643 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -332,6 +332,9 @@ static inline void P_RunThinkers(void) #ifdef PARANOIA I_Assert(currentthinker->function.acp1 != NULL); #endif + if (currentthinker->function.acp1 == P_MobjThinker && issimulation && ((mobj_t*)currentthinker)->isculled) + continue; // apply distance culling + currentthinker->function.acp1(currentthinker); } } From 47960e5c1728602869c6319525bd684f7254ef14 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 14 Feb 2020 21:44:36 +0000 Subject: [PATCH 56/67] Fixed continuous falling thinker bug Resynchs are more effective --- src/d_clisrv.c | 10 ++++++++-- src/p_saveg.c | 11 ++++++++++- src/p_setup.c | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 7d60a871c..92ef1c299 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5441,6 +5441,8 @@ UINT64 saveStateBenchmark = 0; UINT64 loadStateBenchmark = 0; int netUpdateFudge; // our last net update fudge +tic_t lastSavestateClearedTic; + #define MAXOFFSETHISTORY 35 int ticTimeOffsetHistory[MAXOFFSETHISTORY]; @@ -5511,8 +5513,10 @@ void TryRunTics(tic_t realtics) } // record the actual local controls - boolean recordingStates = (gamestate == GS_LEVEL) && leveltime >= 1 && gametic >= BACKUPTICS; - boolean canSimulate = (gamestate == GS_LEVEL) && leveltime >= BACKUPTICS && gametic >= BACKUPTICS && (cv_simulate.value && !server) && !resynch_local_inprogress; + boolean canSimulate = (gamestate == GS_LEVEL) + && leveltime >= TICRATE && gametic >= TICRATE && (cv_simulate.value && !server) + && !resynch_local_inprogress && gametic >= lastSavestateClearedTic + TICRATE; + boolean recordingStates = canSimulate; if (simtic > gametic && !canSimulate) { @@ -5855,6 +5859,8 @@ void InvalidateSavestates() for (int i = 0; i < MAXSIMULATIONS; i++) gameStateBufferIsValid[i] = false; + + lastSavestateClearedTic = gametic; } int rttBuffer[70]; diff --git a/src/p_saveg.c b/src/p_saveg.c index d7ceef50d..59a6b9882 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1476,7 +1476,7 @@ static const specialdef_t specialDefs[] = WITHSECTOR(T_ThwompSector, levelspecthink_t, ST_FLOORDATA | ST_CEILDATA), // tc_thwomp NOSECTOR(T_CameraScanner, elevator_t), // tc_camerascanner WITHSECTOR(T_MoveElevator, elevator_t, ST_CEILDATA | ST_FLOORDATA), // tc_elevator - WITHSECTOR(T_MoveElevator, levelspecthink_t, ST_CEILDATA | ST_FLOORDATA), // tc_contunousfalling + WITHSECTOR(T_ContinuousFalling, levelspecthink_t, ST_CEILDATA | ST_FLOORDATA), // tc_contunousfalling WITHSECTOR(T_BounceCheese, levelspecthink_t, ST_CEILDATA), // tc_bouncecheese WITHSECTOR(T_StartCrumble, elevator_t, ST_FLOORDATA), // tc_startcrumble WITHSECTOR(T_MarioBlock, levelspecthink_t, ST_FLOORDATA | ST_CEILDATA), // tc_marioblock @@ -4732,6 +4732,7 @@ void P_SaveGameState(savestate_t* savestate) save_p = savestate->buffer; + WRITEINT16(save_p, gamemap); WRITEUINT32(save_p, globalmobjnum); CV_SaveNetVars(&save_p); @@ -4788,11 +4789,19 @@ boolean P_LoadGameState(const savestate_t* savestate) UINT64 time = I_GetTimeUs(); angle_t preserveAngle = localangle; INT32 preserveAiming = localaiming; + INT16 savedGameMap; save_p = ((unsigned char*)savestate->buffer); + savedGameMap = READINT16(save_p); globalmobjnum = READUINT32(save_p); + if (savedGameMap != gamemap) + { + // savestates do not work cross-level + return false; + } + CV_LoadNetVars(&save_p, true); P_NetUnArchiveMisc(true); diff --git a/src/p_setup.c b/src/p_setup.c index dff5fa805..5de085525 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2770,6 +2770,11 @@ static boolean P_CanSave(void) */ boolean P_SetupLevel(boolean skipprecip) { + if (issimulation) + { + return true; + } + // use gamemap to get map number. // 99% of the things already did, so. // Map header should always be in place at this point From 7bfb22d10d5c0eb983a9a8a8d18a8fe3ab192f96 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Wed, 19 Feb 2020 17:44:50 -0500 Subject: [PATCH 57/67] It compiles .... And sort of works ... --- src/d_clisrv.c | 24 +- src/g_game.c | 2 +- src/p_mobj.c | 2 +- src/p_saveg.c | 77 ++-- src/s_sound.c | 23 +- src/sdl/i_system.c | 972 +++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 982 insertions(+), 118 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 92ef1c299..92a5d2042 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5191,6 +5191,8 @@ fixed_t FixedDistance2(fixed_t aX, fixed_t aY, fixed_t bX, fixed_t bY) static ticcmd_t lastCmds; +//Kart doesnt have FPS shootouts, so this is unneeded +/* void CorrectPlayerTargeting(ticcmd_t* cmds) { if (!players[consoleplayer].mo || !cv_netsteadyplayers.value || simtic == gametic) @@ -5296,6 +5298,7 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) } } } +*/ static void AdjustSimulatedTiccmdInputs(ticcmd_t* cmds) { @@ -5304,8 +5307,9 @@ static void AdjustSimulatedTiccmdInputs(ticcmd_t* cmds) INT16 oldAngle = cmds->angleturn; - if (gamestate == GS_LEVEL && cv_netsteadyplayers.value && !cv_netslingdelay.value) - CorrectPlayerTargeting(cmds); + //Kart doesnt have match mode where this is relevant + //if (gamestate == GS_LEVEL && cv_netsteadyplayers.value && !cv_netslingdelay.value) + // CorrectPlayerTargeting(cmds); if (cmds->angleturn != oldAngle) { @@ -5830,18 +5834,18 @@ static void RunSimulations() blueflagplayer = &players[i]; } - if (players[i].followmobj) - ADJUSTPOSITION(players[i].followmobj, i); +// if (players[i].followmobj) +// ADJUSTPOSITION(players[i].followmobj, i); } for (mobj = (mobj_t*)thlist[THINK_MOBJ].next; mobj != (mobj_t*)&thlist[THINK_MOBJ]; mobj = (mobj_t*)mobj->thinker.next) { - if (mobj->flags2 & MF2_SHIELD && mobj->target != NULL && mobj->target->player != NULL && mobj->target != players[consoleplayer].mo) - ADJUSTPOSITION(mobj, mobj->target->player - players); - else if (mobj->type == MT_BLUEFLAG && blueflagplayer) - ADJUSTPOSITION(mobj, blueflagplayer - players); - else if (mobj->type == MT_REDFLAG && redflagplayer) - ADJUSTPOSITION(mobj, redflagplayer - players); +// if (mobj->flags2 & MF2_SHIELD && mobj->target != NULL && mobj->target->player != NULL && mobj->target != players[consoleplayer].mo) +// ADJUSTPOSITION(mobj, mobj->target->player - players); +// else if (mobj->type == MT_BLUEFLAG && blueflagplayer) +// ADJUSTPOSITION(mobj, blueflagplayer - players); +// else if (mobj->type == MT_REDFLAG && redflagplayer) +// ADJUSTPOSITION(mobj, redflagplayer - players); } } } diff --git a/src/g_game.c b/src/g_game.c index 0639e1cae..243625e3c 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -7315,7 +7315,7 @@ void G_DoPlayDemo(char *defdemoname) } // net var data - CV_LoadNetVars(&demo_p); + CV_LoadNetVars(&demo_p, false); // Sigh ... it's an empty demo. if (*demo_p == DEMOMARKER) diff --git a/src/p_mobj.c b/src/p_mobj.c index e25073010..fa5fa6297 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6366,7 +6366,7 @@ void P_MobjThinker(mobj_t *mobj) if (mobj->flags & MF_NOTHINK) return; - if ((mobj->flags & MF_BOSS) && mobj->spawnpoint && (bossdisabled & (1<spawnpoint->extrainfo))) + if ((mobj->flags & MF_BOSS) && mobj->spawnpoint) return; // Remove dead target/tracer. diff --git a/src/p_saveg.c b/src/p_saveg.c index 59a6b9882..ce6ce6338 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -465,8 +465,8 @@ static void P_LocalArchivePlayers(void) RELINK(player->axis1); RELINK(player->axis2); RELINK(player->awayviewmobj); - RELINK(player->followmobj); - RELINK(player->drone); + //RELINK(player->followmobj); + //RELINK(player->drone); #undef RELINK } } @@ -497,6 +497,7 @@ static UINT32 num_ffloors = 0; // for loading // Copypasta from r_data.c AddColormapToList // But also check for equality and return the matching index +/* static UINT32 CheckAddNetColormapToList(extracolormap_t *extra_colormap) { extracolormap_t *exc, *exc_prev = NULL; @@ -707,6 +708,7 @@ static void P_NetUnArchiveColormaps(void) } } } +*/ #define SD_FLOORHT 0x01 #define SD_CEILHT 0x02 @@ -845,7 +847,7 @@ static void P_LocalArchiveWorld(void) UINT8* put; // paranoia something something - ClearNetColormaps(); + //ClearNetColormaps(); WRITEUINT32(save_p, ARCHIVEBLOCK_WORLD); put = save_p; @@ -1495,13 +1497,6 @@ static const specialdef_t specialDefs[] = NOSECTOR(T_NoEnemiesSector, levelspecthink_t), // tc_noenemies NOSECTOR(T_EachTimeThinker, levelspecthink_t), // tc_eachtime NOSECTOR(T_Disappear, disappear_t), // tc_disappear - NOSECTOR(T_Fade, fade_t), // tc_fade - WITHSECTOR(T_FadeColormap, fadecolormap_t, ST_FADEMAPDATA), // tc_fade - NOSECTOR(T_PlaneDisplace, planedisplace_t), // tc_planedisplace -#ifdef ESLOPE - NOSECTOR(T_DynamicSlopeLine, dynplanethink_t), // tc_dynslopeline - NOSECTOR(T_DynamicSlopeVert, dynplanethink_t), // tc_dynslopevert -#endif #ifdef POLYOBJECTS NOSECTOR(T_PolyObjRotate, polyrotate_t), // tc_polyrotate NOSECTOR(T_PolyObjMove, polymove_t), // tc_polymove @@ -1510,8 +1505,6 @@ static const specialdef_t specialDefs[] = NOSECTOR(T_PolyDoorSwing, polyswingdoor_t), // tc_polyswingdoor NOSECTOR(T_PolyObjFlag, polymove_t), // tc_polyflag NOSECTOR(T_PolyObjDisplace, polydisplace_t), // tc_polydisplace - NOSECTOR(T_PolyObjRotDisplace, polyrotdisplace_t), // tc_polyrotdisplace - NOSECTOR(T_PolyObjFade, polyfade_t), // tc_polyfade #endif }; #undef A @@ -3326,6 +3319,7 @@ static void P_LocalUnArchiveThinkers() I_Error("Bad SaveState at archive block Thinkers"); // preserve sky box indexes + /* Probably unused for (i = 0; i < 16; i++) { if (skyboxmo[0] == skyboxviewpnts[i]) @@ -3335,6 +3329,7 @@ static void P_LocalUnArchiveThinkers() skyboxviewpnts[i] = NULL; skyboxcenterpnts[i] = NULL; } + */ skyboxmo[0] = skyboxmo[1] = NULL; // sort thinkers into maps to speed up replacement searches @@ -3378,7 +3373,7 @@ static void P_LocalUnArchiveThinkers() for (i = 0; i < (int)numsectors; i++) { mobj_t* thing = sectors[i].thinglist, *next; - sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = sectors[i].fadecolormapdata = NULL; + sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata; // clear nothinkers too while (thing) @@ -3516,6 +3511,7 @@ static void P_LocalUnArchiveThinkers() bflagpoint = mobj->spawnpoint; } + /* if (mobj->type == MT_SKYBOX) { if ((mobj->extravalue2 >> 16) == 1) @@ -3523,6 +3519,7 @@ static void P_LocalUnArchiveThinkers() else skyboxviewpnts[mobj->extravalue2 & 0xFFFF] = mobj; } + */ if (mobj->player && mobj->type == MT_PLAYER) mobj->player->mo = mobj; @@ -3551,10 +3548,12 @@ static void P_LocalUnArchiveThinkers() target->ceilingdata = newthinker; if (specialDefs[tclass].sectorTargets & ST_FLOORDATA) target->floordata = newthinker; + /* if (specialDefs[tclass].sectorTargets & ST_LIGHTDATA) target->lightingdata = newthinker; if (specialDefs[tclass].sectorTargets & ST_FADEMAPDATA) target->fadecolormapdata = newthinker; + */ } // relink into the new thinker list @@ -3693,15 +3692,15 @@ static void P_LocalUnArchiveThinkers() RELINK(players[i].axis1); RELINK(players[i].axis2); RELINK(players[i].awayviewmobj); - RELINK(players[i].followmobj); - RELINK(players[i].drone); + //RELINK(players[i].followmobj); + //RELINK(players[i].drone); } } #undef RELINK // restore skyboxes - skyboxmo[0] = skyboxviewpnts[(skyviewid >= 0) ? skyviewid : 0]; - skyboxmo[1] = skyboxcenterpnts[(skycenterid >= 0) ? skycenterid : 0]; + //skyboxmo[0] = skyboxviewpnts[(skyviewid >= 0) ? skyviewid : 0]; + //skyboxmo[1] = skyboxcenterpnts[(skycenterid >= 0) ? skycenterid : 0]; } // @@ -4545,50 +4544,26 @@ static inline boolean P_NetUnArchiveMisc(boolean preserveLevel) return true; } +//made kart splitscreen compat static inline void P_LocalArchiveCameras() { WRITEMEM(save_p, &camera, sizeof(camera)); - WRITEMEM(save_p, &camera2, sizeof(camera2)); } +//made kart splitscreen compat static inline void P_LocalUnArchiveCameras() { - boolean chase1 = camera.chase; - boolean chase2 = camera2.chase; + UINT32 i; + boolean chase[4]; + for (i = 0; i < 4; i++) + chase[i] = camera[i].chase; // this makes things easy! READMEM(save_p, &camera, sizeof(camera)); - READMEM(save_p, &camera2, sizeof(camera2)); // chase is changed outside of tics, so preserve this - camera.chase = chase1; - camera2.chase = chase2; -} - -static inline void P_ArchiveLuabanksAndConsistency(void) -{ - UINT8 i, banksinuse = NUM_LUABANKS; - - gamespeed = READUINT8(save_p); - franticitems = (boolean)READUINT8(save_p); - comeback = (boolean)READUINT8(save_p); - for (i = 0; i < 4; i++) - battlewanted[i] = READSINT8(save_p); - - wantedcalcdelay = READUINT32(save_p); - indirectitemcooldown = READUINT32(save_p); - hyubgone = READUINT32(save_p); - mapreset = READUINT32(save_p); - nospectategrief = READUINT8(save_p); - thwompsactive = (boolean)READUINT8(save_p); - spbplace = READSINT8(save_p); - - // Is it paused? - if (READUINT8(save_p) == 0x2f) - paused = true; - - return true; + camera[i].chase = chase[i]; } UINT64 I_GetTimeUs(void); @@ -4735,7 +4710,7 @@ void P_SaveGameState(savestate_t* savestate) WRITEINT16(save_p, gamemap); WRITEUINT32(save_p, globalmobjnum); - CV_SaveNetVars(&save_p); + CV_SaveNetVars(&save_p, false); // assign mobj nums for pointer relinking for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) @@ -4777,7 +4752,7 @@ void P_SaveGameState(savestate_t* savestate) LUA_Archive(); #endif - P_ArchiveLuabanksAndConsistency(); + //P_ArchiveLuabanksAndConsistency(); saveStateBenchmark = I_GetTimeUs() - time; } @@ -4821,7 +4796,7 @@ boolean P_LoadGameState(const savestate_t* savestate) // This is stupid and hacky _squared_, but it's in the net load code and it says it might work, so I guess it might work! //P_SetRandSeed(P_GetInitSeed()); - P_UnArchiveLuabanksAndConsistency(); + //P_UnArchiveLuabanksAndConsistency(); loadStateBenchmark = I_GetTimeUs() - time; return true; diff --git a/src/s_sound.c b/src/s_sound.c index c391a91f4..d709b5191 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -154,19 +154,6 @@ consvar_t cv_playsoundifunfocused = {"playsoundsifunfocused", "No", CV_SAVE|CV_C // percent attenuation from front to back #define S_IFRACVOL 30 -typedef struct -{ - // sound information (if null, channel avail.) - sfxinfo_t *sfxinfo; - - // origin of sound - const void *origin; - - // handle of the sound being played - INT32 handle; - -} channel_t; - // the set of channels available static channel_t *channels = NULL; static INT32 numofchannels = 0; @@ -643,7 +630,7 @@ dontplay: if (origin && origin != listenmobj3) { INT32 rc; - rc = S_AdjustSoundParams(listenmobj3, origin, &volume, &sep, &pitch, sfx); + rc = S_AdjustSoundParams(listenmobj3, origin->x, origin->y, origin->z , &volume, &sep, &pitch, sfx); if (!rc) goto dontplay3; // Maybe the other player can hear it... @@ -699,7 +686,7 @@ dontplay3: if (origin && origin != listenmobj4) { INT32 rc; - rc = S_AdjustSoundParams(listenmobj4, origin, &volume, &sep, &pitch, sfx); + rc = S_AdjustSoundParams(listenmobj4, origin->x, origin->y, origin->z, &volume, &sep, &pitch, sfx); if (!rc) goto dontplay4; // Maybe the other player can hear it... @@ -1240,7 +1227,11 @@ void S_DetachChannelsFromOrigin(void* origin) if (channels[i].origin == origin) { // small hack: player-made sounds should stay hearable - if (originmobj->player != &players[displayplayer]) + if (originmobj->player != &players[displayplayers[0]] && + originmobj->player != &players[displayplayers[1]] && + originmobj->player != &players[displayplayers[2]] && + originmobj->player != &players[displayplayers[3]] + ) { channels[i].isdetached = true; channels[i].detachedx = originmobj->x; diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index e5b4e1b66..3454eca8f 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -131,25 +131,26 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #include #endif -// Locations for searching the srb2.pk3 +// Locations for searching the srb2.srb #if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) -#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2" -#define DEFAULTWADLOCATION2 "/usr/local/games/SRB2" -#define DEFAULTWADLOCATION3 "/usr/share/games/SRB2" -#define DEFAULTWADLOCATION4 "/usr/games/SRB2" +#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2Kart" +#define DEFAULTWADLOCATION2 "/usr/local/games/SRB2Kart" +#define DEFAULTWADLOCATION3 "/usr/share/games/SRB2Kart" +#define DEFAULTWADLOCATION4 "/usr/games/SRB2Kart" #define DEFAULTSEARCHPATH1 "/usr/local/games" #define DEFAULTSEARCHPATH2 "/usr/games" #define DEFAULTSEARCHPATH3 "/usr/local" #elif defined (_WIN32) -#define DEFAULTWADLOCATION1 "c:\\games\\srb2" -#define DEFAULTWADLOCATION2 "\\games\\srb2" +#define DEFAULTWADLOCATION1 "c:\\games\\srb2kart" +#define DEFAULTWADLOCATION2 "\\games\\srb2kart" #define DEFAULTSEARCHPATH1 "c:\\games" #define DEFAULTSEARCHPATH2 "\\games" #endif /** \brief WAD file to look for */ -#define WADKEYWORD1 "srb2.pk3" +#define WADKEYWORD1 "srb2.srb" +#define WADKEYWORD2 "srb2.wad" /** \brief holds wad path */ static char returnWadPath[256]; @@ -204,21 +205,36 @@ static void JoyReset(SDLJoyInfo_t *JoySet) /** \brief First joystick up and running */ -static INT32 joystick_started = 0; +static INT32 joystick_started = 0; /** \brief SDL info about joystick 1 */ SDLJoyInfo_t JoyInfo; - /** \brief Second joystick up and running */ static INT32 joystick2_started = 0; -/** \brief SDL inof about joystick 2 +/** \brief SDL info about joystick 2 */ SDLJoyInfo_t JoyInfo2; +/** \brief Third joystick up and running +*/ +static INT32 joystick3_started = 0; + +/** \brief SDL info about joystick 3 +*/ +SDLJoyInfo_t JoyInfo3; + +/** \brief Fourth joystick up and running +*/ +static INT32 joystick4_started = 0; + +/** \brief SDL info about joystick 4 +*/ +SDLJoyInfo_t JoyInfo4; + #ifdef HAVE_TERMIOS static INT32 fdmouse2 = -1; static INT32 mouse2_started = 0; @@ -608,7 +624,7 @@ static void I_StartupConsole(void) if (gotConsole) { - SetConsoleTitleA("SRB2 Console"); + SetConsoleTitleA("SRB2Kart Console"); consolevent = SDL_TRUE; } @@ -827,6 +843,18 @@ void I_JoyScale2(void) JoyInfo2.scale = Joystick2.bGamepadStyle?1:cv_joyscale2.value; } +void I_JoyScale3(void) +{ + Joystick3.bGamepadStyle = cv_joyscale3.value==0; + JoyInfo3.scale = Joystick3.bGamepadStyle?1:cv_joyscale3.value; +} + +void I_JoyScale4(void) +{ + Joystick4.bGamepadStyle = cv_joyscale4.value==0; + JoyInfo4.scale = Joystick4.bGamepadStyle?1:cv_joyscale4.value; +} + // Cheat to get the device index for a joystick handle INT32 I_GetJoystickDeviceIndex(SDL_Joystick *dev) { @@ -837,12 +865,208 @@ INT32 I_GetJoystickDeviceIndex(SDL_Joystick *dev) SDL_Joystick *test = SDL_JoystickOpen(i); if (test && test == dev) return i; - else if (JoyInfo.dev != test && JoyInfo2.dev != test) + else if (JoyInfo.dev != test && JoyInfo2.dev != test && JoyInfo3.dev != test && JoyInfo4.dev != test) SDL_JoystickClose(test); } return -1; } +// Misleading function: updates device indices for all players BUT the one specified. +// Necessary for SDL_JOYDEVICEADDED events +void I_UpdateJoystickDeviceIndices(INT32 player) +{ + if (player != 1) // This is a fucking mess. + { + ////////////////////////////// + // update joystick 1's device index + ////////////////////////////// + + if (JoyInfo.dev) + cv_usejoystick.value = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; + // is cv_usejoystick used? + else if (// don't check JoyInfo or cv_usejoystick; we're currently operating on those + atoi(cv_usejoystick.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick2.value + && atoi(cv_usejoystick.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick3.value + && atoi(cv_usejoystick.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick4.value) + cv_usejoystick.value = atoi(cv_usejoystick.string); + // is cv_usejoystick2 used? + else if ( // don't check JoyInfo or cv_usejoystick; we're currently operating on those + atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick2.value + && atoi(cv_usejoystick2.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick3.value + && atoi(cv_usejoystick2.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick4.value) + cv_usejoystick.value = atoi(cv_usejoystick2.string); + // is cv_usejoystick3 used? + else if (// don't check JoyInfo or cv_usejoystick; we're currently operating on those + atoi(cv_usejoystick3.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick2.value + && atoi(cv_usejoystick3.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick3.value + && atoi(cv_usejoystick3.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick4.value) + cv_usejoystick.value = atoi(cv_usejoystick3.string); + // is cv_usejoystick4 used? + else if (// don't check JoyInfo or cv_usejoystick; we're currently operating on those + atoi(cv_usejoystick4.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick2.value + && atoi(cv_usejoystick4.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick3.value + && atoi(cv_usejoystick4.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick4.value) + cv_usejoystick.value = atoi(cv_usejoystick4.string); + else // we tried... + cv_usejoystick.value = 0; + } + + if (player != 2) + { + ////////////////////////////// + // update joystick 2's device index + ////////////////////////////// + + if (JoyInfo2.dev) + cv_usejoystick2.value = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; + // is cv_usejoystick2 used? + else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick.value + // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those + && atoi(cv_usejoystick2.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick3.value + && atoi(cv_usejoystick2.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick4.value) + cv_usejoystick2.value = atoi(cv_usejoystick2.string); + // is cv_usejoystick used? + else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick.value + // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those + && atoi(cv_usejoystick.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick3.value + && atoi(cv_usejoystick.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick4.value) + cv_usejoystick2.value = atoi(cv_usejoystick.string); + // is cv_usejoystick3 used? + else if (atoi(cv_usejoystick3.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick.value + // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those + && atoi(cv_usejoystick3.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick3.value + && atoi(cv_usejoystick3.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick4.value) + cv_usejoystick2.value = atoi(cv_usejoystick3.string); + // is cv_usejoystick4 used? + else if (atoi(cv_usejoystick4.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick.value + // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those + && atoi(cv_usejoystick4.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick3.value + && atoi(cv_usejoystick4.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick4.value) + cv_usejoystick2.value = atoi(cv_usejoystick4.string); + else // we tried... + cv_usejoystick2.value = 0; + } + + if (player != 3) + { + ////////////////////////////// + // update joystick 3's device index + ////////////////////////////// + + if (JoyInfo3.dev) + cv_usejoystick3.value = I_GetJoystickDeviceIndex(JoyInfo3.dev) + 1; + // is cv_usejoystick3 used? + else if (atoi(cv_usejoystick3.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick.value + && atoi(cv_usejoystick3.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick2.value + // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those + && atoi(cv_usejoystick3.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick4.value) + cv_usejoystick3.value = atoi(cv_usejoystick3.string); + // is cv_usejoystick used? + else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick.value + && atoi(cv_usejoystick.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick2.value + // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those + && atoi(cv_usejoystick.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick4.value) + cv_usejoystick3.value = atoi(cv_usejoystick.string); + // is cv_usejoystick2 used? + else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick.value + && atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick2.value + // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those + && atoi(cv_usejoystick2.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick4.value) + cv_usejoystick3.value = atoi(cv_usejoystick2.string); + // is cv_usejoystick4 used? + else if (atoi(cv_usejoystick4.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick.value + && atoi(cv_usejoystick4.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick2.value + // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those + && atoi(cv_usejoystick4.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick4.value) + cv_usejoystick3.value = atoi(cv_usejoystick4.string); + else // we tried... + cv_usejoystick3.value = 0; + } + + if (player != 4) + { + ////////////////////////////// + // update joystick 4's device index + ////////////////////////////// + + if (JoyInfo4.dev) + cv_usejoystick4.value = I_GetJoystickDeviceIndex(JoyInfo4.dev) + 1; + // is cv_usejoystick4 used? + else if (atoi(cv_usejoystick4.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick.value + && atoi(cv_usejoystick4.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick2.value + && atoi(cv_usejoystick4.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick3.value) + // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those + cv_usejoystick4.value = atoi(cv_usejoystick4.string); + // is cv_usejoystick used? + else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick.value + && atoi(cv_usejoystick.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick2.value + && atoi(cv_usejoystick.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick3.value) + // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those + cv_usejoystick4.value = atoi(cv_usejoystick.string); + // is cv_usejoystick2 used? + else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick.value + && atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick2.value + && atoi(cv_usejoystick2.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick3.value) + // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those + cv_usejoystick4.value = atoi(cv_usejoystick2.string); + // is cv_usejoystick3 used? + else if (atoi(cv_usejoystick3.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick.value + && atoi(cv_usejoystick3.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick2.value + && atoi(cv_usejoystick3.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick3.value) + // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those + cv_usejoystick4.value = atoi(cv_usejoystick3.string); + else // we tried... + cv_usejoystick4.value = 0; + } +} /** \brief Joystick 1 buttons states */ @@ -1386,6 +1610,548 @@ static int joy_open2(int joyindex) } } +//Joystick3 + +/** \brief Joystick 3 buttons states +*/ +static UINT64 lastjoy3buttons = 0; + +/** \brief Joystick 3 hats state +*/ +static UINT64 lastjoy3hats = 0; + +/** \brief Shuts down joystick 3 + + +\return void +*/ +void I_ShutdownJoystick3(void) +{ + INT32 i; + event_t event; + event.type = ev_keyup; + event.data2 = 0; + event.data3 = 0; + + lastjoy3buttons = lastjoy3hats = 0; + + // emulate the up of all joystick buttons + for (i = 0; i < JOYBUTTONS; i++) + { + event.data1 = KEY_3JOY1 + i; + D_PostEvent(&event); + } + + // emulate the up of all joystick hats + for (i = 0; i < JOYHATS*4; i++) + { + event.data1 = KEY_3HAT1 + i; + D_PostEvent(&event); + } + + // reset joystick position + event.type = ev_joystick3; + for (i = 0; i < JOYAXISSET; i++) + { + event.data1 = i; + D_PostEvent(&event); + } + + joystick3_started = 0; + JoyReset(&JoyInfo3); + + // don't shutdown the subsystem here, because hotplugging +} + +void I_GetJoystick3Events(void) +{ + static event_t event = {0,0,0,0}; + INT32 i = 0; + UINT64 joyhats = 0; +#if 0 + INT64 joybuttons = 0; +#endif + INT32 axisx, axisy; + + if (!joystick3_started) + return; + + if (!JoyInfo3.dev) //I_ShutdownJoystick3(); + return; + + +#if 0 + //faB: look for as much buttons as g_input code supports, + // we don't use the others + for (i = JoyInfo3.buttons - 1; i >= 0; i--) + { + joybuttons <<= 1; + if (SDL_JoystickGetButton(JoyInfo3.dev,i)) + joybuttons |= 1; + } + + if (joybuttons != lastjoy3buttons) + { + INT64 j = 1; // keep only bits that changed since last time + INT64 newbuttons = joybuttons ^ lastjoy3buttons; + lastjoy3buttons = joybuttons; + + for (i = 0; i < JOYBUTTONS; i++, j <<= 1) + { + if (newbuttons & j) // button changed state? + { + if (joybuttons & j) + event.type = ev_keydown; + else + event.type = ev_keyup; + event.data1 = KEY_3JOY1 + i; + D_PostEvent(&event); + } + } + } +#endif + + for (i = JoyInfo3.hats - 1; i >= 0; i--) + { + Uint8 hat = SDL_JoystickGetHat(JoyInfo3.dev, i); + + if (hat & SDL_HAT_UP ) joyhats|=(UINT64)0x1<<(0 + 4*i); + if (hat & SDL_HAT_DOWN ) joyhats|=(UINT64)0x1<<(1 + 4*i); + if (hat & SDL_HAT_LEFT ) joyhats|=(UINT64)0x1<<(2 + 4*i); + if (hat & SDL_HAT_RIGHT) joyhats|=(UINT64)0x1<<(3 + 4*i); + } + + if (joyhats != lastjoy3hats) + { + INT64 j = 1; // keep only bits that changed since last time + INT64 newhats = joyhats ^ lastjoy3hats; + lastjoy3hats = joyhats; + + for (i = 0; i < JOYHATS*4; i++, j <<= 1) + { + if (newhats & j) // hat changed state? + { + if (joyhats & j) + event.type = ev_keydown; + else + event.type = ev_keyup; + event.data1 = KEY_3HAT1 + i; + D_PostEvent(&event); + } + } + } + + // send joystick axis positions + event.type = ev_joystick3; + + for (i = JOYAXISSET - 1; i >= 0; i--) + { + event.data1 = i; + if (i*2 + 1 <= JoyInfo3.axises) + axisx = SDL_JoystickGetAxis(JoyInfo3.dev, i*2 + 0); + else axisx = 0; + if (i*2 + 2 <= JoyInfo3.axises) + axisy = SDL_JoystickGetAxis(JoyInfo3.dev, i*2 + 1); + else axisy = 0; + + // -32768 to 32767 + axisx = axisx/32; + axisy = axisy/32; + + if (Joystick3.bGamepadStyle) + { + // gamepad control type, on or off, live or die + if (axisx < -(JOYAXISRANGE/2)) + event.data2 = -1; + else if (axisx > (JOYAXISRANGE/2)) + event.data2 = 1; + else + event.data2 = 0; + if (axisy < -(JOYAXISRANGE/2)) + event.data3 = -1; + else if (axisy > (JOYAXISRANGE/2)) + event.data3 = 1; + else + event.data3 = 0; + } + else + { + + axisx = JoyInfo3.scale?((axisx/JoyInfo3.scale)*JoyInfo3.scale):axisx; + axisy = JoyInfo3.scale?((axisy/JoyInfo3.scale)*JoyInfo3.scale):axisy; + +#ifdef SDL_JDEADZONE + if (-SDL_JDEADZONE <= axisx && axisx <= SDL_JDEADZONE) axisx = 0; + if (-SDL_JDEADZONE <= axisy && axisy <= SDL_JDEADZONE) axisy = 0; +#endif + + // analog control style , just send the raw data + event.data2 = axisx; // x axis + event.data3 = axisy; // y axis + } + D_PostEvent(&event); + } + +} + +/** \brief Open joystick handle + + \param fname name of joystick + + \return axises + + +*/ +static int joy_open3(int joyindex) +{ + SDL_Joystick *newdev = NULL; + int num_joy = 0; + + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + { + CONS_Printf(M_GetText("Joystick subsystem not started\n")); + return -1; + } + + if (joyindex <= 0) + return -1; + + num_joy = SDL_NumJoysticks(); + + if (num_joy == 0) + { + CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); + return -1; + } + + newdev = SDL_JoystickOpen(joyindex - 1); + + // Handle the edge case where the device <-> joystick index assignment can change due to hotplugging + // This indexing is SDL's responsibility and there's not much we can do about it. + // + // Example: + // 1. Plug Controller A -> Index 0 opened + // 2. Plug Controller B -> Index 1 opened + // 3. Unplug Controller A -> Index 0 closed, Index 1 active + // 4. Unplug Controller B -> Index 0 inactive, Index 1 closed + // 5. Plug Controller B -> Index 0 opened + // 6. Plug Controller A -> Index 0 REPLACED, opened as Controller A; Index 1 is now Controller B + if (JoyInfo3.dev) + { + if (JoyInfo3.dev == newdev // same device, nothing to do + || (newdev == NULL && SDL_JoystickGetAttached(JoyInfo3.dev))) // we failed, but already have a working device + return JoyInfo.axises; + // Else, we're changing devices, so send neutral joy events + CONS_Debug(DBG_GAMELOGIC, "Joystick3 device is changing; resetting events...\n"); + I_ShutdownJoystick3(); + } + + JoyInfo3.dev = newdev; + + if (JoyInfo3.dev == NULL) + { + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick3: couldn't open device - %s\n"), SDL_GetError()); + return -1; + } + else + { + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick3: %s\n"), SDL_JoystickName(JoyInfo3.dev)); + JoyInfo3.axises = SDL_JoystickNumAxes(JoyInfo3.dev); + if (JoyInfo3.axises > JOYAXISSET * 2) + JoyInfo3.axises = JOYAXISSET * 2; + /* if (joyaxes<2) + { + I_OutputMsg("Not enought axes?\n"); + return 0; + }*/ + + JoyInfo3.buttons = SDL_JoystickNumButtons(JoyInfo3.dev); + if (JoyInfo3.buttons > JOYBUTTONS) + JoyInfo3.buttons = JOYBUTTONS; + + JoyInfo3.hats = SDL_JoystickNumHats(JoyInfo3.dev); + if (JoyInfo3.hats > JOYHATS) + JoyInfo3.hats = JOYHATS; + + JoyInfo3.balls = SDL_JoystickNumBalls(JoyInfo3.dev); + + //Joystick.bGamepadStyle = !stricmp(SDL_JoystickName(JoyInfo3.dev), "pad"); + + return JoyInfo3.axises; + } +} + +//Joystick4 + +/** \brief Joystick 4 buttons states +*/ +static UINT64 lastjoy4buttons = 0; + +/** \brief Joystick 4 hats state +*/ +static UINT64 lastjoy4hats = 0; + +/** \brief Shuts down joystick 4 + + +\return void +*/ +void I_ShutdownJoystick4(void) +{ + INT32 i; + event_t event; + event.type = ev_keyup; + event.data2 = 0; + event.data3 = 0; + + lastjoy4buttons = lastjoy4hats = 0; + + // emulate the up of all joystick buttons + for (i = 0; i < JOYBUTTONS; i++) + { + event.data1 = KEY_4JOY1 + i; + D_PostEvent(&event); + } + + // emulate the up of all joystick hats + for (i = 0; i < JOYHATS*4; i++) + { + event.data1 = KEY_4HAT1 + i; + D_PostEvent(&event); + } + + // reset joystick position + event.type = ev_joystick4; + for (i = 0; i < JOYAXISSET; i++) + { + event.data1 = i; + D_PostEvent(&event); + } + + joystick4_started = 0; + JoyReset(&JoyInfo4); + + // don't shutdown the subsystem here, because hotplugging +} + +void I_GetJoystick4Events(void) +{ + static event_t event = {0,0,0,0}; + INT32 i = 0; + UINT64 joyhats = 0; +#if 0 + INT64 joybuttons = 0; +#endif + INT32 axisx, axisy; + + if (!joystick4_started) + return; + + if (!JoyInfo4.dev) //I_ShutdownJoystick4(); + return; + + +#if 0 + //faB: look for as much buttons as g_input code supports, + // we don't use the others + for (i = JoyInfo4.buttons - 1; i >= 0; i--) + { + joybuttons <<= 1; + if (SDL_JoystickGetButton(JoyInfo4.dev,i)) + joybuttons |= 1; + } + + if (joybuttons != lastjoy4buttons) + { + INT64 j = 1; // keep only bits that changed since last time + INT64 newbuttons = joybuttons ^ lastjoy4buttons; + lastjoy4buttons = joybuttons; + + for (i = 0; i < JOYBUTTONS; i++, j <<= 1) + { + if (newbuttons & j) // button changed state? + { + if (joybuttons & j) + event.type = ev_keydown; + else + event.type = ev_keyup; + event.data1 = KEY_4JOY1 + i; + D_PostEvent(&event); + } + } + } +#endif + + for (i = JoyInfo4.hats - 1; i >= 0; i--) + { + Uint8 hat = SDL_JoystickGetHat(JoyInfo4.dev, i); + + if (hat & SDL_HAT_UP ) joyhats|=(UINT64)0x1<<(0 + 4*i); + if (hat & SDL_HAT_DOWN ) joyhats|=(UINT64)0x1<<(1 + 4*i); + if (hat & SDL_HAT_LEFT ) joyhats|=(UINT64)0x1<<(2 + 4*i); + if (hat & SDL_HAT_RIGHT) joyhats|=(UINT64)0x1<<(3 + 4*i); + } + + if (joyhats != lastjoy4hats) + { + INT64 j = 1; // keep only bits that changed since last time + INT64 newhats = joyhats ^ lastjoy4hats; + lastjoy4hats = joyhats; + + for (i = 0; i < JOYHATS*4; i++, j <<= 1) + { + if (newhats & j) // hat changed state? + { + if (joyhats & j) + event.type = ev_keydown; + else + event.type = ev_keyup; + event.data1 = KEY_4HAT1 + i; + D_PostEvent(&event); + } + } + } + + // send joystick axis positions + event.type = ev_joystick4; + + for (i = JOYAXISSET - 1; i >= 0; i--) + { + event.data1 = i; + if (i*2 + 1 <= JoyInfo4.axises) + axisx = SDL_JoystickGetAxis(JoyInfo4.dev, i*2 + 0); + else axisx = 0; + if (i*2 + 2 <= JoyInfo4.axises) + axisy = SDL_JoystickGetAxis(JoyInfo4.dev, i*2 + 1); + else axisy = 0; + + // -32768 to 32767 + axisx = axisx/32; + axisy = axisy/32; + + if (Joystick4.bGamepadStyle) + { + // gamepad control type, on or off, live or die + if (axisx < -(JOYAXISRANGE/2)) + event.data2 = -1; + else if (axisx > (JOYAXISRANGE/2)) + event.data2 = 1; + else + event.data2 = 0; + if (axisy < -(JOYAXISRANGE/2)) + event.data3 = -1; + else if (axisy > (JOYAXISRANGE/2)) + event.data3 = 1; + else + event.data3 = 0; + } + else + { + + axisx = JoyInfo4.scale?((axisx/JoyInfo4.scale)*JoyInfo4.scale):axisx; + axisy = JoyInfo4.scale?((axisy/JoyInfo4.scale)*JoyInfo4.scale):axisy; + +#ifdef SDL_JDEADZONE + if (-SDL_JDEADZONE <= axisx && axisx <= SDL_JDEADZONE) axisx = 0; + if (-SDL_JDEADZONE <= axisy && axisy <= SDL_JDEADZONE) axisy = 0; +#endif + + // analog control style , just send the raw data + event.data2 = axisx; // x axis + event.data3 = axisy; // y axis + } + D_PostEvent(&event); + } + +} + +/** \brief Open joystick handle + + \param fname name of joystick + + \return axises + + +*/ +static int joy_open4(int joyindex) +{ + SDL_Joystick *newdev = NULL; + int num_joy = 0; + + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + { + CONS_Printf(M_GetText("Joystick subsystem not started\n")); + return -1; + } + + if (joyindex <= 0) + return -1; + + num_joy = SDL_NumJoysticks(); + + if (num_joy == 0) + { + CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); + return -1; + } + + newdev = SDL_JoystickOpen(joyindex - 1); + + // Handle the edge case where the device <-> joystick index assignment can change due to hotplugging + // This indexing is SDL's responsibility and there's not much we can do about it. + // + // Example: + // 1. Plug Controller A -> Index 0 opened + // 2. Plug Controller B -> Index 1 opened + // 3. Unplug Controller A -> Index 0 closed, Index 1 active + // 4. Unplug Controller B -> Index 0 inactive, Index 1 closed + // 5. Plug Controller B -> Index 0 opened + // 6. Plug Controller A -> Index 0 REPLACED, opened as Controller A; Index 1 is now Controller B + if (JoyInfo4.dev) + { + if (JoyInfo4.dev == newdev // same device, nothing to do + || (newdev == NULL && SDL_JoystickGetAttached(JoyInfo4.dev))) // we failed, but already have a working device + return JoyInfo.axises; + // Else, we're changing devices, so send neutral joy events + CONS_Debug(DBG_GAMELOGIC, "Joystick4 device is changing; resetting events...\n"); + I_ShutdownJoystick4(); + } + + JoyInfo4.dev = newdev; + + if (JoyInfo4.dev == NULL) + { + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick4: couldn't open device - %s\n"), SDL_GetError()); + return -1; + } + else + { + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick4: %s\n"), SDL_JoystickName(JoyInfo4.dev)); + JoyInfo4.axises = SDL_JoystickNumAxes(JoyInfo4.dev); + if (JoyInfo4.axises > JOYAXISSET * 2) + JoyInfo4.axises = JOYAXISSET * 2; + /* if (joyaxes<2) + { + I_OutputMsg("Not enought axes?\n"); + return 0; + }*/ + + JoyInfo4.buttons = SDL_JoystickNumButtons(JoyInfo4.dev); + if (JoyInfo4.buttons > JOYBUTTONS) + JoyInfo4.buttons = JOYBUTTONS; + + JoyInfo4.hats = SDL_JoystickNumHats(JoyInfo4.dev); + if (JoyInfo4.hats > JOYHATS) + JoyInfo4.hats = JOYHATS; + + JoyInfo4.balls = SDL_JoystickNumBalls(JoyInfo4.dev); + + //Joystick.bGamepadStyle = !stricmp(SDL_JoystickName(JoyInfo4.dev), "pad"); + + return JoyInfo4.axises; + } +} + // // I_InitJoystick // @@ -1417,7 +2183,7 @@ void I_InitJoystick(void) if (cv_usejoystick.value) newjoy = SDL_JoystickOpen(cv_usejoystick.value-1); - if (newjoy && JoyInfo2.dev == newjoy) // don't override an active device +if (newjoy && (JoyInfo2.dev == newjoy || JoyInfo3.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device cv_usejoystick.value = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; else if (newjoy && joy_open(cv_usejoystick.value) != -1) { @@ -1434,7 +2200,7 @@ void I_InitJoystick(void) joystick_started = 0; } - if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy) + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) SDL_JoystickClose(newjoy); } @@ -1446,12 +2212,6 @@ void I_InitJoystick2(void) if (M_CheckParm("-nojoy")) return; - if (M_CheckParm("-noxinput")) - SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); - - if (M_CheckParm("-nohidapi")) - SDL_SetHintWithPriority("SDL_JOYSTICK_HIDAPI", "0", SDL_HINT_OVERRIDE); - if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { CONS_Printf("I_InitJoystick2()...\n"); @@ -1466,7 +2226,7 @@ void I_InitJoystick2(void) if (cv_usejoystick2.value) newjoy = SDL_JoystickOpen(cv_usejoystick2.value-1); - if (newjoy && JoyInfo.dev == newjoy) // don't override an active device + if (newjoy && (JoyInfo.dev == newjoy || JoyInfo3.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device cv_usejoystick2.value = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; else if (newjoy && joy_open2(cv_usejoystick2.value) != -1) { @@ -1483,7 +2243,93 @@ void I_InitJoystick2(void) joystick2_started = 0; } - if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy) + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) + SDL_JoystickClose(newjoy); +} + +void I_InitJoystick3(void) +{ + SDL_Joystick *newjoy = NULL; + + //I_ShutdownJoystick3(); + //SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + if (M_CheckParm("-nojoy")) + return; + + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + { + CONS_Printf("I_InitJoystick3()...\n"); + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) + { + CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); + return; + } + } + + if (cv_usejoystick3.value) + newjoy = SDL_JoystickOpen(cv_usejoystick3.value - 1); + + if (newjoy && (JoyInfo.dev == newjoy || JoyInfo2.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device + cv_usejoystick3.value = I_GetJoystickDeviceIndex(JoyInfo3.dev) + 1; + else if (newjoy && joy_open3(cv_usejoystick3.value) != -1) + { + // SDL's device indexes are unstable, so cv_usejoystick may not match + // the actual device index. So let's cheat a bit and find the device's current index. + JoyInfo3.oldjoy = I_GetJoystickDeviceIndex(JoyInfo3.dev) + 1; + joystick3_started = 1; + } + else + { + if (JoyInfo3.oldjoy) + I_ShutdownJoystick3(); + cv_usejoystick3.value = 0; + joystick3_started = 0; + } + + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) + SDL_JoystickClose(newjoy); +} + +void I_InitJoystick4(void) +{ + SDL_Joystick *newjoy = NULL; + + //I_ShutdownJoystick4(); + //SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + if (M_CheckParm("-nojoy")) + return; + + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + { + CONS_Printf("I_InitJoystick4()...\n"); + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) + { + CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); + return; + } + } + + if (cv_usejoystick4.value) + newjoy = SDL_JoystickOpen(cv_usejoystick4.value - 1); + + if (newjoy && (JoyInfo.dev == newjoy || JoyInfo2.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device + cv_usejoystick4.value = I_GetJoystickDeviceIndex(JoyInfo4.dev) + 1; + else if (newjoy && joy_open4(cv_usejoystick4.value) != -1) + { + // SDL's device indexes are unstable, so cv_usejoystick may not match + // the actual device index. So let's cheat a bit and find the device's current index. + JoyInfo4.oldjoy = I_GetJoystickDeviceIndex(JoyInfo4.dev) + 1; + joystick4_started = 1; + } + else + { + if (JoyInfo4.oldjoy) + I_ShutdownJoystick4(); + cv_usejoystick4.value = 0; + joystick4_started = 0; + } + + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) SDL_JoystickClose(newjoy); } @@ -1494,6 +2340,8 @@ static void I_ShutdownInput(void) // Note these methods are internal to this file, not called elsewhere. I_ShutdownJoystick(); I_ShutdownJoystick2(); + I_ShutdownJoystick3(); + I_ShutdownJoystick4(); if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) { @@ -1599,8 +2447,8 @@ void I_UpdateMumble(const mobj_t *mobj, const listener_t listener) return; if(mumble->uiVersion != 2) { - wcsncpy(mumble->name, L"SRB2 "VERSIONSTRINGW, 256); - wcsncpy(mumble->description, L"Sonic Robo Blast 2 with integrated Mumble Link support.", 2048); + wcsncpy(mumble->name, L"SRB2Kart "VERSIONSTRINGW, 256); + wcsncpy(mumble->description, L"Sonic Robo Blast 2 Kart with integrated Mumble Link support.", 2048); mumble->uiVersion = 2; } mumble->uiTick++; @@ -2003,6 +2851,20 @@ void I_Tactile2(FFType pFFType, const JoyFF_t *FFEffect) (void)FFEffect; } +void I_Tactile3(FFType pFFType, const JoyFF_t *FFEffect) +{ + // UNUSED. + (void)pFFType; + (void)FFEffect; +} + +void I_Tactile4(FFType pFFType, const JoyFF_t *FFEffect) +{ + // UNUSED. + (void)pFFType; + (void)FFEffect; +} + /** \brief empty ticcmd for player 1 */ static ticcmd_t emptycmd; @@ -2021,6 +2883,23 @@ ticcmd_t *I_BaseTiccmd2(void) return &emptycmd2; } +/** \brief empty ticcmd for player 3 +*/ +static ticcmd_t emptycmd3; + +ticcmd_t *I_BaseTiccmd3(void) +{ + return &emptycmd3; +} + +/** \brief empty ticcmd for player 4 +*/ +static ticcmd_t emptycmd4; + +ticcmd_t *I_BaseTiccmd4(void) +{ + return &emptycmd4; +} static int lastTimeFudge = -1; extern consvar_t cv_timefudge; @@ -2266,14 +3145,14 @@ void I_Quit(void) #ifndef NONET D_SaveBan(); // save the ban list #endif - G_SaveGameData(); // Tails 12-08-2002 + G_SaveGameData(false); // Tails 12-08-2002 //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. - if (demorecording) + if (demo.recording) G_CheckDemoStatus(); if (metalrecording) - G_StopMetalRecording(false); + G_StopMetalRecording(); D_QuitNetGame(); I_ShutdownMusic(); @@ -2351,7 +3230,7 @@ void I_Error(const char *error, ...) if (errorcount == 9) { M_SaveConfig(NULL); - G_SaveGameData(); + G_SaveGameData(false); } if (errorcount > 20) { @@ -2385,13 +3264,13 @@ void I_Error(const char *error, ...) #ifndef NONET D_SaveBan(); // save the ban list #endif - G_SaveGameData(); // Tails 12-08-2002 + G_SaveGameData(false); // Tails 12-08-2002 // Shutdown. Here might be other errors. - if (demorecording) + if (demo.recording) G_CheckDemoStatus(); if (metalrecording) - G_StopMetalRecording(false); + G_StopMetalRecording(); D_QuitNetGame(); I_ShutdownMusic(); @@ -2407,7 +3286,7 @@ void I_Error(const char *error, ...) // which should fail gracefully if it can't put a message box up // on the target system SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "SRB2 "VERSIONSTRING" Error", + "SRB2Kart "VERSIONSTRING" Error", buffer, NULL); // Note that SDL_ShowSimpleMessageBox does *not* require SDL to be // initialized at the time, so calling it after SDL_Quit() is @@ -2540,7 +3419,7 @@ void I_GetDiskFreeSpace(INT64 *freespace) char *I_GetUserName(void) { - static char username[MAXPLAYERNAME+1]; + static char username[MAXPLAYERNAME]; char *p; #ifdef _WIN32 DWORD i = MAXPLAYERNAME; @@ -2671,6 +3550,14 @@ static boolean isWadPathOk(const char *path) return true; } + sprintf(wad3path, pandf, path, WADKEYWORD2); + + if (FIL_ReadFileOK(wad3path)) + { + free(wad3path); + return true; + } + free(wad3path); return false; } @@ -2688,7 +3575,7 @@ static void pathonly(char *s) } } -/** \brief search for srb2.pk3 in the given path +/** \brief search for srb2.srb in the given path \param searchDir starting path @@ -2708,13 +3595,20 @@ static const char *searchWad(const char *searchDir) pathonly(tempsw); return tempsw; } - + + strcpy(tempsw, WADKEYWORD2); + fstemp = filesearch(tempsw, searchDir, NULL, true, 20); + if (fstemp == FS_FOUND) + { + pathonly(tempsw); + return tempsw; + } return NULL; } -/** \brief go through all possible paths and look for srb2.pk3 +/** \brief go through all possible paths and look for srb2.srb - \return path to srb2.pk3 if any + \return path to srb2.srb if any */ static const char *locateWad(void) { @@ -2843,7 +3737,7 @@ const char *I_LocateWad(void) if (waddir) { - // change to the directory where we found srb2.pk3 + // change to the directory where we found srb2.srb #if defined (_WIN32) SetCurrentDirectoryA(waddir); #else From ff258858c80fbf8240a91cfc296eafa3136a586a Mon Sep 17 00:00:00 2001 From: Ashnal Date: Thu, 20 Feb 2020 17:15:22 -0500 Subject: [PATCH 58/67] This ...might ... fix joining this as a server moved tc_end to where a vanilla client expects it --- src/p_saveg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index ce6ce6338..feafdabde 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2405,8 +2405,8 @@ static void P_NetArchiveThinkers(void) CONS_Debug(DBG_NETPLAY, "%u thinkers saved in list %d\n", numsaved, i); - WRITEUINT8(save_p, tc_end); } + WRITEUINT8(save_p, tc_end); } // Now save the pointers, tracer and target, but at load time we must From 2f410e59c77154ede79d72ba42f017013a295978 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Thu, 20 Feb 2020 19:20:38 -0500 Subject: [PATCH 59/67] Gonna disable this cmd adjustment as it causes desyncs when switching levels --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 92a5d2042..5d6e7115e 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4958,7 +4958,7 @@ static void CL_SendClientCmd(void) else if (gamestate != GS_NULL) { ticcmd_t adjustedCmd = localcmds; - AdjustSimulatedTiccmdInputs(&adjustedCmd); // adjust ticcmds for simulations + //AdjustSimulatedTiccmdInputs(&adjustedCmd); // adjust ticcmds for simulations G_MoveTiccmd(&netbuffer->u.clientpak.cmd, &adjustedCmd, 1); netbuffer->u.clientpak.consistancy = SHORT(consistancy[gametic%BACKUPTICS]); From 0184bd27793318c45ad72f241d4f9afc89c3eb7c Mon Sep 17 00:00:00 2001 From: Ashnal Date: Thu, 20 Feb 2020 21:44:55 -0500 Subject: [PATCH 60/67] Fixes the server not taking player cmd --- src/d_clisrv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 5d6e7115e..9f2b444b0 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4114,8 +4114,9 @@ static void HandlePacketFromAwayNode(SINT8 node) if (client) { - maketic = gametic = simtic = neededtic = (tic_t)LONG(netbuffer->u.servercfg.gametic); - gametype = netbuffer->u.servercfg.gametype; + maketic = gametic = neededtic = (tic_t)LONG(netbuffer->u.servercfg.gametic); + if ((gametype = netbuffer->u.servercfg.gametype) >= NUMGAMETYPES) + I_Error("Bad gametype in cliserv!"); modifiedgame = netbuffer->u.servercfg.modifiedgame; for (j = 0; j < MAXPLAYERS; j++) adminplayers[j] = netbuffer->u.servercfg.adminplayers[j]; @@ -4958,6 +4959,7 @@ static void CL_SendClientCmd(void) else if (gamestate != GS_NULL) { ticcmd_t adjustedCmd = localcmds; + packetsize = sizeof (clientcmd_pak); //AdjustSimulatedTiccmdInputs(&adjustedCmd); // adjust ticcmds for simulations G_MoveTiccmd(&netbuffer->u.clientpak.cmd, &adjustedCmd, 1); From bee9aaee632db077dc1d85cf3c01ca3a36c68198 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Thu, 20 Feb 2020 22:02:23 -0500 Subject: [PATCH 61/67] Game connects and somewhat plays ... still many problems and crashes --- src/p_saveg.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index feafdabde..26604d43f 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -442,6 +442,12 @@ static void P_NetUnArchivePlayers(void) // SRB2kart players[i].kartspeed = READUINT8(save_p); players[i].kartweight = READUINT8(save_p); + + for (j = 0; j < MAXPREDICTTICS; j++) + { + players[i].lturn_max[j] = READINT16(save_p); + players[i].rturn_max[j] = READINT16(save_p); + } } } @@ -700,13 +706,6 @@ static void P_NetUnArchiveColormaps(void) if (i < num_net_colormaps-1 && !exc_next) exc_next = R_CreateDefaultColormap(false); } - - for (j = 0; j < MAXPREDICTTICS; j++) - { - players[i].lturn_max[j] = READINT16(save_p); - players[i].rturn_max[j] = READINT16(save_p); - } - } } */ @@ -4537,6 +4536,22 @@ static inline boolean P_NetUnArchiveMisc(boolean preserveLevel) // SRB2kart numgotboxes = READINT32(save_p); + + gamespeed = READUINT8(save_p); + franticitems = (boolean)READUINT8(save_p); + comeback = (boolean)READUINT8(save_p); + + for (i = 0; i < 4; i++) + battlewanted[i] = READSINT8(save_p); + + wantedcalcdelay = READUINT32(save_p); + indirectitemcooldown = READUINT32(save_p); + hyubgone = READUINT32(save_p); + mapreset = READUINT32(save_p); + nospectategrief = READUINT8(save_p); + thwompsactive = (boolean)READUINT8(save_p); + spbplace = READSINT8(save_p); + // Is it paused? if (READUINT8(save_p) == 0x2f) paused = true; From 0be50629c46c9c6ada5e96ad2a97a3edc6e79af3 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Fri, 21 Feb 2020 19:35:54 -0500 Subject: [PATCH 62/67] Fixed netgame waypoint crash --- src/p_saveg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/p_saveg.c b/src/p_saveg.c index 26604d43f..31d6a75f4 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3756,6 +3756,7 @@ static void P_NetUnArchiveThinkers(boolean preserveLevel) // we don't want the removed mobjs to come back iquetail = iquehead = 0; + waypointcap = NULL; //Hack transplant, was being called in P_InitThinkers, which was removed from here for memory leak reasons? Se we moved the hack here for netgames // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity for (i = 0; i < numsectors; i++) From 70f4b20161a680c73c5438bf123be2a0e7be988f Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 21 Feb 2020 20:41:20 +0000 Subject: [PATCH 63/67] Renamed some commands --- src/d_netcmd.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 7a9d50794..0b062c40e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -474,13 +474,22 @@ boolean forceresetplayers = false; boolean deferencoremode = false; UINT8 splitscreen = 0; boolean circuitmap = true; // SRB2kart + consvar_t cv_simulate = { "simulate", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL }; static CV_PossibleValue_t simulateTics_cons_t[] = { {0, "MIN"}, {MAXSIMULATIONS - 1, "MAX"}, {0, NULL} }; -consvar_t cv_simulatetics = { "simulatetics", "MAX", 0, simulateTics_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_simulatetics = { "simtics", "MAX", 0, simulateTics_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; static CV_PossibleValue_t simulateculldistance_cons_t[] = { {0, "MIN"}, {10000, "MAX"}, {0, NULL} }; -consvar_t cv_simulateculldistance = { "simulateculldistance", "MIN", 0, simulateculldistance_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_simulateculldistance = { "simcull", "MIN", 0, simulateculldistance_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; + +static CV_PossibleValue_t netsteadyplayers_cons_t[] = { {0, "MIN"}, {MAXSIMULATIONS - 1, "MAX"}, {0, NULL} }; +consvar_t cv_netsteadyplayers = { "simsteadyplayers", "0", 0, netsteadyplayers_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; + +static CV_PossibleValue_t nettrails_cons_t[] = { {0, "MIN"}, {5, "MAX"}, {0, NULL} }; +consvar_t cv_nettrails = { "simtrails", "5", 0, nettrails_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; + +consvar_t cv_netslingdelay = { "simslingdelay", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; static CV_PossibleValue_t netdelay_cons_t[] = { {0, "MIN"}, {250, "MAX"}, {0, NULL} }; consvar_t cv_netdelay = { "netdelay", "0", 0, netdelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; @@ -495,17 +504,9 @@ consvar_t cv_netspikes = { "netspikes", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, static CV_PossibleValue_t debugsimulaterewind_cons_t[] = { {0, "MIN"}, {BACKUPTICS - 1, "MAX"}, {0, NULL} }; consvar_t cv_debugsimulaterewind = { "debugsimulaterewind", "0", 0, debugsimulaterewind_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; -static CV_PossibleValue_t netsteadyplayers_cons_t[] = { {0, "MIN"}, {MAXSIMULATIONS - 1, "MAX"}, {0, NULL} }; -consvar_t cv_netsteadyplayers = { "netsteadyplayers", "0", 0, netsteadyplayers_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; - static CV_PossibleValue_t timefudge_cons_t[] = { {0, "MIN"}, {100, "MAX"}, {0, NULL} }; consvar_t cv_timefudge = { "timefudge", "0", 0, timefudge_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; -static CV_PossibleValue_t nettrails_cons_t[] = { {0, "MIN"}, {5, "MAX"}, {0, NULL} }; -consvar_t cv_nettrails = { "nettrails", "5", 0, nettrails_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; - -consvar_t cv_netslingdelay = { "netslingdelay", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; - char timedemo_name[256]; boolean timedemo_csv; char timedemo_csv_id[256]; From 2e4a11fc64bb5545bf51762f59efa19d41f6b4a8 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Mon, 24 Feb 2020 16:38:06 -0500 Subject: [PATCH 64/67] prevent crash until voting screen is fixed --- src/f_finale.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/f_finale.c b/src/f_finale.c index 2bf5c7438..c4332f5d8 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1177,6 +1177,9 @@ void F_WaitingPlayersTicker(void) void F_WaitingPlayersDrawer(void) { + if (!waitcolormap) + F_StartWaitingPlayers(); + UINT32 frame = (finalecount % 8) / 4; // The game only tics every other frame while waitingplayers INT32 flags = V_FLIP; const char *waittext1 = "You will join"; From df4222e8dce31bc4e083bd3a84b167837c9783d5 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Mon, 24 Feb 2020 17:44:54 -0500 Subject: [PATCH 65/67] relink up waypoint cap on local state loading? --- src/p_saveg.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 31d6a75f4..8a46f91fa 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3260,6 +3260,7 @@ static void P_LocalArchiveThinkers(void) WRITEUINT8(save_p, 0xFF); // next list (or end) } + //RELINK(waypointcap); // now write the nothinkers... // turns out that MF_NOTHINKs aren't in thinker lists lol.... // makes sense, but doesn't make life easier. I just wanted an object list. Ah well. @@ -3367,6 +3368,7 @@ static void P_LocalUnArchiveThinkers() // remove from item respawn queues iquetail = iquehead = 0; + waypointcap = NULL; // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity for (i = 0; i < (int)numsectors; i++) @@ -3509,7 +3511,11 @@ static void P_LocalUnArchiveThinkers() blueflag = mobj; bflagpoint = mobj->spawnpoint; } - + if (mobj->type == MT_BOSS3WAYPOINT) + { + //P_SetTarget(&mobj->tracer, waypointcap); + P_SetTarget(&waypointcap, mobj); + } /* if (mobj->type == MT_SKYBOX) { @@ -3650,6 +3656,9 @@ static void P_LocalUnArchiveThinkers() // restore pointers #define RELINK(var) if (var) { UINT32 index = (UINT32)var; var = NULL; P_SetTarget(&var, mobjByNum[index]); } + + //RELINK(waypointcap); + for (thinker = thlist[THINK_MOBJ].next; thinker != &thlist[THINK_MOBJ]; thinker = thinker->next) { if (thinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) From ed1554de2490af46133cab28a66777d5d6aa1767 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Sat, 29 Feb 2020 19:41:22 -0500 Subject: [PATCH 66/67] Disabled sim before race begin and after race end May help with wierd intermission issues --- src/d_clisrv.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 9f2b444b0..d69337d02 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5520,7 +5520,10 @@ void TryRunTics(tic_t realtics) // record the actual local controls boolean canSimulate = (gamestate == GS_LEVEL) - && leveltime >= TICRATE && gametic >= TICRATE && (cv_simulate.value && !server) + && leveltime >= TICRATE*4 + && gametic >= TICRATE + && !countdown2 //SRB2Kart: No simulating after everyone has finished ... it breaks stuff + && (cv_simulate.value && !server) //SRB2Kart: make it impossible to sim before the start of the race && !resynch_local_inprogress && gametic >= lastSavestateClearedTic + TICRATE; boolean recordingStates = canSimulate; @@ -5539,9 +5542,9 @@ void TryRunTics(tic_t realtics) PerformDebugRewinds(); - // record the actual local controls for this frame liveTic = I_GetTime(); + // record the actual local controls for this frame for (tic_t i = 0; i < realtics; i++) localTicBuffer[(liveTic - i) % BACKUPTICS] = localcmds; @@ -5590,8 +5593,8 @@ void TryRunTics(tic_t realtics) } // Leave a certain amount of tics present in the net buffer as long as we've ran at least one tic this frame. - //if (client && gamestate == GS_LEVEL && leveltime > 3 && neededtic <= gametic + cv_netticbuffer.value) - // break; + if (client && gamestate == GS_LEVEL && leveltime > 3 && neededtic <= gametic + cv_netticbuffer.value) + break; } } } From 36cb5624bea04d27d5752a679a998af1cc834bee Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 5 Mar 2024 06:43:53 +0100 Subject: [PATCH 67/67] Revert "gitignore" This reverts commit 7c7d0ba9c368066c38912823260466513518a2f5. --- .gitignore | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.gitignore b/.gitignore index f4141918c..3090417dd 100644 --- a/.gitignore +++ b/.gitignore @@ -21,11 +21,3 @@ Win32_LIB_ASM_Release /.vs /debian /assets/debian -.vscode -SRB2Kart64 -SRB2Kart32 -**/*.gif -**/*.dat -**/*.wad -**/*.pk3 -**/*.exe \ No newline at end of file