2010-02-15 23:26:55 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-2001 Id Software, Inc.
|
|
|
|
Copyright (C) 2002-2005 John Fitzgibbons and others
|
|
|
|
Copyright (C) 2007-2008 Kristian Duske
|
2014-09-22 08:55:46 +00:00
|
|
|
Copyright (C) 2010-2014 QuakeSpasm developers
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
2010-06-19 22:50:48 +00:00
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
#include "quakedef.h"
|
2012-08-16 04:51:41 +00:00
|
|
|
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
|
2014-09-05 19:34:43 +00:00
|
|
|
#if defined(USE_SDL2)
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#else
|
2012-08-16 04:51:41 +00:00
|
|
|
#include <SDL/SDL.h>
|
2014-09-05 19:34:43 +00:00
|
|
|
#endif
|
2012-08-16 04:51:41 +00:00
|
|
|
#else
|
2010-06-19 22:50:48 +00:00
|
|
|
#include "SDL.h"
|
2012-08-16 04:51:41 +00:00
|
|
|
#endif
|
2010-06-19 22:50:48 +00:00
|
|
|
#include <stdio.h>
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2014-10-18 11:20:14 +00:00
|
|
|
static void Sys_AtExit (void)
|
|
|
|
{
|
|
|
|
SDL_Quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Sys_InitSDL (void)
|
2011-12-22 21:20:19 +00:00
|
|
|
{
|
2014-09-05 19:34:43 +00:00
|
|
|
#if defined(USE_SDL2)
|
|
|
|
SDL_version v;
|
|
|
|
SDL_version *sdl_version = &v;
|
|
|
|
SDL_GetVersion(&v);
|
|
|
|
#else
|
2011-12-22 21:20:19 +00:00
|
|
|
const SDL_version *sdl_version = SDL_Linked_Version();
|
2014-09-05 19:34:43 +00:00
|
|
|
#endif
|
2011-12-22 21:20:19 +00:00
|
|
|
|
|
|
|
Sys_Printf("Found SDL version %i.%i.%i\n",sdl_version->major,sdl_version->minor,sdl_version->patch);
|
2014-10-18 11:20:14 +00:00
|
|
|
|
2022-05-24 17:55:04 +00:00
|
|
|
if (SDL_Init(0) < 0) {
|
2014-10-18 16:33:01 +00:00
|
|
|
Sys_Error("Couldn't init SDL: %s", SDL_GetError());
|
2014-10-18 11:20:14 +00:00
|
|
|
}
|
|
|
|
atexit(Sys_AtExit);
|
2011-12-22 21:20:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-09 20:29:22 +00:00
|
|
|
#define DEFAULT_MEMORY (256 * 1024 * 1024) // ericw -- was 72MB (64-bit) / 64MB (32-bit)
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-04-19 16:41:45 +00:00
|
|
|
static quakeparms_t parms;
|
2014-09-05 19:34:43 +00:00
|
|
|
|
|
|
|
// On OS X we call SDL_main from the launcher, but SDL2 doesn't redefine main
|
|
|
|
// as SDL_main on OS X anymore, so we do it ourselves.
|
|
|
|
#if defined(USE_SDL2) && defined(__APPLE__)
|
|
|
|
#define main SDL_main
|
|
|
|
#endif
|
2011-04-19 16:41:45 +00:00
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
int t;
|
|
|
|
double time, oldtime, newtime;
|
|
|
|
|
2011-04-19 16:41:45 +00:00
|
|
|
host_parms = &parms;
|
2010-02-17 23:32:04 +00:00
|
|
|
parms.basedir = ".";
|
|
|
|
|
|
|
|
parms.argc = argc;
|
|
|
|
parms.argv = argv;
|
|
|
|
|
2018-02-21 07:33:07 +00:00
|
|
|
parms.errstate = 0;
|
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
COM_InitArgv(parms.argc, parms.argv);
|
|
|
|
|
|
|
|
isDedicated = (COM_CheckParm("-dedicated") != 0);
|
|
|
|
|
2014-10-18 11:20:14 +00:00
|
|
|
Sys_InitSDL ();
|
2011-12-22 21:20:19 +00:00
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
Sys_Init();
|
|
|
|
|
2022-07-15 13:56:57 +00:00
|
|
|
Sys_Printf("Initializing "ENGINE_NAME_AND_VER"\n");
|
2022-07-03 02:23:00 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
parms.memsize = DEFAULT_MEMORY;
|
|
|
|
if (COM_CheckParm("-heapsize"))
|
2020-06-19 21:32:27 +00:00
|
|
|
{ //in kb
|
2010-02-17 23:32:04 +00:00
|
|
|
t = COM_CheckParm("-heapsize") + 1;
|
|
|
|
if (t < com_argc)
|
|
|
|
parms.memsize = Q_atoi(com_argv[t]) * 1024;
|
|
|
|
}
|
2020-06-19 21:32:27 +00:00
|
|
|
else if (COM_CheckParm("-mem"))
|
|
|
|
{ //in mb, matching vanilla's arg on dos or linux.
|
|
|
|
t = COM_CheckParm("-mem") + 1;
|
|
|
|
if (t < com_argc)
|
|
|
|
parms.memsize = Q_atoi(com_argv[t]) * 1024*1024;
|
|
|
|
}
|
2010-02-17 23:32:04 +00:00
|
|
|
|
|
|
|
parms.membase = malloc (parms.memsize);
|
|
|
|
|
|
|
|
if (!parms.membase)
|
|
|
|
Sys_Error ("Not enough memory free; check disk space\n");
|
|
|
|
|
2011-01-06 20:05:49 +00:00
|
|
|
Sys_Printf("Host_Init\n");
|
2011-04-19 16:41:45 +00:00
|
|
|
Host_Init();
|
2010-02-17 23:32:04 +00:00
|
|
|
|
2011-12-12 16:01:01 +00:00
|
|
|
oldtime = Sys_DoubleTime();
|
2010-06-19 14:50:48 +00:00
|
|
|
if (isDedicated)
|
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
2011-12-12 16:01:01 +00:00
|
|
|
newtime = Sys_DoubleTime ();
|
2010-06-19 14:50:48 +00:00
|
|
|
time = newtime - oldtime;
|
|
|
|
|
|
|
|
while (time < sys_ticrate.value )
|
|
|
|
{
|
|
|
|
SDL_Delay(1);
|
2011-12-12 16:01:01 +00:00
|
|
|
newtime = Sys_DoubleTime ();
|
2010-06-19 14:50:48 +00:00
|
|
|
time = newtime - oldtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
Host_Frame (time);
|
|
|
|
oldtime = newtime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2011-12-16 14:11:37 +00:00
|
|
|
while (1)
|
2010-02-17 23:32:04 +00:00
|
|
|
{
|
2011-12-16 14:11:37 +00:00
|
|
|
/* If we have no input focus at all, sleep a bit */
|
2014-10-18 11:20:14 +00:00
|
|
|
if (!VID_HasMouseOrInputFocus() || cl.paused)
|
2010-02-17 23:32:04 +00:00
|
|
|
{
|
2011-12-16 14:11:37 +00:00
|
|
|
SDL_Delay(16);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
2011-12-16 14:11:37 +00:00
|
|
|
/* If we're minimised, sleep a bit more */
|
2014-10-18 11:20:14 +00:00
|
|
|
if (VID_IsMinimized())
|
2011-12-16 14:11:37 +00:00
|
|
|
{
|
|
|
|
scr_skipupdate = 1;
|
|
|
|
SDL_Delay(32);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scr_skipupdate = 0;
|
|
|
|
}
|
|
|
|
newtime = Sys_DoubleTime ();
|
2010-02-17 23:32:04 +00:00
|
|
|
time = newtime - oldtime;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-16 14:11:37 +00:00
|
|
|
Host_Frame (time);
|
|
|
|
|
2017-11-16 18:21:38 +00:00
|
|
|
if (time < sys_throttle.value && !cls.timedemo)
|
2010-02-17 23:32:04 +00:00
|
|
|
SDL_Delay(1);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
oldtime = newtime;
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
return 0;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|