diff --git a/Source/Engine/Content/Content.cpp b/Source/Engine/Content/Content.cpp index 183903c3b..47ec97c0a 100644 --- a/Source/Engine/Content/Content.cpp +++ b/Source/Engine/Content/Content.cpp @@ -68,10 +68,9 @@ namespace { // Assets CriticalSection AssetsLocker; - Dictionary Assets(2048); - Array LoadCallAssets(PLATFORM_THREADS_LIMIT); + Dictionary Assets; CriticalSection LoadedAssetsToInvokeLocker; - Array LoadedAssetsToInvoke(64); + Array LoadedAssetsToInvoke; Array ToUnload; // Assets Registry Stuff @@ -85,6 +84,7 @@ namespace ConcurrentTaskQueue LoadTasks; ConditionVariable LoadTasksSignal; CriticalSection LoadTasksMutex; + Array LoadCallAssets; #else Array LoadTasks; #endif @@ -125,6 +125,13 @@ bool ContentService::Init() { PROFILE_MEM(Content); + // Init memory containers + Assets.EnsureCapacity(2048); + LoadedAssetsToInvoke.EnsureCapacity(64); +#if PLATFORM_THREADS_LIMIT > 1 + LoadCallAssets.EnsureCapacity(PLATFORM_THREADS_LIMIT); +#endif + // Load assets registry Cache.Init(); @@ -294,6 +301,7 @@ void ContentService::Dispose() for (auto* e : LoadTasks) e->Cancel(); LoadTasks.Clear(); + LoadTasks.SetCapacity(0); #endif } @@ -1381,6 +1389,7 @@ Asset* Content::LoadAsync(const Guid& id, const ScriptingTypeHandle& type) return result; } +#if PLATFORM_THREADS_LIMIT > 1 // Check if that asset is during loading if (LoadCallAssets.Contains(id)) { @@ -1401,9 +1410,12 @@ Asset* Content::LoadAsync(const Guid& id, const ScriptingTypeHandle& type) // Mark asset as loading and release lock so other threads can load other assets LoadCallAssets.Add(id); - AssetsLocker.Unlock(); - #define LOAD_FAILED() AssetsLocker.Lock(); LoadCallAssets.Remove(id); AssetsLocker.Unlock(); return nullptr +#else +#define LOAD_FAILED() return nullptr +#endif + + AssetsLocker.Unlock(); // Get cached asset info (from registry) AssetInfo assetInfo; @@ -1461,7 +1473,9 @@ Asset* Content::LoadAsync(const Guid& id, const ScriptingTypeHandle& type) result->startLoading(); // Remove from the loading queue and release lock +#if PLATFORM_THREADS_LIMIT > 1 LoadCallAssets.Remove(id); +#endif AssetsLocker.Unlock(); #undef LOAD_FAILED diff --git a/Source/Engine/Navigation/Navigation.cpp b/Source/Engine/Navigation/Navigation.cpp index 908819765..3dd4a13f0 100644 --- a/Source/Engine/Navigation/Navigation.cpp +++ b/Source/Engine/Navigation/Navigation.cpp @@ -164,9 +164,6 @@ public: NavigationService() : EngineService(TEXT("Navigation"), 60) { -#if COMPILE_WITH_NAV_MESH_BUILDER - NavMeshBuilder::Init(); -#endif } bool Init() override; @@ -305,6 +302,11 @@ void NavigationSettings::Deserialize(DeserializeStream& stream, ISerializeModifi bool NavigationService::Init() { + PROFILE_MEM(Navigation); +#if COMPILE_WITH_NAV_MESH_BUILDER + NavMeshBuilder::Init(); +#endif + // Link memory allocation calls to use engine default allocator dtAllocSetCustom(dtAllocDefault, Allocator::Free); rcAllocSetCustom(rcAllocDefault, Allocator::Free); diff --git a/Source/Engine/Platform/Web/WebPlatform.cpp b/Source/Engine/Platform/Web/WebPlatform.cpp index 20f036532..8fd8aec94 100644 --- a/Source/Engine/Platform/Web/WebPlatform.cpp +++ b/Source/Engine/Platform/Web/WebPlatform.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -78,6 +79,38 @@ void WebFileSystem::GetSpecialFolderPath(const SpecialFolder type, String& resul result = TEXT("/"); } +#if 0 + +void* WebPlatform::Allocate(uint64 size, uint64 alignment) +{ + void* ptr = nullptr; + if (alignment && size) + { + // Alignment always has to be power of two + ASSERT_LOW_LAYER((alignment & (alignment - 1)) == 0); + ptr = emscripten_builtin_memalign(alignment, size); + if (!ptr) + OutOfMemory(); +#if COMPILE_WITH_PROFILER + OnMemoryAlloc(ptr, size); +#endif + } + return ptr; +} + +void WebPlatform::Free(void* ptr) +{ + if (ptr) + { +#if COMPILE_WITH_PROFILER + OnMemoryFree(ptr); +#endif + emscripten_builtin_free(ptr); + } +} + +#endif + String WebPlatform::GetSystemName() { return TEXT("Browser"); diff --git a/Source/Engine/Platform/Web/WebPlatform.h b/Source/Engine/Platform/Web/WebPlatform.h index a0d17510a..b93b6ef12 100644 --- a/Source/Engine/Platform/Web/WebPlatform.h +++ b/Source/Engine/Platform/Web/WebPlatform.h @@ -92,6 +92,10 @@ public: *dst = value; #endif } +#if 0 + static void* Allocate(uint64 size, uint64 alignment); + static void Free(void* ptr); +#endif FORCE_INLINE static uint64 GetCurrentThreadID() { #ifdef __EMSCRIPTEN_PTHREADS__ diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index 82a589390..70127bf94 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -227,8 +227,8 @@ namespace CachedPSO PsoDepth; CachedPSO PsoNoDepth; CachedPSO* CurrentPso = nullptr; - DynamicVertexBuffer VB(RENDER2D_INITIAL_VB_CAPACITY, (uint32)sizeof(Render2DVertex), TEXT("Render2D.VB")); - DynamicIndexBuffer IB(RENDER2D_INITIAL_IB_CAPACITY, sizeof(uint32), TEXT("Render2D.IB")); + DynamicVertexBuffer VB(0, (uint32)sizeof(Render2DVertex), TEXT("Render2D.VB")); + DynamicIndexBuffer IB(0, sizeof(uint32), TEXT("Render2D.IB")); uint32 VBIndex = 0; uint32 IBIndex = 0; } @@ -633,6 +633,8 @@ bool Render2DService::Init() })); DrawCalls.EnsureCapacity(RENDER2D_INITIAL_DRAW_CALL_CAPACITY); + VB.Data.EnsureCapacity(RENDER2D_INITIAL_VB_CAPACITY); + IB.Data.EnsureCapacity(RENDER2D_INITIAL_IB_CAPACITY); return false; } diff --git a/Source/Engine/Renderer/Renderer.cpp b/Source/Engine/Renderer/Renderer.cpp index 29a80b435..7b09f73ee 100644 --- a/Source/Engine/Renderer/Renderer.cpp +++ b/Source/Engine/Renderer/Renderer.cpp @@ -50,7 +50,7 @@ bool IsBakingLightmaps = false; bool EnableLightmapsUsage = true; #endif -Array PassList(64); +Array PassList; class RendererService : public EngineService { @@ -73,6 +73,7 @@ bool RendererService::Init() PROFILE_MEM(Graphics); // Register passes + PassList.EnsureCapacity(64); PassList.Add(GBufferPass::Instance()); PassList.Add(ShadowsPass::Instance()); PassList.Add(LightPass::Instance()); diff --git a/Source/Engine/Scripting/Scripting.cpp b/Source/Engine/Scripting/Scripting.cpp index 9b8439528..6ee572ef7 100644 --- a/Source/Engine/Scripting/Scripting.cpp +++ b/Source/Engine/Scripting/Scripting.cpp @@ -96,9 +96,9 @@ namespace } }; - Dictionary _objectsDictionary(1024 * 16); + Dictionary _objectsDictionary; #else - Dictionary _objectsDictionary(1024 * 16); + Dictionary _objectsDictionary; #endif bool _isEngineAssemblyLoaded = false; bool _hasGameModulesLoaded = false; @@ -179,6 +179,8 @@ bool ScriptingService::Init() PROFILE_MEM(Scripting); Stopwatch stopwatch; + _objectsDictionary.EnsureCapacity(16 * 1024); + // Initialize managed runtime if (MCore::LoadEngine()) {