From 6c7b7c01249b9a9d74bd5ee630b6c77a5a03216c Mon Sep 17 00:00:00 2001 From: Patedam Date: Wed, 5 Aug 2026 19:12:34 -0400 Subject: [PATCH] Removing debug code (put in #if 0 for now) Added a very simple camera system. --- Game/game.cpp | 4 ++ Juliet/Juliet.vcxproj | 1 + .../include/Core/Application/IApplication.h | 1 - Juliet/include/Engine/Engine.h | 2 + Juliet/include/Graphics/Camera.h | 7 +++ Juliet/src/Engine/Engine.cpp | 8 ++- Juliet/src/Graphics/Camera.cpp | 59 +++++++++++++++++++ JulietApp/main.cpp | 24 +++++++- JulietApp/main.h | 3 + 9 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 Juliet/src/Graphics/Camera.cpp diff --git a/Game/game.cpp b/Game/game.cpp index f8c6210..f6940bc 100644 --- a/Game/game.cpp +++ b/Game/game.cpp @@ -11,6 +11,7 @@ #include #include #include +#include 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(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(worldArena JULIET_DEBUG_PARAM("World")); diff --git a/Juliet/Juliet.vcxproj b/Juliet/Juliet.vcxproj index 46d6974..0175a56 100644 --- a/Juliet/Juliet.vcxproj +++ b/Juliet/Juliet.vcxproj @@ -123,6 +123,7 @@ + diff --git a/Juliet/include/Core/Application/IApplication.h b/Juliet/include/Core/Application/IApplication.h index 1101bb7..7a21e36 100644 --- a/Juliet/include/Core/Application/IApplication.h +++ b/Juliet/include/Core/Application/IApplication.h @@ -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 diff --git a/Juliet/include/Engine/Engine.h b/Juliet/include/Engine/Engine.h index 466fa4d..8e3f337 100644 --- a/Juliet/include/Engine/Engine.h +++ b/Juliet/include/Engine/Engine.h @@ -19,4 +19,6 @@ namespace Juliet void UnloadApplication(); void RunEngine(); + + extern Arena* GetPlatformArena(); } // namespace Juliet diff --git a/Juliet/include/Graphics/Camera.h b/Juliet/include/Graphics/Camera.h index 2a8e4d1..eacf0ed 100644 --- a/Juliet/include/Graphics/Camera.h +++ b/Juliet/include/Graphics/Camera.h @@ -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 diff --git a/Juliet/src/Engine/Engine.cpp b/Juliet/src/Engine/Engine.cpp index 32ac523..7c51854 100644 --- a/Juliet/src/Engine/Engine.cpp +++ b/Juliet/src/Engine/Engine.cpp @@ -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 diff --git a/Juliet/src/Graphics/Camera.cpp b/Juliet/src/Graphics/Camera.cpp new file mode 100644 index 0000000..f75cff3 --- /dev/null +++ b/Juliet/src/Graphics/Camera.cpp @@ -0,0 +1,59 @@ +#pragma once + +#include + +#include +#include +#include +#include + +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(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 diff --git a/JulietApp/main.cpp b/JulietApp/main.cpp index 018f3c8..adad648 100644 --- a/JulietApp/main.cpp +++ b/JulietApp/main.cpp @@ -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) @@ -137,6 +143,7 @@ void JulietApplication::Init(NonNullPtr) 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) blueLight.Color = { blueLightColor[0], blueLightColor[1], blueLightColor[2] }; blueLight.Intensity = blueLightIntensity; BlueLightID = AddPointLight(blueLight); +#endif } GameCode.Functions = reinterpret_cast(&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() { diff --git a/JulietApp/main.h b/JulietApp/main.h index e8a41d5..a9d42c0 100644 --- a/JulietApp/main.h +++ b/JulietApp/main.h @@ -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; }