Skip to content

Commit

Permalink
input_manager: init
Browse files Browse the repository at this point in the history
  • Loading branch information
furkansarihan committed Nov 9, 2023
1 parent 0ebf19f commit d8c2583
Show file tree
Hide file tree
Showing 8 changed files with 1,212 additions and 21 deletions.
6 changes: 3 additions & 3 deletions dev/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ int main()
DebugDrawer *debugDrawer = enigine.debugDrawer;
UpdateManager *updateManager = enigine.updateManager;
TaskManager *taskManager = enigine.taskManager;
InputManager *inputManager = enigine.inputManager;
SoundEngine *soundEngine = enigine.soundEngine;
Camera *mainCamera = enigine.mainCamera;

Expand Down Expand Up @@ -129,9 +130,8 @@ int main()

car.m_controlVehicle = true;
car.m_followVehicle = true;
// TODO: input manager
glfwSetWindowUserPointer(window, &car);
glfwSetKeyCallback(window, car.staticKeyCallback);
inputManager->addKeyListener(std::bind(&CarController::keyListener, &car,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5));

// TODO: before character - parent transform - ?
updateManager->add(&car);
Expand Down
8 changes: 1 addition & 7 deletions src/car_controller/car_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ CarController::~CarController()
delete m_tireSmokeParticles[i];
}

void CarController::keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
void CarController::keyListener(GLFWwindow *window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_1 && action == GLFW_PRESS)
{
Expand All @@ -170,12 +170,6 @@ void CarController::keyCallback(GLFWwindow *window, int key, int scancode, int a
}
}

void CarController::staticKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
{
CarController *cc = (CarController *)glfwGetWindowUserPointer(window);
cc->keyCallback(window, key, scancode, action, mods);
}

void CarController::update(float deltaTime)
{
m_vehicle->update(deltaTime);
Expand Down
3 changes: 1 addition & 2 deletions src/car_controller/car_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ class CarController : public Updatable
void updateTireSmoke(int index, float deltaTime);
glm::mat4 translateOffset(glm::vec3 offset);
void followCar(float deltaTime);
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);
static void staticKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);
void keyListener(GLFWwindow *window, int key, int scancode, int action, int mods);

private:
int m_keyForward = GLFW_KEY_W;
Expand Down
21 changes: 12 additions & 9 deletions src/enigine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ Enigine::Enigine()

Enigine::~Enigine()
{
// cleanup imgui
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
// cleanup glfw
glfwDestroyWindow(window);
glfwTerminate();

// cleanup objects
delete physicsWorld;
delete debugDrawer;
Expand All @@ -22,12 +14,22 @@ Enigine::~Enigine()
delete resourceManager;
delete renderManager;
delete taskManager;
delete inputManager;
delete mainCamera;

// cleanup ui
for (int i = 0; i < rootUI->m_uiList.size(); i++)
delete rootUI->m_uiList[i];
delete rootUI;

// cleanup imgui
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();

// cleanup glfw
glfwDestroyWindow(window);
glfwTerminate();
}

// TODO: return init result enum
Expand Down Expand Up @@ -119,6 +121,7 @@ int Enigine::init()
renderManager = new RenderManager(shaderManager, mainCamera, &cube, &quad, &icosahedron, q_vao);
updateManager = new UpdateManager();
taskManager = new TaskManager();
inputManager = new InputManager(window);

// Time
lastFrame = (float)glfwGetTime();
Expand All @@ -145,7 +148,7 @@ int Enigine::init()
shadowmapUI = new ShadowmapUI(renderManager->m_shadowManager, renderManager->m_shadowmapManager);
CameraUI *cameraUI = new CameraUI(mainCamera);
ResourceUI *resourceUI = new ResourceUI(resourceManager);
renderUI = new RenderUI(window, renderManager, resourceManager);
renderUI = new RenderUI(inputManager, renderManager, resourceManager);
PhysicsWorldUI *physicsWorldUI = new PhysicsWorldUI(physicsWorld, debugDrawer);
rootUI->m_uiList.push_back(systemMonitorUI);
rootUI->m_uiList.push_back(shadowmapUI);
Expand Down
1 change: 1 addition & 0 deletions src/enigine.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Enigine
RenderManager *renderManager;
UpdateManager *updateManager;
TaskManager *taskManager;
InputManager *inputManager;

GLFWwindow *window;
task_basic_info t_info;
Expand Down
Loading

0 comments on commit d8c2583

Please sign in to comment.