simplified some code

svn-id: r14472
This commit is contained in:
Gregory Montoir 2004-08-05 18:10:34 +00:00
parent 6b463e9907
commit aaf6da02db
4 changed files with 66 additions and 112 deletions

@ -216,7 +216,7 @@ void QueenEngine::saveGameState(uint16 slot, const char *desc) {
// write header // write header
GameStateHeader header; GameStateHeader header;
memset(&header, 0, sizeof(header)); memset(&header, 0, sizeof(header));
file->writeUint32BE('SCVM'); file->writeUint32BE(MKID_BE('SCVM'));
header.version = TO_BE_32(SAVESTATE_CUR_VER); header.version = TO_BE_32(SAVESTATE_CUR_VER);
header.flags = TO_BE_32(0); header.flags = TO_BE_32(0);
header.dataSize = TO_BE_32(dataSize); header.dataSize = TO_BE_32(dataSize);

@ -46,6 +46,11 @@ const GameVersion Resource::_gameVersions[] = {
{ "PEint", 0x00103838, 1915913 } { "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) Resource::Resource(const Common::String &datafilePath)
: _datafilePath(datafilePath), _resourceEntries(0), _resourceTable(NULL) { : _datafilePath(datafilePath), _resourceEntries(0), _resourceTable(NULL) {
@ -64,8 +69,7 @@ Resource::~Resource() {
delete[] _resourceTable; delete[] _resourceTable;
} }
int32 Resource::resourceIndex(const char *filename) const { ResourceEntry *Resource::resourceEntry(const char *filename) const {
char entryName[14]; char entryName[14];
char *ptr = entryName; char *ptr = entryName;
@ -75,6 +79,11 @@ int32 Resource::resourceIndex(const char *filename) const {
*ptr = toupper(*ptr); *ptr = toupper(*ptr);
while (*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 low = 0;
uint32 high = _resourceEntries - 1; uint32 high = _resourceEntries - 1;
@ -82,44 +91,19 @@ int32 Resource::resourceIndex(const char *filename) const {
return low; return low;
if (!strcmp(entryName, _resourceTable[high].filename)) if (!strcmp(entryName, _resourceTable[high].filename))
return high; 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 // Does work for me (????) use this instead
uint32 cur = 0; uint32 cur = 0;
do { do {
if (!strcmp(entryName, _resourceTable[cur].filename)) if (!strcmp(entryName, _resourceTable[cur].filename)) {
return cur; re = &_resourceTable[cur];
break;
}
} while (cur++ <= high); } while (cur++ <= high);
#endif #endif
debug(7, "Couldn't find file '%s'", entryName); debug(7, "Couldn't find file '%s'", entryName);
return -1; return re;
}
ResourceEntry *Resource::resourceEntry(const char *filename) const {
int32 index = resourceIndex(filename);
if (index >= 0)
return &_resourceTable[index];
else
return NULL;
} }
uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, byte *dstBuf) { uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, byte *dstBuf) {

@ -115,7 +115,6 @@ protected:
bool findNormalVersion(); bool findNormalVersion();
bool findCompressedVersion(); bool findCompressedVersion();
void checkJASVersion(); void checkJASVersion();
int32 resourceIndex(const char *filename) const;
ResourceEntry *resourceEntry(const char *filename) const; ResourceEntry *resourceEntry(const char *filename) const;
bool readTableFile(const GameVersion *gameVersion); bool readTableFile(const GameVersion *gameVersion);
void readTableCompResource(); void readTableCompResource();

@ -513,85 +513,56 @@ void Talk::initialTalk() {
int Talk::getSpeakCommand(const Person *person, const char *sentence, unsigned &index) { int Talk::getSpeakCommand(const Person *person, const char *sentence, unsigned &index) {
// Lines 1299-1362 in talk.c // Lines 1299-1362 in talk.c
int commandCode = SPEAK_DEFAULT; int commandCode = SPEAK_DEFAULT;
uint16 id = (sentence[index] << 8) | sentence[index + 1];
// cyx: what about something like: switch (id) {
// uint16 id = (sentence[index] << 8) | sentence[index + 1]; case MKID_BE('AO'):
// switch(id) { case 'AO': ... } commandCode = SPEAK_AMAL_ON;
switch (sentence[index]) { break;
case 'A': case MKID_BE('FL'):
if (sentence[index + 1] == 'O') commandCode = SPEAK_FACE_LEFT;
commandCode = SPEAK_AMAL_ON; 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 else
warning("Unknown command string: '%2s'", sentence + index); _vm->walk()->movePerson(person, x, y, _vm->graphics()->numFrames(), 0);
break; index += 11;
// if(JOEWALK==3) CUTQUIT=0;
case 'F': // XXX personWalking = true;
switch (sentence[index + 1]) { }
case 'L': break;
commandCode = SPEAK_FACE_LEFT; default:
break; if (sentence[index + 0] >= '0' && sentence[index + 0] <= '9' &&
case 'F': sentence[index + 1] >= '0' && sentence[index + 1] <= '9') {
commandCode = SPEAK_FACE_FRONT; commandCode = (sentence[index] - '0') * 10 + (sentence[index + 1] - '0');
break; }
case 'B': else
commandCode = SPEAK_FACE_BACK; warning("Unknown command string: '%2s'", sentence + index);
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);
} }
index += 2; index += 2;