コード例 #1
0
ファイル: BaseGame.cs プロジェクト: colbybhearn/3DPhysics
        /// <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());
            }
        }
コード例 #2
0
ファイル: BaseGame.cs プロジェクト: colbybhearn/3DPhysics
 void commServer_ObjectAttributeReceived(ObjectAttributePacket oap)
 {
     // DO NOTHING, READ BELOW for WHY we should DO NOTHING.
     /*
      * If the client and server send a change at the same time
      * the server could tell the client, you just got a radar.
      * the client could have requested to drop a laser
      *
      * if the server sends before it receives the client's request, then it tells the client, you now have a laser and a radar.
      * When the server gets the client's request, the server won't know (currently) what changed, so it has to take the client at face value (no laser and no radar)
      * this is a more general version of the issue with ActionValues and detecting what changed.
      *
      * solutions:
      *  1 the messages need to be true deltas (The server needs to know what, specifically, changed that caused the attribute packet so that it can do only that which was requested. Drop the laser!)
      *  2
      *
      * Implementations:
      *  1 Put old and new in the AttributePacket
      *  2 relay which value to change and to what value. (this can be done by sending the delta, not the actual value)
      *
      * Example:
      * Say a rover's laser is dropped.
      * For the rover, that is boolean value number 2 at index 1
      * instead of sending a false for hasLaser, signify the delta with a true (it did change [flipped])
      * Instead of sending a 70 for energy left, signify the delta with a -5 (it did change by -5)
      * Instead of sending a 20.5 for throttle, signify the delta with a +1.5 (it did change by +1.5)
      *
      * What about synchronization?
      * Will the client get out of sync with the server or vice-a-versa?
      * What if the server sends hard values and the client reports deltas as requests?
      * The client doesn't modify its attributes.
      * The client sends input to the server.
      * the server modifies attributes.
      *
      * Currently, the server processes input.
      * To go forward, the ActionManager is updated about the requets to go forward.
      * Before the client integrates, ActionManager wraps up the input for the object into an Object Action Packet sent to the server.
      * Sever simulates the input, does integration, and replies with an Object Update Packet
      * the client applies that Object Update Packet before integrating.
      *
      * The server needing to process Object Attribute Packets is based on the client processing input which affects other clients.
      * ULTIMATE SOLUTION: If the laser drop were just another ActionValue for the server to simulate, the server would not need to process object attribute requests from the client.
      *
      * That being said, how much needs to be simulated on the server?
      * ANYTHING THAT AFFECTS ANOTHER CLIENT
      *  - changes in Appearance
      *  - changes in Behavior
      *
      * If it only affects the source client, it doesn't need to be sent.
      * Thus, managing internal inventory, or changing where energy is routed can be done locally without server involvement.
      *
      */
 }
コード例 #3
0
ファイル: BaseGame.cs プロジェクト: colbybhearn/3DPhysics
        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
                }
            }
        }
コード例 #4
0
ファイル: BaseGame.cs プロジェクト: colbybhearn/3DPhysics
 void commClient_ObjectAttributeReceived(ObjectAttributePacket oap)
 {
     lock (MultiplayerUpdateQueue)
     {
         MultiplayerUpdateQueue.Add(oap);
     }
 }
コード例 #5
0
ファイル: CommServer.cs プロジェクト: colbybhearn/3DPhysics
 private void CallObjectAttributeReceived(ObjectAttributePacket oap)
 {
     if (ObjectAttributeReceived == null)
         return;
     ObjectAttributeReceived(oap);
 }