[Scummvm-cvs-logs] SF.net SVN: scummvm:[53898] scummvm/trunk/engines/sword25
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Thu Oct 28 02:25:33 CEST 2010
Revision: 53898
http://scummvm.svn.sourceforge.net/scummvm/?rev=53898&view=rev
Author: fingolfin
Date: 2010-10-28 00:25:33 +0000 (Thu, 28 Oct 2010)
Log Message:
-----------
SWORD25: Get rid of CallbackRegistry
Modified Paths:
--------------
scummvm/trunk/engines/sword25/gfx/animation.cpp
scummvm/trunk/engines/sword25/gfx/animation.h
scummvm/trunk/engines/sword25/gfx/graphicengine_script.cpp
scummvm/trunk/engines/sword25/module.mk
Removed Paths:
-------------
scummvm/trunk/engines/sword25/kernel/callbackregistry.cpp
scummvm/trunk/engines/sword25/kernel/callbackregistry.h
Modified: scummvm/trunk/engines/sword25/gfx/animation.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/animation.cpp 2010-10-28 00:24:53 UTC (rev 53897)
+++ scummvm/trunk/engines/sword25/gfx/animation.cpp 2010-10-28 00:25:33 UTC (rev 53898)
@@ -38,7 +38,6 @@
#include "sword25/kernel/resmanager.h"
#include "sword25/kernel/inputpersistenceblock.h"
#include "sword25/kernel/outputpersistenceblock.h"
-#include "sword25/kernel/callbackregistry.h"
#include "sword25/package/packagemanager.h"
#include "sword25/gfx/image/image.h"
#include "sword25/gfx/animationtemplate.h"
@@ -133,14 +132,14 @@
getAnimationDescription()->unlock();
}
- // Delete Callbacks
- Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = _deleteCallbacks.begin();
- for (; it != _deleteCallbacks.end(); it++)((*it).Callback)((*it).Data);
+ // Invoke the "delete" callback
+ if (_deleteCallback)
+ (_deleteCallback)(getHandle());
}
void Animation::play() {
- // Wenn die Animation zuvor komplett durchgelaufen ist, wird sie wieder von Anfang abgespielt
+ // If the animation was completed, then play it again from the start.
if (_finished)
stop();
@@ -242,28 +241,20 @@
BS_ASSERT(0);
}
- // \xDCberl\xE4ufe behandeln
+ // Deal with overflows
if (tmpCurFrame < 0) {
- // Loop-Point Callbacks
- for (uint i = 0; i < _loopPointCallbacks.size();) {
- if ((_loopPointCallbacks[i].Callback)(_loopPointCallbacks[i].Data) == false) {
- _loopPointCallbacks.remove_at(i);
- } else
- i++;
- }
+ // Loop-Point callback
+ if (_loopPointCallback && !(_loopPointCallback)(getHandle()))
+ _loopPointCallback = 0;
- // Ein Unterlauf darf nur auftreten, wenn der Animationstyp JOJO ist.
+ // An underflow may only occur if the animation type is JOJO.
BS_ASSERT(animationDescriptionPtr->getAnimationType() == AT_JOJO);
tmpCurFrame = - tmpCurFrame;
_direction = FORWARD;
} else if (static_cast<uint>(tmpCurFrame) >= animationDescriptionPtr->getFrameCount()) {
- // Loop-Point Callbacks
- for (uint i = 0; i < _loopPointCallbacks.size();) {
- if ((_loopPointCallbacks[i].Callback)(_loopPointCallbacks[i].Data) == false) {
- _loopPointCallbacks.remove_at(i);
- } else
- i++;
- }
+ // Loop-Point callback
+ if (_loopPointCallback && !(_loopPointCallback)(getHandle()))
+ _loopPointCallback = 0;
switch (animationDescriptionPtr->getAnimationType()) {
case AT_ONESHOT:
@@ -290,13 +281,9 @@
forceRefresh();
if (animationDescriptionPtr->getFrame(_currentFrame).action != "") {
- // Action Callbacks
- for (uint i = 0; i < _actionCallbacks.size();) {
- if ((_actionCallbacks[i].Callback)(_actionCallbacks[i].Data) == false) {
- _actionCallbacks.remove_at(i);
- } else
- i++;
- }
+ // action callback
+ if (_actionCallback && !(_actionCallback)(getHandle()))
+ _actionCallback = 0;
}
}
@@ -555,63 +542,6 @@
return result;
}
-void Animation::registerActionCallback(ANIMATION_CALLBACK callback, uint data) {
- ANIMATION_CALLBACK_DATA cd;
- cd.Callback = callback;
- cd.Data = data;
- _actionCallbacks.push_back(cd);
-}
-
-void Animation::registerLoopPointCallback(ANIMATION_CALLBACK callback, uint data) {
- ANIMATION_CALLBACK_DATA cd;
- cd.Callback = callback;
- cd.Data = data;
- _loopPointCallbacks.push_back(cd);
-}
-
-void Animation::registerDeleteCallback(ANIMATION_CALLBACK callback, uint data) {
- ANIMATION_CALLBACK_DATA cd;
- cd.Callback = callback;
- cd.Data = data;
- _deleteCallbacks.push_back(cd);
-}
-
-void Animation::persistCallbackVector(OutputPersistenceBlock &writer, const Common::Array<ANIMATION_CALLBACK_DATA> &vector) {
- // Anzahl an Callbacks persistieren.
- writer.write(vector.size());
-
- // Alle Callbacks einzeln persistieren.
- Common::Array<ANIMATION_CALLBACK_DATA>::const_iterator it = vector.begin();
- while (it != vector.end()) {
- writer.write(CallbackRegistry::instance().resolveCallbackPointer((void (*)(int))it->Callback));
- writer.write(it->Data);
-
- ++it;
- }
-}
-
-void Animation::unpersistCallbackVector(InputPersistenceBlock &reader, Common::Array<ANIMATION_CALLBACK_DATA> &vector) {
- // Callbackvector leeren.
- vector.resize(0);
-
- // Anzahl an Callbacks einlesen.
- uint callbackCount;
- reader.read(callbackCount);
-
- // Alle Callbacks einzeln wieder herstellen.
- for (uint i = 0; i < callbackCount; ++i) {
- ANIMATION_CALLBACK_DATA callbackData;
-
- Common::String callbackFunctionName;
- reader.read(callbackFunctionName);
- callbackData.Callback = reinterpret_cast<ANIMATION_CALLBACK>(CallbackRegistry::instance().resolveCallbackFunction(callbackFunctionName));
-
- reader.read(callbackData.Data);
-
- vector.push_back(callbackData);
- }
-}
-
bool Animation::persist(OutputPersistenceBlock &writer) {
bool result = true;
@@ -644,10 +574,19 @@
//writer.write(_AnimationDescriptionPtr);
writer.write(_framesLocked);
- persistCallbackVector(writer, _loopPointCallbacks);
- persistCallbackVector(writer, _actionCallbacks);
- persistCallbackVector(writer, _deleteCallbacks);
+ // The following is only there to for compatibility with older saves
+ // resp. the original engine.
+ writer.write((uint)1);
+ writer.write(Common::String("LuaLoopPointCB"));
+ writer.write(getHandle());
+ writer.write((uint)1);
+ writer.write(Common::String("LuaActionCB"));
+ writer.write(getHandle());
+ writer.write((uint)1);
+ writer.write(Common::String("LuaDeleteCB"));
+ writer.write(getHandle());
+
result &= RenderObject::persistChildren(writer);
return result;
@@ -690,10 +629,40 @@
if (_framesLocked)
lockAllFrames();
- unpersistCallbackVector(reader, _loopPointCallbacks);
- unpersistCallbackVector(reader, _actionCallbacks);
- unpersistCallbackVector(reader, _deleteCallbacks);
+ // The following is only there to for compatibility with older saves
+ // resp. the original engine.
+ uint callbackCount;
+ Common::String callbackFunctionName;
+ uint callbackData;
+
+ // loop point callback
+ reader.read(callbackCount);
+ assert(callbackCount == 1);
+ reader.read(callbackFunctionName);
+ assert(callbackFunctionName == "LuaLoopPointCB");
+ reader.read(callbackData);
+ assert(callbackData == getHandle());
+
+ // loop point callback
+ reader.read(callbackCount);
+ assert(callbackCount == 1);
+ reader.read(callbackFunctionName);
+ assert(callbackFunctionName == "LuaActionCB");
+ reader.read(callbackData);
+ assert(callbackData == getHandle());
+
+ // loop point callback
+ reader.read(callbackCount);
+ assert(callbackCount == 1);
+ reader.read(callbackFunctionName);
+ assert(callbackFunctionName == "LuaDeleteCB");
+ reader.read(callbackData);
+ assert(callbackData == getHandle());
+
+ // Set the callbacks
+ setCallbacks();
+
result &= RenderObject::unpersistChildren(reader);
return reader.isGood() && result;
Modified: scummvm/trunk/engines/sword25/gfx/animation.h
===================================================================
--- scummvm/trunk/engines/sword25/gfx/animation.h 2010-10-28 00:24:53 UTC (rev 53897)
+++ scummvm/trunk/engines/sword25/gfx/animation.h 2010-10-28 00:25:33 UTC (rev 53898)
@@ -151,9 +151,7 @@
typedef bool (*ANIMATION_CALLBACK)(uint);
- void registerLoopPointCallback(ANIMATION_CALLBACK callback, uint data = 0);
- void registerActionCallback(ANIMATION_CALLBACK callback, uint data = 0);
- void registerDeleteCallback(ANIMATION_CALLBACK Callback, uint Data = 0);
+ void setCallbacks();
protected:
virtual bool doRender();
@@ -178,13 +176,9 @@
uint _animationTemplateHandle;
bool _framesLocked;
- struct ANIMATION_CALLBACK_DATA {
- ANIMATION_CALLBACK Callback;
- uint Data;
- };
- Common::Array<ANIMATION_CALLBACK_DATA> _loopPointCallbacks;
- Common::Array<ANIMATION_CALLBACK_DATA> _actionCallbacks;
- Common::Array<ANIMATION_CALLBACK_DATA> _deleteCallbacks;
+ ANIMATION_CALLBACK _loopPointCallback;
+ ANIMATION_CALLBACK _actionCallback;
+ ANIMATION_CALLBACK _deleteCallback;
/**
@brief Lockt alle Frames.
@@ -216,8 +210,6 @@
int computeYModifier() const;
void initMembers();
- void persistCallbackVector(OutputPersistenceBlock &writer, const Common::Array<ANIMATION_CALLBACK_DATA> &vector);
- void unpersistCallbackVector(InputPersistenceBlock &reader, Common::Array<ANIMATION_CALLBACK_DATA> &vector);
AnimationDescription *getAnimationDescription() const;
void initializeAnimationResource(const Common::String &fileName);
};
Modified: scummvm/trunk/engines/sword25/gfx/graphicengine_script.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/graphicengine_script.cpp 2010-10-28 00:24:53 UTC (rev 53897)
+++ scummvm/trunk/engines/sword25/gfx/graphicengine_script.cpp 2010-10-28 00:25:33 UTC (rev 53898)
@@ -34,7 +34,6 @@
#include "sword25/kernel/common.h"
#include "sword25/kernel/kernel.h"
-#include "sword25/kernel/callbackregistry.h"
#include "sword25/script/script.h"
#include "sword25/script/luabindhelper.h"
#include "sword25/script/luacallback.h"
@@ -621,15 +620,19 @@
lua_setmetatable(L, -2);
// Alle Animationscallbacks registrieren.
- animationPtr->registerDeleteCallback(animationDeleteCallback, animationPtr->getHandle());
- animationPtr->registerLoopPointCallback(animationLoopPointCallback, animationPtr->getHandle());
- animationPtr->registerActionCallback(animationActionCallback, animationPtr->getHandle());
+ animationPtr->setCallbacks();
} else
lua_pushnil(L);
return 1;
}
+void Animation::setCallbacks() {
+ _actionCallback = animationActionCallback;
+ _loopPointCallback = animationLoopPointCallback;
+ _deleteCallback = animationDeleteCallback;
+}
+
static const luaL_reg RENDEROBJECT_METHODS[] = {
{"AddAnimation", ro_addAnimation},
{"AddText", ro_addText},
@@ -1288,10 +1291,6 @@
assert(actionCallbackPtr == 0);
actionCallbackPtr = new ActionCallback(L);
- CallbackRegistry::instance().registerCallbackFunction("LuaLoopPointCB", (void ( *)(int))animationLoopPointCallback);
- CallbackRegistry::instance().registerCallbackFunction("LuaActionCB", (void ( *)(int))animationActionCallback);
- CallbackRegistry::instance().registerCallbackFunction("LuaDeleteCB", (void ( *)(int))animationDeleteCallback);
-
return true;
}
Deleted: scummvm/trunk/engines/sword25/kernel/callbackregistry.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/callbackregistry.cpp 2010-10-28 00:24:53 UTC (rev 53897)
+++ scummvm/trunk/engines/sword25/kernel/callbackregistry.cpp 2010-10-28 00:25:33 UTC (rev 53898)
@@ -1,111 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-/*
- * This code is based on Broken Sword 2.5 engine
- *
- * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
- *
- * Licensed under GNU GPL v2
- *
- */
-
-// Alle Callbackfunktionen die von Objekten gerufen werden, die persistiert werden k\xF6nnen, m\xFCssen hier registriert werden.
-// Beim Speichern wird statt des Pointers der Bezeichner gespeichert. Beim Laden wird der Bezeichner wieder in einen Pointer umgewandelt.
-// Diese Klasse f\xFChrt also so etwas \xE4hnliches wie eine Importtabelle f\xFCr Callback-Funktionen.
-//
-// Dieses Vorgehen hat mehrere Vorteile:
-// 1. Die Speicherst\xE4nde sind plattformunabh\xE4ngig. Es werden keine Pointer auf Funktionen gespeichert, sondern nur Namen von Callbackfunktionen.
-// Diese k\xF6nnen beim Laden \xFCber diese Klasse in systemabh\xE4ngige Pointer umgewandelt werden.
-// 2. Speicherst\xE4nde k\xF6nnen auch nach einem Engineupdate weiterhin benutzt werden. Beim Erstellen einer neun Binary verschieben sich h\xE4ufig die
-// Funktionen. Eine Callbackfunktion k\xF6nnte sich also nach einem Update an einer anderen Stelle befinden als davor. Wenn im Spielstand der
-// Pointer gespeichert war, st\xFCrtzt das Programm beim \xC4ufrufen dieser Callbackfunktion ab. Durch das Aufl\xF6sungverfahren wird beim Laden der
-// Callbackbezeichner in den neuen Funktionspointer umgewandelt und der Aufruf kann erfolgen.
-
-#define BS_LOG_PREFIX "CALLBACKREGISTRY"
-
-#include "sword25/kernel/callbackregistry.h"
-
-namespace Sword25 {
-
-bool CallbackRegistry::registerCallbackFunction(const Common::String &name, CallbackPtr ptr) {
- if (name == "") {
- BS_LOG_ERRORLN("The empty string is not allowed as a callback function name.");
- return false;
- }
-
- if (findPtrByName(name) != 0) {
- BS_LOG_ERRORLN("There is already a callback function with the name \"%s\".", name.c_str());
- return false;
- }
- if (findNameByPtr(ptr) != "") {
- BS_LOG_ERRORLN("There is already a callback function with the pointer 0x%x.", ptr);
- return false;
- }
-
- storeCallbackFunction(name, ptr);
-
- return true;
-}
-
-CallbackPtr CallbackRegistry::resolveCallbackFunction(const Common::String &name) const {
- CallbackPtr result = findPtrByName(name);
-
- if (!result) {
- BS_LOG_ERRORLN("There is no callback function with the name \"%s\".", name.c_str());
- }
-
- return result;
-}
-
-Common::String CallbackRegistry::resolveCallbackPointer(CallbackPtr ptr) const {
- const Common::String &result = findNameByPtr(ptr);
-
- if (result == "") {
- BS_LOG_ERRORLN("There is no callback function with the pointer 0x%x.", ptr);
- }
-
- return result;
-}
-
-CallbackPtr CallbackRegistry::findPtrByName(const Common::String &name) const {
- // Eintrag in der Map finden und den Pointer zur\xFCckgeben.
- NameToPtrMap::const_iterator it = _nameToPtrMap.find(name);
- return it == _nameToPtrMap.end() ? 0 : it->_value;
-}
-
-Common::String CallbackRegistry::findNameByPtr(CallbackPtr ptr) const {
- // Eintrag in der Map finden und den Namen zur\xFCckgeben.
- PtrToNameMap::const_iterator it = _ptrToNameMap.find(ptr);
- return it == _ptrToNameMap.end() ? "" : it->_value;
-}
-
-void CallbackRegistry::storeCallbackFunction(const Common::String &name, CallbackPtr ptr) {
- // Callback-Funktion in beide Maps eintragen.
- _nameToPtrMap[name] = ptr;
- _ptrToNameMap[ptr] = name;
-}
-
-} // End of namespace Sword25
Deleted: scummvm/trunk/engines/sword25/kernel/callbackregistry.h
===================================================================
--- scummvm/trunk/engines/sword25/kernel/callbackregistry.h 2010-10-28 00:24:53 UTC (rev 53897)
+++ scummvm/trunk/engines/sword25/kernel/callbackregistry.h 2010-10-28 00:25:33 UTC (rev 53898)
@@ -1,84 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-/*
- * This code is based on Broken Sword 2.5 engine
- *
- * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
- *
- * Licensed under GNU GPL v2
- *
- */
-
-#ifndef SWORD25_CALLBACK_REGISTRY_H
-#define SWORD25_CALLBACK_REGISTRY_H
-
-#include "common/scummsys.h"
-#include "common/str.h"
-#include "common/hash-str.h"
-#include "common/hashmap.h"
-#include "sword25/kernel/common.h"
-
-namespace Sword25 {
-
-typedef void (*CallbackPtr)(int command);
-
-class CallbackRegistry {
-public:
- static CallbackRegistry &instance() {
- static CallbackRegistry _instance;
- return _instance;
- }
-
- bool registerCallbackFunction(const Common::String &name, CallbackPtr ptr);
- CallbackPtr resolveCallbackFunction(const Common::String &name) const;
- Common::String resolveCallbackPointer(CallbackPtr ptr) const;
-
-private:
- typedef Common::HashMap<Common::String, CallbackPtr, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> NameToPtrMap;
- NameToPtrMap _nameToPtrMap;
-
- struct CallbackPtr_EqualTo {
- bool operator()(CallbackPtr x, CallbackPtr y) const {
- return x == y;
- }
- };
- struct CallbackPtr_Hash {
- uint operator()(CallbackPtr x) const {
- return *(uint *)&x;
- }
- };
-
- typedef Common::HashMap<CallbackPtr, Common::String, CallbackPtr_Hash, CallbackPtr_EqualTo> PtrToNameMap;
- PtrToNameMap _ptrToNameMap;
-
- CallbackPtr findPtrByName(const Common::String &name) const;
- Common::String findNameByPtr(CallbackPtr ptr) const;
- void storeCallbackFunction(const Common::String &name, CallbackPtr ptr);
-};
-
-} // End of namespace Sword25
-
-#endif
Modified: scummvm/trunk/engines/sword25/module.mk
===================================================================
--- scummvm/trunk/engines/sword25/module.mk 2010-10-28 00:24:53 UTC (rev 53897)
+++ scummvm/trunk/engines/sword25/module.mk 2010-10-28 00:25:33 UTC (rev 53898)
@@ -33,7 +33,6 @@
gfx/image/vectorimagerenderer.o \
input/inputengine.o \
input/inputengine_script.o \
- kernel/callbackregistry.o \
kernel/filesystemutil.o \
kernel/inputpersistenceblock.o \
kernel/kernel.o \
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list