/**
 * Start level under pressed button.
 * Start pedometer when level is solved already.
 */
    void
WorldMap::runSelected()
{
    Level *level = createSelected();
    if (level) {
        m_levelStatus->prepareRun(m_selected->getCodename(),
                m_selected->getPoster(),
                m_selected->getBestMoves(),
                m_selected->getBestAuthor());
        level->fillStatus(m_levelStatus);

        if (m_selected->getState() == LevelNode::STATE_SOLVED) {
            Pedometer *pedometer = new Pedometer(m_levelStatus, level);
            pushState(pedometer);
        }
        else {
            pushState(level);
        }
    }
    else {
        if (m_activeMask == m_maskIntro) {
            runIntro();
        }
        else if (m_activeMask == m_maskExit) {
            quitState();
        }
        else if (m_activeMask == m_maskCredits) {
            runCredits();
        }
        else if (m_activeMask == m_maskOptions) {
            runOptions();
        }
    }
}
Exemple #2
0
Lexer::Lexer( Parser* _parser, const QString& content ):
        m_content( content ), m_parser( _parser ),
        m_curpos( 0 ), m_contentSize( m_content.size() ),
        m_tokenBegin( 0 ), m_tokenEnd( 0 )
{
    pushState( ErrorState );
    pushState( DefaultState );
}
Lexer::Lexer(TokenStream* tokenStream, const QString& content, int initialState):
        m_content(content), m_tokenStream(tokenStream),
        m_curpos(0), m_contentSize(m_content.size()),
        m_tokenBegin(0), m_tokenEnd(0), m_haltCompiler(0)
{
    pushState(ErrorState);
    pushState(initialState);
}
Exemple #4
0
TEST(Wikipedia, AddAndMultiply)
{
    input = "1+0+1*1+1+1+1+1+1*1";

    nextToken();
    pushState(0);
    while((top() != STATE_ERROR) && (top() != STATE_ACCEPT))
        pushState(parseFunction(token));

    EXPECT_EQ(STATE_ACCEPT, top()) << "An error has occured while parsing expression";
    EXPECT_EQ(7, valueStack[nbValues - 1].value);
}
void RTF::Reader::read(QIODevice* device, QTextDocument* text)
{
	try {
		// Open file
		m_text = 0;
		if (!m_cursor.isNull()) {
			m_cursor = QTextCursor();
		}
		m_text = text;
		m_cursor = QTextCursor(m_text);
		m_cursor.movePosition(QTextCursor::End);
		m_token.setDevice(device);
		setBlockDirection(Qt::LeftToRight);

		// Check file type
		m_token.readNext();
		if (m_token.type() == StartGroupToken) {
			pushState();
		} else {
			throw tr("Not a supported RTF file.");
		}
		m_token.readNext();
		if (m_token.type() != ControlWordToken || m_token.text() != "rtf" || m_token.value() != 1) {
			throw tr("Not a supported RTF file.");
		}

		// Parse file contents
		while (!m_states.isEmpty() && m_token.hasNext()) {
			m_token.readNext();

			if ((m_token.type() != EndGroupToken) && !m_in_block) {
				m_cursor.insertBlock();
				m_in_block = true;
			}

			if (m_token.type() == StartGroupToken) {
				pushState();
			} else if (m_token.type() == EndGroupToken) {
				popState();
			} else if (m_token.type() == ControlWordToken) {
				if (!m_state.ignore_control_word && functions.contains(m_token.text())) {
					functions[m_token.text()].call(this, m_token);
				}
			} else if (m_token.type() == TextToken) {
				if (!m_state.ignore_text) {
					m_cursor.insertText(m_codec->toUnicode(m_token.text()));
				}
			}
		}
	} catch (const QString& error) {
		m_error = error;
	}
}
Exemple #6
0
void
PlayState::keyPressed
(const OIS::KeyEvent &e)
{
  // Tecla p --> PauseState.
  if (e.key == OIS::KC_P) {
    pushState(PauseState::getSingletonPtr());
  }
  if (e.key == OIS::KC_M) {
    pushState(FinalState::getSingletonPtr());
  }
  if ((e.key == OIS::KC_B) && (_timeLastObject <= 0)) 
    //AddDynamicObject(box);
  if (e.key == OIS::KC_E){
    //_shootKeyDown = true;
  } 
  else{
    _keyDownTime = 0.0;
  }
  if (e.key == OIS::KC_H){
    OBEntity *obAux = new OBEntity("none");
    std::cout << "OBEntities" << std::endl;
    for(std::vector<OBEntity *>::iterator it = _obEntities.begin(); it != _obEntities.end(); ++it) {
      obAux = *it;
      std::cout << obAux->getType() <<std::endl;
    }
  } 
  if (e.key == OIS::KC_A){ //AerialCamera
    _root->getAutoCreatedWindow()->removeAllViewports();
    _viewport = _root->getAutoCreatedWindow()->addViewport(_aerialCamera);
    double width = _viewport->getActualWidth();
    double height = _viewport->getActualHeight();
    _aerialCamera->setAspectRatio(width / height);
  }
  if (e.key == OIS::KC_D){ //DefaultCamera
    _root->getAutoCreatedWindow()->removeAllViewports();
    _viewport = _root->getAutoCreatedWindow()->addViewport(_camera);
    double width = _viewport->getActualWidth();
    double height = _viewport->getActualHeight();
    _camera->setAspectRatio(width / height);
  }

  if (e.key == OIS::KC_S && _trackedBody){
     _root->getAutoCreatedWindow()->removeAllViewports();
     _viewport = _root->getAutoCreatedWindow()->addViewport(_projectileCamera);
     double width = _viewport->getActualWidth();
     double height = _viewport->getActualHeight();
     _projectileCamera->setAspectRatio(width / height);
  } 
   
}
void RTF::Reader::insertUnicodeSymbol(qint32 value)
{
	m_cursor.insertText(QChar(value));

	for (int i = m_state.skip; i > 0;) {
		m_token.readNext();

		if (m_token.type() == TextToken) {
			int len = m_token.text().count();
			if (len > i) {
				m_cursor.insertText(m_codec->toUnicode(m_token.text().mid(i)));
				break;
			} else {
				i -= len;
			}
		} else if (m_token.type() == ControlWordToken) {
			--i;
		} else if (m_token.type() == StartGroupToken) {
			pushState();
			break;
		} else if (m_token.type() == EndGroupToken) {
			popState();
			break;
		}
	}
}
void CursorDropdown::onStateDeactivate(StateEvent* event)
{
    if (!_deactivated)
    {
        auto game = Game::getInstance();
        auto mouse = game->mouse();
        // workaround to get rid of cursor disappearing issues
        std::vector<unsigned int> icons;
        while (mouse->states()->size() > _initialMouseStack)
        {
            icons.push_back(mouse->state());
            mouse->popState();
        }
        if (icons.size() > 0)
        {
            icons.pop_back(); // remove empty icon from CursorDropdown state
            // place only new icons back in stack
            for (auto it = icons.rbegin(); it != icons.rend(); it++)
            {
                mouse->pushState(*it);
            }
        }
        mouse->setX(_initialX);
        mouse->setY(_initialY);
        _deactivated = true;
    }
}
	void GamePlayState::exit() {
		LOG_INFO("GamePlayState: Exiting");

		// mConsole->setActive(false);

		// Debugging pos/dir writes. For performance profiling
		// std::cerr << mCamera->getPosition() << std::endl;
		// std::cerr << mCamera->getDirection() << std::endl;

		if (mPortalOverlay)
			mPortalOverlay->hide();

		if (mDebugOverlay)
			mDebugOverlay->hide();
		/*mConsole->setActive(false);
		mConsole->update(1); // to hide the console while exiting
		*/

		if (mToLoadScreen) {
			pushState(GameLoadState::getSingletonPtr());
			mToLoadScreen = false;
		}

		LOG_INFO("GamePlayState: Exited");
	}
