예제 #1
0
        public override void OnParentChanged(NetworkObj obj, Entity newParent, Entity oldParent)
        {
            var nt = obj.Storage.Values[obj[this] + POSITION].Transform;

            if (nt != null && nt.Simulate)
            {
                if (newParent == null)
                {
                    nt.Simulate.transform.parent = null;
                    UpdateTransformValues(obj, oldParent.UnityObject.transform.localToWorldMatrix, Matrix4x4.identity);
                }
                else if (oldParent == null)
                {
                    nt.Simulate.transform.parent = newParent.UnityObject.transform;
                    UpdateTransformValues(obj, Matrix4x4.identity, newParent.UnityObject.transform.worldToLocalMatrix);
                }
                else
                {
                    nt.Simulate.transform.parent = newParent.UnityObject.transform;
                    UpdateTransformValues(obj, oldParent.UnityObject.transform.localToWorldMatrix, newParent.UnityObject.transform.worldToLocalMatrix);
                }
            }

            if (obj.RootState.Entity.IsOwner)
            {
                obj.Storage.PropertyChanged(obj.OffsetProperties + this.OffsetProperties);
            }
        }
예제 #2
0
        public override bool Write(Connection connection, NetworkObj obj, NetworkStorage storage, Packet packet)
        {
            if (obj.RootState.Entity.HasParent)
            {
                if (connection.entityChannel.ExistsOnRemote(obj.RootState.Entity.Parent))
                {
                    packet.WriteEntity(obj.RootState.Entity.Parent);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                packet.WriteEntity(null);
            }

            if (PositionEnabled)
            {
                PositionCompression.Pack(packet, storage.Values[obj[this] + POSITION].Vector3);

                if (Extrapolation.Enabled)
                {
                    PositionCompression.Pack(packet, storage.Values[obj[this] + VELOCITY].Vector3);
                }
            }

            if (RotationEnabled)
            {
                RotationCompression.Pack(packet, storage.Values[obj[this] + ROTATION].Quaternion);
            }

            return(true);
        }
예제 #3
0
        public override void OnSimulateBefore(NetworkObj obj)
        {
            if (Interpolation.Enabled)
            {
                var root = (NetworkState)obj.Root;

                if (root.Entity.IsOwner)
                {
                    return;
                }

                if (root.Entity.HasControl && !ToController)
                {
                    return;
                }

                var it    = root.Frames.GetIterator();
                var idx   = obj[this];
                var value = NetMath.InterpolateFloat(obj.RootState.Frames, idx + 1, obj.RootState.Entity.Frame, Settings.IsAngle);

                while (it.Next())
                {
                    it.val.Values[idx].Float0 = value;
                }
            }
        }
예제 #4
0
        void UpdateTransformValues(NetworkObj obj, Matrix4x4 l2w, Matrix4x4 w2l)
        {
            var it = obj.RootState.Frames.GetIterator();

            while (it.Next())
            {
                var p = obj.Storage.Values[obj[this] + POSITION].Vector3;
                var r = obj.Storage.Values[obj[this] + ROTATION].Quaternion;

                float   angle;
                Vector3 axis;
                r.ToAngleAxis(out angle, out axis);

                // transform position
                p = l2w.MultiplyPoint(p);
                p = w2l.MultiplyPoint(p);

                // transform rotation
                axis = l2w.MultiplyVector(axis);
                axis = w2l.MultiplyVector(axis);
                r    = Quaternion.AngleAxis(angle, axis);

                // put back into frame
                obj.Storage.Values[obj[this] + POSITION].Vector3    = p;
                obj.Storage.Values[obj[this] + ROTATION].Quaternion = r;
            }
        }
예제 #5
0
        public override int BitCount(NetworkObj obj)
        {
            if (Extrapolation.Enabled)
            {
                return((PositionCompression.BitsRequired * 2) + RotationCompression.BitsRequired);
            }

            return(PositionCompression.BitsRequired + RotationCompression.BitsRequired);
        }
예제 #6
0
        public override int BitCount(NetworkObj obj)
        {
            if (obj.Storage.Values[obj[this]].String == null)
            {
                return(16);
            }

            return(16 + StringSettings.EncodingClass.GetByteCount(obj.Storage.Values[obj[this]].String));
        }
예제 #7
0
        public override object DebugValue(NetworkObj obj, NetworkStorage storage)
        {
            if (storage.Values[obj[this]].ProtocolToken == null)
            {
                return("NULL");
            }

            return(storage.Values[obj[this]].ProtocolToken.ToString());
        }
예제 #8
0
        public override void SetDynamic(NetworkObj obj, object value)
        {
            if (MecanimDirection == MecanimDirection.UsingAnimatorMethods)
            {
                NetLog.Error("Can't call SetDynamic on a trigger in 'UsingAnimatorMethods' mode");
                return;
            }

            obj.Storage.Values[obj[this]].TriggerLocal.Update(Core.Frame, true);
        }
예제 #9
0
        public override void SetDynamic(NetworkObj obj, object value)
        {
            var v = (Guid)value;

            if (NetworkValue.Diff(obj.Storage.Values[obj[this]].Guid, v))
            {
                obj.Storage.Values[obj[this]].Guid = v;
                obj.Storage.PropertyChanged(obj.OffsetProperties + this.OffsetProperties);
            }
        }
예제 #10
0
        public override void SetDynamic(NetworkObj obj, object value)
        {
            var v = (IMessageRider)value;

            if (NetworkValue.Diff(obj.Storage.Values[obj[this]].ProtocolToken, v))
            {
                obj.Storage.Values[obj[this]].ProtocolToken = v;
                obj.Storage.PropertyChanged(obj.OffsetProperties + this.OffsetProperties);
            }
        }
예제 #11
0
        public override object DebugValue(NetworkObj obj, NetworkStorage storage)
        {
            Entity entity = Core.FindEntity(storage.Values[obj[this]].NetworkId);

            if (entity)
            {
                return(entity.ToString());
            }

            return("NULL");
        }
예제 #12
0
 public override void Read(Connection connection, NetworkObj obj, NetworkStorage storage, Packet packet)
 {
     if (Interpolation.Enabled)
     {
         storage.Values[obj[this] + 1].Float1 = Compression.Read(packet);
     }
     else
     {
         storage.Values[obj[this]].Float0 = Compression.Read(packet);
     }
 }
예제 #13
0
        public override bool Write(Connection connection, NetworkObj obj, NetworkStorage storage, Packet packet)
        {
            // adjust trigger
            storage.Values[obj[this]].TriggerSend.Update(Core.Frame, false);

            // write history
            packet.WriteInt(storage.Values[obj[this]].TriggerSend.History, obj.RootState.Entity.SendRate);

            // this always succeeds!
            return(true);
        }
예제 #14
0
        public void InitObject(NetworkObj obj, NetworkObj root, Offsets offsets)
        {
            obj.Root = root;

            obj.OffsetStorage    = offsets.OffsetStorage;
            obj.OffsetObjects    = offsets.OffsetObjects;
            obj.OffsetProperties = offsets.OffsetProperties;

            obj.Add();

            InitObject(obj, offsets);
        }
예제 #15
0
        void MecanimPush(NetworkObj obj, bool push)
        {
            var root   = obj.RootState;
            var frames = root.Frames.GetIterator();

            while (frames.Next())
            {
                var s = frames.val;
                var i = obj[this];

                var t_frame    = s.Values[i].TriggerLocal.Frame;
                var t_history  = s.Values[i].TriggerLocal.History;
                var t_callback = s.Values[i].Action;

                for (int k = (obj.RootState.Entity.SendRate - 1); (k >= 0) && (t_history != 0); --k)
                {
                    if (t_frame - k > obj.RootState.Entity.Frame)
                    {
                        continue;
                    }

                    int b = 1 << k;

                    if ((t_history & b) == b)
                    {
                        t_history &= ~b;

                        // clear history for this bit
                        s.Values[i].TriggerLocal.History = t_history;

                        // update send trigger
                        root.Storage.Values[i].TriggerSend.Update(Core.Frame, true);

                        // meep
                        root.Storage.PropertyChanged(obj.OffsetProperties + this.OffsetProperties);

                        if (push)
                        {
                            for (int a = 0; a < obj.RootState.Animators.Count; ++a)
                            {
                                obj.RootState.Animators[a].SetTrigger(PropertyName);
                            }
                        }

                        if (t_callback != null)
                        {
                            t_callback();
                        }
                    }
                }
            }
        }
예제 #16
0
        public override void Read(Connection connection, NetworkObj obj, NetworkStorage storage, Packet packet)
        {
            UE.Vector3 v = Compression.Read(packet);

            if (Interpolation.Enabled && (obj.Root is NetworkState))
            {
                storage.Values[obj[this] + 1].Vector3 = v;
            }
            else
            {
                storage.Values[obj[this]].Vector3 = v;
            }
        }
예제 #17
0
 public override bool Write(Connection connection, NetworkObj obj, NetworkStorage storage, Packet packet)
 {
     try
     {
         packet.WriteToken(storage.Values[obj[this]].ProtocolToken);
         return(true);
     }
     catch (Exception exn)
     {
         NetLog.Error("User code threw exception while serializing protocol token");
         NetLog.Exception(exn);
         return(false);
     }
 }
예제 #18
0
        public override void SetDynamic(NetworkObj obj, object value)
        {
            if (MecanimDirection == MecanimDirection.UsingAnimatorMethods)
            {
                NetLog.Error("Can't call SetDynamic on a float in 'UsingAnimatorMethods' mode");
                return;
            }

            var v = (float)value;

            if (NetworkValue.Diff(obj.Storage.Values[obj[this]].Float0, v))
            {
                obj.Storage.Values[obj[this]].Float0 = v;
                obj.Storage.PropertyChanged(obj.OffsetProperties + this.OffsetProperties);
            }
        }
예제 #19
0
 public override void OnSimulateAfter(NetworkObj obj)
 {
     if (MecanimMode == MecanimMode.Disabled)
     {
         MecanimPush(obj, false);
     }
     else
     {
         if (ShouldPullDataFromMecanim(obj.RootState))
         {
             MecanimPull(obj, obj.Storage);
         }
         else
         {
             MecanimPush(obj, true);
         }
     }
 }
예제 #20
0
        public override void OnSimulateAfter(NetworkObj obj)
        {
            NetworkState state = (NetworkState)obj.Root;

            if (MecanimMode != MecanimMode.Disabled)
            {
                if (state.Animators.Count > 0)
                {
                    if (MecanimMode == MecanimMode.LayerWeight)
                    {
                        if (ShouldPullDataFromMecanim(state))
                        {
                            PullMecanimLayer(state);
                        }
                        else
                        {
                            PushMecanimLayer(state);
                        }
                    }
                    else
                    {
                        if (ShouldPullDataFromMecanim(state))
                        {
                            PullMecanimValue(state);
                        }
                        else
                        {
                            PushMecanimValue(state);
                        }
                    }
                }
                else
                {
#if DEBUG
                    if (state.MecanimWarningTimeout < UnityEngine.Time.time)
                    {
                        NetLog.Warn("You have not assigned a mecanim animator to the state on {0}, but you have properties set to use mecanim", state.Entity.UnityObject.gameObject.name);
                        state.MecanimWarningTimeout = UnityEngine.Time.time + 1;
                    }
#endif
                }
            }
        }
예제 #21
0
        public override void Read(Connection connection, NetworkObj obj, NetworkStorage storage, Packet packet)
        {
            obj.RootState.Entity.SetParentInternal(packet.ReadEntity());

            if (PositionEnabled)
            {
                storage.Values[obj[this] + POSITION].Vector3 = PositionCompression.Read(packet);

                if (Extrapolation.Enabled)
                {
                    storage.Values[obj[this] + VELOCITY].Vector3 = PositionCompression.Read(packet);
                }
            }

            if (RotationEnabled)
            {
                storage.Values[obj[this] + ROTATION].Quaternion = RotationCompression.Read(packet);
            }
        }
예제 #22
0
        public override void SmoothCommandCorrection(NetworkObj obj, NetworkStorage from, NetworkStorage to, NetworkStorage storage, float t)
        {
            if (Interpolation.Enabled)
            {
                var v0 = from.Values[obj[this]].Vector3;
                var v1 = to.Values[obj[this]].Vector3;
                var m  = (v1 - v0).sqrMagnitude;

                if (m < (Interpolation.SnapMagnitude * Interpolation.SnapMagnitude))
                {
                    storage.Values[obj[this]].Vector3 = UE.Vector3.Lerp(v0, v1, t);
                }
                else
                {
                    storage.Values[obj[this]].Vector3 = v1;
                }
            }
            else
            {
                storage.Values[obj[this]].Vector3 = to.Values[obj[this]].Vector3;
            }
        }
예제 #23
0
        void MecanimPull(NetworkObj obj, NetworkStorage storage)
        {
            if (obj.RootState.Animator == null)
            {
                return;
            }

            if (obj.RootState.Animator.GetBool(PropertyName) && (obj.RootState.Animator.IsInTransition(MecanimLayer) == false))
            {
                // update send trigger
                storage.Values[obj[this]].TriggerSend.Update(Core.Frame, true);

                // notify Ascension this property changed
                storage.PropertyChanged(obj.OffsetProperties + this.OffsetProperties);

                // invoke callback
                var cb = obj.Storage.Values[obj[this]].Action;
                if (cb != null)
                {
                    cb();
                }
            }
        }
예제 #24
0
        public override void OnRender(NetworkObj obj)
        {
            if (obj.RootState.Entity.IsOwner)
            {
                return;
            }

            var nt = obj.Storage.Values[obj[this] + POSITION].Transform;

            if (nt != null && nt.Simulate)
            {
                if (PositionEnabled)
                {
                    var p = nt.RenderDoubleBufferPosition.Previous;
                    var c = nt.RenderDoubleBufferPosition.Current;
                    nt.Simulate.position = Vector3.Lerp(p, c, Core.FrameAlpha);
                }

                if (RotationEnabled)
                {
                    //nt.Render.rotation = nt.RenderDoubleBufferRotation.Current;
                }
            }
        }
예제 #25
0
        public override object DebugValue(NetworkObj obj, NetworkStorage storage)
        {
            var nt = obj.Storage.Values[obj[this]].Transform;

            if (nt != null && nt.Simulate)
            {
                var p = obj.Storage.Values[obj[this] + POSITION].Vector3;
                var r = obj.Storage.Values[obj[this] + ROTATION].Quaternion;

                var pos = string.Format("X:{0} Y:{1} Z:{2}", p.x.ToString("F2"), p.y.ToString("F2"), p.z.ToString("F2"));
                var rot = string.Format("X:{0} Y:{1} Z:{2}", r.x.ToString("F2"), r.y.ToString("F2"), r.z.ToString("F2"));

                var render = "";

                if (nt.Render)
                {
                    render = string.Format("(R: {0})", nt.Render.gameObject.name);
                }

                return(string.Format("{0} / {1}{2}", pos, rot, render));
            }

            return("NOT ASSIGNED");
        }
예제 #26
0
 public override object DebugValue(NetworkObj obj, NetworkStorage storage)
 {
     return(storage.Values[obj[this]].Guid);
 }
예제 #27
0
 public override void Read(Connection connection, NetworkObj obj, NetworkStorage storage, Packet packet)
 {
     storage.Values[obj[this]].Guid = packet.ReadGuid();
 }
예제 #28
0
 public override bool Write(Connection connection, NetworkObj obj, NetworkStorage storage, Packet packet)
 {
     packet.WriteGuid(storage.Values[obj[this]].Guid);
     return(true);
 }
예제 #29
0
 public override int BitCount(NetworkObj obj)
 {
     return(128);
 }
예제 #30
0
 public override object GetDynamic(NetworkObj obj)
 {
     return(obj.Storage.Values[obj[this]].Guid);
 }