コード例 #1
0
ファイル: Server.cs プロジェクト: jamierocks/femtocraft
        static void SchedulerLoop()
        {
            DateTime physicsTick = DateTime.UtcNow;
            DateTime mapTick     = DateTime.UtcNow;
            DateTime pingTick    = DateTime.UtcNow;

            physicsInterval = TimeSpan.FromMilliseconds(Config.PhysicsTick);
            Logger.Log("{0} is ready to go!", VersionString);

            while (true)
            {
                if (listener.Pending())
                {
                    try {
                        listener.BeginAcceptTcpClient(AcceptCallback, null);
                    } catch (Exception ex) {
                        Logger.LogWarning("Could not accept incoming connection: {0}", ex);
                    }
                }

                if (DateTime.UtcNow.Subtract(mapTick) > MapSaveInterval)
                {
                    ThreadPool.QueueUserWorkItem(MapSaveCallback);
                    mapTick = DateTime.UtcNow;
                }

                if (DateTime.UtcNow.Subtract(pingTick) > PingInterval)
                {
                    Players.Send(null, new Packet(OpCode.Ping));
                    pingTick = DateTime.UtcNow;
                }

                while (DateTime.UtcNow.Subtract(physicsTick) > physicsInterval)
                {
                    Map.Tick();
                    physicsTick += physicsInterval;
                }

                Thread.Sleep(5);
            }
        }