| 3015 | } |
| 3016 | |
| 3017 | UpdateResult DispatchInput(Collection* collection, InputAction* input_actions, uint32_t input_action_count) |
| 3018 | { |
| 3019 | DM_PROFILE("DispatchInput"); |
| 3020 | |
| 3021 | // iterate stacks from top to bottom |
| 3022 | for (uint32_t i = 0; i < input_action_count; ++i) |
| 3023 | { |
| 3024 | InputAction& input_action = input_actions[i]; |
| 3025 | if (input_action.m_ActionId != 0 || input_action.m_PositionSet || input_action.m_AccelerationSet) |
| 3026 | { |
| 3027 | uint32_t stack_size = collection->m_InputFocusStack.Size(); |
| 3028 | for (uint32_t k = 0; k < stack_size; ++k) |
| 3029 | { |
| 3030 | HInstance instance = collection->m_InputFocusStack[stack_size - 1 - k]; |
| 3031 | Prototype* prototype = instance->m_Prototype; |
| 3032 | uint32_t components_size = prototype->m_ComponentCount; |
| 3033 | |
| 3034 | InputResult res = INPUT_RESULT_IGNORED; |
| 3035 | uint32_t next_component_instance_data = 0; |
| 3036 | for (uint32_t l = 0; l < components_size; ++l) |
| 3037 | { |
| 3038 | ComponentType* component_type = prototype->m_Components[l].m_Type; |
| 3039 | assert(component_type); |
| 3040 | if (component_type->m_OnInputFunction) |
| 3041 | { |
| 3042 | uintptr_t* component_instance_data = 0; |
| 3043 | if (component_type->m_InstanceHasUserData) |
| 3044 | { |
| 3045 | component_instance_data = &instance->m_ComponentInstanceUserData[next_component_instance_data]; |
| 3046 | } |
| 3047 | ComponentOnInputParams params; |
| 3048 | params.m_Instance = instance; |
| 3049 | params.m_InputAction = &input_action; |
| 3050 | params.m_Context = component_type->m_Context; |
| 3051 | params.m_UserData = component_instance_data; |
| 3052 | InputResult comp_res = component_type->m_OnInputFunction(params); |
| 3053 | if (comp_res == INPUT_RESULT_CONSUMED) |
| 3054 | res = comp_res; |
| 3055 | else if (comp_res == INPUT_RESULT_UNKNOWN_ERROR) |
| 3056 | return UPDATE_RESULT_UNKNOWN_ERROR; |
| 3057 | } |
| 3058 | if (component_type->m_InstanceHasUserData) |
| 3059 | { |
| 3060 | next_component_instance_data++; |
| 3061 | } |
| 3062 | } |
| 3063 | if (res == INPUT_RESULT_CONSUMED) |
| 3064 | { |
| 3065 | memset(&input_action, 0, sizeof(InputAction)); |
| 3066 | input_action.m_Consumed = 1; |
| 3067 | break; |
| 3068 | } |
| 3069 | } |
| 3070 | } |
| 3071 | } |
| 3072 | return UPDATE_RESULT_OK; |
| 3073 | } |
| 3074 | |