Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/SB/Core/gc/iModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <rwcore.h>
#include <rpworld.h>

void iModelInit();
U32 iModelNumBones(RpAtomic* model);
S32 iModelCull(RpAtomic* model, RwMatrixTag* mat);
S32 iModelSphereCull(xSphere* sphere);
Expand All @@ -17,6 +18,7 @@ S32 iModelCullPlusShadow(RpAtomic* model, RwMatrix* mat, xVec3* shadowVec, S32*
void iModelTagEval(RpAtomic* model, const xModelTag* tag, RwMatrixTag* mat, xVec3* dest);
U32 iModelTagSetup(xModelTag* tag, RpAtomic* model, F32 x, F32 y, F32 z);
void iModelSetMaterialAlpha(RpAtomic* model, U8 alpha);
U32 iModelVertCount(RpAtomic* model);
void iModelMaterialMul(RpAtomic* model, F32 rm, F32 gm, F32 bm);
RpAtomic* iModelFileNew(void* buffer, U32 size);
void iModelRender(RpAtomic* model, RwMatrix* mat);
Expand Down
2 changes: 2 additions & 0 deletions src/SB/Core/x/xAnim.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,15 @@ void xAnimDefaultBeforeEnter(xAnimPlay* play, xAnimState* state);
void xAnimPoolInit(xMemPool* pool, U32 count, U32 singles, U32 blendFlags, U32 effectMax);
xAnimPlay* xAnimPoolAlloc(xMemPool* pool, void* object, xAnimTable* table,
xModelInstance* modelInst);
void xAnimPoolFree(xAnimPlay*);
xAnimState* xAnimTableGetState(xAnimTable* table, const char* name);
void xAnimTableAddTransition(xAnimTable* table, xAnimTransition* tran, const char* source);
void xAnimTableAddFile(xAnimTable* table, xAnimFile* file, const char* states);
xAnimState* xAnimTableAddFileID(xAnimTable* table, xAnimFile* file, U32 stateID, U32 subStateID,
U32 subStateCount);
xAnimState* xAnimTableGetStateID(xAnimTable* table, U32 ID);
void xAnimPlaySetState(xAnimSingle* single, xAnimState* state, F32 startTime);
void xAnimPlayChooseTransition(xAnimPlay* play);
void xAnimPlayStartTransition(xAnimPlay* play, xAnimTransition* transition);
void xAnimPlayUpdate(xAnimPlay* play, F32 timeDelta);
void xAnimPlayEval(xAnimPlay* play);
Expand Down
226 changes: 226 additions & 0 deletions src/SB/Core/x/xModel.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,229 @@
#include "iModel.h"
#include "xModel.h"

#include <types.h>

static xModelPool* sxModelPoolList;
static RwCamera* subcamera;
S32 xModelBucketEnabled;

static RwCamera* CameraCreate(int a, int b, int c);
void CameraDestroy(RwCamera* cam);

U32 xModelGetPipeFlags(RpAtomic* model)
{
for (int i = 0; i < xModelLookupCount; i++)
{
if (xModelLookupList[i].model == model)
{
return xModelLookupList[i].PipeFlags;
}
}
return NULL;
}

// Equivalent (regalloc)
void xModelInit()
{
iModelInit();
sxModelPoolList = NULL;
if (subcamera == NULL)
{
subcamera = CameraCreate(0,0,1);
}
xModelPipeNumTables = 0;
}

static xModelInstance* FindChild(xModelInstance* model)
{
xModelInstance* child = model->Next;
while (child != NULL)
{
if (child->Parent == model)
{
return child;
}
child = child->Next;
}
return NULL;
}

void xModelInstanceFree(xModelInstance* model)
{
xModelInstance* prev;
xModelInstance* curr;

while (prev = FindChild(model), prev != NULL)
{
xModelInstanceFree(prev);
}
prev = model->Parent;
if (prev != NULL)
{
for (curr = prev->Next; (curr != NULL) && (curr != model); curr = curr->Next)
{
prev = curr;
}
prev->Next = curr->Next;
}
if (model->Anim != NULL)
{
xAnimPoolFree(model->Anim);
model->Anim = NULL;
}
if (model->Pool != NULL)
{
model->Next = model->Pool->List;
model->Pool->List = model;
}
}

void xModelInstanceAttach(xModelInstance* inst, xModelInstance* parent)
{
xModelInstance* curr = parent;
while (curr->Next != NULL)
{
curr = curr->Next;
}
curr->Next = inst;
inst->Parent = parent;
if ((inst->Flags & 0x2000) != 0)
{
inst->Mat = parent->Mat;
}
}

void xModelUpdate(xModelInstance* modelInst, F32 timeDelta)
{
for (; modelInst != NULL; modelInst = modelInst->Next)
{
if (modelInst->Anim != NULL)
{
if ((modelInst->Flags & 4) != 0)
{
if ((modelInst->Flags & 0x100) != 0)
{
xAnimPlayChooseTransition(modelInst->Anim);
}
xAnimPlayUpdate(modelInst->Anim, timeDelta);
}
}
}
}

void xModelEvalSingle(xModelInstance* model);

void xModelEval(xModelInstance* model)
{
while (model != NULL)
{
xModelEvalSingle(model);
model = model->Next;
}
}

void xModelRender(xModelInstance* model)
{
while (model != NULL)
{
if (xModelBucketEnabled)
{
xModelBucket_Add(model);
}
else
{
xModelRenderSingle(model);
}
model = model->Next;
}
}

static RwCamera* CameraCreate(int a, int b, int c)
{
RwCamera* camera = RwCameraCreate();
if (camera != NULL)
{
_rwObjectHasFrameSetFrame(camera, RwFrameCreate());
camera->frameBuffer = RwRasterCreate(a, b, 0, 2);
if (c != 0)
{
camera->zBuffer = RwRasterCreate(a, b, 0, 1);
}
if (camera->object.object.parent != NULL)
{
if (camera->frameBuffer != NULL)
{
if ((c == 0) || (camera->zBuffer != NULL))
{
return camera;
}
}
}
}
CameraDestroy(camera);
return NULL;
}

void CameraDestroy(RwCamera* cam)
{
RwFrame* frame;
if (cam != NULL)
{
_rwFrameSyncDirty();
frame = (RwFrame*)cam->object.object.parent;
if (frame != NULL)
{
_rwObjectHasFrameSetFrame(cam, 0);
RwFrameDestroy(frame);
}
if (cam->frameBuffer != NULL)
{
RwRasterDestroy(cam->frameBuffer);
cam->frameBuffer = NULL;
}
if (cam->zBuffer != NULL)
{
RwRasterDestroy(cam->zBuffer);
cam->zBuffer = NULL;
}
RwCameraDestroy(cam);
}
}

void xModelSetMaterialAlpha(xModelInstance* model, U8 alpha)
{
iModelSetMaterialAlpha(model->Data, alpha);
}

void xModelMaterialMul(xModelInstance* model, F32 rm, F32 gm, F32 bm)
{
iModelMaterialMul(model->Data, rm, gm, bm);
}

void xModelResetMaterial(xModelInstance* model)
{
iModelResetMaterial(model->Data);
}

void xModel_SceneEnter(RpWorld* world)
{
RpWorldAddCamera(world, subcamera);
}

void xModel_SceneExit(RpWorld* world)
{
RpWorldRemoveCamera(world, subcamera);
}

void xModelAnimCollStart(xModelInstance& model)
{
model.Flags = (model.Flags & ~0x1000) | 0x800;
if (model.anim_coll.verts == NULL)
{
U32 size = iModelVertCount(model.Data);
if (size != 0)
{
model.anim_coll.verts = (xVec3*)xMemAlloc(gActiveHeap, size * sizeof(xVec3), 0);
}
}
}
2 changes: 2 additions & 0 deletions src/SB/Core/x/xModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "xSurface.h"
#include "xMath3.h"
#include "xMath2.h"
#include "xModelBucket.h"

struct xModelBucket;

Expand Down Expand Up @@ -138,6 +139,7 @@ xModelInstance* xModelInstanceAlloc(RpAtomic* data, void* object, U16 flags, U8
void xModelInstanceFree(xModelInstance* modelInst);
void xModelInstanceAttach(xModelInstance* inst, xModelInstance* parent);
void xModelRender(xModelInstance* modelInst);
void xModelRenderSingle(xModelInstance * modelInst);
void xModelRender2D(const xModelInstance& model, const basic_rect<F32>& r, const xVec3& from,
const xVec3& to);
void xModelSetMaterialAlpha(xModelInstance* modelInst, U8 alpha);
Expand Down
2 changes: 2 additions & 0 deletions src/SB/Core/x/xModelBucket.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ struct xModelAlphaBucket
U32 Layer;
};

extern S32 xModelBucketEnabled;

void xModelBucket_RenderAlpha();

S32 CmpAlphaBucket(const void* _a, const void* _b);
Expand Down