Example #1
0
        public static uint GetChangeMask(
            NetworkedComponentTypeInfo networkedComponentTypeInfo, object newValue, object oldValue
            )
        {
            Assert.IsTrue(networkedComponentTypeInfo.ThingsToSynchronize.Count <= (8 * sizeof(uint)));

            if (oldValue == null)
            {
                return(uint.MaxValue);
            }

            uint changeMask         = 0;
            uint changeMaskBitIndex = 0;

            foreach (var field in networkedComponentTypeInfo.ThingsToSynchronize)
            {
                object oldFieldValue, newFieldValue;

                if (field.FieldInfo != null)
                {
                    oldFieldValue = field.FieldInfo.GetValue(oldValue);
                    newFieldValue = field.FieldInfo.GetValue(newValue);
                }
                else if (field.PropertyInfo != null)
                {
                    oldFieldValue = field.PropertyInfo.GetValue(oldValue);
                    newFieldValue = field.PropertyInfo.GetValue(newValue);
                }
                else
                {
                    throw new Exception("Invalid field to synchronize.");
                }

                BitUtilities.SetBit(ref changeMask, (byte)changeMaskBitIndex, !object.Equals(newFieldValue, oldFieldValue));
                changeMaskBitIndex++;
            }

            return(changeMask);
        }