-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
87 lines (72 loc) · 1.55 KB
/
Main.cpp
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
#include "Application.h"
#include "Globals.h"
#include "MemLeaks.h"
#include "SDL.h"
enum class main_states
{
MAIN_CREATION,
MAIN_START,
MAIN_UPDATE,
MAIN_FINISH,
MAIN_EXIT
};
Application* App = nullptr;
int main(int argc, char* argv[])
{
ReportMemoryLeaks();
int mainReturn = EXIT_FAILURE;
main_states state = main_states::MAIN_CREATION;
while (state != main_states::MAIN_EXIT)
{
switch (state)
{
case main_states::MAIN_CREATION:
{
LOG("Application Creation --------------\n");
App = new Application();
state = main_states::MAIN_START;
} break;
case main_states::MAIN_START:
{
LOG("Application Start --------------\n");
if (App->Init() == false)
{
LOG("Application Init exits with error -----\n");
state = main_states::MAIN_EXIT;
}
else
{
state = main_states::MAIN_UPDATE;
}
} break;
case main_states::MAIN_UPDATE:
{
update_status status = App->Update();
if (status == update_status::UPDATE_ERROR)
{
LOG("Application Update exits with error -----\n");
state = main_states::MAIN_EXIT;
}
else if (status == update_status::UPDATE_STOP)
{
state = main_states::MAIN_FINISH;
}
} break;
case main_states::MAIN_FINISH:
{
LOG("Cleaning Game -----\n");
if (App->CleanUp() == false)//if the cleanup gives an error the game is finished with errors
{
LOG("Game CleanUp returning with some errors -----");
}
else {
mainReturn = EXIT_SUCCESS;
state = main_states::MAIN_EXIT;
}
} break;
}
}
LOG("\nBye :)\n");
delete App;
return mainReturn;
}