tracing
This commit is contained in:
@@ -12,6 +12,7 @@ endif()
|
|||||||
# This makes sure that the dynamic library goes into the build directory automatically.
|
# This makes sure that the dynamic library goes into the build directory automatically.
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
|
||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
|
||||||
|
set(PROFILE ON)
|
||||||
|
|
||||||
# Imgui
|
# Imgui
|
||||||
file(GLOB imgui_sources dependency/imgui/*.h dependency/imgui/*.cpp)
|
file(GLOB imgui_sources dependency/imgui/*.h dependency/imgui/*.cpp)
|
||||||
@@ -25,7 +26,7 @@ add_subdirectory("${CMAKE_SOURCE_DIR}/dependency/minidef")
|
|||||||
file(GLOB_RECURSE sources_engine engine/*.cpp engine/*.h)
|
file(GLOB_RECURSE sources_engine engine/*.cpp engine/*.h)
|
||||||
add_executable(PuzGameEngine ${sources_engine})
|
add_executable(PuzGameEngine ${sources_engine})
|
||||||
set_property(TARGET PuzGameEngine PROPERTY CXX_STANDARD 17)
|
set_property(TARGET PuzGameEngine PROPERTY CXX_STANDARD 17)
|
||||||
target_include_directories(PuzGameEngine PUBLIC)
|
target_include_directories(PuzGameEngine PUBLIC dependency/tracy/public/)
|
||||||
|
|
||||||
# Game
|
# Game
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
@@ -41,6 +42,15 @@ add_library(PuzGame SHARED ${sources_game} ${source_singleheader} ${imgui_source
|
|||||||
set_property(TARGET PuzGame PROPERTY CXX_STANDARD 17)
|
set_property(TARGET PuzGame PROPERTY CXX_STANDARD 17)
|
||||||
target_include_directories(PuzGame PUBLIC dependency/imgui)
|
target_include_directories(PuzGame PUBLIC dependency/imgui)
|
||||||
|
|
||||||
|
# Profiling
|
||||||
|
if (PROFILE)
|
||||||
|
option(TRACY_ENABLE "" ON)
|
||||||
|
option(TRACY_ON_DEMAND "" ON)
|
||||||
|
set(TRACY_DELAYED_INIT ON)
|
||||||
|
set(TRACY_MANUAL_LIFETIME ON)
|
||||||
|
add_subdirectory("${CMAKE_SOURCE_DIR}/dependency/tracy")
|
||||||
|
endif()
|
||||||
|
|
||||||
# SDL
|
# SDL
|
||||||
add_subdirectory("${CMAKE_SOURCE_DIR}/dependency/SDL" EXCLUDE_FROM_ALL)
|
add_subdirectory("${CMAKE_SOURCE_DIR}/dependency/SDL" EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
@@ -50,6 +60,6 @@ SET(BGFX_BUILD_EXAMPLES OFF)
|
|||||||
add_subdirectory("${CMAKE_SOURCE_DIR}/dependency/bgfx.cmake")
|
add_subdirectory("${CMAKE_SOURCE_DIR}/dependency/bgfx.cmake")
|
||||||
|
|
||||||
# Link
|
# Link
|
||||||
target_link_libraries(PuzGame bx bimg bgfx SDL3::SDL3)
|
target_link_libraries(PuzGame bx bimg bgfx SDL3::SDL3 Tracy::TracyClient)
|
||||||
target_link_libraries(PuzGameEngine bx SDL3::SDL3)
|
target_link_libraries(PuzGameEngine bx SDL3::SDL3 Tracy::TracyClient)
|
||||||
set_target_properties(PuzGame PROPERTIES OUTPUT_NAME "PuzGame2")
|
set_target_properties(PuzGame PROPERTIES OUTPUT_NAME "PuzGame2")
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <bx/math.h>
|
#include <bx/math.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <tracy/tracy.hpp>
|
||||||
|
|
||||||
namespace Game
|
namespace Game
|
||||||
{
|
{
|
||||||
@@ -160,6 +161,7 @@ namespace Game
|
|||||||
|
|
||||||
void Level::Update()
|
void Level::Update()
|
||||||
{
|
{
|
||||||
|
ZoneScopedN("Level update");
|
||||||
START_PERF();
|
START_PERF();
|
||||||
PlayerData& player = GetInstance().Player;
|
PlayerData& player = GetInstance().Player;
|
||||||
|
|
||||||
@@ -237,6 +239,7 @@ namespace Game
|
|||||||
|
|
||||||
void Level::Render(uint16_t viewId, const Model* models, const Material* materials)
|
void Level::Render(uint16_t viewId, const Model* models, const Material* materials)
|
||||||
{
|
{
|
||||||
|
ZoneScopedN("Level Render");
|
||||||
auto& shared = GetShared();
|
auto& shared = GetShared();
|
||||||
|
|
||||||
float proj[16];
|
float proj[16];
|
||||||
|
|||||||
@@ -3,9 +3,12 @@
|
|||||||
#include "Instance.h"
|
#include "Instance.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Setup.h"
|
#include "Setup.h"
|
||||||
|
#include "rendering/Rendering.h"
|
||||||
|
|
||||||
#include "bx/bx.h"
|
#include "bx/bx.h"
|
||||||
#include "bx/timer.h"
|
#include "bx/timer.h"
|
||||||
#include "rendering/Rendering.h"
|
#include <client/TracyProfiler.hpp>
|
||||||
|
#include <tracy/tracy.hpp>
|
||||||
|
|
||||||
namespace Game
|
namespace Game
|
||||||
{
|
{
|
||||||
@@ -23,6 +26,7 @@ namespace Game
|
|||||||
void Setup(SharedData& shared)
|
void Setup(SharedData& shared)
|
||||||
{
|
{
|
||||||
LOG("Game Setup Start!");
|
LOG("Game Setup Start!");
|
||||||
|
tracy::StartupProfiler();
|
||||||
|
|
||||||
if (shared.Game.PermanentStorage == nullptr)
|
if (shared.Game.PermanentStorage == nullptr)
|
||||||
{
|
{
|
||||||
@@ -56,6 +60,8 @@ namespace Game
|
|||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
ZoneScopedN("TimeUpdate");
|
||||||
auto& inst = GetInstance();
|
auto& inst = GetInstance();
|
||||||
int64_t newNowHP = bx::getHPCounter() - inst.Time.StartTime;
|
int64_t newNowHP = bx::getHPCounter() - inst.Time.StartTime;
|
||||||
inst.Time.DeltaHP = newNowHP - inst.Time.NowHP;
|
inst.Time.DeltaHP = newNowHP - inst.Time.NowHP;
|
||||||
@@ -64,25 +70,25 @@ namespace Game
|
|||||||
inst.Time.Delta = (double)inst.Time.DeltaHP / bx::getHPFrequency();
|
inst.Time.Delta = (double)inst.Time.DeltaHP / bx::getHPFrequency();
|
||||||
GetShared().Window.PerfCounters[(int32_t)PerfCounterType::GameDelta].Write(inst.Time.DeltaHP,
|
GetShared().Window.PerfCounters[(int32_t)PerfCounterType::GameDelta].Write(inst.Time.DeltaHP,
|
||||||
GetShared().Window.FrameCounter);
|
GetShared().Window.FrameCounter);
|
||||||
|
|
||||||
if (GetKeyPressedNow(ScanCode::R))
|
|
||||||
{
|
|
||||||
GetInstance().Size = 0;
|
|
||||||
Shutdown();
|
|
||||||
Setup(GetShared());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupInstance.Rendering.Update();
|
SetupInstance.Rendering.Update();
|
||||||
|
|
||||||
|
{
|
||||||
|
ZoneScopedN("MouseDeltaUpdate");
|
||||||
auto& win = GetShared().Window;
|
auto& win = GetShared().Window;
|
||||||
win.MouseDeltaX = 0.0f;
|
win.MouseDeltaX = 0.0f;
|
||||||
win.MouseDeltaY = 0.0f;
|
win.MouseDeltaY = 0.0f;
|
||||||
bx::memCopy(win.LastHeldScanCodes, win.HeldScanCodes, sizeof(win.HeldScanCodes));
|
bx::memCopy(win.LastHeldScanCodes, win.HeldScanCodes, sizeof(win.HeldScanCodes));
|
||||||
bx::memCopy(win.LastHeldMouseButtons, win.HeldMouseButtons, sizeof(win.HeldMouseButtons));
|
bx::memCopy(win.LastHeldMouseButtons, win.HeldMouseButtons, sizeof(win.HeldMouseButtons));
|
||||||
}
|
}
|
||||||
|
FrameMark;
|
||||||
|
}
|
||||||
|
|
||||||
void Shutdown()
|
void Shutdown()
|
||||||
{
|
{
|
||||||
LOG("Shutdown");
|
LOG("Shutdown");
|
||||||
SetupInstance.Rendering.Shutdown();
|
SetupInstance.Rendering.Shutdown();
|
||||||
|
tracy::ShutdownProfiler();
|
||||||
}
|
}
|
||||||
} // namespace Game
|
} // namespace Game
|
||||||
|
|||||||
@@ -21,11 +21,11 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <tracy/Tracy.hpp>
|
||||||
|
|
||||||
#include "imgui-helper.h"
|
#include "imgui-helper.h"
|
||||||
#include "imgui-style.h"
|
#include "imgui-style.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_internal.h"
|
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
@@ -333,6 +333,8 @@ namespace Game
|
|||||||
void GameRendering::Setup()
|
void GameRendering::Setup()
|
||||||
{
|
{
|
||||||
LOG("--- RENDERING STARTUP ---");
|
LOG("--- RENDERING STARTUP ---");
|
||||||
|
ZoneScopedN("Setup");
|
||||||
|
|
||||||
if (Instance != nullptr) LOG_WARN("old rendering wasn't destroyed!");
|
if (Instance != nullptr) LOG_WARN("old rendering wasn't destroyed!");
|
||||||
Instance = this;
|
Instance = this;
|
||||||
SharedData& shared = GetShared();
|
SharedData& shared = GetShared();
|
||||||
@@ -407,11 +409,11 @@ namespace Game
|
|||||||
DitherGen(DitherTextures, DitherRecursion);
|
DitherGen(DitherTextures, DitherRecursion);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameRendering::Update()
|
void GameRendering::HandleEvents()
|
||||||
{
|
{
|
||||||
|
ZoneScopedN("Handle Events");
|
||||||
SharedData& shared = GetShared();
|
SharedData& shared = GetShared();
|
||||||
|
|
||||||
// Handle events
|
|
||||||
for (uint16_t i = 0; i < shared.Window.SDLEventCount; ++i)
|
for (uint16_t i = 0; i < shared.Window.SDLEventCount; ++i)
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL3_ProcessEvent(&shared.Window.SDLEvents[i]);
|
ImGui_ImplSDL3_ProcessEvent(&shared.Window.SDLEvents[i]);
|
||||||
@@ -453,16 +455,16 @@ namespace Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start Rendering
|
void GameRendering::RenderDebugUI()
|
||||||
imguiBeginFrame(20);
|
|
||||||
ImGui_ImplSDL3_NewFrame();
|
|
||||||
ImGui::DockSpaceOverViewport(0, 0, ImGuiDockNodeFlags_PassthruCentralNode);
|
|
||||||
|
|
||||||
auto& level = GetInstance().GameLevel;
|
|
||||||
auto& debug = GetInstance().DebugData;
|
|
||||||
if (UIVisible == UIVisibilityState::Debug)
|
|
||||||
{
|
{
|
||||||
|
ZoneScopedN("DebugUI");
|
||||||
|
|
||||||
|
auto& shared = GetShared();
|
||||||
|
auto& debug = GetInstance().DebugData;
|
||||||
|
auto& level = GetInstance().GameLevel;
|
||||||
|
|
||||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right))
|
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right))
|
||||||
{
|
{
|
||||||
debug.DebugCardRotation++;
|
debug.DebugCardRotation++;
|
||||||
@@ -646,25 +648,53 @@ namespace Game
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameRendering::Update()
|
||||||
|
{
|
||||||
|
ZoneScopedN("Rendering");
|
||||||
|
SharedData& shared = GetShared();
|
||||||
|
|
||||||
|
HandleEvents();
|
||||||
|
|
||||||
|
// Start Rendering
|
||||||
|
{
|
||||||
|
ZoneScopedN("Imgui Start Frame");
|
||||||
|
imguiBeginFrame(20);
|
||||||
|
ImGui_ImplSDL3_NewFrame();
|
||||||
|
ImGui::DockSpaceOverViewport(0, 0, ImGuiDockNodeFlags_PassthruCentralNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (UIVisible == UIVisibilityState::Debug)
|
||||||
|
{
|
||||||
|
RenderDebugUI();
|
||||||
|
}
|
||||||
|
|
||||||
GetInstance().GameLevel.Update();
|
GetInstance().GameLevel.Update();
|
||||||
GetInstance().GameLevel.Render(MainViewID, Models, Materials);
|
GetInstance().GameLevel.Render(MainViewID, Models, Materials);
|
||||||
|
|
||||||
// Finish Frame
|
// Finish Frame
|
||||||
|
{
|
||||||
|
ZoneScopedN("Imgui End Frame");
|
||||||
imguiEndFrame();
|
imguiEndFrame();
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
|
ZoneScopedN("Imgui Platform Update");
|
||||||
ImGui::UpdatePlatformWindows();
|
ImGui::UpdatePlatformWindows();
|
||||||
ImGui::RenderPlatformWindowsDefault();
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ZoneScopedN("BGFX Frame");
|
||||||
START_PERF();
|
START_PERF();
|
||||||
bgfx::frame();
|
bgfx::frame();
|
||||||
END_PERF(shared.Window.PerfCounters, PerfCounterType::Submit, shared.Window.FrameCounter);
|
END_PERF(shared.Window.PerfCounters, PerfCounterType::Submit, shared.Window.FrameCounter);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GameRendering::Shutdown()
|
void GameRendering::Shutdown()
|
||||||
{
|
{
|
||||||
|
ZoneScopedN("Shutdown");
|
||||||
LOG("--- RENDERING_SHUTDOWN ---");
|
LOG("--- RENDERING_SHUTDOWN ---");
|
||||||
ImGui::SaveIniSettingsToDisk("imgui.ini");
|
ImGui::SaveIniSettingsToDisk("imgui.ini");
|
||||||
auto& debug = GetInstance().DebugData;
|
auto& debug = GetInstance().DebugData;
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ namespace Game
|
|||||||
Model Models[MaxModels];
|
Model Models[MaxModels];
|
||||||
int32_t LastWidth = 0;
|
int32_t LastWidth = 0;
|
||||||
int32_t LastHeight = 0;
|
int32_t LastHeight = 0;
|
||||||
uint32_t ResetFlags = BGFX_RESET_VSYNC;
|
uint32_t ResetFlags = 0; // BGFX_RESET_VSYNC;
|
||||||
uint16_t MainViewID = 10;
|
uint16_t MainViewID = 10;
|
||||||
float LastShaderLoadTime = 0.0f;
|
float LastShaderLoadTime = 0.0f;
|
||||||
int32_t DitherRecursion = 1;
|
int32_t DitherRecursion = 1;
|
||||||
@@ -115,6 +115,8 @@ namespace Game
|
|||||||
public:
|
public:
|
||||||
void Setup();
|
void Setup();
|
||||||
void Update();
|
void Update();
|
||||||
|
void HandleEvents();
|
||||||
|
void RenderDebugUI();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
uint16_t GetModelHandleFromPath(const char* path);
|
uint16_t GetModelHandleFromPath(const char* path);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user