2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
 
 
 
 
 
 

87 lines
2.2 KiB

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