forked from Green-Sky/tomato
more main loop fiddling
This commit is contained in:
parent
92b58cbfa9
commit
845967cf12
29
src/main.cpp
29
src/main.cpp
@ -84,8 +84,7 @@ int main(int argc, char** argv) {
|
|||||||
last_time_tick = new_time;
|
last_time_tick = new_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
// can do both in the same loop
|
// do events outside of tick/render, so they can influence reported intervals
|
||||||
if (render) {
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
if (event.type == SDL_EVENT_QUIT) {
|
if (event.type == SDL_EVENT_QUIT) {
|
||||||
@ -103,11 +102,8 @@ int main(int argc, char** argv) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//float fps_target = 60.f;
|
// can do both in the same loop
|
||||||
//if (SDL_GetWindowFlags(window.get()) & (SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED)) {
|
if (render) {
|
||||||
//fps_target = 30.f;
|
|
||||||
//}
|
|
||||||
|
|
||||||
ImGui_ImplSDLRenderer3_NewFrame();
|
ImGui_ImplSDLRenderer3_NewFrame();
|
||||||
ImGui_ImplSDL3_NewFrame();
|
ImGui_ImplSDL3_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
@ -160,12 +156,23 @@ int main(int argc, char** argv) {
|
|||||||
//screen->nextRender() - time_delta_render
|
//screen->nextRender() - time_delta_render
|
||||||
//)
|
//)
|
||||||
//));
|
//));
|
||||||
SDL_Delay(uint32_t(
|
|
||||||
std::min<float>(
|
const float min_delay = std::min<float>(
|
||||||
screen->nextTick() - time_delta_tick,
|
screen->nextTick() - time_delta_tick,
|
||||||
screen->nextRender() - time_delta_render
|
screen->nextRender() - time_delta_render
|
||||||
) * 1000.f
|
) * 1000.f;
|
||||||
));
|
|
||||||
|
if (min_delay > 0.f) {
|
||||||
|
SDL_Delay(uint32_t(min_delay));
|
||||||
|
}
|
||||||
|
|
||||||
|
// better in theory, but consumes more cpu on linux for some reason
|
||||||
|
//SDL_WaitEventTimeout(nullptr, int32_t(
|
||||||
|
//std::min<float>(
|
||||||
|
//screen->nextTick() - time_delta_tick,
|
||||||
|
//screen->nextRender() - time_delta_render
|
||||||
|
//) * 1000.f
|
||||||
|
//));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user