Removing debug code (put in #if 0 for now)

Added a very simple camera system.
This commit is contained in:
2026-08-05 19:12:34 -04:00
parent f122533f92
commit 6c7b7c0124
9 changed files with 104 additions and 5 deletions
+4
View File
@@ -11,6 +11,7 @@
#include <Core/Memory/MemoryArena.h>
#include <Entity/Entity.h>
#include <Entity/EntityManager.h>
#include <Graphics/Camera.h>
GameState* gGameState = nullptr;
GameState* GetGameState()
@@ -64,6 +65,9 @@ extern "C" JULIET_API void __cdecl GameUpdate(Juliet::GameData* params, [[maybe_
printf("Game Arena Allocated: %p\n", static_cast<void*>(gameState));
// Reserve cameras. Lets go with 4 for now
ReserveCamera(4);
// Bootstrap world
auto* worldArena = ArenaAllocate({ .ReserveSize = Megabytes(1) } JULIET_DEBUG_PARAM("World Arena"));
World* world = ArenaPushStruct<World>(worldArena JULIET_DEBUG_PARAM("World"));
+1
View File
@@ -123,6 +123,7 @@
<ClCompile Include="src\Core\PCH.cpp" />
<ClCompile Include="src\Engine\Debug\MemoryDebugger.cpp" />
<ClCompile Include="src\Engine\Engine.cpp" />
<ClCompile Include="src\Graphics\Camera.cpp" />
<ClCompile Include="src\Graphics\D3D12\AgilitySDK\d3dx12\d3dx12_property_format_table.cpp" />
<ClCompile Include="src\Graphics\D3D12\D3D12Buffer.cpp" />
<ClCompile Include="src\Graphics\D3D12\D3D12CommandList.cpp" />
@@ -29,6 +29,5 @@ namespace Juliet
virtual void OnRender(RenderPass* pass, CommandList* cmd) = 0;
virtual ColorTargetInfo GetColorTargetInfo(Texture* swapchainTexture) = 0;
virtual DepthStencilTargetInfo* GetDepthTargetInfo() = 0;
virtual struct Camera GetDebugCamera() = 0;
};
} // namespace Juliet
+2
View File
@@ -19,4 +19,6 @@ namespace Juliet
void UnloadApplication();
void RunEngine();
extern Arena* GetPlatformArena();
} // namespace Juliet
+7
View File
@@ -7,6 +7,7 @@ namespace Juliet
{
struct Camera
{
index_t Index;
Vector3 Position;
Vector3 Target;
Vector3 Up;
@@ -30,4 +31,10 @@ namespace Juliet
{
return Camera_GetProjectionMatrix(cam) * Camera_GetViewMatrix(cam);
}
JULIET_API extern void ReserveCamera(size_t amount);
extern Camera* GetCurrentCamera();
extern void SetCurrentCamera(index_t index);
extern index_t AddCamera();
extern void RemoveCamera(index_t index);
} // namespace Juliet
+7 -1
View File
@@ -134,7 +134,7 @@ namespace Juliet
EngineInstance.Application->OnRender(pass, cmdList);
// Debug display flush (inside render pass)
Camera debugCamera = EngineInstance.Application->GetDebugCamera();
Camera debugCamera = *GetCurrentCamera();
DebugDisplay_Flush(cmdList, pass, debugCamera);
// Note: The MeshRenderer and SkyboxRenderer draw calls are still inside Application->OnRender
@@ -217,4 +217,10 @@ namespace Juliet
RenderFrame();
}
}
Arena* GetPlatformArena()
{
NonNullPtr arena = EngineInstance.PlatformArena;
return arena.Get();
}
} // namespace Juliet
+59
View File
@@ -0,0 +1,59 @@
#pragma once
#include <Graphics/Camera.h>
#include <Core/Common/CoreUtils.h>
#include <Core/Common/NonNullPtr.h>
#include <Core/Memory/MemoryArena.h>
#include <Engine/Engine.h>
namespace Juliet
{
namespace
{
size_t CameraAmount = 0;
Camera* CameraArray = nullptr;
Camera* CurrentCamera = nullptr;
} // namespace
void ReserveCamera(size_t amount)
{
Assert(CameraAmount == 0);
Assert(amount > 0);
CameraAmount = amount;
CameraArray = ArenaPushArray<Camera>(GetPlatformArena(), CameraAmount JULIET_DEBUG_PARAM("Camera Array"));
for (index_t index = 0; index < CameraAmount; ++index)
{
Camera* cam = CameraArray + index;
cam->Index = index;
}
CurrentCamera = &CameraArray[0];
}
Camera* GetCurrentCamera()
{
if (CameraAmount == 0)
{
ReserveCamera(1);
}
NonNullPtr cam = CurrentCamera;
return cam.Get();
}
void SetCurrentCamera(index_t index)
{
if (CameraAmount == 0)
{
ReserveCamera(1);
}
Assert(index <= CameraAmount);
CurrentCamera = CameraArray + index;
}
} // namespace Juliet
+21 -3
View File
@@ -44,6 +44,8 @@
#endif
static bool ShowMemoryDebugger = false;
#if 0
static bool animateCubes = true;
static bool animateLights = true;
static bool animateCamera = true;
@@ -70,6 +72,7 @@ static float globalAmbientIntensity = 0.2f;
static float blueLightRadius = 15.0f;
static float blueLightIntensity = 8.0f;
static float blueLightColor[3] = { 0.2f, 0.2f, 1.0f };
#endif
// TODO : Replace with message box from framework + call main and not winmain + subsystem
// TODO : Think how to do the draw pipeline.
@@ -96,8 +99,11 @@ namespace
const char* GameFunctionTable[] = { "GameShutdown", "GameUpdate" };
#if 0
LightID RedLightID = 0;
LightID BlueLightID = 0;
#endif
} // namespace
void JulietApplication::Init(NonNullPtr<Arena>)
@@ -137,6 +143,7 @@ void JulietApplication::Init(NonNullPtr<Arena>)
Running = false;
}
#if 0
constexpr int kGridSize = 10;
constexpr float kSpacing = 2.5f;
constexpr float kOffset = (kGridSize - 1) * kSpacing * 0.5f;
@@ -169,6 +176,7 @@ void JulietApplication::Init(NonNullPtr<Arena>)
blueLight.Color = { blueLightColor[0], blueLightColor[1], blueLightColor[2] };
blueLight.Intensity = blueLightIntensity;
BlueLightID = AddPointLight(blueLight);
#endif
}
GameCode.Functions = reinterpret_cast<void**>(&Game);
@@ -251,7 +259,10 @@ void JulietApplication::Update()
bool reloadShaders = false;
static bool reloadShadersDebounce = false;
#if 0
static bool f1Debounce = false;
#endif
SystemEvent evt;
while (GetEvent(evt))
@@ -277,6 +288,7 @@ void JulietApplication::Update()
}
}
#if 0
static bool firstFreeFrame = false;
if (IsKeyDown(ScanCode::F1))
@@ -478,13 +490,14 @@ void JulietApplication::Update()
SetMeshTransform(cube, MatrixTranslation(x, y, z) * rotation * scale);
}
}
DebugDisplay_DrawSphere(blueLightPos, 0.5f, { 0.0f, 0.0f, 1.0f, 1.0f }, true);
DebugDisplay_DrawSphere(redLightPos, 0.5f, { 1.0f, 0.0f, 0.0f, 1.0f }, true);
#endif
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f }, false);
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, true);
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f }, true);
DebugDisplay_DrawSphere({ 0.0f, 0.0f, 0.0f }, 0.5f, { 1.0f, 1.0f, 0.0f, 1.0f }, true);
DebugDisplay_DrawSphere(blueLightPos, 0.5f, { 0.0f, 0.0f, 1.0f, 1.0f }, true);
DebugDisplay_DrawSphere(redLightPos, 0.5f, { 1.0f, 0.0f, 0.0f, 1.0f }, true);
Game.Update(&Data, 0.0f);
@@ -540,9 +553,11 @@ void JulietApplication::OnPreRender(CommandList* /*cmd*/) {}
void JulietApplication::OnRender(RenderPass* pass, CommandList* cmd)
{
Camera cam = {};
PushData pushData = {};
pushData.ViewProjection = Camera_GetViewProjectionMatrix(GetDebugCamera());
pushData.ViewProjection = Camera_GetViewProjectionMatrix(cam);
#if 0
if (enableGlobalLight)
{
pushData.GlobalLightDirection = Normalize({ globalLightDir[0], globalLightDir[1], globalLightDir[2] });
@@ -550,6 +565,7 @@ void JulietApplication::OnRender(RenderPass* pass, CommandList* cmd)
pushData.GlobalAmbientIntensity = globalAmbientIntensity;
}
else
#endif
{
pushData.GlobalLightDirection = { 0.0f, -1.0f, 0.0f };
pushData.GlobalLightColor = { 0.0f, 0.0f, 0.0f };
@@ -580,6 +596,7 @@ DepthStencilTargetInfo* JulietApplication::GetDepthTargetInfo()
return &info;
}
#if 0
Camera JulietApplication::GetDebugCamera()
{
if (freeCameraMode)
@@ -636,6 +653,7 @@ Camera JulietApplication::GetDebugCamera()
return cam;
}
#endif
bool JulietApplication::IsRunning()
{
+3
View File
@@ -31,7 +31,10 @@ class JulietApplication : public Juliet::IApplication
void OnRender(Juliet::RenderPass* pass, Juliet::CommandList* cmd) override;
Juliet::ColorTargetInfo GetColorTargetInfo(Juliet::Texture* swapchainTexture) override;
Juliet::DepthStencilTargetInfo* GetDepthTargetInfo() override;
#if 0
Juliet::Camera GetDebugCamera() override;
#endif
public:
void SetAutoCloseFrameCount(int count) { AutoCloseFrameCount = count; }