Skip to content

Commit

Permalink
LASTEXPRESS: Replace COMPARTMENT_TO and COMPARTMENT_FROM_TO macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Templier committed Jul 17, 2012
1 parent 9e64e62 commit 876a8f9
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 77 deletions.
8 changes: 4 additions & 4 deletions engines/lastexpress/entities/alouan.cpp
Expand Up @@ -86,22 +86,22 @@ IMPLEMENT_FUNCTION_END

//////////////////////////////////////////////////////////////////////////
IMPLEMENT_FUNCTION(6, Alouan, compartment6)
COMPARTMENT_TO(Alouan, kObjectCompartment6, kPosition_4070, "621Cf", "621Df");
Entity::goToCompartment(savepoint, kObjectCompartment6, kPosition_4070, "621Cf", "621Df", WRAP_ENTER_FUNCTION(Alouan, setup_enterExitCompartment));
IMPLEMENT_FUNCTION_END

//////////////////////////////////////////////////////////////////////////
IMPLEMENT_FUNCTION(7, Alouan, compartment8)
COMPARTMENT_TO(Alouan, kObjectCompartment8, kPosition_2740, "621Ch", "621Dh");
Entity::goToCompartment(savepoint, kObjectCompartment8, kPosition_2740, "621Ch", "621Dh", WRAP_ENTER_FUNCTION(Alouan, setup_enterExitCompartment));
IMPLEMENT_FUNCTION_END

//////////////////////////////////////////////////////////////////////////
IMPLEMENT_FUNCTION(8, Alouan, compartment6to8)
COMPARTMENT_FROM_TO(Alouan, kObjectCompartment6, kPosition_4070, "621Bf", kObjectCompartment8, kPosition_2740, "621Ah");
Entity::goToCompartmentFromCompartment(savepoint, kObjectCompartment6, kPosition_4070, "621Bf", kObjectCompartment8, kPosition_2740, "621Ah", WRAP_ENTER_FUNCTION(Alouan, setup_enterExitCompartment), WRAP_UPDATE_FUNCTION(Alouan, setup_updateEntity));
IMPLEMENT_FUNCTION_END

//////////////////////////////////////////////////////////////////////////
IMPLEMENT_FUNCTION(9, Alouan, compartment8to6)
COMPARTMENT_FROM_TO(Alouan, kObjectCompartment8, kPosition_2740, "621Bh", kObjectCompartment6, kPosition_4070, "621Af");
Entity::goToCompartmentFromCompartment(savepoint, kObjectCompartment8, kPosition_2740, "621Bh", kObjectCompartment6, kPosition_4070, "621Af", WRAP_ENTER_FUNCTION(Alouan, setup_enterExitCompartment), WRAP_UPDATE_FUNCTION(Alouan, setup_updateEntity));
IMPLEMENT_FUNCTION_END

//////////////////////////////////////////////////////////////////////////
Expand Down
68 changes: 68 additions & 0 deletions engines/lastexpress/entities/entity.cpp
Expand Up @@ -464,6 +464,74 @@ void Entity::enterExitCompartment(const SavePoint &savepoint, EntityPosition pos
}
}

void Entity::goToCompartment(const SavePoint &savepoint, ObjectIndex compartmentFrom, EntityPosition positionFrom, Common::String sequenceFrom, Common::String sequenceTo, Entity::EnterFunction *enterFunction) {
switch (savepoint.action) {
default:
break;

case kActionDefault:
getData()->entityPosition = positionFrom;
setCallback(1);
(*enterFunction)(sequenceFrom.c_str(), compartmentFrom);
break;

case kActionCallback:
switch (getCallback()) {
default:
break;

case 1:
setCallback(2);
(*enterFunction)(sequenceTo.c_str(), compartmentFrom);
break;

case 2:
getData()->entityPosition = positionFrom;
getEntities()->clearSequences(_entityIndex);
callbackAction();
break;
}
break;
}
}

void Entity::goToCompartmentFromCompartment(const SavePoint &savepoint, ObjectIndex compartmentFrom, EntityPosition positionFrom, Common::String sequenceFrom, ObjectIndex compartmentTo, EntityPosition positionTo, Common::String sequenceTo, Entity::EnterFunction *enterFunction, Entity::UpdateFunction *updateFunction) {
switch (savepoint.action) {
default:
break;

case kActionDefault:
getData()->entityPosition = positionFrom;
getData()->location = kLocationOutsideCompartment;
setCallback(1);
(*enterFunction)(sequenceFrom.c_str(), compartmentFrom);
break;

case kActionCallback:
switch (getCallback()) {
default:
break;

case 1:
setCallback(2);
(*updateFunction)(kCarGreenSleeping, positionTo);
break;

case 2:
setCallback(3);
(*enterFunction)(sequenceTo.c_str(), compartmentTo);
break;

case 3:
getData()->location = kLocationInsideCompartment;
getEntities()->clearSequences(_entityIndex);
callbackAction();
break;
}
break;
}
}

