//********************************* // PAUSE MENU STATE FUNCTION //********************************* STATES Pause_Menu::StateFunction(){ //first frame update al_clear_to_color(al_map_rgb(0,0,0)); Pause_Title.draw(); Pause_Resume.stepFrame(); Pause_Resume.draw(); Pause_Exit.draw(); al_flip_display(); render = false; //**GAME LOOP****GAME LOOP****GAME LOOP** while(!done){ ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); executeEvent(ev); } return next_state; }
void Cmd::handleRequest() { switch(getCommand()) { case LIST : prepareDb(); executeList(); break; case UPDATE : prepareDb(); executeUpdate(); break; case ACT : prepareDb(); executeAct(); break; case DEACT : prepareDb(); executeDeact(); break; case EXEC : prepareDb(); executeExec(); break; case EVENT : prepareDb(); executeEvent(); break; case VERSION : executeVersion(); default: cons.printError("no command found"); break; } }
EventExecutor::~EventExecutor(){ bool wasRunning; { std::lock_guard<std::mutex> lock(m_isRunningMutex); // See if we were running in the first place. wasRunning = m_isRunning; // Exit run loop. m_isRunning = false; // Allows run thread to exit. m_eventSemaphore.shutdown(); } // Unlock Mutex join(); //wait for thread to exit //Run all unexecuted events if only start was called if (wasRunning) { // No need to put m_eventList in mutexes, // as the run thread has exited. while (!m_eventList.empty()){ executeEvent(); } } }
void Service::LoopEvent() { OutputDebugString(L"イベントのハンドリング開始\n"); // サービス初期処理 LoopEventInitialize(); // イベントハンドリング処理 while(true){ // イベント実行 Event ev; if (m_eventList->pop(ev)) { executeEvent(ev); } // サービス停止チェック if (!m_isOpen) { break; } } // サービス終了処理 LoopEventFinalize(); OutputDebugString(L"イベントのハンドリング終了\n"); }
void MountedChampionAI::UpdateAI(const uint32 diff) { if (!UpdateVictim() || defeated) return; eventMap.Update(diff); if (me->HasUnitState(UNIT_STATE_CASTING)) return; if (uint32 eventID = eventMap.ExecuteEvent()) { executeEvent(eventID); return; } // Use Thrust instead of melee attack if (me->isAttackReady() && me->IsWithinMeleeRange(me->getVictim())) { me->AddUnitState(UNIT_STATE_ONVEHICLE); DoCast(me->getVictim(), SPELL_THRUST); me->ResetAttackTimer(); me->ClearUnitState(UNIT_STATE_ONVEHICLE); } }
void MapIso::checkEvents(Point loc) { Point maploc; maploc.x = loc.x >> TILE_SHIFT; maploc.y = loc.y >> TILE_SHIFT; for (int i=0; i<event_count; i++) { if (maploc.x >= events[i].location.x && maploc.y >= events[i].location.y && maploc.x <= events[i].location.x + events[i].location.w-1 && maploc.y <= events[i].location.y + events[i].location.h-1) { executeEvent(i); } } }
void Sequencer::executeEvents() { _commandSection.enter(); int s = _commandCollector.size(); for (int i=0;i<s;i++) { HostEvent* pCommand = &_commandCollector.getReference(i); executeEvent(pCommand); } _commandCollector.clear(); _commandSection.exit(); }
void MapIso::checkEventClick() { Point p; SDL_Rect r; for(int i=0; i<event_count; i++) { p = map_to_screen(events[i].location.x * UNITS_PER_TILE + UNITS_PER_TILE/2, events[i].location.y * UNITS_PER_TILE + UNITS_PER_TILE/2, cam.x, cam.y); r.x = p.x + events[i].hotspot.x; r.y = p.y + events[i].hotspot.y; r.h = events[i].hotspot.h; r.w = events[i].hotspot.w; // execute if: EVENT IS ACTIVE && MOUSE IN HOTSPOT && HOTSPOT EXISTS && CLICKING && HERO WITHIN RANGE if (isActive(i) && isWithin(r, inp->mouse) && (events[i].hotspot.h != 0) && inp->pressing[MAIN1] && !inp->lock[MAIN1] && (abs(cam.x - events[i].location.x * UNITS_PER_TILE) < CLICK_RANGE && abs(cam.y - events[i].location.y * UNITS_PER_TILE) < CLICK_RANGE)) { inp->lock[MAIN1] = true; executeEvent(i); } } }
void RisenGhoulAI::UpdateAI(const uint32 diff) { if (!UpdateVictim()) return; eventMap.Update(diff); if (me->HasUnitState(UNIT_STATE_CASTING)) return; if (uint32 eventID = eventMap.ExecuteEvent()) { executeEvent(eventID); return; } DoMeleeAttackIfReady(); }
void EventManager::executeScript(const std::string& filename, float x, float y) { FileParser script_file; std::queue<Event> script_evnt; if (script_file.open(filename)) { while (script_file.next()) { if (script_file.new_section && script_file.section == "event") { Event tmp_evnt; tmp_evnt.location.x = tmp_evnt.hotspot.x = static_cast<int>(x); tmp_evnt.location.y = tmp_evnt.hotspot.y = static_cast<int>(y); tmp_evnt.location.w = tmp_evnt.hotspot.w = 1; tmp_evnt.location.h = tmp_evnt.hotspot.h = 1; tmp_evnt.center.x = static_cast<float>(tmp_evnt.location.x) + 0.5f; tmp_evnt.center.y = static_cast<float>(tmp_evnt.location.y) + 0.5f; script_evnt.push(tmp_evnt); } if (script_evnt.empty()) continue; if (script_file.key == "script" && script_file.val == filename) { script_file.error("EventManager: Calling a script from within itself is not allowed."); continue; } loadEventComponent(script_file, &script_evnt.back(), NULL); } script_file.close(); while (!script_evnt.empty()) { // create StatBlocks if we need them Event_Component *ec_power = script_evnt.front().getComponent(EC_POWER); if (ec_power) { ec_power->y = mapr->addEventStatBlock(script_evnt.front()); } if (isActive(script_evnt.front())) { executeEvent(script_evnt.front()); } script_evnt.pop(); } } }
int Client::receiveEvent(Event event){ //called when the app receives an event from the server //returns 0 for no error QString text; if (event.nvk>=32 && event.nvk<=126){ text = QString(1,(char)event.nvk); } else if (event.nvk==65293) { //enter text = QString("\n"); } else if (event.nvk==65288) { //backspace text = QString("bksp"); } else if (event.nvk==65535) { //delete text = QString("del"); } else if (event.nvk==65289) { //tab text = QString(" "); } else { text = QString(""); } executeEvent(event.pos,text); return(0); }
// This is the basic program loop. // When the program launches, or when a game ends, you end up here. // If the player has already said what he wants to do next // (by storing it in rogue.nextGame -- possibilities listed in enum NGCommands), // we'll do it. The path (rogue.nextGamePath) is essentially a parameter for this command, and // tells NG_VIEW_RECORDING and NG_OPEN_GAME which file to open. If there is a command but no // accompanying path, and it's a command that should take a path, then pop up a dialog to have // the player specify a path. If there is no command (i.e. if rogue.nextGame contains NG_NOTHING), // then we'll display the title screen so the player can choose. void mainBrogueJunction() { rogueEvent theEvent; char path[BROGUE_FILENAME_MAX], buf[100], seedDefault[100]; char maxSeed[20]; short i, j, k; boolean seedTooBig; // clear screen and display buffer for (i=0; i<COLS; i++) { for (j=0; j<ROWS; j++) { displayBuffer[i][j].character = 0; displayBuffer[i][j].needsUpdate = false; displayBuffer[i][j].opacity = 100; for (k=0; k<3; k++) { displayBuffer[i][j].foreColorComponents[k] = 0; displayBuffer[i][j].backColorComponents[k] = 0; } plotCharWithColor(' ', i, j, &black, &black); } } initializeLaunchArguments(&rogue.nextGame, rogue.nextGamePath, &rogue.nextGameSeed); do { rogue.gameHasEnded = false; rogue.playbackFastForward = false; rogue.playbackMode = false; switch (rogue.nextGame) { case NG_NOTHING: // Run the main menu to get a decision out of the player. // Seth: Added setBrogueGameEvent(BrogueGameEventShowTitle); titleMenu(); break; case NG_NEW_GAME: case NG_NEW_GAME_WITH_SEED: rogue.nextGamePath[0] = '\0'; randomNumbersGenerated = 0; rogue.playbackMode = false; rogue.playbackFastForward = false; rogue.playbackBetweenTurns = false; getAvailableFilePath(path, LAST_GAME_NAME, GAME_SUFFIX); strcat(path, GAME_SUFFIX); strcpy(currentFilePath, path); if (rogue.nextGame == NG_NEW_GAME_WITH_SEED) { if (rogue.nextGameSeed == 0) { // Prompt for seed; default is the previous game's seed. sprintf(maxSeed, "%lu", ULONG_MAX); if (previousGameSeed == 0) { seedDefault[0] = '\0'; } else { sprintf(seedDefault, "%lu", previousGameSeed); } if (getInputTextString(buf, "Generate dungeon with seed number:", log10(ULONG_MAX) + 1, seedDefault, "", TEXT_INPUT_NUMBERS, true) && buf[0] != '\0') { seedTooBig = false; if (strlen(buf) > strlen(maxSeed)) { seedTooBig = true; } else if (strlen(buf) == strlen(maxSeed)) { for (i=0; maxSeed[i]; i++) { if (maxSeed[i] > buf[i]) { break; // we're good } else if (maxSeed[i] < buf[i]) { seedTooBig = true; break; } } } if (seedTooBig) { rogue.nextGameSeed = ULONG_MAX; } else { sscanf(buf, "%lu", &rogue.nextGameSeed); } } else { rogue.nextGame = NG_NOTHING; break; // Don't start a new game after all. } } } else { rogue.nextGameSeed = 0; // Seed based on clock. } // Seth: Added setBrogueGameEvent(BrogueGameEventStartNewGame); rogue.nextGame = NG_NOTHING; initializeRogue(rogue.nextGameSeed); startLevel(rogue.depthLevel, 1); // descending into level 1 mainInputLoop(); freeEverything(); break; case NG_OPEN_GAME: rogue.nextGame = NG_NOTHING; // Seth: Added setBrogueGameEvent(BrogueGameEventBeginOpenGame); path[0] = '\0'; if (rogue.nextGamePath[0]) { strcpy(path, rogue.nextGamePath); rogue.nextGamePath[0] = '\0'; } else { dialogChooseFile(path, GAME_SUFFIX, "Open saved game:"); //chooseFile(path, "Open saved game: ", "Saved game", GAME_SUFFIX); } if (openFile(path)) { loadSavedGame(); // Seth: Added setBrogueGameEvent(BrogueGameEventOpenGame); mainInputLoop(); freeEverything(); } else { //dialogAlert("File not found."); } rogue.playbackMode = false; rogue.playbackOOS = false; // Seth: Added setBrogueGameEvent(BrogueGameEventOpenGameFinished); break; case NG_VIEW_RECORDING: rogue.nextGame = NG_NOTHING; // Seth: Added setBrogueGameEvent(BrogueGameEventBeginOpenGame); path[0] = '\0'; if (rogue.nextGamePath[0]) { strcpy(path, rogue.nextGamePath); rogue.nextGamePath[0] = '\0'; } else { dialogChooseFile(path, RECORDING_SUFFIX, "View recording:"); //chooseFile(path, "View recording: ", "Recording", RECORDING_SUFFIX); } if (openFile(path)) { // Seth: Added setBrogueGameEvent(BrogueGameEventPlayRecording); randomNumbersGenerated = 0; rogue.playbackMode = true; initializeRogue(0); // Seed argument is ignored because we're in playback. if (!rogue.gameHasEnded) { startLevel(rogue.depthLevel, 1); pausePlayback(); displayAnnotation(); // in case there's an annotation for turn 0 } while(!rogue.gameHasEnded && rogue.playbackMode) { rogue.RNG = RNG_COSMETIC; // dancing terrain colors can't influence recordings rogue.playbackBetweenTurns = true; nextBrogueEvent(&theEvent, false, true, false); rogue.RNG = RNG_SUBSTANTIVE; executeEvent(&theEvent); } freeEverything(); } else { // announce file not found } rogue.playbackMode = false; rogue.playbackOOS = false; break; case NG_HIGH_SCORES: rogue.nextGame = NG_NOTHING; // Seth: Added setBrogueGameEvent(BrogueGameEventShowHighScores); printHighScores(false); break; case NG_SCUM: rogue.nextGame = NG_NOTHING; scum(1, 1000, 5); break; case NG_QUIT: // No need to do anything. break; default: break; } } while (rogue.nextGame != NG_QUIT); }
// This is the basic program loop. // When the program launches, or when a game ends, you end up here. // If the player has already said what he wants to do next // (by storing it in rogue.nextGame -- possibilities listed in enum NGCommands), // we'll do it. The path (rogue.nextGamePath) is essentially a parameter for this command, and // tells NG_VIEW_RECORDING and NG_OPEN_GAME which file to open. If there is a command but no // accompanying path, and it's a command that should take a path, then pop up a dialog to have // the player specify a path. If there is no command (i.e. if rogue.nextGame contains NG_NOTHING), // then we'll display the title screen so the player can choose. void mainBrogueJunction() { rogueEvent theEvent; char path[BROGUE_FILENAME_MAX], buf[100], seedDefault[100]; char maxSeed[64]; short i; boolean seedTooBig; if (ioInitialize() != 0) { printf("Failure to initialize display\n"); exit(1); } initializeLaunchArguments(&rogue.nextGame, rogue.nextGamePath, &rogue.nextGameSeed); do { rogue.gameHasEnded = false; rogue.playbackFastForward = false; rogue.playbackMode = false; switch (rogue.nextGame) { case NG_NOTHING: // Run the main menu to get a decision out of the player. titleMenu(); break; case NG_NEW_GAME: case NG_NEW_GAME_WITH_SEED: rogue.nextGamePath[0] = '\0'; randomNumbersGenerated = 0; rogue.playbackMode = false; rogue.playbackFastForward = false; rogue.playbackBetweenTurns = false; getAvailableFilePath(path, LAST_GAME_NAME, GAME_SUFFIX); strcat(path, GAME_SUFFIX); strcpy(currentFilePath, path); if (rogue.nextGame == NG_NEW_GAME_WITH_SEED) { if (rogue.nextGameSeed == 0) { // Prompt for seed; default is the previous game's seed. sprintf(maxSeed, "%lu", ULONG_MAX); if (previousGameSeed == 0) { seedDefault[0] = '\0'; } else { sprintf(seedDefault, "%lu", previousGameSeed); } if (getInputTextString(buf, "输入随机数种子生成地下城:", log10(ULONG_MAX) + 1 + 6, // pad for header text seedDefault, "", TEXT_INPUT_NUMBERS, true) && buf[0] != '\0') { seedTooBig = false; if (strlen(buf) > strlen(maxSeed)) { seedTooBig = true; } else if (strlen(buf) == strlen(maxSeed)) { for (i=0; maxSeed[i]; i++) { if (maxSeed[i] > buf[i]) { break; // we're good } else if (maxSeed[i] < buf[i]) { seedTooBig = true; break; } } } if (seedTooBig) { rogue.nextGameSeed = ULONG_MAX; } else { sscanf(buf, "%lu", &rogue.nextGameSeed); } } else { rogue.nextGame = NG_NOTHING; break; // Don't start a new game after all. } } } else { rogue.nextGameSeed = 0; // Seed based on clock. } rogue.nextGame = NG_NOTHING; initializeRogue(rogue.nextGameSeed); startLevel(rogue.depthLevel, 1); // descending into level 1 mainInputLoop(); freeEverything(); break; case NG_OPEN_GAME: rogue.nextGame = NG_NOTHING; path[0] = '\0'; if (rogue.nextGamePath[0]) { strcpy(path, rogue.nextGamePath); rogue.nextGamePath[0] = '\0'; } else { dialogChooseFile(path, GAME_SUFFIX, "选择中断存档进行读取:"); //chooseFile(path, "Open saved game: ", "Saved game", GAME_SUFFIX); } if (openFile(path)) { loadSavedGame(); mainInputLoop(); freeEverything(); } else { //dialogAlert("File not found."); } rogue.playbackMode = false; rogue.playbackOOS = false; break; case NG_VIEW_RECORDING: rogue.nextGame = NG_NOTHING; path[0] = '\0'; if (rogue.nextGamePath[0]) { strcpy(path, rogue.nextGamePath); rogue.nextGamePath[0] = '\0'; } else { dialogChooseFile(path, RECORDING_SUFFIX, "选择录像文件进行回放:"); //chooseFile(path, "View recording: ", "Recording", RECORDING_SUFFIX); } if (openFile(path)) { randomNumbersGenerated = 0; rogue.playbackMode = true; initializeRogue(0); // Seed argument is ignored because we're in playback. if (!rogue.gameHasEnded) { startLevel(rogue.depthLevel, 1); pausePlayback(); displayAnnotation(); // in case there's an annotation for turn 0 } while(!rogue.gameHasEnded && rogue.playbackMode) { rogue.RNG = RNG_COSMETIC; // dancing terrain colors can't influence recordings rogue.playbackBetweenTurns = true; nextBrogueEvent(&theEvent, false, true, false); rogue.RNG = RNG_SUBSTANTIVE; executeEvent(&theEvent); } freeEverything(); } else { // announce file not found } rogue.playbackMode = false; rogue.playbackOOS = false; break; case NG_HIGH_SCORES: rogue.nextGame = NG_NOTHING; printHighScores(false); break; case NG_SCUM: rogue.nextGame = NG_NOTHING; scum(1, 1000, 5); break; case NG_QUIT: // No need to do anything. break; default: break; } } while (rogue.nextGame != NG_QUIT); }
//-------------------------------------------------------------------------------------------- // implementation of IAppMgrUI::nextEvent //-------------------------------------------------------------------------------------------- StatusCode MTEventLoopMgr::nextEvent(int maxevt) { DataObject* pObject = 0; StatusCode sc; // loop over events if the maxevt (received as input) if different from -1. // if evtmax is -1 it means infinite loop for( int nevt = 0; (maxevt == -1 ? true : nevt < maxevt); nevt++, m_total_nevt++) { // Clear the event store, if used in the event loop if( 0 != m_total_nevt ) { sc = m_evtDataMgrSvc->clearStore(); if( !sc.isSuccess() ) { MsgStream log( msgSvc(), name() ); log << MSG::DEBUG << "Clear of Event data store failed" << endmsg; } } // Setup event in the event store if( m_evtCtxt ) { IOpaqueAddress* addr = 0; // Only if there is a EventSelector sc = getEventRoot(addr); if( !sc.isSuccess() ) { MsgStream log( msgSvc(), name() ); log << MSG::INFO << "No more events in event selection " << endmsg; break; } // Set root clears the event data store first sc = m_evtDataMgrSvc->setRoot ("/Event", addr); if( !sc.isSuccess() ) { MsgStream log( msgSvc(), name() ); log << MSG::WARNING << "Error declaring event root address." << endmsg; continue; } sc = m_evtDataSvc->retrieveObject("/Event", pObject); if( !sc.isSuccess() ) { MsgStream log( msgSvc(), name() ); log << MSG::WARNING << "Unable to retrieve Event root object" << endmsg; break; } } else { sc = m_evtDataMgrSvc->setRoot ("/Event", new DataObject()); if( !sc.isSuccess() ) { MsgStream log( msgSvc(), name() ); log << MSG::WARNING << "Error declaring event root DataObject" << endmsg; } } // Execute event for all required algorithms // Fire BeginEvent "Incident" m_incidentSvc->fireIncident(Incident(name(),IncidentType::BeginEvent)); // Execute Algorithms StatusCode sc = executeEvent(NULL); // Fire EndEvent "Incident" m_incidentSvc->fireIncident(Incident(name(),IncidentType::EndEvent)); if( !sc.isSuccess() ){ MsgStream log( msgSvc(), name() ); log << MSG::ERROR << "Terminating event processing loop due to errors" << endmsg; break; } } return StatusCode::SUCCESS; }
void EventExecutor::run(){ while (isRunning()){ m_eventSemaphore.wait(); executeEvent(); } }