From b8075eaf01e224a6f749ea5afa7869f03d9dd409 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 31 Jan 2011 21:59:28 +0000 Subject: [PATCH] - added code to rename duplicate maps and show a warning at game start --- source/glest_game/main/intro.cpp | 12 +++++++++++ source/glest_game/main/intro.h | 4 ++++ source/glest_game/main/main.cpp | 35 +++++++++++++++++++++++++++++--- source/glest_game/main/program.h | 7 ++++++- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/source/glest_game/main/intro.cpp b/source/glest_game/main/intro.cpp index dc27c54f..82c2c1ad 100644 --- a/source/glest_game/main/intro.cpp +++ b/source/glest_game/main/intro.cpp @@ -67,6 +67,9 @@ Intro::Intro(Program *program): int w= metrics.getVirtualW(); int h= metrics.getVirtualH(); timer=0; + mouseX = 0; + mouseY = 0; + mouse2d = 0; texts.push_back(Text(coreData.getLogoTexture(), Vec2i(w/2-128, h/2-64), Vec2i(256, 128), 4000)); texts.push_back(Text(glestVersionString, Vec2i(w/2+45, h/2-45), 4000, coreData.getMenuFontNormal())); @@ -97,6 +100,8 @@ void Intro::update(){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } + + mouse2d= (mouse2d+1) % Renderer::maxMouse2dAnim; } void Intro::render(){ @@ -136,6 +141,8 @@ void Intro::render(){ if(program != NULL) program->renderProgramMsgBox(); + if(this->forceMouseRender == true) renderer.renderMouse2d(mouseX, mouseY, mouse2d, 0.f); + renderer.swapBuffers(); } @@ -160,4 +167,9 @@ void Intro::mouseUpLeft(int x, int y){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void Intro::mouseMove(int x, int y, const MouseState *ms) { + mouseX = x; + mouseY = y; +} + }}//end namespace diff --git a/source/glest_game/main/intro.h b/source/glest_game/main/intro.h index e18165a7..5eb00a0a 100644 --- a/source/glest_game/main/intro.h +++ b/source/glest_game/main/intro.h @@ -71,6 +71,9 @@ private: private: vector texts; int timer; + int mouseX; + int mouseY; + int mouse2d; public: Intro(Program *program); @@ -78,6 +81,7 @@ public: virtual void render(); virtual void keyDown(char key); virtual void mouseUpLeft(int x, int y); + void mouseMove(int x, int y, const MouseState *ms); }; }}//end namespace diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 47265c22..598957b3 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -1314,6 +1314,7 @@ void CheckForDuplicateData() { throw runtime_error("No maps were found!"); } + vector duplicateMapsToRename; for(int i = 0; i < maps.size(); ++i) { string map1 = maps[i]; for(int j = 0; j < maps.size(); ++j) { @@ -1323,13 +1324,41 @@ void CheckForDuplicateData() { //printf("i = %d map1 [%s] j = %d map2 [%s]\n",i,map1.c_str(),j,map2.c_str()); if(map1 == map2) { - char szBuf[4096]=""; - sprintf(szBuf,"You have duplicate maps for map [%s] in [%s] and [%s]",map1.c_str(),mapPaths[0].c_str(),mapPaths[1].c_str()); - throw runtime_error(szBuf); + if(std::find(duplicateMapsToRename.begin(),duplicateMapsToRename.end(),map1) == duplicateMapsToRename.end()) { + duplicateMapsToRename.push_back(map1); + } } } } } + if(duplicateMapsToRename.size() > 0) { + string errorMsg = "Warning duplicate maps were detected and renamed:\n"; + for(int i = 0; i < duplicateMapsToRename.size(); ++i) { + string oldFile = mapPaths[1] + "/" + duplicateMapsToRename[i]; + string newFile = mapPaths[1] + "/" + duplicateMapsToRename[i]; + string ext = extractExtension(newFile); + newFile = newFile.substr( 0, newFile.length()-ext.length()-1); + newFile = newFile + "_custom." + ext; + + char szBuf[4096]=""; + int result = rename(oldFile.c_str(),newFile.c_str()); + if(result != 0) { + char *errmsg = strerror(errno); + sprintf(szBuf,"Error [%s]\nCould not rename [%s] to [%s]!",errmsg,oldFile.c_str(),newFile.c_str()); + throw runtime_error(szBuf); + } + else { + sprintf(szBuf,"map [%s] in [%s]\nwas renamed to [%s]",duplicateMapsToRename[i].c_str(),oldFile.c_str(),newFile.c_str()); + } + errorMsg += szBuf; + } + //throw runtime_error(szBuf); + Program *program = Program::getInstance(); + if(program) { + program->getState()->setForceMouseRender(true); + } + ExceptionHandler::DisplayMessage(errorMsg.c_str(), false); + } //tilesets std::vector tileSets; diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index 15f3ba8f..aabb5348 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -49,9 +49,13 @@ protected: int startX; int startY; + bool forceMouseRender; public: - ProgramState(Program *program) {this->program= program;} + ProgramState(Program *program) { + this->program= program; + this->forceMouseRender = false; + } virtual ~ProgramState(){}; virtual void render()=0; @@ -81,6 +85,7 @@ public: virtual bool quitTriggered() { return false; } virtual Stats quitAndToggleState() { return Stats(); }; virtual Program * getProgram() { return program; } + virtual void setForceMouseRender(bool value) { forceMouseRender=value;} }; // ===============================