00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00055 #include <string>
00056 #include <signal.h>
00057
00058 #include "omicron/internal.h"
00059 #include "omicron/render.h"
00060 #include "omicron/texture.h"
00061 #include "omicron/gui.h"
00062 #include "omicron/file.h"
00063 #include "omicron/net.h"
00064 #include "omicron/sound.h"
00065
00066
00067
00068
00069
00070
00071
00072 gvar_t gv;
00073 ulong assertions = 0;
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 static void _process_cmd_line
00086 (
00087 ulong argc,
00088 char *argv[]
00089 )
00090 {
00091 gv.init.argc = argc;
00092 gv.init.argv = argv;
00093
00094 if (argc<2)
00095 return;
00096
00097
00098 char *p = NULL;
00099 std::string cmd;
00100 ulong i;
00101
00102 _log_printf(MSG_DEBUG, "processing command line parameters:");
00103
00104 for (i=1; i<argc; i++)
00105 cmd += argv[i];
00106
00107 _log_printf(MSG_DEBUG, "cmd: %s", cmd.c_str());
00108
00109 if (NULL!=(p = strstr(cmd.c_str(), "-w")))
00110 {
00111 gv.init.fullscreen = false;
00112 _log_printf(MSG_DEBUG, " using windowed mode");
00113 }
00114
00115 if (NULL!=(p = strstr(cmd.c_str(), "-s")))
00116 {
00117 gv.init.nosound = 1;
00118 _log_printf(MSG_DEBUG, " silent mode (no sound)");
00119 }
00120
00121 if (NULL!=(p = strstr(cmd.c_str(), "-x")))
00122 {
00123 gv.init.hres = atoi(p+2);
00124 if (gv.init.hres<320)
00125 gv.init.hres = 320;
00126
00127 _log_printf(MSG_DEBUG, " resolution x = %u",gv.init.hres);
00128 }
00129
00130 if (NULL!=(p = strstr(cmd.c_str(), "-y")))
00131 {
00132 gv.init.vres = atoi(p+2);
00133 if (gv.init.vres<200)
00134 gv.init.vres = 200;
00135
00136 _log_printf(MSG_DEBUG, " resolution y = %u",gv.init.vres);
00137 }
00138
00139 if (NULL!=(p = strstr(cmd.c_str(), "-b")))
00140 {
00141 gv.init.bpp = atoi(p+2);
00142 _log_printf(MSG_DEBUG, " color depth : %u bits",gv.init.bpp);
00143 }
00144
00145 if (NULL!=(p = strstr(cmd.c_str(), "-d")))
00146 {
00147 gv.debuglevel = atoi(p+2);
00148 _log_printf(MSG_DEBUG, " debug level : %d", gv.debuglevel);
00149 }
00150
00151 _log_printf(MSG_DEBUG, " debug level : %d", gv.debuglevel);
00152 }
00153
00154
00155
00156
00157
00158
00159 static ulong _init()
00160 {
00161 new file_manager_c;
00162 new net_manager_c;
00163
00164 init_vars();
00165
00166
00167 _log_printf(MSG_NORMAL, "******************************** -");
00168 _log_printf(MSG_NORMAL, "* OMICRON ENGINE * -");
00169 _log_printf(MSG_NORMAL, "******************************** -\n\n");
00170
00171 _log_printf(MSG_NORMAL, OMICRON_VERSION);
00172
00173
00174
00175 _log_printf(MSG_NORMAL, "Omicron engine starting up..");
00176
00177 _log_printf(MSG_DEBUG, "Global variables (gv) take %u bytes", sizeof(gv));
00178
00179 _process_cmd_line(gv.init.argc, gv.init.argv);
00180
00181 if (!gv.init.wnd)
00182 if (!_win_init(gv.init.hres, gv.init.vres,
00183 #if defined(WIN32)
00184 gv.init.hInstance,
00185 #endif
00186 gv.init.fullscreen ))
00187 return 0;
00188
00189 srand(_time_get());
00190
00191 #if defined(WIN32)
00192
00193 ShowWindow((HWND)gv.init.wnd, SW_SHOW);
00194
00195 #else
00196
00197 XMapWindow(gv.init.dpy, gv.init.wnd);
00198
00199 #endif
00200
00201 if (!gv.init.nogfx)
00202 {
00203 if (!_gfx_init( gv.init.hres, gv.init.vres, gv.init.fullscreen ))
00204 return 0;
00205
00206
00207 new renderer_c;
00208
00209 if (!gv.renderer)
00210 return 0;
00211
00212
00213
00214 }
00215
00216 if (!gv.init.noinput)
00217 _input_init();
00218
00219 if (!gv.init.nosound)
00220 new sound_manager_c;
00221
00222 gv.time = 0;
00223 gv.dtime = 0;
00224
00225 if (gv.iface)
00226 gv.iface->init();
00227
00228 gv.active = 1;
00229
00230 return 1;
00231 }
00232
00233
00234
00235
00236
00237 void _deinit()
00238 {
00239 _log_printf(MSG_DEBUG, "_deinit()");
00240
00241 if (gv.iface)
00242 gv.iface->deinit();
00243
00244 SafeDelete(gv.netman);
00245 SafeDelete(gv.soundman);
00246 SafeDelete(gv.iface);
00247 SafeDelete(gv.gui);
00248
00249 _input_deinit();
00250 SafeDelete(gv.renderer);
00251
00252 _gfx_deinit();
00253
00254 SafeDelete(gv.fileman);
00255
00256 _win_deinit();
00257
00258
00259
00260 }
00261
00262 #if defined(WIN32)
00263 static HINSTANCE hInst = NULL;
00264 #endif
00265
00266
00267
00268
00269 int main(int argc, char*argv[])
00270 {
00271 memset(&gv, 0, sizeof(gv));
00272
00273 _log_init();
00274
00275 gv.init.fullscreen = true;
00276 gv.init.wndclassname = "_OMICRON";
00277 gv.init.wndtitle = "OMICRON TEST APPLICATION";
00278 gv.timescale = 1;
00279
00280 gv.init.hres = 640;
00281 gv.init.vres = 480;
00282 gv.init.bpp = 32;
00283 gv.init.zbuffer = 24;
00284 gv.init.stencil = 1;
00285
00286 gv.init.argc = argc;
00287 gv.init.argv = argv;
00288
00289 gv.active = 0;
00290
00291 #if defined(WIN32)
00292 gv.init.hInstance = hInst;
00293 #endif
00294 gv.debuglevel = 0;
00295
00296 if (_init())
00297 {
00298
00299 _win_mainloop();
00300 }
00301
00302 _log_printf(MSG_NORMAL, "Omicron engine shutting down..");
00303
00304 _deinit();
00305
00306 _log_printf(MSG_NORMAL, "Have a nice day..");
00307 _log_deinit();
00308
00309 if (assertions)
00310 {
00311 #if defined(WIN32)
00312
00313 MessageBeep(MB_ICONEXCLAMATION);
00314 MessageBox(NULL, "One or more Assertions have failed. "
00315 "Please see log file for more information",
00316 "There were errors", MB_ICONERROR);
00317 #endif
00318 }
00319
00320 return 0;
00321 }
00322
00323 #if defined(WIN32)
00324
00325
00326
00327 int APIENTRY WinMain(HINSTANCE hInstance,
00328 HINSTANCE ,
00329 LPSTR ,
00330 int )
00331 {
00332 hInst = hInstance;
00333
00334 return main(__argc, __argv);
00335 }
00336 #endif