void QGstreamerPlayerControl::updateMediaStatus()
{
    pushState();
    QMediaPlayer::MediaStatus oldStatus = m_mediaStatus;

    switch (m_session->state()) {
    case QMediaPlayer::StoppedState:
        if (m_currentResource.isNull())
            m_mediaStatus = QMediaPlayer::NoMedia;
        else if (oldStatus != QMediaPlayer::InvalidMedia)
            m_mediaStatus = QMediaPlayer::LoadingMedia;
        break;

    case QMediaPlayer::PlayingState:
    case QMediaPlayer::PausedState:
        if (m_currentState == QMediaPlayer::StoppedState) {
            m_mediaStatus = QMediaPlayer::LoadedMedia;
        } else {
            if (m_bufferProgress == -1 || m_bufferProgress == 100)
                m_mediaStatus = QMediaPlayer::BufferedMedia;
            else
                m_mediaStatus = QMediaPlayer::StalledMedia;
        }
        break;
    }

    if (m_currentState == QMediaPlayer::PlayingState && !m_resources->isGranted())
        m_mediaStatus = QMediaPlayer::StalledMedia;

    //EndOfMedia status should be kept, until reset by pause, play or setMedia
    if (oldStatus == QMediaPlayer::EndOfMedia)
        m_mediaStatus = QMediaPlayer::EndOfMedia;

    popAndNotifyState();
}
void stateMachine::tick(sf::Time deltaTime)
    {
        // check if someone wants to close the window
        // do this at the start of the loop so it doesnt happen inbetween rendering and updating    
        if (_closeWindow)
            {
                _window->close();
            }

        // check if a state is popped
        // We need this flag so a state isnt popped/cleaned up mid render/update. If it does happen, program crashes
        if (_popState)
            {
                // if so, pop it off the stack
                popStateFromStack();
            }

        // this makes sure that a state isnt changed mid render / update
        if (!_queuedState.empty())
            {
                for (int i = (_queuedState.size() - 1); i >= 0; i--)
                    {
                        pushState(_queuedState.front());
                        _queuedState.pop();
                    }
            }
        
        handleInput();
        update(deltaTime);
    }
