Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
graphite/engine/core/include/engine.hpp
2024-01-03 16:05:02 -05:00

96 lines
No EOL
1.9 KiB
C++

#pragma once
#include <vector>
#include <string>
#include <map>
#include <typeindex>
#include <chrono>
#include <system.hpp>
#include <renderer.hpp>
class GameInstance;
struct GameInfo
{
GameInfo()
{
gameName = "Game";
defaultMap = "";
benchmarkingEnabled = false;
debugGUIEnabled = false;
isEditor = false;
}
std::string gameName, defaultMap;
bool benchmarkingEnabled;
bool debugGUIEnabled;
bool isEditor;
};
class Engine
{
public:
Engine(GameInfo info);
~Engine();
void Tick(bool updateSystems = true);
template<typename T>
T* GetSystem()
{
static_assert(std::is_base_of<System, T>::value, "GetSystem requires to be given a type that derives from System!");
if(m_systems.count(typeid(T)))
return static_cast<T*>(m_systems.at(typeid(T)));
return nullptr;
}
Renderer* GetRenderer() const
{
return m_renderer;
}
GameInstance* GetGame() const
{
return m_gameInstance;
}
GameInfo gameInfo;
private:
template<typename T>
void AddSystem()
{
static_assert(std::is_base_of<System, T>::value, "AddSystem requires that the type derives from System!");
T* t = new T;
static_cast<System*>(t)->SetEngine(this);
m_systems.emplace(typeid(T), t);
}
void ApplyOptions();
void PickSuitableBackend();
void CreateBackend();
void DrawDebug();
bool m_debugging, m_benchmarking;
GameInstance* m_gameInstance;
Renderer* m_renderer;
std::map<std::type_index, System*> m_systems;
//used for time calculation
std::chrono::time_point<std::chrono::high_resolution_clock> m_applicationStart;
std::chrono::duration<float> m_currentTime;
int m_frames = 0;
float m_lastTime = 0.0f;
int m_oldWindowX = 0, m_oldWindowY = 0;
};