Merge pull request #6698 from RoosterDragon/memory-savings

Small memory savings
This commit is contained in:
Paul Chote
2014-10-12 11:43:08 +13:00
15 changed files with 79 additions and 82 deletions

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common;
@@ -158,7 +159,7 @@ namespace OpenRA.Mods.RA.AI
bool enabled;
int ticks;
HashSet<int> resourceTypeIndices;
BitArray resourceTypeIndices;
RushFuzzy rushFuzzy = new RushFuzzy();
@@ -208,10 +209,9 @@ namespace OpenRA.Mods.RA.AI
random = new MersenneTwister((int)p.PlayerActor.ActorID);
resourceTypeIndices = new HashSet<int>(
Map.Rules.Actors["world"].Traits
.WithInterface<ResourceTypeInfo>()
.Select(t => world.TileSet.GetTerrainIndex(t.TerrainType)));
resourceTypeIndices = new BitArray(world.TileSet.TerrainInfo.Length); // Big enough
foreach (var t in Map.Rules.Actors["world"].Traits.WithInterface<ResourceTypeInfo>())
resourceTypeIndices.Set(world.TileSet.GetTerrainIndex(t.TerrainType), true);
}
ActorInfo ChooseRandomUnitToBuild(ProductionQueue queue)
@@ -371,7 +371,7 @@ namespace OpenRA.Mods.RA.AI
// Try and place the refinery near a resource field
var nearbyResources = Map.FindTilesInCircle(baseCenter, Info.MaxBaseRadius)
.Where(a => resourceTypeIndices.Contains(Map.GetTerrainIndex(a)))
.Where(a => resourceTypeIndices.Get(Map.GetTerrainIndex(a)))
.Shuffle(random);
foreach (var c in nearbyResources)

View File

@@ -117,7 +117,7 @@ namespace OpenRA.Mods.RA
self.World.Map.CustomTerrain[c] = GetTerrainType(c);
}
int GetTerrainType(CPos cell)
byte GetTerrainType(CPos cell)
{
var dx = cell - self.Location;
var index = dx.X + self.World.TileSet.Templates[template].Size.X * dx.Y;

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Buildings
continue;
// Don't place under other buildings or custom terrain
if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c] != -1)
if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c] != byte.MaxValue)
continue;
var index = Game.CosmeticRandom.Next(template.TilesCount);
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA.Buildings
continue;
// Don't place under other buildings or custom terrain
if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c] != -1)
if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c] != byte.MaxValue)
continue;
layer.AddTile(c, new TerrainTile(template.Id, (byte)i));

View File

@@ -82,7 +82,7 @@ namespace OpenRA.Mods.RA.Move
foreach (var kvp in TerrainSpeeds)
{
int index;
byte index;
if (tileSet.TryGetTerrainIndex(kvp.Key, out index))
info[index] = kvp.Value;
}
@@ -125,7 +125,7 @@ namespace OpenRA.Mods.RA.Move
return int.MaxValue;
var index = world.Map.GetTerrainIndex(cell);
if (index == -1)
if (index == byte.MaxValue)
return int.MaxValue;
return TilesetTerrainInfo[world.TileSet][index].Cost;
@@ -526,7 +526,7 @@ namespace OpenRA.Mods.RA.Move
public int MovementSpeedForCell(Actor self, CPos cell)
{
var index = self.World.Map.GetTerrainIndex(cell);
if (index == -1)
if (index == byte.MaxValue)
return 0;
// TODO: Convert to integers

View File

@@ -203,7 +203,7 @@ namespace OpenRA.Mods.RA
if (--c.Density < 0)
{
content[cell] = EmptyCell;
world.Map.CustomTerrain[cell] = -1;
world.Map.CustomTerrain[cell] = byte.MaxValue;
}
else
content[cell] = c;
@@ -222,7 +222,7 @@ namespace OpenRA.Mods.RA
// Clear cell
content[cell] = EmptyCell;
world.Map.CustomTerrain[cell] = -1;
world.Map.CustomTerrain[cell] = byte.MaxValue;
if (!dirty.Contains(cell))
dirty.Add(cell);