diff options
author | Max Horn | 2010-06-15 12:31:16 +0000 |
---|---|---|
committer | Max Horn | 2010-06-15 12:31:16 +0000 |
commit | 2b24a1a2adcd112a6f3d878c9172ec570a6077d9 (patch) | |
tree | ba8fff2af23a85f0acb98ddcc1567766a47961ac /engines | |
parent | 68eeef8f1aa560954297291887f26bad6591aa15 (diff) | |
download | scummvm-rg350-2b24a1a2adcd112a6f3d878c9172ec570a6077d9.tar.gz scummvm-rg350-2b24a1a2adcd112a6f3d878c9172ec570a6077d9.tar.bz2 scummvm-rg350-2b24a1a2adcd112a6f3d878c9172ec570a6077d9.zip |
SCI: OOpify class ResourceId
svn-id: r49841
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/console.cpp | 32 | ||||
-rw-r--r-- | engines/sci/engine/kscripts.cpp | 4 | ||||
-rw-r--r-- | engines/sci/resource.cpp | 22 | ||||
-rw-r--r-- | engines/sci/resource.h | 67 | ||||
-rw-r--r-- | engines/sci/resource_audio.cpp | 4 |
5 files changed, 69 insertions, 60 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 1c6f4461a8..4c8d588fa0 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -824,7 +824,7 @@ bool Console::cmdVerifyScripts(int argc, const char **argv) { } Common::List<ResourceId> *resources = _engine->getResMan()->listResources(kResourceTypeScript); - sort(resources->begin(), resources->end(), ResourceIdLess()); + Common::sort(resources->begin(), resources->end()); Common::List<ResourceId>::iterator itr = resources->begin(); DebugPrintf("%d SCI1.1-SCI2.1 scripts found, performing sanity checks...\n", resources->size()); @@ -833,15 +833,15 @@ bool Console::cmdVerifyScripts(int argc, const char **argv) { while (itr != resources->end()) { script = _engine->getResMan()->findResource(*itr, false); if (!script) - DebugPrintf("Error: script %d couldn't be loaded\n", itr->number); + DebugPrintf("Error: script %d couldn't be loaded\n", itr->getNumber()); - heap = _engine->getResMan()->findResource(ResourceId(kResourceTypeHeap, itr->number), false); + heap = _engine->getResMan()->findResource(ResourceId(kResourceTypeHeap, itr->getNumber()), false); if (!heap) - DebugPrintf("Error: script %d doesn't have a corresponding heap\n", itr->number); + DebugPrintf("Error: script %d doesn't have a corresponding heap\n", itr->getNumber()); if (script && heap && (script->size + heap->size > 65535)) DebugPrintf("Error: script and heap %d together are larger than 64KB (%d bytes)\n", - itr->number, script->size + heap->size); + itr->getNumber(), script->size + heap->size); ++itr; } @@ -864,7 +864,7 @@ bool Console::cmdShowInstruments(int argc, const char **argv) { parser->setMidiDriver(player); Common::List<ResourceId> *resources = _engine->getResMan()->listResources(kResourceTypeSound); - sort(resources->begin(), resources->end(), ResourceIdLess()); + Common::sort(resources->begin(), resources->end()); Common::List<ResourceId>::iterator itr = resources->begin(); int instruments[128]; bool instrumentsSongs[128][1000]; @@ -885,12 +885,12 @@ bool Console::cmdShowInstruments(int argc, const char **argv) { SoundResource *sound; while (itr != resources->end()) { - if (songNumber >= 0 && itr->number != songNumber) { + if (songNumber >= 0 && itr->getNumber() != songNumber) { ++itr; continue; } - sound = new SoundResource(itr->number, _engine->getResMan(), doSoundVersion); + sound = new SoundResource(itr->getNumber(), _engine->getResMan(), doSoundVersion); int channelFilterMask = sound->getChannelFilterMask(player->getPlayId(), player->hasRhythmChannel()); SoundResource::Track *track = sound->getTrackByType(player->getPlayId()); if (track->digitalChannelNr != -1) { @@ -907,7 +907,7 @@ bool Console::cmdShowInstruments(int argc, const char **argv) { bool endOfTrack = false; bool firstOneShown = false; - DebugPrintf("Song %d: ", itr->number); + DebugPrintf("Song %d: ", itr->getNumber()); do { while (*channelData == 0xF8) @@ -937,7 +937,7 @@ bool Console::cmdShowInstruments(int argc, const char **argv) { DebugPrintf(" %d", instrument); instruments[instrument]++; - instrumentsSongs[instrument][itr->number] = true; + instrumentsSongs[instrument][itr->getNumber()] = true; } break; case 0xD: @@ -1035,19 +1035,19 @@ bool Console::cmdList(int argc, const char **argv) { } Common::List<ResourceId> *resources = _engine->getResMan()->listResources(res, number); - sort(resources->begin(), resources->end(), ResourceIdLess()); + Common::sort(resources->begin(), resources->end()); Common::List<ResourceId>::iterator itr = resources->begin(); int cnt = 0; while (itr != resources->end()) { if (number == -1) { - DebugPrintf("%8i", itr->number); + DebugPrintf("%8i", itr->getNumber()); if (++cnt % 10 == 0) DebugPrintf("\n"); - } - else if (number == (int)itr->number) { - DebugPrintf("(%3i, %3i, %3i, %3i) ", (itr->tuple >> 24) & 0xff, (itr->tuple >> 16) & 0xff, - (itr->tuple >> 8) & 0xff, itr->tuple & 0xff); + } else if (number == (int)itr->getNumber()) { + const uint32 tuple = itr->getTuple(); + DebugPrintf("(%3i, %3i, %3i, %3i) ", (tuple >> 24) & 0xff, (tuple >> 16) & 0xff, + (tuple >> 8) & 0xff, tuple & 0xff); if (++cnt % 4 == 0) DebugPrintf("\n"); } diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp index c6d73556ba..a8cf92b2a6 100644 --- a/engines/sci/engine/kscripts.cpp +++ b/engines/sci/engine/kscripts.cpp @@ -61,8 +61,8 @@ reg_t kLock(EngineState *s, int argc, reg_t *argv) { if (which) g_sci->getResMan()->unlockResource(which); else { - if (id.type == kResourceTypeInvalid) - warning("[resMan] Attempt to unlock resource %i of invalid type %i", id.number, type); + if (id.getType() == kResourceTypeInvalid) + warning("[resMan] Attempt to unlock resource %i of invalid type %i", id.getNumber(), type); else warning("[resMan] Attempt to unlock non-existant resource %s", id.toString().c_str()); } diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index 80b3108988..00da600b26 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -157,7 +157,7 @@ void Resource::unalloc() { } void Resource::writeToStream(Common::WriteStream *stream) const { - stream->writeByte(_id.type | 0x80); // 0x80 is required by old sierra sci, otherwise it wont accept the patch file + stream->writeByte(getType() | 0x80); // 0x80 is required by old sierra sci, otherwise it wont accept the patch file stream->writeByte(_headerSize); if (_headerSize > 0) stream->write(_header, _headerSize); @@ -334,10 +334,10 @@ void PatchResourceSource::loadResource(Resource *res) { } void MacResourceForkResourceSource::loadResource(Resource *res) { - Common::SeekableReadStream *stream = _macResMan->getResource(resTypeToMacTag(res->_id.type), res->_id.number); + Common::SeekableReadStream *stream = _macResMan->getResource(resTypeToMacTag(res->getType()), res->_id.getNumber()); if (!stream) - error("Could not get Mac resource fork resource: %d %d", res->_id.type, res->_id.number); + error("Could not get Mac resource fork resource: %d %d", res->getType(), res->_id.getNumber()); int error = res->decompress(stream); if (error) { @@ -387,7 +387,7 @@ void AudioVolumeResourceSource::loadResource(Resource *res) { mappingTable++; compressedOffset = *mappingTable; // Go to next compressed offset and use that to calculate size of compressed sample - switch (res->_id.type) { + switch (res->getType()) { case kResourceTypeSync: case kResourceTypeSync36: // we should already have a (valid) size @@ -405,7 +405,7 @@ void AudioVolumeResourceSource::loadResource(Resource *res) { error("could not translate offset to compressed offset in audio volume"); fileStream->seek(compressedOffset, SEEK_SET); - switch (res->_id.type) { + switch (res->getType()) { case kResourceTypeAudio: case kResourceTypeAudio36: // Directly read the stream, compressed audio wont have resource type id and header size for SCI1.1 @@ -604,9 +604,9 @@ int ResourceManager::addInternalSources() { Common::List<ResourceId>::iterator itr = resources->begin(); while (itr != resources->end()) { - ResourceSource *src = addSource(new IntMapResourceSource("MAP", itr->number)); + ResourceSource *src = addSource(new IntMapResourceSource("MAP", itr->getNumber())); - if ((itr->number == 65535) && Common::File::exists("RESOURCE.SFX")) + if ((itr->getNumber() == 65535) && Common::File::exists("RESOURCE.SFX")) addSource(new AudioVolumeResourceSource("RESOURCE.SFX", src, 0)); else if (Common::File::exists("RESOURCE.AUD")) addSource(new AudioVolumeResourceSource("RESOURCE.AUD", src, 0)); @@ -799,7 +799,7 @@ Common::List<ResourceId> *ResourceManager::listResources(ResourceType type, int ResourceMap::iterator itr = _resMap.begin(); while (itr != _resMap.end()) { - if ((itr->_value->_id.type == type) && ((mapNumber == -1) || (itr->_value->_id.number == mapNumber))) + if ((itr->_value->getType() == type) && ((mapNumber == -1) || (itr->_value->_id.getNumber() == mapNumber))) resources->push_back(itr->_value->_id); ++itr; } @@ -1220,7 +1220,7 @@ void ResourceManager::readResourcePatchesBase36() { } psrcPatch = new PatchResourceSource(name); - processPatch(psrcPatch, (ResourceType)i, resourceNr, resource36.tuple); + processPatch(psrcPatch, (ResourceType)i, resourceNr, resource36.getTuple()); } } } @@ -1552,8 +1552,8 @@ int Resource::readResourceInfo(Common::SeekableReadStream *file, case kResVersionSci11Mac: // Doesn't store this data in the resource. Fortunately, // we already have this data. - type = _id.type; - number = _id.number; + type = getType(); + number = _id.getNumber(); szPacked = file->size(); szUnpacked = file->size(); wCompression = 0; diff --git a/engines/sci/resource.h b/engines/sci/resource.h index d2dff8f58d..e030db4bc4 100644 --- a/engines/sci/resource.h +++ b/engines/sci/resource.h @@ -114,57 +114,64 @@ class ResourceManager; class ResourceSource; class ResourceId { -public: - ResourceType type; - uint16 number; - uint32 tuple; // Only used for audio36 and sync36 + static inline ResourceType fixupType(ResourceType type) { + if (type < kResourceTypeMacPict || type > kResourceTypeInvalid) + return kResourceTypeInvalid; + return type; + } - ResourceId() : type(kResourceTypeInvalid), number(0), tuple(0) { } + ResourceType _type; + uint16 _number; + uint32 _tuple; // Only used for audio36 and sync36 + +public: + ResourceId() : _type(kResourceTypeInvalid), _number(0), _tuple(0) { } ResourceId(ResourceType type_, uint16 number_, uint32 tuple_ = 0) - : type(type_), number(number_), tuple(tuple_) { - if (type < kResourceTypeMacPict || type > kResourceTypeInvalid) - type = kResourceTypeInvalid; + : _type(fixupType(type_)), _number(number_), _tuple(tuple_) { } ResourceId(ResourceType type_, uint16 number_, byte noun, byte verb, byte cond, byte seq) - : type(type_), number(number_) { - tuple = (noun << 24) | (verb << 16) | (cond << 8) | seq; - - if ((type < kResourceTypeView) || (type > kResourceTypeInvalid)) - type = kResourceTypeInvalid; + : _type(fixupType(type_)), _number(number_) { + _tuple = (noun << 24) | (verb << 16) | (cond << 8) | seq; } - Common::String toString() { + Common::String toString() const { char buf[32]; - snprintf(buf, 32, "%s.%i", getResourceTypeName(type), number); + snprintf(buf, 32, "%s.%i", getResourceTypeName(_type), _number); Common::String retStr = buf; - if (tuple != 0) { - snprintf(buf, 32, "(%i, %i, %i, %i)", tuple >> 24, (tuple >> 16) & 0xff, (tuple >> 8) & 0xff, tuple & 0xff); + if (_tuple != 0) { + snprintf(buf, 32, "(%i, %i, %i, %i)", _tuple >> 24, (_tuple >> 16) & 0xff, (_tuple >> 8) & 0xff, _tuple & 0xff); retStr += buf; } return retStr; } -}; -struct ResourceIdHash : public Common::UnaryFunction<ResourceId, uint> { - uint operator()(ResourceId val) const { return ((uint)((val.type << 16) | val.number)) ^ val.tuple; } -}; + inline ResourceType getType() const { return _type; } + inline uint16 getNumber() const { return _number; } + inline uint32 getTuple() const { return _tuple; } -struct ResourceIdEqualTo : public Common::BinaryFunction<ResourceId, ResourceId, bool> { - bool operator()(const ResourceId &x, const ResourceId &y) const { return (x.type == y.type) && (x.number == y.number) && (x.tuple == y.tuple); } -}; + inline uint hash() const { + return ((uint)((_type << 16) | _number)) ^ _tuple; + } + + bool operator==(const ResourceId &other) const { + return (_type == other._type) && (_number == other._number) && (_tuple == other._tuple); + } -struct ResourceIdLess : public Common::BinaryFunction<ResourceId, ResourceId, bool> { - bool operator()(const ResourceId &x, const ResourceId &y) const { - return (x.type < y.type) || ((x.type == y.type) && (x.number < y.number)) - || ((x.type == y.type) && (x.number == y.number) && (x.tuple < y.tuple)); + bool operator<(const ResourceId &other) const { + return (_type < other._type) || ((_type == other._type) && (_number < other._number)) + || ((_type == other._type) && (_number == other._number) && (_tuple < other._tuple)); } }; +struct ResourceIdHash : public Common::UnaryFunction<ResourceId, uint> { + uint operator()(ResourceId val) const { return val.hash(); } +}; + /** Class for storing resources in memory */ class Resource { friend class ResourceManager; @@ -191,6 +198,8 @@ public: byte *_header; uint32 _headerSize; + inline ResourceType getType() const { return _id.getType(); } + /** * Write the resource to the specified stream. * This method is used only by the "dump" debugger command. @@ -213,7 +222,7 @@ protected: int readResourceInfo(Common::SeekableReadStream *file, uint32 &szPacked, ResourceCompression &compression); }; -typedef Common::HashMap<ResourceId, Resource *, ResourceIdHash, ResourceIdEqualTo> ResourceMap; +typedef Common::HashMap<ResourceId, Resource *, ResourceIdHash> ResourceMap; enum ResVersion { kResVersionUnknown, diff --git a/engines/sci/resource_audio.cpp b/engines/sci/resource_audio.cpp index 9cd3f32561..7a0d9bac6e 100644 --- a/engines/sci/resource_audio.cpp +++ b/engines/sci/resource_audio.cpp @@ -100,8 +100,8 @@ bool Resource::loadFromAudioVolumeSCI11(Common::SeekableReadStream *file) { file->seek(-4, SEEK_CUR); ResourceType type = (ResourceType)(file->readByte() & 0x7f); - if (((_id.type == kResourceTypeAudio || _id.type == kResourceTypeAudio36) && (type != kResourceTypeAudio)) - || ((_id.type == kResourceTypeSync || _id.type == kResourceTypeSync36) && (type != kResourceTypeSync))) { + if (((getType() == kResourceTypeAudio || getType() == kResourceTypeAudio36) && (type != kResourceTypeAudio)) + || ((getType() == kResourceTypeSync || getType() == kResourceTypeSync36) && (type != kResourceTypeSync))) { warning("Resource type mismatch loading %s", _id.toString().c_str()); unalloc(); return false; |