[Scummvm-cvs-logs] scummvm master -> 8c8261aa2a381c3e7f12c5dd0aaf33a69e1f7eb3

eriktorbjorn eriktorbjorn at telia.com
Mon Jan 26 22:19:31 CET 2015


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:
dd5cd42f2e ZVISION: Use ValueSlot for volume in ActionMusic
8c8261aa2a ZVISION: Cleanup.


Commit: dd5cd42f2eff7ca320fe507916b65a06c3a0ee74
    https://github.com/scummvm/scummvm/commit/dd5cd42f2eff7ca320fe507916b65a06c3a0ee74
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2015-01-26T22:18:23+01:00

Commit Message:
ZVISION: Use ValueSlot for volume in ActionMusic

As suggested by Marisa-Chan. I had based my earlier implementation
on parseCritera(), and was unaware of this alternative. The good
thing is that the diff from the old code is now much smaller, which
should reduce the risk of regressions. (There is a lot I haven't
tested here...)

Changed paths:
    engines/zvision/scripting/actions.cpp
    engines/zvision/scripting/actions.h



diff --git a/engines/zvision/scripting/actions.cpp b/engines/zvision/scripting/actions.cpp
index 81d6655..d851a74 100644
--- a/engines/zvision/scripting/actions.cpp
+++ b/engines/zvision/scripting/actions.cpp
@@ -21,7 +21,6 @@
  */
 
 #include "common/scummsys.h"
-#include "common/tokenizer.h"
 #include "video/video_decoder.h"
 
 #include "zvision/scripting/actions.h"
