1 // -----------------------------------------------
3 // -----------------------------------------------
5 // Copyright (c) 2003, 2004, Kronoman
6 // In loving memory of my father
8 // -----------------------------------------------
10 // -----------------------------------------------
11 // Start up code ; program entry point.
12 // -----------------------------------------------
14 #include <allegro.h> // Allegro : http://alleg.sf.net/
15 #include <aldumb.h> // DUMB : http://dumb.sf.net/
17 #include <string.h> // for checking command line
19 #include "gerror.h" // error reporting
20 #include "mapedit.h" // built in map editor -:^D
21 #include "gamemenu.h" // game menu
30 mtracer
.add("CMain()::CMain()");
34 mtracer
.add("CMain()::~CMain()");
37 void start(bool want_map_editor
);
40 CMyTracer mtracer
; // debug tracer
41 CGameMenu game_menu
; // game menu(s)
42 CMapEditor map_editor
; // map editor
45 void CMain::start(bool want_map_editor
)
47 mtracer
.add("CMain()::start()");
53 mtracer
.add("CMain::start()\n\tStarting map editor");
54 map_editor
.start_map_editor();
58 // DEBUG -- here you can construct a more complex loop, for using different stages
59 // like presentation, game menu, and game start, or just a menu, etc
61 mtracer
.add("CMain::start()\n\tStarting main menu");
62 game_menu
.do_main_menu(); // main menu
67 // --------------------------------------------------------
69 // Program entry point
70 // --------------------------------------------------------
73 int main(int argc
, char *argv
[] )
76 int vid_m
= GFX_AUTODETECT
; // screen desired graphic mode
77 int game_color_depth
= -1; // default color depth, -1 = autodetect from desktop default
78 int vid_w
= 640; // desired video resolution
80 bool want_sound
= true; // want sound?
81 bool want_map_editor
= false; // want to use the map editor?
84 CMyTracer mtracer
; // debug tracer
85 CMyTracer::DISABLE_TRACE
= true; // by default, we not debug trace
87 allegro_init(); // init allegro
88 atexit(&dumb_exit
); // DUMB exit functions
90 // check command line parameters
91 for (i
=1; i
< argc
; i
++)
93 if (stricmp(argv
[i
], "-trace") == 0)
94 CMyTracer::DISABLE_TRACE
= false; // enable debug tracer
96 if (stricmp(argv
[i
], "-wn") == 0)
97 vid_m
= GFX_AUTODETECT_WINDOWED
;
99 if (stricmp(argv
[i
], "-nosound") == 0)
102 if (stricmp(argv
[i
], "-w") == 0)
103 vid_m
= GFX_AUTODETECT_WINDOWED
;
105 if (stricmp(argv
[i
], "-f") == 0)
106 vid_m
= GFX_AUTODETECT_FULLSCREEN
;
108 if (stricmp(argv
[i
], "-bpp16") == 0)
109 game_color_depth
= 16;
111 if (stricmp(argv
[i
], "-bpp15") == 0)
112 game_color_depth
= 15;
114 if (stricmp(argv
[i
], "-bpp32") == 0)
115 game_color_depth
= 32;
117 if (stricmp(argv
[i
], "-bpp24") == 0)
118 game_color_depth
= 24;
120 if (stricmp(argv
[i
], "-bpp8") == 0)
122 raise_error("main() : Sorry, this program don't support 8 bpp displays.\nThis program needs a true color display at %3d x %3d resolution.\nTip: Try removing the -bpp8 switch from the command line invocation.", vid_w
, vid_h
);
125 // development options
126 if (stricmp(argv
[i
], "-mapeditor") == 0)
127 want_map_editor
= true; // use the map editor... cool
130 // dumb_register_packfiles(); // DUMB will read from packfiles - NO NECESARIO, no cargo nada del disco, solo a traves de datafiles
132 // register DUMB music files -- DEBUG : registrar solo el formato que voy a usar!
133 dumb_register_dat_it(DUMB_DAT_IT
);
134 dumb_register_dat_xm(DUMB_DAT_XM
);
135 dumb_register_dat_s3m(DUMB_DAT_S3M
);
136 dumb_register_dat_mod(DUMB_DAT_MOD
);
138 set_window_title("KBall"); // setear nombre de la ventana :o
140 mtracer
.add("\n--------------------------------------------------------\nmain() started\n");
142 desk_bpp
= desktop_color_depth(); // using the same color depth as the host will make the game run faster
143 if (desk_bpp
!= 8 && desk_bpp
!= 0 && game_color_depth
== -1)
145 // use the color depth of desktop
146 game_color_depth
= desk_bpp
;
149 if (game_color_depth
< 8)
150 game_color_depth
= 16; // safe check
152 srand(time(NULL
)); // init random numbers
154 if (install_timer() != 0)
155 raise_error("main() : can't install timer driver");
157 mtracer
.add("\tTimer installed");
159 if (install_keyboard() != 0)
160 raise_error("main() : can't install keyboard driver");
164 install_joystick(JOY_TYPE_AUTODETECT
);
166 mtracer
.add("\tInput devices installed");
170 //if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) ) raise_error("install_sound() failed.\n'%s'\nTry disabling the sound with -nosound parameter.\n", allegro_error);
172 reserve_voices(8, 0);
173 set_volume_per_voice(2); // warning - this may cause distortion
175 mtracer
.add("\tInstall sound");
176 if (!install_sound(DIGI_AUTODETECT
, MIDI_NONE
, NULL
) )
177 mtracer
.add("\t\tSound system OK!\n" );
179 mtracer
.add("\t\tSound system FAILED! : %s", allegro_error
);
182 //set_hardware_volume(255,-1);
187 set_color_depth(game_color_depth
);
189 mtracer
.add("\tTrying to run in %3dx%3d@%2d bpp",vid_w
, vid_h
, game_color_depth
);
191 if ( set_gfx_mode(vid_m
, vid_w
, vid_h
, 0, 0) )
194 if ( set_gfx_mode(vid_m
, vid_w
, vid_h
, 0, 0) )
197 if ( set_gfx_mode(vid_m
, vid_w
, vid_h
, 0, 0) )
200 if ( set_gfx_mode(vid_m
, vid_w
, vid_h
, 0, 0) )
203 if ( set_gfx_mode(vid_m
, vid_w
, vid_h
, 0, 0) )
205 raise_error("main() : I can't set the graphics mode (%3d x %3d @ %2d bpp)\nI also tried with 16 bpp, 15 bpp, 32 bpp and 24 bpp\n", vid_w
, vid_h
, game_color_depth
);
212 set_color_conversion(COLORCONV_TOTAL
| COLORCONV_KEEP_TRANS
);
213 // I need software 3D code for this game, so I init the 3D scene system of Allegro - DEBUG
214 mtracer
.add("Starts 3D software rendered scene -> create_scene()");
215 create_scene(4800,2000); // max n of edges and polygons to render - DEBUG - take care of this to see if the calculus is right
217 mtracer
.add("-- Allegro start up code done --\n\nStarting CMain class");
219 kball_do_the_intro(); // INTRO OF GAME
221 textout_centre_ex(screen
, font
, "[ Please wait... loading... ]", SCREEN_W
/2, SCREEN_H
/2, makecol(255,255,255), makecol(0,0,64));
225 cmain
->start(want_map_editor
);
228 kball_do_the_exit(); // exit of game
230 mtracer
.add("\nmain() finished");
232 // Release memory used by the 3D code -- DEBUG
233 mtracer
.add("Stops 3D software rendered scene -> destroy_scene()");
236 return 0; // normal end of the program