diff --git a/Source/Engine/Content/Asset.cpp b/Source/Engine/Content/Asset.cpp index 9bad11533..11b1bed39 100644 --- a/Source/Engine/Content/Asset.cpp +++ b/Source/Engine/Content/Asset.cpp @@ -38,9 +38,10 @@ void Asset::OnDeleteObject() if (!IsInternalType()) Content::AssetDisposing(this); - // Cache data const bool wasMarkedToDelete = _deleteFileOnUnload != 0; +#if USE_EDITOR const String path = wasMarkedToDelete ? GetPath() : String::Empty; +#endif const Guid id = GetID(); // Fire unload event (every object referencing this asset or it's data should release reference so later actions are safe) @@ -66,7 +67,7 @@ void Asset::OnDeleteObject() // Base (after it `this` is invalid) ManagedScriptingObject::OnDeleteObject(); - // Check if asset was marked to delete +#if USE_EDITOR if (wasMarkedToDelete) { LOG(Info, "Deleting asset '{0}':{1}.", path, id.ToString()); @@ -77,6 +78,7 @@ void Asset::OnDeleteObject() // Delete file Content::deleteFileSafety(path, id); } +#endif } void Asset::CreateManaged() @@ -131,6 +133,20 @@ void Asset::ChangeID(const Guid& newId) CRASH; } +bool Asset::LastLoadFailed() const +{ + return _loadFailed != 0; +} + +#if USE_EDITOR + +bool Asset::ShouldDeleteFileOnUnload() const +{ + return _deleteFileOnUnload != 0; +} + +#endif + void Asset::Reload() { // It's better to call it from the main thread @@ -335,7 +351,7 @@ void Asset::startLoading() bool Asset::onLoad(LoadAssetTask* task) { // It may fail when task is cancelled and new one is created later (don't crash but just end with an error) - if (task->GetAsset() != this || _loadingTask == nullptr) + if (task->Asset.Get() != this || _loadingTask == nullptr) return true; Locker.Lock(); diff --git a/Source/Engine/Content/Asset.h b/Source/Engine/Content/Asset.h index fb62e659c..8cb801647 100644 --- a/Source/Engine/Content/Asset.h +++ b/Source/Engine/Content/Asset.h @@ -82,7 +82,6 @@ public: /// /// Gets asset's reference count. Asset will be automatically unloaded when this reaches zero. /// - /// The amount of references to that asset. API_PROPERTY() int32 GetReferencesCount() const { return (int32)Platform::AtomicRead(const_cast(&_refCount)); @@ -109,19 +108,16 @@ public: /// /// Gets the path to the asset storage. /// - /// The asset file. API_PROPERTY() virtual const String& GetPath() const = 0; /// /// Gets the asset type name. /// - /// The typename. virtual const String& GetTypeName() const = 0; /// /// Returns true if asset is loaded, otherwise false. /// - /// true if this asset is loaded; otherwise, false. API_PROPERTY() FORCE_INLINE bool IsLoaded() const { return _isLoaded != 0; @@ -130,16 +126,11 @@ public: /// /// Returns true if last asset loading failed, otherwise false. /// - /// true if last asset loading failed; otherwise, false. - API_PROPERTY() FORCE_INLINE bool LastLoadFailed() const - { - return _loadFailed != 0; - } + API_PROPERTY() bool LastLoadFailed() const; /// /// Determines whether this asset is virtual (generated or temporary, has no storage so it won't be saved). /// - /// true if this asset is virtual; otherwise, false. API_PROPERTY() FORCE_INLINE bool IsVirtual() const { return _isVirtual != 0; @@ -150,11 +141,7 @@ public: /// /// Determines whether this asset was marked to be deleted on unload. /// - /// true if this asset file was marked to be deleted on asset unload; otherwise, false. - API_PROPERTY() FORCE_INLINE bool ShouldDeleteFileOnUnload() const - { - return _deleteFileOnUnload != 0; - } + API_PROPERTY() bool ShouldDeleteFileOnUnload() const; #endif diff --git a/Source/Engine/Content/Assets/AnimationGraph.cpp b/Source/Engine/Content/Assets/AnimationGraph.cpp index 078a7a305..7106fb0e0 100644 --- a/Source/Engine/Content/Assets/AnimationGraph.cpp +++ b/Source/Engine/Content/Assets/AnimationGraph.cpp @@ -74,7 +74,7 @@ BytesContainer AnimationGraph::LoadSurface() return result; } - LOG(Warning, "Animation Graph \'{0}\' surface data is missing.", GetPath()); + LOG(Warning, "Animation Graph \'{0}\' surface data is missing.", ToString()); return BytesContainer(); } diff --git a/Source/Engine/Content/Assets/Material.cpp b/Source/Engine/Content/Assets/Material.cpp index 1f97c6f08..2be5a6b61 100644 --- a/Source/Engine/Content/Assets/Material.cpp +++ b/Source/Engine/Content/Assets/Material.cpp @@ -311,7 +311,12 @@ Asset::LoadResult Material::load() { // Load material (load shader from cache, load params, setup pipeline stuff) MemoryReadStream shaderCacheStream(shaderCache.Data.Get(), shaderCache.Data.Length()); - _materialShader = MaterialShader::Create(GetPath(), shaderCacheStream, _shaderHeader.Material.Info); +#if GPU_ENABLE_RESOURCE_NAMING + const StringView name(GetPath()); +#else + const StringView name; +#endif + _materialShader = MaterialShader::Create(name, shaderCacheStream, _shaderHeader.Material.Info); if (_materialShader == nullptr) { LOG(Warning, "Cannot load material."); @@ -483,7 +488,7 @@ BytesContainer Material::LoadSurface(bool createDefaultIfMissing) } } - LOG(Warning, "Material \'{0}\' surface data is missing.", GetPath()); + LOG(Warning, "Material \'{0}\' surface data is missing.", ToString()); #if COMPILE_WITH_MATERIAL_GRAPH diff --git a/Source/Engine/Content/Assets/Model.cpp b/Source/Engine/Content/Assets/Model.cpp index b05dece38..dd9c484e1 100644 --- a/Source/Engine/Content/Assets/Model.cpp +++ b/Source/Engine/Content/Assets/Model.cpp @@ -821,7 +821,7 @@ Asset::LoadResult Model::load() const auto thisSS = LODs[lodIndex].ScreenSize; if (prevSS <= thisSS) { - LOG(Warning, "Model LOD {0} has invalid screen size compared to LOD {1} (asset: {2})", lodIndex, lodIndex - 1, GetPath()); + LOG(Warning, "Model LOD {0} has invalid screen size compared to LOD {1} (asset: {2})", lodIndex, lodIndex - 1, ToString()); } } #endif diff --git a/Source/Engine/Content/Assets/VisualScript.cpp b/Source/Engine/Content/Assets/VisualScript.cpp index 6667f973d..1b1a30ec4 100644 --- a/Source/Engine/Content/Assets/VisualScript.cpp +++ b/Source/Engine/Content/Assets/VisualScript.cpp @@ -2132,7 +2132,7 @@ BytesContainer VisualScript::LoadSurface() return result; } - LOG(Warning, "\'{0}\' surface data is missing.", GetPath()); + LOG(Warning, "\'{0}\' surface data is missing.", ToString()); return BytesContainer(); } diff --git a/Source/Engine/Content/BinaryAsset.cpp b/Source/Engine/Content/BinaryAsset.cpp index 79ad9f8dc..5b79c1b7d 100644 --- a/Source/Engine/Content/BinaryAsset.cpp +++ b/Source/Engine/Content/BinaryAsset.cpp @@ -301,7 +301,12 @@ bool BinaryAsset::LoadChunks(AssetChunksFlag chunks) #if USE_EDITOR -bool BinaryAsset::SaveAsset(const StringView& path, AssetInitData& data, bool silentMode) +bool BinaryAsset::SaveAsset(AssetInitData& data, bool silentMode) const +{ + return SaveAsset(GetPath(), data, silentMode); +} + +bool BinaryAsset::SaveAsset(const StringView& path, AssetInitData& data, bool silentMode) const { data.Header = _header; data.Metadata.Link(Metadata); diff --git a/Source/Engine/Content/BinaryAsset.h b/Source/Engine/Content/BinaryAsset.h index f73c7ec6e..207faadfa 100644 --- a/Source/Engine/Content/BinaryAsset.h +++ b/Source/Engine/Content/BinaryAsset.h @@ -270,10 +270,7 @@ public: /// Asset data. /// In silent mode don't reload opened storage container that is using target file. /// True if failed, otherwise false. - FORCE_INLINE bool SaveAsset(AssetInitData& data, bool silentMode = false) - { - return SaveAsset(GetPath(), data, silentMode); - } + bool SaveAsset(AssetInitData& data, bool silentMode = false) const; /// /// Saves this asset to the file. @@ -282,7 +279,7 @@ public: /// Asset path (will be used to override the asset or create a new one). /// In silent mode don't reload opened storage container that is using target file. /// True if failed, otherwise false. - bool SaveAsset(const StringView& path, AssetInitData& data, bool silentMode = false); + bool SaveAsset(const StringView& path, AssetInitData& data, bool silentMode = false) const; /// /// Saves asset data to the storage container. Asset unique ID is handled by auto. diff --git a/Source/Engine/Content/Factories/BinaryAssetFactory.cpp b/Source/Engine/Content/Factories/BinaryAssetFactory.cpp index 9dedd92f9..220ea5ed5 100644 --- a/Source/Engine/Content/Factories/BinaryAssetFactory.cpp +++ b/Source/Engine/Content/Factories/BinaryAssetFactory.cpp @@ -15,19 +15,13 @@ bool BinaryAssetFactoryBase::Init(BinaryAsset* asset) { ASSERT(asset && asset->Storage); - - // Prepare auto storage = asset->Storage; - AssetInfo info; - info.ID = asset->GetID(); - info.TypeName = asset->GetTypeName(); - info.Path = storage->GetPath(); // Load serialized asset data AssetInitData initData; - if (storage->LoadAssetHeader(info.ID, initData)) + if (storage->LoadAssetHeader(asset->GetID(), initData)) { - LOG(Error, "Cannot load asset header.\nInfo: {0}", info.ToString()); + LOG(Error, "Cannot load asset header.\nInfo: {0}", AssetInfo(asset->GetID(), asset->GetTypeName(), storage->GetPath()).ToString()); return true; } @@ -37,6 +31,7 @@ bool BinaryAssetFactoryBase::Init(BinaryAsset* asset) if (storage->AllowDataModifications() && upgrader && upgrader->ShouldUpgrade(initData.SerializedVersion)) { const auto startTime = DateTime::NowUTC(); + const AssetInfo info(asset->GetID(), asset->GetTypeName(), storage->GetPath()); LOG(Info, "Starting asset \'{0}\' conversion", info.Path); // Backup source file (in case of conversion failure) @@ -100,14 +95,14 @@ bool BinaryAssetFactoryBase::Init(BinaryAsset* asset) // Check if serialized asset version is supported if (!IsVersionSupported(initData.SerializedVersion)) { - LOG(Warning, "Asset version {1} is not supported.\nInfo: {0}", info.ToString(), initData.SerializedVersion); + LOG(Warning, "Asset version {1} is not supported.\nInfo: {0}", AssetInfo(asset->GetID(), asset->GetTypeName(), storage->GetPath()).ToString(), initData.SerializedVersion); return true; } // Initialize asset if (asset->Init(initData)) { - LOG(Error, "Cannot initialize asset.\nInfo: {0}", info.ToString()); + LOG(Error, "Cannot initialize asset.\nInfo: {0}", AssetInfo(asset->GetID(), asset->GetTypeName(), storage->GetPath()).ToString()); return true; } diff --git a/Source/Engine/Content/JsonAsset.cpp b/Source/Engine/Content/JsonAsset.cpp index f84ba9f88..aade1a29c 100644 --- a/Source/Engine/Content/JsonAsset.cpp +++ b/Source/Engine/Content/JsonAsset.cpp @@ -1,10 +1,11 @@ // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #include "JsonAsset.h" -#include "Storage/ContentStorageManager.h" #include "Engine/Threading/Threading.h" #if USE_EDITOR #include "Engine/Platform/File.h" +#else +#include "Storage/ContentStorageManager.h" #endif #include "FlaxEngine.Gen.h" #include "Engine/Core/Log.h" diff --git a/Source/Engine/Content/Loading/Tasks/LoadAssetTask.h b/Source/Engine/Content/Loading/Tasks/LoadAssetTask.h index 7a7ea285f..ae8dab9e6 100644 --- a/Source/Engine/Content/Loading/Tasks/LoadAssetTask.h +++ b/Source/Engine/Content/Loading/Tasks/LoadAssetTask.h @@ -13,10 +13,6 @@ /// class LoadAssetTask : public ContentLoadTask { -private: - - WeakAssetReference _asset; - public: /// @@ -25,27 +21,20 @@ public: /// The asset to load. LoadAssetTask(Asset* asset) : ContentLoadTask(Type::LoadAsset) - , _asset(asset) + , Asset(asset) { } public: - /// - /// Gets the asset. - /// - /// The asset. - FORCE_INLINE Asset* GetAsset() const - { - return _asset.Get(); - } + WeakAssetReference Asset; public: // [ContentLoadTask] bool HasReference(Object* obj) const override { - return obj == _asset; + return obj == Asset; } protected: @@ -55,7 +44,8 @@ protected: { PROFILE_CPU(); - AssetReference ref = _asset.Get(); + // Keep valid ref to the asset + AssetReference<::Asset> ref = Asset.Get(); if (ref == nullptr) return Result::MissingReferences; @@ -68,7 +58,7 @@ protected: void OnEnd() override { - _asset = nullptr; + Asset = nullptr; // Base ContentLoadTask::OnEnd(); diff --git a/Source/Engine/Content/Storage/JsonStorageProxy.cpp b/Source/Engine/Content/Storage/JsonStorageProxy.cpp index 8b2f07944..1d5dbdf19 100644 --- a/Source/Engine/Content/Storage/JsonStorageProxy.cpp +++ b/Source/Engine/Content/Storage/JsonStorageProxy.cpp @@ -31,7 +31,7 @@ bool JsonStorageProxy::GetAssetInfo(const StringView& path, Guid& resultId, Stri document.Parse((const char*)fileData.Get(), fileData.Count()); if (document.HasParseError()) { - Log::JsonParseException(document.GetParseError(), document.GetErrorOffset(), String(path)); + Log::JsonParseException(document.GetParseError(), document.GetErrorOffset(), path); return false; } @@ -94,7 +94,7 @@ bool JsonStorageProxy::ChangeId(const StringView& path, const Guid& newId) document.Parse((const char*)fileData.Get(), fileData.Count()); if (document.HasParseError()) { - Log::JsonParseException(document.GetParseError(), document.GetErrorOffset(), String(path)); + Log::JsonParseException(document.GetParseError(), document.GetErrorOffset(), path); return false; } diff --git a/Source/Engine/ContentImporters/AssetsImportingManager.cpp b/Source/Engine/ContentImporters/AssetsImportingManager.cpp index 75aa4788d..b4f002b42 100644 --- a/Source/Engine/ContentImporters/AssetsImportingManager.cpp +++ b/Source/Engine/ContentImporters/AssetsImportingManager.cpp @@ -332,7 +332,7 @@ bool AssetsImportingManager::Create(const FunctionParsing error code. /// Parsing error location. JsonParseException(ErrorCode error, size_t offset) - : JsonParseException(error, offset, String::Empty) + : JsonParseException(error, offset, StringView::Empty) { } @@ -35,7 +35,7 @@ namespace Log /// Parsing error code. /// Parsing error location. /// Additional information that help describe error - JsonParseException(ErrorCode error, size_t offset, const String& additionalInfo) + JsonParseException(ErrorCode error, size_t offset, const StringView& additionalInfo) : Exception(String::Format(TEXT("Parsing Json failed with error code {0} (offset {2}). {1}"), static_cast(error), GetParseError_En(error), offset), additionalInfo) { } diff --git a/Source/Engine/Graphics/Materials/DecalMaterialShader.h b/Source/Engine/Graphics/Materials/DecalMaterialShader.h index 0baf88b42..a84960576 100644 --- a/Source/Engine/Graphics/Materials/DecalMaterialShader.h +++ b/Source/Engine/Graphics/Materials/DecalMaterialShader.h @@ -33,7 +33,7 @@ public: /// Init /// /// Material resource name - DecalMaterialShader(const String& name) + DecalMaterialShader(const StringView& name) : MaterialShader(name) { } diff --git a/Source/Engine/Graphics/Materials/DeferredMaterialShader.h b/Source/Engine/Graphics/Materials/DeferredMaterialShader.h index 537547c6a..b8886769d 100644 --- a/Source/Engine/Graphics/Materials/DeferredMaterialShader.h +++ b/Source/Engine/Graphics/Materials/DeferredMaterialShader.h @@ -56,7 +56,7 @@ private: public: - DeferredMaterialShader(const String& name) + DeferredMaterialShader(const StringView& name) : MaterialShader(name) { } diff --git a/Source/Engine/Graphics/Materials/DeformableMaterialShader.h b/Source/Engine/Graphics/Materials/DeformableMaterialShader.h index f2c796a23..c3040ded3 100644 --- a/Source/Engine/Graphics/Materials/DeformableMaterialShader.h +++ b/Source/Engine/Graphics/Materials/DeformableMaterialShader.h @@ -44,7 +44,7 @@ private: public: - DeformableMaterialShader(const String& name) + DeformableMaterialShader(const StringView& name) : MaterialShader(name) { } diff --git a/Source/Engine/Graphics/Materials/ForwardMaterialShader.h b/Source/Engine/Graphics/Materials/ForwardMaterialShader.h index bcba48259..dd053717f 100644 --- a/Source/Engine/Graphics/Materials/ForwardMaterialShader.h +++ b/Source/Engine/Graphics/Materials/ForwardMaterialShader.h @@ -58,7 +58,7 @@ public: /// Init /// /// Material resource name - ForwardMaterialShader(const String& name) + ForwardMaterialShader(const StringView& name) : MaterialShader(name) { } diff --git a/Source/Engine/Graphics/Materials/GUIMaterialShader.h b/Source/Engine/Graphics/Materials/GUIMaterialShader.h index c84373c90..ead9cf4a9 100644 --- a/Source/Engine/Graphics/Materials/GUIMaterialShader.h +++ b/Source/Engine/Graphics/Materials/GUIMaterialShader.h @@ -33,7 +33,7 @@ public: /// Init /// /// Material resource name - GUIMaterialShader(const String& name) + GUIMaterialShader(const StringView& name) : MaterialShader(name) { } diff --git a/Source/Engine/Graphics/Materials/MaterialShader.cpp b/Source/Engine/Graphics/Materials/MaterialShader.cpp index 5191357ad..91c4fe8b8 100644 --- a/Source/Engine/Graphics/Materials/MaterialShader.cpp +++ b/Source/Engine/Graphics/Materials/MaterialShader.cpp @@ -54,7 +54,7 @@ GPUPipelineState* MaterialShader::PipelineStateCache::InitPS(CullMode mode, bool return ps; } -MaterialShader::MaterialShader(const String& name) +MaterialShader::MaterialShader(const StringView& name) : _isLoaded(false) , _shader(nullptr) { @@ -68,7 +68,7 @@ MaterialShader::~MaterialShader() SAFE_DELETE_GPU_RESOURCE(_shader); } -MaterialShader* MaterialShader::Create(const String& name, MemoryReadStream& shaderCacheStream, const MaterialInfo& info) +MaterialShader* MaterialShader::Create(const StringView& name, MemoryReadStream& shaderCacheStream, const MaterialInfo& info) { MaterialShader* material; switch (info.Domain) diff --git a/Source/Engine/Graphics/Materials/MaterialShader.h b/Source/Engine/Graphics/Materials/MaterialShader.h index 8c49389a7..af0045f04 100644 --- a/Source/Engine/Graphics/Materials/MaterialShader.h +++ b/Source/Engine/Graphics/Materials/MaterialShader.h @@ -72,7 +72,7 @@ protected: /// Init /// /// Material resource name - MaterialShader(const String& name); + MaterialShader(const StringView& name); public: @@ -90,7 +90,7 @@ public: /// Stream with compiled shader data /// Loaded material info structure /// The created and loaded material or null if failed. - static MaterialShader* Create(const String& name, MemoryReadStream& shaderCacheStream, const MaterialInfo& info); + static MaterialShader* Create(const StringView& name, MemoryReadStream& shaderCacheStream, const MaterialInfo& info); /// /// Creates the dummy material used by the Null rendering backend to mock object but not perform any rendering. diff --git a/Source/Engine/Graphics/Materials/ParticleMaterialShader.h b/Source/Engine/Graphics/Materials/ParticleMaterialShader.h index a38bf56f0..28a52ddf5 100644 --- a/Source/Engine/Graphics/Materials/ParticleMaterialShader.h +++ b/Source/Engine/Graphics/Materials/ParticleMaterialShader.h @@ -54,7 +54,7 @@ public: /// Init /// /// Material resource name - ParticleMaterialShader(const String& name) + ParticleMaterialShader(const StringView& name) : MaterialShader(name) { } diff --git a/Source/Engine/Graphics/Materials/PostFxMaterialShader.h b/Source/Engine/Graphics/Materials/PostFxMaterialShader.h index 85767736f..0fdc5d416 100644 --- a/Source/Engine/Graphics/Materials/PostFxMaterialShader.h +++ b/Source/Engine/Graphics/Materials/PostFxMaterialShader.h @@ -31,7 +31,7 @@ public: /// Init /// /// Material resource name - PostFxMaterialShader(const String& name) + PostFxMaterialShader(const StringView& name) : MaterialShader(name) { } diff --git a/Source/Engine/Graphics/Materials/TerrainMaterialShader.h b/Source/Engine/Graphics/Materials/TerrainMaterialShader.h index f69fc48ba..519233807 100644 --- a/Source/Engine/Graphics/Materials/TerrainMaterialShader.h +++ b/Source/Engine/Graphics/Materials/TerrainMaterialShader.h @@ -48,7 +48,7 @@ public: /// Init /// /// Material resource name - TerrainMaterialShader(const String& name) + TerrainMaterialShader(const StringView& name) : MaterialShader(name) { } diff --git a/Source/Engine/Graphics/Materials/VolumeParticleMaterialShader.h b/Source/Engine/Graphics/Materials/VolumeParticleMaterialShader.h index e38944342..5cf69fecb 100644 --- a/Source/Engine/Graphics/Materials/VolumeParticleMaterialShader.h +++ b/Source/Engine/Graphics/Materials/VolumeParticleMaterialShader.h @@ -19,7 +19,7 @@ public: /// Init /// /// Material resource name - VolumeParticleMaterialShader(const String& name) + VolumeParticleMaterialShader(const StringView& name) : MaterialShader(name) { } diff --git a/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp b/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp index 6cc718a25..a285c5718 100644 --- a/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp +++ b/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp @@ -39,7 +39,12 @@ bool GPUParticles::Init(ParticleEmitter* owner, MemoryReadStream& shaderCacheStr // Load shader ASSERT(GPUDevice::Instance); - _shader = GPUDevice::Instance->CreateShader(owner->GetPath()); +#if GPU_ENABLE_RESOURCE_NAMING + const StringView name(owner->GetPath()); +#else + const StringView name; +#endif + _shader = GPUDevice::Instance->CreateShader(name); if (_shader->Create(shaderCacheStream)) { LOG(Warning, "Failed to load shader."); diff --git a/Source/Engine/Platform/Windows/WindowsPlatform.cpp b/Source/Engine/Platform/Windows/WindowsPlatform.cpp index ada4227ba..baf724421 100644 --- a/Source/Engine/Platform/Windows/WindowsPlatform.cpp +++ b/Source/Engine/Platform/Windows/WindowsPlatform.cpp @@ -77,16 +77,6 @@ int32 CalculateDpi(HMODULE shCoreDll) return (dpiX + dpiY) / 2; } -int32 CalculateDpi() -{ - if (const HMODULE shCoreDll = LoadLibraryW(L"Shcore.dll")) - { - return CalculateDpi(shCoreDll); - } - - return 96; -} - LONG GetStringRegKey(HKEY hKey, const Char* strValueName, String& strValue, const String& strDefaultValue) { strValue = strDefaultValue; diff --git a/Source/Engine/Profiler/ProfilerCPU.cpp b/Source/Engine/Profiler/ProfilerCPU.cpp index 8693f8ddf..eab1a0210 100644 --- a/Source/Engine/Profiler/ProfilerCPU.cpp +++ b/Source/Engine/Profiler/ProfilerCPU.cpp @@ -7,7 +7,7 @@ #include "Engine/Threading/ThreadRegistry.h" THREADLOCAL ProfilerCPU::Thread* ProfilerCPU::Thread::Current = nullptr; -Array ProfilerCPU::Threads(64); +Array> ProfilerCPU::Threads; bool ProfilerCPU::Enabled = false; void ProfilerCPU::EventBuffer::Extract(Array& data, bool withRemove) diff --git a/Source/Engine/Profiler/ProfilerCPU.h b/Source/Engine/Profiler/ProfilerCPU.h index 72859d8cf..88ec738bf 100644 --- a/Source/Engine/Profiler/ProfilerCPU.h +++ b/Source/Engine/Profiler/ProfilerCPU.h @@ -318,7 +318,7 @@ public: /// /// The registered threads. /// - static Array Threads; + static Array> Threads; /// /// The profiling tools usage flag. Can be used to disable profiler. Engine turns it down before the exit and before platform startup. diff --git a/Source/Engine/Profiler/ProfilerGPU.cpp b/Source/Engine/Profiler/ProfilerGPU.cpp index b1902d7e8..69d06bc86 100644 --- a/Source/Engine/Profiler/ProfilerGPU.cpp +++ b/Source/Engine/Profiler/ProfilerGPU.cpp @@ -55,6 +55,13 @@ int32 ProfilerGPU::EventBuffer::Add(const Event& e) return index; } +void ProfilerGPU::EventBuffer::Clear() +{ + _data.Clear(); + _isResolved = false; + FrameIndex = 0; +} + GPUTimerQuery* ProfilerGPU::GetTimerQuery() { GPUTimerQuery* result; diff --git a/Source/Engine/Profiler/ProfilerGPU.h b/Source/Engine/Profiler/ProfilerGPU.h index 9f5e3ea19..73afc529f 100644 --- a/Source/Engine/Profiler/ProfilerGPU.h +++ b/Source/Engine/Profiler/ProfilerGPU.h @@ -62,21 +62,9 @@ public: { private: - bool _isResolved; + bool _isResolved = true; Array _data; - public: - - EventBuffer() - : _data(256) - { - _isResolved = true; - } - - ~EventBuffer() - { - } - public: /// @@ -87,7 +75,6 @@ public: /// /// Determines whether this buffer has ready data (resolved and not empty). /// - /// true if this buffer has data; otherwise, false. FORCE_INLINE bool HasData() const { return _isResolved && _data.HasItems(); @@ -134,12 +121,7 @@ public: /// /// Clears this buffer. /// - void Clear() - { - _data.Clear(); - _isResolved = false; - FrameIndex = 0; - } + void Clear(); }; private: diff --git a/Source/Engine/Profiler/ProfilingTools.cpp b/Source/Engine/Profiler/ProfilingTools.cpp index d5d88568a..4afab6c04 100644 --- a/Source/Engine/Profiler/ProfilingTools.cpp +++ b/Source/Engine/Profiler/ProfilingTools.cpp @@ -9,7 +9,7 @@ #include "Engine/Graphics/GPUDevice.h" ProfilingTools::MainStats ProfilingTools::Stats; -Array ProfilingTools::EventsCPU(128); +Array> ProfilingTools::EventsCPU; Array ProfilingTools::EventsGPU; class ProfilingToolsService : public EngineService diff --git a/Source/Engine/Profiler/ProfilingTools.h b/Source/Engine/Profiler/ProfilingTools.h index 135041a33..b35caf9a8 100644 --- a/Source/Engine/Profiler/ProfilingTools.h +++ b/Source/Engine/Profiler/ProfilingTools.h @@ -116,7 +116,7 @@ public: /// /// The CPU threads profiler events. /// - API_FIELD(ReadOnly) static Array EventsCPU; + API_FIELD(ReadOnly) static Array> EventsCPU; /// /// The GPU rendering profiler events. diff --git a/Source/Engine/Scripting/BinaryModule.cpp b/Source/Engine/Scripting/BinaryModule.cpp index 93d086af0..be5a356d2 100644 --- a/Source/Engine/Scripting/BinaryModule.cpp +++ b/Source/Engine/Scripting/BinaryModule.cpp @@ -13,7 +13,6 @@ #include "FlaxEngine.Gen.h" #include "MException.h" #include "Scripting.h" -#include "StdTypesContainer.h" #include "Events.h" Dictionary, void(*)(ScriptingObject*, void*, bool)> ScriptingEvents::EventsTable; @@ -332,14 +331,13 @@ ScriptingTypeInitializer::ScriptingTypeInitializer(BinaryModule* module, const S // Script module->Types.AddUninitialized(); new(module->Types.Get() + TypeIndex)ScriptingType(fullname, module, size, initRuntime, spawn, baseType, setupScriptVTable, setupScriptObjectVTable, interfaces); - const MString typeName(fullname.Get(), fullname.Length()); #if BUILD_DEBUG - if (module->TypeNameToTypeIndex.ContainsKey(typeName)) + if (module->TypeNameToTypeIndex.ContainsKey(fullname)) { LOG(Error, "Duplicated native typename {0} from module {1}.", String(fullname), String(module->GetName())); } #endif - module->TypeNameToTypeIndex[typeName] = TypeIndex; + module->TypeNameToTypeIndex[fullname] = TypeIndex; } ScriptingTypeInitializer::ScriptingTypeInitializer(BinaryModule* module, const StringAnsiView& fullname, int32 size, ScriptingType::InitRuntimeHandler initRuntime, ScriptingType::Ctor ctor, ScriptingType::Dtor dtor, ScriptingTypeInitializer* baseType, const ScriptingType::InterfaceImplementation* interfaces) @@ -348,14 +346,13 @@ ScriptingTypeInitializer::ScriptingTypeInitializer(BinaryModule* module, const S // Class module->Types.AddUninitialized(); new(module->Types.Get() + TypeIndex)ScriptingType(fullname, module, size, initRuntime, ctor, dtor, baseType, interfaces); - const MString typeName(fullname.Get(), fullname.Length()); #if BUILD_DEBUG - if (module->TypeNameToTypeIndex.ContainsKey(typeName)) + if (module->TypeNameToTypeIndex.ContainsKey(fullname)) { LOG(Error, "Duplicated native typename {0} from module {1}.", String(fullname), String(module->GetName())); } #endif - module->TypeNameToTypeIndex[typeName] = TypeIndex; + module->TypeNameToTypeIndex[fullname] = TypeIndex; } ScriptingTypeInitializer::ScriptingTypeInitializer(BinaryModule* module, const StringAnsiView& fullname, int32 size, ScriptingType::InitRuntimeHandler initRuntime, ScriptingType::Ctor ctor, ScriptingType::Dtor dtor, ScriptingType::Copy copy, ScriptingType::Box box, ScriptingType::Unbox unbox, ScriptingType::GetField getField, ScriptingType::SetField setField, ScriptingTypeInitializer* baseType, const ScriptingType::InterfaceImplementation* interfaces) @@ -364,14 +361,13 @@ ScriptingTypeInitializer::ScriptingTypeInitializer(BinaryModule* module, const S // Structure module->Types.AddUninitialized(); new(module->Types.Get() + TypeIndex)ScriptingType(fullname, module, size, initRuntime, ctor, dtor, copy, box, unbox, getField, setField, baseType, interfaces); - const MString typeName(fullname.Get(), fullname.Length()); #if BUILD_DEBUG - if (module->TypeNameToTypeIndex.ContainsKey(typeName)) + if (module->TypeNameToTypeIndex.ContainsKey(fullname)) { LOG(Error, "Duplicated native typename {0} from module {1}.", String(fullname), String(module->GetName())); } #endif - module->TypeNameToTypeIndex[typeName] = TypeIndex; + module->TypeNameToTypeIndex[fullname] = TypeIndex; } ScriptingTypeInitializer::ScriptingTypeInitializer(BinaryModule* module, const StringAnsiView& fullname, ScriptingType::InitRuntimeHandler initRuntime, ScriptingTypeInitializer* baseType, const ScriptingType::InterfaceImplementation* interfaces) @@ -380,14 +376,13 @@ ScriptingTypeInitializer::ScriptingTypeInitializer(BinaryModule* module, const S // Interface module->Types.AddUninitialized(); new(module->Types.Get() + TypeIndex)ScriptingType(fullname, module, initRuntime, baseType, interfaces); - const MString typeName(fullname.Get(), fullname.Length()); #if BUILD_DEBUG - if (module->TypeNameToTypeIndex.ContainsKey(typeName)) + if (module->TypeNameToTypeIndex.ContainsKey(fullname)) { LOG(Error, "Duplicated native typename {0} from module {1}.", String(fullname), String(module->GetName())); } #endif - module->TypeNameToTypeIndex[typeName] = TypeIndex; + module->TypeNameToTypeIndex[fullname] = TypeIndex; } BinaryModule::BinaryModulesList& BinaryModule::GetModules() @@ -1075,9 +1070,9 @@ void NativeOnlyBinaryModule::Destroy(bool isReloading) } } -Array& StaticallyLinkedBinaryModuleInitializer::GetStaticallyLinkedBinaryModules() +Array>& StaticallyLinkedBinaryModuleInitializer::GetStaticallyLinkedBinaryModules() { - static Array modules; + static Array> modules; return modules; } diff --git a/Source/Engine/Scripting/BinaryModule.h b/Source/Engine/Scripting/BinaryModule.h index 572a11818..1bc048055 100644 --- a/Source/Engine/Scripting/BinaryModule.h +++ b/Source/Engine/Scripting/BinaryModule.h @@ -396,7 +396,7 @@ private: public: - static Array& GetStaticallyLinkedBinaryModules(); + static Array>& GetStaticallyLinkedBinaryModules(); explicit StaticallyLinkedBinaryModuleInitializer(GetBinaryModuleFunc getter); ~StaticallyLinkedBinaryModuleInitializer(); };