application.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <cstdint>
  2. #include <SDL3/SDL.h>
  3. #include <application/application.h>
  4. #include <application/context.h>
  5. #include <backends/imgui_impl_sdl3.h>
  6. #include <backends/imgui_impl_sdlrenderer3.h>
  7. #include <entt/entity/registry.hpp>
  8. #include <imgui.h>
  9. #include <system/hud_system.h>
  10. #include <system/imgui_system.h>
  11. #include <system/input_system.h>
  12. #include <system/rendering_system.h>
  13. namespace testbed {
  14. void application::update(entt::registry &registry) {
  15. ImGui_ImplSDLRenderer3_NewFrame();
  16. ImGui_ImplSDL3_NewFrame();
  17. ImGui::NewFrame();
  18. // update...
  19. static_cast<void>(registry);
  20. }
  21. void application::draw(entt::registry &registry, const context &context) const {
  22. SDL_SetRenderDrawColor(context, 0u, 0u, 0u, SDL_ALPHA_OPAQUE);
  23. SDL_RenderClear(context);
  24. rendering_system(registry, context);
  25. hud_system(registry, context);
  26. imgui_system(registry);
  27. ImGui::Render();
  28. ImGuiIO &io = ImGui::GetIO();
  29. SDL_SetRenderScale(context, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
  30. ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), context);
  31. SDL_RenderPresent(context);
  32. }
  33. void application::input(entt::registry &registry) {
  34. ImGuiIO &io = ImGui::GetIO();
  35. SDL_Event event{};
  36. while(SDL_PollEvent(&event)) {
  37. ImGui_ImplSDL3_ProcessEvent(&event);
  38. input_system(registry, event, quit);
  39. }
  40. }
  41. application::application()
  42. : quit{} {
  43. SDL_Init(SDL_INIT_EVENTS | SDL_INIT_VIDEO);
  44. }
  45. application::~application() {
  46. SDL_Quit();
  47. }
  48. static void static_setup_for_dev_purposes(entt::registry &registry) {
  49. const auto entt = registry.create();
  50. registry.emplace<double>(entt, 1.2);
  51. registry.emplace<int>(entt, 3);
  52. }
  53. int application::run() {
  54. entt::registry registry{};
  55. context context{};
  56. static_setup_for_dev_purposes(registry);
  57. quit = false;
  58. while(!quit) {
  59. update(registry);
  60. draw(registry, context);
  61. input(registry);
  62. }
  63. return 0;
  64. }
  65. } // namespace testbed