Skip to content

Commit

Permalink
Spine Nerve and NerveExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
shibbo committed Jan 5, 2025
1 parent 83754d9 commit d087959
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 10 deletions.
7 changes: 7 additions & 0 deletions config/SB4E01/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Game/LiveActor/LiveActorGroupArray.cpp:
.text start:0x802384F0 end:0x80238A70
.data start:0x80695378 end:0x806953E0

Game/LiveActor/Spine.cpp:
.text start:0x80243150 end:0x80243330

Game/Map/StageSwitch.cpp:
.text start:0x80269F90 end:0x8026A8A0
.data start:0x8069A600 end:0x8069A670
Expand Down Expand Up @@ -97,6 +100,10 @@ Game/NameObj/NameObjHolder.cpp:
Game/NameObj/NameObjRegister.cpp:
.text start:0x80343E20 end:0x80343E50

Game/System/NerveExecutor.cpp:
.text start:0x804C4BB0 end:0x804C4D20
.data start:0x806FBE80 end:0x806FBE90

Game/System/ResourceInfo.cpp:
.text start:0x804CB0D0 end:0x804CB460
.sdata start:0x807D0470 end:0x807D0478
Expand Down
20 changes: 10 additions & 10 deletions config/SB4E01/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20287,9 +20287,9 @@ __ct__16ActorStateKeeperFi = .text:0x8022CF40; // type:function size:0x88
addState__16ActorStateKeeperFP23ActorStateBaseInterfacePC5NervePCc = .text:0x8022CFD0; // type:function size:0x28
updateCurrentState__16ActorStateKeeperFv = .text:0x8022D000; // type:function size:0x28
fn_8022D028 = .text:0x8022D028; // type:function size:0x4
fn_8022D030 = .text:0x8022D030; // type:function size:0x4C
startState__16ActorStateKeeperFPC5Nerve = .text:0x8022D030; // type:function size:0x4C
fn_8022D080 = .text:0x8022D080; // type:function size:0x20
fn_8022D0A0 = .text:0x8022D0A0; // type:function size:0x5C
endState__16ActorStateKeeperFv = .text:0x8022D0A0; // type:function size:0x5C
fn_8022D100 = .text:0x8022D100; // type:function size:0x40
fn_8022D140 = .text:0x8022D140; // type:function size:0x48
fn_8022D190 = .text:0x8022D190; // type:function size:0x58
Expand Down Expand Up @@ -41549,13 +41549,13 @@ fn_804C4870 = .text:0x804C4870; // type:function size:0x110
fn_804C4980 = .text:0x804C4980; // type:function size:0xB4
fn_804C4A40 = .text:0x804C4A40; // type:function size:0x104
fn_804C4B50 = .text:0x804C4B50; // type:function size:0x58
fn_804C4BB0 = .text:0x804C4BB0; // type:function size:0x18
fn_804C4BD0 = .text:0x804C4BD0; // type:function size:0x64
fn_804C4C40 = .text:0x804C4C40; // type:function size:0x5C
fn_804C4CA0 = .text:0x804C4CA0; // type:function size:0x14
fn_804C4CC0 = .text:0x804C4CC0; // type:function size:0x8
fn_804C4CD0 = .text:0x804C4CD0; // type:function size:0x3C
fn_804C4D10 = .text:0x804C4D10; // type:function size:0xC
__ct__13NerveExecutorFPCc = .text:0x804C4BB0; // type:function size:0x18
__dt__13NerveExecutorFv = .text:0x804C4BD0; // type:function size:0x64
initNerve__13NerveExecutorFPC5Nervel = .text:0x804C4C40; // type:function size:0x5C
updateNerve__13NerveExecutorFv = .text:0x804C4CA0; // type:function size:0x14
setNerve__13NerveExecutorFPC5Nerve = .text:0x804C4CC0; // type:function size:0x8
isNerve__13NerveExecutorCFPC5Nerve = .text:0x804C4CD0; // type:function size:0x3C
getNerveStep__13NerveExecutorCFv = .text:0x804C4D10; // type:function size:0xC
fn_804C4D20 = .text:0x804C4D20; // type:function size:0x74
fn_804C4DA0 = .text:0x804C4DA0; // type:function size:0xA0
fn_804C4E40 = .text:0x804C4E40; // type:function size:0x4C
Expand Down Expand Up @@ -69637,7 +69637,7 @@ lbl_806FBE40 = .data:0x806FBE40; // type:object size:0x10
lbl_806FBE50 = .data:0x806FBE50; // type:object size:0x10
lbl_806FBE60 = .data:0x806FBE60; // type:object size:0x10
lbl_806FBE70 = .data:0x806FBE70; // type:object size:0x10
lbl_806FBE80 = .data:0x806FBE80; // type:object size:0x10
__vt__13NerveExecutor = .data:0x806FBE80; // type:object size:0x10
lbl_806FBE90 = .data:0x806FBE90; // type:object size:0x10
lbl_806FBEA0 = .data:0x806FBEA0; // type:object size:0x20
lbl_806FBEC0 = .data:0x806FBEC0; // type:object size:0x28
Expand Down
2 changes: 2 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def MatchingFor(*versions):
Object(NonMatching, "Game/LiveActor/LiveActorFlag.cpp"),
Object(NonMatching, "Game/LiveActor/LiveActorGroup.cpp"),
Object(NonMatching, "Game/LiveActor/LiveActorGroupArray.cpp"),
Object(NonMatching, "Game/LiveActor/Spine.cpp"),
]
),

