| 2896 | } |
| 2897 | |
| 2898 | static bool PostUpdate(Collection* collection) |
| 2899 | { |
| 2900 | DM_PROFILE("PostUpdate"); |
| 2901 | assert(collection != 0x0); |
| 2902 | HRegister reg = collection->m_Register; |
| 2903 | assert(reg); |
| 2904 | |
| 2905 | bool result = true; |
| 2906 | |
| 2907 | uint32_t component_types = reg->m_ComponentTypeCount; |
| 2908 | for (uint32_t i = 0; i < component_types; ++i) |
| 2909 | { |
| 2910 | uint16_t update_index = reg->m_ComponentTypesOrder[i]; |
| 2911 | ComponentType* component_type = ®->m_ComponentTypes[update_index]; |
| 2912 | |
| 2913 | if (component_type->m_PostUpdateFunction) |
| 2914 | { |
| 2915 | DM_PROFILE_DYN(component_type->m_Name, 0); |
| 2916 | ComponentsPostUpdateParams params; |
| 2917 | params.m_Collection = collection->m_HCollection; |
| 2918 | params.m_World = collection->m_ComponentWorlds[update_index]; |
| 2919 | params.m_Context = component_type->m_Context; |
| 2920 | UpdateResult res = component_type->m_PostUpdateFunction(params); |
| 2921 | if (res != UPDATE_RESULT_OK && result) |
| 2922 | result = false; |
| 2923 | } |
| 2924 | } |
| 2925 | |
| 2926 | uint32_t instances_deleted = 0; |
| 2927 | |
| 2928 | if (collection->m_InstancesToDeleteHead != INVALID_INSTANCE_INDEX) { |
| 2929 | // Arbitrary max pass count to only guard for unexpected cycles and infinite hangs, see clause after while |
| 2930 | uint32_t max_pass_count = 10; |
| 2931 | uint32_t pass_count = 0; |
| 2932 | while (collection->m_InstancesToDeleteHead != INVALID_INSTANCE_INDEX && pass_count < max_pass_count) { |
| 2933 | ++pass_count; |
| 2934 | // Save the list and clear the head and tail |
| 2935 | uint16_t head = collection->m_InstancesToDeleteHead; |
| 2936 | collection->m_InstancesToDeleteHead = INVALID_INSTANCE_INDEX; |
| 2937 | collection->m_InstancesToDeleteTail = INVALID_INSTANCE_INDEX; |
| 2938 | |
| 2939 | uint16_t index = head; |
| 2940 | while (index != INVALID_INSTANCE_INDEX) { |
| 2941 | Instance* instance = collection->m_Instances[index]; |
| 2942 | |
| 2943 | assert(collection->m_Instances[instance->m_Index] == instance); |
| 2944 | assert(instance->m_ToBeDeleted); |
| 2945 | if (instance->m_Initialized) { |
| 2946 | if (!FinalInstance(collection, instance) && result) { |
| 2947 | result = false; |
| 2948 | } |
| 2949 | } |
| 2950 | index = instance->m_NextToDelete; |
| 2951 | } |
| 2952 | |
| 2953 | if (!DispatchAllSockets(collection)) { |
| 2954 | result = false; |
| 2955 | } |