11using System . Collections ;
2+ using System . Linq ;
23using NitroxClient . GameLogic . InitialSync . Base ;
4+ using NitroxClient . MonoBehaviours ;
35using NitroxModel . DataStructures . GameLogic ;
6+ using NitroxModel . Logger ;
47using NitroxModel . Packets ;
58using NitroxModel_Subnautica . Helper ;
69using UnityEngine ;
@@ -10,7 +13,7 @@ namespace NitroxClient.GameLogic.InitialSync
1013 class CyclopsInitialAsyncProcessor : InitialSyncProcessor
1114 {
1215 private readonly Vehicles vehicles ;
13- private int cyclopsStillLoading = 0 ;
16+ private int cyclopsLoaded = 0 ;
1417 private int totalCyclopsToLoad = 0 ;
1518 private WaitScreen . ManualWaitItem waitScreenItem ;
1619
@@ -22,34 +25,35 @@ public CyclopsInitialAsyncProcessor(Vehicles vehicles)
2225 public override IEnumerator Process ( InitialPlayerSync packet , WaitScreen . ManualWaitItem waitScreenItem )
2326 {
2427 this . waitScreenItem = waitScreenItem ;
25-
2628 vehicles . VehicleCreated += OnVehicleCreated ;
2729
30+ totalCyclopsToLoad = packet . Vehicles . Where ( v => v . TechType . Enum ( ) == TechType . Cyclops ) . Count ( ) ;
31+
2832 foreach ( VehicleModel vehicle in packet . Vehicles )
2933 {
3034 if ( vehicle . TechType . Enum ( ) == TechType . Cyclops )
3135 {
32- cyclopsStillLoading ++ ;
36+ Log . Debug ( $ "Trying to spawn { vehicle } " ) ;
3337 vehicles . CreateVehicle ( vehicle ) ;
3438 }
3539 }
3640
37- totalCyclopsToLoad = cyclopsStillLoading ;
38-
39- yield return new WaitUntil ( ( ) => cyclopsStillLoading == 0 ) ;
41+ yield return new WaitUntil ( ( ) => cyclopsLoaded == totalCyclopsToLoad ) ;
4042 }
4143
4244 private void OnVehicleCreated ( GameObject gameObject )
4345 {
44- waitScreenItem . SetProgress ( ( totalCyclopsToLoad - cyclopsStillLoading ) , totalCyclopsToLoad ) ;
45-
46- cyclopsStillLoading -- ;
46+ cyclopsLoaded ++ ;
47+ waitScreenItem . SetProgress ( cyclopsLoaded , totalCyclopsToLoad ) ;
4748
4849 // After all cyclops are created
49- if ( cyclopsStillLoading == 0 )
50+ if ( cyclopsLoaded == totalCyclopsToLoad )
5051 {
5152 vehicles . VehicleCreated -= OnVehicleCreated ;
52- }
53+ Log . Debug ( $ "Spawned cyclops { NitroxEntity . GetId ( gameObject ) } ") ;
54+ }
55+
56+ Log . Debug ( $ "We still need to load { totalCyclopsToLoad - cyclopsLoaded } cyclops") ;
5357 }
5458 }
5559}
0 commit comments