diff --git a/Engine/Engine.cpp b/Engine/Engine.cpp index de01b89..3f38c54 100644 --- a/Engine/Engine.cpp +++ b/Engine/Engine.cpp @@ -80,9 +80,9 @@ const std::shared_ptr Engine::CreateGameObject(const std::string& ob return go; } -void Engine::BindKeyToFunc(const int& key, std::function& func) +void Engine::BindKeyToFunc(const int& key, std::function& func, const ActionType& type) { - mp_controller->SetKeyToFunc(key, func); + mp_controller->SetKeyToFunc(key, func, type); } const std::shared_ptr Engine::GetMainCamera() @@ -90,6 +90,21 @@ const std::shared_ptr Engine::GetMainCamera() return mp_main_camera; } +void Engine::SetWireframeMode() +{ + mp_renderer->SetPolygonFillingMode(VK_POLYGON_MODE_LINE); +} + +void Engine::SetPointMode() +{ + mp_renderer->SetPolygonFillingMode(VK_POLYGON_MODE_POINT); +} + +void Engine::SetFillMode() +{ + mp_renderer->SetPolygonFillingMode(VK_POLYGON_MODE_FILL); +} + const bool& Engine::shouldClose() { return glfwWindowShouldClose(&mp_window->getHandle()); diff --git a/Engine/Engine.h b/Engine/Engine.h index d4a25e0..35b4f60 100644 --- a/Engine/Engine.h +++ b/Engine/Engine.h @@ -28,11 +28,16 @@ class Engine const std::shared_ptr CreateGameObject(const std::string& object_file); // CONTROLLER - void BindKeyToFunc(const int& key, std::function& func); + void BindKeyToFunc(const int& key, std::function& func, const ActionType& type = ActionType::R3D_PRESS); // CAMERA const std::shared_ptr GetMainCamera(); + // VIEWING + void SetWireframeMode(); + void SetPointMode(); + void SetFillMode(); + const bool& shouldClose(); private: diff --git a/Engine/Source.cpp b/Engine/Source.cpp index c3e4d50..6ba6b89 100644 --- a/Engine/Source.cpp +++ b/Engine/Source.cpp @@ -26,8 +26,20 @@ int main() engine.setScene(scene); - std::function my_func = []() {std::clog << "Test d'un key bind" << std::endl; }; - engine.BindKeyToFunc(GLFW_KEY_Q, my_func); + std::function wireframemode = [&engine]() { + engine.SetWireframeMode(); + }; + engine.BindKeyToFunc(GLFW_KEY_Q, wireframemode, ActionType::R3D_PRESS); + + std::function fillmode = [&engine]() { + engine.SetFillMode(); + }; + engine.BindKeyToFunc(GLFW_KEY_E, fillmode, ActionType::R3D_PRESS); + + std::function pointmode = [&engine]() { + engine.SetPointMode(); + }; + engine.BindKeyToFunc(GLFW_KEY_R, pointmode, ActionType::R3D_PRESS); int init = 0; // running loop diff --git a/Engine/cameras/Controller.cpp b/Engine/cameras/Controller.cpp index 6df04ac..008f465 100644 --- a/Engine/cameras/Controller.cpp +++ b/Engine/cameras/Controller.cpp @@ -7,22 +7,25 @@ Controller::Controller(std::shared_ptr p_camera) // Set default controls std::function default_func = [this]() { mp_camera->MoveForward(2.0f); }; - SetKeyToFunc(GLFW_KEY_W, default_func); + SetKeyToFunc(GLFW_KEY_W, default_func, ActionType::R3D_HOLD); default_func = [this]() { mp_camera->MoveBackward(2.0f); }; - SetKeyToFunc(GLFW_KEY_S, default_func); + SetKeyToFunc(GLFW_KEY_S, default_func, ActionType::R3D_HOLD); default_func = [this]() { mp_camera->MoveLeft(2.0f); }; - SetKeyToFunc(GLFW_KEY_A, default_func); + SetKeyToFunc(GLFW_KEY_A, default_func, ActionType::R3D_HOLD); default_func = [this]() { mp_camera->MoveRight(2.0f); }; - SetKeyToFunc(GLFW_KEY_D, default_func); + SetKeyToFunc(GLFW_KEY_D, default_func, ActionType::R3D_HOLD); default_func = [this]() { mp_camera->MoveUp(2.0f); }; - SetKeyToFunc(GLFW_KEY_LEFT_SHIFT, default_func); + SetKeyToFunc(GLFW_KEY_LEFT_SHIFT, default_func, ActionType::R3D_HOLD); default_func = [this]() { mp_camera->MoveDown(2.0f); }; - SetKeyToFunc(GLFW_KEY_LEFT_CONTROL, default_func); + SetKeyToFunc(GLFW_KEY_LEFT_CONTROL, default_func, ActionType::R3D_HOLD); + + m_onpress_actions = std::make_unique, 348>>(); + m_onrelease_actions = std::make_unique, 348>>(); } @@ -35,16 +38,36 @@ void Controller::setInput(int32_t key, int32_t scancode, int32_t mods, int32_t a if (action == GLFW_PRESS) { m_keyboard_press.set(key, true); + + if(m_onpress_actions->at(key)) + m_onpress_actions->at(key)(); } else if (action == GLFW_RELEASE) { m_keyboard_press.set(key, false); + + if(m_onrelease_actions->at(key)) + m_onrelease_actions->at(key)(); } } -void Controller::SetKeyToFunc(const int32_t& key, std::function& func) +void Controller::SetKeyToFunc(const int32_t& key, std::function& func, const ActionType& type) { - m_actions.push_back({ key, func }); + switch (type) + { + case ActionType::RED_RELEASE: + m_onrelease_actions->at(key) = func; + break; + case ActionType::R3D_PRESS: + m_onpress_actions->at(key) = func; + break; + case ActionType::R3D_HOLD: + m_hold_actions.push_back({ key, func }); + break; + default: + m_hold_actions.push_back({ key, func }); + break; + } } void Controller::updateRotation(const double& xpos, const double& ypos) @@ -59,11 +82,11 @@ void Controller::updateRotation(const double& xpos, const double& ypos) void Controller::Update(const float& dt) { - for (size_t i = 0; i < m_actions.size(); i++) + for (size_t i = 0; i < m_hold_actions.size(); i++) { - if (m_keyboard_press[m_actions[i].key]) + if (m_keyboard_press[m_hold_actions[i].key]) { - m_actions[i].func(); + m_hold_actions[i].func(); } } diff --git a/Engine/cameras/Controller.h b/Engine/cameras/Controller.h index 216821c..2b3f247 100644 --- a/Engine/cameras/Controller.h +++ b/Engine/cameras/Controller.h @@ -14,6 +14,13 @@ struct Actions const std::function func; }; +enum class ActionType +{ + RED_RELEASE, + R3D_PRESS, + R3D_HOLD +}; + class Controller { public: @@ -21,17 +28,19 @@ class Controller ~Controller(); void setInput(int32_t key, int32_t scancode, int32_t mods, int32_t action); - void SetKeyToFunc(const int32_t& key, std::function& func); + void SetKeyToFunc(const int32_t& key, std::function& func, const ActionType& type); void Update(const float& dt); void updateRotation(const double& xpos, const double& ypos); uint32_t getLoadRadius(); private: - std::vector m_actions; - std::bitset<348> m_keyboard_press; + std::vector m_hold_actions; + std::unique_ptr, 348>> m_onpress_actions; + std::unique_ptr, 348>> m_onrelease_actions; uint32_t m_load_radius = 4; + std::bitset<348> m_keyboard_press; std::shared_ptr mp_camera; }; diff --git a/Engine/renderer/VulkanDevice.cpp b/Engine/renderer/VulkanDevice.cpp index 55d47ba..3deb844 100644 --- a/Engine/renderer/VulkanDevice.cpp +++ b/Engine/renderer/VulkanDevice.cpp @@ -74,6 +74,7 @@ void VulkanDevice::createLogicalDevice() VkPhysicalDeviceFeatures deviceFeatures = {}; deviceFeatures.samplerAnisotropy = VK_TRUE; + deviceFeatures.fillModeNonSolid = VK_TRUE; VkDeviceCreateInfo device_info = {};