cache the country lookup to avoid doing it every render tick

This commit is contained in:
Matthias Mailänder
2013-08-08 09:33:17 +02:00
parent fb042056b0
commit 669a95479a
2 changed files with 6 additions and 3 deletions

View File

@@ -70,8 +70,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var ipAddress = orderManager.LobbyInfo.ClientWithIndex(clientIndex).IpAddress;
if ((ipAddress == null || ipAddress == "127.0.0.1") && UPnP.NatDevice != null)
ipAddress = UPnP.NatDevice.GetExternalIP().ToString();
ip.GetText = () => LobbyUtils.DescriptiveIpAddress(ipAddress);
location.GetText = () => LobbyUtils.LookupCountry(ipAddress);
var cachedDescriptiveIP = LobbyUtils.DescriptiveIpAddress(ipAddress);
ip.GetText = () => cachedDescriptiveIP;
var cachedCountryLookup = LobbyUtils.LookupCountry(ipAddress);
location.GetText = () => cachedCountryLookup;
}
}
}

View File

@@ -239,7 +239,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
version.IsVisible = () => !game.CompatibleVersion();
var location = item.Get<LabelWidget>("LOCATION");
location.GetText = () => LobbyUtils.LookupCountry(game.Address.Split(':')[0]);
var cachedServerLocation = LobbyUtils.LookupCountry(game.Address.Split(':')[0]);
location.GetText = () => cachedServerLocation;
location.IsVisible = () => game.CompatibleVersion();
if (!canJoin)