diff options
author | Gregory Montoir | 2004-01-06 14:21:50 +0000 |
---|---|---|
committer | Gregory Montoir | 2004-01-06 14:21:50 +0000 |
commit | ceda8aec0250ccc9be6ed98eae9679bb0c387cba (patch) | |
tree | 49658e4d23ac1d7c3bd7642d5f2a198f8ba224dd | |
parent | 065f2bb9eb0ac7b7d7b56ef1f8e76c2638cb484e (diff) | |
download | scummvm-rg350-ceda8aec0250ccc9be6ed98eae9679bb0c387cba.tar.gz scummvm-rg350-ceda8aec0250ccc9be6ed98eae9679bb0c387cba.tar.bz2 scummvm-rg350-ceda8aec0250ccc9be6ed98eae9679bb0c387cba.zip |
moved animation stuff to Graphics class
svn-id: r12182
-rw-r--r-- | queen/cutaway.cpp | 2 | ||||
-rw-r--r-- | queen/graphics.cpp | 155 | ||||
-rw-r--r-- | queen/graphics.h | 8 | ||||
-rw-r--r-- | queen/logic.cpp | 170 | ||||
-rw-r--r-- | queen/logic.h | 10 | ||||
-rw-r--r-- | queen/talk.cpp | 2 | ||||
-rw-r--r-- | queen/xref.txt | 2 |
7 files changed, 176 insertions, 173 deletions
diff --git a/queen/cutaway.cpp b/queen/cutaway.cpp index f68a02fd42..05e345a219 100644 --- a/queen/cutaway.cpp +++ b/queen/cutaway.cpp @@ -1023,7 +1023,7 @@ void Cutaway::run(char *nextFilename) { if (object->image == -3 || object->image == -4) { k++; if (object->name > 0) { - _vm->logic()->animReset(k); + _vm->graphics()->animReset(k); } } } diff --git a/queen/graphics.cpp b/queen/graphics.cpp index 683f185904..0bcbd72c35 100644 --- a/queen/graphics.cpp +++ b/queen/graphics.cpp @@ -668,6 +668,161 @@ uint16 Graphics::textWidth(const char* text) const { } +uint16 Graphics::animCreate(uint16 curImage, const Person *person) { + AnimFrame *animFrames = _newAnim[person->actor->bobNum]; + + uint16 allocatedFrames[256]; + memset(allocatedFrames, 0, sizeof(allocatedFrames)); + const char *p = person->anim; + int frame = 0; + uint16 f1, f2; + do { + sscanf(p, "%3hu,%3hu", &f1, &f2); + animFrames[frame].frame = f1; + animFrames[frame].speed = f2; + + if (f1 > 500) { + // SFX + allocatedFrames[f1 - 500] = 1; + } else { + allocatedFrames[f1] = 1; + } + + p += 8; + ++frame; + } while(f1 != 0); + + // ajust frame numbers + uint16 n = 1; + uint16 i; + for (i = 1; i <= 255; ++i) { + if (allocatedFrames[i] != 0) { + allocatedFrames[i] = n; + ++n; + } + } + for (i = 0; animFrames[i].frame != 0; ++i) { + uint16 frameNum = animFrames[i].frame; + if (frameNum > 500) { + animFrames[i].frame = curImage + allocatedFrames[frameNum - 500] + 500; + } else { + animFrames[i].frame = curImage + allocatedFrames[frameNum]; + } + } + + // unpack necessary frames + for (i = 1; i <= 255; ++i) { + if (allocatedFrames[i] != 0) { + ++curImage; + _vm->bankMan()->unpack(i, curImage, person->actor->bankNum); + } + } + + // start animation + bob(person->actor->bobNum)->animString(animFrames); + + return curImage; +} + + +void Graphics::animSetup(const GraphicData *gd, uint16 firstImage, uint16 bobNum, bool visible) { + int16 tempFrames[20]; + memset(tempFrames, 0, sizeof(tempFrames)); + uint16 numTempFrames = 0; + uint16 i, j; + for (i = 1; i <= _vm->logic()->graphicAnimCount(); ++i) { + const GraphicAnim *pga = _vm->logic()->graphicAnim(i); + if (pga->keyFrame == gd->firstFrame) { + int16 frame = pga->frame; + if (frame > 500) { // SFX + frame -= 500; + } + bool foundMatchingFrame = false; + for (j = 0; j < numTempFrames; ++j) { + if (tempFrames[j] == frame) { + foundMatchingFrame = true; + break; + } + } + if (!foundMatchingFrame) { + assert(numTempFrames < 20); + tempFrames[numTempFrames] = frame; + ++numTempFrames; + } + } + } + + // sort found frames ascending + bool swap = true; + while (swap) { + swap = false; + for (i = 0; i < numTempFrames - 1; ++i) { + if (tempFrames[i] > tempFrames[i + 1]) { + SWAP(tempFrames[i], tempFrames[i + 1]); + swap = true; + } + } + } + + // queen.c l.962-980 / l.1269-1294 + for (i = 0; i < gd->lastFrame; ++i) { + _vm->bankMan()->unpack(ABS(tempFrames[i]), firstImage + i, 15); + } + BobSlot *pbs = bob(bobNum); + pbs->animating = false; + if (visible) { + pbs->curPos(gd->x, gd->y); + if (tempFrames[0] < 0) { + pbs->xflip = true; + } + AnimFrame *paf = _newAnim[bobNum]; + for (i = 1; i <= _vm->logic()->graphicAnimCount(); ++i) { + const GraphicAnim *pga = _vm->logic()->graphicAnim(i); + if (pga->keyFrame == gd->firstFrame) { + uint16 frameNr = 0; + for (j = 1; j <= gd->lastFrame; ++j) { + if (pga->frame > 500) { + if (pga->frame - 500 == tempFrames[j - 1]) { + frameNr = j + firstImage - 1 + 500; + } + } else if (pga->frame == tempFrames[j - 1]) { + frameNr = j + firstImage - 1; + } + } + paf->frame = frameNr; + paf->speed = pga->speed; + ++paf; + } + } + paf->frame = 0; + paf->speed = 0; + pbs->animString(_newAnim[bobNum]); + } +} + + +void Graphics::animReset(uint16 bobNum) { + if (_newAnim[bobNum][0].frame != 0) { + bob(bobNum)->animString(_newAnim[bobNum]); + } +} + + +void Graphics::animErase(uint16 bobNum) { + _newAnim[bobNum][0].frame = 0; + BobSlot *pbs = bob(bobNum); + pbs->animating = false; + pbs->anim.string.buffer = NULL; +} + + +void Graphics::animEraseAll() { + for (int i = 1; i <= 16; ++i) { + _newAnim[i][0].frame = 0; + } +} + + void Graphics::loadPanel() { uint8 *pcxbuf = _vm->resource()->loadFile("panel.pcx"); if (pcxbuf == NULL) { diff --git a/queen/graphics.h b/queen/graphics.h index 0df17c1141..2b9140c331 100644 --- a/queen/graphics.h +++ b/queen/graphics.h @@ -179,6 +179,12 @@ public: int textCenterX(const char *text) const; // MIDDLE() void textColor(uint16 y, uint8 color) { _texts[y].color = color; } + uint16 animCreate(uint16 curImage, const Person *person); + void animSetup(const GraphicData *gd, uint16 firstImage, uint16 bobNum, bool visible); + void animReset(uint16 bobNum); + void animErase(uint16 bobNum); + void animEraseAll(); + void loadPanel(); void putCameraOnBob(int bobNum) { _cameraBob = bobNum; } @@ -209,6 +215,8 @@ private: TextSlot _texts[GAME_SCREEN_HEIGHT]; uint8 _curTextColor; + AnimFrame _newAnim[17][30]; + int _cameraBob; QueenEngine *_vm; diff --git a/queen/logic.cpp b/queen/logic.cpp index 53bc337ee9..fdde034878 100644 --- a/queen/logic.cpp +++ b/queen/logic.cpp @@ -67,18 +67,14 @@ Logic::~Logic() { delete _queen2jas; } -void Logic::initialise() { - +void Logic::initialise() { int16 i, j; - // Step 1 : read queen.jas file and 'unserialize' some arrays uint8 *jas = _vm->resource()->loadFile("QUEEN.JAS", 20); uint8 *ptr = jas; - _queen2jas = new LineReader((char*)_vm->resource()->loadFile("QUEEN2.JAS")); - _numRooms = READ_BE_UINT16(ptr); ptr += 2; _numNames = READ_BE_UINT16(ptr); ptr += 2; _numObjects = READ_BE_UINT16(ptr); ptr += 2; @@ -218,6 +214,8 @@ void Logic::initialise() { // Step 2 : read queen2.jas and grab all description texts + + _queen2jas = new LineReader((char*)_vm->resource()->loadFile("QUEEN2.JAS")); _objDescription = new char*[_numDescriptions + 1]; _objDescription[0] = 0; @@ -622,17 +620,13 @@ void Logic::roomErase() { } else { _vm->display()->palFadeOut(0, 223, _currentRoom); } - - // TODO: credits system // invalidates all persons animations uint16 i; for (i = 0; i <= 3; ++i) { _personFrames[i] = 0; } - for (i = 1; i <= 16; ++i) { - _newAnim[i][0].frame = 0; - } + _vm->graphics()->animEraseAll(); uint16 cur = _roomData[_oldRoom] + 1; uint16 last = _roomData[_oldRoom + 1]; @@ -783,7 +777,7 @@ void Logic::roomSetupObjects() { if (pgd->firstFrame < 0) { // FIXME: if(TEMPA[1]<0) bobs[CURRBOB].xflip=1; curBob = 5 + _numFurnitureAnimated; - animSetup(pgd, curImage + 1, curBob + numObjectAnimated, pod->name > 0); + _vm->graphics()->animSetup(pgd, curImage + 1, curBob + numObjectAnimated, pod->name > 0); curImage += pgd->lastFrame; ++numObjectAnimated; } else if (lastFrame != 0) { @@ -922,7 +916,7 @@ uint16 Logic::roomRefreshObject(uint16 obj) { rebound = true; } if (pgd->firstFrame < 0) { - animSetup(pgd, curImage, curBob, pod->name != 0); + _vm->graphics()->animSetup(pgd, curImage, curBob, pod->name != 0); curImage += pgd->lastFrame - 1; } else if (lastFrame != 0) { // turn on an animated bob @@ -1114,9 +1108,9 @@ uint16 Logic::personSetup(uint16 noun, uint16 curImage) { if (p.anim != NULL) { _personFrames[pad->bobNum] = curImage + 1; - curImage = animCreate(curImage, &p); + curImage = _vm->graphics()->animCreate(curImage, &p); } else { - animErase(pad->bobNum); + _vm->graphics()->animErase(pad->bobNum); } return curImage; } @@ -1173,154 +1167,6 @@ uint16 Logic::personAllocate(uint16 noun, uint16 curImage) { } -uint16 Logic::animCreate(uint16 curImage, const Person *person) { - AnimFrame *animFrames = _newAnim[person->actor->bobNum]; - - uint16 allocatedFrames[256]; - memset(allocatedFrames, 0, sizeof(allocatedFrames)); - const char *p = person->anim; - int frame = 0; - uint16 f1, f2; - do { - sscanf(p, "%3hu,%3hu", &f1, &f2); - animFrames[frame].frame = f1; - animFrames[frame].speed = f2; - - if (f1 > 500) { - // SFX - allocatedFrames[f1 - 500] = 1; - } else { - allocatedFrames[f1] = 1; - } - - p += 8; - ++frame; - } while(f1 != 0); - - // ajust frame numbers - uint16 n = 1; - uint16 i; - for (i = 1; i <= 255; ++i) { - if (allocatedFrames[i] != 0) { - allocatedFrames[i] = n; - ++n; - } - } - for (i = 0; animFrames[i].frame != 0; ++i) { - uint16 frameNum = animFrames[i].frame; - if (frameNum > 500) { - animFrames[i].frame = curImage + allocatedFrames[frameNum - 500] + 500; - } else { - animFrames[i].frame = curImage + allocatedFrames[frameNum]; - } - } - - // unpack necessary frames - for (i = 1; i <= 255; ++i) { - if (allocatedFrames[i] != 0) { - ++curImage; - _vm->bankMan()->unpack(i, curImage, person->actor->bankNum); - } - } - - // start animation - _vm->graphics()->bob(person->actor->bobNum)->animString(animFrames); - - return curImage; -} - - -void Logic::animErase(uint16 bobNum) { - _newAnim[bobNum][0].frame = 0; - BobSlot *pbs = _vm->graphics()->bob(bobNum); - pbs->animating = false; - pbs->anim.string.buffer = NULL; -} - - -void Logic::animReset(uint16 bobNum) { - if (_newAnim[bobNum][0].frame != 0) { - _vm->graphics()->bob(bobNum)->animString(_newAnim[bobNum]); - } -} - - -void Logic::animSetup(const GraphicData *gd, uint16 firstImage, uint16 bobNum, bool visible) { - int16 tempFrames[20]; - memset(tempFrames, 0, sizeof(tempFrames)); - uint16 numTempFrames = 0; - uint16 i, j; - for (i = 1; i <= _numGraphicAnim; ++i) { - const GraphicAnim *pga = &_graphicAnim[i]; - if (pga->keyFrame == gd->firstFrame) { - int16 frame = pga->frame; - if (frame > 500) { // SFX - frame -= 500; - } - bool foundMatchingFrame = false; - for (j = 0; j < numTempFrames; ++j) { - if (tempFrames[j] == frame) { - foundMatchingFrame = true; - break; - } - } - if (!foundMatchingFrame) { - assert(numTempFrames < 20); - tempFrames[numTempFrames] = frame; - ++numTempFrames; - } - } - } - - // sort found frames ascending - bool swap = true; - while (swap) { - swap = false; - for (i = 0; i < numTempFrames - 1; ++i) { - if (tempFrames[i] > tempFrames[i + 1]) { - SWAP(tempFrames[i], tempFrames[i + 1]); - swap = true; - } - } - } - - // queen.c l.962-980 / l.1269-1294 - for (i = 0; i < gd->lastFrame; ++i) { - _vm->bankMan()->unpack(ABS(tempFrames[i]), firstImage + i, 15); - } - BobSlot *pbs = _vm->graphics()->bob(bobNum); - pbs->animating = false; - if (visible) { - pbs->curPos(gd->x, gd->y); - if (tempFrames[0] < 0) { - pbs->xflip = true; - } - AnimFrame *paf = _newAnim[bobNum]; - for (i = 1; i <= _numGraphicAnim; ++i) { - const GraphicAnim *pga = &_graphicAnim[i]; - if (pga->keyFrame == gd->firstFrame) { - uint16 frameNr = 0; - for (j = 1; j <= gd->lastFrame; ++j) { - if (pga->frame > 500) { - if (pga->frame - 500 == tempFrames[j - 1]) { - frameNr = j + firstImage - 1 + 500; - } - } else if (pga->frame == tempFrames[j - 1]) { - frameNr = j + firstImage - 1; - } - } - paf->frame = frameNr; - paf->speed = pga->speed; - ++paf; - } - } - paf->frame = 0; - paf->speed = 0; - pbs->animString(_newAnim[bobNum]); - } -} - - void Logic::joeSetupFromBanks(const char *animBank, const char *standBank) { int i; _vm->bankMan()->load(animBank, 13); diff --git a/queen/logic.h b/queen/logic.h index 509fcce9af..8608b9ce38 100644 --- a/queen/logic.h +++ b/queen/logic.h @@ -106,6 +106,8 @@ public: WalkOffData *walkOffData(int index) const { return &_walkOffData[index]; } uint16 currentRoomObjMax() const { return _objMax[_currentRoom]; } uint16 currentRoomData() const { return _roomData[_currentRoom]; } + GraphicAnim *graphicAnim(int index) const { return &_graphicAnim[index]; } + uint16 graphicAnimCount() const { return _numGraphicAnim; } ObjectDescription *objectDescription(uint16 objNum) const { return &_objectDescription[objNum]; } uint16 objectDescriptionCount() const { return _numObjDesc; } uint16 currentRoomSfx() const { return _sfxName[_currentRoom]; } @@ -171,11 +173,6 @@ public: uint16 personAllocate(uint16 noun, uint16 curImage); uint16 personFrames(uint16 bobNum) const { return _personFrames[bobNum]; } - uint16 animCreate(uint16 curImage, const Person *person); - void animErase(uint16 bobNum); - void animReset(uint16 bobNum); - void animSetup(const GraphicData *gd, uint16 firstImage, uint16 bobNum, bool visible); - void joeSetupFromBanks(const char *animBank, const char *standBank); //! Load the various bobs needed to animate Joe @@ -429,9 +426,6 @@ protected: //! Last frame number used for person animation uint16 _personFrames[4]; - //! Describe a string based animation (30 frames maximum, bob number must be < 17) - AnimFrame _newAnim[17][30]; - //! Inventory items int16 _inventoryItem[4]; diff --git a/queen/talk.cpp b/queen/talk.cpp index c3001e96bc..564a270f27 100644 --- a/queen/talk.cpp +++ b/queen/talk.cpp @@ -337,7 +337,7 @@ void Talk::talk(const char *filename, int personInRoom, char *cutawayFilename) { pbs->y = person.actor->y; // Better kick start the persons anim sequence - _vm->logic()->animReset(person.actor->bobNum); + _vm->graphics()->animReset(person.actor->bobNum); } _vm->logic()->joeWalk(JWM_NORMAL); diff --git a/queen/xref.txt b/queen/xref.txt index dc4696c07c..d23b3a0cdd 100644 --- a/queen/xref.txt +++ b/queen/xref.txt @@ -270,7 +270,7 @@ WALK_OFF_MAX Logic::_numWalkOffs PERSONS ======= ALLOCATE_PERSON() Logic::personAllocate -CREATE_ANIM() Logic::animCreate +CREATE_ANIM() Graphics::animCreate SET_PERSON_DATA() Logic::personSetData SETUP_PERSON() Logic::personSetup OBJ_PERSON() Logic::objectForPerson |