2006-03-20 17:12:09 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
|
|
|
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* inferno.c: Entry point of program (main procedure)
|
|
|
|
*
|
|
|
|
* After main initializes everything, most of the time is spent in the loop
|
2010-04-04 01:31:48 +00:00
|
|
|
* while (window_get_front())
|
2006-03-20 17:12:09 +00:00
|
|
|
* In this loop, the main menu is brought up first.
|
|
|
|
*
|
|
|
|
* main() for Inferno
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-11-24 04:05:35 +00:00
|
|
|
extern const char copyright[];
|
|
|
|
|
|
|
|
const
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
char copyright[] = "DESCENT COPYRIGHT (C) 1994,1995 PARALLAX SOFTWARE CORPORATION";
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
2006-03-20 17:12:09 +00:00
|
|
|
char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
2013-06-30 02:22:56 +00:00
|
|
|
#include <SDL.h>
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
#ifdef __unix__
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "pstypes.h"
|
|
|
|
#include "strutil.h"
|
|
|
|
#include "console.h"
|
|
|
|
#include "gr.h"
|
|
|
|
#include "key.h"
|
|
|
|
#include "3d.h"
|
|
|
|
#include "bm.h"
|
|
|
|
#include "inferno.h"
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2015-07-25 23:10:45 +00:00
|
|
|
#include "player.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "game.h"
|
|
|
|
#include "segment.h" //for Side_to_verts
|
|
|
|
#include "u_mem.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "texmap.h"
|
|
|
|
#include "texmerge.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "digi.h"
|
|
|
|
#include "palette.h"
|
|
|
|
#include "args.h"
|
|
|
|
#include "titles.h"
|
|
|
|
#include "text.h"
|
2007-12-29 14:18:49 +00:00
|
|
|
#include "gauges.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "gamefont.h"
|
|
|
|
#include "kconfig.h"
|
|
|
|
#include "newmenu.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "multi.h"
|
|
|
|
#include "songs.h"
|
|
|
|
#include "gameseq.h"
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "gamepal.h"
|
|
|
|
#include "movie.h"
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-10-21 09:23:52 +00:00
|
|
|
#include "playsave.h"
|
2007-02-10 23:19:21 +00:00
|
|
|
#include "collide.h"
|
2007-04-04 10:24:03 +00:00
|
|
|
#include "newdemo.h"
|
2007-07-14 22:36:04 +00:00
|
|
|
#include "joy.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "../texmap/scanline.h" //for select_tmap -MM
|
2009-05-22 10:53:14 +00:00
|
|
|
#include "event.h"
|
2010-04-02 05:01:08 +00:00
|
|
|
#include "rbaudio.h"
|
2014-09-02 22:10:34 +00:00
|
|
|
#ifndef __linux__
|
2010-11-28 12:08:29 +00:00
|
|
|
#include "messagebox.h"
|
2014-10-10 02:43:14 +00:00
|
|
|
#else
|
|
|
|
#ifdef WORDS_NEED_ALIGNMENT
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
#endif
|
2010-11-30 12:46:23 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
#ifdef EDITOR
|
|
|
|
#include "editor/editor.h"
|
|
|
|
#include "editor/kdefs.h"
|
|
|
|
#include "ui.h"
|
|
|
|
#endif
|
|
|
|
#include "vers_id.h"
|
2011-06-30 23:00:59 +00:00
|
|
|
#ifdef USE_UDP
|
|
|
|
#include "net_udp.h"
|
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-07-05 16:48:12 +00:00
|
|
|
#include "dxxsconf.h"
|
|
|
|
#include "compiler-begin.h"
|
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dsx {
|
2015-12-05 22:57:25 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
int Screen_mode=-1; //game screen or editor screen?
|
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
int HiresGFXAvailable = 0;
|
|
|
|
int MacHog = 0; // using a Mac hogfile?
|
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//read help from a file & print to screen
|
2013-10-27 22:00:14 +00:00
|
|
|
static void print_commandline_help()
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2006-10-18 12:53:34 +00:00
|
|
|
printf( "\n System Options:\n\n");
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -nonicefps Don't free CPU-cycles\n");
|
2015-01-03 23:44:31 +00:00
|
|
|
printf( " -maxfps <n> Set maximum framerate to <n>\n\t\t\t\t(default: %i, available: %i-%i)\n", MAXIMUM_FPS, MINIMUM_FPS, MAXIMUM_FPS);
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -hogdir <s> set shared data directory to <s>\n");
|
2015-09-22 02:28:38 +00:00
|
|
|
#if defined(__unix__)
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -nohogdir don't try to use shared data directory\n");
|
2015-09-22 02:28:38 +00:00
|
|
|
#endif
|
2015-06-14 13:32:48 +00:00
|
|
|
printf( " -add-missions-dir <s> Add contents of location <s> to the missions directory\n");
|
|
|
|
printf( " -use_players_dir Put player files and saved games in Players subdirectory\n");
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -lowmem Lowers animation detail for better performance with\n\t\t\t\tlow memory\n");
|
|
|
|
printf( " -pilot <s> Select pilot <s> automatically\n");
|
2015-02-28 19:36:02 +00:00
|
|
|
printf( " -auto-record-demo Start recording on level entry\n");
|
|
|
|
printf( " -record-demo-format Set demo name automatically\n");
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -autodemo Start in demo mode\n");
|
|
|
|
printf( " -window Run the game in a window\n");
|
2015-06-14 13:32:48 +00:00
|
|
|
printf( " -noborders Don't show borders in window mode\n");
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
printf( " -notitles Skip title screens\n");
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -nomovies Don't play movies\n");
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-10-18 12:53:34 +00:00
|
|
|
|
|
|
|
printf( "\n Controls:\n\n");
|
2013-01-08 16:47:03 +00:00
|
|
|
printf( " -nocursor Hide mouse cursor\n");
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -nomouse Deactivate mouse\n");
|
|
|
|
printf( " -nojoystick Deactivate joystick\n");
|
|
|
|
printf( " -nostickykeys Make CapsLock and NumLock non-sticky\n");
|
2006-10-18 12:53:34 +00:00
|
|
|
|
|
|
|
printf( "\n Sound:\n\n");
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -nosound Disables sound output\n");
|
|
|
|
printf( " -nomusic Disables music output\n");
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -sound11k Use 11KHz sounds\n");
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2007-10-13 23:52:17 +00:00
|
|
|
#ifdef USE_SDLMIXER
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -nosdlmixer Disable Sound output via SDL_mixer\n");
|
2007-10-13 23:52:17 +00:00
|
|
|
#endif // USE SDLMIXER
|
2006-10-18 12:53:34 +00:00
|
|
|
|
|
|
|
printf( "\n Graphics:\n\n");
|
2015-09-13 21:02:19 +00:00
|
|
|
printf( " -lowresfont Force use of low resolution fonts\n");
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2015-09-13 21:02:19 +00:00
|
|
|
printf( " -lowresgraphics Force use of low resolution graphics\n");
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -lowresmovies Play low resolution movies if available (for slow machines)\n");
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-10-18 12:53:34 +00:00
|
|
|
#ifdef OGL
|
2015-06-14 13:32:48 +00:00
|
|
|
printf( " -gl_fixedfont Don't scale fonts to current resolution\n");
|
2015-03-22 17:17:11 +00:00
|
|
|
printf( " -gl_syncmethod <n> OpenGL sync method (default: %i)\n", OGL_SYNC_METHOD_DEFAULT);
|
2015-06-14 13:32:48 +00:00
|
|
|
printf( " 0: Disabled\n");
|
|
|
|
printf( " 1: Fence syncs, limit GPU latency to at most one frame\n");
|
|
|
|
printf( " 2: Like 1, but sleep during sync to reduce CPU load\n");
|
|
|
|
printf( " 3: Immediately sync after buffer swap\n");
|
|
|
|
printf( " 4: Immediately sync after buffer swap\n");
|
|
|
|
printf( " 5: Auto. use mode 2 if available, 0 otherwise\n");
|
|
|
|
printf( " -gl_syncwait <n> Wait interval (ms) for sync mode 2 (default: %i)\n", OGL_SYNC_WAIT_DEFAULT);
|
2006-10-18 12:53:34 +00:00
|
|
|
#endif // OGL
|
|
|
|
|
2013-02-21 00:20:26 +00:00
|
|
|
#if defined(USE_UDP)
|
2006-10-18 12:53:34 +00:00
|
|
|
printf( "\n Multiplayer:\n\n");
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -udp_hostaddr <s> Use IP address/Hostname <s> for manual game joining\n\t\t\t\t(default: %s)\n", UDP_MANUAL_ADDR_DEFAULT);
|
|
|
|
printf( " -udp_hostport <n> Use UDP port <n> for manual game joining (default: %i)\n", UDP_PORT_DEFAULT);
|
|
|
|
printf( " -udp_myport <n> Set my own UDP port to <n> (default: %i)\n", UDP_PORT_DEFAULT);
|
2015-01-24 19:16:35 +00:00
|
|
|
printf( " -no-tracker Disable tracker (unless overridden by later -tracker_hostaddr)\n");
|
2011-04-05 00:24:34 +00:00
|
|
|
#ifdef USE_TRACKER
|
2015-06-14 13:32:48 +00:00
|
|
|
printf( " -tracker_hostaddr <n> Address of tracker server to register/query games to/from\n\t\t\t\t(default: %s)\n", TRACKER_ADDR_DEFAULT);
|
|
|
|
printf( " -tracker_hostport <n> Port of tracker server to register/query games to/from\n\t\t\t\t(default: %i)\n", TRACKER_PORT_DEFAULT);
|
2011-04-05 00:24:34 +00:00
|
|
|
#endif // USE_TRACKER
|
2011-09-13 23:15:32 +00:00
|
|
|
#endif // defined(USE_UDP)
|
2006-10-18 12:53:34 +00:00
|
|
|
|
|
|
|
#ifdef EDITOR
|
|
|
|
printf( "\n Editor:\n\n");
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
printf( " -nobm Don't load BITMAPS.TBL and BITMAPS.BIN - use internal data\n");
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -autoload <s> Autoload level <s> in the editor\n");
|
2015-06-14 13:32:48 +00:00
|
|
|
printf( " -macdata Read and write Mac data files in editor (swap colors)\n");
|
|
|
|
printf( " -hoarddata Make the Hoard ham file from some files, then exit\n");
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-10-18 12:53:34 +00:00
|
|
|
#endif // EDITOR
|
|
|
|
|
2008-10-30 10:45:13 +00:00
|
|
|
printf( "\n Debug (use only if you know what you're doing):\n\n");
|
2012-01-09 14:21:09 +00:00
|
|
|
printf( " -debug Enable debugging output.\n");
|
|
|
|
printf( " -verbose Enable verbose output.\n");
|
|
|
|
printf( " -safelog Write gamelog.txt unbuffered.\n\t\t\t\tUse to keep helpful output to trace program crashes.\n");
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -norun Bail out after initialization\n");
|
2015-09-13 21:02:19 +00:00
|
|
|
printf( " -no-grab Never grab keyboard/mouse\n");
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -renderstats Enable renderstats info by default\n");
|
|
|
|
printf( " -text <s> Specify alternate .tex file\n");
|
2015-10-21 02:45:44 +00:00
|
|
|
printf( " -tmap <s> Select texmapper <s> to use\n\t\t\t\t(default: c, available: c, fp, quad)\n");
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -showmeminfo Show memory statistics\n");
|
|
|
|
printf( " -nodoublebuffer Disable Doublebuffering\n");
|
|
|
|
printf( " -bigpig Use uncompressed RLE bitmaps\n");
|
|
|
|
printf( " -16bpp Use 16Bpp instead of 32Bpp\n");
|
2007-07-18 20:13:17 +00:00
|
|
|
#ifdef OGL
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -gl_oldtexmerge Use old texmerge, uses more ram, but might be faster\n");
|
|
|
|
printf( " -gl_intensity4_ok <n> Override DbgGlIntensity4Ok (default: 1)\n");
|
|
|
|
printf( " -gl_luminance4_alpha4_ok <n> Override DbgGlLuminance4Alpha4Ok (default: 1)\n");
|
|
|
|
printf( " -gl_rgba2_ok <n> Override DbgGlRGBA2Ok (default: 1)\n");
|
|
|
|
printf( " -gl_readpixels_ok <n> Override DbgGlReadPixelsOk (default: 1)\n");
|
|
|
|
printf( " -gl_gettexlevelparam_ok <n> Override DbgGlGetTexLevelParamOk (default: 1)\n");
|
2007-07-23 18:13:49 +00:00
|
|
|
#else
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -hwsurface Use SDL HW Surface\n");
|
|
|
|
printf( " -asyncblit Use queued blits over SDL. Can speed up rendering\n");
|
2009-05-31 07:20:26 +00:00
|
|
|
#endif // OGL
|
2007-07-18 20:13:17 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
printf( "\n Help:\n\n");
|
2011-06-30 23:00:59 +00:00
|
|
|
printf( " -help, -h, -?, ? View this help screen\n");
|
2006-10-18 12:53:34 +00:00
|
|
|
printf( "\n\n");
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2010-07-25 01:22:44 +00:00
|
|
|
int Quitting = 0;
|
2010-04-04 01:31:48 +00:00
|
|
|
|
2015-12-05 22:57:25 +00:00
|
|
|
}
|
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-05 22:57:25 +00:00
|
|
|
|
2010-04-02 05:01:08 +00:00
|
|
|
// Default event handler for everything except the editor
|
2014-10-04 21:47:13 +00:00
|
|
|
int standard_handler(const d_event &event)
|
2010-04-02 05:01:08 +00:00
|
|
|
{
|
|
|
|
int key;
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2010-07-25 01:22:44 +00:00
|
|
|
if (Quitting)
|
|
|
|
{
|
|
|
|
window *wind = window_get_front();
|
|
|
|
if (!wind)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (wind == Game_wind)
|
|
|
|
{
|
|
|
|
int choice;
|
|
|
|
Quitting = 0;
|
|
|
|
choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
|
|
|
|
if (choice != 0)
|
|
|
|
return 0;
|
|
|
|
else
|
2010-11-30 22:45:10 +00:00
|
|
|
{
|
|
|
|
GameArg.SysAutoDemo = 0;
|
2010-07-25 01:22:44 +00:00
|
|
|
Quitting = 1;
|
2010-11-30 22:45:10 +00:00
|
|
|
}
|
2010-07-25 01:22:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close front window, let the code flow continue until all windows closed or quit cancelled
|
2012-04-09 12:41:47 +00:00
|
|
|
if (!window_close(wind))
|
|
|
|
Quitting = 0;
|
2010-07-25 01:22:44 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-10-04 21:47:13 +00:00
|
|
|
switch (event.type)
|
2010-04-02 05:01:08 +00:00
|
|
|
{
|
|
|
|
case EVENT_MOUSE_BUTTON_DOWN:
|
|
|
|
case EVENT_MOUSE_BUTTON_UP:
|
|
|
|
// No window selecting
|
|
|
|
// We stay with the current one until it's closed/hidden or another one is made
|
|
|
|
// Not the case for the editor
|
|
|
|
break;
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2010-04-02 05:01:08 +00:00
|
|
|
case EVENT_KEY_COMMAND:
|
2011-01-14 09:51:13 +00:00
|
|
|
key = event_key_get(event);
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2010-04-02 05:01:08 +00:00
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
#ifdef macintosh
|
|
|
|
case KEY_COMMAND + KEY_SHIFTED + KEY_3:
|
|
|
|
#endif
|
|
|
|
case KEY_PRINT_SCREEN:
|
|
|
|
{
|
|
|
|
gr_set_current_canvas(NULL);
|
|
|
|
save_screen_shot(0);
|
|
|
|
return 1;
|
|
|
|
}
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2010-04-02 05:01:08 +00:00
|
|
|
case KEY_ALTED+KEY_ENTER:
|
|
|
|
case KEY_ALTED+KEY_PADENTER:
|
2013-01-08 16:29:23 +00:00
|
|
|
if (Game_wind)
|
|
|
|
if (Game_wind == window_get_front())
|
|
|
|
return 0;
|
2010-04-02 05:01:08 +00:00
|
|
|
gr_toggle_fullscreen();
|
|
|
|
return 1;
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2010-04-02 05:01:08 +00:00
|
|
|
#if defined(__APPLE__) || defined(macintosh)
|
|
|
|
case KEY_COMMAND+KEY_Q:
|
|
|
|
// Alt-F4 already taken, too bad
|
2010-07-25 01:22:44 +00:00
|
|
|
Quitting = 1;
|
|
|
|
return 1;
|
2010-04-02 05:01:08 +00:00
|
|
|
#endif
|
2011-01-16 10:55:31 +00:00
|
|
|
case KEY_SHIFTED + KEY_ESC:
|
2011-01-14 21:56:00 +00:00
|
|
|
con_showup();
|
|
|
|
return 1;
|
2010-04-02 05:01:08 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2011-07-16 14:02:22 +00:00
|
|
|
case EVENT_WINDOW_DRAW:
|
2010-04-02 05:01:08 +00:00
|
|
|
case EVENT_IDLE:
|
|
|
|
//see if redbook song needs to be restarted
|
|
|
|
RBACheckFinishedHook();
|
|
|
|
return 1;
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2010-04-04 01:31:48 +00:00
|
|
|
case EVENT_QUIT:
|
2012-04-09 12:41:47 +00:00
|
|
|
#ifdef EDITOR
|
|
|
|
if (SafetyCheck())
|
|
|
|
#endif
|
|
|
|
Quitting = 1;
|
2010-07-25 01:22:44 +00:00
|
|
|
return 1;
|
2010-04-04 01:31:48 +00:00
|
|
|
|
2010-04-02 05:01:08 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2010-04-02 05:01:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-05 22:57:25 +00:00
|
|
|
}
|
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dsx {
|
2015-12-05 22:57:25 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
#define PROGNAME argv[0]
|
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
// DESCENT by Parallax Software
|
2006-03-20 17:12:09 +00:00
|
|
|
// DESCENT II by Parallax Software
|
2013-03-03 01:03:33 +00:00
|
|
|
// (varies based on preprocessor options)
|
2006-03-20 17:12:09 +00:00
|
|
|
// Descent Main
|
|
|
|
|
2015-12-05 22:57:25 +00:00
|
|
|
static int main(int argc, char *argv[])
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
mem_init();
|
2014-09-02 22:10:34 +00:00
|
|
|
#ifdef __linux__
|
2013-06-23 21:18:48 +00:00
|
|
|
error_init(NULL);
|
2014-10-10 02:43:14 +00:00
|
|
|
#ifdef WORDS_NEED_ALIGNMENT
|
|
|
|
prctl(PR_SET_UNALIGN, PR_UNALIGN_NOPRINT, 0, 0, 0);
|
|
|
|
#endif
|
2010-11-30 12:46:23 +00:00
|
|
|
#else
|
2013-06-23 21:18:48 +00:00
|
|
|
error_init(msgbox_error);
|
2010-11-28 12:08:29 +00:00
|
|
|
set_warn_func(msgbox_warning);
|
2010-11-30 12:46:23 +00:00
|
|
|
#endif
|
2015-01-28 03:42:53 +00:00
|
|
|
if (!PHYSFSX_init(argc, argv))
|
|
|
|
return 1;
|
2008-04-06 20:23:28 +00:00
|
|
|
con_init(); // Initialise the console
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2009-05-31 07:20:26 +00:00
|
|
|
setbuf(stdout, NULL); // unbuffered output via printf
|
2010-11-26 12:15:56 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
freopen( "CON", "w", stdout );
|
|
|
|
freopen( "CON", "w", stderr );
|
|
|
|
#endif
|
2009-05-31 07:20:26 +00:00
|
|
|
|
2015-11-24 04:05:35 +00:00
|
|
|
if (CGameArg.SysShowCmdHelp) {
|
2010-11-22 13:19:37 +00:00
|
|
|
print_commandline_help();
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\nType %s -help' for a list of command-line options.\n\n", PROGNAME);
|
|
|
|
|
2010-11-26 11:50:18 +00:00
|
|
|
PHYSFSX_listSearchPathContent();
|
2010-11-28 12:08:29 +00:00
|
|
|
|
2010-11-26 11:50:18 +00:00
|
|
|
if (!PHYSFSX_checkSupportedArchiveTypes())
|
|
|
|
return(0);
|
2008-05-01 21:40:34 +00:00
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
if (! PHYSFSX_contfile_init("descent.hog", 1))
|
|
|
|
#define DXX_NAME_NUMBER "1"
|
|
|
|
#define DXX_HOGFILE_NAMES "descent.hog"
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
|
|
|
if (! PHYSFSX_contfile_init("descent2.hog", 1) && ! PHYSFSX_contfile_init("d2demo.hog", 1))
|
2013-03-30 02:45:23 +00:00
|
|
|
#define DXX_NAME_NUMBER "2"
|
|
|
|
#define DXX_HOGFILE_NAMES "descent2.hog or d2demo.hog"
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
|
|
|
{
|
2008-01-19 00:55:54 +00:00
|
|
|
#if defined(__unix__) && !defined(__APPLE__)
|
2013-03-30 02:45:23 +00:00
|
|
|
#define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \
|
|
|
|
"\t$HOME/.d" DXX_NAME_NUMBER "x-rebirth\n" \
|
2006-03-20 17:12:09 +00:00
|
|
|
"\t" SHAREPATH "\n"
|
|
|
|
#else
|
2013-03-30 02:45:23 +00:00
|
|
|
#define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \
|
|
|
|
"\tDirectory containing D" DXX_NAME_NUMBER "X\n"
|
2006-03-20 17:12:09 +00:00
|
|
|
#endif
|
2010-09-17 10:44:21 +00:00
|
|
|
#if (defined(__APPLE__) && defined(__MACH__)) || defined(macintosh)
|
2013-03-30 02:45:23 +00:00
|
|
|
#define DXX_HOGFILE_APPLICATION_BUNDLE \
|
2010-09-17 10:44:21 +00:00
|
|
|
"\tIn 'Resources' inside the application bundle\n"
|
2013-03-30 02:45:23 +00:00
|
|
|
#else
|
|
|
|
#define DXX_HOGFILE_APPLICATION_BUNDLE ""
|
2010-09-17 10:44:21 +00:00
|
|
|
#endif
|
2013-03-30 02:45:23 +00:00
|
|
|
#define DXX_MISSING_HOGFILE_ERROR_TEXT \
|
|
|
|
"Could not find a valid hog file (" DXX_HOGFILE_NAMES ")\nPossible locations are:\n" \
|
|
|
|
DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \
|
|
|
|
"\tIn a subdirectory called 'Data'\n" \
|
|
|
|
DXX_HOGFILE_APPLICATION_BUNDLE \
|
|
|
|
"Or use the -hogdir option to specify an alternate location."
|
2015-10-09 02:46:11 +00:00
|
|
|
UserError(DXX_MISSING_HOGFILE_ERROR_TEXT);
|
2007-07-26 23:57:29 +00:00
|
|
|
}
|
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
switch (PHYSFSX_fsize("descent.hog"))
|
|
|
|
{
|
|
|
|
case D1_MAC_SHARE_MISSION_HOGSIZE:
|
|
|
|
case D1_MAC_MISSION_HOGSIZE:
|
|
|
|
MacHog = 1; // used for fonts and the Automap
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
load_text();
|
|
|
|
|
|
|
|
//print out the banner title
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
2013-12-07 00:47:27 +00:00
|
|
|
con_printf(CON_NORMAL, "%s %s", DESCENT_VERSION, g_descent_build_datetime); // D1X version
|
|
|
|
con_printf(CON_NORMAL, "This is a MODIFIED version of Descent, based on %s.", BASED_VERSION);
|
|
|
|
con_printf(CON_NORMAL, "%s\n%s",TXT_COPYRIGHT,TXT_TRADEMARK);
|
2015-02-13 03:27:28 +00:00
|
|
|
con_printf(CON_NORMAL, "Copyright (C) 2005-2013 Christian Beckhaeuser");
|
2013-03-03 01:03:33 +00:00
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
2013-12-07 00:47:27 +00:00
|
|
|
con_printf(CON_NORMAL, "%s%s %s", DESCENT_VERSION, PHYSFSX_exists(MISSION_DIR "d2x.hog",1) ? " Vertigo Enhanced" : "", g_descent_build_datetime); // D2X version
|
|
|
|
con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2, based on %s.", BASED_VERSION);
|
|
|
|
con_printf(CON_NORMAL, "%s\n%s",TXT_COPYRIGHT,TXT_TRADEMARK);
|
2015-02-13 03:27:28 +00:00
|
|
|
con_printf(CON_NORMAL, "Copyright (C) 1999 Peter Hawkins, 2002 Bradley Bell, 2005-2013 Christian Beckhaeuser");
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-10-18 21:01:21 +00:00
|
|
|
if (CGameArg.DbgVerbose)
|
2015-02-13 03:27:28 +00:00
|
|
|
con_puts(CON_VERBOSE, TXT_VERBOSE_1);
|
2010-11-22 13:19:37 +00:00
|
|
|
|
|
|
|
ReadConfigFile();
|
|
|
|
|
|
|
|
PHYSFSX_addArchiveContent();
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2008-11-14 16:56:40 +00:00
|
|
|
arch_init();
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-10-21 02:45:44 +00:00
|
|
|
select_tmap(GameArg.DbgTexMap);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2006-03-20 17:12:09 +00:00
|
|
|
Lighting_on = 1;
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-07 00:47:27 +00:00
|
|
|
con_printf(CON_VERBOSE, "Going into graphics mode...");
|
2007-08-16 09:16:53 +00:00
|
|
|
gr_set_mode(Game_screen_mode);
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
// Load the palette stuff. Returns non-zero if error.
|
2013-12-07 00:47:27 +00:00
|
|
|
con_printf(CON_DEBUG, "Initializing palette system..." );
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
gr_use_palette_table( "PALETTE.256" );
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
2007-06-11 15:54:09 +00:00
|
|
|
gr_use_palette_table(D2_DEFAULT_PALETTE );
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-07 00:47:27 +00:00
|
|
|
con_printf(CON_DEBUG, "Initializing font system..." );
|
2006-03-20 17:12:09 +00:00
|
|
|
gamefont_init(); // must load after palette data loaded.
|
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2013-12-07 00:47:27 +00:00
|
|
|
con_printf( CON_DEBUG, "Initializing movie libraries..." );
|
2006-03-20 17:12:09 +00:00
|
|
|
init_movies(); //init movie libraries
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2007-03-03 18:27:55 +00:00
|
|
|
show_titles();
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2007-08-08 18:07:21 +00:00
|
|
|
set_screen_mode(SCREEN_MENU);
|
|
|
|
|
2008-02-11 12:12:57 +00:00
|
|
|
con_printf( CON_DEBUG, "\nDoing gamedata_init..." );
|
|
|
|
gamedata_init();
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2006-03-20 17:12:09 +00:00
|
|
|
#ifdef EDITOR
|
2007-07-18 20:13:17 +00:00
|
|
|
if (GameArg.EdiSaveHoardData) {
|
2006-10-02 13:29:04 +00:00
|
|
|
save_hoard_data();
|
2006-03-20 17:12:09 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2007-07-18 20:13:17 +00:00
|
|
|
if (GameArg.DbgNoRun)
|
2006-03-20 17:12:09 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
|
|
|
|
texmerge_init( 10 ); // 10 cache bitmaps
|
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2010-06-14 08:13:16 +00:00
|
|
|
piggy_init_pigfile("groupa.pig"); //get correct pigfile
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2007-10-29 21:40:49 +00:00
|
|
|
|
2013-12-07 00:47:27 +00:00
|
|
|
con_printf( CON_DEBUG, "\nRunning game..." );
|
2006-03-20 17:12:09 +00:00
|
|
|
init_game();
|
|
|
|
|
2015-09-29 02:41:22 +00:00
|
|
|
get_local_player().callsign = {};
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
key_flush();
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
2006-03-20 17:12:09 +00:00
|
|
|
// If built with editor, option to auto-load a level and quit game
|
|
|
|
// to write certain data.
|
|
|
|
#ifdef EDITOR
|
2015-03-22 18:49:20 +00:00
|
|
|
if (!GameArg.EdiAutoLoad.empty()) {
|
2014-07-05 16:48:12 +00:00
|
|
|
Players[0].callsign = "dummy";
|
2006-03-20 17:12:09 +00:00
|
|
|
} else
|
|
|
|
#endif
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-10-10 09:53:58 +00:00
|
|
|
{
|
2015-03-22 18:49:20 +00:00
|
|
|
if (!GameArg.SysPilot.empty())
|
2006-10-10 09:53:58 +00:00
|
|
|
{
|
2007-05-21 11:24:27 +00:00
|
|
|
char filename[32] = "";
|
2014-07-05 03:32:08 +00:00
|
|
|
unsigned j;
|
2010-06-14 08:13:16 +00:00
|
|
|
|
2015-03-22 18:49:20 +00:00
|
|
|
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.12s"), GameArg.SysPilot.c_str());
|
2007-07-14 20:33:42 +00:00
|
|
|
for (j = GameArg.SysUsePlayersDir? 8 : 0; filename[j] != '\0'; j++) {
|
2006-10-18 12:53:34 +00:00
|
|
|
switch (filename[j]) {
|
|
|
|
case ' ':
|
|
|
|
filename[j] = '\0';
|
|
|
|
}
|
|
|
|
}
|
2014-07-05 03:32:08 +00:00
|
|
|
if (j < sizeof(filename) - 4 && (j <= 4 || strcmp(&filename[j - 4], ".plr"))) // if player hasn't specified .plr extension in argument, add it
|
|
|
|
{
|
|
|
|
strcpy(&filename[j], ".plr");
|
|
|
|
j += 4;
|
|
|
|
}
|
2011-06-01 07:59:55 +00:00
|
|
|
if(PHYSFSX_exists(filename,0))
|
2006-10-10 09:53:58 +00:00
|
|
|
{
|
2014-07-05 03:32:08 +00:00
|
|
|
filename[j - 4] = 0;
|
2014-07-05 16:48:12 +00:00
|
|
|
char *b = GameArg.SysUsePlayersDir? &filename[8] : filename;
|
2015-07-25 23:10:46 +00:00
|
|
|
get_local_player().callsign.copy(b, std::distance(b, end(filename)));
|
2006-10-10 09:53:58 +00:00
|
|
|
read_player_file();
|
|
|
|
WriteConfigFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2008-04-06 20:23:28 +00:00
|
|
|
#ifdef EDITOR
|
2015-03-22 18:49:20 +00:00
|
|
|
if (!GameArg.EdiAutoLoad.empty()) {
|
2014-12-20 04:36:11 +00:00
|
|
|
/* Any number >= FILENAME_LEN works */
|
2015-03-22 18:49:20 +00:00
|
|
|
Level_names[0].copy_if(GameArg.EdiAutoLoad.c_str(), GameArg.EdiAutoLoad.size());
|
2010-02-07 04:34:21 +00:00
|
|
|
LoadLevel(1, 1);
|
|
|
|
}
|
2010-04-04 01:31:48 +00:00
|
|
|
else
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2008-04-06 20:23:28 +00:00
|
|
|
#endif
|
2010-04-04 01:31:48 +00:00
|
|
|
{
|
|
|
|
Game_mode = GM_GAME_OVER;
|
|
|
|
DoMenu();
|
|
|
|
}
|
2009-05-21 12:16:39 +00:00
|
|
|
|
2010-04-04 01:31:48 +00:00
|
|
|
while (window_get_front())
|
2009-05-21 12:16:39 +00:00
|
|
|
// Send events to windows and the default handler
|
2010-04-04 01:31:48 +00:00
|
|
|
event_process();
|
2012-03-19 05:49:19 +00:00
|
|
|
|
|
|
|
// Tidy up - avoids a crash on exit
|
|
|
|
{
|
|
|
|
window *wind;
|
|
|
|
|
|
|
|
show_menus();
|
|
|
|
while ((wind = window_get_front()))
|
|
|
|
window_close(wind);
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
WriteConfigFile();
|
2007-03-03 18:27:55 +00:00
|
|
|
show_order_form();
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-07 00:47:27 +00:00
|
|
|
con_printf( CON_DEBUG, "\nCleanup..." );
|
2008-11-14 16:56:40 +00:00
|
|
|
close_game();
|
|
|
|
texmerge_close();
|
|
|
|
gamedata_close();
|
|
|
|
gamefont_close();
|
|
|
|
free_text();
|
2010-07-31 12:09:38 +00:00
|
|
|
newmenu_free_background();
|
2014-07-20 22:13:25 +00:00
|
|
|
Current_mission.reset();
|
2010-08-15 06:57:51 +00:00
|
|
|
PHYSFSX_removeArchiveContent();
|
2007-12-23 00:51:59 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
return(0); //presumably successful exit
|
|
|
|
}
|
2015-12-05 22:57:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
return dsx::main(argc, argv);
|
|
|
|
}
|