| 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; |
nothing calls this directly
no test coverage detected