| 2669 | }; |
| 2670 | |
| 2671 | static bool UpdateComponentFunction(Collection* collection, uint32_t component_type_count, UpdateFunctionType function_type, ComponentsUpdateParams& update_params) |
| 2672 | { |
| 2673 | bool ret = true; |
| 2674 | for (uint32_t i = 0; i < component_type_count; ++i) |
| 2675 | { |
| 2676 | uint16_t update_index = collection->m_Register->m_ComponentTypesOrder[i]; |
| 2677 | ComponentType* component_type = &collection->m_Register->m_ComponentTypes[update_index]; |
| 2678 | |
| 2679 | // Avoid to call UpdateTransforms for each/all component types. |
| 2680 | if (component_type->m_ReadsTransforms && collection->m_DirtyTransforms) |
| 2681 | { |
| 2682 | UpdateTransforms(collection); |
| 2683 | } |
| 2684 | |
| 2685 | // TODO: Could be stored in an array in component type, and just use the function type as index |
| 2686 | ComponentsUpdate func = 0; |
| 2687 | switch(function_type) |
| 2688 | { |
| 2689 | case UPDATE_FUNCTION_TYPE_UPDATE: |
| 2690 | { |
| 2691 | func = component_type->m_UpdateFunction; |
| 2692 | break; |
| 2693 | } |
| 2694 | case UPDATE_FUNCTION_TYPE_FIXED_UPDATE: |
| 2695 | { |
| 2696 | func = component_type->m_FixedUpdateFunction; |
| 2697 | break; |
| 2698 | } |
| 2699 | case UPDATE_FUNCTION_TYPE_LATE_UPDATE: |
| 2700 | { |
| 2701 | func = component_type->m_LateUpdateFunction; |
| 2702 | break; |
| 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | if (func) |
| 2707 | { |
| 2708 | DM_PROFILE_DYN(component_type->m_Name, 0); |
| 2709 | update_params.m_World = collection->m_ComponentWorlds[update_index]; |
| 2710 | update_params.m_Context = component_type->m_Context; |
| 2711 | |
| 2712 | ComponentsUpdateResult update_result; |
| 2713 | update_result.m_TransformsUpdated = false; |
| 2714 | UpdateResult res = func(update_params, update_result); |
| 2715 | if (res != UPDATE_RESULT_OK) |
| 2716 | ret = false; |
| 2717 | |
| 2718 | // Mark the collections transforms as dirty if this component has updated |
| 2719 | // them in its update function. |
| 2720 | if (update_result.m_TransformsUpdated) |
| 2721 | { |
| 2722 | collection->m_DirtyTransforms = 1; |
| 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | if (!DispatchMessages(collection, &collection->m_ComponentSocket, 1)) |
| 2727 | { |
| 2728 | ret = false; |
no test coverage detected