[Scummvm-cvs-logs] SF.net SVN: scummvm:[53211] scummvm/trunk/engines/sword25
sev at users.sourceforge.net
sev at users.sourceforge.net
Wed Oct 13 00:24:38 CEST 2010
Revision: 53211
http://scummvm.svn.sourceforge.net/scummvm/?rev=53211&view=rev
Author: sev
Date: 2010-10-12 22:24:37 +0000 (Tue, 12 Oct 2010)
Log Message:
-----------
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.
Modified Paths:
--------------
scummvm/trunk/engines/sword25/gfx/graphicengine.h
scummvm/trunk/engines/sword25/gfx/renderobject.h
scummvm/trunk/engines/sword25/gfx/renderobjectregistry.h
scummvm/trunk/engines/sword25/kernel/objectregistry.h
scummvm/trunk/engines/sword25/kernel/persistenceservice.cpp
scummvm/trunk/engines/sword25/math/regionregistry.cpp
scummvm/trunk/engines/sword25/sfx/soundengine.h
Modified: scummvm/trunk/engines/sword25/gfx/graphicengine.h
===================================================================
--- scummvm/trunk/engines/sword25/gfx/graphicengine.h 2010-10-12 22:24:03 UTC (rev 53210)
+++ scummvm/trunk/engines/sword25/gfx/graphicengine.h 2010-10-12 22:24:37 UTC (rev 53211)
@@ -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 @@
* 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 @@
* 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 @@
* @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;
Modified: scummvm/trunk/engines/sword25/gfx/renderobject.h
===================================================================
--- scummvm/trunk/engines/sword25/gfx/renderobject.h 2010-10-12 22:24:03 UTC (rev 53210)
+++ scummvm/trunk/engines/sword25/gfx/renderobject.h 2010-10-12 22:24:37 UTC (rev 53211)
@@ -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 @@
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zur\xFCck.<br>
Falls ein Fehler aufgetreten ist wird ein ung\xFCltiger BS_RenderObjectPtr zur\xFCckgegeben.
*/
- BS_RenderObjectPtr<BS_Bitmap> AddBitmap(const std::string& FileName);
+ BS_RenderObjectPtr<BS_Bitmap> AddBitmap(const Common::String &FileName);
/**
@brief Erzeugt ein ver\xE4nderbares Bitmap als Kinderobjekt des Renderobjektes.
@param Width die Breite des Bitmaps
@@ -121,7 +119,7 @@
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zur\xFCck.<br>
Falls ein Fehler aufgetreten ist wird ein ung\xFCltiger BS_RenderObjectPtr zur\xFCckgegeben.
*/
- 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 @@
Falls ein Fehler aufgetreten ist wird ein ung\xFCltiger BS_RenderObjectPtr zur\xFCckgegeben.
@remark Das Renderobjekt \xFCbernimmt 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 @@
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zur\xFCck.<br>
Falls ein Fehler aufgetreten ist wird ein ung\xFCltiger BS_RenderObjectPtr zur\xFCckgegeben.
*/
- 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 @@
// 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 @@
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 @@
/**
@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 @@
static bool Greater(const BS_RenderObjectPtr<BS_RenderObject> lhs, const BS_RenderObjectPtr<BS_RenderObject> rhs);
};
+} // End of namespace Sword25
+
#endif
Modified: scummvm/trunk/engines/sword25/gfx/renderobjectregistry.h
===================================================================
--- scummvm/trunk/engines/sword25/gfx/renderobjectregistry.h 2010-10-12 22:24:03 UTC (rev 53210)
+++ scummvm/trunk/engines/sword25/gfx/renderobjectregistry.h 2010-10-12 22:24:37 UTC (rev 53211)
@@ -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 @@
static std::auto_ptr<BS_RenderObjectRegistry> m_InstancePtr;
};
+} // End of namespace Sword25
+
#endif
Modified: scummvm/trunk/engines/sword25/kernel/objectregistry.h
===================================================================
--- scummvm/trunk/engines/sword25/kernel/objectregistry.h 2010-10-12 22:24:03 UTC (rev 53210)
+++ scummvm/trunk/engines/sword25/kernel/objectregistry.h 2010-10-12 22:24:37 UTC (rev 53211)
@@ -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\xF6nnen 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\xFCckgeben.
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\xFCckgeben.
- else
- {
+ else {
m_Handle2PtrMap[m_NextHandle] = ObjectPtr;
m_Ptr2HandleMap[ObjectPtr] = m_NextHandle;
@@ -83,31 +82,26 @@
// -----------------------------------------------------------------------------
- unsigned int RegisterObject(T * ObjectPtr, unsigned int Handle)
- {
+ unsigned int RegisterObject(T *ObjectPtr, unsigned int Handle) {
// Null-Pointer und Null-Handle k\xF6nnen 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\xFCckgeben.
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\xFCckgegeben.
- 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\xFCnschte Handle zur\xFCckgeben.
- else
- {
+ else {
m_Handle2PtrMap[Handle] = ObjectPtr;
m_Ptr2HandleMap[ObjectPtr] = Handle;
@@ -121,28 +115,23 @@
// -----------------------------------------------------------------------------
- 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\xF6riges Objekt in der Hash-Map finden.
- T * ObjectPtr = FindPtrByHandle(Handle);
+ T *ObjectPtr = FindPtrByHandle(Handle);
// Pointer zur\xFCckgeben. Im Fehlerfall ist dieser 0.
return ObjectPtr;
@@ -150,8 +139,7 @@
// -----------------------------------------------------------------------------
- unsigned int ResolvePtr(T * ObjectPtr)
- {
+ unsigned int ResolvePtr(T *ObjectPtr) {
// Zum Pointer geh\xF6riges Handle in der Hash-Map finden.
unsigned int Handle = FindHandleByPtr(ObjectPtr);
@@ -160,39 +148,49 @@
}
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;
unsigned int m_NextHandle;
// -----------------------------------------------------------------------------
- T * FindPtrByHandle(unsigned int Handle)
- {
+ T *FindPtrByHandle(unsigned int Handle) {
// Zum Handle geh\xF6rigen Pointer finden.
HANDLE2PTR_MAP::const_iterator it = m_Handle2PtrMap.find(Handle);
// Pointer zur\xFCckgeben, oder, falls keiner gefunden wurde, 0 zur\xFCckgeben.
- 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\xF6riges Handle finden.
PTR2HANDLE_MAP::const_iterator it = m_Ptr2HandleMap.find(ObjectPtr);
// Handle zur\xFCckgeben, oder, falls keines gefunden wurde, 0 zur\xFCckgeben.
- 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
Modified: scummvm/trunk/engines/sword25/kernel/persistenceservice.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/persistenceservice.cpp 2010-10-12 22:24:03 UTC (rev 53210)
+++ scummvm/trunk/engines/sword25/kernel/persistenceservice.cpp 2010-10-12 22:24:37 UTC (rev 53211)
@@ -405,32 +405,31 @@
}
#endif
- Bytef *UncompressedDataBuffer = new Bytef[CurSavegameInfo.GamedataUncompressedLength];
- {
- // Komprimierte gespeicherte Spieldaten laden.
- vector<unsigned char> CompressedDataBuffer(CurSavegameInfo.GamedataLength);
- {
- File = sfm->openForLoading(GenerateSavegamePath(SlotID));
+ byte *CompressedDataBuffer = new byte[CurSavegameInfo.GamedataLength];
+ byte *UncompressedDataBuffer = new Bytef[CurSavegameInfo.GamedataUncompressedLength];
- 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;
- }
- }
+ File = sfm->openForLoading(GenerateSavegamePath(SlotID));
- // 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->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);
// Einzelne Engine-Module depersistieren.
@@ -442,6 +441,7 @@
Success &= BS_Kernel::GetInstance()->GetSfx()->Unpersist(Reader);
Success &= BS_Kernel::GetInstance()->GetInput()->Unpersist(Reader);
+ delete[] CompressedDataBuffer;
delete[] UncompressedDataBuffer;
delete File;
Modified: scummvm/trunk/engines/sword25/math/regionregistry.cpp
===================================================================
--- scummvm/trunk/engines/sword25/math/regionregistry.cpp 2010-10-12 22:24:03 UTC (rev 53210)
+++ scummvm/trunk/engines/sword25/math/regionregistry.cpp 2010-10-12 22:24:37 UTC (rev 53211)
@@ -82,10 +82,10 @@
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 @@
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;
Modified: scummvm/trunk/engines/sword25/sfx/soundengine.h
===================================================================
--- scummvm/trunk/engines/sword25/sfx/soundengine.h 2010-10-12 22:24:03 UTC (rev 53210)
+++ scummvm/trunk/engines/sword25/sfx/soundengine.h 2010-10-12 22:24:37 UTC (rev 53211)
@@ -166,7 +166,7 @@
* @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 @@
* @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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list