Optimize C++ compilation time

This commit is contained in:
Wojtek Figat
2021-04-30 16:27:57 +02:00
parent 05ba9b8d45
commit 0e75dba142
222 changed files with 1095 additions and 1506 deletions

View File

@@ -10,6 +10,7 @@
#include "Editor/Editor.h" #include "Editor/Editor.h"
#include "Editor/ProjectInfo.h" #include "Editor/ProjectInfo.h"
#include "Engine/Engine/EngineService.h" #include "Engine/Engine/EngineService.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Graphics/GPUDevice.h" #include "Engine/Graphics/GPUDevice.h"
#include "Engine/Utilities/StringConverter.h" #include "Engine/Utilities/StringConverter.h"
#include "FlaxEngine.Gen.h" #include "FlaxEngine.Gen.h"

View File

@@ -76,7 +76,7 @@ void PreviewsCache::FlushTask::OnEnd()
ThreadPoolTask::OnEnd(); ThreadPoolTask::OnEnd();
} }
REGISTER_BINARY_ASSET(PreviewsCache, "FlaxEditor.PreviewsCache", ::New<TextureAssetUpgrader>(), false); REGISTER_BINARY_ASSET_WITH_UPGRADER(PreviewsCache, "FlaxEditor.PreviewsCache", TextureAssetUpgrader, false);
PreviewsCache::PreviewsCache(const SpawnParams& params, const AssetInfo* info) PreviewsCache::PreviewsCache(const SpawnParams& params, const AssetInfo* info)
: SpriteAtlas(params, info) : SpriteAtlas(params, info)

View File

@@ -10,6 +10,7 @@
#include "Engine/Serialization/JsonTools.h" #include "Engine/Serialization/JsonTools.h"
#include "Engine/Content/Content.h" #include "Engine/Content/Content.h"
#include "Engine/Engine/EngineService.h" #include "Engine/Engine/EngineService.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Threading/ThreadSpawner.h" #include "Engine/Threading/ThreadSpawner.h"
#include "Engine/Platform/FileSystem.h" #include "Engine/Platform/FileSystem.h"
#include "Steps/ValidateStep.h" #include "Steps/ValidateStep.h"

View File

@@ -29,6 +29,7 @@
#include "Engine/Graphics/RenderTools.h" #include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/Textures/TextureData.h" #include "Engine/Graphics/Textures/TextureData.h"
#include "Engine/Engine/Base/GameBase.h" #include "Engine/Engine/Base/GameBase.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Tools/TextureTool/TextureTool.h" #include "Engine/Tools/TextureTool/TextureTool.h"
#if PLATFORM_TOOLS_WINDOWS #if PLATFORM_TOOLS_WINDOWS
#include "Engine/Platform/Windows/WindowsPlatformSettings.h" #include "Engine/Platform/Windows/WindowsPlatformSettings.h"

View File

