static void handle_tick(game_context_s *context, void *data, const nothing_s *n) { input_handler_s *input_handler = data; // process the callback-based events target_context = context; glfwPollEvents(); target_context = NULL; // process joysticks for(int i = 0; i < MAX_JOYSTICKS; i++) { if(glfwGetJoystickParam(i, GLFW_PRESENT) == GL_TRUE) { joystick_event_s *joystick = &input_handler->joysticks[i]; int axis_count = glfwGetJoystickParam(i, GLFW_AXES); array_set_length(joystick->axes, axis_count); glfwGetJoystickPos(i, array_get_ptr(joystick->axes), axis_count); int button_count = glfwGetJoystickParam(i, GLFW_BUTTONS); array_set_length(joystick->buttons, button_count); glfwGetJoystickButtons(i, array_get_ptr(joystick->buttons), button_count); broadcast_input_handler_joystick_event(context, *joystick); } } }
void array_set(array_t* array, uint32_t idx, value_t val) { if (idx >= array->len) array_set_length(array, idx+1); array->elems[idx] = val; }