aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25
diff options
context:
space:
mode:
authorPaul Gilbert2010-08-05 11:52:13 +0000
committerEugene Sandulenko2010-10-12 22:24:37 +0000
commitccba0891fdce8e043fbb7cc5e4015590ab8a7b6b (patch)
tree7973836cdf496e380790a33cc4e049df6c71e7ef /engines/sword25
parent7bc8cd284a0929f67b51dd9ffbd6dd6ce09f0746 (diff)
downloadscummvm-rg350-ccba0891fdce8e043fbb7cc5e4015590ab8a7b6b.tar.gz
scummvm-rg350-ccba0891fdce8e043fbb7cc5e4015590ab8a7b6b.tar.bz2
scummvm-rg350-ccba0891fdce8e043fbb7cc5e4015590ab8a7b6b.zip
SWORD25: Converted further files from old hashmap.h to Common::HashMap
This commit includes a class pointer hash function added in objectregistry.h that should be double-checked to see if it's correct. svn-id: r53211
Diffstat (limited to 'engines/sword25')
-rw-r--r--engines/sword25/gfx/graphicengine.h8
-rw-r--r--engines/sword25/gfx/renderobject.h30
-rw-r--r--engines/sword25/gfx/renderobjectregistry.h10
-rw-r--r--engines/sword25/kernel/objectregistry.h84
-rw-r--r--engines/sword25/kernel/persistenceservice.cpp46
-rw-r--r--engines/sword25/math/regionregistry.cpp7
-rw-r--r--engines/sword25/sfx/soundengine.h4
7 files changed, 96 insertions, 93 deletions
diff --git a/engines/sword25/gfx/graphicengine.h b/engines/sword25/gfx/graphicengine.h
index 7113f6f7ea..3ebe591923 100644
--- a/engines/sword25/gfx/graphicengine.h
+++ b/engines/sword25/gfx/graphicengine.h
@@ -44,6 +44,8 @@
#define SWORD25_GRAPHICENGINE_H
// Includes
+#include "common/array.h"
+#include "common/str.h"
#include "sword25/kernel/common.h"
#include "sword25/kernel/bs_stdint.h"
#include "sword25/kernel/resservice.h"
@@ -178,7 +180,7 @@ public:
* Notes: This method should only be called after a call to EndFrame(), and before the next call to StartFrame().
* @param Filename The filename for the screenshot
*/
- bool SaveScreenshot(const std::string & Filename);
+ bool SaveScreenshot(const Common::String &Filename);
/**
* Creates a thumbnail with the dimensions of 200x125. This will not include the top and bottom of the screen..
@@ -187,7 +189,7 @@ public:
* The frame buffer must have a resolution of 800x600.
* @param Filename The filename for the screenshot
*/
- bool SaveThumbnailScreenshot(const std::string & Filename);
+ bool SaveThumbnailScreenshot(const Common::String &Filename);
/**
* Reads the current contents of the frame buffer
@@ -197,7 +199,7 @@ public:
* @param Height Returns the height of the frame buffer
* @param Data Returns the raw data of the frame buffer as an array of 32-bit colour values.
*/
- virtual bool GetScreenshot(unsigned int & Width, unsigned int & Height, std::vector<unsigned int> & Data) = 0;
+ virtual bool GetScreenshot(unsigned int &Width, unsigned int &Height, Common::Array<unsigned int> &Data) = 0;
virtual BS_RenderObjectPtr<BS_Panel> GetMainPanel() = 0;
diff --git a/engines/sword25/gfx/renderobject.h b/engines/sword25/gfx/renderobject.h
index fefff3fd34..5d1a348125 100644
--- a/engines/sword25/gfx/renderobject.h
+++ b/engines/sword25/gfx/renderobject.h
@@ -46,15 +46,13 @@
#define SWORD25_RENDEROBJECT_H
// Includes
-#include "sword25/kernel/memlog_off.h"
-#include <vector>
-#include "sword25/kernel/memlog_on.h"
-
#include "sword25/kernel/common.h"
#include "sword25/kernel/persistable.h"
#include "sword25/math/rect.h"
#include "sword25/gfx/renderobjectptr.h"
+namespace Sword25 {
+
// -----------------------------------------------------------------------------
// Forward Declarations
// -----------------------------------------------------------------------------
@@ -106,7 +104,7 @@ public:
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
*/
- BS_RenderObjectPtr<BS_Bitmap> AddBitmap(const std::string& FileName);
+ BS_RenderObjectPtr<BS_Bitmap> AddBitmap(const Common::String &FileName);
/**
@brief Erzeugt ein veränderbares Bitmap als Kinderobjekt des Renderobjektes.
@param Width die Breite des Bitmaps
@@ -121,7 +119,7 @@ public:
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
*/
- BS_RenderObjectPtr<BS_Animation> AddAnimation(const std::string& FileName);
+ BS_RenderObjectPtr<BS_Animation> AddAnimation(const Common::String &FileName);
/**
@brief Erzeugt eine Animation auf Basis eines Animationstemplate als Kinderobjekt des Renderobjektes.
@param pAnimationTemplate ein Pointer auf das Animationstemplate
@@ -129,7 +127,7 @@ public:
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
@remark Das Renderobjekt übernimmt die Verwaltung des Animationstemplate.
*/
- BS_RenderObjectPtr<BS_Animation> AddAnimation(const BS_AnimationTemplate & AnimationTemplate);
+ BS_RenderObjectPtr<BS_Animation> AddAnimation(const BS_AnimationTemplate &AnimationTemplate);
/**
@brief Erzeugt ein neues Farbpanel als Kinderobjekt des Renderobjektes.
@param Width die Breite des Panels
@@ -149,7 +147,7 @@ public:
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
*/
- BS_RenderObjectPtr<BS_Text> AddText(const std::string & Font, const std::string & Text = "");
+ BS_RenderObjectPtr<BS_Text> AddText(const Common::String &Font, const Common::String &Text = "");
// Cast-Methoden
// -------------
@@ -330,13 +328,13 @@ public:
// Persistenz-Methoden
// -------------------
- virtual bool Persist(BS_OutputPersistenceBlock & Writer);
- virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
+ virtual bool Persist(BS_OutputPersistenceBlock &Writer);
+ virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
// TODO: Evtl. protected
- bool PersistChildren(BS_OutputPersistenceBlock & Writer);
- bool UnpersistChildren(BS_InputPersistenceBlock & Reader);
+ bool PersistChildren(BS_OutputPersistenceBlock &Writer);
+ bool UnpersistChildren(BS_InputPersistenceBlock &Reader);
// TODO: Evtl. private
- BS_RenderObjectPtr<BS_RenderObject> RecreatePersistedRenderObject(BS_InputPersistenceBlock & Reader);
+ BS_RenderObjectPtr<BS_RenderObject> RecreatePersistedRenderObject(BS_InputPersistenceBlock &Reader);
protected:
// Typen
@@ -365,7 +363,7 @@ protected:
bool m_OldVisible;
/// Ein Pointer auf den BS_RenderObjektManager, der das Objekt verwaltet.
- BS_RenderObjectManager* m_ManagerPtr;
+ BS_RenderObjectManager *m_ManagerPtr;
// Render-Methode
// --------------
@@ -446,7 +444,7 @@ private:
/**
@brief Berechnet die absolute Position des Objektes.
*/
- void CalcAbsolutePos(int& X, int& Y) const;
+ void CalcAbsolutePos(int &X, int &Y) const;
/**
@brief Berechnet die absolute Position des Objektes auf der X-Achse.
*/
@@ -489,4 +487,6 @@ private:
static bool Greater(const BS_RenderObjectPtr<BS_RenderObject> lhs, const BS_RenderObjectPtr<BS_RenderObject> rhs);
};
+} // End of namespace Sword25
+
#endif
diff --git a/engines/sword25/gfx/renderobjectregistry.h b/engines/sword25/gfx/renderobjectregistry.h
index 21dcb4fe40..abae86def7 100644
--- a/engines/sword25/gfx/renderobjectregistry.h
+++ b/engines/sword25/gfx/renderobjectregistry.h
@@ -52,15 +52,15 @@
class BS_RenderObject;
+namespace Sword25 {
+
// -----------------------------------------------------------------------------
// Klassendeklaration
// -----------------------------------------------------------------------------
-class BS_RenderObjectRegistry : public BS_ObjectRegistry<BS_RenderObject>
-{
+class BS_RenderObjectRegistry : public BS_ObjectRegistry<BS_RenderObject> {
public:
- static BS_RenderObjectRegistry & GetInstance()
- {
+ static BS_RenderObjectRegistry & GetInstance() {
if (!m_InstancePtr.get()) m_InstancePtr.reset(new BS_RenderObjectRegistry);
return *m_InstancePtr.get();
}
@@ -74,4 +74,6 @@ private:
static std::auto_ptr<BS_RenderObjectRegistry> m_InstancePtr;
};
+} // End of namespace Sword25
+
#endif
diff --git a/engines/sword25/kernel/objectregistry.h b/engines/sword25/kernel/objectregistry.h
index 2589a8a7c1..5f708ece21 100644
--- a/engines/sword25/kernel/objectregistry.h
+++ b/engines/sword25/kernel/objectregistry.h
@@ -39,41 +39,40 @@
// Includes
// -----------------------------------------------------------------------------
+#include "common/func.h"
+#include "common/hashmap.h"
+#include "sword25/kernel/bs_stdint.h"
#include "sword25/kernel/common.h"
-#include "sword25/kernel/hashmap.h"
+
+namespace Sword25 {
// -----------------------------------------------------------------------------
// Klassendeklaration
// -----------------------------------------------------------------------------
template<typename T>
-class BS_ObjectRegistry
-{
+class BS_ObjectRegistry {
public:
BS_ObjectRegistry() : m_NextHandle(1) {}
virtual ~BS_ObjectRegistry() {}
// -------------------------------------------------------------------------
- unsigned int RegisterObject(T * ObjectPtr)
- {
+ unsigned int RegisterObject(T *ObjectPtr) {
// Null-Pointer können nicht registriert werden.
- if (ObjectPtr == 0)
- {
+ if (ObjectPtr == 0) {
LogErrorLn("Cannot register a null pointer.");
return 0;
}
// Falls das Objekt bereits registriert wurde, wird eine Warnung ausgeben und das Handle zurückgeben.
unsigned int Handle = FindHandleByPtr(ObjectPtr);
- if (Handle != 0)
- {
+ if (Handle != 0) {
LogWarningLn("Tried to register a object that was already registered.");
return Handle;
}
// Ansonsten wird das Objekt in beide Maps eingetragen und das neue Handle zurückgeben.
- else
- {
+ else {
m_Handle2PtrMap[m_NextHandle] = ObjectPtr;
m_Ptr2HandleMap[ObjectPtr] = m_NextHandle;
@@ -83,31 +82,26 @@ public:
// -----------------------------------------------------------------------------
- unsigned int RegisterObject(T * ObjectPtr, unsigned int Handle)
- {
+ unsigned int RegisterObject(T *ObjectPtr, unsigned int Handle) {
// Null-Pointer und Null-Handle können nicht registriert werden.
- if (ObjectPtr == 0 || Handle == 0)
- {
+ if (ObjectPtr == 0 || Handle == 0) {
LogErrorLn("Cannot register a null pointer or a null handle.");
return 0;
}
// Falls das Objekt bereits registriert wurde, wird ein Fehler ausgegeben und 0 zurückgeben.
unsigned int HandleTest = FindHandleByPtr(ObjectPtr);
- if (HandleTest != 0)
- {
+ if (HandleTest != 0) {
LogErrorLn("Tried to register a object that was already registered.");
return 0;
}
// Falls das Handle bereits vergeben ist, wird ein Fehler ausgegeben und 0 zurückgegeben.
- else if (FindPtrByHandle(Handle) != 0)
- {
+ else if (FindPtrByHandle(Handle) != 0) {
LogErrorLn("Tried to register a handle that is already taken.");
return 0;
}
// Ansonsten wird das Objekt in beide Maps eingetragen und das gewünschte Handle zurückgeben.
- else
- {
+ else {
m_Handle2PtrMap[Handle] = ObjectPtr;
m_Ptr2HandleMap[ObjectPtr] = Handle;
@@ -121,28 +115,23 @@ public:
// -----------------------------------------------------------------------------
- void DeregisterObject(T * ObjectPtr)
- {
+ void DeregisterObject(T *ObjectPtr) {
unsigned int Handle = FindHandleByPtr(ObjectPtr);
- if (Handle != 0)
- {
+ if (Handle != 0) {
// Registriertes Objekt aus beiden Maps entfernen.
m_Handle2PtrMap.erase(FindHandleByPtr(ObjectPtr));
m_Ptr2HandleMap.erase(ObjectPtr);
- }
- else
- {
+ } else {
LogWarningLn("Tried to remove a object that was not registered.");
}
}
// -----------------------------------------------------------------------------
- T * ResolveHandle(unsigned int Handle)
- {
+ T *ResolveHandle(unsigned int Handle) {
// Zum Handle gehöriges Objekt in der Hash-Map finden.
- T * ObjectPtr = FindPtrByHandle(Handle);
+ T *ObjectPtr = FindPtrByHandle(Handle);
// Pointer zurückgeben. Im Fehlerfall ist dieser 0.
return ObjectPtr;
@@ -150,8 +139,7 @@ public:
// -----------------------------------------------------------------------------
- unsigned int ResolvePtr(T * ObjectPtr)
- {
+ unsigned int ResolvePtr(T *ObjectPtr) {
// Zum Pointer gehöriges Handle in der Hash-Map finden.
unsigned int Handle = FindHandleByPtr(ObjectPtr);
@@ -160,8 +148,18 @@ public:
}
protected:
- typedef BS_Hashmap<unsigned int, T *> HANDLE2PTR_MAP;
- typedef BS_Hashmap<T *, unsigned int> PTR2HANDLE_MAP;
+ // 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; }
+ };
+ struct ClassPointer_Hash {
+ 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<T *, unsigned int, ClassPointer_Hash, ClassPointer_EqualTo> PTR2HANDLE_MAP;
HANDLE2PTR_MAP m_Handle2PtrMap;
PTR2HANDLE_MAP m_Ptr2HandleMap;
@@ -169,30 +167,30 @@ protected:
// -----------------------------------------------------------------------------
- T * FindPtrByHandle(unsigned int Handle)
- {
+ T *FindPtrByHandle(unsigned int Handle) {
// Zum Handle gehörigen Pointer finden.
HANDLE2PTR_MAP::const_iterator it = m_Handle2PtrMap.find(Handle);
// Pointer zurückgeben, oder, falls keiner gefunden wurde, 0 zurückgeben.
- return (it != m_Handle2PtrMap.end()) ? it->second : 0;
+ return (it != m_Handle2PtrMap.end()) ? it->_value : 0;
}
// -----------------------------------------------------------------------------
- unsigned int FindHandleByPtr(T * ObjectPtr)
- {
+ unsigned int FindHandleByPtr(T *ObjectPtr) {
// Zum Pointer gehöriges Handle finden.
PTR2HANDLE_MAP::const_iterator it = m_Ptr2HandleMap.find(ObjectPtr);
// Handle zurückgeben, oder, falls keines gefunden wurde, 0 zurückgeben.
- return (it != m_Ptr2HandleMap.end()) ? it->second : 0;
+ return (it != m_Ptr2HandleMap.end()) ? it->_value : 0;
}
// -----------------------------------------------------------------------------
- virtual void LogErrorLn(const char * Message) const = 0;
- virtual void LogWarningLn(const char * Message) const = 0;
+ virtual void LogErrorLn(const char *Message) const = 0;
+ virtual void LogWarningLn(const char *Message) const = 0;
};
+} // End of namespace Sword25
+
#endif
diff --git a/engines/sword25/kernel/persistenceservice.cpp b/engines/sword25/kernel/persistenceservice.cpp
index faf450d880..54203b67dc 100644
--- a/engines/sword25/kernel/persistenceservice.cpp
+++ b/engines/sword25/kernel/persistenceservice.cpp
@@ -405,30 +405,29 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) {
}
#endif
- Bytef *UncompressedDataBuffer = new Bytef[CurSavegameInfo.GamedataUncompressedLength];
- {
- // Komprimierte gespeicherte Spieldaten laden.
- vector<unsigned char> CompressedDataBuffer(CurSavegameInfo.GamedataLength);
- {
- File = sfm->openForLoading(GenerateSavegamePath(SlotID));
-
- File->seek(CurSavegameInfo.GamedataOffset);
- File->read(reinterpret_cast<char *>(&CompressedDataBuffer[0]), CurSavegameInfo.GamedataLength);
- if (File->err()) {
- BS_LOG_ERRORLN("Unable to load the gamedata from the savegame file \"%s\".", CurSavegameInfo.Filename.c_str());
- return false;
- }
- }
+ byte *CompressedDataBuffer = new byte[CurSavegameInfo.GamedataLength];
+ byte *UncompressedDataBuffer = new Bytef[CurSavegameInfo.GamedataUncompressedLength];
- // Spieldaten dekomprimieren.
- uLongf UncompressedBufferSize = CurSavegameInfo.GamedataUncompressedLength;
- if (uncompress(reinterpret_cast<Bytef *>(&UncompressedDataBuffer[0]), &UncompressedBufferSize,
- reinterpret_cast<Bytef *>(&CompressedDataBuffer[0]), CompressedDataBuffer.size()) != Z_OK) {
- BS_LOG_ERRORLN("Unable to decompress the gamedata from savegame file \"%s\".", CurSavegameInfo.Filename.c_str());
- delete[] UncompressedDataBuffer;
- delete File;
- return false;
- }
+ File = sfm->openForLoading(GenerateSavegamePath(SlotID));
+
+ File->seek(CurSavegameInfo.GamedataOffset);
+ File->read(reinterpret_cast<char *>(&CompressedDataBuffer[0]), CurSavegameInfo.GamedataLength);
+ if (File->err()) {
+ BS_LOG_ERRORLN("Unable to load the gamedata from the savegame file \"%s\".", CurSavegameInfo.Filename.c_str());
+ delete[] CompressedDataBuffer;
+ delete[] UncompressedDataBuffer;
+ return false;
+ }
+
+ // Spieldaten dekomprimieren.
+ uLongf UncompressedBufferSize = CurSavegameInfo.GamedataUncompressedLength;
+ if (uncompress(reinterpret_cast<Bytef *>(&UncompressedDataBuffer[0]), &UncompressedBufferSize,
+ 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;
+ delete File;
+ return false;
}
BS_InputPersistenceBlock Reader(&UncompressedDataBuffer[0], CurSavegameInfo.GamedataUncompressedLength);
@@ -442,6 +441,7 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) {
Success &= BS_Kernel::GetInstance()->GetSfx()->Unpersist(Reader);
Success &= BS_Kernel::GetInstance()->GetInput()->Unpersist(Reader);
+ delete[] CompressedDataBuffer;
delete[] UncompressedDataBuffer;
delete File;
diff --git a/engines/sword25/math/regionregistry.cpp b/engines/sword25/math/regionregistry.cpp
index 1611f228ea..f29b92e8b7 100644
--- a/engines/sword25/math/regionregistry.cpp
+++ b/engines/sword25/math/regionregistry.cpp
@@ -82,10 +82,10 @@ bool BS_RegionRegistry::Persist(BS_OutputPersistenceBlock &Writer) {
HANDLE2PTR_MAP::const_iterator Iter = m_Handle2PtrMap.begin();
while (Iter != m_Handle2PtrMap.end()) {
// Handle persistence
- Writer.Write(Iter->first);
+ Writer.Write(Iter->_key);
// Persist object
- Result &= Iter->second->Persist(Writer);
+ Result &= Iter->_value->Persist(Writer);
++Iter;
}
@@ -102,7 +102,8 @@ bool BS_RegionRegistry::Unpersist(BS_InputPersistenceBlock &Reader) {
Reader.Read(m_NextHandle);
// Destroy all existing BS_Regions
- while (!m_Handle2PtrMap.empty()) delete m_Handle2PtrMap.begin()->second;
+//FIXME: This doesn't seem right - the value is being deleted but not the actual hash node itself?
+ while (!m_Handle2PtrMap.empty()) delete m_Handle2PtrMap.begin()->_value;
// Read in the number of BS_Regions
unsigned int RegionCount;
diff --git a/engines/sword25/sfx/soundengine.h b/engines/sword25/sfx/soundengine.h
index c0038eb49c..35bab0c3d6 100644
--- a/engines/sword25/sfx/soundengine.h
+++ b/engines/sword25/sfx/soundengine.h
@@ -166,7 +166,7 @@ public:
* @remark If more control is needed over the playing, eg. changing the sound parameters
* for Volume and Panning, then PlaySoundEx should be used.
*/
- virtual bool PlaySound(const std::string& FileName, SOUND_TYPES Type, float Volume = 1.0f, float Pan = 0.0f, bool Loop = false, int LoopStart = -1, int LoopEnd = -1, unsigned int Layer = 0) = 0;
+ virtual bool PlaySound(const Common::String &FileName, SOUND_TYPES Type, float Volume = 1.0f, float Pan = 0.0f, bool Loop = false, int LoopStart = -1, int LoopEnd = -1, unsigned int Layer = 0) = 0;
/**
* Plays a sound
@@ -183,7 +183,7 @@ public:
* @remark If more control is needed over the playing, eg. changing the sound parameters
* for Volume and Panning, then PlaySoundEx should be used.
*/
- virtual unsigned int PlaySoundEx(const std::string& FileName, SOUND_TYPES Type, float Volume = 1.0f, float Pan = 0.0f, bool Loop = false, int LoopStart = -1, int LoopEnd = -1, unsigned int Layer = 0) = 0;
+ virtual unsigned int PlaySoundEx(const Common::String &FileName, SOUND_TYPES Type, float Volume = 1.0f, float Pan = 0.0f, bool Loop = false, int LoopStart = -1, int LoopEnd = -1, unsigned int Layer = 0) = 0;
/**
* Plays a sound generated at runtime