RoomMtx: Prevent cache fighting in multiplayer and remove need to tick roommtxes

This commit is contained in:
Ryan Dwyer
2023-01-07 17:08:30 +10:00
parent 5fe7cd37f6
commit 246d30ce04
10 changed files with 50 additions and 99 deletions
-1
View File
@@ -58,7 +58,6 @@
build/ROMID/game/menustop.o (section); \
build/ROMID/game/menutick.o (section); \
build/ROMID/game/weathertick.o (section); \
build/ROMID/game/roomtick.o (section); \
build/ROMID/game/skytick.o (section); \
build/ROMID/game/casingtick.o (section); \
build/ROMID/game/shardstick.o (section); \
-1
View File
@@ -2041,7 +2041,6 @@ void lvTick(void)
lvUpdateCutsceneTime();
PROFILE(PROFILEMARKER_LVT_VTXSTORE, vtxstoreTick());
lvUpdateSoloHandicaps();
PROFILE(PROFILEMARKER_LVT_ROOMS, roomsTick());
skyTick();
PROFILE(PROFILEMARKER_LVT_CASINGS, casingsTick());
+33 -53
View File
@@ -7,10 +7,9 @@
#include "types.h"
struct roommtx *g_RoomMtxes;
struct roommtx *g_RoomMtxesUsed;
struct roommtx *g_RoomMtxesFree;
s32 var80082050 = 0;
s32 g_NextRoomMtx = 0;
void roomSetLastForOffset(s32 room)
{
@@ -19,13 +18,13 @@ void roomSetLastForOffset(s32 room)
void room0f1668f0(struct roommtx *roommtx, s32 roomnum)
{
g_Rooms[roomnum].unk10 = roommtx->index;
g_Rooms[roomnum].unk10[g_Vars.currentplayernum] = roommtx->index;
roommtx->room1 = roomnum;
}
void room0f16692c(struct roommtx *roommtx, s32 roomnum)
{
g_Rooms[roomnum].unk10 = -1;
g_Rooms[roomnum].unk10[roommtx->playernum] = -1;
roommtx->room1 = -1;
}
@@ -35,28 +34,10 @@ void room0f16696c(struct roommtx *roommtx)
room0f16692c(roommtx, roommtx->room1);
}
roommtx->count = 2;
roommtx->lvframe = 0;
roommtx->playernum = -1;
roommtx->room2 = -1;
roommtx->somefloat = 1;
// Move from used to free
if (roommtx == g_RoomMtxesUsed) {
g_RoomMtxesUsed = roommtx->next;
} else {
struct roommtx *iter = g_RoomMtxesUsed;
while (iter) {
if (iter->next == roommtx) {
iter->next = roommtx->next;
break;
}
iter = iter->next;
}
}
roommtx->next = g_RoomMtxesFree;
g_RoomMtxesFree = roommtx;
}
/**
@@ -64,30 +45,29 @@ void room0f16696c(struct roommtx *roommtx)
*/
struct roommtx *room0f1669fc(void)
{
struct roommtx *roommtx = g_RoomMtxesFree;
s32 i;
if (!roommtx) {
return g_RoomMtxesUsed;
for (i = 0; i < var80082050; i++) {
struct roommtx *roommtx = &g_RoomMtxes[g_NextRoomMtx];
g_NextRoomMtx++;
if (g_NextRoomMtx == var80082050) {
g_NextRoomMtx = 0;
}
if (roommtx->lvframe < g_Vars.lvframenum - 2) {
return roommtx;
}
}
g_RoomMtxesFree = roommtx->next;
roommtx->next = g_RoomMtxesUsed;
g_RoomMtxesUsed = roommtx;
return roommtx;
return &g_RoomMtxes[0];
}
void room0f166a6c(Mtxf *mtx, s32 roomnum)
{
s32 stagenum = g_Vars.stagenum;
mtx4LoadIdentity(mtx);
mtx->m[0][0] = 1;
mtx->m[1][1] = 1;
mtx->m[2][2] = 1;
if (roomnum == g_BgAlwaysRoom) {
mtx->m[3][0] = g_BgRooms[roomnum].pos.x;
mtx->m[3][1] = g_BgRooms[roomnum].pos.y;
@@ -101,27 +81,27 @@ void room0f166a6c(Mtxf *mtx, s32 roomnum)
struct roommtx *room0f166c20(s32 roomnum)
{
s32 index = g_Rooms[roomnum].unk10;
s32 index = g_Rooms[roomnum].unk10[g_Vars.currentplayernum];
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(&g_RoomMtxes[index], roomnum);
}
roommtx = room0f1669fc();
room0f1668f0(roommtx, roomnum);
roommtx->count = 0;
} else {
if (index != -1
&& g_Vars.currentplayer->lastroomforoffset == g_RoomMtxes[index].room2
&& g_RoomMtxes[index].somefloat == var8005ef10[0]) {
roommtx = &g_RoomMtxes[index];
roommtx->count = 0;
roommtx->lvframe = g_Vars.lvframenum;
return roommtx;
}
if (index != -1) {
room0f16692c(&g_RoomMtxes[index], roomnum);
}
roommtx = room0f1669fc();
room0f1668f0(roommtx, roomnum);
roommtx->lvframe = g_Vars.lvframenum;
roommtx->playernum = g_Vars.currentplayernum;
roommtx->room2 = g_Vars.currentplayer->lastroomforoffset;
roommtx->somefloat = var8005ef10[0];
+11 -11
View File
@@ -15,25 +15,25 @@ 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;
g_NextRoomMtx = 0;
for (i = 0; i < PLAYERCOUNT(); i++) {
g_Vars.players[i]->lastroomforoffset = -1;
}
for (i = 0; i < var80082050; i++) {
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_RoomMtxes[i].index = i;
g_RoomMtxes[i].playernum = -1;
g_RoomMtxes[i].lvframe = -10;
g_RoomMtxes[i].room1 = -1;
g_RoomMtxes[i].room2 = -1;
g_RoomMtxes[i].somefloat = 1;
}
g_RoomMtxesFree[var80082050 - 1].next = NULL;
for (i = 0; i < g_Vars.roomcount; i++) {
g_Rooms[i].unk10 = -1;
g_Rooms[i].unk10[0] = -1;
g_Rooms[i].unk10[1] = -1;
g_Rooms[i].unk10[2] = -1;
g_Rooms[i].unk10[3] = -1;
}
}
-23
View File
@@ -1,23 +0,0 @@
#include <ultra64.h>
#include "constants.h"
#include "game/room.h"
#include "bss.h"
#include "data.h"
#include "types.h"
void roomsTick(void)
{
struct roommtx *roommtx = g_RoomMtxesUsed;
while (roommtx) {
struct roommtx *next = roommtx->next;
roommtx->count++;
if (roommtx->count > 1) {
room0f16696c(roommtx);
}
roommtx = next;
}
}
+1 -2
View File
@@ -295,8 +295,7 @@ extern s32 g_LasersightsActive;
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_NextRoomMtx;
extern s32 g_BgAlwaysRoom;
#endif
-1
View File
@@ -3461,7 +3461,6 @@ enum profilemarker {
PROFILEMARKER_LVRENDER,
PROFILEMARKER_LVT_HUDMSGS,
PROFILEMARKER_LVT_VTXSTORE,
PROFILEMARKER_LVT_ROOMS,
PROFILEMARKER_LVT_CASINGS,
PROFILEMARKER_LVT_SHARDS,
PROFILEMARKER_LVT_SPARKS,
-2
View File
@@ -6,8 +6,6 @@
void roomsReset(void);
void roomsTick(void);
void roomSetLastForOffset(s32 room);
void room0f1668f0(struct roommtx *roommtx, s32 roomnum);
void room0f16692c(struct roommtx *roommtx, s32 roomnum);
+3 -3
View File
@@ -3560,7 +3560,7 @@ struct room {
/*0x0a*/ u16 lightindex; // index of start of this room's lights in data file
/*0x0c*/ u16 firstwaypoint; // offset into g_Vars.waypoints
/*0x0e*/ s16 roomportallistoffset;
/*0x10*/ s16 unk10;
/*0x10*/ s16 unk10[4];
/*0x14*/ struct roomgfxdata *gfxdata;
/*0x18*/ f32 bbmin[3];
/*0x24*/ f32 bbmax[3];
@@ -6363,11 +6363,11 @@ struct xz {
struct roommtx {
Mtxf mtx;
u8 index;
u8 count;
s8 playernum;
s32 lvframe;
s16 room1;
s16 room2;
f32 somefloat;
struct roommtx *next;
};
#endif
+2 -2
View File
@@ -93,6 +93,7 @@ void profileStartDynamic(char *file, s32 line)
void profileEndDynamic(char *file, s32 line)
{
u32 count = osGetCount();
s32 i;
struct profileslot *slot = NULL;
@@ -104,7 +105,7 @@ void profileEndDynamic(char *file, s32 line)
}
if (slot) {
slot->ticks = osGetCount() - slot->startticks;
slot->ticks += count - slot->startticks;
slot->startticks = 0;
g_ProfileCurrentSlot = slot->parent;
@@ -266,7 +267,6 @@ Gfx *profileRender(Gfx *gdl)
gdl = profileRenderCpuLine(gdl, x, &y, " lvTick", PROFILEMARKER_LVTICK);
gdl = profileRenderCpuLine(gdl, x, &y, " hudmsgs ", PROFILEMARKER_LVT_HUDMSGS );
gdl = profileRenderCpuLine(gdl, x, &y, " vtxstore ", PROFILEMARKER_LVT_VTXSTORE );
gdl = profileRenderCpuLine(gdl, x, &y, " rooms ", PROFILEMARKER_LVT_ROOMS );
gdl = profileRenderCpuLine(gdl, x, &y, " casings ", PROFILEMARKER_LVT_CASINGS );
gdl = profileRenderCpuLine(gdl, x, &y, " shards ", PROFILEMARKER_LVT_SHARDS );
gdl = profileRenderCpuLine(gdl, x, &y, " sparks ", PROFILEMARKER_LVT_SPARKS );