author | ecalot
<ecalot> 2005-02-23 14:20:06 UTC |
committer | ecalot
<ecalot> 2005-02-23 14:20:06 UTC |
parent | 673a888f62d588e9d97e998f9a5a62d37d320a34 |
FP/src/include/states.h | +3 | -1 |
FP/src/ker/object.c | +2 | -1 |
FP/src/ker/states.c | +16 | -4 |
diff --git a/FP/src/include/states.h b/FP/src/include/states.h index 941c5e1..04839b9 100644 --- a/FP/src/include/states.h +++ b/FP/src/include/states.h @@ -54,7 +54,9 @@ short stateUpdate(tKey* key, tObject* kid,tRoom* room); /* Create a State depending on the level */ int stateKidInLevel(int level); -tState createState(short stateId); +tState stateCreate(short stateId); +void stateInterrupt(tState* state, short stateId); +void stateFree(tState* state); #include "states_conf.h" diff --git a/FP/src/ker/object.c b/FP/src/ker/object.c index d596696..efa8bf4 100644 --- a/FP/src/ker/object.c +++ b/FP/src/ker/object.c @@ -50,6 +50,7 @@ void loadGfx(int storeMirrored, tData** gfxCache, unsigned long resId) { void objectFree(tObject obj) { resFree(obj.gfxCache[DIR_LEFT]); if (obj.gfxCache[DIR_RIGHT]) resFree(obj.gfxCache[DIR_RIGHT]); + stateFree(&obj.action); } /* TODO: make a function in maps.c that calls this one for the kid */ @@ -62,7 +63,7 @@ tObject objectCreate(int location, int floor, int direction, int stateId, unsign object.floor=floor; object.type=type; object.direction=direction; - object.action=createState(stateId); + object.action=stateCreate(stateId); /* Default lives */ object.lives=3; diff --git a/FP/src/ker/states.c b/FP/src/ker/states.c index 7a5644c..79b3315 100644 --- a/FP/src/ker/states.c +++ b/FP/src/ker/states.c @@ -53,7 +53,7 @@ static tsAction statesActionList[]=STATES_ACTIONS; static short statesAnimationList[]=STATES_ANIMATIONS; static tsCondition statesConditionList[]=STATES_CONDITIONS; -void stateGetAnimation(int action,tState *state/*short *frames,short** flags,float* offsets*/) { +void state_GetAnimation(int action,tState *state/*short *frames,short** flags,float* offsets*/) { tsAction* a=statesActionList+action; short i=a->animSize; short* j=statesAnimationList+(a->animStart*4); @@ -82,13 +82,25 @@ int stateKidInLevel(int level) { return statesLevelList[level]; } -tState createState(short stateId) { +tState stateCreate(short stateId) { tState start; - stateGetAnimation(stateId,&start); + state_GetAnimation(stateId,&start); start.currentState=statesActionList[stateId].nextStateId; return start; } +void stateFree(tState* state) { + free(state->animation); + free(state->flags); + free(state->steps); + free(state->offsx); +} + +void stateInterrupt(tState* state, short stateId) { + stateFree(state); + *state=stateCreate(stateId); +} + /* private functions */ /* Evaluates a condition indexed in the condition table */ @@ -224,7 +236,7 @@ short stateUpdate(tKey* key, tObject* kid,tRoom* room) { /* Performs the events called by this action */ /* Remember the animation and flags for the next current->frame frames */ - stateGetAnimation(action,current); + state_GetAnimation(action,current); /* Remember the state where we are now */ current->currentState=statesActionList[action].nextStateId; #ifdef DEBUGSTATES