Working 1-snapshot interpolation
This commit is contained in:
@@ -16,26 +16,39 @@
|
||||
|
||||
#include "Network/EInterpolate.h"
|
||||
|
||||
class InterpolationSystem : public PureSystem
|
||||
class InterpolationSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
InterpolationSystem(SystemParams params);
|
||||
~InterpolationSystem() { }
|
||||
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& transform, double dt) override;
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
private:
|
||||
struct Transform
|
||||
template <typename T>
|
||||
struct Interpolation
|
||||
{
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Scale;
|
||||
glm::quat Orientation;
|
||||
float interpolationTime;
|
||||
Interpolation(const ComponentWrapper& Component, const std::string& Field, const T& Start, const T& Goal)
|
||||
: Component(Component)
|
||||
, Field(Field)
|
||||
, Start(Start)
|
||||
, Goal(Goal)
|
||||
{ }
|
||||
|
||||
ComponentWrapper Component;
|
||||
std::string Field;
|
||||
T Start;
|
||||
T Goal;
|
||||
double Alpha = 0.0;
|
||||
};
|
||||
|
||||
std::unordered_map<EntityID, Transform> m_NextTransform;
|
||||
std::unordered_map<EntityID, Transform> m_LastReceivedTransform;
|
||||
EntityWrapper m_LocalPlayer = EntityWrapper::Invalid;
|
||||
float m_SnapshotInterval;
|
||||
std::unordered_map<EntityWrapper, Interpolation<glm::vec3>> m_InterpolatePosition;
|
||||
std::unordered_map<EntityWrapper, Interpolation<glm::quat>> m_InterpolateOrientation;
|
||||
std::unordered_map<EntityWrapper, Interpolation<glm::vec3>> m_InterpolateVelocity;
|
||||
|
||||
EventRelay<InterpolationSystem, Events::Interpolate> m_EInterpolate;
|
||||
bool InterpolationSystem::OnInterpolate(Events::Interpolate& e);
|
||||
|
||||
template <typename T>
|
||||
T vectorInterpolation(T prev, T next, double currentTime)
|
||||
@@ -44,12 +57,6 @@ private:
|
||||
T vector = difference * (static_cast<float>(currentTime) / m_SnapshotInterval);
|
||||
return vector;
|
||||
}
|
||||
float m_SnapshotInterval;
|
||||
|
||||
EventRelay<InterpolationSystem, Events::Interpolate> m_EInterpolate;
|
||||
bool InterpolationSystem::OnInterpolate(Events::Interpolate& e);
|
||||
EventRelay<InterpolationSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user