Ejemplo n.º 1
0
        public void ChangeState(gxGameState pState, bool destroyPrevious = true)
        {
            Common.UDebug.Assert(m_stateIndex >= 0);
            m_pStateStack[m_stateIndex].Release();
            if (destroyPrevious)
            {
                m_pStateStack[m_stateIndex] = null;
            }
            m_stateIndex--;


            if (pState == null)
            {
                Common.UDebug.Assert(false, "Tried to add a NULL state !!");
                ClearStateStack();
            }

            Common.UDebug.Assert(m_stateIndex < GAME_STATES_STACK_SIZE);

            m_stateIndex++;
            m_pStateStack[m_stateIndex] = pState;

            int result = pState.Initalize();

            if (result < 0)
            {
                Common.UDebug.Log(" state create failed with " + result);
                Common.UDebug.Assert(false, "Failed to create the current state!!!!");
                ClearStateStack();
            }
            else
            {
                pState.Resume();
            }
        }
Ejemplo n.º 2
0
        public void Update(float timestamp)
        {
            if (m_pStatePoped != null)
            {
                m_pStatePoped.Pause();
                m_pStatePoped.Release();
                m_stateIndex--;

                if (m_stateIndex >= 0)
                {
                    m_pStateStack[m_stateIndex].Resume();
                }
                ResetTouch();

                m_pStatePoped = null;
            }

            if (m_pStatePushed.Count > 0)
            {
                gxGameState pState = m_pStatePushed.Pop();

                if (pState == null)
                {
                    Common.UDebug.Assert(false, "Tried to add a NULL state !!!");
                    ClearStateStack();
                }

                Common.UDebug.Assert(m_stateIndex < GAME_STATES_STACK_SIZE);

                gxGameState oldState = CurrentState();
                if (oldState != null)
                {
                    oldState.Pause();
                }
                m_stateIndex++;
                m_pStateStack[m_stateIndex] = pState;

                if (pState.Initalize() < 0)
                {
                    Common.UDebug.Assert(false, "Failed to create the current state!!!!");
                    ClearStateStack();
                }
                else
                {
                    pState.Resume();
                    pState.SetLoading(true);
                }
                ResetTouch();
            }

            if (m_stateIndex < 0)
            {
                return;
            }
            if (m_pStateStack[m_stateIndex].IsLoading())
            {
                m_pStateStack[m_stateIndex].SetLoading(m_pStateStack[m_stateIndex].Load());
            }
            else
            {
                m_pStateStack[m_stateIndex].Update(timestamp);
            }
        }