[Add] Documented joystick.c
This commit is contained in:
parent
8516b33391
commit
1a03c08672
@ -1,11 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* @file joystick.c
|
||||||
|
*
|
||||||
|
* @brief Handles joystick initialization.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "lephisto.h"
|
#include "lephisto.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "joystick.h"
|
#include "joystick.h"
|
||||||
|
|
||||||
static SDL_Joystick* joystick = NULL;
|
static SDL_Joystick* joystick = NULL; /**< Current joystick in use. */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn int joystick_get(char* namjoystick)
|
||||||
|
*
|
||||||
|
* @brief Get the joystick index by name.
|
||||||
|
* @param namjoystick Looks for given string in the joystick name.
|
||||||
|
* @return The index if found, defaults to 0 if it isn't found.
|
||||||
|
*/
|
||||||
int joystick_get(char* namjoystick) {
|
int joystick_get(char* namjoystick) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < SDL_NumJoysticks(); i++)
|
for(i = 0; i < SDL_NumJoysticks(); i++)
|
||||||
@ -17,6 +31,13 @@ int joystick_get(char* namjoystick) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn int joystick_use(int indjoystick)
|
||||||
|
*
|
||||||
|
* @brief Make the game use a joystick by index.
|
||||||
|
* @param indjoystick Index of the joystick to use.
|
||||||
|
* @return 0 on success.
|
||||||
|
*/
|
||||||
int joystick_use(int indjoystick) {
|
int joystick_use(int indjoystick) {
|
||||||
if(indjoystick < 0 || indjoystick >= SDL_NumJoysticks()) {
|
if(indjoystick < 0 || indjoystick >= SDL_NumJoysticks()) {
|
||||||
WARN("Joystick of index number %d does not exist. Switching to default (0)",
|
WARN("Joystick of index number %d does not exist. Switching to default (0)",
|
||||||
@ -41,6 +62,12 @@ int joystick_use(int indjoystick) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn int joystick_init(void)
|
||||||
|
*
|
||||||
|
* @brief Initializes the joystick subsystem.
|
||||||
|
* @return 0 on success.
|
||||||
|
*/
|
||||||
int joystick_init(void) {
|
int joystick_init(void) {
|
||||||
int numjoysticks, i;
|
int numjoysticks, i;
|
||||||
|
|
||||||
@ -62,6 +89,11 @@ int joystick_init(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn void joystick_exit(void)
|
||||||
|
*
|
||||||
|
* @brief Exit the joystick subsystem.
|
||||||
|
*/
|
||||||
void joystick_exit(void) {
|
void joystick_exit(void) {
|
||||||
SDL_JoystickClose(joystick);
|
SDL_JoystickClose(joystick);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user