Skip to content

Commit

Permalink
karm-ui: Fixed high CPU usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Jul 24, 2024
1 parent cf341a7 commit 025d50c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/impls/impl-sdl/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion src/libs/karm-io/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ struct Formatter<char const *> : public StringFormatter<Utf8> {
template <>
struct Formatter<TimeSpan> {
Res<usize> 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);
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/libs/karm-ui/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 025d50c

Please sign in to comment.