diff options
Diffstat (limited to 'src/rpgedit.cpp')
-rw-r--r-- | src/rpgedit.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/rpgedit.cpp b/src/rpgedit.cpp index 48425e5..6057339 100644 --- a/src/rpgedit.cpp +++ b/src/rpgedit.cpp @@ -24,9 +24,9 @@ */ +#include "control/InputHandler.hpp" #include "control/MapContext.hpp" #include "view/MapView.hpp" -#include "model/Entity.hpp" #include <unistd.h> @@ -34,6 +34,9 @@ #include <SDL_main.h> +#define MIN_FRAME_DELAY 10 + + extern "C" int main(__attribute__((unused)) int argc, __attribute__((unused)) char *argv[]) { using namespace RPGEdit; @@ -41,6 +44,8 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char *argv[]) SDL_Init(SDL_INIT_VIDEO); { + Control::InputHandler inputHandler; + Control::ImageLoader tileLoader; std::shared_ptr<Model::Map> map = Model::Map::load("test"); @@ -50,11 +55,28 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char *argv[]) std::shared_ptr<View::MapView> mapView = ctx->initView(window); bool running = true; + uint32_t ticks = SDL_GetTicks(); while (true) { SDL_Event event; - while (SDL_PollEvent(&event)) { - if (event.type == SDL_QUIT) { + while (running) { + int timeout = ticks + MIN_FRAME_DELAY - SDL_GetTicks(); + if (timeout < 0) + timeout = 0; + + if (!SDL_WaitEventTimeout(&event, timeout)) + break; + + switch (event.type) { + case SDL_KEYDOWN: + inputHandler.keyPressed(event.key.keysym.scancode); + break; + + case SDL_KEYUP: + inputHandler.keyReleased(event.key.keysym.scancode); + break; + + case SDL_QUIT: running = false; break; } @@ -63,6 +85,11 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char *argv[]) if (!running) break; + uint32_t newTicks = SDL_GetTicks(); + ctx->advance(&inputHandler, newTicks - ticks); + + ticks = newTicks; + mapView->render(8, 8); } } |