| 809 | } |
| 810 | |
| 811 | void* EntitySystemHelpersBase::CreateComponentImmediateRaw(EntityHandle entity, ExtComponentType type) |
| 812 | { |
| 813 | auto const& meta = GetComponentMeta(type); |
| 814 | if (meta.ComponentIndex == UndefinedComponent |
| 815 | || meta.Properties == nullptr |
| 816 | || meta.Properties->Construct == nullptr) { |
| 817 | return nullptr; |
| 818 | } |
| 819 | |
| 820 | ComponentFrameStorageIndex index; |
| 821 | void* ptr; |
| 822 | auto iwc = GetEntityWorld()->Cache; |
| 823 | if (iwc->PrepareAddComponent(entity, meta.ComponentIndex, ptr)) { |
| 824 | if (meta.IsProxy) { |
| 825 | auto comp = (void**)ptr; |
| 826 | *comp = GameAllocRaw(meta.Size); |
| 827 | memset(*comp, 0, meta.Size); |
| 828 | meta.Properties->Construct(*comp); |
| 829 | return *comp; |
| 830 | } else { |
| 831 | // Ensure we're using zeroed memory since not every component has proper default constructors |
| 832 | // and could end up using leftover garbage from memory |
| 833 | memset(ptr, 0, meta.Size); |
| 834 | meta.Properties->Construct(ptr); |
| 835 | return ptr; |
| 836 | } |
| 837 | |
| 838 | iwc->FinalizeAddComponent(entity, meta.ComponentIndex, ptr); |
| 839 | } |
| 840 | |
| 841 | return nullptr; |
| 842 | } |
| 843 | |
| 844 | bool EntitySystemHelpersBase::RemoveComponent(EntityHandle entity, ExtComponentType type) |
| 845 | { |
nothing calls this directly
no test coverage detected