From 827a2f75eec3fcf886203dcfb2a4d282fe13c2a3 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 22 Oct 2022 20:53:07 +1000 Subject: [PATCH] Cache the playercount instead of calculating it many times --- src/game/playermgr.c | 4 ++++ src/include/constants.h | 2 +- src/include/types.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/game/playermgr.c b/src/game/playermgr.c index f3b782358..a21801f09 100644 --- a/src/game/playermgr.c +++ b/src/game/playermgr.c @@ -30,6 +30,7 @@ void playermgrReset(void) g_Vars.players[1] = NULL; g_Vars.players[2] = NULL; g_Vars.players[3] = NULL; + g_Vars.playercount = 0; g_Vars.currentplayer = NULL; g_Vars.currentplayerindex = 0; g_Vars.currentplayerstats = NULL; @@ -49,6 +50,7 @@ void playermgrAllocatePlayers(s32 count) g_Vars.players[1] = NULL; g_Vars.players[2] = NULL; g_Vars.players[3] = NULL; + g_Vars.playercount = 0; if (count > 0) { s32 i; @@ -67,6 +69,7 @@ void playermgrAllocatePlayers(s32 count) g_Vars.coop = NULL; g_Vars.anti = g_Vars.players[g_Vars.antiplayernum]; } + } else { playermgrAllocatePlayer(0); setCurrentPlayerNum(0); @@ -212,6 +215,7 @@ void playermgrAllocatePlayer(s32 index) s32 i; g_Vars.players[index] = mempAlloc(sizeof(struct player), MEMPOOL_STAGE); + g_Vars.playercount++; g_Vars.players[index]->cameramode = CAMERAMODE_DEFAULT; g_Vars.players[index]->memcampos.x = 0; diff --git a/src/include/constants.h b/src/include/constants.h index 94f50ba78..95e8aba09 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -35,7 +35,7 @@ #define LINEHEIGHT (VERSION == VERSION_JPN_FINAL ? 14 : 11) #define MIXCOLOUR(dialog, property) dialog->transitionfrac < 0.0f ? g_MenuColourPalettes[dialog->type].property : colourBlend(g_MenuColourPalettes[dialog->type2].property, g_MenuColourPalettes[dialog->type].property, dialog->colourweight) #define MPCHR(index) ((index) < 4 ? &g_PlayerConfigsArray[index].base : &g_BotConfigsArray[(index) - 4].base) -#define PLAYERCOUNT() ((g_Vars.players[0] ? 1 : 0) + (g_Vars.players[1] ? 1 : 0) + (g_Vars.players[2] ? 1 : 0) + (g_Vars.players[3] ? 1 : 0)) +#define PLAYERCOUNT() g_Vars.playercount #define RANDOMFRAC() (random() * (1.0f / U32_MAX)) #define SECSTOTIME240(secs) (secs * 240) #define SECSTOTIME60(secs) (secs * 60) diff --git a/src/include/types.h b/src/include/types.h index 53fd59ef4..20d29e24e 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -235,6 +235,7 @@ struct g_vars { // 00f0 = One bit per pak. Does something with the pak if counter expired. // 0f00 = One bit per pak. Does something with the pak if counter expired (likely opposite of the above). /*0x4e4*/ u16 unk0004e4; + u8 playercount; /*0x4e8*/ u32 unk0004e8; /*0x4ec*/ u32 unk0004ec;