Split game_166e40.c into gfxmemory.c and rename related symbols

This commit is contained in:
Ryan Dwyer 2020-12-24 12:09:08 +10:00
parent 1a35e2c3b9
commit 5b0b5e0ae7
16 changed files with 224 additions and 173 deletions

View File

@ -153,6 +153,7 @@
build/ROMID/game/game_165670.o (section); \
build/ROMID/game/game_1668e0.o (section); \
build/ROMID/game/game_166e40.o (section); \
build/ROMID/game/gfxmemory.o (section); \
build/ROMID/game/game_167ae0.o (section); \
build/ROMID/game/data/data_02a0e0.o (section); \
build/ROMID/game/timing.o (section); \

View File

@ -14,7 +14,7 @@
#include "game/game_11f000.h"
#include "game/bondview.h"
#include "game/game_1531a0.h"
#include "game/game_166e40.h"
#include "game/gfxmemory.h"
#include "game/lang.h"
#include "game/pdoptions.h"
#include "gvars/gvars.h"

View File

@ -4778,6 +4778,6 @@ u32 g_VtxSizesByPlayerCount[] = {
};
u32 var80083ffc = 0x00028000;
s32 var80084000[2] = {0, 1};
u32 var80084008 = 0x00000002;
s32 g_GfxNumSwapsPerBuffer[2] = {0, 1};
u32 g_GfxNumSwaps = 0x00000002;
u32 var8008400c = 0x00000000;

View File

