Skip to content

Commit

Permalink
Tracy + Misc
Browse files Browse the repository at this point in the history
- Added Tracy.exe to Resources
- Build Game as a lib (use Game-App to launch the game)
- Fixed an issue where Edit and Continue flag was enabled (It is now disabled, thank you)
- Implemented a better (but temporary) queue system for dirty instances for the Animation System
- Fixed an issue in ModelRenderer where BoneMatrices and TextureTransformMatrices were not properly initialized to identity matrices
- Removed LoaderSystem (Manually calling ClientDBLoader and TextureLoader now)
  • Loading branch information
NixAJ committed Mar 28, 2024
1 parent 57cc8e1 commit e1cca69
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 343 deletions.
370 changes: 194 additions & 176 deletions Premake/ProjectUtil.lua

Large diffs are not rendered by default.

Binary file added Resources/Tracy.exe
Binary file not shown.
35 changes: 0 additions & 35 deletions Source/Game/CMakeLists.txt

This file was deleted.

42 changes: 29 additions & 13 deletions Source/Game/Game.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
local basePath = path.getabsolute("Game/", Game.projectsDir)

local dependencies = { "base", "fileformat", "input", "network", "renderer", "luau-compiler", "luau-vm", "jolt", "enkiTS", "refl-cpp", "utfcpp", "base64" }
local defines = { "_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS", "_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS", "WIN32_LEAN_AND_MEAN", "NOMINMAX" }
ProjectTemplate("Game", "ConsoleApp", ".", Game.binDir, dependencies, defines)

local shaderSourceDir = BuildSettings:Get("Shader Source Dir")
if shaderSourceDir == nil then
error("Failed to find Shader Source Dir, this setting is supposed to be set during the creation of the shaders project")
end

AddDefines("SHADER_SOURCE_DIR=\"" .. shaderSourceDir .. "\"")
local function SetupLib()
ProjectTemplate("Game", "StaticLib", nil, Game.binDir, dependencies, defines)

filter { 'system:Windows' }
files { 'appicon.rc', '**.ico' }
vpaths { ['Resources/*'] = { '*.rc', '**.ico' } }

local function Include()
local includeDir = path.getabsolute("Game/", Game.projectsDir)
local sourceDir = path.getabsolute("Game/", includeDir)
local sourceDir = path.getabsolute("Game", basePath)
local includeDir = { basePath }

local files =
{
(sourceDir .. "/**.h"),
(sourceDir .. "/**.hpp"),
(sourceDir .. "/**.cpp")
sourceDir .. "/**.h",
sourceDir .. "/**.hpp",
sourceDir .. "/**.c",
sourceDir .. "/**.cpp"
}

AddFiles(files)
AddIncludeDirs(includeDir)
AddDefines("SHADER_SOURCE_DIR=\"" .. shaderSourceDir .. "\"")
end
SetupLib()

local function Include()
local includeDir = path.getabsolute("Game/", Game.projectsDir)

AddIncludeDirs(includeDir)
AddDefines({"WIN32_LEAN_AND_MEAN", "NOMINMAX", ("SHADER_SOURCE_DIR=\"" .. shaderSourceDir .. "\"")})
AddLinks("Game")
end
CreateDep("game", Include, dependencies)
CreateDep("game", Include, dependencies)

ProjectTemplate("Game-App", "ConsoleApp", nil, Game.binDir, { "game" }, defines)

AddFiles({basePath .. "/main.cpp"})
vpaths { [""] = "**.cpp" }

filter { 'system:Windows' }
files { 'appicon.rc', '**.ico' }
vpaths { ['Resources/*'] = { '*.rc', '**.ico' } }
29 changes: 19 additions & 10 deletions Source/Game/Game/Animation/AnimationSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ namespace Animation
return -1;

i16 boneID = skeleton.keyBoneIDToBoneID.at(keyBone);
if (boneID >= numBones)
if (boneID >= static_cast<i16>(numBones))
return -1;

