public void ResetValues() { vitalData = vitalDef.GetDefaultData(); /// Notify UI and other subscribed components of change for (int i = 0; i < OnValueChangeCallbacks.Count; ++i) { OnValueChangeCallbacks[i].OnVitalValueChange(this); } }
public VitalData Deserialize(byte[] buffer, ref int bitposition, bool keyframe = true) { double val = (keyframe || buffer.ReadBool(ref bitposition)) ? (double)buffer.Read(ref bitposition, bitsForValue) : double.NegativeInfinity; VitalData data = new VitalData( val, (int)(buffer.ReadBool(ref bitposition) ? buffer.Read(ref bitposition, bitsForDecayDelay) : 0), (int)(buffer.ReadBool(ref bitposition) ? buffer.Read(ref bitposition, bitsForRegenDelay) : 0) ); return(data); }
public VitalData Extrapolate(VitalData prev) { int ticksuntilregen = prev.ticksUntilRegen > 0 ? prev.ticksUntilRegen - 1 : 0; int ticksuntildecay = prev.ticksUntilDecay > 0 ? prev.ticksUntilDecay - 1 : 0; double preval = prev.Value; double val = (preval > FullValue && ticksuntildecay == 0) ? preval - _decayPerTick : (preval < FullValue && ticksuntilregen == 0) ? preval + _regenPerTick : preval; return(new VitalData(val, ticksuntildecay, ticksuntilregen)); }
public SerializationFlags Serialize(VitalData vitalData, VitalData prevVitalData, byte[] buffer, ref int bitposition, bool keyframe = true) { var ticksuntildecay = vitalData.ticksUntilDecay; var ticksuntilregen = vitalData.ticksUntilRegen; //if (keyframe) //{ // buffer.Write((ulong)vitalData.Value, ref bitposition, bitsForValue); // return SerializationFlags.HasChanged; //} //else int newval = (int)vitalData.Value; int prevval = (int)prevVitalData.Value; bool haschanged = newval != prevval; if (keyframe) { buffer.Write((ulong)newval, ref bitposition, bitsForValue); } else { buffer.WriteBool(haschanged, ref bitposition); if (haschanged) { buffer.Write((ulong)newval, ref bitposition, bitsForValue); } } /// We always write the ticks until, even if we are marking this as having no content. if (ticksuntildecay > 0) { buffer.WriteBool(true, ref bitposition); buffer.Write((ulong)ticksuntildecay, ref bitposition, bitsForDecayDelay); } else { buffer.WriteBool(false, ref bitposition); } if (ticksuntilregen > 0) { buffer.WriteBool(true, ref bitposition); buffer.Write((ulong)ticksuntilregen, ref bitposition, bitsForRegenDelay); } else { buffer.WriteBool(false, ref bitposition); } return((haschanged || keyframe) ? SerializationFlags.HasContent : SerializationFlags.None); }
public void Apply(VitalData vdata) { Value = vdata.Value; vitalData.ticksUntilDecay = vdata.ticksUntilDecay; vitalData.ticksUntilRegen = vdata.ticksUntilRegen; }