public void AddNetEntity(NetCreatableInfo info, INetEntity entity)
        {
            NetEntitySnapshot    snapshot = entity.CreateSnapshot(info, snapshotSystem);
            DynamicSnapshotField field    = AddNestedField(info.Id, snapshot);

            snapshotFields.Add(info.Id, field);
        }
Пример #2
0
        public void AddNetPlayer(NetworkPlayer netPlayer, bool isOwner)
        {
            DynamicSnapshotField field = AddNestedField(netPlayer.Id,
                                                        new NetworkPlayerSnapshot(snapshotSystem, OtherConnection, netPlayer, !isOwner));

            snapshotFields.Add(netPlayer.Id, field);
        }
Пример #3
0
        public void AddPlayer(ushort id, bool isAppOwner, bool isCreator)
        {
            DynamicSnapshotField field = AddNestedField(id,
                                                        new PlayerSnapshot(snapshotSystem, OtherConnection, isAppOwner, id, !isCreator));

            playerFields.Add(id, field);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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));
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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));
        }