2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

106 lines
1.9 KiB

  1. #ifndef IZ_JOYSTICK_H
  2. #define IZ_JOYSTICK_H
  3. #include <SDL_joystick.h>
  4. #include <SDL_gamecontroller.h>
  5. #include <SDL_events.h>
  6. #include <ini-config.h>
  7. #include "../../config/IZ_config_guid.h"
  8. #include "../../common/IZ_common.h"
  9. #include "../../stdinc/IZ_string.h"
  10. #include "../../stdinc/IZ_stdlib.h"
  11. #include "IZ_action.h"
  12. typedef u8 IZ_PadButton;
  13. #define IZ_DEFAULT_AXIS_THRESHOLD ((u16) 8000)
  14. typedef enum {
  15. IZ_JOY_AXIS_DIRECTION_HORIZONTAL1 = 0,
  16. IZ_JOY_AXIS_DIRECTION_VERTICAL1 = 1,
  17. IZ_JOY_AXIS_DIRECTION_HORIZONTAL2 = 2,
  18. IZ_JOY_AXIS_DIRECTION_VERTICAL2 = 3,
  19. IZ_JOY_AXIS_DIRECTION_LEFT_SHOULDER = 4,
  20. IZ_JOY_AXIS_DIRECTION_RIGHT_SHOULDER = 5,
  21. } IZ_JoyAxisDirection;
  22. typedef struct {
  23. u16 axis_threshold;
  24. SDL_JoystickID device_id;
  25. SDL_GUID guid;
  26. IZ_PadButton control_mapping[IZ_CONTROLS];
  27. } IZ_JoystickConfig;
  28. typedef struct {
  29. SDL_Joystick* device;
  30. IZ_JoystickConfig config;
  31. } IZ_JoystickState;
  32. static const IZ_JoystickState IZ_JOYSTICK_DEFAULT_STATE[IZ_PLAYERS] = {
  33. {
  34. .config = {
  35. .control_mapping = {
  36. 255,
  37. 255,
  38. 255,
  39. 255,
  40. 11,
  41. 10,
  42. 1,
  43. 0,
  44. 4,
  45. 3,
  46. 6,
  47. 7,
  48. 8,
  49. 9,
  50. 13,
  51. 14,
  52. },
  53. .axis_threshold = IZ_DEFAULT_AXIS_THRESHOLD,
  54. .device_id = 0,
  55. .guid = {
  56. .data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  57. }
  58. },
  59. .device = NULL,
  60. },
  61. #if IZ_PLAYERS > 1
  62. {
  63. .config = {
  64. .control_mapping = {
  65. 255,
  66. 255,
  67. 255,
  68. 255,
  69. 11,
  70. 10,
  71. 1,
  72. 0,
  73. 4,
  74. 3,
  75. 6,
  76. 7,
  77. 8,
  78. 9,
  79. 13,
  80. 14,
  81. },
  82. .axis_threshold = 8000u,
  83. .device_id = 1,
  84. },
  85. .device = NULL,
  86. },
  87. #endif
  88. };
  89. IZ_ProcedureResult IZ_JoystickSaveConfig(IZ_JoystickState(*)[IZ_PLAYERS], const char*);
  90. void IZ_JoystickHandleEvents(IZ_JoystickState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], SDL_Event);
  91. IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(*)[IZ_PLAYERS], const char*, u8, const char*[]);
  92. void IZ_JoystickTeardown(IZ_JoystickState(*)[IZ_PLAYERS]);
  93. #endif