From 7fe1da4e745e2e9ab38f208229e284982b439ca7 Mon Sep 17 00:00:00 2001 From: Vadim Grigoruk Date: Thu, 17 May 2018 21:53:42 +0300 Subject: [PATCH] no message --- CMakeLists.txt | 19 +++++++++++-------- examples/sdl-renderer.c | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58b5af1..87ddf1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,8 +131,11 @@ target_include_directories(tic80lib PRIVATE 3rd-party/fennel) add_dependencies(tic80lib lua lpeg wren giflib) target_link_libraries(tic80lib lua lpeg wren giflib) +if(WIN32) + set(HAVE_LIBC TRUE) +endif() + set(SDL_STATIC ON) -set(HAVE_LIBC TRUE) add_subdirectory(3rd-party/SDL2-2.0.7) set(EXAMPLE_DIR examples) @@ -141,14 +144,14 @@ set(EXAMPLE_SRC ) if(WIN32) - add_executable(example WIN32 ${EXAMPLE_SRC}) + add_executable(sdl-renderer WIN32 ${EXAMPLE_SRC}) else() - add_executable(example ${EXAMPLE_SRC}) + add_executable(sdl-renderer ${EXAMPLE_SRC}) endif() -target_include_directories(example PRIVATE 3rd-party/SDL2-2.0.7/include) -target_include_directories(example PRIVATE include) -target_include_directories(example PRIVATE src) +target_include_directories(sdl-renderer PRIVATE 3rd-party/SDL2-2.0.7/include) +target_include_directories(sdl-renderer PRIVATE include) +target_include_directories(sdl-renderer PRIVATE src) -add_dependencies(example tic80lib SDL2-static SDL2main) -target_link_libraries(example tic80lib SDL2-static SDL2main) +add_dependencies(sdl-renderer tic80lib SDL2-static SDL2main) +target_link_libraries(sdl-renderer tic80lib SDL2-static SDL2main) diff --git a/examples/sdl-renderer.c b/examples/sdl-renderer.c index c4ad533..a0d6562 100644 --- a/examples/sdl-renderer.c +++ b/examples/sdl-renderer.c @@ -60,7 +60,7 @@ int main(int argc, char **argv) { SDL_Window* window = SDL_CreateWindow("TIC-80 SDL demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, TIC80_FULLWIDTH, TIC80_FULLHEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); - SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);// TODO: disable vsync + SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, TIC80_FULLWIDTH, TIC80_FULLHEIGHT); SDL_AudioDeviceID audioDevice = 0; @@ -99,6 +99,9 @@ int main(int argc, char **argv) if(tic) { + u64 nextTick = SDL_GetPerformanceCounter(); + const u64 Delta = SDL_GetPerformanceFrequency() / TIC_FRAMERATE; + while(!state.quit) { SDL_Event event; @@ -139,6 +142,8 @@ int main(int argc, char **argv) } } + nextTick += Delta; + tic80_tick(tic, input); if (!audioStarted && audioDevice) @@ -172,6 +177,15 @@ int main(int argc, char **argv) } SDL_RenderPresent(renderer); + + { + s64 delay = nextTick - SDL_GetPerformanceCounter(); + + if (delay < 0) + nextTick -= delay; + else SDL_Delay((u32)(delay * 1000 / SDL_GetPerformanceFrequency())); + } + } tic80_delete(tic);