void SDLAppInit() { if(gSDLAppResourceDir.size()>0) return; std::string conf_dir = ""; std::string resource_dir = "data/"; std::string fonts_dir = "data/fonts/"; #ifdef _WIN32 char szAppPath[MAX_PATH]; GetModuleFileName(0, szAppPath, MAX_PATH); // Extract directory std::string exepath = std::string(szAppPath); int pos = exepath.rfind("\\"); std::string path = exepath.substr(0, pos+1); conf_dir = path + std::string("\\"); resource_dir = path + std::string("\\data\\"); fonts_dir = path + std::string("\\data\\fonts\\"); #else //get working directory char cwd_buff[1024]; if(getcwd(cwd_buff, 1024) == cwd_buff) { conf_dir = std::string(cwd_buff) + std::string("/"); resource_dir = std::string(cwd_buff) + std::string("/") + resource_dir; fonts_dir = std::string(cwd_buff) + std::string("/") + fonts_dir; } #endif #ifdef SDLAPP_CONF_DIR if (SDLAppDirExists(SDLAPP_CONF_DIR)) { conf_dir = SDLAPP_CONF_DIR; } #endif #ifdef SDLAPP_RESOURCE_DIR if (SDLAppDirExists(SDLAPP_RESOURCE_DIR)) { resource_dir = SDLAPP_RESOURCE_DIR; fonts_dir = SDLAPP_RESOURCE_DIR + std::string("/fonts/"); } #endif #ifdef SDLAPP_FONT_DIR if (SDLAppDirExists(SDLAPP_FONT_DIR)) { fonts_dir = SDLAPP_FONT_DIR; } #endif resource_dir = SDLAppAddSlash(resource_dir); conf_dir = SDLAppAddSlash(conf_dir); fonts_dir = SDLAppAddSlash(fonts_dir); texturemanager.setDir(resource_dir); fontmanager.setDir(fonts_dir); gSDLAppResourceDir = resource_dir; gSDLAppConfDir = conf_dir; }
void RLogMill::run() { logmill_thread_state = LOGMILL_STATE_FETCHING; #if defined(HAVE_PTHREAD) && !defined(_WIN32) sigset_t mask; sigemptyset(&mask); // unblock SIGINT so user can cancel // NOTE: assumes SDL is using pthreads sigaddset(&mask, SIGINT); pthread_sigmask(SIG_UNBLOCK, &mask, 0); #endif std::string log_format = gGourceSettings.log_format; try { clog = fetchLog(log_format); } catch(SeekLogException& exception) { error = "unable to read log file"; } catch(SDLAppException& exception) { error = exception.what(); } if(!clog && error.empty()) { if(SDLAppDirExists(logfile)) { if(!log_format.empty()) { error = "failed to generate log file"; #ifdef _WIN32 // no error - should trigger help message } else if(gGourceSettings.default_path && boost::filesystem::exists("./gource.exe")) { error = ""; #endif } else { error = "directory not supported"; } } else { error = "unsupported log format (you may need to regenerate your log file)"; } } logmill_thread_state = clog ? LOGMILL_STATE_SUCCESS : LOGMILL_STATE_FAILURE; }
void Gource::logic(float t, float dt) { if(draw_loading) return; if(splash>0.0) splash -= dt; //init log file if(commitlog == 0) { commitlog = determineFormat(logfile); if(commitlog == 0) { //if not in a git dir and no log file, show help if(logfile.size() == 0 || logfile == ".") { SDL_Quit(); gource_help(""); } else if(SDLAppDirExists(logfile)) { gource_quit("Directory not supported."); } else { gource_quit("Unsupported log format. You may need to regenerate your log file."); } } if(start_position>0.0) { seekTo(start_position); } } slider.logic(dt); //still want to update camera while paused if(paused) { updateCamera(dt); return; } // get more entries if(commitqueue.size() == 0) { readLog(); } //loop in attempt to find commits if(commitqueue.size()==0 && commitlog->isSeekable() && gGourceFileLoop) { first_read=true; seekTo(0.0); readLog(); } if(currtime==0 && commitqueue.size()) { currtime = commitqueue[0].timestamp; subseconds = 0.0; } //set current time float time_inc = (dt * 86400.0 * gGourceDaysPerSecond); int seconds = (int) time_inc; subseconds += time_inc - ((float) seconds); if(subseconds >= 1.0) { currtime += (int) subseconds; subseconds -= (int) subseconds; } currtime += seconds; // delete files for(std::vector<RFile*>::iterator it = gGourceRemovedFiles.begin(); it != gGourceRemovedFiles.end(); it++) { deleteFile(*it); } gGourceRemovedFiles.clear(); //add commits up until the current time while(commitqueue.size() > 0) { RCommit commit = commitqueue[0]; if(gGourceAutoSkipSeconds>=0.0 && idle_time >= gGourceAutoSkipSeconds) { currtime = commit.timestamp; idle_time = 0.0; } if(commit.timestamp > currtime) break; processCommit(commit, t); currtime = commit.timestamp; subseconds = 0.0; commitqueue.pop_front(); } //reset loop counters gGourceUserInnerLoops = 0; gGourceDirNodeInnerLoops = 0; gGourceFileInnerLoops = 0; interactUsers(); interactDirs(); updateUsers(t, dt); updateDirs(dt); updateCamera(dt); updateTime(); }
void Gource::logic(float t, float dt) { if(draw_loading) return; if(message_timer>0.0f) message_timer -= dt; if(splash>0.0f) splash -= dt; //init log file if(commitlog == 0) { try { commitlog = determineFormat(logfile); } catch(SeekLogException& exception) { throw SDLAppException("unable to read log file"); } if(commitlog == 0) { //if not in a git dir and no log file, show help if(logfile.size() == 0 || logfile == ".") { SDL_Quit(); SDLAppException exception(""); exception.setShowHelp(true); throw exception; } else if(SDLAppDirExists(logfile)) { throw SDLAppException("directory not supported"); } else { throw SDLAppException("unsupported log format (you may need to regenerate your log file)"); } } if(gGourceSettings.start_position>0.0) { seekTo(gGourceSettings.start_position); } } slider.logic(dt); //apply rotation if(rotate_angle != 0.0f) { float s = sinf(rotate_angle); float c = cosf(rotate_angle); root->rotate(s, c); for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) { RUser* user = it->second; vec2f userpos = user->getPos(); user->setPos(userpos.rotate(s, c)); } rotate_angle = 0.0f; } //still want to update camera while paused if(paused) { updateBounds(); updateQuadTree(); updateCamera(dt); return; } // get more entries if(commitqueue.size() == 0) { readLog(); } //loop in attempt to find commits if(commitqueue.size()==0 && commitlog->isSeekable() && gGourceSettings.loop) { first_read=true; seekTo(0.0); readLog(); } if(currtime==0 && commitqueue.size()) { currtime = lasttime = commitqueue[0].timestamp; subseconds = 0.0; } //set current time float time_inc = (dt * 86400.0 * gGourceSettings.days_per_second); int seconds = (int) time_inc; subseconds += time_inc - ((float) seconds); if(subseconds >= 1.0) { currtime += (int) subseconds; subseconds -= (int) subseconds; } currtime += seconds; // delete files for(std::vector<RFile*>::iterator it = gGourceRemovedFiles.begin(); it != gGourceRemovedFiles.end(); it++) { deleteFile(*it); } gGourceRemovedFiles.clear(); //add commits up until the current time while(commitqueue.size() > 0) { RCommit commit = commitqueue[0]; //auto skip ahead, unless stop_position_reached if(gGourceSettings.auto_skip_seconds>=0.0 && idle_time >= gGourceSettings.auto_skip_seconds && !stop_position_reached) { currtime = lasttime = commit.timestamp; idle_time = 0.0; } if(commit.timestamp > currtime) break; processCommit(commit, t); currtime = lasttime = commit.timestamp; subseconds = 0.0; commitqueue.pop_front(); } //reset loop counters gGourceUserInnerLoops = 0; gGourceDirNodeInnerLoops = 0; gGourceFileInnerLoops = 0; interactUsers(); updateUsers(t, dt); updateQuadTree(); updateBounds(); updateDirs(dt); updateCamera(dt); updateTime(commitqueue.size() > 0 ? currtime : lasttime); }