return boneID;
Expand Down Expand Up @@ -711,8 +711,13 @@ namespace Animation

if (hasRenderer && isInstanceDirty)
{
u32 dirtyIndex = _storage.dirtyInstancesIndex.fetch_add(1);
_storage.dirtyInstances[dirtyIndex] = instanceID;
_storage.dirtyInstancesMutex.lock();
if (!_storage.dirtyInstances.contains(instanceID))
{
_storage.dirtyInstances.insert(instanceID);
_storage.dirtyInstancesQueue.push(instanceID);
}
_storage.dirtyInstancesMutex.unlock();
}
}
});
Expand All @@ -725,12 +730,16 @@ namespace Animation
{
u32 throttle = CVAR_AnimationSystemThrottle.Get();

u32 numDirty = _storage.dirtyInstancesIndex.load();
u32 numDirty = static_cast<u32>(_storage.dirtyInstances.size());
u32 numInstancesToUpdate = glm::min(numDirty, throttle);
u32 numUpdatedInstances = 0;

for (u32 i = 0; i < numInstancesToUpdate; i++)
{
InstanceID instanceID = _storage.dirtyInstances[i];
if (numUpdatedInstances >= numInstancesToUpdate)
break;

InstanceID instanceID = _storage.dirtyInstancesQueue.front();
AnimationInstance& instance = _storage.instanceIDToData[instanceID];
const AnimationSkeleton& skeleton = _storage.skeletons[instance.modelID];

Expand All @@ -745,10 +754,11 @@ namespace Animation
{
_modelRenderer->SetTextureTransformMatricesAsDirty(instanceID, 0, numTextureTransforms, &_storage.textureTransformMatrices[instance.textureTransformMatrixOffset]);
}

_storage.dirtyInstancesQueue.pop();
_storage.dirtyInstances.erase(instanceID);
}
}

_storage.dirtyInstancesIndex.store(0);
}

void AnimationSystem::Reserve(u32 numSkeletons, u32 numInstances, u32 numBones, u32 numTextureTransforms)
Expand All @@ -765,7 +775,7 @@ namespace Animation
u32 currentNumInstances = static_cast<u32>(_storage.instanceIDs.size());
_storage.instanceIDs.resize(currentNumInstances + numInstances);
_storage.instanceIDToData.reserve(currentNumInstances + numInstances);
_storage.dirtyInstances.resize(currentNumInstances + numInstances);
_storage.dirtyInstances.reserve(currentNumInstances + numInstances);

u32 currentNumBones = static_cast<u32>(_storage.boneMatrices.size());
_storage.boneMatrices.resize(currentNumBones + numBones);
Expand Down Expand Up @@ -794,7 +804,7 @@ namespace Animation
u32 numInstances = _storage.instancesIndex.load();

_storage.instanceIDs.resize(numInstances);
_storage.dirtyInstances.resize(numInstances);
_storage.dirtyInstances.reserve(numInstances);
}
void AnimationSystem::Clear()
{
Expand All @@ -810,7 +820,6 @@ namespace Animation
_storage.instanceIDs.clear();
_storage.instanceIDToData.clear();

_storage.dirtyInstancesIndex.store(0);
_storage.dirtyInstances.clear();

_storage.boneMatrixIndex.store(0);
Expand Down
6 changes: 4 additions & 2 deletions Source/Game/Game/Animation/AnimationSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <enkiTS/TaskScheduler.h>

#include <limits>
#include <queue>

namespace Model
{
Expand Down Expand Up @@ -1546,8 +1547,9 @@ namespace Animation
std::vector<InstanceID> instanceIDs;
robin_hood::unordered_map<InstanceID, AnimationInstance> instanceIDToData;

std::atomic<u32> dirtyInstancesIndex;
std::vector<InstanceID> dirtyInstances;
std::mutex dirtyInstancesMutex;
std::queue<InstanceID> dirtyInstancesQueue;
robin_hood::unordered_set<InstanceID> dirtyInstances;

std::atomic<u32> boneMatrixIndex;
std::vector<mat4x4> boneMatrices;
Expand Down
21 changes: 5 additions & 16 deletions Source/Game/Game/Application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include "Game/Rendering/GameRenderer.h"
#include "Game/Scripting/LuaManager.h"
#include "Game/Util/ServiceLocator.h"
#include "Game/Loaders/LoaderSystem.h"
#include "Game/Loaders/ClientDB/ClientDBLoader.h"
#include "Game/Loaders/Texture/TextureLoader.h"
#include "Game/Scripting/LuaManager.h"
#include "Game/Scripting/Systems/LuaSystemBase.h"

Expand Down Expand Up @@ -237,28 +238,16 @@ bool Application::Init()
JPH::Factory::sInstance = new JPH::Factory();
JPH::RegisterTypes();

TextureLoader::Init();
ClientDBLoader::Init();

_gameRenderer = new GameRenderer(_inputManager);
_editorHandler = new Editor::EditorHandler();
ServiceLocator::SetEditorHandler(_editorHandler);

_ecsScheduler = new ECS::Scheduler();
_ecsScheduler->Init(*_registries.gameRegistry);

LoaderSystem* loaderSystem = LoaderSystem::Get();
loaderSystem->Init();

bool failedToLoad = false;
for (Loader* loader : loaderSystem->GetLoaders())
{
failedToLoad |= !loader->Init();

if (failedToLoad)
break;
}

if (failedToLoad)
return false;

ServiceLocator::SetGameConsole(new GameConsole());

_luaManager = new Scripting::LuaManager();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Game/Loaders/LoaderSystem.h"
#include "Game/Util/ServiceLocator.h"
#include "Game/ECS/Singletons/ClientDBCollection.h"
#pragma once
#include "Game/Application/EnttRegistries.h"
#include "Game/ECS/Singletons/ClientDBCollection.h"
#include "Game/Util/ServiceLocator.h"

#include <Base/Container/ConcurrentQueue.h>
#include <Base/Memory/FileReader.h>
Expand All @@ -13,7 +13,6 @@

#include <execution>
#include <filesystem>
#include <limits>

namespace fs = std::filesystem;
using namespace ECS::Singletons;
Expand All @@ -26,12 +25,12 @@ struct ClientDBPair
std::string path;
};

class ClientDBLoader : Loader
class ClientDBLoader
{
public:
ClientDBLoader() : Loader("ClientDBLoader", 9999) { }
ClientDBLoader() = delete;

bool Init()
static bool Init()
{
EnttRegistries* registries = ServiceLocator::GetEnttRegistries();

Expand Down Expand Up @@ -104,4 +103,4 @@ class ClientDBLoader : Loader

return true;
}
} clientDBLoader;
};
33 changes: 0 additions & 33 deletions Source/Game/Game/Loaders/LoaderSystem.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions Source/Game/Game/Loaders/LoaderSystem.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Game/Loaders/LoaderSystem.h"
#include "Game/Util/ServiceLocator.h"
#include "Game/ECS/Singletons/TextureSingleton.h"
#pragma once
#include "Game/Application/EnttRegistries.h"
#include "Game/ECS/Singletons/TextureSingleton.h"
#include "Game/Util/ServiceLocator.h"

#include <Base/Util/DebugHandler.h>
#include <Base/Container/ConcurrentQueue.h>
Expand All @@ -18,12 +18,12 @@ struct TexturePair
std::string path;
};

class TextureLoader : Loader
class TextureLoader
{
public:
TextureLoader() : Loader("TextureLoader", 10000) { }
TextureLoader() = delete;

bool Init()
static bool Init()
{
DebugHandler::Print("TextureLoader : Scanning for textures");

Expand Down Expand Up @@ -85,6 +85,4 @@ class TextureLoader : Loader

return true;
}
};

TextureLoader textureLoader;
};
Loading

0 comments on commit e1cca69

Please sign in to comment.