split out debug code
[perl-landing-airplanes.git] / trace-path.pl
index 77a378d..de5d493 100755 (executable)
@@ -14,10 +14,16 @@ use Math::CatmullRom;
 use Carp qw/confess/;
 use Data::Dump qw/dump/;
 
+my $debug = 0;
+
 my ( $w, $h ) = ( 800, 480 );
 my $mouse_trashold = 10;
 my $max_path_length = 200;
 
+sub debug {
+       warn '#', dump @_ if $debug;
+}
+
 our $app = SDL::App->new(
        -width  => $w,
        -height => $h,
@@ -42,7 +48,7 @@ sub curve {
        return unless $#path > 4;
        my $curve = Math::CatmullRom->new( splice @path, 0, $#path + $#path / 2 );
        my @curve = $curve->curve( $mouse_trashold * $max_path_length / 2 );
-       warn "curve ", dump @curve;
+       debug 'curve' => @curve;
 
        my $i = 0;
        while ( $i < $#curve ) {
@@ -58,17 +64,17 @@ sub handle_events {
                my $type = $event->type();
 
                if ( $type == SDL_MOUSEBUTTONDOWN() ) {
-                       warn "mouse down ", $event->button_x, ' ', $event->button_y;
+                       debug 'mouse down', $event->button_x, $event->button_y;
                        $mouse_down = 1;
                } elsif ( $type == SDL_MOUSEBUTTONUP() ) {
-                       warn "mouse up ", $event->button_x, ' ', $event->button_y;
+                       debug 'mouse up', $event->button_x, $event->button_y;
                        $mouse_down = 0;
                        curve;
                } elsif ( $type == SDL_QUIT() ) {
                        exit;
                } elsif ( $type == SDL_KEYDOWN() ) {
                        my $key = $event->key_name;
-                       warn "key down $key\n";
+                       debug 'key down', $key;
                        exit if $key =~ m/^[xq]$/;
                        if ( $key eq 's' ) {
                                curve;
@@ -79,11 +85,10 @@ sub handle_events {
                                $app->update( $rect );
                        }
                } elsif ( $type == SDL_KEYUP() ) {
-                       warn "key up ", $event->key_name,$/;
+                       debug 'key up', $event->key_name;
                } elsif ( $type == SDL_MOUSEMOTION() ) {
-#                      warn "mouse ", $event->motion_xrel, ' ', $event->motion_yrel;
                        my ( $x, $y ) = ( $event->motion_x, $event->motion_y );
-                       warn "mouse $mouse_down @ $x*$y\n";
+                       debug 'mouse', $mouse_down, $x, $y;
                        my $dx = abs( $last_x - $x );
                        my $dy = abs( $last_y - $y );
                        if ( $mouse_down && ( $dx > $mouse_trashold || $dy > $mouse_trashold ) ) {
@@ -100,7 +105,7 @@ sub handle_events {
                                }
                        }
                } else {
-                       warn "unknown $type\n";
+                       debug 'unknown', $type;
                }
        }
 };