예제 #1
0
파일: Packet.cs 프로젝트: suzuke/3DPhysics
        public static Packet Read(byte[] data)
        {
            try
            {
                int    itype = BitConverter.ToInt32(data, 0);
                Types  ptype = (Types)itype;
                byte[] inner = new byte[data.Length - 4];
                for (int i = 4; i < data.Length; i++)
                {
                    inner[i - 4] = data[i];
                }
                switch (ptype)
                {
                case Types.scObjectUpdate:
                    ObjectUpdatePacket oup = new ObjectUpdatePacket();
                    return(oup.CustomDeserialize(inner));

                default:
                    Packet p = new Packet(Types.KeepAlive);
                    return(p.Deserialize(inner));
                }
            }
            catch (Exception E)
            {
            }
            return(null);
        }
예제 #2
0
 public static Packet Read(byte[] data)
 {
     try
     {
         int itype = BitConverter.ToInt32(data, 0);
         Types ptype = (Types)itype;
         byte[] inner = new byte[data.Length - 4];
         for (int i = 4; i < data.Length; i++)
             inner[i - 4] = data[i];
         switch (ptype)
         {
             case Types.scObjectUpdate:
                 ObjectUpdatePacket oup = new ObjectUpdatePacket();
                 return oup.CustomDeserialize(inner);
             default:
                 Packet p = new Packet(Types.KeepAlive);
                 return p.Deserialize(inner);
         }
     }
     catch(Exception E)
     {
     }
     return null;
 }
예제 #3
0
        /// <summary>
        /// the physics engine just integrated, so this is the newest information about "reality"
        /// now is the time for the server to send ObjectUpdatePackets to the client for objects that can move
        /// now is the time for the server to send ObjectAttributePackets to the client for objects whose attributes have changed
        /// </summary>
        void physicsManager_PostIntegrate()
        {
            if (isClient)
            {

            }
            else if (isServer)
            {
                if (commServer != null)
                {
                    lock (gameObjects)
                    {
                        foreach (Gobject go in gameObjects.Values)
                        {
                            #region Send Attribute Updates to the client
                            if (go.hasAttributeChanged)
                            {
                                bool[] bools = null;
                                int[] ints = null;
                                float[] floats = null;
                                go.GetObjectAttributes(out bools, out ints, out floats);
                                ObjectAttributePacket oap = new ObjectAttributePacket(go.ID, bools, ints, floats);
                                commServer.BroadcastPacket(oap);
                            }
                            #endregion

                            #region Send Object Updates to the client

                            if (go.isMoveable && go.IsActive)
                            {
                                go.UpdateCountdown--;
                                if (go.UpdateCountdown == 0 || assetManager.isObjectOwnedByAnyClient(go.ID))
                                {
                                    ObjectUpdatePacket oup = new ObjectUpdatePacket(go.ID, go.type, go.BodyPosition(), go.BodyOrientation(), go.BodyVelocity());
                                    commServer.BroadcastObjectUpdate(oup);
                                    go.UpdateCountdown = 10;
                                }

                            }
                            #endregion
                        }
                    }
                }
            }

            if (cameraManager != null)
            {
                if (UpdateCameraCallback == null)
                    return;
                cameraManager.Update();
                UpdateCamera();

                UpdateCameraCallback(cameraManager.currentCamera, cameraManager.ViewMatrix(), cameraManager.ProjectionMatrix());
            }
        }
예제 #4
0
        private void CatchUpClient(int id)
        {
            lock (gameObjects)
            {
                foreach (Gobject go in gameObjects.Values)
                {
                    //ObjectAddedPacket oap1 = new ObjectAddedPacket(-1, go.ID, go.type);
                    //commServer.SendPacket(oap1, id);

                    #region Send Attribute Updates to the client
                    if (go.hasAttributeChanged)
                    {
                        bool[] bools = null;
                        int[] ints = null;
                        float[] floats = null;
                        go.GetObjectAttributes(out bools, out ints, out floats);
                        ObjectAttributePacket oap = new ObjectAttributePacket(go.ID, bools, ints, floats);
                        commServer.SendPacket(oap,id);
                    }
                    #endregion

                    #region Send Object Updates to the client
                    ObjectUpdatePacket oup = new ObjectUpdatePacket(go.ID, go.type, go.BodyPosition(), go.BodyOrientation(), go.BodyVelocity());
                    commServer.SendPacket(oup,id);
                    #endregion
                }
            }
        }