/// <summary>
        /// see https://github.com/EpicGames/UnrealEngine/blob/099c2469b494de4752e9d63535767bb9fcc90d16/Engine/Source/Runtime/Core/Private/Math/UnrealMath.cpp#L832
        /// </summary>
        /// <param name="reader"></param>
        public void Serialize(NetBitReader reader)
        {
            X = reader.ReadSingle();
            Y = reader.ReadSingle();
            Z = reader.ReadSingle();

            var XYZMagSquared = (X * X + Y * Y + Z * Z);
            var WSquared      = 1.0f - XYZMagSquared;

            // If mag of (X,Y,Z) <= 1.0, then we calculate W to make magnitude of Q 1.0
            if (WSquared >= 0f)
            {
                W = (float)Math.Sqrt(WSquared);
            }
            // If mag of (X,Y,Z) > 1.0, we set W to zero, and then renormalize
            else
            {
                W = 0f;

                float XYZInvMag = (float)(1 / Math.Sqrt(XYZMagSquared));
                X *= XYZInvMag;
                Y *= XYZInvMag;
                Z *= XYZInvMag;
            }
        }
        //bool FQuat::NetSerialize(FArchive& Ar, class UPackageMap*, bool& bOutSuccess)
        public void Serialize(NetBitReader reader)
        {
            X = reader.ReadSingle();
            Y = reader.ReadSingle();
            Z = reader.ReadSingle();

            var XYZMagSquared = (X * X + Y * Y + Z * Z);
            var WSquared      = 1.0f - XYZMagSquared;
        }
示例#3
0
        /// <summary>
        /// see https://github.com/EpicGames/UnrealEngine/blob/c10022aa46e208b1593dd537c2607784aac158f1/Engine/Source/Runtime/Engine/Private/Collision/Collision.cpp#L42
        /// </summary>
        /// <param name="reader"></param>
        public void Serialize(NetBitReader reader)
        {
            // pack bitfield with flags
            // Most of the time the vectors are the same values, use that as an optimization
            BlockingHit      = reader.ReadBit();
            StartPenetrating = reader.ReadBit();
            var bImpactPointEqualsLocation = reader.ReadBit();
            var bImpactNormalEqualsNormal  = reader.ReadBit();

            // Often times the indexes are invalid, use that as an optimization
            var bInvalidItem         = reader.ReadBit();
            var bInvalidFaceIndex    = reader.ReadBit();
            var bNoPenetrationDepth  = reader.ReadBit();
            var bInvalidElementIndex = reader.EngineNetworkVersion >= EngineNetworkVersionHistory.HISTORY_ENUM_SERIALIZATION_COMPAT && reader.ReadBit();

            Time = reader.ReadSingle();

            Location = reader.ReadPackedVector(1, 20);
            Normal   = reader.SerializePropertyVectorNormal();

            ImpactPoint = !bImpactPointEqualsLocation?reader.ReadPackedVector(1, 20) : Location;

            ImpactNormal = !bImpactNormalEqualsNormal?reader.SerializePropertyVectorNormal() : Normal;

            TraceStart = reader.ReadPackedVector(1, 20);
            TraceEnd   = reader.ReadPackedVector(1, 20);

            PenetrationDepth = !bNoPenetrationDepth?reader.SerializePropertyFloat() : 0.0f;

            Distance = (ImpactPoint - TraceStart).Size();
            Item     = !bInvalidItem?reader.ReadInt32() : 0;

            PhysMaterial = reader.SerializePropertyObject();

            if (reader.EngineNetworkVersion < EngineNetworkVersionHistory.HISTORY_HITRESULT_INSTANCEHANDLE)
            {
                Actor = reader.SerializePropertyObject();
            }
            else
            {
                Actor = reader.SerializePropertyObject();

                // see https://github.com/EpicGames/UnrealEngine/blob/4564529ed77196caada6971f5de1be829900b9e1/Engine/Source/Runtime/Engine/Private/EngineTypes.cpp#L558
                //Ar << Handle.Actor;
                //Ar << Handle.Manager;
                //Ar << Handle.InstanceIndex;
            }

            Component = reader.SerializePropertyObject();
            BoneName  = reader.SerializePropertyName();
            FaceIndex = !bInvalidFaceIndex?reader.ReadInt32() : 0;

            ElementIndex = !bInvalidElementIndex && reader.EngineNetworkVersion >= EngineNetworkVersionHistory.HISTORY_ENUM_SERIALIZATION_COMPAT ? reader.ReadByte() : new byte();
        }
