NANCY: Add support for PCAL chunk

This commit is contained in:
Walter van Niftrik 2012-10-22 13:12:42 +02:00 committed by Eugene Sandulenko
parent c0fe9e83a0
commit d73103df45
4 changed files with 36 additions and 3 deletions

View file

@ -87,7 +87,7 @@ bool IFF::load() {
return true;
}
const byte *IFF::getChunk(uint32 id, uint &size) {
const byte *IFF::getChunk(uint32 id, uint &size) const {
for (uint i = 0; i < _chunks.size(); ++i) {
const Chunk &chunk = _chunks[i];
if (chunk.id == id) {
@ -96,7 +96,6 @@ const byte *IFF::getChunk(uint32 id, uint &size) {
}
}
warning("Failed to locate chunk");
return 0;
}

View file

@ -35,6 +35,7 @@ namespace Nancy {
class NancyEngine;
#define ID_DATA MKTAG('D', 'A', 'T', 'A')
#define ID_PCAL MKTAG('P', 'C', 'A', 'L')
class IFF {
public:
@ -42,7 +43,7 @@ public:
~IFF();
bool load();
const byte *getChunk(uint32 id, uint &size);
const byte *getChunk(uint32 id, uint &size) const;
private:
Common::String idToString(uint32 id);

View file

@ -27,6 +27,7 @@
#include "common/debug-channels.h"
#include "common/config-manager.h"
#include "common/textconsole.h"
#include "common/memstream.h"
#include "nancy/nancy.h"
#include "nancy/resource.h"
@ -108,6 +109,7 @@ Common::Error NancyEngine::run() {
IFF *boot = new IFF(this, "boot");
if (!boot->load())
error("Failed to load boot script");
preloadCals(*boot);
delete boot;
Common::EventManager *ev = g_system->getEventManager();
@ -143,6 +145,35 @@ void NancyEngine::initialize() {
_rnd->setSeed(42); // Kick random number generator
}
void NancyEngine::preloadCals(const IFF &boot) {
const byte *buf;
uint size;
buf = boot.getChunk(ID_PCAL, size);
if (buf) {
Common::MemoryReadStream stream(buf, size);
uint16 count = stream.readUint16LE();
debugC(1, kDebugEngine, "Preloading %d CALs", count);
int nameLen = size / count;
char *name = new char[nameLen];
for (uint i = 0; i < count; i++) {
stream.read(name, nameLen);
name[nameLen - 1] = 0;
debugC(1, kDebugEngine, "Preloading CAL '%s'", name);
if (!_res->loadCifTree(name, "cal"))
error("Failed to preload CAL '%s'", name);
}
delete[] name;
if (stream.err())
error("Error reading PCAL chunk");
} else
debugC(1, kDebugEngine, "No PCAL chunk found");
}
void NancyEngine::syncSoundSettings() {
Engine::syncSoundSettings();

View file

@ -66,6 +66,7 @@ enum NancyDebugChannels {
struct NancyGameDescription;
class ResourceManager;
class IFF;
class NancyEngine : public Engine {
public:
@ -108,6 +109,7 @@ private:
Common::Platform _platform;
void initialize();
void preloadCals(const IFF &boot);
};
} // End of namespace Nancy