void RoLoginState::serverConnectResponse(RoNetServerType type, RoOptionalString error) { if (error.is_initialized()) { std::cerr << "[FAILED]" << std::endl; std::cerr << "\tReason: " << error.get() << std::endl; auto currentState = getCurrentStage(); changeStage(currentState, RoLoginStage::NONE); return; } std::cout << "[SUCCESS]" << std::endl; auto currentStage = RoLoginStage::LOGIN_SERVER_CONNECTING; if (getCurrentStage() != currentStage) { std::cerr << "Punting logging in due to unexpected stage" << std::endl; return; } if (!mUsername || !mPassword) { std::cerr << "Login credential is not initialized! Aborting login!" << std::endl; mLoginServer->disconnect(); return; } if (changeStage(currentStage, RoLoginStage::LOGIN_REQUEST_SENT)) { std::cout << "Logging in using credentials provided... "; RoLoginServerInterface::LoginCallback callback = std::bind(&RoLoginState::loginResponse, this, std::placeholders::_1); mLoginServer->login(mUsername.get(), mPassword.get(), callback); mUsername.reset(); mPassword.reset(); } }
void GUIPerson::drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const { glPushName(getGlID()); glPushMatrix(); glTranslated(0, 0, getType() - .1); // don't draw on top of other cars if (hasActiveAddVisualisation(parent, VO_SHOW_WALKINGAREA_PATH)) { drawAction_drawWalkingareaPath(s); } if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) { if (getCurrentStageType() == MOVING_WITHOUT_VEHICLE) { setColor(s); RGBColor current = GLHelper::getColor(); RGBColor darker = current.changedBrightness(-51); GLHelper::setColor(darker); MSPersonStage_Walking* stage = dynamic_cast<MSPersonStage_Walking*>(getCurrentStage()); assert(stage != 0); const SUMOReal exaggeration = s.personSize.getExaggeration(s); const ConstMSEdgeVector& edges = stage->getRoute(); for (ConstMSEdgeVector::const_iterator it = edges.begin(); it != edges.end(); ++it) { GUILane* lane = static_cast<GUILane*>((*it)->getLanes()[0]); GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration); } } } glPopMatrix(); glPopName(); }
void MainController::onHideAnswer() { (qDebug() << "MainController::onHideAnswer"); if ( !assertQuestionState(m_activeQuestionIndex) ) return; m_target.flushQDisplay(); m_target.setQuestion(getCurrentStage().questions[m_activeQuestionIndex].question); m_target.setView(m_view = TemplateManager::QDISPLAY); }
bool MainController::assertQuestionState(ushort qnum) const { if ( m_activeRound == 0 ) { m_target.displayError("No Stage Data", "No stage data received.", true); return false; } if ( getCurrentStage().questions.size() <= qnum ) { m_target.displayError("Question Request Out of Bounds", QString("Requested for question %1 but stage data only has %2 questions."). arg(QString::number(qnum)).arg(QString::number(getCurrentStage().questions.size())). toStdString().c_str(), true); return false; } if ( getCurrentStage().hasContestTime() ) qWarning() << "assertQuestionState(" << qnum << ") called in a stage that has a contest time (probably stages 3 and 4)."; return true; }
void MainController::onQuestionState( ushort qnum, ushort time, QUESTION_STATUS status ) { (qDebug() << "MainController::onQuestionState(" << qnum << ", " << time << ", " << status << ")"); if ( !assertQuestionState(qnum) ) return; const StageData &sd = getCurrentStage(); ContestTimer &tmr = m_target.getContestTimer(); //note: Question indexes are 0-based const Question &q = sd.questions[qnum]; m_target.setQuestionNumber(qnum + 1); m_target.setQuestionTotal(sd.questions.size()); if ( qnum != m_activeQuestionIndex ) { m_target.flushQDisplay(); m_activeQuestionIndex = qnum; } m_target.setQuestion(q.question); switch ( status ) { case QUESTION_RUNNING: if ( q.hasTimeLimit() ) { //we trust that the time sent to us is the "correct" //time, so we prefer it over what we have. tmr.restart(time * 1000u); } else { //we "don't" need the time, so pause it it. tmr.stop(); tmr.setDuration(ContestTimer::INDEFINITE); } //Don't do anything else: since we have the hideAnser and showAnswer //signals, we'll leave it to those signals so show the actual question. //Yes, it's kinda stupid that we can start the time without showing the //question but meh, don't look at me. I'm just following the protocol.. break; case QUESTION_PAUSED: //Again, we trust that the time the server is more "accurate" (though //not necessarily more precise) than what we have. so we "pause" the //timer at the received time. By stopping and setting the duration //at the passed time. tmr.stop(); tmr.setDuration(time * 1000u); break; case QUESTION_STOPPED: tmr.stop(); tmr.setDuration(0); break; } m_target.setView(m_view = TemplateManager::QDISPLAY); }
void GUIPerson::drawAction_drawWalkingareaPath(const GUIVisualizationSettings& s) const { MSPersonStage_Walking* stage = dynamic_cast<MSPersonStage_Walking*>(getCurrentStage()); if (stage != 0) { setColor(s); MSPModel_Striping::PState* stripingState = dynamic_cast<MSPModel_Striping::PState*>(stage->getPedestrianState()); if (stripingState != 0) { MSPModel_Striping::WalkingAreaPath* waPath = stripingState->myWalkingAreaPath; if (waPath != 0) { glPushMatrix(); glTranslated(0, 0, getType()); GLHelper::drawBoxLines(waPath->shape, 0.05); glPopMatrix(); } } } }
void MainController::onContestState( ushort round, CONTEST_STATUS status ) { (qDebug() << "MainController::onContestState(" << round << ", " << status << ")"); if ( m_stageData.size() < round ) { qWarning() << "Round data request out of bounds " << "(round: " << round << ") (maximum: " << m_stageData.size() << ")"; } //if we changed rounds, flush the question display since we might have the leftover //question if ( m_activeRound != round ) { m_target.flushQDisplay(); m_target.setStageNumber(round); } m_activeRound = round; ContestTimer &tmr = m_target.getContestTimer(); switch ( status ) { case CONTEST_RUNNING: //start the thingo! (make sure we set the time first) if ( getCurrentStage().hasContestTime() ) { tmr.start(); } else { //the contest has no timer?! //it must be one of those per-question rounds! //stop the timer and set it to "indefinite" tmr.stop(); tmr.setDuration(ContestTimer::INDEFINITE); } //Show the timeboard regardless. m_target.setView(m_view = TemplateManager::TIMEBOARD); break; case CONTEST_PAUSED: tmr.pause(); m_target.setView(m_view = TemplateManager::TIMEBOARD); break; case CONTEST_STOPPED: tmr.stop(); m_target.setView(m_view = TemplateManager::INDEX); break; } }
void CarManager::spawnTruckCar() { if(getCurrentStage() == 1) return; unsigned int i; Car *car; car = cars.at(cars.size() - 1); if(car->getCarState() == CAR_READY) { car->setSlideDirection(DIRECTION_NONE); car->initMe(); //manage the positions of all the cars findPositionToSpawn(car); car->setCarState(CAR_RUNNING); car->setSpeed(200); } }
bool RoLoginState::updateState(float timeSinceLastFrameInSecs) { auto stage = getCurrentStage(); bool continueState = true; switch (stage) { case RoLoginStage::NONE: if (mLoginServer->isConnected()) { mLoginServer->disconnect(); } changeStage(stage, RoLoginStage::LOGIN_PROMPT); roSCHEDULE_TASK_NAMED(LOGIN_PROMPT_TASK, RoEmptyArgs::INSTANCE); break; case RoLoginStage::LOGIN_CANCELLED: exitGame(); continueState = false; break; } return continueState; }
void RoLoginState::loginPrompt(const RoTaskArgs& args) { auto currentStage = getCurrentStage(); if (RoLoginStage::LOGIN_PROMPT != currentStage) { std::cerr << "Invalid state for login prompt(" << roGetLoginStageString(currentStage) << "). Resetting!" << std::endl; mStage.store(RoLoginStage::NONE); return; } auto username = RoCli::ReadString("Enter Username: "******"Enter Password: "******"Connecting to login server... "; // FIXME: This should come from clientinfo.xml RoLoginServerInterface::ConnectCallback callback = std::bind( &RoLoginState::serverConnectResponse, this, std::placeholders::_1, std::placeholders::_2); mLoginServer->connect(L"127.0.0.1", L"6900", callback); } }
void MainController::onShowAnswer() { (qDebug() << "MainController::onShowAnswer"); if ( !assertQuestionState(m_activeQuestionIndex) ) return; m_target.setAnswer(printfAnswerKey(getCurrentStage().questions[m_activeQuestionIndex])); m_target.setView(m_view = TemplateManager::QDISPLAY); }
void CarManager::init() { //create objects in advance on the pool Car *car = NULL; canSpawnNewCars = yes; int stageCarCount[NUM_STAGES] = {9, 8, 8, 8}; carType listType[NUM_STAGES][POOL_COUNT] = { //Stage 1 {BONUS_CAR, YELLOW_CAR, YELLOW_CAR, YELLOW_CAR, YELLOW_CAR, RED_CAR, BLUE_CAR, BLUEFIGHTER_CAR}, //Stage 2 {BONUS_CAR, YELLOW_CAR, YELLOW_CAR, RED_CAR, BLUE_CAR, BLUEFIGHTER_CAR, BLUEAGGRESSIVE_CAR, TRUCK_CAR}, //Stage 3 {BONUS_CAR, YELLOW_CAR, YELLOW_CAR, RED_CAR, BLUE_CAR, BLUEFIGHTER_CAR, BLUEAGGRESSIVE_CAR, TRUCK_CAR}, //Stage 4 {BONUS_CAR, YELLOW_CAR, YELLOW_CAR, RED_CAR, BLUE_CAR, BLUEFIGHTER_CAR, BLUEAGGRESSIVE_CAR, TRUCK_CAR}, }; int i; int current = getCurrentStage() - 1; for(i = 0; i < stageCarCount[current]; i++) { switch(listType[current][i]) { case BONUS_CAR: car = new BonusCar("Bonus Car"); break; case YELLOW_CAR: car = new YellowCar("Yellow Car"); break; case RED_CAR: car = new RedCar("Red Car"); break; case BLUE_CAR: car = new BlueCar("Blue Car"); break; case BLUEFIGHTER_CAR: car = new BlueFighterCar("Blue Fighter Car"); break; case BLUEAGGRESSIVE_CAR: car = new BlueAggressiveCar("Blue Aggressive Car"); break; case TRUCK_CAR: car = new Truck("Truck"); break; default: assert(0); } if(car != NULL) cars.push_back(car); } }