public void Load(VMMarshal input)
{
var clientJoin = (Context.Architecture == null);
var oldWorld = Context.World;
Context = new VMContext(input.Context, Context);
Context.Globals = FSO.Content.Content.Get().WorldObjectGlobals.Get("global");
Context.VM = this;
Context.Architecture.RegenRoomMap();
Context.RegeneratePortalInfo();
var oldSounds = new List<VMSoundTransfer>();
if (Entities != null) //free any object resources here.
{
foreach (var obj in Entities)
{
obj.Dead = true;
if (obj.HeadlineRenderer != null) obj.HeadlineRenderer.Dispose();
oldSounds.AddRange(obj.GetActiveSounds());
}
}
Entities = new List<VMEntity>();
ObjectsById = new Dictionary<short, VMEntity>();
foreach (var ent in input.Entities)
{
VMEntity realEnt;
var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID);
if (ent is VMAvatarMarshal)
{
var avatar = new VMAvatar(objDefinition);
avatar.Load((VMAvatarMarshal)ent);
if (UseWorld) Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI);
realEnt = avatar;
}
else
{
var worldObject = new ObjectComponent(objDefinition);
var obj = new VMGameObject(objDefinition, worldObject);
obj.Load((VMGameObjectMarshal)ent);
Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI);
Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position);
obj.Position = obj.Position;
realEnt = obj;
}
realEnt.GenerateTreeByName(Context);
Entities.Add(realEnt);
Context.SetToNextCache.NewObject(realEnt);
ObjectsById.Add(ent.ObjectID, realEnt);
}
int i = 0;
foreach (var ent in input.Entities)
{
var threadMarsh = input.Threads[i];
var realEnt = Entities[i++];
realEnt.Thread = new VMThread(threadMarsh, Context, realEnt);
if (realEnt is VMAvatar)
((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context);
else
((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context);
}
foreach (var multi in input.MultitileGroups)
{
new VMMultitileGroup(multi, Context); //should self register
}
foreach (var ent in Entities)
{
if (ent.Container == null) ent.PositionChange(Context, true); //called recursively for contained objects.
}
GlobalState = input.GlobalState;
PlatformState = input.PlatformState;
ObjectId = input.ObjectId;
//just a few final changes to refresh everything, and avoid signalling objects
var clock = Context.Clock;
Context.Architecture.SetTimeOfDay(clock.Hours / 24.0 + clock.Minutes / (24.0 * 60) + clock.Seconds / (24.0 * 60 * 60));
Context.Architecture.RegenRoomMap();
Context.RegeneratePortalInfo();
Context.Architecture.WallDirtyState(input.Context.Architecture);
foreach (var snd in oldSounds)
{
//find new owners
var obj = GetObjectById(snd.SourceID);
if (obj == null || obj.Object.GUID != snd.SourceGUID) snd.SFX.Sound.RemoveOwner(snd.SourceID);
else obj.SoundThreads.Add(snd.SFX); // successfully transfer sound to new object
}
if (clientJoin)
{
//run clientJoin functions to play object sounds, update some gfx.
foreach (var obj in Entities)
{
obj.ExecuteEntryPoint(30, Context, true);
}
}
if (OnFullRefresh != null) OnFullRefresh();
}