2004-04-12 21:40:49 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2004 The ScummVM project
|
|
|
|
*
|
|
|
|
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
|
|
|
|
*
|
|
|
|
* 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$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Event management module
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
|
|
|
#include "saga/gfx.h"
|
|
|
|
|
|
|
|
#include "saga/yslib.h"
|
|
|
|
|
|
|
|
#include "saga/animation.h"
|
2004-08-10 18:31:33 +00:00
|
|
|
#include "saga/console.h"
|
2004-08-04 20:28:57 +00:00
|
|
|
#include "saga/scene.h"
|
2004-08-06 01:39:17 +00:00
|
|
|
#include "saga/interface.h"
|
2004-08-03 00:40:16 +00:00
|
|
|
#include "saga/text.h"
|
2004-08-10 19:20:33 +00:00
|
|
|
#include "saga/palanim.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/render.h"
|
|
|
|
#include "saga/game_mod.h"
|
|
|
|
#include "saga/sndres.h"
|
|
|
|
#include "saga/music.h"
|
|
|
|
|
|
|
|
#include "saga/events.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
namespace Saga {
|
|
|
|
|
2004-08-10 19:00:30 +00:00
|
|
|
Events::Events(SagaEngine *vm) : _vm(vm), _initialized(false) {
|
2004-05-05 13:05:45 +00:00
|
|
|
debug(0, "Initializing event subsystem...");
|
2004-08-10 19:00:30 +00:00
|
|
|
_eventList = ys_dll_create();
|
|
|
|
|
|
|
|
if (_eventList)
|
|
|
|
_initialized = true;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-10 19:00:30 +00:00
|
|
|
Events::~Events(void) {
|
2004-05-05 13:05:45 +00:00
|
|
|
debug(0, "Shutting down event subsystem...");
|
2004-08-10 19:00:30 +00:00
|
|
|
freeList();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Function to process event list once per frame.
|
|
|
|
// First advances event times, then processes each event with the appropriate
|
|
|
|
// handler depending on the type of event.
|
2004-08-10 19:00:30 +00:00
|
|
|
int Events::handleEvents(long msec) {
|
2004-04-12 21:40:49 +00:00
|
|
|
YS_DL_NODE *walk_node;
|
|
|
|
YS_DL_NODE *next_node;
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
EVENT *event_p;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
long delta_time;
|
|
|
|
int result;
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Advance event times
|
2004-08-10 19:00:30 +00:00
|
|
|
processEventTime(msec);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Process each event in list
|
2004-08-10 19:00:30 +00:00
|
|
|
for (walk_node = ys_dll_head(_eventList); walk_node != NULL; walk_node = next_node) {
|
2004-10-27 21:32:28 +00:00
|
|
|
event_p = (EVENT *)ys_dll_get_data(walk_node);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Save next event in case current event is handled and removed
|
2004-04-12 21:40:49 +00:00
|
|
|
next_node = ys_dll_next(walk_node);
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Call the appropriate event handler for the specific event type
|
2004-04-12 21:40:49 +00:00
|
|
|
switch (event_p->type) {
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
case ONESHOT_EVENT:
|
2004-08-10 19:00:30 +00:00
|
|
|
result = handleOneShot(event_p);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
case CONTINUOUS_EVENT:
|
2004-08-10 19:00:30 +00:00
|
|
|
result = handleContinuous(event_p);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
case INTERVAL_EVENT:
|
2004-08-10 19:00:30 +00:00
|
|
|
result = handleInterval(event_p);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
case IMMEDIATE_EVENT:
|
2004-08-11 22:27:39 +00:00
|
|
|
result = handleImmediate(event_p);
|
|
|
|
break;
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
default:
|
2004-10-27 21:32:28 +00:00
|
|
|
result = EVENT_INVALIDCODE;
|
2004-05-05 13:05:45 +00:00
|
|
|
warning("Invalid event code encountered");
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Process the event appropriately based on result code from
|
|
|
|
// handler
|
2004-10-27 21:32:28 +00:00
|
|
|
if ((result == EVENT_DELETE) || (result == EVENT_INVALIDCODE)) {
|
2004-05-01 06:50:20 +00:00
|
|
|
// If there is no event chain, delete the base event.
|
2004-04-12 21:40:49 +00:00
|
|
|
if (event_p->chain == NULL) {
|
|
|
|
ys_dll_delete(walk_node);
|
|
|
|
} else {
|
2004-05-01 06:50:20 +00:00
|
|
|
// If there is an event chain present, move the next event
|
|
|
|
// in the chain up, adjust it by the previous delta time,
|
|
|
|
// and reprocess the event by adjusting next_node. */
|
2004-04-12 21:40:49 +00:00
|
|
|
delta_time = event_p->time;
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
ys_dll_replace(walk_node, event_p->chain, sizeof *event_p);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
event_p = (EVENT *)ys_dll_get_data(walk_node);
|
2004-04-12 21:40:49 +00:00
|
|
|
event_p->time += delta_time;
|
|
|
|
|
|
|
|
next_node = walk_node;
|
|
|
|
}
|
2004-10-27 21:32:28 +00:00
|
|
|
} else if (result == EVENT_BREAK) {
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-05-01 06:50:20 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
int Events::handleContinuous(EVENT *event) {
|
2004-05-01 06:50:20 +00:00
|
|
|
double event_pc = 0.0; // Event completion percentage
|
2004-04-12 21:40:49 +00:00
|
|
|
int event_done = 0;
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
BUFFER_INFO buf_info;
|
2004-04-12 21:40:49 +00:00
|
|
|
SCENE_BGINFO bg_info;
|
2004-10-27 21:32:28 +00:00
|
|
|
SURFACE *back_buf;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
event_pc = ((double)event->duration - event->time) / event->duration;
|
|
|
|
|
|
|
|
if (event_pc >= 1.0) {
|
2004-05-01 06:50:20 +00:00
|
|
|
// Cap percentage to 100
|
2004-04-12 21:40:49 +00:00
|
|
|
event_pc = 1.0;
|
|
|
|
event_done = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event_pc < 0.0) {
|
2004-05-01 06:50:20 +00:00
|
|
|
// Event not signaled, skip it
|
2004-10-27 21:32:28 +00:00
|
|
|
return EVENT_CONTINUE;
|
|
|
|
} else if (!(event->code & SIGNALED)) {
|
2004-05-01 06:50:20 +00:00
|
|
|
// Signal event
|
2004-10-27 21:32:28 +00:00
|
|
|
event->code |= SIGNALED;
|
2004-04-12 21:40:49 +00:00
|
|
|
event_pc = 0.0;
|
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
switch (event->code & EVENT_MASK) {
|
|
|
|
case PAL_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
switch (event->op) {
|
|
|
|
case EVENT_BLACKTOPAL:
|
2004-08-01 11:48:53 +00:00
|
|
|
back_buf = _vm->_gfx->getBackBuffer();
|
|
|
|
_vm->_gfx->blackToPal(back_buf, (PALENTRY *)event->data, event_pc);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_PALTOBLACK:
|
2004-08-01 11:48:53 +00:00
|
|
|
back_buf = _vm->_gfx->getBackBuffer();
|
|
|
|
_vm->_gfx->palToBlack(back_buf, (PALENTRY *)event->data, event_pc);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2004-05-01 06:50:20 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case TRANSITION_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
switch (event->op) {
|
|
|
|
case EVENT_DISSOLVE:
|
2004-07-31 23:00:48 +00:00
|
|
|
_vm->_render->getBufferInfo(&buf_info);
|
2004-08-04 20:28:57 +00:00
|
|
|
_vm->_scene->getBGInfo(&bg_info);
|
2004-10-27 21:32:28 +00:00
|
|
|
_vm->transitionDissolve(buf_info.bg_buf, buf_info.bg_buf_w,
|
|
|
|
buf_info.bg_buf_h, buf_info.bg_buf_w, bg_info.bg_buf, bg_info.bg_w,
|
2004-08-11 14:04:12 +00:00
|
|
|
bg_info.bg_h, bg_info.bg_p, 0, 0, 0, event_pc);
|
2004-08-10 23:04:52 +00:00
|
|
|
break;
|
|
|
|
case EVENT_DISSOLVE_BGMASK:
|
|
|
|
// we dissolve it centered.
|
|
|
|
// set flag of Dissolve to 1. It is a hack to simulate zero masking.
|
|
|
|
int w, h;
|
|
|
|
byte *mask_buf;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
_vm->_render->getBufferInfo(&buf_info);
|
|
|
|
_vm->_scene->getBGMaskInfo(&w, &h, &mask_buf, &len);
|
2004-10-27 21:32:28 +00:00
|
|
|
_vm->transitionDissolve(buf_info.bg_buf, buf_info.bg_buf_w,
|
|
|
|
buf_info.bg_buf_h, buf_info.bg_buf_w, mask_buf, w, h, 0, 1,
|
2004-08-11 14:04:12 +00:00
|
|
|
(320 - w) / 2, (200 - h) / 2, event_pc);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case CONSOLE_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
switch (event->op) {
|
|
|
|
case EVENT_ACTIVATE:
|
2004-08-10 18:31:33 +00:00
|
|
|
_vm->_console->dropConsole(event_pc);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
case EVENT_DEACTIVATE:
|
2004-08-10 18:31:33 +00:00
|
|
|
_vm->_console->raiseConsole(event_pc);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
if (event_done) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return EVENT_DELETE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return EVENT_CONTINUE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
int Events::handleImmediate(EVENT *event) {
|
2004-08-11 22:27:39 +00:00
|
|
|
double event_pc = 0.0; // Event completion percentage
|
|
|
|
bool event_done = false;
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
SURFACE *back_buf;
|
2004-08-11 22:27:39 +00:00
|
|
|
|
|
|
|
event_pc = ((double)event->duration - event->time) / event->duration;
|
|
|
|
|
|
|
|
if (event_pc >= 1.0) {
|
|
|
|
// Cap percentage to 100
|
|
|
|
event_pc = 1.0;
|
|
|
|
event_done = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event_pc < 0.0) {
|
|
|
|
// Event not signaled, skip it
|
2004-10-27 21:32:28 +00:00
|
|
|
return EVENT_BREAK;
|
|
|
|
} else if (!(event->code & SIGNALED)) {
|
2004-08-11 22:27:39 +00:00
|
|
|
// Signal event
|
2004-10-27 21:32:28 +00:00
|
|
|
event->code |= SIGNALED;
|
2004-08-11 22:27:39 +00:00
|
|
|
event_pc = 0.0;
|
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
switch (event->code & EVENT_MASK) {
|
|
|
|
case PAL_EVENT:
|
2004-08-11 22:27:39 +00:00
|
|
|
switch (event->op) {
|
|
|
|
case EVENT_BLACKTOPAL:
|
|
|
|
back_buf = _vm->_gfx->getBackBuffer();
|
|
|
|
_vm->_gfx->blackToPal(back_buf, (PALENTRY *)event->data, event_pc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_PALTOBLACK:
|
|
|
|
back_buf = _vm->_gfx->getBackBuffer();
|
|
|
|
_vm->_gfx->palToBlack(back_buf, (PALENTRY *)event->data, event_pc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case SCRIPT_EVENT:
|
|
|
|
case BG_EVENT:
|
|
|
|
case INTERFACE_EVENT:
|
2004-08-11 22:27:39 +00:00
|
|
|
handleOneShot(event);
|
|
|
|
event_done = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event_done) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return EVENT_DELETE;
|
2004-08-11 22:27:39 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return EVENT_BREAK;
|
2004-08-11 22:27:39 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
int Events::handleOneShot(EVENT *event) {
|
|
|
|
SURFACE *back_buf;
|
|
|
|
SCRIPT_THREAD *sthread;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
static SCENE_BGINFO bginfo;
|
|
|
|
|
|
|
|
if (event->time > 0) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return EVENT_CONTINUE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Event has been signaled
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
switch (event->code & EVENT_MASK) {
|
|
|
|
case TEXT_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
switch (event->op) {
|
|
|
|
case EVENT_DISPLAY:
|
2004-10-27 21:32:28 +00:00
|
|
|
_vm->textSetDisplay((TEXTLIST_ENTRY *)event->data, 1);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
case EVENT_REMOVE:
|
|
|
|
{
|
2004-10-27 21:32:28 +00:00
|
|
|
SCENE_INFO scene_info;
|
2004-08-04 20:28:57 +00:00
|
|
|
_vm->_scene->getInfo(&scene_info);
|
2004-10-27 21:32:28 +00:00
|
|
|
_vm->textDeleteEntry(scene_info.text_list, (TEXTLIST_ENTRY *)event->data);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case VOICE_EVENT:
|
2004-04-28 23:19:45 +00:00
|
|
|
_vm->_sndRes->playVoice(event->param);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case MUSIC_EVENT:
|
2004-10-16 07:46:52 +00:00
|
|
|
_vm->_music->stop();
|
|
|
|
if (event->op == EVENT_PLAY)
|
|
|
|
_vm->_music->play(event->param, event->param2);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case BG_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
{
|
2004-10-27 21:32:28 +00:00
|
|
|
BUFFER_INFO rbuf_info;
|
2004-10-04 23:09:38 +00:00
|
|
|
Point bg_pt;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
if (_vm->_scene->getMode() == SCENE_MODE_NORMAL) {
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-01 11:48:53 +00:00
|
|
|
back_buf = _vm->_gfx->getBackBuffer();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
_vm->_render->getBufferInfo(&rbuf_info);
|
2004-08-04 20:28:57 +00:00
|
|
|
_vm->_scene->getBGInfo(&bginfo);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
bg_pt.x = bginfo.bg_x;
|
|
|
|
bg_pt.y = bginfo.bg_y;
|
|
|
|
|
2004-10-30 22:34:08 +00:00
|
|
|
bufToBuffer(rbuf_info.bg_buf, rbuf_info.bg_buf_w, rbuf_info.bg_buf_h,
|
2004-05-01 06:50:20 +00:00
|
|
|
bginfo.bg_buf, bginfo.bg_w, bginfo.bg_h, NULL, &bg_pt);
|
2004-04-12 21:40:49 +00:00
|
|
|
if (event->param == SET_PALETTE) {
|
|
|
|
PALENTRY *pal_p;
|
2004-08-04 20:28:57 +00:00
|
|
|
_vm->_scene->getBGPal(&pal_p);
|
2004-08-01 11:48:53 +00:00
|
|
|
_vm->_gfx->setPalette(back_buf, pal_p);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case ANIM_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
switch (event->op) {
|
|
|
|
case EVENT_FRAME:
|
2004-07-31 13:34:43 +00:00
|
|
|
_vm->_anim->play(event->param, event->time);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2004-08-10 23:04:52 +00:00
|
|
|
case EVENT_SETFLAG:
|
|
|
|
_vm->_anim->setFlag(event->param, event->param2);
|
|
|
|
break;
|
|
|
|
case EVENT_CLEARFLAG:
|
|
|
|
_vm->_anim->clearFlag(event->param, event->param2);
|
|
|
|
break;
|
2004-04-12 21:40:49 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case SCENE_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
switch (event->op) {
|
|
|
|
case EVENT_END:
|
2004-08-04 20:28:57 +00:00
|
|
|
_vm->_scene->nextScene();
|
2004-10-27 21:32:28 +00:00
|
|
|
return EVENT_BREAK;
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case PALANIM_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
switch (event->op) {
|
|
|
|
case EVENT_CYCLESTART:
|
2004-08-10 19:20:33 +00:00
|
|
|
_vm->_palanim->cycleStart();
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
case EVENT_CYCLESTEP:
|
2004-08-10 19:20:33 +00:00
|
|
|
_vm->_palanim->cycleStep(event->time);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case INTERFACE_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
switch (event->op) {
|
|
|
|
case EVENT_ACTIVATE:
|
2004-08-06 01:39:17 +00:00
|
|
|
_vm->_interface->activate();
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-10-16 07:46:52 +00:00
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case SCRIPT_EVENT:
|
2004-10-16 07:46:52 +00:00
|
|
|
debug(0, "Starting start script #%d", event->param);
|
|
|
|
|
|
|
|
sthread = _vm->_script->SThreadCreate();
|
|
|
|
if (sthread == NULL) {
|
|
|
|
_vm->_console->print("Thread creation failed.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sthread->threadVars[kVarAction] = TO_LE_16(event->param2);
|
|
|
|
sthread->threadVars[kVarObject] = TO_LE_16(event->param3);
|
|
|
|
sthread->threadVars[kVarWithObject] = TO_LE_16(event->param4);
|
|
|
|
sthread->threadVars[kVarActor] = TO_LE_16(event->param5);
|
|
|
|
|
|
|
|
_vm->_script->SThreadExecute(sthread, event->param);
|
|
|
|
|
|
|
|
if (event->op == EVENT_BLOCKING)
|
|
|
|
_vm->_script->SThreadCompleteThread();
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2004-05-01 06:50:20 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return EVENT_DELETE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
int Events::handleInterval(EVENT *event) {
|
|
|
|
return EVENT_DELETE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Schedules an event in the event list; returns a pointer to the scheduled
|
|
|
|
// event suitable for chaining if desired.
|
2004-10-27 21:32:28 +00:00
|
|
|
EVENT *Events::queue(EVENT *event) {
|
2004-04-12 21:40:49 +00:00
|
|
|
YS_DL_NODE *new_node;
|
2004-10-27 21:32:28 +00:00
|
|
|
EVENT *queued_event;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
event->chain = NULL;
|
2004-08-10 19:00:30 +00:00
|
|
|
new_node = ys_dll_add_tail(_eventList, event, sizeof *event);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
if (new_node == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
queued_event = (EVENT *)ys_dll_get_data(new_node);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:00:30 +00:00
|
|
|
initializeEvent(queued_event);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
return queued_event;
|
|
|
|
}
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Places a 'add_event' on the end of an event chain given by 'head_event'
|
|
|
|
// (head_event may be in any position in the event chain)
|
2004-10-27 21:32:28 +00:00
|
|
|
EVENT *Events::chain(EVENT *head_event, EVENT *add_event) {
|
|
|
|
EVENT *walk_event;
|
|
|
|
EVENT *new_event;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Allocate space for new event
|
2004-10-27 21:32:28 +00:00
|
|
|
new_event = (EVENT *)malloc(sizeof *new_event);
|
2004-04-12 21:40:49 +00:00
|
|
|
if (new_event == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Copy event data to new event
|
2004-04-12 21:40:49 +00:00
|
|
|
*new_event = *add_event;
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Walk to end of chain
|
|
|
|
for (walk_event = head_event; walk_event->chain != NULL; walk_event = walk_event->chain) {
|
2004-04-12 21:40:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Place new event
|
2004-04-12 21:40:49 +00:00
|
|
|
walk_event->chain = new_event;
|
|
|
|
new_event->chain = NULL;
|
2004-08-10 19:00:30 +00:00
|
|
|
initializeEvent(new_event);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
return new_event;
|
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
int Events::initializeEvent(EVENT *event) {
|
2004-04-12 21:40:49 +00:00
|
|
|
switch (event->type) {
|
2004-10-27 21:32:28 +00:00
|
|
|
case ONESHOT_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case CONTINUOUS_EVENT:
|
|
|
|
case IMMEDIATE_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
event->time += event->duration;
|
|
|
|
break;
|
2004-10-27 21:32:28 +00:00
|
|
|
case INTERVAL_EVENT:
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-10-27 21:32:28 +00:00
|
|
|
return FAILURE;
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-10 19:00:30 +00:00
|
|
|
int Events::clearList() {
|
2004-04-12 21:40:49 +00:00
|
|
|
YS_DL_NODE *walk_node;
|
|
|
|
YS_DL_NODE *next_node;
|
2004-10-27 21:32:28 +00:00
|
|
|
EVENT *chain_walk;
|
|
|
|
EVENT *next_chain;
|
|
|
|
EVENT *event_p;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Walk down event list
|
2004-08-10 19:00:30 +00:00
|
|
|
for (walk_node = ys_dll_head(_eventList); walk_node != NULL; walk_node = next_node) {
|
2004-04-12 21:40:49 +00:00
|
|
|
next_node = ys_dll_next(walk_node);
|
2004-10-27 21:32:28 +00:00
|
|
|
event_p = (EVENT *)ys_dll_get_data(walk_node);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
// Only remove events not marked NODESTROY (engine events)
|
|
|
|
if (!(event_p->code & NODESTROY)) {
|
2004-05-01 06:50:20 +00:00
|
|
|
// Remove any events chained off this one */
|
|
|
|
for (chain_walk = event_p->chain; chain_walk != NULL; chain_walk = next_chain) {
|
2004-04-12 21:40:49 +00:00
|
|
|
next_chain = chain_walk->chain;
|
|
|
|
free(chain_walk);
|
|
|
|
}
|
|
|
|
ys_dll_delete(walk_node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
// Removes all events from the list (even NODESTROY)
|
2004-08-10 19:00:30 +00:00
|
|
|
int Events::freeList() {
|
2004-04-12 21:40:49 +00:00
|
|
|
YS_DL_NODE *walk_node;
|
|
|
|
YS_DL_NODE *next_node;
|
2004-10-27 21:32:28 +00:00
|
|
|
EVENT *chain_walk;
|
|
|
|
EVENT *next_chain;
|
|
|
|
EVENT *event_p;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Walk down event list
|
2004-08-10 19:00:30 +00:00
|
|
|
for (walk_node = ys_dll_head(_eventList); walk_node != NULL; walk_node = next_node) {
|
2004-10-27 21:32:28 +00:00
|
|
|
event_p = (EVENT *)ys_dll_get_data(walk_node);
|
2004-05-01 06:50:20 +00:00
|
|
|
// Remove any events chained off current node
|
|
|
|
for (chain_walk = event_p->chain; chain_walk != NULL; chain_walk = next_chain) {
|
2004-04-12 21:40:49 +00:00
|
|
|
next_chain = chain_walk->chain;
|
|
|
|
free(chain_walk);
|
|
|
|
}
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Delete current node
|
2004-04-12 21:40:49 +00:00
|
|
|
next_node = ys_dll_next(walk_node);
|
|
|
|
ys_dll_delete(walk_node);
|
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 06:50:20 +00:00
|
|
|
// Walks down the event list, updating event times by 'msec'.
|
2004-08-10 19:00:30 +00:00
|
|
|
int Events::processEventTime(long msec) {
|
2004-04-12 21:40:49 +00:00
|
|
|
YS_DL_NODE *walk_node;
|
2004-10-27 21:32:28 +00:00
|
|
|
EVENT *event_p;
|
2004-04-30 23:02:23 +00:00
|
|
|
uint16 event_count = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:00:30 +00:00
|
|
|
for (walk_node = ys_dll_head(_eventList); walk_node != NULL; walk_node = ys_dll_next(walk_node)) {
|
2004-10-27 21:32:28 +00:00
|
|
|
event_p = (EVENT *)ys_dll_get_data(walk_node);
|
2004-04-12 21:40:49 +00:00
|
|
|
event_p->time -= msec;
|
|
|
|
event_count++;
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
if (event_p->type == IMMEDIATE_EVENT)
|
2004-08-11 22:27:39 +00:00
|
|
|
break;
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
if (event_count > EVENT_WARNINGCOUNT) {
|
|
|
|
warning("Event list exceeds %u", EVENT_WARNINGCOUNT);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|