Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/helpers/Selection.h
/* Copyright (C) 2019 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 66 Lines • ▼ Show 20 Lines | |||||
struct DefaultComponentFilter | struct DefaultComponentFilter | ||||
{ | { | ||||
bool operator()(IComponent* UNUSED(cmp)) | bool operator()(IComponent* UNUSED(cmp)) | ||||
{ | { | ||||
return true; | return true; | ||||
} | } | ||||
}; | }; | ||||
template<typename Filter = DefaultComponentFilter> | 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) | std::vector<entity_id_t> GetEntitiesWithComponentInRect(CSimulation2& simulation, int cid, const CCamera& camera, int sx0, int sy0, int sx1, int sy1) | ||||
Stan: Is this used at all? | |||||
Done Inline ActionsGetEntitiesWithComponentInRect is called on line 120 of simulation2/scripting/JSInterface_Simulation.cpp. Mercury: GetEntitiesWithComponentInRect is called on line 120 of… | |||||
{ | { | ||||
PROFILE2("GetEntitiesWithObstructionInRect"); | PROFILE2("GetEntitiesWithObstructionInRect"); | ||||
// Make sure sx0 <= sx1, and sy0 <= sy1 | // Make sure sx0 <= sx1, and sy0 <= sy1 | ||||
if (sx0 > sx1) | if (sx0 > sx1) | ||||
std::swap(sx0, sx1); | std::swap(sx0, sx1); | ||||
if (sy0 > sy1) | if (sy0 > sy1) | ||||
std::swap(sy0, sy1); | std::swap(sy0, sy1); | ||||
std::vector<entity_id_t> hitEnts; | std::vector<entity_id_t> hitEnts; | ||||
hitEnts.reserve(100); | |||||
Done Inline ActionsCan we resize it? Stan: Can we resize it? | |||||
Done Inline ActionsThat's a good idea, but seems out of scope of this patch? Mercury: That's a good idea, but seems out of scope of this patch? | |||||
Done Inline ActionsProbably. Since you were improving performance it seemed like a good candidate. Stan: Probably. Since you were improving performance it seemed like a good candidate. | |||||
Filter filter; | SComponentDataGenerator gen = simulation.GetComponentsByInterfaceUnordered(cid); | ||||
Done Inline ActionsWhat's the use of this, since it's a method that always returns true? Stan: What's the use of this, since it's a method that always returns true? | |||||
Done Inline ActionsWhich method? Mercury: Which method? | |||||
Done Inline ActionsFilter is by default default filter which does nothing. Stan: Filter is by default default filter which does nothing. | |||||
const CSimulation2::InterfaceListUnordered& entities = simulation.GetEntitiesWithInterfaceUnordered(cid); | while (IComponent* cmp = gen.Next()) | ||||
for (const std::pair<const entity_id_t, IComponent*>& item : entities) | if (CheckEntityInRect(cmp->GetEntityHandle(), camera, sx0, sy0, sx1, sy1, false)) | ||||
{ | hitEnts.push_back(cmp->GetEntityId()); | ||||
if (!filter(item.second)) | |||||
continue; | |||||
if (CheckEntityInRect(item.second->GetEntityHandle(), camera, sx0, sy0, sx1, sy1, false)) | |||||
hitEnts.push_back(item.first); | |||||
} | |||||
return hitEnts; | 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. | ||||
Show All 22 Lines |
Wildfire Games · Phabricator
Is this used at all?