untangling WorldRenderer from World

This commit is contained in:
Bob
2010-10-12 01:11:56 +13:00
parent 1c1483377c
commit 597dba8584
17 changed files with 162 additions and 124 deletions

View File

@@ -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<OrderManager> ConnectionStateChanged = _ => { };
static ConnectionState lastConnectionState = ConnectionState.PreConnecting;
internal static event Action<OrderManager> 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<string,object>{{"world", world}});
Game.AfterGameStart += world => Widget.OpenWindow("INGAME_ROOT", new Dictionary<string,object>{{"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<Color,string,string> AddChatLine = (c,n,s) => {};
public static void Debug(string s, params object[] 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");
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);
}
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; }
}
public static T CreateObject<T>( string name )
@@ -353,4 +358,4 @@ namespace OpenRA
return modData.ObjectCreator.CreateObject<T>( name );
}
}
}
}