Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/helpers/Selection.cpp
/* 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/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "Selection.h" | #include "Selection.h" | ||||
#include "graphics/Camera.h" | #include "graphics/Camera.h" | ||||
#include "simulation2/Simulation2.h" | #include "ps/CLogger.h" | ||||
#include "ps/Profiler2.h" | |||||
#include "simulation2/components/ICmpIdentity.h" | #include "simulation2/components/ICmpIdentity.h" | ||||
#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 "ps/CLogger.h" | |||||
#include "ps/Profiler2.h" | |||||
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()); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | entity_id_t EntitySelection::PickEntityAtPoint(CSimulation2& simulation, const CCamera& camera, int screenX, int screenY, player_id_t player, bool allowEditorSelectables) | ||||
} | } | ||||
return INVALID_ENTITY; | return INVALID_ENTITY; | ||||
} | } | ||||
/** | /** | ||||
* Returns true if the given entity is visible in the given screen area. | * Returns true if the given entity is visible in the given screen area. | ||||
* If the entity is a decorative, the function will only return true if allowEditorSelectables. | * If the entity is a decorative, the function will only return true if allowEditorSelectables. | ||||
*/ | */ | ||||
static bool CheckEntityInRect(CEntityHandle handle, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, bool allowEditorSelectables) | bool CheckEntityInRect(CEntityHandle handle, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, bool allowEditorSelectables) | ||||
{ | { | ||||
// Check if this entity is only selectable in Atlas | // Check if this entity is only selectable in Atlas | ||||
CmpPtr<ICmpSelectable> cmpSelectable(handle); | CmpPtr<ICmpSelectable> cmpSelectable(handle); | ||||
if (!cmpSelectable || (!allowEditorSelectables && cmpSelectable->IsEditorOnly())) | if (!cmpSelectable || (!allowEditorSelectables && cmpSelectable->IsEditorOnly())) | ||||
return false; | return false; | ||||
// Find the current interpolated model position. | // Find the current interpolated model position. | ||||
// (We just use the centre position and not the whole bounding box, because maybe | // (We just use the centre position and not the whole bounding box, because maybe | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator