diff options
-rw-r--r-- | actor.cpp | 58 | ||||
-rw-r--r-- | actor.h | 2 | ||||
-rw-r--r-- | costume.cpp | 56 | ||||
-rw-r--r-- | object.cpp | 2 | ||||
-rw-r--r-- | scumm.h | 27 |
5 files changed, 61 insertions, 84 deletions
@@ -197,12 +197,12 @@ int Actor::remapDirection(int dir) flipY = (walkdata.YXFactor > 0); // Check for X-Flip - if ((flags & 0x08) || _vm->getClass(number, 0x1E)) { + if ((flags & 0x08) || isInClass(0x1E)) { // 0x1E = 30 dir = 360 - dir; flipX = !flipX; } // Check for Y-Flip - if ((flags & 0x10) || _vm->getClass(number, 0x1D)) { + if ((flags & 0x10) || isInClass(0x1D)) { // 0x1E = 29 dir = 180 - dir; flipY = !flipY; } @@ -340,7 +340,7 @@ void Actor::setupActorScale() // FIXME: Special 'no scaling' class for MI1 VGA Floppy // Not totally sure if this is correct. - if (_vm->_gameId == GID_MONKEY_VGA && _vm->getClass(number, 0x96)) + if (_vm->_gameId == GID_MONKEY_VGA && isInClass(0x96)) return; if (_vm->_features & GF_NO_SCALLING) { @@ -577,7 +577,7 @@ AdjustBoxResult Actor::adjustXYToBeInBox(int dstX, int dstY, int pathfrom) abr.y = dstY; abr.dist = 0; - if ((_vm->_features & GF_SMALL_HEADER) && _vm->getClass(number, 22)) + if ((_vm->_features & GF_SMALL_HEADER) && isInClass(22)) return abr; if (ignoreBoxes == 0) { @@ -598,7 +598,7 @@ AdjustBoxResult Actor::adjustXYToBeInBox(int dstX, int dstY, int pathfrom) || !(_vm->_features & GF_SMALL_HEADER)) for (j = box; j >= firstValidBox; j--) { flags = _vm->getBoxFlags(j); - if (flags & 0x80 && (!(flags & 0x20) || _vm->getClass(number, 0x1F))) + if (flags & 0x80 && (!(flags & 0x20) || isInClass(0x1F))) continue; if (pathfrom >= firstValidBox && (_vm->getPathToDestBox(pathfrom, j) == -1)) @@ -835,27 +835,24 @@ void Scumm::processActors() void Actor::drawActorCostume() { - if (!(_vm->_features & GF_AFTER_V7)) { - CostumeRenderer cr; - - if (!needRedraw) - return; + if (!needRedraw) + return; - if (_vm->getClass(number, 20)) - mask = 0; - else if (_vm->getClass(number, 21)) - forceClip = 1; + // FIXME: ugly fix for samnmax inventory + if (_vm->_gameId == GID_SAMNMAX && _vm->getState(995)) + return; - // FIXME: ugly fix for samnmax inventory - if (_vm->_gameId == GID_SAMNMAX && _vm->getState(995)) - return; + needRedraw = false; - needRedraw = false; + setupActorScale(); - setupActorScale(); + if (!(_vm->_features & GF_AFTER_V7)) { + CostumeRenderer cr(_vm); - /* First, zero initialize all fields */ - memset(&cr, 0, sizeof(cr)); + if (isInClass(20)) + mask = 0; + else if (isInClass(21)) + forceClip = 1; cr._actorX = x - _vm->virtscr->xstart; cr._actorY = y - elevation; @@ -863,7 +860,6 @@ void Actor::drawActorCostume() cr._scaleY = scaley; cr._outheight = _vm->virtscr->height; - cr._vm = _vm; cr._zbuf = mask; if (cr._zbuf > _vm->gdi._numZBuffer) @@ -889,13 +885,6 @@ void Actor::drawActorCostume() } else { AkosRenderer ar(_vm); - if (!needRedraw) - return; - - needRedraw = false; - - setupActorScale(); - ar.x = x - _vm->virtscr->xstart; ar.y = y - elevation; ar.scale_x = scalex; @@ -948,9 +937,9 @@ void Actor::actorAnimate() needBgReset = true; } } else { - LoadedCostume lc; - _vm->loadCostume(&lc, costume); - if (_vm->cost_increaseAnims(&lc, this)) { + LoadedCostume lc(_vm); + lc.loadCostume(costume); + if (lc.increaseAnims(this)) { needRedraw = true; needBgReset = true; } @@ -1390,3 +1379,8 @@ void Scumm::resetActorBgs() a->needBgReset = false; } } + +bool Actor::isInClass(int cls) +{ + return _vm->getClass(number, cls); +} @@ -161,6 +161,8 @@ public: animVariable[var] = value; } +protected: + bool isInClass(int cls); }; #endif diff --git a/costume.cpp b/costume.cpp index 92188a1955..6ca5f5618d 100644 --- a/costume.cpp +++ b/costume.cpp @@ -790,8 +790,7 @@ void CostumeRenderer::proc_special(Actor *a, byte mask2) } -#if 0 -void CostumeRenderer::loadCostume(int id) +void LoadedCostume::loadCostume(int id) { _ptr = _vm->getResourceAddress(rtCostume, id); @@ -820,7 +819,6 @@ void CostumeRenderer::loadCostume(int id) _dataptr = _ptr + READ_LE_UINT16(_ptr + _numColors + 8); } -#endif byte CostumeRenderer::drawOneSlot(Actor *a, int slot) { @@ -867,36 +865,6 @@ int Scumm::cost_frameToAnim(Actor *a, int frame) return newDirToOldDir(a->facing) + frame * 4; } -void Scumm::loadCostume(LoadedCostume *lc, int costume) -{ - lc->_ptr = getResourceAddress(rtCostume, costume); - - if (_features & GF_AFTER_V6) { - lc->_ptr += 8; - } else if (!(_features & GF_SMALL_HEADER)) { - lc->_ptr += 2; - } - - switch (lc->_ptr[7] & 0x7F) { - case 0x58: - lc->_numColors = 16; - break; - case 0x59: - lc->_numColors = 32; - break; - case 0x60: /* New since version 6 */ - lc->_numColors = 16; - break; - case 0x61: /* New since version 6 */ - lc->_numColors = 32; - break; - default: - error("Costume %d is invalid", costume); - } - - lc->_dataptr = lc->_ptr + READ_LE_UINT16(lc->_ptr + lc->_numColors + 8); -} - void Scumm::cost_decodeData(Actor *a, int frame, uint usemask) { byte *p, *r; @@ -905,9 +873,9 @@ void Scumm::cost_decodeData(Actor *a, int frame, uint usemask) byte extra, cmd; byte *dataptr; int anim; - LoadedCostume lc; + LoadedCostume lc(this); - loadCostume(&lc, a->costume); + lc.loadCostume(a->costume); anim = cost_frameToAnim(a, frame); @@ -992,22 +960,22 @@ void CostumeRenderer::setFacing(uint16 facing) void CostumeRenderer::setCostume(int costume) { - _vm->loadCostume(&_loaded, costume); + _loaded.loadCostume(costume); } -byte Scumm::cost_increaseAnims(LoadedCostume *lc, Actor *a) +byte LoadedCostume::increaseAnims(Actor *a) { int i; byte r = 0; for (i = 0; i != 16; i++) { if (a->cost.curpos[i] != 0xFFFF) - r += cost_increaseAnim(lc, a, i); + r += increaseAnim(a, i); } return r; } -byte Scumm::cost_increaseAnim(LoadedCostume *lc, Actor *a, int slot) +byte LoadedCostume::increaseAnim(Actor *a, int slot) { int highflag; int i, end; @@ -1019,7 +987,7 @@ byte Scumm::cost_increaseAnim(LoadedCostume *lc, Actor *a, int slot) highflag = a->cost.curpos[slot] & 0x8000; i = a->cost.curpos[slot] & 0x7FFF; end = a->cost.end[slot]; - code = lc->_dataptr[i] & 0x7F; + code = _dataptr[i] & 0x7F; do { if (!highflag) { @@ -1029,16 +997,16 @@ byte Scumm::cost_increaseAnim(LoadedCostume *lc, Actor *a, int slot) if (i != end) i++; } - nc = lc->_dataptr[i]; + nc = _dataptr[i]; if (nc == 0x7C) { a->cost.animCounter1++; if (a->cost.start[slot] != end) continue; } else { - if (_features & GF_AFTER_V6) { + if (_vm->_features & GF_AFTER_V6) { if (nc >= 0x71 && nc <= 0x78) { - addSoundToQueue2(a->sound[nc - 0x71]); + _vm->addSoundToQueue2(a->sound[nc - 0x71]); if (a->cost.start[slot] != end) continue; } @@ -1052,7 +1020,7 @@ byte Scumm::cost_increaseAnim(LoadedCostume *lc, Actor *a, int slot) } a->cost.curpos[slot] = i | highflag; - return (lc->_dataptr[i] & 0x7F) != code; + return (_dataptr[i] & 0x7F) != code; } while (1); } diff --git a/object.cpp b/object.cpp index 22728137db..0943c134db 100644 --- a/object.cpp +++ b/object.cpp @@ -44,7 +44,7 @@ void Scumm::putClass(int obj, int cls, bool set) { checkRange(_numGlobalObjects - 1, 0, obj, "Object %d out of range in putClass"); cls &= 0x7F; - checkRange(32, 1, cls, "Class %d out of range in getClass"); + checkRange(32, 1, cls, "Class %d out of range in putClass"); if (_features & GF_SMALL_HEADER) { @@ -351,18 +351,31 @@ struct CharsetRenderer { void addLinebreaks(int a, byte *str, int pos, int maxwidth); }; -struct LoadedCostume { +class LoadedCostume { +protected: + Scumm *_vm; + +public: byte *_ptr; byte *_dataptr; byte _numColors; - + + LoadedCostume(Scumm *vm) : _vm(vm), _ptr(0), _dataptr(0), _numColors(0) {} + + void loadCostume(int id); + byte increaseAnims(Actor *a); + +protected: + byte increaseAnim(Actor *a, int slot); }; -struct CostumeRenderer { +class CostumeRenderer { +protected: Scumm *_vm; LoadedCostume _loaded; - + +public: byte *_shadow_table; byte *_frameptr; @@ -414,6 +427,9 @@ struct CostumeRenderer { void setPalette(byte *palette); void setFacing(uint16 facing); void setCostume(int costume); + +public: + CostumeRenderer(Scumm *vm) : _vm(vm), _loaded(vm) {} }; #define ARRAY_HDR_SIZE 6 @@ -873,9 +889,6 @@ public: int getDistanceBetween(bool is_obj_1, int b, int c, bool is_obj_2, int e, int f); /* Should be in Costume class */ - void loadCostume(LoadedCostume *lc, int costume); - byte cost_increaseAnims(LoadedCostume *lc, Actor *a); - byte cost_increaseAnim(LoadedCostume *lc, Actor *a, int slot); void cost_decodeData(Actor *a, int frame, uint usemask); int cost_frameToAnim(Actor *a, int frame); |