#include "MiniginPCH.h"
#include "Engine.h"

#include "Renderer.h"
#include "../../../Managers/InputManager.h"
#include "../../../Managers/SceneManager.h"

#include "Time.h"
#include "../../../Managers/RenderManager.h"

void dae::Engine::Initialize()
{
	const int msPerFrame = 16;

	auto& input = dae::InputManager::GetInstance();
	input.Initialize();

	auto& renderManager = RenderManager::GetInstance();
	renderManager.Initialize(450);

	bool lockFrameRate = false;

	auto& time = Time::GetInstance();
	time.SetLockFramerate(lockFrameRate, msPerFrame);
	time.Initialize();
}

void dae::Engine::LoadGame(std::shared_ptr pGame)
{
	pGame->Initialize();
	m_pGame = pGame;
}

void dae::Engine::Run()
{
	auto& renderer = Renderer::GetInstance();
	auto& input = dae::InputManager::GetInstance();
	auto& sceneManager = dae::SceneManager::GetInstance();
	auto& time = Time::GetInstance();
	bool doContinue = true;

	while (doContinue)
	{
		doContinue = input.ProcessInput();
		
		sceneManager.Update();
		renderer.Render();

		time.CalculateDeltaTime();
	}
}

std::shared_ptr dae::Engine::GetCurrentGame()
{
	return m_pGame;
}