mirror of
https://gitlab.com/ryandwyer/perfect-dark
synced 2026-07-03 11:50:05 -04:00
Use dynamic allocation for MP rankings
This commit is contained in:
+2
-3
@@ -2968,12 +2968,11 @@ void botTickUnpaused(struct chrdata *chr)
|
||||
}
|
||||
} else if (aibot->config->type == BOTTYPE_JUDGE) {
|
||||
// Attack the winning player
|
||||
struct ranking rankings[MAX_MPCHRS];
|
||||
s32 count = mpGetPlayerRankings(rankings);
|
||||
s32 count = mpGetPlayerRankings(g_MpRankings);
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
s32 playernum = rankings[i].chrnum;
|
||||
s32 playernum = g_MpRankings[i].chrnum;
|
||||
struct chrdata *otherchr = g_MpChrs[playernum].chr;
|
||||
|
||||
if (otherchr != chr && !chrIsDead(otherchr)) {
|
||||
|
||||
@@ -753,10 +753,9 @@ bool challengeIsCompleteForEndscreen(void)
|
||||
setCurrentPlayerNum(prevplayernum);
|
||||
|
||||
if (!aborted) {
|
||||
struct ranking rankings[12];
|
||||
mpGetTeamRankings(rankings);
|
||||
mpGetTeamRankings(g_MpRankings);
|
||||
|
||||
if (rankings[0].teamnum == 0) {
|
||||
if (g_MpRankings[0].teamnum == 0) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-6
@@ -1695,22 +1695,20 @@ void lvTick(void)
|
||||
}
|
||||
|
||||
if (g_MpScoreLimit > 0) {
|
||||
struct ranking rankings[MAX_MPCHRS];
|
||||
s32 count = mpGetPlayerRankings(rankings);
|
||||
s32 count = mpGetPlayerRankings(g_MpRankings);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
if (rankings[i].score >= g_MpScoreLimit) {
|
||||
if (g_MpRankings[i].score >= g_MpScoreLimit) {
|
||||
g_NumReasonsToEndMpMatch++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (g_MpTeamScoreLimit > 0) {
|
||||
struct ranking rankings[MAX_MPCHRS];
|
||||
s32 count = mpGetTeamRankings(rankings);
|
||||
s32 count = mpGetTeamRankings(g_MpRankings);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
if (rankings[i].score >= g_MpTeamScoreLimit) {
|
||||
if (g_MpRankings[i].score >= g_MpTeamScoreLimit) {
|
||||
g_NumReasonsToEndMpMatch++;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -3289,7 +3289,6 @@ Gfx *menuitem07Render(Gfx *gdl)
|
||||
|
||||
Gfx *menuitemRankingRender(Gfx *gdl, struct menurendercontext *context)
|
||||
{
|
||||
struct ranking rankings[MAX_MPCHRS];
|
||||
s32 numrows;
|
||||
u32 textcolour;
|
||||
s32 x;
|
||||
@@ -3306,9 +3305,9 @@ Gfx *menuitemRankingRender(Gfx *gdl, struct menurendercontext *context)
|
||||
|
||||
if (context->item->param2 == 1) {
|
||||
team = true;
|
||||
numrows = mpGetTeamRankings(rankings);
|
||||
numrows = mpGetTeamRankings(g_MpRankings);
|
||||
} else {
|
||||
numrows = mpGetPlayerRankings(rankings);
|
||||
numrows = mpGetPlayerRankings(g_MpRankings);
|
||||
}
|
||||
|
||||
gdl = text0f153628(gdl);
|
||||
@@ -3456,7 +3455,7 @@ Gfx *menuitemRankingRender(Gfx *gdl, struct menurendercontext *context)
|
||||
gdl = text0f153628(gdl);
|
||||
|
||||
for (i = 0; i < numrows; i++) {
|
||||
struct ranking *ranking = &rankings[i];
|
||||
struct ranking *ranking = &g_MpRankings[i];
|
||||
u32 weight = 0;
|
||||
char valuebuffer[8];
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
u32 var800ac534;
|
||||
s32 g_MpNumChrs;
|
||||
struct mpchr *g_MpChrs;
|
||||
struct ranking *g_MpRankings;
|
||||
struct mpbotconfig g_BotConfigsArray[MAX_BOTS];
|
||||
u8 g_MpSimulantDifficultiesPerNumPlayers[8][4];
|
||||
struct mpplayerconfig g_PlayerConfigsArray[6];
|
||||
@@ -188,6 +189,7 @@ void mpReset(void)
|
||||
}
|
||||
|
||||
g_MpChrs = NULL;
|
||||
g_MpRankings = NULL;
|
||||
|
||||
g_MpSetup.paused = false;
|
||||
|
||||
@@ -2113,20 +2115,9 @@ void mpCalculateAwards(void)
|
||||
s32 prevplayernum;
|
||||
s32 duration60;
|
||||
struct awardmetrics metrics[4];
|
||||
|
||||
// @bug: playerrankings should have 12 elements. Because it's too small,
|
||||
// overflow occurs in mpGetPlayerRankings. The overflow writes into the
|
||||
// metrics array (above) which is yet to be initialised, so this bug has
|
||||
// no effect on IDO.
|
||||
#ifdef AVOID_UB
|
||||
struct ranking playerrankings[MAX_MPCHRS];
|
||||
#else
|
||||
struct ranking playerrankings[1];
|
||||
#endif
|
||||
|
||||
s32 numchrs;
|
||||
s32 numteams;
|
||||
struct ranking teamrankings[MAX_MPCHRS];
|
||||
struct ranking teamrankings[8];
|
||||
u32 stack[4];
|
||||
|
||||
playercount = PLAYERCOUNT();
|
||||
@@ -2135,7 +2126,7 @@ void mpCalculateAwards(void)
|
||||
|
||||
func00033dd8();
|
||||
|
||||
numchrs = mpGetPlayerRankings(playerrankings);
|
||||
numchrs = mpGetPlayerRankings(g_MpRankings);
|
||||
numteams = (g_MpSetup.options & MPOPTION_TEAMSENABLED) ? mpGetTeamRankings(teamrankings) : 0;
|
||||
|
||||
prevplayernum = g_Vars.currentplayernum;
|
||||
|
||||
@@ -869,6 +869,8 @@ void setupAllocateEverything(void)
|
||||
|
||||
killcounts = mempAlloc(g_MpNumChrs * g_MpNumChrs * sizeof(s16), MEMPOOL_STAGE);
|
||||
|
||||
g_MpRankings = mempAlloc(MAX(8, g_MpNumChrs) * sizeof(struct ranking), MEMPOOL_STAGE);
|
||||
|
||||
for (i = 0; i < g_MpNumChrs * g_MpNumChrs; i++) {
|
||||
killcounts[i] = 0;
|
||||
}
|
||||
|
||||
@@ -275,6 +275,7 @@ extern struct scenariodata g_ScenarioData;
|
||||
extern u32 var800ac4cc;
|
||||
extern s32 g_MpNumChrs;
|
||||
extern struct mpchr *g_MpChrs;
|
||||
extern struct ranking *g_MpRankings;
|
||||
extern struct mpbotconfig g_BotConfigsArray[MAX_BOTS];
|
||||
extern u8 g_MpSimulantDifficultiesPerNumPlayers[8][4];
|
||||
extern struct mpplayerconfig g_PlayerConfigsArray[6];
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#define IS4MB() (g_Is4Mb == true)
|
||||
#define IS8MB() (g_Is4Mb != true)
|
||||
#define LINEHEIGHT (VERSION == VERSION_JPN_FINAL ? 14 : 11)
|
||||
#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]
|
||||
#define MPCHRCONFIG(index) ((index) < 4 ? &g_PlayerConfigsArray[index].base : &g_BotConfigsArray[index - 4].base)
|
||||
|
||||
Reference in New Issue
Block a user