Skip to content

Commit

Permalink
m_anmChr OK
Browse files Browse the repository at this point in the history
  • Loading branch information
robojumper committed Jun 21, 2024
1 parent 95f5bbf commit 66fec2e
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 22 deletions.
2 changes: 2 additions & 0 deletions config/SOUE01/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ m/m3d/m3d.cpp:

m/m3d/m_anmchr.cpp:
.text start:0x802E48E0 end:0x802E4D98
.data start:0x805424D0 end:0x805424E8
.sdata2 start:0x8057CCC0 end:0x8057CCD0

m/m3d/m_anmtexsrt.cpp:
.text start:0x802E6EC0 end:0x802E7A54
Expand Down
8 changes: 4 additions & 4 deletions config/SOUE01/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24613,7 +24613,7 @@ fn_80448460 = .text:0x80448460; // type:function size:0x178
fn_804485E0 = .text:0x804485E0; // type:function size:0x640
fn_80448C20 = .text:0x80448C20; // type:function size:0x10
fn_80448C30 = .text:0x80448C30; // type:function size:0x10
fn_80448C40 = .text:0x80448C40; // type:function size:0x1F0
Construct__Q34nw4r3g3d12AnmObjChrResFP12MEMAllocatorPUlQ34nw4r3g3d9ResAnmChrQ34nw4r3g3d6ResMdlb = .text:0x80448C40; // type:function size:0x1F0
fn_80448E30 = .text:0x80448E30; // type:function size:0xC0
fn_80448EF0 = .text:0x80448EF0; // type:function size:0x8
fn_80448F00 = .text:0x80448F00; // type:function size:0xB4
Expand Down Expand Up @@ -29102,9 +29102,9 @@ lbl_804F7180 = .rodata:0x804F7180; // type:object size:0x18
TYPE_NAME__Q34nw4r3g3d20AnmObjTexSrtOverride = .rodata:0x804F7198; // type:object size:0x20
TYPE_NAME__Q34nw4r3g3d15AnmObjTexSrtRes = .rodata:0x804F71B8; // type:object size:0x18
lbl_804F71D0 = .rodata:0x804F71D0; // type:object size:0x10
lbl_804F71E0 = .rodata:0x804F71E0; // type:object size:0x14
TYPE_NAME__Q34nw4r3g3d13AnmObjChrNode = .rodata:0x804F71E0; // type:object size:0x14
lbl_804F71F4 = .rodata:0x804F71F4; // type:object size:0x14
lbl_804F7208 = .rodata:0x804F7208; // type:object size:0x18
TYPE_NAME__Q34nw4r3g3d12AnmObjChrRes = .rodata:0x804F7208; // type:object size:0x18
lbl_804F7220 = .rodata:0x804F7220; // type:object size:0x10
lbl_804F7230 = .rodata:0x804F7230; // type:object size:0x18
lbl_804F7248 = .rodata:0x804F7248; // type:object size:0x10
Expand Down Expand Up @@ -35682,7 +35682,7 @@ lbl_8054243C = .data:0x8054243C; // type:object size:0xC
lbl_80542448 = .data:0x80542448; // type:object size:0x18
lbl_80542460 = .data:0x80542460; // type:object size:0x40
lbl_805424A0 = .data:0x805424A0; // type:object size:0x30
lbl_805424D0 = .data:0x805424D0; // type:object size:0x18
__vt__Q23m3d8anmChr_c = .data:0x805424D0; // type:object size:0x18
lbl_805424E8 = .data:0x805424E8; // type:object size:0x18
lbl_80542500 = .data:0x80542500; // type:object size:0x18
lbl_80542518 = .data:0x80542518; // type:object size:0x18
Expand Down
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def nw4rLib(lib_name, objects, extra_cflags=[]):
Object(Matching, "f/f_list.cpp"),
Object(Matching, "f/f_manager.cpp"),
Object(NonMatching, "m/m3d/m3d.cpp"),
Object(NonMatching, "m/m3d/m_anmchr.cpp"),
Object(Matching, "m/m3d/m_anmchr.cpp"),
Object(Matching, "m/m3d/m_anmtexsrt.cpp"),
Object(Matching, "m/m3d/m_anmvis.cpp"),
Object(Matching, "m/m3d/m_banm.cpp"),
Expand Down
6 changes: 4 additions & 2 deletions include/m/m3d/m_anmchr.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef M_ANMCHR_H
#define M_ANMCHR_H
#ifndef M3D_M_ANMCHR_H
#define M3D_M_ANMCHR_H