void Entity::updatePosition(const SavePoint &savepoint, bool handleExcuseMe) {
EXPOSE_PARAMS(EntityData::EntityParametersSIII)

Expand Down
51 changes: 42 additions & 9 deletions engines/lastexpress/entities/entity.h
Expand Up @@ -616,19 +616,19 @@ class EntityData : Common::Serializable {
EntityParameters *getParameters(uint callback, byte index) const;
EntityParameters *getCurrentParameters(byte index = 0) { return getParameters(_data.currentCall, index); }

int getCallback(uint callback) const;
int getCurrentCallback() { return getCallback(_data.currentCall); }
void setCallback(uint callback, byte index);
void setCurrentCallback(uint index) { setCallback(_data.currentCall, index); }
int getCallback(uint callback) const;
int getCurrentCallback() { return getCallback(_data.currentCall); }
void setCallback(uint callback, byte index);
void setCurrentCallback(uint index) { setCallback(_data.currentCall, index); }

void updateParameters(uint32 index) const;

// Serializable
void saveLoadWithSerializer(Common::Serializer &ser);
void saveLoadWithSerializer(Common::Serializer &ser);

private:

EntityCallData _data;
EntityCallData _data;
EntityCallParameters _parameters[9];
};

Expand Down Expand Up @@ -665,9 +665,15 @@ class Entity : Common::Serializable {
protected:
LastExpressEngine *_engine;

EntityIndex _entityIndex;
EntityData *_data;
Common::Array<Callback *> _callbacks;
EntityIndex _entityIndex;
EntityData *_data;
Common::Array<Callback *> _callbacks;

typedef Common::Functor2<const char *, ObjectIndex, void> EnterFunction;
typedef Common::Functor2<CarIndex, EntityPosition, void> UpdateFunction;

#define WRAP_ENTER_FUNCTION(className, method) new Common::Functor2Mem<const char *, ObjectIndex, void, className>(this, &className::method)
#define WRAP_UPDATE_FUNCTION(className, method) new Common::Functor2Mem<CarIndex, EntityPosition, void, className>(this, &className::method)

/**
* Saves the game
Expand Down Expand Up @@ -781,6 +787,33 @@ class Entity : Common::Serializable {
*/
void enterExitCompartment(const SavePoint &savepoint, EntityPosition position1 = kPositionNone, EntityPosition position2 = kPositionNone, CarIndex car = kCarNone, ObjectIndex compartment = kObjectNone, bool alternate = false, bool updateLocation = false);

/**
* Go to compartment.
*
* @param savepoint The savepoint.
* @param compartmentFrom The compartment from.
* @param positionFrom The position from.
* @param sequenceFrom The sequence from.
* @param sequenceTo The sequence to.
* @param enterFunction The enter/exit compartment function.
*/
void goToCompartment(const SavePoint &savepoint, ObjectIndex compartmentFrom, EntityPosition positionFrom, Common::String sequenceFrom, Common::String sequenceTo, EnterFunction *enterFunction);

/**
* Go to compartment from compartment.
*
* @param savepoint The savepoint.
* @param compartmentFrom The compartment from.
* @param positionFrom The position from.
* @param sequenceFrom The sequence from.
* @param compartmentTo The compartment to.
* @param positionTo The position to.
* @param sequenceTo The sequence to.
* @param enterFunction The enter/exit compartment function.
* @param enterFunction The update entity function.
*/
void goToCompartmentFromCompartment(const SavePoint &savepoint, ObjectIndex compartmentFrom, EntityPosition positionFrom, Common::String sequenceFrom, ObjectIndex compartmentTo, EntityPosition positionTo, Common::String sequenceTo, Entity::EnterFunction *enterFunction, Entity::UpdateFunction *updateFunction);

/**
* Updates the position
*
Expand Down
60 changes: 0 additions & 60 deletions engines/lastexpress/entities/entity_intern.h
Expand Up @@ -451,66 +451,6 @@ void class::setup_##name() { \
if (!parameter) \
parameter = (uint)(type + value);

//////////////////////////////////////////////////////////////////////////
// Compartments
//////////////////////////////////////////////////////////////////////////
// Go from one compartment to another (or the same one if no optional args are passed
#define COMPARTMENT_TO(class, compartmentFrom, positionFrom, sequenceFrom, sequenceTo) \
switch (savepoint.action) { \
default: \
break; \
case kActionDefault: \
getData()->entityPosition = positionFrom; \
setCallback(1); \
setup_enterExitCompartment(sequenceFrom, compartmentFrom); \
break; \
case kActionCallback: \
switch (getCallback()) { \
default: \
break; \
case 1: \
setCallback(2); \
setup_enterExitCompartment(sequenceTo, compartmentFrom); \
break; \
case 2: \
getData()->entityPosition = positionFrom; \
getEntities()->clearSequences(_entityIndex); \
callbackAction(); \
} \
break; \
}

#define COMPARTMENT_FROM_TO(class, compartmentFrom, positionFrom, sequenceFrom, compartmentTo, positionTo, sequenceTo) \
switch (savepoint.action) { \
default: \
break; \
case kActionDefault: \
getData()->entityPosition = positionFrom; \
getData()->location = kLocationOutsideCompartment; \
setCallback(1); \
setup_enterExitCompartment(sequenceFrom, compartmentFrom); \
break; \
case kActionCallback: \
switch (getCallback()) { \
default: \
break; \
case 1: \
setCallback(2); \
setup_updateEntity(kCarGreenSleeping, positionTo); \
break; \
case 2: \
setCallback(3); \
setup_enterExitCompartment(sequenceTo, compartmentTo); \
break; \
case 3: \
getData()->location = kLocationInsideCompartment; \
getEntities()->clearSequences(_entityIndex); \
callbackAction(); \
break; \
} \
break; \
}

} // End of namespace LastExpress

#endif // LASTEXPRESS_ENTITY_INTERN_H
8 changes: 4 additions & 4 deletions engines/lastexpress/entities/hadija.cpp
Expand Up @@ -86,22 +86,22 @@ IMPLEMENT_FUNCTION_END

//////////////////////////////////////////////////////////////////////////
IMPLEMENT_FUNCTION(6, Hadija, compartment6)
COMPARTMENT_TO(Hadija, kObjectCompartment6, kPosition_4070, "619Cf", "619Df");
Entity::goToCompartment(savepoint, kObjectCompartment6, kPosition_4070, "619Cf", "619Df", WRAP_ENTER_FUNCTION(Hadija, setup_enterExitCompartment));
IMPLEMENT_FUNCTION_END

//////////////////////////////////////////////////////////////////////////
IMPLEMENT_FUNCTION(7, Hadija, compartment8)
COMPARTMENT_TO(Hadija, kObjectCompartment8, kPosition_2740, "619Ch", "619Dh");
Entity::goToCompartment(savepoint, kObjectCompartment8, kPosition_2740, "619Ch", "619Dh", WRAP_ENTER_FUNCTION(Hadija, setup_enterExitCompartment));
IMPLEMENT_FUNCTION_END

//////////////////////////////////////////////////////////////////////////
IMPLEMENT_FUNCTION(8, Hadija, compartment6to8)
COMPARTMENT_FROM_TO(Hadija, kObjectCompartment6, kPosition_4070, "619Bf", kObjectCompartment8, kPosition_2740, "619Ah");
Entity::goToCompartmentFromCompartment(savepoint, kObjectCompartment6, kPosition_4070, "619Bf", kObjectCompartment8, kPosition_2740, "619Ah", WRAP_ENTER_FUNCTION(Hadija, setup_enterExitCompartment), WRAP_UPDATE_FUNCTION(Hadija, setup_updateEntity));
IMPLEMENT_FUNCTION_END

//////////////////////////////////////////////////////////////////////////
IMPLEMENT_FUNCTION(9, Hadija, compartment8to6)
COMPARTMENT_FROM_TO(Hadija, kObjectCompartment8, kPosition_2740, "619Bh", kObjectCompartment6, kPosition_4070, "619Af");
Entity::goToCompartmentFromCompartment(savepoint, kObjectCompartment8, kPosition_2740, "619Bh", kObjectCompartment6, kPosition_4070, "619Af", WRAP_ENTER_FUNCTION(Hadija, setup_enterExitCompartment), WRAP_UPDATE_FUNCTION(Hadija, setup_updateEntity));
IMPLEMENT_FUNCTION_END

//////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 876a8f9

Please sign in to comment.