diff --git a/.gitignore b/.gitignore index b160915d..7b3db680 100644 --- a/.gitignore +++ b/.gitignore @@ -85,3 +85,6 @@ data/glest_game/lua/ # +/source/windows_deps_2012 +/source/windows_deps_2010 +/source/windows_deps_2010_old diff --git a/mk/linux/mg_cppcheck.sh b/mk/linux/mg_cppcheck.sh index 39eb54bd..d60a14ca 100755 --- a/mk/linux/mg_cppcheck.sh +++ b/mk/linux/mg_cppcheck.sh @@ -9,6 +9,7 @@ OUTFILE=./cppcheck.log CPUS=`lscpu -p | grep -cv '^#'` if [ "$CPUS" = '' ]; then CPUS=1; fi +#~/cppcheck-1.62/cppcheck ../../source/ -i ../../source/win32_deps -i ../../source/configurator -i ../../source/shared_lib/sources/libircclient -i ../../source/shared_lib/sources/platform/miniupnpc -j $CPUS --enable=all --force --verbose 2> $OUTFILE cppcheck ../../source/ -i ../../source/win32_deps -i ../../source/configurator -i ../../source/shared_lib/sources/libircclient -i ../../source/shared_lib/sources/platform/miniupnpc -j $CPUS --enable=all --force --verbose 2> $OUTFILE echo "Results from cppcheck were written to $OUTFILE" diff --git a/mk/windoze/build-mg-2010.bat b/mk/windoze/build-mg-2010.bat index ec930069..b0b58103 100644 --- a/mk/windoze/build-mg-2010.bat +++ b/mk/windoze/build-mg-2010.bat @@ -43,39 +43,44 @@ ECHO Setting up Visual Studio 2010 environment vars... REM Ensure ultifds HP doesn't mess the build up SET Platform= if "%DevEnvDir%." == "." goto SETVCVARS -GOTO SVNSECTION +GOTO GITSECTION :SETVCVARS IF EXIST "%VS100COMNTOOLS%..\..\" GOTO VC_Common IF EXIST "\Program Files\Microsoft Visual Studio 10.0\" GOTO VC_32 IF EXIST "\Program Files (x86)\Microsoft Visual Studio 10.0\" GOTO VC_64 -goto SVNSECTION +goto GITSECTION :VC_Common call "%VS100COMNTOOLS%..\..\vc\vcvarsall.bat" -goto SVNSECTION +goto GITSECTION :VC_32 ECHO 32 bit Windows detected... call "\Program Files\Microsoft Visual Studio 10.0\vc\vcvarsall.bat" -goto SVNSECTION +goto GITSECTION :VC_64 ECHO 64 bit Windows detected... call "\Program Files (x86)\Microsoft Visual Studio 10.0\vc\vcvarsall.bat" -goto SVNSECTION +goto GITSECTION -:SVNSECTION -rem Update from SVN to latest rev +:GITSECTION +rem Update from GIT to latest rev ECHO -------------------------------- -Echo Updating Code from SVN to latest Revision... -svn update ..\..\ +Echo Updating Code from GIT to latest Revision... +cd ..\..\ +git pull -set SVNVERSION=. -for /f "delims=" %%a in ('svnversion ..\..\ -n') do @set SVNVERSION=%%a -ECHO Will build using SVN Revision: [%SVNVERSION%] +set GITVERSION_SHA1=. +set GITVERSION_REV=. +set GET_GIT_SHA1="git log -1 --format=%%h" +for /f "delims=" %%a in ('%GET_GIT_SHA1%') do @set GITVERSION_SHA1=%%a +for /f "delims=" %%a in ('git rev-list HEAD --count') do @set GITVERSION_REV=%%a +ECHO Will build using GIT Revision: [%GITVERSION_REV%.%GITVERSION_SHA1%] +cd mk\windoze rem pause ECHO -------------------------------- @@ -88,12 +93,12 @@ ECHO -------------------------------- Echo Building Mega-Glest using Visual Studio 2010... set CL= -del ..\..\source\glest_game\facilities\svnversion.h +del ..\..\source\glest_game\facilities\gitversion.h -if not "%SVNVERSION%" == "." set CL=/DSVNVERSIONHEADER -if not "%SVNVERSION%" == "." echo building with CL [%CL%] -if not "%SVNVERSION%" == "." echo #define SVNVERSION "%SVNVERSION%" > ..\..\source\glest_game\facilities\svnversion.h -if not "%SVNVERSION%" == "." copy /b ..\..\source\glest_game\facilities\game_util.cpp +,, +if not "%GITVERSION_SHA1%" == "." set CL=/DGITVERSIONHEADER +if not "%GITVERSION_SHA1%" == "." echo building with CL [%CL%] +if not "%GITVERSION_SHA1%" == "." echo #define GITVERSION "%GITVERSION_REV%.%GITVERSION_SHA1%" > ..\..\source\glest_game\facilities\gitversion.h +if not "%GITVERSION_SHA1%" == "." copy /b ..\..\source\glest_game\facilities\game_util.cpp +,, set msBuildMaxCPU= SET BuildInParallel=false diff --git a/mk/windoze/build-mg-2012.bat b/mk/windoze/build-mg-2012.bat index 91e2f7a4..415bf612 100644 --- a/mk/windoze/build-mg-2012.bat +++ b/mk/windoze/build-mg-2012.bat @@ -50,7 +50,7 @@ ECHO Setting up Visual Studio 2012 environment vars... REM Ensure ultifds HP doesn't mess the build up SET Platform= if "%DevEnvDir%." == "." goto SETVCVARS -GOTO SVNSECTION +GOTO GITSECTION :SETVCVARS @@ -61,45 +61,50 @@ IF EXIST "\Program Files (x86)\Microsoft Visual Studio 11.0\" GOTO VC_64_12 rem IF EXIST "%VS100COMNTOOLS%..\..\" GOTO VC_Common rem IF EXIST "\Program Files\Microsoft Visual Studio 10.0\" GOTO VC_32 rem IF EXIST "\Program Files (x86)\Microsoft Visual Studio 10.0\" GOTO VC_64 -goto SVNSECTION +goto GITSECTION :VC_Common_12 call "%VS110COMNTOOLS%..\..\vc\vcvarsall.bat" %VCVARS_PLATFORM% -goto SVNSECTION +goto GITSECTION :VC_32_12 ECHO 32 bit Windows detected... call "\Program Files\Microsoft Visual Studio 11.0\vc\vcvarsall.bat" %VCVARS_PLATFORM% -goto SVNSECTION +goto GITSECTION :VC_64_12 ECHO 64 bit Windows detected... call "\Program Files (x86)\Microsoft Visual Studio 11.0\vc\vcvarsall.bat" %VCVARS_PLATFORM% -goto SVNSECTION +goto GITSECTION :VC_Common rem call "%VS100COMNTOOLS%..\..\vc\vcvarsall.bat" -goto SVNSECTION +goto GITSECTION :VC_32 ECHO 32 bit Windows detected... rem call "\Program Files\Microsoft Visual Studio 10.0\vc\vcvarsall.bat" -goto SVNSECTION +goto GITSECTION :VC_64 ECHO 64 bit Windows detected... rem call "\Program Files (x86)\Microsoft Visual Studio 10.0\vc\vcvarsall.bat" -goto SVNSECTION +goto GITSECTION -:SVNSECTION -rem Update from SVN to latest rev +:GITSECTION +rem Update from GIT to latest rev ECHO -------------------------------- -Echo Updating Code from SVN to latest Revision... -svn update ..\..\ +Echo Updating Code from GIT to latest Revision... +cd ..\..\ +git pull -set SVNVERSION=. -for /f "delims=" %%a in ('svnversion ..\..\ -n') do @set SVNVERSION=%%a -ECHO Will build using SVN Revision: [%SVNVERSION%] +set GITVERSION_SHA1=. +set GITVERSION_REV=. +set GET_GIT_SHA1="git log -1 --format=%%h" +for /f "delims=" %%a in ('%GET_GIT_SHA1%') do @set GITVERSION_SHA1=%%a +for /f "delims=" %%a in ('git rev-list HEAD --count') do @set GITVERSION_REV=%%a +ECHO Will build using GIT Revision: [%GITVERSION_REV%.%GITVERSION_SHA1%] +cd mk\windoze rem pause ECHO -------------------------------- @@ -127,12 +132,12 @@ rem set CL=/D_USING_V110_SDK71_ %CL% rem set PlatformToolset=v110_xp rem set PlatformToolset=V110 -del ..\..\source\glest_game\facilities\svnversion.h +del ..\..\source\glest_game\facilities\gitversion.h -if not "%SVNVERSION%" == "." set CL=/DSVNVERSIONHEADER -if not "%SVNVERSION%" == "." echo building with CL [%CL%] -if not "%SVNVERSION%" == "." echo #define SVNVERSION "%SVNVERSION%" > ..\..\source\glest_game\facilities\svnversion.h -if not "%SVNVERSION%" == "." copy /b ..\..\source\glest_game\facilities\game_util.cpp +,, +if not "%GITVERSION_SHA1%" == "." set CL=/DGITVERSIONHEADER +if not "%GITVERSION_SHA1%" == "." echo building with CL [%CL%] +if not "%GITVERSION_SHA1%" == "." echo #define GITVERSION "%GITVERSION_REV%.%GITVERSION_SHA1%" > ..\..\source\glest_game\facilities\gitversion.h +if not "%GITVERSION_SHA1%" == "." copy /b ..\..\source\glest_game\facilities\game_util.cpp +,, rem set VisualStudioVersion=11.0 set msBuildMaxCPU= diff --git a/mk/windoze/vc2012/glest_game.vcxproj b/mk/windoze/vc2012/glest_game.vcxproj index fe44bebf..86fc6dcd 100644 --- a/mk/windoze/vc2012/glest_game.vcxproj +++ b/mk/windoze/vc2012/glest_game.vcxproj @@ -272,7 +272,7 @@ true - dsound.lib;dxguid.lib;glew32s.lib;libogg_static.lib;libvorbis_static.lib;libvorbisfile_static.lib;opengl32.lib;glu32.lib;wsock32.lib;libglest.lib;mmc.lib;lua.lib;xerces-c_static_3.lib;Dbghelp.lib;libpng15.lib;jpeg.lib;zlibstat.lib;sdl.lib;sdlmain.lib;winmm.lib;openal64.lib;iphlpapi.lib;libstreflop.lib;libcurl.lib;ws2_32.lib;libircclient.lib;freetype244MT.lib;ftgl_static.lib;%(AdditionalDependencies) + dsound.lib;dxguid.lib;glew32s.lib;libogg_static.lib;libvorbis_static.lib;libvorbisfile_static.lib;opengl32.lib;glu32.lib;wsock32.lib;libglest.lib;mmc.lib;lua.lib;xerces-c_static_3.lib;Dbghelp.lib;libpng15.lib;jpeg.lib;zlibstat.lib;sdl.lib;sdlmain.lib;winmm.lib;openal64.lib;iphlpapi.lib;libcurl.lib;ws2_32.lib;libircclient.lib;freetype244MT.lib;ftgl_static.lib;%(AdditionalDependencies) ../../../source/windows_deps_2012/lib;../../../build/$(Configuration)/libglest;$(DXSDK_DIR)/lib/x64;../../../source/windows_deps_2012/Microsoft DirectX SDK %28November 2007%29/Lib/x64;%(AdditionalLibraryDirectories) ;%(IgnoreSpecificDefaultLibraries) true diff --git a/mk/windoze/vc2012/megaglest_tests.vcxproj b/mk/windoze/vc2012/megaglest_tests.vcxproj index 509c0683..56f02c9e 100644 --- a/mk/windoze/vc2012/megaglest_tests.vcxproj +++ b/mk/windoze/vc2012/megaglest_tests.vcxproj @@ -194,6 +194,7 @@ + diff --git a/source/glest_game/facilities/game_util.cpp b/source/glest_game/facilities/game_util.cpp index 4e57b57e..dcfbe9c2 100644 --- a/source/glest_game/facilities/game_util.cpp +++ b/source/glest_game/facilities/game_util.cpp @@ -36,7 +36,7 @@ const string glestVersionString = "v3.9.0"; const string GIT_RawRev = string(GITVERSION); const string GIT_Rev = string("Rev: ") + string(GITVERSION); #else -const string GIT_RawRev = "$4790$"; +const string GIT_RawRev = "$4446.1a8673f$"; const string GIT_Rev = "$Rev$"; #endif diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 7200745f..8c1018b2 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -430,6 +430,8 @@ Game::~Game() { world.end(); //must die before selection because of referencers + BaseColorPickEntity::resetUniqueColors(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] aiInterfaces.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,aiInterfaces.size()); delete videoPlayer; @@ -1001,6 +1003,8 @@ void Game::load(int loadTypes) { SoundRenderer &soundRenderer= SoundRenderer::getInstance(); soundRenderer.stopAllSounds(fadeMusicMilliseconds); + BaseColorPickEntity::resetUniqueColors(); + Config &config = Config::getInstance(); Logger &logger= Logger::getInstance(); @@ -2608,6 +2612,8 @@ void Game::update() { aiInterfaces.clear(); gui.end(); //selection must be cleared before deleting units world.end(); //must die before selection because of referencers + + BaseColorPickEntity::resetUniqueColors(); // MUST DO THIS LAST!!!! Because objects above have pointers to things like // unit particles and fade them out etc and this end method deletes the original // object pointers. @@ -2632,6 +2638,7 @@ void Game::update() { soundRenderer.stopAllSounds(fadeMusicMilliseconds); world.endScenario(); + BaseColorPickEntity::resetUniqueColors(); Renderer &renderer= Renderer::getInstance(); renderer.endScenario(); @@ -5268,7 +5275,12 @@ string Game::getDebugStats(std::map &factionDebugInfo) { str+= "ExploredCellsLookupItemCache: " + world.getExploredCellsLookupItemCacheStats()+"\n"; str+= "FowAlphaCellsLookupItemCache: " + world.getFowAlphaCellsLookupItemCacheStats()+"\n"; - str += "Selection type: "+toLower(Config::getInstance().getString("SelectionType",Config::colorPicking))+"\n"; + const string selectionType = toLower(Config::getInstance().getString("SelectionType",Config::colorPicking)); + str += "Selection type: " + toLower(selectionType) + "\n"; + + if(selectionType == Config::colorPicking) { + str += "Color picking used color list size: " + intToStr(BaseColorPickEntity::getUsedColorIDListSize()) +"\n"; + } //str+= "AllFactionsCacheStats: " + world.getAllFactionsCacheStats()+"\n"; //str+= "AttackWarningCount: " + intToStr(world.getUnitUpdater()->getAttackWarningCount()) + "\n"; @@ -5588,7 +5600,10 @@ void Game::render2d() { // ==================== misc ==================== void Game::checkWinner() { - if(gameOver == false) { + // lookup int is team #, value is players alive on team + std::map teamsAlive = getTeamsAlive(); + + if(gameOver == false || teamsAlive.size() > 1) { if(gameSettings.getDefaultVictoryConditions()) { checkWinnerStandard(); } @@ -5663,55 +5678,62 @@ void Game::setEndGameTeamWinnersAndLosers() { } } -void Game::checkWinnerStandard() { - if(world.getFactionCount() <= 0) { - return; +std::map Game::getTeamsAlive() { + std::map teamsAlive; + for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) { + if (factionIndex != world.getThisFactionIndex()) { + //if(hasBuilding(world.getFaction(i))) { + if (factionLostGame(world.getFaction(factionIndex)) == false) { + teamsAlive[world.getFaction(factionIndex)->getTeam()] = + teamsAlive[world.getFaction(factionIndex)->getTeam()] + 1; + } + } } - if(this->masterserverMode == true || world.getThisFaction()->getPersonalityType() == fpt_Observer) { - // lookup int is team #, value is players alive on team - std::map teamsAlive; - for(int i = 0; i < world.getFactionCount(); ++i) { - if(i != world.getThisFactionIndex()) { - //if(hasBuilding(world.getFaction(i))) { - if(factionLostGame(world.getFaction(i)) == false) { - teamsAlive[world.getFaction(i)->getTeam()] = teamsAlive[world.getFaction(i)->getTeam()] + 1; + // did some team win + return teamsAlive; +} + +void Game::checkWinnerStandardHeadlessOrObserver() { + // lookup int is team #, value is players alive on team + std::map teamsAlive = getTeamsAlive(); + + // did some team win + if (teamsAlive.size() <= 1) { + if (this->masterserverMode == true) { + printf("Game finished...\n"); + } + for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) { + Faction* faction = world.getFaction(factionIndex); + if (factionIndex != world.getThisFactionIndex() && + teamsAlive.find(faction->getTeam()) != teamsAlive.end()) { + world.getStats()->setVictorious(factionIndex); + if (this->masterserverMode == true) { + printf("Player: %s is on the winning team #: %d\n", + this->gameSettings.getNetworkPlayerName(factionIndex).c_str(), + faction->getTeam()); } } } + bool wasGameOverAlready = gameOver; + gameOver = true; - // did some team win - if(teamsAlive.size() <= 1) { - if(this->masterserverMode == true) { - printf("Game finished...\n"); - } - for(int i=0; i< world.getFactionCount(); ++i) { - Faction *faction = world.getFaction(i); - - if(i != world.getThisFactionIndex() && teamsAlive.find(faction->getTeam()) != teamsAlive.end()) { - world.getStats()->setVictorious(i); - if(this->masterserverMode == true) { - printf("Player: %s is on the winning team #: %d\n",this->gameSettings.getNetworkPlayerName(i).c_str(),faction->getTeam()); - } - } - } - gameOver= true; - if( this->gameSettings.isNetworkGame() == false || - this->gameSettings.getEnableObserverModeAtEndGame() == true) { + // Only need to process this once + if(wasGameOverAlready == false) { + if (this->gameSettings.isNetworkGame() == false || + this->gameSettings.getEnableObserverModeAtEndGame() + == true) { // Let the happy winner view everything left in the world - // This caused too much LAG for network games - if(this->gameSettings.isNetworkGame() == false) { + if (this->gameSettings.isNetworkGame() == false) { Renderer::getInstance().setPhotoMode(true); gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT); } // END } - scriptManager.onGameOver(true); - - if(world.getFactionCount() == 1 && world.getFaction(0)->getPersonalityType() == fpt_Observer) { + if (world.getFactionCount() == 1 && + world.getFaction(0)->getPersonalityType() == fpt_Observer) { //printf("!!!!!!!!!!!!!!!!!!!!"); - //gameCamera.setMoveY(100.0); gameCamera.zoom(-300); //gameCamera.update(); @@ -5721,23 +5743,121 @@ void Game::checkWinnerStandard() { } } } - else { - //lose - bool lose= false; - //if(hasBuilding(world.getThisFaction()) == false) { - if(factionLostGame(world.getThisFaction()) == true) { - lose= true; - for(int i=0; igetPersonalityType() != fpt_Observer) { - if(world.getFaction(i)->isAlly(world.getThisFaction()) == false) { - world.getStats()->setVictorious(i); +} + +void Game::checkWinnerStandardPlayer() { + //lose + bool lose = false; + //if(hasBuilding(world.getThisFaction()) == false) { + if (factionLostGame(world.getThisFaction()) == true) { + lose = true; + for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) { + if (world.getFaction(factionIndex)->getPersonalityType() != fpt_Observer) { + if (world.getFaction(factionIndex)->isAlly(world.getThisFaction()) == false) { + world.getStats()->setVictorious(factionIndex); + } + } + } + bool wasGameOverAlready = gameOver; + gameOver = true; + + // Only need to process losing once + if(wasGameOverAlready == false) { + if (this->gameSettings.isNetworkGame() == false || + this->gameSettings.getEnableObserverModeAtEndGame() + == true) { + // Let the poor user watch everything unfold + // This caused too much LAG for network games + if (this->gameSettings.isNetworkGame() == false) { + Renderer::getInstance().setPhotoMode(true); + gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT); + } + // END + // but don't let him cheat via teamchat + chatManager.setDisableTeamMode(true); + } + scriptManager.onGameOver(!lose); + showLoseMessageBox(); + } + } + //win + if (lose == false) { + bool win = true; + for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) { + if (factionIndex != world.getThisFactionIndex()) { + if (world.getFaction(factionIndex)->getPersonalityType() != fpt_Observer) { + //if(hasBuilding(world.getFaction(i)) && + if (factionLostGame(world.getFaction(factionIndex)) == false && + world.getFaction(factionIndex)->isAlly(world.getThisFaction()) == false) { + win = false; } } } - gameOver= true; + } + //if win + if (win) { + for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) { + if (world.getFaction(factionIndex)->getPersonalityType() != fpt_Observer) { + if (world.getFaction(factionIndex)->isAlly(world.getThisFaction())) { + world.getStats()->setVictorious(factionIndex); + } + } + } + + bool wasGameOverAlready = gameOver; + gameOver = true; + + // Only need to process winning once + if(wasGameOverAlready == false) { + if (this->gameSettings.isNetworkGame() == false || + this->gameSettings.getEnableObserverModeAtEndGame() == true) { + // Let the happy winner view everything left in the world + //world.setFogOfWar(false); + // This caused too much LAG for network games + if (this->gameSettings.isNetworkGame() == false) { + Renderer::getInstance().setPhotoMode(true); + gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT); + } + // END + } + scriptManager.onGameOver(win); + showWinMessageBox(); + } + } + } +} + +void Game::checkWinnerStandard() { + if(world.getFactionCount() <= 0) { + return; + } + if(this->masterserverMode == true || + world.getThisFaction()->getPersonalityType() == fpt_Observer) { + checkWinnerStandardHeadlessOrObserver(); + } + else { + checkWinnerStandardPlayer(); + } +} + +void Game::checkWinnerScripted() { + if(scriptManager.getIsGameOver()) { + bool wasGameOverAlready = gameOver; + gameOver= true; + + + for(int i= 0; igetWinner()) { + world.getStats()->setVictorious(i); + } + } + + // Only need to process winning once + if(wasGameOverAlready == false) { if( this->gameSettings.isNetworkGame() == false || this->gameSettings.getEnableObserverModeAtEndGame() == true) { - // Let the poor user watch everything unfold + // Let the happy winner view everything left in the world + //world.setFogOfWar(false); // This caused too much LAG for network games if(this->gameSettings.isNetworkGame() == false) { @@ -5745,95 +5865,20 @@ void Game::checkWinnerStandard() { gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT); } // END - - // but don't let him cheat via teamchat - chatManager.setDisableTeamMode(true); } - scriptManager.onGameOver(!lose); - - showLoseMessageBox(); - } - - //win - if(lose == false) { - bool win= true; - for(int i = 0; i < world.getFactionCount(); ++i) { - if(i != world.getThisFactionIndex()) { - if(world.getFaction(i)->getPersonalityType() != fpt_Observer) { - //if(hasBuilding(world.getFaction(i)) && - if(factionLostGame(world.getFaction(i)) == false && - world.getFaction(i)->isAlly(world.getThisFaction()) == false) { - win= false; - } - } - } - } - - //if win - if(win) { - for(int i=0; i< world.getFactionCount(); ++i) { - if(world.getFaction(i)->getPersonalityType() != fpt_Observer) { - if(world.getFaction(i)->isAlly(world.getThisFaction())) { - world.getStats()->setVictorious(i); - } - } - } - gameOver= true; - if( this->gameSettings.isNetworkGame() == false || - this->gameSettings.getEnableObserverModeAtEndGame() == true) { - // Let the happy winner view everything left in the world - //world.setFogOfWar(false); - - // This caused too much LAG for network games - if(this->gameSettings.isNetworkGame() == false) { - Renderer::getInstance().setPhotoMode(true); - gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT); - } - // END - } - - scriptManager.onGameOver(win); - + if(this->masterserverMode == true || world.getThisFaction()->getPersonalityType() == fpt_Observer) { showWinMessageBox(); } - } - } -} + else { + scriptManager.onGameOver(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner()); -void Game::checkWinnerScripted() { - if(scriptManager.getIsGameOver()) { - gameOver= true; - for(int i= 0; igetWinner()) { - world.getStats()->setVictorious(i); - } - } - - if( this->gameSettings.isNetworkGame() == false || - this->gameSettings.getEnableObserverModeAtEndGame() == true) { - // Let the happy winner view everything left in the world - //world.setFogOfWar(false); - - // This caused too much LAG for network games - if(this->gameSettings.isNetworkGame() == false) { - Renderer::getInstance().setPhotoMode(true); - gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT); - } - // END - } - - if(this->masterserverMode == true || world.getThisFaction()->getPersonalityType() == fpt_Observer) { - showWinMessageBox(); - } - else { - scriptManager.onGameOver(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner()); - - if(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner()){ - showWinMessageBox(); - } - else{ - showLoseMessageBox(); + if(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner()){ + showWinMessageBox(); + } + else { + showLoseMessageBox(); + } } } } @@ -5845,10 +5890,10 @@ bool Game::factionLostGame(int factionIndex) { bool Game::factionLostGame(const Faction *faction) { if(faction != NULL) { - for(int i=0; igetUnitCount(); ++i) { - const UnitType *ut = faction->getUnit(i)->getType(); + for(int factionIndex=0; factionIndexgetUnitCount(); ++factionIndex) { + const UnitType *ut = faction->getUnit(factionIndex)->getType(); if(ut->getCountInVictoryConditions() == ucvcNotSet) { - if(faction->getUnit(i)->getType()->hasSkillClass(scBeBuilt)) { + if(faction->getUnit(factionIndex)->getType()->hasSkillClass(scBeBuilt)) { return false; } } diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index dc669596..d9903531 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -395,6 +395,9 @@ private: int startIndex, int endIndex, bool onlyNetworkUnassigned); void processNetworkSynchChecksIfRequired(); Stats getEndGameStats(); + void checkWinnerStandardHeadlessOrObserver(); + void checkWinnerStandardPlayer(); + std::map getTeamsAlive(); }; }}//end namespace diff --git a/source/shared_lib/include/graphics/model.h b/source/shared_lib/include/graphics/model.h index 2e89cd49..909a492c 100644 --- a/source/shared_lib/include/graphics/model.h +++ b/source/shared_lib/include/graphics/model.h @@ -261,8 +261,11 @@ class BaseColorPickEntity { public: BaseColorPickEntity(); - virtual ~BaseColorPickEntity() {} + virtual ~BaseColorPickEntity() { + recycleUniqueColor(); + } + //static const int COLOR_COMPONENTS = 3; static const int COLOR_COMPONENTS = 4; static void init(int bufferSize); static void beginPicking(); @@ -275,16 +278,40 @@ public: string getColorDescription() const; virtual string getUniquePickName() const = 0; -private: - unsigned char uniqueColorID[COLOR_COMPONENTS]; + static void resetUniqueColors(); - static unsigned nextColorID; - static const unsigned k, p; - static Mutex mutexNextColorID; + static void setUsingLoopMethod(bool value) { using_loop_method = value; } + + static void setTrackColorUse(bool value) { trackColorUse = value; } + unsigned char * getUniqueColorID() { return &uniqueColorID[0]; } + bool get_next_assign_color(unsigned char *assign_to); + + static int getUsedColorIDListSize() { return (int)usedColorIDList.size(); } + +private: + + unsigned char uniqueColorID[COLOR_COMPONENTS]; + + static unsigned char nextColorID[COLOR_COMPONENTS]; + static unsigned int nextColorRGB; + static const unsigned int k, p; + //static Mutex mutexNextColorID; + + static bool using_loop_method; + + static bool trackColorUse; + static map usedColorIDList; + + static vector > nextColorIDReuseList; static auto_ptr pbo; void assign_color(); + + void assign_color_using_prime(unsigned char *assign_to); + void assign_color_using_loop(unsigned char *assign_to); + + void recycleUniqueColor(); }; }}//end namespace diff --git a/source/shared_lib/sources/graphics/model.cpp b/source/shared_lib/sources/graphics/model.cpp index 6b3ff0b0..1087bb07 100644 --- a/source/shared_lib/sources/graphics/model.cpp +++ b/source/shared_lib/sources/graphics/model.cpp @@ -1826,35 +1826,183 @@ PixelBufferWrapper::~PixelBufferWrapper() { cleanup(); } -const unsigned BaseColorPickEntity::p = 64007; -const unsigned BaseColorPickEntity::k = 43067; -unsigned BaseColorPickEntity::nextColorID = BaseColorPickEntity::k; -Mutex BaseColorPickEntity::mutexNextColorID; +// --------------------------------------------------------------------------- + +const unsigned int BaseColorPickEntity::p = 64007; +const unsigned int BaseColorPickEntity::k = 43067; +unsigned int BaseColorPickEntity::nextColorRGB = BaseColorPickEntity::k; + +//Mutex BaseColorPickEntity::mutexNextColorID; +unsigned char BaseColorPickEntity::nextColorID[COLOR_COMPONENTS] = { 1, 1, 1, 0 }; auto_ptr BaseColorPickEntity::pbo; +map BaseColorPickEntity::usedColorIDList; +bool BaseColorPickEntity::trackColorUse = true; + +vector > BaseColorPickEntity::nextColorIDReuseList; + +bool BaseColorPickEntity::using_loop_method = false; + BaseColorPickEntity::BaseColorPickEntity() { - assign_color(); + uniqueColorID[0] = 0; + uniqueColorID[1] = 0; + uniqueColorID[2] = 0; + uniqueColorID[3] = 0; + assign_color(); +} + +bool BaseColorPickEntity::get_next_assign_color(unsigned char *assign_to) { + //MutexSafeWrapper safeMutex(&mutexNextColorID); + + if(assign_to == NULL) { + throw megaglest_runtime_error("assign_to == NULL"); + } + + if(BaseColorPickEntity::using_loop_method == true) { + assign_color_using_loop(assign_to); + } + else { + assign_color_using_prime(assign_to); + } + + bool isDuplicate = false; + if(BaseColorPickEntity::trackColorUse == true) { + string color_key = getColorDescription(); + //printf("Assigned color [%s]\n",color_key.c_str()); + + if(usedColorIDList.find(color_key) == usedColorIDList.end()) { + usedColorIDList[color_key] = true; + + //printf("Color added to used list [%s] usedColorIDList = %d nextColorIDReuseList = %d!\n",color_key.c_str(),(int)usedColorIDList.size(),(int)nextColorIDReuseList.size()); + } + else { + isDuplicate = true; + printf("Line ref: %d *WARNING* color [%s] used count: %d using_loop: %d ALREADY in history list!\n",__LINE__,color_key.c_str(),(int)usedColorIDList.size(),BaseColorPickEntity::using_loop_method); + } + } + return isDuplicate; } void BaseColorPickEntity::assign_color() { - - MutexSafeWrapper safeMutex(&mutexNextColorID); - - nextColorID = (nextColorID * k) % p; + get_next_assign_color(&uniqueColorID[0]); +} + +void BaseColorPickEntity::assign_color_using_prime(unsigned char *assign_to) { + nextColorRGB = (nextColorRGB * k) % p; // nextColorID is a 16-bit (hi)colour (for players with 16-bit display depths) // we expand it to true-color for use with OpenGL - const unsigned - r = (nextColorID >> 11) & ((1<<5)-1), - g = (nextColorID >> 5) & ((1<<6)-1), - b = nextColorID & ((1<<5)-1); - - uniqueColorID[0] = r << 3; - uniqueColorID[1] = g << 2; - uniqueColorID[2] = b << 3; + const unsigned int + r = (nextColorRGB >> 11) & ((1<<5)-1), + g = (nextColorRGB >> 5) & ((1<<6)-1), + b = nextColorRGB & ((1<<5)-1); + + assign_to[0] = r << 3; + assign_to[1] = g << 2; + assign_to[2] = b << 3; } +void BaseColorPickEntity::assign_color_using_loop(unsigned char *assign_to) { + if(nextColorIDReuseList.empty() == false) { + //printf("Color being reused [%u.%u.%u] usedColorIDList = %d nextColorIDReuseList = %d!\n",nextColorIDReuseList.back()[0],nextColorIDReuseList.back()[1],nextColorIDReuseList.back()[2],(int)usedColorIDList.size(),(int)nextColorIDReuseList.size()); + + assign_to[0] = nextColorIDReuseList.back()[0]; + assign_to[1] = nextColorIDReuseList.back()[1]; + assign_to[2] = nextColorIDReuseList.back()[2]; + + nextColorIDReuseList.pop_back(); + + string color_key = getColorDescription(); + if(usedColorIDList.find(color_key) == usedColorIDList.end()) { + //usedColorIDList[color_key] = true; + //printf("Color added to used list [%s] usedColorIDList = %d nextColorIDReuseList = %d!\n",color_key.c_str(),(int)usedColorIDList.size(),(int)nextColorIDReuseList.size()); + } + else { + printf("Line ref: %d *WARNING* color [%s] ALREADY FOUND in history list!\n",__LINE__,color_key.c_str()); + assign_color_using_loop(assign_to); + } + } + else { + assign_to[0] = nextColorID[0]; + assign_to[1] = nextColorID[1]; + assign_to[2] = nextColorID[2]; + + const int colorSpacing = 8; + + if((int)(nextColorID[0] + colorSpacing) <= 255) { + nextColorID[0] += colorSpacing; + } + else { + nextColorID[0] = 1; + if((int)(nextColorID[1] + colorSpacing) <= 255) { + nextColorID[1] += colorSpacing; + } + else { + nextColorID[1] = 1; + if((int)(nextColorID[2] + colorSpacing) <= 255) { + nextColorID[2] += colorSpacing; + } + else { + + printf("Color rolled over on 3rd level usedColorIDList = %d!\n",(int)usedColorIDList.size()); + + nextColorID[0] = 1; + nextColorID[1] = 1; + nextColorID[2] = 1; + + + // nextColorID[2] = 1; + // nextColorID[3]+=colorSpacing; + // + // if(nextColorID[3] > 255) { + // nextColorID[0] = 1; + // nextColorID[1] = 1; + // nextColorID[2] = 1; + // nextColorID[3] = 1; + // } + } + } + } + } +} + +void BaseColorPickEntity::recycleUniqueColor() { + //MutexSafeWrapper safeMutex(&mutexNextColorID); + + vector reUseColor; + reUseColor.push_back(uniqueColorID[0]); + reUseColor.push_back(uniqueColorID[1]); + reUseColor.push_back(uniqueColorID[2]); + nextColorIDReuseList.push_back(reUseColor); + + //printf("RECYCLE Color [%u.%u.%u] usedColorIDList = %d nextColorIDReuseList = %d!\n",reUseColor[0],reUseColor[1],reUseColor[2],(int)usedColorIDList.size(),(int)nextColorIDReuseList.size()); + + if(usedColorIDList.empty() == false) { + string color_key = getColorDescription(); + if(usedColorIDList.find(color_key) != usedColorIDList.end()) { + usedColorIDList.erase(color_key); + + //printf("REMOVING used Color [%s] usedColorIDList = %d nextColorIDReuseList = %d!\n",color_key.c_str(),(int)usedColorIDList.size(),(int)nextColorIDReuseList.size()); + } + else { + printf("Line ref: %d *WARNING* color [%s] used count: %d NOT FOUND in history list!\n",__LINE__,color_key.c_str(),(int)usedColorIDList.size()); + } + } +} + +void BaseColorPickEntity::resetUniqueColors() { + //MutexSafeWrapper safeMutex(&mutexNextColorID); + + BaseColorPickEntity::nextColorRGB = BaseColorPickEntity::k; + + BaseColorPickEntity::nextColorID[0] = 1; + BaseColorPickEntity::nextColorID[1] = 1; + BaseColorPickEntity::nextColorID[2] = 1; + + usedColorIDList.clear(); + nextColorIDReuseList.clear(); +} void BaseColorPickEntity::init(int bufferSize) { if(BaseColorPickEntity::pbo.get() == NULL) { BaseColorPickEntity::pbo.reset(new PixelBufferWrapper(2,bufferSize)); diff --git a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp index 3c95041e..6a927b44 100644 --- a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp @@ -33,6 +33,15 @@ using namespace Shared::PlatformCommon; namespace Shared{ namespace Platform{ +// Example values: +// DEFAULT_CHARSET (English) = 1 +// GB2312_CHARSET (Chinese) = 134 +#ifdef WIN32 +DWORD PlatformContextGl::charSet = DEFAULT_CHARSET; +#else +int PlatformContextGl::charSet = 1; +#endif + // ====================================== // class PlatformContextGl // ====================================== diff --git a/source/shared_lib/sources/platform/unix/gl_wrap.cpp b/source/shared_lib/sources/platform/unix/gl_wrap.cpp index 8d3e8e59..07f6c74f 100644 --- a/source/shared_lib/sources/platform/unix/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/unix/gl_wrap.cpp @@ -28,14 +28,6 @@ using namespace Shared::Util; namespace Shared { namespace Platform { -// Example values: -// DEFAULT_CHARSET (English) = 1 -// GB2312_CHARSET (Chinese) = 134 -#ifdef WIN32 -DWORD PlatformContextGl::charSet = DEFAULT_CHARSET; -#else -int PlatformContextGl::charSet = 1; -#endif // ====================================== // Global Fcs diff --git a/source/tests/shared_lib/graphics/model_test.cpp b/source/tests/shared_lib/graphics/model_test.cpp new file mode 100644 index 00000000..ae8b5a27 --- /dev/null +++ b/source/tests/shared_lib/graphics/model_test.cpp @@ -0,0 +1,108 @@ +// ============================================================== +// This file is part of MegaGlest Unit Tests (www.megaglest.org) +// +// Copyright (C) 2013 Mark Vejvoda +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include +#include +#include "model.h" +#include +#include + +#ifdef WIN32 +#include +#else +#include +#endif + +using namespace Shared::Graphics; + +class TestBaseColorPickEntity : public BaseColorPickEntity { +public: + virtual string getUniquePickName() const { + return getColorDescription(); + } +}; +// +// Tests for font class +// +class ModelTest : public CppUnit::TestFixture { + // Register the suite of tests for this fixture + CPPUNIT_TEST_SUITE( ModelTest ); + + CPPUNIT_TEST( test_ColorPicking_loop ); + CPPUNIT_TEST( test_ColorPicking_prime ); + + CPPUNIT_TEST_SUITE_END(); + // End of Fixture registration + +public: + + void test_ColorPicking_loop() { + + BaseColorPickEntity::setTrackColorUse(true); + BaseColorPickEntity::setUsingLoopMethod(true); + BaseColorPickEntity::resetUniqueColors(); + + TestBaseColorPickEntity colorPicker; + // This is the max color count this algorithm supports + const int MAX_SUPPORTED_COLORS_USING_THIS_METHOD = 32767; + for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD; ++i) { + bool duplicate = colorPicker.get_next_assign_color(colorPicker.getUniqueColorID()); + CPPUNIT_ASSERT_EQUAL( false,duplicate ); + } + + BaseColorPickEntity::resetUniqueColors(); + + TestBaseColorPickEntity colorPicker2; + // This is a test to prove when the algorithm fails + const int MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL = 32768; + for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL; ++i) { + bool duplicate = colorPicker2.get_next_assign_color(colorPicker2.getUniqueColorID()); + CPPUNIT_ASSERT_EQUAL( (i+1 >= MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL),duplicate ); + } + + BaseColorPickEntity::resetUniqueColors(); + BaseColorPickEntity::setTrackColorUse(false); + } + + void test_ColorPicking_prime() { + + BaseColorPickEntity::setTrackColorUse(true); + BaseColorPickEntity::setUsingLoopMethod(false); + BaseColorPickEntity::resetUniqueColors(); + + TestBaseColorPickEntity colorPicker; + // This is the max color count this algorithm supports + const int MAX_SUPPORTED_COLORS_USING_THIS_METHOD = 64005; + for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD; ++i) { + bool duplicate = colorPicker.get_next_assign_color(colorPicker.getUniqueColorID()); + CPPUNIT_ASSERT_EQUAL( false,duplicate ); + } + + BaseColorPickEntity::resetUniqueColors(); + + TestBaseColorPickEntity colorPicker2; + // This is a test to prove when the algorithm fails + const int MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL = 64006; + for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL; ++i) { + bool duplicate = colorPicker2.get_next_assign_color(colorPicker2.getUniqueColorID()); + CPPUNIT_ASSERT_EQUAL( (i+1 >= MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL),duplicate ); + } + + BaseColorPickEntity::resetUniqueColors(); + BaseColorPickEntity::setTrackColorUse(false); + } + +}; + + +// Test Suite Registrations +CPPUNIT_TEST_SUITE_REGISTRATION( ModelTest ); +//