Use more timeslots for backgrounded props and disable timeslot redistribution

This commit is contained in:
Ryan Dwyer 2022-11-09 17:11:01 +10:00
parent 046270c065
commit c65678ea2e
5 changed files with 38 additions and 176 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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]

View File

@ -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;