aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudvig Strigeus2002-04-11 15:22:02 +0000
committerLudvig Strigeus2002-04-11 15:22:02 +0000
commit34747b792a42e8129af60371541e9b7321d4d55f (patch)
treeab7ef91a2f72fca6d873978b3a95caf86922e5f1
parente28ae164a9567f8b2dd8444070f6e9b42f89d22e (diff)
downloadscummvm-rg350-34747b792a42e8129af60371541e9b7321d4d55f.tar.gz
scummvm-rg350-34747b792a42e8129af60371541e9b7321d4d55f.tar.bz2
scummvm-rg350-34747b792a42e8129af60371541e9b7321d4d55f.zip
various code cleanups
svn-id: r3907
-rw-r--r--actor.cpp8
-rw-r--r--object.cpp22
-rw-r--r--resource.cpp13
-rw-r--r--script.cpp5
-rw-r--r--script_v1.cpp27
-rw-r--r--v3/resource_v3.cpp26
6 files changed, 35 insertions, 66 deletions
diff --git a/actor.cpp b/actor.cpp
index 1cc13c08dd..4f727fecd3 100644
--- a/actor.cpp
+++ b/actor.cpp
@@ -465,7 +465,7 @@ AdjustBoxResult Scumm::adjustXYToBeInBox(Actor *a, int x, int y, int pathfrom) {
AdjustBoxResult abr,tmp;
uint threshold;
uint best;
- int box, iterations = 0; /* Use inerations for those odd times we get stuck in the loop */
+ int box, iterations = 0; /* Use iterations for those odd times we get stuck in the loop */
int firstValidBox,j;
byte flags, b;
@@ -478,12 +478,12 @@ AdjustBoxResult Scumm::adjustXYToBeInBox(Actor *a, int x, int y, int pathfrom) {
abr.y = y;
abr.dist = 0;
+ if ((_features & GF_SMALL_HEADER) && getClass(a->number, 21))
+ return abr;
+
if (a && a->ignoreBoxes==0) {
threshold = 30;
- if ((_features & GF_SMALL_HEADER) && (_classData[a->number] & 0x200000))
- return abr;
-
while(1) {
iterations++;
if (iterations > 1000) return abr; /* Safety net */
diff --git a/object.cpp b/object.cpp
index 3c32a5bd5e..8a3aaa6a25 100644
--- a/object.cpp
+++ b/object.cpp
@@ -29,14 +29,10 @@ bool Scumm::getClass(int obj, int cls) {
checkRange(32,1,cls,"Class %d out of range in getClass");
if (_features & GF_SMALL_HEADER) {
- byte *oldClass = (byte*)&_classData[obj];
if (cls == 32) // CLASS_TOUCHABLE
cls = 23;
-
- return (oldClass[cls/8] & bit_table[cls&0x07]) != 0;
- } else {
- return (_classData[obj] & (1<<(cls-1))) != 0;
}
+ return (_classData[obj] & (1<<(cls-1))) != 0;
}
void Scumm::putClass(int obj, int cls, bool set) {
@@ -45,21 +41,13 @@ void Scumm::putClass(int obj, int cls, bool set) {
checkRange(32,1,cls,"Class %d out of range in getClass");
if (_features & GF_SMALL_HEADER) {
- byte *oldClass = (byte*)&_classData[obj];
if (cls == 32) // CLASS_TOUCHABLE
cls = 23;
-
- if (set)
- oldClass[cls/8] |= bit_table[cls&0x07];
- else
- oldClass[cls/8] &= bit_table[cls&0x07]^0xff;
-
- } else {
- if (set)
- _classData[obj] |= (1<<(cls-1));
- else
- _classData[obj] &= ~(1<<(cls-1));
}
+ if (set)
+ _classData[obj] |= (1<<(cls-1));
+ else
+ _classData[obj] &= ~(1<<(cls-1));
}
int Scumm::getOwner(int obj) {
diff --git a/resource.cpp b/resource.cpp
index 438f90e887..27f6babda8 100644
--- a/resource.cpp
+++ b/resource.cpp
@@ -272,13 +272,14 @@ void Scumm::readIndexFile() {
}
}
fileRead(_fileHandle, _classData, num * sizeof(uint32));
-
-/* #if defined(SCUMM_BIG_ENDIAN)
- for (i=0; i<num; i++) {
+
+ /* This code should be here. Otherwise the flags will be swapped for big endian computers.
+ * If it doesn't work with this code, something else is wrong */
+#if defined(SCUMM_BIG_ENDIAN)
+ for (i=0; i!=num; i++) {
_classData[i] = FROM_LE_32(_classData[i]);
}
-#endif */ // ?? FIXME Remove according to Morphos diff.
-
+#endif
break;
case MKID('RNAM'):
@@ -400,6 +401,8 @@ void Scumm::loadCharset(int no) {
debug(9, "loadCharset(%d)",no);
+
+
memset(_charsetData, 0, sizeof(_charsetData));
checkRange(_maxCharsets-1, 1, no, "Loading illegal charset %d");
diff --git a/script.cpp b/script.cpp
index 349faaa920..cc56f83531 100644
--- a/script.cpp
+++ b/script.cpp
@@ -39,10 +39,7 @@ void Scumm::runScript(int script, int a, int b, int16 *lvarptr) {
if (script < _numGlobalScripts) {
scriptPtr = getResourceAddress(rtScript, script);
- if(_features & GF_SMALL_HEADER)
- scriptOffs = 6;
- else
- scriptOffs = 8;
+ scriptOffs = _resourceHeaderSize;
scriptType = WIO_GLOBAL;
} else {
scriptOffs = _localScriptList[script - _numGlobalScripts];
diff --git a/script_v1.cpp b/script_v1.cpp
index 5cde3ce9a0..5e7d8c7547 100644
--- a/script_v1.cpp
+++ b/script_v1.cpp
@@ -690,7 +690,7 @@ void Scumm::o5_actorFromPos() {
}
void Scumm::o5_actorSet() {
- byte convertTable[20] = {1,0,0,2,0,4,5,6,7,8,9,10,11,12,13,14,15,16,17,20};
+ static const byte convertTable[20] = {1,0,0,2,0,4,5,6,7,8,9,10,11,12,13,14,15,16,17,20};
int act = getVarOrDirectByte(0x80);
Actor *a;
int i,j;
@@ -815,7 +815,6 @@ FixRoom:
void Scumm::o5_actorSetClass() {
int act = getVarOrDirectWord(0x80);
int newClass;
- byte *oldClassData;
while ( (_opcode=fetchScriptByte()) != 0xFF) {
newClass = getVarOrDirectWord(0x80);
@@ -824,18 +823,10 @@ void Scumm::o5_actorSetClass() {
continue;
}
- if(_features & GF_SMALL_HEADER) {
- oldClassData=(byte*)&_classData[act];
- if (newClass&0x80)
- oldClassData[((newClass-1)&0x7f)/8] |= bit_table[((newClass-1)&0x07)];
- else
- oldClassData[((newClass-1)&0x7f)/8] &= bit_table[((newClass-1)&0x07)]^0xff;
- } else {
- if (newClass&0x80)
- putClass(act, newClass, 1);
- else
- putClass(act, newClass, 0);
- }
+ if (newClass&0x80)
+ putClass(act, newClass, 1);
+ else
+ putClass(act, newClass, 0);
}
}
@@ -1349,18 +1340,12 @@ void Scumm::o5_getVerbEntrypoint() {
void Scumm::o5_ifClassOfIs() {
int act,cls, b;
bool cond = true;
- byte *oldClass;
act = getVarOrDirectWord(0x80);
while ( (_opcode = fetchScriptByte()) != 0xFF) {
cls = getVarOrDirectWord(0x80);
- oldClass = (byte*)&_classData[act];
-
- if(_features & GF_SMALL_HEADER)
- b = oldClass[((cls-1)&0x7f)/8] & bit_table[((cls-1)&0x07)];
- else
- b = getClass(act, cls);
+ b = getClass(act, cls);
if (cls&0x80 && !b || !(cls&0x80) && b)
cond = false;
diff --git a/v3/resource_v3.cpp b/v3/resource_v3.cpp
index dc74da751c..31988ac732 100644
--- a/v3/resource_v3.cpp
+++ b/v3/resource_v3.cpp
@@ -29,7 +29,6 @@ void Scumm_v3::readIndexFile() {
uint32 itemsize;
int numblock = 0;
int num, i;
- byte* _oldClass;
debug(9, "readIndexFile()");
@@ -121,21 +120,17 @@ void Scumm_v3::readIndexFile() {
case 0x4F30:
num = fileReadWordLE();
assert(num == _numGlobalObjects);
- for (i=0; i<num; i++) { /* not too sure about all that */
- _oldClass=(byte*)&_classData[i];
- _oldClass[0]=fileReadByte();
- _oldClass[1]=fileReadByte();
- _oldClass[2]=fileReadByte();
- _objectOwnerTable[i] = fileReadByte();
- // _objectStateTable[i] = fileReadByte();
- _objectOwnerTable[i] &= OF_OWNER_MASK;
+ for (i=0; i!=num; i++) {
+ uint32 bits = fileReadByte();
+ byte tmp;
+ bits |= fileReadByte() << 8;
+ bits |= fileReadByte() << 16;
+ _classData[i] = bits;
+ tmp = fileReadByte();
+ _objectOwnerTable[i] = tmp & OF_OWNER_MASK;
+ _objectStateTable[i] = tmp >> OF_STATE_SHL;
}
-/*#if defined(SCUMM_BIG_ENDIAN)
- for (i=0; i<num; i++) {
- _classData[i] = FROM_LE_32(_classData[i]);
- }
-#endif*/
break;
default:
@@ -148,7 +143,8 @@ void Scumm_v3::readIndexFile() {
}
void Scumm_v3::loadCharset(int no){
- uint32 size; memset(_charsetData, 0, sizeof(_charsetData));
+ uint32 size;
+ memset(_charsetData, 0, sizeof(_charsetData));
checkRange(4 ,0 ,no , "Loading illegal charset %d");
openRoom(-1);