summaryrefslogtreecommitdiffhomepage
path: root/src/core.c
diff options
context:
space:
mode:
authorRay <[email protected]>2021-06-10 17:11:31 +0200
committerRay <[email protected]>2021-06-10 17:11:31 +0200
commitd3387c952ae9eaa223777b2fd97674f580476611 (patch)
treed1616f976335935194537723a670ad51086e3b53 /src/core.c
parent36439749491e44c8ba829592a3f154fbdc499c3d (diff)
downloadraylib-d3387c952ae9eaa223777b2fd97674f580476611.tar.gz
raylib-d3387c952ae9eaa223777b2fd97674f580476611.zip
Reviewed Input variables and comments
Diffstat (limited to 'src/core.c')
-rw-r--r--src/core.c76
1 files changed, 41 insertions, 35 deletions
diff --git a/src/core.c b/src/core.c
index 44474b05..421c8d30 100644
--- a/src/core.c
+++ b/src/core.c
@@ -276,8 +276,8 @@
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
#define USE_LAST_TOUCH_DEVICE // When multiple touchscreens are connected, only use the one with the highest event<N> number
- #define DEFAULT_GAMEPAD_DEV "/dev/input/js" // Gamepad input (base dev for all gamepads: js0, js1, ...)
- #define DEFAULT_EVDEV_PATH "/dev/input/" // Path to the linux input events
+ #define DEFAULT_GAMEPAD_DEV "/dev/input/js" // Gamepad input (base dev for all gamepads: js0, js1, ...)
+ #define DEFAULT_EVDEV_PATH "/dev/input/" // Path to the linux input events
#endif
#ifndef MAX_FILEPATH_LENGTH
@@ -288,23 +288,29 @@
#endif
#endif
+#ifndef MAX_KEYBOARD_KEYS
+ #define MAX_KEYBOARD_KEYS 512 // Maximum number of keyboard keys supported
+#endif
+#ifndef MAX_MOUSE_BUTTONS
+ #define MAX_MOUSE_BUTTONS 8 // Maximum number of mouse buttons supported
+#endif
#ifndef MAX_GAMEPADS
- #define MAX_GAMEPADS 4 // Max number of gamepads supported
+ #define MAX_GAMEPADS 4 // Maximum number of gamepads supported
#endif
#ifndef MAX_GAMEPAD_AXIS
- #define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad)
+ #define MAX_GAMEPAD_AXIS 8 // Maximum number of axis supported (per gamepad)
#endif
#ifndef MAX_GAMEPAD_BUTTONS
- #define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad)
+ #define MAX_GAMEPAD_BUTTONS 32 // Maximum number of buttons supported (per gamepad)
#endif
#ifndef MAX_TOUCH_POINTS
#define MAX_TOUCH_POINTS 10 // Maximum number of touch points supported
#endif
#ifndef MAX_KEY_PRESSED_QUEUE
- #define MAX_KEY_PRESSED_QUEUE 16 // Max number of keys in the key input queue
+ #define MAX_KEY_PRESSED_QUEUE 16 // Maximum number of keys in the key input queue
#endif
#ifndef MAX_CHAR_PRESSED_QUEUE
- #define MAX_CHAR_PRESSED_QUEUE 16 // Max number of characters in the char input queue
+ #define MAX_CHAR_PRESSED_QUEUE 16 // Maximum number of characters in the char input queue
#endif
#if defined(SUPPORT_DATA_STORAGE)
@@ -314,7 +320,7 @@
#endif
#ifndef MAX_DECOMPRESSION_SIZE
- #define MAX_DECOMPRESSION_SIZE 64 // Max size allocated for decompression in MB
+ #define MAX_DECOMPRESSION_SIZE 64 // Maximum size allocated for decompression in MB
#endif
// Flags operation macros
@@ -408,8 +414,8 @@ typedef struct CoreData {
#endif
struct {
int exitKey; // Default exit key
- char currentKeyState[512]; // Registers current frame key state
- char previousKeyState[512]; // Registers previous frame key state
+ char currentKeyState[MAX_KEYBOARD_KEYS]; // Registers current frame key state
+ char previousKeyState[MAX_KEYBOARD_KEYS]; // Registers previous frame key state
int keyPressedQueue[MAX_KEY_PRESSED_QUEUE]; // Input keys queue
int keyPressedQueueCount; // Input keys queue count
@@ -432,12 +438,12 @@ typedef struct CoreData {
bool cursorHidden; // Track if cursor is hidden
bool cursorOnScreen; // Tracks if cursor is inside client area
- char currentButtonState[MOUSE_BUTTON_MAX]; // Registers current mouse button state
- char previousButtonState[MOUSE_BUTTON_MAX]; // Registers previous mouse button state
+ char currentButtonState[MAX_MOUSE_BUTTONS]; // Registers current mouse button state
+ char previousButtonState[MAX_MOUSE_BUTTONS]; // Registers previous mouse button state
float currentWheelMove; // Registers current mouse wheel variation
float previousWheelMove; // Registers previous mouse wheel variation
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
- char currentButtonStateEvdev[MOUSE_BUTTON_MAX]; // Holds the new mouse state for the next polling event to grab (Can't be written directly due to multithreading, app could miss the update)
+ char currentButtonStateEvdev[MAX_MOUSE_BUTTONS]; // Holds the new mouse state for the next polling event to grab (Can't be written directly due to multithreading, app could miss the update)
#endif
} Mouse;
struct {
@@ -449,9 +455,9 @@ typedef struct CoreData {
int lastButtonPressed; // Register last gamepad button pressed
int axisCount; // Register number of available gamepad axis
bool ready[MAX_GAMEPADS]; // Flag to know if gamepad is ready
- float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state
- char currentState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
- char previousState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
+ char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
+ char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
+ float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
pthread_t threadId; // Gamepad reading thread id
int streamId[MAX_GAMEPADS]; // Gamepad device file descriptor
@@ -1895,7 +1901,7 @@ void EndDrawing(void)
double waitTime = CORE.Time.current - CORE.Time.previous;
CORE.Time.previous = CORE.Time.current;
- CORE.Time.frame += waitTime; // Total frame time: update + draw + wait
+ CORE.Time.frame += waitTime; // Total frame time: update + draw + wait
}
PollInputEvents(); // Poll user events
@@ -3248,7 +3254,7 @@ bool IsGamepadButtonPressed(int gamepad, int button)
bool pressed = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
- (CORE.Input.Gamepad.previousState[gamepad][button] == 0) && (CORE.Input.Gamepad.currentState[gamepad][button] == 1)) pressed = true;
+ (CORE.Input.Gamepad.previousButtonState[gamepad][button] == 0) && (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 1)) pressed = true;
else pressed = false;
return pressed;
@@ -3260,7 +3266,7 @@ bool IsGamepadButtonDown(int gamepad, int button)
bool result = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
- (CORE.Input.Gamepad.currentState[gamepad][button] == 1)) result = true;
+ (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 1)) result = true;
return result;
}
@@ -3271,7 +3277,7 @@ bool IsGamepadButtonReleased(int gamepad, int button)
bool released = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
- (CORE.Input.Gamepad.previousState[gamepad][button] == 1) && (CORE.Input.Gamepad.currentState[gamepad][button] == 0)) released = true;
+ (CORE.Input.Gamepad.previousButtonState[gamepad][button] == 1) && (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 0)) released = true;
else released = false;
return released;
@@ -3283,7 +3289,7 @@ bool IsGamepadButtonUp(int gamepad, int button)
bool result = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS) &&
- (CORE.Input.Gamepad.currentState[gamepad][button] == 0)) result = true;
+ (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 0)) result = true;
return result;
}
@@ -4623,7 +4629,7 @@ static void PollInputEvents(void)
if (CORE.Input.Gamepad.ready[i]) // Check if gamepad is available
{
// Register previous gamepad states
- for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) CORE.Input.Gamepad.previousState[i][k] = CORE.Input.Gamepad.currentState[i][k];
+ for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) CORE.Input.Gamepad.previousButtonState[i][k] = CORE.Input.Gamepad.currentButtonState[i][k];
}
}
#endif
@@ -4636,7 +4642,7 @@ static void PollInputEvents(void)
{
if (CORE.Input.Gamepad.ready[i])
{
- for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) CORE.Input.Gamepad.previousState[i][k] = CORE.Input.Gamepad.currentState[i][k];
+ for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) CORE.Input.Gamepad.previousButtonState[i][k] = CORE.Input.Gamepad.currentButtonState[i][k];
}
}
@@ -4679,7 +4685,7 @@ static void PollInputEvents(void)
if (CORE.Input.Gamepad.ready[i]) // Check if gamepad is available
{
// Register previous gamepad states
- for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) CORE.Input.Gamepad.previousState[i][k] = CORE.Input.Gamepad.currentState[i][k];
+ for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) CORE.Input.Gamepad.previousButtonState[i][k] = CORE.Input.Gamepad.currentButtonState[i][k];
// Get current gamepad state
// NOTE: There is no callback available, so we get it manually
@@ -4721,10 +4727,10 @@ static void PollInputEvents(void)
{
if (buttons[k] == GLFW_PRESS)
{
- CORE.Input.Gamepad.currentState[i][button] = 1;
+ CORE.Input.Gamepad.currentButtonState[i][button] = 1;
CORE.Input.Gamepad.lastButtonPressed = button;
}
- else CORE.Input.Gamepad.currentState[i][button] = 0;
+ else CORE.Input.Gamepad.currentButtonState[i][button] = 0;
}
}
@@ -4737,8 +4743,8 @@ static void PollInputEvents(void)
}
// Register buttons for 2nd triggers (because GLFW doesn't count these as buttons but rather axis)
- CORE.Input.Gamepad.currentState[i][GAMEPAD_BUTTON_LEFT_TRIGGER_2] = (char)(CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_LEFT_TRIGGER] > 0.1);
- CORE.Input.Gamepad.currentState[i][GAMEPAD_BUTTON_RIGHT_TRIGGER_2] = (char)(CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_RIGHT_TRIGGER] > 0.1);
+ CORE.Input.Gamepad.currentButtonState[i][GAMEPAD_BUTTON_LEFT_TRIGGER_2] = (char)(CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_LEFT_TRIGGER] > 0.1);
+ CORE.Input.Gamepad.currentButtonState[i][GAMEPAD_BUTTON_RIGHT_TRIGGER_2] = (char)(CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_RIGHT_TRIGGER] > 0.1);
CORE.Input.Gamepad.axisCount = GLFW_GAMEPAD_AXIS_LAST + 1;
}
@@ -4763,7 +4769,7 @@ static void PollInputEvents(void)
for (int i = 0; (i < numGamepads) && (i < MAX_GAMEPADS); i++)
{
// Register previous gamepad button states
- for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) CORE.Input.Gamepad.previousState[i][k] = CORE.Input.Gamepad.currentState[i][k];
+ for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) CORE.Input.Gamepad.previousButtonState[i][k] = CORE.Input.Gamepad.currentButtonState[i][k];
EmscriptenGamepadEvent gamepadState;
@@ -4802,10 +4808,10 @@ static void PollInputEvents(void)
{
if (gamepadState.digitalButton[j] == 1)
{
- CORE.Input.Gamepad.currentState[i][button] = 1;
+ CORE.Input.Gamepad.currentButtonState[i][button] = 1;
CORE.Input.Gamepad.lastButtonPressed = button;
}
- else CORE.Input.Gamepad.currentState[i][button] = 0;
+ else CORE.Input.Gamepad.currentButtonState[i][button] = 0;
}
//TRACELOGD("INPUT: Gamepad %d, button %d: Digital: %d, Analog: %g", gamepadState.index, j, gamepadState.digitalButton[j], gamepadState.analogButton[j]);
@@ -5551,10 +5557,10 @@ static void ProcessKeyboard(void)
bufferByteCount = read(STDIN_FILENO, keysBuffer, MAX_KEYBUFFER_SIZE); // POSIX system call
// Reset pressed keys array (it will be filled below)
- if (bufferByteCount > 0) for (int i = 0; i < 512; i++) CORE.Input.Keyboard.currentKeyState[i] = 0;
+ if (bufferByteCount > 0) for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) CORE.Input.Keyboard.currentKeyState[i] = 0;
// Check keys from event input workers (This is the new keyboard reading method)
- //for (int i = 0; i < 512; i++) CORE.Input.Keyboard.currentKeyState[i] = CORE.Input.Keyboard.currentKeyStateEvdev[i];
+ //for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) CORE.Input.Keyboard.currentKeyState[i] = CORE.Input.Keyboard.currentKeyStateEvdev[i];
// Fill all read bytes (looking for keys)
for (int i = 0; i < bufferByteCount; i++)
@@ -6225,7 +6231,7 @@ static void *GamepadThread(void *arg)
if (gamepadEvent.number < MAX_GAMEPAD_BUTTONS)
{
// 1 - button pressed, 0 - button released
- CORE.Input.Gamepad.currentState[i][gamepadEvent.number] = (int)gamepadEvent.value;
+ CORE.Input.Gamepad.currentButtonState[i][gamepadEvent.number] = (int)gamepadEvent.value;
if ((int)gamepadEvent.value == 1) CORE.Input.Gamepad.lastButtonPressed = gamepadEvent.number;
else CORE.Input.Gamepad.lastButtonPressed = -1;
@@ -6456,7 +6462,7 @@ void UWPRegisterGamepadButton(int gamepad, int button, bool down)
{
if (button < MAX_GAMEPAD_BUTTONS)
{
- CORE.Input.Gamepad.currentState[gamepad][button] = down;
+ CORE.Input.Gamepad.currentButtonState[gamepad][button] = down;
CORE.Input.Gamepad.lastButtonPressed = button;
}
}