Added ASSERT_RETURN to input binding constructors
This commit is contained in:
		
							parent
							
								
									663d6e36c2
								
							
						
					
					
						commit
						5d8d996c91
					
				|  | @ -4,6 +4,7 @@ | |||
| 
 | ||||
| KeyBind* keybind_new(SDL_Scancode key) { | ||||
|     KeyBind* self = malloc(sizeof(KeyBind)); | ||||
|     ASSERT_RETURN(self != NULL, NULL, "Failed to allocate space for KeyBind instance"); | ||||
|     *self = (KeyBind) { | ||||
|         .device = NULL, | ||||
|         .scancode = key, | ||||
|  | @ -31,6 +32,7 @@ void keybind_set_device(KeyBind* self, InputDevice* device) { | |||
| 
 | ||||
| ControllerAxis* controlleraxis_new(int axis) { | ||||
|     ControllerAxis* self = malloc(sizeof(ControllerAxis)); | ||||
|     ASSERT_RETURN(self != NULL, NULL, "Failed to allocate space for ControllerAxis instance"); | ||||
|     *self = (ControllerAxis){ | ||||
|         .axis = axis, | ||||
|         .device = NULL | ||||
|  | @ -48,7 +50,6 @@ int controlleraxis_is_changed_by(ControllerAxis* self, SDL_Event event) { | |||
| 
 | ||||
| InputEvent controlleraxis_evaluate(ControllerAxis* self, SDL_Event event) { | ||||
|     float result = (float)event.caxis.value / 32767.0; | ||||
|     LOG_INFO("axis %f", result); | ||||
|     return (InputEvent) { | ||||
|         .type = InputEvent_Float, | ||||
|         .as_float = result | ||||
|  | @ -61,6 +62,7 @@ void controlleraxis_set_device(ControllerAxis* self, InputDevice* device) { | |||
| 
 | ||||
| ControllerButton* controllerbutton_new(int button) { | ||||
|     ControllerButton* self = malloc(sizeof(ControllerButton)); | ||||
|     ASSERT_RETURN(self != NULL, NULL, "Failed to allocate space for ControllerButton instance"); | ||||
|     *self = (ControllerButton) { | ||||
|         .button = button, | ||||
|         .device = NULL | ||||
|  | @ -86,8 +88,14 @@ void controllerbutton_set_device(ControllerButton* self, InputDevice* device) { | |||
|     self->device = device; | ||||
| } | ||||
| 
 | ||||
| #define NEW(__Type, __Variable, ...)\ | ||||
| __Type *__Variable = malloc(sizeof(__Type));\ | ||||
| if(__Variable == NULL) LOG_ERROR("Failed to allocate memory for " #__Variable);\ | ||||
| *__Variable = (__Type)__VA_ARGS__; | ||||
| 
 | ||||
| CompositeAxis1D* compositeaxis1d_new(InputAxis left, InputAxis right, InputEventType type) { | ||||
|     CompositeAxis1D* self = malloc(sizeof(CompositeAxis1D)); | ||||
|     ASSERT_RETURN(self != NULL, NULL, "Failed to allocate space for CompositeAxis1D instance"); | ||||
|     *self = (CompositeAxis1D) { | ||||
|         .left = left, | ||||
|         .right = right, | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Sara
						Sara