2004-01-06 13:44:17 +00:00
|
|
|
/* Copyright (C) 1994-2004 Revolution Software Ltd
|
2003-07-28 01:44:38 +00:00
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2003-07-28 01:44:38 +00:00
|
|
|
// BUILD_DISPLAY.CPP like the old spr_engi but slightly more aptly named
|
2003-09-02 09:54:42 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "common/stdafx.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/sword2.h"
|
|
|
|
#include "sword2/defs.h"
|
|
|
|
#include "sword2/interpreter.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::buildDisplay(void) {
|
2003-09-02 09:54:42 +00:00
|
|
|
uint8 *file;
|
2003-12-28 15:08:12 +00:00
|
|
|
MultiScreenHeader *screenLayerTable;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-02 17:17:10 +00:00
|
|
|
if (_thisScreen.new_palette) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// start the layer palette fading up
|
2003-11-01 16:55:20 +00:00
|
|
|
startNewPalette();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
// should be reset to zero at start of each screen change
|
|
|
|
_largestLayerArea = 0;
|
|
|
|
_largestSpriteArea = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// there is a valid screen to run
|
2003-11-02 17:17:10 +00:00
|
|
|
if (_thisScreen.background_layer_id) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// set the scroll position
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->setScrollTarget(_thisScreen.scroll_offset_x, _thisScreen.scroll_offset_y);
|
2003-09-02 09:54:42 +00:00
|
|
|
// increment the mouse frame
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->animateMouse();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->startRenderCycle();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
while (1) {
|
2003-07-28 01:44:38 +00:00
|
|
|
// first background parallax + related anims
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// open the screen resource
|
2003-11-16 14:18:29 +00:00
|
|
|
file = _resman->openResource(_thisScreen.background_layer_id);
|
2003-12-28 15:08:12 +00:00
|
|
|
screenLayerTable = (MultiScreenHeader *) (file + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
if (screenLayerTable->bg_parallax[0]) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->renderParallax(fetchBackgroundParallaxLayer(file, 0), 0);
|
2003-09-02 09:54:42 +00:00
|
|
|
// release the screen resource before cacheing
|
|
|
|
// the sprites
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-11-01 16:55:20 +00:00
|
|
|
sendBackPar0Frames();
|
2003-09-02 09:54:42 +00:00
|
|
|
} else {
|
|
|
|
// release the screen resource
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// second background parallax + related anims
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// open the screen resource
|
2003-11-16 14:18:29 +00:00
|
|
|
file = _resman->openResource(_thisScreen.background_layer_id);
|
2003-12-28 15:08:12 +00:00
|
|
|
screenLayerTable = (MultiScreenHeader *) (file + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
if (screenLayerTable->bg_parallax[1]) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->renderParallax(fetchBackgroundParallaxLayer(file, 1), 1);
|
2003-09-02 09:54:42 +00:00
|
|
|
// release the screen resource before cacheing
|
|
|
|
// the sprites
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-11-01 16:55:20 +00:00
|
|
|
sendBackPar1Frames();
|
2003-09-02 09:54:42 +00:00
|
|
|
} else {
|
|
|
|
// release the screen resource
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// normal backround layer (just the one!)
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// open the screen resource
|
2003-11-16 14:18:29 +00:00
|
|
|
file = _resman->openResource(_thisScreen.background_layer_id);
|
|
|
|
_graphics->renderParallax(fetchBackgroundLayer(file), 2);
|
2003-09-02 09:54:42 +00:00
|
|
|
// release the screen resource
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// sprites & layers
|
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
sendBackFrames(); // background sprites
|
|
|
|
sortTheSortList();
|
|
|
|
sendSortFrames(); // sorted sprites & layers
|
|
|
|
sendForeFrames(); // foreground sprites
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// first foreground parallax + related anims
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// open the screen resource
|
2003-11-16 14:18:29 +00:00
|
|
|
file = _resman->openResource(_thisScreen.background_layer_id);
|
2003-12-28 15:08:12 +00:00
|
|
|
screenLayerTable = (MultiScreenHeader *) (file + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
if (screenLayerTable->fg_parallax[0]) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->renderParallax(fetchForegroundParallaxLayer(file, 0), 3);
|
2003-09-02 09:54:42 +00:00
|
|
|
// release the screen resource before cacheing
|
|
|
|
// the sprites
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-11-01 16:55:20 +00:00
|
|
|
sendForePar0Frames();
|
2003-09-02 09:54:42 +00:00
|
|
|
} else {
|
|
|
|
// release the screen resource
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// second foreground parallax + related anims
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// open the screen resource
|
2003-11-16 14:18:29 +00:00
|
|
|
file = _resman->openResource(_thisScreen.background_layer_id);
|
2003-12-28 15:08:12 +00:00
|
|
|
screenLayerTable = (MultiScreenHeader *) (file + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
if (screenLayerTable->fg_parallax[1]) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->renderParallax(fetchForegroundParallaxLayer(file, 1), 4);
|
2003-09-02 09:54:42 +00:00
|
|
|
// release the screen resource before cacheing
|
|
|
|
// the sprites
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-11-01 16:55:20 +00:00
|
|
|
sendForePar1Frames();
|
2003-09-02 09:54:42 +00:00
|
|
|
} else {
|
|
|
|
// release the screen resource
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// walkgrid, mouse & player markers & mouse area
|
|
|
|
// rectangle
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-02 15:58:45 +00:00
|
|
|
_debugger->drawDebugGraphics();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// text blocks
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// speech blocks and headup debug text
|
2003-11-16 14:18:29 +00:00
|
|
|
_fontRenderer->printTextBlocs();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// menu bar & icons
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->processMenu();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// ready - blit to screen
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->updateDisplay();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// update our fps reading
|
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
_frameCount++;
|
2003-11-11 10:30:25 +00:00
|
|
|
if (_system->get_msecs() > _cycleTime) {
|
2003-11-01 16:55:20 +00:00
|
|
|
_fps = _frameCount;
|
|
|
|
debug(2, "FPS: %d", _fps);
|
|
|
|
_frameCount = 0;
|
2003-11-11 10:30:25 +00:00
|
|
|
_cycleTime = _system->get_msecs() + 1000;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
// Check if we've got time to render the screen again
|
2003-09-02 09:54:42 +00:00
|
|
|
// this cycle (so drivers can smooth out the scrolling
|
|
|
|
// in between normal game cycles)
|
2003-10-15 06:40:31 +00:00
|
|
|
//
|
|
|
|
// If we haven't got time to render again this cycle,
|
2003-09-02 09:54:42 +00:00
|
|
|
// drop out of 'render cycle' while-loop
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
if (_graphics->endRenderCycle())
|
2003-10-15 06:40:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fades down and displays a message on the screen for time seconds
|
|
|
|
//
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::displayMsg(uint8 *text, int time) {
|
2003-12-28 15:08:12 +00:00
|
|
|
Memory *text_spr;
|
|
|
|
FrameHeader *frame;
|
|
|
|
SpriteInfo spriteInfo;
|
|
|
|
PalEntry pal[256];
|
|
|
|
PalEntry oldPal[256];
|
2003-09-02 09:54:42 +00:00
|
|
|
uint32 rv; // drivers error return value
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-02 15:58:45 +00:00
|
|
|
debug(2, "DisplayMsg: %s", (char *) text);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
if (_graphics->getFadeStatus() != RDFADE_BLACK) {
|
|
|
|
_graphics->fadeDown();
|
|
|
|
_graphics->waitForFade();
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 18:50:09 +00:00
|
|
|
setMouse(0);
|
|
|
|
setLuggage(0);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->closeMenuImmediately();
|
|
|
|
_graphics->clearScene();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
text_spr = _fontRenderer->makeTextSprite(text, 640, 187, _speechFontId);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
frame = (FrameHeader *) text_spr->ad;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
spriteInfo.x = _graphics->_screenWide / 2 - frame->width / 2;
|
2003-07-28 01:44:38 +00:00
|
|
|
if (!time)
|
2003-11-16 14:18:29 +00:00
|
|
|
spriteInfo.y = _graphics->_screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP;
|
2003-07-28 01:44:38 +00:00
|
|
|
else
|
2003-09-02 09:54:42 +00:00
|
|
|
spriteInfo.y = 400 - frame->height;
|
|
|
|
spriteInfo.w = frame->width;
|
|
|
|
spriteInfo.h = frame->height;
|
|
|
|
spriteInfo.scale = 0;
|
|
|
|
spriteInfo.scaledWidth = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
spriteInfo.scaledHeight = 0;
|
2003-10-11 12:26:53 +00:00
|
|
|
spriteInfo.type = RDSPR_DISPLAYALIGN | RDSPR_NOCOMPRESSION | RDSPR_TRANS;
|
2003-09-02 09:54:42 +00:00
|
|
|
spriteInfo.blend = 0;
|
2003-12-28 15:08:12 +00:00
|
|
|
spriteInfo.data = text_spr->ad + sizeof(FrameHeader);
|
2003-09-02 09:54:42 +00:00
|
|
|
spriteInfo.colourTable = 0;
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
rv = _graphics->drawSprite(&spriteInfo);
|
2003-07-28 01:44:38 +00:00
|
|
|
if (rv)
|
2003-09-27 11:02:58 +00:00
|
|
|
error("Driver Error %.8x (in DisplayMsg)", rv);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
memcpy((char *) oldPal, (char *) _graphics->_palCopy, 256 * sizeof(PalEntry));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
memset(pal, 0, 256 * sizeof(PalEntry));
|
2003-09-02 09:54:42 +00:00
|
|
|
pal[187].red = 255;
|
2003-07-28 01:44:38 +00:00
|
|
|
pal[187].green = 255;
|
2003-09-02 09:54:42 +00:00
|
|
|
pal[187].blue = 255;
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->setPalette(0, 256, (uint8 *) pal, RDPAL_FADE);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->fadeUp();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_memory->freeMemory(text_spr);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->waitForFade();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-11 10:30:25 +00:00
|
|
|
uint32 targetTime = _system->get_msecs() + (time * 1000);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-05 15:28:15 +00:00
|
|
|
sleepUntil(targetTime);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->setPalette(0, 256, (uint8 *) oldPal, RDPAL_FADE);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fades message down and removes it, fading up again afterwards
|
|
|
|
//
|
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::removeMsg(void) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->fadeDown();
|
|
|
|
_graphics->waitForFade();
|
|
|
|
_graphics->clearScene();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
// _graphics->fadeUp();
|
2003-09-02 09:54:42 +00:00
|
|
|
// removed by JEL (08oct97) to prevent "eye" smacker corruption when
|
|
|
|
// restarting game from CD2 and also to prevent palette flicker when
|
|
|
|
// restoring game to a different CD since the "insert CD" message uses
|
|
|
|
// this routine to clean up!
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::sendBackPar0Frames(void) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// could be none at all - theoretically at least
|
2003-11-01 16:55:20 +00:00
|
|
|
for (uint i = 0; i < _curBgp0; i++) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// frame attached to 1st background parallax
|
2003-11-01 16:55:20 +00:00
|
|
|
processImage(&_bgp0List[i]);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::sendBackPar1Frames(void) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// could be none at all - theoretically at least
|
2003-11-01 16:55:20 +00:00
|
|
|
for (uint i = 0; i < _curBgp1; i++) {
|
2003-10-08 06:58:34 +00:00
|
|
|
// frame attached to 2nd background parallax
|
2003-11-01 16:55:20 +00:00
|
|
|
processImage(&_bgp1List[i]);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::sendBackFrames(void) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// could be none at all - theoretically at least
|
2003-11-01 16:55:20 +00:00
|
|
|
for (uint i = 0; i < _curBack; i++) {
|
|
|
|
processImage(&_backList[i]);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::sendSortFrames(void) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// send the sort frames for printing - layers, shrinkers & normal flat
|
|
|
|
// sprites
|
|
|
|
|
|
|
|
// could be none at all - theoretically at least
|
2003-11-01 16:55:20 +00:00
|
|
|
for (uint i = 0; i < _curSort; i++) {
|
|
|
|
if (_sortList[_sortOrder[i]].layer_number) {
|
2003-12-28 15:08:12 +00:00
|
|
|
// it's a layer - minus 1 for true layer number
|
|
|
|
// we need to know from the BuildUnit because the
|
|
|
|
// layers will have been sorted in random order
|
2003-11-01 16:55:20 +00:00
|
|
|
processLayer(_sortList[_sortOrder[i]].layer_number - 1);
|
2003-09-02 09:54:42 +00:00
|
|
|
} else {
|
|
|
|
// sprite
|
2003-11-01 16:55:20 +00:00
|
|
|
processImage(&_sortList[_sortOrder[i]]);
|
2003-09-02 09:54:42 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::sendForeFrames(void) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// could be none at all - theoretically at least
|
2003-11-01 16:55:20 +00:00
|
|
|
for (uint i = 0; i < _curFore; i++) {
|
|
|
|
processImage(&_foreList[i]);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::sendForePar0Frames(void) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// could be none at all - theoretically at least
|
2003-11-01 16:55:20 +00:00
|
|
|
for (uint i = 0; i < _curFgp0; i++) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// frame attached to 1st foreground parallax
|
2003-11-01 16:55:20 +00:00
|
|
|
processImage(&_fgp0List[i]);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::sendForePar1Frames(void) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// could be none at all - theoretically at least
|
2003-11-01 16:55:20 +00:00
|
|
|
for (uint i = 0; i < _curFgp1; i++) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// frame attached to 2nd foreground parallax
|
2003-11-01 16:55:20 +00:00
|
|
|
processImage(&_fgp1List[i]);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::processLayer(uint32 layer_number) {
|
2003-09-02 09:54:42 +00:00
|
|
|
uint8 *file;
|
2003-12-28 15:08:12 +00:00
|
|
|
LayerHeader *layer_head;
|
|
|
|
SpriteInfo spriteInfo;
|
2003-09-02 09:54:42 +00:00
|
|
|
uint32 rv;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
uint32 current_layer_area = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// file points to 1st byte in the layer file
|
2003-11-16 14:18:29 +00:00
|
|
|
file = _resman->openResource(_thisScreen.background_layer_id);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// point to layer header
|
2003-11-03 07:47:42 +00:00
|
|
|
layer_head = fetchLayerHeader(file,layer_number);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
spriteInfo.x = layer_head->x;
|
|
|
|
spriteInfo.y = layer_head->y;
|
|
|
|
spriteInfo.w = layer_head->width;
|
|
|
|
spriteInfo.scale = 0;
|
|
|
|
spriteInfo.scaledWidth = 0;
|
|
|
|
spriteInfo.scaledHeight = 0;
|
|
|
|
spriteInfo.h = layer_head->height;
|
2003-10-11 12:26:53 +00:00
|
|
|
spriteInfo.type = RDSPR_TRANS | RDSPR_RLE256FAST;
|
2003-09-02 09:54:42 +00:00
|
|
|
spriteInfo.blend = 0;
|
2003-12-28 15:08:12 +00:00
|
|
|
spriteInfo.data = file + sizeof(StandardHeader) + layer_head->offset;
|
2003-09-02 09:54:42 +00:00
|
|
|
spriteInfo.colourTable = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// check for largest layer for debug info
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-07-28 01:44:38 +00:00
|
|
|
current_layer_area = layer_head->width * layer_head->height;
|
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
if (current_layer_area > _largestLayerArea) {
|
|
|
|
_largestLayerArea = current_layer_area;
|
|
|
|
sprintf(_largestLayerInfo,
|
2003-09-02 09:54:42 +00:00
|
|
|
"largest layer: %s layer(%d) is %dx%d",
|
2003-11-03 07:47:42 +00:00
|
|
|
fetchObjectName(_thisScreen.background_layer_id),
|
2003-09-02 09:54:42 +00:00
|
|
|
layer_number, layer_head->width, layer_head->height);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-10-26 15:42:49 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
rv = _graphics->drawSprite(&spriteInfo);
|
2003-07-28 01:44:38 +00:00
|
|
|
if (rv)
|
2003-09-27 11:02:58 +00:00
|
|
|
error("Driver Error %.8x in Process_layer(%d)", rv, layer_number);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
void Sword2Engine::processImage(BuildUnit *build_unit) {
|
2003-09-02 09:54:42 +00:00
|
|
|
uint8 *file, *colTablePtr = NULL;
|
2003-12-28 15:08:12 +00:00
|
|
|
AnimHeader *anim_head;
|
|
|
|
FrameHeader *frame_head;
|
|
|
|
CdtEntry *cdt_entry;
|
|
|
|
SpriteInfo spriteInfo;
|
2003-09-02 09:54:42 +00:00
|
|
|
uint32 spriteType;
|
|
|
|
uint32 rv;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
uint32 current_sprite_area = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// open anim resource file & point to base
|
2003-11-16 14:18:29 +00:00
|
|
|
file = _resman->openResource(build_unit->anim_resource);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
anim_head = fetchAnimHeader(file);
|
|
|
|
cdt_entry = fetchCdtEntry(file, build_unit->anim_pc);
|
|
|
|
frame_head = fetchFrameHeader(file, build_unit->anim_pc);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// so that 0-colour is transparent
|
|
|
|
spriteType = RDSPR_TRANS;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
if (anim_head->blend)
|
2003-09-26 10:07:18 +00:00
|
|
|
spriteType |= RDSPR_BLEND;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// if the frame is to be flipped (only really applicable to frames
|
|
|
|
// using offsets)
|
|
|
|
if (cdt_entry->frameType & FRAME_FLIPPED)
|
2003-09-26 10:07:18 +00:00
|
|
|
spriteType |= RDSPR_FLIP;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
if (cdt_entry->frameType & FRAME_256_FAST) {
|
|
|
|
// scaling, shading & blending don't work with RLE256FAST
|
|
|
|
// but the same compression can be decompressed using the
|
|
|
|
// RLE256 routines!
|
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
// NOTE: If this restriction refers to drawSprite(), I don't
|
2003-09-02 09:54:42 +00:00
|
|
|
// think we have it any more. But I'm not sure.
|
|
|
|
|
|
|
|
if (build_unit->scale || anim_head->blend || build_unit->shadingFlag)
|
2003-09-26 10:07:18 +00:00
|
|
|
spriteType |= RDSPR_RLE256;
|
2003-07-28 01:44:38 +00:00
|
|
|
else
|
2003-09-26 10:07:18 +00:00
|
|
|
spriteType |= RDSPR_RLE256FAST;
|
2003-09-02 09:54:42 +00:00
|
|
|
} else {
|
|
|
|
// what compression was used?
|
|
|
|
switch (anim_head->runTimeComp) {
|
2003-09-21 16:11:26 +00:00
|
|
|
case NONE:
|
2003-09-26 10:07:18 +00:00
|
|
|
spriteType |= RDSPR_NOCOMPRESSION;
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case RLE256:
|
2003-09-26 10:07:18 +00:00
|
|
|
spriteType |= RDSPR_RLE256;
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case RLE16:
|
2003-09-26 10:07:18 +00:00
|
|
|
spriteType |= RDSPR_RLE16;
|
2003-09-21 16:11:26 +00:00
|
|
|
// points to just after last cdt_entry, ie.
|
|
|
|
// start of colour table
|
2003-12-28 15:08:12 +00:00
|
|
|
colTablePtr = (uint8 *) (anim_head + 1) + anim_head->noAnimFrames * sizeof(CdtEntry);
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// if we want this frame to be affected by the shading mask,
|
|
|
|
// add the status bit
|
2003-11-01 16:55:20 +00:00
|
|
|
if (build_unit->shadingFlag)
|
2003-09-26 10:07:18 +00:00
|
|
|
spriteType |= RDSPR_SHADOW;
|
2003-09-02 09:54:42 +00:00
|
|
|
|
|
|
|
spriteInfo.x = build_unit->x;
|
|
|
|
spriteInfo.y = build_unit->y;
|
|
|
|
spriteInfo.w = frame_head->width;
|
|
|
|
spriteInfo.h = frame_head->height;
|
|
|
|
spriteInfo.scale = build_unit->scale;
|
|
|
|
spriteInfo.scaledWidth = build_unit->scaled_width;
|
2003-07-28 01:44:38 +00:00
|
|
|
spriteInfo.scaledHeight = build_unit->scaled_height;
|
2003-09-02 09:54:42 +00:00
|
|
|
spriteInfo.type = spriteType;
|
|
|
|
spriteInfo.blend = anim_head->blend;
|
|
|
|
// points to just after frame header, ie. start of sprite data
|
2003-09-27 11:02:58 +00:00
|
|
|
spriteInfo.data = (uint8 *) (frame_head + 1);
|
2003-07-28 01:44:38 +00:00
|
|
|
spriteInfo.colourTable = colTablePtr;
|
|
|
|
|
|
|
|
// check for largest layer for debug info
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-07-28 01:44:38 +00:00
|
|
|
current_sprite_area = frame_head->width * frame_head->height;
|
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
if (current_sprite_area > _largestSpriteArea) {
|
|
|
|
_largestSpriteArea = current_sprite_area;
|
|
|
|
sprintf(_largestSpriteInfo,
|
2003-09-02 09:54:42 +00:00
|
|
|
"largest sprite: %s frame(%d) is %dx%d",
|
2003-11-03 07:47:42 +00:00
|
|
|
fetchObjectName(build_unit->anim_resource),
|
2003-09-02 09:54:42 +00:00
|
|
|
build_unit->anim_pc,
|
|
|
|
frame_head->width,
|
|
|
|
frame_head->height);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
if (SYSTEM_TESTING_ANIMS) { // see anims.cpp
|
|
|
|
// bring the anim into the visible screen
|
|
|
|
// but leave extra pixel at edge for box
|
|
|
|
if (spriteInfo.x + spriteInfo.scaledWidth >= 639)
|
|
|
|
spriteInfo.x = 639 - spriteInfo.scaledWidth;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
if (spriteInfo.y + spriteInfo.scaledHeight >= 399)
|
|
|
|
spriteInfo.y = 399 - spriteInfo.scaledHeight;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
if (spriteInfo.x < 1)
|
|
|
|
spriteInfo.x = 1;
|
|
|
|
|
|
|
|
if (spriteInfo.y < 1)
|
|
|
|
spriteInfo.y = 1;
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// create box to surround sprite - just outside sprite box
|
2003-11-02 15:58:45 +00:00
|
|
|
_debugger->_rectX1 = spriteInfo.x - 1;
|
|
|
|
_debugger->_rectY1 = spriteInfo.y - 1;
|
|
|
|
_debugger->_rectX2 = spriteInfo.x + spriteInfo.scaledWidth;
|
|
|
|
_debugger->_rectY2 = spriteInfo.y + spriteInfo.scaledHeight;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// #ifdef _SWORD2_DEBUG
|
|
|
|
// if (frame_head->width <= 1) {
|
2003-11-03 07:47:42 +00:00
|
|
|
// debug(5, "WARNING: 1-pixel-wide frame found in %s (%d)", fetchObjectName(build_unit->anim_resource), build_unit->anim_resource);
|
2003-07-28 01:44:38 +00:00
|
|
|
// }
|
2003-09-02 09:54:42 +00:00
|
|
|
// #endif
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
rv = _graphics->drawSprite(&spriteInfo);
|
2003-07-28 01:44:38 +00:00
|
|
|
if (rv)
|
2003-11-01 16:55:20 +00:00
|
|
|
error("Driver Error %.8x with sprite %s (%d) in processImage",
|
2003-11-03 07:47:42 +00:00
|
|
|
rv, fetchObjectName(build_unit->anim_resource),
|
2003-09-27 11:02:58 +00:00
|
|
|
build_unit->anim_resource);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// release the anim resource
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(build_unit->anim_resource);
|
2003-09-02 09:54:42 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::resetRenderLists(void) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// reset the sort lists - do this before a logic loop
|
|
|
|
// takes into account the fact that the start of the list is pre-built
|
|
|
|
// with the special sortable layers
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
_curBgp0 = 0;
|
|
|
|
_curBgp1 = 0;
|
|
|
|
_curBack = 0;
|
2003-09-02 09:54:42 +00:00
|
|
|
// beginning of sort list is setup with the special sort layers
|
2003-11-02 17:17:10 +00:00
|
|
|
_curSort = _thisScreen.number_of_layers;
|
2003-11-01 16:55:20 +00:00
|
|
|
_curFore = 0;
|
|
|
|
_curFgp0 = 0;
|
|
|
|
_curFgp1 = 0;
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
if (_curSort) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// there are some layers - so rebuild the sort order
|
|
|
|
// positioning
|
2003-11-01 16:55:20 +00:00
|
|
|
for (uint i = 0; i < _curSort; i++)
|
|
|
|
_sortOrder[i] = i; //rebuild the order list
|
2003-09-02 09:54:42 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::sortTheSortList(void) {
|
|
|
|
// sort the list
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
// cannot bubble sort 0 or 1 items!
|
|
|
|
if (_curSort <= 1)
|
2003-09-02 09:54:42 +00:00
|
|
|
return;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
for (uint i = 0; i < _curSort - 1; i++) {
|
|
|
|
for (uint j = 0; j < _curSort - 1; j++) {
|
|
|
|
if (_sortList[_sortOrder[j]].sort_y > _sortList[_sortOrder[j + 1]].sort_y) {
|
|
|
|
SWAP(_sortOrder[j], _sortOrder[j + 1]);
|
2003-09-02 09:54:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
void Sword2Engine::registerFrame(int32 *params, BuildUnit *build_unit) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// params: 0 pointer to mouse structure or NULL for no write to mouse
|
|
|
|
// list (non-zero means write sprite-shape to mouse list)
|
|
|
|
// 1 pointer to graphic structure
|
|
|
|
// 2 pointer to mega structure
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
ObjectMega *ob_mega;
|
|
|
|
ObjectGraphic *ob_graph;
|
|
|
|
ObjectMouse *ob_mouse;
|
2003-09-02 09:54:42 +00:00
|
|
|
uint8 *file;
|
2003-12-28 15:08:12 +00:00
|
|
|
FrameHeader *frame_head;
|
|
|
|
AnimHeader *anim_head;
|
|
|
|
CdtEntry *cdt_entry;
|
2003-09-02 09:54:42 +00:00
|
|
|
int scale = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// open animation file & set up the necessary pointers
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
ob_graph = (ObjectGraphic *) _memory->intToPtr(params[1]);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
assert(ob_graph->anim_resource);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
file = _resman->openResource(ob_graph->anim_resource);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
anim_head = fetchAnimHeader(file);
|
|
|
|
cdt_entry = fetchCdtEntry(file, ob_graph->anim_pc);
|
|
|
|
frame_head = fetchFrameHeader(file, ob_graph->anim_pc);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// update player graphic details for on-screen debug info
|
|
|
|
if (ID == CUR_PLAYER_ID) {
|
2003-11-02 15:58:45 +00:00
|
|
|
_debugger->_playerGraphic.type = ob_graph->type;
|
|
|
|
_debugger->_playerGraphic.anim_resource = ob_graph->anim_resource;
|
2003-09-02 09:54:42 +00:00
|
|
|
// counting 1st frame as 'frame 1'
|
2003-11-02 15:58:45 +00:00
|
|
|
_debugger->_playerGraphic.anim_pc = ob_graph->anim_pc + 1;
|
|
|
|
_debugger->_playerGraphicNoFrames = anim_head->noAnimFrames;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
// fill in the BuildUnit structure for this frame
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
// retrieve the resource
|
2003-09-02 09:54:42 +00:00
|
|
|
build_unit->anim_resource = ob_graph->anim_resource;
|
2003-11-01 16:55:20 +00:00
|
|
|
// retrieve the frame
|
2003-09-02 09:54:42 +00:00
|
|
|
build_unit->anim_pc = ob_graph->anim_pc;
|
2003-11-01 16:55:20 +00:00
|
|
|
// not a layer
|
2003-09-02 09:54:42 +00:00
|
|
|
build_unit->layer_number = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// Affected by shading mask?
|
2003-07-28 01:44:38 +00:00
|
|
|
if (ob_graph->type & SHADED_SPRITE)
|
2003-11-01 16:55:20 +00:00
|
|
|
build_unit->shadingFlag = true;
|
2003-07-28 01:44:38 +00:00
|
|
|
else
|
2003-11-01 16:55:20 +00:00
|
|
|
build_unit->shadingFlag = false;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// check if this frame has offsets ie. this is a scalable mega frame
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
if (cdt_entry->frameType & FRAME_OFFSET) {
|
|
|
|
// param 2 is pointer to mega structure
|
2003-12-28 15:08:12 +00:00
|
|
|
ob_mega = (ObjectMega *) _memory->intToPtr(params[2]);
|
2003-09-02 09:54:42 +00:00
|
|
|
|
|
|
|
// calc scale at which to print the sprite, based on feet
|
|
|
|
// y-coord & scaling constants (NB. 'scale' is actually
|
|
|
|
// 256 * true_scale, to maintain accuracy)
|
|
|
|
|
|
|
|
// Ay+B gives 256 * scale ie. 256 * 256 * true_scale for even
|
|
|
|
// better accuracy, ie. scale = (Ay + B) / 256
|
|
|
|
scale = (ob_mega->scale_a * ob_mega->feet_y + ob_mega->scale_b) / 256;
|
|
|
|
|
|
|
|
// calc final render coordinates (top-left of sprite), based
|
|
|
|
// on feet coords & scaled offsets
|
|
|
|
|
|
|
|
// add scaled offsets to feet coords
|
|
|
|
build_unit->x = ob_mega->feet_x + (cdt_entry->x * scale) / 256;
|
|
|
|
build_unit->y = ob_mega->feet_y + (cdt_entry->y * scale) / 256;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// work out new width and height
|
2003-09-02 09:54:42 +00:00
|
|
|
// always divide by 256 after everything else, to maintain
|
|
|
|
// accurary
|
|
|
|
build_unit->scaled_width = ((scale * frame_head->width) / 256);
|
|
|
|
build_unit->scaled_height = ((scale * frame_head->height) / 256);
|
|
|
|
} else {
|
|
|
|
// it's a non-scaling anim
|
2003-07-28 01:44:38 +00:00
|
|
|
// get render coords for sprite, from cdt
|
2003-09-02 09:54:42 +00:00
|
|
|
build_unit->x = cdt_entry->x;
|
|
|
|
build_unit->y = cdt_entry->y;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// get width and height
|
2003-09-02 09:54:42 +00:00
|
|
|
build_unit->scaled_width = frame_head->width;
|
|
|
|
build_unit->scaled_height = frame_head->height;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// either 0 or required scale, depending on whether 'scale' computed
|
|
|
|
build_unit->scale = scale;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// calc the bottom y-coord for sorting purposes
|
2003-09-02 09:54:42 +00:00
|
|
|
build_unit->sort_y = build_unit->y + build_unit->scaled_height - 1;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
if (params[0]) {
|
2003-11-02 18:50:09 +00:00
|
|
|
// passed a mouse structure, so add to the _mouseList
|
2003-12-28 15:08:12 +00:00
|
|
|
ob_mouse = (ObjectMouse *) _memory->intToPtr(params[0]);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-08 06:58:34 +00:00
|
|
|
// only if 'pointer' isn't NULL
|
2003-09-02 09:54:42 +00:00
|
|
|
if (ob_mouse->pointer) {
|
2003-11-02 18:50:09 +00:00
|
|
|
assert(_curMouse < TOTAL_mouse_list);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-02 18:50:09 +00:00
|
|
|
_mouseList[_curMouse].x1 = build_unit->x;
|
|
|
|
_mouseList[_curMouse].y1 = build_unit->y;
|
|
|
|
_mouseList[_curMouse].x2 = build_unit->x + build_unit->scaled_width;
|
|
|
|
_mouseList[_curMouse].y2 = build_unit->y + build_unit->scaled_height;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-02 18:50:09 +00:00
|
|
|
_mouseList[_curMouse].priority = ob_mouse->priority;
|
|
|
|
_mouseList[_curMouse].pointer = ob_mouse->pointer;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// check if pointer text field is set due to previous
|
|
|
|
// object using this slot (ie. not correct for this
|
|
|
|
// one)
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// if 'pointer_text' field is set, but the 'id' field
|
|
|
|
// isn't same is current id
|
|
|
|
// then we don't want this "left over" pointer text
|
2003-10-05 15:28:15 +00:00
|
|
|
|
2003-11-02 18:50:09 +00:00
|
|
|
if (_mouseList[_curMouse].pointer_text && _mouseList[_curMouse].id != (int32) ID)
|
|
|
|
_mouseList[_curMouse].pointer_text=0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-02 18:50:09 +00:00
|
|
|
_mouseList[_curMouse].id = ID;
|
2003-09-02 09:54:42 +00:00
|
|
|
// not using sprite as detection mask
|
2003-11-02 18:50:09 +00:00
|
|
|
_mouseList[_curMouse].anim_resource = 0;
|
|
|
|
_mouseList[_curMouse].anim_pc = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-02 18:50:09 +00:00
|
|
|
_curMouse++;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// close animation file
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(ob_graph->anim_resource);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnRegisterFrame(int32 *params) {
|
|
|
|
// this call would be made from an objects service script 0
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
// params: 0 pointer to mouse structure or NULL for no write to
|
|
|
|
// mouse list (non-zero means write sprite-shape to
|
|
|
|
// mouse list)
|
|
|
|
// 1 pointer to graphic structure
|
|
|
|
// 2 pointer to mega structure or NULL if not a mega
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
return _vm->registerFrame(params);
|
2003-11-01 16:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32 Sword2Engine::registerFrame(int32 *params) {
|
2003-12-28 15:08:12 +00:00
|
|
|
ObjectGraphic *ob_graph = (ObjectGraphic *) _memory->intToPtr(params[1]);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// check low word for sprite type
|
|
|
|
switch (ob_graph->type & 0x0000ffff) {
|
2003-09-21 16:11:26 +00:00
|
|
|
case BGP0_SPRITE:
|
2003-11-01 16:55:20 +00:00
|
|
|
assert(_curBgp0 < MAX_bgp0_sprites);
|
|
|
|
registerFrame(params, &_bgp0List[_curBgp0]);
|
|
|
|
_curBgp0++;
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case BGP1_SPRITE:
|
2003-11-01 16:55:20 +00:00
|
|
|
assert(_curBgp1 < MAX_bgp1_sprites);
|
|
|
|
registerFrame(params, &_bgp1List[_curBgp1]);
|
|
|
|
_curBgp1++;
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case BACK_SPRITE:
|
2003-11-01 16:55:20 +00:00
|
|
|
assert(_curBack < MAX_back_sprites);
|
|
|
|
registerFrame(params, &_backList[_curBack]);
|
|
|
|
_curBack++;
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case SORT_SPRITE:
|
2003-11-01 16:55:20 +00:00
|
|
|
assert(_curSort < MAX_sort_sprites);
|
|
|
|
_sortOrder[_curSort] = _curSort;
|
|
|
|
registerFrame(params, &_sortList[_curSort]);
|
|
|
|
_curSort++;
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case FORE_SPRITE:
|
2003-11-01 16:55:20 +00:00
|
|
|
assert(_curFore < MAX_fore_sprites);
|
|
|
|
registerFrame(params, &_foreList[_curFore]);
|
|
|
|
_curFore++;
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case FGP0_SPRITE:
|
2003-11-01 16:55:20 +00:00
|
|
|
assert(_curFgp0 < MAX_fgp0_sprites);
|
|
|
|
registerFrame(params, &_fgp0List[_curFgp0]);
|
|
|
|
_curFgp0++;
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case FGP1_SPRITE:
|
2003-11-01 16:55:20 +00:00
|
|
|
assert(_curFgp1 < MAX_fgp1_sprites);
|
|
|
|
registerFrame(params, &_fgp1List[_curFgp1]);
|
|
|
|
_curFgp1++;
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// NO_SPRITE no registering!
|
|
|
|
break;
|
2003-09-02 09:54:42 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::startNewPalette(void) {
|
|
|
|
// start layer palette fading up
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
uint8 *screenFile;
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// if the screen is still fading down then wait for black - could
|
|
|
|
// happen when everythings cached into a large memory model
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->waitForFade();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// open the screen file
|
2003-11-16 14:18:29 +00:00
|
|
|
screenFile = _resman->openResource(_thisScreen.background_layer_id);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(screenFile));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->setPalette(0, 256, fetchPalette(screenFile), RDPAL_FADE);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// indicating that it's a screen palette
|
2003-11-01 16:55:20 +00:00
|
|
|
_lastPaletteRes = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// close screen file
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// start fade up
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->fadeUp();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// reset
|
2003-11-02 17:17:10 +00:00
|
|
|
_thisScreen.new_palette = 0;
|
2003-09-02 09:54:42 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnUpdatePlayerStats(int32 *params) {
|
|
|
|
// engine needs to know certain info about the player
|
|
|
|
|
|
|
|
// params: 0 pointer to mega structure
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
ObjectMega *ob_mega = (ObjectMega *) _vm->_memory->intToPtr(params[0]);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->_thisScreen.player_feet_x = ob_mega->feet_x;
|
|
|
|
_vm->_thisScreen.player_feet_y = ob_mega->feet_y;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
// for the script
|
2003-09-02 09:54:42 +00:00
|
|
|
PLAYER_FEET_X = ob_mega->feet_x;
|
|
|
|
PLAYER_FEET_Y = ob_mega->feet_y;
|
|
|
|
PLAYER_CUR_DIR = ob_mega->current_dir;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
SCROLL_OFFSET_X = _vm->_thisScreen.scroll_offset_x;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
debug(5, "fnUpdatePlayerStats: %d %d", ob_mega->feet_x, ob_mega->feet_y);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnFadeDown(int32 *params) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// NONE means up! can only be called when screen is fully faded up -
|
|
|
|
// multiple calls wont have strange effects
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
// params: none
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
if (_vm->_graphics->getFadeStatus() == RDFADE_NONE)
|
|
|
|
_vm->_graphics->fadeDown();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnFadeUp(int32 *params) {
|
|
|
|
// params: none
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->waitForFade();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
if (_vm->_graphics->getFadeStatus() == RDFADE_BLACK)
|
|
|
|
_vm->_graphics->fadeUp();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnSetPalette(int32 *params) {
|
|
|
|
// params: 0 resource number of palette file, or 0 if it's to be
|
|
|
|
// the palette from the current screen
|
2003-11-01 16:55:20 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->setFullPalette(params[0]);
|
2003-09-02 09:54:42 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
void Sword2Engine::setFullPalette(int32 palRes) {
|
2003-07-28 01:44:38 +00:00
|
|
|
uint8 *file;
|
2003-12-28 15:08:12 +00:00
|
|
|
StandardHeader *head;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// fudge for hut interior
|
2003-09-02 09:54:42 +00:00
|
|
|
// - unpausing should restore last palette as normal (could be screen
|
|
|
|
// palette or 'dark_palette_13')
|
|
|
|
// - but restoring the screen palette after 'dark_plaette_13' should
|
|
|
|
// now work properly too!
|
|
|
|
|
|
|
|
// hut interior
|
|
|
|
if (LOCATION == 13) {
|
|
|
|
// unpausing
|
|
|
|
if (palRes == -1) {
|
|
|
|
// restore whatever palette was last set (screen
|
|
|
|
// palette or 'dark_palette_13')
|
2003-11-01 16:55:20 +00:00
|
|
|
palRes = _lastPaletteRes;
|
2003-09-02 09:54:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-07-28 01:44:38 +00:00
|
|
|
// check if we're just restoring the current screen palette
|
2003-09-02 09:54:42 +00:00
|
|
|
// because we might actually need to use a separate palette
|
|
|
|
// file anyway eg. for pausing & unpausing during the eclipse
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// unpausing (fudged for location 13)
|
|
|
|
if (palRes == -1) {
|
|
|
|
// we really meant '0'
|
|
|
|
palRes = 0;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
if (palRes == 0 && _lastPaletteRes)
|
|
|
|
palRes = _lastPaletteRes;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// non-zero: set palette to this separate palette file
|
|
|
|
if (palRes) {
|
|
|
|
// open the palette file
|
2003-12-28 15:08:12 +00:00
|
|
|
head = (StandardHeader *) _resman->openResource(palRes);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
assert(head->fileType == PALETTE_FILE);
|
2003-09-02 09:54:42 +00:00
|
|
|
|
2003-10-08 06:58:34 +00:00
|
|
|
file = (uint8 *) (head + 1);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// always set colour 0 to black because most background screen
|
|
|
|
// palettes have a bright colour 0 although it should come out
|
|
|
|
// as black in the game!
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
file[0] = 0;
|
|
|
|
file[1] = 0;
|
|
|
|
file[2] = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
file[3] = 0;
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// not yet in separate palette files
|
2003-11-16 14:18:29 +00:00
|
|
|
// _graphics->updatePaletteMatchTable(file + (256 * 4));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->setPalette(0, 256, file, RDPAL_INSTANT);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
if (palRes != CONTROL_PANEL_PALETTE) { // (James 03sep97)
|
|
|
|
// indicating that it's a separate palette resource
|
2003-11-01 16:55:20 +00:00
|
|
|
_lastPaletteRes = palRes;
|
2003-09-02 09:54:42 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// close palette file
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(palRes);
|
2003-09-02 09:54:42 +00:00
|
|
|
} else {
|
|
|
|
// 0: set palette to current screen palette
|
2003-11-02 17:17:10 +00:00
|
|
|
if (_thisScreen.background_layer_id) {
|
2003-09-02 09:54:42 +00:00
|
|
|
// open the screen file
|
2003-11-16 14:18:29 +00:00
|
|
|
file = _resman->openResource(_thisScreen.background_layer_id);
|
|
|
|
_graphics->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(file));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_graphics->setPalette(0, 256, fetchPalette(file), RDPAL_INSTANT);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
// indicating that it's a screen palette
|
2003-11-01 16:55:20 +00:00
|
|
|
_lastPaletteRes = 0;
|
2003-09-02 09:54:42 +00:00
|
|
|
|
|
|
|
// close screen file
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_thisScreen.background_layer_id);
|
2003-09-02 09:54:42 +00:00
|
|
|
} else
|
2003-11-01 16:55:20 +00:00
|
|
|
error("setFullPalette(0) called, but no current screen available!");
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnRestoreGame(int32 *params) {
|
|
|
|
// params: none
|
2003-09-02 09:54:42 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnChangeShadows(int32 *params) {
|
|
|
|
// params: none
|
|
|
|
|
2003-10-05 15:28:15 +00:00
|
|
|
// if last screen was using a shading mask (see below)
|
2003-11-08 15:47:51 +00:00
|
|
|
if (_vm->_thisScreen.mask_flag) {
|
2003-11-16 14:18:29 +00:00
|
|
|
uint32 rv = _vm->_graphics->closeLightMask();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
if (rv)
|
2003-09-27 11:02:58 +00:00
|
|
|
error("Driver Error %.8x [%s line %u]", rv);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->_thisScreen.mask_flag = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-02 09:54:42 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword2
|