示例#1
0
 private void HandleExtrapolation()
 {
     //Validate current idea
     if (checkState != game.OldServerState)
     {
         foreach (PlayerObject po in playerObjects)
         {
                 try
                 {
                     checkState = game.OldServerState;
                     po.UpdatePositionFunction(game.OldServerState, game.MidServerState, game.NewServerState);
                 }
                 catch(NullReferenceException)
                 {
                     /*meh, it's almost expected at first */
                 }
         }
     }
 }
示例#2
0
        private static void DataUnpacker(Packet packet)
        {
            switch (packet.packetType)
            {
                case (PacketType.Registration):
                    id = packet.stringData[0];
                    break;

                case (PacketType.GameState):
                    if (game != null)
                    {
                        //Makes a new serverState
                        ServerState tempState = new ServerState();

                        //Initializes data in the state
                        tempState.GameStatusObject = new GameStatusObject(packet.stringData[0]);

                        tempState.PlayerObjects = new List<PlayerObject>();
                        foreach(string s in packet.stringData[1].Split('|'))
                        {
                            if (s.Length > 0)
                            {
                                tempState.PlayerObjects.Add(new PlayerObject(s));
                            }
                        }

                        tempState.StaticObjects = new List<StaticObject>();
                        foreach (string s in packet.stringData[2].Split('|'))
                        {
                            if (s.Length > 0)
                            {
                                tempState.StaticObjects.Add(new StaticObject(s));
                            }
                        }

                        tempState.DynamicObjects = new List<DynamicObject>();
                        foreach (string s in packet.stringData[3].Split('|'))
                        {
                            if (s.Length > 0)
                            {
                                tempState.DynamicObjects.Add(new DynamicObject(s));
                            }
                        }

                        tempState.TimeSinceLastServerState = TimeSinceLastServerState.Elapsed;
                        TimeSinceLastServerState.Restart();

                        //exchange data
                        lock (game.ServerStateLock)
                        {
                            game.OldServerState = game.MidServerState;
                            game.MidServerState = game.NewServerState;
                            game.NewServerState = tempState;
                        }
                    }
                    break;

                default:
                    Informer.AddEventInformation("wtf pakke modtaget!");
                    break;

            }
        }