From ca055eb7bb78ab2718b3730ea338a0831a8912b0 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Tue, 18 Aug 2015 19:54:50 +0200 Subject: [PATCH 1/5] 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). --- OpenRA.Game/Map/TileSet.cs | 1 - .../PaletteEffects/WaterPaletteRotation.cs | 37 ++++++++++++++----- mods/cnc/rules/palettes.yaml | 3 +- mods/cnc/tilesets/desert.yaml | 1 - mods/cnc/tilesets/jungle.yaml | 1 - mods/cnc/tilesets/snow.yaml | 1 - mods/cnc/tilesets/temperat.yaml | 1 - mods/cnc/tilesets/winter.yaml | 1 - mods/ra/rules/palettes.yaml | 17 +++++++-- mods/ra/tilesets/desert.yaml | 1 - 10 files changed, 42 insertions(+), 22 deletions(-) diff --git a/OpenRA.Game/Map/TileSet.cs b/OpenRA.Game/Map/TileSet.cs index 35dbe6391b..5ae0d38808 100644 --- a/OpenRA.Game/Map/TileSet.cs +++ b/OpenRA.Game/Map/TileSet.cs @@ -171,7 +171,6 @@ namespace OpenRA public readonly int SheetSize = 512; public readonly string Palette; public readonly string PlayerPalette; - public readonly int WaterPaletteRotationBase = 0x60; public readonly Color[] HeightDebugColors = new[] { Color.Red }; public readonly string[] EditorTemplateOrder; public readonly bool IgnoreTileSpriteOffsets; diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/WaterPaletteRotation.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/WaterPaletteRotation.cs index bb973554be..9366e12dc4 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/WaterPaletteRotation.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/WaterPaletteRotation.cs @@ -15,11 +15,24 @@ using OpenRA.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 { + [Desc("Defines which palettes should be excluded from this effect.")] public readonly HashSet ExcludePalettes = new HashSet(); + [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); } } @@ -28,35 +41,39 @@ namespace OpenRA.Mods.Common.Traits readonly WaterPaletteRotationInfo info; readonly World world; float t = 0; + uint[] temp; public WaterPaletteRotation(World world, WaterPaletteRotationInfo info) { this.world = world; this.info = info; + + temp = new uint[info.RotationRange]; /* allocating this on the fly actually hurts our profile */ } - public void Tick(Actor self) { t += .25f; } - - uint[] temp = new uint[7]; /* allocating this on the fly actually hurts our profile */ + public void Tick(Actor self) + { + t += info.RotationStep; + } public void AdjustPalette(IReadOnlyDictionary palettes) { - var rotate = (int)t % 7; + var rotate = (int)t % info.RotationRange; if (rotate == 0) return; foreach (var kvp in palettes) { - if (info.ExcludePalettes.Contains(kvp.Key)) + if (info.ExcludePalettes.Contains(kvp.Key) || info.ExcludeTilesets.Contains(world.TileSet.Id)) continue; var palette = kvp.Value; - for (var i = 0; i < 7; i++) - temp[(rotate + i) % 7] = palette[world.TileSet.WaterPaletteRotationBase + i]; + for (var i = 0; i < info.RotationRange; i++) + temp[(rotate + i) % info.RotationRange] = palette[info.RotationBase + i]; - for (var i = 0; i < 7; i++) - palette[world.TileSet.WaterPaletteRotationBase + i] = temp[i]; + for (var i = 0; i < info.RotationRange; i++) + palette[info.RotationBase + i] = temp[i]; } } } diff --git a/mods/cnc/rules/palettes.yaml b/mods/cnc/rules/palettes.yaml index e789ef80f7..89827675e8 100644 --- a/mods/cnc/rules/palettes.yaml +++ b/mods/cnc/rules/palettes.yaml @@ -73,5 +73,6 @@ CloakPaletteEffect: FlashPaletteEffect: WaterPaletteRotation: - ExcludePalettes: effect + ExcludePalettes: effect, chrome + RotationBase: 32 diff --git a/mods/cnc/tilesets/desert.yaml b/mods/cnc/tilesets/desert.yaml index 8f701b694f..99ac158dce 100644 --- a/mods/cnc/tilesets/desert.yaml +++ b/mods/cnc/tilesets/desert.yaml @@ -2,7 +2,6 @@ General: Name: Desert Id: DESERT Palette: desert.pal - WaterPaletteRotationBase: 32 EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge Terrain: diff --git a/mods/cnc/tilesets/jungle.yaml b/mods/cnc/tilesets/jungle.yaml index 159338d2ae..6ac22b82df 100644 --- a/mods/cnc/tilesets/jungle.yaml +++ b/mods/cnc/tilesets/jungle.yaml @@ -2,7 +2,6 @@ General: Name: Jungle Id: JUNGLE Palette: jungle.pal - WaterPaletteRotationBase: 32 EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge Terrain: diff --git a/mods/cnc/tilesets/snow.yaml b/mods/cnc/tilesets/snow.yaml index e5c63e7a47..1b9bb99754 100644 --- a/mods/cnc/tilesets/snow.yaml +++ b/mods/cnc/tilesets/snow.yaml @@ -2,7 +2,6 @@ General: Name: Snow Id: SNOW Palette: snow.pal - WaterPaletteRotationBase: 32 EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge Terrain: diff --git a/mods/cnc/tilesets/temperat.yaml b/mods/cnc/tilesets/temperat.yaml index c52dd85935..ed055b6e4a 100644 --- a/mods/cnc/tilesets/temperat.yaml +++ b/mods/cnc/tilesets/temperat.yaml @@ -2,7 +2,6 @@ General: Name: Temperate Id: TEMPERAT Palette: temperat.pal - WaterPaletteRotationBase: 32 EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge Terrain: diff --git a/mods/cnc/tilesets/winter.yaml b/mods/cnc/tilesets/winter.yaml index df72d2ae41..41777bce49 100644 --- a/mods/cnc/tilesets/winter.yaml +++ b/mods/cnc/tilesets/winter.yaml @@ -2,7 +2,6 @@ General: Name: Winter Id: WINTER Palette: winter.pal - WaterPaletteRotationBase: 32 EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge Terrain: diff --git a/mods/ra/rules/palettes.yaml b/mods/ra/rules/palettes.yaml index 16878f3e3c..ce48348e28 100644 --- a/mods/ra/rules/palettes.yaml +++ b/mods/ra/rules/palettes.yaml @@ -1,7 +1,8 @@ ^Palettes: - PlayerPaletteFromCurrentTileset: + PaletteFromFile@player: Name: player - ShadowIndex: 3,4 + Filename: temperat.pal + ShadowIndex: 4 PaletteFromCurrentTileset: Name: terrain ShadowIndex: 3,4 @@ -66,8 +67,16 @@ RemapIndex: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 PlayerHighlightPalette: MenuPaletteEffect: - WaterPaletteRotation: - ExcludePalettes: player, effect + WaterPaletteRotation@defaultwater: + 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: ExcludePalettes: terrain, effect ChronoshiftPaletteEffect: diff --git a/mods/ra/tilesets/desert.yaml b/mods/ra/tilesets/desert.yaml index 2afd0f8597..db84afc260 100644 --- a/mods/ra/tilesets/desert.yaml +++ b/mods/ra/tilesets/desert.yaml @@ -3,7 +3,6 @@ General: Id: DESERT Palette: desert.pal PlayerPalette: temperat.pal - WaterPaletteRotationBase: 32 EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Water Cliffs, Beach, River, Bridge Terrain: From 96c7d4345ec1ac56a0e6ff068cf404230686ac8f Mon Sep 17 00:00:00 2001 From: reaperrr Date: Tue, 18 Aug 2015 22:14:49 +0200 Subject: [PATCH 2/5] Renamed WaterPaletteRotation to RotationPaletteEffect --- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 2 +- ...rPaletteRotation.cs => RotationPaletteEffect.cs} | 13 +++++++------ OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs | 7 +++++++ mods/cnc/rules/palettes.yaml | 2 +- mods/ra/rules/palettes.yaml | 6 +++--- 5 files changed, 19 insertions(+), 11 deletions(-) rename OpenRA.Mods.Common/Traits/PaletteEffects/{WaterPaletteRotation.cs => RotationPaletteEffect.cs} (81%) diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 4fbdae0ae0..53799a1de7 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -366,7 +366,7 @@ - + diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/WaterPaletteRotation.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs similarity index 81% rename from OpenRA.Mods.Common/Traits/PaletteEffects/WaterPaletteRotation.cs rename to OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs index 9366e12dc4..8a343594e1 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/WaterPaletteRotation.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs @@ -16,7 +16,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("Palette effect used for sprinkle \"animations\".")] - class WaterPaletteRotationInfo : ITraitInfo + class RotationPaletteEffectInfo : ITraitInfo { [Desc("Defines which palettes should be excluded from this effect.")] public readonly HashSet ExcludePalettes = new HashSet(); @@ -33,22 +33,23 @@ namespace OpenRA.Mods.Common.Traits [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 RotationPaletteEffect(init.World, this); } } - class WaterPaletteRotation : ITick, IPaletteModifier + class RotationPaletteEffect : ITick, IPaletteModifier { - readonly WaterPaletteRotationInfo info; + readonly RotationPaletteEffectInfo info; readonly World world; float t = 0; uint[] temp; - public WaterPaletteRotation(World world, WaterPaletteRotationInfo info) + public RotationPaletteEffect(World world, RotationPaletteEffectInfo info) { this.world = world; this.info = info; - temp = new uint[info.RotationRange]; /* allocating this on the fly actually hurts our profile */ + // Allocating this on the fly actually hurts our profile + temp = new uint[info.RotationRange]; } public void Tick(Actor self) diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 7138902dc0..b6b42cecfd 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -2051,6 +2051,13 @@ namespace OpenRA.Mods.Common.UtilityCommands } } + // WaterPaletteRotation renamed to RotationPaletteEffect + if (engineVersion < 20150903) + { + if (depth == 1 && node.Key == "WaterPaletteRotation") + node.Key = "RotationPaletteEffect"; + } + UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); } } diff --git a/mods/cnc/rules/palettes.yaml b/mods/cnc/rules/palettes.yaml index 89827675e8..819c0ddfc2 100644 --- a/mods/cnc/rules/palettes.yaml +++ b/mods/cnc/rules/palettes.yaml @@ -72,7 +72,7 @@ MenuEffect: Desaturated CloakPaletteEffect: FlashPaletteEffect: - WaterPaletteRotation: + RotationPaletteEffect@water: ExcludePalettes: effect, chrome RotationBase: 32 diff --git a/mods/ra/rules/palettes.yaml b/mods/ra/rules/palettes.yaml index ce48348e28..a4a91689a8 100644 --- a/mods/ra/rules/palettes.yaml +++ b/mods/ra/rules/palettes.yaml @@ -67,13 +67,13 @@ RemapIndex: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 PlayerHighlightPalette: MenuPaletteEffect: - WaterPaletteRotation@defaultwater: + RotationPaletteEffect@defaultwater: ExcludePalettes: chrome ExcludeTilesets: DESERT - WaterPaletteRotation@actorswater: + RotationPaletteEffect@actorswater: ExcludePalettes: chrome, terrain ExcludeTilesets: TEMPERAT, SNOW, INTERIOR - WaterPaletteRotation@desertwater: + RotationPaletteEffect@desertwater: ExcludePalettes: chrome, effect, player ExcludeTilesets: TEMPERAT, SNOW, INTERIOR RotationBase: 32 From cd9effaa35c3983c2afd5542a19bf53aa3b18b5d Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sun, 23 Aug 2015 00:39:20 +0200 Subject: [PATCH 3/5] Added positive palette/tileset properties to RotationPaletteEffect --- .../PaletteEffects/RotationPaletteEffect.cs | 15 +++++++++++++-- mods/ra/rules/palettes.yaml | 9 ++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs index 8a343594e1..d5d105a41c 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs @@ -18,11 +18,19 @@ namespace OpenRA.Mods.Common.Traits [Desc("Palette effect used for sprinkle \"animations\".")] class RotationPaletteEffectInfo : ITraitInfo { + [Desc("Defines to which palettes this effect should be applied to.", + "If none specified, it applies to all palettes not explicitly excluded.")] + public readonly HashSet Palettes = new HashSet(); + + [Desc("Defines for which tileset IDs this effect should be loaded.", + "If none specified, it applies to all tileset IDs not explicitly excluded.")] + public readonly string[] Tilesets = null; + [Desc("Defines which palettes should be excluded from this effect.")] public readonly HashSet ExcludePalettes = new HashSet(); [Desc("Don't apply the effect for these tileset IDs.")] - public readonly string[] ExcludeTilesets = { }; + public readonly string[] ExcludeTilesets = null; [Desc("Palette index of first RotationRange color.")] public readonly int RotationBase = 0x60; @@ -65,7 +73,10 @@ namespace OpenRA.Mods.Common.Traits foreach (var kvp in palettes) { - if (info.ExcludePalettes.Contains(kvp.Key) || info.ExcludeTilesets.Contains(world.TileSet.Id)) + if ((info.Palettes.Count > 0 && !info.Palettes.Any(kvp.Key.StartsWith)) + || (info.Tilesets != null && !info.Tilesets.Contains(world.TileSet.Id)) + || (info.ExcludePalettes.Count > 0 && info.ExcludePalettes.Any(kvp.Key.StartsWith)) + || (info.ExcludeTilesets != null && info.ExcludeTilesets.Contains(world.TileSet.Id))) continue; var palette = kvp.Value; diff --git a/mods/ra/rules/palettes.yaml b/mods/ra/rules/palettes.yaml index a4a91689a8..56813c0b4e 100644 --- a/mods/ra/rules/palettes.yaml +++ b/mods/ra/rules/palettes.yaml @@ -68,14 +68,13 @@ PlayerHighlightPalette: MenuPaletteEffect: RotationPaletteEffect@defaultwater: - ExcludePalettes: chrome + Palettes: terrain ExcludeTilesets: DESERT RotationPaletteEffect@actorswater: - ExcludePalettes: chrome, terrain - ExcludeTilesets: TEMPERAT, SNOW, INTERIOR + Palettes: player, effect RotationPaletteEffect@desertwater: - ExcludePalettes: chrome, effect, player - ExcludeTilesets: TEMPERAT, SNOW, INTERIOR + Palettes: terrain + Tilesets: DESERT RotationBase: 32 LightPaletteRotator: ExcludePalettes: terrain, effect From ea7811a076ec139a5fdeb756e92547263de1b274 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sun, 6 Sep 2015 18:39:17 +0200 Subject: [PATCH 4/5] Rename temp to rotationBuffer and remove comment --- .../Traits/PaletteEffects/RotationPaletteEffect.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs index d5d105a41c..e1881253f8 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs @@ -48,16 +48,15 @@ namespace OpenRA.Mods.Common.Traits { readonly RotationPaletteEffectInfo info; readonly World world; + readonly uint[] rotationBuffer; float t = 0; - uint[] temp; public RotationPaletteEffect(World world, RotationPaletteEffectInfo info) { this.world = world; this.info = info; - // Allocating this on the fly actually hurts our profile - temp = new uint[info.RotationRange]; + rotationBuffer = new uint[info.RotationRange]; } public void Tick(Actor self) @@ -82,10 +81,10 @@ namespace OpenRA.Mods.Common.Traits var palette = kvp.Value; for (var i = 0; i < info.RotationRange; i++) - temp[(rotate + i) % info.RotationRange] = palette[info.RotationBase + i]; + rotationBuffer[(rotate + i) % info.RotationRange] = palette[info.RotationBase + i]; for (var i = 0; i < info.RotationRange; i++) - palette[info.RotationBase + i] = temp[i]; + palette[info.RotationBase + i] = rotationBuffer[i]; } } } From fabdefeaf1025b8068b6d91d399f8698032fe42d Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sun, 6 Sep 2015 19:18:54 +0200 Subject: [PATCH 5/5] Use HashSets for tileset checks, check in constructor for better performance --- .../PaletteEffects/RotationPaletteEffect.cs | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs index e1881253f8..34c63d6a80 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs @@ -24,13 +24,13 @@ namespace OpenRA.Mods.Common.Traits [Desc("Defines for which tileset IDs this effect should be loaded.", "If none specified, it applies to all tileset IDs not explicitly excluded.")] - public readonly string[] Tilesets = null; + public readonly HashSet Tilesets = new HashSet(); [Desc("Defines which palettes should be excluded from this effect.")] public readonly HashSet ExcludePalettes = new HashSet(); [Desc("Don't apply the effect for these tileset IDs.")] - public readonly string[] ExcludeTilesets = null; + public readonly HashSet ExcludeTilesets = new HashSet(); [Desc("Palette index of first RotationRange color.")] public readonly int RotationBase = 0x60; @@ -47,25 +47,41 @@ namespace OpenRA.Mods.Common.Traits class RotationPaletteEffect : ITick, IPaletteModifier { readonly RotationPaletteEffectInfo info; - readonly World world; readonly uint[] rotationBuffer; + readonly bool validTileset; + readonly string tilesetId; float t = 0; public RotationPaletteEffect(World world, RotationPaletteEffectInfo info) { - this.world = world; this.info = info; - rotationBuffer = new uint[info.RotationRange]; + tilesetId = world.TileSet.Id; + + validTileset = IsValidTileset(); + } + + bool IsValidTileset() + { + if (info.Tilesets.Count == 0 && info.ExcludeTilesets.Count == 0) + return true; + + return info.Tilesets.Contains(tilesetId) && !info.ExcludeTilesets.Contains(tilesetId); } public void Tick(Actor self) { + if (!validTileset) + return; + t += info.RotationStep; } public void AdjustPalette(IReadOnlyDictionary palettes) { + if (!validTileset) + return; + var rotate = (int)t % info.RotationRange; if (rotate == 0) return; @@ -73,9 +89,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var kvp in palettes) { if ((info.Palettes.Count > 0 && !info.Palettes.Any(kvp.Key.StartsWith)) - || (info.Tilesets != null && !info.Tilesets.Contains(world.TileSet.Id)) - || (info.ExcludePalettes.Count > 0 && info.ExcludePalettes.Any(kvp.Key.StartsWith)) - || (info.ExcludeTilesets != null && info.ExcludeTilesets.Contains(world.TileSet.Id))) + || (info.ExcludePalettes.Count > 0 && info.ExcludePalettes.Any(kvp.Key.StartsWith))) continue; var palette = kvp.Value;