Index: source/gameengine/GamePlayer/ghost/GPG_ghost.cpp =================================================================== --- source/gameengine/GamePlayer/ghost/GPG_ghost.cpp (revision 15606) +++ source/gameengine/GamePlayer/ghost/GPG_ghost.cpp (working copy) @@ -29,8 +29,13 @@ */ #include +#include +#include +#include #include +#define NPOS ((std::size_t) -1) + #ifdef __linux__ #ifdef __alpha__ #include @@ -146,6 +151,43 @@ #endif /* WIN32 */ + +bool FindSetting(const std::string &fileBuffer, const std::string &setting, std::string &value) +{ + // find setting value in string + std::size_t found, found2, offset = 0; + + found = fileBuffer.find(setting, 0); + if(found != NPOS) + { + found2 = fileBuffer.find('\n', found); + if(found2 != NPOS) + { + offset = found+setting.length(); + value = fileBuffer.substr(offset, (found2-offset)); + return true; + } + } + return false; +} + + +bool ReadFile(const std::string &fileName, std::string &fileBuffer) +{ + std::ifstream file(fileName.c_str()); + + if(file.good()) + { + fileBuffer.reserve(file.tellg()); + fileBuffer.assign((std::istreambuf_iterator(file)), std::istreambuf_iterator()); + file.close(); + return true; + } + file.close(); + return false; +} + + void usage(char* program) { char * consoleoption; @@ -665,7 +707,61 @@ strcpy (pathname, maggie->name); // also copy here (used by GameLogic.getBaseDirectory) strcpy (G.sce, maggie->name); + + // load optional display.ini + bool ini = false; + + char basedpath[240]; + char temppath[242]; + strcpy(basedpath, "display.ini"); + BLI_convertstringcode(basedpath, argv[0]); + + strcpy(temppath, "//"); + strcat(temppath, basedpath); + BLI_convertstringcode(temppath, argv[0]); + + std::string fileName(temppath); + std::string fileBuffer; + std::string value; + + if(ReadFile(fileName, fileBuffer)) + { + // display setting + if(FindSetting(fileBuffer, std::string("width = "), value)) + { + fullScreenWidth = windowWidth = atoi(value.c_str()); + } + + value.clear(); + if(FindSetting(fileBuffer, std::string("height = "), value)) + { + fullScreenHeight = windowHeight = atoi(value.c_str()); + } + + value.clear(); + if(FindSetting(fileBuffer, std::string("fullscreen = "), value)) + { + fullScreen = atoi(value.c_str()); + } + + value.clear(); + if(FindSetting(fileBuffer, std::string("bpp = "), value)) + { + fullScreenBpp = atoi(value.c_str()); + } + + value.clear(); + if(FindSetting(fileBuffer, std::string("vertical refresh rate = "), value)) + { + fullScreenFrequency = atoi(value.c_str()); + } + + FindSetting(fileBuffer, std::string("title = "), value); + ini = true; + printf("Using display.ini.\n"); + } + if (fullScreen) { #ifdef WIN32 @@ -702,8 +798,12 @@ vector parts = path.Explode('\\'); #endif // WIN32 STR_String title; - if (parts.size()) + if(ini) { + title = value.c_str(); + } + else if (parts.size()) + { title = parts[parts.size()-1]; parts = title.Explode('.'); if (parts.size() > 1)