示例#4
0
 public void Serialize(NetBitReader reader)
 {
     X = reader.ReadSingle();
     Y = reader.ReadSingle();
     Z = reader.ReadSingle();
 }
示例#5
0
        /// <summary>
        /// see https://github.com/EpicGames/UnrealEngine/blob/6c20d9831a968ad3cb156442bebb41a883e62152/Engine/Plugins/Runtime/GameplayAbilities/Source/GameplayAbilities/Private/GameplayEffectTypes.cpp#L789
        /// </summary>
        /// <param name="reader"></param>
        public void Serialize(NetBitReader reader)
        {
            const byte NUM_LEVEL_BITS = 5; // need to bump this up to support 20 levels for AbilityLevel
            // const byte MAX_LEVEL = (1 << NUM_LEVEL_BITS) - 1;

            var RepBits = reader.ReadBitsToInt((int)RepFlag.REP_MAX);

            // Tag containers serialize empty containers with 1 bit, so no need to serialize this in the RepBits field.
            AggregatedSourceTags.Serialize(reader);
            AggregatedTargetTags.Serialize(reader);

            if ((RepBits & (1 << (int)RepFlag.REP_NormalizedMagnitude)) > 0)
            {
                NormalizedMagnitude = reader.ReadSingle();
            }
            if ((RepBits & (1 << (int)RepFlag.REP_RawMagnitude)) > 0)
            {
                RawMagnitude = reader.ReadSingle();
            }
            if ((RepBits & (1 << (int)RepFlag.REP_EffectContext)) > 0)
            {
                // FGameplayEffectContextHandle
                if (reader.ReadBit())
                {
                    var handle = new FGameplayEffectContextHandle();
                    handle.Serialize(reader);
                }
            }
            if ((RepBits & (1 << (int)RepFlag.REP_Location)) > 0)
            {
                Location = reader.SerializePropertyVector10();
            }
            if ((RepBits & (1 << (int)RepFlag.REP_Normal)) > 0)
            {
                Normal = reader.SerializePropertyVectorNormal();
            }
            if ((RepBits & (1 << (int)RepFlag.REP_Instigator)) > 0)
            {
                Instigator = reader.ReadIntPacked();
            }
            if ((RepBits & (1 << (int)RepFlag.REP_EffectCauser)) > 0)
            {
                EffectCauser = reader.ReadIntPacked();
            }
            if ((RepBits & (1 << (int)RepFlag.REP_SourceObject)) > 0)
            {
                SourceObject = reader.ReadIntPacked();
            }
            if ((RepBits & (1 << (int)RepFlag.REP_TargetAttachComponent)) > 0)
            {
                TargetAttachComponent = reader.ReadIntPacked();
            }
            if ((RepBits & (1 << (int)RepFlag.REP_PhysMaterial)) > 0)
            {
                PhysicalMaterial = reader.ReadIntPacked();
            }
            if ((RepBits & (1 << (int)RepFlag.REP_GELevel)) > 0)
            {
                GameplayEffectLevel = reader.ReadBitsToInt(NUM_LEVEL_BITS);
            }
            if ((RepBits & (1 << (int)RepFlag.REP_AbilityLevel)) > 0)
            {
                AbilityLevel = reader.ReadBitsToInt(NUM_LEVEL_BITS);
            }
        }
        /// <summary>
        /// see https://github.com/EpicGames/UnrealEngine/blob/c10022aa46e208b1593dd537c2607784aac158f1/Engine/Source/Runtime/Engine/Private/Collision/Collision.cpp#L42
        /// </summary>
        /// <param name="reader"></param>
        public void Serialize(NetBitReader reader)
        {
            // pack bitfield with flags
            var flags = reader.ReadBits(7);

            // Most of the time the vectors are the same values, use that as an optimization
            BlockingHit      = flags[0];
            StartPenetrating = flags[1];
            bool bImpactPointEqualsLocation = flags[2];
            bool bImpactNormalEqualsNormal  = flags[3];

            // Often times the indexes are invalid, use that as an optimization
            bool bInvalidItem        = flags[4];
            bool bInvalidFaceIndex   = flags[5];
            bool bNoPenetrationDepth = flags[6];

            Time = reader.ReadSingle();

            Location = reader.ReadPackedVector(1, 20);
            Normal   = reader.SerializePropertyVectorNormal();

            if (!bImpactPointEqualsLocation)
            {
                ImpactPoint = reader.ReadPackedVector(1, 20);
            }
            else
            {
                ImpactPoint = Location;
            }

            if (!bImpactNormalEqualsNormal)
            {
                ImpactNormal = reader.SerializePropertyVectorNormal();
            }
            else
            {
                ImpactNormal = Normal;
            }

            TraceStart = reader.ReadPackedVector(1, 20);
            TraceEnd   = reader.ReadPackedVector(1, 20);

            if (!bNoPenetrationDepth)
            {
                PenetrationDepth = reader.SerializePropertyFloat();
            }
            else
            {
                PenetrationDepth = 0.0f;
            }

            Distance = (ImpactPoint - TraceStart).Size();

            if (!bInvalidItem)
            {
                Item = reader.ReadInt32();
            }
            else
            {
                Item = 0;
            }

            PhysMaterial = reader.SerializePropertyObject();
            Actor        = reader.SerializePropertyObject();
            Component    = reader.SerializePropertyObject();
            BoneName     = reader.SerializePropertyName();
            if (!bInvalidFaceIndex)
            {
                FaceIndex = reader.ReadInt32();
            }
            else
            {
                FaceIndex = 0;
            }
        }
        public void Serialize(NetBitReader reader)
        {
            return;

            bool[] flags = reader.ReadBits(7);

            BlockingHit      = flags[6];
            StartPenetrating = flags[5];
            bool impactPointEqualsLocation = flags[4];
            bool impactNormalEqualsNormal  = flags[3];
            bool invalidItem        = flags[2];
            bool invalidFaceIndex   = flags[1];
            bool noPenetrationDepth = flags[0];

            Time     = reader.ReadSingle();
            Location = reader.SerializePropertyQuantizeVector();
            Normal   = reader.SerializePropertyVectorNormal();

            if (!impactPointEqualsLocation)
            {
                ImpactPoint = reader.SerializePropertyQuantizeVector();
            }
            else
            {
                ImpactPoint = Location;
            }

            if (!impactNormalEqualsNormal)
            {
                ImpactNormal = reader.SerializePropertyVectorNormal();
            }
            else
            {
                ImpactNormal = Normal;
            }

            TraceStart = reader.SerializePropertyQuantizeVector();
            TraceEnd   = reader.SerializePropertyQuantizeVector();

            if (!noPenetrationDepth)
            {
                PenetrationDepth = reader.SerializePropertyFloat();
            }
            else
            {
                PenetrationDepth = 0;
            }

            Distance = (ImpactPoint - TraceStart).Size();

            if (!invalidItem)
            {
                Item = reader.ReadBitsToInt(32);
            }
            else
            {
                Item = -1;
            }

            PhysMaterial = reader.SerializePropertyUInt16();
            Actor        = reader.SerializePropertyUInt16();
            Component    = reader.SerializePropertyUInt16();
            BoneName     = reader.ReadFString();

            if (!invalidFaceIndex)
            {
                FaceIndex = reader.ReadBitsToInt(32);
            }
            else
            {
                FaceIndex = -1;
            }
        }