shithub: cstory

Download patch

ref: 8549fa561e0b1bccba910451808c22e52cefe5e4
parent: 026fea52ff29ce74cd0b05a6a70d63121a058556
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Apr 13 10:56:48 EDT 2020

Avoid WindowsWrapper.h in controller backend

--- a/src/Backends/Controller.h
+++ b/src/Backends/Controller.h
@@ -1,7 +1,5 @@
 #pragma once
 
-#include "../WindowsWrapper.h"
-
-BOOL ControllerBackend_Init(void);
+bool ControllerBackend_Init(void);
 void ControllerBackend_Deinit(void);
-BOOL ControllerBackend_GetJoystickStatus(BOOL **buttons, unsigned int *button_count, short **axes, unsigned int *axis_count);
+bool ControllerBackend_GetJoystickStatus(bool **buttons, unsigned int *button_count, short **axes, unsigned int *axis_count);
--- a/src/Backends/GLFW3/Controller.cpp
+++ b/src/Backends/GLFW3/Controller.cpp
@@ -8,11 +8,10 @@
 #include <GLFW/glfw3.h>
 
 #include "../Misc.h"
-#include "../../WindowsWrapper.h"
 
 #define DEADZONE (10000.0f / 32767.0f)
 
-static BOOL joystick_connected;
+static bool joystick_connected;
 static int connected_joystick_id;
 
 static float *axis_neutrals;
@@ -47,7 +46,7 @@
 								axis_neutrals[i] = axes[i];
 
 							printf("Joystick #%d selected\n", joystick_id);
-							joystick_connected = TRUE;
+							joystick_connected = true;
 							connected_joystick_id = joystick_id;
 						}
 						else
@@ -64,7 +63,7 @@
 			if (joystick_connected && joystick_id == connected_joystick_id)
 			{
 				Backend_PrintInfo("Joystick #%d disconnected", connected_joystick_id);
-				joystick_connected = FALSE;
+				joystick_connected = false;
 
 				free(axis_neutrals);
 			}
@@ -73,7 +72,7 @@
 	}
 }
 
-BOOL ControllerBackend_Init(void)
+bool ControllerBackend_Init(void)
 {
 	// Connect joysticks that are already plugged-in
 	for (int i = GLFW_JOYSTICK_1; i < GLFW_JOYSTICK_LAST; ++i)
@@ -83,7 +82,7 @@
 	// Set-up the callback for future (dis)connections
 	glfwSetJoystickCallback(JoystickCallback);
 
-	return TRUE;
+	return true;
 }
 
 void ControllerBackend_Deinit(void)
@@ -90,7 +89,7 @@
 {
 	glfwSetJoystickCallback(NULL);
 
-	joystick_connected = FALSE;
+	joystick_connected = false;
 	connected_joystick_id = 0;
 
 	free(axis_neutrals);
@@ -97,10 +96,10 @@
 	axis_neutrals = NULL;
 }
 
-BOOL ControllerBackend_GetJoystickStatus(BOOL **buttons, unsigned int *button_count, short **axes, unsigned int *axis_count)
+bool ControllerBackend_GetJoystickStatus(bool **buttons, unsigned int *button_count, short **axes, unsigned int *axis_count)
 {
 	if (!joystick_connected)
-		return FALSE;
+		return false;
 
 	int total_glfw_buttons;
 	const unsigned char *glfw_buttons = glfwGetJoystickButtons(connected_joystick_id, &total_glfw_buttons);
@@ -116,14 +115,14 @@
 	*button_count = total_glfw_buttons + total_glfw_axes * 2 + total_glfw_hats * 4;
 	*axis_count = total_glfw_axes;
 
-	static BOOL *button_buffer = NULL;
+	static bool *button_buffer = NULL;
 	static short *axis_buffer = NULL;
 
-	BOOL *new_button_buffer = (BOOL*)realloc(button_buffer, *button_count * sizeof(BOOL));
+	bool *new_button_buffer = (bool*)realloc(button_buffer, *button_count * sizeof(bool));
 	short *new_axis_buffer = (short*)realloc(axis_buffer, *axis_count * sizeof(short));
 
 	if (new_button_buffer == NULL || new_axis_buffer == NULL)
-		return FALSE;
+		return false;
 
 	button_buffer = new_button_buffer;
 	axis_buffer = new_axis_buffer;
@@ -167,5 +166,5 @@
 
 	*axes = axis_buffer;
 
-	return TRUE;
+	return true;
 }
--- a/src/Backends/SDL2/Controller.cpp
+++ b/src/Backends/SDL2/Controller.cpp
@@ -7,7 +7,6 @@
 #include "SDL.h"
 
 #include "../Misc.h"
-#include "../../WindowsWrapper.h"
 
 #define DEADZONE 10000
 
@@ -15,15 +14,15 @@
 
 static Sint16 *axis_neutrals;
 
-BOOL ControllerBackend_Init(void)
+bool ControllerBackend_Init(void)
 {
 	if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
 	{
 		Backend_PrintError("Couldn't initialise joystick SDL subsystem: %s", SDL_GetError());
-		return FALSE;
+		return false;
 	}
 
-	return TRUE;
+	return true;
 }
 
 void ControllerBackend_Deinit(void)
@@ -37,10 +36,10 @@
 	SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
 }
 
-BOOL ControllerBackend_GetJoystickStatus(BOOL **buttons, unsigned int *button_count, short **axes, unsigned int *axis_count)
+bool ControllerBackend_GetJoystickStatus(bool **buttons, unsigned int *button_count, short **axes, unsigned int *axis_count)
 {
 	if (joystick == NULL)
-		return FALSE;
+		return false;
 
 	int total_sdl_buttons = SDL_JoystickNumButtons(joystick);
 	if (total_sdl_buttons < 0)
@@ -57,14 +56,14 @@
 	*button_count = total_sdl_buttons + total_sdl_axes * 2 + total_sdl_hats * 4;
 	*axis_count = total_sdl_axes;
 
-	static BOOL *button_buffer = NULL;
+	static bool *button_buffer = NULL;
 	static short *axis_buffer = NULL;
 
-	BOOL *new_button_buffer = (BOOL*)realloc(button_buffer, *button_count * sizeof(BOOL));
+	bool *new_button_buffer = (bool*)realloc(button_buffer, *button_count * sizeof(bool));
 	short *new_axis_buffer = (short*)realloc(axis_buffer, *axis_count * sizeof(short));
 
 	if (new_button_buffer == NULL || new_axis_buffer == NULL)
-		return FALSE;
+		return false;
 
 	button_buffer = new_button_buffer;
 	axis_buffer = new_axis_buffer;
@@ -110,7 +109,7 @@
 
 	*axes = axis_buffer;
 
-	return TRUE;
+	return true;
 }
 
 void ControllerBackend_JoystickConnect(Sint32 joystick_id)
--