Example #1
0
        void InvokeCallbacksForProperty(int propertyIndex)
        {
            try
            {
                NetworkPropertyInfo pi = Meta.Properties[propertyIndex];

                List <PropertyCallback>       callbacks;
                List <PropertyCallbackSimple> callbacksSimple;

                for (int i = 0; i < pi.Paths.Length; ++i)
                {
                    if (Callbacks.TryGetValue(pi.Paths[i], out callbacks))
                    {
                        for (int c = 0; c < callbacks.Count; ++c)
                        {
                            callbacks[c](this, pi.Paths[pi.Paths.Length - 1], new ArrayIndices(pi.Indices));
                        }
                    }

                    if (CallbacksSimple.TryGetValue(pi.Paths[i], out callbacksSimple))
                    {
                        for (int c = 0; c < callbacksSimple.Count; ++c)
                        {
                            callbacksSimple[c]();
                        }
                    }
                }
            }
            catch (Exception exn)
            {
                NetLog.Exception(exn);
            }
        }
Example #2
0
        void AddCopiedProperty(int offsetProperties, int offsetObjects, NetworkPropertyInfo property, string prefix, int arrayIndex)
        {
            AddPropertyToArray(offsetProperties, offsetObjects, property.Property);

            Properties[offsetProperties].Indices =
                (arrayIndex >= 0) && property.Property.AllowCallbacks
              ? property.Indices.AddFirst(arrayIndex)
              : ZeroIndices;

            Properties[offsetProperties].Paths =
                property.Property.AllowCallbacks
              ? property.Paths.Select(x => prefix + "." + x).ToArray().AddFirst(prefix)
              : ZeroPaths;

            if (property.Property.AllowCallbacks)
            {
                for (int i = 0; i < Properties[offsetProperties].Paths.Length; ++i)
                {
                    CallbackPaths.Add(Properties[offsetProperties].Paths[i]);
                }
            }
        }
Example #3
0
        void PackProperties(Connection connection, Packet packet, EntityProxyEnvelope env, Priority[] priority, int count)
        {
            int propertyCountPtr = packet.Position;

            packet.WriteByte(0, Meta.PacketMaxPropertiesBits);

            // how many bits can we write at the most
            int bits = System.Math.Min(Meta.PacketMaxBits, packet.Size - packet.Position);

            for (int i = 0; i < count; ++i)
            {
                // this means we can even fit another property id
                if (bits <= Meta.PropertyIdBits)
                {
                    break;
                }

                // we have written enough properties
                if (env.Written.Count == Meta.PacketMaxProperties)
                {
                    break;
                }

                Priority            p  = priority[i];
                NetworkPropertyInfo pi = Meta.Properties[p.PropertyIndex];

                if (p.PropertyPriority == 0)
                {
                    break;
                }

                int b   = Meta.PropertyIdBits + pi.Property.BitCount(Objects[pi.OffsetObjects]);
                int ptr = packet.Position;

                if (bits >= b)
                {
                    // write property id
                    packet.WriteInt(p.PropertyIndex, Meta.PropertyIdBits);

                    if (pi.Property.Write(connection, Objects[pi.OffsetObjects], Storage, packet))
                    {
#if DEBUG
                        int totalBits = packet.Position - ptr;
                        if (totalBits != b)
                        {
                            //NetLog.Warn("Property of type {0} did not write the correct amount of bits, written: {1}, expected: {2}", pi.Property, totalBits, b);
                        }
#endif

                        if (packet.Overflowing)
                        {
                            packet.Position = ptr;
                            break;
                        }

                        // use up bits
                        bits -= b;

                        // add to written list
                        env.Written.Add(p);
                    }
                    else
                    {
                        // reset position
                        packet.Position = ptr;
                    }
                }
            }

            // gotta be less then 256
            NetAssert.True(env.Written.Count <= Meta.PacketMaxProperties);

            // write the amount of properties
            Packet.WriteByteAt(packet.ByteBuffer, propertyCountPtr, Meta.PacketMaxPropertiesBits, (byte)env.Written.Count);
        }