diff options
author | Gregory Montoir | 2004-08-05 18:10:34 +0000 |
---|---|---|
committer | Gregory Montoir | 2004-08-05 18:10:34 +0000 |
commit | aaf6da02dbff2cefd520122e00859f094ee44e3c (patch) | |
tree | 39c41d5b75b1dd5d5b15a6a1e5f61da0820206f5 /queen | |
parent | 6b463e99076207f16d02b8f23c7894cb94eb7107 (diff) | |
download | scummvm-rg350-aaf6da02dbff2cefd520122e00859f094ee44e3c.tar.gz scummvm-rg350-aaf6da02dbff2cefd520122e00859f094ee44e3c.tar.bz2 scummvm-rg350-aaf6da02dbff2cefd520122e00859f094ee44e3c.zip |
simplified some code
svn-id: r14472
Diffstat (limited to 'queen')
-rw-r--r-- | queen/queen.cpp | 2 | ||||
-rw-r--r-- | queen/resource.cpp | 48 | ||||
-rw-r--r-- | queen/resource.h | 1 | ||||
-rw-r--r-- | queen/talk.cpp | 127 |
4 files changed, 66 insertions, 112 deletions
diff --git a/queen/queen.cpp b/queen/queen.cpp index b94d75182a..657ae3dfab 100644 --- a/queen/queen.cpp +++ b/queen/queen.cpp @@ -216,7 +216,7 @@ void QueenEngine::saveGameState(uint16 slot, const char *desc) { // write header GameStateHeader header; memset(&header, 0, sizeof(header)); - file->writeUint32BE('SCVM'); + file->writeUint32BE(MKID_BE('SCVM')); header.version = TO_BE_32(SAVESTATE_CUR_VER); header.flags = TO_BE_32(0); header.dataSize = TO_BE_32(dataSize); diff --git a/queen/resource.cpp b/queen/resource.cpp index cba0253a4e..58c3ccaf7d 100644 --- a/queen/resource.cpp +++ b/queen/resource.cpp @@ -46,6 +46,11 @@ const GameVersion Resource::_gameVersions[] = { { "PEint", 0x00103838, 1915913 } }; +static int compareResourceEntry(const void *a, const void *b) { + const char *key = (const char *)a; + const ResourceEntry *entry = (const ResourceEntry *)b; + return strcmp(key, entry->filename); +} Resource::Resource(const Common::String &datafilePath) : _datafilePath(datafilePath), _resourceEntries(0), _resourceTable(NULL) { @@ -64,8 +69,7 @@ Resource::~Resource() { delete[] _resourceTable; } -int32 Resource::resourceIndex(const char *filename) const { - +ResourceEntry *Resource::resourceEntry(const char *filename) const { char entryName[14]; char *ptr = entryName; @@ -75,6 +79,11 @@ int32 Resource::resourceIndex(const char *filename) const { *ptr = toupper(*ptr); while (*ptr++); + ResourceEntry *re = NULL; +#ifndef __PALM_OS__ + re = (ResourceEntry *)bsearch(entryName, _resourceTable, _resourceEntries, sizeof(ResourceEntry), compareResourceEntry); +#else + // cyx: is that code still necessary ? uint32 low = 0; uint32 high = _resourceEntries - 1; @@ -82,44 +91,19 @@ int32 Resource::resourceIndex(const char *filename) const { return low; if (!strcmp(entryName, _resourceTable[high].filename)) return high; - - - //Use simple binary search to locate file -#ifndef __PALM_OS__ - for (;;) { - uint32 cur = (low + high) / 2; - int32 diff = strcmp(entryName, _resourceTable[cur].filename); - - if (!diff) - return cur; - - if ((cur == low) || (cur == high)) - break; - if (diff > 0) - low = cur; - else - high = cur; - } -#else // Does work for me (????) use this instead uint32 cur = 0; do { - if (!strcmp(entryName, _resourceTable[cur].filename)) - return cur; + if (!strcmp(entryName, _resourceTable[cur].filename)) { + re = &_resourceTable[cur]; + break; + } } while (cur++ <= high); #endif debug(7, "Couldn't find file '%s'", entryName); - return -1; -} - -ResourceEntry *Resource::resourceEntry(const char *filename) const { - int32 index = resourceIndex(filename); - if (index >= 0) - return &_resourceTable[index]; - else - return NULL; + return re; } uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, byte *dstBuf) { diff --git a/queen/resource.h b/queen/resource.h index bc65aa0a6b..ed304840ce 100644 --- a/queen/resource.h +++ b/queen/resource.h @@ -115,7 +115,6 @@ protected: bool findNormalVersion(); bool findCompressedVersion(); void checkJASVersion(); - int32 resourceIndex(const char *filename) const; ResourceEntry *resourceEntry(const char *filename) const; bool readTableFile(const GameVersion *gameVersion); void readTableCompResource(); diff --git a/queen/talk.cpp b/queen/talk.cpp index 4fd8779664..1d8e2fe21e 100644 --- a/queen/talk.cpp +++ b/queen/talk.cpp @@ -513,85 +513,56 @@ void Talk::initialTalk() { int Talk::getSpeakCommand(const Person *person, const char *sentence, unsigned &index) { // Lines 1299-1362 in talk.c int commandCode = SPEAK_DEFAULT; - - // cyx: what about something like: - // uint16 id = (sentence[index] << 8) | sentence[index + 1]; - // switch(id) { case 'AO': ... } - switch (sentence[index]) { - case 'A': - if (sentence[index + 1] == 'O') - commandCode = SPEAK_AMAL_ON; + uint16 id = (sentence[index] << 8) | sentence[index + 1]; + switch (id) { + case MKID_BE('AO'): + commandCode = SPEAK_AMAL_ON; + break; + case MKID_BE('FL'): + commandCode = SPEAK_FACE_LEFT; + break; + case MKID_BE('FF'): + commandCode = SPEAK_FACE_FRONT; + break; + case MKID_BE('FB'): + commandCode = SPEAK_FACE_BACK; + break; + case MKID_BE('FR'): + commandCode = SPEAK_FACE_RIGHT; + break; + case MKID_BE('GD'): + _vm->logic()->joeGrab(STATE_GRAB_DOWN); + commandCode = SPEAK_NONE; + break; + case MKID_BE('GM'): + _vm->logic()->joeGrab(STATE_GRAB_MID); + commandCode = SPEAK_NONE; + break; + case MKID_BE('WT'): + commandCode = SPEAK_PAUSE; + break; + case MKID_BE('XY'): + // For example *XY00(237,112) + { + commandCode = atoi(sentence + index + 2); + int x = atoi(sentence + index + 5); + int y = atoi(sentence + index + 9); + if (0 == strcmp(person->name, "JOE")) + _vm->walk()->moveJoe(0, x, y, _vm->input()->cutawayRunning()); else - warning("Unknown command string: '%2s'", sentence + index); - break; - - case 'F': - switch (sentence[index + 1]) { - case 'L': - commandCode = SPEAK_FACE_LEFT; - break; - case 'F': - commandCode = SPEAK_FACE_FRONT; - break; - case 'B': - commandCode = SPEAK_FACE_BACK; - break; - case 'R': - commandCode = SPEAK_FACE_RIGHT; - break; - default: - warning("Unknown command string: '%2s'", sentence + index); - break; - } - break; - - case 'G': - switch (sentence[index + 1]) { - case 'D': - _vm->logic()->joeGrab(STATE_GRAB_DOWN); - break; - case 'M': - _vm->logic()->joeGrab(STATE_GRAB_MID); - break; - default: - warning("Unknown command string: '%2s'", sentence + index); - break; - } - commandCode = SPEAK_NONE; - break; - - case 'W': - if (sentence[index + 1] == 'T') - commandCode = SPEAK_PAUSE; - else - warning("Unknown command string: '%2s'", sentence + index); - break; - - case 'X': - // For example *XY00(237,112) - if (sentence[index + 1] == 'Y') { - commandCode = atoi(sentence + index + 2); - int x = atoi(sentence + index + 5); - int y = atoi(sentence + index + 9); - if (0 == strcmp(person->name, "JOE")) - _vm->walk()->moveJoe(0, x, y, _vm->input()->cutawayRunning()); - else - _vm->walk()->movePerson(person, x, y, _vm->graphics()->numFrames(), 0); - index += 11; - // if(JOEWALK==3) CUTQUIT=0; - // XXX personWalking = true; - } - else - warning("Unknown command string: '%2s'", sentence + index); - break; - - default: - if (sentence[index + 0] >= '0' && sentence[index + 0] <= '9' && - sentence[index + 1] >= '0' && sentence[index + 1] <= '9') { - commandCode = (sentence[index] - '0') * 10 + (sentence[index + 1] - '0'); - } - else - warning("Unknown command string: '%2s'", sentence + index); + _vm->walk()->movePerson(person, x, y, _vm->graphics()->numFrames(), 0); + index += 11; + // if(JOEWALK==3) CUTQUIT=0; + // XXX personWalking = true; + } + break; + default: + if (sentence[index + 0] >= '0' && sentence[index + 0] <= '9' && + sentence[index + 1] >= '0' && sentence[index + 1] <= '9') { + commandCode = (sentence[index] - '0') * 10 + (sentence[index + 1] - '0'); + } + else + warning("Unknown command string: '%2s'", sentence + index); } index += 2; |