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.
 
 
 
 
 
 

99 lines
1.7 KiB

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