Skip to content

Commit

Permalink
Update to C++20 (#33)
Browse files Browse the repository at this point in the history
- Updated animationThrottle from 64 to 1024
- Default initialize modelID to u32 max
- Default Initialized Name Component's nameHash to u32 max
- Default Initialize Transform Component's Matrix to Identity
- Updated Submodule Engine
  • Loading branch information
NixAJ authored Apr 6, 2024
1 parent 56f7cd7 commit ddc656c
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Premake/ProjectUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if ProjectTemplate == nil then
_G[internalName] = { }

if cppVersion == nil or cppVersion == "" then
cppVersion = "C++17"
cppVersion = "C++20"
else
local version = tonumber(cppVersion)

Expand All @@ -32,7 +32,7 @@ if ProjectTemplate == nil then
end

if not cppVersion:find("^C++") then
cppVersion = "C++17"
cppVersion = "C++20"
end
end

Expand Down
12 changes: 6 additions & 6 deletions Source/Game/Game/Animation/AnimationSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

AutoCVar_Int CVAR_AnimationSystemEnabled(CVarCategory::Client | CVarCategory::Rendering, "animationEnabled", "Enables the Animation System", 0, CVarFlags::EditCheckbox);
AutoCVar_Float CVAR_AnimationSystemTimeScale(CVarCategory::Client | CVarCategory::Rendering, "animationTimeScale", "Controls the global speed of all animations", 1.0f);
AutoCVar_Int CVAR_AnimationSystemThrottle(CVarCategory::Client | CVarCategory::Rendering, "animationThrottle", "Sets the number of dirty instances that can be updated every frame", 64);
AutoCVar_Int CVAR_AnimationSystemThrottle(CVarCategory::Client | CVarCategory::Rendering, "animationThrottle", "Sets the number of dirty instances that can be updated every frame", 1024);

namespace Animation
{
Expand Down Expand Up @@ -664,22 +664,22 @@ namespace Animation
{
const AnimationSkeletonBone& bone = skeleton.bones[boneIndex];
AnimationBoneInstance& boneInstance = instance.bones[boneIndex];

HandleBoneAnimation(skeleton, instance, bone, boneInstance, adjustedDeltaTime);

if (!bone.info.flags.Transformed)
continue;

const mat4x4& originalMatrix = _storage.boneMatrices[instance.boneMatrixOffset + boneIndex];
mat4x4 boneMatrix = GetBoneMatrix(skeleton, instance, bone, boneInstance);

// Apply parent's transformation
if (bone.info.parentBoneID != -1)
{
const mat4x4& parentBoneMatrix = _storage.boneMatrices[instance.boneMatrixOffset + bone.info.parentBoneID];
boneMatrix = mul(boneMatrix, parentBoneMatrix);
}

bool isDirty = originalMatrix != boneMatrix;
if (isDirty)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Game/Game/Animation/AnimationSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ namespace Animation
FlyMountSelfFall = 649,
Count
};
static constexpr char* AnimationNames[(i32)Type::Count] =
static const char* AnimationNames[(i32)Type::Count] =
{
"Stand",
"Death",
Expand Down Expand Up @@ -1429,7 +1429,7 @@ namespace Animation
face_beard_00_M_JNT = 192,
Count
};
static char* BoneNames[(i16)Bone::Count] = { };
static const char* BoneNames[(i16)Bone::Count] = { };

enum class BlendOverride
{
Expand Down
4 changes: 3 additions & 1 deletion Source/Game/Game/ECS/Components/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#include <Base/Types.h>
#include <Base/Util/Reflection.h>

#include <limits>

namespace ECS::Components
{
struct Model
{
public:
u32 modelID;
u32 modelID = std::numeric_limits<u32>().max();
u32 instanceID = std::numeric_limits<u32>().max();
};
}
Expand Down
4 changes: 3 additions & 1 deletion Source/Game/Game/ECS/Components/Name.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
#include <Base/Types.h>
#include <Base/Util/Reflection.h>

#include <limits>

namespace ECS::Components
{
struct Name
{
public:
std::string name;
std::string fullName;
u32 nameHash;
u32 nameHash = std::numeric_limits<u32>().max();
};
}

Expand Down
11 changes: 0 additions & 11 deletions Source/Game/Game/ECS/Systems/CharacterController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,17 +523,6 @@ namespace ECS::Systems
quat rotation = glm::quat(glm::vec3(0.0f, glm::radians(characterSingleton.waistRotationSettings.x), 0.0f));
animationSystem->SetBoneRotation(instanceID, Animation::Bone::Waist, rotation);
}

//if (characterSingleton.currentOrientation != characterSingleton.targetOrientation)
//{
// characterSingleton.timeSinceLastOrientationChange += deltaTime;
// characterSingleton.timeSinceLastOrientationChange = glm::clamp(characterSingleton.timeSinceLastOrientationChange, 0.0f, characterSingleton.timetoChangeOrientation);
//
// f32 progress = characterSingleton.timeSinceLastOrientationChange / characterSingleton.timetoChangeOrientation;
// characterSingleton.currentOrientation = glm::mix(characterSingleton.currentOrientation, characterSingleton.targetOrientation, progress);
//
// transformSystem.SetLocalRotation(characterSingleton.modelEntity, glm::quat(glm::vec3(0.0f, glm::radians(characterSingleton.currentOrientation), 0.0f)));
//}
}

void CharacterController::ReInitCharacterModel(entt::registry& registry)
Expand Down
2 changes: 1 addition & 1 deletion Source/Game/Game/ECS/Util/Transforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ namespace ECS::Components
}

