- re-enabled fog of war cache to improve performance

- improve xml file loading speed
This commit is contained in:
Mark Vejvoda 2013-01-03 17:30:59 +00:00
parent 1018d85769
commit 1f49886755
11 changed files with 463 additions and 135 deletions

View File

@ -42,7 +42,7 @@ const int PathFinder::maxFreeSearchRadius = 10;
int PathFinder::pathFindNodesAbsoluteMax = 900; int PathFinder::pathFindNodesAbsoluteMax = 900;
int PathFinder::pathFindNodesMax = 2000; int PathFinder::pathFindNodesMax = 2000;
const int PathFinder::pathFindRefresh = 10; //const int PathFinder::pathFindRefresh = 10;
const int PathFinder::pathFindBailoutRadius = 20; const int PathFinder::pathFindBailoutRadius = 20;
const int PathFinder::pathFindExtendRefreshForNodeCount = 25; const int PathFinder::pathFindExtendRefreshForNodeCount = 25;
const int PathFinder::pathFindExtendRefreshNodeCountMin = 40; const int PathFinder::pathFindExtendRefreshNodeCountMin = 40;
@ -142,7 +142,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"[findPath] unit->getPos() [%s] finalPos [%s]", snprintf(szBuf,8096,"[findPath] unit->getPos() [%s] finalPos [%s]",
unit->getPos().getString().c_str(),finalPos.getString().c_str()); unit->getPos().getString().c_str(),finalPos.getString().c_str());
unit->logSynchData(__FILE__,__LINE__,szBuf); unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
} }
//route cache //route cache
@ -245,7 +245,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"[attempting to BAIL OUT] finalPos [%s] ts [%d]", snprintf(szBuf,8096,"[attempting to BAIL OUT] finalPos [%s] ts [%d]",
finalPos.getString().c_str(),ts); finalPos.getString().c_str(),ts);
unit->logSynchData(__FILE__,__LINE__,szBuf); unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
} }
if(wasStuck != NULL) { if(wasStuck != NULL) {
@ -296,7 +296,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"[attempting to BAIL OUT] finalPos [%s] newFinalPos [%s] ts [%d] canUnitMove [%d]", snprintf(szBuf,8096,"[attempting to BAIL OUT] finalPos [%s] newFinalPos [%s] ts [%d] canUnitMove [%d]",
finalPos.getString().c_str(),newFinalPos.getString().c_str(),ts,canUnitMove); finalPos.getString().c_str(),newFinalPos.getString().c_str(),ts,canUnitMove);
unit->logSynchData(__FILE__,__LINE__,szBuf); unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
} }
if(canUnitMove) { if(canUnitMove) {
@ -319,7 +319,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"[attempting to BAIL OUT] finalPos [%s] newFinalPos [%s] ts [%d] canUnitMove [%d]", snprintf(szBuf,8096,"[attempting to BAIL OUT] finalPos [%s] newFinalPos [%s] ts [%d] canUnitMove [%d]",
finalPos.getString().c_str(),newFinalPos.getString().c_str(),ts,canUnitMove); finalPos.getString().c_str(),newFinalPos.getString().c_str(),ts,canUnitMove);
unit->logSynchData(__FILE__,__LINE__,szBuf); unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
} }
if(canUnitMove) { if(canUnitMove) {
@ -864,7 +864,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
float dist= unitPos.dist(finalPos); float dist= unitPos.dist(finalPos);
factions[unitFactionIndex].useMaxNodeCount = PathFinder::pathFindNodesMax; factions[unitFactionIndex].useMaxNodeCount = PathFinder::pathFindNodesMax;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
// Check the previous path find cache for the unit to see if its good to // Check the previous path find cache for the unit to see if its good to
// use // use
@ -888,7 +888,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
//on the way //on the way
ts= tsMoving; ts= tsMoving;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
//store path //store path
if(frameIndex < 0) { if(frameIndex < 0) {
@ -914,13 +914,13 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
pathCount++; pathCount++;
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) { if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"[Setting new path for unit] openNodesList.size() [" MG_SIZE_T_SPECIFIER "] openPosList.size() [" MG_SIZE_T_SPECIFIER "] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d]", snprintf(szBuf,8096,"[Setting new path for unit] openNodesList.size() [" MG_SIZE_T_SPECIFIER "] openPosList.size() [" MG_SIZE_T_SPECIFIER "] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d]",
factions[unitFactionIndex].openNodesList.size(),factions[unitFactionIndex].openPosList.size(),finalPos.getString().c_str(),targetPos.getString().c_str(),inBailout,ts); factions[unitFactionIndex].openNodesList.size(),factions[unitFactionIndex].openPosList.size(),finalPos.getString().c_str(),targetPos.getString().c_str(),inBailout,ts);
unit->logSynchData(__FILE__,__LINE__,szBuf); unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled == true) {
@ -935,7 +935,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
unit->setCurrentUnitTitle(szBuf); unit->setCurrentUnitTitle(szBuf);
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
unit->setUsePathfinderExtendedMaxNodes(false); unit->setUsePathfinderExtendedMaxNodes(false);
return ts; return ts;
@ -945,7 +945,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
//on the way //on the way
ts= tsMoving; ts= tsMoving;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
//store path //store path
if(frameIndex < 0) { if(frameIndex < 0) {
@ -971,13 +971,13 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
pathCount++; pathCount++;
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) { if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"[Setting new path for unit] openNodesList.size() [" MG_SIZE_T_SPECIFIER "] openPosList.size() [" MG_SIZE_T_SPECIFIER "] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d]", snprintf(szBuf,8096,"[Setting new path for unit] openNodesList.size() [" MG_SIZE_T_SPECIFIER "] openPosList.size() [" MG_SIZE_T_SPECIFIER "] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d]",
factions[unitFactionIndex].openNodesList.size(),factions[unitFactionIndex].openPosList.size(),finalPos.getString().c_str(),targetPos.getString().c_str(),inBailout,ts); factions[unitFactionIndex].openNodesList.size(),factions[unitFactionIndex].openPosList.size(),finalPos.getString().c_str(),targetPos.getString().c_str(),inBailout,ts);
unit->logSynchData(__FILE__,__LINE__,szBuf); unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled == true) {
@ -992,7 +992,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
unit->setCurrentUnitTitle(szBuf); unit->setCurrentUnitTitle(szBuf);
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
unit->setUsePathfinderExtendedMaxNodes(false); unit->setUsePathfinderExtendedMaxNodes(false);
return ts; return ts;
@ -1034,7 +1034,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
bool nodeLimitReached = false; bool nodeLimitReached = false;
Node *node = NULL; Node *node = NULL;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
// First check if unit currently blocked all around them, if so don't try to pathfind // First check if unit currently blocked all around them, if so don't try to pathfind
if(inBailout == false && unitPos != finalPos) { if(inBailout == false && unitPos != finalPos) {
@ -1057,7 +1057,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
nodeLimitReached = (failureCount == cellCount); nodeLimitReached = (failureCount == cellCount);
pathFound = !nodeLimitReached; pathFound = !nodeLimitReached;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] **Check if dest blocked, distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d\n",__FILE__,__FUNCTION__,__LINE__,unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] **Check if dest blocked, distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount);
if(showConsoleDebugInfo && nodeLimitReached) { if(showConsoleDebugInfo && nodeLimitReached) {
printf("**Check if src blocked [%d - %d], unit [%d - %s] from [%s] to [%s] distance %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d [%d]\n", printf("**Check if src blocked [%d - %d], unit [%d - %s] from [%s] to [%s] distance %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d [%d]\n",
nodeLimitReached, inBailout, unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount,cellCount); nodeLimitReached, inBailout, unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount,cellCount);
@ -1084,7 +1084,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
nodeLimitReached = (failureCount == cellCount); nodeLimitReached = (failureCount == cellCount);
pathFound = !nodeLimitReached; pathFound = !nodeLimitReached;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] **Check if dest blocked, distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d\n",__FILE__,__FUNCTION__,__LINE__,unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] **Check if dest blocked, distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount);
if(showConsoleDebugInfo && nodeLimitReached) { if(showConsoleDebugInfo && nodeLimitReached) {
printf("**Check if dest blocked [%d - %d], unit [%d - %s] from [%s] to [%s] distance %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d [%d]\n", printf("**Check if dest blocked [%d - %d], unit [%d - %s] from [%s] to [%s] distance %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d [%d]\n",
nodeLimitReached, inBailout, unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount,cellCount); nodeLimitReached, inBailout, unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount,cellCount);
@ -1142,7 +1142,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
} }
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld nodeLimitReached = %d whileLoopCount = %d nodePoolCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),nodeLimitReached,whileLoopCount,factions[unitFactionIndex].nodePoolCount); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld nodeLimitReached = %d whileLoopCount = %d nodePoolCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),nodeLimitReached,whileLoopCount,factions[unitFactionIndex].nodePoolCount);
if(showConsoleDebugInfo && chrono.getMillis() > 2) { if(showConsoleDebugInfo && chrono.getMillis() > 2) {
printf("Distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d whileLoopCount = %d nodePoolCount = %d\n",unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,whileLoopCount,factions[unitFactionIndex].nodePoolCount); printf("Distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d whileLoopCount = %d nodePoolCount = %d\n",unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,whileLoopCount,factions[unitFactionIndex].nodePoolCount);
} }
@ -1159,7 +1159,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
} }
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
//check results of path finding //check results of path finding
ts = tsImpossible; ts = tsImpossible;
@ -1194,10 +1194,10 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"[path for unit BLOCKED] openNodesList.size() [" MG_SIZE_T_SPECIFIER "] openPosList.size() [" MG_SIZE_T_SPECIFIER "] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d]", snprintf(szBuf,8096,"[path for unit BLOCKED] openNodesList.size() [" MG_SIZE_T_SPECIFIER "] openPosList.size() [" MG_SIZE_T_SPECIFIER "] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d]",
factions[unitFactionIndex].openNodesList.size(),factions[unitFactionIndex].openPosList.size(),finalPos.getString().c_str(),targetPos.getString().c_str(),inBailout,ts); factions[unitFactionIndex].openNodesList.size(),factions[unitFactionIndex].openPosList.size(),finalPos.getString().c_str(),targetPos.getString().c_str(),inBailout,ts);
unit->logSynchData(__FILE__,__LINE__,szBuf); unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
} }
else { else {
if(minorDebugPathfinder) printf("Legacy Pathfind Unit [%d - %s] FOUND PATH count = %d frameIndex = %d\n",unit->getId(),unit->getType()->getName().c_str(),whileLoopCount,frameIndex); if(minorDebugPathfinder) printf("Legacy Pathfind Unit [%d - %s] FOUND PATH count = %d frameIndex = %d\n",unit->getId(),unit->getType()->getName().c_str(),whileLoopCount,frameIndex);
@ -1211,7 +1211,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
currNode= currNode->prev; currNode= currNode->prev;
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(frameIndex < 0) { if(frameIndex < 0) {
if(maxNodeCount == pathFindNodesAbsoluteMax) { if(maxNodeCount == pathFindNodesAbsoluteMax) {
@ -1264,13 +1264,13 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
} }
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) { if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"[Setting new path for unit] openNodesList.size() [" MG_SIZE_T_SPECIFIER "] openPosList.size() [" MG_SIZE_T_SPECIFIER "] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d]", snprintf(szBuf,8096,"[Setting new path for unit] openNodesList.size() [" MG_SIZE_T_SPECIFIER "] openPosList.size() [" MG_SIZE_T_SPECIFIER "] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d]",
factions[unitFactionIndex].openNodesList.size(),factions[unitFactionIndex].openPosList.size(),finalPos.getString().c_str(),targetPos.getString().c_str(),inBailout,ts); factions[unitFactionIndex].openNodesList.size(),factions[unitFactionIndex].openPosList.size(),finalPos.getString().c_str(),targetPos.getString().c_str(),inBailout,ts);
unit->logSynchData(__FILE__,__LINE__,szBuf); unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
string pathToTake = ""; string pathToTake = "";
for(int i = 0; i < path->getQueueCount(); ++i) { for(int i = 0; i < path->getQueueCount(); ++i) {
@ -1280,7 +1280,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
} }
pathToTake += pos.getString(); pathToTake += pos.getString();
} }
unit->logSynchData(__FILE__,__LINE__,szBuf); unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
snprintf(szBuf,8096,"Path for unit to take = %s",pathToTake.c_str()); snprintf(szBuf,8096,"Path for unit to take = %s",pathToTake.c_str());
} }
@ -1296,20 +1296,20 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
unit->setCurrentUnitTitle(szBuf); unit->setCurrentUnitTitle(szBuf);
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
} }
factions[unitFactionIndex].openNodesList.clear(); factions[unitFactionIndex].openNodesList.clear();
factions[unitFactionIndex].openPosList.clear(); factions[unitFactionIndex].openPosList.clear();
factions[unitFactionIndex].closedNodesList.clear(); factions[unitFactionIndex].closedNodesList.clear();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(frameIndex >= 0) { if(frameIndex >= 0) {
factions[unitFactionIndex].precachedTravelState[unit->getId()] = ts; factions[unitFactionIndex].precachedTravelState[unit->getId()] = ts;
} }
else { else {
if(SystemFlags::VERBOSE_MODE_ENABLED && chrono.getMillis() >= 5) printf("In [%s::%s Line: %d] astar took [%lld] msecs, ts = %d.\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis(),ts); if(SystemFlags::VERBOSE_MODE_ENABLED && chrono.getMillis() >= 5) printf("In [%s::%s Line: %d] astar took [%lld] msecs, ts = %d.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis(),ts);
} }
//printf("$$$$ Path for Unit [%d - %s] return value = %d inBailout = %d\n",unit->getId(),unit->getFullName().c_str(),ts,inBailout); //printf("$$$$ Path for Unit [%d - %s] return value = %d inBailout = %d\n",unit->getId(),unit->getFullName().c_str(),ts,inBailout);
@ -1505,9 +1505,14 @@ void PathFinder::loadGame(const XmlNode *rootNode) {
//attackWarnRange = unitupdaterNode->getAttribute("attackWarnRange")->getFloatValue(); //attackWarnRange = unitupdaterNode->getAttribute("attackWarnRange")->getFloatValue();
// static int pathFindNodesMax; // static int pathFindNodesMax;
pathFindNodesMax = pathfinderNode->getAttribute("pathFindNodesMax")->getIntValue(); // pathFindNodesMax = pathfinderNode->getAttribute("pathFindNodesMax")->getIntValue();
// static int pathFindNodesAbsoluteMax; // // static int pathFindNodesAbsoluteMax;
pathFindNodesAbsoluteMax = pathfinderNode->getAttribute("pathFindNodesAbsoluteMax")->getIntValue(); // pathFindNodesAbsoluteMax = pathfinderNode->getAttribute("pathFindNodesAbsoluteMax")->getIntValue();
//
// for(int i = 0; i < GameConstants::maxPlayers; ++i) {
// factions[i].nodePool.resize(pathFindNodesAbsoluteMax);
// factions[i].useMaxNodeCount = PathFinder::pathFindNodesMax;
// }
vector<XmlNode *> factionsNodeList = pathfinderNode->getChildList("factions"); vector<XmlNode *> factionsNodeList = pathfinderNode->getChildList("factions");
for(unsigned int i = 0; i < factionsNodeList.size(); ++i) { for(unsigned int i = 0; i < factionsNodeList.size(); ++i) {
@ -1516,7 +1521,7 @@ void PathFinder::loadGame(const XmlNode *rootNode) {
FactionState &factionState = factions[i]; FactionState &factionState = factions[i];
// std::vector<Node> nodePool; // std::vector<Node> nodePool;
vector<XmlNode *> nodePoolListNode = factionsNode->getChildList("nodePool"); vector<XmlNode *> nodePoolListNode = factionsNode->getChildList("nodePool");
for(unsigned int j = 0; j < nodePoolListNode.size(); ++j) { for(unsigned int j = 0; j < nodePoolListNode.size() && j < pathFindNodesAbsoluteMax; ++j) {
XmlNode *nodePoolNode = nodePoolListNode[j]; XmlNode *nodePoolNode = nodePoolListNode[j];
Node *curNode = &factionState.nodePool[j]; Node *curNode = &factionState.nodePool[j];
@ -1553,7 +1558,8 @@ void PathFinder::loadGame(const XmlNode *rootNode) {
// RandomGen random; // RandomGen random;
factionState.random.setLastNumber(factionsNode->getAttribute("random")->getIntValue()); factionState.random.setLastNumber(factionsNode->getAttribute("random")->getIntValue());
// int useMaxNodeCount; // int useMaxNodeCount;
factionState.useMaxNodeCount = factionsNode->getAttribute("useMaxNodeCount")->getIntValue(); //factionState.useMaxNodeCount = factionsNode->getAttribute("useMaxNodeCount")->getIntValue();
factionState.useMaxNodeCount = PathFinder::pathFindNodesMax;
// //
// std::map<int,TravelState> precachedTravelState; // std::map<int,TravelState> precachedTravelState;
// std::map<int,std::vector<Vec2i> > precachedPath; // std::map<int,std::vector<Vec2i> > precachedPath;

View File

@ -138,7 +138,7 @@ public:
public: public:
static const int maxFreeSearchRadius; static const int maxFreeSearchRadius;
static const int pathFindRefresh; //static const int pathFindRefresh;
static const int pathFindBailoutRadius; static const int pathFindBailoutRadius;
static const int pathFindExtendRefreshForNodeCount; static const int pathFindExtendRefreshForNodeCount;
static const int pathFindExtendRefreshNodeCountMin; static const int pathFindExtendRefreshNodeCountMin;

View File

@ -1385,6 +1385,17 @@ void Game::update() {
currentUIState->update(); currentUIState->update();
} }
bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
Chrono chronoPerf;
char perfBuf[8096]="";
std::vector<string> perfList;
if(showPerfStats) chronoPerf.start();
if(showPerfStats) {
sprintf(perfBuf,"=============== FRAME: %d In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",world.getFrameCount(),extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
Chrono chrono; Chrono chrono;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
@ -1441,6 +1452,10 @@ void Game::update() {
int updateLoops= getUpdateLoops(); int updateLoops= getUpdateLoops();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
NetworkManager &networkManager= NetworkManager::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance();
bool enableServerControlledAI = this->gameSettings.getEnableServerControlledAI(); bool enableServerControlledAI = this->gameSettings.getEnableServerControlledAI();
@ -1448,6 +1463,10 @@ void Game::update() {
NetworkRole role = networkManager.getNetworkRole(); NetworkRole role = networkManager.getNetworkRole();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [before ReplaceDisconnectedNetworkPlayersWithAI]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [before ReplaceDisconnectedNetworkPlayersWithAI]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
// Check to see if we are playing a network game and if any players // Check to see if we are playing a network game and if any players
// have disconnected? // have disconnected?
@ -1455,6 +1474,10 @@ void Game::update() {
setupPopupMenus(true); setupPopupMenus(true);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [after ReplaceDisconnectedNetworkPlayersWithAI]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [after ReplaceDisconnectedNetworkPlayersWithAI]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(updateLoops > 0) { if(updateLoops > 0) {
// update the frame based timer in the stats with at least one step // update the frame based timer in the stats with at least one step
@ -1473,7 +1496,12 @@ void Game::update() {
replayCommandsPlayed = (replayTotal - commander.getReplayCommandListForFrameCount()); replayCommandsPlayed = (replayTotal - commander.getReplayCommandListForFrameCount());
} }
for(int i = 0; i < updateLoops; ++i) { for(int i = 0; i < updateLoops; ++i) {
chrono.start(); //if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//AiInterface //AiInterface
if(commander.hasReplayCommandListForFrame() == false) { if(commander.hasReplayCommandListForFrame() == false) {
@ -1498,6 +1526,7 @@ void Game::update() {
*/ */
// Signal the faction threads to do any pre-processing // Signal the faction threads to do any pre-processing
bool hasAIPlayer = false;
for(int j = 0; j < world.getFactionCount(); ++j) { for(int j = 0; j < world.getFactionCount(); ++j) {
Faction *faction = world.getFaction(j); Faction *faction = world.getFaction(j);
@ -1508,40 +1537,51 @@ void Game::update() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] [i = %d] faction = %d, factionCount = %d, took msecs: %lld [before AI updates]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,j,world.getFactionCount(),chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] [i = %d] faction = %d, factionCount = %d, took msecs: %lld [before AI updates]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,j,world.getFactionCount(),chrono.getMillis());
aiInterfaces[j]->signalWorkerThread(world.getFrameCount()); aiInterfaces[j]->signalWorkerThread(world.getFrameCount());
hasAIPlayer = true;
} }
} }
bool workThreadsFinished = false; if(showPerfStats) {
Chrono chrono; sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
chrono.start(); perfList.push_back(perfBuf);
}
const int MAX_FACTION_THREAD_WAIT_MILLISECONDS = 20000; if(hasAIPlayer == true) {
for(;chrono.getMillis() < MAX_FACTION_THREAD_WAIT_MILLISECONDS;) { //sleep(0);
workThreadsFinished = true;
for(int j = 0; j < world.getFactionCount(); ++j) { bool workThreadsFinished = false;
Faction *faction = world.getFaction(j); Chrono chronoAI;
if(faction == NULL) { chronoAI.start();
throw megaglest_runtime_error("faction == NULL");
} const int MAX_FACTION_THREAD_WAIT_MILLISECONDS = 20000;
if( faction->getCpuControl(enableServerControlledAI,isNetworkGame,role) == true && for(;chronoAI.getMillis() < MAX_FACTION_THREAD_WAIT_MILLISECONDS;) {
scriptManager.getPlayerModifiers(j)->getAiEnabled() == true) { workThreadsFinished = true;
if(aiInterfaces[j]->isWorkerThreadSignalCompleted(world.getFrameCount()) == false) { for(int j = 0; j < world.getFactionCount(); ++j) {
workThreadsFinished = false; Faction *faction = world.getFaction(j);
break; if(faction == NULL) {
throw megaglest_runtime_error("faction == NULL");
}
if( faction->getCpuControl(enableServerControlledAI,isNetworkGame,role) == true &&
scriptManager.getPlayerModifiers(j)->getAiEnabled() == true) {
if(aiInterfaces[j]->isWorkerThreadSignalCompleted(world.getFrameCount()) == false) {
workThreadsFinished = false;
break;
}
} }
} }
} if(workThreadsFinished == false) {
if(workThreadsFinished == false) { //sleep(0);
//sleep(0); }
} else {
else { break;
break; }
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
} }
else { else {
@ -1587,6 +1627,11 @@ void Game::update() {
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [AI updates]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [AI updates]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -1595,6 +1640,11 @@ void Game::update() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [world update i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [world update i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(currentCameraFollowUnit!=NULL){ if(currentCameraFollowUnit!=NULL){
Vec3f c=currentCameraFollowUnit->getCurrVector(); Vec3f c=currentCameraFollowUnit->getCurrVector();
int rotation=currentCameraFollowUnit->getRotation(); int rotation=currentCameraFollowUnit->getRotation();
@ -1621,10 +1671,20 @@ void Game::update() {
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
// Commander // Commander
//commander.updateNetwork(); //commander.updateNetwork();
if(pendingQuitError == false) commander.signalNetworkUpdate(this); if(pendingQuitError == false) commander.signalNetworkUpdate(this);
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [commander updateNetwork i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [commander updateNetwork i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -1633,6 +1693,11 @@ void Game::update() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [gui updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [gui updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//Particle systems //Particle systems
if(weatherParticleSystem != NULL) { if(weatherParticleSystem != NULL) {
weatherParticleSystem->setPos(gameCamera.getPos()); weatherParticleSystem->setPos(gameCamera.getPos());
@ -1641,11 +1706,21 @@ void Game::update() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [weather particle updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [weather particle updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
Renderer &renderer= Renderer::getInstance(); Renderer &renderer= Renderer::getInstance();
renderer.updateParticleManager(rsGame,avgRenderFps); renderer.updateParticleManager(rsGame,avgRenderFps);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [particle manager updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [particle manager updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//good_fpu_control_registers(NULL,extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); //good_fpu_control_registers(NULL,extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
} }
} }
@ -1663,15 +1738,30 @@ void Game::update() {
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//call the chat manager //call the chat manager
chatManager.updateNetwork(); chatManager.updateNetwork();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [chatManager.updateNetwork]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [chatManager.updateNetwork]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
updateNetworkMarkedCells(); updateNetworkMarkedCells();
updateNetworkUnMarkedCells(); updateNetworkUnMarkedCells();
updateNetworkHighligtedCells(); updateNetworkHighligtedCells();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//check for quiting status //check for quiting status
if(NetworkManager::getInstance().getGameNetworkInterface() != NULL && if(NetworkManager::getInstance().getGameNetworkInterface() != NULL &&
NetworkManager::getInstance().getGameNetworkInterface()->getQuit() && NetworkManager::getInstance().getGameNetworkInterface()->getQuit() &&
@ -1682,12 +1772,22 @@ void Game::update() {
return; return;
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//update auto test //update auto test
if(Config::getInstance().getBool("AutoTest")){ if(Config::getInstance().getBool("AutoTest")){
AutoTest::getInstance().updateGame(this); AutoTest::getInstance().updateGame(this);
return; return;
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(world.getQueuedScenario() != "") { if(world.getQueuedScenario() != "") {
string name = world.getQueuedScenario(); string name = world.getQueuedScenario();
bool keepFactions = world.getQueuedScenarioKeepFactions(); bool keepFactions = world.getQueuedScenarioKeepFactions();
@ -1833,6 +1933,17 @@ void Game::update() {
throw; throw;
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(showPerfStats && chronoPerf.getMillis() >= 50) {
for(unsigned int x = 0; x < perfList.size(); ++x) {
printf("%s",perfList[x].c_str());
}
}
} }
catch(const exception &ex) { catch(const exception &ex) {
quitPendingIndicator = true; quitPendingIndicator = true;

View File

@ -383,6 +383,12 @@ void Program::loopWorker() {
} }
} }
bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
Chrono chronoPerf;
char perfBuf[8096]="";
std::vector<string> perfList;
if(showPerfStats) chronoPerf.start();
Chrono chronoLoop; Chrono chronoLoop;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chronoLoop.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chronoLoop.start();
@ -407,9 +413,19 @@ void Program::loopWorker() {
} }
ProgramState *prevState = this->programState; ProgramState *prevState = this->programState;
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
assert(programState != NULL); assert(programState != NULL);
programState->render(); programState->render();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld ==============> MAIN LOOP RENDERING\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld ==============> MAIN LOOP RENDERING\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -419,6 +435,11 @@ void Program::loopWorker() {
programState->updateCamera(); programState->updateCamera();
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld ==============> MAIN LOOP CAMERA UPDATING\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld ==============> MAIN LOOP CAMERA UPDATING\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -428,12 +449,21 @@ void Program::loopWorker() {
while(prevState == this->programState && updateTimer.isTime()) { while(prevState == this->programState && updateTimer.isTime()) {
Chrono chronoUpdateLoop; Chrono chronoUpdateLoop;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chronoUpdateLoop.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chronoUpdateLoop.start();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " updateCount: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis(),updateCount);
perfList.push_back(perfBuf);
}
GraphicComponent::update(); GraphicComponent::update();
programState->update(); programState->update();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] programState->update took msecs: %lld, updateCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoUpdateLoop.getMillis(),updateCount); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] programState->update took msecs: %lld, updateCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoUpdateLoop.getMillis(),updateCount);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " updateCount: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis(),updateCount);
perfList.push_back(perfBuf);
}
if(prevState == this->programState) { if(prevState == this->programState) {
if(soundThreadManager == NULL || soundThreadManager->isThreadExecutionLagging()) { if(soundThreadManager == NULL || soundThreadManager->isThreadExecutionLagging()) {
if(soundThreadManager != NULL) { if(soundThreadManager != NULL) {
@ -445,9 +475,20 @@ void Program::loopWorker() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start();
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " updateCount: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis(),updateCount);
perfList.push_back(perfBuf);
}
NetworkManager::getInstance().update(); NetworkManager::getInstance().update();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] NetworkManager::getInstance().update() took msecs: %lld, updateCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoUpdateLoop.getMillis(),updateCount); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] NetworkManager::getInstance().update() took msecs: %lld, updateCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoUpdateLoop.getMillis(),updateCount);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " updateCount: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis(),updateCount);
perfList.push_back(perfBuf);
}
} }
updateCount++; updateCount++;
} }
@ -456,6 +497,11 @@ void Program::loopWorker() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(prevState == this->programState) { if(prevState == this->programState) {
//fps timer //fps timer
chrono.start(); chrono.start();
@ -463,6 +509,11 @@ void Program::loopWorker() {
programState->tick(); programState->tick();
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld ==============> MAIN LOOP TICKING\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld ==============> MAIN LOOP TICKING\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -471,6 +522,12 @@ void Program::loopWorker() {
} }
if(showPerfStats && chronoPerf.getMillis() >= 100) {
for(unsigned int x = 0; x < perfList.size(); ++x) {
printf("%s",perfList[x].c_str());
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] ------------------------------- MAIN LOOP END, stats: loop took msecs: %lld -------------------------------\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoLoop.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] ------------------------------- MAIN LOOP END, stats: loop took msecs: %lld -------------------------------\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoLoop.getMillis());
} }

View File

@ -511,7 +511,9 @@ int Faction::getUnitPathfindingListCount() {
void Faction::clearUnitsPathfinding() { void Faction::clearUnitsPathfinding() {
//printf("CLEAR Faction [%d - %s] threaded updates for [%d] units\n",this->getStartLocationIndex(),this->getType()->getName().c_str(),unitsPathfindingList.size()); //printf("CLEAR Faction [%d - %s] threaded updates for [%d] units\n",this->getStartLocationIndex(),this->getType()->getName().c_str(),unitsPathfindingList.size());
unitsPathfindingList.clear(); if(unitsPathfindingList.empty() == false) {
unitsPathfindingList.clear();
}
} }
bool Faction::canUnitsPathfind() { bool Faction::canUnitsPathfind() {

View File

@ -1752,49 +1752,52 @@ bool Unit::needToUpdate() {
void Unit::updateTimedParticles() { void Unit::updateTimedParticles() {
//!!! //!!!
// Start new particle systems based on start time // Start new particle systems based on start time
for(int i = queuedUnitParticleSystemTypes.size() - 1; i >= 0; i--) { if(queuedUnitParticleSystemTypes.empty() == false) {
UnitParticleSystemType *pst = queuedUnitParticleSystemTypes[i]; for(int i = queuedUnitParticleSystemTypes.size() - 1; i >= 0; i--) {
if(pst != NULL) { UnitParticleSystemType *pst = queuedUnitParticleSystemTypes[i];
if(truncateDecimal<float>(pst->getStartTime()) <= truncateDecimal<float>(animProgress)) { if(pst != NULL) {
//printf("STARTING queued particle system type [%s] [%f] [%f] [%f] [%f]\n",pst->getType().c_str(),truncateDecimal<float>(pst->getStartTime()),truncateDecimal<float>(pst->getEndTime()),truncateDecimal<float>(animProgress),truncateDecimal<float>(lastAnimProgress)); if(truncateDecimal<float>(pst->getStartTime()) <= truncateDecimal<float>(animProgress)) {
//printf("STARTING queued particle system type [%s] [%f] [%f] [%f] [%f]\n",pst->getType().c_str(),truncateDecimal<float>(pst->getStartTime()),truncateDecimal<float>(pst->getEndTime()),truncateDecimal<float>(animProgress),truncateDecimal<float>(lastAnimProgress));
UnitParticleSystem *ups = new UnitParticleSystem(200); UnitParticleSystem *ups = new UnitParticleSystem(200);
pst->setValues(ups); pst->setValues(ups);
ups->setPos(getCurrVector()); ups->setPos(getCurrVector());
if(getFaction()->getTexture()) { if(getFaction()->getTexture()) {
ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0));
}
unitParticleSystems.push_back(ups);
Renderer::getInstance().manageParticleSystem(ups, rsGame);
queuedUnitParticleSystemTypes.erase(queuedUnitParticleSystemTypes.begin() + i);
} }
unitParticleSystems.push_back(ups); }
Renderer::getInstance().manageParticleSystem(ups, rsGame); else {
queuedUnitParticleSystemTypes.erase(queuedUnitParticleSystemTypes.begin() + i); queuedUnitParticleSystemTypes.erase(queuedUnitParticleSystemTypes.begin() + i);
} }
} }
else {
queuedUnitParticleSystemTypes.erase(queuedUnitParticleSystemTypes.begin() + i);
}
} }
// End existing systems based on end time // End existing systems based on end time
for(int i = unitParticleSystems.size() - 1; i >= 0; i--) { if(unitParticleSystems.empty() == false) {
UnitParticleSystem *ps = unitParticleSystems[i]; for(int i = unitParticleSystems.size() - 1; i >= 0; i--) {
if(ps != NULL) { UnitParticleSystem *ps = unitParticleSystems[i];
if(Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) { if(ps != NULL) {
if(truncateDecimal<float>(ps->getStartTime()) != 0.0 || truncateDecimal<float>(ps->getEndTime()) != 1.0) { if(Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) {
//printf("Checking for end particle system #%d [%d] [%f] [%f] [%f] [%f]\n",i,ps->shape,truncateDecimal<float>(ps->getStartTime()),truncateDecimal<float>(ps->getEndTime()),truncateDecimal<float>(animProgress),truncateDecimal<float>(lastAnimProgress)); if(truncateDecimal<float>(ps->getStartTime()) != 0.0 || truncateDecimal<float>(ps->getEndTime()) != 1.0) {
//printf("Checking for end particle system #%d [%d] [%f] [%f] [%f] [%f]\n",i,ps->shape,truncateDecimal<float>(ps->getStartTime()),truncateDecimal<float>(ps->getEndTime()),truncateDecimal<float>(animProgress),truncateDecimal<float>(lastAnimProgress));
if(truncateDecimal<float>(animProgress) >= 0.99 || if(truncateDecimal<float>(animProgress) >= 0.99 ||
truncateDecimal<float>(animProgress) >= truncateDecimal<float>(ps->getEndTime())) { truncateDecimal<float>(animProgress) >= truncateDecimal<float>(ps->getEndTime())) {
//printf("ENDING particle system [%d]\n",ps->shape); //printf("ENDING particle system [%d]\n",ps->shape);
ps->fade(); ps->fade();
unitParticleSystems.erase(unitParticleSystems.begin() + i); unitParticleSystems.erase(unitParticleSystems.begin() + i);
}
} }
} }
} }
} }
} }
} }
bool Unit::update() { bool Unit::update() {

View File

@ -56,7 +56,7 @@ World::World() {
ExploredCellsLookupItemCacheTimerCount = 0; ExploredCellsLookupItemCacheTimerCount = 0;
FowAlphaCellsLookupItemCache.clear(); FowAlphaCellsLookupItemCache.clear();
// Disable this cache as it takes too much RAM (not sure if its worth the performance gain) // Disable this cache as it takes too much RAM (not sure if its worth the performance gain)
enableFowAlphaCellsLookupItemCache = false; enableFowAlphaCellsLookupItemCache = config.getBool("EnableFowCache","true");
nextCommandGroupId = 0; nextCommandGroupId = 0;
techTree = NULL; techTree = NULL;
@ -415,9 +415,9 @@ void World::updateAllFactionUnits() {
// Clear pathfinder list restrictions // Clear pathfinder list restrictions
for(int i = 0; i < factionCount; ++i) { for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i); Faction *faction = getFaction(i);
if(faction == NULL) { //if(faction == NULL) {
throw megaglest_runtime_error("faction == NULL"); // throw megaglest_runtime_error("faction == NULL");
} //}
faction->clearUnitsPathfinding(); faction->clearUnitsPathfinding();
faction->clearAproxCanMoveSoonCached(); faction->clearAproxCanMoveSoonCached();
} }
@ -425,12 +425,13 @@ void World::updateAllFactionUnits() {
// Signal the faction threads to do any pre-processing // Signal the faction threads to do any pre-processing
for(int i = 0; i < factionCount; ++i) { for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i); Faction *faction = getFaction(i);
if(faction == NULL) { //if(faction == NULL) {
throw megaglest_runtime_error("faction == NULL"); // throw megaglest_runtime_error("faction == NULL");
} //}
faction->signalWorkerThread(frameCount); faction->signalWorkerThread(frameCount);
} }
//sleep(0);
bool workThreadsFinished = false; bool workThreadsFinished = false;
Chrono chrono; Chrono chrono;
chrono.start(); chrono.start();
@ -440,9 +441,9 @@ void World::updateAllFactionUnits() {
workThreadsFinished = true; workThreadsFinished = true;
for(int i = 0; i < factionCount; ++i) { for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i); Faction *faction = getFaction(i);
if(faction == NULL) { //if(faction == NULL) {
throw megaglest_runtime_error("faction == NULL"); // throw megaglest_runtime_error("faction == NULL");
} //}
if(faction->isWorkerThreadSignalCompleted(frameCount) == false) { if(faction->isWorkerThreadSignalCompleted(frameCount) == false) {
workThreadsFinished = false; workThreadsFinished = false;
break; break;
@ -461,10 +462,9 @@ void World::updateAllFactionUnits() {
//units //units
for(int i = 0; i < factionCount; ++i) { for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i); Faction *faction = getFaction(i);
if(faction == NULL) { //if(faction == NULL) {
throw megaglest_runtime_error("faction == NULL"); // throw megaglest_runtime_error("faction == NULL");
} //}
faction->clearUnitsPathfinding(); faction->clearUnitsPathfinding();
int unitCount = faction->getUnitCount(); int unitCount = faction->getUnitCount();
@ -539,17 +539,34 @@ void World::updateAllFactionConsumableCosts() {
} }
} }
void World::update(){ void World::update() {
bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
Chrono chronoPerf;
char perfBuf[8096]="";
std::vector<string> perfList;
if(showPerfStats) chronoPerf.start();
++frameCount; ++frameCount;
//time //time
timeFlow.update(); timeFlow.update();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//water effects //water effects
waterEffects.update(1.0f); waterEffects.update(1.0f);
// attack effects // attack effects
attackEffects.update(0.25f); attackEffects.update(0.25f);
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//bool needToUpdateUnits = true; //bool needToUpdateUnits = true;
//if(staggeredFactionUpdates == true) { //if(staggeredFactionUpdates == true) {
// needToUpdateUnits = (frameCount % (GameConstants::updateFps / GameConstants::maxPlayers) == 0); // needToUpdateUnits = (frameCount % (GameConstants::updateFps / GameConstants::maxPlayers) == 0);
@ -561,29 +578,71 @@ void World::update(){
// objects on the map from tilesets // objects on the map from tilesets
updateAllTilesetObjects(); updateAllTilesetObjects();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//units //units
if(getFactionCount() > 0) { if(getFactionCount() > 0) {
updateAllFactionUnits(); updateAllFactionUnits();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//undertake the dead //undertake the dead
underTakeDeadFactionUnits(); underTakeDeadFactionUnits();
//} //}
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//food costs //food costs
updateAllFactionConsumableCosts(); updateAllFactionConsumableCosts();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//fow smoothing //fow smoothing
if(fogOfWarSmoothing && ((frameCount+1) % (fogOfWarSmoothingFrameSkip+1))==0) { if(fogOfWarSmoothing && ((frameCount+1) % (fogOfWarSmoothingFrameSkip+1))==0) {
float fogFactor= static_cast<float>(frameCount % GameConstants::updateFps) / GameConstants::updateFps; float fogFactor= static_cast<float>(frameCount % GameConstants::updateFps) / GameConstants::updateFps;
minimap.updateFowTex(clamp(fogFactor, 0.f, 1.f)); minimap.updateFowTex(clamp(fogFactor, 0.f, 1.f));
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//tick //tick
bool needToTick = canTickWorld(); bool needToTick = canTickWorld();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(needToTick == true) { if(needToTick == true) {
//printf("=========== World is about to be updated, current frameCount = %d\n",frameCount); //printf("=========== World is about to be updated, current frameCount = %d\n",frameCount);
tick(); tick();
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
}
if(showPerfStats && chronoPerf.getMillis() >= 50) {
for(unsigned int x = 0; x < perfList.size(); ++x) {
printf("%s",perfList[x].c_str());
}
} }
} }
@ -625,6 +684,12 @@ int World::tickFactionIndex() {
} }
void World::tick() { void World::tick() {
bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
Chrono chronoPerf;
char perfBuf[8096]="";
std::vector<string> perfList;
if(showPerfStats) chronoPerf.start();
int factionIdxToTick = -1; int factionIdxToTick = -1;
if(staggeredFactionUpdates == true) { if(staggeredFactionUpdates == true) {
factionIdxToTick = tickFactionIndex(); factionIdxToTick = tickFactionIndex();
@ -632,23 +697,36 @@ void World::tick() {
return; return;
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
computeFow(factionIdxToTick); computeFow(factionIdxToTick);
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " fogOfWar: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis(),fogOfWar);
perfList.push_back(perfBuf);
}
if(factionIdxToTick == -1 || factionIdxToTick == 0) { if(factionIdxToTick == -1 || factionIdxToTick == 0) {
if(fogOfWarSmoothing == false) { if(fogOfWarSmoothing == false) {
minimap.updateFowTex(1.f); minimap.updateFowTex(1.f);
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//increase hp //increase hp
//int i = factionIdxToTick; //int i = factionIdxToTick;
int factionCount = getFactionCount(); int factionCount = getFactionCount();
for(int i = 0; i < factionCount; ++i) { for(int i = 0; i < factionCount; ++i) {
if(factionIdxToTick == -1 || i == factionIdxToTick) { if(factionIdxToTick == -1 || i == factionIdxToTick) {
Faction *faction = getFaction(i); Faction *faction = getFaction(i);
if(faction == NULL) {
throw megaglest_runtime_error("faction == NULL");
}
int unitCount = faction->getUnitCount(); int unitCount = faction->getUnitCount();
for(int j = 0; j < unitCount; ++j) { for(int j = 0; j < unitCount; ++j) {
@ -662,15 +740,17 @@ void World::tick() {
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//compute resources balance //compute resources balance
//int k = factionIdxToTick; //int k = factionIdxToTick;
factionCount = getFactionCount(); factionCount = getFactionCount();
for(int k = 0; k < factionCount; ++k) { for(int k = 0; k < factionCount; ++k) {
if(factionIdxToTick == -1 || k == factionIdxToTick) { if(factionIdxToTick == -1 || k == factionIdxToTick) {
Faction *faction= getFaction(k); Faction *faction= getFaction(k);
if(faction == NULL) {
throw megaglest_runtime_error("faction == NULL");
}
//for each resource //for each resource
for(int i = 0; i < techTree->getResourceTypeCount(); ++i) { for(int i = 0; i < techTree->getResourceTypeCount(); ++i) {
@ -695,6 +775,17 @@ void World::tick() {
} }
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(showPerfStats && chronoPerf.getMillis() >= 50) {
for(unsigned int x = 0; x < perfList.size(); ++x) {
printf("%s",perfList[x].c_str());
}
}
} }
Unit* World::findUnitById(int id) const { Unit* World::findUnitById(int id) const {
@ -2001,8 +2092,19 @@ bool World::showWorldForPlayer(int factionIndex) const {
//computes the fog of war texture, contained in the minimap //computes the fog of war texture, contained in the minimap
void World::computeFow(int factionIdxToTick) { void World::computeFow(int factionIdxToTick) {
bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
Chrono chronoPerf;
char perfBuf[8096]="";
std::vector<string> perfList;
if(showPerfStats) chronoPerf.start();
minimap.resetFowTex(); minimap.resetFowTex();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//reset cells //reset cells
if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) { if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
for(int i = 0; i < map.getSurfaceW(); ++i) { for(int i = 0; i < map.getSurfaceW(); ++i) {
@ -2075,6 +2177,11 @@ void World::computeFow(int factionIdxToTick) {
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//compute cells //compute cells
for(int i=0; i<getFactionCount(); ++i) { for(int i=0; i<getFactionCount(); ++i) {
if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) { if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
@ -2087,6 +2194,11 @@ void World::computeFow(int factionIdxToTick) {
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//fire //fire
for(int i=0; i<getFactionCount(); ++i) { for(int i=0; i<getFactionCount(); ++i) {
if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) { if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
@ -2107,6 +2219,11 @@ void World::computeFow(int factionIdxToTick) {
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
//compute texture //compute texture
//printf("Masterserver = %d\n",game->isMasterserverMode()); //printf("Masterserver = %d\n",game->isMasterserverMode());
@ -2181,6 +2298,18 @@ void World::computeFow(int factionIdxToTick) {
} }
} }
} }
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(showPerfStats && chronoPerf.getMillis() >= 50) {
for(unsigned int x = 0; x < perfList.size(); ++x) {
printf("%s",perfList[x].c_str());
}
}
} }
GameSettings * World::getGameSettingsPtr() { GameSettings * World::getGameSettingsPtr() {

View File

@ -85,7 +85,7 @@ public:
bool hasString(const string &key) const; bool hasString(const string &key) const;
static bool applyTagsToValue(string &value, std::map<string,string> *mapTagReplacementValues=NULL); static bool applyTagsToValue(string &value, const std::map<string,string> *mapTagReplacementValues=NULL);
static std::map<string,string> getTagReplacementValues(std::map<string,string> *mapExtraTagReplacementValues=NULL); static std::map<string,string> getTagReplacementValues(std::map<string,string> *mapExtraTagReplacementValues=NULL);
string getpath() const { return path;} string getpath() const { return path;}

View File

@ -64,7 +64,7 @@ public:
~XmlIo(); ~XmlIo();
void cleanup(); void cleanup();
XmlNode *load(const string &path, std::map<string,string> mapTagReplacementValues,bool noValidation=false, bool skipStackCheck=false); XmlNode *load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation=false, bool skipStackCheck=false);
void save(const string &path, const XmlNode *node); void save(const string &path, const XmlNode *node);
}; };
@ -81,7 +81,7 @@ public:
~XmlIoRapid(); ~XmlIoRapid();
void cleanup(); void cleanup();
XmlNode *load(const string &path, std::map<string,string> mapTagReplacementValues,bool noValidation=false,bool skipStackCheck=false); XmlNode *load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation=false,bool skipStackCheck=false);
void save(const string &path, const XmlNode *node); void save(const string &path, const XmlNode *node);
}; };
@ -104,7 +104,7 @@ public:
~XmlTree(); ~XmlTree();
void init(const string &name); void init(const string &name);
void load(const string &path, std::map<string,string> mapTagReplacementValues, bool noValidation=false,bool skipStackCheck=false); void load(const string &path, const std::map<string,string> &mapTagReplacementValues, bool noValidation=false,bool skipStackCheck=false);
void save(const string &path); void save(const string &path);
XmlNode *getRootNode() const {return rootNode;} XmlNode *getRootNode() const {return rootNode;}
@ -127,8 +127,8 @@ private:
void operator =(XmlNode&); void operator =(XmlNode&);
public: public:
XmlNode(XERCES_CPP_NAMESPACE::DOMNode *node, std::map<string,string> mapTagReplacementValues); XmlNode(XERCES_CPP_NAMESPACE::DOMNode *node, const std::map<string,string> &mapTagReplacementValues);
XmlNode(xml_node<> *node, std::map<string,string> mapTagReplacementValues); XmlNode(xml_node<> *node, const std::map<string,string> &mapTagReplacementValues);
XmlNode(const string &name); XmlNode(const string &name);
~XmlNode(); ~XmlNode();
@ -152,7 +152,7 @@ public:
XmlNode *addChild(const string &name); XmlNode *addChild(const string &name);
XmlAttribute *addAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues); XmlAttribute *addAttribute(const string &name, const string &value, const std::map<string,string> &mapTagReplacementValues);
XERCES_CPP_NAMESPACE::DOMElement *buildElement(XERCES_CPP_NAMESPACE::DOMDocument *document) const; XERCES_CPP_NAMESPACE::DOMElement *buildElement(XERCES_CPP_NAMESPACE::DOMDocument *document) const;
xml_node<>* buildElement(xml_document<> *document) const; xml_node<>* buildElement(xml_document<> *document) const;
@ -179,9 +179,9 @@ private:
void operator =(XmlAttribute&); void operator =(XmlAttribute&);
public: public:
XmlAttribute(XERCES_CPP_NAMESPACE::DOMNode *attribute, std::map<string,string> mapTagReplacementValues); XmlAttribute(XERCES_CPP_NAMESPACE::DOMNode *attribute, const std::map<string,string> &mapTagReplacementValues);
XmlAttribute(xml_attribute<> *attribute, std::map<string,string> mapTagReplacementValues); XmlAttribute(xml_attribute<> *attribute, const std::map<string,string> &mapTagReplacementValues);
XmlAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues); XmlAttribute(const string &name, const string &value, const std::map<string,string> &mapTagReplacementValues);
public: public:
const string getName() const {return name;} const string getName() const {return name;}

View File

@ -248,7 +248,7 @@ std::map<string,string> Properties::getTagReplacementValues(std::map<string,stri
return mapTagReplacementValues; return mapTagReplacementValues;
} }
bool Properties::applyTagsToValue(string &value, std::map<string,string> *mapTagReplacementValues) { bool Properties::applyTagsToValue(string &value, const std::map<string,string> *mapTagReplacementValues) {
string originalValue = value; string originalValue = value;
//if(originalValue.find("$APPLICATIONDATAPATH") != string::npos) { //if(originalValue.find("$APPLICATIONDATAPATH") != string::npos) {
@ -256,7 +256,7 @@ bool Properties::applyTagsToValue(string &value, std::map<string,string> *mapTag
//} //}
if(mapTagReplacementValues != NULL) { if(mapTagReplacementValues != NULL) {
for(std::map<string,string>::iterator iterMap = mapTagReplacementValues->begin(); for(std::map<string,string>::const_iterator iterMap = mapTagReplacementValues->begin();
iterMap != mapTagReplacementValues->end(); ++iterMap) { iterMap != mapTagReplacementValues->end(); ++iterMap) {
replaceAll(value, iterMap->first, iterMap->second); replaceAll(value, iterMap->first, iterMap->second);
} }

View File

@ -105,7 +105,7 @@ XmlIo::~XmlIo() {
cleanup(); cleanup();
} }
XmlNode *XmlIo::load(const string &path, std::map<string,string> mapTagReplacementValues,bool noValidation,bool skipStackCheck) { XmlNode *XmlIo::load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation,bool skipStackCheck) {
//printf("Load file using Xerces engine [%s]\n",path.c_str()); //printf("Load file using Xerces engine [%s]\n",path.c_str());
try { try {
@ -264,10 +264,11 @@ XmlIoRapid::~XmlIoRapid() {
cleanup(); cleanup();
} }
XmlNode *XmlIoRapid::load(const string &path, std::map<string,string> mapTagReplacementValues,bool noValidation,bool skipStackCheck) { XmlNode *XmlIoRapid::load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation,bool skipStackCheck) {
bool showPerfStats = SystemFlags::VERBOSE_MODE_ENABLED;
Chrono chrono; Chrono chrono;
chrono.start(); chrono.start();
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Using RapidXml to load file [%s]\n",path.c_str()); if(SystemFlags::VERBOSE_MODE_ENABLED || showPerfStats) printf("Using RapidXml to load file [%s]\n",path.c_str());
//printf("Using RapidXml to load file [%s]\n",path.c_str()); //printf("Using RapidXml to load file [%s]\n",path.c_str());
XmlNode *rootNode = NULL; XmlNode *rootNode = NULL;
@ -282,6 +283,8 @@ XmlNode *XmlIoRapid::load(const string &path, std::map<string,string> mapTagRepl
throw megaglest_runtime_error("Can not open file: [" + path + "]"); throw megaglest_runtime_error("Can not open file: [" + path + "]");
} }
if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
xmlFile.unsetf(ios::skipws); xmlFile.unsetf(ios::skipws);
// Determine stream size // Determine stream size
@ -289,19 +292,30 @@ XmlNode *XmlIoRapid::load(const string &path, std::map<string,string> mapTagRepl
streampos size = xmlFile.tellg(); streampos size = xmlFile.tellg();
xmlFile.seekg(0); xmlFile.seekg(0);
if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
// Load data and add terminating 0 // Load data and add terminating 0
vector<char> buffer; vector<char> buffer;
buffer.resize((unsigned int)size + 1); buffer.resize((unsigned int)size + 1);
xmlFile.read(&buffer.front(), static_cast<streamsize>(size)); xmlFile.read(&buffer.front(), static_cast<streamsize>(size));
buffer[(unsigned int)size] = 0; buffer[(unsigned int)size] = 0;
if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
// This is required because rapidxml seems to choke when we load lua // This is required because rapidxml seems to choke when we load lua
// scenarios that have lua + xml style comments // scenarios that have lua + xml style comments
replaceAllBetweenTokens(buffer, "<!--","-->", "", true); replaceAllBetweenTokens(buffer, "<!--","-->", "", true);
if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
doc->parse<parse_no_data_nodes>(&buffer.front()); doc->parse<parse_no_data_nodes>(&buffer.front());
if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
rootNode= new XmlNode(doc->first_node(),mapTagReplacementValues); rootNode= new XmlNode(doc->first_node(),mapTagReplacementValues);
if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
#if defined(WIN32) && !defined(__MINGW32__) #if defined(WIN32) && !defined(__MINGW32__)
if(fp) { if(fp) {
fclose(fp); fclose(fp);
@ -402,7 +416,7 @@ typedef std::vector<XmlTree*> LoadStack;
//static LoadStack loadStack; //static LoadStack loadStack;
static string loadStackCacheName = string(__FILE__) + string("_loadStackCacheName"); static string loadStackCacheName = string(__FILE__) + string("_loadStackCacheName");
void XmlTree::load(const string &path, std::map<string,string> mapTagReplacementValues, bool noValidation,bool skipStackCheck) { void XmlTree::load(const string &path, const std::map<string,string> &mapTagReplacementValues, bool noValidation,bool skipStackCheck) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s] skipStackCheck = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),skipStackCheck); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s] skipStackCheck = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),skipStackCheck);
this->skipStackCheck = skipStackCheck; this->skipStackCheck = skipStackCheck;
@ -465,7 +479,7 @@ XmlTree::~XmlTree() {
// class XmlNode // class XmlNode
// ===================================================== // =====================================================
XmlNode::XmlNode(DOMNode *node, std::map<string,string> mapTagReplacementValues): superNode(NULL) { XmlNode::XmlNode(DOMNode *node, const std::map<string,string> &mapTagReplacementValues): superNode(NULL) {
if(node == NULL || node->getNodeName() == NULL) { if(node == NULL || node->getNodeName() == NULL) {
throw megaglest_runtime_error("XML structure seems to be corrupt!"); throw megaglest_runtime_error("XML structure seems to be corrupt!");
} }
@ -512,13 +526,15 @@ XmlNode::XmlNode(DOMNode *node, std::map<string,string> mapTagReplacementValues)
} }
} }
XmlNode::XmlNode(xml_node<> *node, std::map<string,string> mapTagReplacementValues) : superNode(NULL) { XmlNode::XmlNode(xml_node<> *node, const std::map<string,string> &mapTagReplacementValues) : superNode(NULL) {
if(node == NULL || node->name() == NULL) { if(node == NULL || node->name() == NULL) {
throw megaglest_runtime_error("XML structure seems to be corrupt!"); throw megaglest_runtime_error("XML structure seems to be corrupt!");
} }
//get name //get name
name = node->name(); name = node->name();
children.reserve(1000);
attributes.reserve(1000);
//check document //check document
if(node->type() == node_document) { if(node->type() == node_document) {
@ -546,7 +562,7 @@ XmlNode::XmlNode(xml_node<> *node, std::map<string,string> mapTagReplacementValu
//get value //get value
if(node->type() == node_element && children.size() == 0) { if(node->type() == node_element && children.size() == 0) {
text = node->value(); text = node->value();
Properties::applyTagsToValue(this->text); Properties::applyTagsToValue(this->text,&mapTagReplacementValues);
} }
} }
@ -670,7 +686,7 @@ XmlNode *XmlNode::addChild(const string &name){
return node; return node;
} }
XmlAttribute *XmlNode::addAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues) { XmlAttribute *XmlNode::addAttribute(const string &name, const string &value, const std::map<string,string> &mapTagReplacementValues) {
XmlAttribute *attr= new XmlAttribute(name, value, mapTagReplacementValues); XmlAttribute *attr= new XmlAttribute(name, value, mapTagReplacementValues);
attributes.push_back(attr); attributes.push_back(attr);
return attr; return attr;
@ -737,7 +753,7 @@ string XmlNode::getTreeString() const {
// class XmlAttribute // class XmlAttribute
// ===================================================== // =====================================================
XmlAttribute::XmlAttribute(DOMNode *attribute, std::map<string,string> mapTagReplacementValues) { XmlAttribute::XmlAttribute(DOMNode *attribute, const std::map<string,string> &mapTagReplacementValues) {
skipRestrictionCheck = false; skipRestrictionCheck = false;
usesCommondata = false; usesCommondata = false;
this->mapTagReplacementValues = mapTagReplacementValues; this->mapTagReplacementValues = mapTagReplacementValues;
@ -752,10 +768,12 @@ XmlAttribute::XmlAttribute(DOMNode *attribute, std::map<string,string> mapTagRep
name= str; name= str;
} }
XmlAttribute::XmlAttribute(xml_attribute<> *attribute, std::map<string,string> mapTagReplacementValues) { XmlAttribute::XmlAttribute(xml_attribute<> *attribute, const std::map<string,string> &mapTagReplacementValues) {
skipRestrictionCheck = false; skipRestrictionCheck = false;
usesCommondata = false; usesCommondata = false;
this->mapTagReplacementValues = mapTagReplacementValues; if(mapTagReplacementValues.size() > 0) {
this->mapTagReplacementValues = mapTagReplacementValues;
}
//char str[strSize] = ""; //char str[strSize] = "";
//XMLString::transcode(attribute->getNodeValue(), str, strSize-1); //XMLString::transcode(attribute->getNodeValue(), str, strSize-1);
@ -767,10 +785,12 @@ XmlAttribute::XmlAttribute(xml_attribute<> *attribute, std::map<string,string> m
name= attribute->name(); name= attribute->name();
} }
XmlAttribute::XmlAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues) { XmlAttribute::XmlAttribute(const string &name, const string &value, const std::map<string,string> &mapTagReplacementValues) {
skipRestrictionCheck = false; skipRestrictionCheck = false;
usesCommondata = false; usesCommondata = false;
this->mapTagReplacementValues = mapTagReplacementValues; if(mapTagReplacementValues.size() > 0) {
this->mapTagReplacementValues = mapTagReplacementValues;
}
this->name = name; this->name = name;
this->value = value; this->value = value;