diff options
author | Eugene Sandulenko | 2010-10-19 21:03:33 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2010-10-19 21:03:33 +0000 |
commit | 6629efc676ca48e958dcfa0ee4e66e6aba1c6597 (patch) | |
tree | 3e76022f90ca9590c1ec376fc436461eaeee11ef /engines/sword25/input | |
parent | ae78107e2a8732977313e208f1d08e65d50ec8e8 (diff) | |
download | scummvm-rg350-6629efc676ca48e958dcfa0ee4e66e6aba1c6597.tar.gz scummvm-rg350-6629efc676ca48e958dcfa0ee4e66e6aba1c6597.tar.bz2 scummvm-rg350-6629efc676ca48e958dcfa0ee4e66e6aba1c6597.zip |
SWORD25: Enforced code formatting rules in rest of the engine
svn-id: r53626
Diffstat (limited to 'engines/sword25/input')
-rw-r--r-- | engines/sword25/input/inputengine.cpp | 296 | ||||
-rw-r--r-- | engines/sword25/input/inputengine.h | 79 | ||||
-rw-r--r-- | engines/sword25/input/inputengine_script.cpp | 248 |
3 files changed, 260 insertions, 363 deletions
diff --git a/engines/sword25/input/inputengine.cpp b/engines/sword25/input/inputengine.cpp index 9936a20127..181e13b7ff 100644 --- a/engines/sword25/input/inputengine.cpp +++ b/engines/sword25/input/inputengine.cpp @@ -51,24 +51,24 @@ namespace Sword25 { InputEngine::InputEngine(Kernel *pKernel) : Service(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) { - memset(m_KeyboardState[0], 0, sizeof(m_KeyboardState[0])); - memset(m_KeyboardState[1], 0, sizeof(m_KeyboardState[1])); - m_LeftMouseState[0] = false; - m_LeftMouseState[1] = false; - m_RightMouseState[0] = false; - m_RightMouseState[1] = false; + _currentState(0), + _leftMouseDown(false), + _rightMouseDown(false), + _mouseX(0), + _mouseY(0), + _leftDoubleClick(false), + _doubleClickTime(DOUBLE_CLICK_TIME), + _doubleClickRectWidth(DOUBLE_CLICK_RECT_SIZE), + _doubleClickRectHeight(DOUBLE_CLICK_RECT_SIZE), + _lastLeftClickTime(0), + _lastLeftClickMouseX(0), + _lastLeftClickMouseY(0) { + memset(_keyboardState[0], 0, sizeof(_keyboardState[0])); + memset(_keyboardState[1], 0, sizeof(_keyboardState[1])); + _leftMouseState[0] = false; + _leftMouseState[1] = false; + _rightMouseState[0] = false; + _rightMouseState[1] = false; if (!registerScriptBindings()) BS_LOG_ERRORLN("Script bindings could not be registered."); @@ -80,18 +80,14 @@ Service *InputEngine_CreateObject(Kernel *pKernel) { return new InputEngine(pKernel); } -// ----------------------------------------------------------------------------- - -bool InputEngine::Init() { +bool InputEngine::init() { // No initialisation needed return true; } -// ----------------------------------------------------------------------------- - -void InputEngine::Update() { +void InputEngine::update() { Common::Event event; - m_CurrentState ^= 1; + _currentState ^= 1; // Loop through processing any pending events bool handleEvents = true; @@ -99,31 +95,31 @@ void InputEngine::Update() { 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; + _leftMouseDown = event.type == Common::EVENT_LBUTTONDOWN; + _mouseX = event.mouse.x; + _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; + _rightMouseDown = event.type == Common::EVENT_RBUTTONDOWN; + _mouseX = event.mouse.x; + _mouseY = event.mouse.y; handleEvents = false; break; case Common::EVENT_MOUSEMOVE: - m_MouseX = event.mouse.x; - m_MouseY = event.mouse.y; + _mouseX = event.mouse.x; + _mouseY = event.mouse.y; break; case Common::EVENT_KEYDOWN: case Common::EVENT_KEYUP: - AlterKeyboardState(event.kbd.keycode, (event.type == Common::EVENT_KEYDOWN) ? 0x80 : 0); + alterKeyboardState(event.kbd.keycode, (event.type == Common::EVENT_KEYDOWN) ? 0x80 : 0); break; case Common::EVENT_QUIT: - Kernel::GetInstance()->GetWindow()->SetWindowAlive(false); + Kernel::getInstance()->getWindow()->setWindowAlive(false); break; default: @@ -131,125 +127,97 @@ void InputEngine::Update() { } } - m_LeftMouseState[m_CurrentState] = m_LeftMouseDown; - m_RightMouseState[m_CurrentState] = m_RightMouseDown; + _leftMouseState[_currentState] = _leftMouseDown; + _rightMouseState[_currentState] = _rightMouseDown; - TestForLeftDoubleClick(); + testForLeftDoubleClick(); } -// ----------------------------------------------------------------------------- - -bool InputEngine::IsLeftMouseDown() { - return m_LeftMouseDown; +bool InputEngine::isLeftMouseDown() { + return _leftMouseDown; } -// ----------------------------------------------------------------------------- - -bool InputEngine::IsRightMouseDown() { - return m_RightMouseDown; +bool InputEngine::isRightMouseDown() { + return _rightMouseDown; } -// ----------------------------------------------------------------------------- - -void InputEngine::TestForLeftDoubleClick() { - m_LeftDoubleClick = false; +void InputEngine::testForLeftDoubleClick() { + _leftDoubleClick = false; // Only bother checking for a double click if the left mouse button was clicked - if (WasLeftMouseDown()) { + if (wasLeftMouseDown()) { // Get the time now - uint Now = Kernel::GetInstance()->GetMilliTicks(); + uint now = Kernel::getInstance()->getMilliTicks(); // 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) { - m_LeftDoubleClick = true; + if (now - _lastLeftClickTime <= _doubleClickTime && + ABS(_mouseX - _lastLeftClickMouseX) <= _doubleClickRectWidth / 2 && + ABS(_mouseY - _lastLeftClickMouseY) <= _doubleClickRectHeight / 2) { + _leftDoubleClick = true; // 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; + _lastLeftClickTime = 0; + _lastLeftClickMouseX = 0; + _lastLeftClickMouseY = 0; } 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; + _lastLeftClickTime = now; + _lastLeftClickMouseX = _mouseX; + _lastLeftClickMouseY = _mouseY; } } } -// ----------------------------------------------------------------------------- - -void InputEngine::AlterKeyboardState(int keycode, byte newState) { - m_KeyboardState[m_CurrentState][keycode] = newState; +void InputEngine::alterKeyboardState(int keycode, byte newState) { + _keyboardState[_currentState][keycode] = newState; } -// ----------------------------------------------------------------------------- - -bool InputEngine::IsLeftDoubleClick() { - return m_LeftDoubleClick; +bool InputEngine::isLeftDoubleClick() { + return _leftDoubleClick; } -// ----------------------------------------------------------------------------- - -bool InputEngine::WasLeftMouseDown() { - return (m_LeftMouseState[m_CurrentState] == false) && (m_LeftMouseState[m_CurrentState ^ 1] == true); +bool InputEngine::wasLeftMouseDown() { + return (_leftMouseState[_currentState] == false) && (_leftMouseState[_currentState ^ 1] == true); } -// ----------------------------------------------------------------------------- - -bool InputEngine::WasRightMouseDown() { - return (m_RightMouseState[m_CurrentState] == false) && (m_RightMouseState[m_CurrentState ^ 1] == true); +bool InputEngine::wasRightMouseDown() { + return (_rightMouseState[_currentState] == false) && (_rightMouseState[_currentState ^ 1] == true); } -// ----------------------------------------------------------------------------- - -int InputEngine::GetMouseX() { - return m_MouseX; +int InputEngine::getMouseX() { + return _mouseX; } -// ----------------------------------------------------------------------------- - -int InputEngine::GetMouseY() { - return m_MouseY; +int InputEngine::getMouseY() { + return _mouseY; } -// ----------------------------------------------------------------------------- - -bool InputEngine::IsKeyDown(uint KeyCode) { - return (m_KeyboardState[m_CurrentState][KeyCode] & 0x80) != 0; +bool InputEngine::isKeyDown(uint keyCode) { + return (_keyboardState[_currentState][keyCode] & 0x80) != 0; } -// ----------------------------------------------------------------------------- - -bool InputEngine::WasKeyDown(uint KeyCode) { - return ((m_KeyboardState[m_CurrentState][KeyCode] & 0x80) == 0) && - ((m_KeyboardState[m_CurrentState ^ 1][KeyCode] & 0x80) != 0); +bool InputEngine::wasKeyDown(uint keyCode) { + return ((_keyboardState[_currentState][keyCode] & 0x80) == 0) && + ((_keyboardState[_currentState ^ 1][keyCode] & 0x80) != 0); } -// ----------------------------------------------------------------------------- - -void InputEngine::SetMouseX(int PosX) { - m_MouseX = PosX; - g_system->warpMouse(m_MouseX, m_MouseY); +void InputEngine::setMouseX(int posX) { + _mouseX = posX; + g_system->warpMouse(_mouseX, _mouseY); } -// ----------------------------------------------------------------------------- - -void InputEngine::SetMouseY(int PosY) { - m_MouseY = PosY; - g_system->warpMouse(m_MouseX, m_MouseY); +void InputEngine::setMouseY(int posY) { + _mouseY = posY; + g_system->warpMouse(_mouseX, _mouseY); } -// ----------------------------------------------------------------------------- - -bool InputEngine::RegisterCharacterCallback(CharacterCallback Callback) { - if (Common::find(m_CharacterCallbacks.begin(), m_CharacterCallbacks.end(), Callback) == m_CharacterCallbacks.end()) { - m_CharacterCallbacks.push_back(Callback); +bool InputEngine::registerCharacterCallback(CharacterCallback callback) { + if (Common::find(_characterCallbacks.begin(), _characterCallbacks.end(), callback) == _characterCallbacks.end()) { + _characterCallbacks.push_back(callback); return true; } else { BS_LOG_WARNINGLN("Tried to register an CharacterCallback that was already registered."); @@ -257,13 +225,11 @@ bool InputEngine::RegisterCharacterCallback(CharacterCallback Callback) { } } -// ----------------------------------------------------------------------------- - -bool InputEngine::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); +bool InputEngine::unregisterCharacterCallback(CharacterCallback callback) { + Common::List<CharacterCallback>::iterator callbackIter = Common::find(_characterCallbacks.begin(), + _characterCallbacks.end(), callback); + if (callbackIter != _characterCallbacks.end()) { + _characterCallbacks.erase(callbackIter); return true; } else { BS_LOG_WARNINGLN("Tried to unregister an CharacterCallback that was not previously registered."); @@ -271,11 +237,9 @@ bool InputEngine::UnregisterCharacterCallback(CharacterCallback Callback) { } } -// ----------------------------------------------------------------------------- - -bool InputEngine::RegisterCommandCallback(CommandCallback Callback) { - if (Common::find(m_CommandCallbacks.begin(), m_CommandCallbacks.end(), Callback) == m_CommandCallbacks.end()) { - m_CommandCallbacks.push_back(Callback); +bool InputEngine::registerCommandCallback(CommandCallback callback) { + if (Common::find(_commandCallbacks.begin(), _commandCallbacks.end(), callback) == _commandCallbacks.end()) { + _commandCallbacks.push_back(callback); return true; } else { BS_LOG_WARNINGLN("Tried to register an CommandCallback that was already registered."); @@ -283,13 +247,11 @@ bool InputEngine::RegisterCommandCallback(CommandCallback Callback) { } } -// ----------------------------------------------------------------------------- - -bool InputEngine::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); +bool InputEngine::unregisterCommandCallback(CommandCallback callback) { + Common::List<CommandCallback>::iterator callbackIter = + Common::find(_commandCallbacks.begin(), _commandCallbacks.end(), callback); + if (callbackIter != _commandCallbacks.end()) { + _commandCallbacks.erase(callbackIter); return true; } else { BS_LOG_WARNINGLN("Tried to unregister an CommandCallback that was not previously registered."); @@ -297,60 +259,52 @@ bool InputEngine::UnregisterCommandCallback(CommandCallback Callback) { } } -// ----------------------------------------------------------------------------- - -void InputEngine::ReportCharacter(byte Character) { - Common::List<CharacterCallback>::const_iterator CallbackIter = m_CharacterCallbacks.begin(); - while (CallbackIter != m_CharacterCallbacks.end()) { +void InputEngine::reportCharacter(byte character) { + Common::List<CharacterCallback>::const_iterator callbackIter = _characterCallbacks.begin(); + while (callbackIter != _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. - Common::List<CharacterCallback>::const_iterator CurCallbackIter = CallbackIter; - ++CallbackIter; + Common::List<CharacterCallback>::const_iterator curCallbackIter = callbackIter; + ++callbackIter; - (*CurCallbackIter)(Character); + (*curCallbackIter)(character); } } -// ----------------------------------------------------------------------------- - -void InputEngine::ReportCommand(KEY_COMMANDS Command) { - Common::List<CommandCallback>::const_iterator CallbackIter = m_CommandCallbacks.begin(); - while (CallbackIter != m_CommandCallbacks.end()) { +void InputEngine::reportCommand(KEY_COMMANDS command) { + Common::List<CommandCallback>::const_iterator callbackIter = _commandCallbacks.begin(); + while (callbackIter != _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. - Common::List<CommandCallback>::const_iterator CurCallbackIter = CallbackIter; - ++CallbackIter; + Common::List<CommandCallback>::const_iterator curCallbackIter = callbackIter; + ++callbackIter; - (*CurCallbackIter)(Command); + (*curCallbackIter)(command); } } -// ----------------------------------------------------------------------------- -// Persistenz -// ----------------------------------------------------------------------------- - bool InputEngine::persist(OutputPersistenceBlock &writer) { // Anzahl an Command-Callbacks persistieren. - writer.write(m_CommandCallbacks.size()); + writer.write(_commandCallbacks.size()); // Alle Command-Callbacks einzeln persistieren. { - Common::List<CommandCallback>::const_iterator It = m_CommandCallbacks.begin(); - while (It != m_CommandCallbacks.end()) { + Common::List<CommandCallback>::const_iterator It = _commandCallbacks.begin(); + while (It != _commandCallbacks.end()) { writer.write(CallbackRegistry::instance().resolveCallbackPointer(*It)); ++It; } } // Anzahl an Character-Callbacks persistieren. - writer.write(m_CharacterCallbacks.size()); + writer.write(_characterCallbacks.size()); // Alle Character-Callbacks einzeln persistieren. { - Common::List<CharacterCallback>::const_iterator It = m_CharacterCallbacks.begin(); - while (It != m_CharacterCallbacks.end()) { + Common::List<CharacterCallback>::const_iterator It = _characterCallbacks.begin(); + while (It != _characterCallbacks.end()) { writer.write(CallbackRegistry::instance().resolveCallbackPointer(*It)); ++It; } @@ -359,38 +313,36 @@ bool InputEngine::persist(OutputPersistenceBlock &writer) { return true; } -// ----------------------------------------------------------------------------- - bool InputEngine::unpersist(InputPersistenceBlock &reader) { // Command-Callbackliste leeren. - m_CommandCallbacks.clear(); + _commandCallbacks.clear(); // Anzahl an Command-Callbacks lesen. - uint CommandCallbackCount; - reader.read(CommandCallbackCount); + uint commandCallbackCount; + reader.read(commandCallbackCount); // Alle Command-Callbacks wieder herstellen. - for (uint i = 0; i < CommandCallbackCount; ++i) { - Common::String CallbackFunctionName; - reader.read(CallbackFunctionName); + for (uint i = 0; i < commandCallbackCount; ++i) { + Common::String callbackFunctionName; + reader.read(callbackFunctionName); - m_CommandCallbacks.push_back(reinterpret_cast<CommandCallback>( - CallbackRegistry::instance().resolveCallbackFunction(CallbackFunctionName))); + _commandCallbacks.push_back(reinterpret_cast<CommandCallback>( + CallbackRegistry::instance().resolveCallbackFunction(callbackFunctionName))); } // Character-Callbackliste leeren. - m_CharacterCallbacks.clear(); + _characterCallbacks.clear(); // Anzahl an Character-Callbacks lesen. - uint CharacterCallbackCount; - reader.read(CharacterCallbackCount); + uint characterCallbackCount; + reader.read(characterCallbackCount); // Alle Character-Callbacks wieder herstellen. - for (uint i = 0; i < CharacterCallbackCount; ++i) { - Common::String CallbackFunctionName; - reader.read(CallbackFunctionName); + for (uint i = 0; i < characterCallbackCount; ++i) { + Common::String callbackFunctionName; + reader.read(callbackFunctionName); - m_CharacterCallbacks.push_back(reinterpret_cast<CharacterCallback>(CallbackRegistry::instance().resolveCallbackFunction(CallbackFunctionName))); + _characterCallbacks.push_back(reinterpret_cast<CharacterCallback>(CallbackRegistry::instance().resolveCallbackFunction(callbackFunctionName))); } return reader.isGood(); diff --git a/engines/sword25/input/inputengine.h b/engines/sword25/input/inputengine.h index 59ce8fedc4..07e56928cb 100644 --- a/engines/sword25/input/inputengine.h +++ b/engines/sword25/input/inputengine.h @@ -45,7 +45,6 @@ #ifndef SWORD25_INPUTENGINE_H #define SWORD25_INPUTENGINE_H -/// Includes #include "sword25/kernel/common.h" #include "sword25/kernel/service.h" #include "sword25/kernel/persistable.h" @@ -176,7 +175,7 @@ public: * Initialises the input engine * @return Returns a true on success, otherwise false. */ - bool Init(); + bool init(); /** * Performs a "tick" of the input engine. @@ -185,17 +184,17 @@ public: * of the input engine that are not running in their own thread, or to perform * additional administrative tasks that are needed. */ - void Update(); + void update(); /** * Returns true if the left mouse button is pressed */ - bool IsLeftMouseDown(); + bool isLeftMouseDown(); /** * Returns true if the right mouse button is pressed. */ - bool IsRightMouseDown(); + bool isRightMouseDown(); /** * Returns true if the left mouse button was pressed and released. @@ -203,7 +202,7 @@ public: * The difference between this and IsLeftMouseDown() is that this only returns * true when the left mouse button is released. */ - bool WasLeftMouseDown(); + bool wasLeftMouseDown(); /** * Returns true if the right mouse button was pressed and released. @@ -211,39 +210,39 @@ public: * The difference between this and IsRightMouseDown() is that this only returns * true when the right mouse button is released. */ - bool WasRightMouseDown(); + bool wasRightMouseDown(); /** * Returns true if the left mouse button double click was done */ - bool IsLeftDoubleClick(); + bool isLeftDoubleClick(); /** * Returns the X position of the cursor in pixels */ - int GetMouseX(); + int getMouseX(); /** * Returns the Y position of the cursor in pixels */ - int GetMouseY(); + int getMouseY(); /** * Sets the X position of the cursor in pixels */ - void SetMouseX(int PosX); + void setMouseX(int posX); /** * Sets the Y position of the cursor in pixels */ - void SetMouseY(int PosY); + void setMouseY(int posY); /** * Returns true if a given key was pressed * @param KeyCode The key code to be checked * @return Returns true if the given key is done, otherwise false. */ - bool IsKeyDown(uint KeyCode); + bool isKeyDown(uint keyCode); /** * Returns true if a certain key was pushed and released. @@ -253,7 +252,7 @@ public: * strings that users type. * @param KeyCode The key code to be checked */ - bool WasKeyDown(uint KeyCode); + bool wasKeyDown(uint keyCode); typedef CallbackPtr CharacterCallback; @@ -269,13 +268,13 @@ public: * The input of strings by the user through use of callbacks should be implemented. * @return Returns true if the function was registered, otherwise false. */ - bool RegisterCharacterCallback(CallbackPtr Callback); + bool registerCharacterCallback(CallbackPtr callback); /** * De-registeres a previously registered callback function. * @return Returns true if the function could be de-registered, otherwise false. */ - bool UnregisterCharacterCallback(CallbackPtr Callback); + bool unregisterCharacterCallback(CallbackPtr callback); typedef CallbackPtr CommandCallback; @@ -288,16 +287,16 @@ public: * The input of strings by the user through the use of callbacks should be implemented. * @return Returns true if the function was registered, otherwise false. */ - bool RegisterCommandCallback(CallbackPtr Callback); + bool registerCommandCallback(CallbackPtr callback); /** * Un-register a callback function for the input of commands that can have an influence on the string input. * @return Returns true if the function could be de-registered, otherwise false. */ - bool UnregisterCommandCallback(CommandCallback Callback); + bool unregisterCommandCallback(CommandCallback callback); - void ReportCharacter(byte Character); - void ReportCommand(KEY_COMMANDS Command); + void reportCharacter(byte character); + void reportCommand(KEY_COMMANDS command); bool persist(OutputPersistenceBlock &writer); bool unpersist(InputPersistenceBlock &reader); @@ -306,26 +305,26 @@ private: bool registerScriptBindings(); private: - void TestForLeftDoubleClick(); - void AlterKeyboardState(int keycode, byte newState); - - byte m_KeyboardState[2][256]; - bool m_LeftMouseState[2]; - bool m_RightMouseState[2]; - uint m_CurrentState; - int m_MouseX; - int m_MouseY; - bool m_LeftMouseDown; - bool m_RightMouseDown; - bool m_LeftDoubleClick; - uint m_DoubleClickTime; - int m_DoubleClickRectWidth; - int m_DoubleClickRectHeight; - uint m_LastLeftClickTime; - int m_LastLeftClickMouseX; - int m_LastLeftClickMouseY; - Common::List<CommandCallback> m_CommandCallbacks; - Common::List<CharacterCallback> m_CharacterCallbacks; + void testForLeftDoubleClick(); + void alterKeyboardState(int keycode, byte newState); + + byte _keyboardState[2][256]; + bool _leftMouseState[2]; + bool _rightMouseState[2]; + uint _currentState; + int _mouseX; + int _mouseY; + bool _leftMouseDown; + bool _rightMouseDown; + bool _leftDoubleClick; + uint _doubleClickTime; + int _doubleClickRectWidth; + int _doubleClickRectHeight; + uint _lastLeftClickTime; + int _lastLeftClickMouseX; + int _lastLeftClickMouseY; + Common::List<CommandCallback> _commandCallbacks; + Common::List<CharacterCallback> _characterCallbacks; }; } // End of namespace Sword25 diff --git a/engines/sword25/input/inputengine_script.cpp b/engines/sword25/input/inputengine_script.cpp index 2b1f3b9ec6..303f0e69e1 100644 --- a/engines/sword25/input/inputengine_script.cpp +++ b/engines/sword25/input/inputengine_script.cpp @@ -32,10 +32,6 @@ * */ -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - #include "common/ptr.h" #include "common/str.h" #include "sword25/kernel/common.h" @@ -51,268 +47,218 @@ namespace Sword25 { -// ----------------------------------------------------------------------------- -// Callback-Objekte -// ----------------------------------------------------------------------------- - -static void TheCharacterCallback(int Character); -static void TheCommandCallback(int Command); +static void theCharacterCallback(int character); +static void theCommandCallback(int command); namespace { class CharacterCallbackClass : public LuaCallback { public: CharacterCallbackClass(lua_State *L) : LuaCallback(L) {} - Common::String Character; + Common::String _character; protected: int PreFunctionInvokation(lua_State *L) { - lua_pushstring(L, Character.c_str()); + lua_pushstring(L, _character.c_str()); return 1; } }; -Common::SharedPtr<CharacterCallbackClass> CharacterCallbackPtr; - -// ----------------------------------------------------------------------------- +Common::SharedPtr<CharacterCallbackClass> characterCallbackPtr; class CommandCallbackClass : public LuaCallback { public: CommandCallbackClass(lua_State *L) : LuaCallback(L) { - Command = InputEngine::KEY_COMMAND_BACKSPACE; + _command = InputEngine::KEY_COMMAND_BACKSPACE; } - InputEngine::KEY_COMMANDS Command; + InputEngine::KEY_COMMANDS _command; protected: - int PreFunctionInvokation(lua_State *L) { - lua_pushnumber(L, Command); + int preFunctionInvokation(lua_State *L) { + lua_pushnumber(L, _command); return 1; } }; -Common::SharedPtr<CommandCallbackClass> CommandCallbackPtr; - -// ------------------------------------------------------------------------- +Common::SharedPtr<CommandCallbackClass> commandCallbackPtr; struct CallbackfunctionRegisterer { CallbackfunctionRegisterer() { - CallbackRegistry::instance().registerCallbackFunction("LuaCommandCB", TheCommandCallback); - CallbackRegistry::instance().registerCallbackFunction("LuaCharacterCB", TheCharacterCallback); + CallbackRegistry::instance().registerCallbackFunction("LuaCommandCB", theCommandCallback); + CallbackRegistry::instance().registerCallbackFunction("LuaCharacterCB", theCharacterCallback); } }; -static CallbackfunctionRegisterer Instance; +static CallbackfunctionRegisterer instance; } -// ----------------------------------------------------------------------------- - -static InputEngine *GetIE() { - Kernel *pKernel = Kernel::GetInstance(); +static InputEngine *getIE() { + Kernel *pKernel = Kernel::getInstance(); BS_ASSERT(pKernel); - InputEngine *pIE = pKernel->GetInput(); + InputEngine *pIE = pKernel->getInput(); BS_ASSERT(pIE); return pIE; } -// ----------------------------------------------------------------------------- - -static int Init(lua_State *L) { - InputEngine *pIE = GetIE(); +static int init(lua_State *L) { + InputEngine *pIE = getIE(); - lua_pushbooleancpp(L, pIE->Init()); + lua_pushbooleancpp(L, pIE->init()); return 1; } -// ----------------------------------------------------------------------------- - -static int Update(lua_State *L) { - InputEngine *pIE = GetIE(); +static int update(lua_State *L) { + InputEngine *pIE = getIE(); // Beim ersten Aufruf der Update()-Methode werden die beiden Callbacks am Input-Objekt registriert. // Dieses kann nicht in _RegisterScriptBindings() passieren, da diese Funktion vom Konstruktor der abstrakten Basisklasse aufgerufen wird und die // Register...()-Methoden abstrakt sind, im Konstruktor der Basisklasse also nicht aufgerufen werden können. - static bool FirstCall = true; - if (FirstCall) { - FirstCall = false; - pIE->RegisterCharacterCallback(TheCharacterCallback); - pIE->RegisterCommandCallback(TheCommandCallback); + static bool firstCall = true; + if (firstCall) { + firstCall = false; + pIE->registerCharacterCallback(theCharacterCallback); + pIE->registerCommandCallback(theCommandCallback); } - pIE->Update(); + pIE->update(); return 0; } -// ----------------------------------------------------------------------------- +static int isLeftMouseDown(lua_State *L) { + InputEngine *pIE = getIE(); -static int IsLeftMouseDown(lua_State *L) { - InputEngine *pIE = GetIE(); - - lua_pushbooleancpp(L, pIE->IsLeftMouseDown()); + lua_pushbooleancpp(L, pIE->isLeftMouseDown()); return 1; } -// ----------------------------------------------------------------------------- - -static int IsRightMouseDown(lua_State *L) { - InputEngine *pIE = GetIE(); +static int isRightMouseDown(lua_State *L) { + InputEngine *pIE = getIE(); - lua_pushbooleancpp(L, pIE->IsRightMouseDown()); + lua_pushbooleancpp(L, pIE->isRightMouseDown()); return 1; } -// ----------------------------------------------------------------------------- - -static int WasLeftMouseDown(lua_State *L) { - InputEngine *pIE = GetIE(); +static int wasLeftMouseDown(lua_State *L) { + InputEngine *pIE = getIE(); - lua_pushbooleancpp(L, pIE->WasLeftMouseDown()); + lua_pushbooleancpp(L, pIE->wasLeftMouseDown()); return 1; } -// ----------------------------------------------------------------------------- - -static int WasRightMouseDown(lua_State *L) { - InputEngine *pIE = GetIE(); +static int wasRightMouseDown(lua_State *L) { + InputEngine *pIE = getIE(); - lua_pushbooleancpp(L, pIE->WasRightMouseDown()); + lua_pushbooleancpp(L, pIE->wasRightMouseDown()); return 1; } -// ----------------------------------------------------------------------------- - -static int IsLeftDoubleClick(lua_State *L) { - InputEngine *pIE = GetIE(); +static int isLeftDoubleClick(lua_State *L) { + InputEngine *pIE = getIE(); - lua_pushbooleancpp(L, pIE->IsLeftDoubleClick()); + lua_pushbooleancpp(L, pIE->isLeftDoubleClick()); return 1; } -// ----------------------------------------------------------------------------- - -static int GetMouseX(lua_State *L) { - InputEngine *pIE = GetIE(); +static int getMouseX(lua_State *L) { + InputEngine *pIE = getIE(); - lua_pushnumber(L, pIE->GetMouseX()); + lua_pushnumber(L, pIE->getMouseX()); return 1; } -// ----------------------------------------------------------------------------- - -static int GetMouseY(lua_State *L) { - InputEngine *pIE = GetIE(); +static int getMouseY(lua_State *L) { + InputEngine *pIE = getIE(); - lua_pushnumber(L, pIE->GetMouseY()); + lua_pushnumber(L, pIE->getMouseY()); return 1; } -// ----------------------------------------------------------------------------- - -static int IsKeyDown(lua_State *L) { - InputEngine *pIE = GetIE(); +static int isKeyDown(lua_State *L) { + InputEngine *pIE = getIE(); - lua_pushbooleancpp(L, pIE->IsKeyDown((uint) luaL_checknumber(L, 1))); + lua_pushbooleancpp(L, pIE->isKeyDown((uint)luaL_checknumber(L, 1))); return 1; } -// ----------------------------------------------------------------------------- +static int wasKeyDown(lua_State *L) { + InputEngine *pIE = getIE(); -static int WasKeyDown(lua_State *L) { - InputEngine *pIE = GetIE(); - - lua_pushbooleancpp(L, pIE->WasKeyDown((uint) luaL_checknumber(L, 1))); + lua_pushbooleancpp(L, pIE->wasKeyDown((uint)luaL_checknumber(L, 1))); return 1; } -// ----------------------------------------------------------------------------- - -static int SetMouseX(lua_State *L) { - InputEngine *pIE = GetIE(); +static int setMouseX(lua_State *L) { + InputEngine *pIE = getIE(); - pIE->SetMouseX((int) luaL_checknumber(L, 1)); + pIE->setMouseX((int)luaL_checknumber(L, 1)); return 0; } -// ----------------------------------------------------------------------------- - -static int SetMouseY(lua_State *L) { - InputEngine *pIE = GetIE(); +static int setMouseY(lua_State *L) { + InputEngine *pIE = getIE(); - pIE->SetMouseY((int) luaL_checknumber(L, 1)); + pIE->setMouseY((int)luaL_checknumber(L, 1)); return 0; } -// ----------------------------------------------------------------------------- - -static void TheCharacterCallback(int Character) { - CharacterCallbackPtr->Character = static_cast<byte>(Character); - lua_State *L = static_cast<lua_State *>(Kernel::GetInstance()->GetScript()->getScriptObject()); - CharacterCallbackPtr->invokeCallbackFunctions(L, 1); +static void theCharacterCallback(int character) { + characterCallbackPtr->_character = static_cast<byte>(character); + lua_State *L = static_cast<lua_State *>(Kernel::getInstance()->getScript()->getScriptObject()); + characterCallbackPtr->invokeCallbackFunctions(L, 1); } -// ----------------------------------------------------------------------------- - -static int RegisterCharacterCallback(lua_State *L) { +static int registerCharacterCallback(lua_State *L) { luaL_checktype(L, 1, LUA_TFUNCTION); - CharacterCallbackPtr->registerCallbackFunction(L, 1); + characterCallbackPtr->registerCallbackFunction(L, 1); return 0; } -// ----------------------------------------------------------------------------- - -static int UnregisterCharacterCallback(lua_State *L) { +static int unregisterCharacterCallback(lua_State *L) { luaL_checktype(L, 1, LUA_TFUNCTION); - CharacterCallbackPtr->unregisterCallbackFunction(L, 1); + characterCallbackPtr->unregisterCallbackFunction(L, 1); return 0; } -// ----------------------------------------------------------------------------- - -static void TheCommandCallback(int Command) { - CommandCallbackPtr->Command = static_cast<InputEngine::KEY_COMMANDS>(Command); - lua_State *L = static_cast<lua_State *>(Kernel::GetInstance()->GetScript()->getScriptObject()); - CommandCallbackPtr->invokeCallbackFunctions(L, 1); +static void theCommandCallback(int command) { + commandCallbackPtr->_command = static_cast<InputEngine::KEY_COMMANDS>(command); + lua_State *L = static_cast<lua_State *>(Kernel::getInstance()->getScript()->getScriptObject()); + commandCallbackPtr->invokeCallbackFunctions(L, 1); } -// ----------------------------------------------------------------------------- - -static int RegisterCommandCallback(lua_State *L) { +static int registerCommandCallback(lua_State *L) { luaL_checktype(L, 1, LUA_TFUNCTION); - CommandCallbackPtr->registerCallbackFunction(L, 1); + commandCallbackPtr->registerCallbackFunction(L, 1); return 0; } -// ----------------------------------------------------------------------------- - -static int UnregisterCommandCallback(lua_State *L) { +static int unregisterCommandCallback(lua_State *L) { luaL_checktype(L, 1, LUA_TFUNCTION); - CommandCallbackPtr->unregisterCallbackFunction(L, 1); + commandCallbackPtr->unregisterCallbackFunction(L, 1); return 0; } -// ----------------------------------------------------------------------------- - static const char *PACKAGE_LIBRARY_NAME = "Input"; static const luaL_reg PACKAGE_FUNCTIONS[] = { - {"Init", Init}, - {"Update", Update}, - {"IsLeftMouseDown", IsLeftMouseDown}, - {"IsRightMouseDown", IsRightMouseDown}, - {"WasLeftMouseDown", WasLeftMouseDown}, - {"WasRightMouseDown", WasRightMouseDown}, - {"IsLeftDoubleClick", IsLeftDoubleClick}, - {"GetMouseX", GetMouseX}, - {"GetMouseY", GetMouseY}, - {"SetMouseX", SetMouseX}, - {"SetMouseY", SetMouseY}, - {"IsKeyDown", IsKeyDown}, - {"WasKeyDown", WasKeyDown}, - {"RegisterCharacterCallback", RegisterCharacterCallback}, - {"UnregisterCharacterCallback", UnregisterCharacterCallback}, - {"RegisterCommandCallback", RegisterCommandCallback}, - {"UnregisterCommandCallback", UnregisterCommandCallback}, + {"Init", init}, + {"Update", update}, + {"IsLeftMouseDown", isLeftMouseDown}, + {"IsRightMouseDown", isRightMouseDown}, + {"WasLeftMouseDown", wasLeftMouseDown}, + {"WasRightMouseDown", wasRightMouseDown}, + {"IsLeftDoubleClick", isLeftDoubleClick}, + {"GetMouseX", getMouseX}, + {"GetMouseY", getMouseY}, + {"SetMouseX", setMouseX}, + {"SetMouseY", setMouseY}, + {"IsKeyDown", isKeyDown}, + {"WasKeyDown", wasKeyDown}, + {"RegisterCharacterCallback", registerCharacterCallback}, + {"UnregisterCharacterCallback", unregisterCharacterCallback}, + {"RegisterCommandCallback", registerCommandCallback}, + {"UnregisterCommandCallback", unregisterCommandCallback}, {0, 0} }; @@ -334,9 +280,9 @@ static const lua_constant_reg PACKAGE_CONSTANTS[] = { // ----------------------------------------------------------------------------- bool InputEngine::registerScriptBindings() { - Kernel *pKernel = Kernel::GetInstance(); + Kernel *pKernel = Kernel::getInstance(); BS_ASSERT(pKernel); - ScriptEngine *pScript = pKernel->GetScript(); + ScriptEngine *pScript = pKernel->getScript(); BS_ASSERT(pScript); lua_State *L = static_cast<lua_State *>(pScript->getScriptObject()); BS_ASSERT(L); @@ -344,8 +290,8 @@ 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<CharacterCallbackClass>(new CharacterCallbackClass(L)); - CommandCallbackPtr = Common::SharedPtr<CommandCallbackClass>(new CommandCallbackClass(L)); + characterCallbackPtr = Common::SharedPtr<CharacterCallbackClass>(new CharacterCallbackClass(L)); + commandCallbackPtr = Common::SharedPtr<CommandCallbackClass>(new CommandCallbackClass(L)); return true; } |