summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Pereira <pmh.pereira@gmail.com>2021-11-21 10:40:03 +0000
committerLinus Groh <mail@linusgroh.de>2021-11-21 16:40:14 +0000
commit7b923d1376bb3fddd5049f220208b4abcf3cf415 (patch)
tree26c095a2fced5b94378983361865364da7859ab0
parent6ac97d439724854c16c315c7b293509377ffbc53 (diff)
downloadserenity-7b923d1376bb3fddd5049f220208b4abcf3cf415.zip
Starfield: Modify speed by command argument
This change allows us to change the speed variable by passing a -s or --speed argument.
-rw-r--r--Userland/Demos/Starfield/Starfield.cpp15
1 files 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<Gfx::Bitmap> 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();