mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-21 09:21:08 +00:00
ZVISION: Make ScriptManager::changeLocation delay the actual change until the end of the frame
This prevents memory corruption since changeLocation could be called in the middle of a Puzzle list iteration and changeLocation clears all the Puzzle lists.
This commit is contained in:
parent
dd11566ffd
commit
2565f96c55
@ -33,7 +33,7 @@
|
||||
|
||||
namespace ZVision {
|
||||
|
||||
ScriptManager::ScriptManager(ZVision *engine) : _engine(engine) {}
|
||||
ScriptManager::ScriptManager(ZVision *engine) : _engine(engine), _changeLocation(false) {}
|
||||
|
||||
void ScriptManager::initialize() {
|
||||
parseScrFile("universe.scr", true);
|
||||
@ -42,6 +42,11 @@ void ScriptManager::initialize() {
|
||||
void ScriptManager::update(uint deltaTimeMillis) {
|
||||
updateNodes(deltaTimeMillis);
|
||||
checkPuzzleCriteria();
|
||||
|
||||
if (_changeLocation) {
|
||||
changeLocationIntern();
|
||||
_changeLocation = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptManager::createReferenceTable() {
|
||||
@ -178,6 +183,19 @@ void ScriptManager::addActionNode(const Common::SharedPtr<ActionNode> &node) {
|
||||
}
|
||||
|
||||
void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 x) {
|
||||
_nextLocation.world = world;
|
||||
_nextLocation.room = room;
|
||||
_nextLocation.node = node;
|
||||
_nextLocation.view = view;
|
||||
_nextLocation.x = x;
|
||||
|
||||
_changeLocation = true;
|
||||
}
|
||||
|
||||
void ScriptManager::changeLocationIntern() {
|
||||
assert(_nextLocation.world != 0);
|
||||
debug("Changing location to: %c %c %c %c %u", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view, _nextLocation.x);
|
||||
|
||||
// Clear all the containers
|
||||
_referenceTable.clear();
|
||||
_puzzlesToCheck.clear();
|
||||
@ -186,16 +204,21 @@ void ScriptManager::changeLocation(char world, char room, char node, char view,
|
||||
_activeControls.clear();
|
||||
|
||||
// Parse into puzzles and controls
|
||||
Common::String fileName = Common::String::format("%c%c%c%c.scr", world, room, node, view);
|
||||
Common::String fileName = Common::String::format("%c%c%c%c.scr", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view);
|
||||
parseScrFile(fileName);
|
||||
|
||||
// Create the puzzle reference table
|
||||
createReferenceTable();
|
||||
|
||||
// Add all the puzzles to the stack to be checked
|
||||
// Add all the local puzzles to the stack to be checked
|
||||
for (Common::List<Puzzle>::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) {
|
||||
_puzzlesToCheck.push(&(*iter));
|
||||
}
|
||||
|
||||
// Add all the global puzzles to the stack to be checked
|
||||
for (Common::List<Puzzle>::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) {
|
||||
_puzzlesToCheck.push(&(*iter));
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace ZVision
|
||||
|
@ -39,6 +39,14 @@ namespace ZVision {
|
||||
class ZVision;
|
||||
class ActionNode;
|
||||
|
||||
struct Location {
|
||||
char world;
|
||||
char room;
|
||||
char node;
|
||||
char view;
|
||||
uint32 x;
|
||||
};
|
||||
|
||||
class ScriptManager {
|
||||
public:
|
||||
ScriptManager(ZVision *engine);
|
||||
@ -64,6 +72,9 @@ private:
|
||||
/** Holds the currently active controls */
|
||||
Common::List<Common::SharedPtr<Control> > _activeControls;
|
||||
|
||||
Location _nextLocation;
|
||||
bool _changeLocation;
|
||||
|
||||
public:
|
||||
|
||||
void initialize();
|
||||
@ -79,6 +90,7 @@ public:
|
||||
|
||||
private:
|
||||
void createReferenceTable();
|
||||
void changeLocationIntern();
|
||||
void updateNodes(uint deltaTimeMillis);
|
||||
void checkPuzzleCriteria();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user