Ejemplo n.º 1
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
            }
        }
Ejemplo n.º 2
0
        public override void physicsManager_PreIntegrate()
        {
            lock (gameObjects)
            {
                #region Send Action Updates to the server
                foreach (int i in clientControlledObjects)
                {
                    if (!gameObjects.ContainsKey(i))
                    {
                        continue;
                    }
                    Entity 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)
                            Entity 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))
                            {
                                Entity 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
            }
        }