3#include "scene/GameObject.h"
4#include "scene/Component.h"
5#include "scene/components/CameraComponent.h"
12 void keyCallback(GLFWwindow* window,
int key,
int,
int action,
int)
15 if (action == GLFW_PRESS)
19 else if (action == GLFW_RELEASE)
21 inputManager.SetKeyPressed(key,
false);
28 if (action == GLFW_PRESS)
32 else if (action == GLFW_RELEASE)
34 inputManager.SetMouseButtonPressed(button,
false);
44 glm::vec2 currentPos(
static_cast<float>(xpos),
static_cast<float>(ypos));
45 inputManager.SetMousePositionCurrent(currentPos);
47 inputManager.SetMousePositionChanged(
true);
64 m_application->RegisterTypes();
66#if defined (__linux__)
67 glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
75 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
76 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
77 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
79 m_window = glfwCreateWindow(width, height,
"GameDevelopmentProject",
nullptr,
nullptr);
81 if (m_window ==
nullptr)
83 std::cout <<
"Error creating window" << std::endl;
91 glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
93 glfwMakeContextCurrent(m_window);
95 if (glewInit() != GLEW_OK)
101 m_graphicsAPI.
Init();
102 m_physicsManager.
Init();
103 m_audioManager.
Init();
105 return m_application->Init();
115 m_lastTimePoint = std::chrono::steady_clock::now();
117 while (!glfwWindowShouldClose(m_window) && !m_application->NeedsToBeClosed())
121 auto now = std::chrono::steady_clock::now();
122 float deltaTime = std::chrono::duration<float>(now - m_lastTimePoint).count();
123 m_lastTimePoint = now;
125 m_physicsManager.
Update(deltaTime);
127 m_application->Update(deltaTime);
133 std::vector<LightData> lights;
137 glfwGetWindowSize(m_window, &width, &height);
138 float aspect =
static_cast<float>(width) /
static_cast<float>(height);
142 if (
auto cameraObject = m_currentScene->GetMainCamera())
148 cameraData.
viewMatrix = cameraComponent->GetViewMatrix();
151 0.0f,
static_cast<float>(width),
152 0.0f,
static_cast<float>(height)
154 cameraData.
position = cameraObject->GetWorldPosition();
158 lights = m_currentScene->CollectLights();
161 m_rederQueue.
Draw(m_graphicsAPI, cameraData, lights);
163 glfwSwapBuffers(m_window);
173 m_application->Destroy();
174 m_application.reset();
182 m_application.reset(app);
187 return m_application.get();
192 return m_inputManager;
197 return m_graphicsAPI;
212 return m_textureManager;
217 return m_physicsManager;
222 return m_audioManager;
227 m_currentScene.reset(scene);
232 return m_currentScene.get();
Application * GetApplication()
void SetApplication(Application *app)
GraphicsAPI & GetGraphicsAPI()
AudioManager & GetAudioManager()
FileSystem & GetFileSystem()
bool Init(int width, int height)
InputManager & GetInputManager()
TextureManager & GetTextureManager()
void SetScene(Scene *scene)
static Engine & GetInstance()
RenderQueue & GetRenderQueue()
PhysicsManager & GetPhysicsManager()
void SetClearColor(float r, float g, float b, float a)
void Update(float deltaTime)
void Draw(GraphicsAPI &graphicsAPI, const CameraData &cameraData, const std::vector< LightData > &lights)
static void RegisterTypes()
Abstract base class for the user-defined game or lab application.
Central singleton that owns and coordinates all engine subsystems.
void keyCallback(GLFWwindow *window, int key, int, int action, int)
void mouseButtonCallback(GLFWwindow *window, int button, int action, int)
void cursorPositionCallback(GLFWwindow *window, double xpos, double ypos)
glm::mat4 projectionMatrix