Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/helpers/Selection.cpp
/* Copyright (C) 2020 Wildfire Games. | /* Copyright (C) 2022 Wildfire Games. | |||||||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | |||||||||
* | * | |||||||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | |||||||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | |||||||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | |||||||||
* (at your option) any later version. | * (at your option) any later version. | |||||||||
* | * | |||||||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | |||||||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | if (owner != INVALID_PLAYER) | |||||||||
for (std::vector<entity_id_t>::iterator it = ents.begin(); it != ents.end(); ++it) | for (std::vector<entity_id_t>::iterator it = ents.begin(); it != ents.end(); ++it) | |||||||||
{ | { | |||||||||
if (CheckEntityVisibleAndInRect(componentManager.LookupEntityHandle(*it), cmpRangeManager, camera, sx0, sy0, sx1, sy1, owner, allowEditorSelectables)) | if (CheckEntityVisibleAndInRect(componentManager.LookupEntityHandle(*it), cmpRangeManager, camera, sx0, sy0, sx1, sy1, owner, allowEditorSelectables)) | |||||||||
hitEnts.push_back(*it); | hitEnts.push_back(*it); | |||||||||
} | } | |||||||||
} | } | |||||||||
else // owner == INVALID_PLAYER; Used when selecting units in Atlas or other mods that allow all kinds of selectables to be selected. | else // owner == INVALID_PLAYER; Used when selecting units in Atlas or other mods that allow all kinds of selectables to be selected. | |||||||||
{ | { | |||||||||
const CSimulation2::InterfaceListUnordered& selectableEnts = simulation.GetEntitiesWithInterfaceUnordered(IID_Selectable); | SComponentDataGenerator gen = simulation.GetComponentsByInterfaceUnordered(IID_Selectable); | |||||||||
for (CSimulation2::InterfaceListUnordered::const_iterator it = selectableEnts.begin(); it != selectableEnts.end(); ++it) | while (IComponent* cmp = gen.Next()) | |||||||||
{ | { | |||||||||
if (CheckEntityVisibleAndInRect(it->second->GetEntityHandle(), cmpRangeManager, camera, sx0, sy0, sx1, sy1, owner, allowEditorSelectables)) | if (CheckEntityVisibleAndInRect(cmp->GetEntityHandle(), cmpRangeManager, camera, sx0, sy0, sx1, sy1, owner, allowEditorSelectables)) | |||||||||
hitEnts.push_back(it->first); | hitEnts.push_back(cmp->GetEntityId()); | |||||||||
} | } | |||||||||
} | } | |||||||||
return hitEnts; | return hitEnts; | |||||||||
} | } | |||||||||
std::vector<entity_id_t> EntitySelection::PickNonGaiaEntitiesInRect(CSimulation2& simulation, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, bool allowEditorSelectables) | std::vector<entity_id_t> EntitySelection::PickNonGaiaEntitiesInRect(CSimulation2& simulation, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, bool allowEditorSelectables) | |||||||||
{ | { | |||||||||
Show All 23 Lines | std::vector<entity_id_t> EntitySelection::PickSimilarEntities(CSimulation2& simulation, const CCamera& camera, | |||||||||
bool allowEditorSelectables, bool allowFoundations) | bool allowEditorSelectables, bool allowFoundations) | |||||||||
{ | { | |||||||||
PROFILE2("PickSimilarEntities"); | PROFILE2("PickSimilarEntities"); | |||||||||
CmpPtr<ICmpTemplateManager> cmpTemplateManager(simulation, SYSTEM_ENTITY); | CmpPtr<ICmpTemplateManager> cmpTemplateManager(simulation, SYSTEM_ENTITY); | |||||||||
CmpPtr<ICmpRangeManager> cmpRangeManager(simulation, SYSTEM_ENTITY); | CmpPtr<ICmpRangeManager> cmpRangeManager(simulation, SYSTEM_ENTITY); | |||||||||
std::vector<entity_id_t> hitEnts; | std::vector<entity_id_t> hitEnts; | |||||||||
const CSimulation2::InterfaceListUnordered& ents = simulation.GetEntitiesWithInterfaceUnordered(IID_Selectable); | SComponentDataGenerator gen = simulation.GetComponentsByInterfaceUnordered(IID_Selectable); | |||||||||
for (CSimulation2::InterfaceListUnordered::const_iterator it = ents.begin(); it != ents.end(); ++it) | while (IComponent* cmp = gen.Next()) | |||||||||
StanUnsubmitted Done Inline Actions
Stan: | ||||||||||
{ | { | |||||||||
entity_id_t ent = it->first; | CEntityHandle handle = cmp->GetEntityHandle(); | |||||||||
CEntityHandle handle = it->second->GetEntityHandle(); | entity_id_t ent = handle.GetId(); | |||||||||
Done Inline ActionsDon't need those two before the if I suppose. Stan: Don't need those two before the if I suppose. | ||||||||||
// Check if this entity is only selectable in Atlas | // Check if this entity is only selectable in Atlas | |||||||||
if (static_cast<ICmpSelectable*>(it->second)->IsEditorOnly() && !allowEditorSelectables) | if (static_cast<ICmpSelectable*>(cmp)->IsEditorOnly() && !allowEditorSelectables) | |||||||||
continue; | continue; | |||||||||
if (matchRank) | if (matchRank) | |||||||||
{ | { | |||||||||
// Exact template name matching, optionally also allowing foundations | // Exact template name matching, optionally also allowing foundations | |||||||||
std::string curTemplateName = cmpTemplateManager->GetCurrentTemplateName(ent); | std::string curTemplateName = cmpTemplateManager->GetCurrentTemplateName(ent); | |||||||||
bool matches = (curTemplateName == templateName || | bool matches = (curTemplateName == templateName || | |||||||||
(allowFoundations && curTemplateName.substr(0, 11) == "foundation|" && curTemplateName.substr(11) == templateName)); | (allowFoundations && curTemplateName.substr(0, 11) == "foundation|" && curTemplateName.substr(11) == templateName)); | |||||||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator