From 03bda8b511377a7adfeb1b9d9bacbb3d0d2473db Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 5 Mar 2011 18:34:52 +1300 Subject: [PATCH] strip all the allocation out of WaterPaletteRotation too (saves ~25M/min) --- OpenRA.Mods.RA/WaterPaletteRotation.cs | 30 +++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/OpenRA.Mods.RA/WaterPaletteRotation.cs b/OpenRA.Mods.RA/WaterPaletteRotation.cs index 17c64bc259..47043892bd 100644 --- a/OpenRA.Mods.RA/WaterPaletteRotation.cs +++ b/OpenRA.Mods.RA/WaterPaletteRotation.cs @@ -6,12 +6,12 @@ * as published by the Free Software Foundation. For more information, * see COPYING. */ -#endregion - -using System.Drawing; +#endregion + +using System.Collections.Generic; +using System.Linq; +using OpenRA.FileFormats; using OpenRA.Traits; -using System.Collections.Generic; -using OpenRA.FileFormats; namespace OpenRA.Mods.RA { @@ -22,20 +22,26 @@ namespace OpenRA.Mods.RA public void Tick(Actor self) { t += .25f; - } + } + + static string[] excludePalettes = { "cursor", "chrome", "colorpicker" }; + static uint[] temp = new uint[7]; public void AdjustPalette(Dictionary palettes) { - var excludePalettes = new List(){"cursor", "chrome", "colorpicker"}; foreach (var pal in palettes) { if (excludePalettes.Contains(pal.Key)) - continue; - - var copy = (uint[])pal.Value.Values.Clone(); + continue; + + var colors = pal.Value.Values; var rotate = (int)t % 7; - for (int i = 0; i < 7; i++) - pal.Value.SetColor(0x60 + (rotate + i) % 7, copy[0x60 + i]); + + for (var i = 0; i < 7; i++) + temp[(rotate + i) % 7] = colors[0x60 + i]; + + for (var i = 0; i < 7; i++) + pal.Value.SetColor(0x60 + i, temp[i]); } } }