Permalink
Browse files

MAde state an object

  • Loading branch information...
1 parent 62e2199 commit 0739b15c7c7ba96a207ae39178bf1d820993edea @kthakore kthakore committed Aug 14, 2010
Showing with 126 additions and 20 deletions.
  1. +8 −1 Build.PL
  2. +12 −0 lib/SDLx/Controller/State.pm
  3. +12 −15 src/SDLx/Controller/Object.xs
  4. +90 −0 src/SDLx/Controller/State.xs
  5. +1 −0 t/00-load.t
  6. +2 −4 t/sdlx_controller_object.t
  7. +1 −0 typemap
View
@@ -179,7 +179,14 @@ my %subsystems = (
from => 'src/SDLx/Controller/Object.xs',
to => 'lib/SDLx/Controller/Object.xs',
},
- libraries => [qw( )],
+ libraries => [qw( SDL )],
+ },
+ StateX => {
+ file => {
+ from => 'src/SDLx/Controller/State.xs',
+ to => 'lib/SDLx/Controller/State.xs',
+ },
+ libraries => [qw( SDL )],
},
Overlay => {
file => {
@@ -0,0 +1,12 @@
+package SDLx::Controller::State;
+use strict;
+use warnings;
+
+our @ISA = qw(Exporter DynaLoader);
+
+use SDL::Internal::Loader;
+internal_load_dlls(__PACKAGE__);
+
+bootstrap SDLx::Controller::State;
+
+1;
@@ -88,29 +88,26 @@ objx_acceleration(obj)
RETVAL
-HV*
+SDLx_State *
objx_interpolate(obj, alpha)
SDLx_Object* obj
float alpha
+ PREINIT:
+ char * CLASS = "SDLx::Controller::State";
CODE:
- RETVAL = newHV();
- float x = obj->current->x * alpha + obj->previous->x * (1 - alpha);
- hv_stores( RETVAL, "x", newSVnv(x) );
- float y = obj->current->y * alpha + obj->previous->y * (1 - alpha);
- hv_stores( RETVAL, "y", newSVnv(y) );
- float v_x = obj->current->v_x * alpha + obj->previous->v_x * (1 - alpha);
- hv_stores( RETVAL, "v_x", newSVnv(v_x) );
- float v_y = obj->current->v_y * alpha + obj->previous->v_y * (1 - alpha);
- hv_stores( RETVAL, "v_y", newSVnv(v_y) );
- float rotation = obj->current->rotation * alpha + obj->previous->rotation * (1 - alpha);
- hv_stores( RETVAL, "rotation", newSVnv(rotation) );
- float ang_v = obj->current->ang_v * alpha + obj->previous->ang_v * (1 - alpha);
- hv_stores( RETVAL, "ang_v", newSVnv(ang_v) );
- sv_2mortal((SV*)RETVAL);
+ RETVAL = (SDLx_State *)safemalloc(sizeof(SDLx_State ));
+ RETVAL->x = obj->current->x * alpha + obj->previous->x * (1 - alpha);
+ RETVAL->y = obj->current->y * alpha + obj->previous->y * (1 - alpha);
+ RETVAL->v_x = obj->current->v_x * alpha + obj->previous->v_x * (1 - alpha);
+ RETVAL->v_y = obj->current->v_y * alpha + obj->previous->v_y * (1 - alpha);
+ RETVAL->rotation = obj->current->rotation * alpha + obj->previous->rotation * (1 - alpha);
+ RETVAL->ang_v = obj->current->ang_v * alpha + obj->previous->ang_v * (1 - alpha);
OUTPUT:
RETVAL
+
+
void
objx_DESTROY( obj )
SDLx_Object *obj
@@ -0,0 +1,90 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+#include "ppport.h"
+
+#ifndef aTHX_
+#define aTHX_
+#endif
+
+#include "SDLx/Controller/Object.h"
+
+
+MODULE = SDLx::Controller::State PACKAGE = SDLx::Controller::State PREFIX = state__
+
+SDLx_State *
+state_new( CLASS, ... )
+ char * CLASS
+ CODE:
+ RETVAL = (SDLx_State * ) safemalloc( sizeof(SDLx_State) );
+ if(items > 2)
+ RETVAL->x = SvIV(ST(2));
+ if(items > 3)
+ RETVAL->y = SvIV(ST(3));
+ if(items > 4)
+ RETVAL->v_x = SvIV(ST(4));
+ if(items > 5)
+ RETVAL->v_y = SvIV(ST(5));
+ if(items > 6)
+ RETVAL->rotation = SvIV(ST(6));
+ if(items > 7)
+ RETVAL->ang_v = SvIV(ST(7));
+ OUTPUT:
+ RETVAL
+
+float
+state_x(state)
+ SDLx_State * state
+ CODE:
+ RETVAL = state->x;
+ OUTPUT:
+ RETVAL
+
+float
+state_y(state)
+ SDLx_State * state
+ CODE:
+ RETVAL = state->y;
+ OUTPUT:
+ RETVAL
+
+float
+state_v_x(state)
+ SDLx_State * state
+ CODE:
+ RETVAL = state->v_x;
+ OUTPUT:
+ RETVAL
+
+float
+state_v_y(state)
+ SDLx_State * state
+ CODE:
+ RETVAL = state->v_y;
+ OUTPUT:
+ RETVAL
+
+float
+state_rotation(state)
+ SDLx_State * state
+ CODE:
+ RETVAL = state->rotation;
+ OUTPUT:
+ RETVAL
+
+float
+state_ang_v(state)
+ SDLx_State * state
+ CODE:
+ RETVAL = state->ang_v;
+ OUTPUT:
+ RETVAL
+
+void
+state_DESTROY( obj )
+ SDLx_State *obj
+ CODE:
+ safefree(obj);
+
+
+
View
@@ -65,6 +65,7 @@ BEGIN {
SDLx::Controller
SDLx::Controller::Object
+ SDLx::Controller::State
SDLx::Controller::Timer
/;
@@ -1,6 +1,7 @@
use strict;
use warnings;
use Test::More;
+use SDLx::Controller::State;
use SDLx::Controller::Object;
use lib 't/lib';
use SDL::TestTool;
@@ -35,9 +36,6 @@ is($av->[2], 0.0);
my $hv = $obj->interpolate(0.5);
-isa_ok ( $hv, 'HASH');
-
-print Dumper $hv;
-
+isa_ok ( $hv, 'SDLx::Controller::State');
done_testing;
View
@@ -58,6 +58,7 @@ sdlx_timer * O_OBJECT
SDLx_LayerManager * O_OBJECT
SDLx_Layer * O_OBJECT
SDLx_Object * O_OBJECT
+SDLx_State * O_OBJECT
SDLPango_Alignment T_UV
int * T_PTR
int ** T_PTR

0 comments on commit 0739b15

Please sign in to comment.