summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-09-17 03:20:02 +0200
committerTreeki <treeki@gmail.com>2011-09-17 03:20:02 +0200
commit5a9232c600b333b325eb14cc91ba1bba1e369283 (patch)
treec96616d1f46d0dfda586d576e2df367db80bde0d
parent75f7a14b0daf22b74a4f6fd55e35b0a407ecf0ba (diff)
downloadkamek-5a9232c600b333b325eb14cc91ba1bba1e369283.tar.gz
kamek-5a9232c600b333b325eb14cc91ba1bba1e369283.zip
new fancy preprocessor stuff for States
Diffstat (limited to '')
-rwxr-xr-xinclude/game.h17
-rw-r--r--src/eventblock.cpp23
2 files changed, 25 insertions, 15 deletions
diff --git a/include/game.h b/include/game.h
index 3476eaa..7382c34 100755
--- a/include/game.h
+++ b/include/game.h
@@ -1104,6 +1104,23 @@ public:
};
+#define DECLARE_STATE(NAME) \
+ static State StateID_##NAME; \
+ void beginState_##NAME(); \
+ void executeState_##NAME(); \
+ void endState_##NAME();
+
+#define CREATE_STATE(CLASS, NAME) \
+ CLASS::State CLASS::StateID_##NAME \
+ (#CLASS "::StateID_" #NAME, \
+ &CLASS::beginState_##NAME, \
+ &CLASS::executeState_##NAME, \
+ &CLASS::endState_##NAME);
+
+#define USING_STATES(CLASS) \
+ typedef State<CLASS> State;
+
+
struct LinkListEntry {
LinkListEntry *prev;
LinkListEntry *next;
diff --git a/src/eventblock.cpp b/src/eventblock.cpp
index f285da8..6f353b7 100644
--- a/src/eventblock.cpp
+++ b/src/eventblock.cpp
@@ -10,8 +10,6 @@ public:
SWAP_EVENTS = 1
};
- typedef State<daEnEventBlock_c> State;
-
TileRenderer tile;
Physics::Info physicsInfo;
@@ -28,21 +26,16 @@ public:
void calledWhenUpMoveExecutes();
void calledWhenDownMoveExecutes();
- void wait_Begin();
- void wait_Execute();
- void wait_End();
-
void blockWasHit(bool isDown);
- static State StateID_Wait;
+ USING_STATES(daEnEventBlock_c);
+ DECLARE_STATE(Wait);
+
static daEnEventBlock_c *build();
};
-daEnEventBlock_c::State daEnEventBlock_c::StateID_Wait(
- "daEnEventBlock_c::StateID_Wait",
- &daEnEventBlock_c::wait_Begin,
- &daEnEventBlock_c::wait_Execute,
- &daEnEventBlock_c::wait_End);
+
+CREATE_STATE(daEnEventBlock_c, Wait);
int daEnEventBlock_c::onCreate() {
@@ -184,13 +177,13 @@ void daEnEventBlock_c::calledWhenDownMoveExecutes() {
-void daEnEventBlock_c::wait_Begin() {
+void daEnEventBlock_c::beginState_Wait() {
}
-void daEnEventBlock_c::wait_End() {
+void daEnEventBlock_c::endState_Wait() {
}
-void daEnEventBlock_c::wait_Execute() {
+void daEnEventBlock_c::executeState_Wait() {
int result = blockResult();
if (result == 0)