mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-12-11 05:01:09 +00:00
8d0c48bf81
- Removed movie volume from the sound menu and renamed some of the other options to give the MIDI device name more room to display itself. - Moved the midi device selection into the main sound menu. - Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the default device. By default, it uses exactly the same DLS instruments as the Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set you want to use, set the snd_midipatchfile cvar to specify where it should load the instruments from. - Changed the ProduceMIDI function to store its output into a TArray<BYTE>. An overloaded version wraps around it to continue to supply file-writing support for external Timidity++ usage. - Added an FMOD credits banner to comply with their non-commercial license. - Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather than a time in ms, this is now the length in samples of the DSP buffer. Also added the snd_buffercount cvar to offer complete control over the call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate below about 44kHz, you will need to set snd_buffersize to avoid long latencies. - Reimplemented the snd_output cvar for the FMOD Ex sound system. - Changed snd_samplerate default to 0. This now means to use the default sample rate. - Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and snd_hrtf available through the menu. - Split the HRTF effect selection into its own cvar: snd_hrtf. - Removed 96000 Hz option from the menu. It's still available through the cvar, if desired. - Fixed: If Windows sound init failed, retry with DirectSound. (Apparently, WASAPI doesn't work with more than two speakers and PCM-Float output at the same time.) - Fixed: Area sounds only played from the front speakers once you got within the 2D panning area. SVN r854 (trunk)
270 lines
7 KiB
C++
270 lines
7 KiB
C++
/*
|
|
** i_main.cpp
|
|
** System-specific startup code. Eventually calls D_DoomMain.
|
|
**
|
|
**---------------------------------------------------------------------------
|
|
** Copyright 1998-2007 Randy Heit
|
|
** All rights reserved.
|
|
**
|
|
** Redistribution and use in source and binary forms, with or without
|
|
** modification, are permitted provided that the following conditions
|
|
** are met:
|
|
**
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
** notice, this list of conditions and the following disclaimer.
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
** documentation and/or other materials provided with the distribution.
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
** derived from this software without specific prior written permission.
|
|
**
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
**---------------------------------------------------------------------------
|
|
**
|
|
*/
|
|
|
|
// HEADER FILES ------------------------------------------------------------
|
|
|
|
#include <SDL.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <signal.h>
|
|
#include <new>
|
|
#include <sys/param.h>
|
|
#include <gtk/gtk.h>
|
|
#include <locale.h>
|
|
|
|
#include "doomerrors.h"
|
|
#include "m_argv.h"
|
|
#include "d_main.h"
|
|
#include "i_system.h"
|
|
#include "i_video.h"
|
|
#include "c_console.h"
|
|
#include "errors.h"
|
|
#include "version.h"
|
|
#include "w_wad.h"
|
|
|
|
// MACROS ------------------------------------------------------------------
|
|
|
|
// The maximum number of functions that can be registered with atterm.
|
|
#define MAX_TERMS 32
|
|
|
|
// TYPES -------------------------------------------------------------------
|
|
|
|
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
|
|
|
extern "C" int cc_install_handlers(int, int*, const char*, int(*)(char*, char*));
|
|
|
|
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
|
|
|
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
|
|
|
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
|
|
|
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
|
|
|
bool GtkAvailable;
|
|
|
|
// The command line arguments.
|
|
DArgs *Args;
|
|
|
|
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
|
|
|
static void (*TermFuncs[MAX_TERMS]) ();
|
|
static const char *TermNames[MAX_TERMS];
|
|
static int NumTerms;
|
|
|
|
// CODE --------------------------------------------------------------------
|
|
|
|
void addterm (void (*func) (), const char *name)
|
|
{
|
|
// Make sure this function wasn't already registered.
|
|
for (int i = 0; i < NumTerms; ++i)
|
|
{
|
|
if (TermFuncs[i] == func)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
if (NumTerms == MAX_TERMS)
|
|
{
|
|
func ();
|
|
I_FatalError (
|
|
"Too many exit functions registered.\n"
|
|
"Increase MAX_TERMS in i_main.cpp");
|
|
}
|
|
TermNames[NumTerms] = name;
|
|
TermFuncs[NumTerms++] = func;
|
|
}
|
|
|
|
void popterm ()
|
|
{
|
|
if (NumTerms)
|
|
NumTerms--;
|
|
}
|
|
|
|
void STACK_ARGS call_terms ()
|
|
{
|
|
while (NumTerms > 0)
|
|
{
|
|
// printf ("term %d - %s\n", NumTerms, TermNames[NumTerms-1]);
|
|
TermFuncs[--NumTerms] ();
|
|
}
|
|
}
|
|
|
|
//==========================================================================
|
|
//
|
|
// FinalGC
|
|
//
|
|
// Collect garbage one last time before exiting.
|
|
//
|
|
//==========================================================================
|
|
|
|
static void FinalGC()
|
|
{
|
|
Args = NULL;
|
|
GC::FullGC();
|
|
}
|
|
|
|
static void STACK_ARGS NewFailure ()
|
|
{
|
|
I_FatalError ("Failed to allocate memory from system heap");
|
|
}
|
|
|
|
static int DoomSpecificInfo (char *buffer, char *end)
|
|
{
|
|
const char *arg;
|
|
int size = end-buffer;
|
|
int i, p;
|
|
|
|
SDL_Quit();
|
|
|
|
p = 0;
|
|
p += snprintf (buffer+p, size-p, GAMENAME" version " DOTVERSIONSTR " (" __DATE__ ")\n");
|
|
p += snprintf (buffer+p, size-p, "\nCommand line:");
|
|
for (i = 0; i < Args->NumArgs(); ++i)
|
|
{
|
|
p += snprintf (buffer+p, size-p, " %s", Args->GetArg(i));
|
|
}
|
|
p += snprintf (buffer+p, size-p, "\n");
|
|
|
|
for (i = 0; (arg = Wads.GetWadName (i)) != NULL; ++i)
|
|
{
|
|
p += snprintf (buffer+p, size-p, "\nWad %d: %s", i, arg);
|
|
}
|
|
|
|
if (gamestate != GS_LEVEL && gamestate != GS_TITLELEVEL)
|
|
{
|
|
p += snprintf (buffer+p, size-p, "\n\nNot in a level.");
|
|
}
|
|
else
|
|
{
|
|
char name[9];
|
|
|
|
strncpy (name, level.mapname, 8);
|
|
name[8] = 0;
|
|
p += snprintf (buffer+p, size-p, "\n\nCurrent map: %s", name);
|
|
|
|
if (!viewactive)
|
|
{
|
|
buffer += snprintf (buffer+p, size-p, "\n\nView not active.");
|
|
}
|
|
else
|
|
{
|
|
p += snprintf (buffer+p, size-p, "\n\nviewx = %d", (int)viewx);
|
|
p += snprintf (buffer+p, size-p, "\nviewy = %d", (int)viewy);
|
|
p += snprintf (buffer+p, size-p, "\nviewz = %d", (int)viewz);
|
|
p += snprintf (buffer+p, size-p, "\nviewangle = %x", (unsigned int)viewangle);
|
|
}
|
|
}
|
|
buffer[p++] = '\n';
|
|
buffer[p++] = '\0';
|
|
|
|
return p;
|
|
}
|
|
|
|
#include "zstring.h"
|
|
|
|
int main (int argc, char **argv)
|
|
{
|
|
printf(GAMENAME" v%s - SVN revision %s - SDL version\nCompiled on %s\n\n",
|
|
DOTVERSIONSTR_NOREV,SVN_REVISION_STRING,__DATE__);
|
|
|
|
{
|
|
int s[4] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS };
|
|
cc_install_handlers(4, s, "zdoom-crash.log", DoomSpecificInfo);
|
|
}
|
|
|
|
seteuid (getuid ());
|
|
std::set_new_handler (NewFailure);
|
|
|
|
GtkAvailable = gtk_init_check (&argc, &argv);
|
|
|
|
setlocale (LC_ALL, "C");
|
|
|
|
if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) == -1)
|
|
{
|
|
fprintf (stderr, "Could not initialize SDL:\n%s\n", SDL_GetError());
|
|
return -1;
|
|
}
|
|
atterm (SDL_Quit);
|
|
|
|
SDL_WM_SetCaption (GAMESIG " " DOTVERSIONSTR " (" __DATE__ ")", NULL);
|
|
|
|
try
|
|
{
|
|
Args = new DArgs(argc, argv);
|
|
atterm(FinalGC);
|
|
|
|
/*
|
|
killough 1/98:
|
|
|
|
This fixes some problems with exit handling
|
|
during abnormal situations.
|
|
|
|
The old code called I_Quit() to end program,
|
|
while now I_Quit() is installed as an exit
|
|
handler and exit() is called to exit, either
|
|
normally or abnormally. Seg faults are caught
|
|
and the error handler is used, to prevent
|
|
being left in graphics mode or having very
|
|
loud SFX noise because the sound card is
|
|
left in an unstable state.
|
|
*/
|
|
|
|
atexit (call_terms);
|
|
atterm (I_Quit);
|
|
|
|
if (realpath (argv[0], progdir) == NULL)
|
|
strcpy (progdir, argv[0]);
|
|
char *slash = strrchr (progdir, '/');
|
|
if (slash)
|
|
*(slash + 1) = '\0';
|
|
else
|
|
progdir[0] = '.', progdir[1] = '/', progdir[2] = '\0';
|
|
|
|
C_InitConsole (80*8, 25*8, false);
|
|
D_DoomMain ();
|
|
}
|
|
catch (class CDoomError &error)
|
|
{
|
|
if (error.GetMessage ())
|
|
fprintf (stderr, "%s\n", error.GetMessage ());
|
|
exit (-1);
|
|
}
|
|
catch (...)
|
|
{
|
|
call_terms ();
|
|
throw;
|
|
}
|
|
return 0;
|
|
}
|