mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 22:28:10 +00:00
PRINCE: Room resource loading started
This commit is contained in:
parent
0a05365e1d
commit
eecc6f3e84
@ -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);
|
||||
|
||||
delete stream;
|
||||
|
||||
return ret;
|
||||
return loadFromStream(*resource, *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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user