diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index d570f0e5ed..ba34fa99e2 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -227,7 +227,7 @@ namespace OpenRA public static bool IsHost { - get + get { var client= orderManager.LobbyInfo.ClientWithIndex ( orderManager.Connection.LocalClientId); diff --git a/OpenRA.Game/Graphics/CursorProvider.cs b/OpenRA.Game/Graphics/CursorProvider.cs index 0896b21be9..4ea40508e0 100644 --- a/OpenRA.Game/Graphics/CursorProvider.cs +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2012 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -20,7 +20,7 @@ namespace OpenRA.Graphics { public static class CursorProvider { - public static HardwarePalette Palette; + static HardwarePalette Palette; static Dictionary cursors; public static void Initialize(string[] sequenceFiles) @@ -32,22 +32,17 @@ namespace OpenRA.Graphics if (sequences.NodesDict.ContainsKey("ShadowIndex")) { Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1); - ShadowIndex[ShadowIndex.Length - 1] = Convert.ToInt32(sequences.NodesDict["ShadowIndex"].Value); + int.TryParse(sequences.NodesDict["ShadowIndex"].Value, out ShadowIndex[ShadowIndex.Length - 1]); } - var palettes = new Dictionary(); - foreach (var s in sequences.NodesDict["Palettes"].Nodes) - palettes.Add(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex)); - Palette = new HardwarePalette(); - foreach (var p in palettes) - Palette.AddPalette(p.Key, p.Value, false); - - // Generate initial palette texture - Palette.Update(new IPaletteModifier[] {}); + foreach (var p in sequences.NodesDict["Palettes"].Nodes) + Palette.AddPalette(p.Key, new Palette(FileSystem.Open(p.Value.Value), ShadowIndex), false); foreach (var s in sequences.NodesDict["Cursors"].Nodes) LoadSequencesForCursor(s.Key, s.Value); + + Palette.Initialize(); } static void LoadSequencesForCursor(string cursorSrc, MiniYaml cursor) @@ -65,9 +60,10 @@ namespace OpenRA.Graphics public static void DrawCursor(Renderer renderer, string cursorName, int2 lastMousePos, int cursorFrame) { - var cursorSequence = CursorProvider.GetCursorSequence(cursorName); + var cursorSequence = GetCursorSequence(cursorName); var cursorSprite = cursorSequence.GetSprite(cursorFrame); - + + renderer.SetPalette(Palette); renderer.SpriteRenderer.DrawSprite(cursorSprite, lastMousePos - cursorSequence.Hotspot, Palette.GetPaletteIndex(cursorSequence.Palette), diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs index f3acab51d0..429735c149 100644 --- a/OpenRA.Game/Graphics/HardwarePalette.cs +++ b/OpenRA.Game/Graphics/HardwarePalette.cs @@ -22,7 +22,7 @@ namespace OpenRA.Graphics public const int MaxPalettes = 256; int allocated = 0; - ITexture texture; + public ITexture Texture { get; private set; } Dictionary palettes; Dictionary indices; Dictionary allowsMods; @@ -32,7 +32,7 @@ namespace OpenRA.Graphics palettes = new Dictionary(); indices = new Dictionary(); allowsMods = new Dictionary(); - texture = Game.Renderer.Device.CreateTexture(); + Texture = Game.Renderer.Device.CreateTexture(); } public Palette GetPalette(string name) @@ -62,7 +62,7 @@ namespace OpenRA.Graphics } uint[,] data = new uint[MaxPalettes, 256]; - public void Update(IEnumerable paletteMods) + public void ApplyModifiers(IEnumerable paletteMods) { var copy = palettes.ToDictionary(p => p.Key, p => new Palette(p.Value)); var modifiable = copy.Where(p => allowsMods[p.Key]).ToDictionary(p => p.Key, p => p.Value); @@ -78,9 +78,12 @@ namespace OpenRA.Graphics data[j,i] = c[i]; } - // TODO: Doesn't work (why?) - texture.SetData(data); - Game.Renderer.SetPalette(texture); + Texture.SetData(data); + } + + public void Initialize() + { + ApplyModifiers(new IPaletteModifier[] {}); } } } diff --git a/OpenRA.Game/Graphics/Renderer.cs b/OpenRA.Game/Graphics/Renderer.cs index 8c1bbd0ea0..6509778669 100644 --- a/OpenRA.Game/Graphics/Renderer.cs +++ b/OpenRA.Game/Graphics/Renderer.cs @@ -73,11 +73,18 @@ namespace OpenRA.Graphics LineRenderer.SetViewportParams(Resolution, 1f, float2.Zero); } - public void SetPalette(ITexture paletteTexture) + ITexture currentPaletteTexture; + public void SetPalette(HardwarePalette palette) { - RgbaSpriteRenderer.SetPalette(paletteTexture); - SpriteRenderer.SetPalette(paletteTexture); - WorldSpriteRenderer.SetPalette(paletteTexture); + if (palette.Texture == currentPaletteTexture) + return; + + Flush(); + currentPaletteTexture = palette.Texture; + + RgbaSpriteRenderer.SetPalette(currentPaletteTexture); + SpriteRenderer.SetPalette(currentPaletteTexture); + WorldSpriteRenderer.SetPalette(currentPaletteTexture); } public void EndFrame(IInputHandler inputHandler) diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 885060c2ce..b3add5a4d4 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -127,7 +127,6 @@ namespace OpenRA.Graphics using( new PerfSample("render_widgets") ) { Ui.Draw(); - var cursorName = Ui.Root.GetCursorOuter(Viewport.LastMousePos) ?? "default"; CursorProvider.DrawCursor(renderer, cursorName, Viewport.LastMousePos, (int)cursorFrame); } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index aee543cc52..c0f19ef77a 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -45,10 +45,9 @@ namespace OpenRA.Graphics palettes = new Cache(CreatePaletteReference); foreach (var pal in world.traitDict.ActorsWithTraitMultiple(world)) - pal.Trait.InitPalette( this ); + pal.Trait.InitPalette(this); - // Generate initial palette texture - palette.Update(new IPaletteModifier[] {}); + palette.Initialize(); terrainRenderer = new TerrainRenderer(world, this); shroudRenderer = new ShroudRenderer(world); @@ -209,7 +208,8 @@ namespace OpenRA.Graphics public void RefreshPalette() { - palette.Update( world.WorldActor.TraitsImplementing() ); + palette.ApplyModifiers(world.WorldActor.TraitsImplementing()); + Game.Renderer.SetPalette(palette); } // Conversion between world and screen coordinates