start cleaning up IWorldLoadHook vs IGameStarted -- IGameStarted dies.

This commit is contained in:
Chris Forbes
2010-08-25 21:53:54 +12:00
parent 50066ec238
commit f4da83e920
13 changed files with 23 additions and 26 deletions

View File

@@ -192,11 +192,6 @@ namespace OpenRA
if (orderManager.GameStarted) return; if (orderManager.GameStarted) return;
Widget.SelectedWidget = null; Widget.SelectedWidget = null;
world.Queries = new World.AllQueries(world);
foreach (var gs in world.WorldActor.TraitsImplementing<IGameStarted>())
gs.GameStarted(world);
orderManager.StartGame(); orderManager.StartGame();
viewport.RefreshPalette(); viewport.RefreshPalette();
AfterGameStart(); AfterGameStart();

View File

@@ -21,10 +21,11 @@ namespace OpenRA.Traits
public readonly int InitialExploreRange = 5; public readonly int InitialExploreRange = 5;
} }
public class MPStartLocations : IGameStarted public class MPStartLocations : IWorldLoaded
{ {
public Dictionary<Player, int2> Start = new Dictionary<Player, int2>(); public Dictionary<Player, int2> Start = new Dictionary<Player, int2>();
public void GameStarted(World world)
public void WorldLoaded(World world)
{ {
var taken = Game.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0) var taken = Game.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0)
.Select(c => world.Map.SpawnPoints.ElementAt(c.SpawnPoint - 1)).ToList(); .Select(c => world.Map.SpawnPoints.ElementAt(c.SpawnPoint - 1)).ToList();

View File

@@ -159,8 +159,7 @@ namespace OpenRA.Traits
public interface ITraitPrerequisite<T> where T : ITraitInfo { } public interface ITraitPrerequisite<T> where T : ITraitInfo { }
public interface INotifySelection { void SelectionChanged(); } public interface INotifySelection { void SelectionChanged(); }
public interface ILoadWorldHook { void WorldLoaded(World w); } public interface IWorldLoaded { void WorldLoaded(World w); }
public interface IGameStarted { void GameStarted(World w); }
public interface ICreatePlayers { void CreatePlayers(World w); } public interface ICreatePlayers { void CreatePlayers(World w); }
public interface IBot { void Activate(Player p); } public interface IBot { void Activate(Player p); }

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Traits
public object Create(ActorInitializer init) { return new BibLayer(init.self, this); } public object Create(ActorInitializer init) { return new BibLayer(init.self, this); }
} }
class BibLayer: IRenderOverlay, ILoadWorldHook class BibLayer: IRenderOverlay, IWorldLoaded
{ {
World world; World world;
BibLayerInfo info; BibLayerInfo info;

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Traits
{ {
public class ResourceLayerInfo : TraitInfo<ResourceLayer> { } public class ResourceLayerInfo : TraitInfo<ResourceLayer> { }
public class ResourceLayer: IRenderOverlay, ILoadWorldHook public class ResourceLayer: IRenderOverlay, IWorldLoaded
{ {
World world; World world;

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Traits
public object Create(ActorInitializer init) { return new SmudgeLayer(this); } public object Create(ActorInitializer init) { return new SmudgeLayer(this); }
} }
public class SmudgeLayer: IRenderOverlay, ILoadWorldHook public class SmudgeLayer: IRenderOverlay, IWorldLoaded
{ {
public SmudgeLayerInfo Info; public SmudgeLayerInfo Info;
TileReference<byte,byte>[,] tiles; TileReference<byte,byte>[,] tiles;

View File

@@ -88,6 +88,7 @@ namespace OpenRA
Timer.Time("renderer: {0}"); Timer.Time("renderer: {0}");
WorldActor = CreateActor( "World", new TypeDictionary() ); WorldActor = CreateActor( "World", new TypeDictionary() );
Queries = new AllQueries(this);
// Add players // Add players
foreach (var cmp in WorldActor.TraitsImplementing<ICreatePlayers>()) foreach (var cmp in WorldActor.TraitsImplementing<ICreatePlayers>())
@@ -100,11 +101,12 @@ namespace OpenRA
p.Stances[q] = Stance.Neutral; p.Stances[q] = Stance.Neutral;
Timer.Time( "worldActor, players: {0}" ); Timer.Time( "worldActor, players: {0}" );
foreach (var wlh in WorldActor.TraitsImplementing<ILoadWorldHook>())
wlh.WorldLoaded(this);
PathFinder = new PathFinder(this); PathFinder = new PathFinder(this);
foreach (var wlh in WorldActor.TraitsImplementing<IWorldLoaded>())
wlh.WorldLoaded(this);
Timer.Time( "hooks, pathing: {0}" ); Timer.Time( "hooks, pathing: {0}" );
Timer.Time( "----end World.ctor" ); Timer.Time( "----end World.ctor" );

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA
{ {
class Gdi01ScriptInfo : TraitInfo<Gdi01Script> { } class Gdi01ScriptInfo : TraitInfo<Gdi01Script> { }
class Gdi01Script: ILoadWorldHook, ITick class Gdi01Script: IWorldLoaded, ITick
{ {
Dictionary<string, Actor> Actors; Dictionary<string, Actor> Actors;
Dictionary<string, Player> Players; Dictionary<string, Player> Players;

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new BridgeLayer(init.self, this); } public object Create(ActorInitializer init) { return new BridgeLayer(init.self, this); }
} }
class BridgeLayer : ILoadWorldHook class BridgeLayer : IWorldLoaded
{ {
readonly BridgeLayerInfo Info; readonly BridgeLayerInfo Info;
readonly World world; readonly World world;

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA
{ {
class ColorPickerPaletteModifierInfo : TraitInfo<ColorPickerPaletteModifier> {} class ColorPickerPaletteModifierInfo : TraitInfo<ColorPickerPaletteModifier> {}
class ColorPickerPaletteModifier : IPaletteModifier, ILoadWorldHook class ColorPickerPaletteModifier : IPaletteModifier, IWorldLoaded
{ {
bool SplitPlayerPalette; bool SplitPlayerPalette;
public void WorldLoaded(World w) public void WorldLoaded(World w)

View File

@@ -16,7 +16,7 @@ namespace OpenRA.Mods.RA
{ {
class DefaultShellmapScriptInfo : TraitInfo<DefaultShellmapScript> { } class DefaultShellmapScriptInfo : TraitInfo<DefaultShellmapScript> { }
class DefaultShellmapScript: ILoadWorldHook, ITick class DefaultShellmapScript: IWorldLoaded, ITick
{ {
Dictionary<string, Actor> Actors; Dictionary<string, Actor> Actors;

View File

@@ -15,9 +15,9 @@ namespace OpenRA.Mods.RA
{ {
class SpawnMPUnitsInfo : TraitInfo<SpawnMPUnits>, ITraitPrerequisite<MPStartLocationsInfo> {} class SpawnMPUnitsInfo : TraitInfo<SpawnMPUnits>, ITraitPrerequisite<MPStartLocationsInfo> {}
class SpawnMPUnits : IGameStarted class SpawnMPUnits : IWorldLoaded
{ {
public void GameStarted(World world) public void WorldLoaded(World world)
{ {
foreach (var s in world.WorldActor.Trait<MPStartLocations>().Start) foreach (var s in world.WorldActor.Trait<MPStartLocations>().Start)
SpawnUnitsForPlayer(s.Key, s.Value); SpawnUnitsForPlayer(s.Key, s.Value);

View File

@@ -15,17 +15,17 @@ namespace OpenRA.Mods.RA
{ {
public class SpawnMapActorsInfo : TraitInfo<SpawnMapActors> { } public class SpawnMapActorsInfo : TraitInfo<SpawnMapActors> { }
public class SpawnMapActors : IGameStarted public class SpawnMapActors : IWorldLoaded
{ {
public Dictionary<string, Actor> Actors = new Dictionary<string, Actor>(); public Dictionary<string, Actor> Actors = new Dictionary<string, Actor>();
public void GameStarted(World world) public void WorldLoaded(World world)
{ {
foreach( var actorReference in world.Map.Actors ) foreach (var actorReference in world.Map.Actors)
{ {
var initDict = actorReference.Value.InitDict; var initDict = actorReference.Value.InitDict;
initDict.Add( new SkipMakeAnimsInit() ); initDict.Add(new SkipMakeAnimsInit());
Actors[ actorReference.Key ] = world.CreateActor( actorReference.Value.Type, initDict ); Actors[actorReference.Key] = world.CreateActor(actorReference.Value.Type, initDict);
} }
} }
} }