Permalink
Browse files

Add support for tagging audio files with the 'Stream' file setting to…

… prevent preloading of the entire audio file, for faster startup times.

Take basic steps to make a dead game actually dead so that players don't think they can interact with it.
  • Loading branch information...
1 parent 3c5d7c3 commit a15be6bd2a99383ae97a5113cc3e3c21243dc29b @kg kg committed Jul 11, 2012
@@ -704,6 +704,8 @@ public struct CompressResult {
if (fileSettings.TryGetValue(fileName, out settings))
return new HashSet<string>(settings.ToString().ToLower().Split(' '));
+ else if (fileSettings.TryGetValue(fileName.Replace("\\", "/"), out settings))
+ return new HashSet<string>(settings.ToString().ToLower().Split(' '));
var fileSettingsRegexes = profileSettings["FileSettingsRegexes"] as Dictionary<string, Regex>;
if (fileSettingsRegexes == null) {
@@ -717,6 +719,7 @@ public struct CompressResult {
var regex = new Regex(
Regex.Escape(key)
+ .Replace("/", "\\\\")
.Replace("\\*", "(.*)")
.Replace("\\?", "(.)"),
RegexOptions.Compiled | RegexOptions.IgnoreCase
@@ -1046,6 +1049,8 @@ where bi.OutputPath.EndsWith(".xnb", StringComparison.OrdinalIgnoreCase)
Dictionary<string, object> profileSettings, Dictionary<string, CompressResult> existingJournal,
Action<string, string, Dictionary<string, object>> logOutput
) {
+ var fileSettings = GetFileSettings(profileSettings, fileName);
+
var results = Common.CompressAudio(
fileName, contentProjectDirectory, itemOutputDirectory,
profileSettings, existingJournal
@@ -1057,6 +1062,9 @@ where bi.OutputPath.EndsWith(".xnb", StringComparison.OrdinalIgnoreCase)
{"sizeBytes", results.Max((r) => r.Size)}
};
+ if (fileSettings.Contains("stream"))
+ properties.Add("stream", true);
+
foreach (var result in results)
formats.Add(Path.GetExtension(result.Filename));
View
@@ -645,6 +645,14 @@ var loadHTML5Sound = function (filename, data, onError, onDoneLoading) {
var state = {
loaded: false
};
+
+ var finisher = function () {
+ allAssets[getAssetName(filename)] = new HTML5SoundAsset(getAssetName(filename, true), e);
+ };
+
+ var nullFinisher = function () {
+ allAssets[getAssetName(filename)] = new NullSoundAsset(getAssetName(filename, true));
+ };
var loadingCallback = function (evt) {
if (state.loaded)
@@ -653,14 +661,6 @@ var loadHTML5Sound = function (filename, data, onError, onDoneLoading) {
var networkState = e.networkState || 0;
var readyState = e.readyState || 0;
- var finisher = function () {
- allAssets[getAssetName(filename)] = new HTML5SoundAsset(getAssetName(filename, true), e);
- };
-
- var nullFinisher = function () {
- allAssets[getAssetName(filename)] = new NullSoundAsset(getAssetName(filename, true));
- };
-
if (
(networkState === HTMLMediaElement.NETWORK_IDLE) ||
(networkState === HTMLMediaElement.NETWORK_LOADED /* This is in the spec, but no browser defines it? */) ||
@@ -742,12 +742,26 @@ var loadHTML5Sound = function (filename, data, onError, onDoneLoading) {
if (typeof (e.load) === "function")
e.load();
- state.interval = setInterval(loadingCallback, loadingPollInterval);
+ if (data.stream) {
+ state.loaded = true;
+ onDoneLoading(finisher);
+ } else {
+ state.interval = setInterval(loadingCallback, loadingPollInterval);
+ }
};
// Chrome and Safari's <audio> implementations are utter garbage.
if (typeof (webkitAudioContext) === "function") {
- assetLoaders["Sound"] = loadWebkitSound.bind(new webkitAudioContext());
+ var $audioContext = new webkitAudioContext();
+ var $loadWebkitSound = loadWebkitSound.bind($audioContext);
+
+ assetLoaders["Sound"] = function (filename, data, onError, onDoneLoading) {
+ if (data.stream) {
+ return loadHTML5Sound(filename, data, onError, onDoneLoading);
+ } else {
+ return $loadWebkitSound(filename, data, onError, onDoneLoading);
+ }
+ };
} else {
assetLoaders["Sound"] = loadHTML5Sound;
}
View
@@ -3047,7 +3047,8 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Game", function ($) {
});
$.RawMethod(false, "_QueueStep", function Game_EnqueueTick () {
- if (Microsoft.Xna.Framework.Game._QuitForced) return;
+ if (Microsoft.Xna.Framework.Game._QuitForced || this._isDead)
+ return;
var self = this;
var stepCallback = self._Step.bind(self);
@@ -3207,12 +3208,34 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Game", function ($) {
Static: false,
Public: true
}, "Dispose", new JSIL.MethodSignature(null, [], []), function () {
- if (this._runHandle !== null) window.clearInterval(this._runHandle);
+ if (this._runHandle !== null)
+ window.clearInterval(this._runHandle);
this._runHandle = null;
this.UnloadContent();
this._isDead = true;
+
+ try {
+ var canvas = JSIL.Host.getCanvas();
+ var ctx = canvas.getContext("2d") || canvas.getContext("webgl-2d");
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
+ ctx.globalAlpha = 1;
+ ctx.globalCompositeOperation = "source-over";
+ ctx.fillStyle = "black";
+ ctx.fillRect(0, 0, 99999, 99999);
+
+ canvas.style.display = "none";
+
+ var fsb = document.getElementById("fullscreenButton");
+ if (fsb)
+ fsb.style.display = "none";
+
+ var stats = document.getElementById("stats");
+ if (stats)
+ stats.style.display = "none";
+ } catch (exc) {
+ }
});
});
@@ -12,7 +12,6 @@
<script type="text/javascript">
var jsilConfig = {
printStackTrace: false,
- webgl2d: true,
winForms: true,
xna: 4,
localStorage: true,
@@ -15,7 +15,10 @@
"OverwriteExistingContent": true,
"ContentOutputDirectory": "%configpath%/Soulcaster1Content",
"UsePNGQuant": true,
+ "MP3Quality": "-V 8",
+ "OGGQuality": "-q 2.65",
"FileSettings": {
+ "Music/*": "Stream"
}
}
}
@@ -12,7 +12,6 @@
<script type="text/javascript">
var jsilConfig = {
printStackTrace: false,
- webgl2d: true,
winForms: true,
xna: 4,
localStorage: true,
@@ -15,7 +15,10 @@
"OverwriteExistingContent": true,
"ContentOutputDirectory": "%configpath%/Soulcaster2Content",
"UsePNGQuant": true,
+ "MP3Quality": "-V 8",
+ "OGGQuality": "-q 2.65",
"FileSettings": {
+ "Audio/Music/*": "Stream"
}
}
}

0 comments on commit a15be6b

Please sign in to comment.