Lazy actor loading
This commit is contained in:
@@ -30,12 +30,12 @@ namespace OpenRA.Editor
|
|||||||
|
|
||||||
public void Apply(Surface surface)
|
public void Apply(Surface surface)
|
||||||
{
|
{
|
||||||
if (surface.Map.Actors.Any(a => a.Value.Location() == surface.GetBrushLocation()))
|
if (surface.Map.Actors.Value.Any(a => a.Value.Location() == surface.GetBrushLocation()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var owner = "Neutral";
|
var owner = "Neutral";
|
||||||
var id = NextActorName(surface);
|
var id = NextActorName(surface);
|
||||||
surface.Map.Actors[id] = new ActorReference(Actor.Info.Name.ToLowerInvariant())
|
surface.Map.Actors.Value[id] = new ActorReference(Actor.Info.Name.ToLowerInvariant())
|
||||||
{
|
{
|
||||||
new LocationInit( surface.GetBrushLocation() ),
|
new LocationInit( surface.GetBrushLocation() ),
|
||||||
new OwnerInit( owner)
|
new OwnerInit( owner)
|
||||||
@@ -48,7 +48,7 @@ namespace OpenRA.Editor
|
|||||||
for (; ; )
|
for (; ; )
|
||||||
{
|
{
|
||||||
var possible = "Actor{0}".F(id++);
|
var possible = "Actor{0}".F(id++);
|
||||||
if (!surface.Map.Actors.ContainsKey(possible)) return possible;
|
if (!surface.Map.Actors.Value.ContainsKey(possible)) return possible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,12 +148,12 @@ namespace OpenRA.Editor
|
|||||||
ReadCncOverlay(file);
|
ReadCncOverlay(file);
|
||||||
ReadCncTrees(file);
|
ReadCncTrees(file);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
LoadActors(file, "STRUCTURES");
|
LoadActors(file, "STRUCTURES");
|
||||||
LoadActors(file, "UNITS");
|
LoadActors(file, "UNITS");
|
||||||
LoadActors(file, "INFANTRY");
|
LoadActors(file, "INFANTRY");
|
||||||
LoadSmudges(file, "SMUDGE");
|
LoadSmudges(file, "SMUDGE");
|
||||||
|
*/
|
||||||
foreach (var p in Players)
|
foreach (var p in Players)
|
||||||
LoadPlayer(file, p, (legacyMapFormat == IniMapFormat.RedAlert));
|
LoadPlayer(file, p, (legacyMapFormat == IniMapFormat.RedAlert));
|
||||||
|
|
||||||
@@ -163,6 +163,7 @@ namespace OpenRA.Editor
|
|||||||
LocationFromMapOffset(int.Parse(kv.Value), MapSize)))
|
LocationFromMapOffset(int.Parse(kv.Value), MapSize)))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
/*
|
||||||
// Add waypoint actors
|
// Add waypoint actors
|
||||||
foreach( var kv in wps )
|
foreach( var kv in wps )
|
||||||
{
|
{
|
||||||
@@ -170,6 +171,7 @@ namespace OpenRA.Editor
|
|||||||
a.Add(new LocationInit(kv.Second));
|
a.Add(new LocationInit(kv.Second));
|
||||||
Map.Actors.Add("spawn" + kv.First, a);
|
Map.Actors.Add("spawn" + kv.First, a);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static int2 LocationFromMapOffset(int offset, int mapSize)
|
static int2 LocationFromMapOffset(int offset, int mapSize)
|
||||||
@@ -341,7 +343,7 @@ namespace OpenRA.Editor
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
void ReadCncTrees(IniFile file)
|
void ReadCncTrees(IniFile file)
|
||||||
{
|
{
|
||||||
IniSection terrain = file.GetSection("TERRAIN", true);
|
IniSection terrain = file.GetSection("TERRAIN", true);
|
||||||
@@ -417,7 +419,7 @@ namespace OpenRA.Editor
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void LoadSmudges(IniFile file, string section)
|
void LoadSmudges(IniFile file, string section)
|
||||||
{
|
{
|
||||||
foreach (var s in file.GetSection(section, true))
|
foreach (var s in file.GetSection(section, true))
|
||||||
|
|||||||
@@ -152,8 +152,8 @@ namespace OpenRA.Editor
|
|||||||
|
|
||||||
Tool = null;
|
Tool = null;
|
||||||
|
|
||||||
var key = Map.Actors.FirstOrDefault(a => a.Value.Location() == BrushLocation);
|
var key = Map.Actors.Value.FirstOrDefault(a => a.Value.Location() == BrushLocation);
|
||||||
if (key.Key != null) Map.Actors.Remove(key.Key);
|
if (key.Key != null) Map.Actors.Value.Remove(key.Key);
|
||||||
|
|
||||||
if (Map.MapResources.Value[BrushLocation.X, BrushLocation.Y].type != 0)
|
if (Map.MapResources.Value[BrushLocation.X, BrushLocation.Y].type != 0)
|
||||||
{
|
{
|
||||||
@@ -338,7 +338,7 @@ namespace OpenRA.Editor
|
|||||||
Map.Bounds.Width * TileSet.TileSize * Zoom,
|
Map.Bounds.Width * TileSet.TileSize * Zoom,
|
||||||
Map.Bounds.Height * TileSet.TileSize * Zoom);
|
Map.Bounds.Height * TileSet.TileSize * Zoom);
|
||||||
|
|
||||||
foreach (var ar in Map.Actors)
|
foreach (var ar in Map.Actors.Value)
|
||||||
DrawActor(e.Graphics, ar.Value.Location(), ActorTemplates[ar.Value.Type],
|
DrawActor(e.Graphics, ar.Value.Location(), ActorTemplates[ar.Value.Type],
|
||||||
GetPaletteForActor(ar.Value));
|
GetPaletteForActor(ar.Value));
|
||||||
|
|
||||||
@@ -347,7 +347,7 @@ namespace OpenRA.Editor
|
|||||||
|
|
||||||
if (Tool == null)
|
if (Tool == null)
|
||||||
{
|
{
|
||||||
var x = Map.Actors.FirstOrDefault(a => a.Value.Location() == GetBrushLocation());
|
var x = Map.Actors.Value.FirstOrDefault(a => a.Value.Location() == GetBrushLocation());
|
||||||
if (x.Key != null)
|
if (x.Key != null)
|
||||||
DrawActorBorder(e.Graphics, x.Value.Location(), ActorTemplates[x.Value.Type]);
|
DrawActorBorder(e.Graphics, x.Value.Location(), ActorTemplates[x.Value.Type]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ namespace OpenRA
|
|||||||
[FieldLoader.Load] public string Author;
|
[FieldLoader.Load] public string Author;
|
||||||
[FieldLoader.Load] public string Tileset;
|
[FieldLoader.Load] public string Tileset;
|
||||||
|
|
||||||
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
|
public Lazy<Dictionary<string, ActorReference>> Actors;
|
||||||
|
|
||||||
public int PlayerCount { get { return SpawnPoints.Count(); } }
|
public int PlayerCount { get { return SpawnPoints.Count(); } }
|
||||||
public IEnumerable<int2> SpawnPoints { get { return Actors.Values.Where(a => a.Type == "mpspawn").Select(a => a.InitDict.Get<LocationInit>().value); } }
|
public IEnumerable<int2> SpawnPoints { get { return Actors.Value.Values.Where(a => a.Type == "mpspawn").Select(a => a.InitDict.Get<LocationInit>().value); } }
|
||||||
|
|
||||||
[FieldLoader.Load] public Rectangle Bounds;
|
[FieldLoader.Load] public Rectangle Bounds;
|
||||||
|
|
||||||
@@ -90,7 +90,8 @@ namespace OpenRA
|
|||||||
{ { new TileReference<ushort, byte> {
|
{ { new TileReference<ushort, byte> {
|
||||||
type = tile.Key,
|
type = tile.Key,
|
||||||
index = (byte)0 }
|
index = (byte)0 }
|
||||||
} })
|
} }),
|
||||||
|
Actors = Lazy.New(() => new Dictionary<string, ActorReference>())
|
||||||
};
|
};
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
@@ -120,10 +121,27 @@ namespace OpenRA
|
|||||||
if (MapFormat < 4)
|
if (MapFormat < 4)
|
||||||
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, path));
|
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, path));
|
||||||
|
|
||||||
|
|
||||||
|
Actors = Lazy.New(() =>
|
||||||
|
{
|
||||||
|
var ret = new Dictionary<string, ActorReference>();
|
||||||
// Load actors
|
// Load actors
|
||||||
foreach (var kv in yaml.NodesDict["Actors"].NodesDict)
|
foreach (var kv in yaml.NodesDict["Actors"].NodesDict)
|
||||||
Actors.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.NodesDict));
|
ret.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.NodesDict));
|
||||||
|
|
||||||
|
// Add waypoint actors
|
||||||
|
|
||||||
|
if (MapFormat < 5)
|
||||||
|
foreach( var wp in yaml.NodesDict[ "Waypoints" ].NodesDict )
|
||||||
|
{
|
||||||
|
string[] loc = wp.Value.Value.Split( ',' );
|
||||||
|
var a = new ActorReference("mpspawn");
|
||||||
|
a.Add(new LocationInit(new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) )));
|
||||||
|
ret.Add(wp.Key, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
});
|
||||||
|
|
||||||
// Load players
|
// Load players
|
||||||
foreach (var kv in yaml.NodesDict["Players"].NodesDict)
|
foreach (var kv in yaml.NodesDict["Players"].NodesDict)
|
||||||
@@ -138,15 +156,6 @@ namespace OpenRA
|
|||||||
// Define RequiresMod for map installer
|
// Define RequiresMod for map installer
|
||||||
RequiresMod = Game.CurrentMods.Keys.First();
|
RequiresMod = Game.CurrentMods.Keys.First();
|
||||||
|
|
||||||
// Add waypoint actors
|
|
||||||
foreach( var wp in yaml.NodesDict[ "Waypoints" ].NodesDict )
|
|
||||||
{
|
|
||||||
string[] loc = wp.Value.Value.Split( ',' );
|
|
||||||
var a = new ActorReference("mpspawn");
|
|
||||||
a.Add(new LocationInit(new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) )));
|
|
||||||
Actors.Add(wp.Key, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
var TopLeft = (int2)FieldLoader.GetValue( "", typeof(int2), yaml.NodesDict["TopLeft"].Value);
|
var TopLeft = (int2)FieldLoader.GetValue( "", typeof(int2), yaml.NodesDict["TopLeft"].Value);
|
||||||
var BottomRight = (int2)FieldLoader.GetValue( "", typeof(int2), yaml.NodesDict["BottomRight"].Value);
|
var BottomRight = (int2)FieldLoader.GetValue( "", typeof(int2), yaml.NodesDict["BottomRight"].Value);
|
||||||
Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
|
Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
|
||||||
@@ -241,7 +250,7 @@ namespace OpenRA
|
|||||||
FieldSaver.Save( p.Value ) ) ).ToList() ) );
|
FieldSaver.Save( p.Value ) ) ).ToList() ) );
|
||||||
|
|
||||||
root.Add( new MiniYamlNode( "Actors", null,
|
root.Add( new MiniYamlNode( "Actors", null,
|
||||||
Actors.Select( x => new MiniYamlNode(
|
Actors.Value.Select( x => new MiniYamlNode(
|
||||||
x.Key,
|
x.Key,
|
||||||
x.Value.Save() ) ).ToList() ) );
|
x.Value.Save() ) ).ToList() ) );
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public void WorldLoaded(World world)
|
public void WorldLoaded(World world)
|
||||||
{
|
{
|
||||||
foreach (var actorReference in world.Map.Actors)
|
foreach (var actorReference in world.Map.Actors.Value)
|
||||||
{
|
{
|
||||||
var initDict = actorReference.Value.InitDict;
|
var initDict = actorReference.Value.InitDict;
|
||||||
initDict.Add(new SkipMakeAnimsInit());
|
initDict.Add(new SkipMakeAnimsInit());
|
||||||
|
|||||||
Reference in New Issue
Block a user