MCPcopy Create free account
hub / github.com/NazaraEngine/NazaraEngine / Destroy

Method Destroy

SDK/src/NDK/Entity.cpp:150–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148 */
149
150 void Entity::Destroy()
151 {
152 OnEntityDestruction(this);
153 OnEntityDestruction.Clear();
154
155 // We prepare components for entity destruction (some components needs this to handle some final callbacks while the entity is still valid)
156 for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
157 m_components[i]->OnEntityDestruction();
158
159 // Detach components while they're still attached to systems
160 for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
161 m_components[i]->SetEntity(nullptr);
162
163 // We alert each system
164 for (std::size_t index = m_systemBits.FindFirst(); index != m_systemBits.npos; index = m_systemBits.FindNext(index))
165 {
166 auto sysIndex = static_cast<Ndk::SystemIndex>(index);
167
168 if (m_world->HasSystem(sysIndex))
169 {
170 BaseSystem& system = m_world->GetSystem(sysIndex);
171 system.RemoveEntity(this);
172 }
173 }
174 m_systemBits.Clear();
175
176 // Destroy components
177 m_components.clear();
178 m_componentBits.Reset();
179
180 // Free every handle
181 UnregisterAllHandles();
182
183 // Remove from every list
184 for (EntityList* list : m_containedInLists)
185 list->NotifyEntityDestruction(this);
186
187 m_containedInLists.clear();
188
189 m_valid = false;
190 }
191
192 /*!
193 * \brief Destroys a component by index

Callers 1

UpdateMethod · 0.45

Calls 3

ClearMethod · 0.45
OnEntityDestructionMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected