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
{
get
get
{
var client= orderManager.LobbyInfo.ClientWithIndex (
orderManager.Connection.LocalClientId);

View File

@@ -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<string, CursorSequence> 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<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();
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),

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Graphics
public const int MaxPalettes = 256;
int allocated = 0;
ITexture texture;
public ITexture Texture { get; private set; }
Dictionary<string, Palette> palettes;
Dictionary<string, int> indices;
Dictionary<string, bool> allowsMods;
@@ -32,7 +32,7 @@ namespace OpenRA.Graphics
palettes = new Dictionary<string, Palette>();
indices = new Dictionary<string, int>();
allowsMods = new Dictionary<string, bool>();
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<IPaletteModifier> paletteMods)
public void ApplyModifiers(IEnumerable<IPaletteModifier> 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[] {});
}
}
}

View File

@@ -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)

View File

@@ -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);
}

View File

@@ -45,10 +45,9 @@ namespace OpenRA.Graphics
palettes = new Cache<string, PaletteReference>(CreatePaletteReference);
foreach (var pal in world.traitDict.ActorsWithTraitMultiple<IPalette>(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<IPaletteModifier>() );
palette.ApplyModifiers(world.WorldActor.TraitsImplementing<IPaletteModifier>());
Game.Renderer.SetPalette(palette);
}
// Conversion between world and screen coordinates