@ -1870,15 +1870,15 @@ void currentPlayerSetMatrix1740(Mtxf *matrix)
player->prev1740 = player->matrix1740;
player->matrix1740 = matrix;
player->unk1744 = var80084008;
player->c_viewfmdynticknum = g_GfxNumSwaps;
player->unk0488 = player->unk0484;
player->unk0484 = g_GfxMemPos;
}
GLOBAL_ASM(
glabel func0f0b5050
/* f0b5050: 3c02800b */ lui $v0,%hi(var800aa5a0)
/* f0b5054: 9042a5a0 */ lbu $v0,%lo(var800aa5a0)($v0)
/* f0b5050: 3c02800b */ lui $v0,%hi(g_GfxActiveBufferIndex)
/* f0b5054: 9042a5a0 */ lbu $v0,%lo(g_GfxActiveBufferIndex)($v0)
/* f0b5058: 3c03800b */ lui $v1,%hi(g_VtxBuffers)
/* f0b505c: 2463a590 */ addiu $v1,$v1,%lo(g_VtxBuffers)
/* f0b5060: 00027080 */ sll $t6,$v0,0x2
@ -1915,12 +1915,12 @@ glabel func0f0b5050
/* f0b50d8: 00001825 */ or $v1,$zero,$zero
/* f0b50dc: 00001025 */ or $v0,$zero,$zero
/* f0b50e0: 11600003 */ beqz $t3,.L0f0b50f0
/* f0b50e4: 3c138008 */ lui $s3,%hi(var80084008)
/* f0b50e4: 3c138008 */ lui $s3,%hi(g_GfxNumSwaps)
/* f0b50e8: 10000001 */ b .L0f0b50f0
/* f0b50ec: 24040001 */ addiu $a0,$zero,0x1
.L0f0b50f0:
/* f0b50f0: 8e0c0064 */ lw $t4,0x64($s0)
/* f0b50f4: 26734008 */ addiu $s3,$s3,%lo(var80084008)
/* f0b50f4: 26734008 */ addiu $s3,$s3,%lo(g_GfxNumSwaps)
/* f0b50f8: 11800003 */ beqz $t4,.L0f0b5108
/* f0b50fc: 00000000 */ nop
/* f0b5100: 10000001 */ b .L0f0b5108
@ -2015,8 +2015,8 @@ glabel func0f0b5050
/* f0b5238: 24040001 */ addiu $a0,$zero,0x1
.L0f0b523c:
/* f0b523c: 8e0b0064 */ lw $t3,0x64($s0)
/* f0b5240: 3c138008 */ lui $s3,%hi(var80084008)
/* f0b5244: 26734008 */ addiu $s3,$s3,%lo(var80084008)
/* f0b5240: 3c138008 */ lui $s3,%hi(g_GfxNumSwaps)
/* f0b5244: 26734008 */ addiu $s3,$s3,%lo(g_GfxNumSwaps)
/* f0b5248: 11600003 */ beqz $t3,.L0f0b5258
/* f0b524c: 02182821 */ addu $a1,$s0,$t8
/* f0b5250: 10000001 */ b .L0f0b5258
@ -2120,8 +2120,8 @@ glabel func0f0b5050
GLOBAL_ASM(
glabel func0f0b53a4
/* f0b53a4: 3c02800b */ lui $v0,%hi(var800aa5a0)
/* f0b53a8: 9042a5a0 */ lbu $v0,%lo(var800aa5a0)($v0)
/* f0b53a4: 3c02800b */ lui $v0,%hi(g_GfxActiveBufferIndex)
/* f0b53a8: 9042a5a0 */ lbu $v0,%lo(g_GfxActiveBufferIndex)($v0)
/* f0b53ac: 3c03800b */ lui $v1,%hi(g_VtxBuffers)
/* f0b53b0: 2463a590 */ addiu $v1,$v1,%lo(g_VtxBuffers)
/* f0b53b4: 00027080 */ sll $t6,$v0,0x2
@ -2158,12 +2158,12 @@ glabel func0f0b53a4
/* f0b542c: 00001825 */ or $v1,$zero,$zero
/* f0b5430: 00001025 */ or $v0,$zero,$zero
/* f0b5434: 11600003 */ beqz $t3,.L0f0b5444
/* f0b5438: 3c138008 */ lui $s3,%hi(var80084008)
/* f0b5438: 3c138008 */ lui $s3,%hi(g_GfxNumSwaps)
/* f0b543c: 10000001 */ b .L0f0b5444
/* f0b5440: 24040001 */ addiu $a0,$zero,0x1
.L0f0b5444:
/* f0b5444: 8e0c0064 */ lw $t4,0x64($s0)
/* f0b5448: 26734008 */ addiu $s3,$s3,%lo(var80084008)
/* f0b5448: 26734008 */ addiu $s3,$s3,%lo(g_GfxNumSwaps)
/* f0b544c: 11800003 */ beqz $t4,.L0f0b545c
/* f0b5450: 00000000 */ nop
/* f0b5454: 10000001 */ b .L0f0b545c
@ -2258,8 +2258,8 @@ glabel func0f0b53a4
/* f0b558c: 24040001 */ addiu $a0,$zero,0x1
.L0f0b5590:
/* f0b5590: 8e0b0064 */ lw $t3,0x64($s0)
/* f0b5594: 3c138008 */ lui $s3,%hi(var80084008)
/* f0b5598: 26734008 */ addiu $s3,$s3,%lo(var80084008)
/* f0b5594: 3c138008 */ lui $s3,%hi(g_GfxNumSwaps)
/* f0b5598: 26734008 */ addiu $s3,$s3,%lo(g_GfxNumSwaps)
/* f0b559c: 11600003 */ beqz $t3,.L0f0b55ac
/* f0b55a0: 02182821 */ addu $a1,$s0,$t8
/* f0b55a4: 10000001 */ b .L0f0b55ac
@ -2395,7 +2395,7 @@ void currentPlayerSetUnk174c(Mtxf *matrix)
{
struct player *player = g_Vars.currentplayer;
player->unk1764 = player->unk1744;
player->c_prevviewfmdynticknum = player->c_viewfmdynticknum;
player->unk1768 = player->unk174c;
player->unk174c = matrix;
}

View File

@ -41,7 +41,7 @@
#include "game/game_1655c0.h"
#include "game/game_165670.h"
#include "game/game_1668e0.h"
#include "game/game_166e40.h"
#include "game/gfxmemory.h"
#include "game/game_167ae0.h"
#include "game/music.h"
#include "game/game_16e810.h"

View File

@ -418,139 +418,3 @@ void func0f167330(void)
{
func0f1672f0(5);
}
/**
* Comments in this function are strings that appear in an XBLA debug build.
* They were likely in the N64 version but ifdeffed out.
*/
void func0f167350(void)
{
s32 stack;
if (func00013010(1, "-mgfx")) {
// Argument specified master_dl_size\n
s32 gfx;
s32 gfxtra = 0;
gfx = func00013408(func00013010(1, "-mgfx"), NULL, 0) * 1024;
if (func00013010(1, "-mgfxtra")) {
// ******** Extra specified but are we in the correct game mode I wonder???\n
if ((g_Vars.coopplayernum >= 0 || g_Vars.antiplayernum >= 0) && PLAYERCOUNT() == 2) {
// ******** Extra Display List Memeory Required\n
// ******** Shall steal from video buffer\n
// ******** If you try and run hi-res then\n
// ******** you're gonna shafted up the arse\n
// ******** so don't blame me\n
gfxtra = func00013408(func00013010(1, "-mgfxtra"), NULL, 0) * 1024;
} else {
// ******** No we're not so there\n
}
}
// ******** Original Amount required = %dK ber buffer\n
// ******** Extra Amount required = %dK ber buffer\n
// ******** Total of %dK (Double Buffered)\n
g_GfxSizesByPlayerCount[PLAYERCOUNT()] = gfx + gfxtra;
}
if (func00013010(1, "-mvtx")) {
// Argument specified mtxvtx_size\n
g_VtxSizesByPlayerCount[PLAYERCOUNT()] = func00013408(func00013010(1, "-mvtx"), NULL, 0) * 1024;
}
// %d Players : Allocating %d bytes for master dl's\n
g_GfxBuffers[0] = malloc(g_GfxSizesByPlayerCount[PLAYERCOUNT()] * 2, 4);
g_GfxBuffers[1] = g_GfxBuffers[0] + g_GfxSizesByPlayerCount[PLAYERCOUNT()];
g_GfxBuffers[2] = g_GfxBuffers[1] + g_GfxSizesByPlayerCount[PLAYERCOUNT()];
// Allocating %d bytes for mtxvtx space\n
g_VtxBuffers[0] = malloc(g_VtxSizesByPlayerCount[PLAYERCOUNT()] * 2, 4);
g_VtxBuffers[1] = g_VtxBuffers[0] + g_VtxSizesByPlayerCount[PLAYERCOUNT()];
g_VtxBuffers[2] = g_VtxBuffers[1] + g_VtxSizesByPlayerCount[PLAYERCOUNT()];
var800aa5a0 = 0;
var800aa5a4 = 0;
g_GfxMemPos = g_VtxBuffers[0];
}
const char var7f1b7728[] = "";
const char var7f1b772c[] = "";
const char var7f1b7730[] = "fr: %d\n";
const char var7f1b7738[] = "cutsceneframe: %d\n";
const char var7f1b774c[] = "pos:%s%s %.2f %.2f %.2f\n";
Gfx *gfxGetMasterDisplayList(void)
{
var800aa5a4 = 1;
return (Gfx *)g_GfxBuffers[var800aa5a0];
}
struct gfxvtx *gfxAllocateVertices(s32 count)
{
void *ptr = g_GfxMemPos;
g_GfxMemPos += count * sizeof(struct gfxvtx);
g_GfxMemPos = (u8 *)ALIGN16((u32)g_GfxMemPos);
return ptr;
}
void *gfxAllocateMatrix(void)
{
void *ptr = g_GfxMemPos;
g_GfxMemPos += sizeof(Mtx);
return ptr;
}
void *gfxAllocate4Words(s32 count)
{
void *ptr = g_GfxMemPos;
g_GfxMemPos += count * 0x10;
return ptr;
}
u32 *gfxAllocateColours(s32 count)
{
void *ptr = g_GfxMemPos;
count = ALIGN16(count * sizeof(u32));
g_GfxMemPos += count;
return ptr;
}
void *gfxAllocate(u32 size)
{
void *ptr = g_GfxMemPos;
size = ALIGN16(size);
g_GfxMemPos += size;
return ptr;
}
extern s32 var80084000[2];
void func0f167a18(void)
{
var800aa5a0 ^= 1;
var800aa5a4 = 0;
g_GfxMemPos = g_VtxBuffers[var800aa5a0];
var80084000[var800aa5a0] = var80084008;
var80084008++;
if (var80084008 == -1) {
var80084008 = 2;
}
}
u32 func0f167a88(long long *arg0)
{
return (long long *)g_GfxBuffers[1 + var800aa5a0] - arg0;
}
u32 func0f167ab0(void)
{
return g_VtxBuffers[1 + var800aa5a0] - g_GfxMemPos;
}

View File

@ -112,6 +112,12 @@
#include "lib/lib_4a360.h"
#include "types.h"
const char var7f1b7730[] = "fr: %d\n";
const char var7f1b7738[] = "cutsceneframe: %d\n";
const char var7f1b774c[] = "pos:%s%s %.2f %.2f %.2f\n";
const char var7f1b7768[] = "";
const char var7f1b776c[] = "";
u32 var80084010 = 0;
bool var80084014 = false;
f32 var80084018 = 1;

173
src/game/gfxmemory.c Normal file
View File

@ -0,0 +1,173 @@
#include <ultra64.h>
#include "constants.h"
#include "game/data/data_000000.h"
#include "game/data/data_0083d0.h"
#include "game/data/data_00e460.h"
#include "game/data/data_0160b0.h"
#include "game/data/data_01a3a0.h"
#include "game/data/data_020df0.h"
#include "game/data/data_02da90.h"
#include "game/gfxmemory.h"
#include "game/game_175f50.h"
#include "gvars/gvars.h"
#include "lib/lib_074f0.h"
#include "lib/lib_0d0a0.h"
#include "lib/lib_121e0.h"
#include "lib/lib_12dc0.h"
#include "lib/lib_13130.h"
#include "types.h"
/**
* This file handles memory usage for graphics related tasks.
*
* There are two pools, "gfx" and "vtx", which are used to store different data.
*
* The gfx pool (g_GfxBuffers) is sized based on the stage's -mgfx and -mgfxtra
* arguments. It contains only the master display list's GBI bytecode.
* The master gdl is passed through all rendering functions in the game engine,
* where each appends to the display list.
*
* The vtx pool (g_VtxBuffers) is sized based on the stage's -mvtx argument.
* It is used for auxiliary graphics data such as vertex arrays, matrices and
* colours.
*
* Both the gfx and vtx pools are split into two buffers of equal size.
* Only one buffer is active at a time - the other is being drawn to the screen
* while the active one is being built. Each time a frame is finished the active
* buffer index is swapped to the other one.
*
* Both the gfx and vtx pools have a third element in them, but this is just a
* marker for the end of the second element's allocation.
*/
/**
* Allocate graphics memory from the heap. Presumably called on stage load.
*
* Comments in this function are strings that appear in an XBLA debug build.
* They were likely in the N64 version but ifdeffed out.
*/
void gfxInitMemory(void)
{
s32 stack;
if (func00013010(1, "-mgfx")) {
// Argument specified master_dl_size\n
s32 gfx;
s32 gfxtra = 0;
gfx = func00013408(func00013010(1, "-mgfx"), NULL, 0) * 1024;
if (func00013010(1, "-mgfxtra")) {
// ******** Extra specified but are we in the correct game mode I wonder???\n
if ((g_Vars.coopplayernum >= 0 || g_Vars.antiplayernum >= 0) && PLAYERCOUNT() == 2) {
// ******** Extra Display List Memeory Required\n
// ******** Shall steal from video buffer\n
// ******** If you try and run hi-res then\n
// ******** you're gonna shafted up the arse\n
// ******** so don't blame me\n
gfxtra = func00013408(func00013010(1, "-mgfxtra"), NULL, 0) * 1024;
} else {
// ******** No we're not so there\n
}
}
// ******** Original Amount required = %dK ber buffer\n
// ******** Extra Amount required = %dK ber buffer\n
// ******** Total of %dK (Double Buffered)\n
g_GfxSizesByPlayerCount[PLAYERCOUNT()] = gfx + gfxtra;
}
if (func00013010(1, "-mvtx")) {
// Argument specified mtxvtx_size\n
g_VtxSizesByPlayerCount[PLAYERCOUNT()] = func00013408(func00013010(1, "-mvtx"), NULL, 0) * 1024;
}
// %d Players : Allocating %d bytes for master dl's\n
g_GfxBuffers[0] = malloc(g_GfxSizesByPlayerCount[PLAYERCOUNT()] * 2, 4);
g_GfxBuffers[1] = g_GfxBuffers[0] + g_GfxSizesByPlayerCount[PLAYERCOUNT()];
g_GfxBuffers[2] = g_GfxBuffers[1] + g_GfxSizesByPlayerCount[PLAYERCOUNT()];
// Allocating %d bytes for mtxvtx space\n
g_VtxBuffers[0] = malloc(g_VtxSizesByPlayerCount[PLAYERCOUNT()] * 2, 4);
g_VtxBuffers[1] = g_VtxBuffers[0] + g_VtxSizesByPlayerCount[PLAYERCOUNT()];
g_VtxBuffers[2] = g_VtxBuffers[1] + g_VtxSizesByPlayerCount[PLAYERCOUNT()];
g_GfxActiveBufferIndex = 0;
g_GfxRequestedDisplayList = false;
g_GfxMemPos = g_VtxBuffers[0];
}
Gfx *gfxGetMasterDisplayList(void)
{
g_GfxRequestedDisplayList = true;
return (Gfx *)g_GfxBuffers[g_GfxActiveBufferIndex];
}
struct gfxvtx *gfxAllocateVertices(s32 count)
{
void *ptr = g_GfxMemPos;
g_GfxMemPos += count * sizeof(struct gfxvtx);
g_GfxMemPos = (u8 *)ALIGN16((u32)g_GfxMemPos);
return ptr;
}
void *gfxAllocateMatrix(void)
{
void *ptr = g_GfxMemPos;
g_GfxMemPos += sizeof(Mtx);
return ptr;
}
void *gfxAllocate4Words(s32 count)
{
void *ptr = g_GfxMemPos;
g_GfxMemPos += count * 0x10;
return ptr;
}
u32 *gfxAllocateColours(s32 count)
{
void *ptr = g_GfxMemPos;
count = ALIGN16(count * sizeof(u32));
g_GfxMemPos += count;
return ptr;
}
void *gfxAllocate(u32 size)
{
void *ptr = g_GfxMemPos;
size = ALIGN16(size);
g_GfxMemPos += 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) {
g_GfxNumSwaps = 2;
}
}
u32 gfxGetFreeGfx(long long *ptr)
{
return (long long *)g_GfxBuffers[g_GfxActiveBufferIndex + 1] - ptr;
}
u32 gfxGetFreeVtx(void)
{
return g_VtxBuffers[g_GfxActiveBufferIndex + 1] - g_GfxMemPos;
}

View File

@ -50,7 +50,7 @@
#include "game/game_157db0.h"
#include "game/game_1655c0.h"
#include "game/game_165670.h"
#include "game/game_166e40.h"
#include "game/gfxmemory.h"
#include "game/game_167ae0.h"
#include "game/game_179060.h"
#include "game/game_17f930.h"

View File

@ -15703,8 +15703,8 @@ u8 *g_GfxBuffers[3] = {NULL};
u32 var800aa58c = 0;
u8 *g_VtxBuffers[3] = {NULL};
u8 *g_GfxMemPos = NULL;
u8 var800aa5a0 = 0;
u32 var800aa5a4 = 0;
u8 g_GfxActiveBufferIndex = 0;
u32 g_GfxRequestedDisplayList = 0;
u32 var800aa5a8 = 0;
u32 var800aa5ac = 0;
struct audiohandle *g_BoostAndSlayerAudioHandles[3] = {NULL};

View File

@ -289,7 +289,7 @@ extern s32 var80082050;
extern void *filetable[];
extern u32 g_GfxSizesByPlayerCount[];
extern u32 g_VtxSizesByPlayerCount[];
extern u32 var80084008;
extern u32 g_GfxNumSwaps;
extern u32 var80084010;
extern bool var80084014;
extern f32 var80084018;

View File

@ -18,13 +18,5 @@ u32 fileGetUnk04(s32 filenum);
u32 func0f1672a8(void);
void func0f1672f0(u8 arg0);
void func0f167330(void);
void func0f167350(void);
Gfx *gfxGetMasterDisplayList(void);
struct gfxvtx *gfxAllocateVertices(s32 count);
void *gfxAllocateMatrix(void);
void *gfxAllocate4Words(s32 count);
u32 *gfxAllocateColours(s32 count);
void *gfxAllocate(u32 size);
void func0f167a18(void);
#endif

View File

@ -0,0 +1,15 @@
#ifndef _IN_GAME_GFXMEMORY_H
#define _IN_GAME_GFXMEMORY_H
#include <ultra64.h>
#include "types.h"
void gfxInitMemory(void);
Gfx *gfxGetMasterDisplayList(void);
struct gfxvtx *gfxAllocateVertices(s32 count);
void *gfxAllocateMatrix(void);
void *gfxAllocate4Words(s32 count);
u32 *gfxAllocateColours(s32 count);
void *gfxAllocate(u32 size);
void gfxSwapBuffers(void);
#endif

View File

@ -759,8 +759,8 @@ extern struct fileinfo g_FileInfo[NUM_FILES];
extern u8 *g_GfxBuffers[3];
extern u8 *g_VtxBuffers[3];
extern u8 *g_GfxMemPos;
extern u8 var800aa5a0;
extern u32 var800aa5a4;
extern u8 g_GfxActiveBufferIndex;
extern u32 g_GfxRequestedDisplayList;
extern struct audiohandle *g_BoostAndSlayerAudioHandles[3];
extern s32 g_BoostAndSlayerActiveTypes[3];
extern u32 var800aa5cc;

View File

@ -2611,7 +2611,7 @@ struct player {
/*0x1738*/ void *unk1738;
/*0x173c*/ Mtx *unk173c;
/*0x1740*/ Mtxf *matrix1740;
/*0x1744*/ u32 unk1744;
/*0x1744*/ u32 c_viewfmdynticknum;
/*0x1748*/ u32 unk1748;
/*0x174c*/ Mtxf *unk174c;
/*0x1750*/ void *unk1750;
@ -2619,7 +2619,7 @@ struct player {
/*0x1758*/ Mtx *unk1758;
/*0x175c*/ void *unk175c;
/*0x1760*/ Mtxf *prev1740;
/*0x1764*/ u32 unk1764;
/*0x1764*/ u32 c_prevviewfmdynticknum;
/*0x1768*/ Mtxf *unk1768;
/*0x176c*/ f32 c_scalelod60;
/*0x1770*/ f32 c_scalelod;

View File

@ -34,7 +34,7 @@
#include "game/endscreen.h"
#include "game/game_127910.h"
#include "game/game_1531a0.h"
#include "game/game_166e40.h"
#include "game/gfxmemory.h"
#include "game/game_167ae0.h"
#include "game/timing.h"
#include "game/music.h"
@ -1031,7 +1031,7 @@ void mainLoop(void)
func0f187944();
}
func0f167350();
gfxInitMemory();
func00013dfc();
func00013798();
func0f17608c(g_StageNum);
@ -1131,7 +1131,7 @@ void mainTick(void)
}
if (var8005d9c8) {
func0f167a18();
gfxSwapBuffers();
func0000a044();
}