#include <CSAction.h>
CSAction can only be created thru a loader (CSActionLoader). CSAction are defined by (now ONLY thru) an xml-File, like: DTD:
Example:<!ELEMENT ACTION (ID,IS_BREAKABLE,REPEATABLE,(PHASE)+,(ANIMATION)+,ENVOKER,(DEFAULT_NEXT_ACTION)?)> <!ELEMENT ID (#PCDATA)> <!ELEMENT IS_BREAKABLE (#PCDATA)> <!ELEMENT REPEATABLE (#PCDATA)> <!ELEMENT PHASE (#PCDATA)> <!ELEMENT ANIMATION (#PCDATA)> <!ELEMENT ENVOKER (#PCDATA)> <!ELEMENT DEFAULT_NEXT_ACTION (#PCDATA)>
<ACTION> <ID>PAC_DOWN_ACTION</ID> <IS_BREAKABLE>&true;</IS_BREAKABLE> <REPEATABLE>&INVERSE_ONCE;</REPEATABLE> <PHASE>0</PHASE> <ANIMATION>animation\\pac_down.xml</ANIMATION> <ENVOKER>&DOWN;</ENVOKER> <DEFAULT_NEXT_ACTION>PAC_DOWN_STAY_ACTION</DEFAULT_NEXT_ACTION> </ACTION>
ID - supposed a unique identifier IS_BREAKABLE - if an action can be interrupted by some action REAPEATABLE - one of: ACTION_NOT_REPEATABLE 0 ACTION_REPEATABLE 1 ACTION_INVERSE_ONCE 2 ACTION_INVERSE_REPEATABLE 3 ACTION_RANDOM 4
PHASES - many phases, each phase is represented by a number the number corresponse to the ANIMATION that is loaded with the ini - file (numbered from top to bottom. NOTE: REAPEATABLE ACTION_INVERSE_ONCE PHASES 0 PHASES 1 PHASES 2 PHASES 3 PHASES 4
gives the same result as: REAPEATABLE ACTION_NOT_REPEATABLE PHASES 0 PHASES 1 PHASES 2 PHASES 3 PHASES 4 PHASES 3 PHASES 2 PHASES 1 PHASES 0
ANIMATION - many animations are possible! describes the animation to be loaded, parameter gives the ini-file for a CSAnimation
ENVOKER - what 'envokes' the action, usually for a sprite this will be something like UP - DOWN (see definition in message.h)
DEFAULT_NEXT_ACTION - the unique id of another action, that will be envoked if this action 'ends' (JUMP - might be an action, but at some stage JUMP WILL end, than another action will per default be envoked, like STAND) This parameter is optional, it overrides (if set), the DEFAULT_ACTION of a CSSprite. This default - actions is not loaded with this action. To have any effect it must also be loaded with the corresponding CSSprite.
ActionState buildState(); void resetState(ActionState &state); void startAction(ActionState &state); void startNextAction(ActionState &state); bool isBreakable(ActionState &state); virtual bool next(ActionState &state); // if finished and not repeat -> false, true otherwise virtual void display(ActionState &state);
// inlines unsigned int getEnvoker() bool isAction(char *id); char *getId() // do not free return pointer! char *getDefaultAction() // do not free return pointer!the action class has no instance relevant data (state independant) thus one instance can be reused one action can be (re) used severall times the data used for printing must come from the outside (ActionState)
Definition at line 215 of file CSAction.h.
Public Member Functions | |
CSAction (const CSAction &action) | |
virtual | ~CSAction () |
virtual std::string | getType () |
unsigned int | getMaxX () |
unsigned int | getMaxY () |
void | setSecPerFrame (float secPerFrame) |
bool | isAction (char *id) |
ActionState | buildState () |
void | resetState (ActionState &state) |
void | startAction (ActionState &state) |
void | startNextAction (ActionState &state) |
bool | isBreakable (ActionState &state) |
virtual bool | next (ActionState &state) |
if finished and not repeat -> false, true otherwise | |
virtual void | display (ActionState &state) |
void | setAlpha (int alpha) |
unsigned int | getEnvoker () |
char * | getId () |
do not free return pointer! | |
int | getActionType () |
char * | getDefaultAction () |
do not free return pointer! | |
Static Public Attributes | |
const char * | CLASS = "CSAction" |
|
Definition at line 22 of file CSAction.cpp. References CSAnimations, LOG_ENTER, LOG_EXIT, mAnimations, mEnvoker, mId, mIsBreakable, mNextAction, mPhases, mRepeatable, mSizePhases, and mType.
00023 { 00024 static char *functionName="CSAction"; 00025 LOG_ENTER 00026 int i; 00027 initialize(); 00028 mIsBreakable = action.mIsBreakable; 00029 mRepeatable = action.mRepeatable; 00030 mSizePhases = action.mSizePhases; 00031 mEnvoker = action.mEnvoker; 00032 mType = action.mType; 00033 00034 mPhases = new unsigned int[mSizePhases]; 00035 for (i=0; i<mSizePhases; i++) 00036 { 00037 mPhases[i] = action.mPhases[i]; 00038 } 00039 00040 mAnimations = new CSAnimations(); 00041 CSAnimations::const_iterator iter = action.mAnimations->begin(); 00042 while (iter != action.mAnimations->end()) 00043 { 00044 // animations are singletons! 00045 // that means, we can (and should) re-use the animation we find at 00046 // the action that we copy from 00047 mAnimations->push_back(*iter); 00048 iter++; 00049 } 00050 mId = strdup(action.mId); 00051 mNextAction = strdup(action.mNextAction); 00052 LOG_EXIT 00053 } |
|
Definition at line 109 of file CSAction.cpp. References LOG_ENTER, and LOG_EXIT.
00110 { 00111 static char *functionName="~CSAction"; 00112 LOG_ENTER 00113 if (mPhases != 0) 00114 { 00115 delete []mPhases; 00116 mPhases = 0; 00117 } 00118 00119 if (mAnimations != 0) 00120 { 00121 // Animation are singletons -> do not delete them 00122 // Animation are deleted by CSAnimationLoader! 00123 delete mAnimations; 00124 mAnimations = 0; 00125 } 00126 00127 if (mId != 0) 00128 { 00129 free(mId); 00130 mId = 0; 00131 } 00132 00133 if (mNextAction != 0) 00134 { 00135 free(mNextAction); 00136 mNextAction = 0; 00137 } 00138 LOG_EXIT 00139 } |
|
Definition at line 242 of file CSAction.h. References CLASS.
00242 {return (std::string) CLASS;} |
|
Definition at line 364 of file CSAction.cpp. References CSAnimation::getMaxX().
00365 { 00366 static char *functionName="getMaxX"; 00367 unsigned int maxX = 0; 00368 unsigned int x; 00369 for (CSAnimations::iterator iter = mAnimations->begin(); iter != mAnimations->end(); iter++) 00370 { 00371 CSAnimation *ani = *iter; 00372 x = ani->getMaxX(); if (maxX < x) maxX = x; 00373 } 00374 return maxX; 00375 } |
Here is the call graph for this function:
|
Definition at line 379 of file CSAction.cpp. References CSAnimation::getMaxY().
00380 { 00381 static char *functionName="getMaxY"; 00382 unsigned int maxY = 0; 00383 unsigned int y; 00384 00385 for (CSAnimations::iterator iter = mAnimations->begin(); iter != mAnimations->end(); iter++) 00386 { 00387 CSAnimation *ani = *iter; 00388 y = ani->getMaxY(); if (maxY < y) maxY = y; 00389 } 00390 return maxY; 00391 } |
Here is the call graph for this function:
|
Definition at line 211 of file CSAction.cpp. References LOG_ENTER, LOG_EXIT, and CSAnimation::setSecPerFrame(). Referenced by CSSprite::setSecPerFrame().
00212 { 00213 static char *functionName="setSecPerFrame"; 00214 LOG_ENTER 00215 CSAnimations::const_iterator iter = mAnimations->begin(); 00216 while (iter != mAnimations->end()) 00217 { 00218 CSAnimation *animation = *iter; 00219 animation->setSecPerFrame(secPerFrame); 00220 iter++; 00221 } 00222 LOG_EXIT 00223 } |
Here is the call graph for this function:
|
Definition at line 356 of file CSAction.cpp. Referenced by CSSprite::next(), and CSSprite::reactOnMessage().
00357 { 00358 static char *functionName="isAction"; 00359 return !(strcmp(id, mId)); 00360 } |
|
Definition at line 142 of file CSAction.cpp. References CSAnimation::buildState(), ActionState::mAnimation, ActionState::mAnimationState, ActionState::mCurrentAnimation, ActionState::mCurrentPhase, ActionState::mFinished, and ActionState::mForward. Referenced by CSSprite::buildState().
00143 { 00144 static char *functionName="buildState"; 00145 ActionState state; 00146 state.mFinished = false; 00147 state.mForward = true; 00148 if (mSizePhases > 0) 00149 { 00150 state.mCurrentPhase = 0; 00151 state.mCurrentAnimation = mPhases[state.mCurrentPhase]; 00152 state.mAnimation = mAnimations->at(state.mCurrentAnimation); 00153 state.mAnimationState = state.mAnimation->buildState(); 00154 } 00155 return state; 00156 } |
Here is the call graph for this function:
|
Definition at line 161 of file CSAction.cpp. References ActionState::mAnimation, ActionState::mAnimationState, ActionState::mCurrentAnimation, ActionState::mCurrentPhase, ActionState::mFinished, ActionState::mForward, and CSAnimation::resetState(). Referenced by CSSprite::resetState().
00162 { 00163 static char *functionName="resetState"; 00164 state.mFinished = false; 00165 state.mForward = true; 00166 if (mSizePhases > 0) 00167 { 00168 state.mCurrentPhase = 0; 00169 state.mCurrentAnimation = mPhases[state.mCurrentPhase]; 00170 state.mAnimation = mAnimations->at(state.mCurrentAnimation); 00171 state.mAnimation->resetState(state.mAnimationState); 00172 } 00173 } |
Here is the call graph for this function:
|
Definition at line 177 of file CSAction.cpp. References ActionState::mAnimation, ActionState::mAnimationState, ActionState::mCurrentAnimation, ActionState::mCurrentPhase, ActionState::mFinished, ActionState::mForward, and CSAnimation::startAnimation(). Referenced by CSSprite::next().
00178 { 00179 static char *functionName="startAction"; 00180 state.mFinished = false; 00181 state.mForward = true; 00182 if (mSizePhases > 0) 00183 { 00184 state.mCurrentPhase = 0; 00185 state.mCurrentAnimation = mPhases[state.mCurrentPhase]; 00186 state.mAnimation = mAnimations->at(state.mCurrentAnimation); 00187 state.mAnimation->startAnimation(state.mAnimationState); 00188 } 00189 } |
Here is the call graph for this function:
|
Definition at line 197 of file CSAction.cpp. References ActionState::mAnimation, ActionState::mAnimationState, ActionState::mCurrentAnimation, ActionState::mCurrentPhase, ActionState::mFinished, ActionState::mForward, and CSAnimation::startNextAnimation(). Referenced by CSSprite::reactOnMessage().
00198 { 00199 static char *functionName="startNextAction"; 00200 state.mFinished = false; 00201 state.mForward = true; 00202 if (mSizePhases > 0) 00203 { 00204 state.mCurrentPhase = 0; 00205 state.mCurrentAnimation = mPhases[state.mCurrentPhase]; 00206 state.mAnimation = mAnimations->at(state.mCurrentAnimation); 00207 state.mAnimation->startNextAnimation(state.mAnimationState); 00208 } 00209 } |
Here is the call graph for this function:
|
Definition at line 346 of file CSAction.cpp. References CSAnimation::isBreakable(), and ActionState::mAnimation. Referenced by CSSprite::reactOnMessage().
00347 { 00348 static char *functionName="isBreakable"; 00349 if (!mIsBreakable) 00350 { 00351 return mIsBreakable; 00352 } 00353 return state.mAnimation->isBreakable(); 00354 } |
Here is the call graph for this function:
|
if finished and not repeat -> false, true otherwise
Definition at line 241 of file CSAction.cpp. References ActionState::mAnimation, ActionState::mAnimationState, ActionState::mCurrentAnimation, ActionState::mCurrentPhase, ActionState::mFinished, ActionState::mForward, CSAnimation::next(), and CSAnimation::startAnimation(). Referenced by CSSprite::next().
00242 { 00243 static char *functionName="next"; 00244 bool finished = false; 00245 if (state.mFinished) 00246 { 00247 return !state.mFinished; 00248 } 00249 00250 finished = !(state.mAnimation->next(state.mAnimationState)); 00251 if (finished) 00252 { 00253 if (mRepeatable == CS_RANDOM) 00254 { 00255 // TODO 00256 } 00257 else 00258 { 00259 if (state.mForward) 00260 { 00261 state.mCurrentPhase++; 00262 if (state.mCurrentPhase == mSizePhases) 00263 { 00264 if (mRepeatable == CS_INVERSE_REPEATABLE) 00265 { 00266 state.mForward = !state.mForward; 00267 if (mSizePhases > 1) 00268 { 00269 state.mCurrentPhase-=2; 00270 } 00271 else 00272 { 00273 state.mCurrentPhase--; 00274 } 00275 } 00276 else 00277 if (mRepeatable == CS_INVERSE_ONCE) 00278 { 00279 state.mForward = !state.mForward; 00280 if (mSizePhases > 1) 00281 { 00282 state.mCurrentPhase-=2; 00283 } 00284 else 00285 { 00286 state.mCurrentPhase--; 00287 } 00288 } 00289 else 00290 { 00291 if (mRepeatable == CS_NOT_REPEATABLE) 00292 { 00293 state.mFinished = true; 00294 return !state.mFinished; 00295 } 00296 state.mCurrentPhase = 0; 00297 } 00298 } 00299 } 00300 else // mForward 00301 { 00302 state.mCurrentPhase--; 00303 if (state.mCurrentPhase == -1) 00304 { 00305 if (mRepeatable == CS_INVERSE_REPEATABLE) 00306 { 00307 state.mForward = !state.mForward; 00308 if (mSizePhases > 1) 00309 { 00310 state.mCurrentPhase+=2; 00311 } 00312 else 00313 { 00314 state.mCurrentPhase++; 00315 } 00316 } 00317 else 00318 { 00319 if (mRepeatable == CS_INVERSE_ONCE) 00320 { 00321 state.mFinished = true; 00322 return !state.mFinished; 00323 } 00324 state.mCurrentPhase = 0; 00325 } 00326 00327 } 00328 } 00329 00330 } // else (mRepeatable == CS_RANDOM) 00331 state.mCurrentAnimation = mPhases[state.mCurrentPhase]; 00332 state.mAnimation = mAnimations->at(state.mCurrentAnimation); 00333 state.mAnimation->startAnimation(state.mAnimationState); 00334 } // (mDelayCounter == mDelays[mPhases[mCurrentPhase]]) 00335 00336 return !state.mFinished; 00337 } |
Here is the call graph for this function:
|
Definition at line 340 of file CSAction.cpp. References CSAnimation::display(), ActionState::mAnimation, and ActionState::mAnimationState. Referenced by CSSprite::display().
00341 { 00342 static char *functionName="display"; 00343 state.mAnimation->display(state.mAnimationState); 00344 } |
Here is the call graph for this function:
|
Definition at line 225 of file CSAction.cpp. References LOG_ENTER, LOG_EXIT, and CSAnimation::setAlpha(). Referenced by CSSprite::setAlpha().
00226 { 00227 static char *functionName="setAlpha"; 00228 LOG_ENTER 00229 CSAnimations::const_iterator iter = mAnimations->begin(); 00230 while (iter != mAnimations->end()) 00231 { 00232 CSAnimation *animation = *iter; 00233 animation->setAlpha(alpha); 00234 iter++; 00235 } 00236 LOG_EXIT 00237 } |
Here is the call graph for this function:
|
Definition at line 258 of file CSAction.h. Referenced by CSSprite::reactOnMessage().
00258 {return mEnvoker;}
|
|
do not free return pointer!
Definition at line 259 of file CSAction.h. Referenced by CSSprite::getCurrentActionId(), and CSSprite::reactOnMessage(). |
|
Definition at line 260 of file CSAction.h. Referenced by CSSprite::getCurrentActionType().
00260 {return mType;}
|
|
do not free return pointer!
Definition at line 261 of file CSAction.h. Referenced by CSSprite::next(), and CSSprite::reactOnMessage(). |
|
Definition at line 10 of file CSAction.cpp. Referenced by getType(). |