inlined InitializeEngineWithMods; cleaned trailing whitespace in Game; removed non-working Replay code

This commit is contained in:
Bob
2010-08-21 19:16:43 +12:00
parent 18914447aa
commit 1a4e3053ce
3 changed files with 31 additions and 41 deletions

View File

@@ -72,7 +72,7 @@ namespace OpenRA
packageChangePending = false; packageChangePending = false;
Timer.Time( "load assemblies, packages: {0}" ); Timer.Time( "load assemblies, packages: {0}" );
} }
static void LoadMap(string mapName) static void LoadMap(string mapName)
{ {
Timer.Time("----LoadMap"); Timer.Time("----LoadMap");
@@ -87,21 +87,21 @@ namespace OpenRA
viewport = new Viewport(clientSize, map.TopLeft, map.BottomRight, Renderer); viewport = new Viewport(clientSize, map.TopLeft, map.BottomRight, Renderer);
world = null; // trying to access the old world will NRE, rather than silently doing it wrong. world = null; // trying to access the old world will NRE, rather than silently doing it wrong.
Timer.Time("viewport: {0}"); Timer.Time("viewport: {0}");
Rules.LoadRules(modData.Manifest,map); Rules.LoadRules(modData.Manifest,map);
Timer.Time( "load rules: {0}" ); Timer.Time( "load rules: {0}" );
SpriteSheetBuilder.Initialize( Rules.TileSets[map.Tileset] ); SpriteSheetBuilder.Initialize( Rules.TileSets[map.Tileset] );
SequenceProvider.Initialize(modData.Manifest.Sequences); SequenceProvider.Initialize(modData.Manifest.Sequences);
Timer.Time("SeqProv: {0}"); Timer.Time("SeqProv: {0}");
world = new World(modData.Manifest, map); world = new World(modData.Manifest, map);
Timer.Time("world: {0}"); Timer.Time("world: {0}");
Timer.Time("----end LoadMap"); Timer.Time("----end LoadMap");
Debug("Map change {0} -> {1}".F(Game.mapName, mapName)); Debug("Map change {0} -> {1}".F(Game.mapName, mapName));
} }
public static void MoveViewport(int2 loc) public static void MoveViewport(int2 loc)
{ {
viewport.Center(loc); viewport.Center(loc);
@@ -119,7 +119,7 @@ namespace OpenRA
lastConnectionState = ConnectionState.PreConnecting; lastConnectionState = ConnectionState.PreConnecting;
ConnectionStateChanged(); ConnectionStateChanged();
orderManager = new OrderManager(new NetworkConnection(host, port), ChooseReplayFilename()); orderManager = new OrderManager(new NetworkConnection(host, port), ChooseReplayFilename());
} }
@@ -132,7 +132,7 @@ namespace OpenRA
{ {
lastConnectionState = ConnectionState.PreConnecting; lastConnectionState = ConnectionState.PreConnecting;
ConnectionStateChanged(); ConnectionStateChanged();
if (orderManager != null) orderManager.Dispose(); if (orderManager != null) orderManager.Dispose();
orderManager = new OrderManager(new EchoConnection()); orderManager = new OrderManager(new EchoConnection());
} }
@@ -151,7 +151,7 @@ namespace OpenRA
public static event Action ConnectionStateChanged = () => { }; public static event Action ConnectionStateChanged = () => { };
static ConnectionState lastConnectionState = ConnectionState.PreConnecting; static ConnectionState lastConnectionState = ConnectionState.PreConnecting;
public static int LocalClientId { get { return orderManager.Connection.LocalClientId; } } public static int LocalClientId { get { return orderManager.Connection.LocalClientId; } }
static void Tick() static void Tick()
{ {
if (packageChangePending) if (packageChangePending)
@@ -170,13 +170,13 @@ namespace OpenRA
mapChangePending = false; mapChangePending = false;
return; return;
} }
if (orderManager.Connection.ConnectionState != lastConnectionState) if (orderManager.Connection.ConnectionState != lastConnectionState)
{ {
lastConnectionState = orderManager.Connection.ConnectionState; lastConnectionState = orderManager.Connection.ConnectionState;
ConnectionStateChanged(); ConnectionStateChanged();
} }
int t = Environment.TickCount; int t = Environment.TickCount;
int dt = t - lastTime; int dt = t - lastTime;
if (dt >= Settings.Timestep) if (dt >= Settings.Timestep)
@@ -289,7 +289,7 @@ namespace OpenRA
LoadMap(map); LoadMap(map);
if (orderManager.GameStarted) return; if (orderManager.GameStarted) return;
Widget.SelectedWidget = null; Widget.SelectedWidget = null;
world.Queries = new World.AllQueries(world); world.Queries = new World.AllQueries(world);
foreach (var gs in world.WorldActor.TraitsImplementing<IGameStarted>()) foreach (var gs in world.WorldActor.TraitsImplementing<IGameStarted>())
@@ -331,7 +331,7 @@ namespace OpenRA
Modifiers = modifierKeys, Modifiers = modifierKeys,
}; };
Widget.HandleInput(world, mi); Widget.HandleInput(world, mi);
if (sync != world.SyncHash() && world == initialWorld) if (sync != world.SyncHash() && world == initialWorld)
throw new InvalidOperationException("Desync in DispatchMouseInput"); throw new InvalidOperationException("Desync in DispatchMouseInput");
} }
@@ -349,7 +349,7 @@ namespace OpenRA
public static void HandleKeyEvent(KeyInput e) public static void HandleKeyEvent(KeyInput e)
{ {
int sync = world.SyncHash(); int sync = world.SyncHash();
if (Widget.HandleKeyPress(e)) if (Widget.HandleKeyPress(e))
return; return;
@@ -364,13 +364,13 @@ namespace OpenRA
internal static void Initialize(Settings settings) internal static void Initialize(Settings settings)
{ {
AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly; AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly;
var defaultSupport = Environment.GetFolderPath(Environment.SpecialFolder.Personal) var defaultSupport = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
+ Path.DirectorySeparatorChar + "OpenRA"; + Path.DirectorySeparatorChar + "OpenRA";
SupportDir = settings.GetValue("SupportDir", defaultSupport); SupportDir = settings.GetValue("SupportDir", defaultSupport);
Settings = new UserSettings(settings); Settings = new UserSettings(settings);
Log.LogPath = SupportDir + "Logs" + Path.DirectorySeparatorChar; Log.LogPath = SupportDir + "Logs" + Path.DirectorySeparatorChar;
Log.AddChannel("perf", "perf.log"); Log.AddChannel("perf", "perf.log");
Log.AddChannel("debug", "debug.log"); Log.AddChannel("debug", "debug.log");
@@ -378,7 +378,7 @@ namespace OpenRA
LobbyInfo.GlobalSettings.Mods = Settings.InitialMods; LobbyInfo.GlobalSettings.Mods = Settings.InitialMods;
modData = new ModData( LobbyInfo.GlobalSettings.Mods ); modData = new ModData( LobbyInfo.GlobalSettings.Mods );
Renderer.SheetSize = Settings.SheetSize; Renderer.SheetSize = Settings.SheetSize;
Renderer.Initialize( settings, Game.Settings.WindowMode ); Renderer.Initialize( settings, Game.Settings.WindowMode );
@@ -395,15 +395,10 @@ namespace OpenRA
Renderer = new Renderer(); Renderer = new Renderer();
clientSize = new int2(Renderer.Resolution); clientSize = new int2(Renderer.Resolution);
if (Settings.Replay != null) JoinLocal();
orderManager = new OrderManager(new ReplayConnection(Settings.Replay));
else
JoinLocal();
StartGame(modData.Manifest.ShellmapUid); StartGame(modData.Manifest.ShellmapUid);
ResetTimer(); ResetTimer();
} }
static bool quit; static bool quit;
@@ -417,10 +412,10 @@ 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 Action<Color,string,string> AddChatLine = (c,n,s) => {};
public static void Debug(string s) public static void Debug(string s)
{ {
AddChatLine(Color.White, "Debug", s); AddChatLine(Color.White, "Debug", s);
} }
@@ -437,30 +432,24 @@ namespace OpenRA
Widget.RootWidget.CloseWindow(); Widget.RootWidget.CloseWindow();
Widget.RootWidget.OpenWindow("MAINMENU_BG"); Widget.RootWidget.OpenWindow("MAINMENU_BG");
} }
static string baseSupportDir = null; static string baseSupportDir = null;
public static string SupportDir public static string SupportDir
{ {
set { set
{
var dir = value; var dir = value;
// Expand paths relative to the personal directory // Expand paths relative to the personal directory
if (dir.ElementAt(0) == '~') if (dir.ElementAt(0) == '~')
dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + dir.Substring(1); dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + dir.Substring(1);
if (!Directory.Exists(dir)) if (!Directory.Exists(dir))
Directory.CreateDirectory(dir); Directory.CreateDirectory(dir);
baseSupportDir = dir + Path.DirectorySeparatorChar; baseSupportDir = dir + Path.DirectorySeparatorChar;
} }
get {return baseSupportDir;} get { return baseSupportDir; }
}
public static void InitializeEngineWithMods(string[] mods)
{
AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly;
modData = new ModData( mods );
Rules.LoadRules(modData.Manifest, new Map());
} }
public static T CreateObject<T>( string name ) public static T CreateObject<T>( string name )

