From 025d50c4262d25cb8ce8b2c0932c787a9ac861d2 Mon Sep 17 00:00:00 2001 From: VAN BOSSUYT Nicolas Date: Wed, 24 Jul 2024 21:00:49 +0200 Subject: [PATCH] karm-ui: Fixed high CPU usage. --- src/impls/impl-sdl/ui.cpp | 2 +- src/libs/karm-io/fmt.h | 2 +- src/libs/karm-ui/host.h | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/impls/impl-sdl/ui.cpp b/src/impls/impl-sdl/ui.cpp index d7416673fb..69f7ec9182 100644 --- a/src/impls/impl-sdl/ui.cpp +++ b/src/impls/impl-sdl/ui.cpp @@ -523,7 +523,7 @@ struct SdlHost : // NOTE: A better option would be to have SDL in a separeted thread // and do the communication over an inter-thread channel but // but this would require to make the Framework thread safe - auto delay = TimeSpan::fromMSecs((usize)(FRAME_TIME * 1000 * 2)); + auto delay = TimeSpan::fromMSecs((usize)(FRAME_TIME * 1000)); auto cappedWait = min(ts, Sys::now() + delay); try$(Sys::globalSched().wait(cappedWait)); diff --git a/src/libs/karm-io/fmt.h b/src/libs/karm-io/fmt.h index d09aef25d6..c41255cdaf 100644 --- a/src/libs/karm-io/fmt.h +++ b/src/libs/karm-io/fmt.h @@ -895,7 +895,7 @@ struct Formatter : public StringFormatter { template <> struct Formatter { Res format(Io::TextWriter &writer, TimeSpan const &val) { - return Io::format(writer, "{}.{03}s", val.toSecs(), val.toUSecs() % 1000); + return Io::format(writer, "{}.{03}s", val.toSecs(), val.toMSecs() % 1000); } }; diff --git a/src/libs/karm-ui/host.h b/src/libs/karm-ui/host.h index 8f07e27103..66e16c1ed8 100644 --- a/src/libs/karm-ui/host.h +++ b/src/libs/karm-ui/host.h @@ -280,7 +280,8 @@ struct Host : public Node { if (_dirty.len() > 0) doPaint(); - try$(wait(nextFrame)); + try$(wait(nextFrameScheduled ? nextFrame : TimeStamp::endOfTime())); + nextFrameScheduled = false; } return _res.unwrap();