-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
69 lines (55 loc) · 1.29 KB
/
main.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
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
#include "pm.h"
#include "p_engine.h"
#include "p_game.h"
#include "p_render.h"
#include "p_menu.h"
#include "p_cutscene.h"
void IERROR (char * msg)
{
printf("[ERROR] %s!\n", msg);
}
void IPRINT (char * msg)
{
printf("[LOG] %s!\n", msg);
}
void spawn_processes (pm_t * pm)
{
int errlv = 0;
errlv |= pm_push(pm, "engine", p_engine_init, p_engine_update, p_engine_dtor );
errlv |= pm_push(pm, "render", p_render_init, p_render_update, p_render_dtor );
errlv |= pm_push(pm, "game", p_game_init, p_game_update, p_game_dtor );
errlv |= pm_push(pm, "menu", p_menu_init, p_menu_update, p_menu_dtor );
errlv |= pm_push(pm, "cutscene", p_cutscene_init, p_cutscene_update, p_cutscene_dtor );
if (errlv != 0)
IERROR("Failed to push certain processes!");
}
void main_loop (pm_t * pm)
{
while (pm->state == PM_RUNNING)
{
pm_update(pm);
}
}
int main (int argc, char * argv[])
{
// create process manager
srand(time(NULL));
pm_t * pm = pm_ctor();
if (pm == NULL)
{
IERROR("pm did not allocate");
return 1;
}
// create processes list
spawn_processes(pm);
// run engine process
pm_run(pm, "engine");
// enter main loop
main_loop(pm);
// cleanup memory and exit
pm_dtor(pm);
return 0;
}