Got Event working. Events at 25%. Poll_event and Push_event done
Kartik Thakore [Mon, 9 Nov 2009 00:57:51 +0000 (19:57 -0500)]
src/Core/Events.xs
src/Core/objects/Event.xs
src/SDL.xs
t/core_events.t
typemap

index 24be987..090ae6c 100644 (file)
@@ -46,7 +46,7 @@ events_poll_event( event )
        SDL_Event *event
        CODE:
                RETVAL = -1;
-               if ( &event != NULL )
+               if (  event != NULL )
                RETVAL = SDL_PollEvent(event);
        OUTPUT:
                RETVAL
index a41c582..2450ae8 100644 (file)
@@ -38,8 +38,7 @@ SDL_Event *
 event_new (CLASS)
        char *CLASS
        CODE:
-               SDL_Event *empty_event;
-               RETVAL = empty_event;
+               RETVAL = (SDL_Event *) safemalloc(sizeof (SDL_Event));
        OUTPUT:
                RETVAL
 
@@ -103,7 +102,7 @@ event_button ( event, ... )
 
 SDL_JoyAxisEvent *
 event_jaxis ( event, ... )
-       SDL_Event *event
+       SDL_Event * event
        PREINIT:
                char *CLASS = "SDL::JoyAxisEvent";
        CODE:
@@ -115,7 +114,7 @@ event_jaxis ( event, ... )
 
 SDL_JoyBallEvent *
 event_jball ( event, ... )
-       SDL_Event *event
+       SDL_Event * event
        PREINIT:
                char *CLASS = "SDL::JoyBallEvent";
        CODE:
@@ -127,7 +126,7 @@ event_jball ( event, ... )
 
 SDL_JoyHatEvent *
 event_jhat ( event, ... )
-       SDL_Event *event
+       SDL_Event * event
        PREINIT:
                char *CLASS = "SDL::JoyHatEvent";
        CODE:
@@ -139,7 +138,7 @@ event_jhat ( event, ... )
 
 SDL_JoyButtonEvent *
 event_jbutton ( event, ... )
-       SDL_Event *event
+       SDL_Event * event
        PREINIT:
                char *CLASS = "SDL::JoyButtonEvent";
        CODE:
@@ -151,7 +150,7 @@ event_jbutton ( event, ... )
 
 SDL_ResizeEvent *
 event_resize ( event, ... )
-       SDL_Event *event
+       SDL_Event * event
        PREINIT:
                char *CLASS = "SDL::ResizeEvent";
        CODE:
@@ -163,7 +162,7 @@ event_resize ( event, ... )
 
 SDL_ExposeEvent *
 event_expose ( event, ... )
-       SDL_Event *event
+       SDL_Event * event
        PREINIT:
                char *CLASS = "SDL::ExposeEvent";
        CODE:
@@ -175,7 +174,7 @@ event_expose ( event, ... )
 
 SDL_QuitEvent *
 event_quit ( event, ... )
-       SDL_Event *event
+       SDL_Event * event
        PREINIT:
                char *CLASS = "SDL::QuitEvent";
        CODE:
@@ -187,7 +186,7 @@ event_quit ( event, ... )
 
 SDL_UserEvent *
 event_user ( event, ... )
-       SDL_Event *event
+       SDL_Event * event
        PREINIT:
                char *CLASS = "SDL::UserEvent";
        CODE:
@@ -199,7 +198,7 @@ event_user ( event, ... )
 
 SDL_SysWMEvent *
 event_syswm ( event, ... )
-       SDL_Event *event
+       SDL_Event * event
        PREINIT:
                char *CLASS = "SDL::SysWMEvent";
        CODE:
@@ -209,3 +208,8 @@ event_syswm ( event, ... )
        OUTPUT:
                RETVAL
 
+void
+event_DESTROY(self)
+       SDL_Event *self
+       CODE:
+               safefree( (char *)self );
index 5e2a2e3..56d517c 100644 (file)
@@ -646,211 +646,6 @@ CDTrack ( cd, number )
        OUTPUT:
                RETVAL
 
