aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xengines/sword25/kernel/resmanager.cpp302
-rwxr-xr-xengines/sword25/kernel/resmanager.h2
-rwxr-xr-xengines/sword25/kernel/resource.cpp62
-rwxr-xr-xengines/sword25/kernel/resource.h100
-rwxr-xr-xengines/sword25/kernel/string.h200
5 files changed, 342 insertions, 324 deletions
diff --git a/engines/sword25/kernel/resmanager.cpp b/engines/sword25/kernel/resmanager.cpp
index f29f5268a7..21342b0487 100755
--- a/engines/sword25/kernel/resmanager.cpp
+++ b/engines/sword25/kernel/resmanager.cpp
@@ -1,21 +1,26 @@
-// -----------------------------------------------------------------------------
-// This file is part of Broken Sword 2.5
-// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer
-//
-// Broken Sword 2.5 is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// Broken Sword 2.5 is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Broken Sword 2.5; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-// -----------------------------------------------------------------------------
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
#include "sword25/kernel/resmanager.h"
@@ -24,41 +29,43 @@
#include "sword25/kernel/string.h"
#include "sword25/package/packagemanager.h"
+namespace Sword25 {
+
#define BS_LOG_PREFIX "RESOURCEMANAGER"
-BS_ResourceManager::~BS_ResourceManager()
-{
- // Alle ungelockten Resourcen freigeben.
+BS_ResourceManager::~BS_ResourceManager() {
+ // Clear all unlocked resources
EmptyCache();
- // Alle übriggebliebenen Resourcen sind nicht freigegeben worden, daher Warnungen ausgeben und freigeben.
- std::list<BS_Resource*>::iterator Iter = m_Resources.begin();
- for (; Iter != m_Resources.end(); ++Iter)
- {
+ // All remaining resources are not released, so print warnings and release
+ Common::List<BS_Resource *>::iterator Iter = m_Resources.begin();
+ for (; Iter != m_Resources.end(); ++Iter) {
BS_LOG_WARNINGLN("Resource \"%s\" was not released.", (*Iter)->GetFileName().c_str());
- // Lock-Count auf 0 setzen.
+ // Set the lock count to zero
while ((*Iter)->GetLockCount() > 0) { (*Iter)->Release(); };
- // Resource freigeben.
+ // Delete the resource
delete(*Iter);
}
}
-BS_Resource* BS_ResourceManager::GetResourceByOrdinal(int Ord) const
-{
+/**
+ * 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.
+ */
+BS_Resource *BS_ResourceManager::GetResourceByOrdinal(int Ord) const {
// Überprüfen ob der Index Ord innerhald der Listengrenzen liegt.
- if (Ord < 0 || Ord >= GetResourceCount())
- {
+ if (Ord < 0 || Ord >= GetResourceCount()) {
BS_LOG_ERRORLN("Resource ordinal (%d) out of bounds (0 - %d).", Ord, GetResourceCount() - 1);
return NULL;
}
// Liste durchlaufen und die Resource mit dem gewünschten Index zurückgeben.
int CurOrd = 0;
- std::list<BS_Resource*>::const_iterator Iter = m_Resources.begin();
- for (; Iter != m_Resources.end(); ++Iter, ++CurOrd)
- {
+ Common::List<BS_Resource*>::const_iterator Iter = m_Resources.begin();
+ for (; Iter != m_Resources.end(); ++Iter, ++CurOrd) {
if (CurOrd == Ord)
return (*Iter);
}
@@ -68,10 +75,13 @@ BS_Resource* BS_ResourceManager::GetResourceByOrdinal(int Ord) const
return NULL;
}
-bool BS_ResourceManager::RegisterResourceService(BS_ResourceService* pService)
-{
- if(!pService)
- {
+/**
+ * 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
+ */
+bool BS_ResourceManager::RegisterResourceService(BS_ResourceService *pService) {
+ if (!pService) {
BS_LOG_ERRORLN("Can't register NULL resource service.");
return false;
}
@@ -81,65 +91,66 @@ bool BS_ResourceManager::RegisterResourceService(BS_ResourceService* pService)
return true;
}
-void BS_ResourceManager::DeleteResourcesIfNecessary()
-{
- // Falls noch genügend Speicher frei ist, oder keine Ressourcen geladen sind, kann die Funktion vorzeitig beendet werden.
+/**
+ * Deletes resources as necessary until the specified memory limit is not being exceeded.
+ */
+void BS_ResourceManager::DeleteResourcesIfNecessary() {
+ // If enough memory is available, or no resources are loaded, then the function can immediately end
if (m_KernelPtr->GetUsedMemory() < m_MaxMemoryUsage || m_Resources.empty()) return;
- // Solange Ressourcen löschen, bis der Speichernutzung des Prozesses unter den festgelegten Maximalwert fällt.
- // Dabei wird die Liste von Hinten nach vorne durchlaufen um zunächst jene Resourcen freizugeben, deren
- // Benutzung lange zurückliegt und sich somit am Ende der Liste befinden.
- std::list<BS_Resource*>::iterator Iter = m_Resources.end();
- do
- {
+ // 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
+ // not been accessed for the longest
+ Common::List<BS_Resource *>::iterator Iter = m_Resources.end();
+ do {
--Iter;
- // Die Resource darf nur freigegeben werden, wenn sie nicht gelockt ist.
+ // The resource may be released only if it isn't locked
if ((*Iter)->GetLockCount() == 0) Iter = DeleteResource(*Iter);
- } while(Iter != m_Resources.begin() && m_KernelPtr->GetUsedMemory() > m_MaxMemoryUsage);
+ } while (Iter != m_Resources.begin() && m_KernelPtr->GetUsedMemory() > m_MaxMemoryUsage);
}
-void BS_ResourceManager::EmptyCache()
-{
- // Resourcenliste durchlaufen und alle nicht gelockten Resourcen freigeben
- std::list<BS_Resource*>::iterator Iter = m_Resources.begin();
- while (Iter != m_Resources.end())
- {
- if ((*Iter)->GetLockCount() == 0)
- {
- // Resource entfernen
+/**
+ * Releases all resources that are not locked.
+ **/
+void BS_ResourceManager::EmptyCache() {
+ // Scan through the resource list
+ Common::List<BS_Resource *>::iterator Iter = m_Resources.begin();
+ while (Iter != m_Resources.end()) {
+ if ((*Iter)->GetLockCount() == 0) {
+ // Delete the resource
Iter = DeleteResource(*Iter);
- }
- else
+ } else
++Iter;
}
}
-BS_Resource* BS_ResourceManager::RequestResource(const std::string& FileName)
-{
- // Absoluten, eindeutigen Pfad zur Datei erzeugen.
- std::string UniqueFileName = GetUniqueFileName(FileName);
+/**
+ * Returns a requested resource. If any error occurs, returns NULL
+ * @param FileName Filename of resource
+ */
+BS_Resource *BS_ResourceManager::RequestResource(const Common::String &FileName) {
+ // Get the absolute path to the file
+ Common::String UniqueFileName = GetUniqueFileName(FileName);
if (UniqueFileName == "")
return NULL;
- // Feststellen, ob die Resource schon geladen ist.
- // Wenn die Resource gefunden wurde wird sie an die Spitze der Resourcenliste gestellt, gelockt und zurückgegeben.
+ // Determine whether the resource is already loaded
+ // If the resource is found, it will be placed at the head of the resource list and returned
{
- BS_Resource* pResource = GetResource(UniqueFileName);
- if (pResource)
- {
+ BS_Resource *pResource = GetResource(UniqueFileName);
+ if (pResource) {
MoveToFront(pResource);
(pResource)->AddReference();
return pResource;
}
}
- // Die Resource wurde nicht gefunden, muss also noch geladen werden.
+ // The resource was not found, therefore, must not be loaded yet
if (m_LogCacheMiss) BS_LOG_WARNINGLN("\"%s\" was not precached.", UniqueFileName.c_str());
- BS_Resource* pResource;
- if (pResource = LoadResource(UniqueFileName))
- {
+ BS_Resource *pResource;
+ if (pResource = LoadResource(UniqueFileName)) {
pResource->AddReference();
return pResource;
}
@@ -147,31 +158,31 @@ BS_Resource* BS_ResourceManager::RequestResource(const std::string& FileName)
return NULL;
}
-bool BS_ResourceManager::PrecacheResource(const std::string& FileName, bool ForceReload)
-{
- // Absoluten, eindeutigen Pfad zur Datei erzeugen.
- std::string UniqueFileName = GetUniqueFileName(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.
+ * This is useful for files that may have changed in the interim
+ */
+bool BS_ResourceManager::PrecacheResource(const Common::String& FileName, bool ForceReload) {
+ // Get the absolute path to the file
+ Common::String UniqueFileName = GetUniqueFileName(FileName);
if (UniqueFileName == "")
return false;
- BS_Resource * ResourcePtr = GetResource(UniqueFileName);
+ BS_Resource *ResourcePtr = GetResource(UniqueFileName);
- if (ForceReload && ResourcePtr)
- {
- if (ResourcePtr->GetLockCount())
- {
+ if (ForceReload && ResourcePtr) {
+ if (ResourcePtr->GetLockCount()) {
BS_LOG_ERRORLN("Could not force precaching of \"%s\". The resource is locked.", FileName.c_str());
return false;
- }
- else
- {
+ } else {
DeleteResource(ResourcePtr);
ResourcePtr = 0;
}
}
- if (!ResourcePtr && LoadResource(UniqueFileName) == NULL)
- {
+ if (!ResourcePtr && LoadResource(UniqueFileName) == NULL) {
BS_LOG_ERRORLN("Could not precache \"%s\",", FileName.c_str());
return false;
}
@@ -179,39 +190,44 @@ bool BS_ResourceManager::PrecacheResource(const std::string& FileName, bool Forc
return true;
}
-void BS_ResourceManager::MoveToFront(BS_Resource* pResource)
-{
- // Resource aus der Liste löschen
+/**
+ * Moves a resource to the top of the resource list
+ * @param pResource The resource
+ */
+void BS_ResourceManager::MoveToFront(BS_Resource *pResource) {
+ // Erase the resource from it's current position
m_Resources.erase(pResource->_Iterator);
- // Resource an die Spitze der Liste setzen
+ // Re-add the resource at the front of the list
m_Resources.push_front(pResource);
- // Iterator aktualisieren
+ // Reset the resource iterator to the repositioned item
pResource->_Iterator = m_Resources.begin();
}
-BS_Resource* BS_ResourceManager::LoadResource(const std::string& FileName)
-{
+/**
+ * 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
+ */
+BS_Resource *BS_ResourceManager::LoadResource(const Common::String &FileName) {
// ResourceService finden, der die Resource laden kann.
- for(unsigned int i = 0; i < m_ResourceServices.size(); ++i)
- {
- if (m_ResourceServices[i]->CanLoadResource(FileName))
- {
- // Falls mehr Speicher belegt ist als gewünscht, muss Speicher freigegeben werden.
+ for (unsigned int i = 0; i < m_ResourceServices.size(); ++i) {
+ if (m_ResourceServices[i]->CanLoadResource(FileName)) {
+ // If more memory is desired, memory must be released
DeleteResourcesIfNecessary();
- // Resource laden
- BS_Resource* pResource;
- if (!(pResource = m_ResourceServices[i]->LoadResource(FileName)))
- {
+ // Load the resource
+ BS_Resource *pResource;
+ if (!(pResource = m_ResourceServices[i]->LoadResource(FileName))) {
BS_LOG_ERRORLN("Responsible service could not load resource \"%s\".", FileName.c_str());
return NULL;
}
- // Resource an die Spitze der Resourcenliste stellen.
+ // Add the resource to the front of the list
m_Resources.push_front(pResource);
pResource->_Iterator = m_Resources.begin();
- // Resource in die Hashtabelle eintragen
+ // Also store the resource in the hash table for quick lookup
m_ResourceHashTable[pResource->GetFileNameHash() % HASH_TABLE_BUCKETS].push_front(pResource);
return pResource;
@@ -222,47 +238,56 @@ BS_Resource* BS_ResourceManager::LoadResource(const std::string& FileName)
return NULL;
}
-std::string BS_ResourceManager::GetUniqueFileName(const std::string& FileName) const
-{
- // Pointer auf den PackageManager holen
- BS_PackageManager* pPackage = (BS_PackageManager*) m_KernelPtr->GetService("package");
- if (!pPackage)
- {
+/**
+ * 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 {
+ // Get a pointer to the package manager
+ BS_PackageManager *pPackage = (BS_PackageManager *)m_KernelPtr->GetService("package");
+ if (!pPackage) {
BS_LOG_ERRORLN("Could not get package manager.");
- return std::string("");
+ return Common::String("");
}
// Absoluten Pfad der Datei bekommen und somit die Eindeutigkeit des Dateinamens sicherstellen
- std::string UniqueFileName = pPackage->GetAbsolutePath(FileName);
+ Common::String UniqueFileName = pPackage->GetAbsolutePath(FileName);
if (UniqueFileName == "")
BS_LOG_ERRORLN("Could not create absolute file name for \"%s\".", FileName.c_str());
return UniqueFileName;
}
-std::list<BS_Resource*>::iterator BS_ResourceManager::DeleteResource(BS_Resource* pResource)
-{
- // Resource aus der Hash-Tabelle entfernen
+/**
+ * Deletes a resource, removes it from the lists, and updates m_UsedMemory
+ */
+Common::List<BS_Resource *>::iterator BS_ResourceManager::DeleteResource(BS_Resource *pResource) {
+ // Remove the resource from the hash table
m_ResourceHashTable[pResource->GetFileNameHash() % HASH_TABLE_BUCKETS].remove(pResource);
- BS_Resource* pDummy = pResource;
+ BS_Resource *pDummy = pResource;
- // Resource aus der Resourcenliste löschen
- std::list<BS_Resource*>::iterator Result = m_Resources.erase(pResource->_Iterator);
+ // Delete the resource from the resource list
+ Common::List<BS_Resource *>::iterator Result = m_Resources.erase(pResource->_Iterator);
- // Resource freigeben
- delete(pDummy);
+ // Delete the resource
+ delete (pDummy);
- // Iterator zurückgeben
+ // Return the iterator
return Result;
}
-BS_Resource* BS_ResourceManager::GetResource(const std::string& UniqueFileName) const
-{
- // Feststellen, ob die Resource schon geladen ist.
- const std::list<BS_Resource*>& HashBucket = m_ResourceHashTable[BS_String::GetHash(UniqueFileName) % HASH_TABLE_BUCKETS];
+/**
+ * Returns a pointer to a loaded resource. If any error occurs, NULL will be returned.
+ * @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 {
+ // Determine whether the resource is already loaded
+ const Common::List<BS_Resource *>& HashBucket = m_ResourceHashTable[
+ BS_String::GetHash(UniqueFileName) % HASH_TABLE_BUCKETS];
{
- std::list<BS_Resource*>::const_iterator Iter = HashBucket.begin();
+ Common::List<BS_Resource*>::const_iterator Iter = HashBucket.begin();
for (; Iter != HashBucket.end(); ++Iter)
{
// Wenn die Resource gefunden wurde wird sie zurückgegeben.
@@ -275,19 +300,26 @@ BS_Resource* BS_ResourceManager::GetResource(const std::string& UniqueFileName)
return NULL;
}
-void BS_ResourceManager::DumpLockedResources()
-{
- for (std::list<BS_Resource*>::iterator Iter = m_Resources.begin(); Iter != m_Resources.end(); ++Iter)
- {
- if ((*Iter)->GetLockCount() > 0)
- {
+/**
+ * Writes the names of all currently locked resources to the log file
+ */
+void BS_ResourceManager::DumpLockedResources() {
+ for (Common::List<BS_Resource *>::iterator Iter = m_Resources.begin(); Iter != m_Resources.end(); ++Iter) {
+ if ((*Iter)->GetLockCount() > 0) {
BS_LOGLN("%s", (*Iter)->GetFileName().c_str());
}
}
}
-void BS_ResourceManager::SetMaxMemoryUsage(unsigned int MaxMemoryUsage)
-{
+/**
+ * Specifies the maximum amount of memory the engine is allowed to use.
+ * If this value is exceeded, resources will be unloaded to make room. This value is meant
+ * as a guideline, and not as a fixed boundary. It is not guaranteed not to be exceeded;
+ * the whole game engine may still use more memory than any amount specified.
+ */
+void BS_ResourceManager::SetMaxMemoryUsage(unsigned int MaxMemoryUsage) {
m_MaxMemoryUsage = MaxMemoryUsage;
DeleteResourcesIfNecessary();
}
+
+} // End of namespace Sword25
diff --git a/engines/sword25/kernel/resmanager.h b/engines/sword25/kernel/resmanager.h
index 265b5339ee..848ca661d1 100755
--- a/engines/sword25/kernel/resmanager.h
+++ b/engines/sword25/kernel/resmanager.h
@@ -136,9 +136,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
- *
*/
BS_Resource *LoadResource(const Common::String &FileName);
diff --git a/engines/sword25/kernel/resource.cpp b/engines/sword25/kernel/resource.cpp
index 9c7a7ec75f..e98c8aa300 100755
--- a/engines/sword25/kernel/resource.cpp
+++ b/engines/sword25/kernel/resource.cpp
@@ -1,45 +1,51 @@
-// -----------------------------------------------------------------------------
-// This file is part of Broken Sword 2.5
-// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer
-//
-// Broken Sword 2.5 is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// Broken Sword 2.5 is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Broken Sword 2.5; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-// -----------------------------------------------------------------------------
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
#include "sword25/kernel/resource.h"
#include "sword25/kernel/string.h"
#include "sword25/kernel/kernel.h"
#include "sword25/package/packagemanager.h"
+namespace Sword25 {
+
#define BS_LOG_PREFIX "RESOURCE"
-BS_Resource::BS_Resource(const std::string& FileName, RESOURCE_TYPES Type) :
- _Type(Type),
- _RefCount(0)
-{
+BS_Resource::BS_Resource(const Common::String &FileName, RESOURCE_TYPES Type) :
+ _Type(Type),
+ _RefCount(0) {
BS_ASSERT(BS_Kernel::GetInstance()->GetService("package"));
_FileName = static_cast<BS_PackageManager *>(BS_Kernel::GetInstance()->GetService("package"))->GetAbsolutePath(FileName);
_FileNameHash = BS_String::GetHash(FileName);
}
-void BS_Resource::Release()
-{
- if (_RefCount)
- {
+void BS_Resource::Release() {
+ if (_RefCount) {
--_RefCount;
- }
- else
+ } else
BS_LOG_WARNINGLN("Released unlocked resource \"%s\".", _FileName.c_str());
}
+
+} // End of namespace Sword25
diff --git a/engines/sword25/kernel/resource.h b/engines/sword25/kernel/resource.h
index 94088068e7..54eaed5767 100755
--- a/engines/sword25/kernel/resource.h
+++ b/engines/sword25/kernel/resource.h
@@ -1,41 +1,45 @@
-// -----------------------------------------------------------------------------
-// This file is part of Broken Sword 2.5
-// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer
-//
-// Broken Sword 2.5 is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// Broken Sword 2.5 is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Broken Sword 2.5; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-// -----------------------------------------------------------------------------
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
#ifndef SWORD25_RESOURCE_H
#define SWORD25_RESOURCE_H
-#include "sword25/kernel/memlog_off.h"
-#include <list>
-#include "sword25/kernel/memlog_on.h"
-
+#include "common/list.h"
+#include "common/str.h"
#include "sword25/kernel/common.h"
+namespace Sword25 {
+
class BS_Kernel;
class BS_ResourceManager;
-class BS_Resource
-{
+class BS_Resource {
friend class BS_ResourceManager;
public:
- enum RESOURCE_TYPES
- {
+ enum RESOURCE_TYPES {
TYPE_UNKNOWN,
TYPE_BITMAP,
TYPE_ANIMATION,
@@ -43,55 +47,53 @@ public:
TYPE_FONT
};
- BS_Resource(const std::string& UniqueFileName, RESOURCE_TYPES Type);
+ BS_Resource(const Common::String &UniqueFileName, RESOURCE_TYPES Type);
/**
- * @brief `Lockt' die Resource, verhindert, dass sie freigegeben wird.
- * @remarks Die Resource wird bereits `gelockt' initialisiert, sie muss also nach dem Anfordern nur
- * gelockt werden, wenn sie mehrfach verwendet wird.
+ * Prevents the resource from being released.
+ * @remarks This method allows a resource to be locked multiple times.
**/
-
void AddReference() { ++_RefCount; }
/**
- * @brief Hebt ein vorhergehendes `lock' auf.
- * @remarks Die Resource kann ruhig öfter freigegeben als `gelockt' werden, auch wenn das nicht gerade empfehlenswert ist.
+ * Cancels a previous lock
+ * @remarks The resource can still be released more times than it was 'locked', although it is
+ * not recommended.
**/
-
void Release();
/**
- * @brief Gibt die Anzahl der aktuellen `locks' zurück.
- * @return Die Zahl der `locks'.
+ * Returns the current lock count for the resource
+ * @return The current lock count
**/
-
int GetLockCount() const { return _RefCount; }
/**
- @brief Gibt den absoluten, eindeutigen Dateinamen der Resource zurück.
- */
-
- const std::string & GetFileName() const { return _FileName; }
+ * Returns the absolute path of the given resource
+ */
+ const Common::String &GetFileName() const { return _FileName; }
/**
- @brief Gibt den Hash des Dateinames der Resource zurück.
+ * Returns the hash of the filename of a resource
*/
unsigned int GetFileNameHash() const { return _FileNameHash; }
/**
- @brief Gibt den Typ der Ressource zurück.
- */
+ * Returns a resource's type
+ */
unsigned int GetType() const { return _Type; }
protected:
virtual ~BS_Resource() {};
private:
- std::string _FileName; //!< Der absolute Dateiname
- unsigned int _FileNameHash; //!< Der Hashwert des Dateinames
- unsigned int _RefCount; //!< Anzahl an Locks
- unsigned int _Type; //!< Der Typ der Resource
- std::list<BS_Resource*>::iterator _Iterator; //!< Der Iterator zeigt auf Position der Resource in der LRU-Liste
+ 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
+
#endif
diff --git a/engines/sword25/kernel/string.h b/engines/sword25/kernel/string.h
index fcd04805d4..9c5f3d1158 100755
--- a/engines/sword25/kernel/string.h
+++ b/engines/sword25/kernel/string.h
@@ -1,117 +1,97 @@
-// -----------------------------------------------------------------------------
-// This file is part of Broken Sword 2.5
-// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer
-//
-// Broken Sword 2.5 is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// Broken Sword 2.5 is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Broken Sword 2.5; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-// -----------------------------------------------------------------------------
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
#ifndef SWORD25_STRING
#define SWORD25_STRING
-#include "sword25/kernel/memlog_off.h"
-#include <string>
-#include "sword25/kernel/memlog_on.h"
-
-namespace BS_String
-{
- inline unsigned int GetHash(const std::string & Str)
- {
- unsigned int Result = 0;
-
- for (unsigned int i = 0; i < Str.size(); i++)
- Result = ((Result << 5) - Result) + Str[i];
-
- return Result;
- }
-
- inline bool ToInt(const std::string & Str, int & Result)
- {
- std::string::const_iterator Iter = Str.begin();
-
- // Whitespace überspringen
- while (*Iter && (*Iter == ' ' || *Iter == '\t')) { ++Iter; }
- if (Iter == Str.end()) return false;
-
- // Vorzeichen auslesen, wenn vorhanden
- bool IsNegative = false;
- if (*Iter == '-')
- {
- IsNegative = true;
- ++Iter;
- }
- else if (*Iter == '+')
- ++Iter;
-
- // Whitespace überspringen
- while (*Iter && (*Iter == ' ' || *Iter == '\t')) { ++Iter; }
- if (Iter ==Str.end()) return false;
-
- // String in Ganzzahl umwandeln
- Result = 0;
- while (Iter != Str.end())
- {
- if (*Iter < '0' || *Iter > '9')
- {
- while (*Iter && (*Iter == ' ' || *Iter == '\t')) { ++Iter; }
- if (Iter != Str.end()) return false;
- break;
- }
- Result = (Result * 10) + (*Iter - '0');
- ++Iter;
- }
-
- if (IsNegative) Result = -Result;
-
- return true;
- }
-
- inline bool ToBool(const std::string & Str, bool & Result)
- {
- if (Str == "true" ||
- Str == "TRUE")
- {
- Result = true;
- return true;
- }
- else if (Str == "false" ||
- Str == "FALSE")
- {
- Result = false;
- return true;
- }
-
- return false;
- }
-
- inline void ToLower(std::string & Str)
- {
- static const unsigned char LowerCaseMap[256] =
- {
- 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
- 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
- 64,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,91,92,93,94,95,
- 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
- 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
- 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
- 192,193,194,195,228,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,246,215,216,217,218,219,252,221,222,223,
- 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
- };
-
- for (unsigned int i = 0; i < Str.size(); ++i)
- Str[i] = LowerCaseMap[Str[i]];
- }
+#include "common/str.h"
+
+namespace BS_String {
+
+inline unsigned int GetHash(const Common::String &Str) {
+ unsigned int Result = 0;
+
+ for (unsigned int i = 0; i < Str.size(); i++)
+ Result = ((Result << 5) - Result) + Str[i];
+
+ return Result;
+}
+
+inline bool ToInt(const Common::String &Str, int &Result) {
+ Common::String::const_iterator Iter = Str.begin();
+
+ // Skip whitespaces
+ while (*Iter && (*Iter == ' ' || *Iter == '\t')) { ++Iter; }
+ if (Iter == Str.end()) return false;
+
+ // Read sign, if available
+ bool IsNegative = false;
+ if (*Iter == '-') {
+ IsNegative = true;
+ ++Iter;
+ }
+ else if (*Iter == '+')
+ ++Iter;
+
+ // Skip whitespaces
+ 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; }
+ if (Iter != Str.end()) return false;
+ break;
+ }
+ Result = (Result * 10) + (*Iter - '0');
+ ++Iter;
+ }
+
+ if (IsNegative) Result = -Result;
+
+ return true;
}
+inline bool ToBool(const Common::String &Str, bool &Result) {
+ if (Str == "true" || Str == "TRUE") {
+ Result = true;
+ return true;
+ } else if (Str == "false" || Str == "FALSE") {
+ Result = false;
+ return true;
+ }
+
+ return false;
+}
+
+inline void ToLower(Common::String &Str) {
+ Str.toLowercase();
+}
+
+} // End of namespace BS_String
+
#endif