diff options
author | Kamil Zbróg | 2013-12-13 07:05:37 +0000 |
---|---|---|
committer | Kamil Zbróg | 2013-12-13 07:05:37 +0000 |
commit | eecc6f3e8462440a26170b2a62941df5101f9c3d (patch) | |
tree | c21d98b6149101e4bba8c73d76345edb05adb17d /engines/prince | |
parent | 0a05365e1dc46a0ef6dbbac1d5c839aa56a6c0ea (diff) | |
download | scummvm-rg350-eecc6f3e8462440a26170b2a62941df5101f9c3d.tar.gz scummvm-rg350-eecc6f3e8462440a26170b2a62941df5101f9c3d.tar.bz2 scummvm-rg350-eecc6f3e8462440a26170b2a62941df5101f9c3d.zip |
PRINCE: Room resource loading started
Diffstat (limited to 'engines/prince')
-rw-r--r-- | engines/prince/resource.h | 33 | ||||
-rw-r--r-- | engines/prince/script.cpp | 85 | ||||
-rw-r--r-- | engines/prince/script.h | 37 |
3 files changed, 131 insertions, 24 deletions
diff --git a/engines/prince/resource.h b/engines/prince/resource.h index a5e389a37d..2f7e6ba3a8 100644 --- a/engines/prince/resource.h +++ b/engines/prince/resource.h @@ -26,6 +26,7 @@ #include "common/stream.h" #include "common/archive.h" #include "common/debug-channels.h" +#include "common/ptr.h" namespace Prince { @@ -36,43 +37,44 @@ namespace Resource { return resource.loadFromStream(stream); } - template<typename T> bool loadResource(T *resource, const char *resourceName, bool required = true) { - Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName); + Common::ScopedPtr<Common::SeekableReadStream> stream(SearchMan.createReadStreamForMember(resourceName)); if (!stream) { if (required) error("Can't load %s", resourceName); return false; } - bool ret = loadFromStream(*resource, *stream); + return loadFromStream(*resource, *stream); + } - delete stream; + template <typename T> + bool loadResource(Common::Array<T> &array, Common::SeekableReadStream &stream, bool required = true) { + T t; + while (t.loadFromStream(stream)) + array.push_back(t); + + return true; + } - return ret; - } template <typename T> bool loadResource(Common::Array<T> &array, const char *resourceName, bool required = true) { - Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName); + Common::ScopedPtr<Common::SeekableReadStream> stream(SearchMan.createReadStreamForMember(resourceName)); if (!stream) { if (required) error("Can't load %s", resourceName); return false; } - T t; - while (t.loadFromStream(*stream)) - array.push_back(t); - - delete stream; - return true; + return loadResource(array, *stream, required); } template <typename T> bool loadResource(Common::Array<T *> &array, const char *resourceName, bool required = true) { - Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName); + + Common::ScopedPtr<Common::SeekableReadStream> stream(SearchMan.createReadStreamForMember(resourceName)); if (!stream) { if (required) error("Can't load %s", resourceName); @@ -88,10 +90,9 @@ namespace Resource { } array.push_back(t); } - - delete stream; return true; } + } } diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index ce250f1c5a..84174ec23c 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -26,19 +26,92 @@ #include "prince/variatxt.h" #include "prince/font.h" #include "prince/hero.h" +#include "prince/resource.h" #include "common/debug.h" #include "common/debug-channels.h" #include "common/stream.h" #include "common/archive.h" - -#include "audio/decoders/wave.h" -#include "audio/audiostream.h" +#include "common/memstream.h" namespace Prince { static const uint16 NUM_OPCODES = 144; +Room::Room() {} + +void Room::loadMobs(Common::SeekableReadStream &stream) { + debug("loadMobs %d", stream.pos()); + static const uint8 MAX_MOBS = 64; + uint8 mobs[MAX_MOBS]; + stream.read(&mobs, sizeof(mobs)); + for(uint8 i = 0; i < sizeof(mobs); ++i) { + debug("mob %d flag %d", i, mobs[i]); + } +} + +void Room::loadBackAnim(Common::SeekableReadStream &stream) { + debug("loadBackAnim %d", stream.pos()); + static const uint8 MAX_BACK_ANIMS = 64; + uint32 backAnim[MAX_BACK_ANIMS]; + debug("loadBackAnim sizeof %lu", sizeof(backAnim)); + stream.read(backAnim, sizeof(backAnim)); + for(uint8 i = 0; i < MAX_BACK_ANIMS; ++i) { + debug("back anim offset %d", backAnim[i]); + } +} + +void Room::loadObj(Common::SeekableReadStream &stream) {} +void Room::loadNak(Common::SeekableReadStream &stream) {} +void Room::loadItemUse(Common::SeekableReadStream &stream) {} +void Room::loadItemGive(Common::SeekableReadStream &stream) {} +void Room::loadWalkTo(Common::SeekableReadStream &stream) {} +void Room::loadExamine(Common::SeekableReadStream &stream) {} +void Room::loadPickup(Common::SeekableReadStream &stream) {} +void Room::loadUse(Common::SeekableReadStream &stream) {} +void Room::loadPushOpen(Common::SeekableReadStream &stream) {} +void Room::loadPullClose(Common::SeekableReadStream &stream) {} +void Room::loadTalk(Common::SeekableReadStream &stream) {} +void Room::loadGive(Common::SeekableReadStream &stream) {} + +void Room::nextLoadStep(Common::SeekableReadStream &stream, LoadingStep step) { + uint32 offset = stream.readUint32LE(); + uint32 pos = stream.pos(); + stream.seek(offset); + + debug("nextLoadStep offset %d, pos %d", offset, pos); + + (this->*step)(stream); + + stream.seek(pos); +} + +bool Room::loadFromStream(Common::SeekableReadStream &stream) { + + uint32 pos = stream.pos(); + + nextLoadStep(stream, &Room::loadMobs); + nextLoadStep(stream, &Room::loadBackAnim); + nextLoadStep(stream, &Room::loadObj); + nextLoadStep(stream, &Room::loadNak); + nextLoadStep(stream, &Room::loadItemUse); + nextLoadStep(stream, &Room::loadItemGive); + nextLoadStep(stream, &Room::loadWalkTo); + nextLoadStep(stream, &Room::loadExamine); + nextLoadStep(stream, &Room::loadPickup); + nextLoadStep(stream, &Room::loadUse); + nextLoadStep(stream, &Room::loadPushOpen); + nextLoadStep(stream, &Room::loadPullClose); + nextLoadStep(stream, &Room::loadTalk); + nextLoadStep(stream, &Room::loadGive); + + // skip some data for now + static const uint8 ROOM_ENTRY_SIZE = 64; + stream.seek(pos + ROOM_ENTRY_SIZE); + + return true;; +} + Script::Script() : _data(nullptr), _dataSize(0) { } @@ -59,6 +132,12 @@ bool Script::loadFromStream(Common::SeekableReadStream &stream) { return false; stream.read(_data, _dataSize); + + Common::MemoryReadStream scriptDataStream(_data, _dataSize); + scriptDataStream.seek(getRoomTableOffset()+64); + debug("room table offset %d", scriptDataStream.pos()); + Room room; + room.loadFromStream(scriptDataStream); return true; } diff --git a/engines/prince/script.h b/engines/prince/script.h index 8f139950be..d51e01b559 100644 --- a/engines/prince/script.h +++ b/engines/prince/script.h @@ -25,8 +25,7 @@ #include "common/random.h" #include "common/endian.h" - -#include "audio/mixer.h" +#include "common/array.h" #include "prince/flags.h" @@ -45,6 +44,35 @@ namespace Detail { template <> inline uint32 LittleEndianReader<uint32>(void *data) { return READ_LE_UINT32(data); } } +class Room { +public: + Room(); + + bool loadFromStream(Common::SeekableReadStream &stream); + +private: + + typedef void (Room::*LoadingStep)(Common::SeekableReadStream &stream); + + void nextLoadStep(Common::SeekableReadStream &stream, LoadingStep step); + + void loadMobs(Common::SeekableReadStream &stream); + void loadBackAnim(Common::SeekableReadStream &stream); + void loadObj(Common::SeekableReadStream &stream); + void loadNak(Common::SeekableReadStream &stream); + void loadItemUse(Common::SeekableReadStream &stream); + void loadItemGive(Common::SeekableReadStream &stream); + void loadWalkTo(Common::SeekableReadStream &stream); + void loadExamine(Common::SeekableReadStream &stream); + void loadPickup(Common::SeekableReadStream &stream); + void loadUse(Common::SeekableReadStream &stream); + void loadPushOpen(Common::SeekableReadStream &stream); + void loadPullClose(Common::SeekableReadStream &stream); + void loadTalk(Common::SeekableReadStream &stream); + void loadGive(Common::SeekableReadStream &stream); +}; + + class Script { public: Script(); @@ -69,6 +97,7 @@ public: private: uint8 *_data; uint32 _dataSize; + Common::Array<Room> _roomList; }; class InterpreterFlags { @@ -114,7 +143,7 @@ private: static const uint32 _STACK_SIZE = 500; uint32 _stack[_STACK_SIZE]; uint8 _stacktop; - uint8 _savedStacktop; + //uint8 _savedStacktop; uint32 _waitFlag; const byte *_string; @@ -124,8 +153,6 @@ private: // Helper functions uint32 step(uint32 opcodePC); - void checkPC(uint32 address); - uint16 readScriptFlagValue(); Flags::Id readScriptFlagId(); |