예제 #1
0
        private void ProcessInputPacket(Packet packet)
        {
            if (packet is ClientInfoRequestPacket)
            {
                ClientInfoResponsePacket clientInfoResponse = new ClientInfoResponsePacket(sAlias);
                client.Send(clientInfoResponse);
            }
            else if (packet is ChatPacket)
            {
                ChatPacket cp = packet as ChatPacket;
                CallChatMessageReceived(cp.message, cp.player);
            }
            else if (packet is ObjectResponsePacket)
            {
                ObjectResponsePacket corp = packet as ObjectResponsePacket;
                CallObjectRequestResponseReceived(corp.ID, corp.AssetName);
            }
            else if (packet is ObjectUpdatePacket)
            {
                ObjectUpdatePacket oup = packet as ObjectUpdatePacket;
                CallObjectUpdateReceived(oup.objectId, oup.assetName, oup.position, oup.orientation, oup.velocity);
            }
            else if (packet is ObjectActionPacket)
            {
                ObjectActionPacket oap = packet as ObjectActionPacket;
                CallObjectActionReceived(oap.objectId, oap.actionParameters);
            }
            else if (packet is ClientDisconnectPacket)
            {
                ClientDisconnectPacket cdp = packet as ClientDisconnectPacket;

                CallClientDisconnected(cdp.Alias);
            }
        }
예제 #2
0
        public override void physicsManager_PreIntegrate()
        {
            base.physicsManager_PreIntegrate();
            lock (gameObjects)
            {
                #region Process Action Updates from the client
                lock (MultiplayerUpdateQueue)
                {
                    while (MultiplayerUpdateQueue.Count > 0)
                    {
                        ObjectActionPacket oap = MultiplayerUpdateQueue[0] as ObjectActionPacket;
                        if (!gameObjects.ContainsKey(oap.objectId))
                        {
                            continue; // TODO - infinite loop if this is hit
                        }
                        Entity go = gameObjects[oap.objectId];
                        go.actionManager.ProcessActionValues(oap.actionParameters);
                        MultiplayerUpdateQueue.RemoveAt(0);
                    }
                }
                #endregion

                #region Apply AI controllers
                lock (gameObjects)
                {
                    DoAiLogic();
                }
                #endregion
            }
        }
예제 #3
0
 private void ProcessInputPacket(Packet packet)
 {
     if (packet is ClientInfoRequestPacket)
     {
         Trace.WriteLine("Received ClientInfoRequest");
         ClientInfoRequestPacket  cir = packet as ClientInfoRequestPacket;
         ClientInfoResponsePacket clientInfoResponse = new ClientInfoResponsePacket(sAlias);
         client.Send(clientInfoResponse);
         CallClientInfoRequestReceived(cir.ID);
     }
     else if (packet is ChatPacket)
     {
         ChatPacket cp = packet as ChatPacket;
         CallChatMessageReceived(new ChatMessage(cp.message, cp.player));
     }
     else if (packet is ObjectAddedPacket)
     {
         Trace.WriteLine("Received ObjectAdded");
         ObjectAddedPacket corp = packet as ObjectAddedPacket;
         CallObjectRequestResponseReceived(corp.Owner, corp.ID, corp.AssetName);
     }
     else if (packet is ObjectUpdatePacket)
     {
         ObjectUpdatePacket oup = packet as ObjectUpdatePacket;
         CallObjectUpdateReceived(oup.objectId, oup.assetName, oup.position, oup.orientation, oup.velocity);
     }
     else if (packet is ObjectActionPacket)
     {
         ObjectActionPacket oap = packet as ObjectActionPacket;
         CallObjectActionReceived(oap.objectId, oap.actionParameters);
     }
     else if (packet is ClientDisconnectPacket)
     {
         ClientDisconnectPacket cdp = packet as ClientDisconnectPacket;
         CallOtherClientDisconnectedFromServer(cdp.id);
     }
     else if (packet is ClientConnectedPacket)
     {
         ClientConnectedPacket ccp = packet as ClientConnectedPacket;
         CallOtherClientConnectedToServer(ccp.ID, ccp.Alias);
     }
     else if (packet is ObjectAttributePacket)
     {
         ObjectAttributePacket oap = packet as ObjectAttributePacket;
         CallObjectAttributeReceived(oap);
     }
     else if (packet is ObjectDeletedPacket)
     {
         Trace.WriteLine("Received ObjectDelete");
         ObjectDeletedPacket odp = packet as ObjectDeletedPacket;
         CallObjectDeleteReceived(odp);
     }
 }
