Adding basic keyboard input
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
void SystemGraph::addSystem(System::UPSystemBase system)
|
||||
void SystemGraph::addSystem(System::OSystemBase system)
|
||||
{
|
||||
systems.add(std::move(system));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user