From 7fcf6f9c977eca35d561cd3c42cb34c8e40fa46f Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 11 Aug 2025 23:47:48 +0200 Subject: [PATCH] Add various improvements --- Source/Engine/Animations/Animations.cpp | 2 ++ .../Content/Storage/ContentStorageManager.cpp | 15 ++++++++------- Source/Engine/Core/ObjectsRemovalService.cpp | 3 ++- Source/Engine/Level/Scene/SceneRendering.cpp | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Source/Engine/Animations/Animations.cpp b/Source/Engine/Animations/Animations.cpp index cc3be45b0..d2708edad 100644 --- a/Source/Engine/Animations/Animations.cpp +++ b/Source/Engine/Animations/Animations.cpp @@ -171,10 +171,12 @@ void AnimationsSystem::PostExecute(TaskGraph* graph) void Animations::AddToUpdate(AnimatedModel* obj) { + ConcurrentSystemLocker::WriteScope lock(SystemLocker, true); AnimationManagerInstance.UpdateList.Add(obj); } void Animations::RemoveFromUpdate(AnimatedModel* obj) { + ConcurrentSystemLocker::WriteScope lock(SystemLocker, true); AnimationManagerInstance.UpdateList.Remove(obj); } diff --git a/Source/Engine/Content/Storage/ContentStorageManager.cpp b/Source/Engine/Content/Storage/ContentStorageManager.cpp index f94235664..80744ae45 100644 --- a/Source/Engine/Content/Storage/ContentStorageManager.cpp +++ b/Source/Engine/Content/Storage/ContentStorageManager.cpp @@ -15,14 +15,9 @@ namespace { CriticalSection Locker; -#if USE_EDITOR - Array Files(1024); - Array Packages; -#else Array Files; - Array Packages(64); -#endif - Dictionary StorageMap(2048); + Array Packages; + Dictionary StorageMap; } class ContentStorageService : public EngineService @@ -231,6 +226,12 @@ void ContentStorageManager::GetStorage(Array& result) bool ContentStorageService::Init() { +#if USE_EDITOR + Files.EnsureCapacity(1024); +#else + Packages.EnsureCapacity(64); +#endif + StorageMap.EnsureCapacity(2048); System = New(); Engine::UpdateGraph->AddSystem(System); return false; diff --git a/Source/Engine/Core/ObjectsRemovalService.cpp b/Source/Engine/Core/ObjectsRemovalService.cpp index 88f054a30..f8eb1d78b 100644 --- a/Source/Engine/Core/ObjectsRemovalService.cpp +++ b/Source/Engine/Core/ObjectsRemovalService.cpp @@ -19,7 +19,7 @@ namespace CriticalSection PoolLocker; double LastUpdate; float LastUpdateGameTime; - Dictionary Pool(8192); + Dictionary Pool; uint64 PoolCounter = 0; } @@ -114,6 +114,7 @@ void ObjectsRemovalService::Flush(float dt, float gameDelta) bool ObjectsRemoval::Init() { + Pool.EnsureCapacity(8192); LastUpdate = Platform::GetTimeSeconds(); LastUpdateGameTime = 0; return false; diff --git a/Source/Engine/Level/Scene/SceneRendering.cpp b/Source/Engine/Level/Scene/SceneRendering.cpp index 18f631833..01ac689dc 100644 --- a/Source/Engine/Level/Scene/SceneRendering.cpp +++ b/Source/Engine/Level/Scene/SceneRendering.cpp @@ -191,7 +191,7 @@ void SceneRendering::UpdateActor(Actor* a, int32& key, ISceneRenderingListener:: const int32 category = a->_drawCategory; ConcurrentSystemLocker::ReadScope lock(Locker); // Read-access only as list doesn't get resized (like Add/Remove do) so allow updating actors from different threads at once auto& list = Actors[category]; - if (list.Count() <= key) // Ignore invalid key softly + if (list.Count() <= key || key < 0) // Ignore invalid key softly return; auto& e = list[key]; if (e.Actor == a) @@ -211,7 +211,7 @@ void SceneRendering::RemoveActor(Actor* a, int32& key) const int32 category = a->_drawCategory; ConcurrentSystemLocker::WriteScope lock(Locker, true); auto& list = Actors[category]; - if (list.Count() > key) // Ignore invalid key softly (eg. list after batch clear during scene unload) + if (list.Count() > key || key < 0) // Ignore invalid key softly (eg. list after batch clear during scene unload) { auto& e = list.Get()[key]; if (e.Actor == a)