adapted to new app run loop
This commit is contained in:
parent
1838a9d6cf
commit
73d41d4774
30
main.cpp
30
main.cpp
@ -33,8 +33,6 @@ const int HEIGHT {900};
|
|||||||
sc::gui::Window* main_window {nullptr};
|
sc::gui::Window* main_window {nullptr};
|
||||||
sc::gui::Image* main_image {nullptr};
|
sc::gui::Image* main_image {nullptr};
|
||||||
ScreensaverPlugin* main_saver {nullptr};
|
ScreensaverPlugin* main_saver {nullptr};
|
||||||
bool expired {true};
|
|
||||||
bool should_run {true};
|
|
||||||
|
|
||||||
void print_help() {
|
void print_help() {
|
||||||
std::cout << "usage: screensaver [-h|-l|--version]\n";
|
std::cout << "usage: screensaver [-h|-l|--version]\n";
|
||||||
@ -53,24 +51,11 @@ void list_plugins() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_frame() {
|
|
||||||
while (should_run) {
|
|
||||||
expired = true;
|
|
||||||
|
|
||||||
struct timespec delay;
|
|
||||||
delay.tv_sec = 0;
|
|
||||||
delay.tv_nsec = static_cast<int>(round(1000000000.0 / main_saver->fps()));
|
|
||||||
nanosleep(&delay, nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
if (expired) {
|
sc::gui::ImageLock lock {*main_image};
|
||||||
expired = false;
|
main_saver->draw_frame();
|
||||||
sc::gui::ImageLock lock {*main_image};
|
main_window->dirty(true);
|
||||||
main_saver->draw_frame();
|
main_window->show_image(*main_image);
|
||||||
main_window->show_image(*main_image);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char * argv[]) {
|
int main(int argc, const char * argv[]) {
|
||||||
@ -154,15 +139,10 @@ int main(int argc, const char * argv[]) {
|
|||||||
main_saver = saver.get();
|
main_saver = saver.get();
|
||||||
main_saver->setup(cr, {0, 0, WIDTH, HEIGHT});
|
main_saver->setup(cr, {0, 0, WIDTH, HEIGHT});
|
||||||
|
|
||||||
// setup thread which periodically sets 'expired'
|
sc::gui::app().fps(main_saver->fps());
|
||||||
std::thread frame_timer {update_frame};
|
|
||||||
|
|
||||||
sc::gui::app().add_run_loop_action(draw);
|
sc::gui::app().add_run_loop_action(draw);
|
||||||
sc::gui::app().run();
|
sc::gui::app().run();
|
||||||
|
|
||||||
should_run = false;
|
|
||||||
frame_timer.join();
|
|
||||||
|
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
std::cerr << "screensaver: " << ex.what() << '\n';
|
std::cerr << "screensaver: " << ex.what() << '\n';
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user