//--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { PBMP bContext = new BMP(); bContext->Width = ClientWidth; bContext->Height = ClientHeight; context = new FastBitmap(bContext); rm = new RenderManager(); rm->setContext(context,Canvas,ClientWidth, ClientHeight, clWhite); DoubleBuffered=true; gm = new GameManager(); gm->setRenderManager(rm); SpriteFabric *sf = SpriteFabric::getInstance(); sc = 0; map = 0; SoundManager * sm = SoundManager::getInstance(); sm->init(Button1); UserStats::getInstance()->loadFromFile("config/autoexec.txt"); }
int main(int argc, char* argv[]) { PHYSFS_init(argv[0]); setupPHYSFS(); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); SDL_EnableUNICODE(1); atexit(SDL_Quit); srand(SDL_GetTicks()); // Default is OpenGL and false // choose renderer RenderManager *rmanager = 0; SoundManager *smanager = 0; try { UserConfig gameConfig; gameConfig.loadFile("config.xml"); TextManager::createTextManager(gameConfig.getString("language")); if(gameConfig.getString("device") == "SDL") rmanager = RenderManager::createRenderManagerSDL(); else if (gameConfig.getString("device") == "GP2X") rmanager = RenderManager::createRenderManagerGP2X(); else if (gameConfig.getString("device") == "OpenGL") rmanager = RenderManager::createRenderManagerGL2D(); else { std::cerr << "Warning: Unknown renderer selected!"; std::cerr << "Falling back to OpenGL" << std::endl; rmanager = RenderManager::createRenderManagerGL2D(); } // fullscreen? if(gameConfig.getString("fullscreen") == "true") rmanager->init(800, 600, true); else rmanager->init(800, 600, false); if(gameConfig.getString("show_shadow") == "true") rmanager->showShadow(true); else rmanager->showShadow(false); SpeedController scontroller(gameConfig.getFloat("gamefps")); SpeedController::setMainInstance(&scontroller); scontroller.setDrawFPS(gameConfig.getBool("showfps")); smanager = SoundManager::createSoundManager(); smanager->init(); smanager->setVolume(gameConfig.getFloat("global_volume")); smanager->setMute(gameConfig.getBool("mute")); smanager->playSound("sounds/bums.wav", 0.0); smanager->playSound("sounds/pfiff.wav", 0.0); std::string bg = std::string("backgrounds/") + gameConfig.getString("background"); if (PHYSFS_exists(bg.c_str())) rmanager->setBackground(bg); InputManager* inputmgr = InputManager::createInputManager(); if (argc == 3) { if (strstr(argv[1], ".lua")) { gameConfig.setString("left_player_human", "false"); gameConfig.setString("left_script_name", argv[1]); } else { gameConfig.setString("left_player_human", "true"); gameConfig.setString("left_player_name", argv[1]); } if (strstr(argv[2], ".lua")) { gameConfig.setString("right_player_human", "false"); gameConfig.setString("right_script_name", argv[2]); } else { gameConfig.setString("right_player_human", "true"); gameConfig.setString("right_player_name", argv[2]); } gameConfig.saveFile("config.xml"); State::setCurrentState(new LocalGameState(), true); } int running = 1; while (running) { inputmgr->updateInput(); running = inputmgr->running(); // This is true by default for compatibility, GUI states may // disable it if necessary rmanager->drawGame(true); IMGUI::getSingleton().begin(); State::getCurrentState()->step(); rmanager = &RenderManager::getSingleton(); //RenderManager may change //draw FPS: if (scontroller.getDrawFPS()) { // We need to ensure that the title bar is only set // when the framerate changed, because setting the // title can ne quite resource intensive on some // windows manager, like for example metacity. static int lastfps = 0; int newfps = scontroller.getFPS(); if (newfps != lastfps) { std::stringstream tmp; tmp << AppTitle << " FPS: " << newfps; rmanager->setTitle(tmp.str()); } lastfps = newfps; } if (!scontroller.doFramedrop()) { rmanager->draw(); IMGUI::getSingleton().end(); BloodManager::getSingleton().step(); rmanager->refresh(); } scontroller.update(); } } catch (std::exception& e) { std::cerr << e.what() << std::endl; if (rmanager) rmanager->deinit(); if (smanager) smanager->deinit(); SDL_Quit(); PHYSFS_deinit(); exit (EXIT_FAILURE); } deinit(); exit(EXIT_SUCCESS); }
int main(int argc, char* argv[]) #endif { DEBUG_STATUS("started main"); FileSystem filesys(argv[0]); setupPHYSFS(); DEBUG_STATUS("physfs initialised"); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); DEBUG_STATUS("SDL initialised"); atexit(SDL_Quit); srand(SDL_GetTicks()); // Default is OpenGL and false // choose renderer RenderManager *rmanager = 0; SoundManager *smanager = 0; // Test Version Startup Warning #ifdef TEST_VERSION struct tm* ptm; time_t time = std::time(0); ptm = gmtime ( &time ); if( ptm->tm_year > (2014-1900) || ptm->tm_mon >= 4 ) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "TEST VERISON OUTDATED", (std::string("This is a test version of ") + AppTitle + " which expired on " "1.04.2014. Please visit blobby.sourceforge.net for a newer version").c_str(), 0); return -1; } SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "TEST VERISON WARNING", (std::string("This is a test version of ") + AppTitle + " for testing only.\n" "It might be unstable and/or incompatible to the current release. " "Use of this version is limited to 1.04.2014.\nUntil then, " "the final version will most likely be released and you should update to that one.\n" "Visit blobby.sourceforge.net for more information or bug reporting.").c_str(), 0); #endif try { UserConfig gameConfig; gameConfig.loadFile("config.xml"); TextManager::createTextManager(gameConfig.getString("language")); if(gameConfig.getString("device") == "SDL") rmanager = RenderManager::createRenderManagerSDL(); /*else if (gameConfig.getString("device") == "GP2X") rmanager = RenderManager::createRenderManagerGP2X();*/ #ifndef __ANDROID__ #ifndef __APPLE__ else if (gameConfig.getString("device") == "OpenGL") rmanager = RenderManager::createRenderManagerGL2D(); else { std::cerr << "Warning: Unknown renderer selected!"; std::cerr << "Falling back to OpenGL" << std::endl; rmanager = RenderManager::createRenderManagerGL2D(); } #else #if MAC_OS_X else if (gameConfig.getString("device") == "OpenGL") rmanager = RenderManager::createRenderManagerGL2D(); else { std::cerr << "Warning: Unknown renderer selected!"; std::cerr << "Falling back to OpenGL" << std::endl; rmanager = RenderManager::createRenderManagerGL2D(); } #endif #endif #endif // fullscreen? if(gameConfig.getString("fullscreen") == "true") rmanager->init(BASE_RESOLUTION_X, BASE_RESOLUTION_Y, true); else rmanager->init(BASE_RESOLUTION_X, BASE_RESOLUTION_Y, false); if(gameConfig.getString("show_shadow") == "true") rmanager->showShadow(true); else rmanager->showShadow(false); SpeedController scontroller(gameConfig.getFloat("gamefps")); SpeedController::setMainInstance(&scontroller); scontroller.setDrawFPS(gameConfig.getBool("showfps")); smanager = SoundManager::createSoundManager(); smanager->init(); smanager->setVolume(gameConfig.getFloat("global_volume")); smanager->setMute(gameConfig.getBool("mute")); /// \todo play sound is misleading. what we actually want to do is load the sound smanager->playSound("sounds/bums.wav", 0.0); smanager->playSound("sounds/pfiff.wav", 0.0); std::string bg = std::string("backgrounds/") + gameConfig.getString("background"); if ( FileSystem::getSingleton().exists(bg) ) rmanager->setBackground(bg); InputManager* inputmgr = InputManager::createInputManager(); int running = 1; DEBUG_STATUS("starting mainloop"); while (running) { inputmgr->updateInput(); running = inputmgr->running(); IMGUI::getSingleton().begin(); State::step(); rmanager = &RenderManager::getSingleton(); //RenderManager may change //draw FPS: static int lastfps = 0; if (scontroller.getDrawFPS()) { // We need to ensure that the title bar is only set // when the framerate changed, because setting the // title can ne quite resource intensive on some // windows manager, like for example metacity. int newfps = scontroller.getFPS(); if (newfps != lastfps) { std::stringstream tmp; tmp << AppTitle << " FPS: " << newfps; rmanager->setTitle(tmp.str()); } lastfps = newfps; } // Dirty workarround for hiding fps in title if (!scontroller.getDrawFPS() && (lastfps != -1)) { std::stringstream tmp; tmp << AppTitle; rmanager->setTitle(tmp.str()); lastfps = -1; } if (!scontroller.doFramedrop()) { rmanager->draw(); IMGUI::getSingleton().end(); BloodManager::getSingleton().step(); rmanager->refresh(); } scontroller.update(); } }