a6548a72b3
# Conflicts: # include/Engine/Collision/CollidableOctreeSystem.h # include/Engine/Collision/CollisionSystem.h # include/Engine/Collision/TriggerSystem.h # include/Engine/Rendering/RenderSystem.h # include/Game/Systems/PlayerSystem.h # resources/Schema/Components/Physics.xsd # resources/Schema/Types/Entity.xsd # src/Engine/Rendering/RenderSystem.cpp # src/Engine/Rendering/Renderer.cpp # src/Game/Game.cpp # src/Game/Systems/HealthSystem.cpp # src/Game/Systems/PlayerSystem.cpp # src/Tests/OctTreeTestGameClass.cpp
54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
#ifndef Systems_InterpolationSystem_h__
|
|
#define Systems_InterpolationSystem_h__
|
|
|
|
#include <queue>
|
|
#include <unordered_map>
|
|
#include <boost/shared_array.hpp>
|
|
#include <glm/common.hpp>
|
|
#include <glm/gtc/quaternion.hpp>
|
|
|
|
#include "Common.h"
|
|
#include "Core/System.h"
|
|
#include "Core/EventBroker.h"
|
|
|
|
#include "Network/EInterpolate.h"
|
|
|
|
#define SNAPSHOTINTERVAL 0.05f
|
|
|
|
class InterpolationSystem : public PureSystem
|
|
{
|
|
struct Transform
|
|
{
|
|
glm::vec3 Position;
|
|
glm::vec3 Scale;
|
|
glm::quat Orientation;
|
|
double interpolationTime;
|
|
};
|
|
public:
|
|
InterpolationSystem(World* world, EventBroker* eventBroker)
|
|
: System(world, eventBroker)
|
|
, PureSystem("Transform")
|
|
{
|
|
EVENT_SUBSCRIBE_MEMBER(m_EInterpolate, &InterpolationSystem::OnInterpolate);
|
|
}
|
|
~InterpolationSystem() { }
|
|
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& transform, double dt) override;
|
|
private:
|
|
std::unordered_map<EntityID, Transform> m_NextTransform;
|
|
std::unordered_map<EntityID, Transform> m_LastReceivedTransform;
|
|
|
|
//glm::vec3 vectorInterpolation(glm::vec3 prev, glm::vec3 next, double currentTime);
|
|
template <typename T>
|
|
T vectorInterpolation(T prev, T next, double currentTime)
|
|
{
|
|
T difference = next - prev;
|
|
T vector = (difference / SNAPSHOTINTERVAL) * static_cast<float>(currentTime);
|
|
return vector;
|
|
}
|
|
|
|
EventRelay<InterpolationSystem, Events::Interpolate> m_EInterpolate;
|
|
bool InterpolationSystem::OnInterpolate(const Events::Interpolate& e);
|
|
};
|
|
|
|
#endif
|