Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SelectedUnitsHandler be a bit smarter about updating. #1825

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions rts/Game/SelectedUnitsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,37 +400,44 @@ void CSelectedUnitsHandler::AddUnit(CUnit* unit)
if (unit->noSelect)
return;

if (selectedUnits.insert(unit->id).second)
if (selectedUnits.insert(unit->id).second) {
AddDeathDependence(unit, DEPENDENCE_SELECTED);

selectionChanged = true;
possibleCommandsChanged = true;
selectionChanged = true;
possibleCommandsChanged = true;

const CGroup* g = unit->GetGroup();
const CGroup* g = unit->GetGroup();

if (g == nullptr || g->id != selectedGroup)
selectedGroup = -1;
if (g == nullptr || g->id != selectedGroup)
selectedGroup = -1;

unit->isSelected = true;
unit->isSelected = true;
}
}


void CSelectedUnitsHandler::RemoveUnit(CUnit* unit)
{
RECOIL_DETAILED_TRACY_ZONE;
if (selectedUnits.erase(unit->id))
if (selectedUnits.erase(unit->id)) {
DeleteDeathDependence(unit, DEPENDENCE_SELECTED);

selectionChanged = true;
possibleCommandsChanged = true;
selectedGroup = -1;
unit->isSelected = false;
selectionChanged = true;
possibleCommandsChanged = true;
selectedGroup = -1;
unit->isSelected = false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how unit->isSelected was hard-guaranteed false previously. I'd keep something like else assert(!unit->isSelected);

}


void CSelectedUnitsHandler::ClearSelected()
{
RECOIL_DETAILED_TRACY_ZONE;

if (selectedUnits.empty()) {
return;
}

for (const int unitID: selectedUnits) {
CUnit* u = unitHandler.GetUnit(unitID);

Expand Down Expand Up @@ -482,8 +489,10 @@ void CSelectedUnitsHandler::SelectGroup(int num)
}
}

selectionChanged = true;
possibleCommandsChanged = true;
if (!selectedUnits.empty()) {
selectionChanged = true;
possibleCommandsChanged = true;
}
}


Expand Down