예제 #4
0
        private void ProcessInputPacket(ClientPacketInfo cpi)
        {
            if (cpi == null)
            {
                return;
            }

            Packet packet = cpi.packet;

            if (packet is ClientInfoResponsePacket)
            {
                Debug.WriteLine("Received Client info Response");
                //client connects. Server sends infoRequest, Client sends infoResponse.
                ClientInfoResponsePacket cirp = packet as ClientInfoResponsePacket;
                CallClientConnected(cpi.id, cirp.Alias);

                // Let everyone know they joined
                ClientConnectedPacket ccp = new ClientConnectedPacket(cpi.id, cirp.Alias);
                BroadcastPacket(ccp);
            }
            else if (packet is ClientReadyPacket)
            {
                ClientReadyPacket crp = packet as ClientReadyPacket;
                CallClientReadyReceived(crp.Id, crp.Alias);
            }
            else if (packet is ChatPacket)
            {
                ChatPacket cp = packet as ChatPacket;
                BroadcastChatMessage(cp.message, cp.player);
                CallChatMessageReceived(new ChatMessage(cp.message, cp.player));
            }
            else if (packet is ObjectRequestPacket)
            {
                Debug.WriteLine("Received ObjectRequestPacket");
                ObjectRequestPacket corp = packet as ObjectRequestPacket;
                CallObjectRequestReceived(cpi.id, corp.AssetName);
            }
            else if (packet is ObjectUpdatePacket)
            {
                ObjectUpdatePacket oup = packet as ObjectUpdatePacket;
                CallObjectUpdateReceived(oup.objectId, oup.assetName, oup.position, oup.orientation, oup.velocity);
            }
            else if (packet is ObjectActionPacket)
            {
                ObjectActionPacket oap = packet as ObjectActionPacket;
                CallObjectActionReceived(oap.objectId, oap.actionParameters);
            }
            else if (packet is ObjectAttributePacket)
            {
                ObjectAttributePacket oap = packet as ObjectAttributePacket;
                CallObjectAttributeReceived(oap);
            }
        }
예제 #5
0
        private void ProcessInputPacket(ClientPacketInfo cpi)
        {
            if (cpi == null)
            {
                return;
            }
            Packet packet = cpi.packet;

            if (packet is ClientInfoResponsePacket)
            {
                ClientInfoResponsePacket cirp = packet as ClientInfoResponsePacket;
                cpi.client.alias = cirp.Alias;
                CallClientConnected(cpi.client.alias);
            }
            else if (packet is ChatPacket)
            {
                ChatPacket cp = packet as ChatPacket;
                SendChatPacket(cp.message, cp.player);
                CallChatMessageReceived(cp.message, cp.player);
            }
            else if (packet is ObjectRequestPacket)
            {
                ObjectRequestPacket corp = packet as ObjectRequestPacket;
                CallObjectRequestReceived(cpi.client.id, corp.AssetName);
            }
            else if (packet is ObjectUpdatePacket)
            {
                ObjectUpdatePacket oup = packet as ObjectUpdatePacket;
                CallObjectUpdateReceived(oup.objectId, oup.assetName, oup.position, oup.orientation, oup.velocity);
            }
            else if (packet is ObjectActionPacket)
            {
                ObjectActionPacket oap = packet as ObjectActionPacket;
                CallObjectActionReceived(oap.objectId, oap.actionParameters);
            }
        }
