From 9b98a195067cf578255a4231b227999d6174bf85 Mon Sep 17 00:00:00 2001 From: Matei Date: Mon, 17 Jul 2006 02:27:55 +0000 Subject: [PATCH] # Faster GUI resource counter updates. These seemed to be eating up 100 MS per frame! I've made the GUI remember old resource values and only refresh counters when they change, but this is still really bad performance, because in a real game we'll have resource values changing every second. We need to find a much better way to lay out those resource counter elements. This was SVN commit r4127. --- .../official/gui/test/functions_sim_player.js | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/binaries/data/mods/official/gui/test/functions_sim_player.js b/binaries/data/mods/official/gui/test/functions_sim_player.js index 31cd4be2aa..9515ff5e56 100644 --- a/binaries/data/mods/official/gui/test/functions_sim_player.js +++ b/binaries/data/mods/official/gui/test/functions_sim_player.js @@ -14,7 +14,6 @@ function createResourceCounters() addResourceCounter(2, "stone"); addResourceCounter(3, "ore"); addResourceCounter(4, "population"); - addResourceCounter(5, "housing"); } // ==================================================================== @@ -44,19 +43,40 @@ function addResourceCounter (index, resourceName) // ==================================================================== +// HACK: Keep track of old resource values so we only update resource counters as necessary. +// We should really find a *much* faster way to render those counters, since resource values are bound to change quite quickly in a real game. +var oldResources = new Object(); + function refreshResources () { // Refreshes all resource counters after update. var resourcePool = localPlayer.resources; - var resourceCount = 0; + + var shouldRefresh = false; for (var currResource in resourcePool) { - if(currResource != "housing") + if( oldResources[currResource] != localPlayer.resources[currResource] ) { - // Pass the array index of the resource as the second parameter (as we'll need that to determine the centered screen position of each counter). - refreshResource (toTitleCase(currResource), resourceUIArray[resourceCount]); - resourceCount++; + oldResources[currResource] = localPlayer.resources[currResource].valueOf(); + shouldRefresh = true; + } + } + + if( shouldRefresh ) + { + for( var i=0; i<2; i++ ) // 2 refreshes seem to be necessary for proper alignment + { + var resourceCount = 0; + for (var currResource in resourcePool) + { + if(currResource != "housing") + { + // Pass the array index of the resource as the second parameter (as we'll need that to determine the centered screen position of each counter). + refreshResource (toTitleCase(currResource), resourceUIArray[resourceCount]); + resourceCount++; + } + } } } }