From de93a620c182ec7fc716eaab91c1d38fbe17871c Mon Sep 17 00:00:00 2001 From: Antonio Carzaniga Date: Sat, 10 Aug 2019 11:11:14 +0200 Subject: [PATCH] added option to disable ball-ball collisions. --- balls.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/balls.c b/balls.c index 35cdc4d..000b85d 100644 --- a/balls.c +++ b/balls.c @@ -24,6 +24,8 @@ struct ball { cairo_surface_t * surface; }; +static int collisions = 1; + static double delta = 0.01; /* seconds */ static unsigned int width = DEFAULT_WIDTH; @@ -128,10 +130,11 @@ static void ball_update_state (struct ball * p) { } static void update_state () { - for(int i = 0; i < n_balls; ++i) - for(int j = i + 1; j < n_balls; ++j) - ball_collision(balls + i, balls + j); - + if (collisions) { + for(int i = 0; i < n_balls; ++i) + for(int j = i + 1; j < n_balls; ++j) + ball_collision(balls + i, balls + j); + } for(int i = 0; i < n_balls; ++i) ball_update_state(balls + i); } @@ -314,6 +317,7 @@ void print_usage (const char * progname) { "\tdelta=\n" "\tclear=\n" "\t-v :: enables rendering timing statitstics\n", + "\t-c :: disables ball-ball collisions\n", progname); } @@ -373,6 +377,10 @@ int main (int argc, const char *argv[]) { rendering_statistics = 1; continue; } + if (strcmp(argv[i], "-c") == 0) { + collisions = 0; + continue; + } print_usage(argv[0]); return 1; }