wip: convert from include style to module import style :D
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
63cb6dfe92
commit
273f1e2006
6 changed files with 49 additions and 74 deletions
|
|
@ -1,4 +1,11 @@
|
||||||
add_library_module(NAME input INTERFACES system.cpp)
|
add_library_module(
|
||||||
target_link_libraries(input PUBLIC surface math logger tbb)
|
NAME
|
||||||
|
input
|
||||||
|
INTERFACES
|
||||||
|
system.cppm
|
||||||
|
codes.cppm
|
||||||
|
components.cppm
|
||||||
|
events.cppm)
|
||||||
|
target_link_libraries(input PUBLIC surface math logger)
|
||||||
|
|
||||||
add_test_module(input system.test.cpp)
|
# add_test_module(input system.test.cpp)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
#pragma once
|
export module input.codes;
|
||||||
|
import std;
|
||||||
|
|
||||||
#include <cstdint>
|
export enum class Key: std::uint16_t {
|
||||||
|
|
||||||
|
|
||||||
enum : uint16_t
|
|
||||||
{
|
|
||||||
/* digits */
|
/* digits */
|
||||||
D0 = 48,
|
D0 = 48,
|
||||||
D1 = 49,
|
D1 = 49,
|
||||||
|
|
@ -173,24 +170,4 @@ enum : uint16_t
|
||||||
Pause = 284,
|
Pause = 284,
|
||||||
|
|
||||||
Menu = 348,
|
Menu = 348,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum : uint8_t
|
|
||||||
{
|
|
||||||
Button1 = 0,
|
|
||||||
Button2 = 1,
|
|
||||||
Button3 = 2,
|
|
||||||
Button4 = 3,
|
|
||||||
Button5 = 4,
|
|
||||||
Button6 = 5,
|
|
||||||
Button7 = 6,
|
|
||||||
Button8 = 7,
|
|
||||||
|
|
||||||
LButton = Button1,
|
|
||||||
RButton = Button2,
|
|
||||||
MButton = Button3,
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::Key
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,17 @@
|
||||||
export module input.components;
|
export module input.system:components;
|
||||||
|
import input.codes;
|
||||||
#include <vector>
|
import std;
|
||||||
|
|
||||||
namespace lt::input {
|
namespace lt::input {
|
||||||
|
|
||||||
struct Trigger
|
export struct Trigger
|
||||||
{
|
{
|
||||||
uint32_t mapped_keycode;
|
Key mapped_keycode;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InputAction
|
export struct InputAction
|
||||||
{
|
{
|
||||||
using Key = size_t;
|
enum class State : std::uint8_t
|
||||||
|
|
||||||
enum class State : uint8_t
|
|
||||||
{
|
{
|
||||||
inactive,
|
inactive,
|
||||||
active,
|
active,
|
||||||
|
|
@ -28,18 +26,18 @@ struct InputAction
|
||||||
Trigger trigger;
|
Trigger trigger;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InputComponent
|
export class InputComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InputComponent() = default;
|
InputComponent() = default;
|
||||||
|
|
||||||
auto add_action(InputAction action) -> size_t
|
auto add_action(InputAction action) -> std::size_t
|
||||||
{
|
{
|
||||||
m_actions.emplace_back(std::move(action));
|
m_actions.emplace_back(std::move(action));
|
||||||
return m_actions.size() - 1;
|
return m_actions.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get_action(auto idx) -> const InputAction &
|
auto get_action(std::size_t idx) -> const InputAction &
|
||||||
{
|
{
|
||||||
return m_actions[idx];
|
return m_actions[idx];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,24 @@
|
||||||
#pragma once
|
export module input.events;
|
||||||
|
|
||||||
#include <math/vec2.hpp>
|
import input.codes;
|
||||||
|
import math.vec2;
|
||||||
|
|
||||||
|
import std;
|
||||||
|
|
||||||
namespace lt::input {
|
namespace lt::input {
|
||||||
|
|
||||||
class AnalogEvent
|
export class AnalogEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AnalogEvent(uint32_t input_code, math::uvec2 pointer_position)
|
AnalogEvent(Key key, math::uvec2 pointer_position)
|
||||||
: m_input_code(input_code)
|
: m_key(key)
|
||||||
, m_pointer_position(pointer_position)
|
, m_pointer_position(pointer_position)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto get_code() const -> uint32_t
|
[[nodiscard]] auto get_key() const -> Key
|
||||||
{
|
{
|
||||||
return m_input_code;
|
return m_key;
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] auto get_pointer_position() const -> math::uvec2
|
[[nodiscard]] auto get_pointer_position() const -> math::uvec2
|
||||||
|
|
@ -25,20 +28,14 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] auto to_string() const -> std::string
|
[[nodiscard]] auto to_string() const -> std::string
|
||||||
{
|
{
|
||||||
auto stream = std::stringstream {};
|
|
||||||
const auto &[x, y] = m_pointer_position;
|
const auto &[x, y] = m_pointer_position;
|
||||||
stream << "input::AnalogEvent: " << m_input_code << " @ " << x << ", " << y;
|
return std::format("input::AnalogEvent: {} @ {}, {}", std::to_underlying(m_key), x, y);
|
||||||
return stream.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t m_input_code;
|
Key m_key;
|
||||||
|
|
||||||
math::uvec2 m_pointer_position;
|
math::uvec2 m_pointer_position;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AxisEvent
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::input
|
} // namespace lt::input
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
#pragma once
|
export module input.system;
|
||||||
|
export import :components;
|
||||||
#include <app/system.hpp>
|
import logger;
|
||||||
#include <ecs/registry.hpp>
|
import app.system;
|
||||||
#include <memory/reference.hpp>
|
import debug.assertions;
|
||||||
#include <surface/components.hpp>
|
import ecs.registry;
|
||||||
#include <surface/events/keyboard.hpp>
|
import memory.reference;
|
||||||
#include <surface/events/mouse.hpp>
|
import surface.system;
|
||||||
|
import surface.events;
|
||||||
|
import math.vec2;
|
||||||
|
import std;
|
||||||
|
|
||||||
namespace lt::input {
|
namespace lt::input {
|
||||||
|
|
||||||
|
|
@ -56,12 +59,7 @@ private:
|
||||||
|
|
||||||
|
|
||||||
module :private;
|
module :private;
|
||||||
|
using namespace lt::input;
|
||||||
#include <input/components.hpp>
|
|
||||||
#include <input/system.hpp>
|
|
||||||
#include <memory/reference.hpp>
|
|
||||||
|
|
||||||
namespace lt::input {
|
|
||||||
|
|
||||||
template<class... Ts>
|
template<class... Ts>
|
||||||
struct overloads: Ts...
|
struct overloads: Ts...
|
||||||
|
|
@ -71,7 +69,7 @@ struct overloads: Ts...
|
||||||
|
|
||||||
System::System(memory::Ref<ecs::Registry> registry): m_registry(std::move(registry))
|
System::System(memory::Ref<ecs::Registry> registry): m_registry(std::move(registry))
|
||||||
{
|
{
|
||||||
ensure(m_registry, "Failed to initialize input system: null registry");
|
debug::ensure(m_registry, "Failed to initialize input system: null registry");
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::tick(app::TickInfo tick)
|
void System::tick(app::TickInfo tick)
|
||||||
|
|
@ -92,7 +90,7 @@ void System::tick(app::TickInfo tick)
|
||||||
// instead of brute-force checking all of them.
|
// instead of brute-force checking all of them.
|
||||||
for (auto &action : input.m_actions)
|
for (auto &action : input.m_actions)
|
||||||
{
|
{
|
||||||
auto code = action.trigger.mapped_keycode;
|
auto code = std::to_underlying(action.trigger.mapped_keycode);
|
||||||
if (code < m_keys.size() && m_keys[code])
|
if (code < m_keys.size() && m_keys[code])
|
||||||
{
|
{
|
||||||
if (action.state == InputAction::State::triggered)
|
if (action.state == InputAction::State::triggered)
|
||||||
|
|
@ -200,5 +198,3 @@ void System::on_button_release(const lt::surface::ButtonReleasedEvent &event)
|
||||||
{
|
{
|
||||||
m_buttons[event.get_button()] = false;
|
m_buttons[event.get_button()] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace lt::input
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue