From 53b20a23960a5ecb5f112717b2dddafcb60a8baf Mon Sep 17 00:00:00 2001 From: Garrett <52760019+Casimir255@users.noreply.github.com> Date: Sun, 21 Jul 2024 16:29:23 -0500 Subject: [PATCH] Revert "Cleanup" This reverts commit 6f1edc1f334ec15d73afaa31f4630c01fca9523d. --- Components/ServerSwitcherComponentOLD.cs | 38 +++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Components/ServerSwitcherComponentOLD.cs b/Components/ServerSwitcherComponentOLD.cs index 66011bb..ae5e7ad 100644 --- a/Components/ServerSwitcherComponentOLD.cs +++ b/Components/ServerSwitcherComponentOLD.cs @@ -191,6 +191,8 @@ namespace SeamlessClient.Components MyMultiplayer.Static.OnSessionReady(); + + UpdateWorldGenerator(); UpdateSessionComponents(TargetWorld.Checkpoint.SessionComponents); StartEntitySync(); @@ -425,6 +427,41 @@ namespace SeamlessClient.Components MyMultiplayer.Static.PendingReplicablesDone -= MyMultiplayer_PendingReplicableDone; } + + private static void UpdateWorldGenerator() + { + //This will re-init the MyProceduralWorldGenerator. (Not doing this will result in asteroids not rendering in properly) + + + //This shoud never be null + var Generator = MySession.Static.GetComponent(); + + //Force component to unload + UnloadProceduralWorldGenerator.Invoke(Generator, null); + + //Re-call the generator init + MyObjectBuilder_WorldGenerator GeneratorSettings = (MyObjectBuilder_WorldGenerator)TargetWorld.Checkpoint.SessionComponents.FirstOrDefault(x => x.GetType() == typeof(MyObjectBuilder_WorldGenerator)); + if (GeneratorSettings != null) + { + //Re-initilized this component (forces to update asteroid areas like not in planets etc) + Generator.Init(GeneratorSettings); + } + + //Force component to reload, re-syncing settings and seeds to the destination server + Generator.LoadData(); + + //We need to go in and force planets to be empty areas in the generator. This is originially done on planet init. + FieldInfo PlanetInitArgs = typeof(MyPlanet).GetField("m_planetInitValues", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + foreach (var Planet in MyEntities.GetEntities().OfType()) + { + MyPlanetInitArguments args = (MyPlanetInitArguments)PlanetInitArgs.GetValue(Planet); + + float MaxRadius = args.MaxRadius; + + Generator.MarkEmptyArea(Planet.PositionComp.GetPosition(), MaxRadius); + } + } + private void UnloadCurrentServer() { //Unload current session on game thread @@ -520,7 +557,6 @@ namespace SeamlessClient.Components if(dict.TryGetValue(t, out var component) & ValidInitTypes.Contains(component.GetType())) { component.Init(entity); - component.LoadData(); } }