[Scummvm-cvs-logs] scummvm master -> 9ec8c509da0db5d1b172ab30e13e93948c70e419

somaen einarjohants at gmail.com
Tue Jan 22 15:45:29 CET 2013


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

Summary:
9ec8c509da WINTERMUTE: Lie to the scripts about the exact master volume-% to avoid round-off-issues.


Commit: 9ec8c509da0db5d1b172ab30e13e93948c70e419
    https://github.com/scummvm/scummvm/commit/9ec8c509da0db5d1b172ab30e13e93948c70e419
Author: Einar Johan Trøan Sømåen (einarjohants at gmail.com)
Date: 2013-01-22T06:42:56-08:00

Commit Message:
WINTERMUTE: Lie to the scripts about the exact master volume-% to avoid round-off-issues.
(Fix Bug #3592875)

Changed paths:
    engines/wintermute/base/sound/base_sound_manager.cpp
    engines/wintermute/base/sound/base_sound_manager.h



diff --git a/engines/wintermute/base/sound/base_sound_manager.cpp b/engines/wintermute/base/sound/base_sound_manager.cpp
index 4417931..f5f1190 100644
--- a/engines/wintermute/base/sound/base_sound_manager.cpp
+++ b/engines/wintermute/base/sound/base_sound_manager.cpp
@@ -26,6 +26,7 @@
  * Copyright (c) 2011 Jan Nedoma
  */
 
+#include <math.h>
 #include "engines/wintermute/base/sound/base_sound_manager.h"
 #include "engines/wintermute/base/base_engine.h"
 #include "engines/wintermute/utils/path_util.h"
@@ -50,6 +51,7 @@ namespace Wintermute {
 BaseSoundMgr::BaseSoundMgr(BaseGame *inGame) : BaseClass(inGame) {
 	_soundAvailable = false;
 	_volumeMaster = 255;
+	_volumeMasterPercent = 100;
 }
 
 
@@ -217,6 +219,11 @@ byte BaseSoundMgr::getVolumePercent(Audio::Mixer::SoundType type) {
 
 //////////////////////////////////////////////////////////////////////////
 bool BaseSoundMgr::setMasterVolume(byte value) {
+	// This function intentionally doesn't touch _volumeMasterPercent,
+	// as that variable keeps track of what the game actually wanted,
+	// and this gives a close approximation, while letting the game
+	// be none the wiser about round-off-errors. This function should thus
+	// ONLY be called by setMasterVolumePercent.
 	_volumeMaster = value;
 	for (uint32 i = 0; i < _sounds.size(); i++) {
 		_sounds[i]->updateVolume();
@@ -226,14 +233,15 @@ bool BaseSoundMgr::setMasterVolume(byte value) {
 
 //////////////////////////////////////////////////////////////////////////
 bool BaseSoundMgr::setMasterVolumePercent(byte percent) {
-	setMasterVolume(percent * 255 / 100);
+	_volumeMasterPercent = percent;
+	setMasterVolume((int)ceil(percent * 255.0 / 100.0));
 	return STATUS_OK;
 }
 
 
 //////////////////////////////////////////////////////////////////////////
 byte BaseSoundMgr::getMasterVolumePercent() {
-	return getMasterVolume() * 100 / 255;
+	return _volumeMasterPercent;
 }
 
 //////////////////////////////////////////////////////////////////////////
diff --git a/engines/wintermute/base/sound/base_sound_manager.h b/engines/wintermute/base/sound/base_sound_manager.h
index 36a729b..1ee3c13 100644
--- a/engines/wintermute/base/sound/base_sound_manager.h
+++ b/engines/wintermute/base/sound/base_sound_manager.h
@@ -45,7 +45,6 @@ public:
 	//DECLARE_PERSISTENT(BaseSoundMgr, BaseClass);
 	byte getMasterVolumePercent();
 	byte getMasterVolume();
-	bool setMasterVolume(byte percent);
 	bool setMasterVolumePercent(byte percent);
 	byte getVolumePercent(Audio::Mixer::SoundType type);
 	bool setVolumePercent(Audio::Mixer::SoundType type, byte percent);
@@ -61,6 +60,9 @@ public:
 	virtual ~BaseSoundMgr();
 	Common::Array<BaseSoundBuffer *> _sounds;
 	void saveSettings();
+private:
+	int _volumeMasterPercent; // Necessary to avoid round-offs.
+	bool setMasterVolume(byte percent);
 };
 
 } // end of namespace Wintermute






More information about the Scummvm-git-logs mailing list