aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2005-03-27 00:42:53 +0000
committerMax Horn2005-03-27 00:42:53 +0000
commit5bd26a52df502391714b539df30eb76e50c72cf7 (patch)
tree68c28db4f1cca6b0c21902424915e17388ed9351
parent446be21239727bcea559e201b77a48860fd5a34f (diff)
downloadscummvm-rg350-5bd26a52df502391714b539df30eb76e50c72cf7.tar.gz
scummvm-rg350-5bd26a52df502391714b539df30eb76e50c72cf7.tar.bz2
scummvm-rg350-5bd26a52df502391714b539df30eb76e50c72cf7.zip
More costume code restructuring
svn-id: r17258
-rw-r--r--scumm/actor.cpp6
-rw-r--r--scumm/akos.h7
-rw-r--r--scumm/base-costume.cpp14
-rw-r--r--scumm/base-costume.h9
-rw-r--r--scumm/costume.cpp164
-rw-r--r--scumm/costume.h26
-rw-r--r--scumm/scumm.h7
7 files changed, 129 insertions, 104 deletions
diff --git a/scumm/actor.cpp b/scumm/actor.cpp
index ee881d81c7..4178d629b8 100644
--- a/scumm/actor.cpp
+++ b/scumm/actor.cpp
@@ -1128,7 +1128,7 @@ void Actor::animateCostume() {
if (_animProgress >= _animSpeed) {
_animProgress = 0;
- BaseCostume *cost = 0;
+ BaseCostumeLoader *cost = 0;
if (_vm->_features & GF_NEW_COSTUMES) {
byte *akos = _vm->getResourceAddress(rtCostume, _costume);
@@ -1138,9 +1138,9 @@ void Actor::animateCostume() {
}
} else {
if (_vm->_features & GF_NES)
- cost = new NESCostume(_vm);
+ cost = new NESCostumeLoader(_vm);
else
- cost = new ClassicCostume(_vm);
+ cost = new ClassicCostumeLoader(_vm);
cost->loadCostume(_costume);
if (cost->increaseAnims(this)) {
_needRedraw = true;
diff --git a/scumm/akos.h b/scumm/akos.h
index f359c94e98..1055f9ab88 100644
--- a/scumm/akos.h
+++ b/scumm/akos.h
@@ -38,10 +38,15 @@ struct AkosHeader;
struct AkosOffset;
/* TODO:
-class AkosCostume : public BaseCostume {
+class AkosCostumeLoader : public BaseCostumeLoader {
public:
+ AkosCostumeLoader(ScummEngine *vm);
+
void loadCostume(int id);
byte increaseAnims(Actor *a);
+ void costumeDecodeData(Actor *a, int frame, uint usemask);
+
+ //void animateLimb(int limb, int f);
};
*/
diff --git a/scumm/base-costume.cpp b/scumm/base-costume.cpp
index b8609aaf49..c1402f922e 100644
--- a/scumm/base-costume.cpp
+++ b/scumm/base-costume.cpp
@@ -22,6 +22,7 @@
#include "stdafx.h"
#include "scumm/base-costume.h"
+#include "scumm/costume.h"
namespace Scumm {
@@ -88,12 +89,17 @@ bool ScummEngine::isCostumeInUse(int cost) const {
}
void ScummEngine::costumeDecodeData(Actor *a, int frame, uint usemask) {
+ // TODO: This should eventually become a method of the appropriate
+ // BaseCostumeLoader subclasses.
if (_features & GF_NEW_COSTUMES)
akos_decodeData(a, frame, usemask);
- else if (_features & GF_NES)
- NES_cost_decodeData(a, frame, usemask);
- else
- cost_decodeData(a, frame, usemask);
+ else if (_features & GF_NES) {
+ NESCostumeLoader lc(this);
+ lc.costumeDecodeData(a, frame, usemask);
+ } else {
+ ClassicCostumeLoader lc(this);
+ lc.costumeDecodeData(a, frame, usemask);
+ }
}
} // End of namespace Scumm
diff --git a/scumm/base-costume.h b/scumm/base-costume.h
index 04798c54a8..b54a3f84de 100644
--- a/scumm/base-costume.h
+++ b/scumm/base-costume.h
@@ -46,12 +46,17 @@ class Actor;
class ScummEngine;
struct VirtScreen;
-class BaseCostume {
+class BaseCostumeLoader {
+protected:
+ ScummEngine *_vm;
+
public:
- virtual ~BaseCostume() {}
+ BaseCostumeLoader(ScummEngine *vm) : _vm(vm) {}
+ virtual ~BaseCostumeLoader() {}
virtual void loadCostume(int id) = 0;
virtual byte increaseAnims(Actor *a) = 0;
+ virtual void costumeDecodeData(Actor *a, int frame, uint usemask) = 0;
};
diff --git a/scumm/costume.cpp b/scumm/costume.cpp
index 2ace1dbdfa..40369e9d85 100644
--- a/scumm/costume.cpp
+++ b/scumm/costume.cpp
@@ -74,6 +74,15 @@ const byte cost_scaleTable[256] = {
};
#endif
+static const int v1MMNESLookup[25] = {
+ 0x00, 0x03, 0x01, 0x06, 0x08,
+ 0x02, 0x00, 0x07, 0x0C, 0x04,
+ 0x09, 0x0A, 0x12, 0x0B, 0x14,
+ 0x0D, 0x11, 0x0F, 0x0E, 0x10,
+ 0x17, 0x00, 0x01, 0x05, 0x16
+};
+
+
byte ClassicCostumeRenderer::mainRoutine(int xmoveCur, int ymoveCur) {
int i, skip = 0;
byte drawFlag = 1;
@@ -564,46 +573,7 @@ void ClassicCostumeRenderer::proc3_ami(Codec1 &v1) {
} while (1);
}
-static const int v1MMNESLookup[25] = {
- 0x00, 0x03, 0x01, 0x06, 0x08,
- 0x02, 0x00, 0x07, 0x0C, 0x04,
- 0x09, 0x0A, 0x12, 0x0B, 0x14,
- 0x0D, 0x11, 0x0F, 0x0E, 0x10,
- 0x17, 0x00, 0x01, 0x05, 0x16
-};
-
-/**
- * costume ID -> v1MMNESLookup[] -> desc -> lens & offs -> data -> Gfx & pal
- */
-void NESCostume::loadCostume(int id) {
- const byte *src;
- int frameset, framenum;
- int offset;
-
- _id = id;
- _baseptr = _vm->getResourceAddress(rtCostume, id);
-
- _format = 0x01;
- _mirror = 0;
- _dataOffsets = _baseptr + 4;
-
- frameset = 0;
- framenum = 0;
-
- src = _dataOffsets;
- // Cost(a)
- offset = src[(frameset * 4 + framenum) * 2];
-
- // Lookup & desc
- offset = READ_LE_UINT16(_vm->_NEScostdesc + v1MMNESLookup[_id] * 2);
- if (v1MMNESLookup[_id] * 2 + 2 < READ_LE_UINT16(_vm->_NEScostdesc - 2)) {
- _numAnim = (READ_LE_UINT16(_vm->_NEScostdesc + v1MMNESLookup[_id] * 2 + 2) - offset);
- } else {
- _numAnim = ((READ_LE_UINT16(_vm->_NEScostlens - 2) - 2) - offset);
- }
-}
-
-void ClassicCostume::loadCostume(int id) {
+void ClassicCostumeLoader::loadCostume(int id) {
_id = id;
byte *ptr = _vm->getResourceAddress(rtCostume, id);
@@ -824,54 +794,36 @@ void NESCostumeRenderer::setPalette(byte *palette) {
}
void NESCostumeRenderer::setFacing(const Actor *a) {
- _mirror = newDirToOldDir(a->getFacing()) != 0 || _loaded._mirror;
+ // TODO
+ //_mirror = newDirToOldDir(a->getFacing()) != 0 || _loaded._mirror;
}
void NESCostumeRenderer::setCostume(int costume) {
_loaded.loadCostume(costume);
}
-void ScummEngine::NES_cost_decodeData(Actor *a, int frame, uint usemask) {
- int anim;
- NESCostume lc(this);
-
- lc.loadCostume(a->_costume);
-
- anim = newDirToOldDir(a->getFacing()) + frame * 4;
-
- if (anim > lc._numAnim) {
- return;
- }
-
- a->_cost.curpos[0] = 0;
- a->_cost.start[0] = 0;
- a->_cost.end[0] = lc._baseptr[2 + 8 * frame + 2 * newDirToOldDir(a->getFacing()) + 1];
- a->_cost.frame[0] = frame;
-}
-
-void ScummEngine::cost_decodeData(Actor *a, int frame, uint usemask) {
+void ClassicCostumeLoader::costumeDecodeData(Actor *a, int frame, uint usemask) {
const byte *r;
uint mask, j;
int i;
byte extra, cmd;
int anim;
- ClassicCostume lc(this);
- lc.loadCostume(a->_costume);
+ loadCostume(a->_costume);
anim = newDirToOldDir(a->getFacing()) + frame * 4;
- if (anim > lc._numAnim) {
+ if (anim > _numAnim) {
return;
}
- r = lc._baseptr + READ_LE_UINT16(lc._dataOffsets + anim * 2);
+ r = _baseptr + READ_LE_UINT16(_dataOffsets + anim * 2);
- if (r == lc._baseptr) {
+ if (r == _baseptr) {
return;
}
- if (_version == 1) {
+ if (_vm->_version == 1) {
mask = *r++ << 8;
} else {
mask = READ_LE_UINT16(r);
@@ -880,7 +832,7 @@ void ScummEngine::cost_decodeData(Actor *a, int frame, uint usemask) {
i = 0;
do {
if (mask & 0x8000) {
- if (_version <= 3) {
+ if (_vm->_version <= 3) {
j = *r++;
if (j == 0xFF)
@@ -896,7 +848,7 @@ void ScummEngine::cost_decodeData(Actor *a, int frame, uint usemask) {
a->_cost.frame[i] = frame;
} else {
extra = *r++;
- cmd = lc._animCmds[j];
+ cmd = _animCmds[j];
if (cmd == 0x7A) {
a->_cost.stopped &= ~(1 << i);
} else if (cmd == 0x79) {
@@ -957,7 +909,7 @@ void ClassicCostumeRenderer::setCostume(int costume) {
_loaded.loadCostume(costume);
}
-byte ClassicCostume::increaseAnims(Actor *a) {
+byte ClassicCostumeLoader::increaseAnims(Actor *a) {
int i;
byte r = 0;
@@ -968,14 +920,7 @@ byte ClassicCostume::increaseAnims(Actor *a) {
return r;
}
-byte NESCostume::increaseAnim(Actor *a, int slot) {
- a->_cost.curpos[slot]++;
- if (a->_cost.curpos[slot] >= a->_cost.end[slot])
- a->_cost.curpos[slot] = a->_cost.start[slot];
- return 0;
-}
-
-byte ClassicCostume::increaseAnim(Actor *a, int slot) {
+byte ClassicCostumeLoader::increaseAnim(Actor *a, int slot) {
int highflag;
int i, end;
byte code, nc;
@@ -1029,6 +974,71 @@ byte ClassicCostume::increaseAnim(Actor *a, int slot) {
} while (1);
}
+/**
+ * costume ID -> v1MMNESLookup[] -> desc -> lens & offs -> data -> Gfx & pal
+ */
+void NESCostumeLoader::loadCostume(int id) {
+ const byte *src;
+ int frameset, framenum;
+ int offset;
+
+ _id = id;
+ _baseptr = _vm->getResourceAddress(rtCostume, id);
+
+ _dataOffsets = _baseptr + 4;
+
+ frameset = 0;
+ framenum = 0;
+
+ src = _dataOffsets;
+ // Cost(a)
+ offset = src[(frameset * 4 + framenum) * 2];
+
+ // Lookup & desc
+ offset = READ_LE_UINT16(_vm->_NEScostdesc + v1MMNESLookup[_id] * 2);
+ if (v1MMNESLookup[_id] * 2 + 2 < READ_LE_UINT16(_vm->_NEScostdesc - 2)) {
+ _numAnim = (READ_LE_UINT16(_vm->_NEScostdesc + v1MMNESLookup[_id] * 2 + 2) - offset);
+ } else {
+ _numAnim = ((READ_LE_UINT16(_vm->_NEScostlens - 2) - 2) - offset);
+ }
+}
+
+void NESCostumeLoader::costumeDecodeData(Actor *a, int frame, uint usemask) {
+ int anim;
+
+ loadCostume(a->_costume);
+
+ anim = newDirToOldDir(a->getFacing()) + frame * 4;
+
+ if (anim > _numAnim) {
+ return;
+ }
+
+ a->_cost.curpos[0] = 0;
+ a->_cost.start[0] = 0;
+ a->_cost.end[0] = _baseptr[2 + 8 * frame + 2 * newDirToOldDir(a->getFacing()) + 1];
+ a->_cost.frame[0] = frame;
+}
+
+byte NESCostumeLoader::increaseAnims(Actor *a) {
+ int i;
+ byte r = 0;
+
+ for (i = 0; i != 16; i++) {
+ if (a->_cost.curpos[i] != 0xFFFF)
+ r += increaseAnim(a, i);
+ }
+ return r;
+}
+
+byte NESCostumeLoader::increaseAnim(Actor *a, int slot) {
+ a->_cost.curpos[slot]++;
+ if (a->_cost.curpos[slot] >= a->_cost.end[slot])
+ a->_cost.curpos[slot] = a->_cost.start[slot];
+ return 0;
+}
+
+
} // End of namespace Scumm
#ifdef __PALM_OS__
diff --git a/scumm/costume.h b/scumm/costume.h
index fb311608a4..9cca20eaea 100644
--- a/scumm/costume.h
+++ b/scumm/costume.h
@@ -25,10 +25,7 @@
namespace Scumm {
-class ClassicCostume : public BaseCostume {
-protected:
- ScummEngine *_vm;
-
+class ClassicCostumeLoader : public BaseCostumeLoader {
public:
int _id;
const byte *_baseptr;
@@ -41,21 +38,30 @@ public:
byte _format;
bool _mirror;
- ClassicCostume(ScummEngine *vm) :
- _vm(vm), _id(-1), _baseptr(0), _animCmds(0), _dataOffsets(0), _palette(0),
+ ClassicCostumeLoader(ScummEngine *vm) :
+ BaseCostumeLoader(vm),
+ _id(-1), _baseptr(0), _animCmds(0), _dataOffsets(0), _palette(0),
_frameOffsets(0), _numColors(0), _numAnim(0), _format(0), _mirror(false) {}
void loadCostume(int id);
+ void costumeDecodeData(Actor *a, int frame, uint usemask);
byte increaseAnims(Actor *a);
protected:
byte increaseAnim(Actor *a, int slot);
};
-class NESCostume : public ClassicCostume {
+class NESCostumeLoader : public BaseCostumeLoader {
public:
- NESCostume(ScummEngine *vm) : ClassicCostume(vm) {}
+ int _id;
+ const byte *_baseptr;
+ const byte *_dataOffsets;
+ byte _numAnim;
+
+ NESCostumeLoader(ScummEngine *vm) : BaseCostumeLoader(vm) {}
void loadCostume(int id);
+ void costumeDecodeData(Actor *a, int frame, uint usemask);
+ byte increaseAnims(Actor *a);
protected:
byte increaseAnim(Actor *a, int slot);
@@ -63,7 +69,7 @@ protected:
class ClassicCostumeRenderer : public BaseCostumeRenderer {
protected:
- ClassicCostume _loaded;
+ ClassicCostumeLoader _loaded;
byte _scaleIndexX; /* must wrap at 256 */
byte _scaleIndexY;
@@ -89,7 +95,7 @@ protected:
class NESCostumeRenderer : public BaseCostumeRenderer {
protected:
- NESCostume _loaded;
+ NESCostumeLoader _loaded;
public:
NESCostumeRenderer(ScummEngine *vm) : BaseCostumeRenderer(vm), _loaded(vm) {}
diff --git a/scumm/scumm.h b/scumm/scumm.h
index 485619588e..31006b61a8 100644
--- a/scumm/scumm.h
+++ b/scumm/scumm.h
@@ -848,13 +848,6 @@ public:
void costumeDecodeData(Actor *a, int frame, uint usemask);
bool isCostumeInUse(int i) const;
- // Classic costume class
- void cost_decodeData(Actor *a, int frame, uint usemask);
-
- // NEWS costume class
- void NES_cost_decodeData(Actor *a, int frame, uint usemask);
- void cost_decodeNESCostumeGfx();
-
// Akos Class
struct {
int16 cmd;