Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

o_omicron.cpp

Go to the documentation of this file.
00001 // OMICRON ENGINE HEADER FILE
00002 //
00003 // --------------------------------------------------------------------------
00004 // Copyright (C) 2001-2002 by Bjoern Paetzel <kolrabi@gmx.de>
00005 //
00006 // This file is part of the Omicron Engine.
00007 //
00008 // The Omicron Engine is free software; you can redistribute it and/or modify
00009 // it under the terms of the  GNU General Public License  as published by the
00010 // Free Software Foundation;  either version  2  of the License,  or (at your
00011 // option) any later version.
00012 //
00013 // The Omicron Engine  is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00015 // or  FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License
00016 // for more details.
00017 //
00018 // You should have  received a copy of the  GNU General Public License  along
00019 // with The Omicron Engine;  if not,  write to the  Free Software Foundation,
00020 // Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
00021 //
00022 // --------------------------------------------------------------------------
00023 // Last modified:       $Date: 2002/12/13 12:29:26 $
00024 // By           :       $Author: kolrabi $
00025 // $Id: o_omicron.cpp,v 1.4 2002/12/13 12:29:26 kolrabi Exp $ 
00026 
00027 /*
00028 
00029   $Log: o_omicron.cpp,v $
00030   Revision 1.4  2002/12/13 12:29:26  kolrabi
00031   fixed some bugs
00032 
00033   Revision 1.3  2002/12/12 13:13:39  kolrabi
00034   made the fullscreen work under X11
00035 
00036   Revision 1.2  2002/12/11 16:35:43  kolrabi
00037   sound is now part of the engine
00038 
00039   Revision 1.1.1.1  2002/12/07 19:02:05  kolrabi
00040   initial release
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  * VARIABLES **************************************************************** 
00069  **************************************************************************** 
00070  ****************************************************************************/ 
00071  
00072 gvar_t              gv;
00073 ulong               assertions = 0;
00074 
00075 
00076 /**************************************************************************** 
00077  **************************************************************************** 
00078  * MAIN ROUTINES ************************************************************ 
00079  **************************************************************************** 
00080  ****************************************************************************/ 
00081  
00082 /**************************************************************************** 
00083  * _process_cmd_line                        processes command line switches * 
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 //    ulong       cmdlinelen  = argc; 
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  * _init                                                     initialization * 
00158  ****************************************************************************/ 
00159 static ulong _init() 
00160 {
00161     new file_manager_c;
00162     new net_manager_c;
00163  
00164     init_vars(); 
00165 
00166     // say hello 
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 //    _showmem(false); 
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            /* end windows specific ***********************************/ 
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             /* end windows specific ***********************************/ 
00196  
00197     XMapWindow(gv.init.dpy, gv.init.wnd); 
00198  
00199 #endif            /* end other's specific ***********************************/ 
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         // create new renderer
00207         new renderer_c;
00208 
00209         if (!gv.renderer)
00210             return 0;
00211 
00212 // let the user decide to use or not to use the gui
00213 //        new gui_c;
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  * _deinit                                                 deinitialization * 
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);               /* deinit gui             */ 
00248  
00249     _input_deinit();                  /* input                  */ 
00250     SafeDelete(gv.renderer);
00251  
00252     _gfx_deinit();                    /* graphics               */ 
00253  
00254     SafeDelete(gv.fileman);
00255  
00256     _win_deinit();                    /* destroy window         */ 
00257 
00258 //    _showmem(true);                   /* show debug information */ 
00259 //    _profile_show(); 
00260 } 
00261  
00262 #if defined(WIN32) 
00263 static HINSTANCE hInst = NULL; 
00264 #endif            /* end windows specific ***********************************/ 
00265  
00266 /**************************************************************************** 
00267  * main                                                                     * 
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            /* end windows specific ***********************************/ 
00294     gv.debuglevel                   = 0; 
00295  
00296     if (_init()) 
00297     {
00298         //signal(SIGQUIT, _signal_handler);
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  * WinMain                                           the win 32 entry point * 
00326  ****************************************************************************/ 
00327 int APIENTRY WinMain(HINSTANCE hInstance, 
00328                      HINSTANCE /* hPrevInstance */, 
00329                      LPSTR     /* lpCmdLine     */, 
00330                      int       /* nCmdShow      */ ) 
00331 { 
00332     hInst = hInstance; 
00333  
00334     return main(__argc, __argv); 
00335 } 
00336 #endif            /* end windows specific ***********************************/ 

Generated on Wed Dec 18 15:48:47 2002 for omicron engine by doxygen1.2.18