MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / moveEntityToList

Function moveEntityToList

src/OpenLoco/src/Entities/EntityManager.cpp:322–387  ·  view source on GitHub ↗

0x0047019F

Source from the content-addressed store, hash-verified

320
321 // 0x0047019F
322 void moveEntityToList(EntityBase* const entity, const EntityListType list)
323 {
324 const auto newListOffset = getLinkedListOffset(list);
325 if (entity->linkedListOffset == newListOffset)
326 {
327 return;
328 }
329
330 const auto newListIndex = enumValue(list);
331 const auto oldListIndex = getLinkedListIndex(entity->linkedListOffset);
332
333 const auto nextId = entity->nextEntityId;
334 const auto previousId = entity->llPreviousId;
335
336 // Unlink previous entity from this entity
337 if (previousId == EntityId::null)
338 {
339 rawListHeads()[oldListIndex] = nextId;
340 }
341 else
342 {
343 auto* previousEntity = get<EntityBase>(previousId);
344 if (previousEntity == nullptr)
345 {
346 Logging::error("Invalid previous entity id. Entity linked list corrupted? Id: {}", enumValue(previousId));
347 }
348 else
349 {
350 previousEntity->nextEntityId = nextId;
351 }
352 }
353 // Unlink next entity from this entity
354 if (nextId != EntityId::null)
355 {
356 auto* nextEntity = get<EntityBase>(nextId);
357 if (nextEntity == nullptr)
358 {
359 Logging::error("Invalid next entity id. Entity linked list corrupted? Id: {}", enumValue(nextId));
360 }
361 else
362 {
363 nextEntity->llPreviousId = previousId;
364 }
365 }
366
367 entity->llPreviousId = EntityId::null;
368 entity->linkedListOffset = newListOffset;
369 entity->nextEntityId = rawListHeads()[newListIndex];
370 rawListHeads()[newListIndex] = entity->id;
371 // Link next entity to this entity
372 if (entity->nextEntityId != EntityId::null)
373 {
374 auto* nextEntity = get<EntityBase>(entity->nextEntityId);
375 if (nextEntity == nullptr)
376 {
377 Logging::error("Invalid next entity id. Entity linked list corrupted? Id: {}", enumValue(entity->nextEntityId));
378 }
379 else

Callers 3

createEntityFunction · 0.85
freeEntityFunction · 0.85
createHeadFunction · 0.85

Calls 4

getLinkedListOffsetFunction · 0.85
enumValueFunction · 0.85
getLinkedListIndexFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected