From 789c4669f18c98e432c72e062d5b523802286dce Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 2 Oct 2023 14:59:30 +1100 Subject: [PATCH] - SW: Initial setup to convert `PlayerArray` array to array of `SWPlayer` pointers. --- source/games/sw/src/game.cpp | 26 ++++++++++++++++---------- source/games/sw/src/game.h | 4 ++-- source/games/sw/src/ninja.cpp | 4 ++-- source/games/sw/src/player.cpp | 23 ++++++++++++----------- source/games/sw/src/save.cpp | 2 +- source/games/sw/src/sounds.cpp | 4 ++-- source/games/sw/src/text.cpp | 2 +- 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index 1fb2dded8..191163d76 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -118,16 +118,16 @@ void markgcroots() GC::MarkArray(GenericQueue, MAX_GENERIC_QUEUE); GC::MarkArray(LoWangsQueue, MAX_LOWANGS_QUEUE); GC::MarkArray(BossSpriteNum, 3); - for (auto& pl : PlayerArray) + for (auto pl : PlayerArray) { - GC::Mark(pl.actor); - GC::Mark(pl.lowActor); - GC::Mark(pl.highActor); - GC::Mark(pl.remoteActor); - GC::Mark(pl.PlayerUnderActor); - GC::Mark(pl.KillerActor); - GC::Mark(pl.HitBy); - GC::Mark(pl.last_camera_act); + GC::Mark(pl->actor); + GC::Mark(pl->lowActor); + GC::Mark(pl->highActor); + GC::Mark(pl->remoteActor); + GC::Mark(pl->PlayerUnderActor); + GC::Mark(pl->KillerActor); + GC::Mark(pl->HitBy); + GC::Mark(pl->last_camera_act); } for (auto& so : SectorObject) { @@ -250,6 +250,13 @@ void GameInterface::SetupSpecialTextures(TilesetBuildInfo& info) void GameInterface::app_init() { + // Initialise player array. + for (unsigned i = 0; i < (MAX_SW_PLAYERS_REG+1); i++) + { + PlayerArray[i] = new SWPlayer; + *PlayerArray[i] = {}; + } + // these are frequently checked markers. FAFPlaceMirrorPic[0] = tileGetTextureID(FAF_PLACE_MIRROR_PIC); FAFPlaceMirrorPic[1] = tileGetTextureID(FAF_PLACE_MIRROR_PIC + 1); @@ -293,7 +300,6 @@ void GameInterface::app_init() defineSky(nullptr, 1, nullptr); memset(Track, 0, sizeof(Track)); - memset(PlayerArray, 0, sizeof(PlayerArray)); for (int i = 0; i < MAX_SW_PLAYERS; i++) INITLIST(&(getPlayer(i)->PanelSpriteList)); diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index c95df8440..9e3b30103 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1859,11 +1859,11 @@ struct SWPlayer final : public CorePlayer } }; -extern SWPlayer PlayerArray[MAX_SW_PLAYERS_REG+1]; +extern SWPlayer* PlayerArray[MAX_SW_PLAYERS_REG+1]; inline SWPlayer* getPlayer(int index) { - return &PlayerArray[index]; + return PlayerArray[index]; } diff --git a/source/games/sw/src/ninja.cpp b/source/games/sw/src/ninja.cpp index 87f0430ad..c28882ace 100644 --- a/source/games/sw/src/ninja.cpp +++ b/source/games/sw/src/ninja.cpp @@ -2321,7 +2321,7 @@ extern ACTOR_ACTION_SET PlayerNinjaActionSet; void InitPlayerSprite(SWPlayer* pp, const DVector3& spawnpos, const DAngle startang) { - int pnum = int(pp - PlayerArray); + int pnum = int(pp - *PlayerArray); double fz,cz; extern bool NewGame; @@ -2408,7 +2408,7 @@ void SpawnPlayerUnderSprite(SWPlayer* pp) { DSWActor* plActor = pp->GetActor(); - int pnum = int(pp - PlayerArray); + int pnum = int(pp - *PlayerArray); pp->PlayerUnderActor = SpawnActor(STAT_PLAYER_UNDER0 + pnum, NINJA_RUN_R0, nullptr, pp->cursector, pp->GetActor()->getPosWithOffsetZ(), pp->GetActor()->spr.Angles.Yaw); diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index d5adfcf58..2bc7f7545 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -119,7 +119,7 @@ extern bool DebugOperate; int ChopTics; -SWPlayer PlayerArray[MAX_SW_PLAYERS_REG + 1]; +SWPlayer* PlayerArray[MAX_SW_PLAYERS_REG + 1]; // These are a bunch of kens variables for the player @@ -1325,7 +1325,7 @@ void DoPlayerWarpTeleporter(SWPlayer* pp) TRAVERSE_CONNECT(pnum) { - if (pnum != pp - PlayerArray) + if (pnum != pp - *PlayerArray) { SWPlayer* npp = getPlayer(pnum); @@ -5458,7 +5458,7 @@ void DoPlayerDeathMessage(SWPlayer* pp, SWPlayer* killer) int pnum; bool SEND_OK = false; - killer->KilledPlayer[pp-PlayerArray]++; + killer->KilledPlayer[pp - *PlayerArray]++; if (pp == killer && pp == getPlayer(myconnectindex)) { @@ -6867,14 +6867,15 @@ void domovethings(const ticcmd_t* playercmds) void InitAllPlayers(void) { SWPlayer* pp; - SWPlayer* pfirst = PlayerArray; - int i; + SWPlayer* pfirst = getPlayer(0); extern bool NewGame; //int fz,cz; // Initialize all [MAX_SW_PLAYERS] arrays here! - for (pp = PlayerArray; pp < getPlayer(MAX_SW_PLAYERS); pp++) + for (int i = 0; i < MAX_SW_PLAYERS; i++) { + auto pp = getPlayer(i); + pp->cursector = pfirst->cursector; // set like this so that player can trigger something on start of the level pp->lastcursector = pfirst->cursector+1; @@ -6897,10 +6898,10 @@ void InitAllPlayers(void) if (NewGame) { - for (i = 0; i < MAX_INVENTORY; i++) + for (unsigned j = 0; j < MAX_INVENTORY; j++) { - pp->InventoryAmount[i] = 0; - pp->InventoryPercent[i] = 0; + pp->InventoryAmount[j] = 0; + pp->InventoryPercent[j] = 0; } } @@ -6967,7 +6968,7 @@ bool SpawnPositionUsed[MAX_SW_PLAYERS_REG+1]; void PlayerSpawnPosition(SWPlayer* pp) { - short pnum = short(pp - PlayerArray); + short pnum = short(pp - *PlayerArray); short pos_num = pnum; int i; DSWActor* spawn_sprite = nullptr; @@ -7079,7 +7080,7 @@ void InitMultiPlayerInfo(const DVector3& spawnpos, const DAngle startang) // set up the zero starting positions - its not saved in the map as a ST1 sprite // like the others - pp = PlayerArray; + pp = getPlayer(0); for (stat = 0; stat < SIZ(MultiStatList); stat++) { if (gNet.MultiGameType != MULTI_GAME_NONE) diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index 55bb50fdd..192fea4e5 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -419,7 +419,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, REMOTE_CONTROL& w, FSerializer& Serialize(FSerializer& arc, const char* keyname, SWPlayer*& w, SWPlayer** def) { - int ndx = w ? int(w - PlayerArray) : -1; + int ndx = w ? int(w - *PlayerArray) : -1; arc(keyname, ndx); w = ndx == -1 ? nullptr : getPlayer(ndx); return arc; diff --git a/source/games/sw/src/sounds.cpp b/source/games/sw/src/sounds.cpp index 01f0602f8..a36eec4a6 100644 --- a/source/games/sw/src/sounds.cpp +++ b/source/games/sw/src/sounds.cpp @@ -379,7 +379,7 @@ public: int SoundSourceIndex(FSoundChan* chan) override { - if (chan->SourceType == SOURCE_Player) return int((SWPlayer*)(chan->Source) - PlayerArray); + if (chan->SourceType == SOURCE_Player) return int((SWPlayer*)(chan->Source) - *PlayerArray); return 0; } @@ -722,7 +722,7 @@ int _PlayerSound(int num, SWPlayer* pp) if (Prediction) return 0; - if (pp < PlayerArray || pp >= getPlayer(MAX_SW_PLAYERS)) + if (pp < *PlayerArray || pp >= getPlayer(MAX_SW_PLAYERS)) { return 0; } diff --git a/source/games/sw/src/text.cpp b/source/games/sw/src/text.cpp index 3dc2bd6a6..3b88f8839 100644 --- a/source/games/sw/src/text.cpp +++ b/source/games/sw/src/text.cpp @@ -47,7 +47,7 @@ BEGIN_SW_NS void PutStringInfo(SWPlayer* pp, const char *string) { - if (pp-PlayerArray == myconnectindex) + if ((pp - *PlayerArray) == myconnectindex) Printf(PRINT_MEDIUM|PRINT_NOTIFY, "%s\n", string); // Put it in the console too }