Tidy up gfxmemory.c

This commit is contained in:
Ryan Dwyer
2023-05-09 08:23:33 +10:00
parent f39432946c
commit 6e8249b8bd
+18 -38
View File
@@ -38,24 +38,8 @@ u8 *g_GfxBuffers[3];
u8 *g_VtxBuffers[3];
u8 *g_GfxMemPos;
u8 g_GfxActiveBufferIndex;
u32 g_GfxRequestedDisplayList;
u32 g_GfxSizesByPlayerCount[] = {
0x00010000,
0x00018000,
0x00020000,
0x00028000,
};
u32 g_VtxSizesByPlayerCount[] = {
0x00010000,
0x00018000,
0x00020000,
0x00028000,
};
s32 g_GfxNumSwapsPerBuffer[2] = {0, 1};
u32 g_GfxNumSwaps = 0x00000002;
u32 g_GfxNumSwaps = 2;
extern s32 g_StageNum;
extern struct stageallocation g_StageAllocations8Mb[];
@@ -64,6 +48,7 @@ void gfxReset(void)
{
s32 index = 0;
s32 gfx;
s32 vtx;
while (g_StageAllocations8Mb[index].stagenum) {
if (g_StageNum == g_StageAllocations8Mb[index].stagenum) {
@@ -79,27 +64,26 @@ void gfxReset(void)
gfx += g_StageAllocations8Mb[index].gfxtra;
}
g_GfxSizesByPlayerCount[PLAYERCOUNT() - 1] = gfx * 1024;
g_VtxSizesByPlayerCount[PLAYERCOUNT() - 1] = g_StageAllocations8Mb[index].mvtx * 1024;
vtx = g_StageAllocations8Mb[index].mvtx;
g_GfxBuffers[0] = mempAlloc(g_GfxSizesByPlayerCount[PLAYERCOUNT() - 1] * 2, MEMPOOL_STAGE);
g_GfxBuffers[1] = g_GfxBuffers[0] + g_GfxSizesByPlayerCount[PLAYERCOUNT() - 1];
g_GfxBuffers[2] = g_GfxBuffers[1] + g_GfxSizesByPlayerCount[PLAYERCOUNT() - 1];
gfx *= 1024;
vtx *= 1024;
g_VtxBuffers[0] = mempAlloc(g_VtxSizesByPlayerCount[PLAYERCOUNT() - 1] * 2, MEMPOOL_STAGE);
g_VtxBuffers[1] = g_VtxBuffers[0] + g_VtxSizesByPlayerCount[PLAYERCOUNT() - 1];
g_VtxBuffers[2] = g_VtxBuffers[1] + g_VtxSizesByPlayerCount[PLAYERCOUNT() - 1];
g_GfxBuffers[0] = UNCACHED(mempAlloc(gfx * 2, MEMPOOL_STAGE));
g_GfxBuffers[1] = g_GfxBuffers[0] + gfx;
g_GfxBuffers[2] = g_GfxBuffers[1] + gfx;
g_VtxBuffers[0] = UNCACHED(mempAlloc(vtx * 2, MEMPOOL_STAGE));
g_VtxBuffers[1] = g_VtxBuffers[0] + vtx;
g_VtxBuffers[2] = g_VtxBuffers[1] + vtx;
g_GfxActiveBufferIndex = 0;
g_GfxRequestedDisplayList = false;
g_GfxMemPos = g_VtxBuffers[0];
}
Gfx *gfxGetMasterDisplayList(void)
{
g_GfxRequestedDisplayList = true;
return (Gfx *) UNCACHED(g_GfxBuffers[g_GfxActiveBufferIndex]);
return (Gfx *) g_GfxBuffers[g_GfxActiveBufferIndex];
}
struct gfxvtx *gfxAllocateVertices(u32 count)
@@ -108,7 +92,7 @@ struct gfxvtx *gfxAllocateVertices(u32 count)
g_GfxMemPos += count * sizeof(struct gfxvtx);
g_GfxMemPos = (u8 *)ALIGN16((u32)g_GfxMemPos);
return UNCACHED(ptr);
return ptr;
}
void *gfxAllocateMatrix(void)
@@ -122,9 +106,9 @@ void *gfxAllocateMatrix(void)
void *gfxAllocateLookAt(s32 count)
{
void *ptr = g_GfxMemPos;
g_GfxMemPos += count * 0x10;
g_GfxMemPos += count * sizeof(LookAt);
return UNCACHED(ptr);
return ptr;
}
void *gfxAllocateColours(s32 count)
@@ -133,7 +117,7 @@ void *gfxAllocateColours(s32 count)
count = ALIGN16(count * sizeof(u32));
g_GfxMemPos += count;
return UNCACHED(ptr);
return ptr;
}
void *gfxAllocate(u32 size)
@@ -145,17 +129,13 @@ void *gfxAllocate(u32 size)
return ptr;
}
extern s32 g_GfxNumSwapsPerBuffer[2];
void gfxSwapBuffers(void)
{
g_GfxActiveBufferIndex ^= 1;
g_GfxRequestedDisplayList = false;
g_GfxMemPos = g_VtxBuffers[g_GfxActiveBufferIndex];
g_GfxNumSwapsPerBuffer[g_GfxActiveBufferIndex] = g_GfxNumSwaps;
g_GfxNumSwaps++;
if (g_GfxNumSwaps == -1) {
if (g_GfxNumSwaps == 0xffffffff) {
g_GfxNumSwaps = 2;
}
}