2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

109 Zeilen
2.4 KiB

  1. #include "IZ_app.h"
  2. IZ_ProcedureResult IZ_AppInitialize(IZ_App* app) {
  3. u32 flags = (
  4. SDL_INIT_VIDEO
  5. | SDL_INIT_GAMECONTROLLER
  6. | SDL_INIT_EVENTS
  7. );
  8. if (SDL_Init(flags) < 0) {
  9. // TODO fix logging
  10. fprintf_s(stderr, "SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
  11. return 1;
  12. }
  13. char config_path[128];
  14. IZ_ConfigGetPath(config_path, 128);
  15. if (IZ_VideoInitialize(config_path, &app->video_state)) {
  16. return 2;
  17. }
  18. IZ_InputInitialize(config_path, &app->input_state);
  19. IZ_PoolInitialize(&app->pool, POOL_MAX_SIZE);
  20. // TODO put into its timer module
  21. app->ticks = 0;
  22. app->quit = false;
  23. return 0;
  24. }
  25. void IZ_AppTeardown(IZ_App* app) {
  26. IZ_PoolTeardown(&app->pool);
  27. IZ_InputTeardown(&app->input_state);
  28. IZ_VideoTeardown(&app->video_state);
  29. SDL_Quit();
  30. }
  31. void IZ_AppHandleSDLEvents(IZ_App* app) {
  32. while (SDL_PollEvent(&app->sdl_event) != 0) {
  33. if (app->sdl_event.type == SDL_QUIT) {
  34. app->quit = true;
  35. break;
  36. }
  37. IZ_InputHandleSDLEvents(app->sdl_event, &app->input_state);
  38. }
  39. }
  40. void IZ_AppHandlePortMIDIEvents(IZ_App* app) {
  41. u8 player_index;
  42. i32* midi_events_count;
  43. u32 midi_event_index;
  44. for (player_index = 0; player_index < PLAYERS; player_index += 1) {
  45. midi_events_count = &app->input_state.midi_input_state[player_index].midi_events_count;
  46. *midi_events_count = Pm_Read(
  47. app->input_state.midi_input_state[player_index].stream,
  48. app->input_state.midi_input_state[player_index].event_buffer,
  49. 1024
  50. );
  51. if (*midi_events_count < 1) {
  52. continue;
  53. }
  54. for (midi_event_index = 0; midi_event_index < *midi_events_count; midi_event_index += 1) {
  55. IZ_InputHandlePortMIDIEvents(
  56. app->input_state.midi_input_state[player_index].event_buffer[midi_event_index],
  57. &app->input_state
  58. );
  59. }
  60. }
  61. }
  62. void IZ_AppHandleEvents(IZ_App* app) {
  63. IZ_AppHandleSDLEvents(app);
  64. IZ_AppHandlePortMIDIEvents(app);
  65. }
  66. IZ_ProcedureResult IZ_AppRun(IZ_App* app, u8 arg_count, char* arg_values[]) {
  67. printf_s("Args (%u):\n", arg_count);
  68. u8 arg_index;
  69. for (arg_index = 0; arg_index < arg_count; arg_index += 1) {
  70. printf_s(" %s\n", arg_values[arg_index]);
  71. }
  72. IZ_ProcedureResult init_result = IZ_AppInitialize(app);
  73. if (init_result) {
  74. return init_result;
  75. }
  76. while (true) {
  77. app->ticks = SDL_GetTicks64();
  78. // TODO do audio processing
  79. // TODO do networking?
  80. IZ_AppHandleEvents(app);
  81. if (app->quit) {
  82. break;
  83. }
  84. IZ_VideoUpdate(&app->video_state, &app->input_state, app->ticks);
  85. }
  86. IZ_AppTeardown(app);
  87. return 0;
  88. }