forked from fredbcode/cabrio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
174 lines (143 loc) · 3 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <stdio.h>
#include "sdl_wrapper.h"
#include "ogl.h"
#include "font.h"
#include "config.h"
#include "category.h"
#include "platform.h"
#include "bg.h"
#include "menu.h"
#include "submenu.h"
#include "hint.h"
#include "game_sel.h"
#include "sound.h"
#include "event.h"
#include "setup.h"
#include "focus.h"
#include "snap.h"
#include "location.h"
#include "video.h"
static int supress_wait = 0;
void supress( int frame_rate ) {
supress_wait = frame_rate / 5;
}
void clean_up( void ) {
sound_free();
game_list_free();
submenu_free();
platform_free();
menu_free();
hint_free();
font_free();
bg_free();
location_free();
event_free();
snap_free();
video_free();
sdl_free();
}
void bail( void ) {
/* Exit "gracefully" */
clean_up();
exit( -1 );
}
int main( int argc, char *arvg[] ) {
const struct config *config_m = config_get();
int quit = 0;
int config_status = 0;
int event = EVENT_SELECT;
// Initialise pseudo random generator
srand( time( NULL ) );
#ifdef __WIN32__
freopen( "cabrio.out", "w", stdout );
freopen( "cabrio.err", "w", stderr );
#endif
config_status = config_open( NULL );
if( config_status == -1 )
return -1;
if( sdl_init() != 0 )
bail();
if( ogl_init() != 0 )
bail();
/* Clear the screen as soon as we can. This avoids graphics
* glitches which can occur with some SDL implementations. */
ogl_clear();
sdl_swap();
if( event_init() != 0 )
bail();
if( font_init() != 0 )
bail();
if( config_status == 1 ) {
/* Config file didn't exist, so run the setup utility */
if( setup() != 0 )
return -1;
config_update();
if( config_create() != 0 )
return -1;
}
location_init();
/* If config or location results in a new font, it'll be loaded here. */
font_free();
font_init();
/* Large game lists take a while to initialise,
* so show the background while we wait... */
bg_init();
bg_clear();
bg_draw();
sdl_swap();
if( platform_init() != 0 )
bail();
if( category_init() != 0 )
bail();
if( game_sel_init() != 0 )
bail();
if( hint_init() != 0 )
bail();
if( snap_init() != 0 )
bail();
if( game_list_create() != 0 )
bail();
if( menu_init() != 0 )
bail();
if( submenu_init() != 0 )
bail();
sound_init();
video_init();
event_flush();
if( !config_m->iface.theme.menu.auto_hide )
menu_show();
focus_set( FOCUS_GAMESEL );
while( !quit ) {
if( event == EVENT_SELECT ) {
event_set_filter();
event = EVENT_NONE;
}
ogl_clear();
bg_draw();
snap_draw();
if (!config_m->iface.hide_buttons)
hint_draw();
menu_draw();
submenu_draw();
game_sel_draw();
sdl_swap();
if (Mix_PlayingMusic() != 1 && config_m->iface.theme_sound && reader_running == 0)
playmusic();
if (( event = event_poll( event ) )) {
if( supress_wait == 0 ) {
if( event == EVENT_QUIT ) {
quit = 1;
}
else {
supress( config_m->iface.frame_rate );
event_process( event );
}
}
}
if( supress_wait > 0 )
supress_wait--;
sdl_frame_delay( config_m->iface.frame_rate );
}
clean_up();
return 0;
}