diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 6fa6741559..5ac0eed4f4 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -51,12 +51,15 @@ namespace OpenRa.Game static Renderer renderer; static bool usingAftermath; static int2 clientSize; + static HardwarePalette palette; public static void ChangeMap(string mapName) { SheetBuilder.Initialize(renderer); Rules.LoadRules(mapName, usingAftermath); + palette = new HardwarePalette(renderer, Rules.Map); + world = new World(); for (int i = 0; i < 8; i++) @@ -163,7 +166,8 @@ namespace OpenRa.Game using (new PerfSample("tick_time")) { lastTime += timestep; - + UpdatePalette(world.Actors.SelectMany( + a => a.traits.WithInterface())); orderManager.TickImmediate(); if (orderManager.IsReadyForNextFrame) @@ -202,6 +206,16 @@ namespace OpenRa.Game PerfHistory.items["batches"].Tick(); } + static void UpdatePalette(IEnumerable paletteMods) + { + var b = new Bitmap(palette.Bitmap); + foreach (var mod in paletteMods) + mod.AdjustPalette(b); + + palette.Texture.SetData(b); + renderer.PaletteTexture = palette.Texture; + } + public static bool IsCellBuildable(int2 a, UnitMovementType umt) { return IsCellBuildable(a, umt, null); diff --git a/OpenRa.Game/Graphics/HardwarePalette.cs b/OpenRa.Game/Graphics/HardwarePalette.cs index e447545842..83f9c5a2e9 100644 --- a/OpenRa.Game/Graphics/HardwarePalette.cs +++ b/OpenRa.Game/Graphics/HardwarePalette.cs @@ -8,7 +8,7 @@ namespace OpenRa.Game.Graphics const int maxEntries = 16; int allocated = 0; - public HardwarePalette(Renderer renderer, Map map, int rotate) + public HardwarePalette(Renderer renderer, Map map) : base(renderer,new Size(256, maxEntries)) { Palette pal = new Palette(FileSystem.Open(map.Theater + ".pal")); @@ -19,10 +19,10 @@ namespace OpenRa.Game.Graphics AddPalette(new Palette(pal, new PaletteRemap(Color.FromArgb(140, 0, 0, 0)))); - using (var bitmapCopy = new Bitmap(bitmap)) - for (int j = 0; j < maxEntries; j++) - for (int i = 0; i < 7; i++) - this[new Point(0x60 + i, j)] = bitmapCopy.GetPixel(0x60 + (rotate + i) % 7, j); + //using (var bitmapCopy = new Bitmap(bitmap)) + // for (int j = 0; j < maxEntries; j++) + // for (int i = 0; i < 7; i++) + // this[new Point(0x60 + i, j)] = bitmapCopy.GetPixel(0x60 + (rotate + i) % 7, j); } int AddPalette(Palette p) diff --git a/OpenRa.Game/Graphics/Renderer.cs b/OpenRa.Game/Graphics/Renderer.cs index e516a06acb..6edf87e78d 100644 --- a/OpenRa.Game/Graphics/Renderer.cs +++ b/OpenRa.Game/Graphics/Renderer.cs @@ -11,24 +11,16 @@ namespace OpenRa.Game.Graphics internal static int SheetSize; readonly GraphicsDevice device; - Texture[] palettes; + public Shader SpriteShader { get; private set; } /* note: shared shader params */ public Shader LineShader { get; private set; } public Shader RgbaSpriteShader { get; private set; } + public Texture PaletteTexture; + readonly SpriteHelper sh; readonly FontHelper fhDebug, fhTitle; - public void BuildPalette(Map map) - { - palettes = Util.MakeArray(7, i => new HardwarePalette(this, map, 6 - i).Texture); - } - - public void SetPalette(HardwarePalette hp) - { - SpriteShader.SetValue("Palette", hp.Texture); - } - public Renderer(Control host, Size resolution, bool windowed) { host.ClientSize = resolution; @@ -49,14 +41,12 @@ namespace OpenRa.Game.Graphics public GraphicsDevice Device { get { return device; } } - public static float waterFrame = 0.0f; - public void BeginFrame(float2 r1, float2 r2, float2 scroll) { device.Begin(); device.Clear(0, Surfaces.Color); - SpriteShader.SetValue("Palette", palettes[(int)(waterFrame * palettes.Length) % palettes.Length]); + SpriteShader.SetValue("Palette", PaletteTexture); SpriteShader.SetValue("Scroll", scroll); SpriteShader.SetValue("r1", r1); SpriteShader.SetValue("r2", r2); diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 38773e93b8..f658f50865 100755 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -64,7 +64,6 @@ namespace OpenRa.Game SequenceProvider.ForcePrecache(); - renderer.BuildPalette( Rules.Map ); ShowCursor(false); Game.ResetTimer(); } diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index da2905de3e..fbbecf4ed0 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -28,7 +28,6 @@ namespace OpenRa.Game foreach (var a in actors) a.Tick(); foreach (var e in effects) e.Tick(); - Renderer.waterFrame += 0.00125f * Game.timestep; Game.viewport.Tick(); var acts = frameEndActions;