-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenaengine.c
More file actions
127 lines (116 loc) · 2.9 KB
/
enaengine.c
File metadata and controls
127 lines (116 loc) · 2.9 KB
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
//Sys includes
//local includes
#include "globaldefs.h"
#include "enaengine.h"
#include "glmanager.h"
#include "vkmanager.h"
//#include "sdlmanager.h"
#include "glfwmanager.h"
#include "console.h"
#include "gamecodemanager.h"
#include "cvarmanager.h"
//#include "worldmanager.h"
extern int initWorldSystem(void);
extern int worldOK;
cvar_t cvar_gl_vulkan = {CVAR_SAVEABLE, "gl_vulkan", "Render using the vulkan api instead of opengl", "0"};
//main
extern double glfwGetTime(void);
//extern int SDL_GetTicks(); //will remove later todo
int main(int argc, char *argv[]){
double to, t;
// unsigned int to, t;
unsigned int framecount = 0;
cvar_init();
if(!cvar_ok){
//todo some sorta shutdown path
printf("ERROR initializing cvar system!\n");
exit(1);
} else {
printf("Cvar system has initialized correctly\n");
}
cvar_register(&cvar_gl_vulkan);
cvar_pset(&cvar_gl_vulkan, "1");
console_init();
// sdlInit(800, 600, 24, 1);
glfw_init(800, 600, 24,1);
if(cvar_gl_vulkan.valueint){
#ifdef VULKAN_COMPILE
if(vk_init()){
console_printf("vulkan has initailized correctly\n");
}
#else
printf("Compiled without vulkan support!, reverting to GL\n");
cvar_pset(&cvar_gl_vulkan, "0");
if(glInit()){
console_printf("opengl has initailized correctly\n");
}
#endif
} else {
if(glInit()){
console_printf("opengl has initailized correctly\n");
}
}
initWorldSystem();
if(worldOK){
console_printf("world has initailized correctly\n");
}
initGameCodeSystem();
if(gamecodeOK){
console_printf("gamecode has initailized correctly\n");
} else {
//todo
console_printf("gamecode has failed to load\n");
}
// printConsoleBackwards();
// to = SDL_GetTicks();
to = glfwGetTime();
// unsigned int timesincelastfpsupdate = 0;
// unsigned int accum = 0;
double timesincelastfpsupdate = 0;
double accum = 0;
while(TRUE){
// t = SDL_GetTicks();
t = glfwGetTime();
// unsigned int delta = t-to;
double delta = (t-to);
to = t;
timesincelastfpsupdate += delta;
/*
if(timesincelastfpsupdate > 10000){
console_printf("%f fps\n", (float)framecount*1000.0/(float)timesincelastfpsupdate);
timesincelastfpsupdate -= 10000;
framecount = 0;
}
*/
// if(timesincelastfpsupdate > 10000){
if(timesincelastfpsupdate > 10.000){
// console_printf("%f fps\n", (float)framecount*1000.0/(float)timesincelastfpsupdate);
console_printf("%f fps\n", (double)framecount/timesincelastfpsupdate);
// timesincelastfpsupdate -= 10000;
timesincelastfpsupdate -=10.0;
framecount = 0;
}
accum+= delta;
// sdlCheckEvent();
glfw_checkEvent();
#ifdef DEBUGTIMESTEP
gameCodeTick();
accum = 0;
#else
// while(accum>GCTIMESTEP){
while(accum*1000.0>GCTIMESTEP){
gameCodeTick();
// accum-=GCTIMESTEP;
accum-=(double)GCTIMESTEP/1000.0;
}
#endif
#ifdef VULKAN_COMPILE
if(cvar_gl_vulkan.valueint) vk_mainDraw();
else glMainDraw();
#else
glMainDraw();
#endif
framecount++;
}
return FALSE;
}