#include <m/m3d/m_bmdl.h>
#include <m/m3d/m_fanm.h>
Expand All @@ -9,10 +9,12 @@
namespace m3d {

class anmChr_c : public fanm_c {
public:
virtual ~anmChr_c();

virtual int getType() override;

bool create(nw4r::g3d::ResMdl, nw4r::g3d::ResAnmChr, mAllocator_c*, u32*);
void setAnm(bmdl_c &, nw4r::g3d::ResAnmChr, playMode_e);
void setAnmAfter(bmdl_c &, nw4r::g3d::ResAnmChr, playMode_e);
void setFrmCtrlDefault(nw4r::g3d::ResAnmChr &, m3d::playMode_e);
Expand Down
4 changes: 2 additions & 2 deletions include/m/m3d/m_anmtexsrt.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef M_ANMTEXSRT_H
#define M_ANMTEXSRT_H
#ifndef M3D_M_ANMTEXSRT_H
#define M3D_M_ANMTEXSRT_H

#include <m/m3d/m_bmdl.h>
#include <m/m3d/m_fanm.h>
Expand Down
5 changes: 3 additions & 2 deletions include/m/m3d/m_anmvis.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef M_ANMVIS_H
#define M_ANMVIS_H
#ifndef M3D_M_ANMVIS_H
#define M3D_M_ANMVIS_H

#include <m/m3d/m_bmdl.h>
#include <m/m3d/m_fanm.h>
Expand All @@ -8,6 +8,7 @@
namespace m3d {

class anmVis_c : public fanm_c {
public:
virtual ~anmVis_c();

virtual int getType() override;
Expand Down
74 changes: 70 additions & 4 deletions include/nw4r/g3d/g3d_anmchr.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef NW4R_G3D_ANMCHR_H
#define NW4R_G3D_ANMCHR_H
#include "common.h"
#include "nw4r/g3d/g3d_anmobj.h"
#include "nw4r/math/math_types.h"

namespace nw4r {
Expand All @@ -12,13 +13,78 @@ struct ChrAnmResult {
math::MTX34 mMtx; // at 0x1C
};

struct AnmObjChr {};
class AnmObjChrRes;

struct AnmObjChrNode {};
class AnmObjChr : public AnmObj {
public:

struct AnmObjChrBlend {};
enum BindOption {};

static const TypeObj GetTypeObjStatic() {
return TypeObj(TYPE_NAME);
}

virtual ChrAnmResult *GetResult(ChrAnmResult *, u32); // at 0x38
virtual void Attach(int, AnmObjChrRes*); // at 0x3C
virtual void Detach(int); // at 0x40
virtual void DetachAll(); // at 0x44
virtual void SetWeight(int, f32); // at 0x48
virtual f32 GetWeight(int) const; // at 0x4C
virtual void Bind(ResMdl, u32, BindOption) = 0; // at 0x50
virtual void Release(ResMdl, u32, BindOption) = 0; // at 0x54

private:
UNKWORD field_0x10;
UNKWORD field_0x14;

protected:
NW4R_G3D_TYPE_OBJ_DECL(AnmObjChr);
};

class AnmObjChrNode : public AnmObjChr {
public:
static const TypeObj GetTypeObjStatic() {
return TypeObj(TYPE_NAME);
}

inline int Size() {
return mNodeArraySize;
}

AnmObjChrRes *GetNode(int i) {
return mpNodes[i];
}

private:
int mNodeArraySize;
AnmObjChrRes **mpNodes;

protected:
NW4R_G3D_TYPE_OBJ_DECL(AnmObjChrNode);
};

struct AnmObjChrBlend : public AnmObjChrNode {
public:
static const TypeObj GetTypeObjStatic() {
return TypeObj(TYPE_NAME);
}

protected:
NW4R_G3D_TYPE_OBJ_DECL(AnmObjChrBlend);
};

struct AnmObjChrRes : public AnmObjChr, public FrameCtrl {
public:
static const TypeObj GetTypeObjStatic() {
return TypeObj(TYPE_NAME);
}

static AnmObjChrRes *Construct(MEMAllocator*, u32*, nw4r::g3d::ResAnmChr, nw4r::g3d::ResMdl, bool);

protected:
NW4R_G3D_TYPE_OBJ_DECL(AnmObjChrRes);
};

struct AnmObjChrRes {};
} // namespace g3d
} // namespace nw4r

Expand Down
15 changes: 15 additions & 0 deletions include/nw4r/g3d/g3d_resanmchr.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace g3d {
struct ResAnmChrData {
char UNK_0x0[0x8];
u32 mRevision; // at 0x8
char UNK_0xC[0x4];
s32 mMatDictOffset; // at 0x10
char UNK_0x14[0x0C];
u16 mNumFrames; // at 0x20
AnmPolicy mAnmPolicy; // at 0x24
};

struct ResAnmChr {
Expand All @@ -20,6 +25,16 @@ struct ResAnmChr {
inline bool CheckRevision() const {
return mAnmChr.ref().mRevision == REVISION;
}

AnmPolicy GetAnmPolicy() const
{
return mAnmChr.ref().mAnmPolicy;
}

int GetNumFrame() const
{
return mAnmChr.ref().mNumFrames;
}
};
} // namespace g3d
} // namespace nw4r
Expand Down
4 changes: 3 additions & 1 deletion include/nw4r/g3d/g3d_resnode.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#ifndef NW4R_G3D_RESNODE_H
#define NW4R_G3D_RESNODE_H
#include "common.h"
#include "nw4r/g3d/g3d_anmchr.h"
#include "nw4r/g3d/g3d_rescommon.h"
#include "nw4r/math/math_types.h"

namespace nw4r {
namespace g3d {

class ChrAnmResult;

struct ResNodeData {
u32 INT_0x0;
s32 INT_0x4;
Expand Down
67 changes: 61 additions & 6 deletions src/m/m3d/m_anmchr.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <m/m3d/m_anmchr.h>
#include <nw4r/g3d/g3d_anmobj.h>
#include <m/m3d/m3d.h>
#include <nw4r/g3d/g3d_anmchr.h>
#include <nw4r/g3d/g3d_resanmchr.h>

namespace m3d {
Expand All @@ -10,21 +11,75 @@ int anmChr_c::getType() {
return 0;
}

bool anmChr_c::create(nw4r::g3d::ResMdl mdl, nw4r::g3d::ResAnmChr anm, mAllocator_c* alloc, u32* pSize) {
if (alloc == nullptr) {
alloc = internal::l_allocator_p;
}

u32 size;
if (pSize == nullptr) {
pSize = &size;
}

nw4r::g3d::AnmObjChrRes::Construct(nullptr, pSize, anm, mdl, false);
if (!createAllocator(alloc, pSize)) {
return false;
}

mpAnmObj = nw4r::g3d::AnmObjChrRes::Construct(&mAllocator, &size, anm, mdl, false);
if (!mpAnmObj->Bind(mdl)) {
remove();
return false;
}

setFrmCtrlDefault(anm, PLAY_MODE_4);
return true;
}

void anmChr_c::setAnm(bmdl_c &mdl, nw4r::g3d::ResAnmChr anm, playMode_e mode) {
mdl.removeAnm((nw4r::g3d::ScnMdlSimple::AnmObjType)getType());
setAnmAfter(mdl, anm, mode);
}

void anmChr_c::setAnmAfter(bmdl_c &mdl, nw4r::g3d::ResAnmChr anm, playMode_e mode) {
// TODO g3d headers
// void *parent = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::AnmObjChrNode>(mpAnmObj->GetParent());
nw4r::g3d::AnmObjChrNode *node;
nw4r::g3d::G3dObj *parent = mpAnmObj->GetParent();
f32 weight;
int idx;
if (parent != nullptr) {
node = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::AnmObjChrNode>(parent);
int size = node->Size();
idx = 0;
for (int i = 0; i < size; i++, idx++) {
if (node->GetNode(i) == mpAnmObj) {
break;
}
}
weight = node->GetWeight(idx);
node->Detach(idx);
}
mpAnmObj->Release();
mpAnmObj->Destroy();
mpFrameHeap->free(3);
u32 tmp;
mpAnmObj = nw4r::g3d::AnmObjChrRes::Construct(&mAllocator, &tmp, anm, mdl.getResMdl(), false);
mpAnmObj->Bind(mdl.getResMdl());
setFrmCtrlDefault(anm, mode);

if (parent != nullptr) {
nw4r::g3d::AnmObjChrRes *o = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::AnmObjChrRes>(mpAnmObj);
node->SetWeight(idx, weight);
node->Attach(idx, o);

}

}

void anmChr_c::setFrmCtrlDefault(nw4r::g3d::ResAnmChr &anm, m3d::playMode_e mode) {
if (mode == 4) {
// TODO g3d headers
if (mode == PLAY_MODE_4) {
mode = anm.GetAnmPolicy() == nw4r::g3d::ANM_POLICY_ONETIME ? PLAY_MODE_1 : PLAY_MODE_0;
}
set(1.0f, mode, 1.0f, -1.0f);
set(anm.GetNumFrame(), mode, 1.0f, -1.0f);
}

} // namespace m3d

0 comments on commit 66fec2e

Please sign in to comment.