public void ResetValues() { vitalData = vitalDef.GetDefaultData(); /// Notify UI and other subscribed components of change for (int i = 0; i < onValueChangeCallbacks.Count; ++i) { onValueChangeCallbacks[i].OnValueChange(this); } }
public VitalData Deserialize(byte[] buffer, ref int bitposition, bool keyframe = true) { float val = (keyframe || buffer.ReadBool(ref bitposition)) ? (float)buffer.Read(ref bitposition, bitsForValue) : float.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; float preval = prev.Value; float 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.HasChanged : SerializationFlags.None); }
public void Apply(VitalData vdata) { Value = vdata.Value; vitalData.ticksUntilDecay = vdata.ticksUntilDecay; vitalData.ticksUntilRegen = vdata.ticksUntilRegen; }