Interpolates states for component.
25 auto* entitysStates = stateholder.GetEntityStates(entity);
29 entitycomponent->StateMarked =
false;
30 return std::make_tuple(
false, StateT());
35 if(!entitycomponent->InterpolatingStartState ||
36 !entitysStates->IsStateValid(entitycomponent->InterpolatingStartState))
38 entitycomponent->InterpolatingEndState =
nullptr;
39 entitycomponent->InterpolatingStartState = entitysStates->GetOldest();
41 if(!entitycomponent->InterpolatingStartState){
44 entitycomponent->StateMarked =
false;
45 return std::make_tuple(
false, StateT());
49 if(entitycomponent->InterpolatingStartTime != 0.f){
51 if(entitycomponent->InterpolatingRemoteStartTick !=
52 entitycomponent->InterpolatingStartState->TickNumber)
61 const float currentTime =
static_cast<float>((currenttick *
TICKSPEED) + timeintick);
64 if(!entitycomponent->InterpolatingEndState){
69 entitycomponent->InterpolatingEndState = entitysStates->GetMatchingOrNewer(
70 entitycomponent->InterpolatingStartState->TickNumber + 1);
72 if(!entitycomponent->InterpolatingEndState){
75 entitycomponent->StateMarked =
false;
79 return std::make_tuple(
true, *entitycomponent->InterpolatingStartState);
84 if(entitycomponent->InterpolatingStartTime == 0.f){
85 entitycomponent->InterpolatingStartTime = currentTime;
86 entitycomponent->InterpolatingRemoteStartTick =
87 entitycomponent->InterpolatingStartState->TickNumber;
91 const float passed = currentTime - entitycomponent->InterpolatingStartTime;
96 return std::make_tuple(
true, *entitycomponent->InterpolatingStartState);
101 const auto duration = std::min((
102 entitycomponent->InterpolatingEndState->TickNumber -
103 entitycomponent->InterpolatingStartState->TickNumber) *
TICKSPEED,
106 if(passed == duration)
107 return std::make_tuple(
true, *entitycomponent->InterpolatingEndState);
110 if(passed > duration){
112 entitycomponent->InterpolatingStartState = entitycomponent->InterpolatingEndState;
113 entitycomponent->InterpolatingEndState =
nullptr;
118 return Interpolate(stateholder, entity, entitycomponent, currenttick, timeintick);
121 const float progress = passed / duration;
123 return std::make_tuple(
true, entitycomponent->InterpolatingStartState->Interpolate(
124 *entitycomponent->InterpolatingEndState, progress));
constexpr auto INTERPOLATION_TIME
constexpr auto TICKSPEED
Number of milliseconds between engine and world ticks.
static std::tuple< bool, StateT > Interpolate(const StateHolder< StateT > &stateholder, ObjectID entity, ComponentT *entitycomponent, int currenttick, int timeintick)
Interpolates states for component.
static void AdjustClock(ComponentT &entitycomponent)