@@ -7,6 +7,7 @@
#include "Engine/Core/Config/GameSettings.h" #include "Engine/Core/Config/GameSettings.h"
#include "Engine/Renderer/ReflectionsPass.h" #include "Engine/Renderer/ReflectionsPass.h"
#include "Engine/Renderer/AntiAliasing/SMAA.h" #include "Engine/Renderer/AntiAliasing/SMAA.h"
#include "Engine/Engine/Globals.h"
bool DeployDataStep::Perform(CookingData& data) bool DeployDataStep::Perform(CookingData& data)
{ {

View File

@@ -3,6 +3,7 @@
#include "CustomEditorsUtil.h" #include "CustomEditorsUtil.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
#include "Engine/Core/Types/DateTime.h" #include "Engine/Core/Types/DateTime.h"
#include "Engine/Core/Types/TimeSpan.h"
#include "Engine/Core/Collections/Dictionary.h" #include "Engine/Core/Collections/Dictionary.h"
#include "Engine/Engine/EngineService.h" #include "Engine/Engine/EngineService.h"
#include "Engine/Scripting/Scripting.h" #include "Engine/Scripting/Scripting.h"

View File

@@ -9,6 +9,7 @@
#include "Engine/Core/Types/StringBuilder.h" #include "Engine/Core/Types/StringBuilder.h"
#include "Engine/Debug/Exceptions/FileNotFoundException.h" #include "Engine/Debug/Exceptions/FileNotFoundException.h"
#include "Engine/Engine/Engine.h" #include "Engine/Engine/Engine.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Platform/FileSystem.h" #include "Engine/Platform/FileSystem.h"
#include "Engine/Platform/FileSystemWatcher.h" #include "Engine/Platform/FileSystemWatcher.h"
#include "Engine/Threading/ThreadPool.h" #include "Engine/Threading/ThreadPool.h"

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#include "EditorUtilities.h" #include "EditorUtilities.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Platform/File.h" #include "Engine/Platform/File.h"
#include "Engine/Platform/FileSystem.h" #include "Engine/Platform/FileSystem.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"

View File

@@ -2,7 +2,9 @@
#include "SplashScreen.h" #include "SplashScreen.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
#include "Engine/Core/Types/TimeSpan.h"
#include "Engine/Engine/CommandLine.h" #include "Engine/Engine/CommandLine.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Render2D/FontAsset.h" #include "Engine/Render2D/FontAsset.h"
#include "Engine/Render2D/Font.h" #include "Engine/Render2D/Font.h"
#include "Engine/Render2D/TextLayoutOptions.h" #include "Engine/Render2D/TextLayoutOptions.h"

View File

@@ -10,6 +10,7 @@
#include "Engine/Scripting/ManagedCLR/MUtils.h" #include "Engine/Scripting/ManagedCLR/MUtils.h"
#include "Engine/Scripting/Scripting.h" #include "Engine/Scripting/Scripting.h"
#include "Engine/Scripting/MException.h" #include "Engine/Scripting/MException.h"
#include "Engine/Content/Assets/SkinnedModel.h"
#include <ThirdParty/mono-2.0/mono/metadata/appdomain.h> #include <ThirdParty/mono-2.0/mono/metadata/appdomain.h>
struct InternalInitData struct InternalInitData
@@ -144,6 +145,17 @@ void AnimGraphExecutor::ProcessGroupCustom(Box* boxBase, Node* nodeBase, Value&
box->Cache = value; box->Cache = value;
} }
bool AnimGraph::IsReady() const
{
return BaseModel && BaseModel->IsLoaded();
}
bool AnimGraph::CanUseWithSkeleton(SkinnedModel* other) const
{
// All data loaded and bones count the same
return IsReady() && other && other->IsLoaded() && other->Skeleton.Bones.Count() == BaseModel->Skeleton.Bones.Count();
}
void AnimGraph::ClearCustomNode(Node* node) void AnimGraph::ClearCustomNode(Node* node)
{ {
// Clear data // Clear data

View File

@@ -1,8 +1,10 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#include "AnimGraph.h" #include "AnimGraph.h"
#include "Engine/Engine/Time.h" #include "Engine/Content/Assets/SkinnedModel.h"
#include "Engine/Graphics/Models/SkeletonData.h"
#include "Engine/Scripting/Scripting.h" #include "Engine/Scripting/Scripting.h"
#include "Engine/Engine/Time.h"
RootMotionData RootMotionData::Identity = { Vector3(0.0f), Quaternion(0.0f, 0.0f, 0.0f, 1.0f) }; RootMotionData RootMotionData::Identity = { Vector3(0.0f), Quaternion(0.0f, 0.0f, 0.0f, 1.0f) };

View File

@@ -3,9 +3,9 @@
#pragma once #pragma once
#include "Engine/Visject/VisjectGraph.h" #include "Engine/Visject/VisjectGraph.h"
#include "Engine/Content/Assets/SkinnedModel.h"
#include "Engine/Content/Assets/Animation.h" #include "Engine/Content/Assets/Animation.h"
#include "Engine/Animations/AlphaBlend.h" #include "Engine/Animations/AlphaBlend.h"
#include "Engine/Core/Math/Matrix.h"
#include "../Config.h" #include "../Config.h"
#define ANIM_GRAPH_PARAM_BASE_MODEL_ID Guid(1000, 0, 0, 0) #define ANIM_GRAPH_PARAM_BASE_MODEL_ID Guid(1000, 0, 0, 0)
@@ -21,6 +21,8 @@ class AnimSubGraph;
class AnimGraphBase; class AnimGraphBase;
class AnimGraphNode; class AnimGraphNode;
class AnimGraphExecutor; class AnimGraphExecutor;
class SkinnedModel;
class SkeletonData;
/// <summary> /// <summary>
/// The root motion data container. Supports displacement and rotation (no scale component). /// The root motion data container. Supports displacement and rotation (no scale component).
@@ -777,22 +779,14 @@ public:
/// <summary> /// <summary>
/// Determines whether this graph is ready for the animation evaluation. /// Determines whether this graph is ready for the animation evaluation.
/// </summary> /// </summary>
/// <returns>True if is ready and can be used for the animation evaluation, otherwise false.</returns> bool IsReady() const;
bool IsReady() const
{
return BaseModel && BaseModel->IsLoaded();
}
/// <summary> /// <summary>
/// Determines whether this graph can be used with the specified skeleton. /// Determines whether this graph can be used with the specified skeleton.
/// </summary> /// </summary>
/// <param name="other">The other skinned model to check.</param> /// <param name="other">The other skinned model to check.</param>
/// <returns>True if can perform the update, otherwise false.</returns> /// <returns>True if can perform the update, otherwise false.</returns>
bool CanUseWithSkeleton(SkinnedModel* other) const bool CanUseWithSkeleton(SkinnedModel* other) const;
{
// All data loaded and bones count the same
return IsReady() && other && other->IsLoaded() && other->Skeleton.Bones.Count() == BaseModel->Skeleton.Bones.Count();
}
private: private:

View File

@@ -8,7 +8,7 @@
#include "Engine/Audio/AudioClip.h" #include "Engine/Audio/AudioClip.h"
#include "Engine/Graphics/PostProcessSettings.h" #include "Engine/Graphics/PostProcessSettings.h"
REGISTER_BINARY_ASSET(SceneAnimation, "FlaxEngine.SceneAnimation", nullptr, false); REGISTER_BINARY_ASSET(SceneAnimation, "FlaxEngine.SceneAnimation", false);
SceneAnimation::SceneAnimation(const SpawnParams& params, const AssetInfo* info) SceneAnimation::SceneAnimation(const SpawnParams& params, const AssetInfo* info)
: BinaryAsset(params, info) : BinaryAsset(params, info)

View File

@@ -9,6 +9,7 @@
#include "Engine/Serialization/Serialization.h" #include "Engine/Serialization/Serialization.h"
#include "Engine/Audio/AudioClip.h" #include "Engine/Audio/AudioClip.h"
#include "Engine/Audio/AudioSource.h" #include "Engine/Audio/AudioSource.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Renderer/RenderList.h" #include "Engine/Renderer/RenderList.h"
#include "Engine/Scripting/Scripting.h" #include "Engine/Scripting/Scripting.h"
#include "Engine/Scripting/Script.h" #include "Engine/Scripting/Script.h"

View File

@@ -3,6 +3,7 @@
#pragma once #pragma once
#include "Engine/Level/Actor.h" #include "Engine/Level/Actor.h"
#include "Engine/Core/Collections/Dictionary.h"
#include "Engine/Content/AssetReference.h" #include "Engine/Content/AssetReference.h"
#include "Engine/Level/Actors/PostFxVolume.h" #include "Engine/Level/Actors/PostFxVolume.h"
#include "SceneAnimation.h" #include "SceneAnimation.h"

View File

@@ -4,6 +4,7 @@
#include "Audio.h" #include "Audio.h"
#include "AudioSource.h" #include "AudioSource.h"
#include "AudioBackend.h" #include "AudioBackend.h"
#include "Engine/Core/Log.h"
#include "Engine/Content/Upgraders/AudioClipUpgrader.h" #include "Engine/Content/Upgraders/AudioClipUpgrader.h"
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Scripting/ManagedCLR/MUtils.h" #include "Engine/Scripting/ManagedCLR/MUtils.h"
@@ -12,7 +13,7 @@
#include "Engine/Tools/AudioTool/OggVorbisDecoder.h" #include "Engine/Tools/AudioTool/OggVorbisDecoder.h"
#include "Engine/Tools/AudioTool/AudioTool.h" #include "Engine/Tools/AudioTool/AudioTool.h"
REGISTER_BINARY_ASSET(AudioClip, "FlaxEngine.AudioClip", ::New<AudioClipUpgrader>(), false); REGISTER_BINARY_ASSET_WITH_UPGRADER(AudioClip, "FlaxEngine.AudioClip", AudioClipUpgrader, false);
bool AudioClip::StreamingTask::Run() bool AudioClip::StreamingTask::Run()
{ {

View File

@@ -7,6 +7,7 @@
#include "Engine/Level/SceneQuery.h" #include "Engine/Level/SceneQuery.h"
#include "Engine/Level/Actor.h" #include "Engine/Level/Actor.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
#include "Engine/Core/Types/TimeSpan.h"
#include "Engine/Graphics/Models/ModelData.h" #include "Engine/Graphics/Models/ModelData.h"
#include "Engine/Content/Content.h" #include "Engine/Content/Content.h"
#include "Engine/Content/Assets/Model.h" #include "Engine/Content/Assets/Model.h"

View File

@@ -11,7 +11,7 @@
#include "Engine/Serialization/MemoryWriteStream.h" #include "Engine/Serialization/MemoryWriteStream.h"
#endif #endif
REGISTER_BINARY_ASSET(Animation, "FlaxEngine.Animation", nullptr, false); REGISTER_BINARY_ASSET(Animation, "FlaxEngine.Animation", false);
Animation::Animation(const SpawnParams& params, const AssetInfo* info) Animation::Animation(const SpawnParams& params, const AssetInfo* info)
: BinaryAsset(params, info) : BinaryAsset(params, info)

View File

@@ -9,7 +9,7 @@
#include "Engine/Serialization/MemoryReadStream.h" #include "Engine/Serialization/MemoryReadStream.h"
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
REGISTER_BINARY_ASSET(AnimationGraph, "FlaxEngine.AnimationGraph", nullptr, false); REGISTER_BINARY_ASSET(AnimationGraph, "FlaxEngine.AnimationGraph", false);
AnimationGraph::AnimationGraph(const SpawnParams& params, const AssetInfo* info) AnimationGraph::AnimationGraph(const SpawnParams& params, const AssetInfo* info)
: BinaryAsset(params, info) : BinaryAsset(params, info)

View File

@@ -6,7 +6,7 @@
#include "Engine/Serialization/MemoryReadStream.h" #include "Engine/Serialization/MemoryReadStream.h"
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
REGISTER_BINARY_ASSET(AnimationGraphFunction, "FlaxEngine.AnimationGraphFunction", nullptr, false); REGISTER_BINARY_ASSET(AnimationGraphFunction, "FlaxEngine.AnimationGraphFunction", false);
AnimationGraphFunction::AnimationGraphFunction(const SpawnParams& params, const AssetInfo* info) AnimationGraphFunction::AnimationGraphFunction(const SpawnParams& params, const AssetInfo* info)
: BinaryAsset(params, info) : BinaryAsset(params, info)

View File

@@ -4,7 +4,7 @@
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Content/Upgraders/TextureAssetUpgrader.h" #include "Engine/Content/Upgraders/TextureAssetUpgrader.h"
REGISTER_BINARY_ASSET(CubeTexture, "FlaxEngine.CubeTexture", ::New<TextureAssetUpgrader>(), true); REGISTER_BINARY_ASSET_WITH_UPGRADER(CubeTexture, "FlaxEngine.CubeTexture", TextureAssetUpgrader, true);
CubeTexture::CubeTexture(const SpawnParams& params, const AssetInfo* info) CubeTexture::CubeTexture(const SpawnParams& params, const AssetInfo* info)
: TextureBase(params, info) : TextureBase(params, info)

View File

@@ -4,7 +4,7 @@
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Content/Upgraders/TextureAssetUpgrader.h" #include "Engine/Content/Upgraders/TextureAssetUpgrader.h"
REGISTER_BINARY_ASSET(IESProfile, "FlaxEngine.IESProfile", ::New<TextureAssetUpgrader>(), false); REGISTER_BINARY_ASSET_WITH_UPGRADER(IESProfile, "FlaxEngine.IESProfile", TextureAssetUpgrader, false);
IESProfile::IESProfile(const SpawnParams& params, const AssetInfo* info) IESProfile::IESProfile(const SpawnParams& params, const AssetInfo* info)
: TextureBase(params, info) : TextureBase(params, info)

View File

@@ -16,6 +16,9 @@
#include "Engine/Utilities/Encryption.h" #include "Engine/Utilities/Encryption.h"
#include "Engine/Tools/MaterialGenerator/MaterialGenerator.h" #include "Engine/Tools/MaterialGenerator/MaterialGenerator.h"
#include "Engine/ShadersCompilation/Config.h" #include "Engine/ShadersCompilation/Config.h"
#if BUILD_DEBUG
#include "Engine/Engine/Globals.h"
#endif
#endif #endif
/// <summary> /// <summary>
@@ -23,7 +26,7 @@
/// </summary> /// </summary>
#define MATERIAL_AUTO_GENERATE_MISSING_SOURCE (USE_EDITOR) #define MATERIAL_AUTO_GENERATE_MISSING_SOURCE (USE_EDITOR)
REGISTER_BINARY_ASSET(Material, "FlaxEngine.Material", ::New<ShaderAssetUpgrader>(), false); REGISTER_BINARY_ASSET_WITH_UPGRADER(Material, "FlaxEngine.Material", ShaderAssetUpgrader, false);
Material::Material(const SpawnParams& params, const AssetInfo* info) Material::Material(const SpawnParams& params, const AssetInfo* info)
: ShaderAssetTypeBase<MaterialBase>(params, info) : ShaderAssetTypeBase<MaterialBase>(params, info)
@@ -116,7 +119,7 @@ Asset::LoadResult Material::load()
FlaxChunk* materialParamsChunk; FlaxChunk* materialParamsChunk;
// Special case for Null renderer // Special case for Null renderer
if (GPUDevice::Instance->GetRendererType() == RendererType::Null) if (IsNullRenderer())
{ {
// Hack loading // Hack loading
MemoryReadStream shaderCacheStream(nullptr, 0); MemoryReadStream shaderCacheStream(nullptr, 0);
@@ -152,18 +155,16 @@ Asset::LoadResult Material::load()
// - If material version is not supported then material cannot be loaded // - If material version is not supported then material cannot be loaded
#if COMPILE_WITH_SHADER_COMPILER #if COMPILE_WITH_SHADER_COMPILER
#if BUILD_DEBUG
// Materials force reload!
Globals::ConvertLoadedMaterialsByForce = false;
#endif
// Check if current engine has different materials version or convert it by force or has no source generated at all // Check if current engine has different materials version or convert it by force or has no source generated at all
if (_shaderHeader.Material.GraphVersion != MATERIAL_GRAPH_VERSION if (_shaderHeader.Material.GraphVersion != MATERIAL_GRAPH_VERSION
|| Globals::ConvertLoadedMaterialsByForce
#if MATERIAL_AUTO_GENERATE_MISSING_SOURCE #if MATERIAL_AUTO_GENERATE_MISSING_SOURCE
|| !HasChunk(SHADER_FILE_CHUNK_SOURCE) || !HasChunk(SHADER_FILE_CHUNK_SOURCE)
#endif #endif
|| HasDependenciesModified() || HasDependenciesModified()
#if COMPILE_WITH_DEV_ENV
// Set to true to enable force GPU shader regeneration (don't commit it)
|| false
#endif
) )
{ {
// Prepare // Prepare

View File

@@ -8,7 +8,7 @@
#endif #endif
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
REGISTER_BINARY_ASSET(MaterialFunction, "FlaxEngine.MaterialFunction", nullptr, false); REGISTER_BINARY_ASSET(MaterialFunction, "FlaxEngine.MaterialFunction", false);
MaterialFunction::MaterialFunction(const SpawnParams& params, const AssetInfo* info) MaterialFunction::MaterialFunction(const SpawnParams& params, const AssetInfo* info)
: BinaryAsset(params, info) : BinaryAsset(params, info)

View File

@@ -7,7 +7,7 @@
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Serialization/MemoryReadStream.h" #include "Engine/Serialization/MemoryReadStream.h"
REGISTER_BINARY_ASSET(MaterialInstance, "FlaxEngine.MaterialInstance", ::New<MaterialInstanceUpgrader>(), true); REGISTER_BINARY_ASSET_WITH_UPGRADER(MaterialInstance, "FlaxEngine.MaterialInstance", MaterialInstanceUpgrader, true);
MaterialInstance::MaterialInstance(const SpawnParams& params, const AssetInfo* info) MaterialInstance::MaterialInstance(const SpawnParams& params, const AssetInfo* info)
: MaterialBase(params, info) : MaterialBase(params, info)

View File

@@ -8,9 +8,11 @@
#include "Engine/Content/Upgraders/ModelAssetUpgrader.h" #include "Engine/Content/Upgraders/ModelAssetUpgrader.h"
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Graphics/RenderTools.h" #include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/Models/ModelInstanceEntry.h" #include "Engine/Graphics/Models/ModelInstanceEntry.h"
#include "Engine/Streaming/StreamingGroup.h" #include "Engine/Streaming/StreamingGroup.h"
#include "Engine/Debug/Exceptions/ArgumentOutOfRangeException.h" #include "Engine/Debug/Exceptions/ArgumentOutOfRangeException.h"
#include "Engine/Renderer/DrawCall.h"
#if GPU_ENABLE_ASYNC_RESOURCES_CREATION #if GPU_ENABLE_ASYNC_RESOURCES_CREATION
#include "Engine/Threading/ThreadPoolTask.h" #include "Engine/Threading/ThreadPoolTask.h"
#define STREAM_TASK_BASE ThreadPoolTask #define STREAM_TASK_BASE ThreadPoolTask
@@ -113,7 +115,7 @@ protected:
} }
}; };
REGISTER_BINARY_ASSET(Model, "FlaxEngine.Model", ::New<ModelAssetUpgrader>(), true); REGISTER_BINARY_ASSET_WITH_UPGRADER(Model, "FlaxEngine.Model", ModelAssetUpgrader, true);
Model::Model(const SpawnParams& params, const AssetInfo* info) Model::Model(const SpawnParams& params, const AssetInfo* info)
: ModelBase(params, info, StreamingGroups::Instance()->Models()) : ModelBase(params, info, StreamingGroups::Instance()->Models())

View File

@@ -4,7 +4,7 @@
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Platform/FileSystem.h" #include "Engine/Platform/FileSystem.h"
REGISTER_BINARY_ASSET(RawDataAsset, "FlaxEngine.RawDataAsset", nullptr, true); REGISTER_BINARY_ASSET(RawDataAsset, "FlaxEngine.RawDataAsset", true);
RawDataAsset::RawDataAsset(const SpawnParams& params, const AssetInfo* info) RawDataAsset::RawDataAsset(const SpawnParams& params, const AssetInfo* info)
: BinaryAsset(params, info) : BinaryAsset(params, info)

View File

@@ -2,11 +2,13 @@
#include "Shader.h" #include "Shader.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Content/Upgraders/ShaderAssetUpgrader.h" #include "Engine/Content/Upgraders/ShaderAssetUpgrader.h"
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Serialization/MemoryReadStream.h" #include "Engine/Serialization/MemoryReadStream.h"
REGISTER_BINARY_ASSET(Shader, "FlaxEngine.Shader", ::New<ShaderAssetUpgrader>(), false); REGISTER_BINARY_ASSET_WITH_UPGRADER(Shader, "FlaxEngine.Shader", ShaderAssetUpgrader, false);
Shader::Shader(const SpawnParams& params, const AssetInfo* info) Shader::Shader(const SpawnParams& params, const AssetInfo* info)
: ShaderAssetTypeBase<BinaryAsset>(params, info) : ShaderAssetTypeBase<BinaryAsset>(params, info)
@@ -25,7 +27,7 @@ Shader::~Shader()
Asset::LoadResult Shader::load() Asset::LoadResult Shader::load()
{ {
// Special case for Null renderer that doesn't need shaders // Special case for Null renderer that doesn't need shaders
if (GPUDevice::Instance->GetRendererType() == RendererType::Null) if (IsNullRenderer())
{ {
return LoadResult::Ok; return LoadResult::Ok;
} }

View File

@@ -3,9 +3,10 @@
#pragma once #pragma once
#include "../BinaryAsset.h" #include "../BinaryAsset.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/Shaders/Cache/ShaderAssetBase.h" #include "Engine/Graphics/Shaders/Cache/ShaderAssetBase.h"
class GPUShader;
/// <summary> /// <summary>
/// The shader asset. Contains a program that runs on the GPU and is able to perform rendering calculation using textures, vertices and other resources. /// The shader asset. Contains a program that runs on the GPU and is able to perform rendering calculation using textures, vertices and other resources.
/// </summary> /// </summary>
@@ -33,7 +34,6 @@ public:
/// <summary> /// <summary>
/// Gets the GPU shader object. /// Gets the GPU shader object.
/// </summary> /// </summary>
/// <returns>The GPU shader object.</returns>
FORCE_INLINE GPUShader* GetShader() const FORCE_INLINE GPUShader* GetShader() const
{ {
return GPU; return GPU;

View File

@@ -7,7 +7,7 @@
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Content/Upgraders/SkeletonMaskUpgrader.h" #include "Engine/Content/Upgraders/SkeletonMaskUpgrader.h"
REGISTER_BINARY_ASSET(SkeletonMask, "FlaxEngine.SkeletonMask", ::New<SkeletonMaskUpgrader>(), true); REGISTER_BINARY_ASSET_WITH_UPGRADER(SkeletonMask, "FlaxEngine.SkeletonMask", SkeletonMaskUpgrader, true);
SkeletonMask::SkeletonMask(const SpawnParams& params, const AssetInfo* info) SkeletonMask::SkeletonMask(const SpawnParams& params, const AssetInfo* info)
: BinaryAsset(params, info) : BinaryAsset(params, info)

View File

@@ -7,12 +7,14 @@
#include "Engine/Streaming/StreamingGroup.h" #include "Engine/Streaming/StreamingGroup.h"
#include "Engine/Threading/ThreadPoolTask.h" #include "Engine/Threading/ThreadPoolTask.h"
#include "Engine/Graphics/RenderTools.h" #include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/Models/ModelInstanceEntry.h" #include "Engine/Graphics/Models/ModelInstanceEntry.h"
#include "Engine/Graphics/Models/Config.h" #include "Engine/Graphics/Models/Config.h"
#include "Engine/Content/WeakAssetReference.h" #include "Engine/Content/WeakAssetReference.h"
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Content/Upgraders/SkinnedModelAssetUpgrader.h" #include "Engine/Content/Upgraders/SkinnedModelAssetUpgrader.h"
#include "Engine/Debug/Exceptions/ArgumentOutOfRangeException.h" #include "Engine/Debug/Exceptions/ArgumentOutOfRangeException.h"
#include "Engine/Renderer/DrawCall.h"
#define CHECK_INVALID_BUFFER(buffer) \ #define CHECK_INVALID_BUFFER(buffer) \
if (buffer->IsValidFor(this) == false) \ if (buffer->IsValidFor(this) == false) \
@@ -106,7 +108,7 @@ protected:
} }
}; };
REGISTER_BINARY_ASSET(SkinnedModel, "FlaxEngine.SkinnedModel", ::New<SkinnedModelAssetUpgrader>(), true); REGISTER_BINARY_ASSET_WITH_UPGRADER(SkinnedModel, "FlaxEngine.SkinnedModel", SkinnedModelAssetUpgrader, true);
SkinnedModel::SkinnedModel(const SpawnParams& params, const AssetInfo* info) SkinnedModel::SkinnedModel(const SpawnParams& params, const AssetInfo* info)
: ModelBase(params, info, StreamingGroups::Instance()->SkinnedModels()) : ModelBase(params, info, StreamingGroups::Instance()->SkinnedModels())
@@ -120,6 +122,11 @@ SkinnedModel::~SkinnedModel()
ASSERT(_streamingTask == nullptr); ASSERT(_streamingTask == nullptr);
} }
bool SkinnedModel::HasAnyLODInitialized() const
{
return LODs.HasItems() && LODs.Last().HasAnyMeshInitialized();
}
Array<String> SkinnedModel::GetBlendShapes() Array<String> SkinnedModel::GetBlendShapes()
{ {
Array<String> result; Array<String> result;

View File

@@ -103,10 +103,7 @@ public:
/// Determines whether any LOD has been initialized. /// Determines whether any LOD has been initialized.
/// </summary> /// </summary>
/// <returns>True if any LOD has been initialized, otherwise false.</returns> /// <returns>True if any LOD has been initialized, otherwise false.</returns>
FORCE_INLINE bool HasAnyLODInitialized() const bool HasAnyLODInitialized() const;
{
return LODs.HasItems() && LODs.Last().HasAnyMeshInitialized();
}
/// <summary> /// <summary>
/// Determines whether this model can be rendered. /// Determines whether this model can be rendered.

View File

@@ -10,7 +10,7 @@
#include "Engine/Scripting/MainThreadManagedInvokeAction.h" #include "Engine/Scripting/MainThreadManagedInvokeAction.h"
#include "Engine/Tools/TextureTool/TextureTool.h" #include "Engine/Tools/TextureTool/TextureTool.h"
REGISTER_BINARY_ASSET(Texture, "FlaxEngine.Texture", ::New<TextureAssetUpgrader>(), true); REGISTER_BINARY_ASSET_WITH_UPGRADER(Texture, "FlaxEngine.Texture", TextureAssetUpgrader, true);
Texture::Texture(const SpawnParams& params, const AssetInfo* info) Texture::Texture(const SpawnParams& params, const AssetInfo* info)
: TextureBase(params, info) : TextureBase(params, info)

View File

@@ -1276,7 +1276,7 @@ void VisualScriptExecutor::ProcessGroupFlow(Box* boxBase, Node* node, Value& val
} }
} }
REGISTER_BINARY_ASSET(VisualScript, "FlaxEngine.VisualScript", nullptr, false); REGISTER_BINARY_ASSET(VisualScript, "FlaxEngine.VisualScript", false);
VisualScript::VisualScript(const SpawnParams& params, const AssetInfo* info) VisualScript::VisualScript(const SpawnParams& params, const AssetInfo* info)
: BinaryAsset(params, info) : BinaryAsset(params, info)

View File

@@ -132,6 +132,13 @@ void BinaryAsset::GetImportMetadata(String& path, String& username) const
} }
} }
String BinaryAsset::GetImportPath() const
{
String path, username;
GetImportMetadata(path, username);
return path;
}
void BinaryAsset::ClearDependencies() void BinaryAsset::ClearDependencies()
{ {
for (auto& e : Dependencies) for (auto& e : Dependencies)
@@ -492,7 +499,6 @@ protected:
return Result::Ok; return Result::Ok;
} }
void OnEnd() override void OnEnd() override
{ {
_dataLock.Release(); _dataLock.Release();

View File

@@ -109,13 +109,7 @@ public:
/// <summary> /// <summary>
/// Gets the imported file path from the asset metadata (can be empty if not available). /// Gets the imported file path from the asset metadata (can be empty if not available).
/// </summary> /// </summary>
/// <returns>The imported source file path.</returns> API_PROPERTY() String GetImportPath() const;
API_PROPERTY() String GetImportPath() const
{
String path, username;
GetImportMetadata(path, username);
return path;
}
/// <summary> /// <summary>
/// Clears the asset dependencies list and unregisters from tracking their changes. /// Clears the asset dependencies list and unregisters from tracking their changes.
@@ -131,7 +125,6 @@ public:
/// <summary> /// <summary>
/// Determines whether any of the dependency assets was modified after last modification time of this asset (last file write time check). /// Determines whether any of the dependency assets was modified after last modification time of this asset (last file write time check).
/// </summary> /// </summary>
/// <returns><c>true</c> if one or more dependencies were modified; otherwise, <c>false</c>.</returns>
bool HasDependenciesModified() const; bool HasDependenciesModified() const;
protected: protected:

View File

@@ -3,6 +3,7 @@
#include "AssetsCache.h" #include "AssetsCache.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
#include "Engine/Core/DeleteMe.h" #include "Engine/Core/DeleteMe.h"
#include "Engine/Core/Types/TimeSpan.h"
#include "Engine/Platform/FileSystem.h" #include "Engine/Platform/FileSystem.h"
#include "Engine/Serialization/FileWriteStream.h" #include "Engine/Serialization/FileWriteStream.h"
#include "Engine/Serialization/FileReadStream.h" #include "Engine/Serialization/FileReadStream.h"
@@ -10,6 +11,7 @@
#include "Engine/Content/Storage/ContentStorageManager.h" #include "Engine/Content/Storage/ContentStorageManager.h"
#include "Engine/Content/Storage/JsonStorageProxy.h" #include "Engine/Content/Storage/JsonStorageProxy.h"
#include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Engine/Globals.h"
#include "FlaxEngine.Gen.h" #include "FlaxEngine.Gen.h"
AssetsCache::AssetsCache() AssetsCache::AssetsCache()
@@ -402,6 +404,16 @@ void AssetsCache::RegisterAssets(FlaxStorage* storage)
_isDirty = true; _isDirty = true;
} }
void AssetsCache::RegisterAsset(const AssetHeader& header, const StringView& path)
{
RegisterAsset(header.ID, header.TypeName, path);
}
void AssetsCache::RegisterAssets(const FlaxStorageReference& storage)
{
RegisterAssets(storage.Get());
}
void AssetsCache::RegisterAsset(const Guid& id, const String& typeName, const StringView& path) void AssetsCache::RegisterAsset(const Guid& id, const String& typeName, const StringView& path)
{ {
PROFILE_CPU(); PROFILE_CPU();

View File

@@ -2,13 +2,19 @@
#pragma once #pragma once
#include "../AssetInfo.h"
#include "../Config.h"
#include "Engine/Core/Types/Guid.h" #include "Engine/Core/Types/Guid.h"
#if ENABLE_ASSETS_DISCOVERY
#include "Engine/Core/Types/DateTime.h"
#endif
#include "Engine/Core/Types/String.h" #include "Engine/Core/Types/String.h"
#include "Engine/Core/Collections/Dictionary.h" #include "Engine/Core/Collections/Dictionary.h"
#include "Engine/Platform/CriticalSection.h" #include "Engine/Platform/CriticalSection.h"
#include "Engine/Content/Storage/FlaxStorageReference.h"
#include "../AssetInfo.h" struct AssetHeader;
#include "../Config.h" struct FlaxStorageReference;
class FlaxStorage;
/// <summary> /// <summary>
/// Assets cache flags. /// Assets cache flags.
@@ -46,19 +52,17 @@ public:
AssetInfo Info; AssetInfo Info;
#if ENABLE_ASSETS_DISCOVERY #if ENABLE_ASSETS_DISCOVERY
/// <summary> /// <summary>
/// The file modified date. /// The file modified date.
/// </summary> /// </summary>
DateTime FileModified; DateTime FileModified;
#endif #endif
Entry() Entry()
{ {
} }
Entry(const Guid& id, const String& typeName, const StringView& path) Entry(const Guid& id, const StringView& typeName, const StringView& path)
: Info(id, typeName, path) : Info(id, typeName, path)
#if ENABLE_ASSETS_DISCOVERY #if ENABLE_ASSETS_DISCOVERY
, FileModified(DateTime::NowUTC()) , FileModified(DateTime::NowUTC())
@@ -167,16 +171,13 @@ public:
/// </summary> /// </summary>
/// <param name="typeName">The asset typename.</param> /// <param name="typeName">The asset typename.</param>
/// <param name="result">The result array.</param> /// <param name="result">The result array.</param>
void GetAllByTypeName(const StringView& typeName, Array<Guid>& result) const; void GetAllByTypeName(const StringView& typeName, Array<Guid, HeapAllocation>& result) const;
/// <summary> /// <summary>
/// Register assets in the cache /// Register assets in the cache
/// </summary> /// </summary>
/// <param name="storage">Flax assets container reference</param> /// <param name="storage">Flax assets container reference</param>
FORCE_INLINE void RegisterAssets(const FlaxStorageReference& storage) void RegisterAssets(const FlaxStorageReference& storage);
{
RegisterAssets(storage.Get());
}
/// <summary> /// <summary>
/// Register assets in the cache /// Register assets in the cache
@@ -189,10 +190,7 @@ public:
/// </summary> /// </summary>
/// <param name="header">Flax asset file header</param> /// <param name="header">Flax asset file header</param>
/// <param name="path">Asset path</param> /// <param name="path">Asset path</param>
FORCE_INLINE void RegisterAsset(const AssetHeader& header, const StringView& path) void RegisterAsset(const AssetHeader& header, const StringView& path);
{
RegisterAsset(header.ID, header.TypeName, path);
}
/// <summary> /// <summary>
/// Register asset in the cache /// Register asset in the cache

View File

@@ -14,6 +14,7 @@
#include "Engine/Threading/Threading.h" #include "Engine/Threading/Threading.h"
#include "Engine/Graphics/Graphics.h" #include "Engine/Graphics/Graphics.h"
#include "Engine/Engine/Time.h" #include "Engine/Engine/Time.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Level/Types.h" #include "Engine/Level/Types.h"
#include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Scripting/ManagedCLR/MClass.h" #include "Engine/Scripting/ManagedCLR/MClass.h"

View File

@@ -4,6 +4,7 @@
#include "../BinaryAsset.h" #include "../BinaryAsset.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
#include "Engine/Core/Math/Math.h" #include "Engine/Core/Math/Math.h"
#include "Engine/Core/Types/TimeSpan.h"
#include "Engine/Platform/FileSystem.h" #include "Engine/Platform/FileSystem.h"
#include "Engine/Content/Storage/ContentStorageManager.h" #include "Engine/Content/Storage/ContentStorageManager.h"
#if USE_EDITOR #if USE_EDITOR
@@ -30,7 +31,7 @@ bool BinaryAssetFactoryBase::Init(BinaryAsset* asset)
return true; return true;
} }
#if COMPILE_WITH_ASSET_UPGRADERS #if USE_EDITOR
// Check if need to perform data conversion to the newer version (only in Editor) // Check if need to perform data conversion to the newer version (only in Editor)
const auto upgrader = GetUpgrader(); const auto upgrader = GetUpgrader();
if (storage->AllowDataModifications() && upgrader && upgrader->ShouldUpgrade(initData.SerializedVersion)) if (storage->AllowDataModifications() && upgrader && upgrader->ShouldUpgrade(initData.SerializedVersion))
@@ -113,7 +114,7 @@ bool BinaryAssetFactoryBase::Init(BinaryAsset* asset)
return false; return false;
} }
#if COMPILE_WITH_ASSET_UPGRADERS #if USE_EDITOR
bool BinaryAssetFactoryBase::UpgradeAsset(const AssetInfo& info, FlaxStorage* storage, AssetMigrationContext& context) bool BinaryAssetFactoryBase::UpgradeAsset(const AssetInfo& info, FlaxStorage* storage, AssetMigrationContext& context)
{ {

View File

@@ -3,7 +3,9 @@
#pragma once #pragma once
#include "IAssetFactory.h" #include "IAssetFactory.h"
#if USE_EDITOR
#include "Engine/Content/Upgraders/BinaryAssetUpgrader.h" #include "Engine/Content/Upgraders/BinaryAssetUpgrader.h"
#endif
#include "Engine/Content/AssetInfo.h" #include "Engine/Content/AssetInfo.h"
#include "Engine/Scripting/ScriptingObject.h" #include "Engine/Scripting/ScriptingObject.h"
@@ -29,7 +31,7 @@ protected:
virtual BinaryAsset* Create(const AssetInfo& info) = 0; virtual BinaryAsset* Create(const AssetInfo& info) = 0;
virtual bool IsVersionSupported(uint32 serializedVersion) const = 0; virtual bool IsVersionSupported(uint32 serializedVersion) const = 0;
#if COMPILE_WITH_ASSET_UPGRADERS #if USE_EDITOR
bool UpgradeAsset(const AssetInfo& info, FlaxStorage* storage, AssetMigrationContext& context); bool UpgradeAsset(const AssetInfo& info, FlaxStorage* storage, AssetMigrationContext& context);
#endif #endif
@@ -65,16 +67,31 @@ protected:
} }
}; };
#define REGISTER_BINARY_ASSET(type, typeName, upgrader, supportsVirtualAssets) \ #define REGISTER_BINARY_ASSET(type, typeName, supportsVirtualAssets) \
const String type::TypeName = TEXT(typeName); \
class CONCAT_MACROS(Factory, type) : public BinaryAssetFactory<type> \
{ \
public: \
CONCAT_MACROS(Factory, type)() { IAssetFactory::Get().Add(type::TypeName, this); } \
~CONCAT_MACROS(Factory, type)() { IAssetFactory::Get().Remove(type::TypeName); } \
bool SupportsVirtualAssets() const override { return supportsVirtualAssets; } \
}; \
static CONCAT_MACROS(Factory, type) CONCAT_MACROS(CFactory, type)
#if USE_EDITOR
#define REGISTER_BINARY_ASSET_WITH_UPGRADER(type, typeName, upgrader, supportsVirtualAssets) \
const String type::TypeName = TEXT(typeName); \ const String type::TypeName = TEXT(typeName); \
class CONCAT_MACROS(Factory, type) : public BinaryAssetFactory<type> \ class CONCAT_MACROS(Factory, type) : public BinaryAssetFactory<type> \
{ \ { \
private: \ private: \
IAssetUpgrader* _upgrader = upgrader; \ IAssetUpgrader* _upgrader = ::New<upgrader>(); \
public: \ public: \
CONCAT_MACROS(Factory, type)() { IAssetFactory::Get().Add(type::TypeName, this); } \ CONCAT_MACROS(Factory, type)() { IAssetFactory::Get().Add(type::TypeName, this); } \
~CONCAT_MACROS(Factory, type)() { if (_upgrader) Delete(_upgrader); IAssetFactory::Get().Remove(type::TypeName); } \ ~CONCAT_MACROS(Factory, type)() { Delete(_upgrader); IAssetFactory::Get().Remove(type::TypeName); } \
bool SupportsVirtualAssets() const override { return supportsVirtualAssets; } \ bool SupportsVirtualAssets() const override { return supportsVirtualAssets; } \
IAssetUpgrader* GetUpgrader() const override { return _upgrader; } \ IAssetUpgrader* GetUpgrader() const override { return _upgrader; } \
}; \ }; \
static CONCAT_MACROS(Factory, type) CONCAT_MACROS(CFactory, type) static CONCAT_MACROS(Factory, type) CONCAT_MACROS(CFactory, type)
#else
#define REGISTER_BINARY_ASSET_WITH_UPGRADER(type, typeName, upgrader, supportsVirtualAssets) REGISTER_BINARY_ASSET(type, typeName, supportsVirtualAssets)
#endif

