Skip to content

Commit

Permalink
Assorted matches, including ports from rat (bfbbdecomp#367)
Browse files Browse the repository at this point in the history
zNPC related matches

More stuff
  • Loading branch information
escape209 committed Sep 21, 2024
1 parent ef0b45a commit 3d9bb60
Show file tree
Hide file tree
Showing 20 changed files with 750 additions and 32 deletions.
9 changes: 9 additions & 0 deletions src/SB/Core/gc/iColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ struct iColor_tag
U8 g;
U8 b;
U8 a;

iColor_tag& operator=(const iColor_tag& rhs)
{
this->r = rhs.r;
this->g = rhs.g;
this->b = rhs.b;
this->a = rhs.a;
return *this;
};
};

#endif
8 changes: 8 additions & 0 deletions src/SB/Core/gc/iMorph.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#ifndef IMORPH_H
#define IMORPH_H

#include "types.h"

#include <rwcore.h>
#include <rpworld.h>

void iMorphOptimize(RpAtomic* model, S32 normals);
void iMorphRender(RpAtomic* model, RwMatrix* mat, S16** v_array, S16* weight, U32 normals, F32 scale);

#endif
14 changes: 8 additions & 6 deletions src/SB/Core/x/xDebug.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#include "xDebug.h"
#include "xFont.h"

#include "iColor.h"

#include <types.h>

U32 gFrameCount;

extern F32 _781; // 0.0020833334f.
extern F32 _783; // 0.0015625f.
// Remaining weak definitions will match once referenced e.g. iColor_tag::operator=

void xprintf(const char* msg, ...)
{
// Redacted. :}
}

S32 xDebugModeAdd(char* mode, void(*debugFunc))
S32 xDebugModeAdd(const char* mode, void(*debugFunc)())
{
// Redacted. :}
return -1;
Expand Down Expand Up @@ -45,10 +47,10 @@ void xtextbox::render(bool cache) const

F32 NSCREENY(F32 scale)
{
return _781 * scale;
return (1.0f / 480) * scale;
}

F32 NSCREENX(F32 scale)
{
return _783 * scale;
}
return (1.0f / 640) * scale;
}
1 change: 1 addition & 0 deletions src/SB/Core/x/xFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void xFXFireworksUpdate(F32 dt);
void xFXStreakInit();
void xFXStreakUpdate(F32 dt);
void xFXStreakRender();
void xFXStreakStop(U32);
void xFXShineInit();
void xFXShineUpdate(F32 dt);
void xFXShineRender();
Expand Down
17 changes: 17 additions & 0 deletions src/SB/Core/x/xFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ struct xfont
void irender(const char* text, F32 x, F32 y) const;
void irender(const char* text, size_t text_size, F32 x, F32 y) const;
void render(const char* text, F32 x, F32 y) const;

xfont& operator=(const xfont& rhs)
{
id = rhs.id;
width = rhs.width;
height = rhs.height;
space = rhs.space;

*(U32*)(&color) = *(U32*)(&rhs.color);

*(U32*)(&clip.x) = *(U32*)(&rhs.clip.x);
*(U32*)(&clip.y) = *(U32*)(&rhs.clip.y);
*(U32*)(&clip.w) = *(U32*)(&rhs.clip.w);
*(U32*)(&clip.h) = *(U32*)(&rhs.clip.h);

return *this;
}
};

struct xtextbox
Expand Down
121 changes: 120 additions & 1 deletion src/SB/Core/x/xMorph.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,122 @@
#include "xMorph.h"

#include <types.h>
#include "xDebug.h"
#include "iModel.h"

#include <string.h>

