From da74436aa4d1c25f5120caa75197c2c4d9e0d1bc Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 16 Sep 2011 19:06:22 -0400 Subject: PEGASUS: Implement fader support --- engines/pegasus/fader.cpp | 214 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100755 engines/pegasus/fader.cpp (limited to 'engines/pegasus/fader.cpp') diff --git a/engines/pegasus/fader.cpp b/engines/pegasus/fader.cpp new file mode 100755 index 0000000000..c3cfe9d263 --- /dev/null +++ b/engines/pegasus/fader.cpp @@ -0,0 +1,214 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "pegasus/fader.h" +#include "pegasus/util.h" + +namespace Pegasus { + +Fader::Fader() { + _currentValue = 0; + _currentFaderMove._numKnots = 0; +} + +void Fader::setFaderValue(const uint32 newValue) { + _currentValue = newValue; +} + +bool Fader::initFaderMove(const FaderMoveSpec &spec) { + bool faderMoves = false; + uint32 value = 0; + + if (spec._numKnots > 0) { + stopFader(); + value = spec._knots[0].knotValue; + TimeValue startTime = spec._knots[0].knotTime; + + if (startTime != 0xffffffff) { + if (spec._numKnots > 1) { + TimeValue stopTime = spec._knots[spec._numKnots - 1].knotTime; + + if (spec._faderScale > 0) { + if (stopTime > startTime) { + for (uint32 i = 1; i < spec._numKnots; ++i) { + if (spec._knots[i - 1].knotValue != spec._knots[i].knotValue) { + faderMoves = true; + break; + } + } + + if (faderMoves) + _currentFaderMove = spec; + } else if (spec._knots[spec._numKnots - 1].knotValue != value) { + value = spec._knots[spec._numKnots - 1].knotValue; + } + } + } + } + } + + setFaderValue(value); + return faderMoves; +} + +void Fader::startFader(const FaderMoveSpec &spec) { + if (initFaderMove(spec)) { + setFlags(0); + setScale(spec._faderScale); + setSegment(spec._knots[0].knotTime, spec._knots[spec._numKnots - 1].knotTime); + setTime(spec._knots[0].knotTime); + start(); + } +} + +void Fader::startFaderSync(const FaderMoveSpec &spec) { + if (initFaderMove(spec)) { + setFlags(0); + setScale(spec._faderScale); + setSegment(spec._knots[0].knotTime, spec._knots[spec._numKnots - 1].knotTime); + setTime(spec._knots[0].knotTime); + start(); + + while (isFading()) + useIdleTime(); + + // Once more, for good measure, to make sure that there are no boundary + // condition problems. + useIdleTime(); + stopFader(); + } +} + +void Fader::loopFader(const FaderMoveSpec &spec) { + if (initFaderMove(spec)) { + setFlags(kLoopTimeBase); + setScale(spec._faderScale); + setSegment(spec._knots[0].knotTime, spec._knots[spec._numKnots - 1].knotTime); + setTime(spec._knots[0].knotTime); + start(); + } +} + +void Fader::stopFader() { + stop(); +} + +void Fader::pauseFader() { + stopFader(); +} + +void Fader::continueFader() { + if (getTime() < getStop()) + start(); +} + +void Fader::timeChanged(const TimeValue newTime) { + if (_currentFaderMove._numKnots != 0) { + uint32 i; + for (i = 0; i < _currentFaderMove._numKnots; i++) + if (_currentFaderMove._knots[i].knotTime > newTime) + break; + + uint32 newValue; + if (i == 0) + newValue = _currentFaderMove._knots[0].knotValue; + else if (i == _currentFaderMove._numKnots) + newValue = _currentFaderMove._knots[i - 1].knotValue; + else + newValue = linearInterp(_currentFaderMove._knots[i - 1].knotTime, _currentFaderMove._knots[i].knotTime, newTime, _currentFaderMove._knots[i - 1].knotValue, _currentFaderMove._knots[i].knotValue); + + if (newValue != _currentValue) + setFaderValue(newValue); + } +} + +void FaderMoveSpec::makeOneKnotFaderSpec(const uint32 knotValue) { + _numKnots = 1; + _knots[0].knotTime = 0; + _knots[0].knotValue = knotValue; +} + +void FaderMoveSpec::makeTwoKnotFaderSpec(const TimeScale faderScale, const TimeValue time1, const uint32 value1, const TimeValue time2, const uint32 value2) { + _numKnots = 2; + _faderScale = faderScale; + _knots[0].knotTime = time1; + _knots[0].knotValue = value1; + _knots[1].knotTime = time2; + _knots[1].knotValue = value2; +} + +void FaderMoveSpec::insertFaderKnot(const TimeValue knotTime, const uint32 knotValue) { + if (_numKnots != kMaxFaderKnots) { + uint32 index; + for (index = 0; index < _numKnots; index++) { + if (knotTime == _knots[index].knotTime) { + _knots[index].knotValue = knotValue; + return; + } else if (knotTime < _knots[index].knotTime) { + break; + } + } + + for (uint32 i = _numKnots; i > index; i--) + _knots[i] = _knots[i - 1]; + + _knots[index].knotTime = knotTime; + _knots[index].knotValue = knotValue; + _numKnots++; + } +} + +void FaderAnimation::setFaderValue(const uint32 newValue) { + if (getFaderValue() != newValue) { + Fader::setFaderValue(newValue); + triggerRedraw(); + } +} + +SoundFader::SoundFader() { + _sound = 0; + _masterVolume = 0xff; +} + +void SoundFader::attachSound(Sound *sound) { + if (!sound && isFading()) + stopFader(); + + _sound = sound; +} + +void SoundFader::setFaderValue(const uint32 newVolume) { + if (_sound) + _sound->setVolume((newVolume * _masterVolume) >> 8); + + _currentValue = newVolume; +} + +void SoundFader::setMasterVolume(const uint16 masterVolume) { + _masterVolume = masterVolume; + setFaderValue(getFaderValue()); +} + +} // End of namespace Pegasus -- cgit v1.2.3 From 4aed723368b9a4e82205bc3ed950a4e04ba3d8dc Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sun, 25 Sep 2011 12:23:19 -0400 Subject: PEGASUS: Fix startFaderSync Since we're not running in multiple threads anymore, we cannot have the fader hold the main thread to itself. --- engines/pegasus/fader.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'engines/pegasus/fader.cpp') diff --git a/engines/pegasus/fader.cpp b/engines/pegasus/fader.cpp index c3cfe9d263..3d8305b2c9 100755 --- a/engines/pegasus/fader.cpp +++ b/engines/pegasus/fader.cpp @@ -31,6 +31,7 @@ namespace Pegasus { Fader::Fader() { _currentValue = 0; _currentFaderMove._numKnots = 0; + _syncMode = false; } void Fader::setFaderValue(const uint32 newValue) { @@ -85,19 +86,13 @@ void Fader::startFader(const FaderMoveSpec &spec) { void Fader::startFaderSync(const FaderMoveSpec &spec) { if (initFaderMove(spec)) { + _syncMode = true; + setFlags(0); setScale(spec._faderScale); setSegment(spec._knots[0].knotTime, spec._knots[spec._numKnots - 1].knotTime); setTime(spec._knots[0].knotTime); - start(); - - while (isFading()) - useIdleTime(); - - // Once more, for good measure, to make sure that there are no boundary - // condition problems. - useIdleTime(); - stopFader(); + start(); } } @@ -144,6 +139,18 @@ void Fader::timeChanged(const TimeValue newTime) { } } +void Fader::checkCallBacks() { + IdlerTimeBase::checkCallBacks(); + + if (_syncMode && !isRunning()) { + // Once more, for good measure, to make sure that there are no boundary + // condition problems. + useIdleTime(); + stopFader(); + _syncMode = false; + } +} + void FaderMoveSpec::makeOneKnotFaderSpec(const uint32 knotValue) { _numKnots = 1; _knots[0].knotTime = 0; -- cgit v1.2.3 From 4f358e7615f7d68887eb3ab608a9d7ce1d9a4d93 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Mon, 26 Sep 2011 12:36:50 -0400 Subject: PEGASUS: Begin populating the Neighborhood class with more useful functions --- engines/pegasus/fader.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/pegasus/fader.cpp') diff --git a/engines/pegasus/fader.cpp b/engines/pegasus/fader.cpp index 3d8305b2c9..8eb1c0176a 100755 --- a/engines/pegasus/fader.cpp +++ b/engines/pegasus/fader.cpp @@ -24,6 +24,7 @@ */ #include "pegasus/fader.h" +#include "pegasus/sound.h" #include "pegasus/util.h" namespace Pegasus { -- cgit v1.2.3 From fe03cd1bfabeab154573b55216c581bb0af41e9a Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Tue, 27 Sep 2011 12:24:45 -0400 Subject: PEGASUS: Partially revert 4aed723368b9a4e82205bc3ed950a4e04ba3d8dc startFaderSync does indeed to hold the main thread. --- engines/pegasus/fader.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'engines/pegasus/fader.cpp') diff --git a/engines/pegasus/fader.cpp b/engines/pegasus/fader.cpp index 8eb1c0176a..fe292d91f7 100755 --- a/engines/pegasus/fader.cpp +++ b/engines/pegasus/fader.cpp @@ -24,6 +24,7 @@ */ #include "pegasus/fader.h" +#include "pegasus/pegasus.h" #include "pegasus/sound.h" #include "pegasus/util.h" @@ -32,7 +33,6 @@ namespace Pegasus { Fader::Fader() { _currentValue = 0; _currentFaderMove._numKnots = 0; - _syncMode = false; } void Fader::setFaderValue(const uint32 newValue) { @@ -86,14 +86,22 @@ void Fader::startFader(const FaderMoveSpec &spec) { } void Fader::startFaderSync(const FaderMoveSpec &spec) { - if (initFaderMove(spec)) { - _syncMode = true; - + if (initFaderMove(spec)) { setFlags(0); setScale(spec._faderScale); setSegment(spec._knots[0].knotTime, spec._knots[spec._numKnots - 1].knotTime); setTime(spec._knots[0].knotTime); - start(); + start(); + + while (isFading()) { + ((PegasusEngine *)g_engine)->checkCallBacks(); + useIdleTime(); + } + + // Once more, for good measure, to make sure that there are no boundary + // condition problems. + useIdleTime(); + stopFader(); } } @@ -140,18 +148,6 @@ void Fader::timeChanged(const TimeValue newTime) { } } -void Fader::checkCallBacks() { - IdlerTimeBase::checkCallBacks(); - - if (_syncMode && !isRunning()) { - // Once more, for good measure, to make sure that there are no boundary - // condition problems. - useIdleTime(); - stopFader(); - _syncMode = false; - } -} - void FaderMoveSpec::makeOneKnotFaderSpec(const uint32 knotValue) { _numKnots = 1; _knots[0].knotTime = 0; -- cgit v1.2.3 From 59d6b036dc66b6988ee189ba8e55a0b858a81449 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Tue, 27 Sep 2011 19:39:43 -0400 Subject: PEGASUS: Fader values should be signed --- engines/pegasus/fader.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'engines/pegasus/fader.cpp') diff --git a/engines/pegasus/fader.cpp b/engines/pegasus/fader.cpp index fe292d91f7..77ad2cbe4e 100755 --- a/engines/pegasus/fader.cpp +++ b/engines/pegasus/fader.cpp @@ -35,13 +35,13 @@ Fader::Fader() { _currentFaderMove._numKnots = 0; } -void Fader::setFaderValue(const uint32 newValue) { +void Fader::setFaderValue(const int32 newValue) { _currentValue = newValue; } bool Fader::initFaderMove(const FaderMoveSpec &spec) { bool faderMoves = false; - uint32 value = 0; + int32 value = 0; if (spec._numKnots > 0) { stopFader(); @@ -135,7 +135,7 @@ void Fader::timeChanged(const TimeValue newTime) { if (_currentFaderMove._knots[i].knotTime > newTime) break; - uint32 newValue; + int32 newValue; if (i == 0) newValue = _currentFaderMove._knots[0].knotValue; else if (i == _currentFaderMove._numKnots) @@ -148,13 +148,13 @@ void Fader::timeChanged(const TimeValue newTime) { } } -void FaderMoveSpec::makeOneKnotFaderSpec(const uint32 knotValue) { +void FaderMoveSpec::makeOneKnotFaderSpec(const int32 knotValue) { _numKnots = 1; _knots[0].knotTime = 0; _knots[0].knotValue = knotValue; } -void FaderMoveSpec::makeTwoKnotFaderSpec(const TimeScale faderScale, const TimeValue time1, const uint32 value1, const TimeValue time2, const uint32 value2) { +void FaderMoveSpec::makeTwoKnotFaderSpec(const TimeScale faderScale, const TimeValue time1, const int32 value1, const TimeValue time2, const int32 value2) { _numKnots = 2; _faderScale = faderScale; _knots[0].knotTime = time1; @@ -163,7 +163,7 @@ void FaderMoveSpec::makeTwoKnotFaderSpec(const TimeScale faderScale, const TimeV _knots[1].knotValue = value2; } -void FaderMoveSpec::insertFaderKnot(const TimeValue knotTime, const uint32 knotValue) { +void FaderMoveSpec::insertFaderKnot(const TimeValue knotTime, const int32 knotValue) { if (_numKnots != kMaxFaderKnots) { uint32 index; for (index = 0; index < _numKnots; index++) { @@ -184,7 +184,7 @@ void FaderMoveSpec::insertFaderKnot(const TimeValue knotTime, const uint32 knotV } } -void FaderAnimation::setFaderValue(const uint32 newValue) { +void FaderAnimation::setFaderValue(const int32 newValue) { if (getFaderValue() != newValue) { Fader::setFaderValue(newValue); triggerRedraw(); @@ -203,7 +203,7 @@ void SoundFader::attachSound(Sound *sound) { _sound = sound; } -void SoundFader::setFaderValue(const uint32 newVolume) { +void SoundFader::setFaderValue(const int32 newVolume) { if (_sound) _sound->setVolume((newVolume * _masterVolume) >> 8); -- cgit v1.2.3 From 983bd16bb78b1a6aa8872f2086dbcbca6954f2fb Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Tue, 3 Apr 2012 15:23:08 -0400 Subject: PEGASUS: Fix file permissions --- engines/pegasus/fader.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 engines/pegasus/fader.cpp (limited to 'engines/pegasus/fader.cpp') diff --git a/engines/pegasus/fader.cpp b/engines/pegasus/fader.cpp old mode 100755 new mode 100644 -- cgit v1.2.3