Improve input time scale handling

This commit is contained in:
Georg Hagen
2025-01-25 22:15:14 +01:00
parent c56d956503
commit 48b3c0745b
8 changed files with 16 additions and 7 deletions

View File

@@ -61,7 +61,7 @@ namespace OpenVulkano
Math::Vector3f_SIMD vec(input->GetAxis(m_actionSide), input->GetAxis(m_actionUp), -input->GetAxis(m_actionForward));
if (vec != Math::Vector3f_SIMD (0))
{
const float timeScale = CURRENT_FRAME.frameTime; //TODO
const float timeScale = input->GetTimeScale(); //TODO
vec = vec * timeScale * m_movementSpeedModifier; // scale vector
vec = GetCamera()->GetRotationMatrix() * Math::Vector3f(vec);
const Math::Vector4f_SIMD movement(vec, 0);

View File

@@ -32,7 +32,7 @@ namespace OpenVulkano
vec = Math::Utils::normalize(vec);
}
float timeScale = 3 * CURRENT_FRAME.frameTime; //TODO
float timeScale = 3 * input->GetTimeScale(); //TODO
vec = vec * timeScale * 3.0f; // scale vector
if (input->GetButton(m_actionBoost))
{

View File

@@ -193,7 +193,7 @@ namespace OpenVulkano
else
{
auto start = clock::now();
inputManager->Tick();
inputManager->Tick(CURRENT_FRAME.frameTime);
mainThreadTaskPool.Tick();
app->Tick();
if (CURRENT_FRAME.needsRedraw)

View File

@@ -136,8 +136,9 @@ namespace OpenVulkano::Input
return devices;
}
void InputManager::Tick()
void InputManager::Tick(double time)
{
timescale = inputTimeRange.Clamp(time);
for(InputDevice* device : devices)
{
device->Tick();

View File

@@ -9,6 +9,7 @@
#include "InputDevice.hpp"
#include "InputAction.hpp"
#include "InputShortcut.hpp"
#include "Math/Range.hpp"
#include <memory>
#include <unordered_map>
@@ -22,7 +23,7 @@ namespace OpenVulkano::Input
public:
static InputManager* GetInstance();
void Tick();
void Tick(double time);
void RegisterInputDevice(InputDevice* device)
{
@@ -53,9 +54,13 @@ namespace OpenVulkano::Input
return lastActiveDevice;
}
[[nodiscard]] float GetTimeScale() const { return timescale; }
private:
std::unordered_map<std::string, std::unique_ptr<InputAction>> actionNameMapping;
std::vector<InputDevice*> devices;
InputDevice* lastActiveDevice = nullptr;
const Math::Range<float> inputTimeRange = { 1.0f / 10000, 1.0f / 30 }; // Limit input time range from 1/10k FPS to 1/30fps
float timescale = 1.0f / 60;
};
}

View File

@@ -6,6 +6,7 @@
#pragma once
#include "Math.hpp"
#ifdef _MSC_VER
#undef min
#undef max
@@ -32,5 +33,7 @@ namespace OpenVulkano::Math
[[nodiscard]] T& GetMax() { return max; }
[[nodiscard]] T GetSize() const { return max - min; }
[[nodiscard]] T Clamp(const T& value) const { return Math::Utils::clamp(value, min, max); }
};
}

View File

@@ -44,7 +44,7 @@ namespace OpenVulkano::Scene
if (m_isMorphing)
{
m_currentTime += CURRENT_FRAME.frameTime;
m_currentTime += input->GetTimeScale();
if (m_currentTime > m_animationDuration) m_currentTime = m_animationDuration;
float t = m_currentTime / m_animationDuration;
if (t >= 1.0f)

View File

@@ -55,7 +55,7 @@ namespace OpenVulkano::Scene
if (Math::Utils::length2(direction) > 0.0f) { direction = Math::Utils::normalize(direction); }
float timeScale = CURRENT_FRAME.frameTime;
float timeScale = input->GetTimeScale();
float speed = 3.0f;
direction *= timeScale * speed;
direction = direction - Math::Utils::dot(direction, m_planeNormal) * m_planeNormal;