[Scummvm-cvs-logs] CVS: scummvm/queen queen.cpp,1.85,1.86 resource.cpp,1.46,1.47 resource.h,1.37,1.38 talk.cpp,1.98,1.99
Gregory Montoir
cyx at users.sourceforge.net
Thu Aug 5 11:11:08 CEST 2004
Update of /cvsroot/scummvm/scummvm/queen
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22125/queen
Modified Files:
queen.cpp resource.cpp resource.h talk.cpp
Log Message:
simplified some code
Index: queen.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/queen.cpp,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- queen.cpp 25 Jun 2004 22:39:19 -0000 1.85
+++ queen.cpp 5 Aug 2004 18:10:34 -0000 1.86
@@ -216,7 +216,7 @@
// 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);
Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/resource.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- resource.cpp 5 Aug 2004 17:25:54 -0000 1.46
+++ resource.cpp 5 Aug 2004 18:10:34 -0000 1.47
@@ -46,6 +46,11 @@
{ "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 @@
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 @@
*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 @@
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) {
Index: resource.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/resource.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- resource.h 17 Mar 2004 14:10:51 -0000 1.37
+++ resource.h 5 Aug 2004 18:10:34 -0000 1.38
@@ -115,7 +115,6 @@
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();
Index: talk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/talk.cpp,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- talk.cpp 27 Jun 2004 21:51:44 -0000 1.98
+++ talk.cpp 5 Aug 2004 18:10:34 -0000 1.99
@@ -513,85 +513,56 @@
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;
- 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');
- }
+ 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);
+ _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;
More information about the Scummvm-git-logs
mailing list