예제 #6
0
        /// <summary>
        /// The physics engine is about to integrate, so we need to process things from the server about "reality"
        /// now is the time for the client to send ObjectActionPackets the server about inputs
        /// now is the tine for the client to process ObjectAttributePackets from the server about changes (shape, mode, behavior).
        /// now is the time for the client to process ObjectUpdatePackets from the server about pos/orient/vel
        /// now is the time for the server to process ObjectActionPackets the client about pos/orient/vel
        /// </summary>
        void physicsManager_PreIntegrate()
        {
            if (isClient)
            {
                lock (gameObjects)
                {
                    #region Send Action Updates to the server
                    foreach (int i in clientControlledObjects)
                    {
                        if (!gameObjects.ContainsKey(i))
                        {
                            continue;
                        }
                        Gobject go = gameObjects[i];
                        if (!go.actionManager.actionApplied)
                        {
                            continue;
                        }

                        if (go is RoverObject)
                        {
                        }
                        object[] vals = go.actionManager.GetActionValues();
                        go.actionManager.ValueSwap();
                        commClient.SendObjectAction(go.ID, vals);
                    }
                    #endregion

                    #region Process packets from the server
                    List <object> ShouldRetry = new List <object>();
                    lock (MultiplayerUpdateQueue)
                    {
                        while (MultiplayerUpdateQueue.Count > 0)
                        {
                            Packet p = MultiplayerUpdateQueue[0] as Packet;
                            MultiplayerUpdateQueue.RemoveAt(0);

                            if (p is ObjectUpdatePacket)
                            {
                                #region Process Update Packets from the server
                                ObjectUpdatePacket oup = p as ObjectUpdatePacket;

                                if (!gameObjects.ContainsKey(oup.objectId))
                                {
                                    AddNewObject(oup.objectId, oup.assetName);
                                    ShouldRetry.Add(oup);
                                    continue;
                                    // TODO -  Should we continue instead of not updating this frame?
                                }
                                // (can't yet due to AddNewObject waiting until the next integrate to actually add it)
                                Gobject go = gameObjects[oup.objectId];
                                if (go.hasNotDoneFirstInterpoladation)
                                {
                                    go.Interpoladate(oup.position, oup.orientation, oup.velocity, 1.0f); // Server knows best!
                                }
                                else
                                {
                                    go.Interpoladate(oup.position, oup.orientation, oup.velocity); // split realities 50/50
                                }
                                #endregion
                            }
                            else if (p is ObjectAttributePacket)
                            {
                                #region Process Attribute Packets from the server
                                ObjectAttributePacket oap = p as ObjectAttributePacket;
                                if (gameObjects.ContainsKey(oap.objectId))
                                {
                                    Gobject go = gameObjects[oap.objectId];
                                    bool    locallyOwnedAndOperated = false;

                                    if (go.OwningClientId == MyClientID)
                                    {
                                        locallyOwnedAndOperated = true;
                                    }
                                    go.SetObjectAttributes(oap.booleans, oap.ints, oap.floats, locallyOwnedAndOperated);
                                }
                                #endregion
                            }
                        }
                        while (ShouldRetry.Count > 0)
                        {
                            MultiplayerUpdateQueue.Add(ShouldRetry[0]);
                            ShouldRetry.RemoveAt(0);
                        }
                    }



                    #endregion
                }
            }
            else if (isServer)
            {
                lock (gameObjects)
                {
                    #region Process Action Updates from the client
                    lock (MultiplayerUpdateQueue)
                    {
                        while (MultiplayerUpdateQueue.Count > 0)
                        {
                            ObjectActionPacket oap = MultiplayerUpdateQueue[0] as ObjectActionPacket;
                            if (!gameObjects.ContainsKey(oap.objectId))
                            {
                                continue; // TODO - infinite loop if this is hit
                            }
                            Gobject go = gameObjects[oap.objectId];
                            go.actionManager.ProcessActionValues(oap.actionParameters);
                            MultiplayerUpdateQueue.RemoveAt(0);
                        }
                    }
                    #endregion
                }
            }
        }