diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index c6f28cf0..bc8673ce 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -589,7 +589,7 @@ Vec2i PathFinder::jump(Vec2i dest, direction dir, Vec2i start,std::vector if (!isEnterable(coord)) return Vec2i(-1,-1); - if(path.size() > max(250,pathLength*2)) { + if(path.size() > max(300,pathLength*2)) { //if(path.size() > 2000) { //printf("path.size() > pathLength [%d]\n",pathLength); //return Vec2i(-1,-1); @@ -1038,64 +1038,60 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout //addToOpenSet (&astar, newNode, node); //printf("JPS #2 node->pos [%s] newNode [%s] path.size() [%d] pos [%s]\n",node->pos.getString().c_str(),newNode.getString().c_str(),(int)path.size(),path[0].getString().c_str()); - //for(unsigned int ipath = 0; ipath < path.size(); ++ipath) { - //for(unsigned int ipath = 0; ipath < 1; ++ipath) { - Vec2i newPath = path[0]; + Vec2i newPath = path[0]; - //bool canUnitMoveToCell = map->aproxCanMove(unit, node->pos, newPath); - //bool posOpen = (openPos(newPath, factions[unit->getFactionIndex()]) == false); - //bool isFreeCell = map->isFreeCell(newPath,unit->getType()->getField()); + //bool canUnitMoveToCell = map->aproxCanMove(unit, node->pos, newPath); + //bool posOpen = (openPos(newPath, factions[unit->getFactionIndex()]) == false); + //bool isFreeCell = map->isFreeCell(newPath,unit->getType()->getField()); - if(canAddNode.find(make_pair(node->pos,newPath)) == canAddNode.end()) { - Node *newNode=NULL; - if(addToOpenSet(unit, node, finalPos, newPath, nodeLimitReached, maxNodeCount,&newNode,false) == true) { - //cameFrom = node->pos; - cameFrom[newPath]=node->pos; - foundQuickRoute = true; + if(canAddNode.find(make_pair(node->pos,newPath)) == canAddNode.end()) { + Node *newNode=NULL; + if(addToOpenSet(unit, node, finalPos, newPath, nodeLimitReached, maxNodeCount,&newNode,false) == true) { + //cameFrom = node->pos; + cameFrom[newPath]=node->pos; + foundQuickRoute = true; + + if(path.size() > 1 && path[path.size()-1] == finalPos) { + canAddEntirePath = true; + for(unsigned int x = 1; x < path.size(); ++x) { + Vec2i futureNode = path[x]; + + bool canUnitMoveToCell = map->aproxCanMoveSoon(unit, newNode->pos, futureNode); + if(canUnitMoveToCell != true || openPos(futureNode, factions[unit->getFactionIndex()]) == true) { + canAddEntirePath = false; + canAddNode[make_pair(node->pos,futureNode)]=false; + //printf("COULD NOT ADD ENTIRE PATH! canUnitMoveToCell = %d\n",canUnitMoveToCell); + break; + } + } + if(canAddEntirePath == true) { + //printf("add node - ENTIRE PATH!\n"); - if(path.size() > 1) { - canAddEntirePath = true; for(unsigned int x = 1; x < path.size(); ++x) { Vec2i futureNode = path[x]; - bool canUnitMoveToCell = map->aproxCanMoveSoon(unit, newNode->pos, futureNode); - if(canUnitMoveToCell != true || openPos(futureNode, factions[unit->getFactionIndex()]) == true) { - canAddEntirePath = false; - canAddNode[make_pair(node->pos,futureNode)]=false; - //printf("COULD NOT ADD ENTIRE PATH! canUnitMoveToCell = %d\n",canUnitMoveToCell); - break; - } + Node *newNode2=NULL; + addToOpenSet(unit, newNode, finalPos, futureNode, nodeLimitReached, maxNodeCount,&newNode2, true); + newNode=newNode2; } - if(canAddEntirePath == true) { - //printf("add node - ENTIRE PATH!\n"); - for(unsigned int x = 1; x < path.size(); ++x) { - Vec2i futureNode = path[x]; - - Node *newNode2=NULL; - addToOpenSet(unit, newNode, finalPos, futureNode, nodeLimitReached, maxNodeCount,&newNode2, true); - newNode=newNode2; - } - - //Node *result = factions[unit->getFactionIndex()].openNodesList.begin()->second[0]; - //if(result->pos == finalPos || result->exploredCell == false) { - // printf("Will break out of pathfinding now!\n"); - //} - } + //Node *result = factions[unit->getFactionIndex()].openNodesList.begin()->second[0]; + //if(result->pos == finalPos || result->exploredCell == false) { + // printf("Will break out of pathfinding now!\n"); + //} } - //printf("add node - current node [%s] next possible node [%s] canUnitMoveToCell [%d] posOpen [%d] isFreeCell [%d]\n",node->pos.getString().c_str(),newPath.getString().c_str(),canUnitMoveToCell,posOpen,isFreeCell); - } - else { - //printf("COULD NOT add node - current node [%s] next possible node [%s] canUnitMoveToCell [%d] posOpen [%d] isFreeCell [%d]\n",node->pos.getString().c_str(),newPath.getString().c_str(),canUnitMoveToCell,posOpen,isFreeCell); - canAddNode[make_pair(node->pos,newPath)]=false; } + //printf("add node - current node [%s] next possible node [%s] canUnitMoveToCell [%d] posOpen [%d] isFreeCell [%d]\n",node->pos.getString().c_str(),newPath.getString().c_str(),canUnitMoveToCell,posOpen,isFreeCell); + } + else { + //printf("COULD NOT add node - current node [%s] next possible node [%s] canUnitMoveToCell [%d] posOpen [%d] isFreeCell [%d]\n",node->pos.getString().c_str(),newPath.getString().c_str(),canUnitMoveToCell,posOpen,isFreeCell); + canAddNode[make_pair(node->pos,newPath)]=false; } - - //} - - if(canAddEntirePath == true) { - break; } + + //if(canAddEntirePath == true) { + // break; + //} } if(foundQuickRoute == false) { @@ -1117,29 +1113,26 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout //addToOpenSet (&astar, newNode, node); //printf("JPS #3 node->pos [%s] newNode [%s]\n",node->pos.getString().c_str(),newNode.getString().c_str()); - //for(unsigned int ipath = 0; ipath < path.size(); ++ipath) { - //for(unsigned int ipath = 0; ipath < 1; ++ipath) { - Vec2i newPath = newNode; + Vec2i newPath = newNode; - //bool canUnitMoveToCell = map->aproxCanMove(unit, node->pos, newPath); - //bool posOpen = (openPos(newPath, factions[unit->getFactionIndex()]) == false); - //bool isFreeCell = map->isFreeCell(newPath,unit->getType()->getField()); + //bool canUnitMoveToCell = map->aproxCanMove(unit, node->pos, newPath); + //bool posOpen = (openPos(newPath, factions[unit->getFactionIndex()]) == false); + //bool isFreeCell = map->isFreeCell(newPath,unit->getType()->getField()); - if(canAddNode.find(make_pair(node->pos,newPath)) == canAddNode.end()) { - Node *newNode=NULL; - if(addToOpenSet(unit, node, finalPos, newPath, nodeLimitReached, maxNodeCount,&newNode, false) == true) { - //cameFrom = node->pos; - cameFrom[newPath]=node->pos; - foundQuickRoute = true; + if(canAddNode.find(make_pair(node->pos,newPath)) == canAddNode.end()) { + Node *newNode=NULL; + if(addToOpenSet(unit, node, finalPos, newPath, nodeLimitReached, maxNodeCount,&newNode, false) == true) { + //cameFrom = node->pos; + cameFrom[newPath]=node->pos; + foundQuickRoute = true; - //printf("#2 add node - current node [%s] next possible node [%s] canUnitMoveToCell [%d] posOpen [%d] isFreeCell [%d]\n",node->pos.getString().c_str(),newPath.getString().c_str(),canUnitMoveToCell,posOpen,isFreeCell); - } - else { - //printf("#2 COULD NOT add node - current node [%s] next possible node [%s] canUnitMoveToCell [%d] posOpen [%d] isFreeCell [%d]\n",node->pos.getString().c_str(),newPath.getString().c_str(),canUnitMoveToCell,posOpen,isFreeCell); - canAddNode[make_pair(node->pos,newPath)]=false; - } + //printf("#2 add node - current node [%s] next possible node [%s] canUnitMoveToCell [%d] posOpen [%d] isFreeCell [%d]\n",node->pos.getString().c_str(),newPath.getString().c_str(),canUnitMoveToCell,posOpen,isFreeCell); } - //} + else { + //printf("#2 COULD NOT add node - current node [%s] next possible node [%s] canUnitMoveToCell [%d] posOpen [%d] isFreeCell [%d]\n",node->pos.getString().c_str(),newPath.getString().c_str(),canUnitMoveToCell,posOpen,isFreeCell); + canAddNode[make_pair(node->pos,newPath)]=false; + } + } } } } diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 7a9d3423..b97af883 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -39,6 +39,8 @@ #include #include "core_data.h" #include "font_text.h" +//#include "FileReader.h" +//#include "JPGReader.h" //#include "sound.h" //#include "unicode/uclean.h" @@ -87,6 +89,7 @@ using namespace Shared::Util; using namespace Shared::Graphics; using namespace Shared::Graphics::Gl; using namespace Shared::Xml; +using namespace Shared; namespace Glest{ namespace Game{ @@ -160,17 +163,25 @@ static void cleanupProcessObjects() { //deleteMapValues(crcFactionPreviewTextureCache.begin(),crcFactionPreviewTextureCache.end()); crcFactionPreviewTextureCache.clear(); + printf("running threads = %lu\n",Thread::getThreadList().size()); time_t elapsed = time(NULL); for(;Thread::getThreadList().size() > 0 && difftime(time(NULL),elapsed) <= 10;) { - sleep(0); + sleep(10); } - SystemFlags::globalCleanupHTTP(); - CacheManager::cleanupMutexes(); + std::map const * >* > &list2d = FileReader::getFileReadersMap(); + //printf("list2d = %lu\n",list2d.size()); + deleteMapValues(list2d.begin(),list2d.end()); + std::map const * >* > &list3d = FileReader::getFileReadersMap(); + //printf("list3d = %lu\n",list3d.size()); + deleteMapValues(list3d.begin(),list3d.end()); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::SHUTDOWN_PROGRAM_MODE=true; + + SystemFlags::globalCleanupHTTP(); + CacheManager::cleanupMutexes(); } #if defined(WIN32) && !defined(_DEBUG) && !defined(__GNUC__) diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 0ef8efea..555870ce 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -645,6 +645,7 @@ void MenuStateCustomGame::cleanup() { } else { publishToMasterserverThread->signalQuit(); + sleep(0); if(publishToMasterserverThread->canShutdown(true) == true && publishToMasterserverThread->shutdownAndWait() == true) { delete publishToMasterserverThread; diff --git a/source/shared_lib/include/graphics/FileReader.h b/source/shared_lib/include/graphics/FileReader.h index 06affa4e..38d1c41c 100644 --- a/source/shared_lib/include/graphics/FileReader.h +++ b/source/shared_lib/include/graphics/FileReader.h @@ -273,23 +273,16 @@ T* FileReader::readPath(const string& filepath, T* object) { template FileReader::FileReader(std::vector extensions): extensions(extensions) { getFileReaders().push_back(this); - //string const * nextExtension = extensions; std::vector nextExtension = extensions; - //while (((*nextExtension) != "")) { for(unsigned int i = 0; i < nextExtension.size(); ++i) { - //vector const* >* curPossibleReaders = (getFileReadersMap())[*nextExtension]; vector const* >* curPossibleReaders = (getFileReadersMap())[nextExtension[i]]; if (curPossibleReaders == NULL) { - //(getFileReadersMap())[*nextExtension] = (curPossibleReaders = new vector const *>()); (getFileReadersMap())[nextExtension[i]] = (curPossibleReaders = new vector const *>()); } curPossibleReaders->push_back(this); - //++nextExtension; } } - - /**Gives a quick estimation of whether the specified file * can be read or not depending on the filename*/ template diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 6b59aeff..8a1e2fa5 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -561,6 +561,8 @@ UnitParticleSystem::UnitParticleSystem(int particleCount): startTime = 0; endTime = 1; + + radiusBasedStartenergy = false; } UnitParticleSystem::~UnitParticleSystem(){ diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 8fec8a4a..29ffc4b8 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -192,6 +192,13 @@ CURL *SystemFlags::initHTTP() { } void SystemFlags::globalCleanupHTTP() { + + if(curl_handle != NULL) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::cleanupHTTP(&curl_handle, true); + curl_handle = NULL; + } + if(SystemFlags::curl_global_init_called == true) { SystemFlags::curl_global_init_called = false; //printf("HTTP cleanup\n"); @@ -297,14 +304,7 @@ SystemFlags::~SystemFlags() { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(curl_handle != NULL) { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - SystemFlags::cleanupHTTP(&curl_handle, true); - curl_handle = NULL; - } - if(SystemFlags::curl_global_init_called == true) { - SystemFlags::globalCleanupHTTP(); - } + SystemFlags::globalCleanupHTTP(); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); }