2004-01-06 13:44:17 +00:00
|
|
|
/* Copyright (C) 1994-2004 Revolution Software Ltd
|
2003-07-28 01:47:41 +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-11-16 14:18:29 +00:00
|
|
|
#include "common/stdafx.h"
|
2003-11-08 18:15:35 +00:00
|
|
|
#include "sword2/sword2.h"
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "sword2/driver/menu.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/driver/render.h"
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
namespace Sword2 {
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
Graphics::Graphics(Sword2Engine *vm, int16 width, int16 height)
|
|
|
|
: _vm(vm), _iconCount(0), _needFullRedraw(false),
|
|
|
|
_fadeStatus(RDFADE_NONE), _mouseSprite(NULL), _mouseAnim(NULL),
|
|
|
|
_luggageAnim(NULL), _layer(0), _renderAverageTime(60),
|
|
|
|
_lightMask(NULL), _screenWide(width), _screenDeep(height) {
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
int i, j;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2004-01-04 15:11:30 +00:00
|
|
|
_buffer = _dirtyGrid = NULL;
|
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
_buffer = (byte *) malloc(width * height);
|
|
|
|
if (!_buffer)
|
|
|
|
error("Could not initialise display");
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_system->init_size(width, height);
|
2003-09-28 14:13:57 +00:00
|
|
|
|
2004-01-04 15:11:30 +00:00
|
|
|
_gridWide = width / CELLWIDE;
|
|
|
|
_gridDeep = height / CELLDEEP;
|
|
|
|
|
|
|
|
if ((width % CELLWIDE) || (height % CELLDEEP))
|
|
|
|
error("Bad cell size");
|
|
|
|
|
|
|
|
_dirtyGrid = (byte *) calloc(_gridWide, _gridDeep);
|
|
|
|
if (!_buffer)
|
|
|
|
error("Could not initialise dirty grid");
|
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
for (i = 0; i < ARRAYSIZE(_blockSurfaces); i++)
|
|
|
|
_blockSurfaces[i] = NULL;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
for (j = 0; j < RDMENU_MAXPOCKETS; j++) {
|
|
|
|
_icons[i][j] = NULL;
|
|
|
|
_pocketStatus[i][j] = 0;
|
|
|
|
}
|
2003-09-28 14:13:57 +00:00
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
_menuStatus[i] = RDMENU_HIDDEN;
|
|
|
|
}
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 15:11:30 +00:00
|
|
|
Graphics::~Graphics() {
|
|
|
|
free(_buffer);
|
|
|
|
free(_dirtyGrid);
|
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
2003-10-15 06:40:31 +00:00
|
|
|
* @return the graphics detail setting
|
2003-09-28 14:13:57 +00:00
|
|
|
*/
|
|
|
|
|
2003-11-11 07:43:02 +00:00
|
|
|
int8 Graphics::getRenderLevel(void) {
|
2003-10-15 06:40:31 +00:00
|
|
|
return _renderLevel;
|
2003-08-26 06:53:00 +00:00
|
|
|
}
|
|
|
|
|
2003-11-11 07:43:02 +00:00
|
|
|
void Graphics::setRenderLevel(int8 level) {
|
2003-10-15 06:40:31 +00:00
|
|
|
_renderLevel = level;
|
|
|
|
|
|
|
|
switch (_renderLevel) {
|
|
|
|
case 0:
|
|
|
|
// Lowest setting: no fancy stuff
|
|
|
|
_renderCaps = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
// Medium-low setting: transparency-blending
|
|
|
|
_renderCaps = RDBLTFX_SPRITEBLEND;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// Medium-high setting: transparency-blending + shading
|
|
|
|
_renderCaps = RDBLTFX_SPRITEBLEND | RDBLTFX_SHADOWBLEND;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
// Highest setting: transparency-blending + shading +
|
|
|
|
// edge-blending + improved stretching
|
|
|
|
_renderCaps = RDBLTFX_SPRITEBLEND | RDBLTFX_SHADOWBLEND | RDBLTFX_EDGEBLEND;
|
|
|
|
break;
|
|
|
|
}
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
2003-09-28 16:38:00 +00:00
|
|
|
* Fill the screen buffer with palette colour zero. Note that it does not
|
|
|
|
* touch the menu areas of the screen.
|
2003-09-28 14:13:57 +00:00
|
|
|
*/
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-11-11 07:43:02 +00:00
|
|
|
void Graphics::clearScene(void) {
|
2003-10-15 06:40:31 +00:00
|
|
|
memset(_buffer + MENUDEEP * _screenWide, 0, _screenWide * RENDERDEEP);
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
void MoviePlayer::openTextObject(MovieTextObject *obj) {
|
2003-09-09 15:17:12 +00:00
|
|
|
if (obj->textSprite)
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->createSurface(obj->textSprite, &_textSurface);
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
void MoviePlayer::closeTextObject(MovieTextObject *obj) {
|
2003-10-05 15:28:15 +00:00
|
|
|
if (_textSurface) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->deleteSurface(_textSurface);
|
2003-10-05 15:28:15 +00:00
|
|
|
_textSurface = NULL;
|
2003-09-09 15:17:12 +00:00
|
|
|
}
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
void MoviePlayer::drawTextObject(MovieTextObject *obj) {
|
2003-10-05 15:28:15 +00:00
|
|
|
if (obj->textSprite && _textSurface)
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->drawSurface(obj->textSprite, _textSurface);
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* Plays an animated cutscene.
|
|
|
|
* @param filename the file name of the cutscene file
|
|
|
|
* @param text the subtitles and voiceovers for the cutscene
|
|
|
|
* @param musicOut lead-out music
|
|
|
|
*/
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
int32 MoviePlayer::play(char *filename, MovieTextObject *text[], uint8 *musicOut) {
|
2003-09-08 17:18:38 +00:00
|
|
|
warning("semi-stub PlaySmacker %s", filename);
|
|
|
|
|
|
|
|
// WORKAROUND: For now, we just do the voice-over parts of the
|
|
|
|
// movies, since they're separate from the actual smacker files.
|
|
|
|
|
|
|
|
if (text) {
|
|
|
|
uint8 oldPal[1024];
|
|
|
|
uint8 tmpPal[1024];
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->clearScene();
|
2003-09-08 17:18:38 +00:00
|
|
|
|
2003-09-09 15:54:13 +00:00
|
|
|
// HACK: Draw instructions
|
|
|
|
//
|
|
|
|
// I'm using the the menu area, because that's unlikely to be
|
|
|
|
// touched by anything else during the cutscene.
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
memset(_vm->_graphics->_buffer, 0, _vm->_graphics->_screenWide * MENUDEEP);
|
2003-09-09 15:54:13 +00:00
|
|
|
|
|
|
|
uint8 msg[] = "Cutscene - Press ESC to exit";
|
2003-12-28 15:08:12 +00:00
|
|
|
Memory *data = _vm->_fontRenderer->makeTextSprite(msg, 640, 255, _vm->_speechFontId);
|
|
|
|
FrameHeader *frame = (FrameHeader *) data->ad;
|
|
|
|
SpriteInfo msgSprite;
|
2003-09-09 15:54:13 +00:00
|
|
|
uint8 *msgSurface;
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
msgSprite.x = _vm->_graphics->_screenWide / 2 - frame->width / 2;
|
2003-09-09 15:54:13 +00:00
|
|
|
msgSprite.y = RDMENU_MENUDEEP / 2 - frame->height / 2;
|
|
|
|
msgSprite.w = frame->width;
|
|
|
|
msgSprite.h = frame->height;
|
2003-12-10 08:01:58 +00:00
|
|
|
msgSprite.type = RDSPR_NOCOMPRESSION;
|
2003-12-28 15:08:12 +00:00
|
|
|
msgSprite.data = data->ad + sizeof(FrameHeader);
|
2003-09-09 15:54:13 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->createSurface(&msgSprite, &msgSurface);
|
|
|
|
_vm->_graphics->drawSurface(&msgSprite, msgSurface);
|
|
|
|
_vm->_graphics->deleteSurface(msgSurface);
|
|
|
|
_vm->_memory->freeMemory(data);
|
2003-09-09 15:54:13 +00:00
|
|
|
|
2003-09-08 17:18:38 +00:00
|
|
|
// In case the cutscene has a long lead-in, start just before
|
|
|
|
// the first line of text.
|
|
|
|
|
|
|
|
int frameCounter = text[0]->startFrame - 12;
|
|
|
|
int textCounter = 0;
|
|
|
|
|
|
|
|
// Fake a palette that will hopefully make the text visible.
|
2003-09-09 07:01:04 +00:00
|
|
|
// In the opening cutscene it seems to use colours 1 (black?)
|
|
|
|
// and 255 (white?).
|
|
|
|
//
|
|
|
|
// The text should probably be colored the same as the rest of
|
|
|
|
// the in-game text.
|
2003-09-08 17:18:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
memcpy(oldPal, _vm->_graphics->_palCopy, 1024);
|
2003-09-08 17:18:38 +00:00
|
|
|
memset(tmpPal, 0, 1024);
|
|
|
|
tmpPal[255 * 4 + 0] = 255;
|
|
|
|
tmpPal[255 * 4 + 1] = 255;
|
|
|
|
tmpPal[255 * 4 + 2] = 255;
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->setPalette(0, 256, tmpPal, RDPAL_INSTANT);
|
2003-09-08 17:18:38 +00:00
|
|
|
|
2003-12-24 00:25:18 +00:00
|
|
|
PlayingSoundHandle handle;
|
2003-09-22 06:36:38 +00:00
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
bool skipCutscene = false;
|
|
|
|
|
2003-12-17 11:52:05 +00:00
|
|
|
uint32 flags = SoundMixer::FLAG_16BITS;
|
|
|
|
|
|
|
|
#ifndef SCUMM_BIG_ENDIAN
|
|
|
|
flags |= SoundMixer::FLAG_LITTLE_ENDIAN;
|
|
|
|
#endif
|
|
|
|
|
2003-09-23 06:34:19 +00:00
|
|
|
while (1) {
|
2003-09-08 17:44:26 +00:00
|
|
|
if (!text[textCounter])
|
|
|
|
break;
|
|
|
|
|
2003-09-08 17:18:38 +00:00
|
|
|
if (frameCounter == text[textCounter]->startFrame) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->clearScene();
|
2003-10-05 15:28:15 +00:00
|
|
|
openTextObject(text[textCounter]);
|
|
|
|
drawTextObject(text[textCounter]);
|
2003-09-22 06:36:38 +00:00
|
|
|
if (text[textCounter]->speech) {
|
2003-12-17 11:52:05 +00:00
|
|
|
_vm->_mixer->playRaw(&handle, text[textCounter]->speech, text[textCounter]->speechBufferSize, 22050, flags);
|
2003-09-22 06:36:38 +00:00
|
|
|
}
|
2003-09-08 17:18:38 +00:00
|
|
|
}
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-08 17:18:38 +00:00
|
|
|
if (frameCounter == text[textCounter]->endFrame) {
|
2003-10-05 15:28:15 +00:00
|
|
|
closeTextObject(text[textCounter]);
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->clearScene();
|
2004-01-04 15:11:30 +00:00
|
|
|
_vm->_graphics->setNeedFullRedraw();
|
2003-09-08 17:18:38 +00:00
|
|
|
textCounter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
frameCounter++;
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->updateDisplay();
|
2003-09-08 17:18:38 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
KeyboardEvent ke;
|
2003-09-08 17:18:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
if (_vm->_input->readKey(&ke) == RD_OK && ke.keycode == 27) {
|
|
|
|
_vm->_mixer->stopHandle(handle);
|
2003-09-28 14:13:57 +00:00
|
|
|
skipCutscene = true;
|
2003-09-08 17:18:38 +00:00
|
|
|
break;
|
2003-09-09 07:01:04 +00:00
|
|
|
}
|
2003-09-08 17:18:38 +00:00
|
|
|
|
2003-09-09 07:01:04 +00:00
|
|
|
// Simulate ~12 frames per second. I don't know what
|
|
|
|
// frame rate the original movies had, or even if it
|
|
|
|
// was constant, but this seems to work reasonably.
|
2003-09-28 14:13:57 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_system->delay_msecs(90);
|
2003-09-08 17:18:38 +00:00
|
|
|
}
|
|
|
|
|
2003-12-14 16:32:21 +00:00
|
|
|
// Wait for the voice to stop playing. This is to make sure
|
|
|
|
// that we don't cut off the speech in mid-sentence, and - even
|
|
|
|
// more importantly - that we don't free the sound buffer while
|
|
|
|
// it's in use.
|
|
|
|
|
2003-12-24 00:25:18 +00:00
|
|
|
while (handle.isActive()) {
|
2003-12-14 16:32:21 +00:00
|
|
|
_vm->_system->delay_msecs(100);
|
|
|
|
};
|
|
|
|
|
2003-10-05 15:28:15 +00:00
|
|
|
closeTextObject(text[textCounter]);
|
2003-09-09 15:54:13 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->clearScene();
|
|
|
|
_vm->_graphics->setNeedFullRedraw();
|
2003-09-30 16:07:04 +00:00
|
|
|
|
2003-09-09 15:54:13 +00:00
|
|
|
// HACK: Remove the instructions created above
|
2003-10-02 17:43:02 +00:00
|
|
|
Common::Rect r;
|
2003-09-09 15:54:13 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
memset(_vm->_graphics->_buffer, 0, _vm->_graphics->_screenWide * MENUDEEP);
|
2003-09-09 15:54:13 +00:00
|
|
|
r.left = r.top = 0;
|
2003-11-16 14:18:29 +00:00
|
|
|
r.right = _vm->_graphics->_screenWide;
|
2003-09-09 15:54:13 +00:00
|
|
|
r.bottom = MENUDEEP;
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->updateRect(&r);
|
2003-09-28 14:13:57 +00:00
|
|
|
|
|
|
|
// FIXME: For now, only play the lead-out music for cutscenes
|
|
|
|
// that have subtitles.
|
|
|
|
|
|
|
|
if (!skipCutscene)
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_sound->playLeadOut(musicOut);
|
2003-09-30 16:07:04 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_graphics->setPalette(0, 256, oldPal, RDPAL_INSTANT);
|
2003-09-08 17:18:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 07:01:12 +00:00
|
|
|
// Lead-in and lead-out music are, as far as I can tell, only used for
|
|
|
|
// the animated cut-scenes, so this seems like a good place to close
|
|
|
|
// both of them.
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_sound->closeFx(-1);
|
|
|
|
_vm->_sound->closeFx(-2);
|
2003-10-02 07:01:12 +00:00
|
|
|
|
2003-09-23 06:31:13 +00:00
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword2
|