Skip to content

Commit

Permalink
Added mod rule pfForceUpdateSingleThreaded to force pathing vertex up…
Browse files Browse the repository at this point in the history
…dates to be handled single threaded during a match.
  • Loading branch information
marcushutchings authored and lhog committed Nov 30, 2022
1 parent 64b24c6 commit 65a8413
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
2 changes: 2 additions & 0 deletions rts/Sim/Misc/ModInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void CModInfo::ResetState()
pfRawDistMult = 1.25f;
pfUpdateRate = 0.007f;
pfForceSingleThreaded = false;
pfForceUpdateSingleThreaded = false;

enableSmoothMesh = true;
quadFieldQuadSizeInElmos = 128;
Expand Down Expand Up @@ -149,6 +150,7 @@ void CModInfo::Init(const std::string& modFileName)
pfRawDistMult = system.GetFloat("pathFinderRawDistMult", pfRawDistMult);
pfUpdateRate = system.GetFloat("pathFinderUpdateRate", pfUpdateRate);
pfForceSingleThreaded = system.GetBool("pfForceSingleThreaded", pfForceSingleThreaded);
pfForceUpdateSingleThreaded = system.GetBool("pfForceUpdateSingleThreaded", pfForceUpdateSingleThreaded);

enableSmoothMesh = system.GetBool("enableSmoothMesh", enableSmoothMesh);

Expand Down
1 change: 1 addition & 0 deletions rts/Sim/Misc/ModInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class CModInfo
/// which pathfinder system (NOP, DEFAULT/legacy, or QT) the mod will use
int pathFinderSystem;
bool pfForceSingleThreaded;
bool pfForceUpdateSingleThreaded;

float pfRawDistMult;
float pfUpdateRate;
Expand Down
2 changes: 1 addition & 1 deletion rts/Sim/Path/TKPFS/PathManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void CPathManager::InitStatic()

pathFinderGroups = ThreadPool::GetNumThreads();

LOG("TK CPathManager::InitStatic: %d threads available (MT permitted %d)", pathFinderGroups, SupportsMultiThreadedRequests());
LOG("TK CPathManager::InitStatic: %d threads available (MT requests=%d, MT updates=%d)", pathFinderGroups, SupportsMultiThreadedRequests(), !modInfo.pfForceUpdateSingleThreaded);

// pathFinders[i] = pfMemPool.alloc<CPathFinder>(true);

Expand Down
41 changes: 27 additions & 14 deletions rts/Sim/Path/TKPFS/PathingState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,13 +718,20 @@ void PathingState::UpdateVertexPathCosts(int blocksToUpdate)
// FindOffset (threadsafe)
{
SCOPED_TIMER("Sim::Path::Estimator::FindOffset");
for_mt(0, consumedBlocks.size(), [&](const int n) {
// copy the next block in line
const SingleBlock sb = consumedBlocks[n];
const int blockN = BlockPosToIdx(sb.blockPos);
const MoveDef* currBlockMD = sb.moveDef;
blockStates.peNodeOffsets[currBlockMD->pathType][blockN] = FindBlockPosOffset(*currBlockMD, sb.blockPos.x, sb.blockPos.y);
});

auto updateOffset = [&](const int n) {
// copy the next block in line
const SingleBlock sb = consumedBlocks[n];
const int blockN = BlockPosToIdx(sb.blockPos);
const MoveDef* currBlockMD = sb.moveDef;
blockStates.peNodeOffsets[currBlockMD->pathType][blockN] = FindBlockPosOffset(*currBlockMD, sb.blockPos.x, sb.blockPos.y);
};

if (modInfo.pfForceUpdateSingleThreaded) {
for(int i = 0; i < consumedBlocks.size(); ++i) { updateOffset(i); };
} else {
for_mt(0, consumedBlocks.size(), updateOffset);
}

// for (int n=0; n<consumedBlocks.size(); n++){
// const SingleBlock sb = consumedBlocks[n];
Expand All @@ -743,13 +750,19 @@ void PathingState::UpdateVertexPathCosts(int blocksToUpdate)
std::atomic<std::int64_t> updateCostBlockNum = consumedBlocks.size();
const size_t threadsUsed = std::min(consumedBlocks.size(), (size_t)ThreadPool::GetNumThreads());

for_mt(0, threadsUsed, [this, &updateCostBlockNum](int threadNum){
std::int64_t n;
while ((n = --updateCostBlockNum) >= 0){
//LOG("TK PathingState::Update: PROC moveDef = %d %p (%p)", n, &consumedBlocks[n], consumedBlocks[n].moveDef);
CalcVertexPathCosts(*consumedBlocks[n].moveDef, consumedBlocks[n].blockPos, threadNum);
}
});
auto updateVertexPathCosts = [this, &updateCostBlockNum](int threadNum){
std::int64_t n;
while ((n = --updateCostBlockNum) >= 0){
//LOG("TK PathingState::Update: PROC moveDef = %d %p (%p)", n, &consumedBlocks[n], consumedBlocks[n].moveDef);
CalcVertexPathCosts(*consumedBlocks[n].moveDef, consumedBlocks[n].blockPos, threadNum);
}
};

if (modInfo.pfForceUpdateSingleThreaded) {
updateVertexPathCosts(0);
} else {
for_mt(0, threadsUsed, updateVertexPathCosts);
}
}
}

Expand Down

0 comments on commit 65a8413

Please sign in to comment.