PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/src/GFX/FPSManager.xs

http://github.com/PerlGameDev/SDL
Unknown | 106 lines | 88 code | 18 blank | 0 comment | 0 complexity | 761385735ce008ae60f376dd242c1272 MD5 | raw file
  1#include "EXTERN.h"
  2#include "perl.h"
  3#include "XSUB.h"
  4#include "ppport.h"
  5
  6#ifndef aTHX_
  7#define aTHX_
  8#endif
  9
 10#include <SDL.h>
 11
 12#ifdef HAVE_SDL_GFX_FRAMERATE
 13#include <SDL_framerate.h>
 14#endif
 15
 16MODULE = SDL::GFX::FPSManager 	PACKAGE = SDL::GFX::FPSManager    PREFIX = gfx_fps_
 17
 18=for documentation
 19
 20The Following are XS bindings to the SDL_gfx Library
 21
 22typedef struct {
 23    Uint32 framecount;
 24    float rateticks;
 25    Uint32 lastticks;
 26    Uint32 rate;
 27    } FPSmanager;
 28
 29Described here:
 30
 31See: L<http:/*www.ferzkopp.net/joomla/content/view/19/14/> */
 32
 33=cut
 34
 35#ifdef HAVE_SDL_GFX_FRAMERATE
 36
 37FPSmanager *
 38gfx_fps_new (CLASS, framecount, rateticks, lastticks, rate)
 39	char *CLASS
 40	Uint32 framecount
 41    float rateticks
 42    Uint32 lastticks
 43    Uint32 rate
 44	CODE:
 45		RETVAL = (FPSmanager *) safemalloc(sizeof(FPSmanager));
 46		RETVAL->framecount = framecount;
 47		RETVAL->rateticks  = rateticks;
 48		RETVAL->lastticks  = lastticks;
 49		RETVAL->rate       = rate;
 50	OUTPUT:
 51		RETVAL
 52
 53Uint32
 54gfx_fps_framecount ( fps, ... )
 55	FPSmanager *fps
 56	CODE:
 57		if (items > 1 ) fps->framecount = SvIV(ST(1)); 
 58		RETVAL = fps->framecount;
 59	OUTPUT:
 60		RETVAL
 61
 62float
 63gfx_fps_rateticks ( fps, ... )
 64	FPSmanager *fps
 65	CODE:
 66		if (items > 1 ) fps->rateticks = SvNV(ST(1)); 
 67		RETVAL = fps->rateticks;
 68	OUTPUT:
 69		RETVAL
 70
 71Uint32
 72gfx_fps_lastticks ( fps, ... )
 73	FPSmanager *fps
 74	CODE:
 75		if (items > 1 ) fps->lastticks = SvIV(ST(1)); 
 76		RETVAL = fps->lastticks;
 77	OUTPUT:
 78		RETVAL
 79
 80Uint32
 81gfx_fps_rate ( fps, ... )
 82	FPSmanager *fps
 83	CODE:
 84		if (items > 1 ) fps->rate = SvIV(ST(1)); 
 85		RETVAL = fps->rate;
 86	OUTPUT:
 87		RETVAL
 88
 89void
 90gfx_fps_DESTROY(bag)
 91	SV *bag
 92	CODE:
 93		if( sv_isobject(bag) && (SvTYPE(SvRV(bag)) == SVt_PVMG) ) {
 94			   void** pointers = (void**)INT2PTR(void *, SvIV((SV *)SvRV( bag ))); 
 95			   FPSmanager * fps = (FPSmanager*)(pointers[0]);
 96			   if (PERL_GET_CONTEXT == pointers[1]) {
 97			       pointers[0] = NULL;
 98			       safefree(fps);
 99			   }
100		       } else if (bag == 0) {
101			   XSRETURN(0);
102		       } else {
103			   XSRETURN_UNDEF;
104		       }
105
106#endif