2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

IZ_app_input.c 1.9 KiB

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