MCPcopy Create free account
hub / github.com/Norbyte/ositools / GetComponentByEntityHandle

Method GetComponentByEntityHandle

OsiInterface/DivInterface.cpp:311–345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

309 }
310
311 void * EntityWorld::GetComponentByEntityHandle(ObjectHandle entityHandle, ComponentType type)
312 {
313 if (entityHandle.GetType() != 0) {
314 OsiError("Entity handle has invalid type " << entityHandle.GetType());
315 return nullptr;
316 }
317
318 auto index = entityHandle.GetIndex();
319 if (index >= EntityEntries.Size) {
320 OsiError("Entity index " << index << " too large!");
321 return nullptr;
322 }
323
324 auto salt = entityHandle.GetSalt();
325 if (salt != EntitySalts.Buf[index]) {
326 OsiError("Salt mismatch on index " << index << "; " << salt << " != " << EntitySalts.Buf[index]);
327 return nullptr;
328 }
329
330 auto entity = EntityEntries.Buf[index];
331 if ((uint32_t)type >= entity->Layout.Entries.Size) {
332 OsiError("Entity " << index << " has no component slot for " << (uint32_t)type);
333 return nullptr;
334 }
335
336 auto const & layoutEntry = entity->Layout.Entries.Buf[(uint32_t)type];
337 if (!layoutEntry.Handle.IsValid()) {
338 OsiError("Entity " << index << " has no component bound to slot " << (uint32_t)type);
339 return nullptr;
340 }
341
342 ObjectHandle componentHandle{ layoutEntry.Handle.Handle };
343 auto componentMgr = Components.Buf[(uint32_t)type].component;
344 return componentMgr->FindComponentByHandle(&componentHandle);
345 }
346
347
348 PendingStatuses gPendingStatuses;

Callers

nothing calls this directly

Calls 5

GetIndexMethod · 0.80
GetSaltMethod · 0.80
IsValidMethod · 0.80
FindComponentByHandleMethod · 0.80
GetTypeMethod · 0.45

Tested by

no test coverage detected