wip: convert from include style to module import style :D
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
light7734 2025-11-06 19:16:37 +03:30
parent 63cb6dfe92
commit 273f1e2006
Signed by: light7734
GPG key ID: 8C30176798F1A6BA
6 changed files with 49 additions and 74 deletions

View file

@ -1,4 +1,11 @@
add_library_module(NAME input INTERFACES system.cpp)
target_link_libraries(input PUBLIC surface math logger tbb)
add_library_module(
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)

View file

@ -1,10 +1,7 @@
#pragma once
export module input.codes;
import std;
#include <cstdint>
enum : uint16_t
{
export enum class Key: std::uint16_t {
/* digits */
D0 = 48,
D1 = 49,
@ -173,24 +170,4 @@ enum : uint16_t
Pause = 284,
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

View file

@ -1,19 +1,17 @@
export module input.components;
#include <vector>
export module input.system:components;
import input.codes;
import std;
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 : uint8_t
enum class State : std::uint8_t
{
inactive,
active,
@ -28,18 +26,18 @@ struct InputAction
Trigger trigger;
};
class InputComponent
export class InputComponent
{
public:
InputComponent() = default;
auto add_action(InputAction action) -> size_t
auto add_action(InputAction action) -> std::size_t
{
m_actions.emplace_back(std::move(action));
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];
}

View file

@ -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 {
class AnalogEvent
export class AnalogEvent
{
public:
AnalogEvent(uint32_t input_code, math::uvec2 pointer_position)
: m_input_code(input_code)
AnalogEvent(Key key, math::uvec2 pointer_position)
: m_key(key)
, 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
@ -25,20 +28,14 @@ public:
[[nodiscard]] auto to_string() const -> std::string
{
auto stream = std::stringstream {};
const auto &[x, y] = m_pointer_position;
stream << "input::AnalogEvent: " << m_input_code << " @ " << x << ", " << y;
return stream.str();
return std::format("input::AnalogEvent: {} @ {}, {}", std::to_underlying(m_key), x, y);
}
private:
uint32_t m_input_code;
Key m_key;
math::uvec2 m_pointer_position;
};
class AxisEvent
{
};
} // namespace lt::input

View file

@ -1,11 +1,14 @@
#pragma once
#include <app/system.hpp>
#include <ecs/registry.hpp>
#include <memory/reference.hpp>
#include <surface/components.hpp>
#include <surface/events/keyboard.hpp>
#include <surface/events/mouse.hpp>
export module input.system;
export import :components;
import logger;
import app.system;
import debug.assertions;
import ecs.registry;
import memory.reference;
import surface.system;
import surface.events;
import math.vec2;
import std;
namespace lt::input {
@ -56,12 +59,7 @@ private:
module :private;
#include <input/components.hpp>
#include <input/system.hpp>
#include <memory/reference.hpp>
namespace lt::input {
using namespace lt::input;
template<class... Ts>
struct overloads: Ts...
@ -71,7 +69,7 @@ struct overloads: Ts...
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)
@ -92,7 +90,7 @@ void System::tick(app::TickInfo tick)
// instead of brute-force checking all of them.
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 (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;
}
} // namespace lt::input