mirror of
https://gitlab.com/ryandwyer/perfect-dark
synced 2026-09-09 11:34:16 -04:00
Refactor room matrices to use used and free linked lists
This commit is contained in:
+63
-34
@@ -7,6 +7,8 @@
|
||||
#include "types.h"
|
||||
|
||||
struct roommtx *g_RoomMtxes;
|
||||
struct roommtx *g_RoomMtxesUsed;
|
||||
struct roommtx *g_RoomMtxesFree;
|
||||
|
||||
s32 var80082050 = 0;
|
||||
|
||||
@@ -15,40 +17,65 @@ void roomSetLastForOffset(s32 room)
|
||||
g_Vars.currentplayer->lastroomforoffset = room;
|
||||
}
|
||||
|
||||
void room0f1668f0(s32 index, s32 roomnum)
|
||||
void room0f1668f0(struct roommtx *roommtx, s32 roomnum)
|
||||
{
|
||||
g_Rooms[roomnum].unk10 = index;
|
||||
g_RoomMtxes[index].room1 = roomnum;
|
||||
g_Rooms[roomnum].unk10 = roommtx->index;
|
||||
roommtx->room1 = roomnum;
|
||||
}
|
||||
|
||||
void room0f16692c(s32 index, s32 roomnum)
|
||||
void room0f16692c(struct roommtx *roommtx, s32 roomnum)
|
||||
{
|
||||
g_Rooms[roomnum].unk10 = -1;
|
||||
g_RoomMtxes[index].room1 = -1;
|
||||
roommtx->room1 = -1;
|
||||
}
|
||||
|
||||
void room0f16696c(s32 index)
|
||||
void room0f16696c(struct roommtx *roommtx)
|
||||
{
|
||||
if (g_RoomMtxes[index].room1 != -1) {
|
||||
room0f16692c(index, g_RoomMtxes[index].room1);
|
||||
if (roommtx->room1 != -1) {
|
||||
room0f16692c(roommtx, roommtx->room1);
|
||||
}
|
||||
|
||||
g_RoomMtxes[index].count = 2;
|
||||
g_RoomMtxes[index].room2 = -1;
|
||||
g_RoomMtxes[index].somefloat = 1;
|
||||
}
|
||||
roommtx->count = 2;
|
||||
roommtx->room2 = -1;
|
||||
roommtx->somefloat = 1;
|
||||
|
||||
s32 room0f1669fc(void)
|
||||
{
|
||||
s32 i;
|
||||
// Move from used to free
|
||||
if (roommtx == g_RoomMtxesUsed) {
|
||||
g_RoomMtxesUsed = roommtx->next;
|
||||
} else {
|
||||
struct roommtx *iter = g_RoomMtxesUsed;
|
||||
|
||||
for (i = 0; i < var80082050; i++) {
|
||||
if (g_RoomMtxes[i].count > 1 && g_RoomMtxes[i].room2 == -1) {
|
||||
return i;
|
||||
while (iter) {
|
||||
if (iter->next == roommtx) {
|
||||
iter->next = roommtx->next;
|
||||
break;
|
||||
}
|
||||
|
||||
iter = iter->next;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
roommtx->next = g_RoomMtxesFree;
|
||||
g_RoomMtxesFree = roommtx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a free mtx and return it.
|
||||
*/
|
||||
struct roommtx *room0f1669fc(void)
|
||||
{
|
||||
struct roommtx *roommtx = g_RoomMtxesFree;
|
||||
|
||||
if (!roommtx) {
|
||||
return g_RoomMtxesUsed;
|
||||
}
|
||||
|
||||
g_RoomMtxesFree = roommtx->next;
|
||||
|
||||
roommtx->next = g_RoomMtxesUsed;
|
||||
g_RoomMtxesUsed = roommtx;
|
||||
|
||||
return roommtx;
|
||||
}
|
||||
|
||||
void room0f166a6c(Mtxf *mtx, s32 roomnum)
|
||||
@@ -84,41 +111,43 @@ void room0f166a6c(Mtxf *mtx, s32 roomnum)
|
||||
}
|
||||
}
|
||||
|
||||
s32 room0f166c20(s32 roomnum)
|
||||
struct roommtx *room0f166c20(s32 roomnum)
|
||||
{
|
||||
s32 index = g_Rooms[roomnum].unk10;
|
||||
struct roommtx *roommtx;
|
||||
Mtxf mtx;
|
||||
|
||||
if (index == -1
|
||||
|| g_Vars.currentplayer->lastroomforoffset != g_RoomMtxes[index].room2
|
||||
|| g_RoomMtxes[index].somefloat != var8005ef10[0]) {
|
||||
if (index != -1) {
|
||||
room0f16692c(index, roomnum);
|
||||
if (index == -1) {
|
||||
roommtx = room0f1669fc();
|
||||
} else {
|
||||
roommtx = &g_RoomMtxes[index];
|
||||
room0f16692c(roommtx, roomnum);
|
||||
}
|
||||
|
||||
index = room0f1669fc();
|
||||
|
||||
room0f1668f0(index, roomnum);
|
||||
g_RoomMtxes[index].count = 0;
|
||||
room0f1668f0(roommtx, roomnum);
|
||||
roommtx->count = 0;
|
||||
} else {
|
||||
g_RoomMtxes[index].count = 0;
|
||||
return index;
|
||||
roommtx->count = 0;
|
||||
return roommtx;
|
||||
}
|
||||
|
||||
g_RoomMtxes[index].room2 = g_Vars.currentplayer->lastroomforoffset;
|
||||
g_RoomMtxes[index].somefloat = var8005ef10[0];
|
||||
roommtx->room2 = g_Vars.currentplayer->lastroomforoffset;
|
||||
roommtx->somefloat = var8005ef10[0];
|
||||
|
||||
room0f166a6c(&mtx, roomnum);
|
||||
mtx00016054(&mtx, &g_RoomMtxes[index].mtx);
|
||||
mtx00016054(&mtx, &roommtx->mtx);
|
||||
|
||||
return index;
|
||||
return roommtx;
|
||||
}
|
||||
|
||||
Gfx *roomPushMtx(Gfx *gdl, s32 roomnum)
|
||||
{
|
||||
s32 index = room0f166c20(roomnum);
|
||||
struct roommtx *roommtx = room0f166c20(roomnum);
|
||||
|
||||
gSPMatrix(gdl++, &g_RoomMtxes[index].mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
|
||||
gSPMatrix(gdl++, &roommtx->mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
|
||||
|
||||
return gdl;
|
||||
}
|
||||
|
||||
+10
-4
@@ -15,18 +15,24 @@ void roomsReset(void)
|
||||
var80082050 = PLAYERCOUNT() >= 2 ? 200 : 120;
|
||||
|
||||
g_RoomMtxes = mempAlloc(ALIGN16(var80082050 * sizeof(struct roommtx)), MEMPOOL_STAGE);
|
||||
g_RoomMtxesUsed = NULL;
|
||||
g_RoomMtxesFree = g_RoomMtxes;
|
||||
|
||||
for (i = 0; i < PLAYERCOUNT(); i++) {
|
||||
g_Vars.players[i]->lastroomforoffset = -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < var80082050; i++) {
|
||||
g_RoomMtxes[i].count = 2;
|
||||
g_RoomMtxes[i].room1 = -1;
|
||||
g_RoomMtxes[i].room2 = -1;
|
||||
g_RoomMtxes[i].somefloat = 1;
|
||||
g_RoomMtxesFree[i].index = i;
|
||||
g_RoomMtxesFree[i].count = 2;
|
||||
g_RoomMtxesFree[i].room1 = -1;
|
||||
g_RoomMtxesFree[i].room2 = -1;
|
||||
g_RoomMtxesFree[i].somefloat = 1;
|
||||
g_RoomMtxesFree[i].next = &g_RoomMtxes[i + 1];
|
||||
}
|
||||
|
||||
g_RoomMtxesFree[var80082050 - 1].next = NULL;
|
||||
|
||||
for (i = 0; i < g_Vars.roomcount; i++) {
|
||||
g_Rooms[i].unk10 = -1;
|
||||
}
|
||||
|
||||
+9
-7
@@ -7,15 +7,17 @@
|
||||
|
||||
void roomsTick(void)
|
||||
{
|
||||
s32 i;
|
||||
struct roommtx *roommtx = g_RoomMtxesUsed;
|
||||
|
||||
for (i = 0; i < var80082050; i++) {
|
||||
if (g_RoomMtxes[i].room2 >= 0) {
|
||||
g_RoomMtxes[i].count++;
|
||||
while (roommtx) {
|
||||
struct roommtx *next = roommtx->next;
|
||||
|
||||
if (g_RoomMtxes[i].count > 1) {
|
||||
room0f16696c(i);
|
||||
}
|
||||
roommtx->count++;
|
||||
|
||||
if (roommtx->count > 1) {
|
||||
room0f16696c(roommtx);
|
||||
}
|
||||
|
||||
roommtx = next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,5 +291,7 @@ extern s32 g_AmActive;
|
||||
extern s32 g_BeamsActive;
|
||||
extern u8 g_HudmsgsActive;
|
||||
extern struct roommtx *g_RoomMtxes;
|
||||
extern struct roommtx *g_RoomMtxesUsed;
|
||||
extern struct roommtx *g_RoomMtxesFree;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,12 +9,12 @@ void roomsReset(void);
|
||||
void roomsTick(void);
|
||||
|
||||
void roomSetLastForOffset(s32 room);
|
||||
void room0f1668f0(s32 index, s32 roomnum);
|
||||
void room0f16692c(s32 index, s32 roomnum);
|
||||
void room0f16696c(s32 index);
|
||||
s32 room0f1669fc(void);
|
||||
void room0f1668f0(struct roommtx *roommtx, s32 roomnum);
|
||||
void room0f16692c(struct roommtx *roommtx, s32 roomnum);
|
||||
void room0f16696c(struct roommtx *roommtx);
|
||||
struct roommtx *room0f1669fc(void);
|
||||
void room0f166a6c(Mtxf *matrix, s32 roomnum);
|
||||
s32 room0f166c20(s32 roomnum);
|
||||
struct roommtx *room0f166c20(s32 roomnum);
|
||||
Gfx *roomPushMtx(Gfx *gdl, s32 roomnum);
|
||||
struct coord *roomGetPos(s32 room);
|
||||
void room0f166df0(s32 room, struct coord *globaldrawworldoffset);
|
||||
|
||||
+3
-2
@@ -6361,12 +6361,13 @@ struct xz {
|
||||
};
|
||||
|
||||
struct roommtx {
|
||||
s32 padding;
|
||||
Mtxf mtx;
|
||||
u8 index;
|
||||
u8 count;
|
||||
s16 room1;
|
||||
s16 room2;
|
||||
f32 somefloat;
|
||||
Mtxf mtx;
|
||||
struct roommtx *next;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user