Skip to content

Commit

Permalink
ZVISION: Use ValueSlot for volume in ActionMusic
Browse files Browse the repository at this point in the history
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...)
  • Loading branch information
Torbjörn Andersson committed Jan 26, 2015
1 parent d0f95b4 commit dd5cd42
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 39 deletions.
64 changes: 27 additions & 37 deletions engines/zvision/scripting/actions.cpp
Expand Up @@ -21,7 +21,6 @@
*/

#include "common/scummsys.h"
#include "common/tokenizer.h"
#include "video/video_decoder.h"

#include "zvision/scripting/actions.h"
Expand Down Expand Up @@ -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() {
Expand All @@ -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));
Expand All @@ -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));
}

Expand Down
3 changes: 1 addition & 2 deletions engines/zvision/scripting/actions.h
Expand Up @@ -224,8 +224,7 @@ class ActionMusic : public ResultAction {
private:
Common::String _fileName;
bool _loop;
uint32 _volume;
bool _volumeIsAKey;
ValueSlot *_volume;
bool _universe;
bool _midi;
int8 _note;
Expand Down

0 comments on commit dd5cd42

Please sign in to comment.