diff options
author | Paul Gilbert | 2010-08-03 09:47:45 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2010-10-12 22:21:24 +0000 |
commit | 86bef1508c3fb3c21a10e3f35305f6eaf641a33e (patch) | |
tree | c2a47a3cca578ba5b9b6a156ddbc576221f14beb | |
parent | fab86ba22250c282139fb0c94a250499abdc875f (diff) | |
download | scummvm-rg350-86bef1508c3fb3c21a10e3f35305f6eaf641a33e.tar.gz scummvm-rg350-86bef1508c3fb3c21a10e3f35305f6eaf641a33e.tar.bz2 scummvm-rg350-86bef1508c3fb3c21a10e3f35305f6eaf641a33e.zip |
SWORD25: Converted the input engine to use the ScummVM event manager
svn-id: r53203
-rw-r--r-- | engines/sword25/input/scummvminput.cpp (renamed from engines/sword25/input/stdwininput.cpp) | 298 | ||||
-rw-r--r-- | engines/sword25/input/scummvminput.h (renamed from engines/sword25/input/stdwininput.h) | 7 | ||||
-rw-r--r-- | engines/sword25/kernel/callbackregistry.h | 31 | ||||
-rw-r--r-- | engines/sword25/kernel/inputpersistenceblock.h | 4 | ||||
-rw-r--r-- | engines/sword25/kernel/service_ids.h | 26 | ||||
-rw-r--r-- | engines/sword25/script/luascript.cpp | 8 |
6 files changed, 176 insertions, 198 deletions
diff --git a/engines/sword25/input/stdwininput.cpp b/engines/sword25/input/scummvminput.cpp index 3da3a6747c..d0824cd0e4 100644 --- a/engines/sword25/input/stdwininput.cpp +++ b/engines/sword25/input/scummvminput.cpp @@ -32,36 +32,41 @@ * */ +#include "common/algorithm.h" +#include "common/events.h" +#include "common/system.h" +#include "common/util.h" #include "sword25/kernel/kernel.h" #include "sword25/kernel/callbackregistry.h" #include "sword25/kernel/inputpersistenceblock.h" #include "sword25/kernel/outputpersistenceblock.h" -#include "sword25/input/stdwininput.h" +#include "sword25/input/scummvminput.h" -#include <algorithm> -using namespace std; +#define BS_LOG_PREFIX "SCUMMVMINPUT" -#define BS_LOG_PREFIX "WININPUT" +namespace Sword25 { + +#define DOUBLE_CLICK_TIME 500 +#define DOUBLE_CLICK_RECT_SIZE 4 // ----------------------------------------------------------------------------- -// Konstruktion / Destruktion +// Constructor / Destructor // ----------------------------------------------------------------------------- -BS_StdWinInput::BS_StdWinInput(BS_Kernel* pKernel) : - m_CurrentState(0), - m_LeftMouseDown(false), - m_RightMouseDown(false), - m_MouseX(0), - m_MouseY(0), - m_LeftDoubleClick(false), - m_DoubleClickTime(GetDoubleClickTime()), - m_DoubleClickRectWidth(GetSystemMetrics(SM_CXDOUBLECLK)), - m_DoubleClickRectHeight(GetSystemMetrics(SM_CYDOUBLECLK)), - m_LastLeftClickTime(0), - m_LastLeftClickMouseX(0), - m_LastLeftClickMouseY(0), - BS_InputEngine(pKernel) -{ +ScummVMInput::ScummVMInput(BS_Kernel *pKernel) : + m_CurrentState(0), + m_LeftMouseDown(false), + m_RightMouseDown(false), + m_MouseX(0), + m_MouseY(0), + m_LeftDoubleClick(false), + m_DoubleClickTime(DOUBLE_CLICK_TIME), + m_DoubleClickRectWidth(DOUBLE_CLICK_RECT_SIZE), + m_DoubleClickRectHeight(DOUBLE_CLICK_RECT_SIZE), + m_LastLeftClickTime(0), + m_LastLeftClickMouseX(0), + m_LastLeftClickMouseY(0), + BS_InputEngine(pKernel) { memset(m_KeyboardState[0], 0, sizeof(m_KeyboardState[0])); memset(m_KeyboardState[1], 0, sizeof(m_KeyboardState[1])); m_LeftMouseState[0] = false; @@ -70,105 +75,101 @@ BS_StdWinInput::BS_StdWinInput(BS_Kernel* pKernel) : m_RightMouseState[1] = false; } -BS_StdWinInput::~BS_StdWinInput() -{ +ScummVMInput::~ScummVMInput() { } // ----------------------------------------------------------------------------- -BS_Service * BS_StdWinInput_CreateObject(BS_Kernel* pKernel) { return new BS_StdWinInput(pKernel); } +BS_Service *ScummVMInput_CreateObject(BS_Kernel *pKernel) { return new ScummVMInput(pKernel); } // ----------------------------------------------------------------------------- -bool BS_StdWinInput::Init() -{ - // Keine Inialisierung notwendig +bool ScummVMInput::Init() { + // No initialisation needed return true; } // ----------------------------------------------------------------------------- -void BS_StdWinInput::Update() -{ - // Der Status wird nur aktualisiert, wenn das Applikationsfenster den Fokus hat, so wird verhindert, dass - // Eingaben verarbeitet werden, die eigentlich für eine andere Applikation gedacht waren. - if (BS_Kernel::GetInstance()->GetWindow()->HasFocus()) - { - m_CurrentState ^= 1; - - // Der Status der Eingabegeräte wird nur einmal pro Frame ausgelesen, damit für - // jeden Frame gleiche Anfragen die gleiche Antwort erhalten. - - POINT MousePos; - if (GetCursorPos(&MousePos)) - { - m_MouseX = MousePos.x - BS_Kernel::GetInstance()->GetWindow()->GetClientX(); - m_MouseY = MousePos.y - BS_Kernel::GetInstance()->GetWindow()->GetClientY(); +void ScummVMInput::Update() { + Common::Event event; + m_CurrentState ^= 1; + + // Loop through processing any pending events + bool handleEvents = true; + while (handleEvents && g_system->getEventManager()->pollEvent(event)) { + switch (event.type) { + case Common::EVENT_LBUTTONDOWN: + case Common::EVENT_LBUTTONUP: + m_LeftMouseDown = event.type == Common::EVENT_LBUTTONDOWN; + m_MouseX = event.mouse.x; m_MouseY = event.mouse.y; + handleEvents = false; + break; + case Common::EVENT_RBUTTONDOWN: + case Common::EVENT_RBUTTONUP: + m_RightMouseDown = event.type == Common::EVENT_RBUTTONDOWN; + m_MouseX = event.mouse.x; m_MouseY = event.mouse.y; + handleEvents = false; + break; + + case Common::EVENT_MOUSEMOVE: + m_MouseX = event.mouse.x; m_MouseY = event.mouse.y; + break; + + case Common::EVENT_KEYDOWN: + case Common::EVENT_KEYUP: + AlterKeyboardState(event.kbd.keycode, (event.type == Common::EVENT_KEYDOWN) ? 0x80 : 0); + break; + + default: + break; } - else - { - BS_LOG_ERRORLN("Call to GetCursorPos() failed."); - m_MouseX = 0; - m_MouseY = 0; - } - - GetKeyboardState(m_KeyboardState[m_CurrentState]); + } - m_LeftMouseDown = (GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0; - m_RightMouseDown = (GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0; - m_LeftMouseState[m_CurrentState] = m_LeftMouseDown; - m_RightMouseState[m_CurrentState] = m_RightMouseDown; + m_LeftMouseState[m_CurrentState] = m_LeftMouseDown; + m_RightMouseState[m_CurrentState] = m_RightMouseDown; - TestForLeftDoubleClick(); - } + TestForLeftDoubleClick(); } // ----------------------------------------------------------------------------- -bool BS_StdWinInput::IsLeftMouseDown() -{ +bool ScummVMInput::IsLeftMouseDown() { return m_LeftMouseDown; } // ----------------------------------------------------------------------------- -bool BS_StdWinInput::IsRightMouseDown() -{ +bool ScummVMInput::IsRightMouseDown() { return m_RightMouseDown; } // ----------------------------------------------------------------------------- -void BS_StdWinInput::TestForLeftDoubleClick() -{ - // Das Doppelklick-Flag wird gelöscht, für den Fall, dass im letzten Frame ein Doppelklick ausgetreten ist. +void ScummVMInput::TestForLeftDoubleClick() { m_LeftDoubleClick = false; - // Die linke Maustaste wurde geklickt, also muss getestet werden, ob ein Doppelklick vorliegt. - if (WasLeftMouseDown()) - { - // Die Zeit auslesen. + // Only bother checking for a double click if the left mouse button was clicked + if (WasLeftMouseDown()) { + // Get the time now unsigned int Now = BS_Kernel::GetInstance()->GetMilliTicks(); - // Ein Doppelklick wird erkannt, wenn: - // 1. Die zwei Klicks liegen nah genug zusammen. - // 2. Der Mauscursor wurde zwischen den Klicks nicht zu viel bewegt. + // A double click is signalled if + // 1. The two clicks are close enough together + // 2. The mouse cursor hasn't moved much if (Now - m_LastLeftClickTime <= m_DoubleClickTime && - abs(m_MouseX - m_LastLeftClickMouseX) <= m_DoubleClickRectWidth / 2 && - abs(m_MouseY - m_LastLeftClickMouseY) <= m_DoubleClickRectHeight / 2) - { + ABS(m_MouseX - m_LastLeftClickMouseX) <= m_DoubleClickRectWidth / 2 && + ABS(m_MouseY - m_LastLeftClickMouseY) <= m_DoubleClickRectHeight / 2) { m_LeftDoubleClick = true; - // Die Zeit und Position des letzten Linksklicks zurücksetzen, damit dieser Klick nicht als erster Klick eines weiteren Doppelklicks - // interpretiert wird. + // Reset the time and position of the last click, so that clicking is not + // interpreted as the first click of a further double-click m_LastLeftClickTime = 0; m_LastLeftClickMouseX = 0; m_LastLeftClickMouseY = 0; - } - else - { - // Es liegt kein Doppelklick vor, die Zeit und die Position dieses Klicks merken, für den Fall das dies der erste Klick eines - // zukünftigen Doppelklicks wird. + } else { + // There is no double click. Remember the position and time of the click, + // in case it's the first click of a double-click sequence m_LastLeftClickTime = Now; m_LastLeftClickMouseX = m_MouseX; m_LastLeftClickMouseY = m_MouseY; @@ -178,80 +179,74 @@ void BS_StdWinInput::TestForLeftDoubleClick() // ----------------------------------------------------------------------------- -bool BS_StdWinInput::IsLeftDoubleClick() -{ +void AlterKeyboardState(int keycode, byte newState) { + +} + +// ----------------------------------------------------------------------------- + +bool ScummVMInput::IsLeftDoubleClick() { return m_LeftDoubleClick; } // ----------------------------------------------------------------------------- -bool BS_StdWinInput::WasLeftMouseDown() -{ +bool ScummVMInput::WasLeftMouseDown() { return (m_LeftMouseState[m_CurrentState] == false) && (m_LeftMouseState[m_CurrentState ^ 1] == true); } // ----------------------------------------------------------------------------- -bool BS_StdWinInput::WasRightMouseDown() -{ +bool ScummVMInput::WasRightMouseDown() { return (m_RightMouseState[m_CurrentState] == false) && (m_RightMouseState[m_CurrentState ^ 1] == true); } // ----------------------------------------------------------------------------- -int BS_StdWinInput::GetMouseX() -{ +int ScummVMInput::GetMouseX() { return m_MouseX; } // ----------------------------------------------------------------------------- -int BS_StdWinInput::GetMouseY() -{ +int ScummVMInput::GetMouseY() { return m_MouseY; } // ----------------------------------------------------------------------------- -bool BS_StdWinInput::IsKeyDown(unsigned int KeyCode) -{ +bool ScummVMInput::IsKeyDown(unsigned int KeyCode) { return (m_KeyboardState[m_CurrentState][KeyCode] & 0x80) != 0; } // ----------------------------------------------------------------------------- -bool BS_StdWinInput::WasKeyDown(unsigned int KeyCode) -{ - return ((m_KeyboardState[m_CurrentState][KeyCode] & 0x80) == 0) && ((m_KeyboardState[m_CurrentState ^ 1][KeyCode] & 0x80) != 0); +bool ScummVMInput::WasKeyDown(unsigned int KeyCode) { + return ((m_KeyboardState[m_CurrentState][KeyCode] & 0x80) == 0) && + ((m_KeyboardState[m_CurrentState ^ 1][KeyCode] & 0x80) != 0); } // ----------------------------------------------------------------------------- -void BS_StdWinInput::SetMouseX(int PosX) -{ +void ScummVMInput::SetMouseX(int PosX) { m_MouseX = PosX; - SetCursorPos(m_MouseX + BS_Kernel::GetInstance()->GetWindow()->GetClientX(), m_MouseY + BS_Kernel::GetInstance()->GetWindow()->GetClientY()); + g_system->warpMouse(m_MouseX, m_MouseY); } // ----------------------------------------------------------------------------- -void BS_StdWinInput::SetMouseY(int PosY) -{ +void ScummVMInput::SetMouseY(int PosY) { m_MouseY = PosY; - SetCursorPos(m_MouseX + BS_Kernel::GetInstance()->GetWindow()->GetClientX(), m_MouseY + BS_Kernel::GetInstance()->GetWindow()->GetClientY()); + g_system->warpMouse(m_MouseX, m_MouseY); } // ----------------------------------------------------------------------------- -bool BS_StdWinInput::RegisterCharacterCallback(CharacterCallback Callback) -{ - if (find(m_CharacterCallbacks.begin(), m_CharacterCallbacks.end(), Callback) == m_CharacterCallbacks.end()) - { +bool ScummVMInput::RegisterCharacterCallback(CharacterCallback Callback) { + if (Common::find(m_CharacterCallbacks.begin(), m_CharacterCallbacks.end(), Callback) == m_CharacterCallbacks.end()) { m_CharacterCallbacks.push_back(Callback); return true; - } - else - { + } else { BS_LOG_WARNINGLN("Tried to register an CharacterCallback that was already registered."); return false; } @@ -259,16 +254,13 @@ bool BS_StdWinInput::RegisterCharacterCallback(CharacterCallback Callback) // ----------------------------------------------------------------------------- -bool BS_StdWinInput::UnregisterCharacterCallback(CharacterCallback Callback) -{ - list<CharacterCallback>::iterator CallbackIter = find(m_CharacterCallbacks.begin(), m_CharacterCallbacks.end(), Callback); - if (CallbackIter != m_CharacterCallbacks.end()) - { +bool ScummVMInput::UnregisterCharacterCallback(CharacterCallback Callback) { + Common::List<CharacterCallback>::iterator CallbackIter = Common::find(m_CharacterCallbacks.begin(), + m_CharacterCallbacks.end(), Callback); + if (CallbackIter != m_CharacterCallbacks.end()) { m_CharacterCallbacks.erase(CallbackIter); return true; - } - else - { + } else { BS_LOG_WARNINGLN("Tried to unregister an CharacterCallback that was not previously registered."); return false; } @@ -276,15 +268,11 @@ bool BS_StdWinInput::UnregisterCharacterCallback(CharacterCallback Callback) // ----------------------------------------------------------------------------- -bool BS_StdWinInput::RegisterCommandCallback(CommandCallback Callback) -{ - if (find(m_CommandCallbacks.begin(), m_CommandCallbacks.end(), Callback) == m_CommandCallbacks.end()) - { +bool ScummVMInput::RegisterCommandCallback(CommandCallback Callback) { + if (Common::find(m_CommandCallbacks.begin(), m_CommandCallbacks.end(), Callback) == m_CommandCallbacks.end()) { m_CommandCallbacks.push_back(Callback); return true; - } - else - { + } else { BS_LOG_WARNINGLN("Tried to register an CommandCallback that was already registered."); return false; } @@ -292,16 +280,13 @@ bool BS_StdWinInput::RegisterCommandCallback(CommandCallback Callback) // ----------------------------------------------------------------------------- -bool BS_StdWinInput::UnregisterCommandCallback(CommandCallback Callback) -{ - list<CommandCallback>::iterator CallbackIter = find(m_CommandCallbacks.begin(), m_CommandCallbacks.end(), Callback); - if (CallbackIter != m_CommandCallbacks.end()) - { +bool ScummVMInput::UnregisterCommandCallback(CommandCallback Callback) { + Common::List<CommandCallback>::iterator CallbackIter = + Common::find(m_CommandCallbacks.begin(), m_CommandCallbacks.end(), Callback); + if (CallbackIter != m_CommandCallbacks.end()) { m_CommandCallbacks.erase(CallbackIter); return true; - } - else - { + } else { BS_LOG_WARNINGLN("Tried to unregister an CommandCallback that was not previously registered."); return false; } @@ -309,15 +294,13 @@ bool BS_StdWinInput::UnregisterCommandCallback(CommandCallback Callback) // ----------------------------------------------------------------------------- -void BS_StdWinInput::ReportCharacter(unsigned char Character) -{ - list<CharacterCallback>::const_iterator CallbackIter = m_CharacterCallbacks.begin(); - while (CallbackIter != m_CharacterCallbacks.end()) - { +void ScummVMInput::ReportCharacter(unsigned char Character) { + Common::List<CharacterCallback>::const_iterator CallbackIter = m_CharacterCallbacks.begin(); + while (CallbackIter != m_CharacterCallbacks.end()) { // Iterator vor dem Aufruf erhöhen und im Folgendem auf einer Kopie arbeiten. // Dieses Vorgehen ist notwendig da der Iterator möglicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks // invalidiert wird. - list<CharacterCallback>::const_iterator CurCallbackIter = CallbackIter; + Common::List<CharacterCallback>::const_iterator CurCallbackIter = CallbackIter; ++CallbackIter; (*CurCallbackIter)(Character); @@ -326,15 +309,13 @@ void BS_StdWinInput::ReportCharacter(unsigned char Character) // ----------------------------------------------------------------------------- -void BS_StdWinInput::ReportCommand(KEY_COMMANDS Command) -{ - list<CommandCallback>::const_iterator CallbackIter = m_CommandCallbacks.begin(); - while (CallbackIter != m_CommandCallbacks.end()) - { +void ScummVMInput::ReportCommand(KEY_COMMANDS Command) { + Common::List<CommandCallback>::const_iterator CallbackIter = m_CommandCallbacks.begin(); + while (CallbackIter != m_CommandCallbacks.end()) { // Iterator vor dem Aufruf erhöhen und im Folgendem auf einer Kopie arbeiten. // Dieses Vorgehen ist notwendig da der Iterator möglicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks // invalidiert wird. - list<CommandCallback>::const_iterator CurCallbackIter = CallbackIter; + Common::List<CommandCallback>::const_iterator CurCallbackIter = CallbackIter; ++CallbackIter; (*CurCallbackIter)(Command); @@ -345,16 +326,14 @@ void BS_StdWinInput::ReportCommand(KEY_COMMANDS Command) // Persistenz // ----------------------------------------------------------------------------- -bool BS_StdWinInput::Persist(BS_OutputPersistenceBlock & Writer) -{ +bool ScummVMInput::Persist(BS_OutputPersistenceBlock &Writer) { // Anzahl an Command-Callbacks persistieren. Writer.Write(m_CommandCallbacks.size()); // Alle Command-Callbacks einzeln persistieren. { - list<CommandCallback>::const_iterator It = m_CommandCallbacks.begin(); - while (It != m_CommandCallbacks.end()) - { + Common::List<CommandCallback>::const_iterator It = m_CommandCallbacks.begin(); + while (It != m_CommandCallbacks.end()) { Writer.Write(BS_CallbackRegistry::GetInstance().ResolveCallbackPointer(*It)); ++It; } @@ -365,9 +344,8 @@ bool BS_StdWinInput::Persist(BS_OutputPersistenceBlock & Writer) // Alle Character-Callbacks einzeln persistieren. { - list<CharacterCallback>::const_iterator It = m_CharacterCallbacks.begin(); - while (It != m_CharacterCallbacks.end()) - { + Common::List<CharacterCallback>::const_iterator It = m_CharacterCallbacks.begin(); + while (It != m_CharacterCallbacks.end()) { Writer.Write(BS_CallbackRegistry::GetInstance().ResolveCallbackPointer(*It)); ++It; } @@ -378,8 +356,7 @@ bool BS_StdWinInput::Persist(BS_OutputPersistenceBlock & Writer) // ----------------------------------------------------------------------------- -bool BS_StdWinInput::Unpersist(BS_InputPersistenceBlock & Reader) -{ +bool ScummVMInput::Unpersist(BS_InputPersistenceBlock &Reader) { // Command-Callbackliste leeren. m_CommandCallbacks.clear(); @@ -388,12 +365,12 @@ bool BS_StdWinInput::Unpersist(BS_InputPersistenceBlock & Reader) Reader.Read(CommandCallbackCount); // Alle Command-Callbacks wieder herstellen. - for (unsigned int i = 0; i < CommandCallbackCount; ++i) - { - std::string CallbackFunctionName; + for (unsigned int i = 0; i < CommandCallbackCount; ++i) { + Common::String CallbackFunctionName; Reader.Read(CallbackFunctionName); - m_CommandCallbacks.push_back(reinterpret_cast<CommandCallback>(BS_CallbackRegistry::GetInstance().ResolveCallbackFunction(CallbackFunctionName))); + m_CommandCallbacks.push_back(reinterpret_cast<CommandCallback>( + BS_CallbackRegistry::GetInstance().ResolveCallbackFunction(CallbackFunctionName))); } // Character-Callbackliste leeren. @@ -404,9 +381,8 @@ bool BS_StdWinInput::Unpersist(BS_InputPersistenceBlock & Reader) Reader.Read(CharacterCallbackCount); // Alle Character-Callbacks wieder herstellen. - for (unsigned int i = 0; i < CharacterCallbackCount; ++i) - { - std::string CallbackFunctionName; + for (unsigned int i = 0; i < CharacterCallbackCount; ++i) { + Common::String CallbackFunctionName; Reader.Read(CallbackFunctionName); m_CharacterCallbacks.push_back(reinterpret_cast<CharacterCallback>(BS_CallbackRegistry::GetInstance().ResolveCallbackFunction(CallbackFunctionName))); @@ -414,3 +390,5 @@ bool BS_StdWinInput::Unpersist(BS_InputPersistenceBlock & Reader) return Reader.IsGood(); } + +} // End of namespace Sword25 diff --git a/engines/sword25/input/stdwininput.h b/engines/sword25/input/scummvminput.h index 11ed63be49..a26060f4ab 100644 --- a/engines/sword25/input/stdwininput.h +++ b/engines/sword25/input/scummvminput.h @@ -47,10 +47,10 @@ namespace Sword25 { class BS_Kernel; /// Class definitions -class BS_StdWinInput : public BS_InputEngine { +class ScummVMInput : public BS_InputEngine { public: - BS_StdWinInput(BS_Kernel *pKernel); - virtual ~BS_StdWinInput(); + ScummVMInput(BS_Kernel *pKernel); + virtual ~ScummVMInput(); virtual bool Init(); virtual void Update(); @@ -77,6 +77,7 @@ public: private: void TestForLeftDoubleClick(); + void AlterKeyboardState(int keycode, byte newState); byte m_KeyboardState[2][256]; bool m_LeftMouseState[2]; diff --git a/engines/sword25/kernel/callbackregistry.h b/engines/sword25/kernel/callbackregistry.h index 19da7e30fb..4197930ae0 100644 --- a/engines/sword25/kernel/callbackregistry.h +++ b/engines/sword25/kernel/callbackregistry.h @@ -39,39 +39,40 @@ // Includes // ----------------------------------------------------------------------------- +#include "common/scummsys.h" +#include "common/str.h" +#include "common/hash-str.h" +#include "common/hashmap.h" #include "sword25/kernel/common.h" -#include "sword25/kernel/memlog_off.h" -#include <map> -#include "sword25/kernel/memlog_on.h" +namespace Sword25 { // ----------------------------------------------------------------------------- // Klassendeklaration // ----------------------------------------------------------------------------- -class BS_CallbackRegistry -{ +class BS_CallbackRegistry { public: - static BS_CallbackRegistry & GetInstance() - { + static BS_CallbackRegistry & GetInstance() { static BS_CallbackRegistry Instance; return Instance; } - bool RegisterCallbackFunction(const std::string & Name, void * Ptr); - void * ResolveCallbackFunction(const std::string & Name) const; - std::string ResolveCallbackPointer(void * Ptr) const; + bool RegisterCallbackFunction(const Common::String &Name, void * Ptr); + void * ResolveCallbackFunction(const Common::String &Name) const; + Common::String ResolveCallbackPointer(void *Ptr) const; private: - typedef std::map<std::string, void *> NameToPtrMap; + typedef Common::HashMap<Common::String, void *, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> NameToPtrMap; NameToPtrMap m_NameToPtrMap; - typedef std::map<void *, std::string> PtrToNameMap; + typedef Common::HashMap<void *, Common::String, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> PtrToNameMap; PtrToNameMap m_PtrToNameMap; - void * FindPtrByName(const std::string & Name) const; - std::string FindNameByPtr(void * Ptr) const; - void StoreCallbackFunction(const std::string & Name, void * Ptr); + void * FindPtrByName(const Common::String &Name) const; + Common::String FindNameByPtr(void * Ptr) const; + void StoreCallbackFunction(const Common::String & Name, void * Ptr); }; +} // End of namespace Sword25 #endif diff --git a/engines/sword25/kernel/inputpersistenceblock.h b/engines/sword25/kernel/inputpersistenceblock.h index b30429771b..0e8e3bf5e6 100644 --- a/engines/sword25/kernel/inputpersistenceblock.h +++ b/engines/sword25/kernel/inputpersistenceblock.h @@ -39,11 +39,9 @@ // Includes // ----------------------------------------------------------------------------- +#include "common/array.h" #include "sword25/kernel/common.h" #include "sword25/kernel/persistenceblock.h" -#include "sword25/kernel/memlog_off.h" -#include <vector> -#include "sword25/kernel/memlog_on.h" namespace Sword25 { diff --git a/engines/sword25/kernel/service_ids.h b/engines/sword25/kernel/service_ids.h index 1aefc2d890..7bb352d9e5 100644 --- a/engines/sword25/kernel/service_ids.h +++ b/engines/sword25/kernel/service_ids.h @@ -49,24 +49,24 @@ namespace Sword25 { -BS_Service *BS_OpenGLGfx_CreateObject(BS_Kernel* pKernel); -BS_Service *BS_ScummVMPackageManager_CreateObject(BS_Kernel* pKernel); -BS_Service *BS_StdWinInput_CreateObject(BS_Kernel* pKernel); -BS_Service *BS_FMODExSound_CreateObject(BS_Kernel* pKernel); -BS_Service *BS_LuaScriptEngine_CreateObject(BS_Kernel* pKernel); -BS_Service *BS_Geometry_CreateObject(BS_Kernel* pKernel); -BS_Service *BS_OggTheora_CreateObject(BS_Kernel* pKernel); +BS_Service *BS_OpenGLGfx_CreateObject(BS_Kernel *pKernel); +BS_Service *BS_ScummVMPackageManager_CreateObject(BS_Kernel *pKernel); +BS_Service *BS_ScummVMInput_CreateObject(BS_Kernel *pKernel); +BS_Service *BS_FMODExSound_CreateObject(BS_Kernel *pKernel); +BS_Service *BS_LuaScriptEngine_CreateObject(BS_Kernel *pKernel); +BS_Service *BS_Geometry_CreateObject(BS_Kernel *pKernel); +BS_Service *BS_OggTheora_CreateObject(BS_Kernel *pKernel); // Services are recorded in this table -const BS_ServiceInfo BS_SERVICE_TABLE[] = -{ - // Die ersten beiden Parameter sind die Namen der Superclass und des Services. - // Der dritte Parameter ist die statische Methode der Klasse, die ein Objekt der Klasse erzeugt und zurückgibt. - // Beispiel: +const BS_ServiceInfo BS_SERVICE_TABLE[] = { + // The first two parameters are the name of the superclass and service + // The third parameter is the static method of the class that creates an object + // of the class and returns it + // Example: // BS_ServiceInfo("Superclass", "Service", CreateMethod) BS_ServiceInfo("gfx", "opengl", BS_OpenGLGfx_CreateObject), BS_ServiceInfo("package", "archiveFS", BS_ScummVMPackageManager_CreateObject), - BS_ServiceInfo("input", "winapi", BS_StdWinInput_CreateObject), + BS_ServiceInfo("input", "winapi", BS_ScummVMInput_CreateObject), BS_ServiceInfo("sfx", "fmodex", BS_FMODExSound_CreateObject), BS_ServiceInfo("script", "lua", BS_LuaScriptEngine_CreateObject), BS_ServiceInfo("geometry", "std", BS_Geometry_CreateObject), diff --git a/engines/sword25/script/luascript.cpp b/engines/sword25/script/luascript.cpp index 129dd03c8a..62b5791a82 100644 --- a/engines/sword25/script/luascript.cpp +++ b/engines/sword25/script/luascript.cpp @@ -38,6 +38,7 @@ // Includes // ----------------------------------------------------------------------------- +#include "common/array.h" #include "sword25/package/packagemanager.h" #include "sword25/script/luascript.h" #include "sword25/script/luabindhelper.h" @@ -58,7 +59,6 @@ extern "C" { namespace Sword25 { -using namespace std; using namespace Lua; // ----------------------------------------------------------------------------- @@ -410,7 +410,7 @@ namespace { namespace { int Chunkwriter(lua_State *L, const void *p, size_t sz, void *ud) { - vector<unsigned char> & chunkData = *reinterpret_cast<vector<unsigned char> * >(ud); + Common::Array<unsigned char> & chunkData = *reinterpret_cast<Common::Array<unsigned char> * >(ud); const unsigned char *buffer = reinterpret_cast<const unsigned char *>(p); while (sz--) chunkData.push_back(*buffer++) ; @@ -431,8 +431,8 @@ bool BS_LuaScriptEngine::Persist(BS_OutputPersistenceBlock &Writer) { PushPermanentsTable(m_State, PTT_PERSIST); lua_getglobal(m_State, "_G"); - // Lua persists and stores the data in a vector - vector<unsigned char> chunkData; + // Lua persists and stores the data in a Common::Array + Common::Array<unsigned char> chunkData; pluto_persist(m_State, Chunkwriter, &chunkData); // Persistenzdaten in den Writer schreiben. |