From b200c38ca1bf6922e2cda7f7f9273b602a31f8d8 Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Sat, 12 Oct 2024 14:35:08 +0200 Subject: [PATCH] 3DRenderer instancing --- Engine/Graphics/3DRenderer.hpp | 1 - Engine/Graphics/Camera.cpp | 2 +- Engine/Graphics/UI.cpp | 4 ++-- Engine/Graphics/UI.hpp | 4 ++-- Game.cpp | 9 ++++----- Game.hpp | 7 +++++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Engine/Graphics/3DRenderer.hpp b/Engine/Graphics/3DRenderer.hpp index b64112a..7df9038 100644 --- a/Engine/Graphics/3DRenderer.hpp +++ b/Engine/Graphics/3DRenderer.hpp @@ -20,7 +20,6 @@ public: void Draw(sf::RenderTexture& context); private: - sf::RenderTexture mWorldRender; // This is used to create the scene std::unique_ptr mMainCamera; // Default player view std::vector> mRenderList; // List of elements to be rendered next frame diff --git a/Engine/Graphics/Camera.cpp b/Engine/Graphics/Camera.cpp index 9edac58..0964ff1 100644 --- a/Engine/Graphics/Camera.cpp +++ b/Engine/Graphics/Camera.cpp @@ -16,7 +16,7 @@ void Camera::UpdateCamView() { M3D_VECTOR L = M3D_V4LoadF3(&mLook); M3D_VECTOR U = M3D_V4LoadF3(&mUp); - M3D_V4StoreF4x4(&mViewMat, M3D_TransformMatrixCamLookAtLH(P, L, U)); + M3D_V4StoreF4x4(&mViewMat, M3D_TransformMatrixCamLookToLH(P, L, U)); } void Camera::LookAt(M3D_VECTOR pos, M3D_VECTOR target, M3D_VECTOR worldUp) { diff --git a/Engine/Graphics/UI.cpp b/Engine/Graphics/UI.cpp index a19389b..ae09b8a 100644 --- a/Engine/Graphics/UI.cpp +++ b/Engine/Graphics/UI.cpp @@ -69,7 +69,7 @@ void CockpitUI::Draw(std::shared_ptr context) { } -WorldUI::WorldUI() : UI() { +WorldUI::WorldUI(std::shared_ptr engineInstance) : UI(), mWorld3D(engineInstance) { sf::ContextSettings sViewSettings; sViewSettings.depthBits = 0; sViewSettings.stencilBits = 0; @@ -98,7 +98,7 @@ void WorldUI::Draw(std::shared_ptr context) { mUIRender.clear(sf::Color::Transparent); // Draw the 3D view - m3DEngine.Draw(mUIRender); + mWorld3D->Draw(mUIRender); // Do the final texture render mUIRender.display(); diff --git a/Engine/Graphics/UI.hpp b/Engine/Graphics/UI.hpp index 030ee66..469f64d 100644 --- a/Engine/Graphics/UI.hpp +++ b/Engine/Graphics/UI.hpp @@ -42,7 +42,7 @@ private: class WorldUI final : public UI { public: - WorldUI(); + WorldUI(std::shared_ptr engineInstance); ~WorldUI() {} WorldUI(WorldUI&&) = default; @@ -54,6 +54,6 @@ public: void Draw(std::shared_ptr) override; private: - Graphic3DRenderer m3DEngine; + std::shared_ptr mWorld3D; }; \ No newline at end of file diff --git a/Game.cpp b/Game.cpp index 2789d63..6288154 100644 --- a/Game.cpp +++ b/Game.cpp @@ -1,7 +1,6 @@ #include "Game.hpp" #include - #include #include @@ -13,12 +12,12 @@ using std::make_unique; #define TARGET_FPS (60) -std::unique_ptr mPerfsTimer = nullptr; Game* Game::smInstance = nullptr; Game::Game(std::shared_ptr mainWnd, bool dbgFlag) : mbDbgModeEnabled(dbgFlag), mMainWindow(mainWnd) { + mWorld3D = make_shared(); mCockpitUI = make_unique(); - mWorldUI = make_unique(); + mWorldUI = make_unique(mWorld3D); if (mbDbgModeEnabled) { mDbgUI = make_unique(); @@ -61,8 +60,8 @@ GAME_STATUS Game::Tick() { // Ugly way to wait for next frame... Maybe create a separate thread for rendering? //while(time.GetDeltaTime() < (1000/TARGET_FPS)) {} - // Process to the final rendering - if (mSysTimer.GetDeltaTime() >= (1000/TARGET_FPS)) { + // Process to the final rendering if the window have the focus + if (mSysTimer.GetDeltaTime() >= (1000/TARGET_FPS) && mMainWindow->hasFocus()) { Render(); mFrameCnt++; mSysTimer.Reset(); diff --git a/Game.hpp b/Game.hpp index dfcb0cd..5311e86 100644 --- a/Game.hpp +++ b/Game.hpp @@ -4,6 +4,7 @@ #include "Engine/Graphics/UI.hpp" #include "Engine/Graphics/DebugUI.hpp" +#include "Engine/Graphics/3DRenderer.hpp" #include "Engine/Utils/Timers.hpp" @@ -41,9 +42,11 @@ private: std::unique_ptr mDbgUI = nullptr; SysTimer mSysTimer; + std::unique_ptr mPerfsTimer = nullptr; std::shared_ptr mMainWindow; - std::unique_ptr mCockpitUI = nullptr; - std::unique_ptr mWorldUI = nullptr; + std::shared_ptr mWorld3D; + std::unique_ptr mCockpitUI; + std::unique_ptr mWorldUI; }; \ No newline at end of file