From 7b923d1376bb3fddd5049f220208b4abcf3cf415 Mon Sep 17 00:00:00 2001 From: Pedro Pereira Date: Sun, 21 Nov 2021 10:40:03 +0000 Subject: Starfield: Modify speed by command argument This change allows us to change the speed variable by passing a -s or --speed argument. --- Userland/Demos/Starfield/Starfield.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Userland/Demos/Starfield/Starfield.cpp b/Userland/Demos/Starfield/Starfield.cpp index 2a93c03427..cd6ed50924 100644 --- a/Userland/Demos/Starfield/Starfield.cpp +++ b/Userland/Demos/Starfield/Starfield.cpp @@ -34,6 +34,8 @@ public: virtual ~Starfield() override; void create_stars(int, int, int); + void set_speed(unsigned speed) { m_speed = speed; } + private: Starfield(int); RefPtr m_bitmap; @@ -142,21 +144,17 @@ int main(int argc, char** argv) return 1; } - int star_count = 0; - int refresh_rate = 0; + unsigned star_count = 1000; + unsigned refresh_rate = 16; + unsigned speed = 1; Core::ArgsParser args_parser; args_parser.set_general_help("The classic starfield screensaver."); args_parser.add_option(star_count, "Number of stars to draw (default = 1000)", "stars", 'c', "number"); args_parser.add_option(refresh_rate, "Refresh rate (default = 16)", "rate", 'r', "milliseconds"); + args_parser.add_option(speed, "Speed (default = 1)", "speed", 's', "number"); args_parser.parse(argc, argv); - if (star_count == 0) - star_count = 1000; - - if (refresh_rate == 0) - refresh_rate = 16; - auto app = GUI::Application::construct(argc, argv); if (pledge("stdio recvfd sendfd rpath", nullptr) < 0) { @@ -182,6 +180,7 @@ int main(int argc, char** argv) window->show(); starfield_window.create_stars(window->width(), window->height(), star_count); + starfield_window.set_speed(speed); starfield_window.update(); window->move_to_front(); -- cgit v1.2.3