From 800db6f142b93c07903ad6ef7c2a57bb563ff6dc Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Sat, 13 Dec 2008 17:31:48 +0000 Subject: Restructuring of rendering code. svn-id: r35342 --- engines/parallaction/dialogue.cpp | 21 +++--- engines/parallaction/gfxbase.cpp | 4 +- engines/parallaction/graphics.cpp | 132 +++++++++++++++------------------- engines/parallaction/graphics.h | 19 ++--- engines/parallaction/gui_br.cpp | 3 +- engines/parallaction/parallaction.cpp | 13 ++-- 6 files changed, 79 insertions(+), 113 deletions(-) diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp index 23272d7b0f..41c87c55db 100644 --- a/engines/parallaction/dialogue.cpp +++ b/engines/parallaction/dialogue.cpp @@ -82,6 +82,7 @@ class DialogueManager { bool isNpc; GfxObj *_questioner; GfxObj *_answerer; + int _faceId; Question *_q; @@ -194,24 +195,24 @@ bool DialogueManager::displayAnswers() { displayAnswer(i); } + int mood = 0; + if (_askPassword) { resetPassword(); -// _vm->_balloonMan->setDialogueBalloon(_q->_answers[0]->_text, 1, 3); - int id = _vm->_gfx->setItem(_answerer, _ballonPos._answerChar.x, _ballonPos._answerChar.y); - _vm->_gfx->setItemFrame(id, 0); } else if (_numVisAnswers == 1) { - int id = _vm->_gfx->setItem(_answerer, _ballonPos._answerChar.x, _ballonPos._answerChar.y); - _vm->_gfx->setItemFrame(id, _q->_answers[0]->_mood & 0xF); + mood = _q->_answers[0]->_mood & 0xF; _vm->_balloonMan->setBalloonText(0, _q->_answers[_visAnswers[0]]->_text.c_str(), BalloonManager::kNormalColor); } else if (_numVisAnswers > 1) { - int id = _vm->_gfx->setItem(_answerer, _ballonPos._answerChar.x, _ballonPos._answerChar.y); - _vm->_gfx->setItemFrame(id, _q->_answers[_visAnswers[0]]->_mood & 0xF); + mood = _q->_answers[_visAnswers[0]]->_mood & 0xF; _oldSelection = -1; _selection = 0; } + _faceId = _vm->_gfx->setItem(_answerer, _ballonPos._answerChar.x, _ballonPos._answerChar.y); + _vm->_gfx->setItemFrame(_faceId, mood); + return _numVisAnswers > 0; } @@ -219,8 +220,8 @@ bool DialogueManager::displayQuestion() { if (!_q->_text.compareToIgnoreCase("NULL")) return false; _vm->_balloonMan->setSingleBalloon(_q->_text.c_str(), _ballonPos._questionBalloon.x, _ballonPos._questionBalloon.y, _q->_mood & 0x10, BalloonManager::kNormalColor); - int id = _vm->_gfx->setItem(_questioner, _ballonPos._questionChar.x, _ballonPos._questionChar.y); - _vm->_gfx->setItemFrame(id, _q->_mood & 0xF); + _faceId = _vm->_gfx->setItem(_questioner, _ballonPos._questionChar.x, _ballonPos._questionChar.y); + _vm->_gfx->setItemFrame(_faceId, _q->_mood & 0xF); return true; } @@ -291,7 +292,7 @@ int16 DialogueManager::selectAnswerN() { if (_selection != -1) { _vm->_balloonMan->setBalloonText(_selection, _q->_answers[_visAnswers[_selection]]->_text.c_str(), BalloonManager::kSelectedColor); - _vm->_gfx->setItemFrame(0, _q->_answers[_visAnswers[_selection]]->_mood & 0xF); + _vm->_gfx->setItemFrame(_faceId, _q->_answers[_visAnswers[_selection]]->_mood & 0xF); } } diff --git a/engines/parallaction/gfxbase.cpp b/engines/parallaction/gfxbase.cpp index d24bfa9cfe..0e1144c350 100644 --- a/engines/parallaction/gfxbase.cpp +++ b/engines/parallaction/gfxbase.cpp @@ -165,7 +165,7 @@ void Gfx::sortAnimations() { } -void Gfx::drawGfxObject(GfxObj *obj, Graphics::Surface &surf, bool scene) { +void Gfx::drawGfxObject(GfxObj *obj, Graphics::Surface &surf) { if (!obj->isVisible()) { return; } @@ -200,7 +200,7 @@ void Gfx::drawGfxObjects(Graphics::Surface &surf) { GfxObjList::iterator e = _gfxobjList.end(); for (; b != e; b++) { - drawGfxObject(*b, surf, true); + drawGfxObject(*b, surf); } } diff --git a/engines/parallaction/graphics.cpp b/engines/parallaction/graphics.cpp index f9fb26fcec..674fa9b93a 100644 --- a/engines/parallaction/graphics.cpp +++ b/engines/parallaction/graphics.cpp @@ -332,28 +332,14 @@ void Gfx::drawInventory() { copyRectToScreen(data, r.width(), r.left, r.top, r.width(), r.height()); } -void Gfx::drawItems() { - if (_numItems == 0) { +void Gfx::drawList(Graphics::Surface &surface, GfxObjArray &list) { + if (list.size() == 0) { return; } - Graphics::Surface *surf = lockScreen(); - for (uint i = 0; i < _numItems; i++) { - drawGfxObject(_items[i].data, *surf, false); - } - unlockScreen(); -} - -void Gfx::drawBalloons() { - if (_balloons.size() == 0) { - return; + for (uint i = 0; i < list.size(); i++) { + drawGfxObject(list[i], surface); } - - Graphics::Surface *surf = lockScreen(); - for (uint i = 0; i < _balloons.size(); i++) { - drawGfxObject(_balloons[i], *surf, false); - } - unlockScreen(); } void Gfx::beginFrame() { @@ -507,45 +493,57 @@ void Gfx::updateScreen() { _varRenderMode = _varAnimRenderMode; - // TODO: transform objects coordinates to be drawn with scrolling Graphics::Surface *surf = lockScreen(); - drawGfxObjects(*surf); - - if (_halfbrite) { - // FIXME: the implementation of halfbrite is now largely sub-optimal in that a full screen - // rewrite is needed to apply the effect. Also, we are manipulating the frame buffer. Is it a good idea? - byte *buf = (byte*)surf->pixels; - for (int i = 0; i < surf->w*surf->h; i++) { - *buf++ |= 0x20; - } - if (_nextProjectorPos) { - int16 x = *_nextProjectorPos++; - int16 y = *_nextProjectorPos++; - if (x == -1 && y == -1) { - _nextProjectorPos = 0; - } else { - setProjectorPos(x, y); - } - } - if (_hbCircleRadius > 0) { - drawCircle(_hbCirclePos.x, _hbCirclePos.y, _hbCircleRadius, 0, &halfbritePixel, surf->pixels); - } - } + // draws animations frames and screen items + drawGfxObjects(*surf); + + // special effects + applyHalfbriteEffect_NS(*surf); + // draws inventory, labels and dialogue items + drawOverlay(*surf); unlockScreen(); + updateScreenIntern(); +} + +void Gfx::applyHalfbriteEffect_NS(Graphics::Surface &surf) { + if (!_halfbrite) { + return; + } + + byte *buf = (byte*)surf.pixels; + for (int i = 0; i < surf.w*surf.h; i++) { + *buf++ |= 0x20; + } + + if (_nextProjectorPos) { + int16 x = *_nextProjectorPos++; + int16 y = *_nextProjectorPos++; + if (x == -1 && y == -1) { + _nextProjectorPos = 0; + } else { + setProjectorPos(x, y); + } + } + if (_hbCircleRadius > 0) { + drawCircle(_hbCirclePos.x, _hbCirclePos.y, _hbCircleRadius, 0, &halfbritePixel, surf.pixels); + } +} + +void Gfx::drawOverlay(Graphics::Surface &surf) { // the following items are handled in screen coordinates, so they need translation before // being drawn _overlayMode = true; - drawInventory(); - drawItems(); - drawBalloons(); - drawLabels(); - updateScreenIntern(); -} + drawInventory(); + updateFloatingLabel(); + drawList(surf, _items); + drawList(surf, _balloons); + drawList(surf, _labels); +} // // graphic primitives @@ -759,20 +757,6 @@ void Gfx::freeLabels() { _floatingLabel = NO_FLOATING_LABEL; } -void Gfx::drawLabels() { - if (_labels.size() == 0) { - return; - } - - updateFloatingLabel(); - - Graphics::Surface* surf = lockScreen(); - for (uint i = 0; i < _labels.size(); i++) { - drawGfxObject(_labels[i], *surf, false); - } - unlockScreen(); -} - void Gfx::copyRect(const Common::Rect &r, Graphics::Surface &src, Graphics::Surface &dst) { @@ -805,12 +789,8 @@ Gfx::Gfx(Parallaction* vm) : setPalette(_palette); - _numItems = 0; _floatingLabel = NO_FLOATING_LABEL; - _screenX = 0; - _screenY = 0; - _backgroundInfo = 0; _halfbrite = false; @@ -853,23 +833,23 @@ Gfx::~Gfx() { int Gfx::setItem(GfxObj* frames, uint16 x, uint16 y, byte transparentColor) { - int id = _numItems; + int id = _items.size(); + + frames->x = x; + frames->y = y; + frames->transparentKey = transparentColor; + frames->layer = LAYER_FOREGROUND; + frames->setFlags(kGfxObjVisible); - _items[id].data = frames; - _items[id].data->x = x; - _items[id].data->y = y; - _items[id].data->layer = LAYER_FOREGROUND; - _items[id].data->transparentKey = transparentColor; + _items.insert_at(id, frames); - _numItems++; + setItemFrame(id, 0); return id; } void Gfx::setItemFrame(uint item, uint16 f) { - assert(item < _numItems); - _items[item].data->frame = f; - _items[item].data->setFlags(kGfxObjVisible); + _items[item]->frame = f; } @@ -894,7 +874,7 @@ void Gfx::destroyBalloons() { } void Gfx::freeItems() { - _numItems = 0; + _items.clear(); } void Gfx::setBackground(uint type, BackgroundInfo *info) { diff --git a/engines/parallaction/graphics.h b/engines/parallaction/graphics.h index e9a7ce2877..c2fbb0dbea 100644 --- a/engines/parallaction/graphics.h +++ b/engines/parallaction/graphics.h @@ -518,7 +518,6 @@ public: int setItem(GfxObj* obj, uint16 x, uint16 y, byte transparentColor = 0); void setItemFrame(uint item, uint16 f); void hideDialogueStuff(); - void freeBalloons(); void freeItems(); // background surface @@ -536,6 +535,7 @@ public: void animatePalette(); // amiga specific + void applyHalfbriteEffect_NS(Graphics::Surface &surf); void setHalfbriteMode(bool enable); void setProjectorPos(int x, int y); void setProjectorProgram(int16 *data); @@ -558,9 +558,6 @@ public: public: Palette _palette; - uint _screenX; // scrolling position - uint _screenY; - byte *_unpackedBitmap; protected: @@ -596,29 +593,23 @@ protected: // overlay mode enables drawing of graphics with automatic screen-to-game coordinate translation bool _overlayMode; + void drawOverlay(Graphics::Surface &surf); public: - struct Item { - GfxObj *data; - } _items[14]; - - uint _numItems; - #define MAX_NUM_LABELS 20 #define NO_FLOATING_LABEL 1000 typedef Common::Array GfxObjArray; GfxObjArray _labels; GfxObjArray _balloons; + GfxObjArray _items; uint _floatingLabel; void drawInventory(); void updateFloatingLabel(); - void drawLabels(); - void drawItems(); - void drawBalloons(); + void drawList(Graphics::Surface &surface, GfxObjArray &list); void copyRect(const Common::Rect &r, Graphics::Surface &src, Graphics::Surface &dst); @@ -628,7 +619,7 @@ public: // low level text and patches void drawText(Font *font, Graphics::Surface* surf, uint16 x, uint16 y, const char *text, byte color); - void drawGfxObject(GfxObj *obj, Graphics::Surface &surf, bool scene); + void drawGfxObject(GfxObj *obj, Graphics::Surface &surf); void blt(const Common::Rect& r, byte *data, Graphics::Surface *surf, uint16 z, uint scale, byte transparentColor); void unpackBlt(const Common::Rect& r, byte *data, uint size, Graphics::Surface *surf, uint16 z, uint scale, byte transparentColor); diff --git a/engines/parallaction/gui_br.cpp b/engines/parallaction/gui_br.cpp index 6b39d5a06a..68bb154750 100644 --- a/engines/parallaction/gui_br.cpp +++ b/engines/parallaction/gui_br.cpp @@ -234,8 +234,7 @@ public: // TODO: keep track of and destroy menu item frames/surfaces for (i = 0; i < _availItems; i++) { _lines[i] = new GfxObj(0, renderMenuItem(_menuStrings[i]), "MenuItem"); - uint id = _vm->_gfx->setItem(_lines[i], MENUITEMS_X, MENUITEMS_Y + MENUITEM_HEIGHT * i, 0xFF); - _vm->_gfx->setItemFrame(id, 0); + _vm->_gfx->setItem(_lines[i], MENUITEMS_X, MENUITEMS_Y + MENUITEM_HEIGHT * i, 0xFF); } _selection = -1; _vm->_input->setArrowCursor(); diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index cb643a36a9..a49c425091 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -572,7 +572,6 @@ void Parallaction::enterCommentMode(ZonePtr z) { // TODO: move this balloons stuff into DialogueManager and BalloonManager if (getGameType() == GType_Nippon) { - int id; if (data->_filename) { if (data->_cnv == 0) { data->_cnv = _disk->loadStatic(data->_filename); @@ -582,20 +581,16 @@ void Parallaction::enterCommentMode(ZonePtr z) { _balloonMan->setSingleBalloon(data->_description.c_str(), 0, 90, 0, BalloonManager::kNormalColor); Common::Rect r; data->_cnv->getRect(0, r); - id = _gfx->setItem(data->_cnv, 140, (_screenHeight - r.height())/2); - _gfx->setItemFrame(id, 0); - id = _gfx->setItem(_char._head, 100, 152); - _gfx->setItemFrame(id, 0); + _gfx->setItem(data->_cnv, 140, (_screenHeight - r.height())/2); + _gfx->setItem(_char._head, 100, 152); } else { _balloonMan->setSingleBalloon(data->_description.c_str(), 140, 10, 0, BalloonManager::kNormalColor); - id = _gfx->setItem(_char._talk, 190, 80); - _gfx->setItemFrame(id, 0); + _gfx->setItem(_char._talk, 190, 80); } } else if (getGameType() == GType_BRA) { _balloonMan->setSingleBalloon(data->_description.c_str(), 0, 0, 1, BalloonManager::kNormalColor); - int id = _gfx->setItem(_char._talk, 10, 80); - _gfx->setItemFrame(id, 0); + _gfx->setItem(_char._talk, 10, 80); } _input->_inputMode = Input::kInputModeComment; -- cgit v1.2.3