xMorphSeqFile* xMorphSeqSetup(void* data, xMorphFindAssetCallback FindAssetCB)
{
S32 i, j;
RpAtomic* model;
xMorphTargetFile* mphtgt;
xMorphSeqFile* header;
F32* timelist;
xMorphFrame* framelist;
U32* assetlist;
char* namelist;
void* assetPtr;
U32 skipsize;

header = (xMorphSeqFile*)data;
timelist = (F32*)(header + 1);
framelist = (xMorphFrame*)(timelist + header->TimeCount);
assetlist = (U32*)(framelist + header->TimeCount);
namelist = (char*)(assetlist + header->ModelCount * 2);

if (header->Flags & 0x80000000) {
return header;
}

header->Flags |= 0x80000000;
if (!(header->Flags & 0x1)) {
namelist = NULL;
}

for (i = 0; i < (S32)header->ModelCount * 2; i++) {
if (assetlist[i]) {
assetPtr = FindAssetCB(assetlist[i], namelist);
assetlist[i] = (U32)assetPtr;
}
if (namelist) {
namelist = strlen(namelist) + 1 + namelist;
}
}

for (i = 0; i < (S32)header->ModelCount; i++) {
if (assetlist[i*2+1]) {
model = (RpAtomic*)assetlist[i*2];
mphtgt = (xMorphTargetFile*)assetlist[i*2+1];
iMorphOptimize(model, mphtgt->Flags & 0x1);
}
}

for (i = 0; i < (S32)header->TimeCount; i++) {
model = (RpAtomic*)assetlist[(U32)framelist[i].Model*2];
mphtgt = (xMorphTargetFile*)assetlist[(U32)framelist[i].Model*2+1];
framelist[i].Model = model;
for (j = 0; j < 4; j++) {
if ((U32)framelist[i].Targets[j] + 0x10000 == 0xFFFF) {
framelist[i].Targets[j] = NULL;
} else {
skipsize = (mphtgt->NumVerts * 3 + 7) & ~7;
if (mphtgt->Flags & 0x1) {
skipsize *= 2;
}
if (j == 0) {
framelist[i].Flags = mphtgt->Flags;
framelist[i].NumVerts = mphtgt->NumVerts;
framelist[i].Scale *= mphtgt->Scale;
}
framelist[i].Targets[j] = (S16*)((U8*)(mphtgt + 1) + skipsize * (U32)framelist[i].Targets[j] * 2);
}
}
}

return header;
}

void xMorphRender(xMorphSeqFile* seq, RwMatrix* mat, F32 time)
{
F32 lerp;
U32 tidx, tcount;
S16 weight[4];
S16* wptr;
F32* times;
xMorphFrame* frame;

times = (F32*)(seq + 1);
tcount = seq->TimeCount;
frame = (xMorphFrame*)(times + seq->TimeCount);

if (time < 0.0f) time = 0.0f;
if (time > times[tcount-1]) time = times[tcount-1];

tidx = (tcount-1) & 0x3;
while (times[tidx] < time) tidx += 4;
while (tidx && time < times[tidx]) tidx--;

frame += tidx;

if (!frame->Targets[0]) {
iModelRender(frame->Model, mat);
} else {
lerp = frame->RecipTime * (time - times[tidx]);
if (lerp == 0.0f) {
wptr = frame->WeightStart;
} else {
weight[0] = (S32)(lerp * (frame->WeightEnd[0] - frame->WeightStart[0])) + frame->WeightStart[0],
weight[1] = (S32)(lerp * (frame->WeightEnd[1] - frame->WeightStart[1])) + frame->WeightStart[1],
weight[2] = (S32)(lerp * (frame->WeightEnd[2] - frame->WeightStart[2])) + frame->WeightStart[2],
weight[3] = (S32)(lerp * (frame->WeightEnd[3] - frame->WeightStart[3])) + frame->WeightStart[3];
wptr = weight;
}

iMorphRender(frame->Model, mat, frame->Targets, wptr, frame->Flags & 0x1, frame->Scale);
}
}

F32 xMorphSeqDuration(xMorphSeqFile* seq)
{
return ((F32*)(seq+1))[seq->TimeCount-1];
}
43 changes: 43 additions & 0 deletions src/SB/Core/x/xMorph.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
#ifndef XMORPH_H
#define XMORPH_H

#include "iMorph.h"
#include "xMath3.h"

#include <rwcore.h>
#include <rpworld.h>

struct xMorphSeqFile
{
U32 Magic;
U32 Flags;
U32 TimeCount;
U32 ModelCount;
};

struct xMorphFrame
{
RpAtomic* Model;
F32 RecipTime;
F32 Scale;
U16 Flags;
U16 NumVerts;
S16* Targets[4];
S16 WeightStart[4];
S16 WeightEnd[4];
};

struct xMorphTargetFile
{
U32 Magic;
U16 NumTargets;
U16 NumVerts;
U32 Flags;
F32 Scale;
xVec3 Center;
F32 Radius;
};