@@ -446,51 +445,48 @@ bool ActionMenuBarEnable::execute() {
 
 ActionMusic::ActionMusic(ZVision *engine, int32 slotkey, const Common::String &line, bool global) :
 	ResultAction(engine, slotkey),
-	_volume(255),
 	_note(0),
 	_prog(0),
 	_universe(global) {
-	Common::StringTokenizer tokenizer(line);
+	uint type = 0;
+	char fileNameBuffer[25];
+	uint loop = 0;
+	char volumeBuffer[15];
 
-	// Parse the type of action. Type 4 actions are MIDI commands, not
-	// files. These are only used by Zork: Nemesis, for the flute and piano
-	// puzzles (tj4e and ve6f, as well as vr)
-	uint type = atoi(tokenizer.nextToken().c_str());
+	// Volume is optional. If it doesn't appear, assume full volume
+	strcpy(volumeBuffer, "100");
 
+	sscanf(line.c_str(), "%u %24s %u %14s", &type, fileNameBuffer, &loop, volumeBuffer);
+
+	// Type 4 actions are MIDI commands, not files. These are only used by
+	// Zork: Nemesis, for the flute and piano puzzles (tj4e and ve6f, as well
+	// as vr)
 	if (type == 4) {
 		_midi = true;
-		_prog = atoi(tokenizer.nextToken().c_str());
-		_note = atoi(tokenizer.nextToken().c_str());
-		_volume = atoi(tokenizer.nextToken().c_str());
-		_volumeIsAKey = false;
+		int note;
+		int prog;
+		sscanf(line.c_str(), "%u %d %d %14s", &type, &prog, &note, volumeBuffer);
+		_volume = new ValueSlot(_engine->getScriptManager(), volumeBuffer);
+		_note = note;
+		_prog = prog;
 	} else {
 		_midi = false;
-		_fileName = tokenizer.nextToken();
-		_loop = atoi(tokenizer.nextToken().c_str()) == 1;
-		if (!tokenizer.empty()) {
-			Common::String token = tokenizer.nextToken();
-			if (token.contains('[')) {
-				sscanf(token.c_str(), "[%u]", &_volume);
-				_volumeIsAKey = true;
-			} else {
-				_volume = atoi(token.c_str());
-				if (_volume > 100) {
-					warning("ActionMusic: Adjusting volume for %s from %d to 100", _fileName.c_str(), _volume);
-					_volume = 100;
-				}
-				_volumeIsAKey = false;
-			}
-		} else {
-			// Volume is optional. If it doesn't appear, assume full volume
-			_volume = 100;
-			_volumeIsAKey = false;
+		_fileName = Common::String(fileNameBuffer);
+		_loop = loop == 1 ? true : false;
+		if (volumeBuffer[0] != '[' && atoi(volumeBuffer) > 100) {
+			// I thought I saw a case like this in Zork Nemesis, so
+			// let's guard against it.
+			warning("ActionMusic: Adjusting volume for %s from %s to 100", _fileName.c_str(), volumeBuffer);
+			strcpy(volumeBuffer, "100");
 		}
+		_volume = new ValueSlot(engine->getScriptManager(), volumeBuffer);
 	}
 }
 
 ActionMusic::~ActionMusic() {
 	if (!_universe)
 		_engine->getScriptManager()->killSideFx(_slotKey);
+	delete _volume;
 }
 
 bool ActionMusic::execute() {
@@ -499,12 +495,7 @@ bool ActionMusic::execute() {
 		_engine->getScriptManager()->setStateValue(_slotKey, 2);
 	}
 
-	uint volume;
-	if (_volumeIsAKey) {
-		volume = _engine->getScriptManager()->getStateValue(_volume);
-	} else {
-		volume = _volume;
-	}
+	uint volume = _volume->getValue();
 
 	if (_midi) {
 		_engine->getScriptManager()->addSideFX(new MusicMidiNode(_engine, _slotKey, _prog, _note, volume));
@@ -513,7 +504,6 @@ bool ActionMusic::execute() {
 			return true;
 
 		// Volume in the script files is mapped to [0, 100], but the ScummVM mixer uses [0, 255]
-
 		_engine->getScriptManager()->addSideFX(new MusicNode(_engine, _slotKey, _fileName, _loop, volume * 255 / 100));
 	}
 
diff --git a/engines/zvision/scripting/actions.h b/engines/zvision/scripting/actions.h
index cbb91fa..94c2d04 100644
--- a/engines/zvision/scripting/actions.h
+++ b/engines/zvision/scripting/actions.h
@@ -224,8 +224,7 @@ public:
 private:
 	Common::String _fileName;
 	bool _loop;
-	uint32 _volume;
-	bool _volumeIsAKey;
+	ValueSlot *_volume;
 	bool _universe;
 	bool _midi;
 	int8 _note;


Commit: 8c8261aa2a381c3e7f12c5dd0aaf33a69e1f7eb3
    https://github.com/scummvm/scummvm/commit/8c8261aa2a381c3e7f12c5dd0aaf33a69e1f7eb3
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2015-01-26T22:18:23+01:00

Commit Message:
ZVISION: Cleanup.

We usually don't check a pointer before deleting it.

Changed paths:
    engines/zvision/scripting/actions.cpp



diff --git a/engines/zvision/scripting/actions.cpp b/engines/zvision/scripting/actions.cpp
index d851a74..5238561 100644
--- a/engines/zvision/scripting/actions.cpp
+++ b/engines/zvision/scripting/actions.cpp
@@ -79,8 +79,7 @@ ActionAssign::ActionAssign(ZVision *engine, int32 slotkey, const Common::String
 }
 
 ActionAssign::~ActionAssign() {
-	if (_value)
-		delete _value;
+	delete _value;
 }
 
 bool ActionAssign::execute() {
@@ -804,8 +803,7 @@ ActionRandom::ActionRandom(ZVision *engine, int32 slotkey, const Common::String
 }
 
 ActionRandom::~ActionRandom() {
-	if (_max)
-		delete _max;
+	delete _max;
 }
 
 bool ActionRandom::execute() {
@@ -1044,8 +1042,7 @@ ActionTimer::ActionTimer(ZVision *engine, int32 slotkey, const Common::String &l
 }
 
 ActionTimer::~ActionTimer() {
-	if (_time)
-		delete _time;
+	delete _time;
 	_engine->getScriptManager()->killSideFx(_slotKey);
 }
 






More information about the Scummvm-git-logs mailing list