From c65678ea2ee5b06911d748c709e6cfbd9e578a40 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 9 Nov 2022 17:11:01 +1000 Subject: [PATCH] Use more timeslots for backgrounded props and disable timeslot redistribution --- src/game/lv.c | 35 +++++++++ src/game/prop.c | 169 ---------------------------------------- src/game/varsreset.c | 7 +- src/include/constants.h | 1 + src/include/types.h | 2 +- 5 files changed, 38 insertions(+), 176 deletions(-) diff --git a/src/game/lv.c b/src/game/lv.c index 611b28106..a95fb69e4 100644 --- a/src/game/lv.c +++ b/src/game/lv.c @@ -898,6 +898,28 @@ Gfx *lvPrintRateGraph(Gfx *gdl) return gdl; } +void lvGetNumPropsByActiveState(s32 *foreground, s32 *background) +{ + struct prop *prop = g_Vars.activeprops; + + *foreground = 0; + *background = 0; + + while (prop) { + if (prop->backgrounded) { + *background += 1; + } else { + *foreground += 1; + } + + if (prop == g_Vars.activepropstail) { + break; + } + + prop = prop->next; + } +} + s32 lvGetNumFreeProps(void) { s32 count = 0; @@ -971,6 +993,19 @@ Gfx *lvPrintRateText(Gfx *gdl) sprintf(buffer, "est free %d KB\n", g_LvEstimatedFreeBytes / 1024); gdl = textRender(gdl, &x, &y, buffer, g_CharsHandelGothicXs, g_FontHandelGothicXs, 0x00ff00a0, 0x000000a0, viGetWidth(), viGetHeight(), 0, 0); + { + s32 foreground; + s32 background; + + lvGetNumPropsByActiveState(&foreground, &background); + + sprintf(buffer, "props fg %d\n", foreground); + gdl = textRender(gdl, &x, &y, buffer, g_CharsHandelGothicXs, g_FontHandelGothicXs, 0x00ff00a0, 0x000000a0, viGetWidth(), viGetHeight(), 0, 0); + + sprintf(buffer, "props bg %d\n", background); + gdl = textRender(gdl, &x, &y, buffer, g_CharsHandelGothicXs, g_FontHandelGothicXs, 0x00ff00a0, 0x000000a0, viGetWidth(), viGetHeight(), 0, 0); + } + sprintf(buffer, "props free %d\n", lvGetNumFreeProps()); gdl = textRender(gdl, &x, &y, buffer, g_CharsHandelGothicXs, g_FontHandelGothicXs, 0x00ff00a0, 0x000000a0, viGetWidth(), viGetHeight(), 0, 0); } diff --git a/src/game/prop.c b/src/game/prop.c index a582d371a..7fc6a943a 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -1842,20 +1842,6 @@ void propsTickPlayer(bool islastplayer) prop->forceonetick = false; } else if (prop->forcetick) { i++; - } else { - rooms = prop->rooms; - - while (*rooms != -1) { - if (g_Rooms[*rooms].flags & ROOMFLAG_STANDBY) { - break; - } - - rooms++; - } - - if (*rooms != -1) { - i++; - } } } } @@ -2027,161 +2013,6 @@ void propsTickPlayer(bool islastplayer) prop = next; } - // If this is the first time propsTickPlayer is being called on this frame, - // and we've completed a full cycle of the propstates, redistribute them. - // For each combination of background/foreground and chr/nonchr, take the - // propstates with the highest quantity of these props and move some to the - // lowest quantity propstate. - if (g_Vars.currentplayerindex == 0 && g_Vars.runstateindex == 0) { - // Background non-chrs - leastindex = g_Vars.numpropstates; - mostindex = g_Vars.numpropstates; - least = 0x7fff; - most = 0; - - for (i = 0; i < g_Vars.numpropstates; i++) { - if (g_Vars.propstates[i].propcount < least) { - least = g_Vars.propstates[i].propcount; - leastindex = i; - } - - if (g_Vars.propstates[i].propcount > most) { - most = g_Vars.propstates[i].propcount; - mostindex = i; - } - } - - i = (g_Vars.propstates[mostindex].propcount - g_Vars.propstates[leastindex].propcount) >> 1; - - if (i != 0) { - prop = g_Vars.activeprops; - - while (prop != g_Vars.pausedprops) { - if (prop->propstateindex == mostindex && prop->backgrounded == 1 && prop->type != PROPTYPE_CHR) { - prop->propstateindex = leastindex; - i--; - - if (i == 0) { - break; - } - } - - prop = prop->next; - } - } - - // Foreground non-chrs - leastindex = g_Vars.numpropstates; - mostindex = g_Vars.numpropstates; - least = 0x7fff; - most = 0; - - for (i = 0; i < g_Vars.numpropstates; i++) { - if (g_Vars.propstates[i].foregroundpropcount < least) { - least = g_Vars.propstates[i].foregroundpropcount; - leastindex = i; - } - - if (g_Vars.propstates[i].foregroundpropcount > most) { - most = g_Vars.propstates[i].foregroundpropcount; - mostindex = i; - } - } - - i = (g_Vars.propstates[mostindex].foregroundpropcount - g_Vars.propstates[leastindex].foregroundpropcount) >> 1; - - if (i != 0) { - prop = g_Vars.activeprops; - - while (prop != g_Vars.pausedprops) { - if (prop->propstateindex == mostindex && prop->backgrounded == 0 && prop->type != PROPTYPE_CHR) { - prop->propstateindex = leastindex; - i--; - - if (i == 0) { - break; - } - } - - prop = prop->next; - } - } - - // Background chrs - leastindex = g_Vars.numpropstates; - mostindex = g_Vars.numpropstates; - least = 0x7fff; - most = 0; - - for (i = 0; i < g_Vars.numpropstates; i++) { - if (g_Vars.propstates[i].chrpropcount < least) { - least = g_Vars.propstates[i].chrpropcount; - leastindex = i; - } - - if (g_Vars.propstates[i].chrpropcount > most) { - most = g_Vars.propstates[i].chrpropcount; - mostindex = i; - } - } - - i = (g_Vars.propstates[mostindex].chrpropcount - g_Vars.propstates[leastindex].chrpropcount) >> 1; - - if (i != 0) { - prop = g_Vars.activeprops; - - while (prop != g_Vars.pausedprops) { - if (prop->propstateindex == mostindex && prop->backgrounded == 1 && prop->type == PROPTYPE_CHR) { - prop->propstateindex = leastindex; - i--; - - if (i == 0) { - break; - } - } - - prop = prop->next; - } - } - - // Foreground chrs - leastindex = g_Vars.numpropstates; - mostindex = g_Vars.numpropstates; - least = 0x7fff; - most = 0; - - for (i = 0; i < g_Vars.numpropstates; i++) { - if (g_Vars.propstates[i].foregroundchrpropcount < least) { - least = g_Vars.propstates[i].foregroundchrpropcount; - leastindex = i; - } - - if (g_Vars.propstates[i].foregroundchrpropcount > most) { - most = g_Vars.propstates[i].foregroundchrpropcount; - mostindex = i; - } - } - - i = (g_Vars.propstates[mostindex].foregroundchrpropcount - g_Vars.propstates[leastindex].foregroundchrpropcount) >> 1; - - if (i != 0) { - prop = g_Vars.activeprops; - - while (prop != g_Vars.pausedprops) { - if (prop->propstateindex == mostindex && prop->backgrounded == 0 && prop->type == PROPTYPE_CHR) { - prop->propstateindex = leastindex; - i--; - - if (i == 0) { - break; - } - } - - prop = prop->next; - } - } - } - g_Vars.lvupdate240 = savedlvupdate240; g_Vars.lvupdate60 = savedlvupdate60; g_Vars.lvupdate60f = savedlvupdate60f; diff --git a/src/game/varsreset.c b/src/game/varsreset.c index bb8ff91cb..6f02d2bae 100644 --- a/src/game/varsreset.c +++ b/src/game/varsreset.c @@ -36,12 +36,7 @@ void varsReset(void) g_Vars.props[i].next = NULL; - if (g_Vars.normmplayerisrunning) { - g_Vars.numpropstates = 4; - } else { - g_Vars.numpropstates = 7; - } - + g_Vars.numpropstates = MIN(g_NumBots, ARRAYCOUNT(g_Vars.propstates)); g_Vars.allocstateindex = 0; g_Vars.runstateindex = 0; g_Vars.alwaystick = 0; diff --git a/src/include/constants.h b/src/include/constants.h index 10d13fe51..237a3d9fb 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -33,6 +33,7 @@ #define IS4MB() (g_Is4Mb == true) #define IS8MB() (g_Is4Mb != true) #define LINEHEIGHT (VERSION == VERSION_JPN_FINAL ? 14 : 11) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #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) &g_MpChrs[index] diff --git a/src/include/types.h b/src/include/types.h index c68fb6bf0..ac471ed6b 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -174,7 +174,7 @@ struct g_vars { /*0x35b*/ u8 alwaystick; /*0x35c*/ u16 updateframe; /*0x35e*/ u16 prevupdateframe; - /*0x360*/ struct propstate propstates[7]; + /*0x360*/ struct propstate propstates[150]; /*0x424*/ struct chrdata *chrdata; /*0x428*/ struct truckobj *truck; /*0x42c*/ struct heliobj *heli;