コード例 #1
0
 private GameTime()
 {
     _offset      = GameConfig.Instance().config.startTime;
     lastSaveTime = _offset;
 }
コード例 #2
0
ファイル: Server.cs プロジェクト: Majiick/FarmWorldServer
        public void BlockingStart()
        {
            SetupDB();
            GameState gameState = new GameState(_db);
            Listener  listener  = new Listener();

            _server = new NetManager(listener);
            listener.Setup(gameState);
            _server.Start(GameConfig.Instance().config.port);
            Console.WriteLine("Server started.");

            Stopwatch _precisionTime = new Stopwatch();

            _precisionTime.Start();
            while (true)
            {
                long unadjustedTickStartTime = _precisionTime.ElapsedMilliseconds;
                GameTime.Instance().UpdateTickStartTime(_precisionTime.ElapsedMilliseconds); // Update the tick start time.
                _server.PollEvents();
                gameState.Tick();
                if (_precisionTime.ElapsedMilliseconds - unadjustedTickStartTime > 1000 / GameConfig.Instance().config.ticksPerSecond)
                {
                    Console.WriteLine(String.Format("Tick took {0} milliseconds which is past the tick rate.", _precisionTime.ElapsedMilliseconds - unadjustedTickStartTime));
                }
                // Wait until time for next tick.
                while (_precisionTime.ElapsedMilliseconds - unadjustedTickStartTime < 1000 / GameConfig.Instance().config.ticksPerSecond)
                {
                    Thread.Sleep(1);
                }
            }

            _server.Stop();
        }