/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/Utilities/DataStructures/Implementation/ObjectSelection.cpp
65 строк
1 KB
Jan Krassnigg
Added OnChangedMainWorld to ezGameState and fixed RTS sample (#1359)
30 июл 2024, 00:44
Не верифицирован
30 июл 2024, 00:44
efcacd5
Код
Авторство
О чём код?
#include <Utilities/UtilitiesPCH.h> #include <Utilities/DataStructures/ObjectSelection.h> ezObjectSelection::ezObjectSelection() { m_pWorld = nullptr; } void ezObjectSelection::SetWorld(ezWorld* pWorld) { EZ_ASSERT_DEV((m_pWorld == pWorld) || m_Objects.IsEmpty(), "The selection has to be empty to change the world."); m_pWorld = pWorld; } void ezObjectSelection::RemoveDeadObjects() { EZ_ASSERT_DEV(m_pWorld != nullptr, "The world has not been set."); for (ezUInt32 i = m_Objects.GetCount(); i > 0; --i) { ezGameObject* pObject; if (!m_pWorld->TryGetObject(m_Objects[i - 1], pObject)) { m_Objects.RemoveAtAndCopy(i - 1); // keep the order } } } void ezObjectSelection::AddObject(ezGameObjectHandle hObject, bool bDontAddTwice) { EZ_IGNORE_UNUSED(bDontAddTwice); EZ_ASSERT_DEV(m_pWorld != nullptr, "The world has not been set."); // only insert valid objects ezGameObject* pObject; if (!m_pWorld->TryGetObject(hObject, pObject)) return; if (m_Objects.IndexOf(hObject) != ezInvalidIndex) return; m_Objects.PushBack(hObject); } bool ezObjectSelection::RemoveObject(ezGameObjectHandle hObject) { return m_Objects.RemoveAndCopy(hObject); } void ezObjectSelection::ToggleSelection(ezGameObjectHandle hObject) { for (ezUInt32 i = 0; i < m_Objects.GetCount(); ++i) { if (m_Objects[i] == hObject) { m_Objects.RemoveAtAndCopy(i); // keep the order return; } } // ensures invalid objects don't get added AddObject(hObject); }