View File

@@ -9,9 +9,6 @@ struct AssetInfo;
class Asset; class Asset;
class IAssetUpgrader; class IAssetUpgrader;
// Enables upgrading asset files from the older version format
#define COMPILE_WITH_ASSET_UPGRADERS (USE_EDITOR)
/// <summary> /// <summary>
/// The asset objects factory. /// The asset objects factory.
/// </summary> /// </summary>

View File

@@ -5,7 +5,9 @@
#include "Engine/Core/Types/Guid.h" #include "Engine/Core/Types/Guid.h"
#include "Engine/Core/Types/Pair.h" #include "Engine/Core/Types/Pair.h"
#include "Engine/Core/Types/String.h" #include "Engine/Core/Types/String.h"
#include "Engine/Core/Types/DataContainer.h" #if USE_EDITOR
#include "Engine/Core/Collections/Array.h"
#endif
#include "FlaxChunk.h" #include "FlaxChunk.h"
/// <summary> /// <summary>
@@ -54,7 +56,8 @@ public:
/// Gets the chunks. /// Gets the chunks.
/// </summary> /// </summary>
/// <param name="output">The output data.</param> /// <param name="output">The output data.</param>
void GetChunks(Array<FlaxChunk*>& output) const template<typename AllocationType = HeapAllocation>
void GetChunks(Array<FlaxChunk*, AllocationType>& output) const
{ {
for (int32 i = 0; i < ASSET_FILE_DATA_CHUNKS; i++) for (int32 i = 0; i < ASSET_FILE_DATA_CHUNKS; i++)
{ {
@@ -67,7 +70,8 @@ public:
/// Gets the chunks that are loaded. /// Gets the chunks that are loaded.
/// </summary> /// </summary>
/// <param name="output">The output data.</param> /// <param name="output">The output data.</param>
void GetLoadedChunks(Array<FlaxChunk*>& output) const template<typename AllocationType = HeapAllocation>
void GetLoadedChunks(Array<FlaxChunk*, AllocationType>& output) const
{ {
for (int32 i = 0; i < ASSET_FILE_DATA_CHUNKS; i++) for (int32 i = 0; i < ASSET_FILE_DATA_CHUNKS; i++)
{ {
@@ -130,7 +134,7 @@ struct FLAXENGINE_API AssetInitData
/// <summary> /// <summary>
/// The serialized asset version /// The serialized asset version
/// </summary> /// </summary>
uint32 SerializedVersion; uint32 SerializedVersion = 0;
/// <summary> /// <summary>
/// The custom asset data (should be small, for eg. texture description structure). /// The custom asset data (should be small, for eg. texture description structure).
@@ -138,7 +142,6 @@ struct FLAXENGINE_API AssetInitData
BytesContainer CustomData; BytesContainer CustomData;
#if USE_EDITOR #if USE_EDITOR
/// <summary> /// <summary>
/// The asset metadata information. Stored in a Json format. /// The asset metadata information. Stored in a Json format.
/// </summary> /// </summary>
@@ -148,24 +151,16 @@ struct FLAXENGINE_API AssetInitData
/// Asset dependencies list used by the asset for tracking (eg. material functions used by material asset). The pair of asset ID and cached file edit time (for tracking modification). /// Asset dependencies list used by the asset for tracking (eg. material functions used by material asset). The pair of asset ID and cached file edit time (for tracking modification).
/// </summary> /// </summary>
Array<Pair<Guid, DateTime>> Dependencies; Array<Pair<Guid, DateTime>> Dependencies;
#endif #endif
public: public:
AssetInitData()
: SerializedVersion(0)
{
}
/// <summary> /// <summary>
/// Gets the hash code. /// Gets the hash code.
/// </summary> /// </summary>
/// <returns>Hash Code</returns>
uint32 GetHashCode() const uint32 GetHashCode() const
{ {
// Note: do not use Metadata/Dependencies because it may not be loaded (it's optional) // Note: do not use Metadata/Dependencies because it may not be loaded (it's optional)
uint32 hashCode = GetHash(Header.ID); uint32 hashCode = GetHash(Header.ID);
hashCode = (hashCode * 397) ^ SerializedVersion; hashCode = (hashCode * 397) ^ SerializedVersion;
hashCode = (hashCode * 397) ^ CustomData.Length(); hashCode = (hashCode * 397) ^ CustomData.Length();

View File

@@ -3,6 +3,7 @@
#pragma once #pragma once
#include "FlaxStorageReference.h" #include "FlaxStorageReference.h"
#include "Engine/Core/Types/TimeSpan.h"
class FlaxFile; class FlaxFile;
class FlaxPackage; class FlaxPackage;

View File

@@ -5,10 +5,15 @@
#include "FlaxPackage.h" #include "FlaxPackage.h"
#include "ContentStorageManager.h" #include "ContentStorageManager.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
#include "Engine/Core/Types/TimeSpan.h"
#include "Engine/Platform/File.h" #include "Engine/Platform/File.h"
#include "Engine/Serialization/FileWriteStream.h" #include "Engine/Serialization/FileWriteStream.h"
#if USE_EDITOR
#include "Engine/Serialization/JsonWriter.h" #include "Engine/Serialization/JsonWriter.h"
#include "Engine/Serialization/JsonWriters.h" #include "Engine/Serialization/JsonWriters.h"
#else
#include "Engine/Engine/Globals.h"
#endif
#include <ThirdParty/LZ4/lz4.h> #include <ThirdParty/LZ4/lz4.h>
String AssetHeader::ToString() const String AssetHeader::ToString() const

View File

@@ -5,7 +5,7 @@
#include "FlaxStorage.h" #include "FlaxStorage.h"
/// <summary> /// <summary>
/// Flax Storage Container Reference /// Flax Storage container reference.
/// </summary> /// </summary>
struct FLAXENGINE_API FlaxStorageReference struct FLAXENGINE_API FlaxStorageReference
{ {
@@ -44,10 +44,8 @@ public:
public: public:
// Assignment operator
FlaxStorageReference& operator=(const FlaxStorageReference& other) FlaxStorageReference& operator=(const FlaxStorageReference& other)
{ {
// Protect against invalid self-assignment
if (this != &other) if (this != &other)
{ {
if (_storage) if (_storage)
@@ -56,7 +54,6 @@ public:
if (_storage) if (_storage)
_storage->AddRef(); _storage->AddRef();
} }
return *this; return *this;
} }

View File

@@ -2,6 +2,8 @@
#pragma once #pragma once
#if USE_EDITOR
#include "BinaryAssetUpgrader.h" #include "BinaryAssetUpgrader.h"
#include "Engine/Audio/AudioClip.h" #include "Engine/Audio/AudioClip.h"
#include "Engine/Tools/AudioTool/OggVorbisDecoder.h" #include "Engine/Tools/AudioTool/OggVorbisDecoder.h"
@@ -130,3 +132,5 @@ private:
return false; return false;
} }
}; };
#endif

View File

@@ -2,6 +2,8 @@
#pragma once #pragma once
#if USE_EDITOR
#include "IAssetUpgrader.h" #include "IAssetUpgrader.h"
#include "Engine/Content/Storage/AssetHeader.h" #include "Engine/Content/Storage/AssetHeader.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
@@ -205,3 +207,5 @@ public:
return false; return false;
} }
}; };
#endif

View File

@@ -2,6 +2,8 @@
#pragma once #pragma once
#if USE_EDITOR
#include "BinaryAssetUpgrader.h" #include "BinaryAssetUpgrader.h"
#include "Engine/Render2D/FontAsset.h" #include "Engine/Render2D/FontAsset.h"
@@ -71,3 +73,5 @@ private:
return CopyChunk(context, 0); return CopyChunk(context, 0);
} }
}; };
#endif

View File

@@ -2,6 +2,8 @@
#pragma once #pragma once
#if USE_EDITOR
#include "Engine/Core/Types/BaseTypes.h" #include "Engine/Core/Types/BaseTypes.h"
/// <summary> /// <summary>
@@ -27,3 +29,5 @@ public:
/// <returns>True if perform conversion, otherwise false.</returns> /// <returns>True if perform conversion, otherwise false.</returns>
virtual bool ShouldUpgrade(uint32 serializedVersion) const = 0; virtual bool ShouldUpgrade(uint32 serializedVersion) const = 0;
}; };
#endif

View File

@@ -2,6 +2,8 @@
#pragma once #pragma once
#if USE_EDITOR
#include "BinaryAssetUpgrader.h" #include "BinaryAssetUpgrader.h"
#include "Engine/Core/Core.h" #include "Engine/Core/Core.h"
#include "Engine/Platform/Platform.h" #include "Engine/Platform/Platform.h"
@@ -105,3 +107,5 @@ private:
return false; return false;
} }
}; };
#endif

View File

@@ -2,6 +2,8 @@
#pragma once #pragma once
#if USE_EDITOR
#include "BinaryAssetUpgrader.h" #include "BinaryAssetUpgrader.h"
#include "Engine/Core/Core.h" #include "Engine/Core/Core.h"
#include "Engine/Platform/Platform.h" #include "Engine/Platform/Platform.h"
@@ -1223,3 +1225,5 @@ private:
return false; return false;
} }
}; };
#endif

View File

@@ -2,6 +2,8 @@
#pragma once #pragma once
#if USE_EDITOR
#include "BinaryAssetUpgrader.h" #include "BinaryAssetUpgrader.h"
#include "Engine/Platform/Platform.h" #include "Engine/Platform/Platform.h"
#include "Engine/Graphics/Shaders/Cache/ShaderStorage.h" #include "Engine/Graphics/Shaders/Cache/ShaderStorage.h"
@@ -86,3 +88,5 @@ private:
return CopyChunks(context); return CopyChunks(context);
} }
}; };
#endif

View File

@@ -2,6 +2,8 @@
#pragma once #pragma once
#if USE_EDITOR
#include "BinaryAssetUpgrader.h" #include "BinaryAssetUpgrader.h"
#include "Engine/Content/Assets/SkinnedModel.h" #include "Engine/Content/Assets/SkinnedModel.h"
#include "Engine/Serialization/MemoryReadStream.h" #include "Engine/Serialization/MemoryReadStream.h"
@@ -97,3 +99,5 @@ private:
return false; return false;
} }
}; };
#endif

View File

@@ -2,6 +2,8 @@
#pragma once #pragma once
#if USE_EDITOR
#include "BinaryAssetUpgrader.h" #include "BinaryAssetUpgrader.h"
#include "Engine/Platform/Platform.h" #include "Engine/Platform/Platform.h"
#include "Engine/Serialization/MemoryReadStream.h" #include "Engine/Serialization/MemoryReadStream.h"
@@ -423,3 +425,5 @@ private:
return false; return false;
} }
}; };
#endif

View File

@@ -2,6 +2,8 @@
#pragma once #pragma once
#if USE_EDITOR
#include "BinaryAssetUpgrader.h" #include "BinaryAssetUpgrader.h"
#include "Engine/Core/Core.h" #include "Engine/Core/Core.h"
#include "Engine/Platform/Platform.h" #include "Engine/Platform/Platform.h"
@@ -825,3 +827,5 @@ private:
return true; return true;
} }
}; };
#endif

View File

@@ -5,6 +5,7 @@
#if COMPILE_WITH_ASSETS_IMPORTER #if COMPILE_WITH_ASSETS_IMPORTER
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
#include "Engine/Core/Math/Math.h"
#include "Engine/Platform/File.h" #include "Engine/Platform/File.h"
#include "Engine/Platform/FileSystem.h" #include "Engine/Platform/FileSystem.h"
#include "Engine/Content/Content.h" #include "Engine/Content/Content.h"

View File

