Browse files

Added Conditional free's for anoymous State objects passed into the a…

…nonymous callback and the interpolate return state. Added a test to check for state mutability and copy to current state of object from acceleration callback. Added more test descriptions to t/sdlx_controller_object.t
  • Loading branch information...
1 parent ea516c5 commit de000ebf1c6b65ea453da83cd0342600d93c3589 @kthakore kthakore committed Aug 16, 2010
Showing with 12 additions and 2 deletions.
  1. +2 −0 src/SDLx/Controller/Object.xs
  2. +10 −2 t/sdlx_controller_object.t
View
2 src/SDLx/Controller/Object.xs
@@ -26,6 +26,7 @@ AV* acceleration_cb( SDLx_Object * obj, float t )
SV * stateref = newSV( sizeof(SDLx_State *) );
void * copyState = safemalloc( sizeof(SDLx_State) );
memcpy( copyState, obj->current, sizeof(SDLx_State) );
+ ((SDLx_State *)copyState)->owned = 0; //conditional free
ENTER;
SAVETMPS;
PUSHMARK(SP);
@@ -195,6 +196,7 @@ objx_interpolate(obj, alpha)
CODE:
SDLx_State* out = (SDLx_State *)safemalloc(sizeof(SDLx_State )) ;
interpolate( obj,out, alpha);
+ out->owned = 0; //condition free
RETVAL = out;
OUTPUT:
RETVAL
View
12 t/sdlx_controller_object.t
@@ -37,7 +37,7 @@ is($av->[2], 0.0);
my $hv = $obj->interpolate(0.5);
-isa_ok ( $hv, 'SDLx::Controller::State');
+isa_ok ( $hv, 'SDLx::Controller::State', '[interpolate] provides state back out');
is($hv->x, 1);
is($hv->y, 2);
@@ -48,13 +48,21 @@ $obj->update( 2, 0.5 );
$hv = $obj->interpolate(0.5);
-isa_ok ( $hv, 'SDLx::Controller::State');
+isa_ok ( $hv, 'SDLx::Controller::State', '[interpolate] provides state back out');
is($hv->x, 1.75);
is($hv->y, 3.625);
is($hv->rotation, 7.6875);
+$obj = SDLx::Controller::Object->new( x=> 1, y=> 2, v_x => 3, v_y => 4, rot => 5, ang_v => 6);
+$obj->set_acceleration( sub { $_[1]->x(2); pass '[state] is mutable'; return (0.0,10,19)});
+
+ $obj->acceleration( 1 );
+my $a = $obj->current;
+my $a_x = $a->x();
+is( $a_x, 2, '[obj/state] acceleration callback copies staet back to current');
done_testing;
+

0 comments on commit de000eb

Please sign in to comment.