Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 156 lines (135 sloc) 2.75 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"

#ifndef aTHX_
#define aTHX_
#endif

#include <SDL.h>
#include "SDLx/Timer.h"

MODULE = SDLx::Controller::Timer PACKAGE = SDLx::Controller::Timer PREFIX = timerx_

sdlx_timer *
timerx_new (CLASS, ... )
char* CLASS
CODE:
RETVAL = (sdlx_timer *)safemalloc( sizeof(sdlx_timer) );
RETVAL->started_ticks = 0;
RETVAL->paused_ticks = 0;
RETVAL->started = 0;
RETVAL->paused = 0;
OUTPUT:
RETVAL


int
timerx_started_ticks ( timer, ... )
sdlx_timer *timer
CODE:
if (items > 1 ) timer->started_ticks = SvIV(ST(1));
RETVAL = timer->started_ticks;
OUTPUT:
RETVAL

int
timerx_paused_ticks ( timer, ... )
sdlx_timer *timer
CODE:
if (items > 1 ) timer->paused_ticks = SvIV(ST(1));
RETVAL = timer->paused_ticks;
OUTPUT:
RETVAL

int
timerx_started ( timer, ... )
sdlx_timer *timer
CODE:
if (items > 1 ) timer->started = SvIV(ST(1));
RETVAL = timer->started;
OUTPUT:
RETVAL

int
timerx_paused ( timer, ... )
sdlx_timer *timer
CODE:
if (items > 1 ) timer->paused = SvIV(ST(1));
RETVAL = timer->paused;
OUTPUT:
RETVAL

void
timerx_start ( timer )
sdlx_timer *timer
CODE:
timer->started = 1;
timer->started_ticks = SDL_GetTicks();

void
timerx_stop ( timer )
sdlx_timer *timer
CODE:
timer->started = 0;
timer->paused = 0;

void
timerx_pause ( timer )
sdlx_timer *timer
CODE:
if( timer->started == 1 && timer->paused == 0)
{
timer->paused = 1;
timer->paused_ticks = SDL_GetTicks() - timer->started_ticks;
}

void
timerx_unpause ( timer )
sdlx_timer *timer
CODE:
timer->paused = 0;
timer->started_ticks = SDL_GetTicks() - timer->started_ticks;
timer->paused_ticks = 0;

int
timerx_get_ticks ( timer )
sdlx_timer *timer
CODE:
if(timer->started == 1)
{
if(timer->paused == 1)
{
RETVAL = timer->paused_ticks;
}
else
{
int update = SDL_GetTicks();
int diff = update - timer->started_ticks;
RETVAL = diff;
}
}
else
{
RETVAL = 0;
}
OUTPUT:
RETVAL


int
timerx_is_started ( timer )
sdlx_timer *timer
CODE:
RETVAL = timer->started;
OUTPUT:
RETVAL

int
timerx_is_paused ( timer)
sdlx_timer *timer
CODE:
RETVAL = timer->paused;
OUTPUT:
RETVAL


void
timerx_DESTROY(bag)
SV *bag
CODE:
if( sv_isobject(bag) && (SvTYPE(SvRV(bag)) == SVt_PVMG) ) {
void** pointers = (void**)INT2PTR(void *, SvIV((SV *)SvRV( bag )));
sdlx_timer * timer = (sdlx_timer*)(pointers[0]);
if (PERL_GET_CONTEXT == pointers[1]) {
pointers[0] = NULL;
safefree( pointers );

safefree(timer);
}
} else if (bag == 0) {
XSRETURN(0);
} else {
XSRETURN_UNDEF;
}

Something went wrong with that request. Please try again.