@@ -2,7 +2,7 @@
#pragma once #pragma once
#include "Engine/Core/Collections/Array.h" #include "Engine/Core/Memory/Memory.h"
#include "Engine/Core/Collections/HashFunctions.h" #include "Engine/Core/Collections/HashFunctions.h"
#include "Engine/Core/Collections/Config.h" #include "Engine/Core/Collections/Config.h"
@@ -781,7 +781,8 @@ public:
/// Gets the keys collection to the output array (will contain unique items). /// Gets the keys collection to the output array (will contain unique items).
/// </summary> /// </summary>
/// <param name="result">The result.</param> /// <param name="result">The result.</param>
void GetKeys(Array<KeyType>& result) const template<typename AllocationType>
void GetKeys(Array<KeyType, AllocationType>& result) const
{ {
for (auto i = Begin(); i.IsNotEnd(); ++i) for (auto i = Begin(); i.IsNotEnd(); ++i)
result.Add(i->Key); result.Add(i->Key);
@@ -791,7 +792,8 @@ public:
/// Gets the values collection to the output array (may contain duplicates). /// Gets the values collection to the output array (may contain duplicates).
/// </summary> /// </summary>
/// <param name="result">The result.</param> /// <param name="result">The result.</param>
void GetValues(Array<ValueType>& result) const template<typename AllocationType>
void GetValues(Array<ValueType, AllocationType>& result) const
{ {
for (auto i = Begin(); i.IsNotEnd(); ++i) for (auto i = Begin(); i.IsNotEnd(); ++i)
result.Add(i->Value); result.Add(i->Value);

View File

@@ -3,6 +3,8 @@
#pragma once #pragma once
#include "Engine/Core/Templates.h" #include "Engine/Core/Templates.h"
#include "Engine/Platform/Platform.h"
#include <new>
#include "CrtAllocator.h" #include "CrtAllocator.h"
typedef CrtAllocator Allocator; typedef CrtAllocator Allocator;

View File

@@ -3,10 +3,9 @@
#pragma once #pragma once
#include "Span.h" #include "Span.h"
#include "Engine/Core/Collections/Array.h" #include "Engine/Core/Templates.h"
#include "Engine/Core/Memory/Memory.h"
#include "Engine/Platform/Platform.h" #include "Engine/Platform/Platform.h"
#include "Engine/Serialization/WriteStream.h"
#include "Engine/Serialization/ReadStream.h"
/// <summary> /// <summary>
/// Universal utility class that can store the chunk of data or just reference to the memory. /// Universal utility class that can store the chunk of data or just reference to the memory.
@@ -49,7 +48,8 @@ public:
/// Initializes a new instance of the <see cref="DataContainer"/> class. /// Initializes a new instance of the <see cref="DataContainer"/> class.
/// </summary> /// </summary>
/// <param name="data">The data array to link.</param> /// <param name="data">The data array to link.</param>
DataContainer(const Array<T>& data) template<typename AllocationType>
DataContainer(const Array<T, AllocationType>& data)
: Base((T*)data.Get(), data.Count()) : Base((T*)data.Get(), data.Count())
, _isAllocated(false) , _isAllocated(false)
{ {
@@ -147,7 +147,8 @@ public:
/// Link external data /// Link external data
/// </summary> /// </summary>
/// <param name="data">Data array to link</param> /// <param name="data">Data array to link</param>
void Link(const Array<T>& data) template<typename AllocationType>
void Link(const Array<T, AllocationType>& data)
{ {
Link(data.Get(), data.Count()); Link(data.Get(), data.Count());
} }
@@ -217,7 +218,8 @@ public:
/// Copies the data to a new allocated chunk /// Copies the data to a new allocated chunk
/// </summary> /// </summary>
/// <param name="data">Data array to copy</param> /// <param name="data">Data array to copy</param>
FORCE_INLINE void Copy(const Array<T>& data) template<typename AllocationType>
FORCE_INLINE void Copy(const Array<T, AllocationType>& data)
{ {
if (data.HasItems()) if (data.HasItems())
Copy(data.Get(), data.Count()); Copy(data.Get(), data.Count());
@@ -347,10 +349,9 @@ public:
public: public:
template<typename ReadStream>
void Read(ReadStream* stream, int32 length) void Read(ReadStream* stream, int32 length)
{ {
// Note: this may not work for the objects, use with primitive types and structures
ASSERT(stream != nullptr); ASSERT(stream != nullptr);
Allocate(length); Allocate(length);
if (length > 0) if (length > 0)
@@ -359,10 +360,9 @@ public:
} }
} }
template<typename WriteStream>
void Write(WriteStream* stream) const void Write(WriteStream* stream) const
{ {
// Note: this may not work for the objects, use with primitive types and structures
ASSERT(stream != nullptr); ASSERT(stream != nullptr);
if (Base::_length > 0) if (Base::_length > 0)
{ {

View File

@@ -6,8 +6,8 @@
#include "Engine/Platform/Platform.h" #include "Engine/Platform/Platform.h"
#include "Engine/Core/Math/Math.h" #include "Engine/Core/Math/Math.h"
const int32 DateTime::CachedDaysPerMonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; const int32 CachedDaysPerMonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const int32 DateTime::CachedDaysToMonth[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; const int32 CachedDaysToMonth[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
DateTime::DateTime(int32 year, int32 month, int32 day, int32 hour, int32 minute, int32 second, int32 millisecond) DateTime::DateTime(int32 year, int32 month, int32 day, int32 hour, int32 minute, int32 second, int32 millisecond)
{ {
@@ -25,6 +25,11 @@ DateTime::DateTime(int32 year, int32 month, int32 day, int32 hour, int32 minute,
+ millisecond * Constants::TicksPerMillisecond; + millisecond * Constants::TicksPerMillisecond;
} }
DateTime DateTime::GetDate() const
{
return DateTime(Ticks - Ticks % Constants::TicksPerDay);
}
void DateTime::GetDate(int32& year, int32& month, int32& day) const void DateTime::GetDate(int32& year, int32& month, int32& day) const
{ {
// Based on: // Based on:
@@ -68,6 +73,11 @@ int32 DateTime::GetDayOfYear() const
return day; return day;
} }
int32 DateTime::GetHour() const
{
return static_cast<int32>(Ticks / Constants::TicksPerHour % 24);
}
int32 DateTime::GetHour12() const int32 DateTime::GetHour12() const
{ {
const int32 hour = GetHour(); const int32 hour = GetHour();
@@ -78,6 +88,26 @@ int32 DateTime::GetHour12() const
return hour; return hour;
} }
double DateTime::GetJulianDay() const
{
return 1721425.5 + static_cast<double>(Ticks) / Constants::TicksPerDay;
}
double DateTime::GetModifiedJulianDay() const
{
return GetJulianDay() - 2400000.5;
}
int32 DateTime::GetMillisecond() const
{
return static_cast<int32>(Ticks / Constants::TicksPerMillisecond % 1000);
}
int32 DateTime::GetMinute() const
{
return static_cast<int32>(Ticks / Constants::TicksPerMinute % 60);
}
int32 DateTime::GetMonth() const int32 DateTime::GetMonth() const
{ {
int32 year, month, day; int32 year, month, day;
@@ -85,6 +115,21 @@ int32 DateTime::GetMonth() const
return month; return month;
} }
MonthOfYear DateTime::GetMonthOfYear() const
{
return static_cast<MonthOfYear>(GetMonth());
}
int32 DateTime::GetSecond() const
{
return static_cast<int32>(Ticks / Constants::TicksPerSecond % 60);
}
TimeSpan DateTime::GetTimeOfDay() const
{
return TimeSpan(Ticks % Constants::TicksPerDay);
}
int32 DateTime::GetYear() const int32 DateTime::GetYear() const
{ {
int32 year, month, day; int32 year, month, day;
@@ -92,6 +137,11 @@ int32 DateTime::GetYear() const
return year; return year;
} }
int32 DateTime::ToUnixTimestamp() const
{
return static_cast<int32>((Ticks - DateTime(1970, 1, 1).Ticks) / Constants::TicksPerSecond);
}
int32 DateTime::DaysInMonth(int32 year, int32 month) int32 DateTime::DaysInMonth(int32 year, int32 month)
{ {
ASSERT_LOW_LAYER((month >= 1) && (month <= 12)); ASSERT_LOW_LAYER((month >= 1) && (month <= 12));
@@ -105,6 +155,16 @@ int32 DateTime::DaysInYear(int32 year)
return IsLeapYear(year) ? 366 : 365; return IsLeapYear(year) ? 366 : 365;
} }
DateTime DateTime::FromJulianDay(double julianDay)
{
return DateTime(static_cast<int64>((julianDay - 1721425.5) * Constants::TicksPerDay));
}
DateTime DateTime::FromUnixTimestamp(int32 unixTime)
{
return DateTime(1970, 1, 1) + TimeSpan(static_cast<int64>(unixTime) * Constants::TicksPerSecond);
}
bool DateTime::IsLeapYear(int32 year) bool DateTime::IsLeapYear(int32 year)
{ {
if ((year % 4) == 0) if ((year % 4) == 0)
@@ -114,6 +174,11 @@ bool DateTime::IsLeapYear(int32 year)
return false; return false;
} }
DateTime DateTime::MaxValue()
{
return DateTime(3652059 * Constants::TicksPerDay - 1);
}
DateTime DateTime::Now() DateTime DateTime::Now()
{ {
int32 year, month, day, dayOfWeek, hour, minute, second, millisecond; int32 year, month, day, dayOfWeek, hour, minute, second, millisecond;
@@ -144,3 +209,30 @@ String DateTime::ToFileNameString() const
GetDate(year, month, day); GetDate(year, month, day);
return String::Format(TEXT("{0}_{1:0>2}_{2:0>2}_{3:0>2}_{4:0>2}_{5:0>2}"), year, month, day, GetHour(), GetMinute(), GetSecond()); return String::Format(TEXT("{0}_{1:0>2}_{2:0>2}_{3:0>2}_{4:0>2}_{5:0>2}"), year, month, day, GetHour(), GetMinute(), GetSecond());
} }
DateTime DateTime::operator+(const TimeSpan& other) const
{
return DateTime(Ticks + other.Ticks);
}
DateTime& DateTime::operator+=(const TimeSpan& other)
{
Ticks += other.Ticks;
return *this;
}
TimeSpan DateTime::operator-(const DateTime& other) const
{
return TimeSpan(Ticks - other.Ticks);
}
DateTime DateTime::operator-(const TimeSpan& other) const
{
return DateTime(Ticks - other.Ticks);
}
DateTime& DateTime::operator-=(const TimeSpan& other)
{
Ticks -= other.Ticks;
return *this;
}

View File

@@ -3,7 +3,8 @@
#pragma once #pragma once
#include "BaseTypes.h" #include "BaseTypes.h"
#include "TimeSpan.h" #include "Engine/Core/Formatting.h"
#include "Engine/Core/Templates.h"
#include "Engine/Core/Enums.h" #include "Engine/Core/Enums.h"
/// <summary> /// <summary>
@@ -21,11 +22,6 @@ DECLARE_ENUM_EX_12(MonthOfYear, int32, 1, January, February, March, April, May,
/// </summary> /// </summary>
API_STRUCT(InBuild, Namespace="System") struct FLAXENGINE_API DateTime API_STRUCT(InBuild, Namespace="System") struct FLAXENGINE_API DateTime
{ {
private:
static const int32 CachedDaysPerMonth[];
static const int32 CachedDaysToMonth[];
public: public:
/// <summary> /// <summary>
@@ -77,32 +73,11 @@ public:
public: public:
DateTime operator+(const TimeSpan& other) const DateTime operator+(const TimeSpan& other) const;
{ DateTime& operator+=(const TimeSpan& other);
return DateTime(Ticks + other.Ticks); TimeSpan operator-(const DateTime& other) const;
} DateTime operator-(const TimeSpan& other) const;
DateTime& operator-=(const TimeSpan& other);
DateTime& operator+=(const TimeSpan& other)
{
Ticks += other.Ticks;
return *this;
}
TimeSpan operator-(const DateTime& other) const
{
return TimeSpan(Ticks - other.Ticks);
}
DateTime operator-(const TimeSpan& other) const
{
return DateTime(Ticks - other.Ticks);
}
DateTime& operator-=(const TimeSpan& other)
{
Ticks -= other.Ticks;
return *this;
}
bool operator==(const DateTime& other) const bool operator==(const DateTime& other) const
{ {
@@ -139,11 +114,7 @@ public:
/// <summary> /// <summary>
/// Gets the date part of this date. The time part is truncated and becomes 00:00:00.000. /// Gets the date part of this date. The time part is truncated and becomes 00:00:00.000.
/// </summary> /// </summary>
/// <returns>A DateTime object containing the date.</returns> DateTime GetDate() const;
DateTime GetDate() const
{
return DateTime(Ticks - Ticks % Constants::TicksPerDay);
}
/// <summary> /// <summary>
/// Gets the date components of this date. /// Gets the date components of this date.
@@ -156,106 +127,68 @@ public:
/// <summary> /// <summary>
/// Gets this date's day part (1 to 31). /// Gets this date's day part (1 to 31).
/// </summary> /// </summary>
/// <returns>The day of the month.</returns>
int32 GetDay() const; int32 GetDay() const;
/// <summary> /// <summary>
/// Calculates this date's day of the week (Sunday - Saturday). /// Calculates this date's day of the week (Sunday - Saturday).
/// </summary> /// </summary>
/// <returns>The week day.</returns>
DayOfWeek GetDayOfWeek() const; DayOfWeek GetDayOfWeek() const;
/// <summary> /// <summary>
/// Gets this date's day of the year. /// Gets this date's day of the year.
/// </summary> /// </summary>
/// <returns>The day of year.</returns>
int32 GetDayOfYear() const; int32 GetDayOfYear() const;
/// <summary> /// <summary>
/// Gets this date's hour part in 24-hour clock format (0 to 23). /// Gets this date's hour part in 24-hour clock format (0 to 23).
/// </summary> /// </summary>
/// <returns>The hour.</returns> int32 GetHour() const;
int32 GetHour() const
{
return static_cast<int32>(Ticks / Constants::TicksPerHour % 24);
}
/// <summary> /// <summary>
/// Gets this date's hour part in 12-hour clock format (1 to 12). /// Gets this date's hour part in 12-hour clock format (1 to 12).
/// </summary> /// </summary>
/// <returns>The hour in AM/PM format.</returns>
int32 GetHour12() const; int32 GetHour12() const;
/// <summary> /// <summary>
/// Gets the Julian Day for this date. /// Gets the Julian Day for this date.
/// </summary> /// </summary>
/// <remarks> /// <remarks>The Julian Day is the number of days since the inception of the Julian calendar at noon on Monday, January 1, 4713 B.C.E. The minimum Julian Day that can be represented in DateTime is 1721425.5, which corresponds to Monday, January 1, 0001 in the Gregorian calendar.</remarks>
/// The Julian Day is the number of days since the inception of the Julian calendar at noon on Monday, January 1, 4713 B.C.E. The minimum Julian Day that can be represented in DateTime is 1721425.5, which corresponds to Monday, January 1, 0001 in the Gregorian calendar. double GetJulianDay() const;
/// </remarks>
/// <returns>Julian Day.</returns>
double GetJulianDay() const
{
return 1721425.5 + static_cast<double>(Ticks) / Constants::TicksPerDay;
}
/// <summary> /// <summary>
/// Gets the Modified Julian day. /// Gets the Modified Julian day.
/// </summary> /// </summary>
/// <remarks> /// <remarks>The Modified Julian Day is calculated by subtracting 2400000.5, which corresponds to midnight UTC on November 17, 1858 in the Gregorian calendar.</remarks>
/// The Modified Julian Day is calculated by subtracting 2400000.5, which corresponds to midnight UTC on November 17, 1858 in the Gregorian calendar. double GetModifiedJulianDay() const;
/// </remarks>
/// <returns>The Modified Julian Day.</returns>
double GetModifiedJulianDay() const
{
return GetJulianDay() - 2400000.5;
}
/// <summary> /// <summary>
/// Gets this date's millisecond part (0 to 999). /// Gets this date's millisecond part (0 to 999).
/// </summary> /// </summary>
/// <returns>The millisecond.</returns> int32 GetMillisecond() const;
int32 GetMillisecond() const
{
return static_cast<int32>(Ticks / Constants::TicksPerMillisecond % 1000);
}
/// <summary> /// <summary>
/// Gets this date's minute part (0 to 59). /// Gets this date's minute part (0 to 59).
/// </summary> /// </summary>
/// <returns>The minute.</returns> int32 GetMinute() const;
int32 GetMinute() const
{
return static_cast<int32>(Ticks / Constants::TicksPerMinute % 60);
}
/// <summary> /// <summary>
/// Gets this date's the month part (1 to 12). /// Gets this date's the month part (1 to 12).
/// </summary> /// </summary>
/// <returns>The month.</returns>
int32 GetMonth() const; int32 GetMonth() const;
/// <summary> /// <summary>
/// Gets the date's month of the year (January to December). /// Gets the date's month of the year (January to December).
/// </summary> /// </summary>
/// <returns>The month of year.</returns> MonthOfYear GetMonthOfYear() const;
MonthOfYear GetMonthOfYear() const
{
return static_cast<MonthOfYear>(GetMonth());
}
/// <summary> /// <summary>
/// Gets this date's second part. /// Gets this date's second part.
/// </summary> /// </summary>
/// <returns>The second.</returns> int32 GetSecond() const;
int32 GetSecond() const
{
return static_cast<int32>(Ticks / Constants::TicksPerSecond % 60);
}
/// <summary> /// <summary>
/// Gets this date's representation as number of ticks. /// Gets this date's representation as number of ticks since midnight, January 1, 0001.
/// </summary> /// </summary>
/// <returns>The number of ticks since midnight, January 1, 0001.</returns>
int64 GetTicks() const int64 GetTicks() const
{ {
return Ticks; return Ticks;
@@ -264,26 +197,17 @@ public:
/// <summary> /// <summary>
/// Gets the time elapsed since midnight of this date. /// Gets the time elapsed since midnight of this date.
/// </summary> /// </summary>
/// <returns>The time span since midnight.</returns> TimeSpan GetTimeOfDay() const;
TimeSpan GetTimeOfDay() const
{
return TimeSpan(Ticks % Constants::TicksPerDay);
}
/// <summary> /// <summary>
/// Gets this date's year part. /// Gets this date's year part.
/// </summary> /// </summary>
/// <returns>The year.</returns>
int32 GetYear() const; int32 GetYear() const;
/// <summary> /// <summary>
/// Gets this date as the number of seconds since the Unix Epoch (January 1st of 1970). /// Gets this date as the number of seconds since the Unix Epoch (January 1st of 1970).
/// </summary> /// </summary>
/// <returns>The time.</returns> int32 ToUnixTimestamp() const;
int32 ToUnixTimestamp() const
{
return static_cast<int32>((Ticks - DateTime(1970, 1, 1).Ticks) / Constants::TicksPerSecond);
}
public: public:
@@ -307,27 +231,19 @@ public:
/// </summary> /// </summary>
/// <param name="julianDay">The Julian Day.</param> /// <param name="julianDay">The Julian Day.</param>
/// <returns>Gregorian date and time.</returns> /// <returns>Gregorian date and time.</returns>
static DateTime FromJulianDay(double julianDay) static DateTime FromJulianDay(double julianDay);
{
return DateTime(static_cast<int64>((julianDay - 1721425.5) * Constants::TicksPerDay));
}
/// <summary> /// <summary>
/// Returns the date from Unix time (seconds from midnight 1970-01-01). /// Returns the date from Unix time (seconds from midnight 1970-01-01).
/// </summary> /// </summary>
/// <param name="unixTime">The Unix time (seconds from midnight 1970-01-01).</param> /// <param name="unixTime">The Unix time (seconds from midnight 1970-01-01).</param>
/// <returns>The Gregorian date and time.</returns> /// <returns>The Gregorian date and time.</returns>
static DateTime FromUnixTimestamp(int32 unixTime) static DateTime FromUnixTimestamp(int32 unixTime);
{
return DateTime(1970, 1, 1) + TimeSpan(static_cast<int64>(unixTime) * Constants::TicksPerSecond);
}
/// <summary> /// <summary>
/// Determines whether the specified year is a leap year. /// Determines whether the specified year is a leap year.
/// </summary> /// </summary>
/// <remarks> /// <remarks>A leap year is a year containing one additional day in order to keep the calendar synchronized with the astronomical year.</remarks>
/// A leap year is a year containing one additional day in order to keep the calendar synchronized with the astronomical year.
/// </remarks>
/// <param name="year">The year.</param> /// <param name="year">The year.</param>
/// <returns><c>true</c> if the specified year os a leap year; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if the specified year os a leap year; otherwise, <c>false</c>.</returns>
static bool IsLeapYear(int32 year); static bool IsLeapYear(int32 year);
@@ -335,22 +251,15 @@ public:
/// <summary> /// <summary>
/// Returns the maximum date value. /// Returns the maximum date value.
/// </summary> /// </summary>
/// <remarks> /// <remarks>The maximum date value is December 31, 9999, 23:59:59.9999999.</remarks>
/// The maximum date value is December 31, 9999, 23:59:59.9999999. /// <returns>The maximum valid date.</returns>
/// </remarks> static DateTime MaxValue();
/// <returns>The date.</returns>
static DateTime MaxValue()
{
return DateTime(3652059 * Constants::TicksPerDay - 1);
}
/// <summary> /// <summary>
/// Returns the minimum date value. /// Returns the minimum date value.
/// </summary> /// </summary>
/// <remarks> /// <remarks>The minimum date value is January 1, 0001, 00:00:00.0.</remarks>
/// The minimum date value is January 1, 0001, 00:00:00.0. /// <returns>The minimum valid date.</returns>
/// </remarks>
/// <returns>The date.</returns>
static DateTime MinValue() static DateTime MinValue()
{ {
return DateTime(1, 1, 1, 0, 0, 0, 0); return DateTime(1, 1, 1, 0, 0, 0, 0);
@@ -359,18 +268,14 @@ public:
/// <summary> /// <summary>
/// Gets the local date and time on this computer. /// Gets the local date and time on this computer.
/// </summary> /// </summary>
/// <remarks> /// <remarks>This method takes into account the local computer's time zone and daylight saving settings. For time zone independent time comparisons, and when comparing times between different computers, use NowUTC() instead.</remarks>
///This method takes into account the local computer's time zone and daylight saving settings. For time zone independent time comparisons, and when comparing times between different computers, use NowUTC() instead.
/// </remarks>
/// <returns>The current date and time.</returns> /// <returns>The current date and time.</returns>
static DateTime Now(); static DateTime Now();
/// <summary> /// <summary>
/// Gets the UTC date and time on this computer. /// Gets the UTC date and time on this computer.
/// </summary> /// </summary>
/// <remarks> /// <remarks>This method returns the Coordinated Universal Time (UTC), which does not take the local computer's time zone and daylight savings settings into account. It should be used when comparing dates and times that should be independent of the user's locale. To get the date and time in the current locale, use Now() instead.</remarks>
/// This method returns the Coordinated Universal Time (UTC), which does not take the local computer's time zone and daylight savings settings into account. It should be used when comparing dates and times that should be independent of the user's locale. To get the date and time in the current locale, use Now() instead.
/// </remarks>
/// <returns>The current date and time.</returns> /// <returns>The current date and time.</returns>
static DateTime NowUTC(); static DateTime NowUTC();

View File

@@ -5,6 +5,7 @@
#include "Engine/Platform/Platform.h" #include "Engine/Platform/Platform.h"
#include "Engine/Platform/StringUtils.h" #include "Engine/Platform/StringUtils.h"
#include "Engine/Core/Formatting.h" #include "Engine/Core/Formatting.h"
#include "Engine/Core/Templates.h"
/// <summary> /// <summary>
/// Represents text as a sequence of characters. Container uses a single dynamic memory allocation to store the characters data. Characters sequence is always null-terminated. /// Represents text as a sequence of characters. Container uses a single dynamic memory allocation to store the characters data. Characters sequence is always null-terminated.

View File

@@ -66,7 +66,6 @@ public:
/// <summary> /// <summary>
/// Returns true if string is empty. /// Returns true if string is empty.
/// </summary> /// </summary>
/// <returns>True if string is empty, otherwise false.</returns>
FORCE_INLINE bool IsEmpty() const FORCE_INLINE bool IsEmpty() const
{ {
return _length == 0; return _length == 0;
@@ -75,7 +74,6 @@ public:
/// <summary> /// <summary>
/// Returns true if string isn't empty. /// Returns true if string isn't empty.
/// </summary> /// </summary>
/// <returns>True if string isn't empty, otherwise false.</returns>
FORCE_INLINE bool HasChars() const FORCE_INLINE bool HasChars() const
{ {
return _length != 0; return _length != 0;
@@ -84,7 +82,6 @@ public:
/// <summary> /// <summary>
/// Gets the length of the string. /// Gets the length of the string.
/// </summary> /// </summary>
/// <returns>The string length.</returns>
FORCE_INLINE int32 Length() const FORCE_INLINE int32 Length() const
{ {
return _length; return _length;
@@ -93,7 +90,6 @@ public:
/// <summary> /// <summary>
/// Gets the pointer to the string. /// Gets the pointer to the string.
/// </summary> /// </summary>
/// <returns>The string.</returns>
FORCE_INLINE const T* operator*() const FORCE_INLINE const T* operator*() const
{ {
return _data; return _data;
@@ -102,7 +98,6 @@ public:
/// <summary> /// <summary>
/// Gets the pointer to the string. /// Gets the pointer to the string.
/// </summary> /// </summary>
/// <returns>The string.</returns>
FORCE_INLINE const T* Get() const FORCE_INLINE const T* Get() const
{ {
return _data; return _data;
@@ -111,7 +106,6 @@ public:
/// <summary> /// <summary>
/// Gets the pointer to the string or to the static empty text if string is null. Returned pointer is always valid (read-only). /// Gets the pointer to the string or to the static empty text if string is null. Returned pointer is always valid (read-only).
/// </summary> /// </summary>
/// <returns>The string handle.</returns>
FORCE_INLINE const T* GetText() const FORCE_INLINE const T* GetText() const
{ {
return _data ? _data : (const T*)TEXT(""); return _data ? _data : (const T*)TEXT("");

View File

@@ -3,7 +3,6 @@
#pragma once #pragma once
#include "BaseTypes.h" #include "BaseTypes.h"
#include "Engine/Platform/Platform.h"
#include "Engine/Core/Formatting.h" #include "Engine/Core/Formatting.h"
#include "Engine/Core/Templates.h" #include "Engine/Core/Templates.h"

View File

@@ -12,11 +12,13 @@
#include "Engine/Content/Assets/Shader.h" #include "Engine/Content/Assets/Shader.h"
#include "Engine/Content/AssetReference.h" #include "Engine/Content/AssetReference.h"
#include "Engine/Graphics/GPUContext.h" #include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/RenderTask.h" #include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/DynamicBuffer.h"
#include "Engine/Graphics/GPUPipelineState.h" #include "Engine/Graphics/GPUPipelineState.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h" #include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderBuffers.h" #include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/DynamicBuffer.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Animations/AnimationUtils.h" #include "Engine/Animations/AnimationUtils.h"
#include "Engine/Profiler/Profiler.h" #include "Engine/Profiler/Profiler.h"
#include "Engine/Debug/DebugLog.h" #include "Engine/Debug/DebugLog.h"

View File

@@ -7,6 +7,7 @@
#include "Engine/Scripting/ManagedCLR/MDomain.h" #include "Engine/Scripting/ManagedCLR/MDomain.h"
#include "Engine/Scripting/ManagedCLR/MAssembly.h" #include "Engine/Scripting/ManagedCLR/MAssembly.h"
#include "Engine/Scripting/ManagedCLR/MClass.h" #include "Engine/Scripting/ManagedCLR/MClass.h"
#include "Engine/Threading/Threading.h"
#include "FlaxEngine.Gen.h" #include "FlaxEngine.Gen.h"
#include <ThirdParty/mono-2.0/mono/metadata/exception.h> #include <ThirdParty/mono-2.0/mono/metadata/exception.h>
#include <ThirdParty/mono-2.0/mono/metadata/appdomain.h> #include <ThirdParty/mono-2.0/mono/metadata/appdomain.h>

View File

@@ -6,6 +6,7 @@
#include "Engine/Engine/Time.h" #include "Engine/Engine/Time.h"
#include "Engine/Engine/Engine.h" #include "Engine/Engine/Engine.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Platform/Window.h" #include "Engine/Platform/Window.h"
#include "Engine/Profiler/Profiler.h" #include "Engine/Profiler/Profiler.h"
#include "Engine/Level/Level.h" #include "Engine/Level/Level.h"
@@ -17,6 +18,7 @@
#include "Engine/Graphics/RenderTask.h" #include "Engine/Graphics/RenderTask.h"
#include "Engine/Render2D/Render2D.h" #include "Engine/Render2D/Render2D.h"
#include "Engine/Graphics/GPUDevice.h" #include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Utilities/Encryption.h" #include "Engine/Utilities/Encryption.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
#include "FlaxEngine.Gen.h" #include "FlaxEngine.Gen.h"
@@ -241,7 +243,7 @@ void GameBaseImpl::OnPostRender(GPUContext* context, RenderContext& renderContex
const Rectangle screenRect(viewport.X, viewport.Y, viewport.Width, viewport.Height); const Rectangle screenRect(viewport.X, viewport.Y, viewport.Width, viewport.Height);
Rectangle imageArea = screenRect; Rectangle imageArea = screenRect;
imageArea.Scale(0.6f); imageArea.Scale(0.6f);
const float aspectRatio = static_cast<float>(splashScreen->Width()) / splashScreen->Height(); const float aspectRatio = static_cast<float>(splashScreen->Width()) / static_cast<float>(splashScreen->Height());
const float height = imageArea.GetWidth() / aspectRatio; const float height = imageArea.GetWidth() / aspectRatio;
imageArea.Location.Y += (imageArea.GetHeight() - height) * 0.5f; imageArea.Location.Y += (imageArea.GetHeight() - height) * 0.5f;
imageArea.Size.Y = height; imageArea.Size.Y = height;

View File

@@ -8,6 +8,8 @@
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Content/Upgraders/BinaryAssetUpgrader.h" #include "Engine/Content/Upgraders/BinaryAssetUpgrader.h"
#if USE_EDITOR
class GameplayGlobalsUpgrader : public BinaryAssetUpgrader class GameplayGlobalsUpgrader : public BinaryAssetUpgrader
{ {
public: public:
@@ -50,7 +52,9 @@ private:
} }
}; };
REGISTER_BINARY_ASSET(GameplayGlobals, "FlaxEngine.GameplayGlobals", ::New<GameplayGlobalsUpgrader>(), true); #endif
REGISTER_BINARY_ASSET_WITH_UPGRADER(GameplayGlobals, "FlaxEngine.GameplayGlobals", GameplayGlobalsUpgrader, true);
GameplayGlobals::GameplayGlobals(const SpawnParams& params, const AssetInfo* info) GameplayGlobals::GameplayGlobals(const SpawnParams& params, const AssetInfo* info)
: BinaryAsset(params, info) : BinaryAsset(params, info)

View File

@@ -25,4 +25,3 @@ int32 Globals::EngineBuildNumber = FLAXENGINE_VERSION_BUILD;
String Globals::ProductName; String Globals::ProductName;
String Globals::CompanyName; String Globals::CompanyName;
int32 Globals::ContentKey; int32 Globals::ContentKey;
bool Globals::ConvertLoadedMaterialsByForce;

View File

@@ -94,7 +94,4 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Globals);
/// The content data keycode. /// The content data keycode.
/// </summary> /// </summary>
static int32 ContentKey; static int32 ContentKey;
// True if convert all loaded material by force
static bool ConvertLoadedMaterialsByForce;
}; };

View File

@@ -5,6 +5,7 @@
#include "FoliageCluster.h" #include "FoliageCluster.h"
#include "Engine/Core/Random.h" #include "Engine/Core/Random.h"
#include "Engine/Engine/Engine.h" #include "Engine/Engine/Engine.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Level/Scene/Scene.h" #include "Engine/Level/Scene/Scene.h"
#include "Engine/Level/SceneQuery.h" #include "Engine/Level/SceneQuery.h"
#include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Profiler/ProfilerCPU.h"

View File

@@ -6,6 +6,7 @@
#include "RenderTask.h" #include "RenderTask.h"
#include "RenderTools.h" #include "RenderTools.h"
#include "Graphics.h" #include "Graphics.h"
#include "Shaders/GPUShader.h"
#include "Async/DefaultGPUTasksExecutor.h" #include "Async/DefaultGPUTasksExecutor.h"
#include "Engine/Content/Assets/Shader.h" #include "Engine/Content/Assets/Shader.h"
#include "Engine/Content/Assets/Material.h" #include "Engine/Content/Assets/Material.h"

View File

@@ -2,6 +2,8 @@
#include "MaterialParams.h" #include "MaterialParams.h"
#include "MaterialInfo.h" #include "MaterialInfo.h"
#include "Engine/Core/Math/Vector4.h"
#include "Engine/Core/Math/Matrix.h"
#include "Engine/Content/Content.h" #include "Engine/Content/Content.h"
#include "Engine/Graphics/GPUContext.h" #include "Engine/Graphics/GPUContext.h"
#include "Engine/Engine/GameplayGlobals.h" #include "Engine/Engine/GameplayGlobals.h"
@@ -96,11 +98,11 @@ Variant MaterialParameter::GetValue() const
case MaterialParameterType::Vector3: case MaterialParameterType::Vector3:
return _asVector3; return _asVector3;
case MaterialParameterType::Vector4: case MaterialParameterType::Vector4:
return _asVector4; return *(Vector4*)&AsData;
case MaterialParameterType::Color: case MaterialParameterType::Color:
return _asColor; return _asColor;
case MaterialParameterType::Matrix: case MaterialParameterType::Matrix:
return Variant(_asMatrix); return Variant(*(Matrix*)&AsData);
case MaterialParameterType::NormalMap: case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture: case MaterialParameterType::Texture:
case MaterialParameterType::CubeTexture: case MaterialParameterType::CubeTexture:
@@ -140,13 +142,13 @@ void MaterialParameter::SetValue(const Variant& value)
_asVector3 = (Vector3)value; _asVector3 = (Vector3)value;
break; break;
case MaterialParameterType::Vector4: case MaterialParameterType::Vector4:
_asVector4 = (Vector4)value; *(Vector4*)&AsData = (Vector4)value;
break; break;
case MaterialParameterType::Color: case MaterialParameterType::Color:
_asColor = (Color)value; _asColor = (Color)value;
break; break;
case MaterialParameterType::Matrix: case MaterialParameterType::Matrix:
_asMatrix = (Matrix)value; *(Matrix*)&AsData = (Matrix)value;
break; break;
case MaterialParameterType::NormalMap: case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture: case MaterialParameterType::Texture:
@@ -245,13 +247,13 @@ void MaterialParameter::Bind(BindMeta& meta) const
*((Vector3*)(meta.Constants + _offset)) = _asVector3; *((Vector3*)(meta.Constants + _offset)) = _asVector3;
break; break;
case MaterialParameterType::Vector4: case MaterialParameterType::Vector4:
*((Vector4*)(meta.Constants + _offset)) = _asVector4; *((Vector4*)(meta.Constants + _offset)) = *(Vector4*)&AsData;
break; break;
case MaterialParameterType::Color: case MaterialParameterType::Color:
*((Color*)(meta.Constants + _offset)) = _asColor; *((Color*)(meta.Constants + _offset)) = _asColor;
break; break;
case MaterialParameterType::Matrix: case MaterialParameterType::Matrix:
Matrix::Transpose(_asMatrix, *(Matrix*)(meta.Constants + _offset)); Matrix::Transpose(*(Matrix*)&AsData, *(Matrix*)(meta.Constants + _offset));
break; break;
case MaterialParameterType::NormalMap: case MaterialParameterType::NormalMap:
{ {
@@ -406,13 +408,13 @@ void MaterialParameter::clone(const MaterialParameter* param)
_asVector3 = param->_asVector3; _asVector3 = param->_asVector3;
break; break;
case MaterialParameterType::Vector4: case MaterialParameterType::Vector4:
_asVector4 = param->_asVector4; *(Vector4*)&AsData = *(Vector4*)&param->AsData;
break; break;
case MaterialParameterType::Color: case MaterialParameterType::Color:
_asColor = param->_asColor; _asColor = param->_asColor;
break; break;
case MaterialParameterType::Matrix: case MaterialParameterType::Matrix:
_asMatrix = param->_asMatrix; *(Matrix*)&AsData = *(Matrix*)&param->AsData;
break; break;
default: default:
break; break;
@@ -585,13 +587,13 @@ bool MaterialParams::Load(ReadStream* stream)
stream->Read(&param->_asVector3); stream->Read(&param->_asVector3);
break; break;
case MaterialParameterType::Vector4: case MaterialParameterType::Vector4:
stream->Read(&param->_asVector4); stream->Read((Vector4*)&param->AsData);
break; break;
case MaterialParameterType::Color: case MaterialParameterType::Color:
stream->Read(&param->_asColor); stream->Read(&param->_asColor);
break; break;
case MaterialParameterType::Matrix: case MaterialParameterType::Matrix:
stream->Read(&param->_asMatrix); stream->Read((Matrix*)&param->AsData);
break; break;
case MaterialParameterType::NormalMap: case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture: case MaterialParameterType::Texture:
@@ -658,13 +660,13 @@ bool MaterialParams::Load(ReadStream* stream)
stream->Read(&param->_asVector3); stream->Read(&param->_asVector3);
break; break;
case MaterialParameterType::Vector4: case MaterialParameterType::Vector4:
stream->Read(&param->_asVector4); stream->Read((Vector4*)&param->AsData);
break; break;
case MaterialParameterType::Color: case MaterialParameterType::Color:
stream->Read(&param->_asColor); stream->Read(&param->_asColor);
break; break;
case MaterialParameterType::Matrix: case MaterialParameterType::Matrix:
stream->Read(&param->_asMatrix); stream->Read((Matrix*)&param->AsData);
break; break;
case MaterialParameterType::NormalMap: case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture: case MaterialParameterType::Texture:
@@ -732,13 +734,13 @@ bool MaterialParams::Load(ReadStream* stream)
stream->Read(&param->_asVector3); stream->Read(&param->_asVector3);
break; break;
case MaterialParameterType::Vector4: case MaterialParameterType::Vector4:
stream->Read(&param->_asVector4); stream->Read((Vector4*)&param->AsData);
break; break;
case MaterialParameterType::Color: case MaterialParameterType::Color:
stream->Read(&param->_asColor); stream->Read(&param->_asColor);
break; break;
case MaterialParameterType::Matrix: case MaterialParameterType::Matrix:
stream->Read(&param->_asMatrix); stream->Read((Matrix*)&param->AsData);
break; break;
case MaterialParameterType::NormalMap: case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture: case MaterialParameterType::Texture:
@@ -824,13 +826,13 @@ void MaterialParams::Save(WriteStream* stream)
stream->Write(&param->_asVector3); stream->Write(&param->_asVector3);
break; break;
case MaterialParameterType::Vector4: case MaterialParameterType::Vector4:
stream->Write(&param->_asVector4); stream->Write((Vector4*)&param->AsData);
break; break;
case MaterialParameterType::Color: case MaterialParameterType::Color:
stream->Write(&param->_asColor); stream->Write(&param->_asColor);
break; break;
case MaterialParameterType::Matrix: case MaterialParameterType::Matrix:
stream->Write(&param->_asMatrix); stream->Write((Matrix*)&param->AsData);
break; break;
case MaterialParameterType::NormalMap: case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture: case MaterialParameterType::Texture:
@@ -898,13 +900,13 @@ void MaterialParams::Save(WriteStream* stream, const Array<SerializedMaterialPar
stream->Write(&param.AsVector3); stream->Write(&param.AsVector3);
break; break;
case MaterialParameterType::Vector4: case MaterialParameterType::Vector4:
stream->Write(&param.AsVector4); stream->Write((Vector4*)&param.AsData);
break; break;
case MaterialParameterType::Color: case MaterialParameterType::Color:
stream->Write(&param.AsColor); stream->Write(&param.AsColor);
break; break;
case MaterialParameterType::Matrix: case MaterialParameterType::Matrix:
stream->Write(&param.AsMatrix); stream->Write((Matrix*)&param.AsData);
break; break;
case MaterialParameterType::NormalMap: case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture: case MaterialParameterType::Texture:

View File

@@ -2,7 +2,9 @@
#pragma once #pragma once
#include "Engine/Core/Math/Matrix.h" #include "Engine/Core/Math/Color.h"
#include "Engine/Core/Math/Vector2.h"
#include "Engine/Core/Math/Vector3.h"
#include "Engine/Core/Types/StringView.h" #include "Engine/Core/Types/StringView.h"
#include "Engine/Core/Collections/Array.h" #include "Engine/Core/Collections/Array.h"
#include "Engine/Scripting/ScriptingObjectReference.h" #include "Engine/Scripting/ScriptingObjectReference.h"
@@ -12,6 +14,7 @@
class MaterialInstance; class MaterialInstance;
class MaterialParams; class MaterialParams;
class GPUContext; class GPUContext;
class GPUTextureView;
class RenderBuffers; class RenderBuffers;
struct MaterialParamsLink struct MaterialParamsLink
@@ -143,10 +146,9 @@ struct SerializedMaterialParam
float AsFloat; float AsFloat;
Vector2 AsVector2; Vector2 AsVector2;
Vector3 AsVector3; Vector3 AsVector3;
Vector4 AsVector4;
Color AsColor; Color AsColor;
Guid AsGuid; Guid AsGuid;
Matrix AsMatrix; byte AsData[16 * 4];
}; };
byte RegisterIndex; byte RegisterIndex;
@@ -181,9 +183,8 @@ private:
float _asFloat; float _asFloat;
Vector2 _asVector2; Vector2 _asVector2;
Vector3 _asVector3; Vector3 _asVector3;
Vector4 _asVector4;
Color _asColor; Color _asColor;
Matrix _asMatrix; byte AsData[16 * 4];
}; };
AssetReference<Asset> _asAsset; AssetReference<Asset> _asAsset;

View File

@@ -2,6 +2,7 @@
#include "MaterialShaderFeatures.h" #include "MaterialShaderFeatures.h"
#include "Engine/Graphics/RenderTask.h" #include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Renderer/RenderList.h" #include "Engine/Renderer/RenderList.h"
#include "Engine/Renderer/ShadowsPass.h" #include "Engine/Renderer/ShadowsPass.h"
#if USE_EDITOR #if USE_EDITOR

View File

@@ -5,6 +5,8 @@
#include "Engine/Content/Assets/Material.h" #include "Engine/Content/Assets/Material.h"
#include "Engine/Content/Assets/Model.h" #include "Engine/Content/Assets/Model.h"
#include "Engine/Graphics/GPUContext.h" #include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Level/Scene/Scene.h" #include "Engine/Level/Scene/Scene.h"
#include "Engine/Renderer/RenderList.h" #include "Engine/Renderer/RenderList.h"
#include "Engine/Serialization/MemoryReadStream.h" #include "Engine/Serialization/MemoryReadStream.h"
@@ -131,6 +133,11 @@ namespace
} }
} }
bool Mesh::HasVertexColors() const
{
return _vertexBuffers[2] != nullptr && _vertexBuffers[2]->IsAllocated();
}
bool Mesh::UpdateMesh(uint32 vertexCount, uint32 triangleCount, VB0ElementType* vb0, VB1ElementType* vb1, VB2ElementType* vb2, void* ib, bool use16BitIndices) bool Mesh::UpdateMesh(uint32 vertexCount, uint32 triangleCount, VB0ElementType* vb0, VB1ElementType* vb1, VB2ElementType* vb2, void* ib, bool use16BitIndices)
{ {
auto model = (Model*)_model; auto model = (Model*)_model;

View File

@@ -3,15 +3,16 @@
#pragma once #pragma once
#include "MeshBase.h" #include "MeshBase.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderTask.h"
#include "ModelInstanceEntry.h" #include "ModelInstanceEntry.h"
#include "Config.h" #include "Config.h"
#include "Types.h" #include "Types.h"
#include "Engine/Level/Types.h"
#if USE_PRECISE_MESH_INTERSECTS #if USE_PRECISE_MESH_INTERSECTS
#include "CollisionProxy.h" #include "CollisionProxy.h"
#endif #endif
struct GeometryDrawStateData;
class Lightmap;
class GPUBuffer; class GPUBuffer;
/// <summary> /// <summary>
@@ -21,7 +22,6 @@ API_CLASS(NoSpawn) class FLAXENGINE_API Mesh : public MeshBase
{ {
DECLARE_SCRIPTING_TYPE_WITH_CONSTRUCTOR_IMPL(Mesh, MeshBase); DECLARE_SCRIPTING_TYPE_WITH_CONSTRUCTOR_IMPL(Mesh, MeshBase);
protected: protected:
int32 _index; int32 _index;
int32 _lodIndex; int32 _lodIndex;
bool _hasLightmapUVs; bool _hasLightmapUVs;
@@ -32,7 +32,6 @@ protected:
#endif #endif
public: public:
Mesh(const Mesh& other) Mesh(const Mesh& other)
: Mesh() : Mesh()
{ {
@@ -47,7 +46,6 @@ public:
~Mesh(); ~Mesh();
public: public:
/// <summary> /// <summary>
/// Gets the model owning this mesh. /// Gets the model owning this mesh.
/// </summary> /// </summary>
@@ -104,10 +102,7 @@ public:
/// Determines whether this mesh has a vertex colors buffer. /// Determines whether this mesh has a vertex colors buffer.
/// </summary> /// </summary>
/// <returns>True if this mesh has a vertex colors buffers.</returns> /// <returns>True if this mesh has a vertex colors buffers.</returns>
API_PROPERTY() FORCE_INLINE bool HasVertexColors() const API_PROPERTY() bool HasVertexColors() const;
{
return _vertexBuffers[2] != nullptr && _vertexBuffers[2]->IsAllocated();
}
/// <summary> /// <summary>
/// Determines whether this mesh contains valid lightmap texture coordinates data. /// Determines whether this mesh contains valid lightmap texture coordinates data.
@@ -132,7 +127,6 @@ public:
#endif #endif
public: public:
/// <summary> /// <summary>
/// Updates the model mesh (used by the virtual models created with Init rather than Load). /// Updates the model mesh (used by the virtual models created with Init rather than Load).
/// </summary> /// </summary>
@@ -211,7 +205,6 @@ public:
bool UpdateMesh(uint32 vertexCount, uint32 triangleCount, Vector3* vertices, uint32* triangles, Vector3* normals = nullptr, Vector3* tangents = nullptr, Vector2* uvs = nullptr, Color32* colors = nullptr); bool UpdateMesh(uint32 vertexCount, uint32 triangleCount, Vector3* vertices, uint32* triangles, Vector3* normals = nullptr, Vector3* tangents = nullptr, Vector2* uvs = nullptr, Color32* colors = nullptr);
public: public:
/// <summary> /// <summary>
/// Updates the model mesh index buffer (used by the virtual models created with Init rather than Load). /// Updates the model mesh index buffer (used by the virtual models created with Init rather than Load).
/// </summary> /// </summary>
@@ -244,7 +237,6 @@ public:
bool UpdateTriangles(uint32 triangleCount, void* ib, bool use16BitIndices); bool UpdateTriangles(uint32 triangleCount, void* ib, bool use16BitIndices);
public: public:
/// <summary> /// <summary>
/// Initializes instance of the <see cref="Mesh"/> class. /// Initializes instance of the <see cref="Mesh"/> class.
/// </summary> /// </summary>
@@ -276,7 +268,6 @@ public:
void Unload(); void Unload();
public: public:
/// <summary> /// <summary>
/// Determines if there is an intersection between the mesh and a ray in given world /// Determines if there is an intersection between the mesh and a ray in given world
/// </summary> /// </summary>
@@ -297,7 +288,6 @@ public:
} }
public: public:
/// <summary> /// <summary>
/// Gets the draw call geometry for this mesh. Sets the index and vertex buffers. /// Gets the draw call geometry for this mesh. Sets the index and vertex buffers.
/// </summary> /// </summary>
@@ -397,14 +387,12 @@ public:
void Draw(const RenderContext& renderContext, const DrawInfo& info, float lodDitherFactor) const; void Draw(const RenderContext& renderContext, const DrawInfo& info, float lodDitherFactor) const;
public: public:
// [MeshBase] // [MeshBase]
bool DownloadDataGPU(MeshBufferType type, BytesContainer& result) const override; bool DownloadDataGPU(MeshBufferType type, BytesContainer& result) const override;
Task* DownloadDataGPUAsync(MeshBufferType type, BytesContainer& result) const override; Task* DownloadDataGPUAsync(MeshBufferType type, BytesContainer& result) const override;
bool DownloadDataCPU(MeshBufferType type, BytesContainer& result) const override; bool DownloadDataCPU(MeshBufferType type, BytesContainer& result) const override;
private: private:
// Internal bindings // Internal bindings
API_FUNCTION(NoProxy) ScriptingObject* GetParentModel(); API_FUNCTION(NoProxy) ScriptingObject* GetParentModel();
API_FUNCTION(NoProxy) bool UpdateMeshInt(int32 vertexCount, int32 triangleCount, MonoArray* verticesObj, MonoArray* trianglesObj, MonoArray* normalsObj, MonoArray* tangentsObj, MonoArray* uvObj, MonoArray* colorsObj); API_FUNCTION(NoProxy) bool UpdateMeshInt(int32 vertexCount, int32 triangleCount, MonoArray* verticesObj, MonoArray* trianglesObj, MonoArray* normalsObj, MonoArray* tangentsObj, MonoArray* uvObj, MonoArray* colorsObj);

View File

@@ -6,6 +6,7 @@
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
#include "Engine/Core/Utilities.h" #include "Engine/Core/Utilities.h"
#include "Engine/Core/Types/DateTime.h" #include "Engine/Core/Types/DateTime.h"
#include "Engine/Core/Types/TimeSpan.h"
#include "Engine/Core/Collections/BitArray.h" #include "Engine/Core/Collections/BitArray.h"
#include "Engine/Tools/ModelTool/ModelTool.h" #include "Engine/Tools/ModelTool/ModelTool.h"
#include "Engine/Tools/ModelTool/VertexTriangleAdjacency.h" #include "Engine/Tools/ModelTool/VertexTriangleAdjacency.h"

View File

@@ -4,6 +4,8 @@
#include "ModelInstanceEntry.h" #include "ModelInstanceEntry.h"
#include "Engine/Content/Assets/Material.h" #include "Engine/Content/Assets/Material.h"
#include "Engine/Content/Assets/SkinnedModel.h" #include "Engine/Content/Assets/SkinnedModel.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Level/Scene/Scene.h" #include "Engine/Level/Scene/Scene.h"
#include "Engine/Renderer/RenderList.h" #include "Engine/Renderer/RenderList.h"
#include "Engine/Serialization/MemoryReadStream.h" #include "Engine/Serialization/MemoryReadStream.h"

View File

@@ -3,13 +3,13 @@
#pragma once #pragma once
#include "MeshBase.h" #include "MeshBase.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderTask.h"
#include "ModelInstanceEntry.h"
#include "Types.h" #include "Types.h"
#include "BlendShape.h" #include "BlendShape.h"
struct GeometryDrawStateData;
struct RenderContext;
class GPUBuffer; class GPUBuffer;
class SkinnedMeshDrawData;
/// <summary> /// <summary>
/// Represents part of the skinned model that is made of vertices and can be rendered using custom material, transformation and skeleton bones hierarchy. /// Represents part of the skinned model that is made of vertices and can be rendered using custom material, transformation and skeleton bones hierarchy.

View File

@@ -5,6 +5,12 @@
#include "Engine/Content/Assets/Model.h" #include "Engine/Content/Assets/Model.h"
#include "Engine/Serialization/MemoryReadStream.h" #include "Engine/Serialization/MemoryReadStream.h"
bool SkinnedModelLOD::HasAnyMeshInitialized() const
{
// Note: we initialize all meshes at once so the last one can be used to check it.
return Meshes.HasItems() && Meshes.Last().IsInitialized();
}
bool SkinnedModelLOD::Load(MemoryReadStream& stream) bool SkinnedModelLOD::Load(MemoryReadStream& stream)
{ {
// Load LOD for each mesh // Load LOD for each mesh

View File

@@ -33,12 +33,7 @@ public:
/// <summary> /// <summary>
/// Determines whether any mesh has been initialized. /// Determines whether any mesh has been initialized.
/// </summary> /// </summary>
/// <returns>True if any mesh has been initialized, otherwise false.</returns> bool HasAnyMeshInitialized() const;
FORCE_INLINE bool HasAnyMeshInitialized() const
{
// Note: we initialize all meshes at once so the last one can be used to check it.
return Meshes.HasItems() && Meshes.Last().IsInitialized();
}
public: public:

View File

@@ -3,6 +3,7 @@
#pragma once #pragma once
#include "Engine/Core/Math/Vector3.h" #include "Engine/Core/Math/Vector3.h"
#include "Engine/Core/Math/Vector4.h"
#include "Engine/Content/AssetReference.h" #include "Engine/Content/AssetReference.h"
#include "Engine/Serialization/ISerializable.h" #include "Engine/Serialization/ISerializable.h"
#include "Engine/Content/Assets/Texture.h" #include "Engine/Content/Assets/Texture.h"

View File

@@ -6,6 +6,7 @@
#include "PixelFormat.h" #include "PixelFormat.h"
#include "RenderView.h" #include "RenderView.h"
#include "GPUDevice.h" #include "GPUDevice.h"
#include "RenderTask.h"
#include "Engine/Content/Assets/Model.h" #include "Engine/Content/Assets/Model.h"
#include "Engine/Content/Assets/SkinnedModel.h" #include "Engine/Content/Assets/SkinnedModel.h"
#include "Engine/Engine/Time.h" #include "Engine/Engine/Time.h"

View File

@@ -4,6 +4,8 @@
#include "ShaderStorage.h" #include "ShaderStorage.h"
#include "ShaderCacheManager.h" #include "ShaderCacheManager.h"
#include "Engine/Engine/CommandLine.h" #include "Engine/Engine/CommandLine.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Serialization/MemoryReadStream.h" #include "Engine/Serialization/MemoryReadStream.h"
#include "Engine/ShadowsOfMordor/AtlasChartsPacker.h" #include "Engine/ShadowsOfMordor/AtlasChartsPacker.h"
@@ -31,6 +33,16 @@ ShaderStorage::CachingMode ShaderStorage::GetCachingMode()
#endif #endif
bool ShaderAssetBase::IsNullRenderer()
{
return GPUDevice::Instance->GetRendererType() == RendererType::Null;
}
int32 ShaderAssetBase::GetCacheChunkIndex()
{
return GetCacheChunkIndex(GPUDevice::Instance->GetShaderProfile());
}
int32 ShaderAssetBase::GetCacheChunkIndex(ShaderProfile profile) int32 ShaderAssetBase::GetCacheChunkIndex(ShaderProfile profile)
{ {
int32 result; int32 result;
@@ -61,6 +73,28 @@ int32 ShaderAssetBase::GetCacheChunkIndex(ShaderProfile profile)
return result; return result;
} }
bool ShaderAssetBase::initBase(AssetInitData& initData)
{
// Validate version
if (initData.SerializedVersion != ShaderStorage::Header::Version)
{
LOG(Warning, "Invalid shader serialized version.");
return true;
}
// Validate data
if (initData.CustomData.Length() != sizeof(_shaderHeader))
{
LOG(Warning, "Invalid shader header.");
return true;
}
// Load header 'as-is'
Platform::MemoryCopy(&_shaderHeader, initData.CustomData.Get(), sizeof(_shaderHeader));
return false;
}
#if USE_EDITOR #if USE_EDITOR
bool ShaderAssetBase::Save() bool ShaderAssetBase::Save()

View File

@@ -4,7 +4,6 @@
#include "Engine/Core/Types/DataContainer.h" #include "Engine/Core/Types/DataContainer.h"
#include "Engine/Content/BinaryAsset.h" #include "Engine/Content/BinaryAsset.h"
#include "Engine/Graphics/GPUDevice.h"
#include "ShaderStorage.h" #include "ShaderStorage.h"
/// <summary> /// <summary>
@@ -18,17 +17,15 @@ protected:
public: public:
/// <summary> static bool IsNullRenderer();
/// Gets internal shader cache chunk index
/// </summary>
/// <returns>Chunk index</returns>
FORCE_INLINE static int32 GetCacheChunkIndex()
{
return GetCacheChunkIndex(GPUDevice::Instance->GetShaderProfile());
}
/// <summary> /// <summary>
/// Gets internal shader cache chunk index /// Gets internal shader cache chunk index (for current GPU device shader profile).
/// </summary>
static int32 GetCacheChunkIndex();
/// <summary>
/// Gets internal shader cache chunk index.
/// </summary> /// </summary>
/// <param name="profile">Shader profile</param> /// <param name="profile">Shader profile</param>
/// <returns>Chunk index</returns> /// <returns>Chunk index</returns>
@@ -47,11 +44,12 @@ public:
#endif #endif
protected: protected:
bool initBase(AssetInitData& initData);
/// <summary> /// <summary>
/// Gets the parent asset. /// Gets the parent asset.
/// </summary> /// </summary>
/// <returns>The asset.</returns>
virtual BinaryAsset* GetShaderAsset() const = 0; virtual BinaryAsset* GetShaderAsset() const = 0;
#if USE_EDITOR #if USE_EDITOR
@@ -110,7 +108,7 @@ protected:
}; };
/// <summary> /// <summary>
/// Base class for assets that can contain shader /// Base class for binary assets that can contain shader.
/// </summary> /// </summary>
template<typename BaseType> template<typename BaseType>
class ShaderAssetTypeBase : public BaseType, public ShaderAssetBase class ShaderAssetTypeBase : public BaseType, public ShaderAssetBase
@@ -121,11 +119,6 @@ public:
protected: protected:
/// <summary>
/// Init
/// </summary>
/// <param name="params">Asset scripting class metadata</param>
/// <param name="info">Asset information</param>
explicit ShaderAssetTypeBase(const ScriptingObjectSpawnParams& params, const AssetInfo* info) explicit ShaderAssetTypeBase(const ScriptingObjectSpawnParams& params, const AssetInfo* info)
: BaseType(params, info) : BaseType(params, info)
{ {
@@ -134,38 +127,22 @@ protected:
protected: protected:
// [BaseType] // [BaseType]
BinaryAsset* GetShaderAsset() const override
{
return (BinaryAsset*)this;
}
bool init(AssetInitData& initData) override bool init(AssetInitData& initData) override
{ {
// Validate version return initBase(initData);
if (initData.SerializedVersion != ShadersSerializedVersion)
{
LOG(Warning, "Invalid shader serialized version.");
return true;
}
// Validate data
if (initData.CustomData.Length() != sizeof(_shaderHeader))
{
LOG(Warning, "Invalid shader header.");
return true;
}
// Load header 'as-is'
Platform::MemoryCopy(&_shaderHeader, initData.CustomData.Get(), sizeof(_shaderHeader));
return false;
} }
AssetChunksFlag getChunksToPreload() const override AssetChunksFlag getChunksToPreload() const override
{ {
AssetChunksFlag result = 0; AssetChunksFlag result = 0;
const auto cachingMode = ShaderStorage::GetCachingMode(); const auto cachingMode = ShaderStorage::GetCachingMode();
if (cachingMode == ShaderStorage::CachingMode::AssetInternal && GPUDevice::Instance->GetRendererType() != RendererType::Null) if (cachingMode == ShaderStorage::CachingMode::AssetInternal && IsNullRenderer())
result |= GET_CHUNK_FLAG(GetCacheChunkIndex()); result |= GET_CHUNK_FLAG(GetCacheChunkIndex());
return result; return result;
} }
// [ShaderAssetBase]
BinaryAsset* GetShaderAsset() const override
{
return (BinaryAsset*)this;
}
}; };

View File

@@ -18,8 +18,7 @@ public:
/// <summary> /// <summary>
/// Gets the texture owner mutex used to synchronize texture logic. /// Gets the texture owner mutex used to synchronize texture logic.
/// </summary> /// </summary>
/// <returns>The mutex.</returns> virtual CriticalSection& GetOwnerLocker() const = 0;
virtual CriticalSection* GetOwnerLocker() const = 0;
/// <summary> /// <summary>
/// Get texture mip map data /// Get texture mip map data

View File

@@ -33,6 +33,23 @@ StreamingTexture::~StreamingTexture()
ASSERT(_streamingTasksCount == 0); ASSERT(_streamingTasksCount == 0);
} }
Vector2 StreamingTexture::Size() const
{
return _texture->Size();
}
int32 StreamingTexture::TextureMipIndexToTotalIndex(int32 textureMipIndex) const
{
const int32 missingMips = TotalMipLevels() - _texture->MipLevels();
return textureMipIndex + missingMips;
}
int32 StreamingTexture::TotalIndexToTextureMipIndex(int32 mipIndex) const
{
const int32 missingMips = TotalMipLevels() - _texture->MipLevels();
return mipIndex - missingMips;
}
bool StreamingTexture::Create(const TextureHeader& header) bool StreamingTexture::Create(const TextureHeader& header)
{ {
// Validate header (further validation is performed by the Texture.Init) // Validate header (further validation is performed by the Texture.Init)
@@ -90,13 +107,27 @@ uint64 StreamingTexture::GetTotalMemoryUsage() const
return CalculateTextureMemoryUsage(_header.Format, _header.Width, _header.Height, _header.MipLevels) * arraySize; return CalculateTextureMemoryUsage(_header.Format, _header.Width, _header.Height, _header.MipLevels) * arraySize;
} }
String StreamingTexture::ToString() const
{
return _texture->ToString();
}
int32 StreamingTexture::GetCurrentResidency() const
{
return _texture->ResidentMipLevels();
}
int32 StreamingTexture::GetAllocatedResidency() const
{
return _texture->MipLevels();
}
bool StreamingTexture::CanBeUpdated() const bool StreamingTexture::CanBeUpdated() const
{ {
// Streaming Texture cannot be updated if: // Streaming Texture cannot be updated if:
// - is not initialized // - is not initialized
// - mip data uploading job running // - mip data uploading job running
// - resize texture job running // - resize texture job running
return IsInitialized() && Platform::AtomicRead(&_streamingTasksCount) == 0; return IsInitialized() && Platform::AtomicRead(&_streamingTasksCount) == 0;
} }
@@ -146,7 +177,6 @@ protected:
return Result::Ok; return Result::Ok;
} }
void OnEnd() override void OnEnd() override
{ {
Platform::InterlockedDecrement(&_streamingTexture->_streamingTasksCount); Platform::InterlockedDecrement(&_streamingTexture->_streamingTasksCount);
@@ -154,7 +184,6 @@ protected:
// Base // Base
GPUTask::OnEnd(); GPUTask::OnEnd();
} }
void OnSync() override void OnSync() override
{ {
Swap(_streamingTexture->_texture, _newTexture); Swap(_streamingTexture->_texture, _newTexture);
@@ -298,7 +327,6 @@ protected:
return Result::Ok; return Result::Ok;
} }
void OnEnd() override void OnEnd() override
{ {
_dataLock.Release(); _dataLock.Release();

View File

@@ -2,7 +2,6 @@
#pragma once #pragma once
#include "GPUTexture.h"
#include "ITextureOwner.h" #include "ITextureOwner.h"
#include "Engine/Streaming/StreamableResource.h" #include "Engine/Streaming/StreamableResource.h"
#include "Types.h" #include "Types.h"
@@ -14,7 +13,6 @@ class FLAXENGINE_API StreamingTexture : public Object, public StreamableResource
{ {
friend class StreamTextureMipTask; friend class StreamTextureMipTask;
friend class StreamTextureResizeTask; friend class StreamTextureResizeTask;
protected: protected:
ITextureOwner* _owner; ITextureOwner* _owner;
@@ -25,16 +23,7 @@ protected:
public: public:
/// <summary>
/// Init
/// </summary>
/// <param name="owner">Parent object</param>
/// <param name="name">Texture object name</param>
StreamingTexture(ITextureOwner* owner, const String& name); StreamingTexture(ITextureOwner* owner, const String& name);
/// <summary>
/// Destructor
/// </summary>
~StreamingTexture(); ~StreamingTexture();
public: public:
@@ -42,31 +31,23 @@ public:
/// <summary> /// <summary>
/// Gets the owner. /// Gets the owner.
/// </summary> /// </summary>
/// <returns>The owner.</returns>
FORCE_INLINE ITextureOwner* GetOwner() const FORCE_INLINE ITextureOwner* GetOwner() const
{ {
return _owner; return _owner;
} }
/// <summary> /// <summary>
/// Gets texture object handle /// Gets texture object handle.
/// </summary> /// </summary>
/// <returns>Texture object</returns>
FORCE_INLINE GPUTexture* GetTexture() const FORCE_INLINE GPUTexture* GetTexture() const
{ {
return _texture; return _texture;
} }
/// <summary> /// <summary>
/// Gets texture size of Vector2::Zero if not loaded /// Gets texture size of Vector2::Zero if not loaded.
/// </summary> /// </summary>
/// <returns>Texture size</returns> Vector2 Size() const;
FORCE_INLINE Vector2 Size() const
{
return _texture->Size();
}
public:
/// <summary> /// <summary>
/// Gets a value indicating whether this instance is initialized. /// Gets a value indicating whether this instance is initialized.
@@ -88,7 +69,6 @@ public:
/// <summary> /// <summary>
/// Gets total texture height (in texels) /// Gets total texture height (in texels)
/// </summary> /// </summary>
/// <returns>Texture width</returns>
FORCE_INLINE int32 TotalHeight() const FORCE_INLINE int32 TotalHeight() const
{ {
return _header.Height; return _header.Height;
@@ -97,7 +77,6 @@ public:
/// <summary> /// <summary>
/// Gets total texture array size /// Gets total texture array size
/// </summary> /// </summary>
/// <returns>Texture array size</returns>
FORCE_INLINE int32 TotalArraySize() const FORCE_INLINE int32 TotalArraySize() const
{ {
return IsCubeMap() ? 6 : 1; return IsCubeMap() ? 6 : 1;
@@ -106,7 +85,6 @@ public:
/// <summary> /// <summary>
/// Gets total texture mip levels count /// Gets total texture mip levels count
/// </summary> /// </summary>
/// <returns>Texture mip levels</returns>
FORCE_INLINE int32 TotalMipLevels() const FORCE_INLINE int32 TotalMipLevels() const
{ {
return _header.MipLevels; return _header.MipLevels;
@@ -115,7 +93,6 @@ public:
/// <summary> /// <summary>
/// Returns texture format type /// Returns texture format type
/// </summary> /// </summary>
/// <returns>Texture format type</returns>
FORCE_INLINE TextureFormatType GetFormatType() const FORCE_INLINE TextureFormatType GetFormatType() const
{ {
return _header.Type; return _header.Type;
@@ -124,7 +101,6 @@ public:
/// <summary> /// <summary>
/// Returns true if it's a cube map texture /// Returns true if it's a cube map texture
/// </summary> /// </summary>
/// <returns>True if i's a cubemap</returns>
FORCE_INLINE bool IsCubeMap() const FORCE_INLINE bool IsCubeMap() const
{ {
return _header.IsCubeMap; return _header.IsCubeMap;
@@ -133,7 +109,6 @@ public:
/// <summary> /// <summary>
/// Returns true if texture cannot be used during GPU resources streaming system /// Returns true if texture cannot be used during GPU resources streaming system
/// </summary> /// </summary>
/// <returns>True if texture cannot be used during GPU resources streaming system</returns>
FORCE_INLINE bool NeverStream() const FORCE_INLINE bool NeverStream() const
{ {
return _header.NeverStream; return _header.NeverStream;
@@ -142,7 +117,6 @@ public:
/// <summary> /// <summary>
/// Gets the texture header. /// Gets the texture header.
/// </summary> /// </summary>
/// <returns>Header</returns>
FORCE_INLINE const TextureHeader* GetHeader() const FORCE_INLINE const TextureHeader* GetHeader() const
{ {
return &_header; return &_header;
@@ -163,22 +137,14 @@ public:
/// </summary> /// </summary>
/// <param name="textureMipIndex">Index of the texture mip.</param> /// <param name="textureMipIndex">Index of the texture mip.</param>
/// <returns>The index of the mip map.</returns> /// <returns>The index of the mip map.</returns>
FORCE_INLINE int32 TextureMipIndexToTotalIndex(int32 textureMipIndex) const int32 TextureMipIndexToTotalIndex(int32 textureMipIndex) const;
{
const int32 missingMips = TotalMipLevels() - _texture->MipLevels();
return textureMipIndex + missingMips;
}
/// <summary> /// <summary>
/// Converts absolute mip map index to the allocated texture mip index. /// Converts absolute mip map index to the allocated texture mip index.
/// </summary> /// </summary>
/// <param name="mipIndex">Index of the texture mip.</param> /// <param name="mipIndex">Index of the texture mip.</param>
/// <returns>The index of the mip map.</returns> /// <returns>The index of the mip map.</returns>
FORCE_INLINE int32 TotalIndexToTextureMipIndex(int32 mipIndex) const int32 TotalIndexToTextureMipIndex(int32 mipIndex) const;
{
const int32 missingMips = TotalMipLevels() - _texture->MipLevels();
return mipIndex - missingMips;
}
public: public:
@@ -211,27 +177,15 @@ public:
public: public:
// [Object] // [Object]
String ToString() const override String ToString() const override;
{
return _texture->ToString();
}
// [StreamableResource] // [StreamableResource]
int32 GetMaxResidency() const override int32 GetMaxResidency() const override
{ {
return _header.MipLevels; return _header.MipLevels;
} }
int32 GetCurrentResidency() const override;
int32 GetCurrentResidency() const override int32 GetAllocatedResidency() const override;
{
return _texture->ResidentMipLevels();
}
int32 GetAllocatedResidency() const override
{
return _texture->MipLevels();
}
bool CanBeUpdated() const override; bool CanBeUpdated() const override;
Task* UpdateAllocation(int32 residency) override; Task* UpdateAllocation(int32 residency) override;
Task* CreateStreamingTask(int32 residency) override; Task* CreateStreamingTask(int32 residency) override;

View File

@@ -3,10 +3,11 @@
#include "TextureBase.h" #include "TextureBase.h"
#include "TextureData.h" #include "TextureData.h"
#include "Engine/Graphics/GPUDevice.h" #include "Engine/Graphics/GPUDevice.h"
#include "Engine/Debug/Exceptions/ArgumentOutOfRangeException.h" #include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Debug/Exceptions/InvalidOperationException.h"
#include "Engine/Graphics/RenderTools.h" #include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/PixelFormatExtensions.h" #include "Engine/Graphics/PixelFormatExtensions.h"
#include "Engine/Debug/Exceptions/ArgumentOutOfRangeException.h"
#include "Engine/Debug/Exceptions/InvalidOperationException.h"
#include "Engine/Core/Math/Color32.h" #include "Engine/Core/Math/Color32.h"
#include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Content/Factories/BinaryAssetFactory.h" #include "Engine/Content/Factories/BinaryAssetFactory.h"
@@ -22,6 +23,36 @@ TextureBase::TextureBase(const SpawnParams& params, const AssetInfo* info)
{ {
} }
Vector2 TextureBase::Size() const
{
return Vector2(static_cast<float>(_texture.TotalWidth()), static_cast<float>(_texture.TotalHeight()));
}
int32 TextureBase::GetArraySize() const
{
return StreamingTexture()->TotalArraySize();
}
int32 TextureBase::GetMipLevels() const
{
return StreamingTexture()->TotalMipLevels();
}
int32 TextureBase::GetResidentMipLevels() const
{
return GetTexture()->ResidentMipLevels();
}
uint64 TextureBase::GetCurrentMemoryUsage() const
{
return GetTexture()->GetMemoryUsage();
}
uint64 TextureBase::GetTotalMemoryUsage() const
{
return StreamingTexture()->GetTotalMemoryUsage();
}
BytesContainer TextureBase::GetMipData(int32 mipIndex, int32& rowPitch, int32& slicePitch) BytesContainer TextureBase::GetMipData(int32 mipIndex, int32& rowPitch, int32& slicePitch)
{ {
BytesContainer result; BytesContainer result;
@@ -193,9 +224,9 @@ int32 TextureBase::calculateChunkIndex(int32 mipIndex) const
return mipIndex; return mipIndex;
} }
CriticalSection* TextureBase::GetOwnerLocker() const CriticalSection& TextureBase::GetOwnerLocker() const
{ {
return &_parent->Locker; return _parent->Locker;
} }
void TextureBase::unload(bool isReloading) void TextureBase::unload(bool isReloading)

View File

@@ -6,6 +6,8 @@
#include "StreamingTexture.h" #include "StreamingTexture.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
class TextureData;
/// <summary> /// <summary>
/// Base class for <see cref="Texture"/>, <see cref="SpriteAtlas"/>, <see cref="IESProfile"/> and other assets that can contain texture data. /// Base class for <see cref="Texture"/>, <see cref="SpriteAtlas"/>, <see cref="IESProfile"/> and other assets that can contain texture data.
/// </summary> /// </summary>
@@ -103,50 +105,32 @@ public:
/// <summary> /// <summary>
/// Gets the total size of the texture. Actual resident size may be different due to dynamic content streaming. Returns Vector2::Zero if texture is not loaded. /// Gets the total size of the texture. Actual resident size may be different due to dynamic content streaming. Returns Vector2::Zero if texture is not loaded.
/// </summary> /// </summary>
API_PROPERTY() FORCE_INLINE Vector2 Size() const API_PROPERTY() Vector2 Size() const;
{
return Vector2(static_cast<float>(_texture.TotalWidth()), static_cast<float>(_texture.TotalHeight()));
}
/// <summary> /// <summary>
/// Gets the total array size of the texture. /// Gets the total array size of the texture.
/// </summary> /// </summary>
API_PROPERTY() int32 GetArraySize() const API_PROPERTY() int32 GetArraySize() const;
{
return StreamingTexture()->TotalArraySize();
}
/// <summary> /// <summary>
/// Gets the total mip levels count of the texture. Actual resident mipmaps count may be different due to dynamic content streaming. /// Gets the total mip levels count of the texture. Actual resident mipmaps count may be different due to dynamic content streaming.
/// </summary> /// </summary>
API_PROPERTY() int32 GetMipLevels() const API_PROPERTY() int32 GetMipLevels() const;
{
return StreamingTexture()->TotalMipLevels();
}
/// <summary> /// <summary>
/// Gets the current mip levels count of the texture that are on GPU ready to use. /// Gets the current mip levels count of the texture that are on GPU ready to use.
/// </summary> /// </summary>
API_PROPERTY() int32 GetResidentMipLevels() const API_PROPERTY() int32 GetResidentMipLevels() const;
{
return GetTexture()->ResidentMipLevels();
}
/// <summary> /// <summary>
/// Gets the amount of the memory used by this resource. Exact value may differ due to memory alignment and resource allocation policy. /// Gets the amount of the memory used by this resource. Exact value may differ due to memory alignment and resource allocation policy.
/// </summary> /// </summary>
API_PROPERTY() uint64 GetCurrentMemoryUsage() const API_PROPERTY() uint64 GetCurrentMemoryUsage() const;
{
return GetTexture()->GetMemoryUsage();
}
/// <summary> /// <summary>
/// Gets the total memory usage that texture may have in use (if loaded to the maximum quality). Exact value may differ due to memory alignment and resource allocation policy. /// Gets the total memory usage that texture may have in use (if loaded to the maximum quality). Exact value may differ due to memory alignment and resource allocation policy.
/// </summary> /// </summary>
API_PROPERTY() uint64 GetTotalMemoryUsage() const API_PROPERTY() uint64 GetTotalMemoryUsage() const;
{
return StreamingTexture()->GetTotalMemoryUsage();
}
public: public:
@@ -186,7 +170,7 @@ private:
public: public:
// [ITextureOwner] // [ITextureOwner]
CriticalSection* GetOwnerLocker() const override; CriticalSection& GetOwnerLocker() const override;
Task* RequestMipDataAsync(int32 mipIndex) override; Task* RequestMipDataAsync(int32 mipIndex) override;
FlaxStorage::LockData LockData() override; FlaxStorage::LockData LockData() override;
void GetMipData(int32 mipIndex, BytesContainer& data) const override; void GetMipData(int32 mipIndex, BytesContainer& data) const override;

View File

@@ -27,6 +27,7 @@
#include "Engine/Core/Utilities.h" #include "Engine/Core/Utilities.h"
#include "Engine/Core/Math/Color32.h" #include "Engine/Core/Math/Color32.h"
#include "Engine/Engine/Engine.h" #include "Engine/Engine/Engine.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Engine/CommandLine.h" #include "Engine/Engine/CommandLine.h"
#include "Engine/Utilities/StringConverter.h" #include "Engine/Utilities/StringConverter.h"
#include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Profiler/ProfilerCPU.h"
@@ -352,7 +353,7 @@ DeferredDeletionQueueVulkan::~DeferredDeletionQueueVulkan()
void DeferredDeletionQueueVulkan::ReleaseResources(bool deleteImmediately) void DeferredDeletionQueueVulkan::ReleaseResources(bool deleteImmediately)
{ {
ScopeLock lock(&_locker); ScopeLock lock(_locker);
const uint64 checkFrame = Engine::FrameCount - VULKAN_RESOURCE_DELETE_SAFE_FRAMES_COUNT; const uint64 checkFrame = Engine::FrameCount - VULKAN_RESOURCE_DELETE_SAFE_FRAMES_COUNT;
for (int32 i = 0; i < _entries.Count(); i++) for (int32 i = 0; i < _entries.Count(); i++)
{ {

View File

@@ -15,6 +15,7 @@
#include "Engine/Core/Cache.h" #include "Engine/Core/Cache.h"
#include "Engine/Core/Collections/CollectionPoolCache.h" #include "Engine/Core/Collections/CollectionPoolCache.h"
#include "Engine/Debug/Exceptions/JsonParseException.h" #include "Engine/Debug/Exceptions/JsonParseException.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderView.h" #include "Engine/Graphics/RenderView.h"
#include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Scripting/Scripting.h" #include "Engine/Scripting/Scripting.h"

View File

@@ -8,6 +8,7 @@
#include "Editor/Editor.h" #include "Editor/Editor.h"
#endif #endif
#include "Engine/Graphics/GPUDevice.h" #include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Level/Scene/Scene.h" #include "Engine/Level/Scene/Scene.h"
#include "Engine/Level/SceneObjectsFactory.h" #include "Engine/Level/SceneObjectsFactory.h"
#include "Engine/Serialization/Serialization.h" #include "Engine/Serialization/Serialization.h"

View File

@@ -6,6 +6,7 @@
#include "Engine/Content/Assets/SkinnedModel.h" #include "Engine/Content/Assets/SkinnedModel.h"
#include "Engine/Content/Assets/AnimationGraph.h" #include "Engine/Content/Assets/AnimationGraph.h"
#include "Engine/Graphics/Models/SkinnedMeshDrawData.h" #include "Engine/Graphics/Models/SkinnedMeshDrawData.h"
#include "Engine/Renderer/DrawCall.h"
/// <summary> /// <summary>
/// Performs an animation and renders a skinned model. /// Performs an animation and renders a skinned model.

View File

@@ -5,14 +5,16 @@
#include "Engine/Core/Math/Viewport.h" #include "Engine/Core/Math/Viewport.h"
#include "Engine/Content/Assets/Model.h" #include "Engine/Content/Assets/Model.h"
#include "Engine/Content/Content.h" #include "Engine/Content/Content.h"
#include "Engine/Platform/Window.h"
#include "Engine/Serialization/Serialization.h" #include "Engine/Serialization/Serialization.h"
#include "Engine/Level/Scene/SceneRendering.h"
#if USE_EDITOR #if USE_EDITOR
#include "Editor/Editor.h" #include "Editor/Editor.h"
#include "Editor/Managed/ManagedEditor.h" #include "Editor/Managed/ManagedEditor.h"
#include "Engine/Renderer/DrawCall.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Level/Scene/SceneRendering.h"
#else #else
#include "Engine/Engine/Engine.h" #include "Engine/Engine/Engine.h"
#include "Engine/Platform/Window.h"
#endif #endif
Array<Camera*> Camera::Cameras; Array<Camera*> Camera::Cameras;

View File

@@ -3,6 +3,7 @@
#include "EnvironmentProbe.h" #include "EnvironmentProbe.h"
#include "Engine/Platform/FileSystem.h" #include "Engine/Platform/FileSystem.h"
#include "Engine/Graphics/RenderView.h" #include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/Textures/TextureData.h" #include "Engine/Graphics/Textures/TextureData.h"
#include "Engine/Renderer/RenderList.h" #include "Engine/Renderer/RenderList.h"
#include "Engine/Renderer/ProbesRenderer.h" #include "Engine/Renderer/ProbesRenderer.h"

View File

@@ -2,6 +2,9 @@
#include "Light.h" #include "Light.h"
#include "../Scene/Scene.h" #include "../Scene/Scene.h"
#if USE_EDITOR
#include "Engine/Graphics/RenderView.h"
#endif
#include "Engine/Serialization/Serialization.h" #include "Engine/Serialization/Serialization.h"
Light::Light(const SpawnParams& params) Light::Light(const SpawnParams& params)

View File

@@ -4,14 +4,17 @@
#include "DirectionalLight.h" #include "DirectionalLight.h"
#include "Engine/Core/Math/Color.h" #include "Engine/Core/Math/Color.h"
#include "Engine/Content/Content.h" #include "Engine/Content/Content.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Renderer/RenderList.h" #include "Engine/Renderer/RenderList.h"
#include "Engine/Renderer/AtmospherePreCompute.h" #include "Engine/Renderer/AtmospherePreCompute.h"
#include "Engine/Renderer/GBufferPass.h" #include "Engine/Renderer/GBufferPass.h"
#include "Engine/Graphics/RenderBuffers.h" #include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/GPUContext.h" #include "Engine/Graphics/GPUContext.h"
#include "Engine/Serialization/Serialization.h" #include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h" #include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Serialization/Serialization.h"
#include "Engine/Level/Scene/SceneRendering.h" #include "Engine/Level/Scene/SceneRendering.h"
PACK_STRUCT(struct Data { PACK_STRUCT(struct Data {

Some files were not shown because too many files have changed in this diff Show More