From c483a22f2a8c02c2b1ecaf5f9626999fd3ed3c7e Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 23 Oct 2010 15:44:04 +0000 Subject: SWORD25: Get rid of global SharedPtr instances svn-id: r53734 --- engines/sword25/gfx/graphicengine.cpp | 1 + engines/sword25/gfx/graphicengine.h | 1 + engines/sword25/gfx/graphicengine_script.cpp | 19 +++++++++++++++---- engines/sword25/input/inputengine.cpp | 4 ++++ engines/sword25/input/inputengine.h | 3 ++- engines/sword25/input/inputengine_script.cpp | 21 +++++++++++++++++---- 6 files changed, 40 insertions(+), 9 deletions(-) (limited to 'engines/sword25') diff --git a/engines/sword25/gfx/graphicengine.cpp b/engines/sword25/gfx/graphicengine.cpp index 37499cc14d..54aa243cd8 100644 --- a/engines/sword25/gfx/graphicengine.cpp +++ b/engines/sword25/gfx/graphicengine.cpp @@ -85,6 +85,7 @@ GraphicEngine::GraphicEngine(Kernel *pKernel) : } GraphicEngine::~GraphicEngine() { + unregisterScriptBindings(); _backSurface.free(); _frameBuffer.free(); delete _thumbnail; diff --git a/engines/sword25/gfx/graphicengine.h b/engines/sword25/gfx/graphicengine.h index 5820a8d420..26eeaa2e22 100644 --- a/engines/sword25/gfx/graphicengine.h +++ b/engines/sword25/gfx/graphicengine.h @@ -363,6 +363,7 @@ protected: private: bool registerScriptBindings(); + void unregisterScriptBindings(); // LastFrameDuration Variables // --------------------------- diff --git a/engines/sword25/gfx/graphicengine_script.cpp b/engines/sword25/gfx/graphicengine_script.cpp index 956c0352f0..fa97b80c82 100644 --- a/engines/sword25/gfx/graphicengine_script.cpp +++ b/engines/sword25/gfx/graphicengine_script.cpp @@ -71,8 +71,8 @@ protected: } }; -Common::ScopedPtr loopPointCallbackPtr; -Common::ScopedPtr actionCallbackPtr; +static LuaCallback *loopPointCallbackPtr = 0; // FIXME: should be turned into GraphicEngine member var +static ActionCallback *actionCallbackPtr = 0; // FIXME: should be turned into GraphicEngine member var struct CallbackfunctionRegisterer { CallbackfunctionRegisterer() { @@ -1289,10 +1289,21 @@ bool GraphicEngine::registerScriptBindings() { if (!LuaBindhelper::addFunctionsToLib(L, GFX_LIBRARY_NAME, GFX_FUNCTIONS)) return false; - loopPointCallbackPtr.reset(new LuaCallback(L)); - actionCallbackPtr.reset(new ActionCallback(L)); + assert(loopPointCallbackPtr == 0); + loopPointCallbackPtr = new LuaCallback(L); + + assert(actionCallbackPtr == 0); + actionCallbackPtr = new ActionCallback(L); return true; } +void GraphicEngine::unregisterScriptBindings() { + delete loopPointCallbackPtr; + loopPointCallbackPtr = 0; + + delete actionCallbackPtr; + actionCallbackPtr = 0; +} + } // End of namespace Sword25 diff --git a/engines/sword25/input/inputengine.cpp b/engines/sword25/input/inputengine.cpp index 181e13b7ff..425e46431c 100644 --- a/engines/sword25/input/inputengine.cpp +++ b/engines/sword25/input/inputengine.cpp @@ -76,6 +76,10 @@ InputEngine::InputEngine(Kernel *pKernel) : BS_LOGLN("Script bindings registered."); } +InputEngine::~InputEngine() { + unregisterScriptBindings(); +} + Service *InputEngine_CreateObject(Kernel *pKernel) { return new InputEngine(pKernel); } diff --git a/engines/sword25/input/inputengine.h b/engines/sword25/input/inputengine.h index 07e56928cb..20bea21a72 100644 --- a/engines/sword25/input/inputengine.h +++ b/engines/sword25/input/inputengine.h @@ -57,7 +57,7 @@ namespace Sword25 { class InputEngine : public Service, public Persistable { public: InputEngine(Kernel *pKernel); - ~InputEngine() {} + ~InputEngine(); // NOTE: These codes are registered in inputengine_script.cpp // Any changes to these enums must also adjust the above file. @@ -303,6 +303,7 @@ public: private: bool registerScriptBindings(); + void unregisterScriptBindings(); private: void testForLeftDoubleClick(); diff --git a/engines/sword25/input/inputengine_script.cpp b/engines/sword25/input/inputengine_script.cpp index 303f0e69e1..0ada7ece5c 100644 --- a/engines/sword25/input/inputengine_script.cpp +++ b/engines/sword25/input/inputengine_script.cpp @@ -63,7 +63,8 @@ protected: return 1; } }; -Common::SharedPtr characterCallbackPtr; + +static CharacterCallbackClass *characterCallbackPtr = 0; // FIXME: should be turned into InputEngine member var class CommandCallbackClass : public LuaCallback { public: @@ -79,7 +80,8 @@ protected: return 1; } }; -Common::SharedPtr commandCallbackPtr; + +static CommandCallbackClass *commandCallbackPtr = 0; // FIXME: should be turned into InputEngine member var struct CallbackfunctionRegisterer { CallbackfunctionRegisterer() { @@ -290,10 +292,21 @@ bool InputEngine::registerScriptBindings() { if (!LuaBindhelper::addFunctionsToLib(L, PACKAGE_LIBRARY_NAME, PACKAGE_FUNCTIONS)) return false; if (!LuaBindhelper::addConstantsToLib(L, PACKAGE_LIBRARY_NAME, PACKAGE_CONSTANTS)) return false; - characterCallbackPtr = Common::SharedPtr(new CharacterCallbackClass(L)); - commandCallbackPtr = Common::SharedPtr(new CommandCallbackClass(L)); + assert(characterCallbackPtr == 0); + characterCallbackPtr = new CharacterCallbackClass(L); + + assert(commandCallbackPtr == 0); + commandCallbackPtr = new CommandCallbackClass(L); return true; } +void InputEngine::unregisterScriptBindings() { + delete characterCallbackPtr; + characterCallbackPtr = 0; + + delete commandCallbackPtr; + commandCallbackPtr = 0; +} + } // End of namespace Sword25 -- cgit v1.2.3