/** Called when the user clicks on a widget. * \param widget that was clicked on. * \param name Name of the widget. * \param playerID The id of the player who clicked the item. */ void LoginScreen::eventCallback(Widget* widget, const std::string& name, const int playerID) { if (name == "login_tabs") { StateManager *sm = StateManager::get(); const std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); if (selection == "tab_guest_login") sm->replaceTopMostScreen(GuestLoginScreen::getInstance()); else if (selection == "tab_register") sm->replaceTopMostScreen(RegisterScreen::getInstance()); } else if (name=="options") { const std::string button = getWidget<RibbonWidget>("options") ->getSelectionIDString(PLAYER_ID_GAME_MASTER); if(button=="sign_in") { login(); } else if(button=="recovery") { } else if(button=="cancel") StateManager::get()->escapePressed(); } } // eventCallback
int main(int argc, char *argv[]) { UNUSED(argc); UNUSED(argv); try { Globals::init(); Arguments::parse(argc, argv); Utils::Random::seed(); Ncurses::init(); Colors::init(); StateManager states; states.run(); Ncurses::exit(); } catch (...) { // I dont really have a nice exception-handling scheme right // now. I must learn how to properly deal with them. Ncurses::exit(); return 666; } return 0; }
/** * Receive all messages and compute the new belief. */ inline void update_belief(const vertex_type& vertex, StateManager& state) { // Get the belief from the state manager belief_type* blf = state.checkout_belief(vertex); // Wipe out the old value for the belief if(vertex.is_variable()) { *blf = 1; } else if(vertex.is_factor()) { *blf = vertex.factor(); } else { assert(false); } // For each of the neighbor variables foreach(const vertex_type& vertex_source, state.neighbors(vertex)) { // get the in message message_type* in_msg = state.try_checkout(vertex_source, vertex, Reading); if(in_msg != NULL) { // Combine the in_msg with the destination factor blf->combine_in(*in_msg, csr_.dot_op); // return the message to the state manager state.checkin(vertex_source, vertex, in_msg); // normalize the belief blf->normalize(); } } // Do an extra normalization (just in case no messages were // available) blf->normalize(); // ASSERT WE BLF IS A VALID DISTRIBUTION (we should check this) // Save the belief state.checkin_belief(vertex, blf); }// End of update belief
int main (int argc, char * argv[]) { Window::getInstance()->create(1366, 768, "inspector gadget!", true); Input * input = Input::getInstance(); if(ifstream("data/preferences.ini")) input->loadKeymapping("data/preferences.ini"); else { input->addMapping("escape", SDLK_ESCAPE); input->addMapping("enter", SDLK_RETURN); input->addMapping("up", SDLK_UP); input->addMapping("down", SDLK_DOWN); input->addMapping("left", SDLK_LEFT); input->addMapping("right", SDLK_RIGHT); input->saveKeymapping("data/preferences.ini"); } StateManager * stateman = StateManager::getInstance(); stateman->changeState(new state::GameState()); stateman->run(); std::cout << "bye\n"; return 0; }
void run() { double lastFPSTime = glfwGetTime(); int fps = 0; while (!m_win->shouldClose()) { glfwPollEvents(); double now = glfwGetTime(); m_stateManager.update(); m_stateManager.draw(); m_win->swapBuffers(); if (now - lastFPSTime > 1) { char fpsString[200]; sprintf( fpsString, "Pxljm 2015 [%d FPS @%dx%d]", fps, m_win->width(), m_win->height()); m_win->title(fpsString); fps = 0; lastFPSTime = now; } fps++; } delete m_win; glfwTerminate(); }
void RouteTable::getFromStates(const State& toState, std::set<State*>& fromStates) { // if didn't found, then just return const std::string& toStateName = toState.name(); StateMapConstIterator it = mapToStateToFromStates.find(toStateName); if (it == mapToStateToFromStates.end()) { std::cout << "RouteTable:: state \"" << toState << "\" didn't have any other state directed to" << std::endl; return; } StateManager* stateManager = StateManager::instance(); fromStates.clear(); const std::set<std::string>& fromStateNames = mapToStateToFromStates[toStateName]; for (std::set<std::string>::const_iterator it = fromStateNames.begin(); it != fromStateNames.end(); ++it) { const std::string& fromState = *it; State* state = stateManager->getState(fromState); if (state) fromStates.insert(state); } return; }
int main() { StateManager* stateManager = new StateManager(); stateManager->run(); delete stateManager; return 0; }
gboolean S9xIdleFunc (gpointer data) { if (needs_fullscreening) { top_level->enter_fullscreen_mode(); needs_fullscreening = FALSE; } if (Settings.Paused) { S9xSetSoundMute (gui_config->mute_sound); S9xSoundStop (); #ifdef USE_JOYSTICK gui_config->flush_joysticks (); #endif #ifdef NETPLAY_SUPPORT if (Settings.NetPlay && NetPlay.Connected) { S9xNPSendPause (TRUE); } #endif /* Move to a timer-based function to use less CPU */ g_timeout_add (100, S9xPauseFunc, NULL); top_level->update_statusbar (); return FALSE; } if (syncing) S9xSyncSpeedFinish (); S9xCheckPointerTimer (); S9xProcessEvents (TRUE); #ifdef NETPLAY_SUPPORT if (!S9xNetplayPush ()) { #endif if(top_level->user_rewind) top_level->user_rewind = stateMan.pop(); else if(IPPU.TotalEmulatedFrames % gui_config->rewindGranularity == 0) stateMan.push(); S9xMainLoop (); S9xMixSound (); #ifdef NETPLAY_SUPPORT S9xNetplayPop (); } #endif return TRUE; }
int main(int argc, const char* argv[]) { ResourceLoader loader(argv[0] + std::string("\\..\\..\\Resources")); StateManager states; states.setState(std::unique_ptr<MenuScreen>(new MenuScreen(loader))); sf::RenderWindow app(sf::VideoMode(768, 768, 32), "Ethan Game"); app.EnableKeyRepeat(false); sf::Clock clock; double timeForSimulation = 0; while (app.IsOpened()) { sf::Event event; while (app.GetEvent(event)) { switch(event.Type) { case sf::Event::Closed: app.Close(); break; default: states.handleEvent(event); } } timeForSimulation+= clock.GetElapsedTime(); clock.Reset(); while (timeForSimulation >= 1.0/60.0) { states.update(1.0/60.0); timeForSimulation -= 1.0/60; } states.draw(app); app.Display(); } return 0; }
int main() { StateManager manager; manager.pushState(new PlayState(&manager)); manager.gameLoop(); return 0; }
void GameEngine::GameLoop() { // Set framerate cap GLdouble framerate = 999.0; GLdouble lastFrameTime = 0, currentFrameTime = 0, fpsLastUpdate = 0; gameRunning = true; // Main-loop while(gameRunning) { currentFrameTime = glfwGetTime(); if ((currentFrameTime - lastFrameTime) * 1000.0 < 1000.0 / framerate) { Sleep(0.0001); } else { // Check if a state has been queued if (StateManager::GetInstance()->StateHasBeenQueued()) { StateManager *sM = StateManager::GetInstance(); ResourceManager * rM = ResourceManager::GetInstance(); // Change state rM->UnloadAll(); sM->ChangeState(sM->GetQueuedState()); rM->StartLoading(); } // Handle input HandleInput(); // Update Update((currentFrameTime - lastFrameTime) * 1000.0); // Draw Draw(); // update fps-counter GLdouble time = currentFrameTime; if (time - fpsLastUpdate >= 1.0) { GLdouble fps = ((currentFrameTime - lastFrameTime) * 1000.0); glfwSetWindowTitle(Context::getWindow(), toString((int)((1000.0 / fps) * 100.0) / 100.0).c_str()); fpsLastUpdate = time; } lastFrameTime = currentFrameTime; } } // Cleanup game if loop stops Cleanup(); }
void RunTest() { StateManager stateManager; // stateManager.Process(0); stateManager.Push(Splash, NULL); stateManager.Process(NULL); stateManager.Pop(); }
int32 changeVarValue(void *v1, void *v2) { StateManager *stateManager = (StateManager *)v1; EventCallback *callbackData = (EventCallback *)v2; StateVariable curVal = stateManager->GetStateVar(FLOAT_VAR_HANDLE); curVal.floatValue += 1.1f; stateManager->SetStateVar(FLOAT_VAR_HANDLE, curVal); curVal.intValue = (int)curVal.floatValue; stateManager->SetStateVar(INT_VAR_HANDLE, curVal); stateManager->PostFutureEvent("FloatChange", NULL, callbackData->gameTime + 3000); return 0; }
//根据状态机判断当前状态是否可以切换到目标状态 bool PostureState::canTransition(StateMachine* self,State* targetState) { bool ret = false; do{ if( self->getBlocked() ) break; //状态机阻塞则返回 State* CurrentPostureState = self->getCurrentPostureState(); //得到当前状态 sStateCode CurrentStateCode = CurrentPostureState->getCode(); sStateCode targetStateCode = targetState->getCode(); StateManager* stateManage = self->getStateManage(); //状态管理器 if( stateManage->isInTransitionVec(self,CurrentStateCode,targetStateCode)) //判断当前状态是否可以切换至目标状态 { ret = true; } } while (0); return ret; }
void SFMLMenu::update(StateManager& manager) { sf::Event event; while (this->_window->pollEvent(event)) { switch (event.type) { case sf::Event::Closed: this->_window->close(); manager.exit(); break; case sf::Event::TextEntered: if (event.text.unicode == 13) { this->connect(); manager.pushState(new StateRoom(this->_window, this->_world, this->_music)); } else if (event.text.unicode == 8) this->_textboxIP->removelastCharacter(); else { if ((event.text.unicode < '0' || event.text.unicode > '9') && event.text.unicode != '.') return; this->_textboxIP->addCharacter(static_cast<char>(event.text.unicode)); } break; case sf::Event::MouseButtonPressed: if (this->_buttonplay->isMouseOnButton()) { this->connect(); manager.pushState(new StateRoom(this->_window, this->_world, this->_music)); } else if (this->_buttonCredit->isMouseOnButton()) manager.pushState(new StateCredit(this->_window)); else if (this->_buttonSolo->isMouseOnButton()) { this->_music->stop(); manager.pushState(new StateSoloGame(this->_world)); } return; default: break; } } }
//----------------------------------------------------------------------------- // Entry point for the application. //----------------------------------------------------------------------------- int main ( ) { // Create our state manager. StateManager stateManager; // Push a new TestStateOne object into our stateManager object. // When we do this the state manager internally calls the // Init() function of the state being pushed in. stateManager.Push( new TestStateOne ( ) ); // The frame() function of the stateManager object calls the // frame() function of the current state. This is the place // where all logical syntax will be executed. stateManager.Frame(); // The render() function of the stateManager object calls the // render() function of the current state. This is the place // where all rendering syntax will be executed. stateManager.Render(); // We now are pushing a TestStateTwo object into our stateManager // object. The testStateOne object still exist inside our // stateManager. Because the testStateTwo object is at the top // of the internal stateManager vector container, it takes focus. stateManager.Push( new TestStateTwo ( ) ); stateManager.Frame(); stateManager.Render(); // We now are removing the current state from stateManager. // This means testStateOne is back in focus. This is where // any custom shutdown syntax would go. stateManager.Pop(); // For demonstration purposes we are going to go ahead and // push a new TestStateTwo object into the stateManager. stateManager.Push( new TestStateTwo ( ) ); // By calling this function we are going to be removing both // the testStateOne object and the testStateTwo object from // our stateManager. stateManager.PopAll(); return 0; }
/** Called when an event occurs (i.e. user clicks on something). */ void OnlineProfileBase::eventCallback(Widget* widget, const std::string& name, const int playerID) { if (m_profile_tabs && name == m_profile_tabs->m_properties[PROP_ID]) { std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); StateManager *sm = StateManager::get(); if (selection == m_friends_tab->m_properties[PROP_ID]) sm->replaceTopMostScreen(OnlineProfileFriends::getInstance()); else if (selection == m_achievements_tab->m_properties[PROP_ID]) sm->replaceTopMostScreen(TabOnlineProfileAchievements::getInstance()); else if (selection == m_settings_tab->m_properties[PROP_ID]) sm->replaceTopMostScreen(OnlineProfileSettings::getInstance()); } else if (name == "back") { StateManager::get()->escapePressed(); } } // eventCallback
int main(int argc, char *argv[]) #endif { srand(time(NULL)); // Create application object StateManager* app = StateManager::getInstance(); try { app->run(PlayState::getInstance()); } catch( Ogre::Exception& e ) { #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); #else std::cerr << "An exception has occured: " << e.getFullDescription().c_str() << std::endl; #endif } catch (std::exception& e) { MessageBox( NULL, e.what(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); } return 0; }
int main() { SetupCallbacks(); scePowerSetClockFrequency(333, 333, 166); //initialize render manager RenderManager::InstancePtr()->Init(); RenderManager::InstancePtr()->CollectPerformance(true); RenderManager::InstancePtr()->InitDebugFont(); //set perspectives RenderManager::InstancePtr()->SetOrtho(0,0,0,0,0,0); //init and load sounds SoundManager::Instance()->Init(); srand(time(NULL)); //new state manager StateManager stateManager; stateManager.Init(); RenderManager::InstancePtr()->SetClearColour(0xFF000000); //splash screens SplashScreen *screen = new SplashScreen(TextureHelper::Instance()->GetTexture(TextureHelper::Genesis),0,0,480,272,3); screen->ShowSplash(); delete screen; SplashScreen *screen2 = new SplashScreen(TextureHelper::Instance()->GetTexture(TextureHelper::PspTeam),0,0,424,72,3); screen2->ShowSplash(); delete screen2; RenderManager::InstancePtr()->SetClearColour(0xFFF5B783); //new active state StateMenu *statePlay = new StateMenu(); statePlay->Init(); stateManager.ChangeState(statePlay); //trun while ( stateManager.Running() ) { stateManager.HandleEvents(); stateManager.Update(); stateManager.Draw(); } sceGuTerm(); // Terminating the Graphics System sceKernelExitGame(); // Quits Application return 0; }
void GameStatePlayingLevel::goToNextLevel(sf::RenderWindow &window, StateManager &stateManager) { //create the next level shared_ptr<GameState> nextLevel = make_shared<GameStatePlayingLevel>("world1", world.players, window); //intro transition to next level shared_ptr<GameState> nextLevelIntro = make_shared<GameStateLevelIntro>(window); vector<State> statesFollowingOutro; statesFollowingOutro.push_back(nextLevel); statesFollowingOutro.push_back(nextLevelIntro); //outro to this level shared_ptr<GameState> outro = make_shared<GameStateOutro>(window, true, statesFollowingOutro); //insert the outro, once outro is finished it will automatically get rid of this level, and add the new level stateManager.push(outro); }
void RunTest() { StateManager stateManager; stateManager.Process(0); stateManager.Push(test1, 0); stateManager.Push(test2, 0); stateManager.Pop(); stateManager.Pop(); }
int main( int argc, char* args[] ) { //Start SDL SDL_Init( SDL_INIT_EVERYTHING ); //Set up screen SDL_Surface* screen = NULL; screen = SDL_SetVideoMode( WINWIDTH, WINHEIGHT, 32, SDL_SWSURFACE ); SDL_WM_SetCaption("Squids of the Galaxy", NULL); //State Mananger StateManager* stateManager = StateManager::Instance(); //Create main menu MainMenuState* mainMenu = new MainMenuState(); stateManager->changeState(mainMenu); //Main game loop while (stateManager->isRunning()) { //USER INPUT while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) stateManager->quit(); //Take user input stateManager->userInput(&event); } //UPDATE stateManager->update(); //RENDER stateManager->display(screen); if (SDL_Flip(screen) == -1) return 1; } //Quit SDL SDL_Quit(); return 0; }
void testStateManager() { cout << "Testing state manager" << endl; StateManager sm; sm.push(g_fact->getNewState()); assert(sm.peek()->getOID() == 0); assert(sm.numStates() == 1); sm.push(g_fact->getNewState()); sm.swap(g_fact->getNewState()); assert(sm.peek()->getOID() == 2); assert(sm.peekPrev()->getOID() == 0); assert(sm.numStates()==2); sm.kill(); assert(sm.numStates()==0); }
void DoSimpleTest(GameManager *mgr, uint32 marker_handle, uint32 width, uint32 height) { StateManager *state = mgr->GetStateManager(); StateVariable tmpVar; tmpVar.intValue = 21; INT_VAR_HANDLE = state->RegisterStateVariable("IntVar", tmpVar); tmpVar.floatValue = 3.1415f; FLOAT_VAR_HANDLE = state->RegisterStateVariable("FloatVar", tmpVar); tmpVar.stringValue = "Hello World!"; STRING_VAR_HANDLE = state->RegisterStateVariable("StringVar", tmpVar); PathFollowingSprite *intPath = new PathFollowingSprite(mgr); intPath->AddSegment(new PathSegmentBezier(CIwVec2(100,100), CIwVec2(200, 900), CIwVec2(700, -50), CIwVec2(800,600))); intPath->SetTotalPathTimeMillis(5000); mgr->RegisterGameObject(intPath); CIwColour transparent; transparent.Set(0, 0, 0, 0); char buffer[1024]; sprintf(buffer, "Int: %d", state->GetStateVar(INT_VAR_HANDLE).intValue); intSprite = new TextSprite(mgr, buffer); intSprite->SetBackgroundColor(g_IwGxColours[IW_GX_COLOUR_WHITE]); intSprite->SetBorderColor(g_IwGxColours[IW_GX_COLOUR_BLUE]); intSprite->SetBorderThickness(CIwVec2(3, 3)); intSprite->SetPadding(CIwVec2(3, 3)); intSprite->SetBaseLocation(CIwVec2(300, 100)); //intSprite->AddTransformation(new AnchorToTransformation(intPath, CIwVec2(0,0))); //intSprite->AddTransformation(new OrbitTransformation(0, 5000)); mgr->RegisterGameObject(intSprite); sprintf(buffer, "Float: %f", state->GetStateVar(FLOAT_VAR_HANDLE).floatValue); floatSprite = new TextSprite(mgr, buffer); floatSprite->SetBackgroundColor(g_IwGxColours[IW_GX_COLOUR_WHITE]); floatSprite->SetBorderColor(g_IwGxColours[IW_GX_COLOUR_GREEN]); floatSprite->SetBorderThickness(CIwVec2(3, 3)); floatSprite->SetPadding(CIwVec2(3, 3)); floatSprite->SetBaseLocation(CIwVec2(300, 200)); mgr->RegisterGameObject(floatSprite); sprintf(buffer, "String: %s", state->GetStateVar(STRING_VAR_HANDLE).stringValue); stringSprite = new TextSprite(mgr, buffer); stringSprite->SetBackgroundColor(g_IwGxColours[IW_GX_COLOUR_WHITE]); stringSprite->SetBorderColor(g_IwGxColours[IW_GX_COLOUR_CYAN]); stringSprite->SetBorderThickness(CIwVec2(5, 5)); stringSprite->SetPadding(CIwVec2(2, 2)); stringSprite->SetBaseLocation(CIwVec2(300, 300)); mgr->RegisterGameObject(stringSprite); sprintf(buffer, "Next string"); stringSprite = new TextSprite(mgr, buffer); stringSprite->SetBackgroundColor(g_IwGxColours[IW_GX_COLOUR_WHITE]); stringSprite->SetBorderColor(g_IwGxColours[IW_GX_COLOUR_BLACK]); stringSprite->SetMargin(CIwVec2(4, 4)); stringSprite->SetBorderThickness(CIwVec2(4, 4)); stringSprite->SetPadding(CIwVec2(4, 4)); stringSprite->SetBaseLocation(CIwVec2(400, 400)); mgr->RegisterGameObject(stringSprite); state->SubscribeStateVarChange(INT_VAR_HANDLE, stateVarChanged, intSprite); state->SubscribeStateVarChange(FLOAT_VAR_HANDLE, stateVarChanged, floatSprite); state->SubscribeEvent("FloatChange", changeVarValue, NULL); state->PostFutureEvent("FloatChange", NULL, mgr->GetCurrentClockTime() + 3000); }
/** * Receive all messages into the factor f and compute all new * outbound messages. */ void send_messages(const vertex_type& vertex, StateManager& state) { // Get the belief from the state manager belief_type* blf; // Wipe out the old value for the belief if(vertex.is_variable()) { blf = state.checkout_belief(vertex); (*blf) = 1; blf->normalize(); // std::cout << "var\n"; } else if(vertex.is_factor()) { blf = new belief_type(); (*blf) = vertex.factor(); blf->normalize(); // std::cout << "fact\n"; } else { assert(false); } // std::cout << blf->arguments()<<"\n"; std::vector<vertex_type> neighbors; std::vector<message_type*> neighbor_inmsg; // For each of the neighbor variables // std::cout << (*blf); foreach(const vertex_type& vertex_source, state.neighbors(vertex)) { // get the in message message_type* in_msg = state.checkout(vertex_source, vertex, Reading); // remember the messages and which neighbor it came from neighbors.push_back(vertex_source); neighbor_inmsg.push_back(in_msg); // Combine the in_msg with the destination factor if (vertex.is_variable()) { assert(in_msg->arguments().size() == 1); assert(in_msg->arguments().contains(&(vertex.variable()))); } else if (vertex.is_factor()) { assert(blf->arguments().contains(&(vertex_source.variable()))); } blf->combine_in(*in_msg, csr_.dot_op); // std::cout << "Include: " << (*in_msg); // normalize the belief blf->normalize(); // std::cout << (*blf); } //std::cout<< "------------------------------------"; // compute the outgoing messages message_type oldmessage; for (size_t i = 0; i< neighbors.size(); ++i) { message_type* out_msg = state.checkout(vertex, neighbors[i], Writing); // divide out the incoming message here oldmessage = (*out_msg); // std::cout << "Exclude: " << (*neighbor_inmsg[i]); if (neighbors[i].is_variable()) { (*out_msg) = blf->collapse(csr_.cross_op, make_domain(&neighbors[i].variable())); out_msg->combine_in(*(neighbor_inmsg[i]), divides_op); } else { (*out_msg) = combine(*blf, *(neighbor_inmsg[i]), divides_op); } out_msg->normalize(); // std::cout<<*out_msg; // Save the damped message to the destination message // lets only damp the factor to variable updates // otherwise we will 'doubly damp' the messages in a pairwise MRF if(neighbors[i].is_variable()) { (*out_msg) = weighted_update(*out_msg, oldmessage, damping_); } // checkin the final message to the state manager state.checkin(neighbors[i], vertex, neighbor_inmsg[i]); state.checkin(vertex, neighbors[i], out_msg); } // getchar(); // lets checkin the belief while we are at it if (vertex.is_variable()) state.checkin_belief(vertex,blf); else delete blf; state.mark_visited(vertex); }
int main(int argc, char *argv[]) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { // Something went very wrong in initialisation, all we can do is exit Utility::log(Utility::E,"Whoops! Something went very wrong, cannot initialise SDL"); return -1; } TTF_Init(); Mix_Init(MIX_INIT_OGG | MIX_INIT_MP3); if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) { Utility::log(Utility::E, "SDL_mixer init failed: " + std::string(Mix_GetError())); } SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); int winPosX = SDL_WINDOWPOS_CENTERED; int winPosY = SDL_WINDOWPOS_CENTERED; int winWidth = 640; int winHeight = 480; SDL_Window *window = SDL_CreateWindow("PGG Assignment 2 by Richard Hancock", // The first parameter is the window title winPosX, winPosY, winWidth, winHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0); SDL_GLContext glcontext = SDL_GL_CreateContext(window); // Call our initialisation function to set up GLEW and print out some GL info to console if (!InitGL()) { return -1; } unsigned int lastTime = SDL_GetTicks(); glEnable(GL_DEPTH_TEST); Utility::randomInit(); //Create the Resource manager that loads resources ResourceManager* resourceManager = new ResourceManager(renderer); StateManager* manager = new StateManager(winWidth, winHeight); manager->addState(new PlayState(manager, resourceManager)); bool go = true; while (go) { unsigned int current = SDL_GetTicks(); float deltaTs = (float)(current - lastTime) / 1000.0f; // Now that we've done this we can use the current time as the next frame's previous time lastTime = current; //Event Handling go = manager->eventHandler(); //Update Utility::Timer::update(deltaTs); manager->update(deltaTs); // Draw our world // // Specify the colour to clear the framebuffer to glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This writes the above colour to the colour part of the framebuffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); manager->render(); // This tells the renderer to actually show its contents to the screen // We'll get into this sort of thing at a later date - or just look up 'double buffering' if you're impatient :P SDL_GL_SwapWindow(window); // Limiter in case we're running really quick if (deltaTs < (1.0f / 50.0f)) // not sure how accurate the SDL_Delay function is.. { SDL_Delay((unsigned int)(((1.0f / 50.0f) - deltaTs)*1000.0f)); } } // If we get outside the main game loop, it means our user has requested we exit manager->popLastState(); delete manager; delete resourceManager; // Our cleanup phase, hopefully fairly self-explanatory ;) IMG_Quit(); Mix_CloseAudio(); Mix_Quit(); SDL_GL_DeleteContext(glcontext); SDL_DestroyWindow(window); SDL_Quit(); return 0; }
S3E_MAIN_DECL void IwMain() { strcpy(EVENT_APPLE_DROP, "AppleDrop"); strcpy(EVENT_NEW_DUMPTRUCK, "NewDumptruck"); srand(time(null)); wordBuilder = new WordBuilder; GameManager *mgr; mgr = new GameManager(); mgr->SetRequestedFPS(100); mgr->GetResourceManager()->RegisterResourceGroup("images.group"); IMAGE_MAIN_MENU = mgr->GetResourceManager()->RegisterImage("MainMenu"); IMAGE_CHANGE_PLAYER_BUTTON = mgr->GetResourceManager()->RegisterImage("ChangePlayerButton"); IMAGE_START_GAME_BUTTON = mgr->GetResourceManager()->RegisterImage("StartGameButton"); IMAGE_LEVEL_SELECT = mgr->GetResourceManager()->RegisterImage("LevelSelectionScreen"); IMAGE_PLAY_BUGS_BUTTON = mgr->GetResourceManager()->RegisterImage("BogsIcon"); IMAGE_PLAY_APPLES_BUTTON = mgr->GetResourceManager()->RegisterImage("ApplesIcon"); IMAGE_PLAY_SANDBOX_BUTTON = mgr->GetResourceManager()->RegisterImage("SandboxIcon"); IMAGE_PLAY_WALL_BUTTON = mgr->GetResourceManager()->RegisterImage("WallIcon"); IMAGE_MAIN_MENU_BUTTON = mgr->GetResourceManager()->RegisterImage("MainMenuButton"); IMAGE_LADYBUG = mgr->GetResourceManager()->RegisterImage("ladybug"); IMAGE_SPLAT = mgr->GetResourceManager()->RegisterImage("splat"); IMAGE_BUGS_BACKGROUND = mgr->GetResourceManager()->RegisterImage("bugs_background"); IMAGE_APPLES_BACKGROUND = mgr->GetResourceManager()->RegisterImage("apples_background"); IMAGE_APPLE = mgr->GetResourceManager()->RegisterImage("apple"); IMAGE_SANDBOX_BACKGROUND = mgr->GetResourceManager()->RegisterImage("sandbox_background"); IMAGE_SANDCASTLE = mgr->GetResourceManager()->RegisterImage("sandcastle"); IMAGE_DUMPTRUCK_FULL = mgr->GetResourceManager()->RegisterImage("dumptruck_full"); IMAGE_DUMPTRUCK_EMPTY = mgr->GetResourceManager()->RegisterImage("dumptruck_empty"); IMAGE_WALL_BACKGROUND = mgr->GetResourceManager()->RegisterImage("wall_background"); IMAGE_BRICK1 = mgr->GetResourceManager()->RegisterImage("brick1"); IMAGE_BRICK2 = mgr->GetResourceManager()->RegisterImage("brick2"); IMAGE_BRICK3 = mgr->GetResourceManager()->RegisterImage("brick3"); IMAGE_BRICK_TARGET = mgr->GetResourceManager()->RegisterImage("brick_target"); IMAGE_STAR_0 = mgr->GetResourceManager()->RegisterImage("star_0"); IMAGE_STAR_1 = mgr->GetResourceManager()->RegisterImage("star_1"); IMAGE_STAR_2 = mgr->GetResourceManager()->RegisterImage("star_2"); IMAGE_STAR_3 = mgr->GetResourceManager()->RegisterImage("star_3"); IMAGE_STAR_4 = mgr->GetResourceManager()->RegisterImage("star_4"); IMAGE_STAR_5 = mgr->GetResourceManager()->RegisterImage("star_5"); FONT_TREB_16 = mgr->GetResourceManager()->RegisterFont("trebuchet16pt"); FONT_TREB_24 = mgr->GetResourceManager()->RegisterFont("trebuchet24pt"); FONT_TREB_36 = mgr->GetResourceManager()->RegisterFont("trebuchet36pt"); FONT_COOPER_18 = mgr->GetResourceManager()->RegisterFont("cooper_18pt"); FONT_COOPER_24 = mgr->GetResourceManager()->RegisterFont("cooper_24pt"); FONT_COOPER_48 = mgr->GetResourceManager()->RegisterFont("cooper_48pt"); SOUND_DING = mgr->GetResourceManager()->RegisterAudio("DING.wav"); SOUND_BUZZ = mgr->GetResourceManager()->RegisterAudio("BUZZ.wav"); GameManager::SetDebugFont(mgr->GetResourceManager()->GetFont(FONT_TREB_16)); StateManager *state = mgr->GetStateManager(); STATE_STARTUP = state->RegisterGameState("Startup"); STATE_MAIN_MENU = state->RegisterGameState("MainMenu"); STATE_LEVEL_SELECT = state->RegisterGameState("LevelSelect"); STATE_BUGS_PLAYING = state->RegisterGameState("BugsPlaying"); STATE_BUGS_SUMMARY = state->RegisterGameState("BugsSummary"); STATE_APPLES_PLAYING = state->RegisterGameState("ApplesPlaying"); STATE_APPLES_SUMMARY = state->RegisterGameState("ApplesSummary"); STATE_SANDBOX_PLAYING = state->RegisterGameState("SandboxPlaying"); STATE_SANDBOX_SUMMARY = state->RegisterGameState("SandboxSummary"); STATE_WALL_PLAYING = state->RegisterGameState("WallPlaying"); STATE_WALL_SUMMARY = state->RegisterGameState("WallSummary"); state->DefineValidStateTransition(STATE_STARTUP, STATE_MAIN_MENU); state->DefineValidStateTransition(STATE_MAIN_MENU, STATE_LEVEL_SELECT); state->DefineValidStateTransition(STATE_LEVEL_SELECT, STATE_MAIN_MENU); state->DefineValidStateTransition(STATE_LEVEL_SELECT, STATE_BUGS_PLAYING); state->DefineValidStateTransition(STATE_BUGS_PLAYING, STATE_BUGS_SUMMARY); state->DefineValidStateTransition(STATE_BUGS_SUMMARY, STATE_LEVEL_SELECT); state->DefineValidStateTransition(STATE_LEVEL_SELECT, STATE_APPLES_PLAYING); state->DefineValidStateTransition(STATE_APPLES_PLAYING, STATE_APPLES_SUMMARY); state->DefineValidStateTransition(STATE_APPLES_SUMMARY, STATE_LEVEL_SELECT); state->DefineValidStateTransition(STATE_LEVEL_SELECT, STATE_SANDBOX_PLAYING); state->DefineValidStateTransition(STATE_SANDBOX_PLAYING, STATE_SANDBOX_SUMMARY); state->DefineValidStateTransition(STATE_SANDBOX_SUMMARY, STATE_LEVEL_SELECT); state->DefineValidStateTransition(STATE_LEVEL_SELECT, STATE_WALL_PLAYING); state->DefineValidStateTransition(STATE_WALL_PLAYING, STATE_WALL_SUMMARY); state->DefineValidStateTransition(STATE_WALL_SUMMARY, STATE_LEVEL_SELECT); state->SetInitialState(STATE_STARTUP); StateVariable initialValue; initialValue.intValue = 0; VAR_POINTS = state->RegisterVariable("GamePoints", initialValue); VAR_CURRENT_THINGY_COUNT = state->RegisterVariable("CurrentBugCount", initialValue); VAR_CURRENT_CORRECT_THINGY_COUNT = state->RegisterVariable("CorrectBugCount", initialValue); initialValue.stringValue = null; VAR_CURRENT_PHONEME = state->RegisterVariable("CurrentPhoneme", initialValue); // These objects do not register, so we have to delete them ourselves MainMenu *mainMenu = new MainMenu(mgr); LevelSelection *levelSelect = new LevelSelection(mgr); BugsLevel *bugsLevel = new BugsLevel(mgr); ApplesLevel *applesLevel = new ApplesLevel(mgr); SandboxLevel *sandboxLevel = new SandboxLevel(mgr); WallLevel *wallLevel = new WallLevel(mgr); levelSummary = new LevelSummary(mgr); state->ChangeState(STATE_MAIN_MENU); mgr->MainLoop(); delete levelSummary; delete wallLevel; delete sandboxLevel; delete applesLevel; delete bugsLevel; delete levelSelect; delete mainMenu; delete mgr; delete wordBuilder; }
//TODO(robert): Convert to new UI system. State_Console::State_Console(StateManager& l_stateManager) : BaseState(l_stateManager), m_console(l_stateManager.GetContext().GetWindow()->GetRenderWindow(), *l_stateManager.GetContext().GetFontManager()){}
// ---------------------------------------------------------------------------- void OptionsScreenInput2::eventCallback(Widget* widget, const std::string& name, const int playerID) { //const std::string& screen_name = getName(); StateManager *sm = StateManager::get(); if (name == "options_choice") { std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); Screen *screen = NULL; if (selection == "tab_audio") screen = OptionsScreenAudio::getInstance(); //else if (selection == "tab_video") // screen = OptionsScreenVideo::getInstance(); else if (selection == "tab_players") screen = TabbedUserScreen::getInstance(); //else if (selection == "tab_controls") // screen = OptionsScreenInput::getInstance(); else if (selection == "tab_ui") screen = OptionsScreenUI::getInstance(); if(screen) StateManager::get()->replaceTopMostScreen(screen); } else if (name == "back_to_device_list") { sm->replaceTopMostScreen(OptionsScreenInput::getInstance()); } else if (name == "back") { sm->replaceTopMostScreen(OptionsScreenInput::getInstance()); } else if (name == "actions") { GUIEngine::ListWidget* actions = getWidget<GUIEngine::ListWidget>("actions"); assert( actions != NULL ); // a player action in the list was clicked. find which one const std::string& clicked = actions->getSelectionInternalName(); for (int n=PA_BEFORE_FIRST+1; n<PA_COUNT; n++) { if (KartActionStrings[n] == clicked) { // we found which one. show the "press a key" dialog. if (UserConfigParams::logMisc()) { Log::info("OptionsScreenInput2", "Entering sensing mode for %s", m_config->getName().c_str()); } binding_to_set = (PlayerAction)n; new PressAKeyDialog(0.4f, 0.4f); if (m_config->getType() == DEVICE_CONFIG_TYPE_KEYBOARD) { input_manager->setMode(InputManager::INPUT_SENSE_KEYBOARD); } else if (m_config->getType() == DEVICE_CONFIG_TYPE_GAMEPAD) { input_manager->setMode(InputManager::INPUT_SENSE_GAMEPAD); } else { Log::error("OptionsScreenInput2", "Unknown selection device in options: %s", m_config->getName().c_str()); } break; } } } else if (name == "delete") { if (m_config->getType() == DEVICE_CONFIG_TYPE_KEYBOARD) { // keyboard configs may be deleted //I18N: shown before deleting an input configuration new MessageDialog( _("Are you sure you want to permanently delete " "this configuration?"), MessageDialog::MESSAGE_DIALOG_CONFIRM, this, false ); } else { // gamepad configs may be disabled if (m_config->isEnabled()) m_config->setEnabled(false); else m_config->setEnabled(true); // update widget label ButtonWidget* deleteBtn = getWidget<ButtonWidget>("delete"); deleteBtn->setLabel(m_config->isEnabled() ? _("Disable Device") : _("Enable Device") ); input_manager->getDeviceList()->serialize(); } } } // eventCallback
int main(int argc, char **argv){ printf("teste"); StateManager novoJogo; novoJogo.run(); return 0; }