summaryrefslogtreecommitdiff
path: root/include/statelib.h
diff options
context:
space:
mode:
authorColin Noga <Tempus@Spectrum-Song.local>2011-07-19 17:07:00 -0500
committerColin Noga <Tempus@Spectrum-Song.local>2011-07-19 17:07:00 -0500
commitc2cc0c0d58b09d4e11003ca53e33b38723709bc1 (patch)
tree63cca09448468beaa000b055acb6d70c712c7ba3 /include/statelib.h
parent4457c47b7cb1e56577760df0e6ddfdc8bf28a7a8 (diff)
downloadkamek-c2cc0c0d58b09d4e11003ca53e33b38723709bc1.tar.gz
kamek-c2cc0c0d58b09d4e11003ca53e33b38723709bc1.zip
Bunch of fixes, Zorder stuff, and non-working sprespawner
Diffstat (limited to 'include/statelib.h')
-rw-r--r--include/statelib.h133
1 files changed, 133 insertions, 0 deletions
diff --git a/include/statelib.h b/include/statelib.h
new file mode 100644
index 0000000..34ab282
--- /dev/null
+++ b/include/statelib.h
@@ -0,0 +1,133 @@
+/******************************************************************************/
+// StateBase class
+/******************************************************************************/
+
+class StateBase {
+public:
+ StateBase(const char *name);
+
+ virtual ~StateBase();
+ virtual bool isInvalid();
+ virtual bool isEqualNotUsedForSomeReason(StateBase *another);
+ virtual bool isEqual(StateBase *another);
+ virtual bool isNotEqual(StateBase *another);
+ virtual bool isSameStateName(const char *name);
+ virtual const char *getName();
+ virtual int getID();
+
+ static StateBase mNoState;
+
+private:
+ const char *mName;
+ int mID;
+
+ static int mLastID;
+};
+
+/******************************************************************************/
+// State<TOwner> : StateBase class
+/******************************************************************************/
+
+template <class TOwner>
+class State : public StateBase {
+public:
+ typedef void (TOwner::*funcPtr)();
+
+ State(const char *name, funcPtr begin, funcPtr execute, funcPtr end) : StateBase(name) {
+ mBegin = begin;
+ mExecute = execute;
+ mEnd = end;
+ }
+
+ ~State();
+ bool isSameStateName(const char *name);
+
+ virtual void doBegin(TOwner *owner);
+ virtual void doExecute(TOwner *owner);
+ virtual void doEnd(TOwner *owner);
+
+ funcPtr mBegin;
+ funcPtr mExecute;
+ funcPtr mEnd;
+};
+
+template <class TOwner>
+State<TOwner>::~State() { }
+
+template <class TOwner>
+bool State<TOwner>::isSameStateName(const char *name) {
+ const char *p = strrchr(name, ':');
+ if (p)
+ name = p + 1;
+
+ int cmp = strcmp(strrchr(getName(), ':')+1, name);
+ if (cmp == 0)
+ return true;
+ else
+ return false;
+}
+
+template <class TOwner>
+void State<TOwner>::doBegin(TOwner *owner) {
+ (owner->*mBegin)();
+}
+
+template <class TOwner>
+void State<TOwner>::doExecute(TOwner *owner) {
+ (owner->*mExecute)();
+}
+
+template <class TOwner>
+void State<TOwner>::doEnd(TOwner *owner) {
+ (owner->*mEnd)();
+}
+
+/******************************************************************************/
+// StateMgrBase class
+/******************************************************************************/
+
+class StateMgrBase {
+public:
+ StateMgrBase(void *one, void *two, StateBase *pInitState);
+
+ virtual ~StateMgrBase();
+ virtual void _vf0C();
+ virtual void execute();
+ virtual void _vf14();
+ virtual void setState(StateBase *pNewState);
+ virtual void setField10ToOne();
+ virtual StateBase *getField20();
+ virtual StateBase *getField14();
+ virtual StateBase *getCurrentState_maybe();
+ virtual StateBase *getField18();
+ virtual bool _vf30() = 0;
+ virtual void _vf34() = 0;
+ virtual void _vf38() = 0;
+ virtual void _vf3C(StateBase *pState) = 0;
+
+private:
+ void *m04, *m08;
+ bool m0C, m0D, m0E, m0F, m10;
+ StateBase *m14, *m18, *m1C;
+ StateBase *m20; // maybe not a StateBase?
+};
+
+/******************************************************************************/
+// StateMgr<TOwner> : StateMgrBase class
+/******************************************************************************/
+
+template <class TOwner>
+class StateMgr : public StateMgrBase {
+public:
+ StateMgr(void *one, void *two, StateBase *pInitState);
+ ~StateMgr();
+
+ bool _vf30();
+ void _vf34();
+ void _vf38();
+ void _vf3C(StateBase *pState);
+};
+
+// TODO: add template methods
+
+