/// <summary> /// Interpolate the <see cref="DeusVector2"/> of the object /// The next <see cref="DeusVector2"/> of the object is : /// newPos = start + (end-start) x (time_elsapsed_since_start / duration_bewteen_start_and_end) /// </summary> /// <param name="dataBeforeTimestamp">The origin</param> /// <param name="dataAfterTimestamp">The destination</param> /// <param name="currentMs">The current time</param> /// <returns>The <see cref="DeusVector2"/> we interpolate</returns> protected override DeusVector2 Interpolate(DataTimed <DeusVector2> dataBeforeTimestamp, DataTimed <DeusVector2> dataAfterTimestamp, uint currentMs) { DeusVector2 result = dataBeforeTimestamp.Data + (dataAfterTimestamp.Data - dataBeforeTimestamp.Data) * (float)((float)(currentMs - dataBeforeTimestamp.TimeStampMs) / (float)(dataAfterTimestamp.TimeStampMs - dataBeforeTimestamp.TimeStampMs)); //Console.WriteLine($"BEFORE : {dataBeforeTimestamp} | AFTER : {dataAfterTimestamp} | RESULT : [{currentMs}]{result}"); return(result); }
public void InsertData(DataTimed <T> dataTimed) { if (dataTimed == null || dataTimed.Data == null) { throw new DeusException("Try to insert null value"); } // We delete all the futur datas that arn't valid anymore m_dataWithTime.RemoveAll(dt => dt.TimeStampMs >= dataTimed.TimeStampMs); // then we add our data m_dataWithTime.Add(dataTimed); }
public object GetViewValue(uint timeStampMs = 0) { uint currentTimeStamp = timeStampMs <= 0 ? TimeHelper.GetUnixMsTimeStamp() : timeStampMs; DataTimed <T> beforeTimeStamp = GetValueAtTime(currentTimeStamp, WANT_DATA_BEFORE_TIMESTAMP); DataTimed <T> afterTimeStamp = GetValueAtTime(currentTimeStamp, !WANT_DATA_BEFORE_TIMESTAMP); if (beforeTimeStamp != null && afterTimeStamp != null) // we are between 2 value -> interpolate { //Console.WriteLine("Interpolate"); return(Interpolate(beforeTimeStamp, afterTimeStamp, currentTimeStamp)); } else if (beforeTimeStamp != null) // only data before timestamp -> Extrapolate { return(Extrapolate(beforeTimeStamp, currentTimeStamp)); } else // no data found or only after the timestamp -> return null; { return(null); } }
public void Deserialize(byte[] packetsBuffer, ref int index) { uint tmpComponentId = 0; Serializer.DeserializeData(packetsBuffer, ref index, out tmpComponentId); ComponentId = tmpComponentId; ComponentType = (EComponentType)packetsBuffer[index]; index++; bool thereIsOrigin = false; Serializer.DeserializeData(packetsBuffer, ref index, out thereIsOrigin); if (thereIsOrigin) { DataTimed <T> tmpOrigin = new DataTimed <T>(); Serializer.DeserializeData(packetsBuffer, ref index, out tmpOrigin); Origin = tmpOrigin; } else { Origin = null; } bool thereIsDestination = false; Serializer.DeserializeData(packetsBuffer, ref index, out thereIsDestination); if (thereIsDestination) { DataTimed <T> tmpDestination = new DataTimed <T>(default(T), 0); Serializer.DeserializeData(packetsBuffer, ref index, out tmpDestination); Destination = tmpDestination; } else { Destination = null; } }
protected override SkillInfos Interpolate(DataTimed <SkillInfos> dataBeforeTimestamp, DataTimed <SkillInfos> dataAfterTimestamp, uint currentMs) { return(dataBeforeTimestamp.Data); }
public SkillTimeLineComponent(uint identifier, uint objectIdentifier, DataTimed <SkillInfos> origin, DataTimed <SkillInfos> destination = null) : base(true, identifier, objectIdentifier, EComponentType.SkillComponent, origin, destination) { }
public TimeLineComponent(bool needRealtimeUpdateView, uint identifier, uint objectIdentifier, EComponentType type, DataTimed <T> origin, DataTimed <T> destination = null) : base(identifier, objectIdentifier, type) { RealtimeViewUpdate = needRealtimeUpdateView; m_componentType = type; if (origin != null) { InsertData(origin); } if (destination != null) { InsertData(destination); } }
protected abstract T Extrapolate(DataTimed <T> dataBeforeTimestamp, uint currentMs);
protected abstract T Interpolate(DataTimed <T> dataBeforeTimestamp, DataTimed <T> dataAfterTimestamp, uint currentMs);
/// <summary> /// When we extrapolate a data, we just give the last one : the player isn't moving /// </summary> /// <param name="dataBeforeTimestamp">The last data known</param> /// <param name="currentMs">The current time</param> /// <returns>The <see cref="DeusVector2"/> we extrapolate</returns> protected override DeusVector2 Extrapolate(DataTimed <DeusVector2> dataBeforeTimestamp, uint currentMs) { return(dataBeforeTimestamp.Data); }
public PositionTimeLineComponent(uint identifier, uint objectIdentifier, DataTimed <DeusVector2> origin, DataTimed <DeusVector2> destination) : base(true, identifier, objectIdentifier, EComponentType.PositionComponent, origin, destination) { }
protected override int Interpolate(DataTimed <int> dataBeforeTimestamp, DataTimed <int> dataAfterTimestamp, uint currentMs) { return(dataBeforeTimestamp.Data); }
protected override int Extrapolate(DataTimed <int> dataBeforeTimestamp, uint currentMs) { return(dataBeforeTimestamp.Data); }
/// <summary> /// Create <see cref="HealthTimeLineComponent"/> /// We specify with the 'base(false)' that we don't want our ViewComponent to bypass the event queue, /// and the view component will only be updated by handling <see cref="Packets.PacketUpdateViewObject"/> packets /// </summary> public HealthTimeLineComponent(uint identifier, uint objectIdentifier, DataTimed <int> origin, DataTimed <int> destination) : base(false, identifier, objectIdentifier, EComponentType.HealthComponent, origin, destination) // This component doesn't have its view updated in at each update loop { }