no message

This commit is contained in:
Vadim Grigoruk 2018-05-17 21:53:42 +03:00
parent 11bf2568f4
commit 7fe1da4e74
2 changed files with 26 additions and 9 deletions

View File

@ -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)

View File

@ -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);