1 /* $Id: inferno.c,v 1.109 2006-07-29 04:02:49 chris Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * inferno.c: Entry point of program (main procedure)
19 * After main initializes everything, most of the time is spent in the loop
20 * while (Function_mode != FMODE_EXIT)
21 * In this loop, the main menu is brought up first.
31 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
41 #include <sys/types.h>
60 #include "segment.h" //for Side_to_verts
98 // # include "3dfx_des.h"
100 //added on 9/30/98 by Matt Mueller for selectable automap modes
104 #include "../texmap/scanline.h" //for select_tmap -MM
107 #include "editor/editor.h"
108 #include "editor/kdefs.h"
119 void arch_init(void);
120 void arch_init_start(void);
122 //Current version number
124 ubyte Version_major = 1; //FULL VERSION
125 ubyte Version_minor = 2;
127 //static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; // 4-byte checksum
128 char desc_id_exit_num = 0;
130 int Function_mode=FMODE_MENU; //game or editor?
131 int Screen_mode=-1; //game screen or editor screen?
133 //--unused-- grs_bitmap Inferno_bitmap_title;
135 int WVIDEO_running=0; //debugger can set to 1 if running
137 //--unused-- int Cyberman_installed=0; // SWIFT device present
138 ubyte CybermouseActive=0;
141 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
144 void check_joystick_calibration(void);
146 void show_order_form(void);
148 //--------------------------------------------------------------------------
150 extern int piggy_low_memory;
153 int descent_critical_error = 0;
154 unsigned descent_critical_deverror = 0;
155 unsigned descent_critical_errcode = 0;
157 extern int Network_allow_socket_changes;
159 extern void vfx_set_palette_sub(ubyte *);
161 extern int VR_low_res;
163 extern int Config_vr_type;
164 extern int Config_vr_resolution;
165 extern int Config_vr_tracking;
169 //read help from a file & print to screen
170 void print_commandline_help()
176 ifile = cfopen("help.tex","rb");
178 ifile = cfopen("help.txb","rb");
180 Warning("Cannot load help text file.");
188 while ((end = cfgets(line,LINE_LEN,ifile))) {
191 decode_text_line (line);
193 // This is the only use of cfgets that needs the CR
197 continue; //don't show comments
207 // printf( " Diagnostic:\n\n");
208 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
209 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
212 printf( " Editor Options:\n\n");
213 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
214 printf( " -hoarddata %s\n","Make the hoard ham file from some files, then exit");
215 // printf( " -nobm %s\n","FIXME: Undocumented");
218 printf( " D2X Options:\n\n");
219 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
220 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
221 #ifdef OGL // currently only does anything on ogl build, so don't advertise othewise.
222 printf(" -renderstats %s\n", "Enable renderstats info by default");
224 printf( " -maxfps <n> %s\n", "Set maximum framerate (1-100)");
225 printf( " -notitles %s\n", "Do not show titlescreens on startup");
226 printf( " -hogdir <dir> %s\n", "set shared data directory to <dir>");
228 printf( " -nohogdir %s\n", "don't try to use shared data directory");
229 printf( " -userdir <dir> %s\n", "set user dir to <dir> instead of $HOME/.d2x");
231 printf( " -ini <file> %s\n", "option file (alternate to command line), defaults to d2x.ini");
232 printf( " -autodemo %s\n", "Start in demo mode");
233 printf( " -bigpig %s\n","FIXME: Undocumented");
234 printf( " -bspgen %s\n","FIXME: Undocumented");
235 // printf( " -cdproxy %s\n","FIXME: Undocumented");
237 printf( " -checktime %s\n","FIXME: Undocumented");
238 printf( " -showmeminfo %s\n","FIXME: Undocumented");
240 // printf( " -codereadonly %s\n","FIXME: Undocumented");
241 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
242 printf( " -debug %s\n","Enable very verbose output");
243 // printf( " -debugmode %s\n","FIXME: Undocumented");
244 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
245 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
246 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
247 // printf( " -forcegfx %s\n","FIXME: Undocumented");
249 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
251 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
253 printf( " -invulnerability %s\n","Make yourself invulnerable");
255 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
256 printf( " -jasen %s\n","FIXME: Undocumented");
257 printf( " -joyslow %s\n","FIXME: Undocumented");
259 printf( " -kali %s\n","use Kali for networking");
261 // printf( " -logfile %s\n","FIXME: Undocumented");
262 printf( " -lowresmovies %s\n","Play low resolution movies if available (for slow machines)");
263 #if defined(EDITOR) || !defined(MACDATA)
264 printf( " -macdata %s\n","Read (and, for editor, write) mac data files (swap colors)");
266 // printf( " -memdbg %s\n","FIXME: Undocumented");
267 // printf( " -monodebug %s\n","FIXME: Undocumented");
268 printf( " -nocdrom %s\n","FIXME: Undocumented");
270 printf( " -nocyberman %s\n","FIXME: Undocumented");
273 printf( " -nofade %s\n","Disable fades");
276 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
277 printf( " -norankings %s\n","Disable multiplayer ranking system");
278 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
279 // printf( " -showaddress %s\n","FIXME: Undocumented");
280 printf( " -socket %s\n","FIXME: Undocumented");
282 #if !defined(MACINTOSH) && !defined(WINDOWS)
283 printf( " -nomixer %s\n","Don't crank music volume");
284 // printf( " -superhires %s\n","Allow higher-resolution modes");
286 // printf( " -nomodex %s\n","FIXME: Undocumented");
288 printf( " -nomovies %s\n","Don't play movies");
289 printf( " -noscreens %s\n","Skip briefing screens");
291 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
292 printf( " -noredbook %s\n","Disable redbook audio");
294 printf( " -norun %s\n","Bail out after initialization");
295 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
296 // printf( " -rtscts %s\n","Same as -ctsrts");
297 // printf( " -semiwin %s\n","Use non-fullscreen mode");
298 // printf( " -specialdevice %s\n","FIXME: Undocumented");
300 printf( " -stickmag %s\n","FIXME: Undocumented");
302 // printf( " -stopwatch %s\n","FIXME: Undocumented");
303 printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
304 // printf( " -sysram %s\n","FIXME: Undocumented");
305 printf( " -text <file> %s\n","Specify alternate .tex file");
306 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
307 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
308 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
309 // printf( " -vidram %s\n","FIXME: Undocumented");
310 printf( " -xcontrol %s\n","FIXME: Undocumented");
311 printf( " -xname %s\n","FIXME: Undocumented");
312 printf( " -xver %s\n","FIXME: Undocumented");
313 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
315 printf( " -<X>x<Y> %s\n", "Change screen resolution. Options:");
316 printf( " 320x100;320x200;320x240;320x400;640x400;640x480;800x600;1024x768\n");
318 printf( " -<X>x<Y> %s\n", "Change screen resolution to <X> by <Y>");
320 printf(" -niceautomap %s\n", "Free cpu while doing automap");
321 printf( " -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
322 printf( " -automap_gameres %s\n","Set automap to use the same resolution as in game");
323 // printf( " -menu<X>x<Y> %s\n","Set menu resolution to <X> by <Y>");
324 // printf( " -menu_gameres %s\n","Set menus to use the same resolution as in game");
325 printf(" -rearviewtime t %s\n", "time holding rearview key to use toggle mode (default 0.0625 seconds)");
328 printf( "D2X System Options:\n\n");
330 printf(" -ihaveabrokenmouse %s\n", "try to make mouse work if it is not currently");
331 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
333 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
334 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
337 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
338 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
339 printf(" -gl_mipmap %s\n", "set gl texture filters to \"standard\" (bilinear) mipmapping");
340 printf(" -gl_trilinear %s\n", "set gl texture filters to trilinear mipmapping");
341 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
342 printf(" -gl_anisotropy <f> %s\n", "set maximum degree of anisotropy to <f>");
343 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
344 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
345 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
346 printf( " -gl_voodoo %s\n","force fullscreen mode only");
348 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
349 printf(" -gl_16bpp %s\n", "attempt to use 16bit screen mode");
350 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
351 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
352 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
353 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
354 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
355 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
356 printf( " -gl_test2 %s\n","FIXME: Undocumented");
357 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
358 #ifdef OGL_RUNTIME_LOAD
359 printf( " -gl_library <l> %s\n","use alternate opengl library");
362 printf(" -gl_refresh <r> %s\n", "set refresh rate (in fullscreen mode)");
366 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
367 printf( " -hwsurface %s\n","FIXME: Undocumented");
370 printf(" -udp %s\n", "Specify options for udp/ip:");
371 printf(" @<shift> %s\n", " shift udp port base offset");
372 printf(" =<HOST_LIST> %s\n", " broadcast both local and to HOST_LIST");
373 printf(" +<HOST_LIST> %s\n", " broadcast only to HOST_LIST");
374 printf(" %s\n", " HOSTS can be any IP or hostname")
376 printf(" %s\n", " HOSTS can also be in the form of <address>:<shift>");
377 printf(" %s\n", " separate multiple HOSTS with a ,");
380 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
381 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
383 printf( "\n Help:\n\n");
384 printf( " -help, -h, -?, ? %s\n", "View this help screen");
388 void do_joystick_init()
391 if (!FindArg( "-nojoystick" )) {
392 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
394 if ( FindArg( "-joyslow" )) {
395 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
396 joy_set_slow_reading(JOY_SLOW_READINGS);
398 if ( FindArg( "-joypolled" )) {
399 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
400 joy_set_slow_reading(JOY_POLLED_READINGS);
402 if ( FindArg( "-joybios" )) {
403 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
404 joy_set_slow_reading(JOY_BIOS_READINGS);
407 // Added from Descent v1.5 by John. Adapted by Samir.
409 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
413 //set this to force game to run in low res
414 int disable_high_res=0;
416 void do_register_player(ubyte *title_pal)
418 Players[Player_num].callsign[0] = '\0';
424 //now, before we bring up the register player menu, we need to
425 //do some stuff to make sure the palette is ok. First, we need to
426 //get our current palette into the 2d's array, so the remapping will
427 //work. Second, we need to remap the fonts. Third, we need to fill
428 //in part of the fade tables so the darkening of the menu edges works
430 memcpy(gr_palette,title_pal,sizeof(gr_palette));
431 remap_fonts_and_menus(1);
432 RegisterPlayer(); //get player's name
437 #define PROGNAME argv[0]
439 extern char Language[];
441 //can we do highres menus?
442 extern int MenuHiresAvailable;
444 int Inferno_verbose = 0;
446 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
447 int start_net_immediately = 0;
448 //int start_with_mission = 0;
449 //char *start_with_mission_name;
450 //end this section addition
452 #define MENU_HIRES_MODE SM(640,480)
454 // DESCENT II by Parallax Software
457 //extern ubyte gr_current_pal[];
461 char Auto_file[128] = "";
464 int main(int argc, char *argv[])
467 ubyte title_pal[768];
469 con_init(); // Initialise the console
472 error_init(NULL, NULL);
473 PHYSFSX_init(argc, argv);
475 if (FindArg("-debug"))
476 con_threshold.value = (float)2;
477 else if (FindArg("-verbose"))
478 con_threshold.value = (float)1;
480 if (! cfile_init("descent2.hog"))
481 if (! cfile_init("d2demo.hog"))
482 Warning("Could not find a valid hog file (descent2.hog or d2demo.hog)\nPossible locations are:\n"
487 "\tCurrent directory\n"
489 "Or use the -hogdir option to specify an alternate location.");
492 //print out the banner title
493 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
495 con_printf(CON_NORMAL, " %s", VERSION_NAME);
497 if (cfexist(MISSION_DIR "d2x.hog"))
498 con_printf(CON_NORMAL, " Vertigo Enhanced");
500 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
501 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
502 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
503 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
506 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
507 print_commandline_help();
508 set_exit_message("");
510 exit(0); /* mingw hangs on this return. dunno why */
515 con_printf(CON_NORMAL, "\n");
516 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
517 con_printf(CON_NORMAL, "\n");
522 for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
523 con_printf(CON_VERBOSE, "PHYSFS: [%s] is in the search path.\n", *i);
525 list = PHYSFS_getCdRomDirs();
526 for (i = list; *i != NULL; i++)
527 con_printf(CON_VERBOSE, "PHYSFS: cdrom dir [%s] is available.\n", *i);
528 PHYSFS_freeList(list);
530 list = PHYSFS_enumerateFiles("");
531 for (i = list; *i != NULL; i++)
532 con_printf(CON_DEBUG, "PHYSFS: * We've got [%s].\n", *i);
533 PHYSFS_freeList(list);
536 //(re)added Mar 30, 2003 Micah Lieske - Allow use of 22K sound samples again.
537 if(FindArg("-sound22k"))
539 digi_sample_rate = SAMPLE_RATE_22K;
542 if(FindArg("-sound11k"))
544 digi_sample_rate = SAMPLE_RATE_11K;
551 //con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
553 if ((t = FindArg("-rearviewtime")))
555 float f = atof(Args[t + 1]);
556 Rear_view_leave_time = f * f1_0;
558 con_printf(CON_VERBOSE, "Rear_view_leave_time=0x%x (%f sec)\n", Rear_view_leave_time, Rear_view_leave_time / (float)f1_0);
560 //added/edited 8/18/98 by Victor Rachels to set maximum fps <= 100
561 if ((t = FindArg( "-maxfps" ))) {
563 if (t > 0 && t <= MAX_FPS)
566 //end addition - Victor Rachels
568 #ifdef SUPPORTS_NICEFPS
569 if (FindArg("-nicefps"))
571 if (FindArg("-niceautomap"))
575 if (FindArg("-renderstats"))
578 if ( FindArg( "-autodemo" ))
582 if ( FindArg( "-noscreens" ) )
583 Skip_briefing_screens = 1;
586 if ((t=FindArg("-tmap"))){
587 select_tmap(Args[t+1]);
593 // if (init_graphics()) return 1;
596 if (gr_check_mode(SM(800, 600)) != 0)
598 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
599 Function_mode = FMODE_MENU;
604 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
606 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
611 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
612 set_display_mode(0); //..then set default display mode
615 int screen_width = 640;
616 int screen_height = 480;
617 int vr_mode = VR_NONE;
618 int screen_flags = VRF_USE_PAGING;
620 if (FindResArg("", &screen_width, &screen_height))
622 /* stuff below mirrors values from display_mode_info in
623 * menu.c which is used by set_display_mode. In fact,
624 * set_display_mode should probably be rewritten to allow
625 * arbitrary resolutions, and then we get rid of this
628 switch (SM(screen_width, screen_height))
632 screen_flags = VRF_ALLOW_COCKPIT + VRF_COMPATIBLE_MENUS;
635 screen_flags = VRF_USE_PAGING;
641 screen_flags = VRF_COMPATIBLE_MENUS;
645 con_printf(CON_VERBOSE, "Using %ix%i ...\n", screen_width, screen_height);
648 // added ifdef on 9/30/98 by Matt Mueller to fix high res in linux
650 if (FindArg("-nodoublebuffer"))
654 con_printf(CON_VERBOSE, "Double-buffering disabled...\n");
655 screen_flags &= ~VRF_USE_PAGING;
658 // added 3/24/99 by Owen Evans for screen res changing
659 Game_screen_mode = SM(screen_width, screen_height);
661 game_init_render_buffers(Game_screen_mode, screen_width, screen_height, vr_mode, screen_flags);
665 // added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
666 int i, argnum = INT_MAX, w, h;
667 // added on 9/30/98 by Matt Mueller for selectable automap modes - edited 11/21/99 whee, more fun with defines. - edited 03/31/02 to use new FindResArg.
668 #define SMODE(V,VV,VG) if ((i=FindResArg(#V, &w, &h)) && (i < argnum)) { argnum = i; VV = SM(w, h); VG = 0; }
669 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
670 #define SMODE_PRINT(V,VV,VG) if (VG) con_printf(CON_VERBOSE, #V " using game resolution ...\n"); else con_printf(CON_VERBOSE, #V " using %ix%i ...\n",SM_W(VV),SM_H(VV) );
671 // aren't #defines great? :)
672 // end addition/edit -MM
673 #define S_MODE(V,VV,VG) argnum = INT_MAX; SMODE(V, VV, VG); SMODE_GR(V, VG); SMODE_PRINT(V, VV, VG);
675 S_MODE(automap,automap_mode,automap_use_game_res);
676 // S_MODE(menu,menu_screen_mode,menu_use_game_res);
680 i = FindArg( "-xcontrol" );
682 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
685 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
686 if (FindArg("-nofade"))
687 grd_fades_disabled=1;
689 //determine whether we're using high-res menus & movies
690 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
691 MovieHires = MenuHires = MenuHiresAvailable = 0;
693 //NOTE LINK TO ABOVE!
694 MenuHires = MenuHiresAvailable = 1;
696 if (FindArg( "-lowresmovies" ))
699 if ((t=gr_init())!=0) //doesn't do much
700 Error(TXT_CANT_INIT_GFX,t);
702 // Load the palette stuff. Returns non-zero if error.
703 con_printf(CON_DEBUG, "Initializing palette system...\n" );
704 gr_use_palette_table(DEFAULT_PALETTE );
706 con_printf(CON_DEBUG, "Initializing font system...\n" );
707 gamefont_init(); // must load after palette data loaded.
709 con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
710 init_movies(); //init movie libraries
713 con_printf(CON_VERBOSE, "Going into graphics mode...\n");
714 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
717 if ( FindArg( "-notitles" ) )
718 songs_play_song( SONG_TITLE, 1);
722 con_printf( CON_DEBUG, "\nShowing loading screen..." );
723 show_loading_screen(title_pal); // title_pal is needed (see below)
725 con_printf( CON_DEBUG , "\nDoing bm_init..." );
727 if (!bm_init_use_tbl())
732 if (FindArg("-hoarddata") != 0)
739 //the bitmap loading code changes gr_palette, so restore it
740 memcpy(gr_palette,title_pal,sizeof(gr_palette));
742 if ( FindArg( "-norun" ) )
745 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
748 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
749 texmerge_init( 10 ); // 10 cache bitmaps
751 con_printf( CON_DEBUG, "\nRunning game...\n" );
752 set_screen_mode(SCREEN_MENU);
756 // If built with editor, option to auto-load a level and quit game
757 // to write certain data.
760 if ( (t = FindArg( "-autoload" )) ) {
762 strcpy(Auto_file, Args[t+1]);
768 strcpy(Players[0].callsign, "dummy");
771 do_register_player(title_pal);
773 gr_palette_fade_out( title_pal, 32, 0 );
775 Game_mode = GM_GAME_OVER;
778 newdemo_start_playback("descent.dem");
779 if (Newdemo_state == ND_STATE_PLAYBACK )
780 Function_mode = FMODE_GAME;
783 //do this here because the demo code can do a longjmp when trying to
784 //autostart a demo from the main menu, never having gone into the game
787 while (Function_mode != FMODE_EXIT)
789 switch( Function_mode ) {
791 set_screen_mode(SCREEN_MENU);
793 newdemo_start_playback(NULL); // Randomly pick a file
794 if (Newdemo_state != ND_STATE_PLAYBACK)
795 Error("No demo files were found for autodemo mode!");
799 strcpy((char *)&Level_names[0], Auto_file);
801 Function_mode = FMODE_EXIT;
806 check_joystick_calibration();
807 gr_palette_clear(); //I'm not sure why we need this, but we do
810 if ( Function_mode == FMODE_EDITOR ) {
812 SetPlayerFromCurseg();
813 load_palette(NULL,1,0);
820 keyd_editor_mode = 0;
824 /* keep the mouse from wandering in SDL */
825 if (FindArg("-grabmouse"))
826 SDL_WM_GrabInput(SDL_GRAB_ON);
832 /* give control back to the WM */
833 if (FindArg("-grabmouse"))
834 SDL_WM_GrabInput(SDL_GRAB_OFF);
837 if ( Function_mode == FMODE_MENU )
838 songs_play_song( SONG_TITLE, 1 );
842 keyd_editor_mode = 1;
845 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
847 if ( Function_mode == FMODE_GAME ) {
848 Game_mode = GM_EDITOR;
849 editor_reset_stuff_on_level();
855 Error("Invalid function mode %d",Function_mode);
861 if (!FindArg( "-notitles" ))
865 if ( FindArg( "-showmeminfo" ) )
866 show_mem_info = 1; // Make memory statistics show
869 return(0); //presumably successful exit
873 void check_joystick_calibration() {
874 int x1, y1, x2, y2, c;
877 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
878 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
879 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
880 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
883 joy_get_pos( &x1, &y1 );
885 t1 = timer_get_fixed_seconds();
886 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
889 joy_get_pos( &x2, &y2 );
891 // If joystick hasn't moved...
892 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
893 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
894 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
906 // void network_abort_game();
907 // if(Network_status)
908 // network_abort_game();