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.
 
 
 
 
 
 

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