-void
-PumpEvents ()
-       CODE:
-               SDL_PumpEvents();
-
-int
-PushEvent( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = SDL_PushEvent( e );
-       OUTPUT:
-               RETVAL
-
-SDL_Event *
-NewEvent ()
-       CODE:   
-               RETVAL = (SDL_Event *) safemalloc (sizeof(SDL_Event));
-       OUTPUT:
-               RETVAL
-
-void
-FreeEvent ( e )
-       SDL_Event *e
-       CODE:
-               safefree(e);
-
-int
-PollEvent ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = SDL_PollEvent(e);
-       OUTPUT:
-               RETVAL
-
-int
-WaitEvent ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = SDL_WaitEvent(e);
-       OUTPUT:
-               RETVAL
-
-Uint8
-EventState ( type, state )
-       Uint8 type
-       int state
-       CODE:
-               RETVAL = SDL_EventState(type,state);
-       OUTPUT:
-               RETVAL 
-
-Uint8
-EventType ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->type;
-       OUTPUT:
-               RETVAL
-
-Uint8
-SetEventType ( e, type )
-       SDL_Event *e
-       Uint8 type
-       CODE:
-               RETVAL = e->type;
-               e->type = type;
-       OUTPUT:
-               RETVAL
-
-Uint8
-ActiveEventGain ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->active.gain;
-       OUTPUT: 
-               RETVAL
-
-Uint8
-ActiveEventState ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->active.state;
-       OUTPUT:
-               RETVAL
-
-Uint8
-KeyEventState( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->key.state;
-       OUTPUT:
-               RETVAL
-
-int
-KeyEventSym ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->key.keysym.sym;
-       OUTPUT:
-               RETVAL
-
-int 
-KeyEventMod ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->key.keysym.mod;
-       OUTPUT:
-               RETVAL
-
-Uint16
-KeyEventUnicode ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->key.keysym.unicode;
-       OUTPUT:
-               RETVAL
-
-Uint8
-key_scancode ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->key.keysym.scancode;
-       OUTPUT:
-               RETVAL
-
-Uint8
-MouseMotionState ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->motion.state;
-       OUTPUT: 
-               RETVAL
-
-Uint16
-MouseMotionX ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->motion.x;
-       OUTPUT:
-               RETVAL
-
-Uint16
-MouseMotionY ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->motion.y;
-       OUTPUT:
-               RETVAL
-
-Sint16
-MouseMotionXrel( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->motion.xrel;
-       OUTPUT:
-               RETVAL
-
-Sint16
-MouseMotionYrel ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->motion.yrel;
-       OUTPUT:
-               RETVAL
-
-Uint8
-button_state ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->button.state;
-       OUTPUT:
-               RETVAL
-
-Uint8
-button ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->button.button;
-       OUTPUT:
-               RETVAL
-
-Uint16
-button_x ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->button.x;
-       OUTPUT:
-               RETVAL
-
-Uint16
-button_y ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->button.y;
-       OUTPUT:
-               RETVAL
-
-SDL_SysWMmsg *
-SysWMEventMsg ( e )
-       SDL_Event *e
-       CODE:
-               RETVAL = e->syswm.msg;
-       OUTPUT:
-               RETVAL
-
 int
 EnableUnicode ( enable )
        int enable
index 4ac5bdd..fb1aaeb 100644 (file)
@@ -17,13 +17,16 @@ use SDL::ResizeEvent;
 use SDL::SysWMEvent;
 use SDL::UserEvent;
 use SDL::Video;
+use Devel::Peek;
 use Test::More;
 
-plan ( tests => 66 );
+plan ( tests => 69 );
 
 my @done =qw/
 pump_events 
 peep_events 
+push_event
+poll_event
 /;
 
 my @done_event =qw/
@@ -98,7 +101,7 @@ my $wrevent = SDL::ResizeEvent->new();
 my $wmevent = SDL::SysWMEvent->new(); 
 my $uevent  = SDL::UserEvent->new(); 
 
-#isa_ok( $event,   'SDL::Event',            '[SDL::Event::new] is creating an Event');
+isa_ok( $event,   'SDL::Event',            '[SDL::Event::new] is creating an Event');
 isa_ok( $aevent,  'SDL::ActiveEvent',      '[SDL::ActiveEvent::new] is creating an ActiveEvent');
 isa_ok( $weevent, 'SDL::ExposeEvent',      '[SDL::ExposeEvent::new] is creating an ExposeEvent');
 isa_ok( $jaevent, 'SDL::JoyAxisEvent',     '[SDL::JoyAxisEvent::new] is creating an JoyAxisEvent');
@@ -130,11 +133,19 @@ is($wrevent->type, SDL_VIDEORESIZE, '[SDL::ResizeEvent->type] returns correctly'
 is($wmevent->type, SDL_SYSWMEVENT, '[SDL::SysWMEvent->type] returns correctly'); 
 is($uevent->type,  SDL_USEREVENT, '[SDL::UserEvent->type] returns correctly'); 
 
+my $num_peep_events = SDL::Events::peep_events($event, 127, SDL_PEEKEVENT, SDL_ALLEVENTS);
+is($num_peep_events >= 0, 1,  '[peep_events] Size of event queue is ' . $num_peep_events);
+
+
+SDL::Events::push_event($aevent); pass '[push_event] ran';
+
+SDL::Events::poll_event($event);
+
+is( $event->type, $aevent->type, '[poll_event] Got the right event back out') ;
+
 $uevent->code(200);
 is( $uevent->code, 200, '[SDL::UserEvent->code] is set correctly');
 
-my $num_peep_events = SDL::Events::peep_events($event, 127, SDL_PEEKEVENT, SDL_ALLEVENTS);
-is($num_peep_events >= 0, 1,  '[peep_events] Size of event queue is ' . $num_peep_events);
 
 TODO:
 {
diff --git a/typemap b/typemap
index 17b93e8..05a4f26 100644 (file)
--- a/typemap
+++ b/typemap
@@ -16,7 +16,7 @@ Sint16                        T_IV
 Sint16 *               T_PTR
 Sint32                 T_IV
 Sint32 *               T_PTR
-SDL_Event *            T_PTR
+SDL_Event *            O_OBJECT        
 SDL_ActiveEvent *      O_OBJECT
 SDL_KeyboardEvent *    O_OBJECT
 SDL_TextInputEvent *   O_OBJECT