-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadditions.c
103 lines (80 loc) · 1.48 KB
/
additions.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
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
#include <stdio.h>
#include <stdlib.h>
//#include <math.h>
#include <string.h>
#include "SDL2/SDL.h"
#include "additions.h"
bool FileExists (const char* fileName)
{
FILE* f = fopen (fileName, "r");
if (f == NULL)
{
return false;
}
else
{
fclose (f);
f = NULL;
return true;
}
}
void Swapc (char** a, char** b)
{
char* t = *a;
*a = *b;
*b = t;
}
void Swaps (short* a, short* b)
{
short t = *a;
*a = *b;
*b = t;
}
void Swapi (int* a, int* b)
{
int t = *a;
*a = *b;
*b = t;
}
void Swapf (float* a, float* b)
{
float t = *a;
*a = *b;
*b = t;
}
void LimitShort (short* a, short min, short max)
{
if (*a < min) *a = min;
if (*a > max) *a = max;
}
void LimitInt (int* a, int min, int max)
{
if (*a < min) *a = min;
if (*a > max) *a = max;
}
void LimitFloat (float* a, float min, float max)
{
if (*a < min) *a = min;
if (*a > max) *a = max;
}
float DegToRad (float degree)
{
static float coeff = 180.0f / M_PI;
return (degree / coeff);
}
float RadToDeg (float radian)
{
static float coeff = 180.0f / M_PI;
return (radian * coeff);
}
byte StrEqual (const char* str1, const char* str2)
{
// not correct!
if (str1 == NULL || str1 == NULL)
return -1;
// strings equal
if (strcmp (str1, str2) == 0)
return true;
// strings not equal
return false;
}