Expand Down Expand Up @@ -346,6 +347,7 @@ def MatchingFor(*versions):
GameLib(
"System",
[
Object(NonMatching, "Game/System/NerveExecutor.cpp"),
Object(NonMatching, "Game/System/ResourceInfo.cpp"),
Object(NonMatching, "Game/System/ScenarioDataParser.cpp"),
]
Expand Down
1 change: 1 addition & 0 deletions include/Game/LiveActor/ActorStateBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
28 changes: 28 additions & 0 deletions include/Game/LiveActor/ActorStateKeeper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <revolution.h>

class ActorStateBaseInterface;
class Nerve;

class ActorStateKeeper {
public:
struct State {
ActorStateBaseInterface* mInterface; // 0x00
const Nerve* mNerve; // 0x04
const char* mStateName; // 0x08
};

ActorStateKeeper(int);

void addState(ActorStateBaseInterface *, const Nerve *, const char *);
void updateCurrentState();
void startState(const Nerve *);

void endState();

int mMaxStates; // 0x00
int mNumStates; // 0x04
State* mStates; // 0x08
State* mCurrentState; // 0x0C
};
43 changes: 43 additions & 0 deletions include/Game/LiveActor/Nerve.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

class Spine;

class Nerve {
public:
inline Nerve() {}

virtual void execute(Spine *) const = 0;
virtual void executeOnEnd(Spine *) const;
};

#define NERVE(name, parent_class, executor_name)\
class name : public Nerve\
{\
public:\
name() NO_INLINE {\
};\
virtual void execute(Spine *pSpine) const {\
parent_class* actor = reinterpret_cast<parent_class*>(pSpine->mExecutor);\
actor->exe##executor_name();\
};\
static name sInstance;\
};\
name name::sInstance;\

#define NERVE_ONEND(name, parent_class, func, onEndFunc)\
class name : public Nerve\
{\
public:\
name() NO_INLINE {\
};\
virtual void execute(Spine *pSpine) const {\
parent_class* actor = reinterpret_cast<parent_class*>(pSpine->mExecutor);\
actor->func();\
};\
virtual void executeOnEnd(Spine *pSpine) const {\
parent_class* actor = reinterpret_cast<parent_class*>(pSpine->mExecutor);\
actor->onEndFunc();\
};\
static name sInstance;\
};\
name name::sInstance;\
19 changes: 19 additions & 0 deletions include/Game/LiveActor/Spine.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "LiveActor/ActorStateKeeper.hpp"

class Spine {
public:
Spine(void *, const Nerve *, s32);

void update();
void setNerve(const Nerve *);
const Nerve* getCurrentNerve() const;
void changeNerve();

void* mExecutor; // 0x00
const Nerve* mCurrentNerve; // 0x04
const Nerve* mNextNerve; // 0x08
s32 mCurrentStep; // 0x0C
ActorStateKeeper* mStateKeeper; // 0x10
};
21 changes: 21 additions & 0 deletions include/Game/System/NerveExecutor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <revolution.h>

class Spine;
class Nerve;

class NerveExecutor {
public:
NerveExecutor(const char *);

virtual ~NerveExecutor();

void initNerve(const Nerve *, s32);
void updateNerve();
void setNerve(const Nerve *);
bool isNerve(const Nerve *) const;
s32 getNerveStep() const;

Spine* mSpine; // 0x04
};
52 changes: 52 additions & 0 deletions src/Game/LiveActor/Spine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "LiveActor/Spine.hpp"
#include "LiveActor/ActorStateKeeper.hpp"
#include "LiveActor/Nerve.hpp"

Spine::Spine(void *pExecutor, const Nerve *pNextNerve, s32 numStates) {
mExecutor = pExecutor;
mCurrentNerve = nullptr;
mNextNerve = pNextNerve;
mCurrentStep = 0;
mStateKeeper = nullptr;

if (numStates > 0) {
mStateKeeper = new ActorStateKeeper(numStates);
}
}

void Spine::update() {
changeNerve();
mCurrentNerve->execute(this);
mCurrentStep++;
changeNerve();
}

void Spine::setNerve(const Nerve *pNerve) {
if (mCurrentStep >= 0 && mCurrentNerve != nullptr) {
mCurrentNerve->executeOnEnd(this);
}

mNextNerve = pNerve;
mCurrentStep = -1;
}

const Nerve* Spine::getCurrentNerve() const {
if (mNextNerve != nullptr) {
return mNextNerve;
}

return mCurrentNerve;
}

void Spine::changeNerve() {
if (mNextNerve != nullptr) {
if (mStateKeeper != nullptr) {
mStateKeeper->endState();
mStateKeeper->startState(mNextNerve);
}

mCurrentNerve = mNextNerve;
mNextNerve = nullptr;
mCurrentStep = 0;
}
}
32 changes: 32 additions & 0 deletions src/Game/System/NerveExecutor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "System/NerveExecutor.hpp"
#include "LiveActor/Spine.hpp"

NerveExecutor::NerveExecutor(const char *) {
mSpine = nullptr;
}

NerveExecutor::~NerveExecutor() {
delete mSpine;
}

void NerveExecutor::initNerve(const Nerve *pNerve, s32 numStates) {
mSpine = new Spine(this, pNerve, numStates);
}

void NerveExecutor::updateNerve() {
if (mSpine != nullptr) {
mSpine->update();
}
}

void NerveExecutor::setNerve(const Nerve *pNerve) {
mSpine->setNerve(pNerve);
}

bool NerveExecutor::isNerve(const Nerve *pNerve) const {
return mSpine->getCurrentNerve() == pNerve;
}

s32 NerveExecutor::getNerveStep() const {
return mSpine->mCurrentStep;
}

0 comments on commit d087959

Please sign in to comment.