diff --git a/Assets/Gothic-Core/Scripts/Domain/Culling/NpcMeshCullingDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Culling/NpcMeshCullingDomain.cs index 8e2e8c732..6dafa8695 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Culling/NpcMeshCullingDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Culling/NpcMeshCullingDomain.cs @@ -253,5 +253,11 @@ public List GetVisibleNpcs() return visibleNpcs; } + + public IEnumerable GetAllNpcContainers() + { + for (var i = 0; i < _count; i++) + yield return _loaders[i].Container; + } } } diff --git a/Assets/Gothic-Core/Scripts/Services/Culling/NpcMeshCullingService.cs b/Assets/Gothic-Core/Scripts/Services/Culling/NpcMeshCullingService.cs index 0b3c6f17f..c63cdff3b 100644 --- a/Assets/Gothic-Core/Scripts/Services/Culling/NpcMeshCullingService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Culling/NpcMeshCullingService.cs @@ -44,5 +44,10 @@ public List GetVisibleNpcs() { return _npcDomain.GetVisibleNpcs(); } + + public IEnumerable GetAllNpcContainers() + { + return _npcDomain.GetAllNpcContainers(); + } } } diff --git a/Assets/Gothic-Core/Scripts/Services/Npc/NpcRoutineService.cs b/Assets/Gothic-Core/Scripts/Services/Npc/NpcRoutineService.cs index 07243bfc8..8af3bf2af 100644 --- a/Assets/Gothic-Core/Scripts/Services/Npc/NpcRoutineService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Npc/NpcRoutineService.cs @@ -140,7 +140,25 @@ public bool CalculateCurrentRoutine(NpcInstance npc) } npcProps.RoutineCurrent = newRoutine; + if (changed) + _npcMeshCullingService.NotifyNpcRoutineChanged(npc.GetUserData()); + return changed; } + + /// + /// Re-evaluates the time-based routine for all NPCs. Culled NPCs whose routine changed + /// will have their culling sphere moved to the new waypoint via NotifyNpcRoutineChanged. + /// Call this after a time skip so off-screen NPCs appear at their correct schedule position. + /// + public void RecalculateAllNpcRoutines() + { + foreach (var container in _npcMeshCullingService.GetAllNpcContainers()) + { + if (container?.Props?.Routines == null || container.Props.Routines.Count == 0) + continue; + CalculateCurrentRoutine(container.Instance); + } + } } }