View File

@@ -47,7 +47,6 @@ namespace OpenRA.GameRules
// External game settings // External game settings
public string LastServer = "localhost:1234"; public string LastServer = "localhost:1234";
public string Replay = null;
public string PlayerName = "Newbie"; public string PlayerName = "Newbie";
public Color PlayerColor1 = Color.FromArgb(255,160,238); public Color PlayerColor1 = Color.FromArgb(255,160,238);
public Color PlayerColor2 = Color.FromArgb(68,0,56); public Color PlayerColor2 = Color.FromArgb(68,0,56);

View File

@@ -39,7 +39,9 @@ namespace RALint
ObjectCreator.MissingTypeAction = s => EmitError("Missing Type: {0}".F(s)); ObjectCreator.MissingTypeAction = s => EmitError("Missing Type: {0}".F(s));
FieldLoader.UnknownFieldAction = (s, f) => EmitError("FieldLoader: Missing field `{0}` on `{1}`".F(s, f.Name)); FieldLoader.UnknownFieldAction = (s, f) => EmitError("FieldLoader: Missing field `{0}` on `{1}`".F(s, f.Name));
Game.InitializeEngineWithMods(args); AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly;
Game.modData = new ModData( args );
Rules.LoadRules(Game.modData.Manifest, new Map());
// all the @something names which actually EXIST. // all the @something names which actually EXIST.
var psuedoPrereqs = Rules.Info.Values.Select(a => a.Traits.GetOrDefault<BuildableInfo>()).Where(b => b != null) var psuedoPrereqs = Rules.Info.Values.Select(a => a.Traits.GetOrDefault<BuildableInfo>()).Where(b => b != null)