[Scummvm-cvs-logs] scummvm master -> 72aa426770af379223b1572f87c003c540f5a263

eriktorbjorn eriktorbjorn at telia.com
Sat Jun 18 18:34:17 CEST 2011


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:
72aa426770 SWORD25: Fix locale-related bug when reading the volume settings


Commit: 72aa426770af379223b1572f87c003c540f5a263
    https://github.com/scummvm/scummvm/commit/72aa426770af379223b1572f87c003c540f5a263
Author: eriktorbjorn (eriktorbjorn at users.sourceforge.net)
Date: 2011-06-18T09:30:04-07:00

Commit Message:
SWORD25: Fix locale-related bug when reading the volume settings

I don't really like this, but I can't think of any better way. It
seems that Lua doesn't like decimal comma at all, so we have to
format the volume settings with a decimal point instead. Otherwise,
all I'll ever get is either full volume or no volume, with nothing
in between.

Changed paths:
    engines/sword25/util/lua/scummvm_file.cpp
    engines/sword25/util/lua/scummvm_file.h



diff --git a/engines/sword25/util/lua/scummvm_file.cpp b/engines/sword25/util/lua/scummvm_file.cpp
index 9df090f..7667e19 100644
--- a/engines/sword25/util/lua/scummvm_file.cpp
+++ b/engines/sword25/util/lua/scummvm_file.cpp
@@ -32,6 +32,25 @@ Sword25FileProxy::Sword25FileProxy(const Common::String &filename, const Common:
 		setupConfigFile();
 }
 
+Common::String Sword25FileProxy::formatDouble(double value) {
+	// This is a bit hackish. The point of it is that it's important that
+	// we ignore the locale decimal mark and force it to be a point. If it
+	// would happen to be a comma instead, it seems that it's seen as two
+	// comma-separated integers rather than one floating-point value. Or
+	// something like that.
+
+	bool negative = value < 0.0;
+	value = fabs(value);
+	double integerPart = floor(value);
+	double fractionalPart = (value - integerPart) * 1000000.0;
+
+	Common::String out = Common::String::format("%.0f.%.0f", integerPart, fractionalPart);
+	if (negative)
+		out = "-" + out;
+
+	return out;
+}
+
 void Sword25FileProxy::setupConfigFile() {
 	double sfxVolume = !ConfMan.hasKey("sfx_volume") ? 1.0 : 1.0 * ConfMan.getInt("sfx_volume") / 255.0;
 	double musicVolume = !ConfMan.hasKey("music_volume") ? 0.5 : 1.0 * ConfMan.getInt("music_volume") / 255.0;
@@ -45,10 +64,13 @@ MAX_MEMORY_USAGE = 256000000\r\n\
 GFX_VSYNC_ACTIVE = true\r\n\
 SFX_SAMPLING_RATE = 44100\r\n\
 SFX_CHANNEL_COUNT = 32\r\n\
-SFX_SOUND_VOLUME = %f\r\n\
-SFX_MUSIC_VOLUME = %f\r\n\
-SFX_SPEECH_VOLUME = %f\r\n",
-		getLanguage().c_str(), subtitles ? "true" : "false", sfxVolume, musicVolume, speechVolume);
+SFX_SOUND_VOLUME = %s\r\n\
+SFX_MUSIC_VOLUME = %s\r\n\
+SFX_SPEECH_VOLUME = %s\r\n",
+		getLanguage().c_str(), subtitles ? "true" : "false",
+		formatDouble(sfxVolume).c_str(),
+		formatDouble(musicVolume).c_str(),
+		formatDouble(speechVolume).c_str());
 
 	_readPos = 0;
 }
diff --git a/engines/sword25/util/lua/scummvm_file.h b/engines/sword25/util/lua/scummvm_file.h
index a4cbd2a..e8c468e 100644
--- a/engines/sword25/util/lua/scummvm_file.h
+++ b/engines/sword25/util/lua/scummvm_file.h
@@ -37,6 +37,7 @@ private:
 	uint _readPos;
 	Common::String _settings;
 
+	Common::String formatDouble(double value);
 	void setupConfigFile();
 	Common::String getLanguage();
 	void setLanguage(const Common::String &lang);






More information about the Scummvm-git-logs mailing list