cryptomaxC
Normal2y ago
20 replies
cryptomax

How is StopWatch Recipe updating other clients?

I dont see a didchange event in this model so how is this starting the stop watch on clients other than the one who started the stopwatch model?

using Normal.Realtime;
using Normal.Realtime.Serialization;

[RealtimeModel]
public partial class StopWatchModel {
[RealtimeProperty(1, true)] private double _startTime;
}

/* ----- Begin Normal Autogenerated Code ----- */
public partial class StopWatchModel : RealtimeModel {
public double startTime {
get {
return _startTimeProperty.value;
}
set {
if (_startTimeProperty.value == value) return;
_startTimeProperty.value = value;
InvalidateReliableLength();
}
}

public enum PropertyID : uint {
StartTime = 1,
}

#region Properties

private ReliableProperty<double> _startTimeProperty;

#endregion

public StopWatchModel() : base(null) {
_startTimeProperty = new ReliableProperty<double>(1, _startTime);
}

protected override void OnParentReplaced(RealtimeModel previousParent, RealtimeModel currentParent) {
_startTimeProperty.UnsubscribeCallback();
}

protected override int WriteLength(StreamContext context) {
var length = 0;
length += _startTimeProperty.WriteLength(context);
return length;
}

protected override void Write(WriteStream stream, StreamContext context) {
var writes = false;
writes |= _startTimeProperty.Write(stream, context);
if (writes) InvalidateContextLength(context);
}

protected override void Read(ReadStream stream, StreamContext context) {
var anyPropertiesChanged = false;
while (stream.ReadNextPropertyID(out uint propertyID)) {
var changed = false;
switch (propertyID) {
case (uint) PropertyID.StartTime: {
changed = _startTimeProperty.Read(stream, context);
break;
}
default: {
stream.SkipProperty();
break;
}
}
anyPropertiesChanged |= changed;
}
if (anyPropertiesChanged) {
UpdateBackingFields();
}
}

private void UpdateBackingFields() {
_startTime = startTime;
}

}
Solution
you don't need an extra int, just add the udpate event parameter to this model
Was this page helpful?