Cytopia
0.3
A city building simulation game
Main Page
Related Pages
Namespaces
Namespace List
Namespace Members
All
Functions
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
w
z
~
Variables
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
w
x
y
z
Typedefs
a
c
d
e
g
i
m
n
p
r
s
t
u
v
Enumerations
Enumerator
Related Functions
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
z
Functions
b
c
d
f
g
i
m
o
p
r
s
t
w
Variables
a
c
d
g
h
i
l
m
n
r
s
t
Typedefs
a
c
d
e
f
g
i
j
l
m
n
r
s
t
v
Enumerations
Enumerator
a
b
d
e
f
g
l
m
n
p
r
s
t
u
w
z
Macros
_
c
e
i
l
n
r
s
t
v
Examples
▼
Cytopia
Todo List
►
Namespaces
►
Classes
▼
Files
▼
File List
▼
src
►
engine
►
game
►
scripting
►
services
►
util
►
windows
Game.cxx
►
Game.hxx
►
main.cxx
►
MainMenu.cxx
►
MainMenu.hxx
phc.hxx
►
File Members
►
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
main.cxx
Go to the documentation of this file.
1
#include <iostream>
2
3
#include "
Game.hxx
"
4
#include "
MainMenu.hxx
"
5
#include "
Exception.hxx
"
6
#include "
LOG.hxx
"
7
#include "
engine/WindowManager.hxx
"
8
#include <
UIManager.hxx
>
9
10
#include <SDL.h>
11
#include <SDL_ttf.h>
12
13
bool
initialize
(
const
char
*videoDriver)
14
{
15
if
(SDL_Init(0) != 0)
16
{
17
LOG
(
LOG_ERROR
) <<
"Failed to Init SDL"
;
18
LOG
(
LOG_ERROR
) <<
"SDL Error: "
<< SDL_GetError();
19
return
false
;
20
}
21
22
if
(SDL_VideoInit(videoDriver) != 0)
23
{
24
LOG
(
LOG_ERROR
) <<
"Unknown video driver "
<< videoDriver;
25
int
nbDriver = SDL_GetNumRenderDrivers();
26
for
(
int
i = 0; i < nbDriver; i++)
27
{
28
SDL_RendererInfo info;
29
SDL_GetRenderDriverInfo(i, &info);
30
LOG
(
LOG_ERROR
) <<
"Found driver "
<< i <<
": "
<< (info.name ? info.name :
"Invalid driver"
)
31
<<
" with flags="
<< info.flags;
32
}
33
return
false
;
34
}
35
36
if
(TTF_Init() == -1)
37
{
38
LOG
(
LOG_ERROR
) <<
"Failed to Init SDL_TTF"
;
39
LOG
(
LOG_ERROR
) <<
"SDL Error: "
<< TTF_GetError();
40
return
false
;
41
}
42
43
// initialize window manager
44
WindowManager::instance
().
setWindowTitle
(
VERSION
);
45
return
true
;
46
}
47
48
int
protected_main
(
int
argc,
char
**argv)
49
{
50
(void)argc;
51
(void)argv;
52
53
LOG
(
LOG_INFO
) <<
VERSION
;
54
55
// add commandline parameter to skipMenu
56
auto
has_args = [argv, argc](
const
std::string
¶m)
57
{
58
for
(
int
i = 1; i < argc; ++i)
59
if
(param == argv[i])
60
return
i;
61
62
LOG
(
LOG_DEBUG
) <<
"Unknown game option "
<< param;
63
return
0;
64
};
65
66
bool
skipMenu = has_args(
"--skipMenu"
);
67
uint32_t videoOpt = has_args(
"--video"
);
68
const
char
*videoDriver =
nullptr
;
69
if
(videoOpt)
70
{
71
videoDriver = argv[videoOpt + 1];
72
}
73
74
LOG
(
LOG_DEBUG
) <<
"Launching Cytopia"
;
75
76
Cytopia::Game
game;
77
78
LOG
(
LOG_DEBUG
) <<
"Initializing Cytopia"
;
79
80
if
(!
initialize
(videoDriver))
81
return
EXIT_FAILURE;
82
else
83
LOG
(
LOG_DEBUG
) <<
"DONE Cytopia"
;
84
85
bool
startGame =
true
;
86
if
(!skipMenu)
87
{
88
startGame =
mainMenu
();
89
}
90
91
if
(startGame)
92
{
93
LOG
(
LOG_DEBUG
) <<
"Running the Game"
;
94
game.
run
(skipMenu);
95
}
96
97
LOG
(
LOG_DEBUG
) <<
"Closing the Game"
;
98
game.
shutdown
();
99
100
return
EXIT_SUCCESS;
101
}
102
103
int
main
(
int
argc,
char
**argv)
104
{
105
systemSetupCrashHandler
();
106
107
try
108
{
109
return
protected_main
(argc, argv);
110
}
111
catch
(std::exception &e)
112
{
113
LOG
(
LOG_ERROR
) << e.what();
114
}
115
catch
(...)
116
{
117
LOG
(
LOG_ERROR
) <<
"Caught unknown exception"
;
118
}
119
120
return
EXIT_FAILURE;
121
}
Cytopia::Game::run
virtual void run(bool SkipMenu=false)
begins the game
Definition:
Game.cxx:82
LOG
Definition:
LOG.hxx:32
LOG_INFO
@ LOG_INFO
Definition:
LOG.hxx:25
mainMenu
bool mainMenu()
initializes and displays the main menu
Definition:
MainMenu.cxx:34
LOG.hxx
protected_main
int protected_main(int argc, char **argv)
Definition:
main.cxx:48
LOG_ERROR
@ LOG_ERROR
Definition:
LOG.hxx:28
LOG_DEBUG
@ LOG_DEBUG
Definition:
LOG.hxx:26
initialize
bool initialize(const char *videoDriver)
Definition:
main.cxx:13
WindowManager.hxx
systemSetupCrashHandler
void systemSetupCrashHandler(void)
install OS crash handler
Definition:
Exception.cxx:206
Cytopia::Game
Definition:
Game.hxx:24
MainMenu.hxx
UIManager.hxx
Singleton< WindowManager >::instance
static WindowManager & instance(void)
Get an instance of the singleton.
Definition:
Singleton.hxx:15
Cytopia::Game::shutdown
virtual void shutdown()
ends the game
Definition:
Game.cxx:191
Game.hxx
Exception.hxx
WindowManager::setWindowTitle
void setWindowTitle(const std::string &title)
sets title of the window
Definition:
WindowManager.cxx:135
main
int main(int argc, char **argv)
Definition:
main.cxx:103
VERSION
#define VERSION
Definition:
MainMenu.hxx:5
string
std::string string
Definition:
AudioConfig.hxx:14
src
main.cxx
Generated on Sun Nov 27 2022 09:50:52 for Cytopia by
1.8.17