Introduce g_BgAlwaysRoom and remove stage checks from BG render code

This commit is contained in:
Ryan Dwyer
2022-11-13 13:05:23 +10:00
parent 4114aa0b21
commit 4c3045ca98
5 changed files with 110 additions and 136 deletions
+25 -44
View File
@@ -103,6 +103,7 @@ s16 var800a4ce6;
struct var800a4ce8 *var800a4ce8;
struct portalthing *g_PortalThings;
struct var800a4cf0 var800a4cf0;
s32 g_BgAlwaysRoom;
bool g_BgPreload = false;
s32 g_StageIndex = 1;
@@ -997,47 +998,11 @@ Gfx *bgRenderScene(Gfx *gdl)
// Render special "always on" rooms, such as the Defection moon,
// Attack Ship planet, and other sky tricks that are implemented as rooms
if (!USINGDEVICE(DEVICE_NIGHTVISION) && !USINGDEVICE(DEVICE_IRSCANNER)
&& (stagenum == g_Stages[STAGEINDEX_INFILTRATION].id
|| stagenum == g_Stages[STAGEINDEX_RESCUE].id
|| stagenum == g_Stages[STAGEINDEX_ESCAPE].id
|| stagenum == g_Stages[STAGEINDEX_MAIANSOS].id
|| stagenum == g_Stages[STAGEINDEX_SKEDARRUINS].id
|| stagenum == g_Stages[STAGEINDEX_WAR].id
|| stagenum == g_Stages[STAGEINDEX_DEFECTION].id
|| stagenum == g_Stages[STAGEINDEX_EXTRACTION].id
|| stagenum == g_Stages[STAGEINDEX_MBR].id
|| stagenum == g_Stages[STAGEINDEX_TEST_OLD].id
|| stagenum == g_Stages[STAGEINDEX_ATTACKSHIP].id)) {
if (g_BgAlwaysRoom >= 0 && !USINGDEVICE(DEVICE_NIGHTVISION) && !USINGDEVICE(DEVICE_IRSCANNER)) {
gdl = envStopFog(gdl);
gdl = vi0000ab78(gdl);
roomnum = -1;
if (stagenum == g_Stages[STAGEINDEX_INFILTRATION].id
|| stagenum == g_Stages[STAGEINDEX_RESCUE].id
|| stagenum == g_Stages[STAGEINDEX_ESCAPE].id
|| stagenum == g_Stages[STAGEINDEX_MAIANSOS].id) {
roomnum = 0x0f;
} else if (stagenum == g_Stages[STAGEINDEX_SKEDARRUINS].id
|| stagenum == g_Stages[STAGEINDEX_WAR].id) {
roomnum = 0x02;
} else if (stagenum == g_Stages[STAGEINDEX_DEFECTION].id
|| stagenum == g_Stages[STAGEINDEX_EXTRACTION].id
|| stagenum == g_Stages[STAGEINDEX_MBR].id) {
roomnum = 0x01;
} else if (stagenum == g_Stages[STAGEINDEX_TEST_OLD].id) {
roomnum = 0x01;
} else if (stagenum == g_Stages[STAGEINDEX_ATTACKSHIP].id) {
roomnum = 0x71;
}
if (PLAYERCOUNT() == 1
&& (stagenum == STAGE_DEFECTION
|| stagenum == STAGE_EXTRACTION
|| stagenum == STAGE_INFILTRATION
|| stagenum == STAGE_ESCAPE
|| stagenum == STAGE_ATTACKSHIP)) {
if (g_StarsActive) {
gdl = text0f153628(gdl);
gSPMatrix(gdl++, osVirtualToPhysical(camGetOrthogonalMtxL()), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
@@ -1049,14 +1014,12 @@ Gfx *bgRenderScene(Gfx *gdl)
gdl = vi0000ab78(gdl);
}
if (roomnum != -1) {
if (!g_Rooms[roomnum].loaded240) {
bgLoadRoom(roomnum);
}
gdl = bgRenderRoomOpaque(gdl, roomnum);
if (!g_Rooms[g_BgAlwaysRoom].loaded240) {
bgLoadRoom(g_BgAlwaysRoom);
}
gdl = bgRenderRoomOpaque(gdl, g_BgAlwaysRoom);
gSPPerspNormalize(gdl++, viGetPerspScale());
}
@@ -1432,6 +1395,24 @@ void bgReset(s32 stagenum)
g_BgTable5 = (f32 *)(g_BgPrimaryData2[5] + g_BgPrimaryData + 0xf1000000);
}
}
g_BgAlwaysRoom = -1;
if (stagenum == STAGE_INFILTRATION
|| stagenum == STAGE_RESCUE
|| stagenum == STAGE_ESCAPE
|| stagenum == STAGE_MAIANSOS) {
g_BgAlwaysRoom = 0x0f;
} else if (stagenum == STAGE_SKEDARRUINS
|| stagenum == STAGE_WAR) {
g_BgAlwaysRoom = 0x02;
} else if (stagenum == STAGE_DEFECTION
|| stagenum == STAGE_EXTRACTION
|| stagenum == STAGE_MBR) {
g_BgAlwaysRoom = 0x01;
} else if (stagenum == STAGE_ATTACKSHIP) {
g_BgAlwaysRoom = 0x71;
}
}
void bgBuildTables(s32 stagenum)
+1 -11
View File
@@ -347,17 +347,7 @@ void lvReset(s32 stagenum)
sparksReset();
weatherReset();
lvResetMiscSfx();
switch (g_Vars.stagenum) {
case STAGE_ESCAPE:
case STAGE_EXTRACTION:
case STAGE_INFILTRATION:
case STAGE_DEFECTION:
case STAGE_ATTACKSHIP:
starsReset();
break;
}
starsReset();
func0f0099a4();
boltbeamsReset();
lasersightsReset();
+1 -13
View File
@@ -88,19 +88,7 @@ void room0f166a6c(Mtxf *mtx, s32 roomnum)
mtx->m[1][1] = 1;
mtx->m[2][2] = 1;
// These are rooms that are always active, such as the moon in Defection.
// This is probably making those rooms always drawn a certain distance away
// relative to the camera, so the moon never gets bigger as you go closer.
if (((stagenum == g_Stages[STAGEINDEX_INFILTRATION].id
|| stagenum == g_Stages[STAGEINDEX_RESCUE].id
|| stagenum == g_Stages[STAGEINDEX_ESCAPE].id
|| stagenum == g_Stages[STAGEINDEX_MAIANSOS].id) && roomnum == 0x0f)
|| ((stagenum == g_Stages[STAGEINDEX_SKEDARRUINS].id
|| stagenum == g_Stages[STAGEINDEX_WAR].id) && roomnum == 0x02)
|| ((stagenum == g_Stages[STAGEINDEX_DEFECTION].id
|| stagenum == g_Stages[STAGEINDEX_EXTRACTION].id
|| stagenum == g_Stages[STAGEINDEX_MBR].id) && roomnum == 0x01)
|| (stagenum == g_Stages[STAGEINDEX_ATTACKSHIP].id && roomnum == 0x71)) {
if (roomnum == g_BgAlwaysRoom) {
mtx->m[3][0] = g_BgRooms[roomnum].pos.x;
mtx->m[3][1] = g_BgRooms[roomnum].pos.y;
mtx->m[3][2] = g_BgRooms[roomnum].pos.z;
+80 -67
View File
@@ -18,6 +18,7 @@ s8 *g_StarPositions = NULL;
f32 *g_StarData3;
s32 g_StarGridSize;
s32 *g_StarPosIndexes;
bool g_StarsActive;
bool g_StarsBelowHorizon = false;
@@ -111,84 +112,96 @@ void starsReset(void)
s32 tmp1;
s32 tmp2;
g_StarsActive = false;
if (PLAYERCOUNT() >= 2) {
return;
}
if (g_Vars.stagenum != STAGE_ESCAPE
&& g_Vars.stagenum != STAGE_EXTRACTION
&& g_Vars.stagenum != STAGE_INFILTRATION
&& g_Vars.stagenum != STAGE_DEFECTION
&& g_Vars.stagenum != STAGE_ATTACKSHIP) {
return;
}
g_StarsActive = true;
g_StarPositions = NULL;
g_StarsBelowHorizon = false;
g_StarGridSize = 3;
if (PLAYERCOUNT() < 2) {
g_StarsBelowHorizon = false;
g_StarGridSize = 3;
if (g_Vars.stagenum == STAGE_DEFECTION || g_Vars.stagenum == STAGE_EXTRACTION) {
g_StarCount = 200;
g_StarGridSize = 2;
} else if (g_Vars.stagenum == STAGE_ATTACKSHIP) {
g_StarsBelowHorizon = true;
g_StarCount = 1200;
} else {
g_StarCount = 200;
g_StarGridSize = 2;
}
if (g_Vars.stagenum == STAGE_DEFECTION || g_Vars.stagenum == STAGE_EXTRACTION) {
g_StarCount = 200;
g_StarGridSize = 2;
} else if (g_Vars.stagenum == STAGE_ATTACKSHIP) {
g_StarsBelowHorizon = true;
g_StarCount = 1200;
} else {
g_StarCount = 200;
g_StarGridSize = 2;
tmp = g_StarGridSize + 1;
g_StarPositions = mempAlloc(ALIGN64(g_StarCount * 3U + tmp * 72 * tmp + 6 * g_StarGridSize * g_StarGridSize * 4U + 4), MEMPOOL_STAGE);
if (g_StarPositions != NULL) {
g_StarPosIndexes = (s32 *)(g_StarPositions + g_StarCount * 3);
for (i = 0; i < (6 * g_StarGridSize * g_StarGridSize + 1); i++) {
g_StarPosIndexes[i] = 0;
}
tmp = g_StarGridSize + 1;
g_StarPositions = mempAlloc(ALIGN64(g_StarCount * 3U + tmp * 72 * tmp + 6 * g_StarGridSize * g_StarGridSize * 4U + 4), MEMPOOL_STAGE);
count = 6 * g_StarGridSize * g_StarGridSize + 1;
g_StarData3 = (f32 *)(count * sizeof(f32) + (s32)g_StarPosIndexes);
if (g_StarPositions != NULL) {
g_StarPosIndexes = (s32 *)(g_StarPositions + g_StarCount * 3);
stars0f135c70();
for (i = 0; i < (6 * g_StarGridSize * g_StarGridSize + 1); i++) {
g_StarPosIndexes[i] = 0;
for (i = 0; i < g_StarCount; i++) {
spd4.f[0] = 2.0f * RANDOMFRAC() - 1.0f;
spd4.f[1] = g_StarsBelowHorizon ? 2.0f * RANDOMFRAC() - 1.0f : RANDOMFRAC();
spd4.f[2] = 2.0f * RANDOMFRAC() - 1.0f;
guNormalize(&spd4.f[0], &spd4.f[1], &spd4.f[2]);
f0 = (ABS2(spd4.f[0]) > ABS2(spd4.f[1])) ? (ABS2(spd4.f[0]) > ABS2(spd4.f[2]) ? ABS2(spd4.f[0]) : ABS2(spd4.f[2])) : (ABS2(spd4.f[1]) > ABS2(spd4.f[2]) ? ABS2(spd4.f[1]) : ABS2(spd4.f[2]));
spc8.f[0] = spd4.f[0] / f0;
spc8.f[1] = spd4.f[1] / f0;
spc8.f[2] = spd4.f[2] / f0;
tmp1 = g_StarGridSize * g_StarGridSize;
if (spc8.f[0] == 1 || spc8.f[0] == -1) {
spb0 = spc8.f[0] == -1 ? 0 : 1;
spc0 = spc8.f[1];
spbc = spc8.f[2];
} else if (spc8.f[1] == 1 || spc8.f[1] == -1) {
spb0 = spc8.f[1] == -1 ? 2 : 3;
spc0 = spc8.f[2];
spbc = spc8.f[0];
} else if (spc8.f[2] == 1 || spc8.f[2] == -1) {
spb0 = spc8.f[2] == -1 ? 4 : 5;
spc0 = spc8.f[0];
spbc = spc8.f[1];
} else {
// empty
}
count = 6 * g_StarGridSize * g_StarGridSize + 1;
g_StarData3 = (f32 *)(count * sizeof(f32) + (s32)g_StarPosIndexes);
v0 = (spc0 + 1) / 2 * g_StarGridSize;
v1 = (spbc + 1) / 2 * g_StarGridSize;
stars0f135c70();
for (i = 0; i < g_StarCount; i++) {
spd4.f[0] = 2.0f * RANDOMFRAC() - 1.0f;
spd4.f[1] = g_StarsBelowHorizon ? 2.0f * RANDOMFRAC() - 1.0f : RANDOMFRAC();
spd4.f[2] = 2.0f * RANDOMFRAC() - 1.0f;
guNormalize(&spd4.f[0], &spd4.f[1], &spd4.f[2]);
f0 = (ABS2(spd4.f[0]) > ABS2(spd4.f[1])) ? (ABS2(spd4.f[0]) > ABS2(spd4.f[2]) ? ABS2(spd4.f[0]) : ABS2(spd4.f[2])) : (ABS2(spd4.f[1]) > ABS2(spd4.f[2]) ? ABS2(spd4.f[1]) : ABS2(spd4.f[2]));
spc8.f[0] = spd4.f[0] / f0;
spc8.f[1] = spd4.f[1] / f0;
spc8.f[2] = spd4.f[2] / f0;
tmp1 = g_StarGridSize * g_StarGridSize;
if (spc8.f[0] == 1 || spc8.f[0] == -1) {
spb0 = spc8.f[0] == -1 ? 0 : 1;
spc0 = spc8.f[1];
spbc = spc8.f[2];
} else if (spc8.f[1] == 1 || spc8.f[1] == -1) {
spb0 = spc8.f[1] == -1 ? 2 : 3;
spc0 = spc8.f[2];
spbc = spc8.f[0];
} else if (spc8.f[2] == 1 || spc8.f[2] == -1) {
spb0 = spc8.f[2] == -1 ? 4 : 5;
spc0 = spc8.f[0];
spbc = spc8.f[1];
} else {
// empty
}
v0 = (spc0 + 1) / 2 * g_StarGridSize;
v1 = (spbc + 1) / 2 * g_StarGridSize;
if (v0 == g_StarGridSize) {
v0--;
}
if (v1 == g_StarGridSize) {
v1--;
}
tmp2 = v0 + g_StarGridSize * v1;
starInsert(spb0 * tmp1 + tmp2, &spd4);
if (v0 == g_StarGridSize) {
v0--;
}
if (v1 == g_StarGridSize) {
v1--;
}
tmp2 = v0 + g_StarGridSize * v1;
starInsert(spb0 * tmp1 + tmp2, &spd4);
}
}
}
+3 -1
View File
@@ -287,11 +287,13 @@ extern u8 g_AmBotCommands[16];
extern struct mpsetup g_MpSetup;
extern struct bossfile g_BossFile;
extern struct chrdata *g_MpBotChrPtrs[MAX_BOTS];
extern s32 g_AmActive;
extern bool g_AmActive;
extern s32 g_BeamsActive;
extern bool g_StarsActive;
extern u8 g_HudmsgsActive;
extern struct roommtx *g_RoomMtxes;
extern struct roommtx *g_RoomMtxesUsed;
extern struct roommtx *g_RoomMtxesFree;
extern s32 g_BgAlwaysRoom;
#endif