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.
 
 
 
 
 
 

105 lines
2.7 KiB

  1. #ifndef IZ_GAMECONTROLLER_H
  2. #define IZ_GAMECONTROLLER_H
  3. #include <SDL_gamecontroller.h>
  4. #include <SDL_events.h>
  5. #include <ini-config.h>
  6. #include <ini-config/source/types/int.h>
  7. #include <ini-config/source/types/string.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 "../../log/IZ_log.h"
  13. #include "IZ_action.h"
  14. #define IZ_GAME_CONTROLLER_AXIS_THRESHOLD ((u16) 8000)
  15. #define IZ_GAME_CONTROLLER_MIN_AXIS_THRESHOLD ((u16) 4000)
  16. #define IZ_GAME_CONTROLLER_MAX_AXIS_THRESHOLD ((u16) 12000)
  17. #define IZ_GAME_CONTROLLER_DEFAULT_CONFIGS 2
  18. #define IZ_GAME_CONTROLLER_MAX_CONTROL_NAME_LENGTH 64
  19. typedef struct {
  20. u16 axis_threshold;
  21. SDL_JoystickID device_id;
  22. SDL_GUID guid;
  23. const char control_mapping[IZ_CONTROLS][IZ_GAME_CONTROLLER_MAX_CONTROL_NAME_LENGTH];
  24. } IZ_GameControllerConfig;
  25. typedef struct {
  26. SDL_GameController* device;
  27. IZ_GameControllerConfig config;
  28. } IZ_GameControllerState;
  29. static const IZ_GameControllerState IZ_GAME_CONTROLLER_DEFAULT_STATE[IZ_PLAYERS] = {
  30. {
  31. .config = {
  32. .control_mapping = {
  33. "button:dpup axis:+lefty axis:+righty",
  34. "button:dpright axis:+leftx axis:+rightx",
  35. "button:dpdown axis:-lefty axis:-righty",
  36. "button:dpleft axis:-leftx axis:-rightx",
  37. "button:start",
  38. "button:back",
  39. "button:x",
  40. "axis:+righttrigger",
  41. "axis:+lefttrigger",
  42. "button:a",
  43. "button:y",
  44. "button:rightshoulder",
  45. "button:leftstick",
  46. "button:rightstick",
  47. "button:leftshoulder",
  48. "button:b",
  49. },
  50. .axis_threshold = IZ_GAME_CONTROLLER_AXIS_THRESHOLD,
  51. .guid = {
  52. .data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  53. },
  54. },
  55. .device = NULL,
  56. },
  57. #if IZ_PLAYERS > 1
  58. {
  59. .config = {
  60. .control_mapping = {
  61. "button:dpadup",
  62. "button:dpadright",
  63. "button:dpaddown",
  64. "button:dpadleft",
  65. "button:start",
  66. "button:back",
  67. "button:x",
  68. "button:y",
  69. "button:a",
  70. "button:b",
  71. "button:rightshoulder",
  72. "axis:righttrigger",
  73. "button:leftstick",
  74. "button:rightstick",
  75. "button:leftshoulder",
  76. "axis:lefttrigger",
  77. },
  78. .axis_threshold = 8000u,
  79. .guid = {
  80. .data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  81. },
  82. },
  83. .device = NULL,
  84. },
  85. #endif
  86. };
  87. IZ_ProcedureResult IZ_GameControllerSaveConfig(IZ_GameControllerState(*)[IZ_PLAYERS], const char*);
  88. void IZ_GameControllerHandleEvents(IZ_GameControllerState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], SDL_Event);
  89. IZ_ProcedureResult IZ_GameControllerInitialize(IZ_GameControllerState(*)[IZ_PLAYERS], const char*, u8, const char*[]);
  90. void IZ_GameControllerTeardown(IZ_GameControllerState(*)[IZ_PLAYERS]);
  91. #endif