Skip to content

Commit

Permalink
sort can be implemented differently on different compilers
Browse files Browse the repository at this point in the history
synced code needs to use stable_sort
Fix desync from #5313
  • Loading branch information
ashdnazg committed Jul 27, 2016
1 parent d249d5d commit 98a5a80
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rts/Game/GameHelper.cpp
Expand Up @@ -871,7 +871,7 @@ static const vector<SearchOffset>& GetSearchOffsetTable (int radius)
i.qdist = i.dx*i.dx + i.dy*i.dy;
}

std::sort(searchOffsets.begin(), searchOffsets.end(), SearchOffsetComparator);
std::stable_sort(searchOffsets.begin(), searchOffsets.end(), SearchOffsetComparator);
}

return searchOffsets;
Expand Down Expand Up @@ -1161,7 +1161,7 @@ CGameHelper::BuildSquareStatus CGameHelper::TestBuildSquare(

if (!buildingMaskMap->TestTileMaskUnsafe(sqx >> 1, sqz >> 1, mask))
return BUILDSQUARE_BLOCKED;


// check maxHeightDif constraint (structures only)
//
Expand Down
5 changes: 3 additions & 2 deletions rts/Game/SelectedUnitsAI.cpp
Expand Up @@ -538,14 +538,14 @@ void CSelectedUnitsHandlerAI::SelectAttack(const Command& cmd, int player)

for (unsigned int t = 0; t < targetsCount; t++) {
const CUnit* unit = unitHandler->units[ targets[t] ];
const float3 unitPos = queueing ? LastQueuePosition(unit) : float3(unit->midPos);
const float3 unitPos = float3(unit->midPos);

DistInfo di;
di.unitID = targets[t];
di.dist = (unitPos - midPos).SqLength2D();
distVec.push_back(di);
}
sort(distVec.begin(), distVec.end());
stable_sort(distVec.begin(), distVec.end());

// give the commands
for (unsigned int s = 0; s < selectedCount; s++) {
Expand All @@ -566,6 +566,7 @@ void CSelectedUnitsHandlerAI::SelectAttack(const Command& cmd, int player)

if (!queueing || !commandAI->WillCancelQueued(attackCmd)) {
commandAI->GiveCommand(attackCmd, false);

AddUnitSetMaxSpeedCommand(unit, attackCmd.options);
// following commands are always queued
attackCmd.options |= SHIFT_KEY;
Expand Down

0 comments on commit 98a5a80

Please sign in to comment.