Refactored WaterPaletteRotation

Moved RotationBase from tileset definition to WaterPaletteRotation effect.
Unhardcoded rotation range and rotation rate.
Added possibility to exclude Tilesets from effect.

Fixed RA water palette rotation for actors on desert maps (#8872).
This commit is contained in:
reaperrr
2015-08-18 19:54:50 +02:00
parent 7912e3c7ff
commit ca055eb7bb
10 changed files with 42 additions and 22 deletions

View File

@@ -171,7 +171,6 @@ namespace OpenRA
public readonly int SheetSize = 512; public readonly int SheetSize = 512;
public readonly string Palette; public readonly string Palette;
public readonly string PlayerPalette; public readonly string PlayerPalette;
public readonly int WaterPaletteRotationBase = 0x60;
public readonly Color[] HeightDebugColors = new[] { Color.Red }; public readonly Color[] HeightDebugColors = new[] { Color.Red };
public readonly string[] EditorTemplateOrder; public readonly string[] EditorTemplateOrder;
public readonly bool IgnoreTileSpriteOffsets; public readonly bool IgnoreTileSpriteOffsets;

View File

@@ -15,11 +15,24 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Palette effect used for sprinkle \"animations\" on terrain tiles.")] [Desc("Palette effect used for sprinkle \"animations\".")]
class WaterPaletteRotationInfo : ITraitInfo class WaterPaletteRotationInfo : ITraitInfo
{ {
[Desc("Defines which palettes should be excluded from this effect.")]
public readonly HashSet<string> ExcludePalettes = new HashSet<string>(); public readonly HashSet<string> ExcludePalettes = new HashSet<string>();
[Desc("Don't apply the effect for these tileset IDs.")]
public readonly string[] ExcludeTilesets = { };
[Desc("Palette index of first RotationRange color.")]
public readonly int RotationBase = 0x60;
[Desc("Range of colors to rotate.")]
public readonly int RotationRange = 7;
[Desc("Step towards next color index per tick.")]
public readonly float RotationStep = .25f;
public object Create(ActorInitializer init) { return new WaterPaletteRotation(init.World, this); } public object Create(ActorInitializer init) { return new WaterPaletteRotation(init.World, this); }
} }
@@ -28,35 +41,39 @@ namespace OpenRA.Mods.Common.Traits
readonly WaterPaletteRotationInfo info; readonly WaterPaletteRotationInfo info;
readonly World world; readonly World world;
float t = 0; float t = 0;
uint[] temp;
public WaterPaletteRotation(World world, WaterPaletteRotationInfo info) public WaterPaletteRotation(World world, WaterPaletteRotationInfo info)
{ {
this.world = world; this.world = world;
this.info = info; this.info = info;
temp = new uint[info.RotationRange]; /* allocating this on the fly actually hurts our profile */
} }
public void Tick(Actor self) { t += .25f; } public void Tick(Actor self)
{
uint[] temp = new uint[7]; /* allocating this on the fly actually hurts our profile */ t += info.RotationStep;
}
public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes) public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
{ {
var rotate = (int)t % 7; var rotate = (int)t % info.RotationRange;
if (rotate == 0) if (rotate == 0)
return; return;
foreach (var kvp in palettes) foreach (var kvp in palettes)
{ {
if (info.ExcludePalettes.Contains(kvp.Key)) if (info.ExcludePalettes.Contains(kvp.Key) || info.ExcludeTilesets.Contains(world.TileSet.Id))
continue; continue;
var palette = kvp.Value; var palette = kvp.Value;
for (var i = 0; i < 7; i++) for (var i = 0; i < info.RotationRange; i++)
temp[(rotate + i) % 7] = palette[world.TileSet.WaterPaletteRotationBase + i]; temp[(rotate + i) % info.RotationRange] = palette[info.RotationBase + i];
for (var i = 0; i < 7; i++) for (var i = 0; i < info.RotationRange; i++)
palette[world.TileSet.WaterPaletteRotationBase + i] = temp[i]; palette[info.RotationBase + i] = temp[i];
} }
} }
} }

View File

@@ -73,5 +73,6 @@
CloakPaletteEffect: CloakPaletteEffect:
FlashPaletteEffect: FlashPaletteEffect:
WaterPaletteRotation: WaterPaletteRotation:
ExcludePalettes: effect ExcludePalettes: effect, chrome
RotationBase: 32

View File

@@ -2,7 +2,6 @@ General:
Name: Desert Name: Desert
Id: DESERT Id: DESERT
Palette: desert.pal Palette: desert.pal
WaterPaletteRotationBase: 32
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge
Terrain: Terrain:

View File

@@ -2,7 +2,6 @@ General:
Name: Jungle Name: Jungle
Id: JUNGLE Id: JUNGLE
Palette: jungle.pal Palette: jungle.pal
WaterPaletteRotationBase: 32
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge
Terrain: Terrain:

View File

@@ -2,7 +2,6 @@ General:
Name: Snow Name: Snow
Id: SNOW Id: SNOW
Palette: snow.pal Palette: snow.pal
WaterPaletteRotationBase: 32
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge
Terrain: Terrain:

View File

@@ -2,7 +2,6 @@ General:
Name: Temperate Name: Temperate
Id: TEMPERAT Id: TEMPERAT
Palette: temperat.pal Palette: temperat.pal
WaterPaletteRotationBase: 32
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge
Terrain: Terrain:

View File

@@ -2,7 +2,6 @@ General:
Name: Winter Name: Winter
Id: WINTER Id: WINTER
Palette: winter.pal Palette: winter.pal
WaterPaletteRotationBase: 32
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge
Terrain: Terrain:

View File

@@ -1,7 +1,8 @@
^Palettes: ^Palettes:
PlayerPaletteFromCurrentTileset: PaletteFromFile@player:
Name: player Name: player
ShadowIndex: 3,4 Filename: temperat.pal
ShadowIndex: 4
PaletteFromCurrentTileset: PaletteFromCurrentTileset:
Name: terrain Name: terrain
ShadowIndex: 3,4 ShadowIndex: 3,4
@@ -66,8 +67,16 @@
RemapIndex: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 RemapIndex: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95
PlayerHighlightPalette: PlayerHighlightPalette:
MenuPaletteEffect: MenuPaletteEffect:
WaterPaletteRotation: WaterPaletteRotation@defaultwater:
ExcludePalettes: player, effect ExcludePalettes: chrome
ExcludeTilesets: DESERT
WaterPaletteRotation@actorswater:
ExcludePalettes: chrome, terrain
ExcludeTilesets: TEMPERAT, SNOW, INTERIOR
WaterPaletteRotation@desertwater:
ExcludePalettes: chrome, effect, player
ExcludeTilesets: TEMPERAT, SNOW, INTERIOR
RotationBase: 32
LightPaletteRotator: LightPaletteRotator:
ExcludePalettes: terrain, effect ExcludePalettes: terrain, effect
ChronoshiftPaletteEffect: ChronoshiftPaletteEffect:

View File

@@ -3,7 +3,6 @@ General:
Id: DESERT Id: DESERT
Palette: desert.pal Palette: desert.pal
PlayerPalette: temperat.pal PlayerPalette: temperat.pal
WaterPaletteRotationBase: 32
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Water Cliffs, Beach, River, Bridge EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Water Cliffs, Beach, River, Bridge
Terrain: Terrain: