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,33 +60,35 @@ namespace Game
|
|||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
auto& inst = GetInstance();
|
|
||||||
int64_t newNowHP = bx::getHPCounter() - inst.Time.StartTime;
|
|
||||||
inst.Time.DeltaHP = newNowHP - inst.Time.NowHP;
|
|
||||||
inst.Time.NowHP = newNowHP;
|
|
||||||
inst.Time.Now = (double)inst.Time.NowHP / bx::getHPFrequency();
|
|
||||||
inst.Time.Delta = (double)inst.Time.DeltaHP / bx::getHPFrequency();
|
|
||||||
GetShared().Window.PerfCounters[(int32_t)PerfCounterType::GameDelta].Write(inst.Time.DeltaHP,
|
|
||||||
GetShared().Window.FrameCounter);
|
|
||||||
|
|
||||||
if (GetKeyPressedNow(ScanCode::R))
|
|
||||||
{
|
{
|
||||||
GetInstance().Size = 0;
|
ZoneScopedN("TimeUpdate");
|
||||||
Shutdown();
|
auto& inst = GetInstance();
|
||||||
Setup(GetShared());
|
int64_t newNowHP = bx::getHPCounter() - inst.Time.StartTime;
|
||||||
|
inst.Time.DeltaHP = newNowHP - inst.Time.NowHP;
|
||||||
|
inst.Time.NowHP = newNowHP;
|
||||||
|
inst.Time.Now = (double)inst.Time.NowHP / bx::getHPFrequency();
|
||||||
|
inst.Time.Delta = (double)inst.Time.DeltaHP / bx::getHPFrequency();
|
||||||
|
GetShared().Window.PerfCounters[(int32_t)PerfCounterType::GameDelta].Write(inst.Time.DeltaHP,
|
||||||
|
GetShared().Window.FrameCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupInstance.Rendering.Update();
|
SetupInstance.Rendering.Update();
|
||||||
|
|
||||||
auto& win = GetShared().Window;
|
{
|
||||||
win.MouseDeltaX = 0.0f;
|
ZoneScopedN("MouseDeltaUpdate");
|
||||||
win.MouseDeltaY = 0.0f;
|
auto& win = GetShared().Window;
|
||||||
bx::memCopy(win.LastHeldScanCodes, win.HeldScanCodes, sizeof(win.HeldScanCodes));
|
win.MouseDeltaX = 0.0f;
|
||||||
bx::memCopy(win.LastHeldMouseButtons, win.HeldMouseButtons, sizeof(win.HeldMouseButtons));
|
win.MouseDeltaY = 0.0f;
|
||||||
|
bx::memCopy(win.LastHeldScanCodes, win.HeldScanCodes, sizeof(win.HeldScanCodes));
|
||||||
|
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,218 +455,246 @@ namespace Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start Rendering
|
void GameRendering::RenderDebugUI()
|
||||||
imguiBeginFrame(20);
|
{
|
||||||
ImGui_ImplSDL3_NewFrame();
|
ZoneScopedN("DebugUI");
|
||||||
ImGui::DockSpaceOverViewport(0, 0, ImGuiDockNodeFlags_PassthruCentralNode);
|
|
||||||
|
|
||||||
auto& level = GetInstance().GameLevel;
|
auto& shared = GetShared();
|
||||||
auto& debug = GetInstance().DebugData;
|
auto& debug = GetInstance().DebugData;
|
||||||
if (UIVisible == UIVisibilityState::Debug)
|
auto& level = GetInstance().GameLevel;
|
||||||
|
|
||||||
|
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right))
|
||||||
{
|
{
|
||||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right))
|
debug.DebugCardRotation++;
|
||||||
|
if (debug.DebugCardRotation >= 4) debug.DebugCardRotation = 0;
|
||||||
|
}
|
||||||
|
if (ImGui::Begin("Rendering"))
|
||||||
|
{
|
||||||
|
if (LastShaderLoadTime >= 0.0f)
|
||||||
{
|
{
|
||||||
debug.DebugCardRotation++;
|
ImGui::TextColored({0.2f, 0.9f, 0.2f, 1.0f},
|
||||||
if (debug.DebugCardRotation >= 4) debug.DebugCardRotation = 0;
|
"Shader loaded %.0f seconds ago",
|
||||||
|
GetInstance().Time.Now - LastShaderLoadTime);
|
||||||
}
|
}
|
||||||
if (ImGui::Begin("Rendering"))
|
else
|
||||||
{
|
{
|
||||||
if (LastShaderLoadTime >= 0.0f)
|
ImGui::TextColored({0.9f, 0.2f, 0.2f, 1.0f}, "Shader load Failiure!");
|
||||||
{
|
|
||||||
ImGui::TextColored({0.2f, 0.9f, 0.2f, 1.0f},
|
|
||||||
"Shader loaded %.0f seconds ago",
|
|
||||||
GetInstance().Time.Now - LastShaderLoadTime);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImGui::TextColored({0.9f, 0.2f, 0.2f, 1.0f}, "Shader load Failiure!");
|
|
||||||
}
|
|
||||||
if (ImGui::Button("Reload Meshes"))
|
|
||||||
{
|
|
||||||
LoadModels(Models, ModelCount);
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
if (ImGui::Button("Reload Level"))
|
|
||||||
{
|
|
||||||
level = {};
|
|
||||||
level.Setup(shared.Game);
|
|
||||||
}
|
|
||||||
ImGui::Checkbox("Show ImGui Demo", &debug.ShowImguiDemo);
|
|
||||||
if (debug.ShowImguiDemo) ImGui::ShowDemoWindow(&debug.ShowImguiDemo);
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
ImGui::Checkbox("Cubes", &level.Cubes.IsEnabled);
|
|
||||||
ImGui::Checkbox("Tests", &level.Tests.IsEnabled);
|
|
||||||
ImGui::Checkbox("PuzzleTiles", &level.PuzzleTiles.IsEnabled);
|
|
||||||
ImGui::Checkbox("UIQuads", &level.UIQuads.IsEnabled);
|
|
||||||
|
|
||||||
if (ImGui::Button("Dithergen"))
|
|
||||||
{
|
|
||||||
DitherGen(DitherTextures, DitherRecursion);
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::SliderInt("Recursion", &DitherRecursion, 1, 4);
|
|
||||||
ImGui::Text(
|
|
||||||
"%ux%ux%u", DitherTextures.DitherTexWH, DitherTextures.DitherTexWH, DitherTextures.DitherTexDepth);
|
|
||||||
if (!isValid(DitherTextures.PreviewTex))
|
|
||||||
{
|
|
||||||
ImGui::Text("Invalid Texture");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImGui::Image(DitherTextures.PreviewTex.idx,
|
|
||||||
{(float)DitherTextures.DitherTexWH,
|
|
||||||
(float)DitherTextures.DitherTexWH * DitherTextures.DitherTexDepth});
|
|
||||||
}
|
|
||||||
if (isValid(DitherTextures.RampTex))
|
|
||||||
{
|
|
||||||
ImGui::Image(DitherTextures.RampTex.idx, {BX_COUNTOF(DitherTextures.BrightnessRamp), 8});
|
|
||||||
}
|
|
||||||
Vec3 quadPos = level.UIQuads.Get({0}).EData.Transform.GetPosition();
|
|
||||||
ImGui::Text("%f %f %f", quadPos.x, quadPos.y, quadPos.z);
|
|
||||||
|
|
||||||
if (ImGui::ColorEdit3("Base Color", &DefaultBaseColor.x))
|
|
||||||
{
|
|
||||||
auto& tiles = GetInstance().GameLevel.PuzzleTiles;
|
|
||||||
for (int32_t i = 0; i < tiles.Count; ++i)
|
|
||||||
{
|
|
||||||
tiles.Data[i].EData.BaseColor = DefaultBaseColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ImGui::ColorEdit3("Dot Color", &DefaultTileColor.x))
|
|
||||||
{
|
|
||||||
auto& tiles = GetInstance().GameLevel.PuzzleTiles;
|
|
||||||
for (int32_t i = 0; i < tiles.Count; ++i)
|
|
||||||
{
|
|
||||||
tiles.Data[i].EData.TestColor = DefaultTileColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::Text("Shader log:");
|
|
||||||
ImGui::TextWrapped("%s", GetShared().Dev.ShaderLog);
|
|
||||||
}
|
}
|
||||||
ImGui::End();
|
if (ImGui::Button("Reload Meshes"))
|
||||||
if (ImGui::Begin("Puzzles"))
|
|
||||||
{
|
{
|
||||||
if (ImGui::Button("Add"))
|
LoadModels(Models, ModelCount);
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Reload Level"))
|
||||||
|
{
|
||||||
|
level = {};
|
||||||
|
level.Setup(shared.Game);
|
||||||
|
}
|
||||||
|
ImGui::Checkbox("Show ImGui Demo", &debug.ShowImguiDemo);
|
||||||
|
if (debug.ShowImguiDemo) ImGui::ShowDemoWindow(&debug.ShowImguiDemo);
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
ImGui::Checkbox("Cubes", &level.Cubes.IsEnabled);
|
||||||
|
ImGui::Checkbox("Tests", &level.Tests.IsEnabled);
|
||||||
|
ImGui::Checkbox("PuzzleTiles", &level.PuzzleTiles.IsEnabled);
|
||||||
|
ImGui::Checkbox("UIQuads", &level.UIQuads.IsEnabled);
|
||||||
|
|
||||||
|
if (ImGui::Button("Dithergen"))
|
||||||
|
{
|
||||||
|
DitherGen(DitherTextures, DitherRecursion);
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SliderInt("Recursion", &DitherRecursion, 1, 4);
|
||||||
|
ImGui::Text(
|
||||||
|
"%ux%ux%u", DitherTextures.DitherTexWH, DitherTextures.DitherTexWH, DitherTextures.DitherTexDepth);
|
||||||
|
if (!isValid(DitherTextures.PreviewTex))
|
||||||
|
{
|
||||||
|
ImGui::Text("Invalid Texture");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImGui::Image(DitherTextures.PreviewTex.idx,
|
||||||
|
{(float)DitherTextures.DitherTexWH,
|
||||||
|
(float)DitherTextures.DitherTexWH * DitherTextures.DitherTexDepth});
|
||||||
|
}
|
||||||
|
if (isValid(DitherTextures.RampTex))
|
||||||
|
{
|
||||||
|
ImGui::Image(DitherTextures.RampTex.idx, {BX_COUNTOF(DitherTextures.BrightnessRamp), 8});
|
||||||
|
}
|
||||||
|
Vec3 quadPos = level.UIQuads.Get({0}).EData.Transform.GetPosition();
|
||||||
|
ImGui::Text("%f %f %f", quadPos.x, quadPos.y, quadPos.z);
|
||||||
|
|
||||||
|
if (ImGui::ColorEdit3("Base Color", &DefaultBaseColor.x))
|
||||||
|
{
|
||||||
|
auto& tiles = GetInstance().GameLevel.PuzzleTiles;
|
||||||
|
for (int32_t i = 0; i < tiles.Count; ++i)
|
||||||
{
|
{
|
||||||
bool found = false;
|
tiles.Data[i].EData.BaseColor = DefaultBaseColor;
|
||||||
for (int32_t i = 0; i < BX_COUNTOF(level.Puzzles); ++i)
|
|
||||||
{
|
|
||||||
auto& puz = level.Puzzles[i].Data;
|
|
||||||
if (puz.ID == UINT16_MAX)
|
|
||||||
{
|
|
||||||
bx::strCopy(puz.PuzzleName, sizeof(puz.PuzzleName), "Unnamed Puzzle");
|
|
||||||
puz.ID = i;
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found)
|
|
||||||
{
|
|
||||||
LOG_ERROR("Too many puzzles!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ImGui::Separator();
|
}
|
||||||
|
if (ImGui::ColorEdit3("Dot Color", &DefaultTileColor.x))
|
||||||
|
{
|
||||||
|
auto& tiles = GetInstance().GameLevel.PuzzleTiles;
|
||||||
|
for (int32_t i = 0; i < tiles.Count; ++i)
|
||||||
|
{
|
||||||
|
tiles.Data[i].EData.TestColor = DefaultTileColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Text("Shader log:");
|
||||||
|
ImGui::TextWrapped("%s", GetShared().Dev.ShaderLog);
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
if (ImGui::Begin("Puzzles"))
|
||||||
|
{
|
||||||
|
if (ImGui::Button("Add"))
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
for (int32_t i = 0; i < BX_COUNTOF(level.Puzzles); ++i)
|
for (int32_t i = 0; i < BX_COUNTOF(level.Puzzles); ++i)
|
||||||
{
|
{
|
||||||
auto& puzzleData = level.Puzzles[i].Data;
|
auto& puz = level.Puzzles[i].Data;
|
||||||
if (puzzleData.ID == UINT16_MAX) continue;
|
if (puz.ID == UINT16_MAX)
|
||||||
|
|
||||||
bool isSelected = debug.SelectedDebugLevel == i;
|
|
||||||
ImGui::PushID("selectable");
|
|
||||||
if (ImGui::Selectable(puzzleData.PuzzleName, isSelected))
|
|
||||||
{
|
{
|
||||||
debug.SelectedDebugLevel = isSelected ? UINT16_MAX : i;
|
bx::strCopy(puz.PuzzleName, sizeof(puz.PuzzleName), "Unnamed Puzzle");
|
||||||
|
puz.ID = i;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
}
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
LOG_ERROR("Too many puzzles!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::Separator();
|
||||||
if (debug.SelectedDebugLevel < BX_COUNTOF(level.Puzzles))
|
for (int32_t i = 0; i < BX_COUNTOF(level.Puzzles); ++i)
|
||||||
{
|
{
|
||||||
if (!Puzzle::RenderDebugUI(level.Puzzles[debug.SelectedDebugLevel].Data))
|
auto& puzzleData = level.Puzzles[i].Data;
|
||||||
|
if (puzzleData.ID == UINT16_MAX) continue;
|
||||||
|
|
||||||
|
bool isSelected = debug.SelectedDebugLevel == i;
|
||||||
|
ImGui::PushID("selectable");
|
||||||
|
if (ImGui::Selectable(puzzleData.PuzzleName, isSelected))
|
||||||
{
|
{
|
||||||
debug.SelectedDebugLevel = UINT16_MAX;
|
debug.SelectedDebugLevel = isSelected ? UINT16_MAX : i;
|
||||||
}
|
}
|
||||||
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
if (ImGui::Begin("Cards"))
|
}
|
||||||
|
ImGui::End();
|
||||||
|
if (debug.SelectedDebugLevel < BX_COUNTOF(level.Puzzles))
|
||||||
|
{
|
||||||
|
if (!Puzzle::RenderDebugUI(level.Puzzles[debug.SelectedDebugLevel].Data))
|
||||||
{
|
{
|
||||||
Generated::StaticPuzzleData& staticData = Puzzle::GetStaticPuzzleData();
|
debug.SelectedDebugLevel = UINT16_MAX;
|
||||||
if (ImGui::Button("Save"))
|
}
|
||||||
|
}
|
||||||
|
if (ImGui::Begin("Cards"))
|
||||||
|
{
|
||||||
|
Generated::StaticPuzzleData& staticData = Puzzle::GetStaticPuzzleData();
|
||||||
|
if (ImGui::Button("Save"))
|
||||||
|
{
|
||||||
|
Puzzle::SaveStaticPuzzleData();
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Reload"))
|
||||||
|
{
|
||||||
|
Puzzle::LoadStaticPuzzleData();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < BX_COUNTOF(staticData.Cards); ++i)
|
||||||
|
{
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
Generated::StaticPuzzleCard& card = staticData.Cards[i];
|
||||||
|
ImGui::PushID(i);
|
||||||
|
char cardName[64]{0};
|
||||||
|
bx::snprintf(cardName, sizeof(cardName), "%i", i);
|
||||||
|
ImGui::Selectable(cardName);
|
||||||
|
if (ImGui::BeginDragDropSource())
|
||||||
{
|
{
|
||||||
Puzzle::SaveStaticPuzzleData();
|
Puzzle::DrawCard(card, debug.DebugCardRotation, ImGui::GetCursorScreenPos());
|
||||||
}
|
ImGui::SetDragDropPayload("cardtype", &i, sizeof(i));
|
||||||
ImGui::SameLine();
|
ImGui::EndDragDropSource();
|
||||||
if (ImGui::Button("Reload"))
|
|
||||||
{
|
|
||||||
Puzzle::LoadStaticPuzzleData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < BX_COUNTOF(staticData.Cards); ++i)
|
Tools::ModelDropdown(card.ModelHandle);
|
||||||
|
for (int8_t y = 0; y < Puzzle::Config::CardSize; ++y)
|
||||||
{
|
{
|
||||||
ImGui::Separator();
|
ImGui::PushID(y);
|
||||||
|
for (int8_t x = 0; x < Puzzle::Config::CardSize; ++x)
|
||||||
Generated::StaticPuzzleCard& card = staticData.Cards[i];
|
|
||||||
ImGui::PushID(i);
|
|
||||||
char cardName[64]{0};
|
|
||||||
bx::snprintf(cardName, sizeof(cardName), "%i", i);
|
|
||||||
ImGui::Selectable(cardName);
|
|
||||||
if (ImGui::BeginDragDropSource())
|
|
||||||
{
|
{
|
||||||
Puzzle::DrawCard(card, debug.DebugCardRotation, ImGui::GetCursorScreenPos());
|
if (x > 0) ImGui::SameLine();
|
||||||
ImGui::SetDragDropPayload("cardtype", &i, sizeof(i));
|
ImGui::PushID(x);
|
||||||
ImGui::EndDragDropSource();
|
auto& node = Puzzle::EditCardNodeAt(card, 0, x, y);
|
||||||
}
|
if (ImGui::Button(Generated::PuzzleElementType::ShortName[node], {26, 24}))
|
||||||
|
|
||||||
Tools::ModelDropdown(card.ModelHandle);
|
|
||||||
for (int8_t y = 0; y < Puzzle::Config::CardSize; ++y)
|
|
||||||
{
|
|
||||||
ImGui::PushID(y);
|
|
||||||
for (int8_t x = 0; x < Puzzle::Config::CardSize; ++x)
|
|
||||||
{
|
{
|
||||||
if (x > 0) ImGui::SameLine();
|
int32_t newVal = int32_t(node) + 1;
|
||||||
ImGui::PushID(x);
|
if (newVal >= Generated::PuzzleElementType::EntryCount)
|
||||||
auto& node = Puzzle::EditCardNodeAt(card, 0, x, y);
|
|
||||||
if (ImGui::Button(Generated::PuzzleElementType::ShortName[node], {26, 24}))
|
|
||||||
{
|
{
|
||||||
int32_t newVal = int32_t(node) + 1;
|
newVal = 0;
|
||||||
if (newVal >= Generated::PuzzleElementType::EntryCount)
|
|
||||||
{
|
|
||||||
newVal = 0;
|
|
||||||
}
|
|
||||||
node = Generated::PuzzleElementType::Enum(newVal);
|
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
node = Generated::PuzzleElementType::Enum(newVal);
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
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
|
||||||
imguiEndFrame();
|
{
|
||||||
|
ZoneScopedN("Imgui End Frame");
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
START_PERF();
|
{
|
||||||
bgfx::frame();
|
ZoneScopedN("BGFX Frame");
|
||||||
END_PERF(shared.Window.PerfCounters, PerfCounterType::Submit, shared.Window.FrameCounter);
|
START_PERF();
|
||||||
|
bgfx::frame();
|
||||||
|
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