diff options
Diffstat (limited to 'engines/sword25/kernel')
36 files changed, 717 insertions, 670 deletions
diff --git a/engines/sword25/kernel/bs_stdint.h b/engines/sword25/kernel/bs_stdint.h index c39a219bc9..c1970bff3e 100644 --- a/engines/sword25/kernel/bs_stdint.h +++ b/engines/sword25/kernel/bs_stdint.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer diff --git a/engines/sword25/kernel/callbackregistry.cpp b/engines/sword25/kernel/callbackregistry.cpp index b9b48ed18f..a530159cd7 100644 --- a/engines/sword25/kernel/callbackregistry.cpp +++ b/engines/sword25/kernel/callbackregistry.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -76,7 +76,7 @@ bool BS_CallbackRegistry::RegisterCallbackFunction(const Common::String &Name, C } StoreCallbackFunction(Name, Ptr); - + return true; } diff --git a/engines/sword25/kernel/callbackregistry.h b/engines/sword25/kernel/callbackregistry.h index 72b8135e47..a4ebd03dba 100644 --- a/engines/sword25/kernel/callbackregistry.h +++ b/engines/sword25/kernel/callbackregistry.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -52,28 +52,30 @@ namespace Sword25 { // Klassendeklaration // ----------------------------------------------------------------------------- -typedef void (*CallbackPtr)(int Command); +typedef void (*CallbackPtr)(int Command); class BS_CallbackRegistry { public: - static BS_CallbackRegistry & GetInstance() { + static BS_CallbackRegistry &GetInstance() { static BS_CallbackRegistry Instance; return Instance; } - bool RegisterCallbackFunction(const Common::String &Name, CallbackPtr Ptr); - CallbackPtr ResolveCallbackFunction(const Common::String &Name) const; - Common::String ResolveCallbackPointer(CallbackPtr Ptr) const; + bool RegisterCallbackFunction(const Common::String &Name, CallbackPtr Ptr); + CallbackPtr ResolveCallbackFunction(const Common::String &Name) const; + Common::String ResolveCallbackPointer(CallbackPtr Ptr) const; private: typedef Common::HashMap<Common::String, CallbackPtr, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> NameToPtrMap; NameToPtrMap m_NameToPtrMap; struct CallbackPtr_EqualTo { - bool operator()(CallbackPtr x, CallbackPtr y) const { return x == y; } + bool operator()(CallbackPtr x, CallbackPtr y) const { + return x == y; + } }; struct CallbackPtr_Hash { - uint operator()(CallbackPtr x) const { + uint operator()(CallbackPtr x) const { return static_cast<uint>((int64)x % ((int64)1 << sizeof(uint))); } }; @@ -81,9 +83,9 @@ private: typedef Common::HashMap<CallbackPtr, Common::String, CallbackPtr_Hash, CallbackPtr_EqualTo> PtrToNameMap; PtrToNameMap m_PtrToNameMap; - CallbackPtr FindPtrByName(const Common::String &Name) const; - Common::String FindNameByPtr(CallbackPtr Ptr) const; - void StoreCallbackFunction(const Common::String &Name, CallbackPtr Ptr); + CallbackPtr FindPtrByName(const Common::String &Name) const; + Common::String FindNameByPtr(CallbackPtr Ptr) const; + void StoreCallbackFunction(const Common::String &Name, CallbackPtr Ptr); }; } // End of namespace Sword25 diff --git a/engines/sword25/kernel/common.h b/engines/sword25/kernel/common.h index 93231f1a95..4e272f2591 100644 --- a/engines/sword25/kernel/common.h +++ b/engines/sword25/kernel/common.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -47,10 +47,10 @@ // Global constants #if _DEBUG && !DEBUG - #define DEBUG +#define DEBUG #endif -#define BS_ACTIVATE_LOGGING // When defined, logging is activated +#define BS_ACTIVATE_LOGGING // When defined, logging is activated // Engine Includes #include "sword25/kernel/memleaks.h" diff --git a/engines/sword25/kernel/filesystemutil.cpp b/engines/sword25/kernel/filesystemutil.cpp index 831efc6add..5eddc06bd0 100644 --- a/engines/sword25/kernel/filesystemutil.cpp +++ b/engines/sword25/kernel/filesystemutil.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -78,7 +78,7 @@ public: return ""; } - // Return the path + // Return the path return path; } diff --git a/engines/sword25/kernel/filesystemutil.h b/engines/sword25/kernel/filesystemutil.h index 828ff31922..0fffa72d9f 100644 --- a/engines/sword25/kernel/filesystemutil.h +++ b/engines/sword25/kernel/filesystemutil.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -33,8 +33,8 @@ */ /* - * - * The class BS_FileSystemUtil represents a wrapper for file system specific + * + * The class BS_FileSystemUtil represents a wrapper for file system specific * operations that do not have equivalents in the C/C++ libraries. * * Each supported platform must implement this interface, and the method @@ -69,42 +69,42 @@ public: * This function returns the name of the directory in which all user data is to be stored. * * These are for example Screenshots, game saves, configuration files, log files, ... - * @return Returns the name of the directory for user data. + * @return Returns the name of the directory for user data. */ virtual Common::String GetUserdataDirectory() = 0; /** - * @return Returns the path seperator + * @return Returns the path seperator */ - virtual Common::String GetPathSeparator() = 0; + virtual Common::String GetPathSeparator() = 0; /** - * @param Filename The path to a file. - * @return Returns the size of the specified file. If the size could not be + * @param Filename The path to a file. + * @return Returns the size of the specified file. If the size could not be * determined, or the file does not exist, returns -1 */ virtual int64 GetFileSize(const Common::String &Filename) = 0; /** - * @param Filename The path to a file. - * @return Returns the timestamp of the specified file. + * @param Filename The path to a file. + * @return Returns the timestamp of the specified file. */ virtual TimeDate GetFileTime(const Common::String &Filename) = 0; /** - * @param Filename The path to a file. - * @return Returns true if the file exists. + * @param Filename The path to a file. + * @return Returns true if the file exists. */ virtual bool FileExists(const Common::String &Filename) = 0; /** * This function creates a directory - * + * * If the parameter is "\b\c\d\e" is passed, and "\b\c" already exists, then folder 'd' * will be created, and subdirectory 'e' under it. - * @param DirectoryName The name of the directory to be created - * @return Returns true if the folder(s) could be created, otherwise false. + * @param DirectoryName The name of the directory to be created + * @return Returns true if the folder(s) could be created, otherwise false. */ virtual bool CreateDirectory(const Common::String &DirectoryName) = 0; /** * Creates a list of filenames in a given directory. - * @param Directory The directory to search - * @return Returns a vector containing all of the found filenames + * @param Directory The directory to search + * @return Returns a vector containing all of the found filenames */ virtual Common::StringArray GetFilesInDirectory(const Common::String &Path) = 0; }; diff --git a/engines/sword25/kernel/inputpersistenceblock.cpp b/engines/sword25/kernel/inputpersistenceblock.cpp index 6528d041ad..764cadd373 100644 --- a/engines/sword25/kernel/inputpersistenceblock.cpp +++ b/engines/sword25/kernel/inputpersistenceblock.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -46,9 +46,9 @@ namespace Sword25 { // Constructor / Destructor // ----------------------------------------------------------------------------- -BS_InputPersistenceBlock::BS_InputPersistenceBlock(const void * Data, unsigned int DataLength) : - m_Data(static_cast<const unsigned char *>(Data), DataLength), - m_ErrorState(NONE) { +BS_InputPersistenceBlock::BS_InputPersistenceBlock(const void *Data, unsigned int DataLength) : + m_Data(static_cast<const unsigned char *>(Data), DataLength), + m_ErrorState(NONE) { m_Iter = m_Data.begin(); } @@ -118,7 +118,7 @@ void BS_InputPersistenceBlock::Read(bool &Value) { void BS_InputPersistenceBlock::Read(Common::String &Value) { Value = ""; - + if (CheckMarker(STRING_MARKER)) { unsigned int Size; Read(Size); @@ -146,7 +146,7 @@ void BS_InputPersistenceBlock::Read(Common::Array<unsigned char> &Value) { // ----------------------------------------------------------------------------- -void BS_InputPersistenceBlock::RawRead(void * DestPtr, size_t Size) { +void BS_InputPersistenceBlock::RawRead(void *DestPtr, size_t Size) { if (CheckBlockSize(Size)) { memcpy(DestPtr, &*m_Iter, Size); m_Iter += Size; diff --git a/engines/sword25/kernel/inputpersistenceblock.h b/engines/sword25/kernel/inputpersistenceblock.h index 0e8e3bf5e6..0bd50bbeb1 100644 --- a/engines/sword25/kernel/inputpersistenceblock.h +++ b/engines/sword25/kernel/inputpersistenceblock.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -32,7 +32,7 @@ * */ -#ifndef SWORD25_INPUTPERSISTENCEBLOCK_H +#ifndef SWORD25_INPUTPERSISTENCEBLOCK_H #define SWORD25_INPUTPERSISTENCEBLOCK_H // ----------------------------------------------------------------------------- @@ -68,8 +68,12 @@ public: void Read(Common::String &Value); void Read(Common::Array<unsigned char> &Value); - bool IsGood() const { return m_ErrorState == NONE; } - ErrorState GetErrorState() const { return m_ErrorState; } + bool IsGood() const { + return m_ErrorState == NONE; + } + ErrorState GetErrorState() const { + return m_ErrorState; + } private: bool CheckMarker(unsigned char Marker); diff --git a/engines/sword25/kernel/kernel.cpp b/engines/sword25/kernel/kernel.cpp index 8275db67f7..6348ca0f63 100644 --- a/engines/sword25/kernel/kernel.cpp +++ b/engines/sword25/kernel/kernel.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -54,7 +54,7 @@ BS_Kernel::BS_Kernel() : _Running(false), _pResourceManager(NULL), _InitSuccess(false) { - + // Log that the kernel is beign created BS_LOGLN("created."); @@ -115,7 +115,7 @@ BS_Kernel::~BS_Kernel() { delete _SuperclassList.back(); _SuperclassList.pop_back(); } - + // Release the window object delete _pWindow; BS_LOGLN("Window destroyed."); @@ -129,12 +129,11 @@ BS_Kernel::~BS_Kernel() { // Service Methoden // ---------------- -BS_Kernel::Superclass::Superclass (BS_Kernel* pKernel, const Common::String& Identifier) : +BS_Kernel::Superclass::Superclass(BS_Kernel *pKernel, const Common::String &Identifier) : _pKernel(pKernel), - _Identifier(Identifier), - _ServiceCount(0), - _ActiveService(NULL) -{ + _Identifier(Identifier), + _ServiceCount(0), + _ActiveService(NULL) { for (unsigned int i = 0; i < BS_SERVICE_COUNT; i++) if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier) _ServiceCount++; @@ -147,15 +146,15 @@ BS_Kernel::Superclass::~Superclass() { /** * Gets the identifier of a service with a given superclass. * The number of services in a superclass can be learned with GetServiceCount(). - * @param SuperclassIdentifier The name of the superclass - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentifier The name of the superclass + * z.B: "sfx", "gfx", "package" ... * @param Number die Nummer des Services, dessen Bezeichner man erfahren will.<br> - * Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen - * 0 und GetServiceCount() - 1 sein. + * Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen + * 0 und GetServiceCount() - 1 sein. */ Common::String BS_Kernel::Superclass::GetServiceIdentifier(unsigned int Number) { if (Number > _ServiceCount) return NULL; - + unsigned int CurServiceOrd = 0; for (unsigned int i = 0; i < BS_SERVICE_COUNT; i++) { if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier) @@ -169,31 +168,27 @@ Common::String BS_Kernel::Superclass::GetServiceIdentifier(unsigned int Number) } /** - * Creates a new service with the given identifier. Returns a pointer to the service, or null if the + * Creates a new service with the given identifier. Returns a pointer to the service, or null if the * service could not be created * Note: All services must be registered in service_ids.h, otherwise they cannot be created here - * @param SuperclassIdentifier The name of the superclass of the service - * z.B: "sfx", "gfx", "package" ... - * @param ServiceIdentifier The name of the service - * For the superclass "sfx" an example could be "Fmod" or "directsound" + * @param SuperclassIdentifier The name of the superclass of the service + * z.B: "sfx", "gfx", "package" ... + * @param ServiceIdentifier The name of the service + * For the superclass "sfx" an example could be "Fmod" or "directsound" */ BS_Service *BS_Kernel::Superclass::NewService(const Common::String &ServiceIdentifier) { for (unsigned int i = 0; i < BS_SERVICE_COUNT; i++) if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier && - BS_SERVICE_TABLE[i].ServiceIdentifier == ServiceIdentifier) - { - BS_Service* NewService = BS_SERVICE_TABLE[i].CreateMethod(_pKernel); - - if (NewService) - { + BS_SERVICE_TABLE[i].ServiceIdentifier == ServiceIdentifier) { + BS_Service *NewService = BS_SERVICE_TABLE[i].CreateMethod(_pKernel); + + if (NewService) { DisconnectService(); BS_LOGLN("Service '%s' created from superclass '%s'.", ServiceIdentifier.c_str(), _Identifier.c_str()); _ActiveService = NewService; _ActiveServiceName = BS_SERVICE_TABLE[i].ServiceIdentifier; return _ActiveService; - } - else - { + } else { BS_LOG_ERRORLN("Failed to create service '%s' from superclass '%s'.", ServiceIdentifier.c_str(), _Identifier.c_str()); return NULL; } @@ -204,10 +199,10 @@ BS_Service *BS_Kernel::Superclass::NewService(const Common::String &ServiceIdent } /** - * Ends the current service of a superclass. Returns true on success, and false if the superclass + * Ends the current service of a superclass. Returns true on success, and false if the superclass * does not exist or if not service was active - * @param SuperclassIdentfier The name of the superclass which is to be disconnected - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentfier The name of the superclass which is to be disconnected + * z.B: "sfx", "gfx", "package" ... */ bool BS_Kernel::Superclass::DisconnectService() { if (_ActiveService) { @@ -221,7 +216,7 @@ bool BS_Kernel::Superclass::DisconnectService() { } BS_Kernel::Superclass *BS_Kernel::GetSuperclassByIdentifier(const Common::String &Identifier) { - Common::Array<Superclass*>::iterator Iter; + Common::Array<Superclass *>::iterator Iter; for (Iter = _SuperclassList.begin(); Iter != _SuperclassList.end(); ++Iter) { if ((*Iter)->GetIdentifier() == Identifier) return *Iter; @@ -241,32 +236,32 @@ unsigned int BS_Kernel::GetSuperclassCount() { /** * Returns the name of a superclass with the specified index. * Note: The number of superclasses can be retrieved using GetSuperclassCount - * @param Number The number of the superclass to return the identifier for. + * @param Number The number of the superclass to return the identifier for. * It should be noted that the number should be between 0 und GetSuperclassCount() - 1. */ Common::String BS_Kernel::GetSuperclassIdentifier(unsigned int Number) { if (Number > _SuperclassList.size()) return NULL; - + unsigned int CurSuperclassOrd = 0; - Common::Array<Superclass*>::iterator Iter; + Common::Array<Superclass *>::iterator Iter; for (Iter = _SuperclassList.begin(); Iter != _SuperclassList.end(); ++Iter) { if (CurSuperclassOrd == Number) return ((*Iter)->GetIdentifier()); - + CurSuperclassOrd++; } - + return Common::String(""); } /** * Returns the number of services registered with a given superclass - * @param SuperclassIdentifier The name of the superclass - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentifier The name of the superclass + * z.B: "sfx", "gfx", "package" ... */ -unsigned int BS_Kernel::GetServiceCount(const Common::String & SuperclassIdentifier) { +unsigned int BS_Kernel::GetServiceCount(const Common::String &SuperclassIdentifier) { Superclass *pSuperclass; - if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) + if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return 0; return pSuperclass->GetServiceCount(); @@ -276,29 +271,29 @@ unsigned int BS_Kernel::GetServiceCount(const Common::String & SuperclassIdentif /** * Gets the identifier of a service with a given superclass. * The number of services in a superclass can be learned with GetServiceCount(). - * @param SuperclassIdentifier The name of the superclass - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentifier The name of the superclass + * z.B: "sfx", "gfx", "package" ... * @param Number die Nummer des Services, dessen Bezeichner man erfahren will.<br> - * Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen - * 0 und GetServiceCount() - 1 sein. + * Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen + * 0 und GetServiceCount() - 1 sein. */ -Common::String BS_Kernel::GetServiceIdentifier(const Common::String & SuperclassIdentifier, unsigned int Number) { - Superclass* pSuperclass; +Common::String BS_Kernel::GetServiceIdentifier(const Common::String &SuperclassIdentifier, unsigned int Number) { + Superclass *pSuperclass; if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL; - return (pSuperclass->GetServiceIdentifier(Number)); + return (pSuperclass->GetServiceIdentifier(Number)); } /** - * Creates a new service with the given identifier. Returns a pointer to the service, or null if the + * Creates a new service with the given identifier. Returns a pointer to the service, or null if the * service could not be created * Note: All services must be registered in service_ids.h, otherwise they cannot be created here - * @param SuperclassIdentifier The name of the superclass of the service - * z.B: "sfx", "gfx", "package" ... - * @param ServiceIdentifier The name of the service - * For the superclass "sfx" an example could be "Fmod" or "directsound" + * @param SuperclassIdentifier The name of the superclass of the service + * z.B: "sfx", "gfx", "package" ... + * @param ServiceIdentifier The name of the service + * For the superclass "sfx" an example could be "Fmod" or "directsound" */ -BS_Service *BS_Kernel::NewService(const Common::String& SuperclassIdentifier, const Common::String& ServiceIdentifier) { +BS_Service *BS_Kernel::NewService(const Common::String &SuperclassIdentifier, const Common::String &ServiceIdentifier) { Superclass *pSuperclass; if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL; @@ -309,12 +304,12 @@ BS_Service *BS_Kernel::NewService(const Common::String& SuperclassIdentifier, co } /** - * Ends the current service of a superclass. Returns true on success, and false if the superclass + * Ends the current service of a superclass. Returns true on success, and false if the superclass * does not exist or if not service was active - * @param SuperclassIdentfier The name of the superclass which is to be disconnected - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentfier The name of the superclass which is to be disconnected + * z.B: "sfx", "gfx", "package" ... */ -bool BS_Kernel::DisconnectService(const Common::String& SuperclassIdentifier) { +bool BS_Kernel::DisconnectService(const Common::String &SuperclassIdentifier) { Superclass *pSuperclass; if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return false; @@ -323,10 +318,10 @@ bool BS_Kernel::DisconnectService(const Common::String& SuperclassIdentifier) { /** * Returns a pointer to the currently active service object of a superclass - * @param SuperclassIdentfier The name of the superclass - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentfier The name of the superclass + * z.B: "sfx", "gfx", "package" ... */ -BS_Service *BS_Kernel::GetService(const Common::String& SuperclassIdentifier) { +BS_Service *BS_Kernel::GetService(const Common::String &SuperclassIdentifier) { Superclass *pSuperclass; if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL; @@ -336,11 +331,11 @@ BS_Service *BS_Kernel::GetService(const Common::String& SuperclassIdentifier) { /** * Returns the name of the currentl active service object of a superclass. * If an error occurs, then an empty string is returned - * @param SuperclassIdentfier The name of the superclass - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentfier The name of the superclass + * z.B: "sfx", "gfx", "package" ... */ -Common::String BS_Kernel::GetActiveServiceIdentifier(const Common::String& SuperclassIdentifier) { - Superclass * pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier); +Common::String BS_Kernel::GetActiveServiceIdentifier(const Common::String &SuperclassIdentifier) { + Superclass *pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier); if (!pSuperclass) return Common::String(""); return (pSuperclass->GetActiveServiceName()); @@ -350,8 +345,8 @@ Common::String BS_Kernel::GetActiveServiceIdentifier(const Common::String& Super /** * Returns a random number - * @param Min The minimum allowed value - * @param Max The maximum allowed value + * @param Min The minimum allowed value + * @param Max The maximum allowed value */ int BS_Kernel::GetRandomNumber(int Min, int Max) { BS_ASSERT(Min <= Max); @@ -386,12 +381,9 @@ size_t BS_Kernel::GetUsedMemory() { #ifdef SCUMMVM_DISABLED_CODE PROCESS_MEMORY_COUNTERS pmc; pmc.cb = sizeof(pmc); - if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) - { + if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) { return pmc.WorkingSetSize; - } - else - { + } else { BS_LOG_ERRORLN("Call to GetProcessMemoryInfo() failed. Error code: %d", GetLastError()); return 0; } @@ -403,7 +395,7 @@ size_t BS_Kernel::GetUsedMemory() { /** * Returns a pointer to the active Gfx Service, or NULL if no Gfx service is active */ -BS_GraphicEngine * BS_Kernel::GetGfx() { +BS_GraphicEngine *BS_Kernel::GetGfx() { return static_cast<BS_GraphicEngine *>(GetService("gfx")); } @@ -412,7 +404,7 @@ BS_GraphicEngine * BS_Kernel::GetGfx() { /** * Returns a pointer to the active Sfx Service, or NULL if no Sfx service is active */ -BS_SoundEngine * BS_Kernel::GetSfx() { +BS_SoundEngine *BS_Kernel::GetSfx() { return static_cast<BS_SoundEngine *>(GetService("sfx")); } @@ -421,7 +413,7 @@ BS_SoundEngine * BS_Kernel::GetSfx() { /** * Returns a pointer to the active input service, or NULL if no input service is active */ -BS_InputEngine * BS_Kernel::GetInput() { +BS_InputEngine *BS_Kernel::GetInput() { return static_cast<BS_InputEngine *>(GetService("input")); } @@ -430,7 +422,7 @@ BS_InputEngine * BS_Kernel::GetInput() { /** * Returns a pointer to the active package manager, or NULL if no manager is active */ -BS_PackageManager * BS_Kernel::GetPackage() { +BS_PackageManager *BS_Kernel::GetPackage() { return static_cast<BS_PackageManager *>(GetService("package")); } @@ -439,7 +431,7 @@ BS_PackageManager * BS_Kernel::GetPackage() { /** * Returns a pointer to the script engine, or NULL if it is not active */ -BS_ScriptEngine * BS_Kernel::GetScript() { +BS_ScriptEngine *BS_Kernel::GetScript() { return static_cast<BS_ScriptEngine *>(GetService("script")); } @@ -448,7 +440,7 @@ BS_ScriptEngine * BS_Kernel::GetScript() { /** * Returns a pointer to the movie player, or NULL if it is not active */ -BS_MoviePlayer * BS_Kernel::GetFMV() { +BS_MoviePlayer *BS_Kernel::GetFMV() { return static_cast<BS_MoviePlayer *>(GetService("fmv")); } diff --git a/engines/sword25/kernel/kernel.h b/engines/sword25/kernel/kernel.h index d09cf68ab6..b610c0caab 100644 --- a/engines/sword25/kernel/kernel.h +++ b/engines/sword25/kernel/kernel.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -71,7 +71,7 @@ class BS_MoviePlayer; /** * This is the main engine class * - * This class creates and manages all other engine components such as sound engine, graphics engine ... + * This class creates and manages all other engine components such as sound engine, graphics engine ... * It is not necessary to release all the items individually, this is performed by the Kernel class. */ class BS_Kernel { @@ -82,42 +82,44 @@ public: /** * Returns a pointer to the window object */ - BS_Window *GetWindow() { return _pWindow; } + BS_Window *GetWindow() { + return _pWindow; + } // Service Methods // --------------- /** - * Creates a new service with the given identifier. Returns a pointer to the service, or null if the + * Creates a new service with the given identifier. Returns a pointer to the service, or null if the * service could not be created - * Note: All services must be registered in service_ids.h, otherwise they cannot be created here - * @param SuperclassIdentifier The name of the superclass of the service - * z.B: "sfx", "gfx", "package" ... - * @param ServiceIdentifier The name of the service - * For the superclass "sfx" an example could be "Fmod" or "directsound" + * Note: All services must be registered in service_ids.h, otherwise they cannot be created here + * @param SuperclassIdentifier The name of the superclass of the service + * z.B: "sfx", "gfx", "package" ... + * @param ServiceIdentifier The name of the service + * For the superclass "sfx" an example could be "Fmod" or "directsound" */ BS_Service *NewService(const Common::String &SuperclassIdentifier, const Common::String &ServiceIdentifier); /** - * Ends the current service of a superclass. Returns true on success, and false if the superclass + * Ends the current service of a superclass. Returns true on success, and false if the superclass * does not exist or if not service was active - * @param SuperclassIdentfier The name of the superclass which is to be disconnected - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentfier The name of the superclass which is to be disconnected + * z.B: "sfx", "gfx", "package" ... */ bool DisconnectService(const Common::String &SuperclassIdentifier); /** * Returns a pointer to the currently active service object of a superclass - * @param SuperclassIdentfier The name of the superclass - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentfier The name of the superclass + * z.B: "sfx", "gfx", "package" ... */ BS_Service *GetService(const Common::String &SuperclassIdentifier); /** * Returns the name of the currentl active service object of a superclass. * If an error occurs, then an empty string is returned - * @param SuperclassIdentfier The name of the superclass - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentfier The name of the superclass + * z.B: "sfx", "gfx", "package" ... */ Common::String GetActiveServiceIdentifier(const Common::String &SuperclassIdentifier); @@ -129,26 +131,26 @@ public: /** * Returns the name of a superclass with the specified index. * Note: The number of superclasses can be retrieved using GetSuperclassCount - * @param Number The number of the superclass to return the identifier for. + * @param Number The number of the superclass to return the identifier for. * It should be noted that the number should be between 0 und GetSuperclassCount() - 1. */ Common::String GetSuperclassIdentifier(unsigned int Number); /** * Returns the number of services registered with a given superclass - * @param SuperclassIdentifier The name of the superclass - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentifier The name of the superclass + * z.B: "sfx", "gfx", "package" ... */ - unsigned int GetServiceCount(const Common::String & SuperclassIdentifier); + unsigned int GetServiceCount(const Common::String &SuperclassIdentifier); /** * Gets the identifier of a service with a given superclass. * The number of services in a superclass can be learned with GetServiceCount(). - * @param SuperclassIdentifier The name of the superclass - * z.B: "sfx", "gfx", "package" ... + * @param SuperclassIdentifier The name of the superclass + * z.B: "sfx", "gfx", "package" ... * @param Number die Nummer des Services, dessen Bezeichner man erfahren will.<br> - * Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen - * 0 und GetServiceCount() - 1 sein. + * Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen + * 0 und GetServiceCount() - 1 sein. */ Common::String GetServiceIdentifier(const Common::String &SuperclassIdentifier, unsigned int Number); @@ -166,19 +168,23 @@ public: /** * Specifies whether the kernel was successfully initialised */ - bool GetInitSuccess() { return _InitSuccess; } + bool GetInitSuccess() { + return _InitSuccess; + } /** * Returns a pointer to the BS_ResourceManager */ - BS_ResourceManager *GetResourceManager() { return _pResourceManager; } + BS_ResourceManager *GetResourceManager() { + return _pResourceManager; + } /** * Returns how much memory is being used */ size_t GetUsedMemory(); /** * Returns a random number - * @param Min The minimum allowed value - * @param Max The maximum allowed value + * @param Min The minimum allowed value + * @param Max The maximum allowed value */ int GetRandomNumber(int Min, int Max); /** @@ -208,14 +214,14 @@ public: /** * Pauses for the specified amount of time - * @param Msecs The amount of time in milliseconds + * @param Msecs The amount of time in milliseconds */ void Sleep(unsigned int Msecs) const; /** * Returns the singleton instance for the kernel */ - static BS_Kernel *GetInstance() { + static BS_Kernel *GetInstance() { if (!_Instance) _Instance = new BS_Kernel(); return _Instance; } @@ -238,13 +244,13 @@ public: void Crash() const { error("BS_Kernel::Crash"); } - + private: // ----------------------------------------------------------------------------- // Constructor / destructor // Private singleton methods // ----------------------------------------------------------------------------- - + BS_Kernel(); virtual ~BS_Kernel(); @@ -262,27 +268,35 @@ private: Common::String _Identifier; BS_Service *_ActiveService; Common::String _ActiveServiceName; - + public: - Superclass (BS_Kernel *pKernel, const Common::String &Identifier); + Superclass(BS_Kernel *pKernel, const Common::String &Identifier); ~Superclass(); - - unsigned int GetServiceCount() const { return _ServiceCount; } - Common::String GetIdentifier() const { return _Identifier; } - BS_Service *GetActiveService() const { return _ActiveService; } - Common::String GetActiveServiceName() const { return _ActiveServiceName; } + + unsigned int GetServiceCount() const { + return _ServiceCount; + } + Common::String GetIdentifier() const { + return _Identifier; + } + BS_Service *GetActiveService() const { + return _ActiveService; + } + Common::String GetActiveServiceName() const { + return _ActiveServiceName; + } Common::String GetServiceIdentifier(unsigned int Number); BS_Service *NewService(const Common::String &ServiceIdentifier); bool DisconnectService(); }; - - Common::Array<Superclass*> _SuperclassList; - Common::Stack<Common::String> _ServiceCreationOrder; + + Common::Array<Superclass *> _SuperclassList; + Common::Stack<Common::String> _ServiceCreationOrder; Superclass *GetSuperclassByIdentifier(const Common::String &Identifier); - + bool _InitSuccess; // Specifies whether the engine was set up correctly - bool _Running; // Specifies whether the application should keep running on the next main loop iteration - + bool _Running; // Specifies whether the application should keep running on the next main loop iteration + // Active window // ------------- BS_Window *_pWindow; @@ -296,22 +310,22 @@ private: // ---------------------------------- enum _CPU_FEATURES_BITMASKS { - _MMX_BITMASK = (1 << 23), - _SSE_BITMASK = (1 << 25), - _SSE2_BITMASK = (1 << 26), - _3DNOW_BITMASK = (1 << 30), - _3DNOWEXT_BITMASK = (1 << 31) + _MMX_BITMASK = (1 << 23), + _SSE_BITMASK = (1 << 25), + _SSE2_BITMASK = (1 << 26), + _3DNOW_BITMASK = (1 << 30), + _3DNOWEXT_BITMASK = (1 << 31) }; - bool _DetectCPU(); + bool _DetectCPU(); - bool _MMXPresent; - bool _SSEPresent; - bool _SSE2Present; - bool _3DNowPresent; - bool _3DNowExtPresent; - CPU_TYPES _CPUType; - Common::String _CPUVendorID; + bool _MMXPresent; + bool _SSEPresent; + bool _SSE2Present; + bool _3DNowPresent; + bool _3DNowExtPresent; + CPU_TYPES _CPUType; + Common::String _CPUVendorID; */ // Resourcemanager @@ -322,21 +336,21 @@ private: }; /** - * This is only a small class that manages the data of a service. It is a little ugly, I know, + * This is only a small class that manages the data of a service. It is a little ugly, I know, * but with Common::String a simple struct could not be used. */ class BS_ServiceInfo { public: - BS_ServiceInfo(const Common::String &SuperclassIdentifier_, const Common::String& ServiceIdentifier_, - BS_Service* (*CreateMethod_)(BS_Kernel*)) { + BS_ServiceInfo(const Common::String &SuperclassIdentifier_, const Common::String &ServiceIdentifier_, + BS_Service*(*CreateMethod_)(BS_Kernel *)) { this->SuperclassIdentifier = SuperclassIdentifier_; this->ServiceIdentifier = ServiceIdentifier_; this->CreateMethod = CreateMethod_; }; - - Common::String SuperclassIdentifier; - Common::String ServiceIdentifier; - BS_Service* (*CreateMethod)(BS_Kernel *); + + Common::String SuperclassIdentifier; + Common::String ServiceIdentifier; + BS_Service*(*CreateMethod)(BS_Kernel *); }; template<class T> diff --git a/engines/sword25/kernel/kernel_script.cpp b/engines/sword25/kernel/kernel_script.cpp index f26a8a4f33..11caaf9d79 100644 --- a/engines/sword25/kernel/kernel_script.cpp +++ b/engines/sword25/kernel/kernel_script.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -64,7 +64,7 @@ static int GetActiveServiceIdentifier(lua_State *L) { BS_Kernel *pKernel = BS_Kernel::GetInstance(); BS_ASSERT(pKernel); - lua_pushstring(L, pKernel->GetActiveServiceIdentifier(luaL_checkstring(L,1)).c_str()); + lua_pushstring(L, pKernel->GetActiveServiceIdentifier(luaL_checkstring(L, 1)).c_str()); return 1; } @@ -87,7 +87,7 @@ static int GetSuperclassIdentifier(lua_State *L) { BS_ASSERT(pKernel); lua_pushstring(L, pKernel->GetSuperclassIdentifier( - static_cast<unsigned int>(luaL_checknumber(L,1))).c_str()); + static_cast<unsigned int>(luaL_checknumber(L, 1))).c_str()); return 1; } @@ -109,8 +109,8 @@ static int GetServiceIdentifier(lua_State *L) { BS_Kernel *pKernel = BS_Kernel::GetInstance(); BS_ASSERT(pKernel); - lua_pushstring(L, pKernel->GetServiceIdentifier(luaL_checkstring(L, 1), - static_cast<unsigned int>(luaL_checknumber(L, 2))).c_str()); + lua_pushstring(L, pKernel->GetServiceIdentifier(luaL_checkstring(L, 1), + static_cast<unsigned int>(luaL_checknumber(L, 2))).c_str()); return 1; } @@ -171,7 +171,7 @@ static int Crash(lua_State *L) { static int ExecuteFile(lua_State *L) { BS_Kernel *pKernel = BS_Kernel::GetInstance(); BS_ASSERT(pKernel); - BS_ScriptEngine * pSE = static_cast<BS_ScriptEngine *>(pKernel->GetService("script")); + BS_ScriptEngine *pSE = static_cast<BS_ScriptEngine *>(pKernel->GetService("script")); BS_ASSERT(pSE); lua_pushbooleancpp(L, pSE->ExecuteFile(luaL_checkstring(L, 1))); @@ -231,7 +231,7 @@ static int GetUsedMemory(lua_State *L) { // ----------------------------------------------------------------------------- -static const char * KERNEL_LIBRARY_NAME = "Kernel"; +static const char *KERNEL_LIBRARY_NAME = "Kernel"; static const luaL_reg KERNEL_FUNCTIONS[] = { "DisconnectService", DisconnectService, @@ -492,7 +492,7 @@ static int HasFocus(lua_State *L) { // ----------------------------------------------------------------------------- -static const char * WINDOW_LIBRARY_NAME = "Window"; +static const char *WINDOW_LIBRARY_NAME = "Window"; static const luaL_reg WINDOW_FUNCTIONS[] = { "IsVisible", IsVisible, @@ -622,7 +622,7 @@ static int DumpLockedResources(lua_State *L) { // ----------------------------------------------------------------------------- -static const char * RESOURCE_LIBRARY_NAME = "Resource"; +static const char *RESOURCE_LIBRARY_NAME = "Resource"; static const luaL_reg RESOURCE_FUNCTIONS[] = { "PrecacheResource", PrecacheResource, @@ -655,7 +655,7 @@ static int GetSlotCount(lua_State *L) { static int IsSlotOccupied(lua_State *L) { lua_pushbooleancpp(L, BS_PersistenceService::GetInstance().IsSlotOccupied( - static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1)); + static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1)); return 1; } @@ -670,7 +670,7 @@ static int GetSavegameDirectory(lua_State *L) { static int IsSavegameCompatible(lua_State *L) { lua_pushbooleancpp(L, BS_PersistenceService::GetInstance().IsSavegameCompatible( - static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1)); + static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1)); return 1; } @@ -678,7 +678,7 @@ static int IsSavegameCompatible(lua_State *L) { static int GetSavegameDescription(lua_State *L) { lua_pushstring(L, BS_PersistenceService::GetInstance().GetSavegameDescription( - static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1).c_str()); + static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1).c_str()); return 1; } @@ -705,7 +705,7 @@ static int SaveGame(lua_State *L) { // ----------------------------------------------------------------------------- -static const char * PERSISTENCE_LIBRARY_NAME = "Persistence"; +static const char *PERSISTENCE_LIBRARY_NAME = "Persistence"; static const luaL_reg PERSISTENCE_FUNCTIONS[] = { "ReloadSlots", ReloadSlots, @@ -723,7 +723,7 @@ static const luaL_reg PERSISTENCE_FUNCTIONS[] = { // ----------------------------------------------------------------------------- bool BS_Kernel::_RegisterScriptBindings() { - BS_ScriptEngine * pScript = static_cast<BS_ScriptEngine *>(GetService("script")); + BS_ScriptEngine *pScript = static_cast<BS_ScriptEngine *>(GetService("script")); BS_ASSERT(pScript); lua_State *L = static_cast<lua_State *>(pScript->GetScriptObject()); BS_ASSERT(L); diff --git a/engines/sword25/kernel/log.cpp b/engines/sword25/kernel/log.cpp index 36a17115d3..07c57e9931 100644 --- a/engines/sword25/kernel/log.cpp +++ b/engines/sword25/kernel/log.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -41,18 +41,18 @@ namespace Sword25 { // Constants static const char *BF_LOG_FILENAME = "log.txt"; -static const size_t LOG_BUFFERSIZE = 1024 * 16; +static const size_t LOG_BUFFERSIZE = 1024 * 16; // Logging will take place only when it's activated #ifdef BS_ACTIVATE_LOGGING -Common::WriteStream* BS_Log::_LogFile = NULL; -bool BS_Log::_LineBegin = true; -const char * BS_Log::_Prefix = NULL; -const char * BS_Log::_File = NULL; -int BS_Log::_Line = 0; -bool BS_Log::_AutoNewline = false; -Common::Array<BS_Log::LOG_LISTENER_CALLBACK> BS_Log::_LogListener; +Common::WriteStream *BS_Log::_LogFile = NULL; +bool BS_Log::_LineBegin = true; +const char *BS_Log::_Prefix = NULL; +const char *BS_Log::_File = NULL; +int BS_Log::_Line = 0; +bool BS_Log::_AutoNewline = false; +Common::Array<BS_Log::LOG_LISTENER_CALLBACK> BS_Log::_LogListener; bool BS_Log::_CreateLog() { // Open the log file @@ -109,7 +109,7 @@ void BS_Log::LogPrefix(const char *Prefix, const char *Format, ...) { if (!NextLine || *(NextLine + strlen("\n")) == 0) { _snprintf(ExtFormat, sizeof(ExtFormat), "%s%s", ExtFormat, Format); if (NextLine) _LineBegin = true; - break; + break; } else { strncat(ExtFormat, Format, (NextLine - Format) + strlen("\n")); _snprintf(ExtFormat, sizeof(ExtFormat), "%s%s: ", ExtFormat, Prefix); @@ -117,7 +117,7 @@ void BS_Log::LogPrefix(const char *Prefix, const char *Format, ...) { Format = NextLine + strlen("\n"); } - + // Create message va_list ArgList; va_start(ArgList, Format); @@ -140,7 +140,7 @@ void BS_Log::LogDecorated(const char *Format, ...) { char SecondaryPrefix[1024]; if (_File && _Line) _snprintf(SecondaryPrefix, sizeof(SecondaryPrefix), "(file: %s, line: %d) - ", _File, _Line); - + // Nachricht zeilenweise ausgeben und an jeden Zeilenanfang das Präfix setzen char *MessageWalker = Message; for (;;) { @@ -183,7 +183,7 @@ void BS_Log::LogDecorated(const char *Format, ...) { _FlushLog(); } -int BS_Log::_WriteLog(const char * Message) { +int BS_Log::_WriteLog(const char *Message) { if (!_LogFile) if (!_CreateLog()) return false; Common::Array<LOG_LISTENER_CALLBACK>::iterator Iter = _LogListener.begin(); @@ -207,7 +207,7 @@ void BS_Log_C(const char *Message) { #else -void BS_Log_C(const char* Message) {}; +void BS_Log_C(const char *Message) {}; #endif diff --git a/engines/sword25/kernel/log.h b/engines/sword25/kernel/log.h index 1c158cfa7b..1fe9ff4ed6 100644 --- a/engines/sword25/kernel/log.h +++ b/engines/sword25/kernel/log.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -46,32 +46,41 @@ namespace Sword25 { #ifdef BS_ACTIVATE_LOGGING // Logging-Makros -#define BS_LOG BS_Log::SetPrefix(BS_LOG_PREFIX ": "), BS_Log::LogDecorated -#define BS_LOGLN BS_Log::SetPrefix(BS_LOG_PREFIX ": "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated -#define BS_LOG_WARNING BS_Log::SetPrefix(BS_LOG_PREFIX ": WARNING - "), BS_Log::LogDecorated -#define BS_LOG_WARNINGLN BS_Log::SetPrefix(BS_LOG_PREFIX ": WARNING - "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated -#define BS_LOG_ERROR BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR - "), BS_Log::LogDecorated -#define BS_LOG_ERRORLN BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR - "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated -#define BS_LOG_EXTERROR BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR "), BS_Log::SetFile(__FILE__), BS_Log::SetLine(__LINE__), BS_Log::LogDecorated -#define BS_LOG_EXTERRORLN BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR "), BS_Log::SetFile(__FILE__), BS_Log::SetLine(__LINE__), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated +#define BS_LOG BS_Log::SetPrefix(BS_LOG_PREFIX ": "), BS_Log::LogDecorated +#define BS_LOGLN BS_Log::SetPrefix(BS_LOG_PREFIX ": "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated +#define BS_LOG_WARNING BS_Log::SetPrefix(BS_LOG_PREFIX ": WARNING - "), BS_Log::LogDecorated +#define BS_LOG_WARNINGLN BS_Log::SetPrefix(BS_LOG_PREFIX ": WARNING - "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated +#define BS_LOG_ERROR BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR - "), BS_Log::LogDecorated +#define BS_LOG_ERRORLN BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR - "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated +#define BS_LOG_EXTERROR BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR "), BS_Log::SetFile(__FILE__), BS_Log::SetLine(__LINE__), BS_Log::LogDecorated +#define BS_LOG_EXTERRORLN BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR "), BS_Log::SetFile(__FILE__), BS_Log::SetLine(__LINE__), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated // Die Version der Logging-Klasse mit aktiviertem Logging -class BS_Log -{ +class BS_Log { public: static void Clear(); - static void Log(const char* Format, ...); - static void LogPrefix(const char* Prefix, const char* Format, ...); - static void LogDecorated(const char* Format, ...); + static void Log(const char *Format, ...); + static void LogPrefix(const char *Prefix, const char *Format, ...); + static void LogDecorated(const char *Format, ...); - static void SetPrefix(const char* Prefix) { _Prefix = Prefix; } - static void SetFile(const char* File) { _File = File; } - static void SetLine(int Line) { _Line = Line; } - static void SetAutoNewline(bool AutoNewline) { _AutoNewline = AutoNewline; } + static void SetPrefix(const char *Prefix) { + _Prefix = Prefix; + } + static void SetFile(const char *File) { + _File = File; + } + static void SetLine(int Line) { + _Line = Line; + } + static void SetAutoNewline(bool AutoNewline) { + _AutoNewline = AutoNewline; + } typedef void (*LOG_LISTENER_CALLBACK)(const char *); - static void RegisterLogListener(LOG_LISTENER_CALLBACK Callback) { _LogListener.push_back(Callback); } - static bool IsListenerRegistered(LOG_LISTENER_CALLBACK Callback) { + static void RegisterLogListener(LOG_LISTENER_CALLBACK Callback) { + _LogListener.push_back(Callback); + } + static bool IsListenerRegistered(LOG_LISTENER_CALLBACK Callback) { Common::Array<LOG_LISTENER_CALLBACK>::iterator i; for (i = _LogListener.begin(); i != _LogListener.end(); ++i) { if (**i == Callback) @@ -82,17 +91,17 @@ public: static void _CloseLog(); private: - static Common::WriteStream * _LogFile; - static bool _LineBegin; - static const char * _Prefix; - static const char * _File; - static int _Line; - static bool _AutoNewline; - static Common::Array<LOG_LISTENER_CALLBACK> _LogListener; - + static Common::WriteStream *_LogFile; + static bool _LineBegin; + static const char *_Prefix; + static const char *_File; + static int _Line; + static bool _AutoNewline; + static Common::Array<LOG_LISTENER_CALLBACK> _LogListener; + static bool _CreateLog(); - static int _WriteLog(const char* Message); + static int _WriteLog(const char *Message); static void _FlushLog(); }; @@ -112,16 +121,16 @@ private: #define BS_LOG_EXTERROR #define BS_LOG_EXTERRORLN -// The version of the logging class with logging disabled +// The version of the logging class with logging disabled class BS_Log { public: // This version implements all the various methods as empty stubs - static void Log(const char* Text, ...) {}; - static void LogPrefix(const char* Prefix, const char* Format, ...) {}; - static void LogDecorated(const char* Format, ...) {}; + static void Log(const char *Text, ...) {}; + static void LogPrefix(const char *Prefix, const char *Format, ...) {}; + static void LogDecorated(const char *Format, ...) {}; - static void SetPrefix(const char* Prefix) {}; - static void SetFile(const char* File) {}; + static void SetPrefix(const char *Prefix) {}; + static void SetFile(const char *File) {}; static void SetLine(int Line) {}; static void SetAutoNewline(bool AutoNewline) {}; diff --git a/engines/sword25/kernel/memleaks.cpp b/engines/sword25/kernel/memleaks.cpp index ca4dde0fc3..e6ba1df608 100644 --- a/engines/sword25/kernel/memleaks.cpp +++ b/engines/sword25/kernel/memleaks.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -53,54 +53,47 @@ #include <stdio.h> #include <string.h> -typedef struct -{ - unsigned int address; - unsigned int size; - std::string file; - unsigned int line; +typedef struct { + unsigned int address; + unsigned int size; + std::string file; + unsigned int line; } ALLOC_INFO; -static const char * MEMLEAK_LOG_FILE = "memory_leaks.txt"; +static const char *MEMLEAK_LOG_FILE = "memory_leaks.txt"; static const unsigned int BUCKET_COUNT = 1021; std::vector< std::vector<ALLOC_INFO> > TrackData(BUCKET_COUNT); static unsigned int TotalSize = 0; // Diese Klasse stellt sicher, dass beim Programmende, das Memory-Leak Log geschrieben wird. -static class LeakDumper -{ +static class LeakDumper { public: - LeakDumper() : OutputFilename(BS_FileSystemUtil::GetInstance().GetUserdataDirectory() + "\\" + MEMLEAK_LOG_FILE) - { + LeakDumper() : OutputFilename(BS_FileSystemUtil::GetInstance().GetUserdataDirectory() + "\\" + MEMLEAK_LOG_FILE) { // Sicherstellen, dass das Ausgabeverzeichnis für die Datei existiert. BS_FileSystemUtil::GetInstance().CreateDirectory(BS_FileSystemUtil::GetInstance().GetUserdataDirectory()); } - ~LeakDumper() - { + ~LeakDumper() { DumpUnfreed(OutputFilename.c_str()); } std::string OutputFilename; } LeakDumperInstance; -void DumpUnfreed(const char * OutputFilename) -{ - FILE * Log = fopen(OutputFilename, "w"); +void DumpUnfreed(const char *OutputFilename) { + FILE *Log = fopen(OutputFilename, "w"); fputs("MEMORY LEAK REPORT:\n----------------------\n", Log); std::vector< std::vector<ALLOC_INFO> >::iterator BucketIter = TrackData.begin(); - for (; BucketIter != TrackData.end(); ++BucketIter) - { + for (; BucketIter != TrackData.end(); ++BucketIter) { std::vector<ALLOC_INFO>::iterator Iter = (*BucketIter).begin(); - for (; Iter != (*BucketIter).end(); ++Iter) - { - ALLOC_INFO & CurItem = (*Iter); + for (; Iter != (*BucketIter).end(); ++Iter) { + ALLOC_INFO &CurItem = (*Iter); fprintf(Log, "%-50s LINE:%d ADDRESS:0x%x SIZE:%d\n", - CurItem.file.c_str(), - CurItem.line, - CurItem.address, - CurItem.size); + CurItem.file.c_str(), + CurItem.line, + CurItem.address, + CurItem.size); } } @@ -109,8 +102,7 @@ void DumpUnfreed(const char * OutputFilename) fclose(Log); } -void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum) -{ +void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum) { std::vector<ALLOC_INFO> & CurBucket = TrackData[(addr >> 3) % BUCKET_COUNT]; ALLOC_INFO Info; Info.address = addr; @@ -122,18 +114,14 @@ void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsign TotalSize += asize; } -void RemoveTrack(unsigned int addr) -{ - if (addr != 0 && TrackData.size() == BUCKET_COUNT) - { +void RemoveTrack(unsigned int addr) { + if (addr != 0 && TrackData.size() == BUCKET_COUNT) { std::vector<ALLOC_INFO> & CurBucket = TrackData[(addr >> 3) % BUCKET_COUNT]; std::vector<ALLOC_INFO>::iterator Iter = CurBucket.begin(); - for (; Iter != CurBucket.end(); ++Iter) - { - if ((*Iter).address == addr) - { + for (; Iter != CurBucket.end(); ++Iter) { + if ((*Iter).address == addr) { TotalSize -= (*Iter).size; - + std::swap(*Iter, CurBucket.back()); CurBucket.pop_back(); return; diff --git a/engines/sword25/kernel/memleaks.h b/engines/sword25/kernel/memleaks.h index 4b2cde8bb6..aff61338f8 100644 --- a/engines/sword25/kernel/memleaks.h +++ b/engines/sword25/kernel/memleaks.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -43,25 +43,22 @@ #include <malloc.h> -void DumpUnfreed(const char * OutputFilename); +void DumpUnfreed(const char *OutputFilename); void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum); void RemoveTrack(unsigned int addr); -inline void * __cdecl operator new(unsigned int size, const char *file, int line) -{ +inline void *__cdecl operator new(unsigned int size, const char *file, int line) { void *ptr = malloc(size); if (ptr) AddTrack((unsigned int)ptr, size, file, line); return(ptr); }; -inline void __cdecl operator delete(void *p) -{ +inline void __cdecl operator delete(void *p) { RemoveTrack((unsigned int)p); free(p); }; -inline void __cdecl operator delete[](void *p) -{ +inline void __cdecl operator delete[](void *p) { RemoveTrack((unsigned int)p); free(p); }; diff --git a/engines/sword25/kernel/memlog_off.h b/engines/sword25/kernel/memlog_off.h index 7efe7da751..26bb8e2f8a 100644 --- a/engines/sword25/kernel/memlog_off.h +++ b/engines/sword25/kernel/memlog_off.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -35,8 +35,8 @@ // Deaktivieren der Memory-Leak Detektion #ifdef BS_MEMLOG - #ifdef new - #undef new - #undef DEBUG_NEW - #endif +#ifdef new +#undef new +#undef DEBUG_NEW +#endif #endif diff --git a/engines/sword25/kernel/memlog_on.h b/engines/sword25/kernel/memlog_on.h index 5f851f8b53..ef5d150c47 100644 --- a/engines/sword25/kernel/memlog_on.h +++ b/engines/sword25/kernel/memlog_on.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -35,8 +35,8 @@ // Aktivieren der Memory-Leak Detektion #ifdef BS_MEMLOG - #ifndef DEBUG_NEW - #define DEBUG_NEW new(__FILE__, __LINE__) - #endif - #define new DEBUG_NEW +#ifndef DEBUG_NEW +#define DEBUG_NEW new(__FILE__, __LINE__) +#endif +#define new DEBUG_NEW #endif diff --git a/engines/sword25/kernel/objectregistry.h b/engines/sword25/kernel/objectregistry.h index 52ff1d556c..befebfaedf 100644 --- a/engines/sword25/kernel/objectregistry.h +++ b/engines/sword25/kernel/objectregistry.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -150,20 +150,22 @@ public: protected: // FIXME: I'm not entirely sure my current hash function is legitimate struct ClassPointer_EqualTo { - bool operator()(const T *x, const T *y) const { return x == y; } + bool operator()(const T *x, const T *y) const { + return x == y; + } }; struct ClassPointer_Hash { - uint operator()(const T *x) const { + uint operator()(const T *x) const { return static_cast<uint>((int64)x % ((int64)1 << sizeof(uint))); } }; - typedef Common::HashMap<unsigned int, T *> HANDLE2PTR_MAP; + typedef Common::HashMap<unsigned int, T *> HANDLE2PTR_MAP; typedef Common::HashMap<T *, unsigned int, ClassPointer_Hash, ClassPointer_EqualTo> PTR2HANDLE_MAP; - HANDLE2PTR_MAP m_Handle2PtrMap; - PTR2HANDLE_MAP m_Ptr2HandleMap; - unsigned int m_NextHandle; + HANDLE2PTR_MAP m_Handle2PtrMap; + PTR2HANDLE_MAP m_Ptr2HandleMap; + unsigned int m_NextHandle; // ----------------------------------------------------------------------------- diff --git a/engines/sword25/kernel/outputpersistenceblock.cpp b/engines/sword25/kernel/outputpersistenceblock.cpp index 880f4be8d0..589e498408 100644 --- a/engines/sword25/kernel/outputpersistenceblock.cpp +++ b/engines/sword25/kernel/outputpersistenceblock.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -45,7 +45,7 @@ // ----------------------------------------------------------------------------- namespace { - const unsigned int INITIAL_BUFFER_SIZE = 1024 * 64; +const unsigned int INITIAL_BUFFER_SIZE = 1024 * 64; } namespace Sword25 { diff --git a/engines/sword25/kernel/outputpersistenceblock.h b/engines/sword25/kernel/outputpersistenceblock.h index adc0105dd2..c13f86215d 100644 --- a/engines/sword25/kernel/outputpersistenceblock.h +++ b/engines/sword25/kernel/outputpersistenceblock.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -32,7 +32,7 @@ * */ -#ifndef SWORD25_OUTPUTPERSISTENCEBLOCK_H +#ifndef SWORD25_OUTPUTPERSISTENCEBLOCK_H #define SWORD25_OUTPUTPERSISTENCEBLOCK_H // ----------------------------------------------------------------------------- @@ -59,8 +59,12 @@ public: void Write(const Common::String &String); void Write(const void *BufferPtr, size_t Size); - const void *GetData() const { return &m_Data[0]; } - unsigned int GetDataSize() const { return m_Data.size(); } + const void *GetData() const { + return &m_Data[0]; + } + unsigned int GetDataSize() const { + return m_Data.size(); + } private: void WriteMarker(unsigned char Marker); diff --git a/engines/sword25/kernel/persistable.h b/engines/sword25/kernel/persistable.h index 5c1b973435..ff3bd9c098 100644 --- a/engines/sword25/kernel/persistable.h +++ b/engines/sword25/kernel/persistable.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -44,8 +44,8 @@ class BS_Persistable { public: virtual ~BS_Persistable() {}; - virtual bool Persist(BS_OutputPersistenceBlock & Writer) = 0; - virtual bool Unpersist(BS_InputPersistenceBlock & Reader) = 0; + virtual bool Persist(BS_OutputPersistenceBlock &Writer) = 0; + virtual bool Unpersist(BS_InputPersistenceBlock &Reader) = 0; }; } // End of namespace Sword25 diff --git a/engines/sword25/kernel/persistenceblock.h b/engines/sword25/kernel/persistenceblock.h index 1417d3df69..71cf2135da 100644 --- a/engines/sword25/kernel/persistenceblock.h +++ b/engines/sword25/kernel/persistenceblock.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -32,7 +32,7 @@ * */ -#ifndef SWORD25_PERSISTENCEBLOCK_H +#ifndef SWORD25_PERSISTENCEBLOCK_H #define SWORD25_PERSISTENCEBLOCK_H // ----------------------------------------------------------------------------- @@ -49,12 +49,20 @@ namespace Sword25 { class BS_PersistenceBlock { public: - static unsigned int GetSInt32Size() { return sizeof(signed int) + sizeof(unsigned char); } - static unsigned int GetUInt32Size() { return sizeof(unsigned int) + sizeof(unsigned char); } - static unsigned int GetFloat32Size() { return sizeof(float) + sizeof(unsigned char); } - static unsigned int GetBoolSize() { return sizeof(unsigned char) + sizeof(unsigned char); } - static unsigned int GetStringSize(const Common::String &String) { - return static_cast<unsigned int>(sizeof(unsigned int) + String.size() + sizeof(unsigned char)); + static unsigned int GetSInt32Size() { + return sizeof(signed int) + sizeof(unsigned char); + } + static unsigned int GetUInt32Size() { + return sizeof(unsigned int) + sizeof(unsigned char); + } + static unsigned int GetFloat32Size() { + return sizeof(float) + sizeof(unsigned char); + } + static unsigned int GetBoolSize() { + return sizeof(unsigned char) + sizeof(unsigned char); + } + static unsigned int GetStringSize(const Common::String &String) { + return static_cast<unsigned int>(sizeof(unsigned int) + String.size() + sizeof(unsigned char)); } protected: @@ -90,7 +98,7 @@ protected: private: static bool IsBigEndian() { unsigned int Dummy = 1; - unsigned char * DummyPtr = reinterpret_cast<unsigned char *>(&Dummy); + unsigned char *DummyPtr = reinterpret_cast<unsigned char *>(&Dummy); return DummyPtr[0] == 0; } @@ -103,7 +111,7 @@ private: static void ReverseByteOrder(void *Ptr) { // Reverses the byte order of the 32-bit word pointed to by Ptr - unsigned char * CharPtr = static_cast<unsigned char *>(Ptr); + unsigned char *CharPtr = static_cast<unsigned char *>(Ptr); Swap(CharPtr[0], CharPtr[3]); Swap(CharPtr[1], CharPtr[2]); } diff --git a/engines/sword25/kernel/persistenceservice.cpp b/engines/sword25/kernel/persistenceservice.cpp index 54203b67dc..e3f3347799 100644 --- a/engines/sword25/kernel/persistenceservice.cpp +++ b/engines/sword25/kernel/persistenceservice.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -58,61 +58,61 @@ using namespace std; // ----------------------------------------------------------------------------- namespace Sword25 { - const char * SAVEGAME_EXTENSION = ".b25s"; - const char * SAVEGAME_DIRECTORY = "saves"; - const char * FILE_MARKER = "BS25SAVEGAME"; - const unsigned int SLOT_COUNT = 18; - const unsigned int FILE_COPY_BUFFER_SIZE = 1024 * 10; - const char *VERSIONID = "1"; - - // ------------------------------------------------------------------------- - - Common::String GenerateSavegameFilename(unsigned int SlotID) { - Common::String oss; - oss += SlotID; - oss += SAVEGAME_EXTENSION; - return oss; - } +const char *SAVEGAME_EXTENSION = ".b25s"; +const char *SAVEGAME_DIRECTORY = "saves"; +const char *FILE_MARKER = "BS25SAVEGAME"; +const unsigned int SLOT_COUNT = 18; +const unsigned int FILE_COPY_BUFFER_SIZE = 1024 * 10; +const char *VERSIONID = "1"; + +// ------------------------------------------------------------------------- + +Common::String GenerateSavegameFilename(unsigned int SlotID) { + Common::String oss; + oss += SlotID; + oss += SAVEGAME_EXTENSION; + return oss; +} - // ------------------------------------------------------------------------- +// ------------------------------------------------------------------------- - Common::String GenerateSavegamePath(unsigned int SlotID) { - Common::String oss; - oss = BS_PersistenceService::GetSavegameDirectory(); - oss += BS_FileSystemUtil::GetInstance().GetPathSeparator(); - oss += GenerateSavegameFilename(SlotID); - return oss; - } - - // ------------------------------------------------------------------------- - - Common::String FormatTimestamp(TimeDate Time) { - // In the original BS2.5 engine, this used a local object to show the date/time as as a string. - // For now in ScummVM it's being hardcoded to 'dd-MON-yyyy hh:mm:ss' - Common::String monthList[12] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }; - char buffer[100]; - snprintf(buffer, 100, "%.2d-%s-%.4d %.2d:%.2d:%.2d", - Time.tm_mday, monthList[Time.tm_mon].c_str(), Time.tm_year, - Time.tm_hour, Time.tm_min, Time.tm_sec - ); - - return Common::String(buffer); - } +Common::String GenerateSavegamePath(unsigned int SlotID) { + Common::String oss; + oss = BS_PersistenceService::GetSavegameDirectory(); + oss += BS_FileSystemUtil::GetInstance().GetPathSeparator(); + oss += GenerateSavegameFilename(SlotID); + return oss; +} - // ------------------------------------------------------------------------- +// ------------------------------------------------------------------------- + +Common::String FormatTimestamp(TimeDate Time) { + // In the original BS2.5 engine, this used a local object to show the date/time as as a string. + // For now in ScummVM it's being hardcoded to 'dd-MON-yyyy hh:mm:ss' + Common::String monthList[12] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; + char buffer[100]; + snprintf(buffer, 100, "%.2d-%s-%.4d %.2d:%.2d:%.2d", + Time.tm_mday, monthList[Time.tm_mon].c_str(), Time.tm_year, + Time.tm_hour, Time.tm_min, Time.tm_sec + ); + + return Common::String(buffer); +} - Common::String LoadString(Common::InSaveFile *In, uint MaxSize = 999) { - Common::String Result; - char ch; - while ((ch = (char)In->readByte()) != '\0') { - Result += ch; - if (Result.size() >= MaxSize) break; - } +// ------------------------------------------------------------------------- - return Result; +Common::String LoadString(Common::InSaveFile *In, uint MaxSize = 999) { + Common::String Result; + char ch; + while ((ch = (char)In->readByte()) != '\0') { + Result += ch; + if (Result.size() >= MaxSize) break; } + + return Result; +} } namespace Sword25 { @@ -122,15 +122,17 @@ namespace Sword25 { // ----------------------------------------------------------------------------- struct SavegameInformation { - bool IsOccupied; - bool IsCompatible; - Common::String Description; - Common::String Filename; - unsigned int GamedataLength; - unsigned int GamedataOffset; - unsigned int GamedataUncompressedLength; - - SavegameInformation() { Clear(); } + bool IsOccupied; + bool IsCompatible; + Common::String Description; + Common::String Filename; + unsigned int GamedataLength; + unsigned int GamedataOffset; + unsigned int GamedataUncompressedLength; + + SavegameInformation() { + Clear(); + } void Clear() { IsOccupied = false; @@ -163,7 +165,7 @@ struct BS_PersistenceService::Impl { void ReadSlotSavegameInformation(unsigned int SlotID) { // Aktuelle Slotinformationen in den Ausgangszustand versetzen, er wird im Folgenden neu gefüllt. - SavegameInformation & CurSavegameInfo = m_SavegameInformations[SlotID]; + SavegameInformation &CurSavegameInfo = m_SavegameInformations[SlotID]; CurSavegameInfo.Clear(); // Den Dateinamen für den Spielstand des Slots generieren. @@ -207,7 +209,7 @@ struct BS_PersistenceService::Impl { // Construction / Destruction // ----------------------------------------------------------------------------- -BS_PersistenceService & BS_PersistenceService::GetInstance() { +BS_PersistenceService &BS_PersistenceService::GetInstance() { static BS_PersistenceService Instance; return Instance; } @@ -246,16 +248,16 @@ Common::String BS_PersistenceService::GetSavegameDirectory() { // ----------------------------------------------------------------------------- namespace { - bool CheckSlotID(unsigned int SlotID) { - // Überprüfen, ob die Slot-ID zulässig ist. - if (SlotID >= SLOT_COUNT) { - BS_LOG_ERRORLN("Tried to access an invalid slot (%d). Only slot ids from 0 to %d are allowed.", SlotID, SLOT_COUNT - 1); - return false; - } else { - return true; - } +bool CheckSlotID(unsigned int SlotID) { + // Überprüfen, ob die Slot-ID zulässig ist. + if (SlotID >= SLOT_COUNT) { + BS_LOG_ERRORLN("Tried to access an invalid slot (%d). Only slot ids from 0 to %d are allowed.", SlotID, SLOT_COUNT - 1); + return false; + } else { + return true; } } +} // ----------------------------------------------------------------------------- @@ -304,7 +306,7 @@ bool BS_PersistenceService::SaveGame(unsigned int SlotID, const Common::String & // Spielstanddatei öffnen und die Headerdaten schreiben. Common::SaveFileManager *sfm = g_system->getSavefileManager(); - Common::OutSaveFile *File = sfm->openForSaving(Filename); + Common::OutSaveFile *File = sfm->openForSaving(Filename); File->writeString(FILE_MARKER); File->writeByte(' '); @@ -330,7 +332,7 @@ bool BS_PersistenceService::SaveGame(unsigned int SlotID, const Common::String & // Daten komprimieren. uLongf CompressedLength = Writer.GetDataSize() + (Writer.GetDataSize() + 500) / 1000 + 12; Bytef *CompressionBuffer = new Bytef[CompressedLength]; - + if (compress2(&CompressionBuffer[0], &CompressedLength, reinterpret_cast<const Bytef *>(Writer.GetData()), Writer.GetDataSize(), 6) != Z_OK) { error("Unable to compress savegame data in savegame file \"%s\".", Filename.c_str()); } @@ -353,7 +355,7 @@ bool BS_PersistenceService::SaveGame(unsigned int SlotID, const Common::String & // Screenshotdatei an die Datei anfügen. if (BS_FileSystemUtil::GetInstance().FileExists(ScreenshotFilename)) { Common::File ScreenshotFile; - if (!ScreenshotFile.open(ScreenshotFilename.c_str())) + if (!ScreenshotFile.open(ScreenshotFilename.c_str())) error("Unable to load screenshot file"); byte *Buffer = new Byte[FILE_COPY_BUFFER_SIZE]; @@ -386,7 +388,7 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) { return false; } - SavegameInformation & CurSavegameInfo = m_impl->m_SavegameInformations[SlotID]; + SavegameInformation &CurSavegameInfo = m_impl->m_SavegameInformations[SlotID]; // Überprüfen, ob der Slot belegt ist. if (!CurSavegameInfo.IsOccupied) { @@ -398,8 +400,7 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) { // Im Debug-Modus wird dieser Test übersprungen. Für das Testen ist es hinderlich auf die Einhaltung dieser strengen Bedingung zu bestehen, // da sich die Versions-ID bei jeder Codeänderung mitändert. #ifndef DEBUG - if (!CurSavegameInfo.IsCompatible) - { + if (!CurSavegameInfo.IsCompatible) { BS_LOG_ERRORLN("Tried to load a savegame (%d) that is not compatible with this engine version.", SlotID); return false; } @@ -408,7 +409,7 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) { byte *CompressedDataBuffer = new byte[CurSavegameInfo.GamedataLength]; byte *UncompressedDataBuffer = new Bytef[CurSavegameInfo.GamedataUncompressedLength]; - File = sfm->openForLoading(GenerateSavegamePath(SlotID)); + File = sfm->openForLoading(GenerateSavegamePath(SlotID)); File->seek(CurSavegameInfo.GamedataOffset); File->read(reinterpret_cast<char *>(&CompressedDataBuffer[0]), CurSavegameInfo.GamedataLength); @@ -422,7 +423,7 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) { // Spieldaten dekomprimieren. uLongf UncompressedBufferSize = CurSavegameInfo.GamedataUncompressedLength; if (uncompress(reinterpret_cast<Bytef *>(&UncompressedDataBuffer[0]), &UncompressedBufferSize, - reinterpret_cast<Bytef *>(&CompressedDataBuffer[0]), CurSavegameInfo.GamedataLength) != Z_OK) { + reinterpret_cast<Bytef *>(&CompressedDataBuffer[0]), CurSavegameInfo.GamedataLength) != Z_OK) { BS_LOG_ERRORLN("Unable to decompress the gamedata from savegame file \"%s\".", CurSavegameInfo.Filename.c_str()); delete[] UncompressedDataBuffer; delete[] CompressedDataBuffer; diff --git a/engines/sword25/kernel/persistenceservice.h b/engines/sword25/kernel/persistenceservice.h index 5fa3d320a5..15fb15c7ec 100644 --- a/engines/sword25/kernel/persistenceservice.h +++ b/engines/sword25/kernel/persistenceservice.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -32,7 +32,7 @@ * */ -#ifndef SWORD25_PERSISTENCESERVICE_H +#ifndef SWORD25_PERSISTENCESERVICE_H #define SWORD25_PERSISTENCESERVICE_H // ----------------------------------------------------------------------------- @@ -62,21 +62,21 @@ public: // Interface // ----------------------------------------------------------------------------- - static unsigned int GetSlotCount(); + static unsigned int GetSlotCount(); static Common::String GetSavegameDirectory(); - void ReloadSlots(); - bool IsSlotOccupied(unsigned int SlotID); - bool IsSavegameCompatible(unsigned int SlotID); + void ReloadSlots(); + bool IsSlotOccupied(unsigned int SlotID); + bool IsSavegameCompatible(unsigned int SlotID); Common::String &GetSavegameDescription(unsigned int SlotID); Common::String &GetSavegameFilename(unsigned int SlotID); - - bool SaveGame(unsigned int SlotID, const Common::String & ScreenshotFilename); - bool LoadGame(unsigned int SlotID); + + bool SaveGame(unsigned int SlotID, const Common::String &ScreenshotFilename); + bool LoadGame(unsigned int SlotID); private: struct Impl; - Impl * m_impl; + Impl *m_impl; }; } // End of namespace Sword25 diff --git a/engines/sword25/kernel/resmanager.cpp b/engines/sword25/kernel/resmanager.cpp index d0a32965ce..1e232ca63b 100644 --- a/engines/sword25/kernel/resmanager.cpp +++ b/engines/sword25/kernel/resmanager.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -53,7 +53,9 @@ BS_ResourceManager::~BS_ResourceManager() { BS_LOG_WARNINGLN("Resource \"%s\" was not released.", (*Iter)->GetFileName().c_str()); // Set the lock count to zero - while ((*Iter)->GetLockCount() > 0) { (*Iter)->Release(); }; + while ((*Iter)->GetLockCount() > 0) { + (*Iter)->Release(); + }; // Delete the resource delete(*Iter); @@ -63,7 +65,7 @@ BS_ResourceManager::~BS_ResourceManager() { /** * Returns a resource by it's ordinal index. Returns NULL if any error occurs * Note: This method is not optimised for speed and should be used only for debugging purposes - * @param Ord Ordinal number of the resource. Must be between 0 and GetResourceCount() - 1. + * @param Ord Ordinal number of the resource. Must be between 0 and GetResourceCount() - 1. */ BS_Resource *BS_ResourceManager::GetResourceByOrdinal(int Ord) const { // Überprüfen ob der Index Ord innerhald der Listengrenzen liegt. @@ -74,7 +76,7 @@ BS_Resource *BS_ResourceManager::GetResourceByOrdinal(int Ord) const { // Liste durchlaufen und die Resource mit dem gewünschten Index zurückgeben. int CurOrd = 0; - Common::List<BS_Resource*>::const_iterator Iter = m_Resources.begin(); + Common::List<BS_Resource *>::const_iterator Iter = m_Resources.begin(); for (; Iter != m_Resources.end(); ++Iter, ++CurOrd) { if (CurOrd == Ord) return (*Iter); @@ -88,7 +90,7 @@ BS_Resource *BS_ResourceManager::GetResourceByOrdinal(int Ord) const { /** * Registers a RegisterResourceService. This method is the constructor of * BS_ResourceService, and thus helps all resource services in the ResourceManager list - * @param pService Which service + * @param pService Which service */ bool BS_ResourceManager::RegisterResourceService(BS_ResourceService *pService) { if (!pService) { @@ -109,7 +111,7 @@ void BS_ResourceManager::DeleteResourcesIfNecessary() { if (m_KernelPtr->GetUsedMemory() < m_MaxMemoryUsage || m_Resources.empty()) return; // Keep deleting resources until the memory usage of the process falls below the set maximum limit. - // The list is processed backwards in order to first release those resources who have been + // The list is processed backwards in order to first release those resources who have been // not been accessed for the longest Common::List<BS_Resource *>::iterator Iter = m_Resources.end(); do { @@ -137,7 +139,7 @@ void BS_ResourceManager::EmptyCache() { /** * Returns a requested resource. If any error occurs, returns NULL - * @param FileName Filename of resource + * @param FileName Filename of resource */ BS_Resource *BS_ResourceManager::RequestResource(const Common::String &FileName) { // Get the absolute path to the file @@ -170,11 +172,11 @@ BS_Resource *BS_ResourceManager::RequestResource(const Common::String &FileName) /** * Loads a resource into the cache - * @param FileName The filename of the resource to be cached - * @param ForceReload Indicates whether the file should be reloaded if it's already in the cache. + * @param FileName The filename of the resource to be cached + * @param ForceReload Indicates whether the file should be reloaded if it's already in the cache. * This is useful for files that may have changed in the interim */ -bool BS_ResourceManager::PrecacheResource(const Common::String& FileName, bool ForceReload) { +bool BS_ResourceManager::PrecacheResource(const Common::String &FileName, bool ForceReload) { // Get the absolute path to the file Common::String UniqueFileName = GetUniqueFileName(FileName); if (UniqueFileName == "") @@ -202,7 +204,7 @@ bool BS_ResourceManager::PrecacheResource(const Common::String& FileName, bool F /** * Moves a resource to the top of the resource list - * @param pResource The resource + * @param pResource The resource */ void BS_ResourceManager::MoveToFront(BS_Resource *pResource) { // Erase the resource from it's current position @@ -217,7 +219,7 @@ void BS_ResourceManager::MoveToFront(BS_Resource *pResource) { * Loads a resource and updates the m_UsedMemory total * * The resource must not already be loaded - * @param FileName The unique filename of the resource to be loaded + * @param FileName The unique filename of the resource to be loaded */ BS_Resource *BS_ResourceManager::LoadResource(const Common::String &FileName) { // ResourceService finden, der die Resource laden kann. @@ -252,7 +254,7 @@ BS_Resource *BS_ResourceManager::LoadResource(const Common::String &FileName) { * Returns the full path of a given resource filename. * It will return an empty string if a path could not be created. */ -Common::String BS_ResourceManager::GetUniqueFileName(const Common::String& FileName) const { +Common::String BS_ResourceManager::GetUniqueFileName(const Common::String &FileName) const { // Get a pointer to the package manager BS_PackageManager *pPackage = (BS_PackageManager *)m_KernelPtr->GetService("package"); if (!pPackage) { @@ -281,7 +283,7 @@ Common::List<BS_Resource *>::iterator BS_ResourceManager::DeleteResource(BS_Reso Common::List<BS_Resource *>::iterator Result = m_Resources.erase(pResource->_Iterator); // Delete the resource - delete (pDummy); + delete(pDummy); // Return the iterator return Result; @@ -289,17 +291,16 @@ Common::List<BS_Resource *>::iterator BS_ResourceManager::DeleteResource(BS_Reso /** * Returns a pointer to a loaded resource. If any error occurs, NULL will be returned. - * @param UniqueFileName The absolute path and filename + * @param UniqueFileName The absolute path and filename * Gibt einen Pointer auf die angeforderte Resource zurück, oder NULL, wenn die Resourcen nicht geladen ist. */ -BS_Resource * BS_ResourceManager::GetResource(const Common::String &UniqueFileName) const { +BS_Resource *BS_ResourceManager::GetResource(const Common::String &UniqueFileName) const { // Determine whether the resource is already loaded const Common::List<BS_Resource *>& HashBucket = m_ResourceHashTable[ - BS_String::GetHash(UniqueFileName) % HASH_TABLE_BUCKETS]; + BS_String::GetHash(UniqueFileName) % HASH_TABLE_BUCKETS]; { - Common::List<BS_Resource*>::const_iterator Iter = HashBucket.begin(); - for (; Iter != HashBucket.end(); ++Iter) - { + Common::List<BS_Resource *>::const_iterator Iter = HashBucket.begin(); + for (; Iter != HashBucket.end(); ++Iter) { // Wenn die Resource gefunden wurde wird sie zurückgegeben. if ((*Iter)->GetFileName() == UniqueFileName) return *Iter; diff --git a/engines/sword25/kernel/resmanager.h b/engines/sword25/kernel/resmanager.h index 511bf63d68..e642e54055 100644 --- a/engines/sword25/kernel/resmanager.h +++ b/engines/sword25/kernel/resmanager.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -48,41 +48,43 @@ class BS_Resource; class BS_Kernel; class BS_ResourceManager { -friend class BS_Kernel; + friend class BS_Kernel; public: /** * Returns a requested resource. If any error occurs, returns NULL - * @param FileName Filename of resource + * @param FileName Filename of resource */ BS_Resource *RequestResource(const Common::String &FileName); /** * Loads a resource into the cache - * @param FileName The filename of the resource to be cached - * @param ForceReload Indicates whether the file should be reloaded if it's already in the cache. + * @param FileName The filename of the resource to be cached + * @param ForceReload Indicates whether the file should be reloaded if it's already in the cache. * This is useful for files that may have changed in the interim */ - bool PrecacheResource(const Common::String& FileName, bool ForceReload = false); + bool PrecacheResource(const Common::String &FileName, bool ForceReload = false); /** * Returns the number of loaded resources */ - int GetResourceCount() const { return static_cast<int>(m_Resources.size()); } + int GetResourceCount() const { + return static_cast<int>(m_Resources.size()); + } /** * Returns a resource by it's ordinal index. Returns NULL if any error occurs * Note: This method is not optimised for speed and should be used only for debugging purposes - * @param Ord Ordinal number of the resource. Must be between 0 and GetResourceCount() - 1. + * @param Ord Ordinal number of the resource. Must be between 0 and GetResourceCount() - 1. */ BS_Resource *GetResourceByOrdinal(int Ord) const; /** * Registers a RegisterResourceService. This method is the constructor of * BS_ResourceService, and thus helps all resource services in the ResourceManager list - * @param pService Which service + * @param pService Which service */ - bool RegisterResourceService(BS_ResourceService* pService); + bool RegisterResourceService(BS_ResourceService *pService); /** * Releases all resources that are not locked. @@ -92,7 +94,9 @@ public: /** * Returns the maximum memory the kernel has used */ - int GetMaxMemoryUsage() const { return m_MaxMemoryUsage; } + int GetMaxMemoryUsage() const { + return m_MaxMemoryUsage; + } /** * Specifies the maximum amount of memory the engine is allowed to use. @@ -106,13 +110,17 @@ public: * Specifies whether a warning is written to the log when a cache miss occurs. * THe default value is "false". */ - bool IsLogCacheMiss() const { return m_LogCacheMiss; } + bool IsLogCacheMiss() const { + return m_LogCacheMiss; + } /** * Sets whether warnings are written to the log if a cache miss occurs. - * @param Flag If "true", then future warnings will be logged + * @param Flag If "true", then future warnings will be logged */ - void SetLogCacheMiss(bool Flag) { m_LogCacheMiss = Flag; } + void SetLogCacheMiss(bool Flag) { + m_LogCacheMiss = Flag; + } /** * Writes the names of all currently locked resources to the log file @@ -124,21 +132,20 @@ private: * Creates a new resource manager * Only the BS_Kernel class can generate copies this class. Thus, the constructor is private */ - BS_ResourceManager(BS_Kernel* pKernel) : + BS_ResourceManager(BS_Kernel *pKernel) : m_KernelPtr(pKernel), m_MaxMemoryUsage(100000000), m_LogCacheMiss(false) {}; virtual ~BS_ResourceManager(); - - enum - { + + enum { HASH_TABLE_BUCKETS = 256 }; /** * Moves a resource to the top of the resource list - * @param pResource The resource + * @param pResource The resource */ void MoveToFront(BS_Resource *pResource); @@ -146,7 +153,7 @@ private: * Loads a resource and updates the m_UsedMemory total * * The resource must not already be loaded - * @param FileName The unique filename of the resource to be loaded + * @param FileName The unique filename of the resource to be loaded */ BS_Resource *LoadResource(const Common::String &FileName); @@ -159,11 +166,11 @@ private: /** * Deletes a resource, removes it from the lists, and updates m_UsedMemory */ - Common::List<BS_Resource*>::iterator DeleteResource(BS_Resource *pResource); + Common::List<BS_Resource *>::iterator DeleteResource(BS_Resource *pResource); /** * Returns a pointer to a loaded resource. If any error occurs, NULL will be returned. - * @param UniqueFileName The absolute path and filename + * @param UniqueFileName The absolute path and filename * Gibt einen Pointer auf die angeforderte Resource zurück, oder NULL, wenn die Resourcen nicht geladen ist. */ BS_Resource *GetResource(const Common::String &UniqueFileName) const; @@ -173,12 +180,12 @@ private: */ void DeleteResourcesIfNecessary(); - BS_Kernel * m_KernelPtr; - unsigned int m_MaxMemoryUsage; - Common::Array<BS_ResourceService *> m_ResourceServices; - Common::List<BS_Resource *> m_Resources; - Common::List<BS_Resource *> m_ResourceHashTable[HASH_TABLE_BUCKETS]; - bool m_LogCacheMiss; + BS_Kernel *m_KernelPtr; + unsigned int m_MaxMemoryUsage; + Common::Array<BS_ResourceService *> m_ResourceServices; + Common::List<BS_Resource *> m_Resources; + Common::List<BS_Resource *> m_ResourceHashTable[HASH_TABLE_BUCKETS]; + bool m_LogCacheMiss; }; } // End of namespace Sword25 diff --git a/engines/sword25/kernel/resource.cpp b/engines/sword25/kernel/resource.cpp index 9bb491b8b4..c33bfea268 100644 --- a/engines/sword25/kernel/resource.cpp +++ b/engines/sword25/kernel/resource.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -42,8 +42,8 @@ namespace Sword25 { #define BS_LOG_PREFIX "RESOURCE" BS_Resource::BS_Resource(const Common::String &FileName, RESOURCE_TYPES Type) : - _Type(Type), - _RefCount(0) { + _Type(Type), + _RefCount(0) { BS_ASSERT(BS_Kernel::GetInstance()->GetService("package")); _FileName = static_cast<BS_PackageManager *>(BS_Kernel::GetInstance()->GetService("package"))->GetAbsolutePath(FileName); diff --git a/engines/sword25/kernel/resource.h b/engines/sword25/kernel/resource.h index 4b0e8ccd21..4653eab149 100644 --- a/engines/sword25/kernel/resource.h +++ b/engines/sword25/kernel/resource.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -45,7 +45,7 @@ class BS_Kernel; class BS_ResourceManager; class BS_Resource { -friend class BS_ResourceManager; + friend class BS_ResourceManager; public: enum RESOURCE_TYPES { @@ -60,47 +60,57 @@ public: /** * Prevents the resource from being released. - * @remarks This method allows a resource to be locked multiple times. + * @remarks This method allows a resource to be locked multiple times. **/ - void AddReference() { ++_RefCount; } + void AddReference() { + ++_RefCount; + } /** * Cancels a previous lock - * @remarks The resource can still be released more times than it was 'locked', although it is + * @remarks The resource can still be released more times than it was 'locked', although it is * not recommended. **/ void Release(); /** * Returns the current lock count for the resource - * @return The current lock count + * @return The current lock count **/ - int GetLockCount() const { return _RefCount; } + int GetLockCount() const { + return _RefCount; + } /** * Returns the absolute path of the given resource */ - const Common::String &GetFileName() const { return _FileName; } + const Common::String &GetFileName() const { + return _FileName; + } /** * Returns the hash of the filename of a resource */ - unsigned int GetFileNameHash() const { return _FileNameHash; } + unsigned int GetFileNameHash() const { + return _FileNameHash; + } /** * Returns a resource's type */ - unsigned int GetType() const { return _Type; } + unsigned int GetType() const { + return _Type; + } protected: virtual ~BS_Resource() {}; private: - Common::String _FileName; ///< The absolute filename - unsigned int _FileNameHash; ///< The hash value of the filename - unsigned int _RefCount; ///< The number of locks - unsigned int _Type; ///< The type of the resource - Common::List<BS_Resource *>::iterator _Iterator; ///< Points to the resource position in the LRU list + Common::String _FileName; ///< The absolute filename + unsigned int _FileNameHash; ///< The hash value of the filename + unsigned int _RefCount; ///< The number of locks + unsigned int _Type; ///< The type of the resource + Common::List<BS_Resource *>::iterator _Iterator; ///< Points to the resource position in the LRU list }; } // End of namespace Sword25 diff --git a/engines/sword25/kernel/resservice.h b/engines/sword25/kernel/resservice.h index 8804b5bbac..2197d283bf 100644 --- a/engines/sword25/kernel/resservice.h +++ b/engines/sword25/kernel/resservice.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -47,9 +47,8 @@ class BS_Resource; class BS_ResourceService : public BS_Service { public: - BS_ResourceService(BS_Kernel* pKernel) : BS_Service(pKernel) - { - BS_ResourceManager* pResource = pKernel->GetResourceManager(); + BS_ResourceService(BS_Kernel *pKernel) : BS_Service(pKernel) { + BS_ResourceManager *pResource = pKernel->GetResourceManager(); pResource->RegisterResourceService(this); } @@ -58,25 +57,25 @@ public: /** * Loads a resource - * @return Returns the resource if successful, otherwise NULL + * @return Returns the resource if successful, otherwise NULL */ virtual BS_Resource *LoadResource(const Common::String &FileName) = 0; /** * Checks whether the given name can be loaded by the resource service - * @param FileName Dateiname - * @return Returns true if the resource can be loaded. + * @param FileName Dateiname + * @return Returns true if the resource can be loaded. */ - virtual bool CanLoadResource(const Common::String& FileName) = 0; + virtual bool CanLoadResource(const Common::String &FileName) = 0; protected: // Alternative methods for classes BS_ResourceService /** * Compares two strings, with the second string allowed to contain '*' and '?' wildcards - * @param String The first comparison string. This must not contain wildcards - * @param Pattern The sceond comaprison string. Wildcards of '*' and '?' are allowed. - * @return Returns true if the string matches the pattern, otherwise false. + * @param String The first comparison string. This must not contain wildcards + * @param Pattern The sceond comaprison string. Wildcards of '*' and '?' are allowed. + * @return Returns true if the string matches the pattern, otherwise false. */ bool _WildCardStringMatch(const Common::String &String, const Common::String &Pattern) { return _WildCardStringMatchRecursion(String.c_str(), Pattern.c_str()); @@ -89,18 +88,20 @@ private: if (*Pattern == '*') { // Use a copy of the pattern pointer so as not to destroy the current state const char *PatternCopy = Pattern; - while (*PatternCopy == '*') { PatternCopy++; } + while (*PatternCopy == '*') { + PatternCopy++; + } if (!*PatternCopy) return true; } // 2. The string is over, but the patern is not -> FALSE if (!*String && *Pattern) return false; // 3. The string is over, and the pattern is finished -> TRUE if (!*String) return true; - + // Recursive check 1: // If the two current characters are the same, or pattern '?', then keep scanning if (*String == *Pattern || *Pattern == '?') return _WildCardStringMatchRecursion(String + 1, Pattern + 1); - + // Falls nicht, wird untersucht ob ein '*' vorliegt if (*Pattern == '*') { // Recursive check 2: @@ -111,7 +112,7 @@ private: // The recursion ends, therefore, keep returning to this place until a character // in the string which corresponds to the '*' in pattern } - + // The match has failed return false; } diff --git a/engines/sword25/kernel/scummvmwindow.cpp b/engines/sword25/kernel/scummvmwindow.cpp index 56e3b14adb..2b4e820160 100644 --- a/engines/sword25/kernel/scummvmwindow.cpp +++ b/engines/sword25/kernel/scummvmwindow.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -45,7 +45,7 @@ namespace Sword25 { bool BS_ScummVMWindow::_ClassRegistered = false; -// Constructor / Destructor +// Constructor / Destructor // ------------------------ BS_ScummVMWindow::BS_ScummVMWindow(int X, int Y, int Width, int Height, bool Visible) { // Presume that init will fail @@ -163,133 +163,133 @@ bool BS_ScummVMWindow::WaitForFocus() { // 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; + 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/scummvmwindow.h b/engines/sword25/kernel/scummvmwindow.h index da223ae102..57d9a7e2f9 100644 --- a/engines/sword25/kernel/scummvmwindow.h +++ b/engines/sword25/kernel/scummvmwindow.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -33,9 +33,9 @@ */ /* - BS_ScummVMWindow - ---------------- - Implementation of the BS_Window Interfaces for ScummVM + BS_ScummVMWindow + ---------------- + Implementation of the BS_Window Interfaces for ScummVM */ #ifndef SWORD25_SCUMMVMWINDOW_H @@ -75,9 +75,9 @@ public: private: static bool _ClassRegistered; - bool _WindowAlive; - int _ClientXDelta; - int _ClientYDelta; + bool _WindowAlive; + int _ClientXDelta; + int _ClientYDelta; }; } // End of namespace Sword25 diff --git a/engines/sword25/kernel/service.h b/engines/sword25/kernel/service.h index a42b5206bc..0afcb05f11 100644 --- a/engines/sword25/kernel/service.h +++ b/engines/sword25/kernel/service.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -38,7 +38,7 @@ * This is the base class for all engine services. * A serivce is an essential part of the engine, ex. the graphics system. * This was intended to allow, for example, different plug in modules for - * different kinds of hardware and/or systems. + * different kinds of hardware and/or systems. * The services are created at runtime via the kernel method NewService and NEVER with new. * * Autor: Malte Thiesen @@ -57,13 +57,15 @@ class BS_Kernel; class BS_Service { private: - BS_Kernel * _pKernel; - + BS_Kernel *_pKernel; + protected: BS_Service(BS_Kernel *pKernel) : _pKernel(pKernel) {}; - - BS_Kernel* GetKernel() const { return _pKernel; } - + + BS_Kernel *GetKernel() const { + return _pKernel; + } + public: virtual ~BS_Service() {}; }; diff --git a/engines/sword25/kernel/service_ids.h b/engines/sword25/kernel/service_ids.h index 7bb352d9e5..0529d53fbe 100644 --- a/engines/sword25/kernel/service_ids.h +++ b/engines/sword25/kernel/service_ids.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -37,7 +37,7 @@ * ------------- * This file lists all the services. * EVERY new service needs to be entered here, otherwise it cannot be instantiated - * by pKernel->NewService(..) + * by pKernel->NewService(..) * * Autor: Malte Thiesen */ @@ -60,7 +60,7 @@ BS_Service *BS_OggTheora_CreateObject(BS_Kernel *pKernel); // Services are recorded in this table 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 + // 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) diff --git a/engines/sword25/kernel/string.h b/engines/sword25/kernel/string.h index feaf546c3e..7ff1d75f7b 100644 --- a/engines/sword25/kernel/string.h +++ b/engines/sword25/kernel/string.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -52,7 +52,9 @@ inline bool ToInt(const Common::String &Str, int &Result) { Common::String::const_iterator Iter = Str.begin(); // Skip whitespaces - while (*Iter && (*Iter == ' ' || *Iter == '\t')) { ++Iter; } + while (*Iter && (*Iter == ' ' || *Iter == '\t')) { + ++Iter; + } if (Iter == Str.end()) return false; // Read sign, if available @@ -60,19 +62,22 @@ inline bool ToInt(const Common::String &Str, int &Result) { if (*Iter == '-') { IsNegative = true; ++Iter; - } - else if (*Iter == '+') + } else if (*Iter == '+') ++Iter; // Skip whitespaces - while (*Iter && (*Iter == ' ' || *Iter == '\t')) { ++Iter; } - if (Iter ==Str.end()) return false; + while (*Iter && (*Iter == ' ' || *Iter == '\t')) { + ++Iter; + } + if (Iter == Str.end()) return false; // Convert string to integer Result = 0; while (Iter != Str.end()) { if (*Iter < '0' || *Iter > '9') { - while (*Iter && (*Iter == ' ' || *Iter == '\t')) { ++Iter; } + while (*Iter && (*Iter == ' ' || *Iter == '\t')) { + ++Iter; + } if (Iter != Str.end()) return false; break; } diff --git a/engines/sword25/kernel/window.cpp b/engines/sword25/kernel/window.cpp index ecafcfa829..b4936e8afc 100644 --- a/engines/sword25/kernel/window.cpp +++ b/engines/sword25/kernel/window.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -42,7 +42,7 @@ 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) { // Fenster erstellen - BS_Window *pWindow = (BS_Window*) new BS_ScummVMWindow(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 @@ -54,7 +54,7 @@ BS_Window *BS_Window::CreateBSWindow(int X, int Y, int Width, int Height, bool V return NULL; } -// Gibt True zurück wenn das Fenster WM_CLOSE empfangen hat - +// Gibt True zurück wenn das Fenster WM_CLOSE empfangen hat - // solange, bis RejectClose() aufgerufen wurde. bool BS_Window::CloseWanted() { bool result = _CloseWanted; diff --git a/engines/sword25/kernel/window.h b/engines/sword25/kernel/window.h index 18b3930dca..ae8709f157 100644 --- a/engines/sword25/kernel/window.h +++ b/engines/sword25/kernel/window.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -63,7 +63,7 @@ protected: bool _CloseWanted; public: - virtual ~BS_Window(){}; + virtual ~BS_Window() {}; /** * Returns the visibility of the window. @@ -72,7 +72,7 @@ public: /** * Sets the visibility of the window - * @param Visible Specifies whether the window should be visible or hidden + * @param Visible Specifies whether the window should be visible or hidden */ virtual void SetVisible(bool Visible) = 0; /** @@ -81,7 +81,7 @@ public: virtual int GetX() = 0; /** * Sets the X position of the window - * @paramX The new X position for the window, or -1 for centre aligned + * @paramX The new X position for the window, or -1 for centre aligned */ virtual void SetX(int X) = 0; /** @@ -90,7 +90,7 @@ public: virtual int GetY() = 0; /** * Sets the Y position of the window - * @param Y The new Y position for the window, or -1 for centre aligned + * @param Y The new Y position for the window, or -1 for centre aligned */ virtual void SetY(int X) = 0; /** @@ -123,7 +123,7 @@ public: virtual Common::String GetTitle() = 0; /** * Sets the title of the window - * @param Title The new window title + * @param Title The new window title */ virtual void SetTitle(const Common::String &Title) = 0; /** @@ -135,7 +135,7 @@ public: * Pauses the applicaiton until the window has focus, or has been closed. * Returns false if the window was closed. */ - virtual bool WaitForFocus() = 0; + virtual bool WaitForFocus() = 0; /** * Returns true if the window has focus, false otherwise. */ @@ -152,9 +152,9 @@ public: * Specifies whether the window is wanted to be closed. This is used together with CloseWanted() * to allow scripts to query when the main window should be closed, or the user is asking it to close **/ - void SetCloseWanted(bool Wanted); + void SetCloseWanted(bool Wanted); /** - * Returns the previous value set in a call to SetCloseWanted. + * Returns the previous value set in a call to SetCloseWanted. * Note that calling this also resets the value back to false, until such time as the SetCloseWanted() * method is called again. **/ @@ -163,11 +163,11 @@ public: /** * Creates a new window instance. Returns a pointer to the window, or NULL if the creation failed. * Note: It is the responsibility of the client to free the pointer when done with it. - * @param X The X position of the window, or -1 for centre horizontal alignment - * @param Y The Y position of the window, or -1 for centre vertical alignment - * @param Width The width of the window without the frame - * @param Height The height of the window without the frame - * @param Visible Specifies whether window should be visible + * @param X The X position of the window, or -1 for centre horizontal alignment + * @param Y The Y position of the window, or -1 for centre vertical alignment + * @param Width The width of the window without the frame + * @param Height The height of the window without the frame + * @param Visible Specifies whether window should be visible */ static BS_Window *CreateBSWindow(int X, int Y, int Width, int Height, bool Visible); }; |