[Scummvm-git-logs] scummvm master -> 1b1afe951fbb6032b5adf6b4af00e287470d7b66
tnm23
noreply at scummvm.org
Fri Oct 3 18:06:03 UTC 2025
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
1b1afe951f ZVISION: Reduce code reuse and improve clarity of function in ChangeLocationReal().
Commit: 1b1afe951fbb6032b5adf6b4af00e287470d7b66
https://github.com/scummvm/scummvm/commit/1b1afe951fbb6032b5adf6b4af00e287470d7b66
Author: Thomas N McEwan (46427621+tnm23 at users.noreply.github.com)
Date: 2025-10-03T19:04:09+01:00
Commit Message:
ZVISION: Reduce code reuse and improve clarity of function in ChangeLocationReal().
Additional comments and function documentation for script manager.
Changed paths:
engines/zvision/scripting/script_manager.cpp
engines/zvision/scripting/script_manager.h
diff --git a/engines/zvision/scripting/script_manager.cpp b/engines/zvision/scripting/script_manager.cpp
index 0266eef7578..f84d9a0d26e 100644
--- a/engines/zvision/scripting/script_manager.cpp
+++ b/engines/zvision/scripting/script_manager.cpp
@@ -641,14 +641,11 @@ void ScriptManager::ChangeLocationReal(bool isLoading) {
}
if (enteringMenu) {
- if (isSaveScreen && !leavingMenu) {
+ if (isSaveScreen && !leavingMenu)
_engine->getSaveManager()->prepareSaveBuffer();
- }
- } else {
- if (leavingMenu) {
- _engine->getSaveManager()->flushSaveBuffer();
- }
}
+ else if (leavingMenu)
+ _engine->getSaveManager()->flushSaveBuffer();
setStateValue(StateKey_World, _nextLocation.world);
setStateValue(StateKey_Room, _nextLocation.room);
@@ -661,45 +658,40 @@ void ScriptManager::ChangeLocationReal(bool isLoading) {
_engine->getMenuManager()->setEnable(0xFFFF);
- if (_nextLocation.world != _currentLocation.world) {
- cleanScriptScope(_nodeview);
- cleanScriptScope(_room);
+ TransitionLevel level = NONE;
+ Common::Path filePath;
+ if (_nextLocation.world != _currentLocation.world)
+ level = WORLD;
+ else if (_nextLocation.room != _currentLocation.room)
+ level = ROOM;
+ else if (_nextLocation.node != _currentLocation.node)
+ level = NODE;
+ else if (_nextLocation.view != _currentLocation.view)
+ level = VIEW;
+
+ switch (level) {
+ case WORLD:
cleanScriptScope(_world);
-
- Common::Path fileName(Common::String::format("%c%c%c%c.scr", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view));
- parseScrFile(fileName, _nodeview);
- addPuzzlesToReferenceTable(_nodeview);
-
- fileName = Common::Path(Common::String::format("%c%c.scr", _nextLocation.world, _nextLocation.room));
- parseScrFile(fileName, _room);
- addPuzzlesToReferenceTable(_room);
-
- fileName = Common::Path(Common::String::format("%c.scr", _nextLocation.world));
- parseScrFile(fileName, _world);
- addPuzzlesToReferenceTable(_world);
- } else if (_nextLocation.room != _currentLocation.room) {
- cleanScriptScope(_nodeview);
+ filePath = Common::Path(Common::String::format("%c.scr", _nextLocation.world));
+ parseScrFile(filePath, _world);
+ // fall through
+ case ROOM:
cleanScriptScope(_room);
-
- addPuzzlesToReferenceTable(_world);
-
- Common::Path fileName(Common::String::format("%c%c%c%c.scr", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view));
- parseScrFile(fileName, _nodeview);
- addPuzzlesToReferenceTable(_nodeview);
-
- fileName = Common::Path(Common::String::format("%c%c.scr", _nextLocation.world, _nextLocation.room));
- parseScrFile(fileName, _room);
- addPuzzlesToReferenceTable(_room);
-
- } else if (_nextLocation.node != _currentLocation.node || _nextLocation.view != _currentLocation.view) {
+ filePath = Common::Path(Common::String::format("%c%c.scr", _nextLocation.world, _nextLocation.room));
+ parseScrFile(filePath, _room);
+ // fall through
+ case NODE:
+ case VIEW:
cleanScriptScope(_nodeview);
-
- addPuzzlesToReferenceTable(_room);
+ filePath = Common::Path(Common::String::format("%c%c%c%c.scr", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view));
+ parseScrFile(filePath, _nodeview);
addPuzzlesToReferenceTable(_world);
-
- Common::Path fileName(Common::String::format("%c%c%c%c.scr", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view));
- parseScrFile(fileName, _nodeview);
+ addPuzzlesToReferenceTable(_room);
addPuzzlesToReferenceTable(_nodeview);
+ break;
+ case NONE:
+ default:
+ break;
}
_activeControls = &_nodeview.controls;
@@ -710,22 +702,24 @@ void ScriptManager::ChangeLocationReal(bool isLoading) {
// Change the background position
_engine->getRenderManager()->setBackgroundPosition(_nextLocation.offset);
- if (_currentLocation == "0000") {
+ if (_currentLocation == "0000")
+ level = WORLD;
+ if (level != NONE)
_currentLocation = _nextLocation;
+ switch (level) {
+ case WORLD:
execScope(_world);
+ // fall through
+ case ROOM:
execScope(_room);
+ // fall through
+ case NODE:
+ case VIEW:
execScope(_nodeview);
- } else if (_nextLocation.world != _currentLocation.world) {
- _currentLocation = _nextLocation;
- execScope(_room);
- execScope(_nodeview);
- } else if (_nextLocation.room != _currentLocation.room) {
- _currentLocation = _nextLocation;
- execScope(_room);
- execScope(_nodeview);
- } else if (_nextLocation.node != _currentLocation.node || _nextLocation.view != _currentLocation.view) {
- _currentLocation = _nextLocation;
- execScope(_nodeview);
+ break;
+ case NONE:
+ default:
+ break;
}
_engine->getRenderManager()->checkBorders();
diff --git a/engines/zvision/scripting/script_manager.h b/engines/zvision/scripting/script_manager.h
index 42973b50ca7..fba3ca490b1 100644
--- a/engines/zvision/scripting/script_manager.h
+++ b/engines/zvision/scripting/script_manager.h
@@ -197,6 +197,14 @@ private:
uint32 _currentlyFocusedControl;
public:
+ enum TransitionLevel {
+ NONE,
+ VIEW,
+ NODE,
+ ROOM,
+ WORLD
+ };
+
void initialize(bool restarted = false);
void process(uint deltaTimeMillis);
void queuePuzzles(uint32 key);
@@ -290,9 +298,20 @@ private:
void addPuzzlesToReferenceTable(ScriptScope &scope);
void updateNodes(uint deltaTimeMillis);
void updateControls(uint deltaTimeMillis);
+ /**
+ * Check a puzzle's criteria; execute its actions and set its state to 1 if these critera are met.
+ * Will not check or execute if:
+ * Puzzle is disabled
+ * Puzzle has already triggered and has a state value of 1
+ * procCount has reached zero AND do_me_now is not set
+ *
+ * @param puzzle puzzle to check
+ * @param counter procCount from this puzzle's scope container
+ * Returns true if OK to keep calling this function this frame; false if we should break and start next frame (only used by RestoreGame action)
+ */
bool checkPuzzleCriteria(Puzzle *puzzle, uint counter);
- void cleanStateTable();
- void cleanScriptScope(ScriptScope &scope);
+ void cleanStateTable(); // Set all global state values to zero
+ void cleanScriptScope(ScriptScope &scope); // Resets everything in this scope, all lists empty, procCount to zero.
bool execScope(ScriptScope &scope);
/** Perform change location */
More information about the Scummvm-git-logs
mailing list