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 All 16 Lines | |||||
#include "simulation2/components/ICmpOwnership.h" | #include "simulation2/components/ICmpOwnership.h" | ||||
#include "simulation2/components/ICmpRangeManager.h" | #include "simulation2/components/ICmpRangeManager.h" | ||||
#include "simulation2/components/ICmpTemplateManager.h" | #include "simulation2/components/ICmpTemplateManager.h" | ||||
#include "simulation2/components/ICmpSelectable.h" | #include "simulation2/components/ICmpSelectable.h" | ||||
#include "simulation2/components/ICmpVisual.h" | #include "simulation2/components/ICmpVisual.h" | ||||
#include "simulation2/components/ICmpUnitRenderer.h" | #include "simulation2/components/ICmpUnitRenderer.h" | ||||
#include "simulation2/system/ComponentManager.h" | #include "simulation2/system/ComponentManager.h" | ||||
#include <string_view> | |||||
entity_id_t EntitySelection::PickEntityAtPoint(CSimulation2& simulation, const CCamera& camera, int screenX, int screenY, player_id_t player, bool allowEditorSelectables) | entity_id_t EntitySelection::PickEntityAtPoint(CSimulation2& simulation, const CCamera& camera, int screenX, int screenY, player_id_t player, bool allowEditorSelectables) | ||||
{ | { | ||||
PROFILE2("PickEntityAtPoint"); | PROFILE2("PickEntityAtPoint"); | ||||
CVector3D origin, dir; | CVector3D origin, dir; | ||||
camera.BuildCameraRay(screenX, screenY, origin, dir); | camera.BuildCameraRay(screenX, screenY, origin, dir); | ||||
CmpPtr<ICmpUnitRenderer> cmpUnitRenderer(simulation.GetSimContext().GetSystemEntity()); | CmpPtr<ICmpUnitRenderer> cmpUnitRenderer(simulation.GetSimContext().GetSystemEntity()); | ||||
ENSURE(cmpUnitRenderer); | ENSURE(cmpUnitRenderer); | ||||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | for (CSimulation2::InterfaceListUnordered::const_iterator it = ents.begin(); it != ents.end(); ++it) | ||||
// 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*>(it->second)->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); | const std::string curTemplateName = cmpTemplateManager->GetCurrentTemplateName(ent); | ||||
Stan: Can you create a std::string_view directly? | |||||
Done Inline ActionsNo, it would be dangling phosit: No, it would be dangling | |||||
Done Inline Actionsconst. vladislavbelov: `const`. | |||||
bool matches = (curTemplateName == templateName || | bool matches = (curTemplateName == templateName || | ||||
(allowFoundations && curTemplateName.substr(0, 11) == "foundation|" && curTemplateName.substr(11) == templateName)); | (allowFoundations && | ||||
std::string_view{curTemplateName}.substr(0, 11) == "foundation|" && | |||||
std::string_view{curTemplateName}.substr(11) == templateName)); | |||||
if (!matches) | if (!matches) | ||||
continue; | continue; | ||||
} | } | ||||
// Ignore entities hidden by LOS (or otherwise hidden, e.g. when not IsInWorld) | // Ignore entities hidden by LOS (or otherwise hidden, e.g. when not IsInWorld) | ||||
// In this case, the checking is done to avoid selecting garrisoned units | // In this case, the checking is done to avoid selecting garrisoned units | ||||
if (cmpRangeManager->GetLosVisibility(handle, owner) == LosVisibility::HIDDEN) | if (cmpRangeManager->GetLosVisibility(handle, owner) == LosVisibility::HIDDEN) | ||||
continue; | continue; | ||||
Show All 34 Lines |
Wildfire Games · Phabricator
Can you create a std::string_view directly?