From e140aa7baf9cc75ff42729380faa5f76d88b6032 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sat, 1 May 2010 16:20:58 +0000 Subject: [PATCH] Avoid running the old simulation code in the background when it's not needed. Optimise GUI updates to only occur when necessary. Switch to more peaceful music after starting the game. This was SVN commit r7492. --- .../data/mods/public/gui/loading/loading.js | 4 ++ .../data/mods/public/gui/page_session_new.xml | 1 - .../data/mods/public/gui/session_new/music.js | 27 +++++++++ .../mods/public/gui/session_new/selection.js | 13 +++- .../mods/public/gui/session_new/session.js | 19 ++++++ .../mods/public/gui/session_new/session.xml | 9 +-- source/graphics/GameView.cpp | 9 ++- source/graphics/MapWriter.cpp | 39 ++++++------ source/gui/MiniMap.cpp | 39 +++++++----- source/main.cpp | 15 +++-- source/ps/Game.cpp | 14 +++-- source/ps/GameSetup/GameSetup.cpp | 59 +++++++++++++------ source/ps/World.cpp | 6 +- source/renderer/PatchRData.cpp | 3 +- source/renderer/TerrainRenderer.cpp | 24 ++++---- source/simulation2/Simulation2.cpp | 11 ++-- source/simulation2/Simulation2.h | 2 +- .../GameInterface/Handlers/MapHandlers.cpp | 7 ++- .../GameInterface/Handlers/TriggerHandler.cpp | 13 ++++ source/tools/atlas/GameInterface/View.cpp | 16 +++-- 20 files changed, 229 insertions(+), 101 deletions(-) create mode 100644 binaries/data/mods/public/gui/session_new/music.js diff --git a/binaries/data/mods/public/gui/loading/loading.js b/binaries/data/mods/public/gui/loading/loading.js index 86d8cf54c6..a07c22ae60 100644 --- a/binaries/data/mods/public/gui/loading/loading.js +++ b/binaries/data/mods/public/gui/loading/loading.js @@ -34,6 +34,10 @@ function init() function reallyStartGame() { + // Stop the music + if (curr_music) + curr_music.fade(-1, 0.0, 5.0); // fade to 0 over 5 seconds + // This is a reserved function name that is executed by the engine when it is ready // to start the game (ie loading progress has reached 100%). diff --git a/binaries/data/mods/public/gui/page_session_new.xml b/binaries/data/mods/public/gui/page_session_new.xml index 74d32b17bf..76973cb60d 100644 --- a/binaries/data/mods/public/gui/page_session_new.xml +++ b/binaries/data/mods/public/gui/page_session_new.xml @@ -3,7 +3,6 @@ common/setup.xml common/styles.xml common/sprite1.xml - common/init.xml common/icon_sprites.xml session_new/sprites.xml session_new/styles.xml diff --git a/binaries/data/mods/public/gui/session_new/music.js b/binaries/data/mods/public/gui/session_new/music.js new file mode 100644 index 0000000000..2a83ed3df3 --- /dev/null +++ b/binaries/data/mods/public/gui/session_new/music.js @@ -0,0 +1,27 @@ +var g_CurrentMusic = null; + +/* + * At some point, this ought to be extended to do dynamic music selection and + * crossfading - it at least needs to pick the music track based on the player's + * civ and peace/battle + */ + +function startMusic() +{ + var gain = 0.5; + g_CurrentMusic = new Sound("audio/music/germanic_peace_1.ogg"); + if (g_CurrentMusic) + { + g_CurrentMusic.loop(); + g_CurrentMusic.fade(0.0, gain, 10.0); + } +} + +function stopMusic() +{ + if (g_CurrentMusic) + { + g_CurrentMusic.fade(-1, 0.0, 5.0); + g_CurrentMusic = null; + } +} diff --git a/binaries/data/mods/public/gui/session_new/selection.js b/binaries/data/mods/public/gui/session_new/selection.js index c394f3a2a3..9036d12cbb 100644 --- a/binaries/data/mods/public/gui/session_new/selection.js +++ b/binaries/data/mods/public/gui/session_new/selection.js @@ -4,19 +4,25 @@ var g_InactiveSelectionColour = { r:1, g:1, b:1, a:0 }; function _setHighlight(ents, colour) { - Engine.GuiInterfaceCall("SetSelectionHighlight", { "entities":ents, "colour":colour }); + if (ents.length) + Engine.GuiInterfaceCall("SetSelectionHighlight", { "entities":ents, "colour":colour }); } function _setMotionOverlay(ents, enabled) { - Engine.GuiInterfaceCall("SetMotionDebugOverlay", { "entities":ents, "enabled":enabled }); + if (ents.length) + Engine.GuiInterfaceCall("SetMotionDebugOverlay", { "entities":ents, "enabled":enabled }); } function EntitySelection() { + // Private properties: this.selected = {}; // { id: 1, id: 1, ... } for each selected entity ID 'id' this.highlighted = {}; // { id: 1, ... } for mouseover-highlighted entity IDs this.motionDebugOverlay = false; + + // Public properties: + this.dirty = false; // set whenever the selection has changed } EntitySelection.prototype.toggle = function(ent) @@ -33,6 +39,7 @@ EntitySelection.prototype.toggle = function(ent) _setMotionOverlay([ent], this.motionDebugOverlay); this.selected[ent] = 1; } + this.dirty = true; }; EntitySelection.prototype.addList = function(ents) @@ -48,6 +55,7 @@ EntitySelection.prototype.addList = function(ents) } _setHighlight(added, g_ActiveSelectionColour); _setMotionOverlay(added, this.motionDebugOverlay); + this.dirty = true; }; EntitySelection.prototype.reset = function() @@ -55,6 +63,7 @@ EntitySelection.prototype.reset = function() _setHighlight(this.toList(), g_InactiveSelectionColour); _setMotionOverlay(this.toList(), false); this.selected = {}; + this.dirty = true; }; EntitySelection.prototype.toList = function() diff --git a/binaries/data/mods/public/gui/session_new/session.js b/binaries/data/mods/public/gui/session_new/session.js index df4fceb493..b62a0bc1e0 100644 --- a/binaries/data/mods/public/gui/session_new/session.js +++ b/binaries/data/mods/public/gui/session_new/session.js @@ -5,14 +5,27 @@ var g_DevSettings = { function init(initData, hotloadData) { + if (hotloadData) { g_Selection.selected = hotloadData.selection; } + else + { + // Starting for the first time: + startMusic(); + } onSimulationUpdate(); } +function leaveGame() +{ + stopMusic(); + endGame(); + Engine.SwitchGuiPage("page_pregame.xml"); +} + // Return some data that we'll use when hotloading this file after changes function getHotloadData() { @@ -26,10 +39,16 @@ function onTick() // player checks (once it has some player checks) updateCursor(); + + // If the selection changed, we need to regenerate the sim display + if (g_Selection.dirty) + onSimulationUpdate(); } function onSimulationUpdate() { + g_Selection.dirty = false; + var simState = Engine.GuiInterfaceCall("GetSimulationState"); // If we're called during init when the game is first loading, there will be diff --git a/binaries/data/mods/public/gui/session_new/session.xml b/binaries/data/mods/public/gui/session_new/session.xml index 1c38bc1561..a8eb4be026 100644 --- a/binaries/data/mods/public/gui/session_new/session.xml +++ b/binaries/data/mods/public/gui/session_new/session.xml @@ -6,12 +6,9 @@