generated from encounter/dtk-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
215 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#pragma once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |