diff --git a/engines/nancy/iff.cpp b/engines/nancy/iff.cpp index 9fa3fcf1335..4dbdf0db163 100644 --- a/engines/nancy/iff.cpp +++ b/engines/nancy/iff.cpp @@ -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; } diff --git a/engines/nancy/iff.h b/engines/nancy/iff.h index 49950a14a6c..3603c4ca623 100644 --- a/engines/nancy/iff.h +++ b/engines/nancy/iff.h @@ -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); diff --git a/engines/nancy/nancy.cpp b/engines/nancy/nancy.cpp index 9d3e00030ae..a5433b238cd 100644 --- a/engines/nancy/nancy.cpp +++ b/engines/nancy/nancy.cpp @@ -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(); diff --git a/engines/nancy/nancy.h b/engines/nancy/nancy.h index 6a13f68b2e2..8bb532b9e54 100644 --- a/engines/nancy/nancy.h +++ b/engines/nancy/nancy.h @@ -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