diff options
-rw-r--r-- | engines/wintermute/Base/BKeyboardState.cpp | 7 | ||||
-rw-r--r-- | engines/wintermute/Sys/SysClass.cpp | 88 | ||||
-rw-r--r-- | engines/wintermute/Sys/SysClass.h | 22 | ||||
-rw-r--r-- | engines/wintermute/Sys/SysClassRegistry.cpp | 25 | ||||
-rw-r--r-- | engines/wintermute/video/VidTheoraPlayer.cpp | 6 |
5 files changed, 89 insertions, 59 deletions
diff --git a/engines/wintermute/Base/BKeyboardState.cpp b/engines/wintermute/Base/BKeyboardState.cpp index 32a5d529eb..c91438dba9 100644 --- a/engines/wintermute/Base/BKeyboardState.cpp +++ b/engines/wintermute/Base/BKeyboardState.cpp @@ -225,6 +225,13 @@ HRESULT CBKeyboardState::Persist(CBPersistMgr *PersistMgr) { PersistMgr->Transfer(TMEMBER(_currentKeyData));
PersistMgr->Transfer(TMEMBER(_currentPrintable));
PersistMgr->Transfer(TMEMBER(_currentShift));
+
+ if (!PersistMgr->_saving) {
+ _keyStates = new uint8[323]; // Hardcoded size for the common/keyboard.h enum
+ for (int i = 0; i < 323; i++) {
+ _keyStates[i] = false;
+ }
+ }
return S_OK;
}
diff --git a/engines/wintermute/Sys/SysClass.cpp b/engines/wintermute/Sys/SysClass.cpp index 30ccf3aa08..dede71b756 100644 --- a/engines/wintermute/Sys/SysClass.cpp +++ b/engines/wintermute/Sys/SysClass.cpp @@ -35,8 +35,6 @@ namespace WinterMute {
-// TODO: Note that the set was removed, this might have bizarre side-effects.
-
//////////////////////////////////////////////////////////////////////////
CSysClass::CSysClass(const AnsiString &name, PERSISTBUILD build, PERSISTLOAD load, bool persistent_class) {
_name = name;
@@ -60,11 +58,11 @@ CSysClass::~CSysClass() { //////////////////////////////////////////////////////////////////////////
bool CSysClass::RemoveAllInstances() {
- InstanceMap::iterator it;
- for (it = _instanceMap.begin(); it != _instanceMap.end(); ++it) {
+ Instances::iterator it;
+ for (it = _instances.begin(); it != _instances.end(); ++it) {
delete(it->_value);
}
- //_instances.clear();
+ _instances.clear();
_instanceMap.clear();
return true;
@@ -74,7 +72,7 @@ bool CSysClass::RemoveAllInstances() { CSysInstance *CSysClass::AddInstance(void *instance, int id, int savedId) {
CSysInstance *inst = new CSysInstance(instance, id, this);
inst->SetSavedID(savedId);
- //_instances.insert(inst);
+ _instances[inst] = (inst);
_instanceMap[instance] = inst;
@@ -88,14 +86,13 @@ CSysInstance *CSysClass::AddInstance(void *instance, int id, int savedId) { bool CSysClass::RemoveInstance(void *instance) {
InstanceMap::iterator mapIt = _instanceMap.find(instance);
if (mapIt == _instanceMap.end()) return false;
- /*
- Instances::iterator it = _instances.find((*mapIt).second);
- if (it != _instances.end()) {
- delete(*it);
- _instances.erase(it);
- }*/
-
- delete mapIt->_value;
+
+ Instances::iterator it = _instances.find((mapIt->_value));
+ if (it != _instances.end()) {
+ delete(it->_value);
+ _instances.erase(it);
+ }
+
_instanceMap.erase(mapIt);
return false;
@@ -105,18 +102,14 @@ bool CSysClass::RemoveInstance(void *instance) { int CSysClass::GetInstanceID(void *pointer) {
InstanceMap::iterator mapIt = _instanceMap.find(pointer);
if (mapIt == _instanceMap.end()) return -1;
- else return (*mapIt)._value->GetID();
+ else return (mapIt->_value)->GetID();
}
//////////////////////////////////////////////////////////////////////////
void *CSysClass::IDToPointer(int savedID) {
//slow
- /*Instances::iterator it;
+ Instances::iterator it;
for (it = _instances.begin(); it != _instances.end(); ++it) {
- if ((*it)->GetSavedID() == savedID) return (*it)->GetInstance();
- }*/
- InstanceMap::iterator it;
- for (it = _instanceMap.begin(); it != _instanceMap.end(); ++it) {
if ((it->_value)->GetSavedID() == savedID) return (it->_value)->GetInstance();
}
return NULL;
@@ -124,58 +117,59 @@ void *CSysClass::IDToPointer(int savedID) { //////////////////////////////////////////////////////////////////////////
int CSysClass::GetNumInstances() {
- //return _instances.size();
- return _instanceMap.size(); // TODO: This might break, if we have multiple keys per value.
+ return _instances.size();
}
//////////////////////////////////////////////////////////////////////////
void CSysClass::Dump(Common::WriteStream *stream) {
- Common::String str = Common::String::format("%03d %c %-20s instances: %d\n", _iD, _persistent ? 'p' : ' ', _name.c_str(), GetNumInstances());
- stream->writeString(str);
+ //fprintf(stream, "%03d %c %-20s instances: %d\n", _iD, _persistent ? 'p' : ' ', _name.c_str(), GetNumInstances());
+ Common::String str;
+ str = Common::String::format("%03d %c %-20s instances: %d\n", _iD, _persistent ? 'p' : ' ', _name.c_str(), GetNumInstances());
+ stream->write(str.c_str(), str.size());
}
//////////////////////////////////////////////////////////////////////////
void CSysClass::SaveTable(CBGame *Game, CBPersistMgr *PersistMgr) {
+ warning("Saving %d:%s with %d instancces", _iD, _name.c_str(), _instances.size());
PersistMgr->PutString(_name.c_str());
PersistMgr->PutDWORD(_iD);
- PersistMgr->PutDWORD(_instanceMap.size());
+ PersistMgr->PutDWORD(_instances.size());
- InstanceMap::iterator it;
- for (it = _instanceMap.begin(); it != _instanceMap.end(); ++it) {
- PersistMgr->PutDWORD((it->_value)->GetID());
- }
- /*
Instances::iterator it;
for (it = _instances.begin(); it != _instances.end(); ++it) {
- PersistMgr->PutDWORD((*it)->GetID());
- }*/
+ PersistMgr->PutDWORD((it->_value)->GetID());
+ }
}
//////////////////////////////////////////////////////////////////////////
void CSysClass::LoadTable(CBGame *Game, CBPersistMgr *PersistMgr) {
_savedID = PersistMgr->GetDWORD();
int numInstances = PersistMgr->GetDWORD();
-
+ warning("Loading table for %d:%s with %d instances", _savedID, _name.c_str(), numInstances);
for (int i = 0; i < numInstances; i++) {
+ int instID = PersistMgr->GetDWORD();
+ warning("Loaded instanceID: %d", instID);
if (_persistent) {
- int instId = PersistMgr->GetDWORD();
if (i > 0) {
Game->LOG(0, "Warning: attempting to load multiple instances of persistent class %s (%d)", _name.c_str(), numInstances);
continue;
}
- InstanceMap::iterator it = _instanceMap.begin();
- /* Instances::iterator it = _instances.begin();*/
- if (it != _instanceMap.end()) {
- (it->_value)->SetSavedID(instId);
+ Instances::iterator it = _instances.begin();
+ if (it != _instances.end()) {
+ (it->_value)->SetSavedID(instID);
CSysClassRegistry::GetInstance()->AddInstanceToTable((it->_value), (it->_value)->GetInstance());
} else Game->LOG(0, "Warning: instance %d of persistent class %s not found", i, _name.c_str());
}
// normal instances, create empty objects
else {
void *emptyObject = _build();
- AddInstance(emptyObject, CSysClassRegistry::GetInstance()->GetNextID(), PersistMgr->GetDWORD());
+ if (!emptyObject) {
+ warning("HALT");
+ }
+
+ AddInstance(emptyObject, CSysClassRegistry::GetInstance()->GetNextID(), instID);
}
}
@@ -183,13 +177,15 @@ void CSysClass::LoadTable(CBGame *Game, CBPersistMgr *PersistMgr) { //////////////////////////////////////////////////////////////////////////
void CSysClass::SaveInstances(CBGame *Game, CBPersistMgr *PersistMgr) {
- InstanceMap::iterator it;
- for (it = _instanceMap.begin(); it != _instanceMap.end(); ++it) {
+ Instances::iterator it;
+ for (it = _instances.begin(); it != _instances.end(); ++it) {
// write instace header
+ PersistMgr->PutString("<INSTANCE_HEAD>");
PersistMgr->PutDWORD(_iD);
PersistMgr->PutDWORD((it->_value)->GetID());
-
+ PersistMgr->PutString("</INSTANCE_HEAD>");
_load((it->_value)->GetInstance(), PersistMgr);
+ PersistMgr->PutString("</INSTANCE>");
}
}
@@ -201,16 +197,16 @@ void CSysClass::LoadInstance(void *instance, CBPersistMgr *PersistMgr) { //////////////////////////////////////////////////////////////////////////
void CSysClass::ResetSavedIDs() {
- InstanceMap::iterator it;
- for (it = _instanceMap.begin(); it != _instanceMap.end(); ++it) {
+ Instances::iterator it;
+ for (it = _instances.begin(); it != _instances.end(); ++it) {
(it->_value)->SetSavedID(-1);
}
}
//////////////////////////////////////////////////////////////////////////
void CSysClass::InstanceCallback(SYS_INSTANCE_CALLBACK lpCallback, void *lpData) {
- InstanceMap::iterator it;
- for (it = _instanceMap.begin(); it != _instanceMap.end(); ++it) {
+ Instances::iterator it;
+ for (it = _instances.begin(); it != _instances.end(); ++it) {
lpCallback((it->_value)->GetInstance(), lpData);
}
}
diff --git a/engines/wintermute/Sys/SysClass.h b/engines/wintermute/Sys/SysClass.h index c81e38ee43..a2575c262c 100644 --- a/engines/wintermute/Sys/SysClass.h +++ b/engines/wintermute/Sys/SysClass.h @@ -35,6 +35,14 @@ #include "common/func.h"
#include "common/stream.h"
+namespace WinterMute {
+class CSysInstance;
+class CBGame;
+class CBPersistMgr;
+class CSysClass;
+
+}
+
namespace Common {
template<typename T> struct Hash;
@@ -44,12 +52,17 @@ template<> struct Hash<void *> : public UnaryFunction<void *, uint> { }
};
+template<> struct Hash<WinterMute::CSysInstance*> : public UnaryFunction<WinterMute::CSysInstance*, uint> {
+ uint operator()(WinterMute::CSysInstance* val) const {
+ return (uint)((size_t)val);
+ }
+};
+
+
}
namespace WinterMute {
-class CSysInstance;
-class CBGame;
-class CBPersistMgr;
+
class CSysClass {
public:
CSysClass(const AnsiString &name, PERSISTBUILD build, PERSISTLOAD load, bool persistent_class);
@@ -105,7 +118,8 @@ private: PERSISTLOAD _load;
//typedef std::set<CSysInstance *> Instances;
- //Instances _instances;
+ typedef Common::HashMap<CSysInstance *, CSysInstance *> Instances;
+ Instances _instances;
typedef Common::HashMap<void *, CSysInstance *> InstanceMap;
InstanceMap _instanceMap;
diff --git a/engines/wintermute/Sys/SysClassRegistry.cpp b/engines/wintermute/Sys/SysClassRegistry.cpp index 1a644c3a61..a7d401c5bb 100644 --- a/engines/wintermute/Sys/SysClassRegistry.cpp +++ b/engines/wintermute/Sys/SysClassRegistry.cpp @@ -148,9 +148,20 @@ void *CSysClassRegistry::IDToPointer(int classID, int instanceID) { else return (*it)._value->GetInstance();
}
+bool checkHeader(const char* tag, CBPersistMgr *pm) {
+ char *test = pm->GetString();
+ Common::String verify = test;
+ delete[] test;
+ bool retVal = (verify == tag);
+ if (!retVal) {
+ error("Expected %s in Save-file not found", tag);
+ }
+ return retVal;
+}
//////////////////////////////////////////////////////////////////////////
HRESULT CSysClassRegistry::SaveTable(CBGame *Game, CBPersistMgr *PersistMgr, bool quickSave) {
+ PersistMgr->PutString("<CLASS_REGISTRY_TABLE>");
PersistMgr->PutDWORD(_classes.size());
int counter = 0;
@@ -167,16 +178,17 @@ HRESULT CSysClassRegistry::SaveTable(CBGame *Game, CBPersistMgr *PersistMgr, boo (it->_value)->SaveTable(Game, PersistMgr);
}
-
+ PersistMgr->PutString("</CLASS_REGISTRY_TABLE>");
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
HRESULT CSysClassRegistry::LoadTable(CBGame *Game, CBPersistMgr *PersistMgr) {
- Classes::iterator it;
+ checkHeader("<CLASS_REGISTRY_TABLE>", PersistMgr);
// reset SavedID of current instances
+ Classes::iterator it;
for (it = _classes.begin(); it != _classes.end(); ++it) {
(it->_value)->ResetSavedIDs();
}
@@ -188,7 +200,6 @@ HRESULT CSysClassRegistry::LoadTable(CBGame *Game, CBPersistMgr *PersistMgr) { _instanceMap.clear();
-
int numClasses = PersistMgr->GetDWORD();
for (int i = 0; i < numClasses; i++) {
@@ -201,6 +212,8 @@ HRESULT CSysClassRegistry::LoadTable(CBGame *Game, CBPersistMgr *PersistMgr) { if (mapIt != _nameMap.end())(*mapIt)._value->LoadTable(Game, PersistMgr);
}
+ checkHeader("</CLASS_REGISTRY_TABLE>", PersistMgr);
+
return S_OK;
}
@@ -237,7 +250,6 @@ HRESULT CSysClassRegistry::SaveInstances(CBGame *Game, CBPersistMgr *PersistMgr, return S_OK;
}
-
//////////////////////////////////////////////////////////////////////////
HRESULT CSysClassRegistry::LoadInstances(CBGame *Game, CBPersistMgr *PersistMgr) {
// get total instances
@@ -250,17 +262,22 @@ HRESULT CSysClassRegistry::LoadInstances(CBGame *Game, CBPersistMgr *PersistMgr) Game->_renderer->Flip();
}
+ checkHeader("<INSTANCE_HEAD>", PersistMgr);
+
int classID = PersistMgr->GetDWORD();
int instanceID = PersistMgr->GetDWORD();
void *instance = IDToPointer(classID, instanceID);
+ checkHeader("</INSTANCE_HEAD>", PersistMgr);
Classes::iterator it;
for (it = _classes.begin(); it != _classes.end(); ++it) {
if ((it->_value)->GetSavedID() == classID) {
(it->_value)->LoadInstance(instance, PersistMgr);
+ break;
}
}
+ checkHeader("</INSTANCE>", PersistMgr);
}
_savedInstanceMap.clear();
diff --git a/engines/wintermute/video/VidTheoraPlayer.cpp b/engines/wintermute/video/VidTheoraPlayer.cpp index d64a6f2bb1..d0553a4ffd 100644 --- a/engines/wintermute/video/VidTheoraPlayer.cpp +++ b/engines/wintermute/video/VidTheoraPlayer.cpp @@ -816,12 +816,8 @@ HRESULT CVidTheoraPlayer::Persist(CBPersistMgr *PersistMgr) { PersistMgr->Transfer(TMEMBER(_playZoom)); PersistMgr->Transfer(TMEMBER_INT(_playbackType)); PersistMgr->Transfer(TMEMBER(_looping)); + PersistMgr->Transfer(TMEMBER(_volume)); - if (PersistMgr->CheckVersion(1, 7, 3)) { - PersistMgr->Transfer(TMEMBER(_volume)); - } else { - _volume = 100; - } return S_OK; } |