@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA;
|
||||
@@ -18,19 +19,29 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class ShroudRendererInfo : ITraitInfo
|
||||
{
|
||||
public string Sequence = "shroud";
|
||||
public string[] Variants = new[] { "shroud" };
|
||||
public readonly string Sequence = "shroud";
|
||||
public readonly string[] ShroudVariants = new[] { "shroud" };
|
||||
public readonly string[] FogVariants = new[] { "fog" };
|
||||
|
||||
public readonly string ShroudPalette = "shroud";
|
||||
public readonly string FogPalette = "fog";
|
||||
|
||||
[Desc("Bitfield of shroud directions for each frame. Lower four bits are",
|
||||
"corners clockwise from TL; upper four are edges clockwise from top")]
|
||||
public int[] Index = new[] { 12, 9, 8, 3, 1, 6, 4, 2, 13, 11, 7, 14 };
|
||||
public readonly int[] Index = new[] { 12, 9, 8, 3, 1, 6, 4, 2, 13, 11, 7, 14 };
|
||||
|
||||
[Desc("Use the upper four bits when calculating frame")]
|
||||
public bool UseExtendedIndex = false;
|
||||
public readonly bool UseExtendedIndex = false;
|
||||
|
||||
[Desc("Palette index for synthesized unexplored tile")]
|
||||
public int ShroudColor = 12;
|
||||
public BlendMode ShroudBlend = BlendMode.Alpha;
|
||||
[Desc("Override for source art that doesn't define a fully shrouded tile")]
|
||||
public readonly string OverrideFullShroud = null;
|
||||
public readonly int OverrideShroudIndex = 15;
|
||||
|
||||
[Desc("Override for source art that doesn't define a fully fogged tile")]
|
||||
public readonly string OverrideFullFog = null;
|
||||
public readonly int OverrideFogIndex = 15;
|
||||
|
||||
public readonly BlendMode ShroudBlend = BlendMode.Alpha;
|
||||
public object Create(ActorInitializer init) { return new ShroudRenderer(init.world, this); }
|
||||
}
|
||||
|
||||
@@ -53,17 +64,15 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
}
|
||||
|
||||
ShroudRendererInfo info;
|
||||
Sprite[] sprites;
|
||||
Sprite unexploredTile;
|
||||
int[] spriteMap;
|
||||
readonly ShroudRendererInfo info;
|
||||
readonly Sprite[] shroudSprites, fogSprites;
|
||||
readonly int[] spriteMap;
|
||||
readonly CellLayer<ShroudTile> tiles;
|
||||
readonly int variantStride;
|
||||
readonly Map map;
|
||||
|
||||
CellLayer<ShroudTile> tiles;
|
||||
int variantStride;
|
||||
|
||||
int shroudHash;
|
||||
PaletteReference fogPalette, shroudPalette;
|
||||
Map map;
|
||||
int shroudHash;
|
||||
|
||||
public ShroudRenderer(World world, ShroudRendererInfo info)
|
||||
{
|
||||
@@ -76,13 +85,33 @@ namespace OpenRA.Mods.RA
|
||||
shroudHash = -1;
|
||||
|
||||
// Load sprite variants
|
||||
sprites = new Sprite[info.Variants.Length * info.Index.Length];
|
||||
variantStride = info.Index.Length;
|
||||
for (var j = 0; j < info.Variants.Length; j++)
|
||||
if (info.ShroudVariants.Length != info.FogVariants.Length)
|
||||
throw new InvalidOperationException("ShroudRenderer must define the same number of shroud and fog variants!");
|
||||
|
||||
if ((info.OverrideFullFog == null) ^ (info.OverrideFullShroud == null))
|
||||
throw new InvalidOperationException("ShroudRenderer must cannot define overrides for only one of shroud or fog!");
|
||||
|
||||
var variantCount = info.ShroudVariants.Length;
|
||||
variantStride = info.Index.Length + (info.OverrideFullShroud != null ? 1 : 0);
|
||||
shroudSprites = new Sprite[variantCount * variantStride];
|
||||
fogSprites = new Sprite[variantCount * variantStride];
|
||||
|
||||
for (var j = 0; j < variantCount; j++)
|
||||
{
|
||||
var seq = map.SequenceProvider.GetSequence(info.Sequence, info.Variants[j]);
|
||||
var shroud = map.SequenceProvider.GetSequence(info.Sequence, info.ShroudVariants[j]);
|
||||
var fog = map.SequenceProvider.GetSequence(info.Sequence, info.FogVariants[j]);
|
||||
for (var i = 0; i < info.Index.Length; i++)
|
||||
sprites[j * variantStride + i] = seq.GetSprite(i);
|
||||
{
|
||||
shroudSprites[j * variantStride + i] = shroud.GetSprite(i);
|
||||
fogSprites[j * variantStride + i] = fog.GetSprite(i);
|
||||
}
|
||||
|
||||
if (info.OverrideFullShroud != null)
|
||||
{
|
||||
var i = (j + 1) * variantStride - 1;
|
||||
shroudSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullShroud).GetSprite(0);
|
||||
fogSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullFog).GetSprite(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Mapping of shrouded directions -> sprite index
|
||||
@@ -90,22 +119,14 @@ namespace OpenRA.Mods.RA
|
||||
for (var i = 0; i < info.Index.Length; i++)
|
||||
spriteMap[info.Index[i]] = i;
|
||||
|
||||
// Synthesize unexplored tile if it isn't defined
|
||||
if (!info.Index.Contains(0))
|
||||
{
|
||||
var ts = Game.modData.Manifest.TileSize;
|
||||
var data = Exts.MakeArray<byte>(ts.Width * ts.Height, _ => (byte)info.ShroudColor);
|
||||
var s = map.SequenceProvider.SpriteLoader.SheetBuilder.Add(data, ts);
|
||||
unexploredTile = new Sprite(s.sheet, s.bounds, s.offset, s.channel, info.ShroudBlend);
|
||||
}
|
||||
else
|
||||
unexploredTile = sprites[spriteMap[0]];
|
||||
if (info.OverrideFullShroud != null)
|
||||
spriteMap[info.OverrideShroudIndex] = variantStride - 1;
|
||||
}
|
||||
|
||||
static int FoggedEdges(Shroud s, CPos p, bool useExtendedIndex)
|
||||
{
|
||||
if (!s.IsVisible(p))
|
||||
return 15;
|
||||
return useExtendedIndex ? 240 : 15;
|
||||
|
||||
// If a side is shrouded then we also count the corners
|
||||
var u = 0;
|
||||
@@ -132,7 +153,7 @@ namespace OpenRA.Mods.RA
|
||||
static int ShroudedEdges(Shroud s, CPos p, bool useExtendedIndex)
|
||||
{
|
||||
if (!s.IsExplored(p))
|
||||
return 15;
|
||||
return useExtendedIndex ? 240 : 15;
|
||||
|
||||
// If a side is shrouded then we also count the corners
|
||||
var u = 0;
|
||||
@@ -179,12 +200,12 @@ namespace OpenRA.Mods.RA
|
||||
foreach (var cell in map.Cells)
|
||||
{
|
||||
var screen = wr.ScreenPosition(cell.CenterPosition);
|
||||
var variant = Game.CosmeticRandom.Next(info.Variants.Length);
|
||||
var variant = Game.CosmeticRandom.Next(info.ShroudVariants.Length);
|
||||
tiles[cell] = new ShroudTile(cell, screen, variant);
|
||||
}
|
||||
|
||||
fogPalette = wr.Palette("fog");
|
||||
shroudPalette = wr.Palette("shroud");
|
||||
fogPalette = wr.Palette(info.FogPalette);
|
||||
shroudPalette = wr.Palette(info.ShroudPalette);
|
||||
}
|
||||
|
||||
Sprite GetTile(int flags, int variant)
|
||||
@@ -192,10 +213,7 @@ namespace OpenRA.Mods.RA
|
||||
if (flags == 0)
|
||||
return null;
|
||||
|
||||
if (flags == 15)
|
||||
return unexploredTile;
|
||||
|
||||
return sprites[variant * variantStride + spriteMap[flags]];
|
||||
return shroudSprites[variant * variantStride + spriteMap[flags]];
|
||||
}
|
||||
|
||||
void Update(Shroud shroud)
|
||||
@@ -213,8 +231,8 @@ namespace OpenRA.Mods.RA
|
||||
var t = tiles[cell];
|
||||
var shrouded = ObserverShroudedEdges(t.Position, map.Bounds, info.UseExtendedIndex);
|
||||
|
||||
t.Shroud = GetTile(shrouded, t.Variant);
|
||||
t.Fog = GetTile(shrouded, t.Variant);
|
||||
t.Shroud = shrouded != 0 ? shroudSprites[t.Variant * variantStride + spriteMap[shrouded]] : null;
|
||||
t.Fog = shrouded != 0 ? fogSprites[t.Variant * variantStride + spriteMap[shrouded]] : null;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -225,8 +243,8 @@ namespace OpenRA.Mods.RA
|
||||
var shrouded = ShroudedEdges(shroud, t.Position, info.UseExtendedIndex);
|
||||
var fogged = FoggedEdges(shroud, t.Position, info.UseExtendedIndex);
|
||||
|
||||
t.Shroud = GetTile(shrouded, t.Variant);
|
||||
t.Fog = GetTile(fogged, t.Variant);
|
||||
t.Shroud = shrouded != 0 ? shroudSprites[t.Variant * variantStride + spriteMap[shrouded]] : null;
|
||||
t.Fog = fogged != 0 ? fogSprites[t.Variant * variantStride + spriteMap[fogged]] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Widgets\Logic\TSInstallFromCDLogic.cs" />
|
||||
<Compile Include="ShroudPalette.cs" />
|
||||
</ItemGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
46
OpenRA.Mods.TS/ShroudPalette.cs
Normal file
46
OpenRA.Mods.TS/ShroudPalette.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.TS
|
||||
{
|
||||
[Desc("Adds the hard-coded shroud palette to the game")]
|
||||
class TSShroudPaletteInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Internal palette name")]
|
||||
public readonly string Name = "shroud";
|
||||
|
||||
public object Create(ActorInitializer init) { return new TSShroudPalette(this); }
|
||||
}
|
||||
|
||||
class TSShroudPalette : IPalette
|
||||
{
|
||||
readonly TSShroudPaletteInfo info;
|
||||
|
||||
public TSShroudPalette(TSShroudPaletteInfo info) { this.info = info; }
|
||||
|
||||
public void InitPalette(WorldRenderer wr)
|
||||
{
|
||||
Func<int, uint> makeColor = i =>
|
||||
{
|
||||
if (i < 128)
|
||||
return (uint)(int2.Lerp(255, 0, i, 127) << 24);
|
||||
return 0;
|
||||
};
|
||||
|
||||
wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => makeColor(i))), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
mods/cnc/bits/fullshroud.shp
Normal file
BIN
mods/cnc/bits/fullshroud.shp
Normal file
Binary file not shown.
@@ -72,7 +72,10 @@ World:
|
||||
Name: fog
|
||||
Fog: true
|
||||
ShroudRenderer:
|
||||
Variants: typea, typeb, typec, typed
|
||||
ShroudVariants: typea, typeb, typec, typed
|
||||
FogVariants: typea, typeb, typec, typed
|
||||
OverrideFullShroud: full
|
||||
OverrideFullFog: full
|
||||
Country@gdi:
|
||||
Name: GDI
|
||||
Race: gdi
|
||||
|
||||
@@ -442,6 +442,7 @@ shroud:
|
||||
typed: shadow
|
||||
Start: 36
|
||||
Length: 12
|
||||
full: fullshroud
|
||||
|
||||
# Note: The order of smudges and craters determines
|
||||
# the index that is mapped to them in maps
|
||||
|
||||
BIN
mods/d2k/bits/fullshroud.shp
Normal file
BIN
mods/d2k/bits/fullshroud.shp
Normal file
Binary file not shown.
@@ -87,9 +87,11 @@ World:
|
||||
Offset: 12007
|
||||
InvertColor: true
|
||||
ShroudRenderer:
|
||||
Variants: typea, typeb, typec, typed
|
||||
ShroudVariants: typea, typeb, typec, typed
|
||||
FogVariants: typea, typeb, typec, typed
|
||||
Index: 11, 3, 7, 9, 6, 13, 12, 14, 4, 8, 2, 1, 5, 10
|
||||
ShroudColor: 31
|
||||
OverrideFullShroud: full
|
||||
OverrideFullFog: full
|
||||
ShroudBlend: Multiply
|
||||
Country@Atreides:
|
||||
Name: Atreides
|
||||
|
||||
@@ -347,6 +347,8 @@ shroud:
|
||||
Length: 14
|
||||
Offset: -16,-16
|
||||
BlendMode: Multiply
|
||||
full: fullshroud
|
||||
BlendMode: Multiply
|
||||
|
||||
rockcraters:
|
||||
rockcrater1: DATA
|
||||
|
||||
@@ -87,6 +87,7 @@ World:
|
||||
Name: fog
|
||||
Fog: true
|
||||
ShroudRenderer:
|
||||
FogVariants: shroud
|
||||
Index: 255, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 20, 40, 56, 65, 97, 130, 148, 194, 24, 33, 66, 132, 28, 41, 67, 134, 1, 2, 4, 8, 3, 6, 12, 9, 7, 14, 13, 11, 5, 10, 15, 255
|
||||
UseExtendedIndex: true
|
||||
Country@0:
|
||||
|
||||
Binary file not shown.
@@ -68,14 +68,13 @@ World:
|
||||
G: 0
|
||||
B: 0
|
||||
A: 180
|
||||
ShroudPalette@shroud:
|
||||
TSShroudPalette@shroud:
|
||||
Type: Shroud
|
||||
ShroudPalette@fog:
|
||||
Name: fog
|
||||
Fog: true
|
||||
ShroudRenderer:
|
||||
Index: 255, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 20, 40, 56, 65, 97, 130, 148, 194, 24, 33, 66, 132, 28, 41, 67, 134, 1, 2, 4, 8, 3, 6, 12, 9, 7, 14, 13, 11, 5, 10, 15, 255
|
||||
UseExtendedIndex: true
|
||||
ShroudPalette: shroud
|
||||
FogPalette: shroud
|
||||
VoxelNormalsPalette@normals:
|
||||
Name: normals
|
||||
Type: TiberianSun
|
||||
|
||||
@@ -385,7 +385,9 @@ resources:
|
||||
ShadowStart: 12
|
||||
|
||||
shroud:
|
||||
shroud: shadow #TODO: use shroud.shp
|
||||
shroud: shroud
|
||||
Length: *
|
||||
fog: fog
|
||||
Length: *
|
||||
|
||||
scorches: #TODO: make use of 07-12 as well
|
||||
|
||||
Reference in New Issue
Block a user