void ExchangeDialog::execute(Character *&c, int &charIndex) { Screen &screen = *_vm->_screen; EventsManager &events = *_vm->_events; Interface &intf = *_vm->_interface; Party &party = *_vm->_party; loadButtons(); Window &w = screen._windows[31]; w.open(); w.writeString(Res.EXCHANGE_WITH_WHOM); _iconSprites.draw(w, 0, Common::Point(225, 120)); w.update(); while (!_vm->shouldQuit()) { events.pollEventsAndWait(); checkEvents(_vm); if (_buttonValue >= Common::KEYCODE_F1 && _buttonValue <= Common::KEYCODE_F6) { _buttonValue -= Common::KEYCODE_F1; if (_buttonValue < (int)party._activeParty.size()) { SWAP(party._activeParty[charIndex], party._activeParty[_buttonValue]); charIndex = _buttonValue; c = &party._activeParty[charIndex]; break; } } else if (_buttonValue == Common::KEYCODE_ESCAPE) { break; } } w.close(); intf.drawParty(true); intf.highlightChar(charIndex); }
static int simulationUpdate(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo) { prefixedName_updateContinuousSystem(data, threadData); if (solverInfo->solverMethod == S_SYM_IMP_EULER) data->callback->symEulerUpdate(data, solverInfo->solverStepSize); saveZeroCrossings(data, threadData); messageClose(LOG_SOLVER); /***** Event handling *****/ if (measure_time_flag) rt_tick(SIM_TIMER_EVENT); int syncRet = handleTimers(data, threadData, solverInfo); int syncRet1; do { int eventType = checkEvents(data, threadData, solverInfo->eventLst, &(solverInfo->currentTime), solverInfo); if(eventType > 0 || syncRet == 2) /* event */ { threadData->currentErrorStage = ERROR_EVENTHANDLING; infoStreamPrint(LOG_EVENTS, 1, "%s event at time=%.12g", eventType == 1 ? "time" : "state", solverInfo->currentTime); /* prevent emit if noEventEmit flag is used */ if (!(omc_flag[FLAG_NOEVENTEMIT])) /* output left limit */ sim_result.emit(&sim_result, data, threadData); handleEvents(data, threadData, solverInfo->eventLst, &(solverInfo->currentTime), solverInfo); messageClose(LOG_EVENTS); threadData->currentErrorStage = ERROR_SIMULATION; solverInfo->didEventStep = 1; overwriteOldSimulationData(data); } else /* no event */ { solverInfo->laststep = solverInfo->currentTime; solverInfo->didEventStep = 0; } if (measure_time_flag) rt_accumulate(SIM_TIMER_EVENT); /***** End event handling *****/ /***** check state selection *****/ if (stateSelection(data, threadData, 1, 1)) { /* if new set is calculated reinit the solver */ solverInfo->didEventStep = 1; overwriteOldSimulationData(data); } /* Check for warning of variables out of range assert(min<x || x>xmax, ...)*/ data->callback->checkForAsserts(data, threadData); storePreValues(data); storeOldValues(data); syncRet1 = handleTimers(data, threadData, solverInfo); syncRet = syncRet1 == 0 ? syncRet : syncRet1; } while (syncRet1); return syncRet; }
void FightsManager::fightLoop() { LureEngine &engine = LureEngine::getReference(); Resources &res = Resources::getReference(); Game &game = Game::getReference(); Room &room = Room::getReference(); FighterRecord &playerFight = getDetails(PLAYER_ID); uint32 timerVal = g_system->getMillis(); // Loop for the duration of the battle while (!engine.shouldQuit() && (playerFight.fwhits != GENERAL_MAGIC_ID)) { checkEvents(); if (g_system->getMillis() > timerVal + GAME_FRAME_DELAY) { timerVal = g_system->getMillis(); game.tick(); room.update(); res.delayList().tick(); } Screen::getReference().update(); game.debugger().onFrame(); g_system->delayMillis(10); } }
void Minesweeper::waitPlayer(SDL_Event* event){ while ((isPlayerWinner() || gameOver) && !done){ checkEvents(event); struct timespec timespec_st = {0,NANOSEC}; nanosleep(×pec_st,NULL); } }
Direction TBFE::runEngine() { frame_++; bool checkOnce=false; while(logic_.pollEvent() || !checkOnce) { SDL_Event currentSdlEvent=logic_.getEvent(); checkEvents(); //Normal KeyBoard Events if (currentSdlEvent.type==SDL_KEYDOWN && logic_.isEventNew()) { if (logic_.checkKeyDown(27)) { quit_=true; }; }; checkOnce=true; }; PositionI mapDimensions=Current_Map.getDimensions(); if (keyControl_==true) { logic_.playerMovement(Main_Player); }; renderWindow_.finalRender(true); if (frameRate_.GetTicks() > 1000) { frameRate_.Start(); time_++; int Minutes=time_-(time_/100)*100; if (Minutes>=60) { time_+=100-Minutes; }; if (time_>2400) { time_=0; }; frame_=0; if (!showMouse_ && (mousePosition_.X!=screenDimensions_.X/2 || mousePosition_.Y!=screenDimensions_.Y/2)) { SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); SDL_WarpMouse(mouseCenter_.X,mouseCenter_.Y); SDL_WM_GrabInput( SDL_GRAB_ON ); SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE); }; return SECOND; }; gameSpeed_=60/(frame_*1000/frameRate_.GetTicks()); if (gameSpeed_>3) { gameSpeed_=3; }; if (quit_==true) { return QUIT; }; return NORMAL; };
SGameResult PauseScene::onPauseMenu(sf::RenderWindow & window) { clearResult(); checkEvents(window); render(window); window.display(); return m_result; }
void MainMenu::executeMenu(bool* doneGame){ this->doneGame = NULL; doneMenu = false; this->doneGame = doneGame; SDL_Event event; while (!doneMenu){ checkEvents(&event); } }
/** * Main game loop */ void Game::Game::run() { std::cout << "Game Launched" << std::endl; while(WindowManager::gw->isOpen()) { sf::Color bg_color(87,123,255); WindowManager::gw->clear(bg_color); checkEvents(); GameEngine::gc->update(); GameEngine::gc->draw(); WindowManager::gw->display(); } }
void mainLoop(sf::RenderWindow & window) { Clock clock; clock.initialize(); while (window.isOpen()) { checkEvents(window); clock.setTime(getSystemTime()); clock.update(); clock.render(window); window.display(); } }
/* * ======== Event_post ======== */ Void Event_post(Event_Object *event, UInt eventId) { UInt tskKey, hwiKey; Event_PendElem *elem; Queue_Handle pendQ; Assert_isTrue((eventId != 0), Event_A_nullEventId); Log_write3(Event_LM_post, (UArg)event, (UArg)event->postedEvents, (UArg)eventId); pendQ = Event_Instance_State_pendQ(event); /* atomically post this event */ hwiKey = Hwi_disable(); /* or in this eventId */ event->postedEvents |= eventId; /* confirm that ANY tasks are pending on this event */ if (Queue_empty(pendQ)) { Hwi_restore(hwiKey); return; } tskKey = Task_disable(); /* examine pendElem on pendQ */ elem = (Event_PendElem *)Queue_head(pendQ); /* check for match, consume matching eventIds if so. */ elem->matchingEvents = checkEvents(event, elem->andMask, elem->orMask); if (elem->matchingEvents != 0) { /* remove event elem from elem queue */ Queue_remove((Queue_Elem *)elem); /* mark the Event as having been posted */ elem->pendState = Event_PendState_POSTED; /* put task back into readyQ */ Task_unblockI(elem->tpElem.task, hwiKey); } Hwi_restore(hwiKey); /* context switch may occur here */ Task_restore(tskKey); }
void Reports::insert(const Report &report) { auto experimentOpt = Experiments{session}.getActive(); if (!experimentOpt || experimentOpt.value().ID != report.experimentID) { throw InvalidData{"given experiment ID is not an ID of currently active experiment"}; } auto experiment = experimentOpt.value(); checkID(report.ID); checkEvents(experiment, report.history); checkSurveyAns(experiment.surveyBefore, report.surveyBefore); checkSurveyAns(experiment.surveyAfter, report.surveyAfter); retainExhibits(report.history); Impl::insert(session, toDB(report)); }
/** * Main task dispatcher for the buffered socket abstraction. * @todo Fix the polling... */ int BufferedSocket::run() { dcdebug("BufferedSocket::run() start %p\n", (void*)this); while(true) { try { if(!checkEvents()) break; checkSocket(); } catch(const Exception& e) { fail(e.getError()); } } dcdebug("BufferedSocket::run() end %p\n", (void*)this); delete this; return 0; }
int Town::townWait() { EventsManager &events = *_vm->_events; _buttonValue = 0; while (!_vm->shouldQuit() && !_buttonValue) { events.updateGameCounter(); while (!_vm->shouldQuit() && !_buttonValue && events.timeElapsed() < 3) { events.pollEventsAndWait(); checkEvents(_vm); } if (!_buttonValue) drawTownAnim(!_vm->_screen->_windows[11]._enabled); } return _buttonValue; }
int VideoPreview::run() { while (true) { try { if (!checkEvents()) break; } catch (const Exception& e) { fail(e.getError()); } } return 0; }
static bool dumpFileList(const char* path) { MAHandle list = maFileListStart(path, "*", 0); if(list < 0) { LPRINTFLN("FLS error %i", list); return false; } bool empty = true; while(maFileListNext(list, buffer, sizeof(buffer)) > 0) { checkEvents(); MAUtil::String p2(path); p2 += buffer; LOG(p2); if(p2[p2.size()-1] == '/') dumpFileList(p2.c_str()); empty = false; } maFileListClose(list); //printf("%s: %s\n", empty ? "Empty" : "Done", path); return !empty; }
void dispSurface(SDL_Surface *disp) { if (checkEvents()) { debug("Interrupt quit requested. Terminating.\n"); exit(EXIT_SUCCESS); } // centre the bitmap on screen SDL_Rect dstrect; dstrect.x = (screen->w - disp->w) / 2; dstrect.y = (screen->h - disp->h) / 2; // clear screen SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 255, 255, 255)); // draw bitmap SDL_BlitSurface(disp, 0, screen, &dstrect); // finally, update the screen :) SDL_Flip(screen); }
int main(int argc, char** argv) { fprintf(stderr, "Welcome to stand-alone Android quake.\n"); AndroidInitArgs(argc, argv); int result = init(argc, argv); if (result) { return result; } if (!AndroidInit()) { return 1; } while(true) { AndroidStep(gDisplayWidth, gDisplayHeight); checkGLError("AndroidStep"); eglSwapBuffers(gDisplay, gSurface); checkEGLError("eglSwapBuffers"); checkEvents(); } return 0; }
void FileContentProvider::watch() { boost::filesystem::path watchDir = _filepath.parent_path(); initInotify(); watchDirectory(watchDir); while (true) { LOG_DEBUG(filecontentproviderlog) << "[FileContentProvider] watching directory " << watchDir << std::endl; if (!checkEvents()) { LOG_DEBUG(filecontentproviderlog) << "[FileContentProvider] got an interrupt signal" << std::endl; break; } inotify_event* event = readInotifyEvent(); if (event == NULL ) break; LOG_ALL(filecontentproviderlog) << "directory " << watchDir << " changed!" << std::endl; LOG_ALL(filecontentproviderlog) << "\tmask is: " << event->mask << std::endl; LOG_ALL(filecontentproviderlog) << "\tname is: " << event->name << std::endl; if (strcmp(event->name, _filepath.leaf().c_str()) != 0) { LOG_ALL(filecontentproviderlog) << "file " << event->name << " changed, but I'm interested in " << _filepath.leaf() << std::endl; continue; } processInotifyEvent(event); } unwatchDirectory(watchDir); tearDownInotify(); }
int main(void) { int screen; display = XOpenDisplay(NULL); screen = DefaultScreen(display); white_pixel = WhitePixel (display, screen); black_pixel = BlackPixel (display, screen); rootwindow = RootWindow(display,screen); displayWinA(); displayWinB(); checkEvents(); XFlush(display); XDestroyWindow(display, winA); XDestroyWindow(display, winB); XCloseDisplay(display); return (0); }
void Minesweeper::startGame(){ SDL_Event event; thread timer(&Minesweeper::renderTimerText,this); while (!done){ checkEvents(&event); mtx.lock(); renderGame(); mtx.unlock(); if (isPlayerWinner() || gameOver){ if (isPlayerWinner() && !cheatActived) saveScore(); waitPlayer(&event); } checkCheat(); struct timespec timespec_st = {0,NANOSEC}; nanosleep(×pec_st,NULL); //used to not consume 100% of the cpu 0,1s } timer.join(); SDL_FreeSurface(displayVideo); SDL_FreeSurface(images); SDL_Quit(); TTF_Quit(); }
void Quests::execute() { EventsManager &events = *_vm->_events; Party &party = *_vm->_party; Windows &windows = *_vm->_windows; Mode oldMode = _vm->_mode; int count = 0; bool headerShown = false; int topRow = 0; const char **questItemNames = (g_vm->getGameID() == GType_Swords) ? Res.QUEST_ITEM_NAMES_SWORDS : Res.QUEST_ITEM_NAMES; int itemsCount = (g_vm->getGameID() == GType_Swords) ? TOTAL_QUEST_ITEMS_SWORDS : TOTAL_QUEST_ITEMS; const char *title1 = (g_vm->getGameID() == GType_Swords) ? Res.SWORDS_OF_XEEN_LINE : Res.CLOUDS_OF_XEEN_LINE; addButtons(); loadQuestNotes(); enum { QUEST_ITEMS, CURRENT_QUESTS, AUTO_NOTES } mode = QUEST_ITEMS; bool windowFlag; if (windows[29]._enabled) { windowFlag = false; } else { windows[29].open(); windows[30].open(); windowFlag = true; } windows[29].writeString(Res.QUESTS_DIALOG_TEXT); drawButtons(&windows[0]); while (!_vm->shouldExit()) { Common::String lines[MAX_DIALOG_LINES]; switch (mode) { case QUEST_ITEMS: for (int idx = 0; idx < itemsCount; ++idx) lines[idx] = "\b \b*"; count = 0; headerShown = false; for (int idx = 0; idx < itemsCount; ++idx) { if (party._questItems[idx]) { if (!count ) { if (_vm->getGameID() == GType_Swords) lines[count++] = Res.SWORDS_OF_XEEN_LINE; else if (idx < 35) lines[count++] = Res.CLOUDS_OF_XEEN_LINE; } else if (_vm->getGameID() != GType_Swords && idx >= 35 && !headerShown) { lines[count++] = Res.DARKSIDE_OF_XEEN_LINE; headerShown = true; } bool multiFlag = false; if (_vm->getGameID() == GType_Swords) { multiFlag = (idx == 20) || (idx == 27) || (idx == 41); } else { switch (idx) { case 17: case 26: case 79: case 80: case 81: case 82: case 83: case 84: multiFlag = true; break; default: break; } } if (multiFlag) { lines[count++] = Common::String::format("%d %s%c", party._questItems[idx], questItemNames[idx], party._questItems[idx] == 1 ? ' ' : 's'); } else { lines[count++] = questItemNames[idx]; } } } if (count == 0) { windows[30].writeString(Res.NO_QUEST_ITEMS); } else { windows[30].writeString(Common::String::format(Res.QUEST_ITEMS_DATA, lines[topRow].c_str(), lines[topRow + 1].c_str(), lines[topRow + 2].c_str(), lines[topRow + 3].c_str(), lines[topRow + 4].c_str(), lines[topRow + 5].c_str(), lines[topRow + 6].c_str(), lines[topRow + 7].c_str(), lines[topRow + 8].c_str() )); } break; case CURRENT_QUESTS: for (int idx = 0; idx < itemsCount; ++idx) lines[idx] = ""; count = 0; headerShown = false; for (int idx = 0; idx < TOTAL_QUEST_FLAGS; ++idx) { if (party._questFlags[idx + 1]) { if (!count && !headerShown && (_vm->getGameID() == GType_Swords || idx < 29)) { lines[count++] = title1; } if (_vm->getGameID() != GType_Swords && idx > 28 && !headerShown) { lines[count++] = Res.DARKSIDE_OF_XEEN_LINE; headerShown = true; } lines[count++] = _questNotes[idx]; } } if (count == 0) lines[1] = Res.NO_CURRENT_QUESTS; windows[30].writeString(Common::String::format(Res.CURRENT_QUESTS_DATA, lines[topRow].c_str(), lines[topRow + 1].c_str(), lines[topRow + 2].c_str())); break; case AUTO_NOTES: { int max, offset; switch (_vm->getGameID()) { case GType_Swords: max = 49; offset = 51; break; case GType_Clouds: max = MAX_DIALOG_LINES; offset = 31; break; default: max = MAX_DIALOG_LINES; offset = 56; break; } for (int idx = 0; idx < max; ++idx) lines[idx] = ""; count = 0; headerShown = false; for (int idx = 0; idx < max; ++idx) { if (party._worldFlags[idx + (_vm->getGameID() != GType_Swords ? 1 : 0)]) { if (!count && !headerShown && (_vm->getGameID() == GType_Swords || idx < 72)) { lines[count++] = title1; } if (idx >= 72 && !headerShown) { lines[count++] = Res.DARKSIDE_OF_XEEN_LINE; headerShown = true; } lines[count++] = _questNotes[idx + offset]; } } if (count == 0) lines[1] = Res.NO_AUTO_NOTES; windows[30].writeString(Common::String::format(Res.AUTO_NOTES_DATA, lines[topRow].c_str(), lines[topRow + 1].c_str(), lines[topRow + 2].c_str(), lines[topRow + 3].c_str(), lines[topRow + 4].c_str(), lines[topRow + 5].c_str(), lines[topRow + 6].c_str(), lines[topRow + 7].c_str(), lines[topRow + 8].c_str() )); break; } } windows[30].writeString("\v000\t000"); windows[24].update(); // Key handling _buttonValue = 0; while (!_vm->shouldExit() && !_buttonValue) { events.pollEventsAndWait(); checkEvents(_vm); } if (_buttonValue == Common::KEYCODE_ESCAPE) break; switch (_buttonValue) { case Common::KEYCODE_a: mode = AUTO_NOTES; topRow = 0; break; case Common::KEYCODE_i: mode = QUEST_ITEMS; topRow = 0; break; case Common::KEYCODE_q: mode = CURRENT_QUESTS; topRow = 0; break; case Common::KEYCODE_HOME: topRow = 0; break; case Common::KEYCODE_END: topRow = MAX(count - 1, 0); break; case Common::KEYCODE_PAGEUP: topRow = MAX(topRow - 3, 0); break; case Common::KEYCODE_PAGEDOWN: topRow = CLIP(topRow + 3, 0, MAX(count - 1, 0)); break; case Common::KEYCODE_UP: case Common::KEYCODE_KP8: topRow = MAX(topRow - 1, 0); break; case Common::KEYCODE_DOWN: case Common::KEYCODE_KP2: topRow = CLIP(topRow + 1, 0, MAX(count - 1, 0)); break; default: break; } } if (windowFlag) { windows[30].close(); windows[29].close(); } _vm->_mode = oldMode; }
int main(int argc, char *argv[]) { #ifdef __APPLE__ || __MACH__ || OSX glutInit(&argc,argv); #endif #ifdef LINUX setenv("__GL_SYNC_TO_VBLANK","1",true); #else // SDL console output hack freopen( "CON", "w", stdout ); #endif /// configure the screen g_screen.setCaptionText("SDL EXAMPLE"); g_screen.addFlags(SDL_SRCALPHA | SDL_ANYFORMAT | SDL_OPENGL); // g_screen.addFlags(SDL_FULLSCREEN); //Initialize if( g_screen.init() == false ) { return 1; } // Init glew if (GLEW_OK != glewInit()) { std::cout << "'glewInit()' failed." << std::endl; exit(0); } // some gl state calls glClearColor(0.0, 0.0, 0.0, 1.0); glEnable(GL_TEXTURE_2D); // glEnable(GL_CULL_FACE); // glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_NORMALIZE); glDisable(GL_COLOR_MATERIAL); /// loading ... init(); // main loop while (!g_input.getKeyState(SDLK_ESCAPE)) { /// update event handler g_input.update(); /// handle events checkEvents(); if (g_frameDone == false) { /// render 3d content renderVolume(); /// render 2d content render2d(); glFlush(); SDL_GL_SwapBuffers(); } } // clean up sdl clean_up(); return 0; }
/********************************************************************** * Function: doMasterSM * @return None. * @remark Executes one cycle of the boat's master state machine. * @author David Goodman * @date 2013.03.28 **********************************************************************/ static void doMasterSM() { checkEvents(); #ifdef USE_TILTCOMPASS TiltCompass_runSM(); #endif #ifdef USE_GPS GPS_runSM(); #endif #ifdef USE_NAVIGATION Navigation_runSM(); #ifdef USE_ERROR_CORRECTION gpsCorrectionUpdate(); #endif #endif #ifdef USE_DRIVE Drive_runSM(); #endif #ifdef USE_XBEE Xbee_runSM(); #endif #ifdef USE_BAROMETER Barometer_runSM(); doBarometerUpdate(); // send barometer data #endif switch (state) { case STATE_SETSTATION: doSetStationSM(); if (event.flags.haveStartRescueMessage) { startRescueSM(); } else if (event.flags.setStationDone) { if (haveOrigin) startStationKeepSM(); else startOverrideSM(); } break; case STATE_SETORIGIN: doSetOriginSM(); if (event.flags.setOriginDone) startOverrideSM(); break; case STATE_STATIONKEEP: doStationKeepSM(); if (event.flags.haveStartRescueMessage) startRescueSM(); else if (!haveStation) setError(ERROR_NO_STATION); break; case STATE_OVERRIDE: if (!wantOverride) { //setError(ERROR_NO_ORIGIN); if (!haveOrigin) startSetOriginSM(); // do we ant infinite startup loop? else if (event.flags.haveStartRescueMessage) startRescueSM(); else if (event.flags.haveSetStationMessage ) startSetStationSM(); else if (haveOrigin && haveStation) startStationKeepSM(); // Use autonomous controls if (haveOrigin && (haveStation || event.flags.haveStartRescueMessage)) { Override_giveMicroControl(); DBPRINT("Micro has control.\n"); #ifdef USE_SIREN Siren_blueLightOff(); #endif } } break; case STATE_RESCUE: doRescueSM(); if (event.flags.haveStartRescueMessage) { startRescueSM(); } else if (event.flags.haveReturnStationMessage) { if (haveStation) startStationKeepSM(); else setError(ERROR_NO_STATION); } // Turn off rescue siren (red) if (event.flags.haveError || state != STATE_RESCUE) { #ifdef USE_SIREN Siren_redLightOff(); #endif } break; } // ------- Caught by most states ----------- if (state != STATE_RESCUE) { if (event.flags.haveSetStationMessage) startSetStationSM(); } if (state != STATE_OVERRIDE) { if (event.flags.haveError) { startOverrideSM(); overrideShutdown = TRUE; } if (wantOverride) startOverrideSM(); } if (event.flags.haveResetMessage) resetAtlas(); }
void Quests::execute() { EventsManager &events = *_vm->_events; Party &party = *_vm->_party; Screen &screen = *_vm->_screen; Mode oldMode = _vm->_mode; int count = 0; bool headerShown = false; int topRow = 0; addButtons(); loadQuestNotes(); enum { QUEST_ITEMS, CURRENT_QUESTS, AUTO_NOTES } mode = QUEST_ITEMS; bool windowFlag; if (screen._windows[29]._enabled) { windowFlag = false; } else { screen._windows[29].open(); screen._windows[30].open(); windowFlag = true; } screen._windows[29].writeString(QUESTS_DIALOG_TEXT); drawButtons(&screen); while (!_vm->shouldQuit()) { Common::String lines[MAX_DIALOG_LINES]; switch (mode) { case QUEST_ITEMS: for (int idx = 0; idx < TOTAL_QUEST_ITEMS; ++idx) lines[idx] = "\b \b*"; count = 0; headerShown = false; for (int idx = 0; idx < TOTAL_QUEST_ITEMS; ++idx) { if (party._questItems[idx]) { if (!count && !headerShown && idx < 35) { lines[count++] = CLOUDS_OF_XEEN_LINE; } if (idx >= 35 && !headerShown) { lines[count++] = DARKSIDE_OF_XEEN_LINE; headerShown = true; } switch (idx) { case 17: case 26: case 79: case 80: case 81: case 82: case 83: case 84: lines[count++] = Common::String::format("%d %s%c", party._questItems[idx], QUEST_ITEM_NAMES[idx], party._questItems[idx] == 1 ? ' ' : 's'); break; default: lines[count++] = QUEST_ITEM_NAMES[idx]; break; } } } if (count == 0) { screen._windows[30].writeString(NO_QUEST_ITEMS); } else { screen._windows[30].writeString(Common::String::format(QUEST_ITEMS_DATA, lines[topRow].c_str(), lines[topRow + 1].c_str(), lines[topRow + 2].c_str(), lines[topRow + 3].c_str(), lines[topRow + 4].c_str(), lines[topRow + 5].c_str(), lines[topRow + 6].c_str(), lines[topRow + 7].c_str(), lines[topRow + 8].c_str() )); } break; case CURRENT_QUESTS: for (int idx = 0; idx < TOTAL_QUEST_ITEMS; ++idx) lines[idx] = ""; count = 0; headerShown = false; for (int idx = 0; idx < TOTAL_QUEST_FLAGS; ++idx) { if (party._quests[idx]) { if (!count && !headerShown && idx < 29) { lines[count++] = CLOUDS_OF_XEEN_LINE; } if (idx > 28 && !headerShown) { lines[count++] = DARKSIDE_OF_XEEN_LINE; headerShown = true; } lines[count++] = _questNotes[idx]; } } if (count == 0) lines[1] = NO_CURRENT_QUESTS; screen._windows[30].writeString(Common::String::format(CURRENT_QUESTS_DATA, lines[topRow].c_str(), lines[topRow + 1].c_str(), lines[topRow + 2].c_str())); break; case AUTO_NOTES: for (int idx = 0; idx < MAX_DIALOG_LINES; ++idx) lines[idx] = ""; count = 0; headerShown = false; for (int idx = 0; idx < MAX_DIALOG_LINES; ++idx) { if (party._worldFlags[idx]) { if (!count && !headerShown && idx < 72) { lines[count++] = CLOUDS_OF_XEEN_LINE; } if (idx >= 72 && !headerShown) { lines[count++] = DARKSIDE_OF_XEEN_LINE; headerShown = true; } lines[count++] = _questNotes[idx + 56]; } } if (count == 0) lines[1] = NO_AUTO_NOTES; screen._windows[30].writeString(Common::String::format(AUTO_NOTES_DATA, lines[topRow].c_str(), lines[topRow + 1].c_str(), lines[topRow + 2].c_str(), lines[topRow + 3].c_str(), lines[topRow + 4].c_str(), lines[topRow + 5].c_str(), lines[topRow + 6].c_str(), lines[topRow + 7].c_str(), lines[topRow + 8].c_str() )); break; } screen._windows[30].writeString("\v000\t000"); screen._windows[24].update(); // Key handling _buttonValue = 0; while (!_vm->shouldQuit() && !_buttonValue) { events.pollEventsAndWait(); checkEvents(_vm); } if (_buttonValue == Common::KEYCODE_ESCAPE) break; switch (_buttonValue) { case Common::KEYCODE_a: mode = AUTO_NOTES; topRow = 0; break; case Common::KEYCODE_i: mode = QUEST_ITEMS; topRow = 0; break; case Common::KEYCODE_q: mode = CURRENT_QUESTS; topRow = 0; break; case Common::KEYCODE_HOME: topRow = 0; break; case Common::KEYCODE_END: topRow = count - 1; break; case Common::KEYCODE_PAGEUP: topRow = MAX(topRow - 3, 0); break; case Common::KEYCODE_PAGEDOWN: topRow = CLIP(topRow + 3, 0, count - 1); break; case Common::KEYCODE_UP: case Common::KEYCODE_KP8: topRow = MAX(topRow - 1, 0); break; case Common::KEYCODE_DOWN: case Common::KEYCODE_KP2: topRow = CLIP(topRow + 1, 0, count - 1); break; default: break; } } if (windowFlag) { screen._windows[30].close(); screen._windows[29].close(); } _vm->_mode = oldMode; }
/** * Method that does the actual resize of the guest framebuffer and * then changes the SDL framebuffer setup. */ static void bench(unsigned long w, unsigned long h, unsigned long bpp) { Uint32 Rmask, Gmask, Bmask, Amask = 0; Uint32 Rsize, Gsize, Bsize; Uint32 newWidth, newHeight; guGuestXRes = w; guGuestYRes = h; guGuestBpp = bpp; RTPrintf("\n"); /* a different format we support directly? */ switch (guGuestBpp) { case 16: { Rmask = 0xF800; Gmask = 0x07E0; Bmask = 0x001F; Amask = 0x0000; Rsize = 5; Gsize = 6; Bsize = 5; break; } case 24: { Rmask = 0x00FF0000; Gmask = 0x0000FF00; Bmask = 0x000000FF; Amask = 0x00000000; Rsize = 8; Gsize = 8; Bsize = 8; break; } default: Rmask = 0x00FF0000; Gmask = 0x0000FF00; Bmask = 0x000000FF; Amask = 0x00000000; Rsize = 8; Gsize = 8; Bsize = 8; break; } int sdlFlags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL; #ifdef VBOX_OPENGL if (gfOpenGL) sdlFlags |= SDL_OPENGL; #endif if (gfResizable) sdlFlags |= SDL_RESIZABLE; if (gfFullscreen) sdlFlags |= SDL_FULLSCREEN; /* * Now we have to check whether there are video mode restrictions */ SDL_Rect **modes; /* Get available fullscreen/hardware modes */ modes = SDL_ListModes(NULL, sdlFlags); if (modes == NULL) { RTPrintf("Error: SDL_ListModes failed with message '%s'\n", SDL_GetError()); return; } /* -1 means that any mode is possible (usually non fullscreen) */ if (modes != (SDL_Rect **)-1) { /* * according to the SDL documentation, the API guarantees that * the modes are sorted from larger to smaller, so we just * take the first entry as the maximum. */ guMaxScreenWidth = modes[0]->w; guMaxScreenHeight = modes[0]->h; } else { /* no restriction */ guMaxScreenWidth = ~0; guMaxScreenHeight = ~0; } newWidth = RT_MIN(guMaxScreenWidth, guGuestXRes); newHeight = RT_MIN(guMaxScreenHeight, guGuestYRes); /* * Now set the screen resolution and get the surface pointer * @todo BPP is not supported! */ #ifdef VBOX_OPENGL if (gfOpenGL) { checkSDL("SDL_GL_SetAttribute", SDL_GL_SetAttribute(SDL_GL_RED_SIZE, Rsize)); checkSDL("SDL_GL_SetAttribute", SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, Gsize)); checkSDL("SDL_GL_SetAttribute", SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, Bsize)); checkSDL("SDL_GL_SetAttribute", SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0)); } #else NOREF(Rsize); NOREF(Gsize); NOREF(Bsize); #endif RTPrintf("Testing " ESC_BOLD "%ldx%ld@%ld" ESC_NORM "\n", guGuestXRes, guGuestYRes, guGuestBpp); gScreen = SDL_SetVideoMode(newWidth, newHeight, 0, sdlFlags); if (!gScreen) { RTPrintf("SDL_SetVideoMode failed (%s)\n", SDL_GetError()); return; } /* first free the current surface */ if (gSurfVRAM) { SDL_FreeSurface(gSurfVRAM); gSurfVRAM = NULL; } if (gPtrVRAM) { free(gPtrVRAM); gPtrVRAM = NULL; } if (gScreen->format->BitsPerPixel != guGuestBpp) { /* Create a source surface from guest VRAM. */ int bytes_per_pixel = (guGuestBpp + 7) / 8; gPtrVRAM = malloc(guGuestXRes * guGuestYRes * bytes_per_pixel); gSurfVRAM = SDL_CreateRGBSurfaceFrom(gPtrVRAM, guGuestXRes, guGuestYRes, guGuestBpp, bytes_per_pixel * guGuestXRes, Rmask, Gmask, Bmask, Amask); } else { /* Create a software surface for which SDL allocates the RAM */ gSurfVRAM = SDL_CreateRGBSurface(SDL_SWSURFACE, guGuestXRes, guGuestYRes, guGuestBpp, Rmask, Gmask, Bmask, Amask); } if (!gSurfVRAM) { RTPrintf("Failed to allocate surface %ldx%ld@%ld\n", guGuestXRes, guGuestYRes, guGuestBpp); return; } RTPrintf(" gScreen=%dx%d@%d (surface: %s)\n", gScreen->w, gScreen->h, gScreen->format->BitsPerPixel, (gScreen->flags & SDL_HWSURFACE) == 0 ? "software" : "hardware"); SDL_Rect rect = { 0, 0, (Uint16)guGuestXRes, (Uint16)guGuestYRes }; checkSDL("SDL_FillRect", SDL_FillRect(gSurfVRAM, &rect, SDL_MapRGB(gSurfVRAM->format, 0x5F, 0x6F, 0x1F))); #ifdef VBOX_OPENGL if (gfOpenGL) { int r, g, b, d, o; SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &r); SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &g); SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &b); SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &d); SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &o); RTPrintf(" OpenGL ctxt red=%d, green=%d, blue=%d, depth=%d, dbl=%d", r, g, b, d, o); glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glGenTextures(1, &gTexture); glBindTexture(GL_TEXTURE_2D, gTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); for (guTextureWidth = 32; guTextureWidth < newWidth; guTextureWidth <<= 1) ; for (guTextureHeight = 32; guTextureHeight < newHeight; guTextureHeight <<= 1) ; RTPrintf(", tex %ldx%ld\n", guTextureWidth, guTextureHeight); switch (guGuestBpp) { case 16: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5, guTextureWidth, guTextureHeight, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0); break; case 24: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, guTextureWidth, guTextureHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, 0); break; case 32: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, guTextureWidth, guTextureHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0); break; default: RTPrintf("guGuestBpp=%d?\n", guGuestBpp); return; } glViewport(0, 0, newWidth, newHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, newWidth, newHeight, 0.0, -1.0, 1.0); } #endif checkEvents(); benchExecute(); #ifdef VBOX_OPENGL if (gfOpenGL) { glDeleteTextures(1, &gTexture); } #endif }
int main ( int argc, char** argv ) { //make sure we have all the necessary arguments if( argc < 4 ) { fprintf(stderr, "Usage: %s (input texture filename) (texton neighborhood diameter) \n", argv[0]); fprintf(stderr, " (output size) [number threads] [r weight] [g weight] [b weight]\n"); fprintf(stderr, " Options in () are required, options in [] are optional.\n"); fprintf(stderr, " Note that if you want to set r weight, number threads must be set too.\n"); fprintf(stderr, " Input texture reading is handled by SDL_Image so the file can be tga, bmp, \n"); fprintf(stderr, " pnm, xpm, xcf, pcx, gif, jpg, lbm, or png.\n"); fprintf(stderr, " If [number threads] is set to 0, no threads will be generated. If it is set\n"); fprintf(stderr, " to 1, one thread will be generated to do all the work. Default is %d.\n", TEX_SYN_THREADS); fprintf(stderr, " [rgb weight] defines how much weight to give to the r, g, and b channels\n"); fprintf(stderr, " when calculating the similarity between two neighborhoods.\n"); fprintf(stderr, " These values are only used if rgb weighting is enabled in the code.\n"); fprintf(stderr, " Default Values are %f, %f, and %f respectively.\n", TEX_SYN_RED_WEIGHT, TEX_SYN_GREEN_WEIGHT, TEX_SYN_BLUE_WEIGHT); exit(EXIT_FAILURE); } //looks good, start loading values: //diameter textonDiameter = atoi(argv[2]); //make sure textonDiameter is odd, add one to it if it is even. if(textonDiameter % 2 == 0) textonDiameter++; //output size outputSize = atoi(argv[3]); //# threads if(argc >= 5) TEX_SYN_THREADS = atoi(argv[4]); //r weight if(argc >= 6) TEX_SYN_RED_WEIGHT = atof(argv[5]); //g weight if(argc >= 7) TEX_SYN_GREEN_WEIGHT = atof(argv[6]); //b weight if(argc >= 8) TEX_SYN_BLUE_WEIGHT = atof(argv[7]); debug("Will generate texture using file %s as a kernel and\n", argv[1]); debug("\tneighborhood size %d to generate unique %d x %d texture\n", textonDiameter, outputSize, outputSize); #ifdef TEX_SYN_USE_MULTIRESOLUTION debug("\twith a multi-resolution synthesis algorithm.\n"); #else debug("\twith a single-resolution synthesis algorithm.\n"); #endif if(TEX_SYN_THREADS == 0) debug("No threads will be generated to compare neighborhoods.\n"); else debug("%d threads will be generated to compare neighborhoods.\n", TEX_SYN_THREADS); #ifdef TEX_SYN_WEIGHTED_COLORS debug("When comparing neighborhoods, red, green, and blue will be weighted\n"); debug("\twith the values %f, %f, and %f respectively\n", TEX_SYN_RED_WEIGHT, TEX_SYN_GREEN_WEIGHT, TEX_SYN_BLUE_WEIGHT); #else debug("When comparing neighborhoods, red, green, and blue will not be weighted\n"); #endif //initialize SDL debug("Initializing SDL\n"); initSDL(outputSize, outputSize); // load an image debug("Loading Image %s\n", argv[1]); SDL_Surface *loadedTexture = IMG_Load(argv[1]); if (!loadedTexture) { printf("Unable to load image %s: %s\n", argv[1], SDL_GetError()); return 1; } //convert to be the same format as the display (32 bit) debug("Convert input texture to useable format\n"); inputTexture = SDL_DisplayFormat(loadedTexture); SDL_FreeSurface(loadedTexture); //run the texture synthesis SDL_Surface *outputTexture = textureSynthesis(inputTexture, outputSize, outputSize); //this is the texture that will be rendered on screen: SDL_Surface *renderTexture = outputTexture; // centre the bitmap on screen SDL_Rect dstrect; dstrect.x = (screen->w - renderTexture->w) / 2; dstrect.y = (screen->h - renderTexture->h) / 2; // program main loop debug("Entering display loop...\n"); while (!checkEvents()) { // DRAWING STARTS HERE // clear screen SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 255, 255, 255)); // draw bitmap SDL_BlitSurface(renderTexture, 0, screen, &dstrect); // DRAWING ENDS HERE // finally, update the screen :) SDL_Flip(screen); } // end main loop //save output texture char stripped[256]; char outName[256]; int start = 0, end = 0; for(int i = strlen(argv[1]) - 1; i>=0; i--) { if( argv[1][i] == '/' && i > start ) start = i + 1; if( argv[1][i] == '.' && i > end ) end = i; } int i = 0; for( int n = start; n < end; n++, i++) stripped[i] = argv[1][n]; stripped[i] = '\0'; sprintf(outName, "synthesizedTextures/%s-%dx%d,%d.bmp", stripped, outputSize, outputSize, textonDiameter); debug("Saving the output image to %s\n", outName); if(SDL_SaveBMP(outputTexture, outName) < 0) { fprintf(stderr, "ERROR saving output texture to file %s: %s\n", outName, SDL_GetError()); exit(EXIT_FAILURE); } debug("Cleaning up\n"); // free loaded bitmap SDL_FreeSurface(inputTexture); SDL_FreeSurface(outputTexture); //note, sdl_quit doesn't need to be here because it's told to run //on quit in the init function. return 0; }
/* * ======== Event_pend ======== */ UInt Event_pend(Event_Object *event, UInt andMask, UInt orMask, UInt timeout) { UInt hwiKey, tskKey; Event_PendElem elem; UInt matchingEvents; Queue_Handle pendQ; Clock_Struct clockStruct; Assert_isTrue(((andMask | orMask) != 0), Event_A_nullEventMasks); Log_write5(Event_LM_pend, (UArg)event, (UArg)event->postedEvents, (UArg)andMask, (UArg)orMask, (IArg)((Int)timeout)); /* * elem is filled in entirely before interrupts are disabled. * This significantly reduces latency at the potential cost of wasted time * if it turns out that there is already an event match. */ /* add Clock event if timeout is not FOREVER nor NO_WAIT */ if (BIOS_clockEnabled && (timeout != BIOS_WAIT_FOREVER) && (timeout != BIOS_NO_WAIT)) { Clock_Params clockParams; Clock_Params_init(&clockParams); clockParams.arg = (UArg)&elem; clockParams.startFlag = FALSE; /* will start when necessary, thankyou */ Clock_construct(&clockStruct, (Clock_FuncPtr)Event_pendTimeout, timeout, &clockParams); elem.tpElem.clock = Clock_handle(&clockStruct); elem.pendState = Event_PendState_CLOCK_WAIT; } else { elem.tpElem.clock = NULL; elem.pendState = Event_PendState_WAIT_FOREVER; } /* fill in this task's Event_PendElem */ elem.andMask = andMask; elem.orMask = orMask; pendQ = Event_Instance_State_pendQ(event); /* get task handle */ elem.tpElem.task = Task_self(); /* leave a pointer for Task_delete() */ elem.tpElem.task->pendElem = (Task_PendElem *)&(elem); /* Atomically check for a match and block if none */ hwiKey = Hwi_disable(); /* check if events are already available */ matchingEvents = checkEvents(event, andMask, orMask); if (matchingEvents != 0) { Hwi_restore(hwiKey); /* deconstruct Clock if appropriate */ if (BIOS_clockEnabled && (elem.tpElem.clock != NULL)) { Clock_destruct(Clock_struct(elem.tpElem.clock)); } return (matchingEvents);/* yes, then return with matching bits */ } if (timeout == BIOS_NO_WAIT) { Hwi_restore(hwiKey); return (0); /* No match, no wait */ } Assert_isTrue((BIOS_getThreadType() == BIOS_ThreadType_Task), Event_A_badContext); /* lock scheduler */ tskKey = Task_disable(); /* only one Task allowed!!! */ Assert_isTrue(Queue_empty(pendQ), Event_A_eventInUse); /* add it to Event_PendElem queue */ Queue_enqueue(pendQ, (Queue_Elem *)&elem); Task_blockI(elem.tpElem.task); if (BIOS_clockEnabled && (elem.pendState == Event_PendState_CLOCK_WAIT)) { Clock_startI(elem.tpElem.clock); } Hwi_restore(hwiKey); /* unlock task scheduler and block */ Task_restore(tskKey); /* the calling task will switch out here */ /* Here on unblock due to Event_post or Event_pendTimeout */ /* deconstruct Clock if appropriate */ if (BIOS_clockEnabled && (elem.tpElem.clock != NULL)) { Clock_destruct(Clock_struct(elem.tpElem.clock)); } elem.tpElem.task->pendElem = NULL; /* event match? */ if (elem.pendState != Event_PendState_TIMEOUT) { return (elem.matchingEvents); } else { return (0); /* timeout */ } }
bool TownMessage::execute(int portrait, const Common::String &name, const Common::String &text, int confirm) { EventsManager &events = *_vm->_events; Interface &intf = *_vm->_interface; Screen &screen = *_vm->_screen; Town &town = *_vm->_town; Window &w = screen._windows[11]; town._townMaxId = 4; town._townActionId = 7; town._drawFrameIndex = 0; town._townPos = Common::Point(23, 22); if (!confirm) loadButtons(); if (town._townSprites[0].empty()) { town._townSprites[0].load(Common::String::format("face%02d.fac", portrait)); town._townSprites[1].load("frame.fac"); } if (!w._enabled) w.open(); int result = -1; Common::String msgText = text; for (;;) { Common::String msg = Common::String::format("\r\v014\x03c\t125%s\t000\v054%s", name.c_str(), msgText.c_str()); const char *msgEnd = w.writeString(msg.c_str()); int wordCount = 0; for (const char *msgP = msg.c_str(); msgP < msgEnd; ++msgP) { if (*msgP == ' ') ++wordCount; } town._drawCtr2 = wordCount * 2; town._townSprites[1].draw(screen, 0, Common::Point(16, 16)); town._townSprites[0].draw(screen, town._drawFrameIndex, Common::Point(23, 22)); w.update(); if (!msgEnd) { // Doesn't look like the code here in original can ever be reached assert(0); } if (confirm == 2) { intf._face1State = intf._face2State = 2; return false; } do { events.clearEvents(); events.updateGameCounter(); if (msgEnd) clearButtons(); do { events.wait(3); checkEvents(_vm); if (_vm->shouldQuit()) return false; town.drawTownAnim(false); events.updateGameCounter(); } while (!_buttonValue); if (msgEnd) break; if (!msgEnd) { if (confirm || _buttonValue == Common::KEYCODE_ESCAPE || _buttonValue == Common::KEYCODE_n) result = 0; else if (_buttonValue == Common::KEYCODE_y) result = 1; } } while (result == -1); if (msgEnd) { msgText = Common::String(msgEnd); town._drawCtr2 = wordCount; continue; } } while (result == -1); intf._face1State = intf._face2State = 2; if (!confirm) intf.mainIconsPrint(); town._townSprites[0].clear(); town._townSprites[1].clear(); return result == 1; }