Commit 491884ab authored by Matej Vašek's avatar Matej Vašek
Browse files

feat(osi): Reworked input system

(WIP)
parent 1167aa11
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
set(THIS_TARGET_NAME osi)

file(GLOB "${THIS_TARGET_NAME}_HPP" "./include/${THIS_TARGET_NAME}/*.hpp")
file(GLOB "${THIS_TARGET_NAME}_CPP" "./src/*.cpp")
file(GLOB_RECURSE "${THIS_TARGET_NAME}_HPP" "./include/${THIS_TARGET_NAME}/*.hpp")
file(GLOB_RECURSE "${THIS_TARGET_NAME}_CPP" "./src/*.cpp")

add_library(${THIS_TARGET_NAME}
    "${${THIS_TARGET_NAME}_HPP}"
+10 −6
Original line number Diff line number Diff line
#ifndef OSI_INDEX_HPP_INCLUDED
#   define OSI_INDEX_HPP_INCLUDED

#   include <osi/input/input_system.hpp>
#   include <osi/window.hpp>
#   include <osi/keyboard.hpp>
#   include <osi/mouse.hpp>
@@ -18,9 +19,10 @@ struct Index final
    com::Folder* runners() const { return m_runners; }
    com::Folder* updaters() const { return m_updaters; }
    com::Folder* presenters() const { return m_presenters; }
    InputSystem* input_system() const { return m_input_system; }
    Window const* window() const { return m_window; }
    Keyboard const* keyboard() const { return m_keyboard; }
    Mouse const* mouse() const { return m_mouse; }
    OldKeyboard const* keyboard() const { return m_keyboard; }
    OldMouse const* mouse() const { return m_mouse; }
    Timer const* timer() const { return m_timer; }
    Termination* termination() const { return m_termination; }
    Data const* data() const { return m_data; }
@@ -35,9 +37,10 @@ private:
    com::Folder* m_runners;
    com::Folder* m_updaters;
    com::Folder* m_presenters;
    InputSystem* m_input_system;
    Window* m_window;
    Keyboard* m_keyboard;
    Mouse* m_mouse;
    OldKeyboard* m_keyboard;
    OldMouse* m_mouse;
    Timer* m_timer;
    Termination* m_termination;
    Data* m_data;
@@ -47,9 +50,10 @@ inline Index const& index() { return Index::instance(); }
inline com::Folder* runners() { return index().runners(); }
inline com::Folder* updaters() { return index().updaters(); }
inline com::Folder* presenters() { return index().presenters(); }
inline InputSystem* input_system() { return index().input_system(); }
inline Window const* window() { return index().window(); }
inline Keyboard const* keyboard() { return index().keyboard(); }
inline Mouse const* mouse() { return index().mouse(); }
inline OldKeyboard const* keyboard() { return index().keyboard(); }
inline OldMouse const* mouse() { return index().mouse(); }
inline Timer const* timer() { return index().timer(); }
inline Termination* termination() { return index().termination(); }
inline Data const* data() { return index().data(); }
+9 −0
Original line number Diff line number Diff line
ACTIVE     ACTUATED      ACTUATED == ACTIVE      ACTION
N          N             N                       nothing
Y          N             N                       nothing
N          Y             N                       actuated becomes active, then forward
Y          Y             N                       nothing
N          N             Y                       forward, then look for another one
Y          N             Y                       cant happen
N          Y             Y                       cant happen
Y          Y             Y                       forward
 No newline at end of file
+53 −0
Original line number Diff line number Diff line
#ifndef AGE_APP_TEMPLATE_INPUT_BINDING_HPP
#define AGE_APP_TEMPLATE_INPUT_BINDING_HPP

#include "input_binding_base.hpp"

namespace osi
{
    template<typename TValue> struct InputAction;

    template<class TValue>
    struct InputBinding : InputBindingBase<TValue>
    {
        InputBinding(std::string const& name, InputControl<TValue>* control, std::vector<InputProcessorDescriptor<TValue>> processor_descs = {})
            : InputBindingBase<TValue>(name, processor_descs), m_control(control)
        {
            m_control->on_actuated += [this](InputContext<TValue>& ctx) {
                ctx.init(this, false);
                this->process(ctx);
                this->write_context(ctx);
            };
        }

        protected:
        friend struct InputAction<TValue>;
        InputProcessor<TValue>* default_interaction_processor() const override
        {
            return m_control->default_interaction_processor();
        }

        private:
        InputControl<TValue>* m_control;
    };

    template<typename TValue>
    struct InputBindingDescriptor : InputBindingDescriptorBase<TValue>
    {
        explicit InputBindingDescriptor(InputControl<TValue>* ctrl, std::vector<InputProcessorDescriptor<TValue>> proc_descs = {})
        {
            this->factory = [ctrl, processor_descs = std::move(proc_descs)](com::Folder* parent, std::string const& action_name) {
                return parent->push_back<InputBinding<TValue>>(ctrl->name() + "_" + action_name + "_binding", ctrl, processor_descs);
            };
        }
    };

    // Factory syntax helper
    template<typename TValue>
    InputBindingDescriptor<TValue> binding(InputControl<TValue>* control, std::vector<InputProcessorDescriptor<TValue>> proc_descs = {})
    {
        return InputBindingDescriptor<TValue>{control, std::move(proc_descs)};
    }
}

#endif //AGE_APP_TEMPLATE_INPUT_BINDING_HPP
 No newline at end of file
+25 −0
Original line number Diff line number Diff line
#ifndef AGE_APP_TEMPLATE_INPUT_BINDING_BASE_HPP
#define AGE_APP_TEMPLATE_INPUT_BINDING_BASE_HPP

#include "osi/input/controls/input_control.hpp"

namespace osi
{
    template<typename TValue> struct InputAction;

    template<class TValue>
    struct InputBindingBase : InputState<TValue>
    {
        using InputState<TValue>::InputState;

        friend struct InputAction<TValue>;
    };

    template<typename TValue>
    struct InputBindingDescriptorBase
    {
        std::function<InputBindingBase<TValue>*(com::Folder*, std::string const&)> factory;
    };
}

#endif //AGE_APP_TEMPLATE_INPUT_BINDING_BASE_HPP
 No newline at end of file
Loading