diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index fae356a275..b2f1998ffe 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -6,19 +6,19 @@ * as published by the Free Software Foundation. For more information, * see LICENSE. */ -#endregion - +#endregion + using System; using System.Collections.Generic; -using System.Drawing; -using System.IO; +using System.Drawing; +using System.IO; using System.Linq; -using System.Windows.Forms; +using System.Windows.Forms; using OpenRA.FileFormats; -using OpenRA.GameRules; -using OpenRA.Graphics; -using OpenRA.Network; -using OpenRA.Server; +using OpenRA.GameRules; +using OpenRA.Graphics; +using OpenRA.Network; +using OpenRA.Server; using OpenRA.Support; using OpenRA.Widgets; @@ -32,6 +32,8 @@ namespace OpenRA public static ModData modData; public static World world; + public static WorldRenderer worldRenderer; + public static Viewport viewport; public static Settings Settings; @@ -48,6 +50,7 @@ namespace OpenRA viewport = new Viewport(new float2(Renderer.Resolution), map.TopLeft, map.BottomRight, Renderer); world = new World(modData.Manifest, map, orderManager); + worldRenderer = new WorldRenderer(world); } public static void MoveViewport(int2 loc) @@ -92,18 +95,18 @@ namespace OpenRA internal static int RenderFrame = 0; internal static int LocalTick = 0; const int NetTickScale = 3; // 120ms net tick for 40ms local tick - - internal static event Action ConnectionStateChanged = _ => { }; - static ConnectionState lastConnectionState = ConnectionState.PreConnecting; + + internal static event Action ConnectionStateChanged = _ => { }; + static ConnectionState lastConnectionState = ConnectionState.PreConnecting; public static int LocalClientId { get { return orderManager.Connection.LocalClientId; } } static void Tick( World world, OrderManager orderManager, Viewport viewPort ) { - if (orderManager.Connection.ConnectionState != lastConnectionState) - { - lastConnectionState = orderManager.Connection.ConnectionState; - ConnectionStateChanged( orderManager ); - } + if (orderManager.Connection.ConnectionState != lastConnectionState) + { + lastConnectionState = orderManager.Connection.ConnectionState; + ConnectionStateChanged( orderManager ); + } int t = Environment.TickCount; int dt = t - lastTime; @@ -131,6 +134,7 @@ namespace OpenRA world.OrderGenerator.Tick(world); world.Selection.Tick(world); world.Tick(); + worldRenderer.Tick(); PerfHistory.Tick(); } @@ -143,7 +147,7 @@ namespace OpenRA using (new PerfSample("render")) { ++RenderFrame; - viewport.DrawRegions(world.WorldRenderer, world); + viewport.DrawRegions(worldRenderer, world); Sound.SetListenerPosition(viewport.Location + .5f * new float2(viewport.Width, viewport.Height)); } @@ -174,9 +178,9 @@ namespace OpenRA if (orderManager.GameStarted) return; Widget.SelectedWidget = null; - LocalTick = 0; + LocalTick = 0; - orderManager.StartGame(); + orderManager.StartGame(); viewport.RefreshPalette(); AfterGameStart( world ); } @@ -221,24 +225,24 @@ namespace OpenRA internal static void Initialize(Arguments args) { - AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly; - - var defaultSupport = Environment.GetFolderPath(Environment.SpecialFolder.Personal) - + Path.DirectorySeparatorChar + "OpenRA"; - - SupportDir = args.GetValue("SupportDir", defaultSupport); - Settings = new Settings(SupportDir + "settings.yaml", args); - + AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly; + + var defaultSupport = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + + Path.DirectorySeparatorChar + "OpenRA"; + + SupportDir = args.GetValue("SupportDir", defaultSupport); + Settings = new Settings(SupportDir + "settings.yaml", args); + // force master server upgrade -- remove once everyone is switched over. if (Settings.Server.MasterServer == "http://open-ra.org/master/") Settings.Server.MasterServer = "http://master.open-ra.org/"; - Settings.Save(); - - Log.LogPath = SupportDir + "Logs" + Path.DirectorySeparatorChar; - Log.AddChannel("perf", "perf.log"); - Log.AddChannel("debug", "debug.log"); - Log.AddChannel("sync", "syncreport.log"); + Settings.Save(); + + Log.LogPath = SupportDir + "Logs" + Path.DirectorySeparatorChar; + Log.AddChannel("perf", "perf.log"); + Log.AddChannel("debug", "debug.log"); + Log.AddChannel("sync", "syncreport.log"); FileSystem.Mount("."); // Needed to access shaders Renderer.Initialize( Game.Settings.Graphics.Mode ); @@ -259,13 +263,14 @@ namespace OpenRA PerfHistory.items["render"].hasNormalTick = false; PerfHistory.items["batches"].hasNormalTick = false; PerfHistory.items["text"].hasNormalTick = false; - PerfHistory.items["cursor"].hasNormalTick = false; - + PerfHistory.items["cursor"].hasNormalTick = false; + + JoinLocal(); StartGame(modData.Manifest.ShellmapUid); Game.AfterGameStart += world => Widget.OpenWindow("INGAME_ROOT", new Dictionary{{"world", world}}); - + Game.ConnectionStateChanged += orderManager => { Widget.CloseWindow(); @@ -309,13 +314,13 @@ namespace OpenRA } } - public static void Exit() { quit = true; } - + public static void Exit() { quit = true; } + public static Action AddChatLine = (c,n,s) => {}; - public static void Debug(string s, params object[] args) - { - AddChatLine(Color.White, "Debug", String.Format(s,args)); + public static void Debug(string s, params object[] args) + { + AddChatLine(Color.White, "Debug", String.Format(s,args)); } public static void Disconnect() @@ -327,25 +332,25 @@ namespace OpenRA Widget.CloseWindow(); Widget.OpenWindow("MAINMENU_BG"); - } - - static string baseSupportDir = null; - public static string SupportDir - { - set - { - var dir = value; - - // Expand paths relative to the personal directory - if (dir.ElementAt(0) == '~') - dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + dir.Substring(1); - - if (!Directory.Exists(dir)) - Directory.CreateDirectory(dir); - - baseSupportDir = dir + Path.DirectorySeparatorChar; + } + + static string baseSupportDir = null; + public static string SupportDir + { + set + { + var dir = value; + + // Expand paths relative to the personal directory + if (dir.ElementAt(0) == '~') + dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + dir.Substring(1); + + if (!Directory.Exists(dir)) + Directory.CreateDirectory(dir); + + baseSupportDir = dir + Path.DirectorySeparatorChar; } - get { return baseSupportDir; } + get { return baseSupportDir; } } public static T CreateObject( string name ) @@ -353,4 +358,4 @@ namespace OpenRA return modData.ObjectCreator.CreateObject( name ); } } -} +} diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index bedf3b0ed5..013c09f00f 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -111,7 +111,7 @@ namespace OpenRA.Graphics public void RefreshPalette() { - Game.world.WorldRenderer.palette.Update( + Game.worldRenderer.palette.Update( Game.world.WorldActor.TraitsImplementing()); } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index eaaab05951..b79b562c53 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -31,6 +31,9 @@ namespace OpenRA.Graphics terrainRenderer = new TerrainRenderer(world, this); uiOverlay = new UiOverlay(); palette = new HardwarePalette(world.Map); + + foreach( var pal in world.traitDict.ActorsWithTraitMultiple( world ) ) + pal.Trait.InitPalette( this ); } public int GetPaletteIndex(string name) { return palette.GetPaletteIndex(name); } diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index d04d3d2e2f..01ebeef752 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -63,7 +63,6 @@ namespace OpenRA PlayerRef = pr; - RegisterPlayerColor(world, Palette); PlayerActor = world.CreateActor("Player", new TypeDictionary{ new OwnerInit( this ) }); } @@ -85,18 +84,9 @@ namespace OpenRA ClientIndex = client.Index; PlayerRef = pr; - RegisterPlayerColor(world, Palette); PlayerActor = world.CreateActor("Player", new TypeDictionary{ new OwnerInit( this ) }); } - public void RegisterPlayerColor(World world, string palette) - { - var info = Rules.Info["world"].Traits.Get(); - var newpal = new Palette(world.WorldRenderer.GetPalette(info.BasePalette), - new PlayerColorRemap(Color, Color2, info.PaletteFormat)); - world.WorldRenderer.AddPalette(palette, newpal); - } - public void GiveAdvice(string advice) { Sound.PlayToPlayer(this, advice); diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index ec67480ab0..ac4fbd1725 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -105,6 +105,7 @@ namespace OpenRA.Traits public interface IDamageModifier { float GetDamageModifier( WarheadInfo warhead ); } public interface ISpeedModifier { float GetSpeedModifier(); } public interface IFirepowerModifier { float GetFirepowerModifier(); } + public interface IPalette { void InitPalette( WorldRenderer wr ); } public interface IPaletteModifier { void AdjustPalette(Dictionary b); } public interface IPips { IEnumerable GetPips(Actor self); } public interface ITags { IEnumerable GetTags(); } diff --git a/OpenRA.Game/Traits/World/PlayerColorPalette.cs b/OpenRA.Game/Traits/World/PlayerColorPalette.cs index d081b12ea2..9ed20d2362 100644 --- a/OpenRA.Game/Traits/World/PlayerColorPalette.cs +++ b/OpenRA.Game/Traits/World/PlayerColorPalette.cs @@ -9,13 +9,34 @@ #endregion using OpenRA.FileFormats; +using OpenRA.Graphics; namespace OpenRA.Traits { - public class PlayerColorPaletteInfo : TraitInfo + public class PlayerColorPaletteInfo : ITraitInfo { public readonly string BasePalette = null; + public readonly string BaseName = "player"; public readonly PaletteFormat PaletteFormat = PaletteFormat.ra; + + public object Create( ActorInitializer init ) { return new PlayerColorPalette( init.self.Owner, this ); } } - public class PlayerColorPalette {} + public class PlayerColorPalette : IPalette + { + readonly Player owner; + readonly PlayerColorPaletteInfo info; + public PlayerColorPalette( Player owner, PlayerColorPaletteInfo info ) + { + this.owner = owner; + this.info = info; + } + + public void InitPalette( WorldRenderer wr ) + { + var paletteName = "{0}{1}".F( info.BaseName, owner.Index ); + var newpal = new Palette(wr.GetPalette(info.BasePalette), + new PlayerColorRemap(owner.Color, owner.Color2, info.PaletteFormat)); + wr.AddPalette(paletteName, newpal); + } + } } diff --git a/OpenRA.Game/Widgets/ShpImageWidget.cs b/OpenRA.Game/Widgets/ShpImageWidget.cs index ab838be719..cfcb9843a9 100644 --- a/OpenRA.Game/Widgets/ShpImageWidget.cs +++ b/OpenRA.Game/Widgets/ShpImageWidget.cs @@ -61,7 +61,7 @@ namespace OpenRA.Widgets cachedFrame = frame; } - Game.Renderer.WorldSpriteRenderer.DrawSprite(sprite,RenderOrigin, Game.world.WorldRenderer, palette); + Game.Renderer.WorldSpriteRenderer.DrawSprite(sprite,RenderOrigin, Game.worldRenderer, palette); } } } diff --git a/OpenRA.Game/Widgets/WidgetUtils.cs b/OpenRA.Game/Widgets/WidgetUtils.cs index 212916a6ca..4789d619bf 100644 --- a/OpenRA.Game/Widgets/WidgetUtils.cs +++ b/OpenRA.Game/Widgets/WidgetUtils.cs @@ -29,7 +29,7 @@ namespace OpenRA.Widgets public static void DrawSHP(Sprite s, float2 pos) { - Game.Renderer.WorldSpriteRenderer.DrawSprite(s,pos, Game.world.WorldRenderer, "chrome"); + Game.Renderer.WorldSpriteRenderer.DrawSprite(s,pos, Game.worldRenderer, "chrome"); } public static void DrawPanel(string collection, Rectangle Bounds) diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 5f83d3f78c..b8d26e173c 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -41,7 +41,7 @@ namespace OpenRA.Widgets Game.Renderer.LineRenderer.DrawLine(a, a + c, Color.White, Color.White); foreach (var u in SelectActorsInBox(world, selbox.Value.First, selbox.Value.Second)) - world.WorldRenderer.DrawSelectionBox(u, Color.Yellow); + Game.worldRenderer.DrawSelectionBox(u, Color.Yellow); } float2 dragStart, dragEnd; diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 3e30abfb7f..d9f8b9d54b 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -57,8 +57,6 @@ namespace OpenRA public readonly Map Map; public readonly TileSet TileSet; - public readonly WorldRenderer WorldRenderer; - IOrderGenerator orderGenerator_; public IOrderGenerator OrderGenerator { @@ -97,8 +95,6 @@ namespace OpenRA TileSet = Rules.TileSets[Map.Tileset]; TileSet.LoadTiles(); - WorldRenderer = new WorldRenderer(this); - WorldActor = CreateActor( "World", new TypeDictionary() ); Queries = new AllQueries(this); @@ -170,8 +166,6 @@ namespace OpenRA Game.viewport.Tick(); while (frameEndActions.Count != 0) frameEndActions.Dequeue()(this); - - WorldRenderer.Tick(); } public IEnumerable Actors { get { return actors; } } diff --git a/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs b/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs index 27be188181..631f8bfe62 100644 --- a/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs +++ b/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs @@ -11,21 +11,21 @@ using System.Collections.Generic; using OpenRA.FileFormats; using OpenRA.Traits; -using OpenRA.Widgets.Delegates; +using OpenRA.Widgets.Delegates; +using OpenRA.Graphics; namespace OpenRA.Mods.RA { class ColorPickerPaletteModifierInfo : TraitInfo {} - class ColorPickerPaletteModifier : IPaletteModifier, IWorldLoaded + class ColorPickerPaletteModifier : IPalette, IPaletteModifier { PaletteFormat format; - public void WorldLoaded(World w) - { - // Copy the base palette for the colorpicker - var info = Rules.Info["world"].Traits.Get(); + public void InitPalette( WorldRenderer wr ) + { + var info = Rules.Info["player"].Traits.Get(); format = info.PaletteFormat; - w.WorldRenderer.AddPalette("colorpicker", w.WorldRenderer.GetPalette(info.BasePalette)); + wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette)); } public void AdjustPalette(Dictionary palettes) @@ -33,6 +33,6 @@ namespace OpenRA.Mods.RA palettes["colorpicker"] = new Palette(palettes["colorpicker"], new PlayerColorRemap(LobbyDelegate.CurrentColorPreview1, LobbyDelegate.CurrentColorPreview2, format)); - } + } } } diff --git a/OpenRA.Mods.RA/PaletteFromCurrentTheatre.cs b/OpenRA.Mods.RA/PaletteFromCurrentTheatre.cs index badf0b4c9f..63bdf56da3 100644 --- a/OpenRA.Mods.RA/PaletteFromCurrentTheatre.cs +++ b/OpenRA.Mods.RA/PaletteFromCurrentTheatre.cs @@ -21,12 +21,20 @@ namespace OpenRA.Mods.RA public object Create(ActorInitializer init) { return new PaletteFromCurrentTheatre(init.world, this); } } - class PaletteFromCurrentTheatre - { + class PaletteFromCurrentTheatre : IPalette + { + readonly World world; + readonly PaletteFromCurrentTheatreInfo info; + public PaletteFromCurrentTheatre(World world, PaletteFromCurrentTheatreInfo info) - { - world.WorldRenderer.AddPalette(info.Name, - new Palette(FileSystem.Open(world.TileSet.Palette), info.Transparent)); - } + { + this.world = world; + this.info = info; + } + + public void InitPalette( OpenRA.Graphics.WorldRenderer wr ) + { + wr.AddPalette( info.Name, new Palette( FileSystem.Open( world.TileSet.Palette ), info.Transparent ) ); + } } } diff --git a/OpenRA.Mods.RA/PaletteFromFile.cs b/OpenRA.Mods.RA/PaletteFromFile.cs index 30ad938bb2..dec6abd263 100644 --- a/OpenRA.Mods.RA/PaletteFromFile.cs +++ b/OpenRA.Mods.RA/PaletteFromFile.cs @@ -10,6 +10,7 @@ using OpenRA.FileFormats; using OpenRA.Traits; +using OpenRA.Graphics; namespace OpenRA.Mods.RA { @@ -23,16 +24,20 @@ namespace OpenRA.Mods.RA public object Create(ActorInitializer init) { return new PaletteFromFile(init.world, this); } } - class PaletteFromFile + class PaletteFromFile : IPalette { + readonly World world; + readonly PaletteFromFileInfo info; public PaletteFromFile(World world, PaletteFromFileInfo info) { - if (info.Theater == null || - info.Theater.ToLowerInvariant() == world.Map.Theater.ToLowerInvariant()) - { - world.WorldRenderer.AddPalette(info.Name, - new Palette(FileSystem.Open(info.Filename), info.Transparent)); - } + this.world = world; + this.info = info; + } + + public void InitPalette( WorldRenderer wr ) + { + if( info.Theater == null || info.Theater.ToLowerInvariant() == world.Map.Theater.ToLowerInvariant() ) + wr.AddPalette( info.Name, new Palette( FileSystem.Open( info.Filename ), info.Transparent ) ); } } } diff --git a/OpenRA.Mods.RA/PaletteFromRGBA.cs b/OpenRA.Mods.RA/PaletteFromRGBA.cs index 5d6bec1afb..67d034ae9a 100644 --- a/OpenRA.Mods.RA/PaletteFromRGBA.cs +++ b/OpenRA.Mods.RA/PaletteFromRGBA.cs @@ -11,6 +11,7 @@ using System.Drawing; using OpenRA.FileFormats; using OpenRA.Traits; +using OpenRA.Graphics; namespace OpenRA.Mods.RA { @@ -26,15 +27,21 @@ namespace OpenRA.Mods.RA public object Create(ActorInitializer init) { return new PaletteFromRGBA(init.world, this); } } - class PaletteFromRGBA + class PaletteFromRGBA : IPalette { + readonly World world; + readonly PaletteFromRGBAInfo info; public PaletteFromRGBA(World world, PaletteFromRGBAInfo info) { - if (info.Theatre == null || - info.Theatre.ToLowerInvariant() == world.Map.Theater.ToLowerInvariant()) + this.world = world; + this.info = info; + } + + public void InitPalette( WorldRenderer wr ) + { + if (info.Theatre == null || info.Theatre.ToLowerInvariant() == world.Map.Theater.ToLowerInvariant()) { // TODO: This shouldn't rely on a base palette - var wr = world.WorldRenderer; var pal = wr.GetPalette("terrain"); wr.AddPalette(info.Name, new Palette(pal, new SingleColorRemap(Color.FromArgb(info.A, info.R, info.G, info.B)))); } diff --git a/OpenRA.Mods.RA/ShroudPalette.cs b/OpenRA.Mods.RA/ShroudPalette.cs index c62607c544..e332e3a755 100644 --- a/OpenRA.Mods.RA/ShroudPalette.cs +++ b/OpenRA.Mods.RA/ShroudPalette.cs @@ -11,6 +11,7 @@ using System.Drawing; using OpenRA.FileFormats; using OpenRA.Traits; +using OpenRA.Graphics; namespace OpenRA.Mods.RA { @@ -18,17 +19,21 @@ namespace OpenRA.Mods.RA { public readonly string Name = "shroud"; public readonly bool IsFog = false; - public object Create(ActorInitializer init) { return new ShroudPalette(init.world, this); } + public object Create(ActorInitializer init) { return new ShroudPalette(this); } } - class ShroudPalette + class ShroudPalette : IPalette { - public ShroudPalette(World world, ShroudPaletteInfo info) + readonly ShroudPaletteInfo info; + public ShroudPalette( ShroudPaletteInfo info ) { - // TODO: This shouldn't rely on a base palette - var wr = world.WorldRenderer; - var pal = wr.GetPalette("terrain"); - wr.AddPalette(info.Name, new Palette(pal, new ShroudPaletteRemap(info.IsFog))); + this.info = info; + } + + public void InitPalette( WorldRenderer wr ) + { + var pal = wr.GetPalette( "terrain" ); + wr.AddPalette( info.Name, new Palette( pal, new ShroudPaletteRemap( info.IsFog ) ) ); } } diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index 2dd7460792..9d9c9582c3 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -37,10 +37,12 @@ Player: ActorGroupProxy: DeveloperMode: HackyAI: - + PlayerColorPalette: + BasePalette: terrain + PaletteFormat: cnc + World: ScreenShaker: - ColorPickerPaletteModifier: NukePaletteEffect: WaterPaletteRotation: CncMode: true @@ -50,9 +52,6 @@ World: Bridges: bridge1, bridge2, bridge3, bridge4 PaletteFromCurrentTheatre: Name: terrain - PlayerColorPalette: - BasePalette: terrain - PaletteFormat: cnc PaletteFromFile@chrome: Name: chrome Filename: temperat.pal @@ -85,6 +84,7 @@ World: G: 0 B: 0 A: 180 + ColorPickerPaletteModifier: ShroudPalette@shroud: ShroudPalette@fog: IsFog: yes diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index 60fdcd1b28..545dff818f 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -98,11 +98,11 @@ Player: ActorGroupProxy: DeveloperMode: HackyAI: - + PlayerColorPalette: + BasePalette: terrain World: ScreenShaker: - ColorPickerPaletteModifier: WaterPaletteRotation: ChronoshiftPaletteEffect: NukePaletteEffect: @@ -119,8 +119,6 @@ World: WaterChance: .2 PaletteFromCurrentTheatre: Name: terrain - PlayerColorPalette: - BasePalette: terrain PaletteFromFile@chrome: Name: chrome Filename: temperat.pal @@ -154,6 +152,7 @@ World: G: 0 B: 0 A: 180 + ColorPickerPaletteModifier: ShroudPalette@shroud: ShroudPalette@fog: IsFog: yes