コード例 #1
0
ファイル: Application.cs プロジェクト: rc183/igf
        /// <summary>
        /// </summary>
        /// <param name = "gameState"></param>
        /// <param name = "loadingGameState"></param>
        public void LoadGameState(GameState gameState, LoadingGameState loadingGameState)
        {
            if (_hideActive)
            {
                _hideActive = false;
            }

            if (gameState == null)
            {
                throw new ArgumentNullException("gameState");
            }

            // If a LoadingGameState is already associated with the Application and isn't the same as the provided one, we dispose it for replacement
            if (_loadingGameState != null && _loadingGameState != loadingGameState)
            {
                _loadingGameState.Dispose();
                _loadingGameState = null;
                GC.Collect();
            }
            // We load the LoadingGameState synchronously to avoid waiting and we make sure it will render instead of the ActiveGameState.
            if (loadingGameState != null)
            {
                _loadingGameState = loadingGameState;
                _loadingGameState.Initialize();
                _loadingGameState.Load();
                _loadingGameState.ShouldRenderLoadedGameState = false;
            }

            // We associate the GameState currently being loaded so that we can retrieve its loading percentage.
            if (_loadingGameState != null)
            {
                _loadingGameState.GameStateLoading = gameState;
            }

            if (ActiveGameState != null)
            {
                ActiveGameState.Dispose();
                ActiveGameState = null;
                GC.Collect();
            }

            ActiveGameState = gameState;

            ActiveGameState.Initialize();

            ActiveGameState.Load();
        }
コード例 #2
0
ファイル: StateManager.cs プロジェクト: KuubStudios/SAMSARA
        public GameState Push(GameState gameState)
        {
            if (gameState == null)
            {
                throw new ArgumentNullException("gameState");
            }
            if (ActiveGameState != null)
            {
                ActiveGameState.Pause();
            }

            GameStates.Add(gameState);
            ActiveGameState = gameState;
            gameState.Start();

            return(gameState);
        }
コード例 #3
0
ファイル: StateManager.cs プロジェクト: KuubStudios/SAMSARA
        public void Switch(GameState gameState)
        {
            if (gameState == null)
            {
                throw new ArgumentNullException("gameState");
            }

            if (ActiveGameState != null)
            {
                ActiveGameState.Pause();
            }
            if (!GameStates.Remove(gameState))
            {
                throw new ArgumentException(gameState + " is not on the stack");
            }

            GameStates.Add(gameState);

            gameState.Resume();
            ActiveGameState = gameState;
        }
コード例 #4
0
ファイル: StateManager.cs プロジェクト: KuubStudios/SAMSARA
        public GameState Pop()
        {
            if (ActiveGameState == null)
            {
                throw new StackOverflowException("There are no GameStates on the stack to pop");
            }

            ActiveGameState.End();
            GameStates.Remove(ActiveGameState);

            if (GameStates.Count > 0)
            {
                ActiveGameState = GameStates[GameStates.Count - 1];
                ActiveGameState.Resume();
            }
            else
            {
                ActiveGameState = null;
            }

            return(ActiveGameState);
        }
コード例 #5
0
 internal void Reset()
 {
     state = new ActiveGameState();
     OnStateChanged();
 }