SDL  2.0
common.c
Go to the documentation of this file.
1 /*
2  * common.c
3  * written by Holmes Futrell
4  * use however you want
5  */
6 
7 #include "common.h"
8 #include "SDL.h"
9 #include <stdlib.h>
10 
11 /*
12  Produces a random int x, min <= x <= max
13  following a uniform distribution
14 */
15 int
16 randomInt(int min, int max)
17 {
18  return min + rand() % (max - min + 1);
19 }
20 
21 /*
22  Produces a random float x, min <= x <= max
23  following a uniform distribution
24  */
25 float
26 randomFloat(float min, float max)
27 {
28  return rand() / (float) RAND_MAX *(max - min) + min;
29 }
30 
31 void
32 fatalError(const char *string)
33 {
34  printf("%s: %s\n", string, SDL_GetError());
36  exit(1);
37 }
38 
39 static Uint64 prevTime = 0;
40 
41 double
43 {
44  Uint64 curTime;
45  double deltaTime;
46 
47  if (prevTime == 0) {
49  }
50 
51  curTime = SDL_GetPerformanceCounter();
52  deltaTime = (double) (curTime - prevTime) / (double) SDL_GetPerformanceFrequency();
53  prevTime = curTime;
54 
55  return deltaTime;
56 }
static Uint64 prevTime
Definition: common.c:39
#define SDL_GetError
double updateDeltaTime(void)
Definition: common.c:42
void fatalError(const char *string)
Definition: common.c:32
Uint64 SDL_GetPerformanceFrequency(void)
Get the count per second of the high resolution counter.
int randomInt(int min, int max)
Definition: common.c:16
uint64_t Uint64
Definition: SDL_stdinc.h:216
float randomFloat(float min, float max)
Definition: common.c:26
#define SDL_ShowSimpleMessageBox
#define SDL_GetPerformanceCounter
#define NULL
Definition: begin_code.h:164