Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/helpers/Selection.h
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2019 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, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#ifndef INCLUDED_SELECTION | #ifndef INCLUDED_SELECTION | ||||
#define INCLUDED_SELECTION | #define INCLUDED_SELECTION | ||||
/** | #include "simulation2/components/ICmpObstruction.h" | ||||
* @file | #include "simulation2/helpers/Player.h" | ||||
* Helper functions related to entity selection | #include "simulation2/Simulation2.h" | ||||
*/ | |||||
#include "simulation2/system/Entity.h" | #include "simulation2/system/Entity.h" | ||||
#include "Player.h" | |||||
#include <vector> | #include <vector> | ||||
class CSimulation2; | class CSimulation2; | ||||
class CCamera; | class CCamera; | ||||
bool CheckEntityInRect(CEntityHandle handle, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, bool allowEditorSelectables); | |||||
namespace EntitySelection | namespace EntitySelection | ||||
{ | { | ||||
/** | /** | ||||
* Finds all selectable entities under the given screen coordinates. | * Finds all selectable entities under the given screen coordinates. | ||||
* | * | ||||
* @param camera use this view to convert screen to world coordinates. | * @param camera use this view to convert screen to world coordinates. | ||||
* @param screenX,screenY 2D screen coordinates. | * @param screenX,screenY 2D screen coordinates. | ||||
Show All 24 Lines | |||||
/** | /** | ||||
* Finds all selectable entities within the given screen coordinate rectangle, | * Finds all selectable entities within the given screen coordinate rectangle, | ||||
* belonging to any given player (excluding Gaia). Used for status bars. | * belonging to any given player (excluding Gaia). Used for status bars. | ||||
*/ | */ | ||||
std::vector<entity_id_t> PickNonGaiaEntitiesInRect(CSimulation2& simulation, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, bool allowEditorSelectables); | std::vector<entity_id_t> PickNonGaiaEntitiesInRect(CSimulation2& simulation, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, bool allowEditorSelectables); | ||||
/** | /** | ||||
* Finds all entities with a given component belonging to any given player. | |||||
*/ | |||||
struct DefaultComponentFilter | |||||
{ | |||||
bool operator()(IComponent* UNUSED(cmp)) | |||||
{ | |||||
return true; | |||||
} | |||||
}; | |||||
template<typename Filter = DefaultComponentFilter> | |||||
std::vector<entity_id_t> GetEntitiesWithComponentInRect(CSimulation2& simulation, int cid, const CCamera& camera, int sx0, int sy0, int sx1, int sy1) | |||||
{ | |||||
PROFILE2("GetEntitiesWithObstructionInRect"); | |||||
// Make sure sx0 <= sx1, and sy0 <= sy1 | |||||
if (sx0 > sx1) | |||||
std::swap(sx0, sx1); | |||||
if (sy0 > sy1) | |||||
std::swap(sy0, sy1); | |||||
std::vector<entity_id_t> hitEnts; | |||||
Filter filter; | |||||
const CSimulation2::InterfaceListUnordered& entities = simulation.GetEntitiesWithInterfaceUnordered(cid); | |||||
for (const std::pair<const entity_id_t, IComponent*>& item : entities) | |||||
{ | |||||
if (!filter(item.second)) | |||||
continue; | |||||
if (CheckEntityInRect(item.second->GetEntityHandle(), camera, sx0, sy0, sx1, sy1, false)) | |||||
hitEnts.push_back(item.first); | |||||
} | |||||
return hitEnts; | |||||
} | |||||
/** | |||||
* Finds all entities with the given entity template name, belonging to the given player. | * Finds all entities with the given entity template name, belonging to the given player. | ||||
* | * | ||||
* @param camera use this view to convert screen to world coordinates. | * @param camera use this view to convert screen to world coordinates. | ||||
* @param templateName the name of the template to match, or the selection group name | * @param templateName the name of the template to match, or the selection group name | ||||
* for similar matching. | * for similar matching. | ||||
* @param owner player whose entities we are selecting. Ownership is ignored if | * @param owner player whose entities we are selecting. Ownership is ignored if | ||||
* INVALID_PLAYER is used. | * INVALID_PLAYER is used. | ||||
* @param includeOffScreen if true, then all entities visible in the world will be selected, | * @param includeOffScreen if true, then all entities visible in the world will be selected, | ||||
Show All 17 Lines |
Wildfire Games · Phabricator