2014-03-13 14:31:02 +01:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "illusions/illusions.h"
|
2014-03-21 17:21:55 +01:00
|
|
|
#include "illusions/abortablethread.h"
|
2014-03-20 14:16:48 +01:00
|
|
|
#include "illusions/actor.h"
|
2014-03-13 14:31:02 +01:00
|
|
|
#include "illusions/scriptman.h"
|
2014-03-13 19:55:25 +01:00
|
|
|
#include "illusions/scriptthread.h"
|
|
|
|
#include "illusions/scriptopcodes.h"
|
2014-03-22 02:32:44 +01:00
|
|
|
#include "illusions/talkthread.h"
|
2014-03-19 23:18:25 +01:00
|
|
|
#include "illusions/timerthread.h"
|
2014-03-13 14:31:02 +01:00
|
|
|
|
|
|
|
namespace Illusions {
|
|
|
|
|
|
|
|
// ActiveScenes
|
|
|
|
|
2014-03-13 19:55:25 +01:00
|
|
|
ActiveScenes::ActiveScenes() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2014-03-13 14:31:02 +01:00
|
|
|
void ActiveScenes::clear() {
|
|
|
|
_stack.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActiveScenes::push(uint32 sceneId) {
|
|
|
|
ActiveScene activeScene;
|
|
|
|
activeScene._sceneId = sceneId;
|
|
|
|
activeScene._pauseCtr = 0;
|
|
|
|
_stack.push(activeScene);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActiveScenes::pop() {
|
|
|
|
_stack.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActiveScenes::pauseActiveScene() {
|
|
|
|
++_stack.top()._pauseCtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActiveScenes::unpauseActiveScene() {
|
|
|
|
--_stack.top()._pauseCtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ActiveScenes::getActiveScenesCount() {
|
|
|
|
return _stack.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActiveScenes::getActiveSceneInfo(uint index, uint32 *sceneId, int *pauseCtr) {
|
|
|
|
if (sceneId)
|
|
|
|
*sceneId = _stack[index]._sceneId;
|
|
|
|
if (pauseCtr)
|
|
|
|
*pauseCtr = _stack[index]._pauseCtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 ActiveScenes::getCurrentScene() {
|
|
|
|
if (_stack.size() > 0)
|
|
|
|
return _stack.top()._sceneId;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ActiveScenes::isSceneActive(uint32 sceneId) {
|
|
|
|
for (uint i = 0; i < _stack.size(); ++i)
|
|
|
|
if (_stack[i]._sceneId == sceneId && _stack[i]._pauseCtr <= 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ScriptStack
|
|
|
|
|
|
|
|
ScriptStack::ScriptStack() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptStack::clear() {
|
|
|
|
for (uint i = 0; i < 256; ++i)
|
|
|
|
_stack[i] = (int16)0xEEEE;
|
|
|
|
_stackPos = 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptStack::push(int16 value) {
|
|
|
|
--_stackPos;
|
|
|
|
if (_stackPos > 0)
|
|
|
|
_stack[_stackPos] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int16 ScriptStack::pop() {
|
|
|
|
int16 value = 0;
|
|
|
|
if (_stackPos < 256) {
|
|
|
|
value = _stack[_stackPos];
|
|
|
|
_stack[_stackPos] = (int16)0xEEEE;
|
|
|
|
++_stackPos;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int16 ScriptStack::peek() {
|
|
|
|
int16 value = 0;
|
|
|
|
if (_stackPos < 256)
|
|
|
|
value = _stack[_stackPos];
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2014-03-20 14:16:48 +01:00
|
|
|
int16 *ScriptStack::topPtr() {
|
|
|
|
return &_stack[_stackPos];
|
|
|
|
}
|
|
|
|
|
2014-03-13 14:31:02 +01:00
|
|
|
// ScriptMan
|
|
|
|
|
|
|
|
ScriptMan::ScriptMan(IllusionsEngine *vm)
|
2014-03-13 19:55:25 +01:00
|
|
|
: _vm(vm), _pauseCtr(0), _doScriptThreadInit(false) {
|
|
|
|
_threads = new ThreadList(vm);
|
|
|
|
_scriptOpcodes = new ScriptOpcodes(vm);
|
2014-03-22 02:32:44 +01:00
|
|
|
_field8 = 1;
|
|
|
|
_fieldA = 0;
|
|
|
|
_fieldE = 240;
|
2014-03-13 14:31:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ScriptMan::~ScriptMan() {
|
2014-03-13 19:55:25 +01:00
|
|
|
delete _threads;
|
|
|
|
delete _scriptOpcodes;
|
2014-03-13 14:31:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptMan::setSceneIdThreadId(uint32 theSceneId, uint32 theThreadId) {
|
|
|
|
_theSceneId = theSceneId;
|
|
|
|
_theThreadId = theThreadId;
|
|
|
|
}
|
|
|
|
|
2014-03-13 19:55:25 +01:00
|
|
|
void ScriptMan::startScriptThread(uint32 threadId, uint32 callingThreadId,
|
|
|
|
uint32 value8, uint32 valueC, uint32 value10) {
|
|
|
|
debug("Starting script thread %08X", threadId);
|
|
|
|
byte *scriptCodeIp = _scriptResource->getThreadCode(threadId);
|
|
|
|
newScriptThread(threadId, callingThreadId, 0, scriptCodeIp, value8, valueC, value10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptMan::startAnonScriptThread(int32 threadId, uint32 callingThreadId,
|
|
|
|
uint32 value8, uint32 valueC, uint32 value10) {
|
|
|
|
debug("Starting anonymous script thread %08X", threadId);
|
|
|
|
uint32 tempThreadId = newTempThreadId();
|
|
|
|
byte *scriptCodeIp = _scriptResource->getThreadCode(threadId);
|
|
|
|
scriptCodeIp = _scriptResource->getThreadCode(threadId);
|
|
|
|
newScriptThread(tempThreadId, callingThreadId, 0, scriptCodeIp, value8, valueC, value10);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 ScriptMan::startTempScriptThread(byte *scriptCodeIp, uint32 callingThreadId,
|
|
|
|
uint32 value8, uint32 valueC, uint32 value10) {
|
|
|
|
uint32 tempThreadId = newTempThreadId();
|
2014-03-22 02:32:44 +01:00
|
|
|
debug("Starting temp script thread %08X", tempThreadId);
|
2014-03-13 19:55:25 +01:00
|
|
|
newScriptThread(tempThreadId, callingThreadId, 0, scriptCodeIp, value8, valueC, value10);
|
|
|
|
return tempThreadId;
|
|
|
|
}
|
|
|
|
|
2014-03-19 23:18:25 +01:00
|
|
|
uint32 ScriptMan::startAbortableTimerThread(uint32 duration, uint32 threadId) {
|
|
|
|
return newTimerThread(duration, threadId, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 ScriptMan::startTimerThread(uint32 duration, uint32 threadId) {
|
|
|
|
return newTimerThread(duration, threadId, false);
|
|
|
|
}
|
|
|
|
|
2014-03-21 17:21:55 +01:00
|
|
|
uint32 ScriptMan::startAbortableThread(byte *scriptCodeIp1, byte *scriptCodeIp2, uint32 callingThreadId) {
|
|
|
|
uint32 tempThreadId = newTempThreadId();
|
2014-03-22 02:32:44 +01:00
|
|
|
debug("Starting abortable thread %08X", tempThreadId);
|
2014-03-21 17:21:55 +01:00
|
|
|
uint32 scriptThreadId = startTempScriptThread(scriptCodeIp1, tempThreadId, 0, 0, 0);
|
2014-03-22 02:32:44 +01:00
|
|
|
AbortableThread *abortableThread = new AbortableThread(_vm, tempThreadId, callingThreadId, 0,
|
|
|
|
scriptThreadId, scriptCodeIp2);
|
2014-03-21 17:21:55 +01:00
|
|
|
_threads->startThread(abortableThread);
|
|
|
|
return tempThreadId;
|
|
|
|
}
|
|
|
|
|
2014-03-22 02:32:44 +01:00
|
|
|
uint32 ScriptMan::startTalkThread(int16 duration, uint32 objectId, uint32 talkId, uint32 sequenceId1,
|
|
|
|
uint32 sequenceId2, uint32 namedPointId, uint32 callingThreadId) {
|
|
|
|
debug("Starting talk thread");
|
|
|
|
uint32 tempThreadId = newTempThreadId();
|
|
|
|
// TODO endTalkThreadsNoNotify();
|
|
|
|
TalkThread *talkThread = new TalkThread(_vm, tempThreadId, callingThreadId, 0,
|
|
|
|
duration, objectId, talkId, sequenceId1, sequenceId2, namedPointId);
|
|
|
|
_threads->startThread(talkThread);
|
|
|
|
return tempThreadId;
|
|
|
|
}
|
|
|
|
|
2014-03-19 20:39:16 +01:00
|
|
|
void ScriptMan::setCurrFontId(uint32 fontId) {
|
|
|
|
_fontId = fontId;
|
|
|
|
}
|
|
|
|
|
2014-03-22 02:32:44 +01:00
|
|
|
bool ScriptMan::checkActiveTalkThreads() {
|
|
|
|
// TODO
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 ScriptMan::clipTextDuration(uint32 duration) {
|
|
|
|
switch (_field8) {
|
|
|
|
case 2:
|
|
|
|
if (duration == 0)
|
|
|
|
duration = 240;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (duration < _fieldA)
|
|
|
|
duration = _fieldA;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (duration > _fieldA)
|
|
|
|
duration = _fieldA;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2014-03-20 14:16:48 +01:00
|
|
|
void ScriptMan::reset() {
|
2014-03-22 02:32:44 +01:00
|
|
|
_scriptResource->_blockCounters.clear();
|
|
|
|
_scriptResource->_properties.clear();
|
2014-03-20 14:16:48 +01:00
|
|
|
// TODO script_sub_417FF0(1, 0);
|
|
|
|
}
|
|
|
|
|
2014-03-19 20:39:16 +01:00
|
|
|
bool ScriptMan::enterScene(uint32 sceneId, uint32 threadId) {
|
|
|
|
ProgInfo *progInfo = _scriptResource->getProgInfo(sceneId & 0xFFFF);
|
|
|
|
if (!progInfo) {
|
|
|
|
// TODO dumpActiveScenes(_someSceneId2, threadId);
|
|
|
|
sceneId = _theSceneId;
|
|
|
|
}
|
|
|
|
_activeScenes.push(sceneId);
|
|
|
|
return progInfo != 0;
|
|
|
|
}
|
|
|
|
|
2014-03-20 14:16:48 +01:00
|
|
|
void ScriptMan::exitScene(uint32 threadId) {
|
|
|
|
uint32 sceneId = _activeScenes.getCurrentScene();
|
|
|
|
// TODO krnfileDump(sceneId);
|
|
|
|
// TODO UpdateFunctions_disableByTag__TODO_maybe(sceneId);
|
|
|
|
_threads->terminateThreadsByTag(sceneId, threadId);
|
|
|
|
_vm->_controls->destroyControlsByTag(sceneId);
|
|
|
|
// TODO causeFunc_removeBySceneId(sceneId);
|
2014-03-21 17:21:55 +01:00
|
|
|
_vm->_resSys->unloadResourcesByTag(sceneId);
|
2014-03-20 14:16:48 +01:00
|
|
|
_activeScenes.pop();
|
|
|
|
}
|
|
|
|
|
2014-03-13 19:55:25 +01:00
|
|
|
void ScriptMan::newScriptThread(uint32 threadId, uint32 callingThreadId, uint notifyFlags,
|
|
|
|
byte *scriptCodeIp, uint32 value8, uint32 valueC, uint32 value10) {
|
2014-03-19 23:18:25 +01:00
|
|
|
ScriptThread *scriptThread = new ScriptThread(_vm, threadId, callingThreadId, notifyFlags,
|
|
|
|
scriptCodeIp, value8, valueC, value10);
|
2014-03-13 19:55:25 +01:00
|
|
|
_threads->startThread(scriptThread);
|
|
|
|
if (_pauseCtr > 0)
|
|
|
|
scriptThread->pause();
|
|
|
|
if (_doScriptThreadInit) {
|
|
|
|
int updateResult = 4;
|
|
|
|
while (scriptThread->_pauseCtr <= 0 && updateResult != 1 && updateResult != 2)
|
|
|
|
updateResult = scriptThread->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 23:18:25 +01:00
|
|
|
uint32 ScriptMan::newTimerThread(uint32 duration, uint32 callingThreadId, bool isAbortable) {
|
|
|
|
uint32 tempThreadId = newTempThreadId();
|
|
|
|
TimerThread *timerThread = new TimerThread(_vm, tempThreadId, callingThreadId, 0,
|
|
|
|
duration, isAbortable);
|
|
|
|
_threads->startThread(timerThread);
|
|
|
|
return tempThreadId;
|
|
|
|
}
|
|
|
|
|
2014-03-13 19:55:25 +01:00
|
|
|
uint32 ScriptMan::newTempThreadId() {
|
|
|
|
uint32 threadId = _nextTempThreadId + 2 * _scriptResource->_codeCount;
|
|
|
|
if (threadId > 65535) {
|
|
|
|
_nextTempThreadId = 0;
|
|
|
|
threadId = 2 * _scriptResource->_codeCount;
|
|
|
|
}
|
|
|
|
++_nextTempThreadId;
|
|
|
|
return 0x00020000 | threadId;
|
|
|
|
}
|
|
|
|
|
2014-03-13 14:31:02 +01:00
|
|
|
} // End of namespace Illusions
|