2005-01-17 10:57:15 +00:00
|
|
|
/* Copyright (C) 1994-1998 Revolution Software Ltd.
|
|
|
|
* Copyright (C) 2003-2005 The ScummVM project
|
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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-07-28 01:44:38 +00:00
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2003-07-28 01:44:38 +00:00
|
|
|
// A more intelligent version of the old ANIMS.C
|
|
|
|
// All this stuff by James
|
|
|
|
// DON'T TOUCH!
|
2003-09-19 06:41:41 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "common/stdafx.h"
|
|
|
|
#include "common/file.h"
|
2005-02-19 14:02:16 +00:00
|
|
|
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/sword2.h"
|
|
|
|
#include "sword2/defs.h"
|
2005-02-19 14:02:16 +00:00
|
|
|
#include "sword2/build_display.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/interpreter.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/logic.h"
|
|
|
|
#include "sword2/maketext.h"
|
|
|
|
#include "sword2/resman.h"
|
2005-05-12 06:30:16 +00:00
|
|
|
#include "sword2/router.h"
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
#include "sword2/sound.h"
|
2004-01-13 14:22:29 +00:00
|
|
|
#include "sword2/driver/animation.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2005-05-12 06:30:16 +00:00
|
|
|
int Router::doAnimate(ObjectLogic *ob_logic, ObjectGraphic *ob_graphic, int32 animRes, bool reverse) {
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *anim_file;
|
2003-12-28 15:08:12 +00:00
|
|
|
AnimHeader *anim_head;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
if (ob_logic->looping == 0) {
|
2004-03-27 12:02:38 +00:00
|
|
|
StandardHeader *head;
|
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// This is the start of the anim - set up the first frame
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-06 07:32:54 +00:00
|
|
|
// For testing all anims!
|
2003-09-19 06:41:41 +00:00
|
|
|
// A script loop can send every resource number to the anim
|
|
|
|
// function & it will only run the valid ones. See
|
|
|
|
// 'testing_routines' object in George's Player Character
|
|
|
|
// section of linc
|
|
|
|
|
2005-05-12 06:30:16 +00:00
|
|
|
if (Logic::_scriptVars[SYSTEM_TESTING_ANIMS]) {
|
|
|
|
if (!_vm->_resman->checkValid(animRes)) {
|
2003-09-19 06:41:41 +00:00
|
|
|
// Not a valid resource number. Switch off
|
|
|
|
// the sprite. Don't animate - just continue
|
|
|
|
// script next cycle.
|
2005-05-12 06:30:16 +00:00
|
|
|
setSpriteStatus(ob_graphic, NO_SPRITE);
|
2003-09-19 06:41:41 +00:00
|
|
|
return IR_STOP;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 13:12:15 +00:00
|
|
|
head = (StandardHeader *)_vm->_resman->openResource(animRes);
|
2005-05-12 06:30:16 +00:00
|
|
|
|
|
|
|
// if it's not an animation file
|
|
|
|
if (head->fileType != ANIMATION_FILE) {
|
|
|
|
_vm->_resman->closeResource(animRes);
|
|
|
|
|
|
|
|
// switch off the sprite
|
|
|
|
// don't animate - just continue
|
|
|
|
// script next cycle
|
|
|
|
setSpriteStatus(ob_graphic, NO_SPRITE);
|
|
|
|
return IR_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_resman->closeResource(animRes);
|
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// switch on the sprite
|
2005-05-12 06:30:16 +00:00
|
|
|
setSpriteStatus(ob_graphic, SORT_SPRITE);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 06:30:16 +00:00
|
|
|
assert(animRes);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// open anim file
|
2005-05-12 06:30:16 +00:00
|
|
|
anim_file = _vm->_resman->openResource(animRes);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-05-12 13:12:15 +00:00
|
|
|
head = (StandardHeader *)anim_file;
|
2004-03-27 12:02:38 +00:00
|
|
|
assert(head->fileType == ANIMATION_FILE);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// point to anim header
|
2003-11-08 15:47:51 +00:00
|
|
|
anim_head = _vm->fetchAnimHeader(anim_file);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-05-12 06:30:16 +00:00
|
|
|
// now running an anim, looping back to this call again
|
2003-09-19 06:41:41 +00:00
|
|
|
ob_logic->looping = 1;
|
2005-05-12 06:30:16 +00:00
|
|
|
ob_graphic->anim_resource = animRes;
|
2003-09-19 06:41:41 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
if (reverse)
|
2003-09-19 06:41:41 +00:00
|
|
|
ob_graphic->anim_pc = anim_head->noAnimFrames - 1;
|
|
|
|
else
|
|
|
|
ob_graphic->anim_pc = 0;
|
2005-05-12 06:30:16 +00:00
|
|
|
} else if (_vm->_logic->getSync() != -1) {
|
2003-09-19 06:41:41 +00:00
|
|
|
// We've received a sync - return to script immediately
|
2005-05-12 06:30:16 +00:00
|
|
|
debug(5, "**sync stopped %d**", Logic::_scriptVars[ID]);
|
2003-09-19 06:41:41 +00:00
|
|
|
|
|
|
|
// If sync received, anim finishes right now (remaining on
|
|
|
|
// last frame). Quit animation, but continue script.
|
|
|
|
ob_logic->looping = 0;
|
|
|
|
return IR_CONT;
|
|
|
|
} else {
|
|
|
|
// Not first frame, and no sync received - set up the next
|
|
|
|
// frame of the anim.
|
|
|
|
|
|
|
|
// open anim file and point to anim header
|
2003-11-16 14:18:29 +00:00
|
|
|
anim_file = _vm->_resman->openResource(ob_graphic->anim_resource);
|
2003-11-08 15:47:51 +00:00
|
|
|
anim_head = _vm->fetchAnimHeader(anim_file);
|
2003-09-19 06:41:41 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
if (reverse)
|
2003-09-19 06:41:41 +00:00
|
|
|
ob_graphic->anim_pc--;
|
|
|
|
else
|
|
|
|
ob_graphic->anim_pc++;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 06:41:41 +00:00
|
|
|
|
2003-07-28 01:44:38 +00:00
|
|
|
// check for end of anim
|
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
if (reverse) {
|
2003-09-19 06:41:41 +00:00
|
|
|
if (ob_graphic->anim_pc == 0)
|
|
|
|
ob_logic->looping = 0;
|
|
|
|
} else {
|
2005-05-12 06:30:16 +00:00
|
|
|
if (ob_graphic->anim_pc == anim_head->noAnimFrames - 1)
|
2003-09-19 06:41:41 +00:00
|
|
|
ob_logic->looping = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// close the anim file
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_resman->closeResource(ob_graphic->anim_resource);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// check if we want the script to loop back & call this function again
|
2003-09-19 06:41:41 +00:00
|
|
|
return ob_logic->looping ? IR_REPEAT : IR_STOP;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 06:41:41 +00:00
|
|
|
|
2005-05-12 06:30:16 +00:00
|
|
|
int Router::megaTableAnimate(ObjectLogic *ob_logic, ObjectGraphic *ob_graph, ObjectMega *ob_mega, uint32 *animTable, bool reverse) {
|
|
|
|
int32 animRes = 0;
|
2004-03-27 12:02:38 +00:00
|
|
|
|
|
|
|
// If this is the start of the anim, read the anim table to get the
|
2003-09-19 06:41:41 +00:00
|
|
|
// appropriate anim resource
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
if (ob_logic->looping == 0) {
|
2005-05-12 06:30:16 +00:00
|
|
|
// Appropriate anim resource is in 'table[direction]'
|
|
|
|
animRes = animTable[ob_mega->current_dir];
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 06:30:16 +00:00
|
|
|
return doAnimate(ob_logic, ob_graph, animRes, reverse);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 06:41:41 +00:00
|
|
|
|
2005-05-12 06:30:16 +00:00
|
|
|
void Router::setSpriteStatus(ObjectGraphic *ob_graph, uint32 type) {
|
2004-03-27 12:02:38 +00:00
|
|
|
// Remove the previous status, but don't affect the shading upper-word
|
2005-05-12 06:30:16 +00:00
|
|
|
ob_graph->type = (ob_graph->type & 0xffff0000) | type;
|
2004-03-27 12:02:38 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 06:30:16 +00:00
|
|
|
void Router::setSpriteShading(ObjectGraphic *ob_graph, uint32 type) {
|
2004-03-27 12:02:38 +00:00
|
|
|
// Remove the previous shading, but don't affect the status lower-word.
|
2005-05-12 06:30:16 +00:00
|
|
|
// Note that mega frames may still be shaded automatically, even when
|
|
|
|
// not sent 'RDSPR_SHADOW'.
|
|
|
|
ob_graph->type = (ob_graph->type & 0x0000ffff) | type;
|
2004-03-27 12:02:38 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
void Logic::createSequenceSpeech(MovieTextObject *sequenceText[]) {
|
2003-09-19 06:41:41 +00:00
|
|
|
uint32 line;
|
2003-12-28 15:08:12 +00:00
|
|
|
FrameHeader *frame;
|
2003-09-19 06:41:41 +00:00
|
|
|
uint32 local_text;
|
|
|
|
uint32 text_res;
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *text;
|
2003-09-22 06:36:38 +00:00
|
|
|
uint32 wavId; // ie. offical text number (actor text number)
|
2003-11-01 16:55:20 +00:00
|
|
|
bool speechRunning;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// for each sequence text line that's been logged
|
2003-11-01 16:55:20 +00:00
|
|
|
for (line = 0; line < _sequenceTextLines; line++) {
|
2003-09-19 06:41:41 +00:00
|
|
|
// allocate this structure
|
2003-12-28 15:08:12 +00:00
|
|
|
sequenceText[line] = new MovieTextObject;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
sequenceText[line]->startFrame = _sequenceTextList[line].startFrame;
|
|
|
|
sequenceText[line]->endFrame = _sequenceTextList[line].endFrame;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// pull out the text line to get the official text number
|
|
|
|
// (for wav id)
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
text_res = _sequenceTextList[line].textNumber / SIZE;
|
|
|
|
local_text = _sequenceTextList[line].textNumber & 0xffff;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// open text resource & get the line
|
2003-11-16 14:18:29 +00:00
|
|
|
text = _vm->fetchTextLine(_vm->_resman->openResource(text_res), local_text);
|
2003-09-19 06:41:41 +00:00
|
|
|
wavId = (int32) READ_LE_UINT16(text);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// now ok to close the text file
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_resman->closeResource(text_res);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// 1st word of text line is the official line number
|
2003-10-12 13:04:46 +00:00
|
|
|
debug(5,"(%d) SEQUENCE TEXT: %s", READ_LE_UINT16(text), text + 2);
|
2003-09-19 06:41:41 +00:00
|
|
|
|
2003-07-28 01:44:38 +00:00
|
|
|
// is it to be speech or subtitles or both?
|
2003-09-19 06:41:41 +00:00
|
|
|
// assume speech is not running until know otherwise
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
speechRunning = false;
|
|
|
|
_sequenceTextList[line].speech_mem = NULL;
|
2003-09-19 06:41:41 +00:00
|
|
|
sequenceText[line]->speech = NULL;
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
if (!_vm->_sound->isSpeechMute()) {
|
2004-08-22 14:28:11 +00:00
|
|
|
_sequenceTextList[line].speechBufferSize = _vm->_sound->preFetchCompSpeech(wavId, &_sequenceTextList[line].speech_mem);
|
2003-11-01 16:55:20 +00:00
|
|
|
if (_sequenceTextList[line].speechBufferSize) {
|
2003-09-22 06:36:38 +00:00
|
|
|
// ok, we've got speech!
|
2003-11-01 16:55:20 +00:00
|
|
|
speechRunning = true;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// if we want subtitles, or speech failed to load
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-02-20 15:38:48 +00:00
|
|
|
if (_vm->getSubtitles() || !speechRunning) {
|
2003-09-19 06:41:41 +00:00
|
|
|
// open text resource & get the line
|
2003-11-16 14:18:29 +00:00
|
|
|
text = _vm->fetchTextLine(_vm->_resman->openResource(text_res), local_text);
|
2003-09-19 06:41:41 +00:00
|
|
|
// make the sprite
|
|
|
|
// 'text+2' to skip the first 2 bytes which form the
|
|
|
|
// line reference number
|
|
|
|
|
|
|
|
// NB. The mem block containing the text sprite is
|
|
|
|
// currently FLOATING!
|
|
|
|
|
2003-10-11 12:26:53 +00:00
|
|
|
// When rendering text over a sequence we need a
|
|
|
|
// different colour for the border.
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_sequenceTextList[line].text_mem = _vm->_fontRenderer->makeTextSprite(text + 2, 600, 255, _vm->_speechFontId, 1);
|
2003-09-19 06:41:41 +00:00
|
|
|
|
|
|
|
// ok to close the text resource now
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_resman->closeResource(text_res);
|
2003-09-19 06:41:41 +00:00
|
|
|
} else {
|
2003-11-01 16:55:20 +00:00
|
|
|
_sequenceTextList[line].text_mem = NULL;
|
2003-09-19 06:41:41 +00:00
|
|
|
sequenceText[line]->textSprite = NULL;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// for drivers: NULL-terminate the array of pointers to
|
2003-12-28 15:08:12 +00:00
|
|
|
// MovieTextObject's
|
2003-11-01 16:55:20 +00:00
|
|
|
sequenceText[_sequenceTextLines] = NULL;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
for (line = 0; line < _sequenceTextLines; line++) {
|
2003-09-19 06:41:41 +00:00
|
|
|
// if we've made a text sprite for this line...
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
if (_sequenceTextList[line].text_mem) {
|
2003-12-28 15:08:12 +00:00
|
|
|
// now fill out the SpriteInfo structure in the
|
|
|
|
// MovieTextObjectStructure
|
2003-09-19 06:41:41 +00:00
|
|
|
|
2005-05-12 13:12:15 +00:00
|
|
|
frame = (FrameHeader *)_sequenceTextList[line].text_mem;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
sequenceText[line]->textSprite = new SpriteInfo;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// center text at bottom of screen
|
|
|
|
sequenceText[line]->textSprite->x = 320 - frame->width / 2;
|
|
|
|
sequenceText[line]->textSprite->y = 440 - frame->height;
|
|
|
|
sequenceText[line]->textSprite->w = frame->width;
|
|
|
|
sequenceText[line]->textSprite->h = frame->height;
|
|
|
|
sequenceText[line]->textSprite->type = RDSPR_DISPLAYALIGN | RDSPR_NOCOMPRESSION;
|
2004-04-23 07:02:11 +00:00
|
|
|
sequenceText[line]->textSprite->data = _sequenceTextList[line].text_mem + sizeof(FrameHeader);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// if we've loaded a speech sample for this line...
|
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
if (_sequenceTextList[line].speech_mem) {
|
2003-09-19 06:41:41 +00:00
|
|
|
// for drivers: set up pointer to decompressed wav in
|
|
|
|
// memory
|
|
|
|
|
2003-11-01 16:55:20 +00:00
|
|
|
sequenceText[line]->speechBufferSize = _sequenceTextList[line].speechBufferSize;
|
|
|
|
sequenceText[line]->speech = _sequenceTextList[line].speech_mem;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
void Logic::clearSequenceSpeech(MovieTextObject *sequenceText[]) {
|
2004-04-23 07:02:11 +00:00
|
|
|
for (uint i = 0; i < _sequenceTextLines; i++) {
|
2003-12-28 15:08:12 +00:00
|
|
|
// free up the memory used by this MovieTextObject
|
2004-04-23 07:02:11 +00:00
|
|
|
delete sequenceText[i];
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// free up the mem block containing this text sprite
|
2004-04-23 07:02:11 +00:00
|
|
|
if (_sequenceTextList[i].text_mem)
|
|
|
|
free(_sequenceTextList[i].text_mem);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// free up the mem block containing this speech sample
|
2004-04-23 07:02:11 +00:00
|
|
|
if (_sequenceTextList[i].speech_mem)
|
|
|
|
free(_sequenceTextList[i].speech_mem);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-19 06:41:41 +00:00
|
|
|
// IMPORTANT! Reset the line count ready for the next sequence!
|
2003-11-01 16:55:20 +00:00
|
|
|
_sequenceTextLines = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 06:41:41 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
} // End of namespace Sword2
|