Permalink
Browse files

added some more utility functions

  • Loading branch information...
1 parent a21f00a commit 70955373419bc2f295f7644192d92ac23c9c3573 @niksaak committed Feb 3, 2013
Showing with 38 additions and 1 deletion.
  1. +30 −0 src/engine/util.c
  2. +8 −1 src/engine/util.h
View
30 src/engine/util.c
@@ -6,6 +6,16 @@
#include "util.h"
+SDL_Point SDLpt(int x, int y)
+{
+ static SDL_Point pt;
+
+ pt.x = x;
+ pt.y = y;
+
+ return pt;
+}
+
SDL_Point cpvSDL(cpVect vector, SDL_Surface* target, cpVect offset)
{
SDL_Point pt;
@@ -16,6 +26,11 @@ SDL_Point cpvSDL(cpVect vector, SDL_Surface* target, cpVect offset)
return pt;
}
+cpVect SDLcpv(SDL_Point point, SDL_Surface* target, cpVect offset)
+{
+ return cpvzero; // FIXME
+}
+
bool nullp(const void* ptr)
{
if(ptr == NULL)
@@ -35,3 +50,18 @@ void crash(const char* funname, const char* reason)
fprintf(stderr, "%s: CRUSHING ERROR: %s\n", funname, reason);
exit(EXIT_FAILURE);
}
+
+int ran_domo(Uint32 min, Uint32 max)
+{
+ int domo = rand();
+
+ if(domo == RAND_MAX)
+ return ran_domo(min, max);
+ int range = max - min;
+ int rem = RAND_MAX % range;
+ int bucket = RAND_MAX / range;
+
+ if(domo < RAND_MAX - rem)
+ return min + domo / bucket;
+ return ran_domo(min, max);
+}
View
9 src/engine/util.h
@@ -1,5 +1,6 @@
#pragma once
+#include <stdlib.h>
#include <stdbool.h>
#include <SDL/SDL.h>
@@ -22,10 +23,16 @@ typedef struct SDL_point {
int y;
} SDL_Point;
-extern SDL_Point cpvSDL(cpVect point, SDL_Surface* target, cpVect offset);
+extern SDL_Point SDLpt(int x, int y);
+
+extern SDL_Point cpvSDL(cpVect vector, SDL_Surface* target, cpVect offset);
+
+extern cpVect SDLcpv(SDL_Point point, SDL_Surface* target, cpVect offset);
extern bool nullp(const void*);
extern void warn(const char*, const char*);
extern void crash(const char*, const char*);
+
+extern int ran_domo(Uint32 min, Uint32 max);

0 comments on commit 7095537

Please sign in to comment.