[Scummvm-cvs-logs] SF.net SVN: scummvm:[53203] scummvm/trunk/engines/sword25
sev at users.sourceforge.net
sev at users.sourceforge.net
Wed Oct 13 00:21:24 CEST 2010
Revision: 53203
http://scummvm.svn.sourceforge.net/scummvm/?rev=53203&view=rev
Author: sev
Date: 2010-10-12 22:21:24 +0000 (Tue, 12 Oct 2010)
Log Message:
-----------
SWORD25: Converted the input engine to use the ScummVM event manager
Modified Paths:
--------------
scummvm/trunk/engines/sword25/kernel/callbackregistry.h
scummvm/trunk/engines/sword25/kernel/inputpersistenceblock.h
scummvm/trunk/engines/sword25/kernel/service_ids.h
scummvm/trunk/engines/sword25/script/luascript.cpp
Added Paths:
-----------
scummvm/trunk/engines/sword25/input/scummvminput.cpp
scummvm/trunk/engines/sword25/input/scummvminput.h
Removed Paths:
-------------
scummvm/trunk/engines/sword25/input/stdwininput.cpp
scummvm/trunk/engines/sword25/input/stdwininput.h
Copied: scummvm/trunk/engines/sword25/input/scummvminput.cpp (from rev 53202, scummvm/trunk/engines/sword25/input/stdwininput.cpp)
===================================================================
--- scummvm/trunk/engines/sword25/input/scummvminput.cpp (rev 0)
+++ scummvm/trunk/engines/sword25/input/scummvminput.cpp 2010-10-12 22:21:24 UTC (rev 53203)
@@ -0,0 +1,394 @@
+/* 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
+ *
+ */
+
+#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/scummvminput.h"
+
+#define BS_LOG_PREFIX "SCUMMVMINPUT"
+
+namespace Sword25 {
+
+#define DOUBLE_CLICK_TIME 500
+#define DOUBLE_CLICK_RECT_SIZE 4
+
+// -----------------------------------------------------------------------------
+// Constructor / Destructor
+// -----------------------------------------------------------------------------
+
+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;
+ m_LeftMouseState[1] = false;
+ m_RightMouseState[0] = false;
+ m_RightMouseState[1] = false;
+}
+
+ScummVMInput::~ScummVMInput() {
+}
+
+// -----------------------------------------------------------------------------
+
+BS_Service *ScummVMInput_CreateObject(BS_Kernel *pKernel) { return new ScummVMInput(pKernel); }
+
+// -----------------------------------------------------------------------------
+
+bool ScummVMInput::Init() {
+ // No initialisation needed
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+
+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;
+ }
+ }
+
+ m_LeftMouseState[m_CurrentState] = m_LeftMouseDown;
+ m_RightMouseState[m_CurrentState] = m_RightMouseDown;
+
+ TestForLeftDoubleClick();
+}
+
+// -----------------------------------------------------------------------------
+
+bool ScummVMInput::IsLeftMouseDown() {
+ return m_LeftMouseDown;
+}
+
+// -----------------------------------------------------------------------------
+
+bool ScummVMInput::IsRightMouseDown() {
+ return m_RightMouseDown;
+}
+
+// -----------------------------------------------------------------------------
+
+void ScummVMInput::TestForLeftDoubleClick() {
+ m_LeftDoubleClick = false;
+
+ // 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();
+
+ // 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;
+
+ // 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 {
+ // 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;
+ }
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+void AlterKeyboardState(int keycode, byte newState) {
+
+}
+
+// -----------------------------------------------------------------------------
+
+bool ScummVMInput::IsLeftDoubleClick() {
+ return m_LeftDoubleClick;
+}
+
+// -----------------------------------------------------------------------------
+
+bool ScummVMInput::WasLeftMouseDown() {
+ return (m_LeftMouseState[m_CurrentState] == false) && (m_LeftMouseState[m_CurrentState ^ 1] == true);
+}
+
+// -----------------------------------------------------------------------------
+
+bool ScummVMInput::WasRightMouseDown() {
+ return (m_RightMouseState[m_CurrentState] == false) && (m_RightMouseState[m_CurrentState ^ 1] == true);
+}
+
+// -----------------------------------------------------------------------------
+
+int ScummVMInput::GetMouseX() {
+ return m_MouseX;
+}
+
+// -----------------------------------------------------------------------------
+
+int ScummVMInput::GetMouseY() {
+ return m_MouseY;
+}
+
+// -----------------------------------------------------------------------------
+
+bool ScummVMInput::IsKeyDown(unsigned int KeyCode) {
+ return (m_KeyboardState[m_CurrentState][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 ScummVMInput::SetMouseX(int PosX) {
+ m_MouseX = PosX;
+ g_system->warpMouse(m_MouseX, m_MouseY);
+}
+
+// -----------------------------------------------------------------------------
+
+void ScummVMInput::SetMouseY(int PosY) {
+ m_MouseY = PosY;
+ g_system->warpMouse(m_MouseX, m_MouseY);
+}
+
+// -----------------------------------------------------------------------------
+
+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 {
+ BS_LOG_WARNINGLN("Tried to register an CharacterCallback that was already registered.");
+ return false;
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+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 {
+ BS_LOG_WARNINGLN("Tried to unregister an CharacterCallback that was not previously registered.");
+ return false;
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+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 {
+ BS_LOG_WARNINGLN("Tried to register an CommandCallback that was already registered.");
+ return false;
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+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 {
+ BS_LOG_WARNINGLN("Tried to unregister an CommandCallback that was not previously registered.");
+ return false;
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+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\xF6hen und im Folgendem auf einer Kopie arbeiten.
+ // Dieses Vorgehen ist notwendig da der Iterator m\xF6glicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks
+ // invalidiert wird.
+ Common::List<CharacterCallback>::const_iterator CurCallbackIter = CallbackIter;
+ ++CallbackIter;
+
+ (*CurCallbackIter)(Character);
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+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\xF6hen und im Folgendem auf einer Kopie arbeiten.
+ // Dieses Vorgehen ist notwendig da der Iterator m\xF6glicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks
+ // invalidiert wird.
+ Common::List<CommandCallback>::const_iterator CurCallbackIter = CallbackIter;
+ ++CallbackIter;
+
+ (*CurCallbackIter)(Command);
+ }
+}
+
+// -----------------------------------------------------------------------------
+// Persistenz
+// -----------------------------------------------------------------------------
+
+bool ScummVMInput::Persist(BS_OutputPersistenceBlock &Writer) {
+ // Anzahl an Command-Callbacks persistieren.
+ Writer.Write(m_CommandCallbacks.size());
+
+ // Alle Command-Callbacks einzeln persistieren.
+ {
+ Common::List<CommandCallback>::const_iterator It = m_CommandCallbacks.begin();
+ while (It != m_CommandCallbacks.end()) {
+ Writer.Write(BS_CallbackRegistry::GetInstance().ResolveCallbackPointer(*It));
+ ++It;
+ }
+ }
+
+ // Anzahl an Character-Callbacks persistieren.
+ Writer.Write(m_CharacterCallbacks.size());
+
+ // Alle Character-Callbacks einzeln persistieren.
+ {
+ Common::List<CharacterCallback>::const_iterator It = m_CharacterCallbacks.begin();
+ while (It != m_CharacterCallbacks.end()) {
+ Writer.Write(BS_CallbackRegistry::GetInstance().ResolveCallbackPointer(*It));
+ ++It;
+ }
+ }
+
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+
+bool ScummVMInput::Unpersist(BS_InputPersistenceBlock &Reader) {
+ // Command-Callbackliste leeren.
+ m_CommandCallbacks.clear();
+
+ // Anzahl an Command-Callbacks lesen.
+ unsigned int CommandCallbackCount;
+ Reader.Read(CommandCallbackCount);
+
+ // Alle Command-Callbacks wieder herstellen.
+ 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)));
+ }
+
+ // Character-Callbackliste leeren.
+ m_CharacterCallbacks.clear();
+
+ // Anzahl an Character-Callbacks lesen.
+ unsigned int CharacterCallbackCount;
+ Reader.Read(CharacterCallbackCount);
+
+ // Alle Character-Callbacks wieder herstellen.
+ 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)));
+ }
+
+ return Reader.IsGood();
+}
+
+} // End of namespace Sword25
Property changes on: scummvm/trunk/engines/sword25/input/scummvminput.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Copied: scummvm/trunk/engines/sword25/input/scummvminput.h (from rev 53202, scummvm/trunk/engines/sword25/input/stdwininput.h)
===================================================================
--- scummvm/trunk/engines/sword25/input/scummvminput.h (rev 0)
+++ scummvm/trunk/engines/sword25/input/scummvminput.h 2010-10-12 22:21:24 UTC (rev 53203)
@@ -0,0 +1,103 @@
+/* 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_STDWININPUT_H
+#define SWORD25_STDWININPUT_H
+
+/// Includes
+#include "common/scummsys.h"
+#include "common/list.h"
+#include "sword25/kernel/common.h"
+#include "sword25/input/inputengine.h"
+
+namespace Sword25 {
+
+/// Forward class definitions
+class BS_Kernel;
+
+/// Class definitions
+class ScummVMInput : public BS_InputEngine {
+public:
+ ScummVMInput(BS_Kernel *pKernel);
+ virtual ~ScummVMInput();
+
+ virtual bool Init();
+ virtual void Update();
+ virtual bool IsLeftMouseDown();
+ virtual bool IsRightMouseDown();
+ virtual bool WasLeftMouseDown();
+ virtual bool WasRightMouseDown();
+ virtual bool IsLeftDoubleClick();
+ virtual int GetMouseX();
+ virtual int GetMouseY();
+ virtual bool IsKeyDown(unsigned int KeyCode);
+ virtual bool WasKeyDown(unsigned int KeyCode);
+ virtual void SetMouseX(int PosX);
+ virtual void SetMouseY(int PosY);
+ virtual bool RegisterCharacterCallback(CharacterCallback Callback);
+ virtual bool UnregisterCharacterCallback(CharacterCallback Callback);
+ virtual bool RegisterCommandCallback(CommandCallback Callback);
+ virtual bool UnregisterCommandCallback(CommandCallback Callback);
+ virtual void ReportCharacter(unsigned char Character);
+ virtual void ReportCommand(KEY_COMMANDS Command);
+
+ bool Persist(BS_OutputPersistenceBlock &Writer);
+ bool Unpersist(BS_InputPersistenceBlock &Reader);
+
+private:
+ void TestForLeftDoubleClick();
+ void AlterKeyboardState(int keycode, byte newState);
+
+ byte m_KeyboardState[2][256];
+ bool m_LeftMouseState[2];
+ bool m_RightMouseState[2];
+ unsigned int m_CurrentState;
+ int m_MouseX;
+ int m_MouseY;
+ bool m_LeftMouseDown;
+ bool m_RightMouseDown;
+ bool m_LeftDoubleClick;
+ unsigned int m_DoubleClickTime;
+ int m_DoubleClickRectWidth;
+ int m_DoubleClickRectHeight;
+ unsigned int m_LastLeftClickTime;
+ int m_LastLeftClickMouseX;
+ int m_LastLeftClickMouseY;
+ Common::List<CommandCallback> m_CommandCallbacks;
+ Common::List<CharacterCallback> m_CharacterCallbacks;
+};
+
+} // End of namespace Sword25
+
+#endif
Property changes on: scummvm/trunk/engines/sword25/input/scummvminput.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Deleted: scummvm/trunk/engines/sword25/input/stdwininput.cpp
===================================================================
--- scummvm/trunk/engines/sword25/input/stdwininput.cpp 2010-10-12 22:20:41 UTC (rev 53202)
+++ scummvm/trunk/engines/sword25/input/stdwininput.cpp 2010-10-12 22:21:24 UTC (rev 53203)
@@ -1,416 +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
- *
- */
-
-#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 <algorithm>
-using namespace std;
-
-#define BS_LOG_PREFIX "WININPUT"
-
-// -----------------------------------------------------------------------------
-// Konstruktion / Destruktion
-// -----------------------------------------------------------------------------
-
-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)
-{
- 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;
-}
-
-BS_StdWinInput::~BS_StdWinInput()
-{
-}
-
-// -----------------------------------------------------------------------------
-
-BS_Service * BS_StdWinInput_CreateObject(BS_Kernel* pKernel) { return new BS_StdWinInput(pKernel); }
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::Init()
-{
- // Keine Inialisierung notwendig
- 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\xFCr eine andere Applikation gedacht waren.
- if (BS_Kernel::GetInstance()->GetWindow()->HasFocus())
- {
- m_CurrentState ^= 1;
-
- // Der Status der Eingabeger\xE4te wird nur einmal pro Frame ausgelesen, damit f\xFCr
- // 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();
- }
- 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;
-
- TestForLeftDoubleClick();
- }
-}
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::IsLeftMouseDown()
-{
- return m_LeftMouseDown;
-}
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::IsRightMouseDown()
-{
- return m_RightMouseDown;
-}
-
-// -----------------------------------------------------------------------------
-
-void BS_StdWinInput::TestForLeftDoubleClick()
-{
- // Das Doppelklick-Flag wird gel\xF6scht, f\xFCr den Fall, dass im letzten Frame ein Doppelklick ausgetreten ist.
- m_LeftDoubleClick = false;
-
- // Die linke Maustaste wurde geklickt, also muss getestet werden, ob ein Doppelklick vorliegt.
- if (WasLeftMouseDown())
- {
- // Die Zeit auslesen.
- 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.
- 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;
-
- // Die Zeit und Position des letzten Linksklicks zur\xFCcksetzen, damit dieser Klick nicht als erster Klick eines weiteren Doppelklicks
- // interpretiert wird.
- m_LastLeftClickTime = 0;
- m_LastLeftClickMouseX = 0;
- m_LastLeftClickMouseY = 0;
- }
- else
- {
- // Es liegt kein Doppelklick vor, die Zeit und die Position dieses Klicks merken, f\xFCr den Fall das dies der erste Klick eines
- // zuk\xFCnftigen Doppelklicks wird.
- m_LastLeftClickTime = Now;
- m_LastLeftClickMouseX = m_MouseX;
- m_LastLeftClickMouseY = m_MouseY;
- }
- }
-}
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::IsLeftDoubleClick()
-{
- return m_LeftDoubleClick;
-}
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::WasLeftMouseDown()
-{
- return (m_LeftMouseState[m_CurrentState] == false) && (m_LeftMouseState[m_CurrentState ^ 1] == true);
-}
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::WasRightMouseDown()
-{
- return (m_RightMouseState[m_CurrentState] == false) && (m_RightMouseState[m_CurrentState ^ 1] == true);
-}
-
-// -----------------------------------------------------------------------------
-
-int BS_StdWinInput::GetMouseX()
-{
- return m_MouseX;
-}
-
-// -----------------------------------------------------------------------------
-
-int BS_StdWinInput::GetMouseY()
-{
- return m_MouseY;
-}
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::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);
-}
-
-// -----------------------------------------------------------------------------
-
-void BS_StdWinInput::SetMouseX(int PosX)
-{
- m_MouseX = PosX;
- SetCursorPos(m_MouseX + BS_Kernel::GetInstance()->GetWindow()->GetClientX(), m_MouseY + BS_Kernel::GetInstance()->GetWindow()->GetClientY());
-}
-
-// -----------------------------------------------------------------------------
-
-void BS_StdWinInput::SetMouseY(int PosY)
-{
- m_MouseY = PosY;
- SetCursorPos(m_MouseX + BS_Kernel::GetInstance()->GetWindow()->GetClientX(), m_MouseY + BS_Kernel::GetInstance()->GetWindow()->GetClientY());
-}
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::RegisterCharacterCallback(CharacterCallback Callback)
-{
- if (find(m_CharacterCallbacks.begin(), m_CharacterCallbacks.end(), Callback) == m_CharacterCallbacks.end())
- {
- m_CharacterCallbacks.push_back(Callback);
- return true;
- }
- else
- {
- BS_LOG_WARNINGLN("Tried to register an CharacterCallback that was already registered.");
- return false;
- }
-}
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::UnregisterCharacterCallback(CharacterCallback Callback)
-{
- list<CharacterCallback>::iterator CallbackIter = find(m_CharacterCallbacks.begin(), m_CharacterCallbacks.end(), Callback);
- if (CallbackIter != m_CharacterCallbacks.end())
- {
- m_CharacterCallbacks.erase(CallbackIter);
- return true;
- }
- else
- {
- BS_LOG_WARNINGLN("Tried to unregister an CharacterCallback that was not previously registered.");
- return false;
- }
-}
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::RegisterCommandCallback(CommandCallback Callback)
-{
- if (find(m_CommandCallbacks.begin(), m_CommandCallbacks.end(), Callback) == m_CommandCallbacks.end())
- {
- m_CommandCallbacks.push_back(Callback);
- return true;
- }
- else
- {
- BS_LOG_WARNINGLN("Tried to register an CommandCallback that was already registered.");
- return false;
- }
-}
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::UnregisterCommandCallback(CommandCallback Callback)
-{
- list<CommandCallback>::iterator CallbackIter = find(m_CommandCallbacks.begin(), m_CommandCallbacks.end(), Callback);
- if (CallbackIter != m_CommandCallbacks.end())
- {
- m_CommandCallbacks.erase(CallbackIter);
- return true;
- }
- else
- {
- BS_LOG_WARNINGLN("Tried to unregister an CommandCallback that was not previously registered.");
- return false;
- }
-}
-
-// -----------------------------------------------------------------------------
-
-void BS_StdWinInput::ReportCharacter(unsigned char Character)
-{
- list<CharacterCallback>::const_iterator CallbackIter = m_CharacterCallbacks.begin();
- while (CallbackIter != m_CharacterCallbacks.end())
- {
- // Iterator vor dem Aufruf erh\xF6hen und im Folgendem auf einer Kopie arbeiten.
- // Dieses Vorgehen ist notwendig da der Iterator m\xF6glicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks
- // invalidiert wird.
- list<CharacterCallback>::const_iterator CurCallbackIter = CallbackIter;
- ++CallbackIter;
-
- (*CurCallbackIter)(Character);
- }
-}
-
-// -----------------------------------------------------------------------------
-
-void BS_StdWinInput::ReportCommand(KEY_COMMANDS Command)
-{
- list<CommandCallback>::const_iterator CallbackIter = m_CommandCallbacks.begin();
- while (CallbackIter != m_CommandCallbacks.end())
- {
- // Iterator vor dem Aufruf erh\xF6hen und im Folgendem auf einer Kopie arbeiten.
- // Dieses Vorgehen ist notwendig da der Iterator m\xF6glicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks
- // invalidiert wird.
- list<CommandCallback>::const_iterator CurCallbackIter = CallbackIter;
- ++CallbackIter;
-
- (*CurCallbackIter)(Command);
- }
-}
-
-// -----------------------------------------------------------------------------
-// Persistenz
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::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())
- {
- Writer.Write(BS_CallbackRegistry::GetInstance().ResolveCallbackPointer(*It));
- ++It;
- }
- }
-
- // Anzahl an Character-Callbacks persistieren.
- Writer.Write(m_CharacterCallbacks.size());
-
- // Alle Character-Callbacks einzeln persistieren.
- {
- list<CharacterCallback>::const_iterator It = m_CharacterCallbacks.begin();
- while (It != m_CharacterCallbacks.end())
- {
- Writer.Write(BS_CallbackRegistry::GetInstance().ResolveCallbackPointer(*It));
- ++It;
- }
- }
-
- return true;
-}
-
-// -----------------------------------------------------------------------------
-
-bool BS_StdWinInput::Unpersist(BS_InputPersistenceBlock & Reader)
-{
- // Command-Callbackliste leeren.
- m_CommandCallbacks.clear();
-
- // Anzahl an Command-Callbacks lesen.
- unsigned int CommandCallbackCount;
- Reader.Read(CommandCallbackCount);
-
- // Alle Command-Callbacks wieder herstellen.
- for (unsigned int i = 0; i < CommandCallbackCount; ++i)
- {
- std::string CallbackFunctionName;
- Reader.Read(CallbackFunctionName);
-
- m_CommandCallbacks.push_back(reinterpret_cast<CommandCallback>(BS_CallbackRegistry::GetInstance().ResolveCallbackFunction(CallbackFunctionName)));
- }
-
- // Character-Callbackliste leeren.
- m_CharacterCallbacks.clear();
-
- // Anzahl an Character-Callbacks lesen.
- unsigned int CharacterCallbackCount;
- Reader.Read(CharacterCallbackCount);
-
- // Alle Character-Callbacks wieder herstellen.
- for (unsigned int i = 0; i < CharacterCallbackCount; ++i)
- {
- std::string CallbackFunctionName;
- Reader.Read(CallbackFunctionName);
-
- m_CharacterCallbacks.push_back(reinterpret_cast<CharacterCallback>(BS_CallbackRegistry::GetInstance().ResolveCallbackFunction(CallbackFunctionName)));
- }
-
- return Reader.IsGood();
-}
Deleted: scummvm/trunk/engines/sword25/input/stdwininput.h
===================================================================
--- scummvm/trunk/engines/sword25/input/stdwininput.h 2010-10-12 22:20:41 UTC (rev 53202)
+++ scummvm/trunk/engines/sword25/input/stdwininput.h 2010-10-12 22:21:24 UTC (rev 53203)
@@ -1,102 +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_STDWININPUT_H
-#define SWORD25_STDWININPUT_H
-
-/// Includes
-#include "common/scummsys.h"
-#include "common/list.h"
-#include "sword25/kernel/common.h"
-#include "sword25/input/inputengine.h"
-
-namespace Sword25 {
-
-/// Forward class definitions
-class BS_Kernel;
-
-/// Class definitions
-class BS_StdWinInput : public BS_InputEngine {
-public:
- BS_StdWinInput(BS_Kernel *pKernel);
- virtual ~BS_StdWinInput();
-
- virtual bool Init();
- virtual void Update();
- virtual bool IsLeftMouseDown();
- virtual bool IsRightMouseDown();
- virtual bool WasLeftMouseDown();
- virtual bool WasRightMouseDown();
- virtual bool IsLeftDoubleClick();
- virtual int GetMouseX();
- virtual int GetMouseY();
- virtual bool IsKeyDown(unsigned int KeyCode);
- virtual bool WasKeyDown(unsigned int KeyCode);
- virtual void SetMouseX(int PosX);
- virtual void SetMouseY(int PosY);
- virtual bool RegisterCharacterCallback(CharacterCallback Callback);
- virtual bool UnregisterCharacterCallback(CharacterCallback Callback);
- virtual bool RegisterCommandCallback(CommandCallback Callback);
- virtual bool UnregisterCommandCallback(CommandCallback Callback);
- virtual void ReportCharacter(unsigned char Character);
- virtual void ReportCommand(KEY_COMMANDS Command);
-
- bool Persist(BS_OutputPersistenceBlock &Writer);
- bool Unpersist(BS_InputPersistenceBlock &Reader);
-
-private:
- void TestForLeftDoubleClick();
-
- byte m_KeyboardState[2][256];
- bool m_LeftMouseState[2];
- bool m_RightMouseState[2];
- unsigned int m_CurrentState;
- int m_MouseX;
- int m_MouseY;
- bool m_LeftMouseDown;
- bool m_RightMouseDown;
- bool m_LeftDoubleClick;
- unsigned int m_DoubleClickTime;
- int m_DoubleClickRectWidth;
- int m_DoubleClickRectHeight;
- unsigned int m_LastLeftClickTime;
- int m_LastLeftClickMouseX;
- int m_LastLeftClickMouseY;
- Common::List<CommandCallback> m_CommandCallbacks;
- Common::List<CharacterCallback> m_CharacterCallbacks;
-};
-
-} // End of namespace Sword25
-
-#endif
Modified: scummvm/trunk/engines/sword25/kernel/callbackregistry.h
===================================================================
--- scummvm/trunk/engines/sword25/kernel/callbackregistry.h 2010-10-12 22:20:41 UTC (rev 53202)
+++ scummvm/trunk/engines/sword25/kernel/callbackregistry.h 2010-10-12 22:21:24 UTC (rev 53203)
@@ -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
Modified: scummvm/trunk/engines/sword25/kernel/inputpersistenceblock.h
===================================================================
--- scummvm/trunk/engines/sword25/kernel/inputpersistenceblock.h 2010-10-12 22:20:41 UTC (rev 53202)
+++ scummvm/trunk/engines/sword25/kernel/inputpersistenceblock.h 2010-10-12 22:21:24 UTC (rev 53203)
@@ -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 {
Modified: scummvm/trunk/engines/sword25/kernel/service_ids.h
===================================================================
--- scummvm/trunk/engines/sword25/kernel/service_ids.h 2010-10-12 22:20:41 UTC (rev 53202)
+++ scummvm/trunk/engines/sword25/kernel/service_ids.h 2010-10-12 22:21:24 UTC (rev 53203)
@@ -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\xFCckgibt.
- // 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),
Modified: scummvm/trunk/engines/sword25/script/luascript.cpp
===================================================================
--- scummvm/trunk/engines/sword25/script/luascript.cpp 2010-10-12 22:20:41 UTC (rev 53202)
+++ scummvm/trunk/engines/sword25/script/luascript.cpp 2010-10-12 22:21:24 UTC (rev 53203)
@@ -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 @@
namespace Sword25 {
-using namespace std;
using namespace Lua;
// -----------------------------------------------------------------------------
@@ -410,7 +410,7 @@
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 @@
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.
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