also fix some of the new warnings to make a dedicated build just pass DEDICATED=1 to the compiler TODO:make this compatible with bluajit
239 lines
4.8 KiB
C
239 lines
4.8 KiB
C
// Emacs style mode select -*- C++ -*-
|
|
//-----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
|
//
|
|
// This program is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU General Public License
|
|
// as published by the Free Software Foundation; either version 2
|
|
// of the License, or (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//-----------------------------------------------------------------------------
|
|
/// \file
|
|
/// \brief Main program, simply calls D_SRB2Main and D_SRB2Loop, the high level loop.
|
|
|
|
#include "../doomdef.h"
|
|
#include "../m_argv.h"
|
|
#include "../d_main.h"
|
|
#include "../m_misc.h" /* path shit */
|
|
#include "../i_system.h"
|
|
#include "../d_clisrv.h"
|
|
|
|
#if defined (__GNUC__) || defined (__unix__)
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#ifdef __unix__
|
|
#include <errno.h>
|
|
#endif
|
|
|
|
#include "time.h" // For log timestamps
|
|
|
|
#ifdef HAVE_TTF
|
|
#include "i_ttf.h"
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBBACKTRACE
|
|
#include <backtrace.h>
|
|
|
|
struct backtrace_state *bt_state = NULL;
|
|
#endif
|
|
|
|
#ifdef LOGMESSAGES
|
|
FILE *logstream = NULL;
|
|
char logfilename[1024];
|
|
#endif
|
|
|
|
#ifndef DOXYGEN
|
|
#ifndef O_TEXT
|
|
#define O_TEXT 0
|
|
#endif
|
|
|
|
#ifndef O_SEQUENTIAL
|
|
#define O_SEQUENTIAL 0
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
#ifndef _AMD64_
|
|
#include "exchndl.h"
|
|
#define DRMINGW
|
|
#endif
|
|
#endif
|
|
|
|
#if defined (_WIN32)
|
|
#include "../win32/win_dbg.h"
|
|
typedef BOOL (WINAPI *p_IsDebuggerPresent)(VOID);
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
static void
|
|
ChDirToExe (void)
|
|
{
|
|
CHAR path[MAX_PATH];
|
|
if (GetModuleFileNameA(NULL, path, MAX_PATH) > 0)
|
|
{
|
|
strrchr(path, '\\')[0] = '\0';
|
|
SetCurrentDirectoryA(path);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/** \brief The main function
|
|
|
|
\param argc number of arg
|
|
\param *argv string table
|
|
|
|
\return int
|
|
*/
|
|
#if defined (__GNUC__) && (__GNUC__ >= 4)
|
|
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
|
|
#endif
|
|
|
|
#ifdef LOGMESSAGES
|
|
static void InitLogging(void)
|
|
{
|
|
const char *logdir = NULL;
|
|
time_t my_time;
|
|
struct tm * timeinfo;
|
|
const char *format;
|
|
const char *reldir;
|
|
int left;
|
|
boolean fileabs;
|
|
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
|
|
const char *link;
|
|
#endif
|
|
|
|
logdir = D_Home();
|
|
|
|
my_time = time(NULL);
|
|
timeinfo = localtime(&my_time);
|
|
|
|
if (M_CheckParm("-logfile") && M_IsNextParm())
|
|
{
|
|
format = M_GetNextParm();
|
|
fileabs = M_IsPathAbsolute(format);
|
|
}
|
|
else
|
|
{
|
|
format = "log-%Y-%m-%d_%H-%M-%S.txt";
|
|
fileabs = false;
|
|
}
|
|
|
|
if (fileabs)
|
|
{
|
|
strftime(logfilename, sizeof logfilename, format, timeinfo);
|
|
}
|
|
else
|
|
{
|
|
if (M_CheckParm("-logdir") && M_IsNextParm())
|
|
reldir = M_GetNextParm();
|
|
else
|
|
reldir = "logs";
|
|
|
|
if (M_IsPathAbsolute(reldir))
|
|
{
|
|
left = snprintf(logfilename, sizeof logfilename,
|
|
"%s"PATHSEP, reldir);
|
|
}
|
|
else
|
|
#ifdef DEFAULTDIR
|
|
if (logdir)
|
|
{
|
|
left = snprintf(logfilename, sizeof logfilename,
|
|
"%s"PATHSEP DEFAULTDIR PATHSEP"%s"PATHSEP, logdir, reldir);
|
|
}
|
|
else
|
|
#endif/*DEFAULTDIR*/
|
|
{
|
|
left = snprintf(logfilename, sizeof logfilename,
|
|
"."PATHSEP"%s"PATHSEP, reldir);
|
|
}
|
|
|
|
strftime(&logfilename[left], sizeof logfilename - left,
|
|
format, timeinfo);
|
|
}
|
|
|
|
M_MkdirEachUntil(logfilename,
|
|
M_PathParts(logdir) - 1,
|
|
M_PathParts(logfilename) - 1, 0755);
|
|
|
|
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
|
|
logstream = fopen(logfilename, "w");
|
|
#ifdef DEFAULTDIR
|
|
if (logdir)
|
|
link = va("%s/"DEFAULTDIR"/latest-log.txt", logdir);
|
|
else
|
|
#endif/*DEFAULTDIR*/
|
|
link = "latest-log.txt";
|
|
unlink(link);
|
|
if (symlink(logfilename, link) == -1)
|
|
{
|
|
I_OutputMsg("Error symlinking latest-log.txt: %s\n", strerror(errno));
|
|
}
|
|
#else/*defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)*/
|
|
logstream = fopen("latest-log.txt", "wt+");
|
|
#endif/*defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)*/
|
|
}
|
|
#endif
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
myargc = argc;
|
|
myargv = argv; /// \todo pull out path to exe from this string
|
|
|
|
dedicated = true;
|
|
|
|
#ifdef HAVE_LIBBACKTRACE
|
|
bt_state = backtrace_create_state(
|
|
argv[0],
|
|
#ifdef HAVE_THREADS
|
|
1,
|
|
#else
|
|
0,
|
|
#endif
|
|
NULL,
|
|
NULL
|
|
);
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
ChDirToExe();
|
|
#endif
|
|
|
|
#ifdef LOGMESSAGES
|
|
if (!M_CheckParm("-nolog"))
|
|
InitLogging();
|
|
#endif/*LOGMESSAGES*/
|
|
|
|
//I_OutputMsg("I_StartupSystem() ...\n");
|
|
I_StartupSystem();
|
|
#if defined (_WIN32)
|
|
{
|
|
#ifdef DRMINGW
|
|
ExcHndlInit();
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
// startup SRB2
|
|
CONS_Printf("Setting up SRB2Kart...\n");
|
|
D_SRB2Main();
|
|
CONS_Printf("Entering main game loop...\n");
|
|
// never return
|
|
D_SRB2Loop();
|
|
|
|
#ifdef BUGTRAP
|
|
// This is safe even if BT didn't start.
|
|
ShutdownBugTrap();
|
|
#endif
|
|
|
|
// return to OS
|
|
return 0;
|
|
}
|