summaryrefslogtreecommitdiff
path: root/include/statelib.h
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-01-08 05:26:39 +0100
committerTreeki <treeki@gmail.com>2012-01-08 05:26:39 +0100
commit14fc0d0f71e1cb682473b7f7bbc959cfa70d163d (patch)
tree5e227316b6cc4a18e76b7cc51e397d0109ff523a /include/statelib.h
parent0ba16c2ac037346cea4566dadcb23d7c179e9588 (diff)
downloadkamek-14fc0d0f71e1cb682473b7f7bbc959cfa70d163d.tar.gz
kamek-14fc0d0f71e1cb682473b7f7bbc959cfa70d163d.zip
finally, a proper state API! hopefully this didn't break anything
Diffstat (limited to '')
-rw-r--r--include/statelib.h159
1 files changed, 131 insertions, 28 deletions
diff --git a/include/statelib.h b/include/statelib.h
index c039934..d387f02 100644
--- a/include/statelib.h
+++ b/include/statelib.h
@@ -24,6 +24,7 @@ private:
static int mLastID;
};
+
/******************************************************************************/
// dState_c<TOwner> : dStateBase_c class
/******************************************************************************/
@@ -49,6 +50,8 @@ public:
funcPtr mBegin;
funcPtr mExecute;
funcPtr mEnd;
+
+ void *mBaseState;
};
template <class TOwner>
@@ -83,51 +86,151 @@ void dState_c<TOwner>::doEnd(TOwner *owner) {
}
/******************************************************************************/
-// dStateMgrBase_c class
+// A Very Useless Class
+/******************************************************************************/
+class dStatePointless_c {
+ public:
+ virtual ~dStatePointless_c();
+ virtual int returnsOne(); // Does exactly what it says on the tin.
+};
+
+/******************************************************************************/
+// Executor Interfaces
+/******************************************************************************/
+class dStateMethodExecutorBase_c {
+ public:
+ virtual ~dStateMethodExecutorBase_c() = 0;
+
+ virtual void callBegin() = 0;
+ virtual void callExecute() = 0;
+ virtual void callEnd() = 0;
+};
+
+class dStateExecutorBase_c {
+ public:
+ virtual ~dStateExecutorBase_c() = 0;
+
+ virtual dStateMethodExecutorBase_c *getMethodExecutorForState(dStateBase_c *state) = 0;
+ virtual void clearMethodExecutor(dStateMethodExecutorBase_c **ptrToPtrToExecutor) = 0;
+};
+
+/******************************************************************************/
+// Executor Implementations
/******************************************************************************/
+template <class TOwner>
+class dStateMethodExecutor_c : public dStateMethodExecutorBase_c {
+ public:
+ ~dStateMethodExecutor_c();
+
+ void callBegin();
+ void callExecute();
+ void callEnd();
+
+ TOwner *mOwningObject;
+ dState_c<TOwner> *mState;
+};
+
+template <class TOwner>
+class dStateExecutor_c : public dStateExecutorBase_c {
+ public:
+ ~dStateExecutor_c();
+
+ dStateMethodExecutorBase_c *getMethodExecutorForState(dStateBase_c *state);
+ void clearMethodExecutor(dStateMethodExecutorBase_c **ptrToPtrToExecutor);
+
+ private:
+ dStateMethodExecutor_c<TOwner> mStockExecutor;
+};
+
+
+
+
+template <class TOwner>
+dStateMethodExecutorBase_c *dStateExecutor_c<TOwner>::getMethodExecutorForState(dStateBase_c *state) {
+ if (!state->isInvalid()) {
+ mStockExecutor.mState = static_cast<dState_c<TOwner>*>(state);
+ return &mStockExecutor;
+ } else {
+ return 0;
+ }
+}
+
+template <class TOwner>
+void dStateExecutor_c<TOwner>::clearMethodExecutor(dStateMethodExecutorBase_c **ptrToPtrToExecutor) {
+ *ptrToPtrToExecutor = 0;
+}
+
+
+template <class TOwner>
+void dStateMethodExecutor_c<TOwner>::callBegin() { mState->doBegin(mOwningObject); }
+template <class TOwner>
+void dStateMethodExecutor_c<TOwner>::callExecute() { mState->doExecute(mOwningObject); }
+template <class TOwner>
+void dStateMethodExecutor_c<TOwner>::callEnd() { mState->doEnd(mOwningObject); }
+
+/******************************************************************************/
+// dStateMgrBase_c class
+/******************************************************************************/
class dStateMgrBase_c {
public:
- dStateMgrBase_c(void *one, void *two, dStateBase_c *pInitState);
+ dStateMgrBase_c(dStatePointless_c *pPointlessClass, dStateExecutorBase_c *pStateExecutor, dStateBase_c *pInitState);
virtual ~dStateMgrBase_c();
- virtual void _vf0C();
+ virtual void ensureStateHasBegun();
virtual void execute();
- virtual void _vf14();
+ virtual void endCurrentState();
virtual void setState(dStateBase_c *pNewState);
- virtual void setField10ToOne();
- virtual dStateBase_c *getField20();
- virtual dStateBase_c *getField14();
- virtual dStateBase_c *getCurrentState_maybe();
- virtual dStateBase_c *getField18();
- virtual bool _vf30() = 0;
- virtual void _vf34() = 0;
- virtual void _vf38() = 0;
- virtual void _vf3C(dStateBase_c *pState) = 0;
-private:
- void *m04, *m08;
- bool m0C, m0D, m0E, m0F, m10;
- dStateBase_c *m14, *m18, *m1C;
- dStateBase_c *m20; // maybe not a dStateBase_c?
+ virtual void executeNextStateThisTick() {
+ mExecuteNextStateThisTick = true;
+ }
+
+ virtual dStateMethodExecutorBase_c *getCurrentStateMethodExecutor() {
+ return mCurrentStateMethodExecutor;
+ }
+
+ virtual dStateBase_c *getNextState() {
+ return mNextState;
+ }
+
+ virtual dStateBase_c *getCurrentState() {
+ return mCurrentState;
+ }
+
+ virtual dStateBase_c *getPreviousState() {
+ return mPreviousState;
+ }
+
+ virtual bool callBeginOnState() = 0;
+ virtual void callExecuteOnState() = 0;
+ virtual void callEndOnState() = 0;
+ virtual void doSwitchToNextState(dStateBase_c *pState/*unused*/) = 0;
+
+protected:
+ dStatePointless_c *mPointlessClass;
+ dStateExecutorBase_c *mStateExecutor;
+
+ bool mIsStateBeginningOrEnding, mIsStateExecuting;
+ bool mStateIsCurrentlyActive, mStateChangeHasOccurred;
+ bool mExecuteNextStateThisTick;
+
+ dStateBase_c *mNextState, *mPreviousState, *mCurrentState;
+ dStateMethodExecutorBase_c *mCurrentStateMethodExecutor;
};
/******************************************************************************/
-// dStateMgr_c<TOwner> : dStateMgrBase_c class
+// dStateMgr_c : dStateMgrBase_c class
/******************************************************************************/
-
-template <class TOwner>
class dStateMgr_c : public dStateMgrBase_c {
public:
- dStateMgr_c(void *one, void *two, dStateBase_c *pInitState);
+ dStateMgr_c(dStatePointless_c *pPointlessClass, dStateExecutorBase_c *pStateExecutor, dStateBase_c *pInitState);
~dStateMgr_c();
- bool _vf30();
- void _vf34();
- void _vf38();
- void _vf3C(dStateBase_c *pState);
+ bool callBeginOnState();
+ void callExecuteOnState();
+ void callEndOnState();
+ void doSwitchToNextState(dStateBase_c *pState/*unused*/);
};
-// TODO: add template methods
-