2003-07-28 01:47:41 +00:00
|
|
|
/* Copyright (C) 1994-2003 Revolution Software Ltd
|
|
|
|
*
|
|
|
|
* 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$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2003-07-28 03:12:49 +00:00
|
|
|
#include "stdafx.h"
|
2003-07-28 01:47:41 +00:00
|
|
|
#include "driver96.h"
|
2003-09-09 15:54:13 +00:00
|
|
|
#include "bs2/header.h" // HACK: For cutscenes instruction message
|
|
|
|
#include "bs2/maketext.h" // HACK: For cutscenes instruction message
|
2003-09-22 06:36:38 +00:00
|
|
|
#include "bs2/sword2.h"
|
|
|
|
#include "sound/mixer.h"
|
2003-07-28 01:47:41 +00:00
|
|
|
#include "rdwin.h"
|
|
|
|
#include "d_draw.h"
|
|
|
|
#include "palette.h"
|
2003-08-29 06:42:34 +00:00
|
|
|
#include "render.h"
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-08-28 06:36:15 +00:00
|
|
|
byte *lpBackBuffer;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
|
|
|
// Game screen metrics
|
2003-09-23 16:38:38 +00:00
|
|
|
int16 screenDeep;
|
|
|
|
int16 screenWide;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
|
|
|
// Scroll variables. scrollx and scrolly hold the current scroll position,
|
|
|
|
|
2003-09-27 17:41:02 +00:00
|
|
|
int16 scrollx;
|
|
|
|
int16 scrolly;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-27 17:41:02 +00:00
|
|
|
int32 renderCaps = 0;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-08-19 14:57:26 +00:00
|
|
|
int32 PlotDots(int16 x, int16 y, int16 count) {
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-07-28 02:37:47 +00:00
|
|
|
warning("stub PlotDots( %d, %d, %d )", x, y, count);
|
|
|
|
/*
|
2003-07-28 01:47:41 +00:00
|
|
|
int16 i;
|
|
|
|
uint8 *dst;
|
|
|
|
|
|
|
|
DDSURFACEDESC ddDescription;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
ddDescription.dwSize = sizeof(ddDescription);
|
|
|
|
|
|
|
|
hr = IDirectDrawSurface2_Lock(lpBackBuffer, NULL, &ddDescription, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
|
|
|
|
if (hr != DD_OK)
|
|
|
|
{
|
|
|
|
hr = IDirectDrawSurface2_Lock(lpBackBuffer, NULL, &ddDescription, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hr == DD_OK)
|
|
|
|
{
|
|
|
|
|
|
|
|
dst = (uint8 *) ddDescription.lpSurface + y * ddDescription.lPitch + x;
|
|
|
|
|
|
|
|
for (i=0; i<=count; i++)
|
|
|
|
{
|
|
|
|
*dst = 184;
|
|
|
|
dst += 2;
|
|
|
|
}
|
|
|
|
dst = (uint8 *) ddDescription.lpSurface + (y+1) * ddDescription.lPitch + x;
|
|
|
|
for (i=0; i<=count/10; i++)
|
|
|
|
{
|
|
|
|
*dst = 184;
|
|
|
|
dst += 20;
|
|
|
|
}
|
|
|
|
IDirectDrawSurface2_Unlock(lpBackBuffer, ddDescription.lpSurface);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2003-09-28 16:38:00 +00:00
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* Initialise the display with the sizes passed in.
|
|
|
|
* @return RD_OK, or an error code if the display cannot be set up.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int32 InitialiseDisplay(int16 width, int16 height) {
|
|
|
|
g_system->init_size(width, height);
|
|
|
|
|
2003-08-17 14:07:16 +00:00
|
|
|
screenWide = width;
|
|
|
|
screenDeep = height;
|
|
|
|
|
2003-08-28 06:36:15 +00:00
|
|
|
lpBackBuffer = (byte *) malloc(screenWide * screenDeep);
|
2003-09-28 14:13:57 +00:00
|
|
|
if (!lpBackBuffer)
|
|
|
|
return RDERR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-08-26 06:53:00 +00:00
|
|
|
// FIXME: Clean up this mess. I don't want to add any new flags, but some of
|
|
|
|
// them should be renamed. Or maybe we should abandon the whole renderCaps
|
|
|
|
// thing and simply check the numeric value of the graphics quality setting
|
|
|
|
// instead.
|
|
|
|
|
|
|
|
// Note that SetTransFx() actually clears a bit. That's intentional.
|
|
|
|
|
|
|
|
void SetTransFx(void) {
|
|
|
|
renderCaps &= ~RDBLTFX_ALLHARDWARE;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-08-26 06:53:00 +00:00
|
|
|
void ClearTransFx(void) {
|
|
|
|
renderCaps |= RDBLTFX_ALLHARDWARE;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* Sets the edge blend and arithmetic stretching effects.
|
|
|
|
*/
|
|
|
|
|
2003-08-26 06:53:00 +00:00
|
|
|
void SetBltFx(void) {
|
|
|
|
renderCaps |= (RDBLTFX_EDGEBLEND | RDBLTFX_ARITHMETICSTRETCH);
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* Clears the edge blend and arithmetic stretching effects.
|
|
|
|
*/
|
|
|
|
|
2003-08-26 06:53:00 +00:00
|
|
|
void ClearBltFx(void) {
|
|
|
|
renderCaps &= ~(RDBLTFX_EDGEBLEND | RDBLTFX_ARITHMETICSTRETCH);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetShadowFx(void) {
|
2003-07-28 01:47:41 +00:00
|
|
|
renderCaps |= RDBLTFX_SHADOWBLEND;
|
2003-08-26 06:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearShadowFx(void) {
|
|
|
|
renderCaps &= ~RDBLTFX_SHADOWBLEND;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
|
|
|
* @return the graphics detail setting
|
|
|
|
*/
|
|
|
|
|
|
|
|
int32 GetRenderType(void) {
|
2003-07-28 01:47:41 +00:00
|
|
|
if (renderCaps & RDBLTFX_ALLHARDWARE)
|
2003-09-28 14:13:57 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (renderCaps & (RDBLTFX_EDGEBLEND | RDBLTFX_ARITHMETICSTRETCH))
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
if (renderCaps & RDBLTFX_SHADOWBLEND)
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
return 1;
|
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-08-19 14:57:26 +00:00
|
|
|
int32 EraseBackBuffer( void ) {
|
2003-08-29 06:42:34 +00:00
|
|
|
memset(lpBackBuffer + MENUDEEP * screenWide, 0, screenWide * RENDERDEEP);
|
2003-08-28 06:36:15 +00:00
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-19 14:57:26 +00:00
|
|
|
int32 NextSmackerFrame(void) {
|
2003-07-28 01:47:41 +00:00
|
|
|
warning("stub NextSmackerFrame");
|
2003-09-28 14:13:57 +00:00
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-28 16:38:00 +00:00
|
|
|
static uint8 *textSurface = NULL;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-08-19 14:57:26 +00:00
|
|
|
void OpenTextObject(_movieTextObject *obj) {
|
2003-09-09 15:17:12 +00:00
|
|
|
if (obj->textSprite)
|
|
|
|
CreateSurface(obj->textSprite, &textSurface);
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-08-19 14:57:26 +00:00
|
|
|
void CloseTextObject(_movieTextObject *obj) {
|
2003-09-09 15:17:12 +00:00
|
|
|
if (textSurface) {
|
|
|
|
DeleteSurface(textSurface);
|
|
|
|
textSurface = 0;
|
|
|
|
}
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-08-19 14:57:26 +00:00
|
|
|
void DrawTextObject(_movieTextObject *obj) {
|
2003-09-09 15:17:12 +00:00
|
|
|
if (obj->textSprite && textSurface)
|
|
|
|
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-08-19 14:57:26 +00:00
|
|
|
int32 PlaySmacker(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];
|
|
|
|
|
|
|
|
EraseBackBuffer();
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
memset(lpBackBuffer, 0, screenWide * MENUDEEP);
|
|
|
|
|
|
|
|
uint8 msg[] = "Cutscene - Press ESC to exit";
|
|
|
|
mem *data = MakeTextSprite(msg, 640, 255, speech_font_id);
|
|
|
|
_frameHeader *frame = (_frameHeader *) data->ad;
|
|
|
|
_spriteInfo msgSprite;
|
|
|
|
uint8 *msgSurface;
|
|
|
|
|
|
|
|
msgSprite.x = screenWide / 2 - frame->width / 2;
|
|
|
|
msgSprite.y = RDMENU_MENUDEEP / 2 - frame->height / 2;
|
|
|
|
msgSprite.w = frame->width;
|
|
|
|
msgSprite.h = frame->height;
|
2003-09-14 23:42:07 +00:00
|
|
|
msgSprite.type = RDSPR_DISPLAYALIGN | RDSPR_NOCOMPRESSION | RDSPR_TRANS;
|
2003-09-09 15:54:13 +00:00
|
|
|
msgSprite.data = data->ad + sizeof(_frameHeader);
|
|
|
|
|
|
|
|
CreateSurface(&msgSprite, &msgSurface);
|
|
|
|
DrawSurface(&msgSprite, msgSurface);
|
|
|
|
DeleteSurface(msgSurface);
|
2003-09-30 14:37:42 +00:00
|
|
|
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
|
|
|
|
|
|
|
memcpy(oldPal, palCopy, 1024);
|
|
|
|
memset(tmpPal, 0, 1024);
|
|
|
|
tmpPal[255 * 4 + 0] = 255;
|
|
|
|
tmpPal[255 * 4 + 1] = 255;
|
|
|
|
tmpPal[255 * 4 + 2] = 255;
|
|
|
|
BS2_SetPalette(0, 256, tmpPal, RDPAL_INSTANT);
|
|
|
|
|
2003-09-23 06:34:19 +00:00
|
|
|
PlayingSoundHandle handle = 0;
|
2003-09-22 06:36:38 +00:00
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
bool skipCutscene = false;
|
|
|
|
|
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) {
|
|
|
|
EraseBackBuffer();
|
2003-09-09 15:17:12 +00:00
|
|
|
OpenTextObject(text[textCounter]);
|
|
|
|
DrawTextObject(text[textCounter]);
|
2003-09-22 06:36:38 +00:00
|
|
|
if (text[textCounter]->speech) {
|
|
|
|
g_sword2->_mixer->playRaw(&handle, text[textCounter]->speech, text[textCounter]->speechBufferSize, 22050, SoundMixer::FLAG_16BITS);
|
|
|
|
}
|
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-09-09 15:17:12 +00:00
|
|
|
CloseTextObject(text[textCounter]);
|
2003-09-08 17:18:38 +00:00
|
|
|
EraseBackBuffer();
|
|
|
|
textCounter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
frameCounter++;
|
|
|
|
|
|
|
|
ServiceWindows();
|
|
|
|
|
2003-09-23 15:59:52 +00:00
|
|
|
_keyboardEvent ke;
|
2003-09-08 17:18:38 +00:00
|
|
|
|
2003-09-23 15:59:52 +00:00
|
|
|
if (ReadKey(&ke) == RD_OK && ke.keycode == 27) {
|
2003-09-22 06:36:38 +00:00
|
|
|
g_sword2->_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-09-30 16:07:04 +00:00
|
|
|
g_system->delay_msecs(90);
|
2003-09-08 17:18:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-09 15:17:12 +00:00
|
|
|
CloseTextObject(text[textCounter]);
|
2003-09-09 15:54:13 +00:00
|
|
|
|
2003-09-30 16:07:04 +00:00
|
|
|
EraseBackBuffer();
|
|
|
|
SetNeedRedraw();
|
|
|
|
|
2003-09-09 15:54:13 +00:00
|
|
|
// HACK: Remove the instructions created above
|
|
|
|
ScummVM::Rect r;
|
|
|
|
|
|
|
|
memset(lpBackBuffer, 0, screenWide * MENUDEEP);
|
|
|
|
r.left = r.top = 0;
|
|
|
|
r.right = screenWide;
|
|
|
|
r.bottom = MENUDEEP;
|
|
|
|
UploadRect(&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)
|
|
|
|
g_sound->playLeadOut(musicOut);
|
2003-09-30 16:07:04 +00:00
|
|
|
|
|
|
|
BS2_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.
|
|
|
|
|
|
|
|
g_sound->closeFx(-1);
|
|
|
|
g_sound->closeFx(-2);
|
|
|
|
|
2003-09-23 06:31:13 +00:00
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|