M4: Added function pointers to the the script engine data map list

svn-id: r54034
This commit is contained in:
Paul Gilbert 2010-11-02 00:15:18 +00:00
parent 997625c3b3
commit 274fbd028d
4 changed files with 26 additions and 10 deletions

View file

@ -229,15 +229,18 @@ struct MadsConfigData {
#define SET_GLOBAL(x,y) _madsVm->globals()->_globals[x] = y #define SET_GLOBAL(x,y) _madsVm->globals()->_globals[x] = y
#define SET_GLOBAL32(x,y) { _madsVm->globals()->_globals[x] = (y) & 0xffff; _madsVm->globals()->_globals[(x) + 1] = (y) >> 16; } #define SET_GLOBAL32(x,y) { _madsVm->globals()->_globals[x] = (y) & 0xffff; _madsVm->globals()->_globals[(x) + 1] = (y) >> 16; }
typedef int (*IntFunctionPtr)();
union DataMapEntry { union DataMapEntry {
bool *boolValue; bool *boolValue;
uint16 *uint16Value; uint16 *uint16Value;
int *intValue; int *intValue;
IntFunctionPtr fnPtr;
}; };
typedef Common::HashMap<uint16, uint16> DataMapHash; typedef Common::HashMap<uint16, uint16> DataMapHash;
enum DataMapType {BOOL, UINT16, INT}; enum DataMapType {BOOL, UINT16, INT, INT_FN};
class DataMapWrapper { class DataMapWrapper {
friend class DataMap; friend class DataMap;
@ -249,16 +252,18 @@ public:
DataMapWrapper(uint16 *v) { _value.uint16Value = v; _type = UINT16; } DataMapWrapper(uint16 *v) { _value.uint16Value = v; _type = UINT16; }
DataMapWrapper(int16 *v) { _value.uint16Value = (uint16 *)v; _type = UINT16; } DataMapWrapper(int16 *v) { _value.uint16Value = (uint16 *)v; _type = UINT16; }
DataMapWrapper(int *v) { _value.intValue = v; _type = INT; } DataMapWrapper(int *v) { _value.intValue = v; _type = INT; }
DataMapWrapper(IntFunctionPtr v) { _value.fnPtr = v; _type = INT_FN; }
uint16 getIntValue() { uint16 getIntValue() {
if (_type == BOOL) return *_value.boolValue ? 0xffff : 0; if (_type == BOOL) return *_value.boolValue ? 0xffff : 0;
else if (_type == UINT16) return *_value.uint16Value; else if (_type == UINT16) return *_value.uint16Value;
else return *_value.intValue; else if (_type == INT) return *_value.intValue;
else return _value.fnPtr();
} }
void setIntValue(uint16 v) { void setIntValue(uint16 v) {
if (_type == BOOL) *_value.boolValue = v != 0; if (_type == BOOL) *_value.boolValue = v != 0;
else if (_type == UINT16) *_value.uint16Value = v; else if (_type == UINT16) *_value.uint16Value = v;
else *_value.intValue = v; else if (_type == INT) *_value.intValue = v;
} }
}; };

View file

@ -182,7 +182,9 @@ void MadsSceneLogic::initialiseDataMap() {
MAP_DATA(&_madsVm->_player._playerPos.y); MAP_DATA(&_madsVm->_player._playerPos.y);
MAP_DATA(&_madsVm->_player._direction); MAP_DATA(&_madsVm->_player._direction);
MAP_DATA(&_madsVm->_player._visible); MAP_DATA(&_madsVm->_player._visible);
MAP_DATA(&_madsVm->scene()->_animActive); MAP_DATA(&getActiveAnimationBool);
MAP_DATA(&getAnimationCurrentFrame);
} }
DataMap &MadsSceneLogic::dataMap() { DataMap &MadsSceneLogic::dataMap() {

View file

@ -62,7 +62,6 @@ void SceneNode::load(Common::SeekableReadStream *stream) {
MadsScene::MadsScene(MadsEngine *vm): _sceneResources(), Scene(vm, &_sceneResources), MadsView(this) { MadsScene::MadsScene(MadsEngine *vm): _sceneResources(), Scene(vm, &_sceneResources), MadsView(this) {
_vm = vm; _vm = vm;
_activeAnimation = NULL; _activeAnimation = NULL;
_animActive = false;
MadsView::_bgSurface = Scene::_backgroundSurface; MadsView::_bgSurface = Scene::_backgroundSurface;
MadsView::_depthSurface = Scene::_walkSurface; MadsView::_depthSurface = Scene::_walkSurface;
@ -217,7 +216,6 @@ void MadsScene::leaveScene() {
if (_activeAnimation) { if (_activeAnimation) {
delete _activeAnimation; delete _activeAnimation;
_activeAnimation = NULL; _activeAnimation = NULL;
_animActive = false;
} }
Scene::leaveScene(); Scene::leaveScene();
@ -386,7 +384,6 @@ void MadsScene::updateState() {
if (((MadsAnimation *) _activeAnimation)->freeFlag() || freeFlag) { if (((MadsAnimation *) _activeAnimation)->freeFlag() || freeFlag) {
delete _activeAnimation; delete _activeAnimation;
_activeAnimation = NULL; _activeAnimation = NULL;
_animActive = false;
} }
} }
@ -458,7 +455,6 @@ void MadsScene::freeAnimation() {
delete _activeAnimation; delete _activeAnimation;
_activeAnimation = NULL; _activeAnimation = NULL;
_animActive = false;
} }
@ -578,7 +574,6 @@ void MadsScene::loadAnimation(const Common::String &animName, int abortTimers) {
MadsAnimation *anim = new MadsAnimation(_vm, this); MadsAnimation *anim = new MadsAnimation(_vm, this);
anim->load(animName.c_str(), abortTimers); anim->load(animName.c_str(), abortTimers);
_activeAnimation = anim; _activeAnimation = anim;
_animActive = true;
} }
bool MadsScene::getDepthHighBit(const Common::Point &pt) { bool MadsScene::getDepthHighBit(const Common::Point &pt) {
@ -1244,4 +1239,16 @@ void MadsInterfaceView::leaveScene() {
_madsVm->_viewManager->deleteView(view); _madsVm->_viewManager->deleteView(view);
} }
//--------------------------------------------------------------------------
int getActiveAnimationBool() {
return (_madsVm->scene()->activeAnimation()) ? 1 : 0;
}
int getAnimationCurrentFrame() {
Animation *anim = _madsVm->scene()->activeAnimation();
return anim ? anim->getCurrentFrame() : 0;
}
} // End of namespace M4 } // End of namespace M4

View file

@ -108,7 +108,6 @@ public:
Common::Point _destPos; Common::Point _destPos;
int _destFacing; int _destFacing;
Common::Point _customDest; Common::Point _customDest;
bool _animActive;
public: public:
MadsScene(MadsEngine *vm); MadsScene(MadsEngine *vm);
virtual ~MadsScene(); virtual ~MadsScene();
@ -192,6 +191,9 @@ public:
bool onEvent(M4EventType eventType, int32 param1, int x, int y, bool &captureEvents); bool onEvent(M4EventType eventType, int32 param1, int x, int y, bool &captureEvents);
}; };
extern int getActiveAnimationBool();
extern int getAnimationCurrentFrame();
} // End of namespace M4 } // End of namespace M4
#endif #endif