2010-02-02 16:25:35 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/util.h"
|
|
|
|
#include "common/stack.h"
|
|
|
|
#include "graphics/primitives.h"
|
|
|
|
|
|
|
|
#include "sci/sci.h"
|
2010-06-23 15:23:37 +00:00
|
|
|
#include "sci/engine/kernel.h"
|
2010-02-02 16:25:35 +00:00
|
|
|
#include "sci/engine/state.h"
|
|
|
|
#include "sci/engine/selector.h"
|
|
|
|
#include "sci/engine/vm.h"
|
|
|
|
#include "sci/graphics/cache.h"
|
2010-02-06 19:35:51 +00:00
|
|
|
#include "sci/graphics/coordadjuster.h"
|
2010-02-03 01:36:53 +00:00
|
|
|
#include "sci/graphics/font.h"
|
2010-02-02 16:25:35 +00:00
|
|
|
#include "sci/graphics/view.h"
|
|
|
|
#include "sci/graphics/screen.h"
|
2010-02-04 17:57:44 +00:00
|
|
|
#include "sci/graphics/paint32.h"
|
2010-06-20 16:36:34 +00:00
|
|
|
#include "sci/graphics/palette.h"
|
2010-02-02 16:25:35 +00:00
|
|
|
#include "sci/graphics/picture.h"
|
|
|
|
#include "sci/graphics/frameout.h"
|
|
|
|
|
|
|
|
namespace Sci {
|
|
|
|
|
2010-02-06 19:35:51 +00:00
|
|
|
GfxFrameout::GfxFrameout(SegManager *segMan, ResourceManager *resMan, GfxCoordAdjuster *coordAdjuster, GfxCache *cache, GfxScreen *screen, GfxPalette *palette, GfxPaint32 *paint32)
|
2010-02-04 17:57:44 +00:00
|
|
|
: _segMan(segMan), _resMan(resMan), _cache(cache), _screen(screen), _palette(palette), _paint32(paint32) {
|
2010-02-05 19:33:39 +00:00
|
|
|
|
2010-02-06 19:35:51 +00:00
|
|
|
_coordAdjuster = (GfxCoordAdjuster32 *)coordAdjuster;
|
2010-02-02 16:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GfxFrameout::~GfxFrameout() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxFrameout::kernelAddPlane(reg_t object) {
|
|
|
|
_planes.push_back(object);
|
2010-06-20 17:17:46 +00:00
|
|
|
sortPlanes();
|
2010-02-02 16:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GfxFrameout::kernelUpdatePlane(reg_t object) {
|
2010-06-20 17:17:46 +00:00
|
|
|
sortPlanes();
|
2010-02-02 16:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GfxFrameout::kernelDeletePlane(reg_t object) {
|
2010-06-20 17:17:46 +00:00
|
|
|
for (Common::List<reg_t>::iterator it = _planes.begin(); it != _planes.end(); it++) {
|
|
|
|
if (object == *it) {
|
|
|
|
_planes.erase(it);
|
|
|
|
return;
|
2010-02-02 16:25:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxFrameout::kernelAddScreenItem(reg_t object) {
|
|
|
|
_screenItems.push_back(object);
|
2010-07-14 00:52:21 +00:00
|
|
|
//warning("addScreenItem %X:%X (%s)", object.segment, object.offset, _segMan->getObjectName(object));
|
2010-02-02 16:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GfxFrameout::kernelDeleteScreenItem(reg_t object) {
|
|
|
|
for (uint32 itemNr = 0; itemNr < _screenItems.size(); itemNr++) {
|
|
|
|
if (_screenItems[itemNr] == object) {
|
|
|
|
_screenItems.remove_at(itemNr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int16 GfxFrameout::kernelGetHighPlanePri() {
|
2010-06-20 17:17:46 +00:00
|
|
|
sortPlanes();
|
|
|
|
return readSelectorValue(g_sci->getEngineState()->_segMan, _planes.back(), SELECTOR(priority));
|
2010-02-02 16:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool sortHelper(const FrameoutEntry* entry1, const FrameoutEntry* entry2) {
|
|
|
|
return (entry1->priority == entry2->priority) ? (entry1->y < entry2->y) : (entry1->priority < entry2->priority);
|
|
|
|
}
|
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
bool planeSortHelper(const reg_t entry1, const reg_t entry2) {
|
|
|
|
SegManager *segMan = g_sci->getEngineState()->_segMan;
|
2010-02-02 16:25:35 +00:00
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
uint16 plane1Priority = readSelectorValue(segMan, entry1, SELECTOR(priority));
|
|
|
|
uint16 plane2Priority = readSelectorValue(segMan, entry2, SELECTOR(priority));
|
2010-06-20 16:36:34 +00:00
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
if (plane1Priority == 0xffff)
|
|
|
|
return true;
|
2010-02-02 16:25:35 +00:00
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
if (plane2Priority == 0xffff)
|
|
|
|
return false;
|
2010-06-14 16:58:15 +00:00
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
return plane1Priority < plane2Priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxFrameout::sortPlanes() {
|
|
|
|
// First, remove any invalid planes
|
|
|
|
for (Common::List<reg_t>::iterator it = _planes.begin(); it != _planes.end();) {
|
|
|
|
if (!_segMan->isObject(*it))
|
|
|
|
it = _planes.erase(it);
|
|
|
|
else
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the rest of them
|
|
|
|
Common::sort(_planes.begin(), _planes.end(), planeSortHelper);
|
|
|
|
}
|
2010-06-14 16:58:15 +00:00
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
void GfxFrameout::kernelFrameout() {
|
|
|
|
_palette->palVaryUpdate();
|
2010-02-02 16:25:35 +00:00
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
// Allocate enough space for all screen items
|
|
|
|
FrameoutEntry *itemData = (FrameoutEntry *)malloc(_screenItems.size() * sizeof(FrameoutEntry));
|
|
|
|
|
2010-06-30 14:26:47 +00:00
|
|
|
const SciGameId gameId = g_sci->getGameId();
|
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
for (Common::List<reg_t>::iterator it = _planes.begin(); it != _planes.end(); it++) {
|
|
|
|
reg_t planeObject = *it;
|
|
|
|
uint16 planePriority = readSelectorValue(_segMan, planeObject, SELECTOR(priority));
|
|
|
|
|
|
|
|
if (planePriority == 0xffff) // Plane currently not meant to be shown
|
2010-02-02 16:25:35 +00:00
|
|
|
continue;
|
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
Common::Rect planeRect;
|
2010-05-29 23:37:15 +00:00
|
|
|
planeRect.top = readSelectorValue(_segMan, planeObject, SELECTOR(top));
|
|
|
|
planeRect.left = readSelectorValue(_segMan, planeObject, SELECTOR(left));
|
|
|
|
planeRect.bottom = readSelectorValue(_segMan, planeObject, SELECTOR(bottom));
|
|
|
|
planeRect.right = readSelectorValue(_segMan, planeObject, SELECTOR(right));
|
2010-06-20 17:17:46 +00:00
|
|
|
int16 planeResY = readSelectorValue(_segMan, planeObject, SELECTOR(resY));
|
|
|
|
int16 planeResX = readSelectorValue(_segMan, planeObject, SELECTOR(resX));
|
2010-02-02 16:25:35 +00:00
|
|
|
|
2010-02-04 16:12:47 +00:00
|
|
|
planeRect.top = (planeRect.top * _screen->getHeight()) / planeResY;
|
|
|
|
planeRect.left = (planeRect.left * _screen->getWidth()) / planeResX;
|
2010-02-04 16:14:59 +00:00
|
|
|
planeRect.bottom = (planeRect.bottom * _screen->getHeight()) / planeResY;
|
|
|
|
planeRect.right = (planeRect.right * _screen->getWidth()) / planeResX;
|
2010-02-04 16:12:47 +00:00
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
byte planeBack = readSelectorValue(_segMan, planeObject, SELECTOR(back));
|
|
|
|
if (planeBack)
|
2010-02-04 17:57:44 +00:00
|
|
|
_paint32->fillRect(planeRect, planeBack);
|
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
GuiResourceId planePictureNr = readSelectorValue(_segMan, planeObject, SELECTOR(picture));
|
|
|
|
GfxPicture *planePicture = 0;
|
|
|
|
int16 planePictureCels = 0;
|
|
|
|
|
2010-02-04 17:57:44 +00:00
|
|
|
if ((planePictureNr != 0xFFFF) && (planePictureNr != 0xFFFE)) {
|
2010-02-06 19:35:51 +00:00
|
|
|
planePicture = new GfxPicture(_resMan, _coordAdjuster, 0, _screen, _palette, planePictureNr, false);
|
2010-02-04 17:57:44 +00:00
|
|
|
planePictureCels = planePicture->getSci32celCount();
|
2010-02-06 19:35:51 +00:00
|
|
|
|
|
|
|
_coordAdjuster->pictureSetDisplayArea(planeRect);
|
2010-06-20 20:52:31 +00:00
|
|
|
_palette->drewPicture(planePictureNr);
|
2010-02-04 17:57:44 +00:00
|
|
|
}
|
|
|
|
|
2010-02-02 16:25:35 +00:00
|
|
|
// Fill our itemlist for this plane
|
2010-06-20 17:17:46 +00:00
|
|
|
int16 itemCount = 0;
|
|
|
|
FrameoutEntry *itemEntry = itemData;
|
|
|
|
FrameoutList itemList;
|
|
|
|
|
2010-02-02 16:25:35 +00:00
|
|
|
for (uint32 itemNr = 0; itemNr < _screenItems.size(); itemNr++) {
|
2010-06-20 17:17:46 +00:00
|
|
|
reg_t itemObject = _screenItems[itemNr];
|
2010-06-14 16:58:15 +00:00
|
|
|
|
|
|
|
// Remove any invalid items
|
|
|
|
if (!_segMan->isObject(itemObject)) {
|
|
|
|
_screenItems.remove_at(itemNr);
|
|
|
|
itemNr--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
reg_t itemPlane = readSelector(_segMan, itemObject, SELECTOR(plane));
|
2010-02-02 16:25:35 +00:00
|
|
|
if (planeObject == itemPlane) {
|
|
|
|
// Found an item on current plane
|
2010-05-29 23:37:15 +00:00
|
|
|
itemEntry->viewId = readSelectorValue(_segMan, itemObject, SELECTOR(view));
|
|
|
|
itemEntry->loopNo = readSelectorValue(_segMan, itemObject, SELECTOR(loop));
|
|
|
|
itemEntry->celNo = readSelectorValue(_segMan, itemObject, SELECTOR(cel));
|
|
|
|
itemEntry->x = readSelectorValue(_segMan, itemObject, SELECTOR(x));
|
|
|
|
itemEntry->y = readSelectorValue(_segMan, itemObject, SELECTOR(y));
|
|
|
|
itemEntry->z = readSelectorValue(_segMan, itemObject, SELECTOR(z));
|
|
|
|
itemEntry->priority = readSelectorValue(_segMan, itemObject, SELECTOR(priority));
|
2010-06-30 14:26:47 +00:00
|
|
|
if (gameId == GID_GK1) {
|
|
|
|
if ((itemEntry->viewId == 11000) && (itemEntry->loopNo == 0) && (itemEntry->celNo == 0) && (itemEntry->priority == 1)) {
|
|
|
|
itemEntry->priority = 0; // HACK for gk1 hires main menu
|
|
|
|
}
|
|
|
|
if ((itemEntry->viewId == 10100) && (itemEntry->priority == 0)) {
|
|
|
|
itemEntry->priority = 1; // HACK for gk1 hires main menu
|
|
|
|
}
|
|
|
|
}
|
2010-05-29 23:37:15 +00:00
|
|
|
itemEntry->signal = readSelectorValue(_segMan, itemObject, SELECTOR(signal));
|
|
|
|
itemEntry->scaleX = readSelectorValue(_segMan, itemObject, SELECTOR(scaleX));
|
|
|
|
itemEntry->scaleY = readSelectorValue(_segMan, itemObject, SELECTOR(scaleY));
|
2010-02-03 01:36:53 +00:00
|
|
|
itemEntry->object = itemObject;
|
2010-02-02 16:25:35 +00:00
|
|
|
|
2010-02-04 12:07:27 +00:00
|
|
|
itemEntry->y = ((itemEntry->y * _screen->getHeight()) / planeResY);
|
|
|
|
itemEntry->x = ((itemEntry->x * _screen->getWidth()) / planeResX);
|
2010-02-04 16:12:47 +00:00
|
|
|
itemEntry->y += planeRect.top;
|
|
|
|
itemEntry->x += planeRect.left;
|
2010-02-04 12:07:27 +00:00
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
if (!(itemEntry->signal & 0x0010)) { // kSignalFixedPriority
|
|
|
|
// TODO: Change priority of this item
|
|
|
|
}
|
2010-02-02 16:25:35 +00:00
|
|
|
|
|
|
|
itemList.push_back(itemEntry);
|
|
|
|
itemEntry++;
|
|
|
|
itemCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now sort our itemlist
|
|
|
|
Common::sort(itemList.begin(), itemList.end(), sortHelper);
|
|
|
|
|
|
|
|
// Now display itemlist
|
2010-06-20 17:17:46 +00:00
|
|
|
int16 planePictureCel = 0;
|
2010-02-02 16:25:35 +00:00
|
|
|
itemEntry = itemData;
|
2010-06-20 17:17:46 +00:00
|
|
|
|
|
|
|
for (FrameoutList::iterator listIterator = itemList.begin(); listIterator != itemList.end(); listIterator++) {
|
2010-02-02 16:25:35 +00:00
|
|
|
itemEntry = *listIterator;
|
|
|
|
if (planePicture) {
|
|
|
|
while ((planePictureCel <= itemEntry->priority) && (planePictureCel < planePictureCels)) {
|
2010-07-21 13:13:55 +00:00
|
|
|
planePicture->drawSci32Vga(planePictureCel, planeResY, planeResX);
|
2010-02-02 16:25:35 +00:00
|
|
|
planePictureCel++;
|
|
|
|
}
|
|
|
|
}
|
2010-06-20 17:17:46 +00:00
|
|
|
|
2010-02-02 16:25:35 +00:00
|
|
|
if (itemEntry->viewId != 0xFFFF) {
|
2010-02-04 22:17:58 +00:00
|
|
|
GfxView *view = _cache->getView(itemEntry->viewId);
|
2010-02-02 16:25:35 +00:00
|
|
|
|
2010-06-30 14:26:47 +00:00
|
|
|
if (view->isSci2Hires())
|
|
|
|
_screen->adjustToUpscaledCoordinates(itemEntry->y, itemEntry->x);
|
|
|
|
|
2010-06-20 17:17:46 +00:00
|
|
|
if ((itemEntry->scaleX == 128) && (itemEntry->scaleY == 128))
|
2010-06-28 11:20:14 +00:00
|
|
|
view->getCelRect(itemEntry->loopNo, itemEntry->celNo, itemEntry->x, itemEntry->y, itemEntry->z, itemEntry->celRect);
|
2010-06-20 17:17:46 +00:00
|
|
|
else
|
2010-06-28 11:20:14 +00:00
|
|
|
view->getCelScaledRect(itemEntry->loopNo, itemEntry->celNo, itemEntry->x, itemEntry->y, itemEntry->z, itemEntry->scaleX, itemEntry->scaleY, itemEntry->celRect);
|
2010-02-02 16:25:35 +00:00
|
|
|
|
2010-06-30 14:26:47 +00:00
|
|
|
int16 screenHeight = _screen->getHeight();
|
|
|
|
int16 screenWidth = _screen->getWidth();
|
|
|
|
if (view->isSci2Hires()) {
|
|
|
|
screenHeight = _screen->getDisplayHeight();
|
|
|
|
screenWidth = _screen->getDisplayWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemEntry->celRect.top < 0 || itemEntry->celRect.top >= screenHeight)
|
2010-02-02 16:25:35 +00:00
|
|
|
continue;
|
|
|
|
|
2010-06-30 14:26:47 +00:00
|
|
|
if (itemEntry->celRect.left < 0 || itemEntry->celRect.left >= screenWidth)
|
2010-02-02 16:25:35 +00:00
|
|
|
continue;
|
|
|
|
|
2010-02-04 16:12:47 +00:00
|
|
|
Common::Rect clipRect;
|
|
|
|
clipRect = itemEntry->celRect;
|
2010-06-30 14:26:47 +00:00
|
|
|
if (view->isSci2Hires()) {
|
|
|
|
Common::Rect upscaledPlaneRect = planeRect;
|
|
|
|
_screen->adjustToUpscaledCoordinates(upscaledPlaneRect.top, upscaledPlaneRect.left);
|
|
|
|
_screen->adjustToUpscaledCoordinates(upscaledPlaneRect.bottom, upscaledPlaneRect.right);
|
|
|
|
clipRect.clip(upscaledPlaneRect);
|
|
|
|
} else {
|
|
|
|
clipRect.clip(planeRect);
|
|
|
|
}
|
2010-02-04 16:12:47 +00:00
|
|
|
|
2010-02-02 16:25:35 +00:00
|
|
|
if ((itemEntry->scaleX == 128) && (itemEntry->scaleY == 128))
|
2010-06-30 14:26:47 +00:00
|
|
|
view->draw(itemEntry->celRect, clipRect, clipRect, itemEntry->loopNo, itemEntry->celNo, 255, 0, view->isSci2Hires());
|
2010-02-02 16:25:35 +00:00
|
|
|
else
|
2010-02-04 16:12:47 +00:00
|
|
|
view->drawScaled(itemEntry->celRect, clipRect, clipRect, itemEntry->loopNo, itemEntry->celNo, 255, itemEntry->scaleX, itemEntry->scaleY);
|
2010-02-03 01:36:53 +00:00
|
|
|
} else {
|
|
|
|
// Most likely a text entry
|
|
|
|
// This draws text the "SCI0-SCI11" way. In SCI2, text is prerendered in kCreateTextBitmap
|
|
|
|
// TODO: rewrite this the "SCI2" way (i.e. implement the text buffer to draw inside kCreateTextBitmap)
|
2010-07-02 08:55:12 +00:00
|
|
|
if (lookupSelector(_segMan, itemEntry->object, SELECTOR(text), NULL, NULL) == kSelectorVariable) {
|
|
|
|
Common::String text = _segMan->getString(readSelector(_segMan, itemEntry->object, SELECTOR(text)));
|
|
|
|
GfxFont *font = _cache->getFont(readSelectorValue(_segMan, itemEntry->object, SELECTOR(font)));
|
|
|
|
bool dimmed = readSelectorValue(_segMan, itemEntry->object, SELECTOR(dimmed));
|
|
|
|
uint16 foreColor = readSelectorValue(_segMan, itemEntry->object, SELECTOR(fore));
|
|
|
|
uint16 curX = itemEntry->x;
|
|
|
|
uint16 curY = itemEntry->y;
|
|
|
|
for (uint32 i = 0; i < text.size(); i++) {
|
|
|
|
unsigned char curChar = text[i];
|
|
|
|
// TODO: proper text splitting... this is a hack
|
|
|
|
if ((curChar == ' ' && i > 0 && text[i - i] == ' ') || curChar == '\n' ||
|
|
|
|
(curX + font->getCharWidth(curChar) > _screen->getWidth())) {
|
|
|
|
curY += font->getHeight();
|
|
|
|
curX = itemEntry->x;
|
2010-02-03 01:36:53 +00:00
|
|
|
}
|
2010-07-02 08:55:12 +00:00
|
|
|
font->draw(curChar, curY, curX, foreColor, dimmed);
|
|
|
|
curX += font->getCharWidth(curChar);
|
2010-02-03 01:36:53 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-02 16:25:35 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-20 17:17:46 +00:00
|
|
|
|
2010-02-02 16:25:35 +00:00
|
|
|
if (planePicture) {
|
|
|
|
while (planePictureCel < planePictureCels) {
|
2010-07-21 13:13:55 +00:00
|
|
|
planePicture->drawSci32Vga(planePictureCel, planeResY, planeResX);
|
2010-02-02 16:25:35 +00:00
|
|
|
planePictureCel++;
|
|
|
|
}
|
|
|
|
delete planePicture;
|
|
|
|
planePicture = 0;
|
|
|
|
}
|
|
|
|
}
|
2010-06-20 17:17:46 +00:00
|
|
|
|
2010-02-02 16:25:35 +00:00
|
|
|
free(itemData);
|
2010-02-05 16:03:14 +00:00
|
|
|
_screen->copyToScreen();
|
2010-02-02 16:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Sci
|