diff options
author | Max Horn | 2002-06-04 23:32:53 +0000 |
---|---|---|
committer | Max Horn | 2002-06-04 23:32:53 +0000 |
commit | d35eed21f1cbd769bdad4e3028d16361c7bf9f74 (patch) | |
tree | 3d38928c8c0f89bdbc51dd660cdb79da4b5e30c6 | |
parent | 31a2efd89cdae6f8722af77177dba2a7763a94a5 (diff) | |
download | scummvm-rg350-d35eed21f1cbd769bdad4e3028d16361c7bf9f74.tar.gz scummvm-rg350-d35eed21f1cbd769bdad4e3028d16361c7bf9f74.tar.bz2 scummvm-rg350-d35eed21f1cbd769bdad4e3028d16361c7bf9f74.zip |
more Actor class cleanup; renamed unkRoomFunc4 to palManipulate and added an icky, wrong implementation for it - yes this is complete nonsense but I'll try to replace it with the right thing RSN :-)
svn-id: r4404
-rw-r--r-- | actor.cpp | 106 | ||||
-rw-r--r-- | actor.h | 5 | ||||
-rw-r--r-- | gfx.cpp | 39 | ||||
-rw-r--r-- | object.cpp | 6 | ||||
-rw-r--r-- | script.cpp | 58 | ||||
-rw-r--r-- | script_v1.cpp | 10 | ||||
-rw-r--r-- | script_v2.cpp | 12 | ||||
-rw-r--r-- | scumm.h | 10 | ||||
-rw-r--r-- | scummvm.cpp | 56 |
9 files changed, 171 insertions, 131 deletions
@@ -452,6 +452,45 @@ void Actor::startAnimActor(int frame) } } +void Actor::animateActor(int anim) +{ + int cmd, dir; + + if (_vm->_features & GF_AFTER_V7) { + + if (anim == 0xFF) + anim = 2000; + + cmd = anim / 1000; + dir = anim % 1000; + + } else { + + cmd = anim >> 2; + dir = Scumm::oldDirToNewDir(anim & 3); + + // Convert into old cmd code + cmd = 0x3F - cmd + 2; + + } + + switch (cmd) { + case 2: + stopActorMoving(); + startAnimActor(standFrame); + break; + case 3: + moving &= ~MF_TURN; + setActorDirection(dir); + break; + case 4: + turnToDirection(dir); + break; + default: + startAnimActor(anim); + } +} + void Actor::setActorDirection(int direction) { uint aMask; @@ -499,7 +538,7 @@ void Scumm::putActor(Actor * a, int dstX, int dstY, byte room) } if (a->visible) { - if (_currentRoom == room) { + if (a->isInCurrentRoom()) { if (a->moving) { a->startAnimActor(a->standFrame); a->moving = 0; @@ -509,7 +548,7 @@ void Scumm::putActor(Actor * a, int dstX, int dstY, byte room) a->hideActor(); } } else { - if (_currentRoom == room) + if (a->isInCurrentRoom()) a->showActor(); } } @@ -526,7 +565,7 @@ int Scumm::getActorXYPos(Actor * a) return 0; } -AdjustBoxResult Scumm::adjustXYToBeInBox(Actor * a, int dstX, int dstY, int pathfrom) +AdjustBoxResult Actor::adjustXYToBeInBox(int dstX, int dstY, int pathfrom) { AdjustBoxResult abr, tmp; uint threshold; @@ -535,7 +574,7 @@ AdjustBoxResult Scumm::adjustXYToBeInBox(Actor * a, int dstX, int dstY, int path int firstValidBox, j; byte flags, b; - if (_features & GF_SMALL_HEADER) + if (_vm->_features & GF_SMALL_HEADER) firstValidBox = 0; else firstValidBox = 1; @@ -544,44 +583,44 @@ AdjustBoxResult Scumm::adjustXYToBeInBox(Actor * a, int dstX, int dstY, int path abr.y = dstY; abr.dist = 0; - if ((_features & GF_SMALL_HEADER) && getClass(a->number, 22)) + if ((_vm->_features & GF_SMALL_HEADER) && _vm->getClass(number, 22)) return abr; - if (a && a->ignoreBoxes == 0) { + if (ignoreBoxes == 0) { threshold = 30; while (1) { iterations++; if (iterations > 1000) return abr; /* Safety net */ - box = getNumBoxes() - 1; + box = _vm->getNumBoxes() - 1; if (box == 0) return abr; best = (uint) 0xFFFF; b = 0; - if (((_features & GF_SMALL_HEADER) && box) - || !(_features & GF_SMALL_HEADER)) + if (((_vm->_features & GF_SMALL_HEADER) && box) + || !(_vm->_features & GF_SMALL_HEADER)) for (j = box; j >= firstValidBox; j--) { - flags = getBoxFlags(j); - if (flags & 0x80 && (!(flags & 0x20) || getClass(a->number, 0x1F))) + flags = _vm->getBoxFlags(j); + if (flags & 0x80 && (!(flags & 0x20) || _vm->getClass(number, 0x1F))) continue; - if (pathfrom && (getPathToDestBox(pathfrom, j) == -1)) + if (pathfrom && (_vm->getPathToDestBox(pathfrom, j) == -1)) continue; - if (!inBoxQuickReject(j, dstX, dstY, threshold)) + if (!_vm->inBoxQuickReject(j, dstX, dstY, threshold)) continue; - if (checkXYInBoxBounds(j, dstX, dstY)) { + if (_vm->checkXYInBoxBounds(j, dstX, dstY)) { abr.x = dstX; abr.y = dstY; abr.dist = j; return abr; } - tmp = getClosestPtOnBox(j, dstX, dstY); + tmp = _vm->getClosestPtOnBox(j, dstX, dstY); if (tmp.dist >= best) continue; @@ -612,7 +651,7 @@ void Actor::adjustActorPos() AdjustBoxResult abr; byte flags; - abr = _vm->adjustXYToBeInBox(this, x, y, 0); + abr = adjustXYToBeInBox(x, y, 0); x = abr.x; y = abr.y; @@ -920,7 +959,7 @@ void Scumm::processActors() return; // Sort actors by position before we draw them (to ensure that actors in - // front are drawn after thos behind them). + // front are drawn after those "behind" them). ac = actors; cnt = numactors; do { @@ -1182,7 +1221,7 @@ void Actor::startWalkActor(int destX, int destY, int dir) { AdjustBoxResult abr; - abr = _vm->adjustXYToBeInBox(this, destX, destY, walkbox); + abr = adjustXYToBeInBox(destX, destY, walkbox); if (!isInCurrentRoom()) { x = abr.x; @@ -1199,7 +1238,7 @@ void Actor::startWalkActor(int destX, int destY, int dir) if (_vm->checkXYInBoxBounds(walkdata.destbox, abr.x, abr.y)) { abr.dist = walkdata.destbox; } else { - abr = _vm->adjustXYToBeInBox(this, abr.x, abr.y, walkbox); + abr = adjustXYToBeInBox(abr.x, abr.y, walkbox); } if (moving && walkdata.destdir == dir && walkdata.destx == abr.x && walkdata.desty == abr.y) @@ -1380,3 +1419,32 @@ void Actor::walkActorOld() moving |= MF_NEW_LEG; goto restart; } + +void Scumm::resetActorBgs() +{ + Actor *a; + int i; + uint32 onlyActorFlags, bitpos; + + for (i = 0; i < 40; i++) { + onlyActorFlags = (gfxUsageBits[_screenStartStrip + i] &= 0x3FFFFFFF); + a = getFirstActor(); + bitpos = 1; + + while (onlyActorFlags) { + if (onlyActorFlags & 1 && a->top != 0xFF && a->needBgReset) { + gfxUsageBits[_screenStartStrip + i] ^= bitpos; + + if((a->bottom - a->top) >=0) + gdi.resetBackground(a->top, a->bottom, i); + } + bitpos <<= 1; + onlyActorFlags >>= 1; + a++; + } + } + + for (i = 1, a = getFirstActor(); ++a, i < NUM_ACTORS; i++) { + a->needBgReset = false; + } +} @@ -70,7 +70,6 @@ struct CostumeData { class Actor { -//protected: public: int x, y, top, bottom; int elevation; @@ -131,6 +130,7 @@ public: int updateActorDirection(); void setActorDirection(int direction); + AdjustBoxResult adjustXYToBeInBox(int dstX, int dstY, int pathfrom); void adjustActorPos(); void turnToDirection(int newdir); void walkActor(); @@ -142,8 +142,11 @@ public: void remapActor(int b, int c, int d, int e); void walkActorOld(); + + void animateActor(int anim); bool isInCurrentRoom() { return room == _vm->_currentRoom; } + int getRoom() { return room; } int getAnimVar(byte var) { return animVariable[var]; } void setAnimVar(byte var, int value) { animVariable[var] = value; } @@ -311,8 +311,8 @@ void Scumm::setCameraFollows(Actor * a) cd->_follows = a->number; - if (a->room != _currentRoom) { - startScene(a->room, 0, 0); + if (!a->isInCurrentRoom()) { + startScene(a->getRoom(), 0, 0); } ax = abs(a->x - cd->_cur.x); @@ -332,8 +332,8 @@ void Scumm::setCameraFollows(Actor * a) cd->_mode = CM_FOLLOW_ACTOR; cd->_follows = a->number; - if (a->room != _currentRoom) { - startScene(a->room, 0, 0); + if (!a->isInCurrentRoom()) { + startScene(a->getRoom(), 0, 0); cd->_mode = CM_FOLLOW_ACTOR; cd->_cur.x = a->x; setCameraAt(cd->_cur.x, 0); @@ -346,7 +346,7 @@ void Scumm::setCameraFollows(Actor * a) setCameraAt(a->x, 0); for (i = 1, a = getFirstActor(); ++a, i < NUM_ACTORS; i++) { - if (a->room == _currentRoom) + if (a->isInCurrentRoom()) a->needRedraw = true; } runHook(0); @@ -2216,35 +2216,6 @@ void Scumm::screenEffect(int effect) _screenEffectFlag = true; } -void Scumm::resetActorBgs() -{ - Actor *a; - int i; - uint32 onlyActorFlags, bitpos; - - for (i = 0; i < 40; i++) { - onlyActorFlags = (gfxUsageBits[_screenStartStrip + i] &= 0x3FFFFFFF); - a = getFirstActor(); - bitpos = 1; - - while (onlyActorFlags) { - if (onlyActorFlags & 1 && a->top != 0xFF && a->needBgReset) { - gfxUsageBits[_screenStartStrip + i] ^= bitpos; - - if((a->bottom - a->top) >=0) - gdi.resetBackground(a->top, a->bottom, i); - } - bitpos <<= 1; - onlyActorFlags >>= 1; - a++; - } - } - - for (i = 1, a = getFirstActor(); ++a, i < NUM_ACTORS; i++) { - a->needBgReset = false; - } -} - void Gdi::resetBackground(int top, int bottom, int strip) { VirtScreen *vs = &_vm->virtscr[0]; diff --git a/object.cpp b/object.cpp index ca09c6b33e..63776d83a0 100644 --- a/object.cpp +++ b/object.cpp @@ -224,8 +224,8 @@ int Scumm::getObjActToObjActDist(int a, int b) if (b < NUM_ACTORS) actb = derefActorSafe(b, "getObjActToObjActDist(2)"); - if (acta && actb && acta->room == actb->room && acta->room && - acta->room != _currentRoom) + if (acta && actb && acta->getRoom() == actb->getRoom() && acta->getRoom() && + !acta->isInCurrentRoom()) return 0; if (getObjectOrActorXY(a) == -1) @@ -238,7 +238,7 @@ int Scumm::getObjActToObjActDist(int a, int b) return 0xFF; if (acta) { - AdjustBoxResult r = adjustXYToBeInBox(acta, _xPos, _yPos, 0); + AdjustBoxResult r = acta->adjustXYToBeInBox(_xPos, _yPos, 0); _xPos = r.x; _yPos = r.y; } diff --git a/script.cpp b/script.cpp index 4bcef00604..45dc2aa916 100644 --- a/script.cpp +++ b/script.cpp @@ -889,61 +889,11 @@ void Scumm::faceActorToObj(int act, int obj) void Scumm::animateActor(int act, int anim) { - if (_features & GF_AFTER_V7) { - int cmd, dir; - Actor *a; - - a = derefActorSafe(act, "animateActor"); - - if (anim == 0xFF) - anim = 2000; - - cmd = anim / 1000; - dir = anim % 1000; - - switch (cmd) { - case 2: - a->stopActorMoving(); - a->startAnimActor(a->standFrame); - break; - case 3: - a->moving &= ~MF_TURN; - a->setActorDirection(dir); - break; - case 4: - a->turnToDirection(dir); - break; - default: - a->startAnimActor(anim); - } - - } else { - int dir; - Actor *a; - - a = derefActorSafe(act, "animateActor"); - if (!a) - return; - - dir = anim & 3; - - switch (anim >> 2) { - case 0x3F: - a->stopActorMoving(); - a->startAnimActor(a->standFrame); - break; - case 0x3E: - a->moving &= ~MF_TURN; - a->setActorDirection(oldDirToNewDir(dir)); - break; - case 0x3D: - a->turnToDirection(oldDirToNewDir(dir)); - break; - default: - a->startAnimActor(anim); - } + Actor *a = derefActorSafe(act, "animateActor"); + if (!a) + return; - } + a->animateActor(anim); } bool Scumm::isScriptRunning(int script) diff --git a/script_v1.cpp b/script_v1.cpp index 70c35d2e13..abb2f8c484 100644 --- a/script_v1.cpp +++ b/script_v1.cpp @@ -801,7 +801,7 @@ void Scumm::o5_actorSet() a->ignoreBoxes = 1; a->forceClip = 0; FixRoom: - if (a->room == _currentRoom) + if (a->isInCurrentRoom()) putActor(a, a->x, a->y, a->room); break; case 21: /* followboxes */ @@ -2047,14 +2047,14 @@ void Scumm::o5_roomOps() ; warning("roomops:14 load-string(%d,\"%s\") not implemented", a, buf); break; - case 15: /* palmanip? */ + case 15: /* palmanip */ a = getVarOrDirectByte(0x80); _opcode = fetchScriptByte(); b = getVarOrDirectByte(0x80); c = getVarOrDirectByte(0x40); _opcode = fetchScriptByte(); d = getVarOrDirectByte(0x80); - unkRoomFunc4(b, c, a, d, 1); + palManipulate(b, c, a, d, 1); break; case 16: @@ -2566,7 +2566,7 @@ void Scumm::o5_walkActorToActor() if (!a) return; - if (a->room != _currentRoom) { + if (!a->isInCurrentRoom()) { getVarOrDirectByte(0x40); fetchScriptByte(); return; @@ -2583,7 +2583,7 @@ void Scumm::o5_walkActorToActor() if (!a2) return; - if (a2->room != _currentRoom) { + if (!a2->isInCurrentRoom()) { fetchScriptByte(); return; } diff --git a/script_v2.cpp b/script_v2.cpp index ccad06cb1b..800e4e56c7 100644 --- a/script_v2.cpp +++ b/script_v2.cpp @@ -1351,7 +1351,7 @@ void Scumm::o6_walkActorToObj() a2 = derefActorSafe(obj, "o6_walkActorToObj(2)"); if (!a2) return; - if (a2->room != _currentRoom || a->room != _currentRoom) + if (!a->isInCurrentRoom() || !a->isInCurrentRoom()) return; if (dist == 0) { dist = a2->scalex * a2->width / 0xFF; @@ -1883,7 +1883,7 @@ void Scumm::o6_roomOps() c = pop(); b = pop(); a = pop(); - unkRoomFunc4(a, b, c, d, 1); + palManipulate(a, b, c, d, 1); break; case 187: /* color cycle delay */ @@ -2001,7 +2001,7 @@ void Scumm::o6_actorSet() else a->forceClip = 0; FixRooms:; - if (a->room == _currentRoom) + if (a->isInCurrentRoom()) putActor(a, a->x, a->y, a->room); break; case 96: @@ -2049,7 +2049,7 @@ void Scumm::o6_actorSet() a->startAnimActor(a->standFrame); break; case 230: /* set direction */ - a->moving &= ~4; + a->moving &= ~MF_TURN; a->setActorDirection(pop()); break; case 231: /* turn to direction */ @@ -2369,7 +2369,7 @@ void Scumm::o6_wait() case 226:{ /* wait until actor drawn */ Actor *a = derefActorSafe(pop(), "o6_wait:226"); int offs = (int16) fetchScriptWord(); - if (a->room == _currentRoom && a->needRedraw) { + if (a->isInCurrentRoom() && a->needRedraw) { _scriptPointer += offs; o6_breakHere(); } @@ -2378,7 +2378,7 @@ void Scumm::o6_wait() case 232:{ /* wait until actor stops turning */ Actor *a = derefActorSafe(pop(), "o6_wait:226"); int offs = (int16) fetchScriptWord(); - if (a->room == _currentRoom && a->moving & 4) { + if (a->isInCurrentRoom() && a->moving & MF_TURN) { _scriptPointer += offs; o6_breakHere(); } @@ -639,7 +639,7 @@ public: int8 _userPut; int _resourceHeaderSize; void unkRoomFunc3(int a, int b, int c, int d, int e); - void unkRoomFunc4(int a, int b, int c, int d, int e); + void palManipulate(int a, int b, int c, int d, int e); void setScaleItem(int slot, int a, int b, int c, int d); void clearClickedStatus(); void startManiac(); @@ -863,9 +863,6 @@ public: /* Should be in Costume class */ void loadCostume(LoadedCostume *lc, int costume); -// void cost_setPalette(CostumeRenderer *cr, byte *palette); -// void cost_setFacing(CostumeRenderer *cr, Actor *a); -// void cost_setCostume(CostumeRenderer *cr, 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); @@ -984,8 +981,8 @@ public: uint32 *_classData; - int newDirToOldDir(int dir); - int oldDirToNewDir(int dir); + static int newDirToOldDir(int dir); + static int oldDirToNewDir(int dir); static int normalizeAngle(int angle); int getAngleFromPos(int x, int y); @@ -996,7 +993,6 @@ public: int getProgrDirChange(Actor *a, int mode); int getActorXYPos(Actor *a); - AdjustBoxResult adjustXYToBeInBox(Actor *a, int x, int y, int pathfrom); void walkActors(); void playActorSounds(); void setActorRedrawFlags(); diff --git a/scummvm.cpp b/scummvm.cpp index 26653cb0cd..746ba973b8 100644 --- a/scummvm.cpp +++ b/scummvm.cpp @@ -789,10 +789,62 @@ void Scumm::unkRoomFunc3(int a, int b, int c, int d, int e) } -void Scumm::unkRoomFunc4(int a, int b, int c, int d, int e) +void Scumm::palManipulate(int palettes, int brightness, int color, int time, int e) { + byte *cptr; + /* TODO: implement this */ - warning("unkRoomFunc4: not implemented"); + warning("palManipulate(%d, %d, %d, %d): not implemented", palettes, brightness, color, time); + + printf("_curPalIndex=%d\n", _curPalIndex); + + cptr = _currentPalette + color * 3; + printf("color %d = (%d,%d,%d)\n", color, (int)*cptr++, (int)*cptr++, (int)*cptr++); + +// darkenPalette(0, 255, 0xFF+0x10, brightness, brightness); + { + int startColor = 0; + int endColor = 255; + int redScale = 0xFF; + int greenScale = brightness; + int blueScale = brightness; + byte *cur; + int num; + int color; + + cptr = _currentPalette + startColor * 3; + cur = _currentPalette + startColor * 3; + num = endColor - startColor + 1; + + do { + color = *cptr++; + if (redScale != 0xFF) + color = color * redScale / 0xFF; + if (color > 255) + color = 255; + *cur++ = color; + + color = *cptr++; + if (greenScale != 0xFF) + color = color * greenScale / 0xFF; + if (color > 255) + color = 255; + *cur++ = color; + + color = *cptr++; + if (blueScale != 0xFF) + color = color * blueScale / 0xFF; + if (color > 255) + color = 255; + *cur++ = color; + } while (--num); + setDirtyColors(startColor, endColor); + } + + cptr = _currentPalette + color * 3; + printf("color %d = (%d,%d,%d)\n", color, (int)*cptr++, (int)*cptr++, (int)*cptr++); + +// setPalette(palettes); } void Scumm::pauseGame(bool user) |