use strict;
use warnings;
use SDL;
use SDLx::App;
use SDLx::Controller;
use SDLx::Controller::State;
use SDLx::Controller::Interface;

use Data::Dumper;

my $videodriver = $ENV{SDL_VIDEODRIVER};
$ENV{SDL_VIDEODRIVER} = 'dummy';


my $obj = SDLx::Controller::Interface->new( x => 1, y => 2, v_x => 3, v_y => 4, rot => 5, ang_v => 6 );

my $s = sub { warn 'Accel 1'; return ( 0.0, 10, 19 ) };

$obj->set_acceleration($s);

my $av = $obj->acceleration(1);

my $hv = $obj->interpolate(0.5);


$obj->update( 2, 0.5 );

$hv = $obj->interpolate(0.5);

$obj = SDLx::Controller::Interface->new( x => 1, y => 2, v_x => 3, v_y => 4, rot => 5, ang_v => 6 );


$obj->set_acceleration( sub { $_[1]->x(2); warn 'Accel 2';  return ( 0.0, 10, 19 ) } );

$obj->acceleration(1);
my $a   = $obj->current;
my $a_x = $a->x();

my $dummy = SDLx::App->new();

my $controller = SDLx::Controller->new( dt => 0.2 );

my $interface    = SDLx::Controller::Interface->new();
my $event_called = 0;

require SDL::Event;
require SDL::Events;
my $eve = SDL::Event->new();

SDL::Events::push_event($eve);
my $counts = [ 0, 0, 0 ];
$controller->add_event_handler( sub { $counts->[0]++; return 0 if $interface->current->x; return 0 } );

$interface->set_acceleration(
	sub {
		die
			if $counts->[1] > 100; $counts->[1]++;
			return ( 10, 10, 10 );
	}
);

$interface->attach(
	$controller,
	sub {
		$counts->[2]++;
		
	}
);


$controller->run();
$interface->detach();



if ($videodriver) {
	$ENV{SDL_VIDEODRIVER} = $videodriver;
} else {
	delete $ENV{SDL_VIDEODRIVER};
}


