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_FULLSCREEN
; // 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
], "-bpp16") == 0)
106 game_color_depth
= 16;
108 if (stricmp(argv
[i
], "-bpp15") == 0)
109 game_color_depth
= 15;
111 if (stricmp(argv
[i
], "-bpp32") == 0)
112 game_color_depth
= 32;
114 if (stricmp(argv
[i
], "-bpp24") == 0)
115 game_color_depth
= 24;
117 if (stricmp(argv
[i
], "-bpp8") == 0)
119 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
);
122 // development options
123 if (stricmp(argv
[i
], "-mapeditor") == 0)
124 want_map_editor
= true; // use the map editor... cool
127 // dumb_register_packfiles(); // DUMB will read from packfiles - NO NECESARIO, no cargo nada del disco, solo a traves de datafiles
129 // register DUMB music files -- DEBUG : registrar solo el formato que voy a usar!
130 dumb_register_dat_it(DUMB_DAT_IT
);
131 dumb_register_dat_xm(DUMB_DAT_XM
);
132 dumb_register_dat_s3m(DUMB_DAT_S3M
);
133 dumb_register_dat_mod(DUMB_DAT_MOD
);
135 set_window_title("KBall"); // setear nombre de la ventana :o
137 mtracer
.add("\n--------------------------------------------------------\nmain() started\n");
139 desk_bpp
= desktop_color_depth(); // using the same color depth as the host will make the game run faster
140 if (desk_bpp
!= 8 && desk_bpp
!= 0 && game_color_depth
== -1)
142 // use the color depth of desktop
143 game_color_depth
= desk_bpp
;
146 if (game_color_depth
< 8)
147 game_color_depth
= 16; // safe check
149 srand(time(NULL
)); // init random numbers
151 if (install_timer() != 0)
152 raise_error("main() : can't install timer driver");
154 mtracer
.add("\tTimer installed");
156 if (install_keyboard() != 0)
157 raise_error("main() : can't install keyboard driver");
161 install_joystick(JOY_TYPE_AUTODETECT
);
163 mtracer
.add("\tInput devices installed");
167 //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);
169 reserve_voices(8, 0);
170 set_volume_per_voice(2); // warning - this may cause distortion
172 mtracer
.add("\tInstall sound");
173 if (!install_sound(DIGI_AUTODETECT
, MIDI_NONE
, NULL
) )
174 mtracer
.add("\t\tSound system OK!\n" );
176 mtracer
.add("\t\tSound system FAILED! : %s", allegro_error
);
179 //set_hardware_volume(255,-1);
184 set_color_depth(game_color_depth
);
186 mtracer
.add("\tTrying to run in %3dx%3d@%2d bpp",vid_w
, vid_h
, game_color_depth
);
188 if ( set_gfx_mode(vid_m
, vid_w
, vid_h
, 0, 0) )
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) )
202 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
);
209 set_color_conversion(COLORCONV_TOTAL
| COLORCONV_KEEP_TRANS
);
210 // I need software 3D code for this game, so I init the 3D scene system of Allegro - DEBUG
211 mtracer
.add("Starts 3D software rendered scene -> create_scene()");
212 create_scene(4800,2000); // max n of edges and polygons to render - DEBUG - take care of this to see if the calculus is right
214 mtracer
.add("-- Allegro start up code done --\n\nStarting CMain class");
216 kball_do_the_intro(); // INTRO OF GAME
218 textout_centre_ex(screen
, font
, "[ Please wait... loading... ]", SCREEN_W
/2, SCREEN_H
/2, makecol(255,255,255), makecol(0,0,64));
222 cmain
->start(want_map_editor
);
225 kball_do_the_exit(); // exit of game
227 mtracer
.add("\nmain() finished");
229 // Release memory used by the 3D code -- DEBUG
230 mtracer
.add("Stops 3D software rendered scene -> destroy_scene()");
233 return 0; // normal end of the program