[Scummvm-cvs-logs] scummvm master -> 37d4316a4014970171dfea8fc19f8c9e978e9102

RichieSams adastley at gmail.com
Fri Nov 1 05:39:15 CET 2013


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
992f43cc9c ZVISION: Move Puzzle flags to a ScriptManager HashMap
37d4316a40 ZVISION: Update timer logic


Commit: 992f43cc9c926364e50c88d33980d1a6830440fa
    https://github.com/scummvm/scummvm/commit/992f43cc9c926364e50c88d33980d1a6830440fa
Author: RichieSams (adastley at gmail.com)
Date: 2013-10-31T21:38:03-07:00

Commit Message:
ZVISION: Move Puzzle flags to a ScriptManager HashMap

This can be used to enable/disable Controls as well. Also, enabling/disabling
should be somewhat faster now as well as checking for enabled/disabled.

Changed paths:
    engines/zvision/actions.cpp
    engines/zvision/puzzle.h
    engines/zvision/scr_file_handling.cpp
    engines/zvision/script_manager.cpp
    engines/zvision/script_manager.h



diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp
index 1fa9fcf..0bb553a 100644
--- a/engines/zvision/actions.cpp
+++ b/engines/zvision/actions.cpp
@@ -124,7 +124,8 @@ ActionDisableControl::ActionDisableControl(const Common::String &line) {
 bool ActionDisableControl::execute(ZVision *engine) {
 	debug("Disabling control %u", _key);
 	
-	engine->getScriptManager()->disableControl(_key);
+	ScriptManager *scriptManager = engine->getScriptManager();
+	scriptManager->setStateFlags(_key, scriptManager->getStateFlags(_key) | StateFlags::DISABLED);
 
 	return true;
 }
@@ -141,7 +142,8 @@ ActionEnableControl::ActionEnableControl(const Common::String &line) {
 bool ActionEnableControl::execute(ZVision *engine) {
 	debug("Enabling control %u", _key);
 
-	engine->getScriptManager()->enableControl(_key);
+	ScriptManager *scriptManager = engine->getScriptManager();
+	scriptManager->setStateFlags(_key, scriptManager->getStateFlags(_key) & ~StateFlags::DISABLED);
 
 	return true;
 }
@@ -223,8 +225,10 @@ bool ActionPreloadAnimation::execute(ZVision *engine) {
 	// TODO: Check if the Control already exists
 
 	// Create the control, but disable it until PlayPreload is called
-	engine->getScriptManager()->addControl(new AnimationControl(engine, _key, _fileName));
-	engine->getScriptManager()->disableControl(_key);
+	ScriptManager *scriptManager = engine->getScriptManager();
+	scriptManager->addControl(new AnimationControl(engine, _key, _fileName));
+	scriptManager->setStateFlags(_key, scriptManager->getStateFlags(_key) | StateFlags::DISABLED);
+
 	return true;
 }
 
diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h
index 1e73036..d468da1 100644
--- a/engines/zvision/puzzle.h
+++ b/engines/zvision/puzzle.h
@@ -32,7 +32,7 @@
 namespace ZVision {
 
 struct Puzzle {
-	Puzzle() : key(0), flags(0) {}
+	Puzzle() : key(0) {}
 
 	~Puzzle() {
 		for (Common::List<ResultAction *>::iterator iter = resultActions.begin(); iter != resultActions.end(); ++iter) {
@@ -63,17 +63,10 @@ struct Puzzle {
 		bool argumentIsAKey;
 	};
 
-	enum StateFlags {
-		ONCE_PER_INST = 0x01,
-		DO_ME_NOW = 0x02, // Somewhat useless flag since anything that needs to be done immediately has no criteria
-		DISABLED = 0x04
-	};
-
 	uint32 key;
 	Common::List<Common::List <CriteriaEntry> > criteriaList;
 	// This has to be list of pointers because ResultAction is abstract
 	Common::List<ResultAction *> resultActions;
-	uint flags;
 };
 
 } // End of namespace ZVision
diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp
index e90408c..0c952ae 100644
--- a/engines/zvision/scr_file_handling.cpp
+++ b/engines/zvision/scr_file_handling.cpp
@@ -81,7 +81,7 @@ void ScriptManager::parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stre
 		} else if (line.matchString("results {", true)) {
 			parseResults(stream, puzzle->resultActions);
 		} else if (line.matchString("flags {", true)) {
-			puzzle->flags = parseFlags(stream);
+			setStateFlags(puzzle->key, parseFlags(stream));
 		}
 
 		line = stream.readLine();
@@ -259,11 +259,11 @@ uint ScriptManager::parseFlags(Common::SeekableReadStream &stream) const {
 
 	while (!stream.eos() && !line.contains('}')) {
 		if (line.matchString("ONCE_PER_INST", true)) {
-			flags |= Puzzle::ONCE_PER_INST;
+			flags |= ONCE_PER_INST;
 		} else if (line.matchString("DO_ME_NOW", true)) {
-			flags |= Puzzle::DO_ME_NOW;
+			flags |= DO_ME_NOW;
 		} else if (line.matchString("DISABLED", true)) {
-			flags |= Puzzle::DISABLED;
+			flags |= DISABLED;
 		}
 
 		line = stream.readLine();
diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp
index 66a5408..0e08345 100644
--- a/engines/zvision/script_manager.cpp
+++ b/engines/zvision/script_manager.cpp
@@ -126,8 +126,7 @@ void ScriptManager::checkPuzzleCriteria() {
 
 		// Check if the puzzle is already finished
 		// Also check that the puzzle isn't disabled
-		if (getStateValue(puzzle->key) == 1 &&
-			(puzzle->flags & Puzzle::DISABLED) == 0) {
+		if (getStateValue(puzzle->key) == 1 && (getStateFlags(puzzle->key) & DISABLED) == 0) {
 			continue;
 		}
 
@@ -223,6 +222,23 @@ void ScriptManager::setStateValue(uint32 key, uint value) {
 	}
 }
 
+uint ScriptManager::getStateFlags(uint32 key) {
+	if (_globalStateFlags.contains(key))
+		return _globalStateFlags[key];
+	else
+		return 0;
+}
+
+void ScriptManager::setStateFlags(uint32 key, uint flags) {
+	_globalStateFlags[key] = flags;
+
+	if (_referenceTable.contains(key)) {
+		for (Common::Array<Puzzle *>::iterator iter = _referenceTable[key].begin(); iter != _referenceTable[key].end(); ++iter) {
+			_puzzlesToCheck.push((*iter));
+		}
+	}
+}
+
 void ScriptManager::addToStateValue(uint32 key, uint valueToAdd) {
 	_globalState[key] += valueToAdd;
 }
@@ -241,24 +257,6 @@ Control *ScriptManager::getControl(uint32 key) {
 	return nullptr;
 }
 
-void ScriptManager::enableControl(uint32 key) {
-	for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) {
-		if ((*iter)->getKey() == key) {
-			(*iter)->enable();
-			break;
-		}
-	}
-}
-
-void ScriptManager::disableControl(uint32 key) {
-	for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) {
-		if ((*iter)->getKey() == key) {
-			(*iter)->disable();
-			break;
-		}
-	}
-}
-
 void ScriptManager::focusControl(uint32 key) {
 	for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) {
 		uint32 controlKey = (*iter)->getKey();
@@ -352,7 +350,7 @@ void ScriptManager::changeLocation(char world, char room, char node, char view,
 	// Add all the local puzzles to the queue to be checked
 	for (PuzzleList::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); ++iter) {
 		// Reset any Puzzles that have the flag ONCE_PER_INST
-		if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) {
+		if ((getStateFlags((*iter)->key) & ONCE_PER_INST) == ONCE_PER_INST) {
 			setStateValue((*iter)->key, 0);
 		}
 
@@ -362,7 +360,7 @@ void ScriptManager::changeLocation(char world, char room, char node, char view,
 	// Add all the global puzzles to the queue to be checked
 	for (PuzzleList::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); ++iter) {
 		// Reset any Puzzles that have the flag ONCE_PER_INST
-		if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) {
+		if ((getStateFlags((*iter)->key) & ONCE_PER_INST) == ONCE_PER_INST) {
 			setStateValue((*iter)->key, 0);
 		}
 
diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h
index 388d080..a5079e3 100644
--- a/engines/zvision/script_manager.h
+++ b/engines/zvision/script_manager.h
@@ -49,11 +49,18 @@ struct Location {
 	uint32 offset;
 };
 
+enum StateFlags {
+	ONCE_PER_INST = 0x01,
+	DO_ME_NOW = 0x02, // Somewhat useless flag since anything that needs to be done immediately has no criteria
+	DISABLED = 0x04
+};
+
 typedef Common::HashMap<uint32, Common::Array<Puzzle *> > PuzzleMap;
 typedef Common::List<Puzzle *> PuzzleList;
 typedef Common::Queue<Puzzle *> PuzzleQueue;
 typedef Common::List<Control *> ControlList;
 typedef Common::HashMap<uint32, uint32> StateMap;
+typedef Common::HashMap<uint32, uint> StateFlagMap;
 
 class ScriptManager {
 public:
@@ -68,6 +75,11 @@ private:
 	 * particular state key are checked after the key is modified.
 	 */
 	StateMap _globalState;
+	/** 
+	 * Holds the flags for the global states. This is used to enable/disable puzzles and/or 
+	 * controls as well as which puzzles should are allowed to be re-executed 
+	 */
+	StateFlagMap _globalStateFlags;
 	/** References _globalState keys to Puzzles */
 	PuzzleMap _referenceTable;
 	/** Holds the Puzzles that should be checked this frame */
@@ -91,12 +103,12 @@ public:
 	void setStateValue(uint32 key, uint value);
 	void addToStateValue(uint32 key, uint valueToAdd);
 
+	uint getStateFlags(uint32 key);
+	void setStateFlags(uint32 key, uint flags);
+
 	void addControl(Control *control);
 	Control *getControl(uint32 key);
 
-	void enableControl(uint32 key);
-	void disableControl(uint32 key);
-
 	void focusControl(uint32 key);
 
 	/**


Commit: 37d4316a4014970171dfea8fc19f8c9e978e9102
    https://github.com/scummvm/scummvm/commit/37d4316a4014970171dfea8fc19f8c9e978e9102
Author: RichieSams (adastley at gmail.com)
Date: 2013-10-31T21:38:03-07:00

Commit Message:
ZVISION: Update timer logic

Also account ZNem and ZGI using different timer scales

Changed paths:
    engines/zvision/timer_node.cpp
    engines/zvision/timer_node.h



diff --git a/engines/zvision/timer_node.cpp b/engines/zvision/timer_node.cpp
index 55dfa51..b529a66 100644
--- a/engines/zvision/timer_node.cpp
+++ b/engines/zvision/timer_node.cpp
@@ -31,16 +31,30 @@
 
 
 namespace ZVision {
+	
+TimerNode::TimerNode(ZVision *engine, uint32 key, uint timeInSeconds)
+		: Control(engine, key) {
+	if (_engine->getGameId() == GID_NEMESIS) {
+		_timeLeft = timeInSeconds * 1000;
+	} else if (_engine->getGameId() == GID_GRANDINQUISITOR) {
+		_timeLeft = timeInSeconds * 100;
+	}
+
+	_engine->getScriptManager()->setStateValue(_key, 1);
+}
 
-TimerNode::TimerNode(ZVision *engine, uint32 key, uint timeInSeconds) 
-	: Control(engine, key), _timeLeft(timeInSeconds * 1000) {
+TimerNode::~TimerNode() {
+	if (_timeLeft <= 0)
+		_engine->getScriptManager()->setStateValue(_key, 2);
+	else
+		_engine->getScriptManager()->setStateValue(_key, _timeLeft); // If timer was stopped by stop or kill
 }
 
 bool TimerNode::process(uint32 deltaTimeInMillis) {
 	_timeLeft -= deltaTimeInMillis;
 
 	if (_timeLeft <= 0) {
-		_engine->getScriptManager()->setStateValue(_key, 0);
+		// Let the destructor reset the state value
 		return true;
 	}
 
diff --git a/engines/zvision/timer_node.h b/engines/zvision/timer_node.h
index 32dca71..a953733 100644
--- a/engines/zvision/timer_node.h
+++ b/engines/zvision/timer_node.h
@@ -32,6 +32,7 @@ class ZVision;
 class TimerNode : public Control {
 public:
 	TimerNode(ZVision *engine, uint32 key, uint timeInSeconds);
+	~TimerNode();
 
 	/**
 	 * Decrement the timer by the delta time. If the timer is finished, set the status






More information about the Scummvm-git-logs mailing list