Fixed input
This commit is contained in:
@ -32,6 +32,7 @@ void Game::update() {
|
||||
}
|
||||
|
||||
timeManager.update();
|
||||
inputManager.update();
|
||||
if(currentScene) currentScene->update();
|
||||
renderHost.update(shared_from_this());
|
||||
}
|
||||
|
@ -5,17 +5,17 @@
|
||||
|
||||
#pragma once
|
||||
#include "util/Math.hpp"
|
||||
#include "input/InputBinds.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class DawnGame;
|
||||
typedef int_fast16_t inputbind_t;
|
||||
|
||||
template<typename T>
|
||||
class IInputManager {
|
||||
protected:
|
||||
std::unordered_map<inputbind_t, std::vector<T>> binds;
|
||||
std::unordered_map<inputbind_t, float_t> valuesLeft;
|
||||
std::unordered_map<inputbind_t, float_t> valuesRight;
|
||||
std::unordered_map<enum InputBind, std::vector<T>> binds;
|
||||
std::unordered_map<enum InputBind, float_t> valuesLeft;
|
||||
std::unordered_map<enum InputBind, float_t> valuesRight;
|
||||
bool_t currentIsLeft = true;
|
||||
|
||||
/**
|
||||
@ -34,7 +34,7 @@ namespace Dawn {
|
||||
* @param bind Bind to bind the axis to.
|
||||
* @param axis Axis to use for this bind.
|
||||
*/
|
||||
void bind(const inputbind_t bind, const T axis) {
|
||||
void bind(const enum InputBind bind, const T axis) {
|
||||
this->binds[bind].push_back(axis);
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ namespace Dawn {
|
||||
*
|
||||
* @param bind Bind to remove all binds from.
|
||||
*/
|
||||
void unbind(const inputbind_t bind) {
|
||||
void unbind(const enum InputBind bind) {
|
||||
this->binds[bind].clear();
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ namespace Dawn {
|
||||
* @param bind Bind to get the value of.
|
||||
* @return The current input state (between 0 and 1).
|
||||
*/
|
||||
float_t getValue(const inputbind_t bind) {
|
||||
float_t getValue(const enum InputBind bind) {
|
||||
if(this->currentIsLeft) {
|
||||
auto exist = this->valuesLeft.find(bind);
|
||||
return exist == this->valuesLeft.end() ? 0.0f : exist->second;
|
||||
@ -77,7 +77,7 @@ namespace Dawn {
|
||||
* @param bind Bind to get the value of.
|
||||
* @return The value of the bind, last frame.
|
||||
*/
|
||||
float_t getValueLastUpdate(const inputbind_t bind) {
|
||||
float_t getValueLastUpdate(const enum InputBind bind) {
|
||||
if(this->currentIsLeft) {
|
||||
auto exist = this->valuesRight.find(bind);
|
||||
return exist == this->valuesRight.end() ? 0.0f : exist->second;
|
||||
@ -99,15 +99,15 @@ namespace Dawn {
|
||||
* @param positive Bind to use for the positive axis.
|
||||
* @return A value between -1 and 1.
|
||||
*/
|
||||
float_t getAxis(const inputbind_t negative, const inputbind_t positive) {
|
||||
float_t getAxis(const enum InputBind negative, const enum InputBind positive) {
|
||||
return -getValue(negative) + getValue(positive);
|
||||
}
|
||||
|
||||
glm::vec2 getAxis2D(
|
||||
const inputbind_t negativeX,
|
||||
const inputbind_t positiveX,
|
||||
const inputbind_t negativeY,
|
||||
const inputbind_t positiveY
|
||||
const enum InputBind negativeX,
|
||||
const enum InputBind positiveX,
|
||||
const enum InputBind negativeY,
|
||||
const enum InputBind positiveY
|
||||
) {
|
||||
return glm::vec2(
|
||||
getAxis(negativeX, positiveX),
|
||||
@ -122,7 +122,7 @@ namespace Dawn {
|
||||
* @param y Y Axis bind.
|
||||
* @return 2D vector of the two given input binds.
|
||||
*/
|
||||
glm::vec2 getAxis2D(const inputbind_t x, const inputbind_t y) {
|
||||
glm::vec2 getAxis2D(const enum InputBind x, const enum InputBind y) {
|
||||
return glm::vec2(getValue(x), getValue(y));
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ namespace Dawn {
|
||||
* @param bind Bind to check if pressed.
|
||||
* @return True if value is non-zero, or false for zero.
|
||||
*/
|
||||
bool_t isDown(const inputbind_t bind) {
|
||||
bool_t isDown(const enum InputBind bind) {
|
||||
return this->getValue(bind) != 0.0f;
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ namespace Dawn {
|
||||
* @param bind Bind to check if pressed.
|
||||
* @return True if down this frame and not down last frame.
|
||||
*/
|
||||
bool_t isPressed(const inputbind_t bind) {
|
||||
bool_t isPressed(const enum InputBind bind) {
|
||||
return this->getValue(bind) != 0 && this->getValueLastUpdate(bind) == 0;
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ namespace Dawn {
|
||||
* @param bind Bind to check if released.
|
||||
* @return True if up this frame, and down last frame.
|
||||
*/
|
||||
bool_t wasReleased(const inputbind_t bind) {
|
||||
bool_t wasReleased(const enum InputBind bind) {
|
||||
return this->getValue(bind) == 0 && this->getValueLastUpdate(bind) != 0;
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,32 @@ glm::quat SceneItemTransform::getLocalRotation() {
|
||||
return this->localRotation;
|
||||
}
|
||||
|
||||
void SceneItemTransform::setParent(std::shared_ptr<SceneItem> parent) {
|
||||
if(this->parent.lock() == parent) return;
|
||||
|
||||
auto self = dynamic_cast<SceneItem*>(this);
|
||||
assertNotNull(self, "Cannot set parent of null item?");
|
||||
|
||||
if(auto oldParent = this->parent.lock()) {
|
||||
auto &children = oldParent->children;
|
||||
children.erase(
|
||||
std::remove_if(
|
||||
children.begin(),
|
||||
children.end(),
|
||||
[self](std::weak_ptr<SceneItem> &item) {
|
||||
return item.lock() == self->shared_from_this();
|
||||
}
|
||||
),
|
||||
children.end()
|
||||
);
|
||||
}
|
||||
this->parent = parent;
|
||||
if(auto newParent = this->parent.lock()) {
|
||||
newParent->children.push_back(self->shared_from_this());
|
||||
}
|
||||
this->updateWorldTransformFromParent();
|
||||
}
|
||||
|
||||
void SceneItemTransform::setLocalTransform(const glm::mat4 transform) {
|
||||
this->transformLocal = transform;
|
||||
this->updateLocalValuesFromLocalTransform();
|
||||
|
@ -106,6 +106,13 @@ namespace Dawn {
|
||||
* @return Local rotation of this item.
|
||||
*/
|
||||
glm::quat getLocalRotation();
|
||||
|
||||
/**
|
||||
* Sets the parent of this item.
|
||||
*
|
||||
* @param parent Parent of this item.
|
||||
*/
|
||||
void setParent(std::shared_ptr<SceneItem> parent);
|
||||
|
||||
/**
|
||||
* Sets the transform of this item within local space (relative to parent)
|
||||
|
Reference in New Issue
Block a user