|
@@ -1,21 +1,34 @@
|
|
|
#include "SDL.hxx"
|
|
|
#include "SDLWindow.hxx"
|
|
|
+#include "SDLRenderer.hxx"
|
|
|
+
|
|
|
+#include "game/GameStateManager.hxx"
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
-void main_loop(SDLWindow& window)
|
|
|
+void main_loop(SDLRenderer& renderer)
|
|
|
{
|
|
|
+ using namespace std::chrono;
|
|
|
+
|
|
|
+ GameStateManager gsm;
|
|
|
+
|
|
|
+ auto start = high_resolution_clock::now();
|
|
|
for (;;) {
|
|
|
SDL_Event evt;
|
|
|
while (SDL_PollEvent(&evt)!=0) {
|
|
|
- if (evt.type==SDL_QUIT) {
|
|
|
+ if (evt.type==SDL_QUIT)
|
|
|
return;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- // Game logic, render... (Implement your logic here if needed.)
|
|
|
+ auto const state = gsm.current();
|
|
|
+ if (state==nullptr)
|
|
|
+ return;
|
|
|
+
|
|
|
+ auto const end = high_resolution_clock::now();
|
|
|
+ auto const delta_time = duration_cast<milliseconds>(end-start);
|
|
|
|
|
|
- SDL_Delay(16);
|
|
|
+ state->update(gsm, delta_time);
|
|
|
+ state->render(renderer);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -28,8 +41,9 @@ int main(int argc, char** argv) try
|
|
|
0, 0,
|
|
|
SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_BORDERLESS
|
|
|
};
|
|
|
+ SDLRenderer renderer{window};
|
|
|
|
|
|
- main_loop(window);
|
|
|
+ main_loop(renderer);
|
|
|
return EXIT_SUCCESS;
|
|
|
} catch (std::exception const& ex) {
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", ex.what());
|