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(); } }
static FILE *ino_cache(xPVStr(rootpath),int dev,int *ixp) { CStr(icache,1024); CStr(path,1024); CStr(rootpathbuf,1024); CStr(parent,1024); CStr(tmp,1024); FILE *ic; int ix,dev1; if( icachedir == NULL ) return NULL; for( ix = 0; dev1 = ICs[ix].ic_dev; ix++ ){ if( dev1 == dev && ICs[ix].ic_file ){ if( ixp ) *ixp = ix; if( rootpath && *rootpath == 0 ) strcpy(rootpath,ICs[ix].ic_rootpath); return ICs[ix].ic_file; } } sprintf(icache,"%s/dev-%08x",icachedir,dev); if( !fileIsdir(icache) ){ if( mkdir(icache,0755) != 0 ){ errlog("can't make inode cache directory: %s\n", icache); exit(1); } } sprintf(path,"%s/rootpath",icache); if( rootpath && *rootpath ){ ic = fopen_rw(path); if( ic == NULL ){ errlog("can't make inode cache file: %s\n",path); return NULL; } rootpath = filesys(rootpath,AVStr(rootpathbuf),AVStr(parent)); fputs(rootpath,ic); fclose(ic); if( inocnt == 0 ){ inocnt++; put_force = 1; put_icacheR(parent); put_force = 0; inocnt--; } }else{ ic = fopen(path,"r"); if( ic == NULL ){ errlog("can't open inode cache file: %s\n",path); return NULL; } if( rootpath == NULL ) setPStr(rootpath,rootpathbuf,sizeof(rootpathbuf)); fgets(tmp,sizeof(tmp),ic); Xsscanf(tmp,"%s",AVStr(rootpath)); fclose(ic); } sprintf(path,"%s/ino",icache); ic = fopen_rw(path); if( ic == NULL ){ errlog("can't make inode cache file: %s\n",path); exit(1); } ICs[ix].ic_dev = dev; ICs[ix].ic_file = ic; ICs[ix].ic_rootpath = stralloc(rootpath); if( ixp ) *ixp = ix; return ic; }