#include "gwutil.h" #include #include #include #include #include #include #include #include #include boost::posix_time::milliseconds gst_DefaultLockTimeout (60000); namespace geoworld { static const char * MARS_TYCOON_RESULTS_DIR_ENV_KEY = "MarsTycoon_ResultsDir"; PNGDEM GLOBALDEM; void rotateGenFiles() { using namespace std; using namespace boost::filesystem; const string sResultsDir (std::getenv(MARS_TYCOON_RESULTS_DIR_ENV_KEY)); stringstream ssSpec; int h, r; vector files; ssSpec << sResultsDir << "\\gen.*.png" << std::ends; for (const directory_entry & entry : directory_iterator(ssSpec.str())) { if (entry.status().type() == regular_file) files.push_back(entry.path().stem().string()); } sort(files.begin(), files.end()); regex rx ("gen\\.([0-9]+)\\.png"); for (vector::reverse_iterator i = files.rbegin(); i != files.rend(); ++i) { cmatch m; regex_search(i->c_str(), m, rx); stringstream ssNewName, ssOldName; ssOldName << sResultsDir << "\\" << *i << std::ends; ssNewName << sResultsDir << "\\gen." << std::setw(3) << std::setfill('0') << (atoi(m[1].str().c_str()) + 1) << ".png" << std::ends; rename(ssOldName.str(), ssNewName.str()); } stringstream ssDefault; stringstream ssNewName; ssDefault << sResultsDir << "\\gen.png" << std::ends; ssNewName << sResultsDir << "\\gen.001.png" << std::ends; rename (ssDefault.str(), ssNewName.str()); } void dumpPNGDEM( PNGDEM & pngdem ) { rotateGenFiles(); writePNGDEM(pngdem, "gen.png"); } void loadPNGDEM( PNGDEM & pngdem, const std::string & sName ) { using namespace std; stringstream ssPath; ssPath << std::getenv(MARS_TYCOON_RESULTS_DIR_ENV_KEY) << "\\" << sName << std::ends; std::ifstream ifs (ssPath.str(), ios::binary | ios::in); pngdem << ifs; ifs.close(); } void writePNGDEM( PNGDEM & pngdem, const std::string & sName ) { using namespace std; const string sResultsDir = std::getenv(MARS_TYCOON_RESULTS_DIR_ENV_KEY); stringstream ssPath; ssPath << sResultsDir << '\\' << sName << std::ends; std::ofstream ofs (ssPath.str(), ios::out | ios::binary | ios::ate); pngdem >> ofs; ofs.close(); } }