Adding basic keyboard input

This commit is contained in:
Dynamitos
2023-11-17 22:31:26 +01:00
parent 897eda18b0
commit ec760e8deb
18 changed files with 167 additions and 90 deletions
+3
View File
@@ -5,6 +5,8 @@ target_sources(Engine
ComponentSystem.h
Executor.h
Executor.cpp
KeyboardInput.h
KeyboardInput.cpp
LightGather.h
LightGather.cpp
MeshUpdater.h
@@ -19,6 +21,7 @@ target_sources(Engine
CameraUpdater.h
ComponentSystem.h
Executor.h
KeyboardInput.h
LightGather.h
MeshUpdater.h
SystemBase.h
+51
View File
@@ -0,0 +1,51 @@
#include "KeyboardInput.h"
using namespace Seele;
using namespace Seele::System;
KeyboardInput::KeyboardInput(PScene scene)
: ComponentSystem<Component::KeyboardInput>(scene)
{
}
KeyboardInput::~KeyboardInput()
{
}
void KeyboardInput::update(Component::KeyboardInput& input)
{
std::memcpy(input.keys.data(), keys.data(), sizeof(keys));
input.deltaX = deltaX;
input.deltaY = deltaY;
input.mouseX = mouseX;
input.mouseY = mouseY;
input.mouse1 = mouse1;
input.mouse2 = mouse2;
}
void KeyboardInput::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
{
keys[code] = action != InputAction::RELEASE;
}
void KeyboardInput::mouseCallback(double x, double y)
{
mouseX = x;
mouseY = y;
deltaX = x - lastMouseX;
deltaY = y - lastMouseY;
lastMouseX = x;
lastMouseY = y;
}
void KeyboardInput::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier)
{
if (button == MouseButton::MOUSE_BUTTON_1)
{
mouse1 = action != InputAction::RELEASE;
}
if (button == MouseButton::MOUSE_BUTTON_2)
{
mouse2 = action != InputAction::RELEASE;
}
}
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include "ComponentSystem.h"
#include "Component/KeyboardInput.h"
namespace Seele
{
namespace System
{
class KeyboardInput : public ComponentSystem<Component::KeyboardInput>
{
public:
KeyboardInput(PScene scene);
virtual ~KeyboardInput();
virtual void update(Component::KeyboardInput& input) override;
void keyCallback(KeyCode code, InputAction action, KeyModifier modifier);
void mouseCallback(double xPos, double yPos);
void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier);
private:
Seele::StaticArray<bool, (size_t)KeyCode::KEY_LAST> keys;
bool mouse1 = false;
bool mouse2 = false;
float lastMouseX = 0;
float lastMouseY = 0;
float mouseX = 0;
float mouseY = 0;
float deltaX = 0;
float deltaY = 0;
};
DEFINE_REF(KeyboardInput)
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
using namespace Seele;
void SystemGraph::addSystem(System::UPSystemBase system)
void SystemGraph::addSystem(System::OSystemBase system)
{
systems.add(std::move(system));
}
+2 -2
View File
@@ -7,10 +7,10 @@ namespace Seele
class SystemGraph
{
public:
void addSystem(System::UPSystemBase system);
void addSystem(System::OSystemBase system);
void run(dp::thread_pool<>& threadPool, float deltaTime);
private:
Array<System::UPSystemBase> systems;
Array<System::OSystemBase> systems;
};
DEFINE_REF(SystemGraph)
} // namespace Seele;