Skip to content

Commit

Permalink
Cleaned up Leap class
Browse files Browse the repository at this point in the history
SetEnabledDebugDrawing is now being called in the main.cpp instead of the Leap.cpp
Removed m_Renderer variable in the Leap class
  • Loading branch information
AtlantiaKing committed Nov 12, 2023
1 parent 118668e commit 29d1cd7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
19 changes: 9 additions & 10 deletions LeapEngine/Leap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ leap::LeapEngine::LeapEngine(int width, int height, const std::string& title)
Debug::Log("LeapEngine Log: Registering default physics (PhysX)");
ServiceLocator::RegisterPhysics<physics::PhysXEngine>();

m_pRenderer = &ServiceLocator::GetRenderer();
m_pRenderer->Initialize();
ServiceLocator::GetRenderer().Initialize();

// Set default icon
Debug::Log("LeapEngine Log: Setting default window icon");
Expand All @@ -69,8 +68,8 @@ leap::LeapEngine::~LeapEngine()

void leap::LeapEngine::Run(int desiredFPS)
{
auto& input = input::InputManager::GetInstance();
auto& gameContext = GameContext::GetInstance();
auto& input{ input::InputManager::GetInstance() };
auto& gameContext{ GameContext::GetInstance() };

Debug::Log("LeapEngine Log: Loading default scene");
auto& sceneManager = SceneManager::GetInstance();
Expand All @@ -80,16 +79,16 @@ void leap::LeapEngine::Run(int desiredFPS)
const int frameTimeNs{ 1'000'000'000 / desiredFPS };
float fixedTotalTime{};

auto& audio = ServiceLocator::GetAudio();
auto& physics = ServiceLocator::GetPhysics();
auto& audio{ ServiceLocator::GetAudio() };
auto& physics{ ServiceLocator::GetPhysics() };
physics.SetSyncFunc(PhysicsSync::SetTransform, PhysicsSync::GetTransform);
physics.OnCollisionEnter().AddListener(PhysicsSync::OnCollisionEnter);
physics.OnCollisionStay().AddListener(PhysicsSync::OnCollisionStay);
physics.OnCollisionExit().AddListener(PhysicsSync::OnCollisionExit);
physics.OnTriggerEnter().AddListener(PhysicsSync::OnTriggerEnter);
physics.OnTriggerStay().AddListener(PhysicsSync::OnTriggerStay);
physics.OnTriggerExit().AddListener(PhysicsSync::OnTriggerExit);
physics.SetEnabledDebugDrawing(true);
auto& renderer{ ServiceLocator::GetRenderer() };

while (!glfwWindowShouldClose(m_pWindow))
{
Expand Down Expand Up @@ -118,12 +117,12 @@ void leap::LeapEngine::Run(int desiredFPS)

sceneManager.LateUpdate();

m_pRenderer->GuiDraw();
renderer.GuiDraw();
sceneManager.OnGUI();
gameContext.OnGUI();

m_pRenderer->DrawLines(physics.GetDebugDrawings());
m_pRenderer->Draw();
renderer.DrawLines(physics.GetDebugDrawings());
renderer.Draw();
glfwSwapBuffers(m_pWindow);

sceneManager.OnFrameEnd();
Expand Down
1 change: 0 additions & 1 deletion LeapEngine/Leap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ namespace leap

private:
GLFWwindow* m_pWindow{};
leap::graphics::IRenderer* m_pRenderer{};
};
}
3 changes: 3 additions & 0 deletions UnnamedAdventureGame/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "GameContext/Logger/ImGuiLogger.h"
#include "SceneGraph/SceneManager.h"
#include "Scenes/MainMenuScene.h"
#include <ServiceLocator/ServiceLocator.h>
#include <Interfaces/IPhysics.h>

#if _DEBUG
#include <vld.h>
Expand All @@ -13,6 +15,7 @@ int main()
{
leap::GameContext::GetInstance().AddLogger<leap::ImGuiLogger>();
leap::LeapEngine engine{ 1280, 720, "Leap game engine" };
leap::ServiceLocator::GetPhysics().SetEnabledDebugDrawing(true);
leap::SceneManager::GetInstance().AddScene("Test scene", unag::MainMenuScene::Load);
engine.Run(60);
return 0;
Expand Down

0 comments on commit 29d1cd7

Please sign in to comment.