-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.c
72 lines (54 loc) · 1.02 KB
/
common.c
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
#include "common.h"
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
void common_GetBasePath(const char *input, char *output)
{
#ifndef WIN32
char *e = strrchr(input, '/');
#else
char *e = strrchr(input, '\\');
#endif
int l = e - input + 1;
memmove(output, input, (size_t)l);
output[l] = 0;
}
double common_RandD()
{
return (double)random() / (double)(RAND_MAX);
}
int common_RandI()
{
return random();
}
void **common_Alloc2DTable(int w, int h, unsigned int elsz)
{
int i;
void **t;
t = malloc(sizeof(void*) * w);
for(i = 0; i < w; ++i)
t[i] = malloc(elsz * h);
return t;
}
void common_Free2DTable(void **table, int w)
{
int i;
for(i = 0; i < w; ++i)
free(table[i]);
free(table);
}
inline Point point(float x, float y)
{
Point p = {x: x, y: y};
return p;
}
inline Color color(float r, float g, float b, float a)
{
Color c = {r: r, g: g, b: b, a: a};
return c;
}
void common_Init()
{
srandom(time(NULL));
}