Remove vtxstore

This commit is contained in:
Ryan Dwyer
2022-11-05 21:44:46 +10:00
parent c9d8cf7016
commit 6dd1136477
8 changed files with 0 additions and 533 deletions
-2
View File
@@ -33,7 +33,6 @@
build/ROMID/game/wallhitreset.o (section); \
build/ROMID/game/shardsreset.o (section); \
build/ROMID/game/surfacereset.o (section); \
build/ROMID/game/vtxstorereset.o (section); \
build/ROMID/game/tilesreset.o (section); \
build/ROMID/game/roomreset.o (section); \
build/ROMID/game/setupcover.o (section); \
@@ -133,7 +132,6 @@
build/ROMID/game/playermgr.o (section); \
build/ROMID/game/crc.o (section); \
build/ROMID/game/rng2.o (section); \
build/ROMID/game/vtxstore.o (section); \
build/ROMID/game/explosions.o (section); \
build/ROMID/game/smoke.o (section); \
build/ROMID/game/sparks.o (section); \
-58
View File
@@ -18,7 +18,6 @@
#include "game/game_0c33f0.h"
#include "game/playermgr.h"
#include "game/game_1291b0.h"
#include "game/vtxstore.h"
#include "game/gfxmemory.h"
#include "game/explosions.h"
#include "game/smoke.h"
@@ -1223,7 +1222,6 @@ void chrRemove(struct prop *prop, bool delete)
wallhitFadeSplatsForRemovedChr(prop);
func0f0926bc(prop, 1, 0xffff);
shieldhitsRemoveByProp(prop);
modelFreeVertices(VTXSTORETYPE_CHRVTX, model);
propDeregisterRooms(prop);
child = prop->child;
@@ -3922,23 +3920,6 @@ void chr0f0260c4(struct model *model, s32 hitpart, struct modelnode *node, struc
if (x == bestcoords[0] && y == bestcoords[1] && z == bestcoords[2]) {
u32 tmp = ALIGN8((u32)&rodata->vertices[(u32)rodata->numvertices]); // u32 0xc
if ((u32)rwdata->colours == tmp) {
struct colour *colours = vtxstoreAllocate(rodata->numcolours, VTXSTORETYPE_CHRCOL, 0, 0);
s32 j;
if (colours) {
for (j = 0; j < rodata->numcolours; j++) {
colours[j] = rwdata->colours[j];
}
rwdata->colours = colours;
tmp = ALIGN8((s32)&rodata->vertices[rodata->numvertices]); // s32 0xc
} else {
tmp = ALIGN8((s32)&rodata->vertices[rodata->numvertices]); // s32 0xc
}
}
if ((u32)rwdata->colours != tmp) {
u32 offset = rwdata->vertices[word / 12u + i].colour >> 2; // u32 0xc (both divide and mult)
struct colour *colours = (struct colour *) ((u32)rwdata->colours + spac);
@@ -4223,19 +4204,6 @@ void chrBruise(struct model *model, s32 hitpart, struct modelnode *node, struct
coordinate = vertices[i].z + (s32)spd4.f[2];
if (coordinate == bestcoords[2]) {
if ((u32)rwdata->colours == ALIGN8((u32)rodata->vertices + rodata->numvertices * sizeof(struct gfxvtx))) {
struct colour *colours = vtxstoreAllocate(rodata->numcolours, VTXSTORETYPE_CHRCOL, 0, 0);
s32 j;
if (colours) {
for (j = 0; j < rodata->numcolours; j++) {
colours[j] = rwdata->colours[j];
}
rwdata->colours = colours;
}
}
if ((u32)rwdata->colours != ALIGN8((u32)rodata->vertices + rodata->numvertices * sizeof(struct gfxvtx))) {
s32 offset = rwdata->vertices[word / sizeof(struct gfxvtx) + i].colour >> 2;
struct colour *colours = (struct colour *) ((u32)rwdata->colours + spac);
@@ -4339,32 +4307,6 @@ void chrDisfigure(struct chrdata *chr, struct coord *exppos, f32 damageradius)
// Check that the node is using the modeldef's vertices
// (ie. we haven't disfigured this node already)
if (rwdata->vertices == rodata->vertices) {
// Copy the vertices from the modeldef to the vtxstore
if (rwdata->vertices == rodata->vertices) {
struct gfxvtx *vertices = vtxstoreAllocate(rodata->numvertices, VTXSTORETYPE_CHRVTX, 0, 0);
if (vertices) {
for (i = 0; i < rodata->numvertices; i++) {
vertices[i] = rwdata->vertices[i];
}
rwdata->vertices = vertices;
}
}
// Copy the colours from the modeldef to the vtxstore
if ((u32)rwdata->colours == ALIGN8((u32)&rodata->vertices[rodata->numvertices])) {
colours = vtxstoreAllocate(rodata->numcolours, VTXSTORETYPE_CHRCOL, 0, 0);
if (colours) {
for (i = 0; i < rodata->numcolours; i++) {
colours[i] = rwdata->colours[i];
}
rwdata->colours = colours;
}
}
// Iterate the node's primary and secondary DLs, looking for
// MTX and VTX pointers
if (rwdata->vertices != rodata->vertices
-3
View File
@@ -71,7 +71,6 @@
#include "game/tiles.h"
#include "game/title.h"
#include "game/utils.h"
#include "game/vtxstore.h"
#include "game/wallhit.h"
#include "lib/anim.h"
#include "lib/args.h"
@@ -347,7 +346,6 @@ void lvReset(s32 stagenum)
mpSetDefaultNamesIfEmpty();
animsReset();
vtxstoreReset();
modelmgrReset();
propsndReset();
setupLoadFiles(stagenum);
@@ -1752,7 +1750,6 @@ void lvTick(void)
langTick();
pakExecuteDebugOperations();
} else {
vtxstoreTick();
lvUpdateSoloHandicaps();
roomsTick();
skyTick();
-182
View File
@@ -30,7 +30,6 @@
#include "game/inv.h"
#include "game/playermgr.h"
#include "game/game_1291b0.h"
#include "game/vtxstore.h"
#include "game/explosions.h"
#include "game/smoke.h"
#include "game/sparks.h"
@@ -2145,10 +2144,6 @@ void objFree(struct defaultobj *obj, bool freeprop, bool canregen)
propDeregisterRooms(obj->prop);
if (obj->prop->type != PROPTYPE_DOOR) {
modelFreeVertices(1, obj->model);
}
modelmgrFreeModel(obj->model);
if (freeprop) {
@@ -9546,7 +9541,6 @@ u32 objTick(struct prop *prop)
obj->damage = 0;
obj->hidden2 &= ~OBJH2FLAG_DESTROYED;
modelFreeVertices(1, obj->model);
}
if (obj->type == OBJTYPE_SHIELD) {
@@ -12490,113 +12484,6 @@ void objDeform(struct defaultobj *obj, s32 level)
parent = parent->parent;
}
if (modelIsNodeNotTvscreen(modeldef, node) && parentbbox == bbox) {
struct modelrodata_dl *rodata = &node->rodata->dl;
struct modelrwdata_dl *rwdata = (struct modelrwdata_dl *)&model->rwdatas[rodata->rwdataindex];
struct gfxvtx *vertices = vtxstoreAllocate(rodata->numvertices, VTXSTORETYPE_OBJVTX, node, objGetDestroyedLevel(obj));
if (vertices) {
if (rwdata->vertices != rodata->vertices) {
// Replacing modified vertices with a new set
for (i = 0; i < rodata->numvertices; i++) {
vertices[i] = rwdata->vertices[i];
}
vtxstoreFree(VTXSTORETYPE_OBJVTX, rwdata->vertices);
} else {
// Replacing original vertices with modified vertices
for (i = 0; i < rodata->numvertices; i++) {
vertices[i] = rodata->vertices[i];
}
}
rwdata->vertices = vertices;
} else {
ok = false;
}
if ((u32)rwdata->colours == ALIGN8((u32)&rodata->vertices[rodata->numvertices])) {
struct colour *colours = vtxstoreAllocate(rodata->numcolours, VTXSTORETYPE_OBJCOL, NULL, 0);
if (colours) {
for (i = 0; i < rodata->numcolours; i++) {
colours[i] = rwdata->colours[i];
}
rwdata->colours = colours;
} else {
ok = false;
}
}
if (ok) {
for (i = 0; i < rodata->numcolours; i++) {
if (i > 0) {
rwdata->colours[i].a = 0;
}
}
for (i = 0; i < rodata->numvertices; i++) {
s16 tmp = average;
rng2SetSeed(rodata->vertices[i].x + rodata->vertices[i].y + rodata->vertices[i].z + salt);
#if VERSION < VERSION_NTSC_1_0
if (uninitialisedvariable)
#endif
{
if (swap) {
if (rwdata->vertices[i].v[axis] >= tmp) {
chance = 20;
} else {
chance = 90;
}
} else {
if (rwdata->vertices[i].v[axis] <= tmp) {
chance = 20;
} else {
chance = 90;
}
}
if ((s32)(random2() % 100) < chance) {
rwdata->vertices[i].colour = 0;
}
}
rwdata->vertices[i].x += (s32)(((s32)(random2() % 20) - 10) * spb0[0]);
rwdata->vertices[i].y += (s32)(((s32)(random2() % 20) - 10) * spb0[1]);
rwdata->vertices[i].z += (s32)(((s32)(random2() % 20) - 10) * spb0[2]);
if (parentbbox != NULL) {
if (rwdata->vertices[i].x < (s16)parentbbox->xmin) {
rwdata->vertices[i].x = (s16)parentbbox->xmin;
}
if (rwdata->vertices[i].x > (s16)parentbbox->xmax) {
rwdata->vertices[i].x = (s16)parentbbox->xmax;
}
if (rwdata->vertices[i].y < (s16)parentbbox->ymin) {
rwdata->vertices[i].y = (s16)parentbbox->ymin;
}
if (rwdata->vertices[i].y > (s16)parentbbox->ymax) {
rwdata->vertices[i].y = (s16)parentbbox->ymax;
}
if (rwdata->vertices[i].z < (s16)parentbbox->zmin) {
rwdata->vertices[i].z = (s16)parentbbox->zmin;
}
if (rwdata->vertices[i].z > (s16)parentbbox->zmax) {
rwdata->vertices[i].z = (s16)parentbbox->zmax;
}
}
}
}
}
break;
case MODELNODETYPE_DISTANCE:
model0001c784(obj->model, node);
@@ -12622,14 +12509,6 @@ void objDeform(struct defaultobj *obj, s32 level)
}
}
}
if ((obj->hidden2 & OBJH2FLAG_80) == 0) {
if (!ok) {
modelFreeVertices(VTXSTORETYPE_OBJVTX, model);
} else {
obj->hidden2 |= OBJH2FLAG_80;
}
}
}
/**
@@ -15896,67 +15775,6 @@ s32 objTestForPickup(struct prop *prop)
return TICKOP_NONE;
}
void modelFreeVertices(s32 vtxstoretype, struct model *model)
{
struct modelfiledata *modeldef = model->filedata;
struct modelnode *node = modeldef->rootnode;
while (node) {
u32 type = node->type & 0xff;
union modelrodata *rodata;
union modelrwdata *rwdata;
s32 newtype;
switch (type) {
case MODELNODETYPE_DL:
rodata = node->rodata;
rwdata = modelGetNodeRwData(model, node);
if (modelIsNodeNotTvscreen(modeldef, node)) {
if (rwdata->dl.vertices != rodata->dl.vertices) {
vtxstoreFree(vtxstoretype, rwdata->dl.vertices);
rwdata->dl.vertices = rodata->dl.vertices;
}
if ((u32)rwdata->dl.colours != ALIGN8((u32)rodata->dl.vertices + rodata->dl.numvertices * sizeof(struct gfxvtx))) {
if (vtxstoretype == VTXSTORETYPE_OBJVTX) {
newtype = VTXSTORETYPE_OBJCOL;
} else {
newtype = VTXSTORETYPE_CHRCOL;
}
vtxstoreFree(newtype, rwdata->dl.colours);
rwdata->dl.colours = (struct colour *)ALIGN8((u32)rodata->dl.vertices + rodata->dl.numvertices * sizeof(struct gfxvtx));
}
}
break;
case MODELNODETYPE_DISTANCE:
model0001c784(model, node);
break;
case MODELNODETYPE_TOGGLE:
model0001c7d0(model, node);
break;
case MODELNODETYPE_HEADSPOT:
modelAttachHead(model, node);
break;
}
if (node->child) {
node = node->child;
} else {
while (node) {
if (node->next) {
node = node->next;
break;
}
node = node->parent;
}
}
}
}
struct prop *hatApplyToChr(struct hatobj *hat, struct chrdata *chr, struct modelfiledata *filedata, struct prop *prop, struct model *model)
{
if (chr->model->filedata->skel == &g_SkelChr) {
-1
View File
@@ -17,7 +17,6 @@
#include "game/game_0c33f0.h"
#include "game/playermgr.h"
#include "game/game_1291b0.h"
#include "game/vtxstore.h"
#include "game/gfxmemory.h"
#include "game/explosions.h"
#include "game/smoke.h"
-234
View File
@@ -1,234 +0,0 @@
#include <ultra64.h>
#include "constants.h"
#include "game/chraction.h"
#include "game/chr.h"
#include "game/vtxstore.h"
#include "game/propobj.h"
#include "bss.h"
#include "lib/mema.h"
#include "lib/model.h"
#include "lib/rng.h"
#include "data.h"
#include "types.h"
const char var7f1b5230[] = "VTXSTORE : vtxfixrefs -> Start - p1=%x, p2=%x\n";
const char var7f1b5260[] = "vtxfixrefs : Part=%x -- Mapping ptr %x -> %x\n";
const char var7f1b5290[] = "VTXSTORE : vtxfixrefs -> End - Done=%d\n";
const char var7f1b52b8[] = "vtxstorecheck : memaFree -> %u bytes at Ptr=%x(%x)\n";
const char var7f1b52ec[] = "vtxstorecheck : At block 1 %d -> Ref1=%x, Ref2=%x\n";
const char var7f1b5320[] = "vtxstorecheck : At block 2 %d -> Ref1=%x, Ref2=%x\n";
const char var7f1b5354[] = "vtx buffer low, need to delete objects\n";
const char var7f1b537c[] = "getfreevertices : %d of type %d -> ref1=%x, ref2=%x\n";
const char var7f1b53b4[] = "vtxstore: 1st mema alloc of %u bytes\n";
#if VERSION < VERSION_NTSC_1_0
const char var7f1af8ecnb[] = "vtxstore: Trying to free %d from mema (bgRooms)\n";
#endif
const char var7f1b53dc[] = "getfreevertices : Return ptr = %x\n";
const char var7f1b5400[] = "vtxstore: Out of mema (returning NULL)\n";
const char var7f1b5428[] = "vtxstore: GROSS! CorspeCount > MAX_CORPSES corpses! Freeing corpse %x\n";
const char var7f1b5470[] = "vtxstore: CorpseCount %d, Trying to free %d\n";
const char var7f1b54a0[] = "vtxstore: Freeing corpse %x\n";
const char var7f1b54c0[] = "vtxstore: Out of vertices type %d wanted %d free %d (returning NULL)\n";
const char var7f1b5508[] = "vtxstore: freevertices type %d, list %x\n";
const char var7f1b5534[] = "freevertices: address not found in array %x\n";
struct vtxstoretype g_VtxstoreTypes[] = {
{ 3000, 120, 3000, 80, 0, 0, 500, 20, 12, 0, 0, 0, 0 },
{ 1500, 40, 500, 20, 0, 0, 500, 20, 12, 0, 0, 0, 0 },
{ 6000, 120, 6000, 80, 0, 0, 1000, 20, 4, 0, 0, 0, 0 },
{ 1500, 40, 500, 20, 0, 0, 500, 20, 4, 0, 0, 0, 0 },
};
/**
* Search all props and their model data for something, and replace it with
* something else.
*/
void vtxstoreFixRefs(union modelrwdata *find, union modelrwdata *replacement)
{
u32 stack;
struct prop *prop = g_Vars.activeprops;
while (prop) {
if (prop->type == PROPTYPE_OBJ) {
struct defaultobj *obj = prop->obj;
struct model *model = obj->model;
struct modelfiledata *filedata = model->filedata;
struct modelnode *node = filedata->rootnode;
struct modelrodata_dl *rodata;
while (node) {
switch (node->type & 0xff) {
case MODELNODETYPE_DL:
rodata = &node->rodata->dl;
if (model->rwdatas[rodata->rwdataindex] == find) {
model->rwdatas[rodata->rwdataindex] = replacement;
}
break;
case MODELNODETYPE_DISTANCE:
model0001c784(obj->model, node);
break;
case MODELNODETYPE_TOGGLE:
model0001c7d0(obj->model, node);
break;
case MODELNODETYPE_HEADSPOT:
modelAttachHead(obj->model, node);
break;
}
if (node->child) {
node = node->child;
} else {
while (node) {
if (node->next) {
node = node->next;
break;
}
node = node->parent;
}
}
}
}
prop = prop->next;
}
}
void vtxstoreTick(void)
{
s32 i;
s32 j;
if (g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].val2 < g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].val1 >> 2) {
for (i = 0; i < g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].numallocated - 1; i++) {
if (g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[i].unk0e > 0) {
for (j = i + 1; j < g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].numallocated; j++) {
if (g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[j].unk0e > 0
&& g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[i].node == g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[j].node
&& g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[i].level == g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[j].level) {
s32 size = ALIGN16(g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[j].count * 0x0c);
vtxstoreFixRefs(g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[j].unk00, g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[i].unk00);
g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[i].unk0e += g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[j].unk0e;
memaFree(g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[j].unk00, size);
g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[j].unk0e = 0;
g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].val2 += g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].unk24[j].count;
}
}
}
}
}
if (g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].val2 < g_VtxstoreTypes[VTXSTORETYPE_OBJVTX].val1 >> 2) {
func0f091030();
}
}
void *vtxstoreAllocate(s32 count, s32 index, struct modelnode *node, s32 level)
{
s32 i;
s32 numchrs;
s32 tally;
s32 rand;
u32 size;
struct chrdata *chrs[6];
#if VERSION >= VERSION_NTSC_1_0
if (IS4MB()) {
return NULL;
}
#endif
if (count <= g_VtxstoreTypes[index].val2) {
for (i = 0; i < g_VtxstoreTypes[index].numallocated; i++) {
if (g_VtxstoreTypes[index].unk24[i].unk0e == 0) {
size = ALIGN16(count * 0xc);
g_VtxstoreTypes[index].unk24[i].unk00 = memaAlloc(size);
#if VERSION < VERSION_NTSC_1_0
if (!g_VtxstoreTypes[index].unk24[i].unk00) {
bgGarbageCollectRooms(size, false);
g_VtxstoreTypes[index].unk24[i].unk00 = memaAlloc(size);
}
#endif
if (g_VtxstoreTypes[index].unk24[i].unk00) {
g_VtxstoreTypes[index].unk24[i].count = count;
g_VtxstoreTypes[index].unk24[i].unk0e = 1;
g_VtxstoreTypes[index].unk24[i].node = node;
g_VtxstoreTypes[index].unk24[i].level = level;
g_VtxstoreTypes[index].val2 -= count;
return g_VtxstoreTypes[index].unk24[i].unk00;
}
return NULL;
}
}
}
// Build an array of all corpses. If the array becomes full then enable
// reaping on a random corpse and replace its entry in the array.
// So at the end, we'll have an array of up to six unreapable corpses and
// all other corpses will be flagged for reaping.
numchrs = chrsGetNumSlots();
tally = 0;
for (i = 0; i < numchrs; i++) {
struct chrdata *chr = &g_ChrSlots[i];
if (chr->model
&& chr->prop
&& (chr->prop->flags & PROPFLAG_ONANYSCREENPREVTICK) == 0
&& chr->actiontype == ACT_DEAD
&& chr->act_dead.fadewheninvis == false) {
if (tally < 6) {
chrs[tally] = chr;
tally++;
} else {
rand = random() % tally;
chrFadeCorpseWhenOffScreen(chrs[rand]);
chrs[rand] = chr;
}
}
}
// Enable reaping on half the remaining corpses.
// I'm reusing the rand and i variables here in order to get a match.
// The original code likely didn't reuse them.
rand = tally >> 1;
while (rand) {
i = random() % tally;
if (chrs[i]) {
chrFadeCorpseWhenOffScreen(chrs[i]);
chrs[i] = NULL;
rand--;
}
}
return NULL;
}
void vtxstoreFree(s32 type, void *arg1)
{
s32 i;
for (i = 0; i < g_VtxstoreTypes[type].numallocated; i++) {
if (g_VtxstoreTypes[type].unk24[i].unk0e > 0 && arg1 == g_VtxstoreTypes[type].unk24[i].unk00) {
g_VtxstoreTypes[type].unk24[i].unk0e--;
if (g_VtxstoreTypes[type].unk24[i].unk0e) {
return;
}
memaFree(g_VtxstoreTypes[type].unk24[i].unk00, ALIGN16(g_VtxstoreTypes[type].unk24[i].count * 0xc));
g_VtxstoreTypes[type].val2 += g_VtxstoreTypes[type].unk24[i].count;
return;
}
}
}
-39
View File
@@ -1,39 +0,0 @@
#include <ultra64.h>
#include "constants.h"
#include "bss.h"
#include "lib/memp.h"
#include "data.h"
#include "types.h"
void vtxstoreReset(void)
{
s32 i;
s32 j;
s32 num;
s32 val;
for (i = 0; i < 4; i++) {
if (PLAYERCOUNT() >= 2) {
val = g_VtxstoreTypes[i].valifmp;
num = g_VtxstoreTypes[i].numifmp;
} else if (g_Vars.stagenum >= STAGE_TITLE) {
val = g_VtxstoreTypes[i].valifspecial;
num = g_VtxstoreTypes[i].numifspecial;
} else {
val = g_VtxstoreTypes[i].valifsp;
num = g_VtxstoreTypes[i].numifsp;
}
if (num > 0) {
g_VtxstoreTypes[i].unk24 = mempAlloc(num * sizeof(struct var8007e3d0_data), MEMPOOL_STAGE);
}
for (j = 0; j < num; j++) {
g_VtxstoreTypes[i].unk24[j].unk0e = 0;
}
g_VtxstoreTypes[i].numallocated = num;
g_VtxstoreTypes[i].val1 = val;
g_VtxstoreTypes[i].val2 = val;
}
}
-14
View File
@@ -1,14 +0,0 @@
#ifndef _IN_GAME_GAME_129210_H
#define _IN_GAME_GAME_129210_H
#include <ultra64.h>
#include "data.h"
#include "types.h"
void vtxstoreReset(void);
void vtxstoreFixRefs(union modelrwdata *find, union modelrwdata *replacement);
void vtxstoreTick(void);
void *vtxstoreAllocate(s32 count, s32 index, struct modelnode *node, s32 level);
void vtxstoreFree(s32 type, void *arg1);
#endif