From 88b81aa28b70a005b3c7f42aef3a299b0ac1a299 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Jul 2024 15:56:44 +0200 Subject: [PATCH 01/51] e --- src/r_main.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 6ea1433a8..764d34403 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -140,7 +140,6 @@ ps_metric_t ps_numsprites = {0}; ps_metric_t ps_numdrawnodes = {0}; ps_metric_t ps_numpolyobjects = {0}; -#if defined(__x86_64__) || defined(__amd64__) || defined(__aarch64__) || defined(__arm64__) // only for 64bit (idk how else to proper check lmao) static CV_PossibleValue_t drawdist_cons_t[] = { /*{256, "256"},*/ {512, "512"}, {768, "768"}, {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, @@ -148,17 +147,12 @@ static CV_PossibleValue_t drawdist_cons_t[] = { {8192, "8192"}, {12288, "12288"}, {20480, "20480"}, {24576, "24576"},{0, "Infinite"}, {0, NULL}}; +#if defined(__x86_64__) || defined(__amd64__) || defined(__aarch64__) || defined(__arm64__) // only for 64bit (idk how else to proper check lmao) static CV_PossibleValue_t drawdist_precip_cons_t[] = { {256, "256"}, {512, "512"}, {768, "768"}, {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, {3072, "3072"}, {4096, "4096"}, {0, "None"}, {0, NULL}}; #else -static CV_PossibleValue_t drawdist_cons_t[] = { - /*{256, "256"},*/ {512, "512"}, {768, "768"}, - {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, - {3072, "3072"}, {4096, "4096"}, {6144, "6144"}, - {8192, "8192"}, {0, "Infinite"}, {0, NULL}}; - static CV_PossibleValue_t drawdist_precip_cons_t[] = { {256, "256"}, {512, "512"}, {768, "768"}, {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, From 51ce092a6a204bf74ef875808fa7cc2ccfdf937f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 04:13:42 +0200 Subject: [PATCH 02/51] lower pinchdist in director since we cant get an accurate value for distance to finish line, this should do it perhaps --- src/k_director.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_director.c b/src/k_director.c index eb4e458ed..60f9f896a 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -23,7 +23,7 @@ #define TRANSFERTIME TICRATE // how long to delay reaction shots? #define BREAKAWAYDIST 4000 // how *far* until players considered far apart? #define WALKBACKDIST 600 // how close should a trailing player be before we switch? -#define PINCHDIST 30000 // how close should the leader be to be considered "end of race"? +#define PINCHDIST 20000 // how close should the leader be to be considered "end of race"? struct directorinfo directorinfo; From 01b060b0fe5238a6fd261f73bc96d6a285648913 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 04:13:51 +0200 Subject: [PATCH 03/51] cleanup k_director --- src/k_director.c | 30 ++++++++++++++---------------- src/k_director.h | 12 ------------ 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/k_director.c b/src/k_director.c index 60f9f896a..4d94e4b81 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -25,7 +25,17 @@ #define WALKBACKDIST 600 // how close should a trailing player be before we switch? #define PINCHDIST 20000 // how close should the leader be to be considered "end of race"? -struct directorinfo directorinfo; +struct directorinfo +{ + tic_t cooldown; // how long has it been since we last switched? + tic_t freeze; // when nonzero, fixed switch pending, freeze logic! + INT32 attacker; // who to switch to when freeze delay elapses + INT32 maxdist; // how far is the closest player from finishing? + + INT32 sortedplayers[MAXPLAYERS]; // position-1 goes in, player index comes out. + INT32 gap[MAXPLAYERS]; // gap between a given position and their closest pursuer + INT32 boredom[MAXPLAYERS]; // how long has a given position had no credible attackers? +} directorinfo; static boolean race_rules() { @@ -164,7 +174,7 @@ static void K_UpdateDirectorPositions(void) if (directorinfo.gap[position] >= BREAKAWAYDIST) { - directorinfo.boredom[position] = min(BOREDOMTIME * 2, directorinfo.boredom[position] + 1); + directorinfo.boredom[position] = (INT32)(min(BOREDOMTIME * 2, directorinfo.boredom[position] + 1)); } else if (directorinfo.boredom[position] > 0) { @@ -183,13 +193,6 @@ static void K_UpdateDirectorPositions(void) static boolean K_CanSwitchDirector(void) { - /*INT32 *displayplayerp = &displayplayers[0]; - - if (players[*displayplayerp].trickpanel > 0) - { - return false; - }*/ - if (directorinfo.cooldown > 0) { return false; @@ -283,11 +286,6 @@ void K_DrawDirectorDebugger(void) V_DrawThinString(10, ytxt, V_70TRANS, va("%d", position)); V_DrawThinString(20, ytxt, V_70TRANS, va("%d", position + 1)); - /*if (players[leader].positiondelay) - { - V_DrawThinString(40, ytxt, V_70TRANS, va("NG")); - }*/ - V_DrawThinString(80, ytxt, V_70TRANS, va("%d", directorinfo.gap[position])); if (directorinfo.boredom[position] >= BOREDOMTIME) @@ -378,13 +376,13 @@ void K_UpdateDirector(void) target = directorinfo.sortedplayers[targetposition]; // if we're certain the back half of the pair is actually in this position, try to switch - if (*displayplayerp != target /*&& !players[target].positiondelay*/) + if (*displayplayerp != target) { K_DirectorSwitch(target, false); } // even if we're not certain, if we're certain we're watching the WRONG player, try to switch - if (players[*displayplayerp].kartstuff[k_position] != targetposition+1 /*&& !players[target].positiondelay*/) + if (players[*displayplayerp].kartstuff[k_position] != targetposition+1) { K_DirectorSwitch(target, false); } diff --git a/src/k_director.h b/src/k_director.h index 7218cc7e3..3be71b675 100644 --- a/src/k_director.h +++ b/src/k_director.h @@ -10,18 +10,6 @@ /// \file k_director.h /// \brief SRB2kart automatic spectator camera. -extern struct directorinfo -{ - tic_t cooldown; // how long has it been since we last switched? - tic_t freeze; // when nonzero, fixed switch pending, freeze logic! - INT32 attacker; // who to switch to when freeze delay elapses - INT32 maxdist; // how far is the closest player from finishing? - - INT32 sortedplayers[MAXPLAYERS]; // position-1 goes in, player index comes out. - INT32 gap[MAXPLAYERS]; // gap between a given position and their closest pursuer - INT32 boredom[MAXPLAYERS]; // how long has a given position had no credible attackers? -} directorinfo; - void K_InitDirector(void); void K_UpdateDirector(void); void K_DrawDirectorDebugger(void); From 48bcaacada927af26f7917310033af7c1e33136e Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 04:26:06 +0200 Subject: [PATCH 04/51] fix K_DrawDirectorDebugger --- src/k_kart.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/k_kart.c b/src/k_kart.c index 3f134ef33..93a4006e0 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -10663,6 +10663,9 @@ void K_drawKartHUD(void) if (cv_kartdebugcheckpoint.value) K_drawCheckpointDebugger(); + if (cv_kartdebugdirector.value) + K_DrawDirectorDebugger(); + if (cv_kartdebugnodes.value) { UINT8 p; From ffcff99a79bd1ed124109b6cac1987154248ad00 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 04:29:05 +0200 Subject: [PATCH 05/51] lower breakawaydist in director --- src/k_director.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_director.c b/src/k_director.c index 4d94e4b81..326b81fe4 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -21,7 +21,7 @@ #define SWITCHTIME TICRATE * 5 // cooldown between unforced switches #define BOREDOMTIME 3 * TICRATE / 2 // how long until players considered far apart? #define TRANSFERTIME TICRATE // how long to delay reaction shots? -#define BREAKAWAYDIST 4000 // how *far* until players considered far apart? +#define BREAKAWAYDIST 2000 // how *far* until players considered far apart? #define WALKBACKDIST 600 // how close should a trailing player be before we switch? #define PINCHDIST 20000 // how close should the leader be to be considered "end of race"? From 41e97ffa79cbf6439e46fa6c8481d2d0aadf0fee Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 16:40:37 +0200 Subject: [PATCH 06/51] another smol fix to director --- src/k_director.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/k_director.c b/src/k_director.c index 326b81fe4..225bfe70e 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -375,6 +375,12 @@ void K_UpdateDirector(void) target = directorinfo.sortedplayers[targetposition]; + // stop here since we're already viewing this player + if (displayplayers[0] == target) + { + break; + } + // if we're certain the back half of the pair is actually in this position, try to switch if (*displayplayerp != target) { From 67542d3cf154b37ff5920edf504c7e9b27602cef Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 18:00:04 +0200 Subject: [PATCH 07/51] i didnt knew k_positiondelay exists --- src/k_director.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/k_director.c b/src/k_director.c index 225bfe70e..c0687494d 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -286,6 +286,11 @@ void K_DrawDirectorDebugger(void) V_DrawThinString(10, ytxt, V_70TRANS, va("%d", position)); V_DrawThinString(20, ytxt, V_70TRANS, va("%d", position + 1)); + if (players[leader].kartstuff[k_positiondelay]) + { + V_DrawThinString(40, ytxt, V_70TRANS, va("NG")); + } + V_DrawThinString(80, ytxt, V_70TRANS, va("%d", directorinfo.gap[position])); if (directorinfo.boredom[position] >= BOREDOMTIME) @@ -376,19 +381,19 @@ void K_UpdateDirector(void) target = directorinfo.sortedplayers[targetposition]; // stop here since we're already viewing this player - if (displayplayers[0] == target) + if (*displayplayerp == target) { break; } // if we're certain the back half of the pair is actually in this position, try to switch - if (*displayplayerp != target) + if (!players[target].kartstuff[k_positiondelay]) { K_DirectorSwitch(target, false); } // even if we're not certain, if we're certain we're watching the WRONG player, try to switch - if (players[*displayplayerp].kartstuff[k_position] != targetposition+1) + if (players[*displayplayerp].kartstuff[k_position] != targetposition+1 && !players[*displayplayerp].kartstuff[k_positiondelay]) { K_DirectorSwitch(target, false); } From 8b60fb6b6cd06b384b1e239fb60392565a9df9df Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 3 Aug 2024 17:36:07 +0200 Subject: [PATCH 08/51] revert this --- src/k_kart.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 93a4006e0..628060743 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -4139,13 +4139,6 @@ void K_UpdateHnextList(player_t *player, boolean clean) P_RemoveMobj(work); } - - if (player->mo->hnext == NULL || P_MobjWasRemoved(player->mo->hnext)) - { - // Like below, try to clean up the pointer if it's NULL. - // Maybe this was a cause of the shrink/eggbox fails? - P_SetTarget(&player->mo->hnext, NULL); - } } // For getting hit! From 96ee117657018df5f686c340c56ff3a2aaf33e7a Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 3 Aug 2024 17:36:31 +0200 Subject: [PATCH 09/51] Revert "more reference fixes" This reverts commit 94bd1cb37b9b0e90e8c1fb00649aed96b2c0e20d. --- src/lua_blockmaplib.c | 4 +--- src/p_map.c | 18 ++++++++---------- src/p_mobj.c | 27 +++++---------------------- 3 files changed, 14 insertions(+), 35 deletions(-) diff --git a/src/lua_blockmaplib.c b/src/lua_blockmaplib.c index 2367673cd..0b93766b8 100644 --- a/src/lua_blockmaplib.c +++ b/src/lua_blockmaplib.c @@ -53,12 +53,10 @@ 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 @@ -258,4 +256,4 @@ int LUA_BlockmapLib(lua_State *L) { lua_register(L, "searchBlockmap", lib_searchBlockmap); return 0; -} +} \ No newline at end of file diff --git a/src/p_map.c b/src/p_map.c index bcb2b6a73..6051d5d1c 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1548,13 +1548,13 @@ static boolean PIT_CheckThing(mobj_t *thing) { tmfloorz = tmceilingz = topz; // block while in air tmceilingslope = NULL; - P_SetTarget(&tmfloorthing, thing); // needed for side collision + tmfloorthing = thing; // needed for side collision } else if (topz < tmceilingz && tmthing->z <= thing->z+thing->height) { tmceilingz = topz; tmceilingslope = NULL; - P_SetTarget(&tmfloorthing, thing); // thing we may stand on + tmfloorthing = thing; // thing we may stand on } } else @@ -1585,13 +1585,13 @@ static boolean PIT_CheckThing(mobj_t *thing) { tmfloorz = tmceilingz = topz; // block while in air tmfloorslope = NULL; - P_SetTarget(&tmfloorthing, thing); // needed for side collision + tmfloorthing = thing; // needed for side collision } else if (topz > tmfloorz && tmthing->z+tmthing->height >= thing->z) { tmfloorz = topz; tmfloorslope = NULL; - P_SetTarget(&tmfloorthing, thing); // thing we may stand on + tmfloorthing = thing; // thing we may stand on } } } @@ -1991,8 +1991,8 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) } // tmfloorthing is set when tmfloorz comes from a thing's top - P_SetTarget(&tmfloorthing, NULL); - P_SetTarget(&tmhitthing, NULL); + tmfloorthing = NULL; + tmhitthing = NULL; validcount++; @@ -2489,10 +2489,8 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) if (tmceilingz - tmfloorz < thing->height) { - if (tmfloorthing != NULL) - { - P_SetTarget(&tmhitthing, tmfloorthing); - } + if (tmfloorthing) + tmhitthing = tmfloorthing; return false; // doesn't fit } diff --git a/src/p_mobj.c b/src/p_mobj.c index 5e5b9924b..3cfb92f85 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6112,8 +6112,7 @@ void P_MobjThinker(mobj_t *mobj) mobj->flags2 &= ~MF2_PUSHED; mobj->eflags &= ~(MFE_SPRUNG|MFE_JUSTBOUNCEDWALL); - P_SetTarget(&tmfloorthing, NULL); - P_SetTarget(&tmhitthing, NULL); + tmfloorthing = tmhitthing = NULL; // 970 allows ANY mobj to trigger a linedef exec if (mobj->subsector && GETSECSPECIAL(mobj->subsector->sector->special, 2) == 8) @@ -10070,29 +10069,13 @@ void P_RemoveMobj(mobj_t *mobj) P_SetTarget(&mobj->target, NULL); P_SetTarget(&mobj->tracer, NULL); - // repair hnext chain - mobj_t *cachenext = mobj->hnext; - if (mobj->hnext && !P_MobjWasRemoved(mobj->hnext)) - { - if (mobj->hnext->hprev == mobj) - { - P_SetTarget(&mobj->hnext->hprev, mobj->hprev); - } - - P_SetTarget(&mobj->hnext, NULL); - } - + P_SetTarget(&mobj->hnext->hprev, mobj->hprev); if (mobj->hprev && !P_MobjWasRemoved(mobj->hprev)) - { - if (mobj->hprev->hnext == mobj) - { - P_SetTarget(&mobj->hprev->hnext, cachenext); - } + P_SetTarget(&mobj->hprev->hnext, mobj->hnext); + + P_SetTarget(&mobj->hnext, P_SetTarget(&mobj->hprev, NULL)); - P_SetTarget(&mobj->hprev, NULL); - } - // clear the reference from the mapthing if (mobj->spawnpoint) P_SetTarget(&mobj->spawnpoint->mobj, NULL); From fd797436fa2a9cc2e616f4ea0101a1e363eb83df Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 3 Aug 2024 17:36:53 +0200 Subject: [PATCH 10/51] Revert "fix declaration" This reverts commit 8f195530b5fa02e13cc97be2b8f3c7992f13fd24. --- src/p_tick.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_tick.h b/src/p_tick.h index 11b5889ed..d22995a11 100644 --- a/src/p_tick.h +++ b/src/p_tick.h @@ -28,7 +28,7 @@ void P_RunChaseCameras(void); void P_Ticker(boolean run); void P_PreTicker(INT32 frames); void P_DoTeamscrambling(void); -void P_RemoveThinkerDelayed(thinker_t *thinker); +void P_RemoveThinkerDelayed(void *pthinker); //killed mobj_t *P_SetTarget(mobj_t **mo, mobj_t *target); // killough 11/98 #endif From 6f53263107c77afed4d07567c7a40e4831660d99 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 3 Aug 2024 17:37:06 +0200 Subject: [PATCH 11/51] Revert "Clean up mobj and thinker removal" This reverts commit 048ccf52b0de555b91a2bb7130dee04dc4427d58. --- src/p_mobj.c | 47 +++++++++++++++++++++++++++++------------------ src/p_tick.c | 44 +++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 3cfb92f85..d7d2b37c6 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10075,7 +10075,7 @@ void P_RemoveMobj(mobj_t *mobj) P_SetTarget(&mobj->hprev->hnext, mobj->hnext); P_SetTarget(&mobj->hnext, P_SetTarget(&mobj->hprev, NULL)); - + // clear the reference from the mapthing if (mobj->spawnpoint) P_SetTarget(&mobj->spawnpoint->mobj, NULL); @@ -10083,34 +10083,45 @@ void P_RemoveMobj(mobj_t *mobj) R_RemoveMobjInterpolator(mobj); // free block - if (!mobj->thinker.next) + // DBG: set everything in mobj_t to 0xFF instead of leaving it. debug memory error. + if (mobj->flags & MF_NOTHINK && !mobj->thinker.next) { // Uh-oh, the mobj doesn't think, P_RemoveThinker would never go through! - INT32 prevreferences; if (!mobj->thinker.references) { - Z_Free(mobj); // No references? Can be removed immediately! :D - return; - } - - prevreferences = mobj->thinker.references; - P_AddThinker((thinker_t *)mobj); - mobj->thinker.references = prevreferences; - } - - P_RemoveThinker((thinker_t *)mobj); - - // DBG: set everything in mobj_t to 0xFF instead of leaving it. debug memory error. #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)); + // 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((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); + } + } + 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); + } } // This does not need to be added to Lua. // To test it in Lua, check mobj.valid boolean P_MobjWasRemoved(mobj_t *mobj) { - return !(mobj && mobj->thinker.function.acp1 == (actionf_p1)P_MobjThinker); + if (mobj && mobj->thinker.function.acp1 == (actionf_p1)P_MobjThinker) + return false; + return true; } void P_RemovePrecipMobj(precipmobj_t *mobj) diff --git a/src/p_tick.c b/src/p_tick.c index 6bf32f1c3..edb57236a 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -230,27 +230,23 @@ 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(thinker_t *thinker) +void P_RemoveThinkerDelayed(void *pthinker) { - thinker_t *next; -#ifdef PARANOIA - if (thinker->next) - thinker->next = NULL; - else if (thinker->references) // Usually gets cleared up in one frame; what's going on here, then? - CONS_Printf("Number of potentially faulty references: %d\n", thinker->references); -#endif - if (thinker->references) - return; - - /* 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; - R_DestroyLevelInterpolators(thinker); - Z_Free(thinker); + thinker_t *thinker = pthinker; + if (!thinker->references) + { + { + /* 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; + } + R_DestroyLevelInterpolators(thinker); + Z_Free(thinker); + } } // @@ -268,7 +264,7 @@ void P_RemoveThinkerDelayed(thinker_t *thinker) void P_RemoveThinker(thinker_t *thinker) { LUA_InvalidateUserdata(thinker); - thinker->function.acp1 = (actionf_p1)P_RemoveThinkerDelayed; + thinker->function.acp1 = P_RemoveThinkerDelayed; } /* @@ -287,7 +283,7 @@ mobj_t *P_SetTarget(mobj_t **mop, mobj_t *targ) { if (*mop) // If there was a target already, decrease its refcount (*mop)->thinker.references--; - if ((*mop = targ) != NULL) // Set new target and if non-NULL, increase its counter +if ((*mop = targ) != NULL) // Set new target and if non-NULL, increase its counter targ->thinker.references++; return targ; } @@ -318,9 +314,7 @@ static inline void P_RunThinkers(void) { for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { -#ifdef PARANOIA - I_Assert(currentthinker->function.acp1 != NULL) -#endif + if (currentthinker->function.acp1) currentthinker->function.acp1(currentthinker); } } From 5b9e1790170bb711a9d0b9c4fab03a642e87231f Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 3 Aug 2024 17:37:12 +0200 Subject: [PATCH 12/51] Revert "dont access delayremoved thinkers" This reverts commit df9ad5a31f7616433be9cf335dd51ce093670b5f. --- src/d_clisrv.c | 8 ++- src/d_netcmd.c | 3 +- src/g_game.c | 12 +--- src/lua_script.c | 5 -- src/m_cheat.c | 2 - src/p_enemy.c | 43 ++------------ src/p_inter.c | 4 -- src/p_mobj.c | 18 ------ src/p_polyobj.c | 85 ++++++++++++++++---------- src/p_saveg.c | 152 +++++++++++++++++++++++------------------------ src/p_setup.c | 13 ++-- src/p_spec.c | 16 ----- src/p_tick.c | 4 -- src/p_user.c | 14 ----- src/r_data.c | 3 +- 15 files changed, 148 insertions(+), 234 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index c03584043..10d46689a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5595,6 +5595,11 @@ static INT16 Consistancy(void) ret += P_GetRandSeed(); #ifdef MOBJCONSISTANCY + if (!thinkercap.next) + { + DEBFILE(va("Consistancy = %u\n", ret)); + return ret; + } if (gamestate == GS_LEVEL) { for (th = thinkercap.next; th != &thinkercap; th = th->next) @@ -5602,9 +5607,6 @@ static INT16 Consistancy(void) if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - 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 c451cca4f..a8e01a766 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5792,8 +5792,7 @@ static void Command_Archivetest_f(void) i = 1; for (th = thinkercap.next; th != &thinkercap; th = th->next) if (th->function.acp1 == (actionf_p1)P_MobjThinker) - if (th->function.acp1 != (actionf_p1)P_RemoveThinkerDelayed) - ((mobj_t *)th)->mobjnum = i++; + ((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 22b051024..bc881c5d5 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3051,9 +3051,6 @@ void G_ChangePlayerReferences(mobj_t *oldmo, mobj_t *newmo) if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - mo2 = (mobj_t *)th; if (!(mo2->flags & MF_MISSILE)) @@ -5658,13 +5655,11 @@ void G_ConsGhostTic(INT32 playernum) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - 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; } - if ((th != &thinkercap && th->function.acp1 != (actionf_p1)P_MobjThinker) && mobj->health != health) // Wasn't damaged?! This is desync! Fix it! + if (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")); @@ -8131,14 +8126,11 @@ void G_DoPlayMetal(void) if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - mo = (mobj_t *)th; if (mo->type == MT_METALSONIC_RACE) break; } - if (th == &thinkercap && th->function.acp1 == (actionf_p1)P_MobjThinker) + if (!mo) { CONS_Alert(CONS_ERROR, M_GetText("Failed to find bot entity.\n")); Z_Free(metalbuffer); diff --git a/src/lua_script.c b/src/lua_script.c index 6528a515e..5a2f6448c 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1601,9 +1601,6 @@ void LUA_Archive(void) if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - 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"); @@ -1640,8 +1637,6 @@ void LUA_UnArchive(void) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj continue; UnArchiveExtVars(th); // apply variables diff --git a/src/m_cheat.c b/src/m_cheat.c index 6b93461f3..abada4be5 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -906,8 +906,6 @@ static mapthing_t *OP_CreateNewMapThing(player_t *player, UINT16 type, boolean c { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - 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 diff --git a/src/p_enemy.c b/src/p_enemy.c index 1a23317ed..3a032fbf0 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -2635,8 +2635,6 @@ void A_BossDeath(mobj_t *mo) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2 != mo && (mo2->flags & MF_BOSS) && mo2->health > 0) @@ -2695,8 +2693,6 @@ bossjustdie: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -5304,8 +5300,6 @@ void A_RingExplode(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -6874,23 +6868,13 @@ void A_Boss3Path(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - 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; - - - P_SetTarget(&actor->target, mo2); - break; + if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && mo2->spawnpoint->angle == actor->threshold) + { + P_SetTarget(&actor->target, mo2); + break; + } } if (!actor->target) // Should NEVER happen @@ -7321,8 +7305,6 @@ void A_FindTarget(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -7387,8 +7369,6 @@ void A_FindTracer(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -7931,8 +7911,6 @@ void A_RemoteAction(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -8711,8 +8689,6 @@ void A_MementosTPParticles(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_MEMENTOSTP && mo2 != actor) @@ -8812,8 +8788,6 @@ void A_ReaperThinker(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -8870,6 +8844,7 @@ void A_ReaperThinker(mobj_t *actor) // 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. @@ -8879,8 +8854,6 @@ void A_ReaperThinker(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -9056,8 +9029,6 @@ void A_SetObjectTypeState(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -9680,8 +9651,6 @@ void A_CheckThingCount(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; diff --git a/src/p_inter.c b/src/p_inter.c index c23bfe286..054ff16a1 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1055,8 +1055,6 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_KOOPA) @@ -1951,8 +1949,6 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)th; if (mo->type == (mobjtype_t)target->info->mass && mo->tracer == target) diff --git a/src/p_mobj.c b/src/p_mobj.c index d7d2b37c6..78fcb8f63 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3223,8 +3223,6 @@ void P_DestroyRobots(void) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) continue; // not a mobj thinker - 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)) @@ -4033,8 +4031,6 @@ static void P_Boss3Thinker(mobj_t *mobj) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == (mobjtype_t)mobj->info->mass && mo2->tracer == mobj) @@ -4126,8 +4122,6 @@ static void P_Boss3Thinker(mobj_t *mobj) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -4759,8 +4753,6 @@ static void P_Boss7Thinker(mobj_t *mobj) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint) @@ -4816,8 +4808,6 @@ static void P_Boss7Thinker(mobj_t *mobj) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - 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) @@ -4941,8 +4931,6 @@ static void P_Boss9Thinker(mobj_t *mobj) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS9GATHERPOINT) @@ -5403,8 +5391,6 @@ mobj_t *P_GetClosestAxis(mobj_t *source) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -10413,8 +10399,6 @@ void P_RespawnSpecials(void) if (th->function.acp1 != (actionf_p1)P_MobjThinker) // not a mobj continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; box = (mobj_t *)th; @@ -11561,8 +11545,6 @@ ML_NOCLIMB : Direction not controllable { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 03df03905..bbf934231 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1514,31 +1514,29 @@ void Polyobj_InitLevel(void) // the mobj_t pointers on a queue for use below. for (th = thinkercap.next; th != &thinkercap; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - - mobj_t *mo = (mobj_t *)th; - - if (mo->info->doomednum == POLYOBJ_SPAWN_DOOMEDNUM || - mo->info->doomednum == POLYOBJ_SPAWNCRUSH_DOOMEDNUM) + if (th->function.acp1 == (actionf_p1)P_MobjThinker) { - ++numPolyObjects; + mobj_t *mo = (mobj_t *)th; - 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; + 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), &anchorqueue); + 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); + } } } @@ -1573,6 +1571,39 @@ void Polyobj_InitLevel(void) Polyobj_linkToBlockmap(&PolyObjects[i]); } +#if 0 + // haleyjd 02/22/06: temporary debug + printf("DEBUG: numPolyObjects = %d\n", numPolyObjects); + for (i = 0; i < numPolyObjects; ++i) + { + INT32 j; + polyobj_t *po = &PolyObjects[i]; + + printf("polyobj %d:\n", i); + printf("id = %d, first = %d, next = %d\n", po->id, po->first, po->next); + printf("segCount = %d, numSegsAlloc = %d\n", po->segCount, po->numSegsAlloc); + for (j = 0; j < po->segCount; ++j) + printf("\tseg %d: %p\n", j, po->segs[j]); + printf("numVertices = %d, numVerticesAlloc = %d\n", po->numVertices, po->numVerticesAlloc); + for (j = 0; j < po->numVertices; ++j) + { + printf("\tvtx %d: (%d, %d) / orig: (%d, %d)\n", + j, po->vertices[j]->x>>FRACBITS, po->vertices[j]->y>>FRACBITS, + po->origVerts[j].x>>FRACBITS, po->origVerts[j].y>>FRACBITS); + } + printf("numLines = %d, numLinesAlloc = %d\n", po->numLines, po->numLinesAlloc); + for (j = 0; j < po->numLines; ++j) + printf("\tline %d: %p\n", j, po->lines[j]); + printf("spawnSpot = (%d, %d)\n", po->spawnSpot.x >> FRACBITS, po->spawnSpot.y >> FRACBITS); + printf("centerPt = (%d, %d)\n", po->centerPt.x >> FRACBITS, po->centerPt.y >> FRACBITS); + printf("attached = %d, linked = %d, validcount = %d, isBad = %d\n", + po->attached, po->linked, po->validcount, po->isBad); + printf("blockbox: [%d, %d, %d, %d]\n", + po->blockbox[BOXLEFT], po->blockbox[BOXRIGHT], po->blockbox[BOXBOTTOM], + po->blockbox[BOXTOP]); + } +#endif + // done with mobj queues M_QueueFree(&spawnqueue); M_QueueFree(&anchorqueue); @@ -1789,8 +1820,6 @@ void T_PolyObjWaypoint(polywaypoint_t *th) { if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)wp; @@ -1875,8 +1904,6 @@ void T_PolyObjWaypoint(polywaypoint_t *th) { if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)wp; @@ -1916,8 +1943,6 @@ void T_PolyObjWaypoint(polywaypoint_t *th) { if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)wp; @@ -1955,8 +1980,6 @@ void T_PolyObjWaypoint(polywaypoint_t *th) { if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)wp; @@ -2477,8 +2500,6 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) { if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)wp; diff --git a/src/p_saveg.c b/src/p_saveg.c index ca41198ab..be393c51b 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1879,8 +1879,6 @@ mobj_t *P_FindNewPosition(UINT32 oldposition) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mobj = (mobj_t *)th; if (mobj->mobjnum != oldposition) @@ -3001,12 +2999,11 @@ static inline void P_FinishMobjs(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (currentthinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - mobj = (mobj_t *)currentthinker; - mobj->info = &mobjinfo[mobj->type]; + if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj = (mobj_t *)currentthinker; + mobj->info = &mobjinfo[mobj->type]; + } } } @@ -3020,71 +3017,69 @@ static void P_RelinkPointers(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (currentthinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; + if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj = (mobj_t *)currentthinker; - mobj = (mobj_t *)currentthinker; + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; - 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 (!P_SetTarget(&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 (!P_SetTarget(&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); + 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 (!P_SetTarget(&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 (!P_SetTarget(&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); + } } } } @@ -3460,14 +3455,13 @@ void P_SaveNetGame(void) { for (th = thinkercap.next; th != &thinkercap; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - 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++; + 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++; + } } } diff --git a/src/p_setup.c b/src/p_setup.c index 2f17d6d24..c150a2f2f 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -752,8 +752,6 @@ void P_ReloadRings(void) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)th; @@ -2197,6 +2195,7 @@ static void P_LevelInitStuff(void) void P_LoadThingsOnly(void) { // Search through all the thinkers. + mobj_t *mo; thinker_t *think; virtres_t* virt = vres_GetMap(lastloadedmaplumpnum); @@ -2205,10 +2204,12 @@ void P_LoadThingsOnly(void) for (think = thinkercap.next; think != &thinkercap; think = think->next) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - P_RemoveMobj((mobj_t *)think); + continue; // not a mobj thinker + + mo = (mobj_t *)think; + + if (mo) + P_RemoveMobj(mo); } P_LevelInitStuff(); diff --git a/src/p_spec.c b/src/p_spec.c index 4fa7a5275..2e8b09a12 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2989,8 +2989,6 @@ void P_SetupSignExit(player_t *player) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) continue; // not a mobj thinker - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; thing = (mobj_t *)think; if (thing->type != MT_SIGN) @@ -3040,8 +3038,6 @@ boolean P_IsFlagAtBase(mobjtype_t flag) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) continue; // not a mobj thinker - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)think; @@ -3476,8 +3472,6 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -3820,8 +3814,6 @@ DoneSection2: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -3901,8 +3893,6 @@ DoneSection2: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -4124,8 +4114,6 @@ DoneSection2: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -4164,8 +4152,6 @@ DoneSection2: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -4193,8 +4179,6 @@ DoneSection2: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; diff --git a/src/p_tick.c b/src/p_tick.c index edb57236a..2bf7f1024 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -155,8 +155,6 @@ void Command_CountMobjs_f(void) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; if (((mobj_t *)th)->type == i) count++; @@ -177,8 +175,6 @@ void Command_CountMobjs_f(void) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; if (((mobj_t *)th)->type == i) count++; diff --git a/src/p_user.c b/src/p_user.c index c14a4c541..4a74657fd 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1142,8 +1142,6 @@ void P_SpawnShieldOrb(player_t *player) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; shieldobj = (mobj_t *)th; @@ -1872,8 +1870,6 @@ void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -2626,8 +2622,6 @@ static void P_DoZoomTube(player_t *player) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -2723,8 +2717,6 @@ void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) continue; // not a mobj thinker - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)think; @@ -2805,8 +2797,6 @@ boolean P_LookForEnemies(player_t *player) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) continue; // not a mobj thinker - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)think; if (!(mo->flags & (MF_ENEMY|MF_BOSS|MF_MONITOR|MF_SPRING))) @@ -2932,8 +2922,6 @@ void P_FindEmerald(void) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_EMERHUNT) @@ -4656,8 +4644,6 @@ void P_PlayerThink(player_t *player) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; diff --git a/src/r_data.c b/src/r_data.c index a725d2ac9..ad8b420f3 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1687,8 +1687,7 @@ void R_PrecacheLevel(void) for (th = thinkercap.next; th != &thinkercap; th = th->next) if (th->function.acp1 == (actionf_p1)P_MobjThinker) - if (th->function.acp1 != (actionf_p1)P_RemoveThinkerDelayed) - spritepresent[((mobj_t *)th)->sprite] = 1; + spritepresent[((mobj_t *)th)->sprite] = 1; spritememory = 0; for (i = 0; i < numsprites; i++) From b3f16e935d59e13457092b09c2bda4bd4d674c3a Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 3 Aug 2024 17:37:46 +0200 Subject: [PATCH 13/51] Revert "more mobj reference fixes + cleanup" This reverts commit bd8ff77fe00700aada3495b4b5c8ac583f1051ef. --- src/g_game.c | 1 + src/lua_script.c | 24 +++---- src/m_cheat.c | 5 +- src/p_enemy.c | 8 +-- src/p_floor.c | 24 +++++++ src/p_mobj.c | 71 ++++++++++---------- src/p_polyobj.c | 165 +++++++++++++++++++++++++++-------------------- src/p_saveg.c | 20 +++--- src/p_spec.c | 53 +++++++-------- src/p_user.c | 20 +++--- 10 files changed, 213 insertions(+), 178 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index bc881c5d5..c1629af5a 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5658,6 +5658,7 @@ void G_ConsGhostTic(INT32 playernum) 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! { diff --git a/src/lua_script.c b/src/lua_script.c index 5a2f6448c..85aefbfbd 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1597,14 +1597,12 @@ void LUA_Archive(void) if (gamestate == GS_LEVEL) { for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - // archive function will determine when to skip mobjs, - // and write mobjnum in otherwise. - ArchiveExtVars(th, "mobj"); - } + 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. @@ -1634,13 +1632,9 @@ 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) - continue; - if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj - continue; - UnArchiveExtVars(th); // apply variables - } + 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. LUAh_NetArchiveHook(NetUnArchive); // call the NetArchive hook in unarchive mode diff --git a/src/m_cheat.c b/src/m_cheat.c index abada4be5..91ca536c8 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -909,9 +909,8 @@ static mapthing_t *OP_CreateNewMapThing(player_t *player, UINT16 type, boolean c mo = (mobj_t *)th; // get offset from mt, which points to old mapthings, then add new location - if (!mo->spawnpoint) - continue; - mo->spawnpoint = (mo->spawnpoint - mt) + mapthings; + if (mo->spawnpoint) + mo->spawnpoint = (mo->spawnpoint - mt) + mapthings; } } diff --git a/src/p_enemy.c b/src/p_enemy.c index 3a032fbf0..caa85e331 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -2418,11 +2418,9 @@ 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) - { - mobj_t *tracer = actor->tracer; - P_SetTarget(&actor->tracer, NULL); - P_RemoveMobj(tracer); + if (actor->tracer) { + P_RemoveMobj(actor->tracer); + P_SetTarget(&actor->target, NULL); } return; } diff --git a/src/p_floor.c b/src/p_floor.c index bebc9a272..27460eda6 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -1968,8 +1968,32 @@ void T_ThwompSector(levelspecthink_t *thwomp) } else // Not going anywhere, so look for players. { + //thinker_t *th; + //mobj_t *mo; + thwomp->direction = -1; + /* // SRB2kart 170217 - Thwomps are automatic. + // scan the thinkers to find players! + if (!rover || (rover->flags & FF_EXISTS)) + { + // scan the thinkers to find players! + for (th = thinkercap.next; th != &thinkercap; 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 + && P_AproxDistance(thwompx - mo->x, thwompy - mo->y) <= 96*FRACUNIT) + { + thwomp->direction = -1; + break; + } + } + }*/ + thwomp->sector->ceilspeed = 0; thwomp->sector->floorspeed = 0; } diff --git a/src/p_mobj.c b/src/p_mobj.c index 78fcb8f63..37af3777c 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -4124,21 +4124,11 @@ static void P_Boss3Thinker(mobj_t *mobj) continue; mo2 = (mobj_t *)th; - - if (!mo2) - continue; - - if (mo2->type != MT_BOSS3WAYPOINT) - continue; - - if (!mo2->spawnpoint) - continue; - - if (mo2->spawnpoint->angle != mobj->threshold) - continue; - - P_SetTarget(&mobj->target, mo2); - break; + if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && mo2->spawnpoint->angle == mobj->threshold) + { + P_SetTarget(&mobj->target, mo2); + break; + } } if (!mobj->target) // Should NEVER happen @@ -10052,19 +10042,28 @@ void P_RemoveMobj(mobj_t *mobj) // killough 11/98: // // Remove any references to other mobjs. - P_SetTarget(&mobj->target, NULL); - P_SetTarget(&mobj->tracer, NULL); + P_SetTarget(&mobj->target, P_SetTarget(&mobj->tracer, NULL)); - if (mobj->hnext && !P_MobjWasRemoved(mobj->hnext)) - P_SetTarget(&mobj->hnext->hprev, mobj->hprev); - if (mobj->hprev && !P_MobjWasRemoved(mobj->hprev)) - P_SetTarget(&mobj->hprev->hnext, mobj->hnext); + // repair hnext chain + { + mobj_t *cachenext = mobj->hnext; - P_SetTarget(&mobj->hnext, P_SetTarget(&mobj->hprev, NULL)); + if (mobj->hnext && !P_MobjWasRemoved(mobj->hnext)) + { + P_SetTarget(&mobj->hnext->hprev, mobj->hprev); + P_SetTarget(&mobj->hnext, NULL); + } + + if (mobj->hprev && !P_MobjWasRemoved(mobj->hprev)) + { + P_SetTarget(&mobj->hprev->hnext, cachenext); + P_SetTarget(&mobj->hprev, NULL); + } + } // clear the reference from the mapthing if (mobj->spawnpoint) - P_SetTarget(&mobj->spawnpoint->mobj, NULL); + mobj->spawnpoint->mobj = NULL; R_RemoveMobjInterpolator(mobj); @@ -11815,12 +11814,11 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) { P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); + //mobj->hprev = nextmobj; + //mobj->hprev->hnext = mobj; } else - { - P_SetTarget(&mobj->hprev, NULL); - P_SetTarget(&mobj->hnext, NULL); - } + mobj->hprev = mobj->hnext = NULL; nextmobj = mobj; } @@ -11846,9 +11844,11 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - P_SetTarget(&mobj->hnext, NULL); + mobj->hnext = NULL; P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); + //mobj->hprev = nextmobj; + //mobj->hprev->hnext = mobj; nextmobj = mobj; } @@ -11873,9 +11873,11 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - P_SetTarget(&mobj->hnext, NULL); + mobj->hnext = NULL; P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); + //mobj->hprev = nextmobj; + //mobj->hprev->hnext = mobj; nextmobj = mobj; } @@ -11958,12 +11960,11 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) { P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); + //mobj->hprev = nextmobj; + //mobj->hprev->hnext = mobj; } else - { - P_SetTarget(&mobj->hprev, NULL); - P_SetTarget(&mobj->hnext, NULL); - } + mobj->hprev = mobj->hnext = NULL; nextmobj = mobj; } @@ -12000,9 +12001,11 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - P_SetTarget(&mobj->hnext, NULL); + 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 bbf934231..9a3376595 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1826,14 +1826,11 @@ void T_PolyObjWaypoint(polywaypoint_t *th) if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold != th->sequence) - continue; - - if (mo2->health != th->pointnum) - continue; - - target = mo2; - break; + if (mo2->threshold == th->sequence && mo2->health == th->pointnum) + { + target = mo2; + break; + } } if (!target) @@ -1910,23 +1907,23 @@ void T_PolyObjWaypoint(polywaypoint_t *th) if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold != th->sequence) - continue; - - if (th->direction == -1) + if (mo2->threshold == th->sequence) { - if (mo2->health == target->health - 1) + if (th->direction == -1) { - waypoint = mo2; - break; + if (mo2->health == target->health - 1) + { + waypoint = mo2; + break; + } } - } - else - { - if (mo2->health == target->health + 1) + else { - waypoint = mo2; - break; + if (mo2->health == target->health + 1) + { + waypoint = mo2; + break; + } } } } @@ -1949,22 +1946,22 @@ void T_PolyObjWaypoint(polywaypoint_t *th) if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold != th->sequence) - continue; - - if (th->direction == -1) + if (mo2->threshold == th->sequence) { - if (waypoint == NULL) - waypoint = mo2; - else if (mo2->health > waypoint->health) - waypoint = mo2; - } - else - { - if (mo2->health == 0) + if (th->direction == -1) { - waypoint = mo2; - break; + if (waypoint == NULL) + waypoint = mo2; + else if (mo2->health > waypoint->health) + waypoint = mo2; + } + else + { + if (mo2->health == 0) + { + waypoint = mo2; + break; + } } } } @@ -1986,23 +1983,23 @@ void T_PolyObjWaypoint(polywaypoint_t *th) if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold != th->sequence) - continue; - - if (th->direction == -1) + if (mo2->threshold == th->sequence) { - if (mo2->health == target->health - 1) + if (th->direction == -1) { - waypoint = mo2; - break; + if (mo2->health == target->health - 1) + { + waypoint = mo2; + break; + } } - } - else - { - if (mo2->health == target->health + 1) + else { - waypoint = mo2; - break; + if (mo2->health == target->health + 1) + { + waypoint = mo2; + break; + } } } } @@ -2506,31 +2503,31 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold != th->sequence) - continue; - - if (th->direction == -1) // highest waypoint # + if (mo2->threshold == th->sequence) { - if (mo2->health == 0) - last = mo2; - else + if (th->direction == -1) // highest waypoint # { - if (first == NULL) - first = mo2; - else if (mo2->health > first->health) - first = mo2; + 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) - first = mo2; - else + else // waypoint 0 { - if (last == NULL) - last = mo2; - else if (mo2->health > last->health) - last = mo2; + if (mo2->health == 0) + first = mo2; + else + { + if (last == NULL) + last = mo2; + else if (mo2->health > last->health) + last = mo2; + } } } } @@ -2567,6 +2564,36 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) // Find the actual target movement waypoint target = first; + /*for (wp = thinkercap.next; wp != &thinkercap; 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) + continue; + + if (mo2->threshold == th->sequence) + { + if (th->direction == -1) // highest waypoint # + { + if (mo2->health == first->health - 1) + { + target = mo2; + break; + } + } + else // waypoint 0 + { + if (mo2->health == first->health + 1) + { + target = mo2; + break; + } + } + } + }*/ if (!target) { diff --git a/src/p_saveg.c b/src/p_saveg.c index be393c51b..e260321be 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1881,10 +1881,8 @@ mobj_t *P_FindNewPosition(UINT32 oldposition) continue; mobj = (mobj_t *)th; - if (mobj->mobjnum != oldposition) - continue; - - return mobj; + if (mobj->mobjnum == oldposition) + return mobj; } CONS_Debug(DBG_GAMELOGIC, "mobj not found\n"); return NULL; @@ -2883,14 +2881,12 @@ static void P_NetUnArchiveThinkers(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - 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); + if (currentthinker->function.acp1 == (actionf_p1)T_ExecutorDelay) + { + delay = (void *)currentthinker; + if ((mobjnum = (UINT32)(size_t)delay->caller)) + delay->caller = P_FindNewPosition(mobjnum); + } } } } diff --git a/src/p_spec.c b/src/p_spec.c index 2e8b09a12..370afc056 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3032,7 +3032,7 @@ boolean P_IsFlagAtBase(mobjtype_t flag) { thinker_t *think; mobj_t *mo; - INT32 specialnum = (flag == MT_REDFLAG) ? 3 : 4; + INT32 specialnum = 0; for (think = thinkercap.next; think != &thinkercap; think = think->next) { @@ -3044,6 +3044,11 @@ boolean P_IsFlagAtBase(mobjtype_t flag) 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 @@ -3058,11 +3063,9 @@ 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))) - continue; - - 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)) + return true; } } } @@ -3474,11 +3477,8 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers continue; mo2 = (mobj_t *)th; - - if (mo2->type != MT_EGGTRAP) - continue; - - P_KillMobj(mo2, NULL, player->mo); + if (mo2->type == MT_EGGTRAP) + P_KillMobj(mo2, NULL, player->mo); } // clear the special so you can't push the button twice. @@ -3817,15 +3817,12 @@ DoneSection2: mo2 = (mobj_t *)th; - if (mo2->type != MT_TUBEWAYPOINT) - continue; - if (mo2->threshold != sequence) - continue; - if (mo2->health != 0) - continue; - - waypoint = mo2; - break; + if (mo2->type == MT_TUBEWAYPOINT && mo2->threshold == sequence + && mo2->health == 0) + { + waypoint = mo2; + break; + } } if (!waypoint) @@ -3896,15 +3893,13 @@ DoneSection2: mo2 = (mobj_t *)th; - if (mo2->type != MT_TUBEWAYPOINT) - continue; - if (mo2->threshold != sequence) - continue; - - if (!waypoint) - waypoint = mo2; - else if (mo2->health > waypoint->health) - waypoint = mo2; + if (mo2->type == MT_TUBEWAYPOINT && mo2->threshold == sequence) + { + if (!waypoint) + waypoint = mo2; + else if (mo2->health > waypoint->health) + waypoint = mo2; + } } if (!waypoint) diff --git a/src/p_user.c b/src/p_user.c index 4a74657fd..60661e4c2 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2628,17 +2628,15 @@ static void P_DoZoomTube(player_t *player) if (mo2->type != MT_TUBEWAYPOINT) continue; - 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 (mo2->threshold == sequence) + { + if ((reverse && mo2->health == player->mo->tracer->health - 1) + || (!reverse && mo2->health == player->mo->tracer->health + 1)) + { + waypoint = mo2; + break; + } + } } if (waypoint) From d675b98330e92035bc14b9589d71f0dc7b009b76 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 3 Aug 2024 17:38:15 +0200 Subject: [PATCH 14/51] Revert "Fix mobj reference management of player->mo" This reverts commit c5ec61baa5653029d5c01eeac3faca9ca1ff4538. --- src/g_game.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/p_mobj.c | 4 +-- src/p_user.c | 2 +- 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index c1629af5a..ff459c59a 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3072,6 +3072,12 @@ void G_DoReborn(INT32 playernum) player_t *player = &players[playernum]; boolean starpost = false; + /*if (modeattacking) // Not needed for SRB2Kart. + { + M_EndModeAttackRun(); + return; + }*/ + // Make sure objectplace is OFF when you first start the level! OP_ResetObjectplace(); @@ -3085,13 +3091,74 @@ void G_DoReborn(INT32 playernum) oldmo = player->mo; // Don't leave your carcass stuck 10-billion feet in the ground! P_RemoveMobj(player->mo); - P_SetTarget(&player->mo, NULL); } B_RespawnBot(playernum); if (oldmo) G_ChangePlayerReferences(oldmo, players[playernum].mo); } + /*else if (countdowntimeup || (!multiplayer && !modeattacking)) + { + // reload the level from scratch + if (countdowntimeup) + { + player->starpostangle = 0; + player->starposttime = 0; + player->starpostx = 0; + player->starposty = 0; + player->starpostz = 0; + player->starpostnum = 0; + } + if (!countdowntimeup && (mapheaderinfo[gamemap-1]->levelflags & LF_NORELOAD)) + { + INT32 i; + + player->playerstate = PST_REBORN; + + P_LoadThingsOnly(); + + // Do a wipe + wipegamestate = -1; + + if (player->starpostnum) // SRB2kart + starpost = true; + + for (i = 0; i <= splitscreen; i++) + { + if (camera[i].chase) + P_ResetCamera(&players[displayplayers[i]], &camera[i]); + } + + // clear cmd building stuff + memset(gamekeydown, 0, sizeof (gamekeydown)); + for (i = 0;i < JOYAXISSET; i++) + { + joyxmove[i] = joyymove[i] = 0; + joy2xmove[i] = joy2ymove[i] = 0; + joy3xmove[i] = joy3ymove[i] = 0; + joy4xmove[i] = joy4ymove[i] = 0; + } + mousex = mousey = 0; + mouse2x = mouse2y = 0; + + // clear hud messages remains (usually from game startup) + CON_ClearHUD(); + + // Starpost support + G_SpawnPlayer(playernum, starpost); + + if (botingame) + { // Bots respawn next to their master. + players[displayplayers[1]].playerstate = PST_REBORN; + G_SpawnPlayer(displayplayers[1], false); + } + } + else + { + LUAh_MapChange(gamemap); + G_DoLoadLevel(true); + } + }*/ else { // respawn at the start @@ -3108,7 +3175,6 @@ void G_DoReborn(INT32 playernum) oldmo = player->mo; // Don't leave your carcass stuck 10-billion feet in the ground! P_RemoveMobj(player->mo); - P_SetTarget(&player->mo, NULL); } G_SpawnPlayer(playernum, starpost); diff --git a/src/p_mobj.c b/src/p_mobj.c index 37af3777c..a0d80b413 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10597,9 +10597,7 @@ void P_SpawnPlayer(INT32 playernum) mobj = P_SpawnMobj(0, 0, 0, MT_PLAYER); I_Assert(mobj != NULL); - - mobj->player = p; - P_SetTarget(&p->mo, mobj); + (mobj->player = p)->mo = mobj; mobj->angle = 0; diff --git a/src/p_user.c b/src/p_user.c index 60661e4c2..118c1d06d 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -4025,7 +4025,7 @@ boolean P_SpectatorJoinGame(player_t *player) if (player->mo) { P_RemoveMobj(player->mo); - P_SetTarget(&player->mo, NULL); + player->mo = NULL; } player->spectator = false; player->pflags &= ~PF_WANTSTOJOIN; From 023cade51d742199e936c23bc45b13a10748d697 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 15:04:01 +0200 Subject: [PATCH 15/51] smol fix to frameskipping --- src/d_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/d_main.c b/src/d_main.c index 161ed604e..1c7fc63e1 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -839,6 +839,8 @@ void D_SRB2Loop(void) // Fully completed frame made. finishprecise = I_GetPreciseTime(); + // Use the time before sleep for frameskip calculations: + // post-sleep time is literally being intentionally wasted deltasecs = (double)((INT64)(finishprecise - enterprecise)) / I_GetPrecisePrecision(); deltatics = deltasecs * NEWTICRATE; @@ -873,6 +875,8 @@ void D_SRB2Loop(void) } // Capture the time once more to get the real delta time. finishprecise = I_GetPreciseTime(); + deltasecs = (double)((INT64)(finishprecise - enterprecise)) / I_GetPrecisePrecision(); + deltatics = deltasecs * NEWTICRATE; } } From e11363db3a2d235d6771b24a3b0903125172a87a Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 15:04:14 +0200 Subject: [PATCH 16/51] Fix sound falloff calculation overflow --- src/s_sound.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index e6f2af24a..fe44d51a1 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1046,7 +1046,8 @@ boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 if (sfxinfo->pitch & SF_OUTSIDESOUND) // Rain special case { - fixed_t x, y, yl, yh, xl, xh, newdist; + INT64 x, y, yl, yh, xl, xh; + fixed_t newdist; if (R_PointInSubsector(listensource.x, listensource.y)->sector->ceilingpic == skyflatnum) approx_dist = 0; From 9fceabed8f2a27f6a3162416845fd01756aeb7e0 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 15:04:25 +0200 Subject: [PATCH 17/51] Ensure Z_Malloc provides same alignment as libc --- src/z_zone.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/z_zone.c b/src/z_zone.c index b0223460b..dd10f36e3 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -25,6 +25,9 @@ /// allocator was fragmenting badly. Finally, this version is a bit /// simpler (about half the lines of code). +#include +#include + #include "doomdef.h" #include "doomstat.h" #include "r_patch.h" @@ -67,8 +70,9 @@ typedef struct memblock_s struct memblock_s *next, *prev; } memblock_t; -#define MEMORY(x) (void *)((uintptr_t)(x) + sizeof(memblock_t)) -#define MEMBLOCK(x) (memblock_t *)((uintptr_t)(x) - sizeof(memblock_t)) +#define ALIGNPAD (((sizeof (memblock_t) + (alignof (max_align_t) - 1)) & ~(alignof (max_align_t) - 1)) - sizeof (memblock_t)) +#define MEMORY(x) (void *)((uintptr_t)(x) + sizeof(memblock_t) + ALIGNPAD) +#define MEMBLOCK(x) (memblock_t *)((uintptr_t)(x) - ALIGNPAD - sizeof(memblock_t)) // both the head and tail of the zone memory block list static memblock_t head; @@ -219,15 +223,16 @@ void *Z_MallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) { memblock_t *block; void *ptr; - (void)(alignbits); // no longer used, so silence warnings. + + (void)(alignbits); // no longer used, so silence warnings. TODO we should figure out a solution for this #ifdef ZDEBUG2 CONS_Debug(DBG_MEMORY, "Z_Malloc %s:%d\n", file, line); #endif - block = xm(sizeof (memblock_t) + size); + block = xm(sizeof (memblock_t) + ALIGNPAD + size); ptr = MEMORY(block); - I_Assert((intptr_t)ptr % sizeof (void *) == 0); + I_Assert((intptr_t)ptr % alignof (max_align_t) == 0); #ifdef HAVE_VALGRIND Z_calloc = false; From 99779629d0789f1775605cefdcca3721e2196ef9 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 15:04:47 +0200 Subject: [PATCH 18/51] dont always reset texture depth in ogl --- src/screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screen.c b/src/screen.c index e5c1ebff4..8fe00e821 100644 --- a/src/screen.c +++ b/src/screen.c @@ -331,7 +331,7 @@ void SCR_SetDefaultMode(void) // remember the default screen size CV_SetValue(&cv_scr_width, vid.width); CV_SetValue(&cv_scr_height, vid.height); - CV_SetValue(&cv_scr_depth, vid.bpp*8); + //CV_SetValue(&cv_scr_depth, vid.bpp*8); } // Change fullscreen on/off according to cv_fullscreen From 685220140a2b1cd6e60ac9b62236712e0d156c7c Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 15:05:19 +0200 Subject: [PATCH 19/51] fix potential crash on nix while quitting --- src/sdl/i_system.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index b20eeba7d..7a7cd7e7e 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -3402,13 +3402,13 @@ INT32 I_StartupSystem(void) SDL_version SDLlinked; SDL_VERSION(&SDLcompiled) SDL_GetVersion(&SDLlinked); -#ifdef HAVE_THREADS - I_start_threads(); - I_AddExitFunc(I_stop_threads); -#endif I_StartupConsole(); #ifdef NEWSIGNALHANDLER I_Fork(); +#endif +#ifdef HAVE_THREADS + I_start_threads(); + I_AddExitFunc(I_stop_threads); #endif I_RegisterSignals(); I_OutputMsg("Compiled for SDL version: %d.%d.%d\n", From 2448a0b735787265ed29bc1d0ce32760e89a1176 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 15:35:47 +0200 Subject: [PATCH 20/51] Cache pk3 central directory and Refactor ResFindSignature to work in chunks https://github.com/KartKrewDev/RingRacers/commit/8ca2dc77e75b1ba8c511380257f0bbaf6d21c27b https://github.com/KartKrewDev/RingRacers/commit/dedd0047bd8f9f73aba4defc19c429af7c987983 --- src/w_wad.c | 164 ++++++++++++++++++++++++++++------------------------ 1 file changed, 90 insertions(+), 74 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 762cdc417..8df0654f0 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -464,27 +464,53 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen */ static boolean ResFindSignature (FILE* handle, char endPat[], UINT32 startpos) { + //the Wii U has rather slow filesystem access, and fgetc is *unbearable* + //so I reimplemented this function to buffer 128k chunks char *s; int c; + fseek(handle, 0, SEEK_END); + size_t len = ftell(handle); + fseek(handle, startpos, SEEK_SET); + size_t remaining = len - startpos; + size_t chunkpos = startpos; + s = endPat; - while((c = fgetc(handle)) != EOF) - { - if (*s != c && s > endPat) // No match? - s = endPat; // We "reset" the counter by sending the s pointer back to the start of the array. - if (*s == c) - { - s++; - if (*s == 0x00) // The array pointer has reached the key char which marks the end. It means we have matched the signature. + + //128k buffers + size_t buffer_size = min(128 * 1024 * sizeof(char), remaining); + char* buffer = (char*)(malloc(buffer_size)); + + size_t bytes_read = 0; + while ((bytes_read = fread(buffer, 1, buffer_size, handle)) > 0) { + for (size_t i = 0; i < bytes_read; i++) { + c = (int)buffer[i]; + + if (*s != c && s > endPat) // No match? + s = endPat; // We "reset" the counter by sending the s pointer back to the start of the array. + if (*s == c) { - return true; + s++; + if (*s == 0x00) // The array pointer has reached the key char which marks the end. It means we have matched the signature. + { + //the original function would leave the FILE* seeked to the end of the match + size_t foundpos = chunkpos + i + 1; + fseek(handle, foundpos, SEEK_SET); + + free(buffer); + return true; + } } } + chunkpos += bytes_read; } + + free(buffer); return false; } + #if defined(_MSC_VER) #pragma pack(1) #endif @@ -544,7 +570,6 @@ typedef struct zlentry_s static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) { zend_t zend; - zentry_t zentry; zlentry_t zlentry; UINT16 numlumps = *nlmp; @@ -570,42 +595,45 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) CONS_Alert(CONS_ERROR, "Corrupt central directory (%s)\n", M_FileError(handle)); return NULL; } - numlumps = zend.entries; + numlumps = SHORT(zend.entries); lump_p = lumpinfo = Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL); - fseek(handle, zend.cdiroffset, SEEK_SET); + fseek(handle, LONG(zend.cdiroffset), SEEK_SET); + + char *cdir = (Z_MallocAlign(LONG(zend.cdirsize), PU_STATIC, &cdir, 7)); + + if (fread(cdir, 1, LONG(zend.cdirsize), handle) < (UINT32)(LONG(zend.cdirsize))) + { + CONS_Alert(CONS_ERROR, "Failed to read central directory (%s)\n", M_FileError(handle)); + Z_Free(cdir); + Z_Free(lumpinfo); + return NULL; + } + + size_t offset = 0; + for (i = 0; i < numlumps; i++, lump_p++) { + zentry_t *zentry = (zentry_t*)(cdir + offset); char* fullname; char* trimname; char* dotpos; - if (fread(&zentry, 1, sizeof(zentry_t), handle) < sizeof(zentry_t)) - { - CONS_Alert(CONS_ERROR, "Failed to read central directory (%s)\n", M_FileError(handle)); - Z_Free(lumpinfo); - return NULL; - } - if (memcmp(zentry.signature, pat_central, 4)) + if (memcmp(zentry->signature, pat_central, 4)) { CONS_Alert(CONS_ERROR, "Central directory is corrupt\n"); + Z_Free(cdir); Z_Free(lumpinfo); return NULL; } - lump_p->position = zentry.offset; // NOT ACCURATE YET: we still need to read the local entry to find our true position - lump_p->disksize = zentry.compsize; - lump_p->size = zentry.size; + lump_p->position = LONG(zentry->offset); // NOT ACCURATE YET: we still need to read the local entry to find our true position + lump_p->disksize = LONG(zentry->compsize); + lump_p->size = LONG(zentry->size); - fullname = malloc(zentry.namelen + 1); - if (fgets(fullname, zentry.namelen + 1, handle) != fullname) - { - CONS_Alert(CONS_ERROR, "Unable to read lumpname (%s)\n", M_FileError(handle)); - Z_Free(lumpinfo); - free(fullname); - return NULL; - } + fullname = (char*)(malloc(SHORT(zentry->namelen) + 1)); + strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. if ((trimname = strrchr(fullname, '/')) != 0) @@ -622,10 +650,10 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) lump_p->longname = Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL); strlcpy(lump_p->longname, trimname, dotpos - trimname + 1); - lump_p->fullname = Z_Calloc(zentry.namelen + 1, PU_STATIC, NULL); - strncpy(lump_p->fullname, fullname, zentry.namelen); + lump_p->fullname = (char*)(Z_Calloc(SHORT(zentry->namelen) + 1, PU_STATIC, NULL)); + strncpy(lump_p->fullname, fullname, SHORT(zentry->namelen)); - switch(zentry.compression) + switch(SHORT(zentry->compression)) { case 0: lump_p->compression = CM_NOCOMPRESSION; @@ -646,14 +674,11 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) free(fullname); // skip and ignore comments/extra fields - if (fseek(handle, zentry.xtralen + zentry.commlen, SEEK_CUR) != 0) - { - CONS_Alert(CONS_ERROR, "Central directory is corrupt\n"); - Z_Free(lumpinfo); - return NULL; - } + offset += sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen); } + Z_Free(cdir); + // Adjust lump position values properly for (i = 0, lump_p = lumpinfo; i < numlumps; i++, lump_p++) { @@ -665,7 +690,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) return NULL; } - lump_p->position += sizeof(zlentry_t) + zlentry.namelen + zlentry.xtralen; + lump_p->position += sizeof(zlentry_t) + SHORT(zlentry.namelen) + SHORT(zlentry.xtralen); } *nlmp = numlumps; @@ -1895,14 +1920,11 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) int verified = true; zend_t zend; - zentry_t zentry; zlentry_t zlentry; long file_size;/* size of zip file */ long data_size;/* size of data inside zip file */ - long old_position; - UINT16 numlumps; size_t i; @@ -1928,28 +1950,31 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) data_size = sizeof zend; - numlumps = zend.entries; + numlumps = SHORT(zend.entries); + + fseek(fp, LONG(zend.cdiroffset), SEEK_SET); + + char *cdir = (char*)(malloc(LONG(zend.cdirsize))); + + if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize))) + return true; + + size_t offset = 0; - fseek(fp, zend.cdiroffset, SEEK_SET); for (i = 0; i < numlumps; i++) { + zentry_t *zentry = (zentry_t*)(cdir + offset); char* fullname; char* trimname; char* dotpos; - if (fread(&zentry, 1, sizeof(zentry_t), fp) < sizeof(zentry_t)) - return true; - if (memcmp(zentry.signature, pat_central, 4)) + if (memcmp(zentry->signature, pat_central, 4) != 0) return true; if (verified == true) { - fullname = malloc(zentry.namelen + 1); - if (fgets(fullname, zentry.namelen + 1, fp) != fullname) - { - free(fullname); - return true; - } + fullname = (char*)(malloc(SHORT(zentry->namelen) + 1)); + strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. if ((trimname = strrchr(fullname, '/')) != 0) @@ -1974,34 +1999,25 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) } free(fullname); + } - // skip and ignore comments/extra fields - if (fseek(fp, zentry.xtralen + zentry.commlen, SEEK_CUR) != 0) - return true; - } - else - { - if (fseek(fp, zentry.namelen + zentry.xtralen + zentry.commlen, SEEK_CUR) != 0) - return true; - } + offset += sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen); data_size += - sizeof zentry + zentry.namelen + zentry.xtralen + zentry.commlen; + sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen); - old_position = ftell(fp); - - if (fseek(fp, zentry.offset, SEEK_SET) != 0) + if (fseek(fp, LONG(zentry->offset), SEEK_SET) != 0) return true; if (fread(&zlentry, 1, sizeof(zlentry_t), fp) < sizeof (zlentry_t)) return true; data_size += - sizeof zlentry + zlentry.namelen + zlentry.xtralen + zlentry.compsize; - - fseek(fp, old_position, SEEK_SET); + sizeof zlentry + SHORT(zlentry.namelen) + SHORT(zlentry.xtralen) + LONG(zlentry.compsize); } + free(cdir); + if (data_size < file_size) { const char * error = "ZIP file has holes (%ld extra bytes)\n"; @@ -2127,14 +2143,14 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) // Remember that we're assuming that the WAD will have a specific set of lumps in a specific order. UINT8 *wadData = W_CacheLumpNum(lumpnum, PU_LEVEL); - filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs); + filelump_t *fileinfo = (filelump_t *)(wadData + LONG(((wadinfo_t *)wadData)->infotableofs)); - i = ((wadinfo_t *)wadData)->numlumps; + i = LONG(((wadinfo_t *)wadData)->numlumps); vsizecache = Z_Malloc(sizeof(size_t)*i, PU_LEVEL, NULL); for (realentry = 0; realentry < i; realentry++) { - vsizecache[realentry] = (size_t)(((filelump_t *)(fileinfo + realentry))->size); + vsizecache[realentry] = (size_t)(LONG(((filelump_t *)(fileinfo + realentry))->size)); if (!vsizecache[realentry]) continue; @@ -2154,7 +2170,7 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) memcpy(vlumps[i].name, (fileinfo + realentry)->name, 8); vlumps[i].name[8] = '\0'; vlumps[i].data = Z_Malloc(vlumps[i].size, PU_LEVEL, NULL); // This is memory inefficient, sorry about that. - memcpy(vlumps[i].data, wadData + (fileinfo + realentry)->filepos, vlumps[i].size); + memcpy(vlumps[i].data, wadData + LONG((fileinfo + realentry)->filepos), vlumps[i].size); i++; } From a6fc237c883bd6604d4ff60f0c23a15b20b8c813 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 15:37:23 +0200 Subject: [PATCH 21/51] try to prevent potential infinite SIGARBT hang in signal handler --- src/console.c | 8 ++++++-- src/i_system.h | 3 +++ src/sdl/i_system.c | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/console.c b/src/console.c index 90212469e..8bd8518f9 100644 --- a/src/console.c +++ b/src/console.c @@ -43,8 +43,12 @@ #ifdef HAVE_THREADS I_mutex con_mutex; -# define Lock_state() I_lock_mutex(&con_mutex) -# define Unlock_state() I_unlock_mutex(con_mutex) +// g_in_exiting_signal_handler is an evil hack +// to avoid infinite SIGABRT recursion in the signal handler +// due to poisoned locks or mach-o kernel not supporting locks in signals +// or something like that. idk +# define Lock_state() if (!g_in_exiting_signal_handler) { I_lock_mutex(&con_mutex); } +# define Unlock_state() if (!g_in_exiting_signal_handler) { I_unlock_mutex(con_mutex); } #else/*HAVE_THREADS*/ # define Lock_state() # define Unlock_state() diff --git a/src/i_system.h b/src/i_system.h index a78eb5c5e..f1d098e4a 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -34,6 +34,9 @@ extern UINT8 graphics_started; */ extern UINT8 keyboard_started; +/** \brief Set to true when inside a signal handler that will exit the program. */ +extern boolean g_in_exiting_signal_handler; + /** \brief The I_GetFreeMem function \param total total memory in the system diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 7a7cd7e7e..00bc3200f 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -446,6 +446,7 @@ SDL_bool consolevent = SDL_FALSE; SDL_bool framebuffer = SDL_FALSE; UINT8 keyboard_started = false; +boolean g_in_exiting_signal_handler = false; static void I_ReportSignal(int num, int coredumped) { @@ -512,6 +513,8 @@ static void I_ReportSignal(int num, int coredumped) #ifndef NEWSIGNALHANDLER FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) { + g_in_exiting_signal_handler = true; + D_QuitNetGame(); // Fix server freezes #ifdef HAVE_LIBBACKTRACE From 4b69b39d39cb3637f122ff99e4cec91e5259f903 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 15:49:01 +0200 Subject: [PATCH 22/51] HMS_fetch_rules: Return NULL if the curl connection failed, instead of producing garbled rules --- src/http-mserv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/http-mserv.c b/src/http-mserv.c index d1ef80ae4..9e32f9ea7 100644 --- a/src/http-mserv.c +++ b/src/http-mserv.c @@ -532,7 +532,9 @@ HMS_fetch_rules (char *buffer, size_t buffer_size) if (! hms) return NULL; - if (HMS_do(hms)) + boolean ok = HMS_do(hms); + + if (ok) { char *p = strstr(hms->buffer, "\n\n"); @@ -550,6 +552,9 @@ HMS_fetch_rules (char *buffer, size_t buffer_size) HMS_end(hms); + if (!ok) + return NULL; + return buffer; } From fe6ad4f76269a2fef8c235c4c9cd9d8a90314fed Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 16:54:24 +0200 Subject: [PATCH 23/51] Do not run ST_Ticker if dedicated --- src/st_stuff.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 7e28edfc8..df4ba7db9 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -456,7 +456,9 @@ void ST_Start(void) ST_Stop(); ST_InitData(); - st_stopped = false; + + if (!dedicated) + st_stopped = false; } // From 64ef0465d5bccf11d50dd990234df7b50c15f200 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 18:06:46 +0200 Subject: [PATCH 24/51] calloc soundchannels insteal of mallocing --- src/s_sound.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index fe44d51a1..0bc76bce2 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -311,8 +311,6 @@ void S_RegisterSoundStuff(void) static void SetChannelsNum(void) { - INT32 i; - // Allocating the internal channels for mixing // (the maximum number of sounds rendered // simultaneously) within zone memory. @@ -322,7 +320,6 @@ static void SetChannelsNum(void) Z_Free(channels); channels = NULL; - if (cv_numChannels.value == 999999999) //Alam_GBC: OH MY ROD!(ROD rimmiced with GOD!) CV_StealthSet(&cv_numChannels,cv_numChannels.defaultvalue); @@ -333,13 +330,10 @@ static void SetChannelsNum(void) return; } #endif - if (cv_numChannels.value) - channels = (channel_t *)Z_Malloc(cv_numChannels.value * sizeof (channel_t), PU_STATIC, NULL); - numofchannels = cv_numChannels.value; - // Free all channels for use - for (i = 0; i < numofchannels; i++) - channels[i].sfxinfo = 0; + if (cv_numChannels.value) + channels = (channel_t *)Z_Calloc(cv_numChannels.value * sizeof (channel_t), PU_STATIC, NULL); + numofchannels = (channels ? cv_numChannels.value : 0); } // Retrieve the lump number of sfx From cd72bce3cbbb54e59a9d58c047bf6f9549c9cb49 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 18:13:28 +0200 Subject: [PATCH 25/51] dont reload palette until config was loaded --- src/d_main.c | 4 ++++ src/d_main.h | 2 ++ src/v_video.c | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/src/d_main.c b/src/d_main.c index 1c7fc63e1..3b6573e5c 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -150,6 +150,8 @@ INT32 eventhead, eventtail; boolean dedicated = false; +boolean loaded_config = false; + // // D_PostEvent // Called by the I/O functions when input is detected @@ -1753,6 +1755,8 @@ void D_SRB2Main(void) savedata.lives = 0; // flag this as not-used + loaded_config = true; // so pallettechange doesent get called 500 times at startup lol + //------------------------------------------------ COMMAND LINE PARAMS // this must be done after loading gamedata, diff --git a/src/d_main.h b/src/d_main.h index d4d3e6e95..851eaa8b5 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -20,6 +20,8 @@ // make sure not to write back the config until it's been correctly loaded extern tic_t rendergametic; +extern boolean loaded_config; + extern char srb2home[256]; //Alam: My Home extern boolean usehome; //Alam: which path? extern const char *pandf; //Alam: how to path? diff --git a/src/v_video.c b/src/v_video.c index 4c5e1cfd3..202b5d288 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -14,6 +14,7 @@ /// Functions to blit a block to the screen. #include "doomdef.h" +#include "d_main.h" #include "r_local.h" #include "p_local.h" #include "v_video.h" @@ -132,6 +133,9 @@ static boolean InitCube(void) float globalgammamul, globalgammaoffs; boolean doinggamma; + if (loaded_config == false) + return false; + #define diffcons(cv) (cv.value != atoi(cv.defaultvalue)) doinggamma = diffcons(cv_globalgamma); @@ -568,6 +572,8 @@ void V_SetPaletteLump(const char *pal) static void CV_palette_OnChange(void) { + if (loaded_config == false) + return; // reload palette LoadMapPalette(); V_SetPalette(0); From 5c7d9327e3bda82b1b0725be2cfd6ecb466ee147 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 18:18:29 +0200 Subject: [PATCH 26/51] SDL: only react to window focus changes if state actually changes --- src/sdl/i_video.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 16f4c4336..da055265e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -775,6 +775,7 @@ void I_DownSample(void) static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { +#define FOCUSUNION (mousefocus | (kbfocus << 1)) static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; @@ -782,6 +783,8 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) static SDL_bool windowmoved = SDL_FALSE; #endif + const unsigned int oldfocus = FOCUSUNION; + switch (evt.event) { case SDL_WINDOWEVENT_ENTER: @@ -807,6 +810,18 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) #endif } +#ifdef USE_FBO_OGL + if (windowmoved && rendermode == render_opengl) + { + I_DownSample(); + } +#endif + + if (FOCUSUNION == oldfocus) // No state change + { + return; + } + if (mousefocus && kbfocus) { // Tell game we got focus back, resume music if necessary @@ -843,13 +858,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) SDLdoUngrabMouse(); } } - -#ifdef USE_FBO_OGL - if (windowmoved && rendermode == render_opengl) - { - I_DownSample(); - } -#endif +#undef FOCUSUNION } static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) From 4423fb300f8bac242c43ed10c7093d360f97e085 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Jul 2024 19:54:08 +0200 Subject: [PATCH 27/51] set controller rgb to playercolor eh only for 1st player now no splitscreen support idk if everything here is even correct --- src/d_main.c | 4 ++++ src/d_netcmd.c | 2 ++ src/g_input.c | 19 +++++++++++++++++++ src/g_input.h | 2 ++ src/i_video.h | 2 ++ src/sdl/i_video.c | 17 +++++++++++++++++ 6 files changed, 46 insertions(+) diff --git a/src/d_main.c b/src/d_main.c index 3b6573e5c..62b8025bb 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -37,6 +37,7 @@ #include "d_net.h" #include "f_finale.h" #include "g_game.h" +#include "g_input.h" #include "hu_stuff.h" #include "i_sound.h" #include "i_system.h" @@ -1841,6 +1842,9 @@ void D_SRB2Main(void) CONS_Printf("ST_Init(): Init status bar.\n"); ST_Init(); + if (!dedicated) + G_SetPlayerGamepadIndicatorToPlayerColor(); // no idea where else to throw it lol + // Set up splitscreen players before joining! if (!dedicated && (M_CheckParm("-splitscreen") && M_IsNextParm())) { diff --git a/src/d_netcmd.c b/src/d_netcmd.c index a8e01a766..57b4a8824 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -6079,6 +6079,8 @@ static void Color_OnChange(void) CV_StealthSetValue(&cv_playercolor, players[consoleplayer].skincolor); } + + G_SetPlayerGamepadIndicatorToPlayerColor(); } /** Sends a color change for the secondary splitscreen player, unless that diff --git a/src/g_input.c b/src/g_input.c index 536ea0c83..86094fbf8 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -14,11 +14,16 @@ #include "doomdef.h" #include "doomstat.h" #include "g_input.h" +#include "g_game.h" #include "keys.h" #include "hu_stuff.h" // need HUFONT start & end #include "d_net.h" #include "console.h" +#include "i_video.h" +#include "r_draw.h" +#include "v_video.h" + #define MAXMOUSESENSITIVITY 100 // sensitivity steps static CV_PossibleValue_t mousesens_cons_t[] = {{1, "MIN"}, {MAXMOUSESENSITIVITY, "MAX"}, {0, NULL}}; @@ -817,6 +822,20 @@ static const char *gamecontrolname[num_gamecontrols] = #define NUMKEYNAMES (sizeof (keynames)/sizeof (keyname_t)) +#include "k_kart.h" +// ehhhhhh ill maybe add splitscreen support eventually lol +void G_SetPlayerGamepadIndicatorToPlayerColor(void) +{ + UINT16 skincolor; + byteColor_t byte_color; + + skincolor = cv_playercolor.value; + + byte_color = V_GetColor(colortranslations[skincolor][8]).s; + + I_SetGamepadIndicatorColor(1, byte_color.red, byte_color.green, byte_color.blue); +} + // // Detach any keys associated to the given game control // - pass the pointer to the gamecontrol table for the player being edited diff --git a/src/g_input.h b/src/g_input.h index 635e1f64b..25b1dc119 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -130,6 +130,8 @@ extern INT32 gamecontrol4[num_gamecontrols][2]; // peace to my little coder fingers! // check a gamecontrol being active or not +void G_SetPlayerGamepadIndicatorToPlayerColor(void); + // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev); diff --git a/src/i_video.h b/src/i_video.h index 708fde03c..553e3851a 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,6 +139,8 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); +void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue); + #ifdef USE_FBO_OGL void RefreshOGLSDLSurface(void); void I_DownSample(void); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index da055265e..b94b81c19 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1529,6 +1529,23 @@ void I_StartupMouse(void) SDLdoUngrabMouse(); } +void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue) +{ +#if !(SDL_VERSION_ATLEAST(2,0,14)) + (void)device_id; +#else + I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher + + SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1); + if (controller == NULL) + { + return; + } + + SDL_GameControllerSetLED(controller, red, green, blue); +#endif +} + // // I_OsPolling // From 754b028623424f8751b4bd74001d75daf65683c6 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 01:11:54 +0200 Subject: [PATCH 28/51] give rgb custom color support, change rgb light color earlier in Color_OnChange so it always unconditionally changes the color also --- src/d_main.c | 3 --- src/d_netcmd.c | 4 ++-- src/g_input.c | 7 +++++-- src/g_input.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 62b8025bb..79f564e1f 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1842,9 +1842,6 @@ void D_SRB2Main(void) CONS_Printf("ST_Init(): Init status bar.\n"); ST_Init(); - if (!dedicated) - G_SetPlayerGamepadIndicatorToPlayerColor(); // no idea where else to throw it lol - // Set up splitscreen players before joining! if (!dedicated && (M_CheckParm("-splitscreen") && M_IsNextParm())) { diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 57b4a8824..2f8c4afaa 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -6060,6 +6060,8 @@ static void Command_SkinSearch(void) */ static void Color_OnChange(void) { + G_SetPlayerGamepadIndicatorToPlayerColor(0); // i want this to always change so its here + if (!Playing()) return; // do whatever you want @@ -6079,8 +6081,6 @@ static void Color_OnChange(void) CV_StealthSetValue(&cv_playercolor, players[consoleplayer].skincolor); } - - G_SetPlayerGamepadIndicatorToPlayerColor(); } /** Sends a color change for the secondary splitscreen player, unless that diff --git a/src/g_input.c b/src/g_input.c index 86094fbf8..ad15f44ce 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -824,12 +824,15 @@ static const char *gamecontrolname[num_gamecontrols] = #include "k_kart.h" // ehhhhhh ill maybe add splitscreen support eventually lol -void G_SetPlayerGamepadIndicatorToPlayerColor(void) +void G_SetPlayerGamepadIndicatorToPlayerColor(UINT16 color) { UINT16 skincolor; byteColor_t byte_color; - skincolor = cv_playercolor.value; + if (color) + skincolor = color; + else + skincolor = cv_playercolor.value; byte_color = V_GetColor(colortranslations[skincolor][8]).s; diff --git a/src/g_input.h b/src/g_input.h index 25b1dc119..13b0fa508 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -130,7 +130,7 @@ extern INT32 gamecontrol4[num_gamecontrols][2]; // peace to my little coder fingers! // check a gamecontrol being active or not -void G_SetPlayerGamepadIndicatorToPlayerColor(void); +void G_SetPlayerGamepadIndicatorToPlayerColor(UINT16 color); // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev); From 694c1ad808b6861a5860dbeb7edf3db4eb5fcdc5 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 01:12:17 +0200 Subject: [PATCH 29/51] change color light when you cycle between colors in player setup --- src/m_menu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/m_menu.c b/src/m_menu.c index 80b1d635a..3807d1374 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -11253,6 +11253,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor--; + G_SetPlayerGamepadIndicatorToPlayerColor(setupm_fakecolor); } break; @@ -11308,6 +11309,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor++; + G_SetPlayerGamepadIndicatorToPlayerColor(setupm_fakecolor); } break; @@ -11635,6 +11637,7 @@ static boolean M_QuitMultiPlayerMenu(void) // you know what? always putting these in the buffer won't hurt anything. COM_BufAddText (va("%s \"%s\"\n",setupm_cvskin->name,skins[setupm_fakeskin].name)); COM_BufAddText (va("%s %d\n",setupm_cvcolor->name,setupm_fakecolor)); + return true; } From 9dc5e3d338a18644d9372c47d894fc677447bdba Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 01:39:33 +0200 Subject: [PATCH 30/51] ressting to defaultcolor should also set led color --- src/m_menu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/m_menu.c b/src/m_menu.c index 3807d1374..703bf3dc2 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -11349,6 +11349,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor = col; + G_SetPlayerGamepadIndicatorToPlayerColor(setupm_fakecolor); } } break; From fe8e00895a06003f5e618058cb076d2e7a3602f8 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 02:59:42 +0200 Subject: [PATCH 31/51] simplify reduntand condition --- src/k_kart.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 628060743..293e5209b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -617,10 +617,8 @@ UINT8 K_GetKartColorByName(const char *name) UINT8 K_GetHudColor(void) { - if (cv_colorizedhud.value){ - if (cv_colorizedhudcolor.value) return cv_colorizedhudcolor.value; - } - if (stplyr && P_IsLocalPlayer(stplyr) && gamestate == GS_LEVEL) return stplyr->skincolor; + if (cv_colorizedhud.value && cv_colorizedhudcolor.value) return cv_colorizedhudcolor.value; + return ((stplyr && gamestate == GS_LEVEL) ? stplyr->skincolor : cv_playercolor.value); } From 7bd1808c882d0d15a3a852c695731d0ef1d8ab26 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 03:57:20 +0200 Subject: [PATCH 32/51] change gamepad rgb color when switching viewpoints --- src/d_netcmd.c | 2 ++ src/g_game.c | 5 +++++ src/g_input.c | 8 +++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 2f8c4afaa..873824567 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -6081,6 +6081,8 @@ static void Color_OnChange(void) CV_StealthSetValue(&cv_playercolor, players[consoleplayer].skincolor); } + + G_SetPlayerGamepadIndicatorToPlayerColor(0); // update again } /** Sends a color change for the secondary splitscreen player, unless that diff --git a/src/g_game.c b/src/g_game.c index ff459c59a..767c2e7bf 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2150,6 +2150,8 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) if (viewnum == 1 && demo.playback) consoleplayer = displayplayers[0]; + + G_SetPlayerGamepadIndicatorToPlayerColor(0); } // @@ -8537,6 +8539,9 @@ boolean G_DemoTitleResponder(event_t *ev) void G_SetGamestate(gamestate_t newstate) { gamestate = newstate; + + G_SetPlayerGamepadIndicatorToPlayerColor(0); // dumb hack but works + #ifdef HAVE_DISCORDRPC DRPC_UpdatePresence(); #endif diff --git a/src/g_input.c b/src/g_input.c index ad15f44ce..c1ab6af57 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -823,6 +823,12 @@ static const char *gamecontrolname[num_gamecontrols] = #define NUMKEYNAMES (sizeof (keynames)/sizeof (keyname_t)) #include "k_kart.h" + +static UINT16 G_GetSkinColor(void) +{ + return ((gamestate == GS_LEVEL) ? players[displayplayers[0]].skincolor : cv_playercolor.value); +} + // ehhhhhh ill maybe add splitscreen support eventually lol void G_SetPlayerGamepadIndicatorToPlayerColor(UINT16 color) { @@ -832,7 +838,7 @@ void G_SetPlayerGamepadIndicatorToPlayerColor(UINT16 color) if (color) skincolor = color; else - skincolor = cv_playercolor.value; + skincolor = G_GetSkinColor(); byte_color = V_GetColor(colortranslations[skincolor][8]).s; From c75e6ba63c114a4b2f768cce61534539384e7f48 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 20:40:13 +0200 Subject: [PATCH 33/51] add basic rumble support for gamepads --- src/d_netcmd.c | 2 ++ src/g_input.c | 12 ++++++++++++ src/g_input.h | 2 ++ src/i_video.h | 1 + src/p_tick.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/sdl/i_video.c | 19 +++++++++++++++++++ 6 files changed, 81 insertions(+) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 873824567..8d1584cd7 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1073,6 +1073,8 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_controlperkey); CV_RegisterVar(&cv_turnsmooth); + CV_RegisterVar(&cv_rumble); + CV_RegisterVar(&cv_usemouse); CV_RegisterVar(&cv_usemouse2); CV_RegisterVar(&cv_invertmouse); diff --git a/src/g_input.c b/src/g_input.c index c1ab6af57..98495274a 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -38,6 +38,8 @@ consvar_t cv_mouseysens2 = {"mouseysens2", "20", CV_SAVE, mousesens_cons_t, NULL consvar_t cv_controlperkey = {"controlperkey", "One", CV_SAVE, onecontrolperkey_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_turnsmooth = {"turnsmoothing", "Slow", CV_SAVE, turnsmooth_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_rumble = {"gamepadrumble", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + INT32 mousex, mousey; INT32 mlooky; // like mousey but with a custom sensitivity for mlook @@ -845,6 +847,16 @@ void G_SetPlayerGamepadIndicatorToPlayerColor(UINT16 color) I_SetGamepadIndicatorColor(1, byte_color.red, byte_color.green, byte_color.blue); } +void G_PlayerDeviceRumble(UINT16 low_strength, UINT16 high_strength) +{ + if (cv_rumble.value == 0) + { + return; + } + + I_GamepadRumble(1, low_strength, high_strength); +} + // // Detach any keys associated to the given game control // - pass the pointer to the gamecontrol table for the player being edited diff --git a/src/g_input.h b/src/g_input.h index 13b0fa508..3090f2117 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -106,6 +106,7 @@ typedef enum extern consvar_t cv_mousesens, cv_mouseysens; extern consvar_t cv_mousesens2, cv_mouseysens2; extern consvar_t cv_controlperkey, cv_turnsmooth; +extern consvar_t cv_rumble; extern INT32 mousex, mousey; extern INT32 mlooky; //mousey with mlookSensitivity @@ -131,6 +132,7 @@ extern INT32 gamecontrol4[num_gamecontrols][2]; // check a gamecontrol being active or not void G_SetPlayerGamepadIndicatorToPlayerColor(UINT16 color); +void G_PlayerDeviceRumble(UINT16 low_strength, UINT16 high_strength); // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev); diff --git a/src/i_video.h b/src/i_video.h index 553e3851a..8cb332c5c 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,6 +139,7 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength); void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue); #ifdef USE_FBO_OGL diff --git a/src/p_tick.c b/src/p_tick.c index 2bf7f1024..22def813f 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -315,6 +315,45 @@ static inline void P_RunThinkers(void) } } +static inline void P_DeviceRumbleTick(void) +{ + player_t *player; + UINT16 low = 0; + UINT16 high = 0; + + if (cv_rumble.value == 0) + { + return; + } + + if (paused) + return; + + player = &players[displayplayers[0]]; + + if (!P_IsLocalPlayer(player)) + return; + + if (player->mo != NULL && !player->exiting) + { + if (player->kartstuff[k_spinouttimer]) + { + low = high = 65536 / 4; + } + else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) + { + low = high = 65536 / 8; + } + else if ((player->kartstuff[k_offroad]) + && P_IsObjectOnGround(player->mo) && player->speed != 0) + { + low = high = 65536 / 64; + } + } + + G_PlayerDeviceRumble(low, high); +} + void P_RunChaseCameras(void) { UINT8 i; @@ -420,6 +459,12 @@ void P_Ticker(boolean run) } #endif } + + // Apply rumble to local players + if (!demo.playback) + { + P_DeviceRumbleTick(); + } ps_lua_mobjhooks.value.i = 0; ps_checkposition_calls.value.i = 0; diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index b94b81c19..c0f9d0bf1 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1529,6 +1529,25 @@ void I_StartupMouse(void) SDLdoUngrabMouse(); } +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength) +{ +#if !(SDL_VERSION_ATLEAST(2,0,14)) + (void)device_id; + (void)left_strength; + (void)right_strength; +#else + I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher + + SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1); + if (controller == NULL) + { + return; + } + + SDL_GameControllerRumble(controller, low_strength, high_strength, 0); +#endif +} + void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue) { #if !(SDL_VERSION_ATLEAST(2,0,14)) From 6efc8fdad374dea84b10f637a077013a5f063a97 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 21:41:18 +0200 Subject: [PATCH 34/51] add splitscreen support to gamepad led also add more proper device check --- src/d_netcmd.c | 10 ++++++-- src/g_game.c | 6 +++-- src/g_input.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++---- src/g_input.h | 2 +- src/m_menu.c | 16 ++++++++++--- 5 files changed, 83 insertions(+), 13 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 8d1584cd7..9128f5e4d 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -6062,7 +6062,7 @@ static void Command_SkinSearch(void) */ static void Color_OnChange(void) { - G_SetPlayerGamepadIndicatorToPlayerColor(0); // i want this to always change so its here + G_SetPlayerGamepadIndicatorToPlayerColor(0, 0); // i want this to always change so its here if (!Playing()) return; // do whatever you want @@ -6084,7 +6084,7 @@ static void Color_OnChange(void) players[consoleplayer].skincolor); } - G_SetPlayerGamepadIndicatorToPlayerColor(0); // update again + G_SetPlayerGamepadIndicatorToPlayerColor(0, 0); // update again } /** Sends a color change for the secondary splitscreen player, unless that @@ -6107,6 +6107,8 @@ static void Color2_OnChange(void) CV_StealthSetValue(&cv_playercolor2, players[displayplayers[1]].skincolor); } + + G_SetPlayerGamepadIndicatorToPlayerColor(1, 0); } static void Color3_OnChange(void) @@ -6124,6 +6126,8 @@ static void Color3_OnChange(void) CV_StealthSetValue(&cv_playercolor3, players[displayplayers[2]].skincolor); } + + G_SetPlayerGamepadIndicatorToPlayerColor(2, 0); } static void Color4_OnChange(void) @@ -6141,6 +6145,8 @@ static void Color4_OnChange(void) CV_StealthSetValue(&cv_playercolor4, players[displayplayers[3]].skincolor); } + + G_SetPlayerGamepadIndicatorToPlayerColor(3, 0); } /** Displays the result of the chat being muted or unmuted. diff --git a/src/g_game.c b/src/g_game.c index 767c2e7bf..8c7431ff8 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2151,7 +2151,7 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) if (viewnum == 1 && demo.playback) consoleplayer = displayplayers[0]; - G_SetPlayerGamepadIndicatorToPlayerColor(0); + G_SetPlayerGamepadIndicatorToPlayerColor(viewnum-1, 0); } // @@ -8538,9 +8538,11 @@ boolean G_DemoTitleResponder(event_t *ev) // void G_SetGamestate(gamestate_t newstate) { + SINT8 i; gamestate = newstate; - G_SetPlayerGamepadIndicatorToPlayerColor(0); // dumb hack but works + for (i = 0; i <= splitscreen; i++) + G_SetPlayerGamepadIndicatorToPlayerColor(i, 0); // dumb hack but works #ifdef HAVE_DISCORDRPC DRPC_UpdatePresence(); diff --git a/src/g_input.c b/src/g_input.c index 98495274a..46b44347c 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -826,25 +826,77 @@ static const char *gamecontrolname[num_gamecontrols] = #include "k_kart.h" -static UINT16 G_GetSkinColor(void) +static INT32 G_GetDeviceForPlayer(INT32 player) { - return ((gamestate == GS_LEVEL) ? players[displayplayers[0]].skincolor : cv_playercolor.value); + switch (player) + { + case 0: + return cv_usejoystick.value; + break; + case 1: + return cv_usejoystick2.value; + break; + case 2: + return cv_usejoystick3.value; + break; + case 3: + return cv_usejoystick4.value; + break; + default: + return 0; + break; + } +} + +static UINT16 G_GetSkinColor(INT32 player) +{ + if (gamestate == GS_LEVEL) + return players[displayplayers[player]].skincolor; + + switch (player) + { + case 0: + return cv_playercolor.value; + break; + case 1: + return cv_playercolor2.value; + break; + case 2: + return cv_playercolor3.value; + break; + case 3: + return cv_playercolor4.value; + break; + default: + return 0; + break; + } } // ehhhhhh ill maybe add splitscreen support eventually lol -void G_SetPlayerGamepadIndicatorToPlayerColor(UINT16 color) +void G_SetPlayerGamepadIndicatorToPlayerColor(INT32 player, UINT16 color) { + INT32 device; UINT16 skincolor; byteColor_t byte_color; + I_Assert(player >= 0 && player < MAXSPLITSCREENPLAYERS); + + device = G_GetDeviceForPlayer(player); + + if (device <= 0) + { + return; + } + if (color) skincolor = color; else - skincolor = G_GetSkinColor(); + skincolor = G_GetSkinColor(player); byte_color = V_GetColor(colortranslations[skincolor][8]).s; - I_SetGamepadIndicatorColor(1, byte_color.red, byte_color.green, byte_color.blue); + I_SetGamepadIndicatorColor(device, byte_color.red, byte_color.green, byte_color.blue); } void G_PlayerDeviceRumble(UINT16 low_strength, UINT16 high_strength) diff --git a/src/g_input.h b/src/g_input.h index 3090f2117..978f377d6 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -131,7 +131,7 @@ extern INT32 gamecontrol4[num_gamecontrols][2]; // peace to my little coder fingers! // check a gamecontrol being active or not -void G_SetPlayerGamepadIndicatorToPlayerColor(UINT16 color); +void G_SetPlayerGamepadIndicatorToPlayerColor(INT32 player, UINT16 color); void G_PlayerDeviceRumble(UINT16 low_strength, UINT16 high_strength); // remaps the input event to a game control. diff --git a/src/m_menu.c b/src/m_menu.c index 703bf3dc2..08098fc88 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10412,6 +10412,8 @@ static UINT8 setupm_skinypos; static INT32 setupm_skinselect; static boolean setupm_skinlockedselect; +static UINT8 setupm_playernum; //brap + #define SELECTEDSTATSCOUNT skinstatscount[setupm_skinxpos][setupm_skinypos] #define LASTSELECTEDSTAT skinstats[setupm_skinxpos][setupm_skinypos][skinstatscount[setupm_skinxpos][setupm_skinypos]] @@ -11253,7 +11255,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor--; - G_SetPlayerGamepadIndicatorToPlayerColor(setupm_fakecolor); + G_SetPlayerGamepadIndicatorToPlayerColor(setupm_playernum, setupm_fakecolor); } break; @@ -11309,7 +11311,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor++; - G_SetPlayerGamepadIndicatorToPlayerColor(setupm_fakecolor); + G_SetPlayerGamepadIndicatorToPlayerColor(setupm_playernum, setupm_fakecolor); } break; @@ -11349,7 +11351,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor = col; - G_SetPlayerGamepadIndicatorToPlayerColor(setupm_fakecolor); + G_SetPlayerGamepadIndicatorToPlayerColor(setupm_playernum, setupm_fakecolor); } } break; @@ -11483,6 +11485,8 @@ static void M_SetupMultiPlayer(INT32 choice) setupm_skinypos = 0; setupm_skinlockedselect = false; + setupm_playernum = 0; + // For whatever reason this doesn't work right if you just use ->value setupm_fakeskin = R_SkinAvailable(setupm_cvskin->string); if (setupm_fakeskin == -1) @@ -11522,6 +11526,8 @@ static void M_SetupMultiPlayer2(INT32 choice) setupm_skinypos = 0; setupm_skinlockedselect = false; + setupm_playernum = 1; + // For whatever reason this doesn't work right if you just use ->value setupm_fakeskin = R_SkinAvailable(setupm_cvskin->string); if (setupm_fakeskin == -1) @@ -11561,6 +11567,8 @@ static void M_SetupMultiPlayer3(INT32 choice) setupm_skinypos = 0; setupm_skinlockedselect = false; + setupm_playernum = 2; + // For whatever reason this doesn't work right if you just use ->value setupm_fakeskin = R_SkinAvailable(setupm_cvskin->string); if (setupm_fakeskin == -1) @@ -11600,6 +11608,8 @@ static void M_SetupMultiPlayer4(INT32 choice) setupm_skinypos = 0; setupm_skinlockedselect = false; + setupm_playernum = 3; + // For whatever reason this doesn't work right if you just use ->value setupm_fakeskin = R_SkinAvailable(setupm_cvskin->string); if (setupm_fakeskin == -1) From acb0144742bb1ffb0502f78343e766910b573f14 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 22:17:01 +0200 Subject: [PATCH 35/51] splitscreen support for rumble --- src/d_netcmd.c | 5 +++- src/g_input.c | 73 ++++++++++++++++++++++++++++++++++++++++++---- src/g_input.h | 5 ++-- src/i_system.h | 3 ++ src/i_video.h | 3 -- src/p_tick.c | 56 +++++++++++++++++++---------------- src/sdl/i_system.c | 36 +++++++++++++++++++++++ src/sdl/i_video.c | 36 ----------------------- 8 files changed, 144 insertions(+), 73 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 9128f5e4d..03c3dc93e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1073,7 +1073,10 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_controlperkey); CV_RegisterVar(&cv_turnsmooth); - CV_RegisterVar(&cv_rumble); + CV_RegisterVar(&cv_rumble[0]); + CV_RegisterVar(&cv_rumble[1]); + CV_RegisterVar(&cv_rumble[2]); + CV_RegisterVar(&cv_rumble[3]); CV_RegisterVar(&cv_usemouse); CV_RegisterVar(&cv_usemouse2); diff --git a/src/g_input.c b/src/g_input.c index 46b44347c..4e5b8b1ba 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -16,10 +16,12 @@ #include "g_input.h" #include "g_game.h" #include "keys.h" +#include "k_kart.h" #include "hu_stuff.h" // need HUFONT start & end #include "d_net.h" #include "console.h" +#include "i_system.h" #include "i_video.h" #include "r_draw.h" #include "v_video.h" @@ -38,7 +40,45 @@ consvar_t cv_mouseysens2 = {"mouseysens2", "20", CV_SAVE, mousesens_cons_t, NULL consvar_t cv_controlperkey = {"controlperkey", "One", CV_SAVE, onecontrolperkey_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_turnsmooth = {"turnsmoothing", "Slow", CV_SAVE, turnsmooth_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_rumble = {"gamepadrumble", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +static void G_ResetPlayerDeviceRumble(INT32 player); +static void rumble_off_handle(void); +static void rumble_off_handle2(void); +static void rumble_off_handle3(void); +static void rumble_off_handle4(void); + +consvar_t cv_rumble[MAXSPLITSCREENPLAYERS] = { + {"rumble", "Off", CV_SAVE, CV_OnOff, rumble_off_handle, 0, NULL, NULL, 0, 0, NULL}, + {"rumble2", "Off", CV_SAVE, CV_OnOff, rumble_off_handle2, 0, NULL, NULL, 0, 0, NULL}, + {"rumble3", "Off", CV_SAVE, CV_OnOff, rumble_off_handle3, 0, NULL, NULL, 0, 0, NULL}, + {"rumble4", "Off", CV_SAVE, CV_OnOff, rumble_off_handle4, 0, NULL, NULL, 0, 0, NULL} +}; + +static void rumble_off_handle(void) +{ + if (cv_rumble[0].value == 0) + G_ResetPlayerDeviceRumble(0); +} + + +static void rumble_off_handle2(void) +{ + if (cv_rumble[1].value == 0) + G_ResetPlayerDeviceRumble(1); +} + + +static void rumble_off_handle3(void) +{ + if (cv_rumble[2].value == 0) + G_ResetPlayerDeviceRumble(2); +} + + +static void rumble_off_handle4(void) +{ + if (cv_rumble[3].value == 0) + G_ResetPlayerDeviceRumble(3); +} INT32 mousex, mousey; INT32 mlooky; // like mousey but with a custom sensitivity for mlook @@ -824,8 +864,6 @@ static const char *gamecontrolname[num_gamecontrols] = #define NUMKEYNAMES (sizeof (keynames)/sizeof (keyname_t)) -#include "k_kart.h" - static INT32 G_GetDeviceForPlayer(INT32 player) { switch (player) @@ -899,14 +937,37 @@ void G_SetPlayerGamepadIndicatorToPlayerColor(INT32 player, UINT16 color) I_SetGamepadIndicatorColor(device, byte_color.red, byte_color.green, byte_color.blue); } -void G_PlayerDeviceRumble(UINT16 low_strength, UINT16 high_strength) +static void G_ResetPlayerDeviceRumble(INT32 player) { - if (cv_rumble.value == 0) + INT32 device_id; + + device_id = G_GetDeviceForPlayer(player); + + if (device_id < 1) { return; } - I_GamepadRumble(1, low_strength, high_strength); + I_GamepadRumble(device_id, 0, 0); +} + +void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength) +{ + INT32 device_id; + + if (cv_rumble[player].value == 0) + { + return; + } + + device_id = G_GetDeviceForPlayer(player); + + if (device_id < 1) + { + return; + } + + I_GamepadRumble(device_id, low_strength, high_strength); } // diff --git a/src/g_input.h b/src/g_input.h index 978f377d6..f3230b0f3 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -15,6 +15,7 @@ #define __G_INPUT__ #include "d_event.h" +#include "doomstat.h" #include "keys.h" #include "command.h" @@ -106,7 +107,7 @@ typedef enum extern consvar_t cv_mousesens, cv_mouseysens; extern consvar_t cv_mousesens2, cv_mouseysens2; extern consvar_t cv_controlperkey, cv_turnsmooth; -extern consvar_t cv_rumble; +extern consvar_t cv_rumble[MAXSPLITSCREENPLAYERS]; extern INT32 mousex, mousey; extern INT32 mlooky; //mousey with mlookSensitivity @@ -132,7 +133,7 @@ extern INT32 gamecontrol4[num_gamecontrols][2]; // check a gamecontrol being active or not void G_SetPlayerGamepadIndicatorToPlayerColor(INT32 player, UINT16 color); -void G_PlayerDeviceRumble(UINT16 low_strength, UINT16 high_strength); +void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength); // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev); diff --git a/src/i_system.h b/src/i_system.h index f1d098e4a..8239bade8 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -230,6 +230,9 @@ INT32 I_NumJoys(void); */ const char *I_GetJoyName(INT32 joyindex); +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength); +void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue); + #ifndef NOMUMBLE #include "p_mobj.h" // mobj_t #include "s_sound.h" // listener_t diff --git a/src/i_video.h b/src/i_video.h index 8cb332c5c..708fde03c 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,9 +139,6 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); -void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength); -void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue); - #ifdef USE_FBO_OGL void RefreshOGLSDLSurface(void); void I_DownSample(void); diff --git a/src/p_tick.c b/src/p_tick.c index 22def813f..0d98a0d59 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -317,11 +317,9 @@ static inline void P_RunThinkers(void) static inline void P_DeviceRumbleTick(void) { - player_t *player; - UINT16 low = 0; - UINT16 high = 0; + UINT8 i; - if (cv_rumble.value == 0) + if (cv_rumble[0].value && cv_rumble[1].value && cv_rumble[2].value && cv_rumble[3].value == 0) { return; } @@ -329,29 +327,37 @@ static inline void P_DeviceRumbleTick(void) if (paused) return; - player = &players[displayplayers[0]]; - - if (!P_IsLocalPlayer(player)) - return; - - if (player->mo != NULL && !player->exiting) + for (i = 0; i <= splitscreen; i++) { - if (player->kartstuff[k_spinouttimer]) - { - low = high = 65536 / 4; - } - else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) - { - low = high = 65536 / 8; - } - else if ((player->kartstuff[k_offroad]) - && P_IsObjectOnGround(player->mo) && player->speed != 0) - { - low = high = 65536 / 64; - } - } + player_t *player = &players[displayplayers[i]]; + UINT16 low = 0; + UINT16 high = 0; - G_PlayerDeviceRumble(low, high); + if (!P_IsLocalPlayer(player)) + continue; + + if (!playeringame[i]) + continue; + + if (player->mo != NULL && !player->exiting) + { + if (player->kartstuff[k_spinouttimer]) + { + low = high = 65536 / 4; + } + else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) + { + low = high = 65536 / 8; + } + else if ((player->kartstuff[k_offroad]) + && P_IsObjectOnGround(player->mo) && player->speed != 0) + { + low = high = 65536 / 64; + } + } + + G_PlayerDeviceRumble(i, low, high); + } } void P_RunChaseCameras(void) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 00bc3200f..454c1e295 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2666,6 +2666,42 @@ const char *I_GetJoyName(INT32 joyindex) return joyname; } +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength) +{ +#if !(SDL_VERSION_ATLEAST(2,0,14)) + (void)device_id; + (void)left_strength; + (void)right_strength; +#else + I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher + + SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1); + if (controller == NULL) + { + return; + } + + SDL_GameControllerRumble(controller, low_strength, high_strength, 0); +#endif +} + +void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue) +{ +#if !(SDL_VERSION_ATLEAST(2,0,14)) + (void)device_id; +#else + I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher + + SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1); + if (controller == NULL) + { + return; + } + + SDL_GameControllerSetLED(controller, red, green, blue); +#endif +} + #ifndef NOMUMBLE #ifdef HAVE_MUMBLE // Best Mumble positional audio settings: diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index c0f9d0bf1..da055265e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1529,42 +1529,6 @@ void I_StartupMouse(void) SDLdoUngrabMouse(); } -void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength) -{ -#if !(SDL_VERSION_ATLEAST(2,0,14)) - (void)device_id; - (void)left_strength; - (void)right_strength; -#else - I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher - - SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1); - if (controller == NULL) - { - return; - } - - SDL_GameControllerRumble(controller, low_strength, high_strength, 0); -#endif -} - -void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue) -{ -#if !(SDL_VERSION_ATLEAST(2,0,14)) - (void)device_id; -#else - I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher - - SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1); - if (controller == NULL) - { - return; - } - - SDL_GameControllerSetLED(controller, red, green, blue); -#endif -} - // // I_OsPolling // From 49fcf3e4865bb08be4a6f18a81f8347e1ea3af7f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 22:45:39 +0200 Subject: [PATCH 36/51] rename to G_SetPlayerGamepadIndicatorColor --- src/d_netcmd.c | 10 +++++----- src/g_game.c | 4 ++-- src/g_input.c | 6 +++--- src/g_input.h | 2 +- src/lua_baselib.c | 2 +- src/m_menu.c | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 03c3dc93e..3103b4fc8 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -6065,7 +6065,7 @@ static void Command_SkinSearch(void) */ static void Color_OnChange(void) { - G_SetPlayerGamepadIndicatorToPlayerColor(0, 0); // i want this to always change so its here + G_SetPlayerGamepadIndicatorColor(0, 0); // i want this to always change so its here if (!Playing()) return; // do whatever you want @@ -6087,7 +6087,7 @@ static void Color_OnChange(void) players[consoleplayer].skincolor); } - G_SetPlayerGamepadIndicatorToPlayerColor(0, 0); // update again + G_SetPlayerGamepadIndicatorColor(0, 0); // update again } /** Sends a color change for the secondary splitscreen player, unless that @@ -6111,7 +6111,7 @@ static void Color2_OnChange(void) players[displayplayers[1]].skincolor); } - G_SetPlayerGamepadIndicatorToPlayerColor(1, 0); + G_SetPlayerGamepadIndicatorColor(1, 0); } static void Color3_OnChange(void) @@ -6130,7 +6130,7 @@ static void Color3_OnChange(void) players[displayplayers[2]].skincolor); } - G_SetPlayerGamepadIndicatorToPlayerColor(2, 0); + G_SetPlayerGamepadIndicatorColor(2, 0); } static void Color4_OnChange(void) @@ -6149,7 +6149,7 @@ static void Color4_OnChange(void) players[displayplayers[3]].skincolor); } - G_SetPlayerGamepadIndicatorToPlayerColor(3, 0); + G_SetPlayerGamepadIndicatorColor(3, 0); } /** Displays the result of the chat being muted or unmuted. diff --git a/src/g_game.c b/src/g_game.c index 8c7431ff8..2101d9fb2 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2151,7 +2151,7 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) if (viewnum == 1 && demo.playback) consoleplayer = displayplayers[0]; - G_SetPlayerGamepadIndicatorToPlayerColor(viewnum-1, 0); + G_SetPlayerGamepadIndicatorColor(viewnum-1, 0); } // @@ -8542,7 +8542,7 @@ void G_SetGamestate(gamestate_t newstate) gamestate = newstate; for (i = 0; i <= splitscreen; i++) - G_SetPlayerGamepadIndicatorToPlayerColor(i, 0); // dumb hack but works + G_SetPlayerGamepadIndicatorColor(i, 0); // dumb hack but works #ifdef HAVE_DISCORDRPC DRPC_UpdatePresence(); diff --git a/src/g_input.c b/src/g_input.c index 4e5b8b1ba..3177da488 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -16,7 +16,6 @@ #include "g_input.h" #include "g_game.h" #include "keys.h" -#include "k_kart.h" #include "hu_stuff.h" // need HUFONT start & end #include "d_net.h" #include "console.h" @@ -864,6 +863,8 @@ static const char *gamecontrolname[num_gamecontrols] = #define NUMKEYNAMES (sizeof (keynames)/sizeof (keyname_t)) +#include "k_kart.h" + static INT32 G_GetDeviceForPlayer(INT32 player) { switch (player) @@ -911,8 +912,7 @@ static UINT16 G_GetSkinColor(INT32 player) } } -// ehhhhhh ill maybe add splitscreen support eventually lol -void G_SetPlayerGamepadIndicatorToPlayerColor(INT32 player, UINT16 color) +void G_SetPlayerGamepadIndicatorColor(INT32 player, UINT16 color) { INT32 device; UINT16 skincolor; diff --git a/src/g_input.h b/src/g_input.h index f3230b0f3..dac5bd3f8 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -132,7 +132,7 @@ extern INT32 gamecontrol4[num_gamecontrols][2]; // peace to my little coder fingers! // check a gamecontrol being active or not -void G_SetPlayerGamepadIndicatorToPlayerColor(INT32 player, UINT16 color); +void G_SetPlayerGamepadIndicatorColor(INT32 player, UINT16 color); void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength); // remaps the input event to a game control. diff --git a/src/lua_baselib.c b/src/lua_baselib.c index be561e7ba..da0fd5724 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3266,4 +3266,4 @@ int LUA_BaseLib(lua_State *L) lua_pushvalue(L, LUA_GLOBALSINDEX); luaL_register(L, NULL, lib); return 0; -} \ No newline at end of file +} diff --git a/src/m_menu.c b/src/m_menu.c index 08098fc88..033cae5db 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -11255,7 +11255,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor--; - G_SetPlayerGamepadIndicatorToPlayerColor(setupm_playernum, setupm_fakecolor); + G_SetPlayerGamepadIndicatorColor(setupm_playernum, setupm_fakecolor); } break; @@ -11311,7 +11311,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor++; - G_SetPlayerGamepadIndicatorToPlayerColor(setupm_playernum, setupm_fakecolor); + G_SetPlayerGamepadIndicatorColor(setupm_playernum, setupm_fakecolor); } break; @@ -11351,7 +11351,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor = col; - G_SetPlayerGamepadIndicatorToPlayerColor(setupm_playernum, setupm_fakecolor); + G_SetPlayerGamepadIndicatorColor(setupm_playernum, setupm_fakecolor); } } break; From acad230daa5f95d0c7e06400c59694bc6dd1638b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 22:54:23 +0200 Subject: [PATCH 37/51] expose rumble and led to lua --- src/lua_baselib.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index da0fd5724..3ce53fad1 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -20,6 +20,7 @@ #include "m_random.h" #include "s_sound.h" #include "g_game.h" +#include "g_input.h" #include "hu_stuff.h" // HU_AddChatText #include "console.h" #include "k_kart.h" // SRB2Kart @@ -3000,6 +3001,56 @@ static int lib_kSetHyuCountdown(lua_State *L) return 0; } +// G_INPUT +//////////// + +static int lib_gSetPlayerGamepadIndicatorColor(lua_State *L) +{ + INT32 player = -1; + player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); // retrieve player + UINT16 color = (UINT16)luaL_checkinteger(L, 2); // skincolor + + for (int i = 0; i < MAXSPLITSCREENPLAYERS; ++i) + { + if (plr - players == displayplayers[i]) + { + player = i; + break; + } + } + + // Not a local player + if (player == -1) return 0; + + G_SetPlayerGamepadIndicatorColor(player, color); + + return 0; +} + +static int lib_gPlayerDeviceRumble(lua_State *L) +{ + INT32 player = -1; + player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); // retrieve player + UINT16 low_strength = (INT32)luaL_checkinteger(L, 2); + UINT16 high_strength = (INT32)luaL_checkinteger(L, 3); + + for (int i = 0; i < MAXSPLITSCREENPLAYERS; ++i) + { + if (plr - players == displayplayers[i]) + { + player = i; + break; + } + } + + // Not a local player + if (player == -1) return 0; + + G_PlayerDeviceRumble(player, low_strength, high_strength); + + return 0; +} + static luaL_Reg lib[] = { {"print", lib_print}, {"chatprint", lib_chatprint}, @@ -3247,6 +3298,10 @@ static luaL_Reg lib[] = { {"K_SetIndirectItemCooldown",lib_kSetIndirectItemCountdown}, {"K_SetHyudoroCooldown",lib_kSetHyuCountdown}, + //g_input + {"G_SetPlayerGamepadIndicatorColor",lib_gSetPlayerGamepadIndicatorColor}, + {"G_PlayerDeviceRumble",lib_gPlayerDeviceRumble}, + {NULL, NULL} }; From 2afa18bbdd8808bf268c8776bb2101e194a28c46 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 23:27:36 +0200 Subject: [PATCH 38/51] add duration field to G_PlayerDeviceRumble duration is in ms --- src/g_input.c | 6 +++--- src/g_input.h | 2 +- src/i_system.h | 2 +- src/lua_baselib.c | 7 ++++--- src/p_tick.c | 2 +- src/sdl/i_system.c | 4 ++-- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/g_input.c b/src/g_input.c index 3177da488..105e84532 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -948,10 +948,10 @@ static void G_ResetPlayerDeviceRumble(INT32 player) return; } - I_GamepadRumble(device_id, 0, 0); + I_GamepadRumble(device_id, 0, 0, 0); } -void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength) +void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength, UINT32 duration) { INT32 device_id; @@ -967,7 +967,7 @@ void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strengt return; } - I_GamepadRumble(device_id, low_strength, high_strength); + I_GamepadRumble(device_id, low_strength, high_strength, duration); } // diff --git a/src/g_input.h b/src/g_input.h index dac5bd3f8..92444cccc 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -133,7 +133,7 @@ extern INT32 gamecontrol4[num_gamecontrols][2]; // check a gamecontrol being active or not void G_SetPlayerGamepadIndicatorColor(INT32 player, UINT16 color); -void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength); +void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength, UINT32 duration); // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev); diff --git a/src/i_system.h b/src/i_system.h index 8239bade8..f49bca4a1 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -230,7 +230,7 @@ INT32 I_NumJoys(void); */ const char *I_GetJoyName(INT32 joyindex); -void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength); +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength, UINT32 duration); void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue); #ifndef NOMUMBLE diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 3ce53fad1..381e20e79 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3031,8 +3031,9 @@ static int lib_gPlayerDeviceRumble(lua_State *L) { INT32 player = -1; player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); // retrieve player - UINT16 low_strength = (INT32)luaL_checkinteger(L, 2); - UINT16 high_strength = (INT32)luaL_checkinteger(L, 3); + UINT16 low_strength = (INT32)luaL_checkinteger(L, 2); // low frequency rumble motor strenght + UINT16 high_strength = (INT32)luaL_checkinteger(L, 3); // high frequency rumble motor strenght + UINT32 duration = (INT32)luaL_checkinteger(L, 4); // duration of rumble in ms for (int i = 0; i < MAXSPLITSCREENPLAYERS; ++i) { @@ -3046,7 +3047,7 @@ static int lib_gPlayerDeviceRumble(lua_State *L) // Not a local player if (player == -1) return 0; - G_PlayerDeviceRumble(player, low_strength, high_strength); + G_PlayerDeviceRumble(player, low_strength, high_strength, duration); return 0; } diff --git a/src/p_tick.c b/src/p_tick.c index 0d98a0d59..0c99660d8 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -356,7 +356,7 @@ static inline void P_DeviceRumbleTick(void) } } - G_PlayerDeviceRumble(i, low, high); + G_PlayerDeviceRumble(i, low, high, 0); } } diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 454c1e295..eabe017c4 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2666,7 +2666,7 @@ const char *I_GetJoyName(INT32 joyindex) return joyname; } -void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength) +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength, UINT32 duration) { #if !(SDL_VERSION_ATLEAST(2,0,14)) (void)device_id; @@ -2681,7 +2681,7 @@ void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength) return; } - SDL_GameControllerRumble(controller, low_strength, high_strength, 0); + SDL_GameControllerRumble(controller, low_strength, high_strength, duration); #endif } From b0880607d4f748ca00731e9c71bfb07b06c29e0f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Jul 2024 23:35:32 +0200 Subject: [PATCH 39/51] fix cassting, make one tic duration default, but can still pass ms to it --- src/lua_baselib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 381e20e79..097fa9f33 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3031,9 +3031,9 @@ static int lib_gPlayerDeviceRumble(lua_State *L) { INT32 player = -1; player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); // retrieve player - UINT16 low_strength = (INT32)luaL_checkinteger(L, 2); // low frequency rumble motor strenght - UINT16 high_strength = (INT32)luaL_checkinteger(L, 3); // high frequency rumble motor strenght - UINT32 duration = (INT32)luaL_checkinteger(L, 4); // duration of rumble in ms + UINT16 low_strength = (UINT16)luaL_checkinteger(L, 2); // low frequency rumble motor strenght + UINT16 high_strength = (UINT16)luaL_checkinteger(L, 3); // high frequency rumble motor strenght + UINT32 duration = (UINT32)luaL_optinteger(L, 4, 28); // duration of rumble in ms for (int i = 0; i < MAXSPLITSCREENPLAYERS; ++i) { From 11329d5794a95d066a85643f3d36a5e9e517cb0a Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Jul 2024 00:16:19 +0200 Subject: [PATCH 40/51] throw rumble ticker into right place --- src/p_tick.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index 0c99660d8..e4b15feca 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -465,12 +465,6 @@ void P_Ticker(boolean run) } #endif } - - // Apply rumble to local players - if (!demo.playback) - { - P_DeviceRumbleTick(); - } ps_lua_mobjhooks.value.i = 0; ps_checkposition_calls.value.i = 0; @@ -505,6 +499,12 @@ void P_Ticker(boolean run) if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo)) P_PlayerAfterThink(&players[i]); + // Apply rumble to local players + if (!demo.playback) + { + P_DeviceRumbleTick(); + } + PS_START_TIMING(ps_lua_thinkframe_time); LUAh_ThinkFrame(); PS_STOP_TIMING(ps_lua_thinkframe_time); From 4acbca4c8f6362448dae59dce90e27cfade16736 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Jul 2024 00:20:13 +0200 Subject: [PATCH 41/51] do not constantly reset rumble so it can work from lua --- src/p_tick.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/p_tick.c b/src/p_tick.c index e4b15feca..83dd8e993 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -356,7 +356,8 @@ static inline void P_DeviceRumbleTick(void) } } - G_PlayerDeviceRumble(i, low, high, 0); + if (low && high != 0) + G_PlayerDeviceRumble(i, low, high, 57); // hack alert! i just dont want this think constantly resetting the rumble lol } } From 41dc34efe804d45cfab6efbac789d464bd4f9232 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Jul 2024 00:20:26 +0200 Subject: [PATCH 42/51] set default duration to 84 --- src/lua_baselib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 097fa9f33..f5763dc09 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3033,7 +3033,7 @@ static int lib_gPlayerDeviceRumble(lua_State *L) player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); // retrieve player UINT16 low_strength = (UINT16)luaL_checkinteger(L, 2); // low frequency rumble motor strenght UINT16 high_strength = (UINT16)luaL_checkinteger(L, 3); // high frequency rumble motor strenght - UINT32 duration = (UINT32)luaL_optinteger(L, 4, 28); // duration of rumble in ms + UINT32 duration = (UINT32)luaL_optinteger(L, 4, 84); // duration of rumble in ms for (int i = 0; i < MAXSPLITSCREENPLAYERS; ++i) { From 47d3cf3e62cba57bd8d022562e8b232c2e5d15ef Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Jul 2024 00:59:06 +0200 Subject: [PATCH 43/51] change rumble ticker loop a bit --- src/p_tick.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index 83dd8e993..afcfdbb78 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -336,28 +336,33 @@ static inline void P_DeviceRumbleTick(void) if (!P_IsLocalPlayer(player)) continue; - if (!playeringame[i]) + if (!playeringame[i] || player->spectator) continue; - if (player->mo != NULL && !player->exiting) + if (player->exiting) + continue; + + if (player->mo == NULL) + continue; + + if (player->kartstuff[k_spinouttimer]) { - if (player->kartstuff[k_spinouttimer]) - { - low = high = 65536 / 4; - } - else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) - { - low = high = 65536 / 8; - } - else if ((player->kartstuff[k_offroad]) - && P_IsObjectOnGround(player->mo) && player->speed != 0) - { - low = high = 65536 / 64; - } + low = high = 65536 / 4; + } + else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) + { + low = high = 65536 / 8; + } + else if ((player->kartstuff[k_offroad]) + && P_IsObjectOnGround(player->mo) && player->speed != 0) + { + low = high = 65536 / 64; } - if (low && high != 0) - G_PlayerDeviceRumble(i, low, high, 57); // hack alert! i just dont want this think constantly resetting the rumble lol + if (low == 0 && high == 0) + continue; + + G_PlayerDeviceRumble(i, low, high, 57); // hack alert! i just dont want this think constantly resetting the rumble lol } } From c5eb81c26ad19fc3d09cfa82b7bb56205a3e1f72 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Jul 2024 01:02:05 +0200 Subject: [PATCH 44/51] remove redundant check --- src/p_tick.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index afcfdbb78..8a0a95969 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -324,9 +324,6 @@ static inline void P_DeviceRumbleTick(void) return; } - if (paused) - return; - for (i = 0; i <= splitscreen; i++) { player_t *player = &players[displayplayers[i]]; From 4301e0f750922e8b8e2e08a7f1978ba1294726cf Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Jul 2024 01:04:24 +0200 Subject: [PATCH 45/51] make this more explicit --- src/p_tick.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_tick.c b/src/p_tick.c index 8a0a95969..15cd2f1fc 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -319,7 +319,7 @@ static inline void P_DeviceRumbleTick(void) { UINT8 i; - if (cv_rumble[0].value && cv_rumble[1].value && cv_rumble[2].value && cv_rumble[3].value == 0) + if (cv_rumble[0].value == 0 && cv_rumble[1].value == 0 && cv_rumble[2].value == 0 && cv_rumble[3].value == 0) { return; } From 0eda508cf6e2e8c2abed557167ce3c2329fd1306 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Jul 2024 01:43:56 +0200 Subject: [PATCH 46/51] revert some lightlevel stuff in hw_main --- src/hardware/hw_main.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 676c018d1..0800bcb8a 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -500,9 +500,6 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col tint_color.rgba = (colormap != NULL) ? (UINT32)colormap->rgba : GL_DEFAULTMIX; fade_color.rgba = (colormap != NULL) ? (UINT32)colormap->fadergba : GL_DEFAULTFOG; - // Clamp the light level, since it can sometimes go out of the 0-255 range from animations - light_level = CLAMP(SOFTLIGHT(light_level), cv_secbright.value, 255); - // Crappy backup coloring if you can't do shaders if (!HWR_UseShader()) { @@ -540,6 +537,9 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col poly_color.s.blue = (UINT8)blue; } + // Clamp the light level, since it can sometimes go out of the 0-255 range from animations + light_level = CLAMP(SOFTLIGHT(light_level), cv_secbright.value, 255); + // in palette rendering mode, this is not needed since it properly takes the changes to the palette itself if (!HWR_ShouldUsePaletteRendering()) { @@ -3173,7 +3173,7 @@ static void HWR_Subsector(size_t num) false, *rover->bottomheight, *gr_frontsector->lightlist[light].lightlevel, - rover->alpha, rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, + CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, false, gr_frontsector->lightlist[light].extra_colormap); } else @@ -3217,7 +3217,7 @@ static void HWR_Subsector(size_t num) true, *rover->topheight, *gr_frontsector->lightlist[light].lightlevel, - rover->alpha, rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, + CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, false, gr_frontsector->lightlist[light].extra_colormap); } else @@ -3872,7 +3872,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) continue; if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i-1].lightlevel; + lightlevel = min(*list[i-1].lightlevel, 255); colormap = list[i-1].extra_colormap; break; } @@ -3886,7 +3886,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) if (!(list[i].flags & FF_NOSHADE) && (list[i].flags & FF_CUTSPRITES)) { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i].lightlevel; + lightlevel = min(*list[i-1].lightlevel, 255); colormap = list[i].extra_colormap; } @@ -4104,7 +4104,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) extracolormap_t *colormap = sector->extra_colormap; if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = sector->lightlevel; + lightlevel = min(sector->lightlevel, 255); HWR_Lighting(&Surf, lightlevel, colormap); @@ -4203,7 +4203,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) light = R_GetPlaneLight(sector, spr->mobj->z + spr->mobj->height, false); // Always use the light at the top instead of whatever I was doing before if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *sector->lightlist[light].lightlevel; + lightlevel = min(*sector->lightlist[light].lightlevel, 255); if (sector->lightlist[light].extra_colormap) colormap = sector->lightlist[light].extra_colormap; @@ -4211,7 +4211,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) else { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = sector->lightlevel; + lightlevel = min(sector->lightlevel, 255); if (sector->extra_colormap) colormap = sector->extra_colormap; @@ -4405,7 +4405,7 @@ void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, boolean planeinfo->lumpnum = lumpnum; planeinfo->xsub = xsub; - planeinfo->alpha = CLAMP(alpha, 0, 255); + planeinfo->alpha = alpha; planeinfo->FOFSector = FOFSector; planeinfo->blend = blend; planeinfo->fogplane = fogplane; @@ -4425,7 +4425,7 @@ void HWR_AddTransparentPolyobjectFloor(lumpnum_t lumpnum, polyobj_t *polysector, polyplaneinfo->lumpnum = lumpnum; polyplaneinfo->polysector = polysector; - polyplaneinfo->alpha = CLAMP(alpha, 0, 255); + polyplaneinfo->alpha = alpha; polyplaneinfo->FOFSector = FOFSector; polyplaneinfo->blend = blend; polyplaneinfo->planecolormap = planecolormap; From 77a2976d05f02dfcc5124c0b27d815deab9f8b1f Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Jul 2024 23:54:49 +0200 Subject: [PATCH 47/51] smol interp fixes --- src/d_clisrv.c | 16 +++++++++++++++- src/g_game.c | 42 ++++++++++++++++++++++++------------------ src/p_spec.c | 9 +++++++++ src/p_tick.c | 1 - src/p_user.c | 1 - src/y_inter.c | 10 +++++++++- 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 10d46689a..2bc316c64 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -49,6 +49,7 @@ #include "s_sound.h" // sfx_syfail #include "m_perfstats.h" #include "d_main.h" +#include "r_fps.h" #ifdef CLIENT_LOADINGSCREEN // cl loading screen @@ -6109,6 +6110,8 @@ boolean TryRunTics(tic_t realtics) if (ticking) { + boolean tickInterp = true; + // run the count * tics while (neededtic > gametic) { @@ -6119,7 +6122,18 @@ boolean TryRunTics(tic_t realtics) if (update_stats) PS_START_TIMING(ps_tictime); - G_Ticker((gametic % NEWTICRATERATIO) == 0); + boolean run = (gametic % NEWTICRATERATIO) == 0; + + if (run && tickInterp) + { + // Update old view state BEFORE ticking so resetting + // the old interpolation state from game logic works. + R_UpdateViewInterpolation(); + tickInterp = false; // do not update again in sped-up tics + } + + G_Ticker(run); + ExtraDataTicker(); gametic++; consistancy[gametic%TICQUEUE] = Consistancy(); diff --git a/src/g_game.c b/src/g_game.c index 2101d9fb2..20aa54135 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -525,6 +525,8 @@ consvar_t cv_sliptideroll = {"sliptideroll", "Off", CV_SAVE, CV_OnOff, NULL, 0, consvar_t cv_cechotoggle = {"show_cecho", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +static void G_FixCamera(UINT8 view); + #if MAXPLAYERS > 16 #error "please update player_name table using the new value for MAXPLAYERS" #endif @@ -2083,7 +2085,6 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) UINT8 viewd; INT32 *displayplayerp; - camera_t *camerap; INT32 olddisplayplayer; INT32 playersviewable; @@ -2122,29 +2123,14 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) (*displayplayerp) = playernum; if ((*displayplayerp) != olddisplayplayer) { - camerap = &camera[viewnum-1]; - P_ResetCamera(&players[(*displayplayerp)], camerap); - - // Make sure the viewport doesn't interpolate at all into - // its new position -- just snap instantly into place. - R_ResetViewInterpolation(viewnum); + G_FixCamera(viewnum); } if (viewnum > splits) { for (viewd = splits+1; viewd < viewnum; ++viewd) { - displayplayerp = (&displayplayers[viewd-1]); - camerap = &camera[viewd]; - - (*displayplayerp) = G_FindView(0, viewd, onlyactive, false); - - P_ResetCamera(&players[(*displayplayerp)], camerap); - - - // Make sure the viewport doesn't interpolate at all into - // its new position -- just snap instantly into place. - R_ResetViewInterpolation(viewd); + G_FixCamera(viewd); } } @@ -2204,6 +2190,26 @@ void G_ResetViews(void) } } +// +// G_FixCamera +// Reset camera position, angle and interpolation on a view +// after changing state. +// +static void G_FixCamera(UINT8 view) +{ + player_t *player = &players[displayplayers[view - 1]]; + + // The order of displayplayers can change, which would + // invalidate localangle. + localangle[view - 1] = player->cmd.angleturn; + + P_ResetCamera(player, &camera[view - 1]); + + // Make sure the viewport doesn't interpolate at all into + // its new position -- just snap instantly into place. + R_ResetViewInterpolation(view); +} + // // G_Ticker // Make ticcmd_ts for the players. diff --git a/src/p_spec.c b/src/p_spec.c index 370afc056..87036a892 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2483,6 +2483,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 422: // Cut away to another view { mobj_t *altview; + INT32 i; if (!mo || !mo->player) // only players have views return; @@ -2497,6 +2498,14 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) P_SetTarget(&mo->player->awayviewmobj, altview); mo->player->awayviewtics = P_AproxDistance(line->dx, line->dy)>>FRACBITS; + for (i = 0; i <= splitscreen; i++) + { + if (displayplayers[i] == (mo->player - players)) + { + R_ResetViewInterpolation(i + 1); + } + } + if (line->flags & ML_NOCLIMB) // lets you specify a vertical angle { INT32 aim; diff --git a/src/p_tick.c b/src/p_tick.c index 15cd2f1fc..0dc34b487 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -642,7 +642,6 @@ void P_Ticker(boolean run) if (run) { R_UpdateLevelInterpolators(); - R_UpdateViewInterpolation(); // Hack: ensure newview is assigned every tic. // Ensures view interpolation is T-1 to T in poor network conditions diff --git a/src/p_user.c b/src/p_user.c index 118c1d06d..d61044ba7 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3965,7 +3965,6 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall { P_MoveChaseCamera(player, thiscam, false); R_ResetViewInterpolation(num + 1); - R_ResetViewInterpolation(num + 1); } return (x == thiscam->x && y == thiscam->y && z == thiscam->z && angle == thiscam->aiming); diff --git a/src/y_inter.c b/src/y_inter.c index 5d292f36c..8527ff799 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -728,8 +728,16 @@ void Y_Ticker(void) return; } - if (intertic < TICRATE || intertic & 1 || endtic != -1) + if (intertic < TICRATE || endtic != -1) + { return; + } + + if (data.match.rankingsmode && intertic & 1) + { + memset(data.match.jitter, 0, sizeof (data.match.jitter)); + return; + } if (intertype == int_race || intertype == int_match) { From 3f4afb604afab6aaad74a476d3767b471488446b Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 31 Jul 2024 00:28:29 +0200 Subject: [PATCH 48/51] check if displayplayer skincolor is availible before returning it --- src/g_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/g_input.c b/src/g_input.c index 105e84532..f7057d4e4 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -889,7 +889,7 @@ static INT32 G_GetDeviceForPlayer(INT32 player) static UINT16 G_GetSkinColor(INT32 player) { - if (gamestate == GS_LEVEL) + if (players[displayplayers[player]].skincolor && gamestate == GS_LEVEL) return players[displayplayers[player]].skincolor; switch (player) From 3a56bf2bb59a5501cfca18dfaf2b4a305d67c9fd Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 3 Aug 2024 17:43:47 +0200 Subject: [PATCH 49/51] fix up ogl sprite drawers, fix floor clip fix remove ty and reduntand hires stuff --- src/hardware/hw_glob.h | 2 +- src/hardware/hw_main.c | 49 +++++++++++++----------------------------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 542a99b33..4a8a5dd9c 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -28,7 +28,7 @@ typedef struct gr_vissprite_s float x1, x2; float z1, z2; float gz, gzt; - float tz, ty; + float tz; float scale; float spritexscale, spriteyscale; float spritexoffset, spriteyoffset; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 0800bcb8a..3b65f1e96 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3711,12 +3711,10 @@ static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts static void HWR_SplitSprite(gr_vissprite_t *spr) { - float this_scale = 1.0f; FOutVector wallVerts[4]; FOutVector baseWallVerts[4]; // This is what the verts should end up as GLPatch_t *gpatch; FSurfaceInfo Surf; - const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->flags & SF_HIRES); extracolormap_t *colormap; FUINT lightlevel; FBITFIELD blend = 0; @@ -3736,11 +3734,6 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) fixed_t v1x, v1y, v2x, v2y; INT32 shader = SHADER_NONE; - this_scale = FIXED_TO_FLOAT(spr->mobj->scale); - - if (hires) - this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->highresscale); - gpatch = spr->gpatch; //W_CachePatchNum(spr->patchlumpnum, PU_CACHE); // cache the patch in the graphics card memory @@ -3801,7 +3794,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) // push it toward the camera to mitigate floor-clipping sprites { - float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->ty - gr_viewz)*(spr->ty - gr_viewz)); + float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; for (i = 0; i < 4; i++) { @@ -3990,7 +3983,6 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) // -----------------+ static void HWR_DrawSprite(gr_vissprite_t *spr) { - float this_scale = 1.0f; FOutVector wallVerts[4]; GLPatch_t *gpatch; // sprite patch converted to hardware FSurfaceInfo Surf; @@ -4009,12 +4001,6 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) return; } - const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->flags & SF_HIRES); - if (spr->mobj) - this_scale = FIXED_TO_FLOAT(spr->mobj->scale); - if (hires) - this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->highresscale); - // cache sprite graphics //12/12/99: Hurdler: // OK, I don't change anything for MD2 support because I want to be @@ -4083,7 +4069,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) // push it toward the camera to mitigate floor-clipping sprites { - float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->ty - gr_viewz)*(spr->ty - gr_viewz)); + float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; size_t i; for (i = 0; i < 4; i++) @@ -4169,8 +4155,8 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) // 0--1 wallVerts[0].x = wallVerts[3].x = spr->x1; wallVerts[2].x = wallVerts[1].x = spr->x2; - wallVerts[2].y = wallVerts[3].y = spr->ty; - wallVerts[0].y = wallVerts[1].y = spr->ty - gpatch->height; + wallVerts[2].y = wallVerts[3].y = spr->gzt; + wallVerts[0].y = wallVerts[1].y = spr->gz; // make a wall polygon (with 2 triangles), using the floor/ceiling heights, // and the 2d map coords of start/end vertices @@ -4767,7 +4753,7 @@ void HWR_ProjectSprite(mobj_t *thing) float x1, x2; float z1, z2; float rightsin, rightcos; - float this_scale, this_xscale, this_yscale; + float this_scale; float spritexscale, spriteyscale; float gz, gzt; spritedef_t *sprdef; @@ -5001,20 +4987,20 @@ void HWR_ProjectSprite(mobj_t *thing) rightcos = FIXED_TO_FLOAT(FINECOSINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); } - this_xscale = spritexscale * this_scale; - this_yscale = spriteyscale * this_scale; + spritexscale *= this_scale; + spriteyscale *= this_scale; flip = !flip != !hflip; if (flip) { - x1 = (FIXED_TO_FLOAT(spr_width - spr_offset) * this_xscale); - x2 = (FIXED_TO_FLOAT(spr_offset) * this_xscale); + x1 = (FIXED_TO_FLOAT(spr_width - spr_offset) * spritexscale); + x2 = (FIXED_TO_FLOAT(spr_offset) * spritexscale); } else { - x1 = (FIXED_TO_FLOAT(spr_offset) * this_xscale); - x2 = (FIXED_TO_FLOAT(spr_width - spr_offset) * this_xscale); + x1 = (FIXED_TO_FLOAT(spr_offset) * spritexscale); + x2 = (FIXED_TO_FLOAT(spr_width - spr_offset) * spritexscale); } z1 = tr_y + x1 * rightsin; @@ -5022,16 +5008,15 @@ void HWR_ProjectSprite(mobj_t *thing) x1 = tr_x + x1 * rightcos; x2 = tr_x - x2 * rightcos; - if (thing->eflags & MFE_VERTICALFLIP) { - gz = FIXED_TO_FLOAT(interp.z + thing->height) - (FIXED_TO_FLOAT(spr_topoffset) * this_yscale); - gzt = gz + (FIXED_TO_FLOAT(spr_height) * this_yscale); + gz = FIXED_TO_FLOAT(interp.z + thing->height) - (FIXED_TO_FLOAT(spr_topoffset) * spriteyscale); + gzt = gz + (FIXED_TO_FLOAT(spr_height) * spriteyscale); } else { - gzt = FIXED_TO_FLOAT(interp.z) + (FIXED_TO_FLOAT(spr_topoffset) * this_yscale); - gz = gzt - (FIXED_TO_FLOAT(spr_height) * this_yscale); + gzt = FIXED_TO_FLOAT(interp.z) + (FIXED_TO_FLOAT(spr_topoffset) * spriteyscale); + gz = gzt - (FIXED_TO_FLOAT(spr_height) * spriteyscale); } if (thing->subsector->sector->cullheight) @@ -5114,8 +5099,6 @@ void HWR_ProjectSprite(mobj_t *thing) } // set top/bottom coords - vis->ty = gzt; - vis->gzt = gzt; vis->gz = gz; @@ -5244,8 +5227,6 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) #endif // set top/bottom coords - vis->ty = FIXED_TO_FLOAT(interp.z + spritecachedinfo[lumpoff].topoffset); - vis->gzt = FIXED_TO_FLOAT(interp.z + spritecachedinfo[lumpoff].topoffset); vis->gz = vis->gzt - FIXED_TO_FLOAT(spritecachedinfo[lumpoff].height); From 5e2b50c49e263ff2e73ee573c1eab3da86ffa660 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 31 Jul 2024 06:05:49 +0200 Subject: [PATCH 50/51] add very light rumble to brakedrift --- src/p_tick.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/p_tick.c b/src/p_tick.c index 0dc34b487..5acb8b5fb 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -355,6 +355,11 @@ static inline void P_DeviceRumbleTick(void) { low = high = 65536 / 64; } + else if (player->kartstuff[k_brakedrift]) + { + low = 0; + high = 65536 / 256; + } if (low == 0 && high == 0) continue; From 5c3a2bf5be34c8e0880fc0b5f6f39e7f25cbd86b Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 3 Aug 2024 07:31:12 +0200 Subject: [PATCH 51/51] make inline macros for pointtodist --- src/r_main.c | 11 ----------- src/r_main.h | 6 ++++-- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 764d34403..fb3ca1c1c 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -440,11 +440,6 @@ angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) 0; } -fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1) -{ - return FixedHypot(px1 - px2, py1 - py2); -} - angle_t R_PlayerSliptideAngle(player_t *player) { mobj_t *mo; @@ -489,12 +484,6 @@ angle_t R_PlayerSliptideAngle(player_t *player) return FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), mo->player->sliproll*(mo->player->sliptidemem)); } -// Little extra utility. Works in the same way as R_PointToAngle2 -fixed_t R_PointToDist(fixed_t x, fixed_t y) -{ - return R_PointToDist2(viewx, viewy, x, y); -} - INT32 R_GetHudUncap(void) { return cv_uncappedhud.value ? rendertimefrac & FRACMASK : 0; diff --git a/src/r_main.h b/src/r_main.h index 6c59d9961..058a30c80 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -73,14 +73,16 @@ INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line); angle_t R_PointToAngle(fixed_t x, fixed_t y); angle_t R_PointToAngle64(INT64 x, INT64 y); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); -fixed_t R_PointToDist(fixed_t x, fixed_t y); -fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PlayerSliptideAngle(player_t *player); fixed_t R_ScaleFromGlobalAngle(angle_t visangle); subsector_t *R_PointInSubsector(fixed_t x, fixed_t y); subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y); +#define R_PointToDist(x, y) R_PointToDist2(viewx, viewy, x, y) +#define R_PointToDist2(px2, py2, px1, py1) FixedHypot(px1 - px2, py1 - py2) + + boolean R_DoCulling(line_t *cullheight, line_t *viewcullheight, fixed_t vz, fixed_t bottomh, fixed_t toph); void R_GetRenderBlockMapDimensions(fixed_t drawdist, INT32 *xl, INT32 *xh, INT32 *yl, INT32 *yh);