shroud: it works. perf is pretty ugly, and there are a lot of small bugs.

This commit is contained in:
Chris Forbes
2010-01-05 22:12:22 +13:00
parent 27b2d20cab
commit 77da5c89de
11 changed files with 142 additions and 5 deletions

View File

@@ -0,0 +1,9 @@
using System;
using System.Drawing;
namespace OpenRa.FileFormats
{
public interface IPaletteRemap
{
Color GetRemappedColor(Color original, int index);
}
}

View File

@@ -55,6 +55,7 @@
<Compile Include="Format80.cs" />
<Compile Include="IniFile.cs" />
<Compile Include="IniWriter.cs" />
<Compile Include="IPaletteRemap.cs" />
<Compile Include="Map.cs" />
<Compile Include="PackageEntry.cs" />
<Compile Include="Package.cs" />
@@ -62,6 +63,7 @@
<Compile Include="PaletteRemap.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShpReader.cs" />
<Compile Include="ShroudPaletteRemap.cs" />
<Compile Include="Terrain.cs" />
<Compile Include="TileReference.cs" />
<Compile Include="TileSet.cs" />

View File

@@ -31,7 +31,7 @@ namespace OpenRa.FileFormats
colors[4] = Color.FromArgb(140, 0, 0, 0);
}
public Palette(Palette p, PaletteRemap r)
public Palette(Palette p, IPaletteRemap r)
{
for (int i = 0; i < 256; i++)
colors.Add(r.GetRemappedColor(p.GetColor(i), i));

View File

@@ -4,7 +4,7 @@ using System.IO;
namespace OpenRa.FileFormats
{
public class PaletteRemap
public class PaletteRemap : IPaletteRemap
{
int offset;
List<Color> remapColors = new List<Color>();

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace OpenRa.FileFormats
{
public class ShroudPaletteRemap : IPaletteRemap
{
public Color GetRemappedColor(Color original, int index)
{
// false-color version for debug
//return new[] {
// Color.Orange, Color.Green,
// Color.Blue, Color.Yellow,
// Color.Black,
// Color.Red,
// Color.Purple,
// Color.Cyan}[index % 8];
return new[] {
Color.Transparent, Color.Green,
Color.Blue, Color.Yellow,
Color.Black,
Color.FromArgb(192,0,0,0),
Color.FromArgb(128,0,0,0),
Color.FromArgb(64,0,0,0)}[index % 8];
}
}
}

View File

@@ -102,6 +102,12 @@ namespace OpenRa.Game
oreFrequency = (int)(Rules.General.GrowthRate * 60 * 1000);
oreTicks = oreFrequency;
foreach (var a in Game.world.Actors)
if (a.Info != null && a.Owner == players[0])
players[0].Shroud.Explore(a);
Game.world.ActorAdded += a => players[0].Shroud.Explore(a);
}
public static void Initialize(string mapName, Renderer renderer, int2 clientSize,

View File

@@ -3,7 +3,12 @@ using OpenRa.FileFormats;
namespace OpenRa.Game.Graphics
{
public enum PaletteType { Gold, Blue, Red, Orange, Teal, Salmon, Green, Gray, Shadow, Invuln, Chrome };
public enum PaletteType
{
Gold, Blue, Red, Orange, Teal, Salmon, Green, Gray,
Shadow, Invuln, Chrome, Shroud,
};
class HardwarePalette : Sheet
{
const int maxEntries = 16;
@@ -21,6 +26,7 @@ namespace OpenRa.Game.Graphics
AddPalette(new Palette(pal, new PaletteRemap(Color.FromArgb(140, 0, 0, 0))));
AddPalette(pal); // iron curtain. todo: remap!
AddPalette(pal); // chrome (it's like gold, but we're not going to hax it in palettemods)
AddPalette(new Palette(pal, new ShroudPaletteRemap()));
}
int AddPalette(Palette p)

View File

@@ -87,6 +87,8 @@ namespace OpenRa.Game.Graphics
if (Game.controller.orderGenerator != null)
Game.controller.orderGenerator.Render();
Game.LocalPlayer.Shroud.Draw(spriteRenderer);
lineRenderer.Flush();
spriteRenderer.Flush();
}

View File

@@ -3,15 +3,85 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using IjwFramework.Types;
using OpenRa.Game.Graphics;
namespace OpenRa.Game
{
class Shroud
{
bool[,] explored = new bool[128, 128];
Sprite[] shadowBits = SpriteSheetBuilder.LoadAllSprites("shadow");
Sprite[,] sprites = new Sprite[128, 128];
bool dirty;
public void Explore(Actor a)
{
foreach (var t in Game.FindTilesInCircle(a.Location, a.Info.Sight))
explored[t.X, t.Y] = true;
dirty = true;
}
Sprite ChooseShroud(int i, int j)
{
// bits are for exploredness: left, right, up, down, self
var n = new[] {
0xf,0xf,0xf,0xf,
0xf,0x0f,0x0f,0xf,
0xf,0x0f,0x0f,0xf,
0xf,0xf,0xf,0xf,
0,7,13,0,
14,6,12,4,
11,3,9,1,
0,2,8,0,
};
var v = 0;
if (explored[i-1,j]) v |= 1;
if (explored[i+1,j]) v |= 2;
if (explored[i,j-1]) v |= 4;
if (explored[i,j+1]) v |= 8;
if (explored[i, j]) v |= 16;
var x = n[v];
if (x == 0)
{
// bits are for exploredness: TL, TR, BR, BL
var m = new[] {
46, 41, 42, 38,
43, 45, 39, 35,
40, 37, 44, 34,
36, 33, 32, 47,
};
var u = 0;
if (explored[i - 1, j - 1]) u |= 1;
if (explored[i + 1, j - 1]) u |= 2;
if (explored[i + 1, j + 1]) u |= 4;
if (explored[i - 1, j + 1]) u |= 8;
return shadowBits[m[u]];
}
return shadowBits[x];
}
public void Draw(SpriteRenderer r)
{
if (dirty)
{
dirty = false;
for (int j = 1; j < 127; j++)
for (int i = 1; i < 127; i++)
sprites[i, j] = ChooseShroud(i, j);
}
for (var j = 0; j < 128; j++)
for (var i = 0; i < 128; i++)
if (sprites[i,j] != null)
r.DrawSprite(sprites[i, j],
Game.CellSize * new float2(i, j),
PaletteType.Shroud);
}
}
}

View File

@@ -18,7 +18,16 @@ namespace OpenRa.Game.Traits
public int2 toCell
{
get { return self.Location; }
set { Game.UnitInfluence.Remove(self, this); self.Location = value; Game.UnitInfluence.Add(self, this); }
set
{
if (self.Location != value)
{
Game.UnitInfluence.Remove(self, this);
self.Location = value;
self.Owner.Shroud.Explore(self);
}
Game.UnitInfluence.Add(self, this);
}
}
public Mobile(Actor self)

View File

@@ -83,7 +83,8 @@ namespace SequenceEditor
Doc = new XmlDocument();
Doc.Load(XmlFilename);
Pal = new Palette(FileSystem.Open("temperat.pal"));
var tempPal = new Palette(FileSystem.Open("temperat.pal"));
Pal = new Palette(tempPal, new ShroudPaletteRemap());
UnitName = args.FirstOrDefault( x => !x.EndsWith(".xml") );
if (UnitName == null)