aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2013-12-08 16:51:50 -0500
committerPaul Gilbert2013-12-08 16:51:50 -0500
commitfc7c1cd33e21c7fd9b78764ee7bb02e35733fbac (patch)
tree0216521249932a483773593bbe44906955727617
parentce3cb58d1511aa7de1dfad5bc92149559b4450f6 (diff)
downloadscummvm-rg350-fc7c1cd33e21c7fd9b78764ee7bb02e35733fbac.tar.gz
scummvm-rg350-fc7c1cd33e21c7fd9b78764ee7bb02e35733fbac.tar.bz2
scummvm-rg350-fc7c1cd33e21c7fd9b78764ee7bb02e35733fbac.zip
VOYEUR: More thread/stack initialisation
-rw-r--r--engines/voyeur/files.cpp31
-rw-r--r--engines/voyeur/files.h20
-rw-r--r--engines/voyeur/voyeur.h5
-rw-r--r--engines/voyeur/voyeur_game.cpp47
4 files changed, 94 insertions, 9 deletions
diff --git a/engines/voyeur/files.cpp b/engines/voyeur/files.cpp
index b17f324ffe..8f188fa3c8 100644
--- a/engines/voyeur/files.cpp
+++ b/engines/voyeur/files.cpp
@@ -276,6 +276,11 @@ void BoltFile::freeBoltGroup(uint32 id) {
_state._curGroupPtr->unload();
}
+void BoltFile::freeBoltMember(uint32 id) {
+ // TODO: Determine whether this is needed
+ warning("TODO: BoltFile::freeBoltMember");
+}
+
BoltEntry &BoltFile::getBoltEntryFromLong(uint32 id) {
BoltGroup &group = _groups[id >> 24];
assert(group._loaded);
@@ -532,6 +537,9 @@ StampBoltFile::StampBoltFile(BoltFilesState &state): BoltFile("stampblt.blt", st
void StampBoltFile::initResource(int resType) {
switch (resType) {
+ case 0:
+ initThread();
+ break;
case 6:
initPtr();
break;
@@ -544,6 +552,13 @@ void StampBoltFile::initResource(int resType) {
}
}
+void StampBoltFile::initThread() {
+ initDefault();
+
+ _state._curMemberPtr->_threadResource = new ThreadResource(_state,
+ _state._curMemberPtr->_data);
+}
+
void StampBoltFile::initPtr() {
initDefault();
@@ -611,6 +626,7 @@ BoltEntry::BoltEntry(Common::SeekableReadStream *f): _file(f) {
_vInitCyclResource = NULL;
_ptrResource = NULL;
_controlResource = NULL;
+ _threadResource = NULL;
byte buffer[16];
_file->read(&buffer[0], 16);
@@ -646,7 +662,8 @@ void BoltEntry::load() {
bool BoltEntry::hasResource() const {
return _picResource || _viewPortResource || _viewPortListResource
|| _fontResource || _fontInfoResource || _cMapResource
- || _vInitCyclResource || _ptrResource || _controlResource;
+ || _vInitCyclResource || _ptrResource || _controlResource
+ || _threadResource;
}
/*------------------------------------------------------------------------*/
@@ -1288,6 +1305,11 @@ VInitCyclResource::VInitCyclResource(BoltFilesState &state, const byte *src) {
/*------------------------------------------------------------------------*/
+ThreadResource::ThreadResource(BoltFilesState &state, const byte *src) {
+}
+
+/*------------------------------------------------------------------------*/
+
PtrResource::PtrResource(BoltFilesState &state, const byte *src) {
// Load pointer list
uint32 *idP = (uint32 *)&src[0];
@@ -1308,6 +1330,11 @@ ControlResource::ControlResource(BoltFilesState &state, const byte *src) {
uint32 ptrId = READ_LE_UINT32(&src[0x32]);
_ptr = state._curLibPtr->getBoltEntryFromLong(ptrId)._data;
+ for (int i = 0; i < 8; ++i) {
+ _memberIds[i] = READ_LE_UINT16(src + i * 2);
+ _entries[i] = NULL;
+ }
+
// Load pointer list
uint32 *idP = (uint32 *)&src[0x10];
int count = READ_LE_UINT16(&src[0x36]);
@@ -1316,7 +1343,7 @@ ControlResource::ControlResource(BoltFilesState &state, const byte *src) {
uint32 id = READ_LE_UINT32(idP);
BoltEntry &entry = state._curLibPtr->getBoltEntryFromLong(id);
- _entries.push_back(entry._data);
+ _entries[i] = entry._data;
}
}
diff --git a/engines/voyeur/files.h b/engines/voyeur/files.h
index 584328c853..8cb7fc8b22 100644
--- a/engines/voyeur/files.h
+++ b/engines/voyeur/files.h
@@ -43,6 +43,7 @@ class CMapResource;
class VInitCyclResource;
class PtrResource;
class ControlResource;
+class ThreadResource;
#define DECOMPRESS_SIZE 0x7000
@@ -120,6 +121,7 @@ public:
bool getBoltGroup(uint32 id);
void freeBoltGroup(uint32 id);
+ void freeBoltMember(uint32 id);
byte *memberAddr(uint32 id);
byte *memberAddrOffset(uint32 id);
void resolveIt(uint32 id, byte **p);
@@ -150,6 +152,7 @@ public:
class StampBoltFile: public BoltFile {
private:
+ void initThread();
void initPtr();
void initControl();
protected:
@@ -202,6 +205,7 @@ public:
// stampblt.blt resource types
PtrResource *_ptrResource;
ControlResource *_controlResource;
+ ThreadResource *_threadResource;
public:
BoltEntry(Common::SeekableReadStream *f);
virtual ~BoltEntry();
@@ -400,13 +404,27 @@ public:
class ControlResource {
public:
+ int _memberIds[8];
+ byte *_entries[8];
byte *_ptr;
- Common::Array<byte *> _entries;
ControlResource(BoltFilesState &state, const byte *src);
virtual ~ControlResource() {}
};
+class ThreadResource {
+public:
+ int _field0;
+ int _controlIndex;
+ int _field4, _field6;
+ int _field3A;
+ int _field3E;
+ byte *_ctlPtr;
+public:
+ ThreadResource(BoltFilesState &state, const byte *src);
+ virtual ~ThreadResource() {}
+};
+
} // End of namespace Voyeur
#endif /* VOYEUR_FILES_H */
diff --git a/engines/voyeur/voyeur.h b/engines/voyeur/voyeur.h
index 43a18e0a3a..236d83ff6d 100644
--- a/engines/voyeur/voyeur.h
+++ b/engines/voyeur/voyeur.h
@@ -84,7 +84,10 @@ private:
void playStamp();
void initStamp();
void initUseCount();
- void initThreadStruct(byte *threadStruct);
+ void initThreadStruct(ThreadResource *thread, int v1, int idx);
+ bool stm_loadAStack(ThreadResource *thread, int idx);
+ void stm_unloadAStack(int idx);
+ void stm_doState(ThreadResource *thread);
protected:
// Engine APIs
virtual Common::Error run();
diff --git a/engines/voyeur/voyeur_game.cpp b/engines/voyeur/voyeur_game.cpp
index 07821d8086..f6dc0b0d43 100644
--- a/engines/voyeur/voyeur_game.cpp
+++ b/engines/voyeur/voyeur_game.cpp
@@ -44,8 +44,8 @@ void VoyeurEngine::playStamp() {
initStamp();
PtrResource *threadsList = _stampLibPtr->boltEntry(3)._ptrResource;
- byte *threadP = threadsList->_entries[0]->_data;
- initThreadStruct(threadP);
+ ThreadResource *threadP = threadsList->_entries[0]->_threadResource;
+ initThreadStruct(threadP, 0, 0);
_voy._delaySecs = 0;
_eventsManager._videoComputerNum = 9;
@@ -65,7 +65,7 @@ void VoyeurEngine::initStamp() {
_stampFlags &= ~1;
_stackGroupPtr = _controlGroupPtr;
- if (_controlPtr->_entries.size() == 0)
+ if (!_controlPtr->_entries[0])
error("No control entries");
initUseCount();
@@ -75,8 +75,45 @@ void VoyeurEngine::initUseCount() {
Common::fill(&_stm_useCount[0], &_stm_useCount[8], 0);
}
-void VoyeurEngine::initThreadStruct(byte *threadStruct) {
- // TODO
+void VoyeurEngine::initThreadStruct(ThreadResource *thread, int v1, int idx) {
+ thread->_controlIndex = -1;
+ if (stm_loadAStack(thread, idx)) {
+ thread->_field4 = thread->_field6 = -1;
+ thread->_field0 = idx;
+ thread->_field3A = -1;
+ thread->_field3E = -1;
+
+ stm_doState(thread);
+ }
+}
+
+bool VoyeurEngine::stm_loadAStack(ThreadResource *thread, int idx) {
+ if (_stampFlags & 1) {
+ stm_unloadAStack(thread->_controlIndex);
+ if (!_stm_useCount[idx]) {
+ BoltEntry &boltEntry = _stampLibPtr->boltEntry(_controlPtr->_memberIds[idx]);
+ if (!boltEntry._data)
+ return false;
+
+ _controlPtr->_entries[idx] = boltEntry._data;
+ }
+
+ ++_stm_useCount[idx];
+ }
+
+ thread->_ctlPtr = _controlPtr->_entries[idx];
+}
+
+void VoyeurEngine::stm_unloadAStack(int idx) {
+ if ((_stampFlags & 1) && _stm_useCount[idx]) {
+ if (--_stm_useCount[idx] == 0) {
+ _stampLibPtr->freeBoltMember(_controlPtr->_memberIds[idx]);
+ }
+ }
+}
+
+void VoyeurEngine::stm_doState(ThreadResource *thread) {
+
}
} // End of namespace Voyeur