aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2010-08-06 10:50:16 +0000
committerEugene Sandulenko2010-10-12 22:28:21 +0000
commit87553862d92d462534cb7a050bf481d9cd1d0d59 (patch)
tree65cd08fa6a58888b98d95c5cb240e9515f936727 /engines
parentbf53914c2aedbe340be8fb920a5023020d64c101 (diff)
downloadscummvm-rg350-87553862d92d462534cb7a050bf481d9cd1d0d59.tar.gz
scummvm-rg350-87553862d92d462534cb7a050bf481d9cd1d0d59.tar.bz2
scummvm-rg350-87553862d92d462534cb7a050bf481d9cd1d0d59.zip
SWORD25: Converted remainder of Kernel/ folder
svn-id: r53216
Diffstat (limited to 'engines')
-rw-r--r--engines/sword25/gfx/framecounter.cpp17
-rw-r--r--engines/sword25/gfx/framecounter.h2
-rw-r--r--engines/sword25/input/scummvminput.cpp4
-rw-r--r--engines/sword25/kernel/outputpersistenceblock.cpp37
-rw-r--r--engines/sword25/kernel/scummvmwindow.cpp296
-rw-r--r--engines/sword25/kernel/scummvmwindow.h (renamed from engines/sword25/kernel/win32window.h)43
-rw-r--r--engines/sword25/kernel/timer.cpp68
-rw-r--r--engines/sword25/kernel/timer.h84
-rw-r--r--engines/sword25/kernel/win32window.cpp440
-rw-r--r--engines/sword25/kernel/window.cpp17
-rw-r--r--engines/sword25/kernel/window.h3
-rw-r--r--engines/sword25/module.mk3
-rw-r--r--engines/sword25/sword25.cpp25
-rw-r--r--engines/sword25/sword25.h2
14 files changed, 370 insertions, 671 deletions
diff --git a/engines/sword25/gfx/framecounter.cpp b/engines/sword25/gfx/framecounter.cpp
index 65a0c9f053..c2e6ab772d 100644
--- a/engines/sword25/gfx/framecounter.cpp
+++ b/engines/sword25/gfx/framecounter.cpp
@@ -32,36 +32,33 @@
*
*/
+#include "common/system.h"
#include "sword25/gfx/framecounter.h"
-#include "sword25/kernel/timer.h"
namespace Sword25 {
BS_Framecounter::BS_Framecounter(int UpdateFrequency) :
- m_FPS(0),
- m_FPSCount(0),
- m_LastUpdateTime(-1)
-{
+ m_FPS(0),
+ m_FPSCount(0),
+ m_LastUpdateTime(-1) {
SetUpdateFrequency(UpdateFrequency);
}
void BS_Framecounter::Update()
{
// Aktuellen Systemtimerstand auslesen
- uint64_t Timer = BS_Timer::GetMicroTicks();
+ uint64_t Timer = g_system->getMillis() * 1000;
// Falls m_LastUpdateTime == -1 ist, wird der Frame-Counter zum ersten Mal aufgerufen und der aktuelle Systemtimer als erster
// Messzeitpunkt genommen.
if (m_LastUpdateTime == -1)
m_LastUpdateTime = Timer;
- else
- {
+ else {
// Die Anzahl der Frames im aktuellen Messzeitraum wird erhöht.
m_FPSCount++;
// Falls der Messzeitraum verstrichen ist, wird die durchschnittliche Framerate berechnet und ein neuer Messzeitraum begonnen.
- if (Timer - m_LastUpdateTime >= m_UpdateDelay)
- {
+ if (Timer - m_LastUpdateTime >= m_UpdateDelay) {
m_FPS = static_cast<int>((1000000 * (uint64_t)m_FPSCount) / (Timer - m_LastUpdateTime));
m_LastUpdateTime = Timer;
m_FPSCount = 0;
diff --git a/engines/sword25/gfx/framecounter.h b/engines/sword25/gfx/framecounter.h
index ebdc78ce65..89612f94be 100644
--- a/engines/sword25/gfx/framecounter.h
+++ b/engines/sword25/gfx/framecounter.h
@@ -77,7 +77,7 @@ public:
private:
int m_FPS;
int m_FPSCount;
- uint64_t m_LastUpdateTime;
+ int64_t m_LastUpdateTime;
uint64_t m_UpdateDelay;
};
diff --git a/engines/sword25/input/scummvminput.cpp b/engines/sword25/input/scummvminput.cpp
index d0824cd0e4..14c94bd226 100644
--- a/engines/sword25/input/scummvminput.cpp
+++ b/engines/sword25/input/scummvminput.cpp
@@ -121,6 +121,10 @@ void ScummVMInput::Update() {
AlterKeyboardState(event.kbd.keycode, (event.type == Common::EVENT_KEYDOWN) ? 0x80 : 0);
break;
+ case Common::EVENT_QUIT:
+ BS_Kernel::GetInstance()->GetWindow()->SetWindowAlive(false);
+ break;
+
default:
break;
}
diff --git a/engines/sword25/kernel/outputpersistenceblock.cpp b/engines/sword25/kernel/outputpersistenceblock.cpp
index 9573ba7b08..880f4be8d0 100644
--- a/engines/sword25/kernel/outputpersistenceblock.cpp
+++ b/engines/sword25/kernel/outputpersistenceblock.cpp
@@ -44,17 +44,17 @@
// Constants
// -----------------------------------------------------------------------------
-namespace
-{
+namespace {
const unsigned int INITIAL_BUFFER_SIZE = 1024 * 64;
}
+namespace Sword25 {
+
// -----------------------------------------------------------------------------
// Construction / Destruction
// -----------------------------------------------------------------------------
-BS_OutputPersistenceBlock::BS_OutputPersistenceBlock()
-{
+BS_OutputPersistenceBlock::BS_OutputPersistenceBlock() {
m_Data.reserve(INITIAL_BUFFER_SIZE);
}
@@ -62,8 +62,7 @@ BS_OutputPersistenceBlock::BS_OutputPersistenceBlock()
// Writing
// -----------------------------------------------------------------------------
-void BS_OutputPersistenceBlock::Write(signed int Value)
-{
+void BS_OutputPersistenceBlock::Write(signed int Value) {
WriteMarker(SINT_MARKER);
Value = ConvertEndianessFromSystemToStorage(Value);
RawWrite(&Value, sizeof(Value));
@@ -71,8 +70,7 @@ void BS_OutputPersistenceBlock::Write(signed int Value)
// -----------------------------------------------------------------------------
-void BS_OutputPersistenceBlock::Write(unsigned int Value)
-{
+void BS_OutputPersistenceBlock::Write(unsigned int Value) {
WriteMarker(UINT_MARKER);
Value = ConvertEndianessFromSystemToStorage(Value);
RawWrite(&Value, sizeof(Value));
@@ -80,8 +78,7 @@ void BS_OutputPersistenceBlock::Write(unsigned int Value)
// -----------------------------------------------------------------------------
-void BS_OutputPersistenceBlock::Write(float Value)
-{
+void BS_OutputPersistenceBlock::Write(float Value) {
WriteMarker(FLOAT_MARKER);
Value = ConvertEndianessFromSystemToStorage(Value);
RawWrite(&Value, sizeof(Value));
@@ -89,8 +86,7 @@ void BS_OutputPersistenceBlock::Write(float Value)
// -----------------------------------------------------------------------------
-void BS_OutputPersistenceBlock::Write(bool Value)
-{
+void BS_OutputPersistenceBlock::Write(bool Value) {
WriteMarker(BOOL_MARKER);
unsigned int UIntBool = Value ? 1 : 0;
@@ -100,8 +96,7 @@ void BS_OutputPersistenceBlock::Write(bool Value)
// -----------------------------------------------------------------------------
-void BS_OutputPersistenceBlock::Write(const std::string & String)
-{
+void BS_OutputPersistenceBlock::Write(const Common::String &String) {
WriteMarker(STRING_MARKER);
Write(String.size());
@@ -110,8 +105,7 @@ void BS_OutputPersistenceBlock::Write(const std::string & String)
// -----------------------------------------------------------------------------
-void BS_OutputPersistenceBlock::Write(const void * BufferPtr, size_t Size)
-{
+void BS_OutputPersistenceBlock::Write(const void *BufferPtr, size_t Size) {
WriteMarker(BLOCK_MARKER);
Write(Size);
@@ -120,19 +114,18 @@ void BS_OutputPersistenceBlock::Write(const void * BufferPtr, size_t Size)
// -----------------------------------------------------------------------------
-void BS_OutputPersistenceBlock::WriteMarker(unsigned char Marker)
-{
+void BS_OutputPersistenceBlock::WriteMarker(unsigned char Marker) {
m_Data.push_back(Marker);
}
// -----------------------------------------------------------------------------
-void BS_OutputPersistenceBlock::RawWrite(const void * DataPtr, size_t Size)
-{
- if (Size > 0)
- {
+void BS_OutputPersistenceBlock::RawWrite(const void *DataPtr, size_t Size) {
+ if (Size > 0) {
unsigned int OldSize = m_Data.size();
m_Data.resize(OldSize + Size);
memcpy(&m_Data[OldSize], DataPtr, Size);
}
}
+
+} // End of namespace Sword25
diff --git a/engines/sword25/kernel/scummvmwindow.cpp b/engines/sword25/kernel/scummvmwindow.cpp
new file mode 100644
index 0000000000..56e3b14adb
--- /dev/null
+++ b/engines/sword25/kernel/scummvmwindow.cpp
@@ -0,0 +1,296 @@
+/* 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/system.h"
+#include "engines/util.h"
+#include "graphics/pixelformat.h"
+#include "sword25/kernel/scummvmwindow.h"
+#include "sword25/kernel/kernel.h"
+#include "sword25/input/inputengine.h"
+
+#define BS_LOG_PREFIX "WIN32WINDOW"
+
+namespace Sword25 {
+
+bool BS_ScummVMWindow::_ClassRegistered = false;
+
+// Constructor / Destructor
+// ------------------------
+BS_ScummVMWindow::BS_ScummVMWindow(int X, int Y, int Width, int Height, bool Visible) {
+ // Presume that init will fail
+ _InitSuccess = false;
+
+ // We don't support any window creation except at the origin 0,0
+ assert(X == 0);
+ assert(Y == 0);
+
+ if (!_ClassRegistered) {
+ // Nothing here currently
+
+ _ClassRegistered = true;
+ }
+
+ // Fenstersichtbarkeit setzen
+ SetVisible(Visible);
+
+ // Indicate success
+ _InitSuccess = true;
+ _WindowAlive = true;
+ _CloseWanted = false;
+}
+
+BS_ScummVMWindow::~BS_ScummVMWindow() {
+}
+
+// Get Methods
+// ------------
+int BS_ScummVMWindow::GetX() {
+ return 0;
+}
+
+int BS_ScummVMWindow::GetY() {
+ return 0;
+}
+
+int BS_ScummVMWindow::GetClientX() {
+ return 0;
+}
+
+int BS_ScummVMWindow::GetClientY() {
+ return 0;
+}
+
+int BS_ScummVMWindow::GetWidth() {
+ return g_system->getWidth();
+}
+
+int BS_ScummVMWindow::GetHeight() {
+ return g_system->getHeight();
+}
+
+Common::String BS_ScummVMWindow::GetTitle() {
+ return Common::String("");
+}
+
+bool BS_ScummVMWindow::IsVisible() {
+ return true;
+}
+
+bool BS_ScummVMWindow::HasFocus() {
+ // FIXME: Is there a way to tell if ScummVM has the focus in Windowed mode?
+ return true;
+}
+
+uint BS_ScummVMWindow::GetWindowHandle() {
+ return 0;
+}
+
+void BS_ScummVMWindow::SetWindowAlive(bool v) {
+ _WindowAlive = v;
+}
+
+
+// Set Methods
+// ------------
+
+void BS_ScummVMWindow::SetX(int X) {
+ // No implementation
+}
+
+void BS_ScummVMWindow::SetY(int Y) {
+ // No implementation
+}
+
+void BS_ScummVMWindow::SetWidth(int Width) {
+ // No implementation
+}
+
+void BS_ScummVMWindow::SetHeight(int Height) {
+ // No implementation
+}
+
+void BS_ScummVMWindow::SetVisible(bool Visible) {
+ // No implementation
+}
+
+void BS_ScummVMWindow::SetTitle(const Common::String &Title) {
+ // No implementation
+}
+
+bool BS_ScummVMWindow::ProcessMessages() {
+ // No implementation
+ return false;
+}
+
+bool BS_ScummVMWindow::WaitForFocus() {
+ // No implementation
+ return true;
+}
+
+// FIXME: Special keys detected here need to be moved into the Input Engine
+/*
+// Die WindowProc aller Fenster der Klasse
+LRESULT CALLBACK BS_ScummVMWindow::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch(uMsg)
+ {
+ case WM_PAINT:
+ ValidateRect(hwnd, NULL);
+ break;
+
+ case WM_DESTROY:
+ // Das Fenster wird zerstört
+ PostQuitMessage(0);
+ break;
+
+ case WM_CLOSE:
+ {
+ BS_Window * WindowPtr = BS_Kernel::GetInstance()->GetWindow();
+ if (WindowPtr) {
+ WindowPtr->SetCloseWanted(true);
+ }
+ break;
+ }
+
+ case WM_KEYDOWN:
+ {
+ // Tastendrücke, die für das Inputmodul interessant sind, werden diesem gemeldet.
+ BS_InputEngine * InputPtr = BS_Kernel::GetInstance()->GetInput();
+
+ if (InputPtr)
+ {
+ switch (wParam)
+ {
+ case VK_RETURN:
+ InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_ENTER);
+ break;
+
+ case VK_LEFT:
+ InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_LEFT);
+ break;
+
+ case VK_RIGHT:
+ InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_RIGHT);
+ break;
+
+ case VK_HOME:
+ InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_HOME);
+ break;
+
+ case VK_END:
+ InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_END);
+ break;
+
+ case VK_BACK:
+ InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_BACKSPACE);
+ break;
+
+ case VK_TAB:
+ InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_TAB);
+ break;
+
+ case VK_INSERT:
+ InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_INSERT);
+ break;
+
+ case VK_DELETE:
+ InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_DELETE);
+ break;
+ }
+ }
+ break;
+ }
+
+ case WM_KEYUP:
+ case WM_SYSKEYUP:
+ // Alle Tastendrücke werden ignoriert, damit Windows per DefWindowProc() nicht darauf
+ // reagieren kann und damit unerwartete Seiteneffekte auslöst.
+ // Zum Beispiel würden ALT und F10 Tastendrücke das "Menü" aktivieren und somit den Message-Loop zum Stillstand bringen.
+ break;
+
+ case WM_SYSCOMMAND:
+ // Verhindern, dass der Bildschirmschoner aktiviert wird, während das Spiel läuft
+ if (wParam != SC_SCREENSAVE) return DefWindowProc(hwnd,uMsg,wParam,lParam);
+ break;
+
+ case WM_CHAR:
+ {
+ unsigned char theChar = static_cast<unsigned char>(wParam & 0xff);
+
+ // Alle Zeichen, die keine Steuerzeichen sind, werden als Buchstaben dem Input-Service mitgeteilt.
+ if (theChar >= 32)
+ {
+ BS_InputEngine * InputPtr = BS_Kernel::GetInstance()->GetInput();
+ if (InputPtr) InputPtr->ReportCharacter(theChar);
+ }
+ }
+ break;
+
+ case WM_SETCURSOR:
+ {
+ // Der Systemcursor wird in der Client-Area des Fensters nicht angezeigt, jedoch in der nicht Client-Area, damit der Benutzer das Fenster wie gewohnt
+ // schließen und verschieben kann.
+
+ // Koordinaten des Cursors in der Client-Area berechnen.
+ POINT pt;
+ GetCursorPos(&pt);
+ ScreenToClient(hwnd, &pt);
+
+ // Feststellen, ob sich der Cursor in der Client-Area befindet.
+ // Get client rect
+ RECT rc;
+ GetClientRect(hwnd, &rc);
+
+ // See if cursor is in client area
+ if(PtInRect(&rc, pt))
+ // In der Client-Area keinen Cursor anzeigen.
+ SetCursor(NULL);
+ else
+ // Ausserhalb der Client-Area den Cursor anzeigen.
+ SetCursor(LoadCursor(NULL, IDC_ARROW));
+
+ return TRUE;
+ }
+ break;
+
+ default:
+ // Um alle anderen Vorkommnisse kümmert sich Windows
+ return DefWindowProc(hwnd,uMsg,wParam,lParam);
+ }
+
+ return 0;
+}
+*/
+
+} // End of namespace Sword25
diff --git a/engines/sword25/kernel/win32window.h b/engines/sword25/kernel/scummvmwindow.h
index a8376d8a6d..da223ae102 100644
--- a/engines/sword25/kernel/win32window.h
+++ b/engines/sword25/kernel/scummvmwindow.h
@@ -33,32 +33,25 @@
*/
/*
- BS_Win32Window
- -------------
- Implementation des BS_Window Interfaces für Win32.
- Zu den einzelnen Methoden bitte "window.h" konsultieren.
-
- Autor: Malte Thiesen
+ BS_ScummVMWindow
+ ----------------
+ Implementation of the BS_Window Interfaces for ScummVM
*/
-#ifndef SWORD25_WIN32WINDOW_H
-#define SWORD25_WIN32WINDOW_H
+#ifndef SWORD25_SCUMMVMWINDOW_H
+#define SWORD25_SCUMMVMWINDOW_H
// Includes
-#include "sword25/kernel/memlog_off.h"
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include "sword25/kernel/memlog_on.h"
-
#include "sword25/kernel/common.h"
#include "sword25/kernel/window.h"
-// Klassendefinition
-class BS_Win32Window : public BS_Window
-{
+namespace Sword25 {
+
+// Class definition
+class BS_ScummVMWindow : public BS_Window {
public:
- BS_Win32Window(int X, int Y, int Width, int Height, bool Visible);
- virtual ~BS_Win32Window();
+ BS_ScummVMWindow(int X, int Y, int Width, int Height, bool Visible);
+ virtual ~BS_ScummVMWindow();
bool IsVisible();
void SetVisible(bool Visible);
@@ -72,21 +65,21 @@ public:
void SetWidth(int Width);
int GetHeight();
void SetHeight(int Height);
- std::string GetTitle();
- void SetTitle(std::string Title);
+ Common::String GetTitle();
+ void SetWindowAlive(bool v);
+ void SetTitle(const Common::String &Title);
bool HasFocus();
- UINT GetWindowHandle();
+ uint GetWindowHandle();
bool WaitForFocus();
bool ProcessMessages();
private:
static bool _ClassRegistered;
bool _WindowAlive;
- HWND _Window;
int _ClientXDelta;
int _ClientYDelta;
-
- static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};
-#endif \ No newline at end of file
+} // End of namespace Sword25
+
+#endif
diff --git a/engines/sword25/kernel/timer.cpp b/engines/sword25/kernel/timer.cpp
deleted file mode 100644
index da3656ed12..0000000000
--- a/engines/sword25/kernel/timer.cpp
+++ /dev/null
@@ -1,68 +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
- *
- */
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-#include "sword25/kernel/timer.h"
-
-#define BS_LOG_PREFIX "BS_TIMER"
-
-uint64_t BS_Timer::GetMicroTicks()
-{
- HANDLE ThreadID = ::GetCurrentThread();
-
- DWORD_PTR OldAffinityMask = ::SetThreadAffinityMask(ThreadID, 1);
-
- uint64_t Frequency;
- ::QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(&Frequency));
-
- uint64_t Tick;
- ::QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&Tick));
-
- ::SetThreadAffinityMask(ThreadID, OldAffinityMask);
-
- return Tick * 1000000 / Frequency;
-}
-
-unsigned int BS_Timer::GetMilliTicks()
-{
- return (unsigned int)(GetMicroTicks() / 1000);
-}
-
-bool BS_Timer::IsTimerAvaliable()
-{
- LARGE_INTEGER Dummy;
- return ::QueryPerformanceFrequency(&Dummy) ? true : false;
-}
diff --git a/engines/sword25/kernel/timer.h b/engines/sword25/kernel/timer.h
deleted file mode 100644
index a4ef1c4d00..0000000000
--- a/engines/sword25/kernel/timer.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-/*
- * This code is based on Broken Sword 2.5 engine
- *
- * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
- *
- * Licensed under GNU GPL v2
- *
- */
-
-/*
- BS_Timer
- --------
- Eine Klasse zum Auslesen des Systemtimers.
-
- Autor: Malte Thiesen
-*/
-
-#ifndef SWORD25_TIMER_H
-#define SWORD25_TIMER_H
-
-// Includes
-#include "sword25/kernel/common.h"
-#include "sword25/kernel/bs_stdint.h"
-
-/**
- @brief Eine Klasse zum Auslesen des Systemtimers.
-
- Vor der Benutzung sollte immer mit IsTimerAvaliable() getestet werden, ob der Timer von der benutzten
- Hardware unterstützt wird.
-*/
-class BS_Timer
-{
-public:
- /**
- @brief List den Systemtimer in Microsekunden aus.
- @return Die Zahl vergangener Microsekunden seit dem Systemstart.<br>
- */
- static uint64_t GetMicroTicks();
-
- /**
- @brief List den Systemtimer in Millisekunden aus.
- @return Die Zahl vergangener Millisekunden seit dem Systemstart.<br>
- */
- static unsigned int GetMilliTicks();
-
- /**
- @brief Prüft, ob der Timer auf der vorhandenen Hardware existiert.
- @return Gibt false zurück, fals der Timer auf der vorhandenen Hardware nicht existiert.
- */
- static bool IsTimerAvaliable();
-
-private:
- /**
- @brief Initialisiert den Timer.
- */
- static void Init();
-};
-
-#endif
diff --git a/engines/sword25/kernel/win32window.cpp b/engines/sword25/kernel/win32window.cpp
deleted file mode 100644
index 1b41329370..0000000000
--- a/engines/sword25/kernel/win32window.cpp
+++ /dev/null
@@ -1,440 +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/win32window.h"
-#include "../../projects/resource.h"
-
-#include "sword25/kernel/kernel.h"
-#include "sword25/input/inputengine.h"
-
-bool BS_Win32Window::_ClassRegistered = false;
-
-#define BS_LOG_PREFIX "WIN32WINDOW"
-
-
-// Konstanten
-// ----------
-static const UINT WINDOW_STYLE = WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
-static const UINT WINDOW_STYLE_EX = 0;
-static const UINT WINDOW_MAX_MESSAGES = 50;
-
-// Konstruktion/Destruktion
-// ------------------------
-BS_Win32Window::BS_Win32Window(int X, int Y, int Width, int Height, bool Visible)
-{
- const char WINDOW_CLASS[] = "BSEngine-Class";
-
- // Von negativen Fall ausgehen
- _InitSuccess = false;
-
- // Fensterklasse registrieren falls nötig
- if (!_ClassRegistered)
- {
- //Fensterklasse
- WNDCLASSEX wndclass;
-
- //Werte der Fensterklasse festlegen
- ZeroMemory(&wndclass, sizeof(WNDCLASSEX));
- wndclass.cbSize = sizeof(WNDCLASSEX);
- wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
- wndclass.lpfnWndProc = BS_Win32Window::WindowProc;
- wndclass.hInstance = GetModuleHandle(NULL);
- wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
- wndclass.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
- wndclass.hCursor = NULL;
- wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
- wndclass.lpszClassName = WINDOW_CLASS;
-
- //Fensterklasse registrieren
- if (!RegisterClassEx(&wndclass)) return;
-
- _ClassRegistered = true;
- }
-
- //Fenster erstellen
- if (!(_Window=CreateWindowEx(
- WINDOW_STYLE_EX, // Erweiterte Darstellungsflags
- WINDOW_CLASS, // Registrierter Fenstername
- "", // Kein Fenstertitel
- WINDOW_STYLE, // Darstellungsflags
- 0,0, // Default-Position
- 0,0, // Default-Grösse
- NULL, // Kein Parent-Fenster
- NULL, // Kein Menü
- GetModuleHandle(NULL), // Instance-Handle
- NULL)))
- return;
-
- // Fensterposition und Fenstergröße setzen
- SetWidth(Width);
- SetHeight(Height);
- SetX(X);
- SetY(Y);
-
- // Fenstersichtbarkeit setzen
- SetVisible(Visible);
-
- // Icon setzen
- HICON hIcon = LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON1));
- if (hIcon)
- {
- SendMessage(_Window, WM_SETICON, ICON_BIG, (LPARAM) hIcon);
- SendMessage(_Window, WM_SETICON, ICON_SMALL, (LPARAM) hIcon);
- }
-
- // Erfolg signalisieren
- _InitSuccess = true;
- _WindowAlive = true;
- _CloseWanted = false;
-}
-
-BS_Win32Window::~BS_Win32Window()
-{
- // Fenster zerstören, falls dies nicht ohnehin schon passiert ist
- if (_WindowAlive) DestroyWindow(_Window);
-}
-
-// Get-Methoden
-// ------------
-int BS_Win32Window::GetX()
-{
- RECT Rect;
- GetWindowRect(_Window, &Rect);
- return Rect.left;
-}
-
-int BS_Win32Window::GetY()
-{
- RECT Rect;
- GetWindowRect(_Window, &Rect);
- return Rect.top;
-}
-
-int BS_Win32Window::GetClientX()
-{
- POINT Point = {0, 0};
- ClientToScreen(_Window, &Point);
- return Point.x;
-}
-
-int BS_Win32Window::GetClientY()
-{
- POINT Point = {0, 0};
- ClientToScreen(_Window, &Point);
- return Point.y;
-}
-
-int BS_Win32Window::GetWidth()
-{
- RECT Rect;
- GetClientRect(_Window, &Rect);
- return Rect.right - Rect.left;
-}
-
-int BS_Win32Window::GetHeight()
-{
- RECT Rect;
- GetClientRect(_Window, &Rect);
- return Rect.bottom - Rect.top;
-}
-
-std::string BS_Win32Window::GetTitle()
-{
- char String[512];
- if (GetWindowText(_Window, String, sizeof(String)))
- return std::string(String);
-
- return std::string("");
-}
-
-bool BS_Win32Window::IsVisible()
-{
- return IsWindowVisible(_Window) ? true : false;
-}
-
-bool BS_Win32Window::HasFocus()
-{
- return GetForegroundWindow() == _Window ? true : false;
-}
-
-UINT BS_Win32Window::GetWindowHandle()
-{
- return (UINT)_Window;
-}
-
-// Set Methoden
-// ------------
-
-void BS_Win32Window::SetX(int X)
-{
- int RealX;
- if (X == -1)
- {
- RECT Rect;
- GetWindowRect(_Window, &Rect);
- RealX = (GetSystemMetrics(SM_CXSCREEN) - (Rect.right - Rect.left)) / 2;
- }
- else
- RealX = X;
-
- SetWindowPos(_Window, NULL, RealX, GetY(), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
-}
-
-void BS_Win32Window::SetY(int Y)
-{
- int RealY;
- if (Y == -1)
- {
- RECT Rect;
- GetWindowRect(_Window, &Rect);
- RealY = (GetSystemMetrics(SM_CYSCREEN) - (Rect.bottom - Rect.top)) / 2;
- }
- else
- RealY = Y;
-
- SetWindowPos(_Window, NULL, GetX(), RealY, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
-}
-
-void BS_Win32Window::SetWidth(int Width)
-{
- RECT Rect = {0, 0, Width, GetHeight()};
- AdjustWindowRectEx(&Rect, WINDOW_STYLE, false, WINDOW_STYLE_EX);
- SetWindowPos(_Window, NULL, 0, 0, Rect.right - Rect.left, Rect.bottom - Rect.top, SWP_NOMOVE | SWP_NOZORDER);
-}
-
-void BS_Win32Window::SetHeight(int Height)
-{
- RECT Rect = {0, 0, GetWidth(), Height};
- AdjustWindowRectEx(&Rect, WINDOW_STYLE, false, WINDOW_STYLE_EX);
- SetWindowPos(_Window, NULL, 0, 0, Rect.right - Rect.left, Rect.bottom - Rect.top, SWP_NOMOVE | SWP_NOZORDER);
-}
-
-void BS_Win32Window::SetVisible(bool Visible)
-{
- ShowWindow(_Window, Visible ? SW_SHOW : SW_HIDE);
-}
-
-void BS_Win32Window::SetTitle(std::string Title)
-{
- SetWindowText(_Window, Title.c_str());
-}
-
-// Asynchroner Message-Loop
-bool BS_Win32Window::ProcessMessages()
-{
- for (UINT i = 0; i < WINDOW_MAX_MESSAGES; i++)
- {
- MSG msg;
- if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
- {
- if (msg.message == WM_QUIT)
- {
- _WindowAlive = false;
- return false;
- }
-
- // Alle Nachrichten zur Verarbeitung durch WindowProc vorbereiten
- TranslateMessage(&msg);
- // Nachricht an WindowProc übergeben
- DispatchMessage(&msg);
- }
- else
- return true;
- }
-
- return true;
-}
-
-// Synchroner Message-Loop
-bool BS_Win32Window::WaitForFocus()
-{
- MSG msg;
-
- // Fenster minimieren
- ShowWindow(_Window, SW_MINIMIZE);
-
- for (;;)
- {
- // Auf Nachricht warten
- WaitMessage();
- // Nachricht einlesen
- GetMessage(&msg, NULL, 0, 0);
- // Nachricht zur Verarbeitung durch WindowProc vorbereiten
- TranslateMessage(&msg);
- // Nachricht an WindowProc übergeben
- DispatchMessage(&msg);
-
- // Überprüfen ob das Fenster geschlossen wurde
- if (msg.message == WM_QUIT)
- {
- _WindowAlive = false;
- return false;
- }
-
- // Überprüfen, ob das Fenster den Focus wiedererlangt hat
- if (HasFocus()) return true;
- }
-}
-
-// Die WindowProc aller Fenster der Klasse
-LRESULT CALLBACK BS_Win32Window::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- switch(uMsg)
- {
- case WM_PAINT:
- ValidateRect(hwnd, NULL);
- break;
-
- case WM_DESTROY:
- // Das Fenster wird zerstört
- PostQuitMessage(0);
- break;
-
- case WM_CLOSE:
- {
- BS_Window * WindowPtr = BS_Kernel::GetInstance()->GetWindow();
- if (WindowPtr) {
- WindowPtr->SetCloseWanted(true);
- }
- break;
- }
-
- case WM_KEYDOWN:
- {
- // Tastendrücke, die für das Inputmodul interessant sind, werden diesem gemeldet.
- BS_InputEngine * InputPtr = BS_Kernel::GetInstance()->GetInput();
-
- if (InputPtr)
- {
- switch (wParam)
- {
- case VK_RETURN:
- InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_ENTER);
- break;
-
- case VK_LEFT:
- InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_LEFT);
- break;
-
- case VK_RIGHT:
- InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_RIGHT);
- break;
-
- case VK_HOME:
- InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_HOME);
- break;
-
- case VK_END:
- InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_END);
- break;
-
- case VK_BACK:
- InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_BACKSPACE);
- break;
-
- case VK_TAB:
- InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_TAB);
- break;
-
- case VK_INSERT:
- InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_INSERT);
- break;
-
- case VK_DELETE:
- InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_DELETE);
- break;
- }
- }
- break;
- }
-
- case WM_KEYUP:
- case WM_SYSKEYUP:
- // Alle Tastendrücke werden ignoriert, damit Windows per DefWindowProc() nicht darauf
- // reagieren kann und damit unerwartete Seiteneffekte auslöst.
- // Zum Beispiel würden ALT und F10 Tastendrücke das "Menü" aktivieren und somit den Message-Loop zum Stillstand bringen.
- break;
-
- case WM_SYSCOMMAND:
- // Verhindern, dass der Bildschirmschoner aktiviert wird, während das Spiel läuft
- if (wParam != SC_SCREENSAVE) return DefWindowProc(hwnd,uMsg,wParam,lParam);
- break;
-
- case WM_CHAR:
- {
- unsigned char theChar = static_cast<unsigned char>(wParam & 0xff);
-
- // Alle Zeichen, die keine Steuerzeichen sind, werden als Buchstaben dem Input-Service mitgeteilt.
- if (theChar >= 32)
- {
- BS_InputEngine * InputPtr = BS_Kernel::GetInstance()->GetInput();
- if (InputPtr) InputPtr->ReportCharacter(theChar);
- }
- }
- break;
-
- case WM_SETCURSOR:
- {
- // Der Systemcursor wird in der Client-Area des Fensters nicht angezeigt, jedoch in der nicht Client-Area, damit der Benutzer das Fenster wie gewohnt
- // schließen und verschieben kann.
-
- // Koordinaten des Cursors in der Client-Area berechnen.
- POINT pt;
- GetCursorPos(&pt);
- ScreenToClient(hwnd, &pt);
-
- // Feststellen, ob sich der Cursor in der Client-Area befindet.
- // Get client rect
- RECT rc;
- GetClientRect(hwnd, &rc);
-
- // See if cursor is in client area
- if(PtInRect(&rc, pt))
- // In der Client-Area keinen Cursor anzeigen.
- SetCursor(NULL);
- else
- // Ausserhalb der Client-Area den Cursor anzeigen.
- SetCursor(LoadCursor(NULL, IDC_ARROW));
-
- return TRUE;
- }
- break;
-
- default:
- // Um alle anderen Vorkommnisse kümmert sich Windows
- return DefWindowProc(hwnd,uMsg,wParam,lParam);
- }
-
- return 0;
-}
diff --git a/engines/sword25/kernel/window.cpp b/engines/sword25/kernel/window.cpp
index 8ef8f37366..ecafcfa829 100644
--- a/engines/sword25/kernel/window.cpp
+++ b/engines/sword25/kernel/window.cpp
@@ -35,13 +35,14 @@
#include "sword25/kernel/window.h"
// Alle Implementationen von BS_Window müssen hier eingetragen werden
-#include "sword25/kernel/win32window.h"
+#include "sword25/kernel/scummvmwindow.h"
+
+namespace Sword25 {
// Erstellt ein Fenster des GUI des aktuellen Betriebssystems
-BS_Window* BS_Window::CreateBSWindow(int X, int Y, int Width, int Height, bool Visible)
-{
+BS_Window *BS_Window::CreateBSWindow(int X, int Y, int Width, int Height, bool Visible) {
// Fenster erstellen
- BS_Window* pWindow = (BS_Window*) new BS_Win32Window(X, Y, Width, Height, Visible);
+ BS_Window *pWindow = (BS_Window*) new BS_ScummVMWindow(X, Y, Width, Height, Visible);
// Falls das Fenster erfolgreich initialisiert wurde, wird ein Pointer auf das Fensterobjekt
// zurückgegeben
@@ -55,14 +56,14 @@ BS_Window* BS_Window::CreateBSWindow(int X, int Y, int Width, int Height, bool V
// Gibt True zurück wenn das Fenster WM_CLOSE empfangen hat -
// solange, bis RejectClose() aufgerufen wurde.
-bool BS_Window::CloseWanted()
-{
+bool BS_Window::CloseWanted() {
bool result = _CloseWanted;
_CloseWanted = false;
return result;
}
-void BS_Window::SetCloseWanted(bool Wanted)
-{
+void BS_Window::SetCloseWanted(bool Wanted) {
_CloseWanted = Wanted;
}
+
+} // End of namespace Sword25
diff --git a/engines/sword25/kernel/window.h b/engines/sword25/kernel/window.h
index d8ff3feb4d..18b3930dca 100644
--- a/engines/sword25/kernel/window.h
+++ b/engines/sword25/kernel/window.h
@@ -144,8 +144,9 @@ public:
* Returns the system handle that represents the window. Note that any use of the handle
* will not be portable code.
*/
- virtual unsigned int GetWindowHandle() = 0;
+ virtual uint GetWindowHandle() = 0;
+ virtual void SetWindowAlive(bool v) = 0;
/**
* Specifies whether the window is wanted to be closed. This is used together with CloseWanted()
diff --git a/engines/sword25/module.mk b/engines/sword25/module.mk
index f61a86a262..1d79852e36 100644
--- a/engines/sword25/module.mk
+++ b/engines/sword25/module.mk
@@ -49,8 +49,7 @@ MODULE_OBJS := \
kernel/persistenceservice.o \
kernel/resmanager.o \
kernel/resource.o \
- kernel/timer.o \
- kernel/win32window.o \
+ kernel/scummvmwindow.o \
kernel/window.o \
math/geometry.o \
math/geometry_script.o \
diff --git a/engines/sword25/sword25.cpp b/engines/sword25/sword25.cpp
index feaac4adac..07fc302da0 100644
--- a/engines/sword25/sword25.cpp
+++ b/engines/sword25/sword25.cpp
@@ -65,9 +65,10 @@ Sword25Engine::~Sword25Engine() {
Common::Error Sword25Engine::run() {
// Engine initialisation
Common::StringArray commandParameters;
- if (!AppStart(commandParameters)) {
+ Common::Error errorCode = AppStart(commandParameters);
+ if (errorCode != Common::kNoError) {
AppEnd();
- error("A fatal error occured during engine startup");
+ return errorCode;
}
// Run the game
@@ -79,41 +80,47 @@ Common::Error Sword25Engine::run() {
return (RunSuccess && DeinitSuccess) ? Common::kNoError : Common::kUnknownError;
}
-bool Sword25Engine::AppStart(const Common::StringArray &CommandParameters) {
+Common::Error Sword25Engine::AppStart(const Common::StringArray &CommandParameters) {
// All log messages will be sent to StdOut
BS_Log::RegisterLogListener(LogToStdout);
+ // Initialise the graphics mode to RGBA8888
+ Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
+ initGraphics(800, 600, true, &format);
+ if (format != g_system->getScreenFormat())
+ return Common::kUnsupportedColorMode;
+
// Kernel initialisation
if (!BS_Kernel::GetInstance()->GetInitSuccess()) {
BS_LOG_ERRORLN("Kernel initialization failed.");
- return false;
+ return Common::kUnknownError;
}
// Package-Manager starten, damit die Packfiles geladen werden können.
BS_PackageManager *PackageManagerPtr = static_cast<BS_PackageManager *>(BS_Kernel::GetInstance()->NewService("package", PACKAGE_MANAGER));
if (!PackageManagerPtr) {
BS_LOG_ERRORLN("Packagemanager initialization failed.");
- return false;
+ return Common::kUnknownError;
}
// Packages laden oder das aktuelle Verzeichnis mounten, wenn das über Kommandozeile angefordert wurde.
if (find(CommandParameters.begin(), CommandParameters.end(), MOUNT_DIR_PARAMETER) != CommandParameters.end()) {
- if (!PackageManagerPtr->LoadDirectoryAsPackage(".", "/")) return false;
+ if (!PackageManagerPtr->LoadDirectoryAsPackage(".", "/")) return Common::kUnknownError;
} else {
- if (!LoadPackages()) return false;
+ if (!LoadPackages()) return Common::kUnknownError;
}
// Einen Pointer auf den Skript-Engine holen.
BS_ScriptEngine *ScriptPtr = static_cast<BS_ScriptEngine *>(BS_Kernel::GetInstance()->GetService("script"));
if (!ScriptPtr) {
BS_LOG_ERRORLN("Skript intialization failed.");
- return false;
+ return Common::kUnknownError;
}
// Die Kommandozeilen-Parameter der Skriptumgebung zugänglich machen.
ScriptPtr->SetCommandLine(CommandParameters);
- return true;
+ return Common::kNoError;
}
bool Sword25Engine::AppMain() {
diff --git a/engines/sword25/sword25.h b/engines/sword25/sword25.h
index 5b29a750f2..7f10f58368 100644
--- a/engines/sword25/sword25.h
+++ b/engines/sword25/sword25.h
@@ -51,7 +51,7 @@ struct Sword25GameDescription;
class Sword25Engine : public Engine {
private:
- bool AppStart(const Common::StringArray &CommandParameters);
+ Common::Error AppStart(const Common::StringArray &CommandParameters);
bool AppMain();
bool AppEnd();