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

View File

@ -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);

View File

@ -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) {

View File

@ -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();

View File

@ -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;