Пример #1
0
        public void Unregister(Game game)
        {
            GameLoopCallbacks callbacks;
            _callbacks.TryRemove(game.ID, out callbacks);
            _loop.RemoveCallback(callbacks.UpdateLoopCallback);
            _loop.RemoveCallback(callbacks.PushLoopCallback);

            TryLoopStop();
        }
Пример #2
0
        private GameLoopCallbacks CreateAndCacheCallbacks(Game game)
        {
            var callbacks = new GameLoopCallbacks
            {
                UpdateLoopCallback = new TimedCallback
                {
                    Callback = game.PrepareUpdate
                },
                PushLoopCallback = new TimedCallback
                {
                    Callback = game.PreparePush
                }
            };

            // Add the callback to the callback cache
            _callbacks.TryAdd(game.ID, callbacks);

            return callbacks;
        }
Пример #3
0
        public GameRegistration Register(Game game)
        {
            var callbacks = CreateAndCacheCallbacks(game);

            // Try to start the loop prior to adding our games callback.  This callback may be the first, hence the "Try"
            TryLoopStart();

            // Add our callback to the game loop (which is now running), it will now be called on an interval dictated by the callbacks
            _loop.AddCallback(callbacks.UpdateLoopCallback);
            _loop.AddCallback(callbacks.PushLoopCallback);

            // Updating the "updateRate" and "pushRate" is an essential element to the game configuration.
            // If a game is running slowly we need to be able to slow down the update rate.
            return new GameRegistration
            {
                UpdateRateSetter = CreateRateSetter(callbacks.UpdateLoopCallback),
                PushRateSetter = CreateRateSetter(callbacks.PushLoopCallback)
            };
        }