Make Color use uint for ARGB.

This is a more natural representation than int that allows removal of casts in many places that require uint. Additionally, we can change the internal representation from long to uint, making the Color struct smaller. Since arrays of colors are common, this can save on memory.
This commit is contained in:
RoosterDragon
2024-03-02 12:02:06 +00:00
committed by Gustas
parent 7b82d85b27
commit 5f97e2de5a
15 changed files with 35 additions and 40 deletions

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
readonly World world;
IRadarTerrainLayer[] radarTerrainLayers;
CellLayer<(int, int)> terrainColor;
CellLayer<(uint, uint)> terrainColor;
readonly Shroud shroud;
public event Action<MPos> CellTerrainColorChanged = null;
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits
public void WorldLoaded(World w, WorldRenderer wr)
{
radarTerrainLayers = w.WorldActor.TraitsImplementing<IRadarTerrainLayer>().ToArray();
terrainColor = new CellLayer<(int, int)>(w.Map);
terrainColor = new CellLayer<(uint, uint)>(w.Map);
w.AddFrameEndTask(_ =>
{
@@ -82,9 +82,9 @@ namespace OpenRA.Mods.Common.Traits
});
}
public (int Left, int Right) this[MPos uv] => terrainColor[uv];
public (uint Left, uint Right) this[MPos uv] => terrainColor[uv];
public static (int Left, int Right) GetColor(Map map, IRadarTerrainLayer[] radarTerrainLayers, MPos uv)
public static (uint Left, uint Right) GetColor(Map map, IRadarTerrainLayer[] radarTerrainLayers, MPos uv)
{
foreach (var rtl in radarTerrainLayers)
if (rtl.TryGetTerrainColorPair(uv, out var c))