ILLUSIONS: More work on the script system
This commit is contained in:
parent
bb67c2c2ff
commit
fc47ac41ae
6 changed files with 238 additions and 0 deletions
|
@ -33,6 +33,7 @@
|
|||
#include "illusions/actorresource.h"
|
||||
#include "illusions/thread.h"
|
||||
#include "illusions/scriptresource.h"
|
||||
#include "illusions/scriptman.h"
|
||||
|
||||
#include "audio/audiostream.h"
|
||||
#include "common/config-manager.h"
|
||||
|
|
|
@ -11,6 +11,7 @@ MODULE_OBJS := \
|
|||
illusions.o \
|
||||
input.o \
|
||||
resourcesystem.o \
|
||||
scriptman.o \
|
||||
scriptresource.o \
|
||||
spritedecompressqueue.o \
|
||||
spritedrawqueue.o \
|
||||
|
|
126
engines/illusions/scriptman.cpp
Normal file
126
engines/illusions/scriptman.cpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
/* 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"
|
||||
#include "illusions/scriptman.h"
|
||||
|
||||
namespace Illusions {
|
||||
|
||||
// ActiveScenes
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// ScriptMan
|
||||
|
||||
ScriptMan::ScriptMan(IllusionsEngine *vm)
|
||||
: _vm(vm) {
|
||||
}
|
||||
|
||||
ScriptMan::~ScriptMan() {
|
||||
}
|
||||
|
||||
void ScriptMan::setSceneIdThreadId(uint32 theSceneId, uint32 theThreadId) {
|
||||
_theSceneId = theSceneId;
|
||||
_theThreadId = theThreadId;
|
||||
}
|
||||
|
||||
} // End of namespace Illusions
|
85
engines/illusions/scriptman.h
Normal file
85
engines/illusions/scriptman.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
/* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ILLUSIONS_SCRIPTMAN_H
|
||||
#define ILLUSIONS_SCRIPTMAN_H
|
||||
|
||||
#include "illusions/scriptresource.h"
|
||||
#include "common/algorithm.h"
|
||||
#include "common/stack.h"
|
||||
|
||||
namespace Illusions {
|
||||
|
||||
class IllusionsEngine;
|
||||
|
||||
struct ActiveScene {
|
||||
uint32 _sceneId;
|
||||
int _pauseCtr;
|
||||
};
|
||||
|
||||
class ActiveScenes {
|
||||
public:
|
||||
ActiveScenes();
|
||||
void clear();
|
||||
void push(uint32 sceneId);
|
||||
void pop();
|
||||
void pauseActiveScene();
|
||||
void unpauseActiveScene();
|
||||
int getActiveScenesCount();
|
||||
void getActiveSceneInfo(uint index, uint32 *sceneId, int *pauseCtr);
|
||||
uint32 getCurrentScene();
|
||||
bool isSceneActive(uint32 sceneId);
|
||||
protected:
|
||||
Common::FixedStack<ActiveScene, 16> _stack;
|
||||
};
|
||||
|
||||
class ScriptStack {
|
||||
public:
|
||||
ScriptStack();
|
||||
void clear();
|
||||
void push(int16 value);
|
||||
int16 pop();
|
||||
int16 peek();
|
||||
protected:
|
||||
int _stackPos;
|
||||
int16 _stack[256];
|
||||
};
|
||||
|
||||
class ScriptMan {
|
||||
public:
|
||||
ScriptMan(IllusionsEngine *vm);
|
||||
~ScriptMan();
|
||||
void setSceneIdThreadId(uint32 theSceneId, uint32 theThreadId);
|
||||
public:
|
||||
|
||||
IllusionsEngine *_vm;
|
||||
ActiveScenes _activeScenes;
|
||||
ScriptStack _stack;
|
||||
|
||||
uint32 _theSceneId;
|
||||
uint32 _theThreadId;
|
||||
|
||||
};
|
||||
|
||||
} // End of namespace Illusions
|
||||
|
||||
#endif // ILLUSIONS_SCRIPTMAN_H
|
|
@ -71,6 +71,18 @@ void BlockCounters::init(uint count, byte *blockCounters) {
|
|||
_blockCounters = blockCounters;
|
||||
}
|
||||
|
||||
void BlockCounters::clear() {
|
||||
for (uint i = 0; i < _count; ++i)
|
||||
_blockCounters[i] = 0;
|
||||
}
|
||||
|
||||
byte BlockCounters::get(uint index) {
|
||||
return _blockCounters[index] & 0x3F;
|
||||
}
|
||||
|
||||
void BlockCounters::set(uint index, byte value) {
|
||||
_blockCounters[index] = (get(index) ^ value) & 0x3F;
|
||||
}
|
||||
|
||||
// TriggerCause
|
||||
|
||||
|
@ -159,6 +171,9 @@ ScriptResource::~ScriptResource() {
|
|||
void ScriptResource::load(byte *data, uint32 dataSize) {
|
||||
Common::MemoryReadStream stream(data, dataSize, DisposeAfterUse::NO);
|
||||
|
||||
_data = data;
|
||||
_dataSize = dataSize;
|
||||
|
||||
stream.skip(4); // Skip unused
|
||||
uint propertiesCount = stream.readUint16LE();
|
||||
uint blockCountersCount = stream.readUint16LE();
|
||||
|
@ -194,4 +209,8 @@ void ScriptResource::load(byte *data, uint32 dataSize) {
|
|||
|
||||
}
|
||||
|
||||
byte *ScriptResource::getThreadCode(uint32 threadId) {
|
||||
return _data + _codeOffsets[threadId & 0xFFFF];
|
||||
}
|
||||
|
||||
} // End of namespace Illusions
|
||||
|
|
|
@ -54,6 +54,9 @@ class BlockCounters {
|
|||
public:
|
||||
BlockCounters();
|
||||
void init(uint count, byte *blockCounters);
|
||||
void clear();
|
||||
byte get(uint index);
|
||||
void set(uint index, byte value);
|
||||
public:
|
||||
uint _count;
|
||||
byte *_blockCounters;
|
||||
|
@ -95,7 +98,10 @@ public:
|
|||
ScriptResource();
|
||||
~ScriptResource();
|
||||
void load(byte *data, uint32 dataSize);
|
||||
byte *getThreadCode(uint32 threadId);
|
||||
public:
|
||||
byte *_data;
|
||||
uint32 _dataSize;
|
||||
Properties _properties;
|
||||
BlockCounters _blockCounters;
|
||||
uint32 *_codeOffsets;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue