1
0
forked from 0ad/0ad

# 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.
This commit is contained in:
Matei 2006-07-17 02:27:55 +00:00
parent f0ec100d1a
commit 9b98a19506

View File

@ -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++;
}
}
}
}
}