typedef void*(*xMorphFindAssetCallback)(U32, char*);

xMorphSeqFile* xMorphSeqSetup(void* data, xMorphFindAssetCallback FindAssetCB);
void xMorphRender(xMorphSeqFile* seq, RwMatrix* mat, F32 time);
F32 xMorphSeqDuration(xMorphSeqFile* seq);

#endif
38 changes: 37 additions & 1 deletion src/SB/Core/x/xMovePoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,42 @@ void xMovePointSplineDestroy(xMovePoint* m)
}
}

void xMovePointSplineSetup(xMovePoint* m)
{
xMovePoint* w0, *w1, *w2, *w3;
xVec3 points[2];
xVec3 p1, p2;

if (m->asset->bezIndex != 1) return;
if (m->spl) return;

w0 = m->prev;
w1 = m;
w2 = m->nodes[0];

points[0] = *w0->pos;
if (w2->asset->bezIndex > 0)
{
w3 = w2->nodes[0];
p1 = *w1->pos;
p2 = *w2->pos;
points[1] = *w3->pos;
}
else
{
p1.x = (1/3.f) * w0->pos->x + (2/3.f) * w1->pos->x;
p1.y = (1/3.f) * w0->pos->y + (2/3.f) * w1->pos->y;
p1.z = (1/3.f) * w0->pos->z + (2/3.f) * w1->pos->z;
p2.x = (2/3.f) * w1->pos->x + (1/3.f) * w2->pos->x;
p2.y = (2/3.f) * w1->pos->y + (1/3.f) * w2->pos->y;
p2.z = (2/3.f) * w1->pos->z + (1/3.f) * w2->pos->z;
points[1] = *w2->pos;
}

m->spl = xSpline3_Bezier(points, NULL, 2, 0, &p1, &p2);
xSpline3_ArcInit(m->spl, 20);
}

#if 0
// If you uncomment the numPoints variable then this function is a perfect match
// minus ordering. In the original assembly some variable fetches are lifted to
Expand Down Expand Up @@ -138,7 +174,7 @@ F32 xMovePointGetNext(xMovePoint* m, xMovePoint* prev, xMovePoint** next, xVec3*
}
#endif

xVec3* xMovePointGetPos(xMovePoint* m)
xVec3* xMovePointGetPos(const xMovePoint* m)
{
return m->pos;
}
32 changes: 32 additions & 0 deletions src/SB/Core/x/xPad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,38 @@ void xPadRumbleEnable(S32 idx, S32 enable)
}
}

void xPadAnalogIsDigital(S32 idx, S32 enable)
{
if (idx != 0)
return;

_tagxPad* pad = &mPad[idx];

if (enable)
{
pad->flags |= 0x10;
}
else
{
pad->flags &= ~0x10;
}

if (pad->al2d_timer >= 0.35f)
{
pad->al2d_timer = 0.35f;
}

if (pad->ar2d_timer >= 0.35f)
{
pad->ar2d_timer = 0.35f;
}

if (pad->d_timer >= 0.35f)
{
pad->d_timer = 0.35f;
}
}

void xPadKill()
{
iPadKill();
Expand Down
2 changes: 2 additions & 0 deletions src/SB/Core/x/xPad.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ void xPadDestroyRumbleChain(_tagxPad* pad);
void xPadDestroyRumbleChain(S32 idx);
S32 xPadAddRumble(S32 idx, _tagRumbleType type, F32 time, S32 replace, U32 fxflags);

void xPadAnalogIsDigital(F32, F32);

#endif
5 changes: 4 additions & 1 deletion src/SB/Core/x/xRenderState.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "xRenderState.h"

extern int sBlendTable[11];
static int sBlendTable[11] =
{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
};

void xRenderStateSetTexture(RwTexture* texture)
{
Expand Down
3 changes: 3 additions & 0 deletions src/SB/Core/x/xSpline.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ struct xSpline3
F32* arcLength;
};

void xSpline3_ArcInit(xSpline3* spl, U32 sample);
xSpline3* xSpline3_Bezier(xVec3* points, F32* time, U32 numpoints, U32 numalloc, xVec3* p1, xVec3* p2);

#endif
Loading

0 comments on commit 3d9bb60

Please sign in to comment.