Ver Fonte

:sparkles: added simple main loop

Felix Bytow há 1 ano atrás
pai
commit
b41284f59c
2 ficheiros alterados com 19 adições e 3 exclusões
  1. 1 2
      SDL.cxx
  2. 18 1
      main.cxx

+ 1 - 2
SDL.cxx

@@ -7,8 +7,7 @@ SDLError::SDLError(std::string_view const context, std::source_location location
     :std::runtime_error{(std::ostringstream{}
     << context << " at "
     << location.file_name() << ":" << location.line() << ":" << location.column()
-    << " - " << SDL_GetError()
-                        ).str()}
+    << " - " << SDL_GetError()).str()}
 {
 }
 

+ 18 - 1
main.cxx

@@ -3,6 +3,22 @@
 
 #include <cstdlib>
 
+void main_loop(SDLWindow& window)
+{
+  for (;;) {
+    SDL_Event evt;
+    while (SDL_PollEvent(&evt)!=0) {
+      if (evt.type==SDL_QUIT) {
+        return;
+      }
+    }
+
+    // Game logic, render... (Implement your logic here if needed.)
+
+    SDL_Delay(16);
+  }
+}
+
 int main(int argc, char** argv) try
 {
   SDL sdl{};
@@ -13,8 +29,9 @@ int main(int argc, char** argv) try
       SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_BORDERLESS
   };
 
+  main_loop(window);
   return EXIT_SUCCESS;
 } catch (std::exception const& ex) {
   SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", ex.what());
   return EXIT_FAILURE;
-}
+}