static int doPlay(const char *filename) { int result; int done = 0; int bpp = 0; FILE *mve; MVE_videoSpec vSpec; mve = fopen(filename, "rb"); if (mve == NULL) { fprintf(stderr, "can't open MVE file\n"); return 1; } memset(g_palette, 0, 768); MVE_sndInit(1); MVE_memCallbacks(D2_ALLOC, D2_FREE); MVE_ioCallbacks(fileRead); MVE_sfCallbacks(showFrame); MVE_palCallbacks(setPalette); MVE_rmPrepMovie(mve, -1, -1, 1); MVE_getVideoSpec(&vSpec); #ifndef _WIN32_WCE // doesn't like to change bpp? bpp = vSpec.truecolor?16:8; #endif #ifdef LANDSCAPE real_screen = SDL_SetVideoMode(vSpec.screenHeight, vSpec.screenWidth, bpp, SDL_FULLSCREEN); g_screen = CreateRotatedSurface(real_screen); #else g_screen = SDL_SetVideoMode(vSpec.screenWidth, vSpec.screenHeight, bpp, SDL_ANYFORMAT); #endif g_truecolor = vSpec.truecolor; while (!done && (result = MVE_rmStepMovie()) == 0) { done = pollEvents(); } MVE_rmEndMovie(); fclose(mve); return 0; }
int Application::run() { PVRFrameEnableControlWindow(false); // Main message loop: LARGE_INTEGER nLast; LARGE_INTEGER nNow; QueryPerformanceCounter(&nLast); initGLContextAttrs(); // Initialize instance and cocos2d. if (!applicationDidFinishLaunching()) { return 1; } auto director = Director::getInstance(); auto glview = director->getOpenGLView(); // Retain glview to avoid glview being released in the while loop glview->retain(); while(!glview->windowShouldClose()) { QueryPerformanceCounter(&nNow); if (nNow.QuadPart - nLast.QuadPart > _animationInterval.QuadPart) { nLast.QuadPart = nNow.QuadPart - (nNow.QuadPart % _animationInterval.QuadPart); director->mainLoop(); glview->pollEvents(); } else { Sleep(1); } } // Director should still do a cleanup if the window was closed manually. if (glview->isOpenGLReady()) { director->end(); director->mainLoop(); director = nullptr; } glview->release(); return 0; }
int main() { init(); while (window.isOpen()) { step(); pollEvents(); } cleanUp(); return 0; }
void Window::update() { pollEvents(); static bool firstCall = true; if(m_window && glfwWindowShouldClose(m_window)) { if(firstCall) { firstCall = false; } else { logWarning("[Window] You should stop your application when " "Window::isValid() returns false! Now closing window..."); close(); } } }
void Context::startLoop() { Info() << "Context initializing renderloop."; m_loop->initialize(*this); Info() << "Starting render loop."; do { m_loop->render(); swapBuffers(); pollEvents(); } while (!windowShouldClose()); Info() << "Renderloop exited."; }
void rScene5::update(float deltaTime) { pollEvents(); m_deltaTime = deltaTime; playerStep(); moveSpotlight(player->getX(), player->getY()); updatePotatoes(); updateEnemies(); updateBullets(); if (player->getX() > 928) message = "go:Scene6"; }
int Application::run() { initGLContextAttrs(); // Initialize instance and cocos2d. if (! applicationDidFinishLaunching()) { return 0; } long lastTime = 0L; long curTime = 0L; auto director = Director::getInstance(); auto glview = director->getOpenGLView(); // Retain glview to avoid glview being released in the while loop glview->retain(); while (!glview->windowShouldClose()) { lastTime = getCurrentMillSecond(); director->mainLoop(); glview->pollEvents(); curTime = getCurrentMillSecond(); if (curTime - lastTime < _animationInterval) { usleep((_animationInterval - curTime + lastTime)*1000); } } /* Only work on Desktop * Director::mainLoop is really one frame logic * when we want to close the window, we should call Director::end(); * then call Director::mainLoop to do release of internal resources */ if (glview->isOpenGLReady()) { director->end(); director->mainLoop(); director = nullptr; } glview->release(); return EXIT_SUCCESS; }
xdl_int XdevLJoystickServerMac::RunThread(thread::ThreadArgument*) { XDEVL_MODULE_INFO("Starting threading mode.\n"); m_running = xdl_true; for(;;) { { m_mutex.Lock(); xdl_bool tmp = m_running; m_mutex.Unlock(); if(tmp == xdl_false) { break; } } pollEvents(); } XDEVL_MODULE_INFO("Stopping threading mode.\n"); return 0; }
void ofMainLoop::loopOnce(){ for(map<shared_ptr<ofAppBaseWindow>,shared_ptr<ofBaseApp> >::iterator i = windowsApps.begin(); !windowsApps.empty() && i != windowsApps.end() ;){ if(i->first->getWindowShouldClose()){ i->first->close(); windowsApps.erase(i++); ///< i now points at the window after the one which was just erased }else{ currentWindow = i->first; i->first->makeCurrent(); i->first->update(); i->first->draw(); i++; ///< continue to next window } } if(pollEvents){ pollEvents(); } }
static int doPlay(const char *filename) { int result; int done = 0; int bpp = 0; FILE *mve; MVE_videoSpec vSpec; mve = fopen(filename, "rb"); if (mve == NULL) { fprintf(stderr, "can't open MVE file\n"); return 1; } memset(g_palette, 0, 768); MVE_sndInit(1); MVE_memCallbacks((mve_cb_Alloc)malloc, free); MVE_ioCallbacks(fileRead); MVE_sfCallbacks(showFrame); MVE_palCallbacks(setPalette); MVE_rmPrepMovie(mve, -1, -1, 1); MVE_getVideoSpec(&vSpec); bpp = vSpec.truecolor?16:8; g_screen = SDL_SetVideoMode(vSpec.screenWidth, vSpec.screenHeight, bpp, SDL_ANYFORMAT); g_truecolor = vSpec.truecolor; while (!done && (result = MVE_rmStepMovie()) == 0) { done = pollEvents(); } MVE_rmEndMovie(); fclose(mve); return 0; }
void StarTrekEngine::waitForNextTick(bool queueEvents) { pollEvents(queueEvents); uint nextFrame = _frameStartMillis + 1000 / 18.206; uint millis = _system->getMillis(); if (millis < nextFrame) _system->delayMillis(nextFrame - millis); _clockTicks++; _frameStartMillis = nextFrame; if (queueEvents) { TrekEvent tickEvent; tickEvent.type = TREKEVENT_TICK; tickEvent.tick = _clockTicks; addEventToQueue(tickEvent); } }
int main(int argc, char **argv) { if( SDL_Init( SDL_INIT_VIDEO ) != 0 ) // Initialisieren des SDL Video Subsystems { cerr << "Die SDL konnte nicht initalisiert werden (" << SDL_GetError() << ")" << endl; return 1; } cout << "Willkommen zum SDL Testprogramm." << endl; SDL_WM_SetCaption("Mein Prog", "Mein Proggy"); // Titel setzen SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // Doublebuffer fuer fluessigen Spielverlauf SDL_SetVideoMode(640,420,32,SDL_OPENGL); glClearColor( 1.0, 0.5, 0.4, 0.0 ); // Loeschfarbe setzen glMatrixMode(GL_MODELVIEW); // Matrix setzen glLoadIdentity(); // Matrixitentitaet laden glEnable(GL_DEPTH_TEST); glFrustum( -1.6, 1.6, -1.2, 1.2, 1.5, 6.5 ); // Endlosschleife zum Offen halten. while(true) { if (!pollEvents()) break; drawOnBuffer(); } SDL_Quit(); // Herunterfahren der SDL Bibliotheken return 0; }
void GLView::pollInputEvents() { pollEvents(); }
void EventsManager::waitKeyMouse() { while (!_vm->shouldQuit() && !isKeyMousePressed()) { pollEvents(true); delay(); } }
void EventsManager::pollEventsAndWait() { pollEvents(); delay(); }
void Events::pollEventsAndWait() { pollEvents(); g_system->delayMillis(10); }
int main(int argc, char **argv) { init(); pollEvents(); close(); return 0; }
void rScene1::update(float deltaTime) { pollEvents(); m_deltaTime = deltaTime; }
bool Game::runAndDontCrashPls() { if (mainMenu.getEngineSettings().debug){ ns::debug = new DebugConsole; ns::debug->draw(); } else{ HWND hwnd = GetConsoleWindow(); ShowWindow(hwnd, SW_HIDE); } while (ns::reloadState || ns::restartState || (mainMenu.showMenu() && !ns::exitState)){ if (!ns::restartState) init(); else resetStates(); while (ns::runningState){ if (mainMenu.getEngineSettings().vSync){ if (updateClock.getElapsedTime().asSeconds() > ns::g_updateTimerValue){ if (!paused && !ns::deathState){ update(); pollEvents(); } render(); if (paused){ player[0]->resetClocks(); player[1]->resetClocks(); } if (pauseMenu->showMenu(paused)) paused = false; deathMenu.showMenu(); endMenu.showMenu(gameTime.getElapsedTime().asSeconds() + (ns::dirtyRun * ns::checkPointTime.asSeconds())); } } else { if (updateClock.getElapsedTime().asSeconds() > ns::g_updateTimerValue && !paused && !ns::deathState){ update(); pollEvents(); } render(); if (paused){ player[0]->resetClocks(); player[1]->resetClocks(); } if (pauseMenu->showMenu(paused)) paused = false; deathMenu.showMenu(); endMenu.showMenu(gameTime.getElapsedTime().asSeconds() + (ns::dirtyRun * ns::checkPointTime.asSeconds())); } if (!paused && !ns::endOfLevelState && !ns::deathState) gameTime.start(); else gameTime.stop(); } if (!ns::restartState) deInit(); if (ns::exitState) return true; } if (ns::debug != nullptr) delete ns::debug; return true; }
//Game Loop for one game, until there is a winner or the board is full GameMenuDecision::Enum Game::runGame(){ sf::Clock clock; float elapsedTime; float fpsElapsedTime = 0; reset(); LoopState lastLoopState = DISPLAY_END_SCREEN; LoopState loopState = INIT_STATE; LoopState oldLoopState = INIT_STATE; // for pause menu GameMenuDecision::Enum gameMenuDecision = GameMenuDecision::KEEP_PLAYING; InputEvents inputEvents; //bool gameMenuActive = false; // used to show / hide the game menu soundManager->getMusic(SoundManager::GAME_START)->play(); if (backgroundMusic != nullptr){ backgroundMusic->stop(); } backgroundMusic = soundManager->getMusic(SoundManager::BACKGROUND); backgroundMusic->play(); while (window->isOpen() && gameMenuDecision == GameMenuDecision::KEEP_PLAYING){ elapsedTime = clock.getElapsedTime().asSeconds(); float fps = 1.f / elapsedTime; clock.restart(); inputEvents = pollEvents(); //Snow-Animation if (inputEvents.rightMouseButtonPressed){ //It's ok that the number of particles might decrease at lower frame rates mouseCursorParticleBuilder->setPosition(inputEvents.mousePosition); particleSystem->newParticleCloud(1, *mouseCursorParticleBuilder); } // TODO maybe change to whitelist! //bool pause = false; //pause = inputEvents.releasedEscape == true ? true : pause; if (inputEvents.windowLostFocus) { inputEvents.windowLostFocus = false; inputEvents.releasedEscape = true; } // come in if I want to show the game menu if (inputEvents.releasedEscape == true && loopState != DISPLAY_PAUSE_MENU && loopState != DISPLAY_END_SCREEN) { oldLoopState = loopState; loopState = DISPLAY_PAUSE_MENU; gameMenu->setMenuState(GameWinner::PAUSE); inputEvents.releasedEscape = false; } if (inputEvents.windowGainedFocus) { inputEvents.windowGainedFocus = false; inputEvents.releasedEscape = true; } if (inputEvents.windowHasFocus){ switch (loopState) { case INIT_STATE: // TODO das stimmt no ned ganz human iplayer und tc !!!! loopState = players[activePlayerIndex]->type == Player::HUMAN ? HUMAN_SELECT_MEEPLE : TC_START_SELECT_MEEPLE; break; case I_PLAYER_SELECT_MEEPLE: loopState = i_playerSelectMeeple(); break; case HUMAN_SELECT_MEEPLE: loopState = humanSelectMeeple(inputEvents); break; case TC_START_SELECT_MEEPLE: loopState = tcStartSelectMeeple(); break; case TC_WAIT_FOR_SELECTED_MEEPLE: loopState = tcWaitForSelectedMeeple(); break; case HIGHLIGHT_SELECTED_MEEPLE: loopState = highlightSelectedMeeple(elapsedTime); break; case I_PLAYER_SELECT_MEEPLE_POSITION: loopState = i_playerSelectMeeplePosition(); break; case HUMAN_SELECT_MEEPLE_POSITION: loopState = humanSelectMeeplePosition(inputEvents); break; case TC_START_SELECT_MEEPLE_POSITION: loopState = tcStartSelectMeeplePosition(); break; case TC_WAIT_FOR_SELECTED_MEEPLE_POSITION: loopState = tcWaitForSelectedMeeplePosition(); break; case MOVE_MEEPLE_TO_SELECTED_POSITION: loopState = moveMeepleToSelectedPosition(elapsedTime); break; case CHECK_END_CONDITION: loopState = checkEndCondition(); if (loopState == DISPLAY_END_SCREEN){ // Optimization to avoid a (minimal) lag gameMenuDecision = displayEndscreen(inputEvents, elapsedTime); } break; case DISPLAY_PAUSE_MENU: if (inputEvents.releasedEscape == true){ loopState = oldLoopState; inputEvents.releasedEscape = false; } if (hoveredMeeple != nullptr) { hoveredMeeple->setGlow(nullptr); } hoveredMeeple = nullptr; gameMenu->resetHover(); gameMenuDecision = gameMenu->handleClickAndHover(&inputEvents); break; case DISPLAY_END_SCREEN: gameMenuDecision = displayEndscreen(inputEvents, elapsedTime); break; } } fpsElapsedTime += elapsedTime; if (fpsElapsedTime > 0.75) { std::ostringstream ss; ss.precision(4); ss << WINDOW_TITLE << fps << "fps"; window->setTitle(ss.str()); fpsElapsedTime = 0; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //draw /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// window->clear(sf::Color::White); background->update(elapsedTime); background->draw(*window); board->draw(*window); sort(meeplesToDrawAndSort.begin(), meeplesToDrawAndSort.end(), [](RMeeple* a, RMeeple* b){return a->getYPos() < b->getYPos(); }); for (std::vector<RMeeple*>::iterator it = meeplesToDrawAndSort.begin(); it != meeplesToDrawAndSort.end(); ++it){ (*it)->draw(*window); } particleSystem->update(elapsedTime); particleSystem->draw(*window); textManager->update(elapsedTime); if (loopState == DISPLAY_END_SCREEN){ gameMenu->draw(*window); } else { textManager->drawTodo(*window, todoText, activePlayerIndex); } if (loopState == DISPLAY_PAUSE_MENU){ gameMenu->draw(*window); } window->display(); if (lastLoopState != loopState){ firstFrameOfState = true; lastLoopState = loopState; }else{ firstFrameOfState = false; } } backgroundMusic->stop(); particleSystem->fadeOutAllParticles(); return gameMenuDecision; }
int main(int argc, char ** argv) { // Initialise SDL if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) DIE("SDL_Init: %s", SDL_GetError()); GL_Init(); //Init SDL_TTF to print text to the screen... if ( TTF_Init() ) { fprintf( stderr, "Error initializing SDL_ttf!\n" ); exit ( 1 ); } S9xInitDisplay(argc, argv); // Configure snes9x #if CONF_GUI OssoInit(); // Hildon-games-wrapper initialization. #endif S9xLoadConfig(argc, argv); // Load config files and parse cmd line. readOptions(); #if CONF_GUI OssoConfig(); // Apply specific hildon-games config. #endif // S9x initialization S9xInitDisplay(argc, argv); S9xInitAudioOutput(); S9xInitInputDevices(); while(1) { S9xInit(); S9xReset(); char * rom = romSelector(); S9xSetRomFile(rom); free(rom); // Load rom and related files: state, unfreeze if needed loadRom(); resumeGame(); // Late initialization sprintf(String, "DrNokSnes - %s", Memory.ROMName); S9xSetTitle(String); S9xHacksLoadFile(Config.hacksFile); if (!S9xGraphicsInit()) DIE("S9xGraphicsInit failed"); S9xAudioOutputEnable(true); SDL_PauseAudio(0); S9xVideoReset(); Config.running = true; do { frameSync(); // May block, or set frameskip to true. S9xMainLoop(); // Does CPU things, renders if needed. pollEvents(); //Ouch that this is going here... updateBindingMessage(); } while (Config.running); S9xVideoReset(); S9xGraphicsDeinit(); // Save state Memory.SaveSRAM(S9xGetFilename(FILE_SRAM)); pauseGame(); Memory.Deinit(); S9xDeinitAPU(); } // Deinitialization S9xAudioOutputEnable(false); S9xDeinitInputDevices(); S9xDeinitAudioOutput(); S9xDeinitDisplay(); // Late deinitialization S9xUnloadConfig(); #if CONF_GUI OssoDeinit(); #endif SDL_Quit(); return 0; }
xdl_int XdevLWindowEventServerAndroid::update() { return pollEvents(); }
void XdevLWindowEventServerAndroid::flush() { pollEvents(); }
xdl_int XdevLJoystickServerMac::update() { return pollEvents(); }
int main() { auto entityManager = EntityManager::getInstance(); //create entities auto entity = std::shared_ptr<entityType> (new MainEntity("Cursor", 0)); entityManager->addEntity(entity); auto shapeComponent = std::shared_ptr<componentType> (new ShapeComponent("CursorHeight")); entity->addComponent(shapeComponent); shapeComponent->setAttribute_string(ATTRIBUTE_SHAPE_TYPE, SHAPETYPE_RECTANGLE); shapeComponent->setAttribute_float(ATTRIBUTE_WIDTH, 2.0f); shapeComponent->setAttribute_float(ATTRIBUTE_HEIGHT, 10.0f); shapeComponent->setAttribute_float(ATTRIBUTE_RADIUS, 5.0); shapeComponent->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_ALPHA, 0); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 255); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 0); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 0); shapeComponent->setAttribute_float(ATTRIBUTE_OFFSET_X, 4.0); shapeComponent->setAttribute_float(ATTRIBUTE_OFFSET_Y, 0.0); shapeComponent->setAttribute_float(ATTRIBUTE_ZBUFFER, 1.1f); shapeComponent->update(); auto shapeComponent2 = std::shared_ptr<componentType> (new ShapeComponent("CursorWidth")); entity->addComponent(shapeComponent2); shapeComponent2->setAttribute_string(ATTRIBUTE_SHAPE_TYPE, SHAPETYPE_RECTANGLE); shapeComponent2->setAttribute_float(ATTRIBUTE_WIDTH, 10.0f); shapeComponent2->setAttribute_float(ATTRIBUTE_HEIGHT, 2.0f); shapeComponent2->setAttribute_float(ATTRIBUTE_RADIUS, 5.0); shapeComponent2->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_ALPHA, 0); shapeComponent2->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 255); shapeComponent2->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 0); shapeComponent2->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 0); shapeComponent2->setAttribute_float(ATTRIBUTE_OFFSET_X, 0.0); shapeComponent2->setAttribute_float(ATTRIBUTE_OFFSET_Y, 4.0); shapeComponent2->setAttribute_float(ATTRIBUTE_ZBUFFER, 1.1f); shapeComponent2->update(); auto collisionComponent = std::shared_ptr<componentType> (new CollisionComponent("Cursor Collision")); entity->addComponent(collisionComponent); collisionComponent->setAttribute_string(ATTRIBUTE_COLLISION_BOUND_TYPE, COLLISION_BOUND_RECTANGLE); collisionComponent->setAttribute_float(ATTRIBUTE_WIDTH, 5.0); collisionComponent->setAttribute_float(ATTRIBUTE_HEIGHT, 5.0); collisionComponent->setAttribute_string(ATTRIBUTE_COLLISION_TAG, "Cursor"); auto positionComponent = std::shared_ptr<componentType> (new PositionComponent("CursorPosition")); entity->addComponent(positionComponent); positionComponent->setAttribute_float(ATTRIBUTE_POSITION_X, 400); positionComponent->setAttribute_float(ATTRIBUTE_POSITION_Y, 300); positionComponent->setAttribute_float(ATTRIBUTE_OFFSET_X, -5.0); positionComponent->setAttribute_float(ATTRIBUTE_OFFSET_Y, -5.0); auto inputComponent = std::shared_ptr<componentType> (new InputComponent("Cursor Input")); entity->addComponent(inputComponent); inputComponent->setAttribute_string(ATTRIBUTE_INPUT_TYPE, INPUT_MOUSE_MOVE); inputComponent->setAttribute_string(ATTRIBUTE_CALLBACK, MOUSEINPUTCALLBACK); auto callbackManager = CallbackManager::getInstance(); callbackManager->addCallback(MOUSEINPUTCALLBACK, (functionEventTemplate) [] (int ID, int eventIndex) { auto entity = EntityManager::getInstance()->getEntityById(ID); sf::Event theEvent = *EventManager::getInstance()->getEvents()[eventIndex]; float xPosition = static_cast<float> (theEvent.mouseMove.x); float yPosition = static_cast<float> (theEvent.mouseMove.y); //apply the position of the mouse to the position of the entity auto positionComponent = entity->getComponentByName("CursorPosition"); positionComponent->setAttribute_float("Position_X", xPosition); positionComponent->setAttribute_float("Position_Y", yPosition); return 0; }); auto entity2 = std::shared_ptr<entityType> (new MainEntity("Collidable Button", 1)); entityManager->addEntity(entity2); auto shapeComponent3 = std::shared_ptr<componentType> (new ShapeComponent("Button Shape")); entity2->addComponent(shapeComponent3); shapeComponent3->setAttribute_string(ATTRIBUTE_SHAPE_TYPE, SHAPETYPE_RECTANGLE); shapeComponent3->setAttribute_float(ATTRIBUTE_WIDTH, 300.0f); shapeComponent3->setAttribute_float(ATTRIBUTE_HEIGHT, 200.0f); shapeComponent3->setAttribute_float(ATTRIBUTE_RADIUS, 5.0); shapeComponent3->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_RED, 0); shapeComponent3->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_BLUE, 255); shapeComponent3->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_GREEN, 0); shapeComponent3->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_ALPHA, 255); shapeComponent3->setAttribute_float(ATTRIBUTE_OUTLINE_THICKNESS, 5.0); shapeComponent3->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 0); shapeComponent3->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 0); shapeComponent3->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 255); shapeComponent3->setAttribute_float(ATTRIBUTE_OFFSET_X, 0.0); shapeComponent3->setAttribute_float(ATTRIBUTE_OFFSET_Y, 0.0); shapeComponent3->setAttribute_float(ATTRIBUTE_ZBUFFER, 0.0); shapeComponent3->update(); auto textComponent = std::shared_ptr<componentType> (new TextComponent("Text")); entity2->addComponent(textComponent); textComponent->setAttribute_string(ATTRIBUTE_TEXT_STRING, "Not collided with"); textComponent->setAttribute_int(ATTRIBUTE_TEXT_SIZE, 30); textComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_ALPHA, 200); textComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 20); textComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 20); textComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 20); textComponent->update(); auto positionComponent2 = std::shared_ptr<componentType> (new PositionComponent("BoxPosition")); entity2->addComponent(positionComponent2); positionComponent2->setAttribute_float(ATTRIBUTE_POSITION_X, 100.0); positionComponent2->setAttribute_float(ATTRIBUTE_POSITION_Y, 150.0); positionComponent2->setAttribute_float(ATTRIBUTE_OFFSET_X, 0); positionComponent2->setAttribute_float(ATTRIBUTE_OFFSET_Y, 0); auto collisionComponent2 = std::shared_ptr<componentType> (new CollisionComponent("CollisionButton")); entity2->addComponent(collisionComponent2); collisionComponent2->setAttribute_string(ATTRIBUTE_COLLISION_BOUND_TYPE, COLLISION_BOUND_RECTANGLE); collisionComponent2->setAttribute_float(ATTRIBUTE_WIDTH, 300.0); collisionComponent2->setAttribute_float(ATTRIBUTE_HEIGHT, 200.0); collisionComponent2->setAttribute_string(ATTRIBUTE_COLLISION_TAG, "Button"); //adding callbacks for when collisions occur auto collisionManager = CollisionManager::getInstance(); collisionManager->addCallback(collisionTagTuple("Button", "Cursor"), (functionCollisionTemplate) [] (collisionParamTuple paramTuple) { int entityID1, entityID2; std::string compName1, compName2; bool bRegistered; std::tie(entityID1, compName1, entityID2, compName2, bRegistered) = paramTuple; //grab the button entity auto buttonEntity = EntityManager::getInstance()->getEntityById(entityID1); //grab the shape component within that entity auto shapeComponent = buttonEntity->getComponentByName("Button Shape"); auto textComponent = buttonEntity->getComponentByName("Text"); if (bRegistered) { //change the shape component to have new outline shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 255); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 0); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 0); textComponent->setAttribute_string(ATTRIBUTE_TEXT_STRING, "Collided!"); std::cout << "Collision!" << std::endl; } else { shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 0); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 255); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 0); textComponent->setAttribute_string(ATTRIBUTE_TEXT_STRING, "Not Collided"); } shapeComponent->update(); textComponent->update(); return 0; }); //Start working on the window instance and system auto window = sf::RenderWindow(sf::VideoMode(800,600), "Mouse Cursor Input Test"); //remove the mouse cursor window.setMouseCursorVisible(false); auto eventManager = EventManager::getInstance(); //we set the target window to our render window eventManager->setWindow(&window); auto eventSystem = std::shared_ptr<EventSystem> (new EventSystem()); eventSystem->registerClosed_Callback([&] (int ID, int eventIndex) { window.close(); return 0; }); //populate the system manager auto systemManager = SystemManager::getInstance(); systemManager->addSystem(std::shared_ptr<systemType> (new SpriteSystem(window))); systemManager->addSystem(std::shared_ptr<systemType> (new InputSystem())); systemManager->addSystem(std::shared_ptr<systemType> (new CollisionSystem())); systemManager->addSystem(std::shared_ptr<systemType> (std::static_pointer_cast<systemType> (eventSystem))); while(window.isOpen()) { window.clear(); eventManager->pollEvents(); systemManager->processSystemList(); window.display(); } return 0; }
void Tutorial::runLoop() { sf::Clock clock; float elapsedTime; float fpsElapsedTime = 0; switchClock.restart(); while (window->isOpen() && goToMenu == false){ elapsedTime = clock.getElapsedTime().asSeconds(); float fps = 1.f / elapsedTime; clock.restart(); pollEvents(); if (skipToMenuButton.getGlobalBounds().contains(mousePosition)) { //hovered skipToMenuButton.setFillColor(sf::Color(220,0,220,255)); //magenta if (leftMouseClicked) { leftMouseClicked = false; goToMenu = true; break; } } else { skipToMenuButton.setFillColor(sf::Color::Black); } switch (loopState) { case CROSSFADE: { leftMouseClicked = false; rightMouseClicked = false; // check if/why needed if (firstFadingFrame){ firstFadingFrame = false; alpha1 = 255; alpha2 = 0; } if (crossfade(elapsedTime, background[fadeIndexA], background[fadeIndexB])){ loopState = WAIT; bool goForward = fadeIndexB < fadeIndexA; if (goForward){ uint8_t temp = fadeIndexA; // swap indices fadeIndexA = fadeIndexB; fadeIndexB = temp; } else{ ++fadeIndexA; ++fadeIndexB; } } } break; case WAIT: { if (rightMouseClicked) { rightMouseClicked = false; // consume events leftMouseClicked = false; // just to be safe switchClock.restart(); if (fadeIndexB > 1){ // at second screen or higher firstFadingFrame = true; loopState = CROSSFADE; fadeIndexB -= 2; // jump to one before fadeIndexA } } else if (switchClock.getElapsedTime().asSeconds() > TIME_TO_WAIT_TILL_NEXT_SWITCH || leftMouseClicked) { if (fadeIndexB == 10) // 10 = backgroundarray size { goToMenu = true; break; } leftMouseClicked = false; // consume events //rightMouseClicked = false; // not needed because of the else if // just to be safe loopState = CROSSFADE; firstFadingFrame = true; switchClock.restart(); } } break; default: { assert(false); } break; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //draw /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// window->clear(sf::Color::White); window->draw(background[fadeIndexA]); window->draw(background[fadeIndexB]); if (fadeIndexA != 0 || loopState == CROSSFADE){ window->draw(skipToMenuButton); } window->display(); fpsElapsedTime += elapsedTime; if (fpsElapsedTime > 0.75) { std::ostringstream ss; ss.precision(4); ss << WINDOW_TITLE << fps << "fps"; window->setTitle(ss.str()); fpsElapsedTime = 0; } } }