public void AddNetEntity(NetCreatableInfo info, INetEntity entity) { NetEntitySnapshot snapshot = entity.CreateSnapshot(info, snapshotSystem); DynamicSnapshotField field = AddNestedField(info.Id, snapshot); snapshotFields.Add(info.Id, field); }
public void AddNetPlayer(NetworkPlayer netPlayer, bool isOwner) { DynamicSnapshotField field = AddNestedField(netPlayer.Id, new NetworkPlayerSnapshot(snapshotSystem, OtherConnection, netPlayer, !isOwner)); snapshotFields.Add(netPlayer.Id, field); }
public void AddPlayer(ushort id, bool isAppOwner, bool isCreator) { DynamicSnapshotField field = AddNestedField(id, new PlayerSnapshot(snapshotSystem, OtherConnection, isAppOwner, id, !isCreator)); playerFields.Add(id, field); }
protected DynamicSnapshotField AddCustomField <K>(K dynamicKey, CustomSnapshot child) where K : struct { DynamicSnapshotField field = new DynamicSnapshotField(this, dynamicKey, SnapshotFieldType.Custom, child, GetPrimitiveType(typeof(K))); dynamicFields.Add(dynamicKey, field); return(field); }
protected DynamicSnapshotField AddTrigger <K>(K dynamicKey) where K : struct { DynamicSnapshotField field = new DynamicSnapshotField(this, dynamicKey, SnapshotFieldType.Trigger, new Trigger(), GetPrimitiveType(typeof(K))); dynamicFields.Add(dynamicKey, field); return(field); }
protected bool RemoveDynamicField(DynamicSnapshotField field) { if (field.Type == SnapshotFieldType.Snapshot) { // Make sure we dispose of a delta supporting snapshots Snapshot snapshot = (Snapshot)field.Value; snapshot.Dispose(); } return(dynamicFields.Remove(field.Id)); }
protected DynamicSnapshotField AddNestedField <K>(K dynamicKey, Snapshot child) where K : struct { DynamicSnapshotField field = new DynamicSnapshotField(this, dynamicKey, SnapshotFieldType.Snapshot, child, GetPrimitiveType(typeof(K))); child.Parent = this; dynamicFields.Add(dynamicKey, field); return(field); }
protected DynamicSnapshotField AddPrimitiveField <T, K>(K dynamicKey, T defaultValue = default(T)) where T : struct where K : struct { SnapshotPrimitiveType primType = GetPrimitiveType(defaultValue.GetType()); DynamicSnapshotField field = new DynamicSnapshotField(this, dynamicKey, SnapshotFieldType.Primitive, defaultValue, GetPrimitiveType(typeof(K)), primType); dynamicFields.Add(dynamicKey, field); return(field); }
bool SerializeDynamicField(DynamicSnapshotField field, NetBuffer buffer, DeltaSnapshot prev) { // Attempt to delta compress if (prev != null && !field.NeverCompress) { if (field.Type == SnapshotFieldType.Primitive) { // If the field in the last acknowledged snapshot is the same as // what were sending, skip it object prevField; if (prev.DynamicFields.TryGetValue(field.Id, out prevField)) { if (field.Value.Equals(prevField)) { return(false); } } } else if (field.Type == SnapshotFieldType.Trigger) { // If the trigger was never activated, dont send. // Receiving end assumes that the trigger is zero when not received. Trigger ct = (Trigger)field.Value; if (ct.Iterations == 0) { return(false); } } } // Write field id buffer.Write((byte)field.IdPrimitiveType); buffer.WriteDynamic(field.Id); return(SerializeField(field, buffer, prev)); }