Fix graphic corruptions by returning the max palette number to 16

This commit is contained in:
Paul Chote
2010-02-04 22:37:17 +13:00
parent 302af4edce
commit 6c99b33364
7 changed files with 30 additions and 17 deletions

View File

@@ -36,7 +36,7 @@ namespace OpenRa
if (name != null)
{
Log.Write("Loading {0}",name.ToLowerInvariant());
//Log.Write("Loading {0}",name.ToLowerInvariant());
Info = Rules.Info[name.ToLowerInvariant()];
Health = this.GetMaxHP();

View File

@@ -8,17 +8,18 @@ namespace OpenRa.Graphics
{
class HardwarePalette : Sheet
{
const int maxEntries = 32;
const int maxEntries = 16;
int allocated = 0;
// We need to store the Palettes themselves for the remap palettes to work
// We should probably try to fix this somehow
static Dictionary<string, Palette> palettes;
static Dictionary<string, int> indices;
public HardwarePalette(Renderer renderer, Map map)
: base(renderer,new Size(256, maxEntries))
{
palettes = new Dictionary<string, Palette>();
indices = new Dictionary<string, int>();
}
public Palette GetPalette(string name)
@@ -31,9 +32,20 @@ namespace OpenRa.Graphics
}
}
public int GetPaletteIndex(string name)
{
try { return indices[name]; }
catch (KeyNotFoundException)
{
throw new InvalidOperationException(
"Palette `{0}` does not exist".F(name));
}
}
public int AddPalette(string name, Palette p)
{
palettes.Add(name, p);
indices.Add(name, allocated);
for (int i = 0; i < 256; i++)
{
this[new Point(i, allocated)] = p.GetColor(i);

View File

@@ -34,9 +34,9 @@ namespace OpenRa.Graphics
for( int i = map.XOffset ; i < map.XOffset + map.Width; i++ )
{
Sprite tile = tileMapping[map.MapTiles[i, j]];
//var bar = Game.world.WorldRenderer;
var foo = wr.GetPaletteIndex("terrain");
Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, foo, nv, ni, tile.size);
// TODO: The zero below should explicitly refer to the terrain palette, but this code is called
// before the palettes are created
Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, 0, nv, ni, tile.size);
nv += 4;
ni += 6;
}

View File

@@ -35,7 +35,7 @@ namespace OpenRa.Graphics
// TODO: Implement
public int GetPaletteIndex(string name)
{
return 0;
return palette.GetPaletteIndex(name);
}
public Palette GetPalette(string name)

View File

@@ -20,7 +20,7 @@ namespace OpenRa.Traits
if (info.Theatre == null ||
info.Theatre.ToLowerInvariant() == self.World.Map.Theater.ToLowerInvariant())
{
Log.Write("Loading palette {0} from file {1}", info.Name, info.Filename);
//Log.Write("Loading palette {0} from file {1}", info.Name, info.Filename);
self.World.WorldRenderer.AddPalette(info.Name, new Palette(FileSystem.Open(info.Filename)));
}
}

View File

@@ -18,6 +18,7 @@ namespace OpenRa.Traits
// TODO: This shouldn't rely on a base palette
var wr = self.World.WorldRenderer;
var pal = wr.GetPalette("terrain");
wr.AddPalette("shroud", new Palette(pal, new ShroudPaletteRemap()));
}
}

View File

@@ -44,14 +44,14 @@ World:
Name: player5
BasePalette: player
Remap: salmon.rem
PaletteFromRemap@player6:
Name: player6
BasePalette: player
Remap: green.rem
PaletteFromRemap@player7:
Name: player7
BasePalette: player
Remap: gray.rem
# PaletteFromRemap@player6:
# Name: player6
# BasePalette: player
# Remap: green.rem
# PaletteFromRemap@player7:
# Name: player7
# BasePalette: player
# Remap: gray.rem
PaletteFromFile@chrome:
Name: chrome
Filename: temperat.pal