Exemple #12
0
void Game::init(int width, int height, bool fullscreen) {
	Game::print("Initialisation du jeu...");
	end = false;

	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) == -1) {
		Game::assert(std::string("Impossible d'initialiser la SDL") + SDL_GetError());
	}

	atexit(SDL_Quit);

	if (TTF_Init() == -1) {
		Game::assert(std::string("Impossible d'initialiser SDL_ttf : ") + TTF_GetError());
	}

	atexit(TTF_Quit);

	Uint32 flags = SDL_HWSURFACE | SDL_DOUBLEBUF;
	if (fullscreen) flags |= SDL_FULLSCREEN;
	if ((window = SDL_SetVideoMode(width, height, 0, SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL)
		Game::assert(std::string("La fenêtre n'a pas pu être créé : ") + SDL_GetError());
	SDL_WM_SetCaption("My Game Square", NULL);

	std::srand(std::time(0));

	std::string fontName = "/usr/share/fonts/TTF/DejaVuSans.ttf";
	if ((font = TTF_OpenFont(fontName.c_str(), 28)) == NULL)
		Game::assert(std::string("Impossible de charger la police " + fontName + " : " + TTF_GetError()));

	Game::print("Création du menu...");
	GameState *menu = new Menu();
	if (!menu)
		Game::assert("Création du menu impossible");
	Game::print("Menu comme premier état du jeu.");
	pushState(menu);
}
Exemple #13
0
void CGameEngine::winGame()
{
	CLog::debug("Partie gagne");
	pause();
	boost::shared_ptr<CGameWonState> winState(new CGameWonState());
	pushState(winState);
}
void StateManager::changeState(State *state) {
	// pop the current state
	popState();

	// push the new state
	pushState(state);
}
//-----------------------------------------------------------------
    void
WorldMap::runIntro()
{
#ifdef HAVE_SMPEG
    Path movieFile = Path::dataReadPath("images/menu/intro.mpg");
    if (movieFile.exists()) {
        pushState(new MovieState(movieFile));
        return;
    }

    LOG_WARNING(ExInfo("cannot find intro")
            .addInfo("file", movieFile.getNative()));
#endif

    pushState(new DemoMode(Path::dataReadPath("script/share/demo_intro.lua")));
}
Exemple #16
0
void Game::changeState(GameState* state) {
    if(!this->states.empty())
        popState();
    pushState(state);

    return;
}
/**
 * Internal function to start a new field.
 * @param name Name of the field to declare.
**/
void JsonState::openField(const char * name)
{
	//check where we are
	assert(getState() & (JSON_STATE_ROOT | JSON_STATE_STRUCT));

	//print name
	if (!isFirst())
	{
		if (useIndent)
			bufferdStream << ',' << LINE_BREAK;
		else
			bufferdStream << ',';
	}

	//setup state
	pushState(JSON_STATE_FIELD);

	//print padding
	putPadding();

	//print name
	if (lua)
		bufferdStream << name << '=';
	else
		bufferdStream << '"' << name << '"' << ':';
}
Exemple #18
0
void Game::executeStackChanges()
{
	// Parameters expected in mStackAction and mStackParam.
	switch (rStackAction) {
	case SAID::POP:
	{
		popState();
		break;
	}
	case SAID::PUSH:
	{
		pushState(rStackParam);
		break;
	}
	case SAID::SWAP:
	{
		swapState(rStackParam);
		break;
	}
	case SAID::RETURN_TO:
	{
		returnToState(rStackParam);
		break;
	}
	case SAID::CLEAR:
	{
		clearStateStack();
		break;
	}
	default: break;
	}

	// Finally, reset stack action requests:
	rStackAction = SAID::NOTHING;
}
Exemple #19
0
void StateMachine::popStateOrRevert()
{
	if(!popState())
	{
		pushState(previousState);
	}
}
Exemple #20
0
//Notifie le jeu qu'un Hero est mort
void CGameEngine::heroDied(boost::shared_ptr<CHero> deadHero)
{
	deadHero->setActive(false);

	bool areAllPlayerDead = true;
	for(std::map<Int8, CPlayer>::const_iterator i=m_players.begin(); i != m_players.end(); i++)
		if(i->second.getEntity()->isActive())
			areAllPlayerDead = false;

	if(areAllPlayerDead)
	{
		CLog::debug("Partie perdu");
		pause();
		boost::shared_ptr<CGameLostState> loseState(new CGameLostState());
		pushState(loseState);
	}
	else
	{
		boost::shared_ptr<IModel> satanModel = getResEngine()->getModel("Satan");
		satanModel->setAnim("Fly");
		boost::shared_ptr<CSatanModel> model(new CSatanModel(deadHero->getModel(),satanModel));
		boost::shared_ptr<IEntity> satan(new CSatan(200,deadHero,model));
		satan->setDim(sf::Vector2f(140,200));
		addEntity(satan);
	}
}
void QGstreamerPlayerControl::setPosition(qint64 pos)
{
#ifdef DEBUG_PLAYBIN
    qDebug() << Q_FUNC_INFO << pos/1000.0;
#endif

    pushState();

    if (m_mediaStatus == QMediaPlayer::EndOfMedia) {
        m_mediaStatus = QMediaPlayer::LoadedMedia;
    }

    if (m_currentState == QMediaPlayer::StoppedState) {
        m_pendingSeekPosition = pos;
        emit positionChanged(m_pendingSeekPosition);
    } else if (m_session->isSeekable()) {
        m_session->showPrerollFrames(true);
        m_session->seek(pos);
        m_pendingSeekPosition = -1;
    } else if (m_session->state() == QMediaPlayer::StoppedState) {
        m_pendingSeekPosition = pos;
        emit positionChanged(m_pendingSeekPosition);
    } else if (m_pendingSeekPosition != -1) {
        m_pendingSeekPosition = -1;
        emit positionChanged(m_pendingSeekPosition);
    }

    popAndNotifyState();
}
void PlayState::keyPressed(const OIS::KeyEvent &e)
{
  CEGUI::System::getSingleton().getDefaultGUIContext().injectKeyDown(static_cast<CEGUI::Key::Scan>(e.key));
  CEGUI::System::getSingleton().getDefaultGUIContext().injectChar(e.text);
  
  _vtBarco = Ogre::Vector3(0,0,0);
  _vtCamara = Ogre::Vector3(0,0,0);

  switch (e.key)
  {
    case OIS::KC_UP:		_vtCamara+=Ogre::Vector3(0,0,-1); cout<< "UP" << endl; break;
    case OIS::KC_DOWN:		_vtCamara+=Ogre::Vector3(0,0,1);  cout<< "DOWN" << endl; break;
    //case OIS::KC_LEFT:		_vtCamara+=Ogre::Vector3(-1,0,0); cout<< "LEFT" << endl; break;
    //case OIS::KC_RIGHT:		_vtCamara+=Ogre::Vector3(1,0,0);  cout<< "RIGHT" << endl; break;
    case OIS::KC_A:	_vtBarco+=Vector3(1,0,0);  break;
    case OIS::KC_S:	_vtBarco+=Vector3(0,0,-1); break;
    case OIS::KC_D:	_vtBarco+=Vector3(-1,0,0); break;
    case OIS::KC_W:	_vtBarco+=Vector3(0,0,1);  break;
    default:   	cout << "VTBarco " << _vtBarco << endl;
                cout << "VTCamara " << _vtCamara << endl;
  }
  

  // Tecla p --> PauseState.
  if (e.key == OIS::KC_P) {
    pushState(PauseState::getSingletonPtr());
  }
}
Exemple #23
0
void App::changeState(AppState* state) {
    if(!this->states.empty())
        popState();
    pushState(state);
    
    return;
}
Exemple #24
0
void GameManager::changeState(GameState* state)
{
	if (!gameState.empty())
	{
		popState();
	}
	pushState(state);
}
Exemple #25
0
void Game::changeState(GameState* state)
{
	if (!states.empty())
	{
		popState();
	}
	pushState(state);
}
Exemple #26
0
void StateManager::jumpState (const std::string &state)
{
	if (canChangeState())
	{
		popAllStates();
		pushState(state);
	}
}
void StateManager::startGame() {
	popAll();	// pop all current states

	// put party on world map
	MapState *ms = new MapState();
	pushState(ms);
	ms->pushMap(new World());
}
void QGstreamerPlayerControl::handleInvalidMedia()
{
    pushState();
    m_mediaStatus = QMediaPlayer::InvalidMedia;
    m_currentState = QMediaPlayer::StoppedState;
    m_setMediaPending = true;
    popAndNotifyState();
}
Exemple #29
0
/**
 * Pops all the states currently in stack and pushes in the new state.
 * A shortcut for cleaning up all the old states when they're not necessary
 * like in one-way transitions.
 * @param state Pointer to the new state.
 */
void Game::setState(State *state)
{
	while (!_states.empty())
	{
		popState();
	}
	pushState(state);
	_init = false;
}
Exemple #30
0
void GameEngine::changeState(GameState* state)
{
    if (!states.empty()) {
        popState();
    }

    pushState(state);

    peekState()->Init(this);
}