-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine.c
78 lines (63 loc) · 1.9 KB
/
engine.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
#include "engine.h"
#include "service_provider.h"
#include <stddef.h>
#ifndef NDEBUG
#include <stdio.h>
#include <assert.h>
#endif
#ifndef RAYLIB_PROVIDER
#define RCAMERA_IMPLEMENTATION
#define RCAMERA_STANDALONE
#include "rcamera.h"// Includes raymath definitions
#endif
typedef enum{
Update,
Render,
Shutdown
}private_funcs_e;
static Engine engine ={0};
// Define the camera to look into our 3d world
static Camera camera = { 0 };
void engine_init(const char* window_name,int w, int h){
//load service and open window
service_provider_init(window_name,w,h);
create_timer_provider(&engine);
create_input_provider(&engine);
create_ui_provider(&engine);
create_logger_provider(&engine);
create_world_provider(&engine);
create_graphics_provider(&engine);
create_audio_provider(&engine);
create_levelLoader_provider(&engine);
// #ifndef NDEBUG
// size_t IInputSize = sizeof(IInput);
// unsigned char *bytePtr = (unsigned char *)engine.input;
// for (size_t i = 0; i < IInputSize; i+=sizeof(void*)) {
// void* data = bytePtr[i];
// if(data == NULL){
// int index = i == 0 ? 0: i /sizeof(void*);
// fprintf(stderr,"Field at index %d of IInput Provider is not implemented.\n",index);
// }
// assert(data != NULL);
// }
// #endif
}
void engine_update(void){
engine.timer->private_funcs[Update](NULL);
engine.input->private_funcs[Update](NULL);
engine.sfx->private_funcs[Update](NULL);
engine.world->private_funcs[Update](NULL);
engine.world->private_funcs[Render](NULL);
engine.timer->sleep_end_frame();
}
void engine_start(void){
service_provider_start(engine_update);
engine.ui->private_funcs[Shutdown](NULL);
engine.log->private_funcs[Shutdown](NULL);
}
void engine_stop(void){
service_provider_stop();
}
const Engine* engine_get(void){
return &engine;
}