fixes #2885 forgot to enable the cursor palette before drawing

split HardwarePalette.Update into two functions, closes #2847
This commit is contained in:
Matthias Mailänder
2013-04-04 18:41:36 +02:00
parent 6c6f5601d8
commit acc8cd1e5e
6 changed files with 35 additions and 30 deletions

View File

@@ -227,7 +227,7 @@ namespace OpenRA
public static bool IsHost public static bool IsHost
{ {
get get
{ {
var client= orderManager.LobbyInfo.ClientWithIndex ( var client= orderManager.LobbyInfo.ClientWithIndex (
orderManager.Connection.LocalClientId); orderManager.Connection.LocalClientId);

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -20,7 +20,7 @@ namespace OpenRA.Graphics
{ {
public static class CursorProvider public static class CursorProvider
{ {
public static HardwarePalette Palette; static HardwarePalette Palette;
static Dictionary<string, CursorSequence> cursors; static Dictionary<string, CursorSequence> cursors;
public static void Initialize(string[] sequenceFiles) public static void Initialize(string[] sequenceFiles)
@@ -32,22 +32,17 @@ namespace OpenRA.Graphics
if (sequences.NodesDict.ContainsKey("ShadowIndex")) if (sequences.NodesDict.ContainsKey("ShadowIndex"))
{ {
Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1); 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<string, Palette>();
foreach (var s in sequences.NodesDict["Palettes"].Nodes)
palettes.Add(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex));
Palette = new HardwarePalette(); Palette = new HardwarePalette();
foreach (var p in palettes) foreach (var p in sequences.NodesDict["Palettes"].Nodes)
Palette.AddPalette(p.Key, p.Value, false); Palette.AddPalette(p.Key, new Palette(FileSystem.Open(p.Value.Value), ShadowIndex), false);
// Generate initial palette texture
Palette.Update(new IPaletteModifier[] {});
foreach (var s in sequences.NodesDict["Cursors"].Nodes) foreach (var s in sequences.NodesDict["Cursors"].Nodes)
LoadSequencesForCursor(s.Key, s.Value); LoadSequencesForCursor(s.Key, s.Value);
Palette.Initialize();
} }
static void LoadSequencesForCursor(string cursorSrc, MiniYaml cursor) 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) 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); var cursorSprite = cursorSequence.GetSprite(cursorFrame);
renderer.SetPalette(Palette);
renderer.SpriteRenderer.DrawSprite(cursorSprite, renderer.SpriteRenderer.DrawSprite(cursorSprite,
lastMousePos - cursorSequence.Hotspot, lastMousePos - cursorSequence.Hotspot,
Palette.GetPaletteIndex(cursorSequence.Palette), Palette.GetPaletteIndex(cursorSequence.Palette),

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Graphics
public const int MaxPalettes = 256; public const int MaxPalettes = 256;
int allocated = 0; int allocated = 0;
ITexture texture; public ITexture Texture { get; private set; }
Dictionary<string, Palette> palettes; Dictionary<string, Palette> palettes;
Dictionary<string, int> indices; Dictionary<string, int> indices;
Dictionary<string, bool> allowsMods; Dictionary<string, bool> allowsMods;
@@ -32,7 +32,7 @@ namespace OpenRA.Graphics
palettes = new Dictionary<string, Palette>(); palettes = new Dictionary<string, Palette>();
indices = new Dictionary<string, int>(); indices = new Dictionary<string, int>();
allowsMods = new Dictionary<string, bool>(); allowsMods = new Dictionary<string, bool>();
texture = Game.Renderer.Device.CreateTexture(); Texture = Game.Renderer.Device.CreateTexture();
} }
public Palette GetPalette(string name) public Palette GetPalette(string name)
@@ -62,7 +62,7 @@ namespace OpenRA.Graphics
} }
uint[,] data = new uint[MaxPalettes, 256]; uint[,] data = new uint[MaxPalettes, 256];
public void Update(IEnumerable<IPaletteModifier> paletteMods) public void ApplyModifiers(IEnumerable<IPaletteModifier> paletteMods)
{ {
var copy = palettes.ToDictionary(p => p.Key, p => new Palette(p.Value)); 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); 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]; data[j,i] = c[i];
} }
// TODO: Doesn't work (why?) Texture.SetData(data);
texture.SetData(data); }
Game.Renderer.SetPalette(texture);
public void Initialize()
{
ApplyModifiers(new IPaletteModifier[] {});
} }
} }
} }

View File

@@ -73,11 +73,18 @@ namespace OpenRA.Graphics
LineRenderer.SetViewportParams(Resolution, 1f, float2.Zero); LineRenderer.SetViewportParams(Resolution, 1f, float2.Zero);
} }
public void SetPalette(ITexture paletteTexture) ITexture currentPaletteTexture;
public void SetPalette(HardwarePalette palette)
{ {
RgbaSpriteRenderer.SetPalette(paletteTexture); if (palette.Texture == currentPaletteTexture)
SpriteRenderer.SetPalette(paletteTexture); return;
WorldSpriteRenderer.SetPalette(paletteTexture);
Flush();
currentPaletteTexture = palette.Texture;
RgbaSpriteRenderer.SetPalette(currentPaletteTexture);
SpriteRenderer.SetPalette(currentPaletteTexture);
WorldSpriteRenderer.SetPalette(currentPaletteTexture);
} }
public void EndFrame(IInputHandler inputHandler) public void EndFrame(IInputHandler inputHandler)

View File

@@ -127,7 +127,6 @@ namespace OpenRA.Graphics
using( new PerfSample("render_widgets") ) using( new PerfSample("render_widgets") )
{ {
Ui.Draw(); Ui.Draw();
var cursorName = Ui.Root.GetCursorOuter(Viewport.LastMousePos) ?? "default"; var cursorName = Ui.Root.GetCursorOuter(Viewport.LastMousePos) ?? "default";
CursorProvider.DrawCursor(renderer, cursorName, Viewport.LastMousePos, (int)cursorFrame); CursorProvider.DrawCursor(renderer, cursorName, Viewport.LastMousePos, (int)cursorFrame);
} }

View File

@@ -45,10 +45,9 @@ namespace OpenRA.Graphics
palettes = new Cache<string, PaletteReference>(CreatePaletteReference); palettes = new Cache<string, PaletteReference>(CreatePaletteReference);
foreach (var pal in world.traitDict.ActorsWithTraitMultiple<IPalette>(world)) foreach (var pal in world.traitDict.ActorsWithTraitMultiple<IPalette>(world))
pal.Trait.InitPalette( this ); pal.Trait.InitPalette(this);
// Generate initial palette texture palette.Initialize();
palette.Update(new IPaletteModifier[] {});
terrainRenderer = new TerrainRenderer(world, this); terrainRenderer = new TerrainRenderer(world, this);
shroudRenderer = new ShroudRenderer(world); shroudRenderer = new ShroudRenderer(world);
@@ -209,7 +208,8 @@ namespace OpenRA.Graphics
public void RefreshPalette() public void RefreshPalette()
{ {
palette.Update( world.WorldActor.TraitsImplementing<IPaletteModifier>() ); palette.ApplyModifiers(world.WorldActor.TraitsImplementing<IPaletteModifier>());
Game.Renderer.SetPalette(palette);
} }
// Conversion between world and screen coordinates // Conversion between world and screen coordinates