2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IZ_app_input.c 2.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "IZ_app_input.h"
  2. #if defined IZ_WINDOWS
  3. #define IZ_DEBUG_CONNECT SDLK_PAGEUP
  4. #define IZ_DEBUG_DISCONNECT SDLK_PAGEDOWN
  5. #define IZ_DEBUG_SEND_MESSAGE SDLK_INSERT
  6. #elif defined IZ_UNIX
  7. #define IZ_DEBUG_CONNECT SDLK_PAGEUP
  8. #define IZ_DEBUG_DISCONNECT SDLK_PAGEDOWN
  9. #define IZ_DEBUG_SEND_MESSAGE SDLK_INSERT
  10. #elif defined IZ_MACOS
  11. #define IZ_DEBUG_CONNECT SDLK_EQUALS
  12. #define IZ_DEBUG_DISCONNECT SDLK_MINUS
  13. #define IZ_DEBUG_SEND_MESSAGE SDLK_BACKSLASH
  14. #endif
  15. IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) {
  16. SDL_Event e;
  17. IZ_InputState* input_state = IZ_AppGetInputState(app);
  18. IZ_NetClientState* net_state = IZ_AppGetNetState(app);
  19. while (SDL_PollEvent(&e) != 0) {
  20. if (e.type == SDL_QUIT) {
  21. return 1;
  22. }
  23. #ifdef IZ_DEBUG
  24. if (e.type == SDL_KEYDOWN) {
  25. if (e.key.keysym.sym == IZ_DEBUG_CONNECT) {
  26. IZ_NetClientConnect(
  27. net_state,
  28. (IZ_WSClientInitializeParams) {
  29. .host = "127.0.0.1",
  30. .path = "/",
  31. .port = 42069,
  32. }
  33. );
  34. } else if (e.key.keysym.sym == IZ_DEBUG_DISCONNECT) {
  35. IZ_NetClientDisconnect(net_state);
  36. } else if (e.key.keysym.sym == IZ_DEBUG_SEND_MESSAGE) {
  37. IZ_NetClientSendTextMessage(net_state, "hello", 5);
  38. }
  39. }
  40. #endif
  41. IZ_InputHandleSDLEvents(input_state, e);
  42. }
  43. return 0;
  44. }
  45. void IZ_AppHandlePortMIDIEvents(struct IZ_App* app) {
  46. IZ_InputState* input_state = IZ_AppGetInputState(app);
  47. u8 player_index;
  48. i32* midi_events_count;
  49. u32 midi_event_index;
  50. for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) {
  51. if (!input_state->midi_input_state[player_index].device_info) {
  52. continue;
  53. }
  54. midi_events_count = &input_state->midi_input_state[player_index].midi_events_count;
  55. *midi_events_count = Pm_Read(
  56. input_state->midi_input_state[player_index].stream,
  57. // TODO bind buffers and streams to device instead of player input state
  58. input_state->midi_input_state[player_index].event_buffer,
  59. 1024
  60. );
  61. if (*midi_events_count < 1) {
  62. continue;
  63. }
  64. for (midi_event_index = 0; midi_event_index < *midi_events_count; midi_event_index += 1) {
  65. IZ_InputHandlePortMIDIEvents(
  66. input_state,
  67. input_state->midi_input_state[player_index].event_buffer[midi_event_index]
  68. );
  69. }
  70. }
  71. }
  72. IZ_ProcedureResult IZ_AppHandleInputEvents(struct IZ_App* app) {
  73. i32 sdl_events_result = IZ_AppHandleSDLEvents(app);
  74. if (sdl_events_result) {
  75. return sdl_events_result;
  76. }
  77. IZ_AppHandlePortMIDIEvents(app);
  78. return 0;
  79. }