-
Notifications
You must be signed in to change notification settings - Fork 0
/
Engine.h
142 lines (109 loc) · 2.79 KB
/
Engine.h
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Engine is built on top of SDL.
// SDL functions have prefix SDL_.....
// Engine functions don't have a prefix.
#pragma once
#include <cstring>
#include <stdint.h>
#include <stdio.h>
#include <string>
#include <time.h>
typedef int64_t s64;
typedef int32_t s32;
typedef int16_t s16;
typedef int8_t s8;
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
struct v2 {
float x, y;
};
struct v2i {
int x, y;
bool operator==(const v2i& other) const {
return x == other.x && y == other.y;
}
};
struct v3 {
float x, y, z;
};
struct v4 {
float x, y, z, w;
};
struct IntRect {
int x, y, w, h;
};
struct FloatRect {
float x, y, w, h;
};
// bmalloc with auto casting
// We don't use new because new usually implies a constructor.
#define bmalloc(t) (t *)(malloc(sizeof(t)))
#define bmalloc_arr(t, n) (t *)(malloc(sizeof(t) * n))
#include "utils/itoa.h"
#include "utils/string.h"
#include <GL/glew.h>
// SDL cross platform includes
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
// printf + SDL does not work (something to do with SDL redirecting the entry
// point, I think), and so you are forced to use print. I've added a cheat here
// so that it's more readable. If I could avoid it I would.
// This also means if I ever figure out how to actually use printf, I can
// smoothly transition by doing something like #define print as printf + "\n"
#undef print
#undef printf
#define print SDL_Log
// for any libraries so that I don't have to replace all the printfs with print
// / print.
#define printf SDL_Log
// Because consistent casing is nice
#define glew_init glewInit
#ifdef _WIN32
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
#elif __linux__
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_ttf.h>
#else
#include <SDL2_image/SDL_image.h>
#include <SDL2_ttf/SDL_ttf.h>
#include <SDL2_mixer/SDL_mixer.h>
#endif
#ifdef ENGINE_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#define GLT_IMPLEMENTATION
#define MINIAUDIO_IMPLEMENTATION
#define ASE_LOADER_IMPLEMENTATION
#endif
#include "Window.h"
#include "Graphics.h"
#include "Controls.h"
#include "Asset.h"
#include "Clock.h"
#include "Animation.h"
#include "ExtraMath.h"
#include "utils/miniaudio.h"
#include "Sound.h"
void EngineInit();
void EngineQuit();
#ifdef ENGINE_IMPLEMENTATION
void EngineInit() {
SDL_Init(SDL_INIT_EVERYTHING);
assert(TTF_Init() == 0);
IMG_Init(IMG_INIT_PNG);
srand(time(0));
g_controls.Init();
assert(ma_engine_init(NULL, & sound_engine) == MA_SUCCESS);
Ase_SetFlipVerticallyOnLoad(true);
stbi_set_flip_vertically_on_load(true);
}
void EngineQuit() {
IMG_Quit();
TTF_Quit();
ma_engine_uninit(& sound_engine);
SDL_Quit();
}
#endif