Rename "Created" to "Initialize" and let it handle adding to the world

This commit is contained in:
abcdefg30
2020-05-25 16:37:23 +02:00
committed by reaperrr
parent 7386816f52
commit 52a9fcef3c
3 changed files with 8 additions and 9 deletions

View File

@@ -172,7 +172,7 @@ namespace OpenRA
SyncHashes = TraitsImplementing<ISync>().Select(sync => new SyncHash(sync)).ToArray(); SyncHashes = TraitsImplementing<ISync>().Select(sync => new SyncHash(sync)).ToArray();
} }
internal void Created() internal void Initialize(bool addToWorld = true)
{ {
created = true; created = true;
@@ -226,6 +226,9 @@ namespace OpenRA
activity.Queue(CurrentActivity); activity.Queue(CurrentActivity);
CurrentActivity = activity; CurrentActivity = activity;
} }
if (addToWorld)
World.Add(this);
} }
public void Tick() public void Tick()

View File

@@ -169,12 +169,11 @@ namespace OpenRA
// Special case handling is required for the Player actor: // Special case handling is required for the Player actor:
// Since Actor.Created would be called before PlayerActor is assigned here // Since Actor.Created would be called before PlayerActor is assigned here
// querying player traits in INotifyCreated.Created would crash. // querying player traits in INotifyCreated.Created would crash.
// Therefore only call the constructor of Actor and run the Created callbacks ourselves. // Therefore assign the uninitialized actor and run the Created callbacks
// Add the PlayerActor to the world afterwards. // by calling Initialize ourselves.
var playerActorType = world.Type == WorldType.Editor ? EditorPlayerActorType : PlayerActorType; var playerActorType = world.Type == WorldType.Editor ? EditorPlayerActorType : PlayerActorType;
PlayerActor = new Actor(world, playerActorType, new TypeDictionary { new OwnerInit(this) }); PlayerActor = new Actor(world, playerActorType, new TypeDictionary { new OwnerInit(this) });
PlayerActor.Created(); PlayerActor.Initialize(true);
world.Add(PlayerActor);
Shroud = PlayerActor.Trait<Shroud>(); Shroud = PlayerActor.Trait<Shroud>();
FrozenActorLayer = PlayerActor.TraitOrDefault<FrozenActorLayer>(); FrozenActorLayer = PlayerActor.TraitOrDefault<FrozenActorLayer>();

View File

@@ -337,10 +337,7 @@ namespace OpenRA
public Actor CreateActor(bool addToWorld, string name, TypeDictionary initDict) public Actor CreateActor(bool addToWorld, string name, TypeDictionary initDict)
{ {
var a = new Actor(this, name, initDict); var a = new Actor(this, name, initDict);
a.Created(); a.Initialize(addToWorld);
if (addToWorld)
Add(a);
return a; return a;
} }