Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,31 @@ const std::shared_ptr<GameObject> Engine::CreateGameObject(const std::string& ob
return go;
}

void Engine::BindKeyToFunc(const int& key, std::function<void()>& func)
void Engine::BindKeyToFunc(const int& key, std::function<void()>& func, const ActionType& type)
{
mp_controller->SetKeyToFunc(key, func);
mp_controller->SetKeyToFunc(key, func, type);
}

const std::shared_ptr<Camera> 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());
Expand Down
7 changes: 6 additions & 1 deletion Engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ class Engine
const std::shared_ptr<GameObject> CreateGameObject(const std::string& object_file);

// CONTROLLER
void BindKeyToFunc(const int& key, std::function<void()>& func);
void BindKeyToFunc(const int& key, std::function<void()>& func, const ActionType& type = ActionType::R3D_PRESS);

// CAMERA
const std::shared_ptr<Camera> GetMainCamera();

// VIEWING
void SetWireframeMode();
void SetPointMode();
void SetFillMode();

const bool& shouldClose();

private:
Expand Down
16 changes: 14 additions & 2 deletions Engine/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,20 @@ int main()

engine.setScene(scene);

std::function<void()> my_func = []() {std::clog << "Test d'un key bind" << std::endl; };
engine.BindKeyToFunc(GLFW_KEY_Q, my_func);
std::function<void()> wireframemode = [&engine]() {
engine.SetWireframeMode();
};
engine.BindKeyToFunc(GLFW_KEY_Q, wireframemode, ActionType::R3D_PRESS);

std::function<void()> fillmode = [&engine]() {
engine.SetFillMode();
};
engine.BindKeyToFunc(GLFW_KEY_E, fillmode, ActionType::R3D_PRESS);

std::function<void()> pointmode = [&engine]() {
engine.SetPointMode();
};
engine.BindKeyToFunc(GLFW_KEY_R, pointmode, ActionType::R3D_PRESS);

int init = 0;
// running loop
Expand Down
45 changes: 34 additions & 11 deletions Engine/cameras/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ Controller::Controller(std::shared_ptr<Camera> p_camera)

// Set default controls
std::function<void()> 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<std::array<std::function<void()>, 348>>();
m_onrelease_actions = std::make_unique<std::array<std::function<void()>, 348>>();
}


Expand All @@ -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<void()>& func)
void Controller::SetKeyToFunc(const int32_t& key, std::function<void()>& 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)
Expand All @@ -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();
}
}

Expand Down
15 changes: 12 additions & 3 deletions Engine/cameras/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,33 @@ struct Actions
const std::function<void()> func;
};

enum class ActionType
{
RED_RELEASE,
R3D_PRESS,
R3D_HOLD
};

class Controller
{
public:
Controller(std::shared_ptr<Camera> p_camera);
~Controller();

void setInput(int32_t key, int32_t scancode, int32_t mods, int32_t action);
void SetKeyToFunc(const int32_t& key, std::function<void()>& func);
void SetKeyToFunc(const int32_t& key, std::function<void()>& func, const ActionType& type);

void Update(const float& dt);
void updateRotation(const double& xpos, const double& ypos);

uint32_t getLoadRadius();
private:
std::vector<Actions> m_actions;
std::bitset<348> m_keyboard_press;
std::vector<Actions> m_hold_actions;
std::unique_ptr<std::array<std::function<void()>, 348>> m_onpress_actions;
std::unique_ptr<std::array<std::function<void()>, 348>> m_onrelease_actions;

uint32_t m_load_radius = 4;
std::bitset<348> m_keyboard_press;

std::shared_ptr<Camera> mp_camera;
};
Expand Down
1 change: 1 addition & 0 deletions Engine/renderer/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void VulkanDevice::createLogicalDevice()

VkPhysicalDeviceFeatures deviceFeatures = {};
deviceFeatures.samplerAnisotropy = VK_TRUE;
deviceFeatures.fillModeNonSolid = VK_TRUE;


VkDeviceCreateInfo device_info = {};
Expand Down