private:
mat4a matrix;
mat4a matrix = mat4a(1.0f);
Transform* transform{};
entt::entity ownerEntity;

Expand Down
6 changes: 3 additions & 3 deletions Source/Game/Game/Editor/AssetBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ namespace Editor
tSystem.SetLocalTransform(entity, cameraTransform.GetWorldPosition(), quat(1.0f, 0.0f, 0.0f, 0.0f), vec3(1.0f, 1.0f, 1.0f));

std::string relativePath = fs::relative(item, _modelTopPath).string();
std::replace(relativePath.begin(), relativePath.end(), L'\\', L'/');
std::replace(relativePath.begin(), relativePath.end(), '\\', '/');

u32 modelPathHash = StringUtils::fnv1a_32(relativePath.c_str(), relativePath.length());
_gameRenderer->GetModelLoader()->LoadModelForEntity(entity, modelPathHash);
Expand Down Expand Up @@ -475,12 +475,12 @@ namespace Editor

if (search.size() > _searchedString.size() && !_searchedFiles.empty())
{
const auto temp = _searchedFiles;
const std::vector<fs::path>& temp = _searchedFiles;
_searchedFiles.clear();
_searchedFiles.reserve(temp.size());

_searchedString = search;
for (auto& file : temp)
for (const fs::path& file : temp)
{
if (StringUtils::SearchString(file.filename().string(), _searchedString, true))
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Game/Game/Editor/AssetBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <entt/fwd.hpp>
#include <imgui/imgui.h>
#include <imgui/imgui_internal.h>
#include <imgui/imgui_notify.h>
#include <imgui/ImGuiNotify.hpp>

#include <filesystem>
#include <utility>
Expand Down
2 changes: 1 addition & 1 deletion Source/Game/Game/Editor/EditorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <imgui/imgui.h>
#include <imgui/imgui_internal.h>
#include <imgui/imgui_notify.h>
#include <imgui/ImGuiNotify.hpp>
#include <imgui/imguizmo/ImGuizmo.h>
#include <tracy/Tracy.hpp>

Expand Down
2 changes: 1 addition & 1 deletion Source/Game/Game/Editor/SkyboxSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ namespace Editor
if (ImGui::BeginPopupEx(popupContextID, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings))
{
const fs::path& skyboxPath = data.skyboxPaths[popupSkyboxID];
std::string& skyboxName = skyboxPath.stem().string();
std::string skyboxName = skyboxPath.stem().string();

ImGui::Text("Actions for %s", skyboxName.c_str());
ImGui::Separator();
Expand Down
1 change: 1 addition & 0 deletions Source/Game/Game/Rendering/CulledRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <FileFormat/Shared.h>
#include <FileFormat/Novus/Model/ComplexModel.h>

#include <Renderer/RenderGraphBuilder.h>
#include <Renderer/DescriptorSetResource.h>
#include <Renderer/FrameResource.h>
#include <Renderer/GPUVector.h>
Expand Down
2 changes: 1 addition & 1 deletion Source/Game/Game/Rendering/GameRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <Renderer/Renderers/Vulkan/Backend/stb_image.h>

#include <imgui/imgui.h>
#include <imgui/imgui_notify.h>
#include <imgui/ImGuiNotify.hpp>
#include <imgui/implot.h>
#include <imgui/imnodes.h>
#include <imgui/ruda.h>
Expand Down
4 changes: 2 additions & 2 deletions Source/Game/Game/Rendering/Liquid/LiquidRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void LiquidRenderer::Load(LoadDesc& desc)
drawCallData.textureCount = 1;
drawCallData.hasDepth = 0;
drawCallData.liquidType = 0;
drawCallData.uvAnim = hvec2(0, 0);
drawCallData.uvAnim = hvec2(0.0f, 0.0f);

// Load textures if they exist
entt::registry* registry = ServiceLocator::GetEnttRegistries()->gameRegistry;
Expand Down Expand Up @@ -182,7 +182,7 @@ void LiquidRenderer::Load(LoadDesc& desc)
drawCallData.textureStartIndex = textureStartIndex;
drawCallData.textureCount = textureCount;
drawCallData.liquidType = liquidType.soundBank; // This is a workaround for now, but we don't want to rely on soundbank for knowing if this is liquid, lava or slime in the future
drawCallData.uvAnim = hvec2(0, 0); // TODO: Load this from Vertex format data
drawCallData.uvAnim = hvec2(0.0f, 0.0f); // TODO: Load this from Vertex format data
}

vec3 min = vec3(100000, 100000, 100000);
Expand Down
7 changes: 3 additions & 4 deletions Source/Game/Game/Rendering/Model/ModelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,22 @@
#include "Game/Util/JoltStream.h"
#include "Game/Util/ServiceLocator.h"

#include <Base/CVarSystem/CVarSystem.h>
#include <Base/Memory/FileReader.h>
#include <Base/Util/StringUtils.h>
#include <Base/CVarSystem/CVarSystem.h>

#include <FileFormat/Novus/Map/Map.h>
#include <FileFormat/Novus/Map/MapChunk.h>

#include <entt/entt.hpp>


#include <Jolt/Physics/Body/BodyCreationSettings.h>
#include <Jolt/Physics/Collision/Shape/ScaledShape.h>

#include <atomic>
#include <mutex>
#include <execution>
#include <filesystem>
#include <mutex>
#include <vector>

namespace fs = std::filesystem;
Expand Down Expand Up @@ -670,7 +669,7 @@ bool ModelLoader::LoadRequest(const LoadRequestInternal& request)
// Generate Jolt Shape
{
// Disabled on purpose for now
i32 physicsEnabled = *CVarSystem::Get()->GetIntCVar(CVarCategory::Client | CVarCategory::Physics, "enabled");
i32 physicsEnabled = *CVarSystem::Get()->GetIntCVar(CVarCategory::Client | CVarCategory::Physics, "enabled"_h);
u32 numPhysicsBytes = static_cast<u32>(model->physicsData.size());

if (physicsEnabled && numPhysicsBytes > 0)
Expand Down
4 changes: 2 additions & 2 deletions Source/Game/Game/Rendering/Model/ModelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ u32 ModelRenderer::AddInstance(entt::entity entityID, u32 modelID, const mat4x4&

if (manifest.isAnimated)
{
i32* animationSystemEnabled = CVarSystem::Get()->GetIntCVar(CVarCategory::Client | CVarCategory::Rendering, "animationSystemEnabled"_h);
i32* animationSystemEnabled = CVarSystem::Get()->GetIntCVar(CVarCategory::Client | CVarCategory::Rendering, "animationEnabled"_h);
if (animationSystemEnabled && *animationSystemEnabled == 1)
{
u32 animatedVertexOffset = _animatedVerticesIndex.fetch_add(manifest.numVertices);
Expand Down Expand Up @@ -1426,7 +1426,7 @@ void ModelRenderer::ModifyInstance(entt::entity entityID, u32 instanceID, u32 mo

if (manifest.isAnimated)
{
i32* animationSystemEnabled = CVarSystem::Get()->GetIntCVar(CVarCategory::Client | CVarCategory::Rendering, "animationSystemEnabled"_h);
i32* animationSystemEnabled = CVarSystem::Get()->GetIntCVar(CVarCategory::Client | CVarCategory::Rendering, "animationEnabled"_h);
if (animationSystemEnabled && *animationSystemEnabled == 1)
{
u32 animatedVertexOffset = _animatedVerticesIndex.fetch_add(manifest.numVertices);
Expand Down
2 changes: 1 addition & 1 deletion Source/Game/Game/Scripting/LuaStateCtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ namespace Scripting
}
else if (any.type() == typeid(LuaTable))
{
auto& val = std::any_cast<const LuaTable>(any);
auto& val = std::any_cast<const LuaTable&>(any);
SetLuaTable(key.c_str(), val, recursiveCounter + 1);
}
else if (any.type() == typeid(LuaTable&))
Expand Down
2 changes: 1 addition & 1 deletion Source/ShaderCookerStandalone/ShaderCookerStandalone.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local dependencies = { "base", "shadercooker" }
local defines = { }
local defines = { "_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS", "_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS" }
ProjectTemplate("ShaderCookerStandalone", "ConsoleApp", ".", Game.binDir, dependencies, defines)

local dxCompilerLibPath = BuildSettings:Get("DXCompiler Dynamic Lib Path")
Expand Down
8 changes: 5 additions & 3 deletions Source/ShaderCookerStandalone/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ i32 main(int argc, char* argv[])
const bool debugSkipCache = false;
if (!debugSkipCache)
{
std::string shaderCachePathStr = shaderCachePath.string();

if (shaderCache.Load(shaderCachePath))
{
DebugHandler::Print("Loaded shadercache from: {0}", shaderCachePath.string().c_str());
DebugHandler::Print("Loaded shadercache from: {0}", shaderCachePathStr);
}
else
{
DebugHandler::Print("Creating shadercache at: {0}", shaderCachePath.string().c_str());
DebugHandler::Print("Creating shadercache at: {0}", shaderCachePathStr);
}
}
else
Expand Down Expand Up @@ -90,7 +92,7 @@ i32 main(int argc, char* argv[])
}
else
{
DebugHandler::PrintError("{0} shaders failed to compile.", numFailedShaders);
DebugHandler::PrintError("Failed to compile {0} shaders", numFailedShaders);
}

std::chrono::system_clock::time_point endTime = std::chrono::system_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion Source/Shaders/Shaders.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local dependencies = { }
local defines = { }
ProjectTemplate("Shaders", "Utility", nil, Game.binDir, dependencies, defines)
dependson ("ShaderCookerStandalone")
dependson { "ShaderCookerStandalone" }

local rootDir = path.getabsolute("Shaders/", Game.projectsDir)
local sourceDir = path.getabsolute("Shaders/", rootDir)
Expand Down
2 changes: 1 addition & 1 deletion Submodules/Engine

0 comments on commit ddc656c

Please sign in to comment.