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

Method Update

SDK/src/NDK/World.cpp:166–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164 */
165
166 void World::Update()
167 {
168 if (!m_orderedSystemsUpdated)
169 ReorderSystems();
170
171 // Move waiting entities to entity list
172 if (!m_waitingEntities.empty())
173 {
174 constexpr std::size_t MinEntityCapacity = 10; //< We want to be able to grow maximum entity count by at least ten without going to the waiting list
175
176 m_entities.reserve(m_entities.size() + m_waitingEntities.size() + MinEntityCapacity);
177 for (auto& blockPtr : m_waitingEntities)
178 m_entities.push_back(std::move(*blockPtr));
179
180 m_waitingEntities.clear();
181
182 // Update entity blocks pointers
183 for (std::size_t i = 0; i < m_entities.size(); ++i)
184 m_entityBlocks[i] = &m_entities[i];
185 }
186
187 // Handle killed entities before last call
188 for (std::size_t i = m_killedEntities.FindFirst(); i != m_killedEntities.npos; i = m_killedEntities.FindNext(i))
189 {
190 NazaraAssert(i < m_entityBlocks.size(), "Entity index out of range");
191
192 Entity* entity = &m_entityBlocks[i]->entity;
193
194 // Destruction of the entity (invalidation of handle by the same way)
195 entity->Destroy();
196
197 // Send back the identifier of the entity to the free queue
198 m_freeIdList.push_back(entity->GetId());
199 }
200 m_killedEntities.Reset();
201
202 // Handle of entities which need an update from the systems
203 for (std::size_t i = m_dirtyEntities.FindFirst(); i != m_dirtyEntities.npos; i = m_dirtyEntities.FindNext(i))
204 {
205 NazaraAssert(i < m_entityBlocks.size(), "Entity index out of range");
206
207 Entity* entity = &m_entityBlocks[i]->entity;
208
209 // Check entity validity (as it could have been reported as dirty and killed during the same iteration)
210 if (!entity->IsValid())
211 continue;
212
213 Nz::Bitset<>& removedComponents = entity->GetRemovedComponentBits();
214 for (std::size_t j = removedComponents.FindFirst(); j != m_dirtyEntities.npos; j = removedComponents.FindNext(j))
215 entity->DestroyComponent(static_cast<Ndk::ComponentIndex>(j));
216 removedComponents.Reset();
217
218 for (auto& system : m_orderedSystems)
219 {
220 // Is our entity already part of this system?
221 bool partOfSystem = system->HasEntity(entity);
222
223 // Should it be part of it?

Callers 11

RunMethod · 0.45
ConsoleMethod · 0.45
SendCharacterMethod · 0.45
SendEventMethod · 0.45
SetCharacterSizeMethod · 0.45
RefreshHistoryMethod · 0.45
UpdateBoundingVolumeMethod · 0.45
AppendTextMethod · 0.45
OnKeyPressedMethod · 0.45
LuaBinding_UtilityMethod · 0.45
OnUpdateMethod · 0.45

Calls 8

push_backMethod · 0.80
GetIdMethod · 0.80
DestroyComponentMethod · 0.80
FiltersMethod · 0.80
DestroyMethod · 0.45
ResetMethod · 0.45
IsValidMethod · 0.45
IsEnabledMethod · 0.45

Tested by

no test coverage detected