application.cpp 1.9 KB

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