*/
void SCR_BeginLoadingPlaque (void)
{
- S_StopAllSounds ();
+ Host_StartVideo();
+ S_StopAllSounds();
SCR_UpdateLoadingScreen();
}
static sizebuf_t cmd_text;
static qbyte cmd_text_buf[32768];
-/*
-============
-Cbuf_Init
-============
-*/
-void Cbuf_Init (void)
-{
- // space for commands and script files
- cmd_text.data = cmd_text_buf;
- cmd_text.maxsize = sizeof(cmd_text_buf);
- cmd_text.cursize = 0;
-}
-
-/*
-============
-Cbuf_Shutdown
-============
-*/
-void Cbuf_Shutdown (void)
-{
-}
-
/*
============
Cbuf_AddText
quake -nosound +cmd amlev1
===============
*/
+qboolean host_stuffcmdsrun = false;
void Cmd_StuffCmds_f (void)
{
int i, j, l;
return;
}
+ host_stuffcmdsrun = true;
for (i = 0;i < com_argc;i++)
{
if (com_argv[i] && com_argv[i][0] == '+' && (com_argv[i][1] < '0' || com_argv[i][1] > '9'))
}
a->next = current;
}
-
+
// copy the rest of the command line
cmd[0] = 0; // start out with a null string
void Cmd_Init (void)
{
cmd_mempool = Mem_AllocPool("commands", 0, NULL);
+ // space for commands and script files
+ cmd_text.data = cmd_text_buf;
+ cmd_text.maxsize = sizeof(cmd_text_buf);
+ cmd_text.cursize = 0;
+}
+void Cmd_Init_Commands (void)
+{
//
// register our commands
//
return; // no tokens
}
-// check functions (only after host_initialized)
- if (host_initialized || !strcasecmp(cmd_argv[0], "exec") || !strcasecmp(cmd_argv[0], "set") || !strcasecmp(cmd_argv[0], "seta"))
+// check functions
+ for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
{
- for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
+ if (!strcasecmp (cmd_argv[0],cmd->name))
{
- if (!strcasecmp (cmd_argv[0],cmd->name))
- {
- cmd->function ();
- cmd_tokenizebufferpos = oldpos;
- return;
- }
+ cmd->function ();
+ cmd_tokenizebufferpos = oldpos;
+ return;
}
}
-// check alias (only after host_initialized)
- if (host_initialized)
+// check alias
+ for (a=cmd_alias ; a ; a=a->next)
{
- for (a=cmd_alias ; a ; a=a->next)
+ if (!strcasecmp (cmd_argv[0], a->name))
{
- if (!strcasecmp (cmd_argv[0], a->name))
- {
- Cbuf_InsertText (a->value);
- cmd_tokenizebufferpos = oldpos;
- return;
- }
+ Cbuf_InsertText (a->value);
+ cmd_tokenizebufferpos = oldpos;
+ return;
}
}
-// check cvars (always)
- if (!Cvar_Command () && host_initialized)
+// check cvars
+ if (!Cvar_Command ())
Con_Printf("Unknown command \"%s\"\n", Cmd_Argv(0));
cmd_tokenizebufferpos = oldpos;
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.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
void Cbuf_Init (void);
// allocates an initial text buffer that will grow as needed
+void Cmd_Init_Commands (void);
+
void Cbuf_Shutdown (void);
void Cbuf_AddText (const char *text);
}
-extern void Mathlib_Init(void);
-extern void FS_Init (void);
-
/*
================
COM_Init
================
*/
-void COM_Init (void)
+void COM_Init_Commands (void)
{
Cvar_RegisterVariable (®istered);
Cvar_RegisterVariable (&cmdline);
-
- Mathlib_Init();
-
- FS_Init ();
- COM_CheckRegistered ();
-}
-
-extern void FS_Shutdown (void);
-
-/*
-================
-COM_Shutdown
-================
-*/
-void COM_Shutdown (void)
-{
- FS_Shutdown ();
}
/*
}
-/*
-====================
-Log_Init
-====================
-*/
-void Log_Init (void)
-{
- // Allocate a log queue
- logq_size = 512;
- logqueue = Mem_Alloc (tempmempool, logq_size);
- logq_ind = 0;
-
- Cvar_RegisterVariable (&log_file);
-
- // support for the classic Quake option
-// COMMANDLINEOPTION: Console: -condebug logs console messages to qconsole.log, see also log_file
- if (COM_CheckParm ("-condebug") != 0)
- Cvar_SetQuick (&log_file, "qconsole.log");
-}
-
-
/*
====================
Log_Open
if (width == con_linewidth)
return;
- if (width < 1) // video hasn't been initialized yet
- {
- width = 80;
- con_linewidth = width;
- con_totallines = CON_TEXTSIZE / con_linewidth;
- memset (con_text, ' ', CON_TEXTSIZE);
- }
- else
- {
- oldwidth = con_linewidth;
- con_linewidth = width;
- oldtotallines = con_totallines;
- con_totallines = CON_TEXTSIZE / con_linewidth;
- numlines = oldtotallines;
+ oldwidth = con_linewidth;
+ con_linewidth = width;
+ oldtotallines = con_totallines;
+ con_totallines = CON_TEXTSIZE / con_linewidth;
+ numlines = oldtotallines;
- if (con_totallines < numlines)
- numlines = con_totallines;
+ if (con_totallines < numlines)
+ numlines = con_totallines;
- numchars = oldwidth;
+ numchars = oldwidth;
- if (con_linewidth < numchars)
- numchars = con_linewidth;
+ if (con_linewidth < numchars)
+ numchars = con_linewidth;
- memcpy (tbuf, con_text, CON_TEXTSIZE);
- memset (con_text, ' ', CON_TEXTSIZE);
+ memcpy (tbuf, con_text, CON_TEXTSIZE);
+ memset (con_text, ' ', CON_TEXTSIZE);
- for (i=0 ; i<numlines ; i++)
+ for (i=0 ; i<numlines ; i++)
+ {
+ for (j=0 ; j<numchars ; j++)
{
- for (j=0 ; j<numchars ; j++)
- {
- con_text[(con_totallines - 1 - i) * con_linewidth + j] =
- tbuf[((con_current - i + oldtotallines) %
- oldtotallines) * oldwidth + j];
- }
+ con_text[(con_totallines - 1 - i) * con_linewidth + j] =
+ tbuf[((con_current - i + oldtotallines) %
+ oldtotallines) * oldwidth + j];
}
-
- Con_ClearNotify ();
}
+ Con_ClearNotify ();
+
con_backscroll = 0;
con_current = con_totallines - 1;
}
void Con_Init (void)
{
memset (con_text, ' ', CON_TEXTSIZE);
- con_linewidth = -1;
- Con_CheckResize ();
+ con_linewidth = 80;
+ con_totallines = CON_TEXTSIZE / con_linewidth;
+
+ // Allocate a log queue
+ logq_size = 512;
+ logqueue = Mem_Alloc (tempmempool, logq_size);
+ logq_ind = 0;
+
+ Cvar_RegisterVariable (&log_file);
+ // support for the classic Quake option
+// COMMANDLINEOPTION: Console: -condebug logs console messages to qconsole.log, see also log_file
+ if (COM_CheckParm ("-condebug") != 0)
+ Cvar_SetQuick (&log_file, "qconsole.log");
+}
+
+void Con_Init_Commands (void)
+{
// register our cvars
Cvar_RegisterVariable (&con_notifytime);
Cvar_RegisterVariable (&con_notify);
void Con_CheckResize (void);
void Con_Init (void);
+void Con_Init_Commands (void);
void Con_DrawConsole (int lines);
void Con_Print(const char *txt);
void Con_Printf(const char *fmt, ...);
if (developer.integer)
Con_Printf("Cvar_Get(\"%s\", \"%s\", %i);\n", name, value, flags);
-
+
// first check to see if it has already been defined
cvar = Cvar_FindVar (name);
if (cvar)
// perform a variable print or set
if (Cmd_Argc() == 1)
{
- // only print if host_initialized (otherwise it could print twice if this is in a script)
- if (host_initialized)
- Con_Printf("\"%s\" is \"%s\"\n", v->name, v->string);
+ Con_Printf("\"%s\" is \"%s\"\n", v->name, v->string);
return true;
}
const char *homedir;
#endif
- strlcpy (com_modname, dir, sizeof (com_modname));
-
// Add the common game directory
FS_AddGameDirectory (va("%s/%s", fs_basedir, dir));
fs_mempool = Mem_AllocPool("file management", 0, NULL);
- Cvar_RegisterVariable (&scr_screenshot_name);
-
- Cmd_AddCommand ("path", FS_Path_f);
- Cmd_AddCommand ("dir", FS_Dir_f);
- Cmd_AddCommand ("ls", FS_Ls_f);
-
strcpy(fs_basedir, ".");
strcpy(fs_gamedir, ".");
// add the game-specific paths
// gamedirname1 (typically id1)
FS_AddGameHierarchy (gamedirname1);
- Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname);
// add the game-specific path, if any
if (gamedirname2)
FS_AddGameHierarchy (gamedirname2);
}
+ // set the com_modname (reported in server info)
+ strlcpy(com_modname, gamedirname1, sizeof(com_modname));
+
// -game <gamedir>
// Adds basedir/gamedir as an override game
// LordHavoc: now supports multiple -game directories
i++;
fs_modified = true;
FS_AddGameHierarchy (com_argv[i]);
- Cvar_SetQuick (&scr_screenshot_name, com_modname);
+ // update the com_modname
+ strlcpy (com_modname, com_argv[i], sizeof (com_modname));
}
}
unlink (va("%s/qconsole.log", fs_gamedir));
}
+void FS_Init_Commands(void)
+{
+ Cvar_RegisterVariable (&scr_screenshot_name);
+
+ Cmd_AddCommand ("path", FS_Path_f);
+ Cmd_AddCommand ("dir", FS_Dir_f);
+ Cmd_AddCommand ("ls", FS_Ls_f);
+
+ // set the default screenshot name to either the mod name or the
+ // gamemode screenshot name
+ if (fs_modified)
+ Cvar_SetQuick (&scr_screenshot_name, com_modname);
+ else
+ Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname);
+}
+
/*
================
FS_Shutdown
*/
-// true if into command execution
-qboolean host_initialized;
-// LordHavoc: used to turn Host_Error into Sys_Error if starting up or shutting down
-qboolean host_loopactive = false;
+// how many frames have occurred
+// (checked by Host_Error and Host_SaveConfig_f)
+int host_framecount;
// LordHavoc: set when quit is executed
qboolean host_shuttingdown = false;
double realtime;
// realtime from previous frame
double oldrealtime;
-// how many frames have occurred
-int host_framecount;
// used for -developer commandline parameter, hacky hacky
int forcedeveloper;
Con_Printf("Host_Error: %s\n", hosterrorstring1);
- // LordHavoc: if first frame has not been shown, or currently shutting
- // down, do Sys_Error instead
- if (!host_loopactive || host_shuttingdown)
+ // LordHavoc: if crashing very early, or currently shutting down, do
+ // Sys_Error instead
+ if (host_framecount < 3 || host_shuttingdown)
Sys_Error ("Host_Error: %s", hosterrorstring1);
if (hosterror)
void Host_ServerOptions (void)
{
- int i, numplayers;
+ int i;
// general default
- numplayers = 8;
+ svs.maxclients = 8;
// COMMANDLINEOPTION: Server: -dedicated [playerlimit] starts a dedicated server (with a command console), default playerlimit is 8
// COMMANDLINEOPTION: Server: -listen [playerlimit] starts a multiplayer server with graphical client, like singleplayer but other players can connect, default playerlimit is 8
{
cls.state = ca_dedicated;
// default players unless specified
- if (i != (com_argc - 1))
- numplayers = atoi (com_argv[i+1]);
+ if (i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
+ svs.maxclients = atoi (com_argv[i+1]);
if (COM_CheckParm ("-listen"))
Sys_Error ("Only one of -dedicated or -listen can be specified");
}
if (i)
{
// default players unless specified
- if (i != (com_argc - 1))
- numplayers = atoi (com_argv[i+1]);
+ if (i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
+ svs.maxclients = atoi (com_argv[i+1]);
}
else
{
// default players in some games, singleplayer in most
if (gamemode != GAME_TRANSFUSION && gamemode != GAME_GOODVSBAD2 && gamemode != GAME_NEXUIZ && gamemode != GAME_BATTLEMECH)
- numplayers = 1;
+ svs.maxclients = 1;
}
}
}
// check for -dedicated specifying how many players
i = COM_CheckParm ("-dedicated");
// default players unless specified
- if (i && i != (com_argc - 1))
- numplayers = atoi (com_argv[i+1]);
+ if (i && i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
+ svs.maxclients = atoi (com_argv[i+1]);
}
- if (numplayers < 1)
- numplayers = 8;
+ svs.maxclients = bound(1, svs.maxclients, MAX_SCOREBOARD);
- numplayers = bound(1, numplayers, MAX_SCOREBOARD);
+ svs.clients = Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
- if (numplayers > 1 && !deathmatch.integer)
+ if (svs.maxclients > 1 && !deathmatch.integer)
Cvar_SetValueQuick(&deathmatch, 1);
-
- svs.maxclients = numplayers;
- svs.clients = Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
}
/*
void Host_SaveConfig_f(void);
void Host_InitLocal (void)
{
- Host_InitCommands ();
-
Cmd_AddCommand("saveconfig", Host_SaveConfig_f);
Cvar_RegisterVariable (&host_framerate);
Cvar_RegisterVariable (×tamps);
Cvar_RegisterVariable (&timeformat);
-
- Host_ServerOptions ();
}
// dedicated servers initialize the host but don't parse and set the
// config.cfg cvars
- // LordHavoc: save a config only after Host_Frame finished the first frame
- if (host_initialized && host_loopactive && cls.state != ca_dedicated)
+ // LordHavoc: don't save a config if it crashed in startup
+ if (host_framecount >= 3 && cls.state != ca_dedicated)
{
f = FS_Open ("config.cfg", "wb", false, false);
if (!f)
}
host_framecount++;
- host_loopactive = true;
-
}
void Host_Frame (float time)
//============================================================================
-void Render_Init(void);
+qboolean vid_opened = false;
+void Host_StartVideo(void)
+{
+ if (!vid_opened && cls.state != ca_dedicated)
+ {
+ vid_opened = true;
+ VID_Open();
+ CDAudio_Startup();
+ CL_InitTEnts(); // We must wait after sound startup to load tent sounds
+ MR_Init();
+ SCR_BeginLoadingPlaque();
+ }
+}
+
+char engineversion[128];
+
+qboolean sys_nostdout = false;
+
+extern void Render_Init(void);
+extern void Mathlib_Init(void);
+extern void FS_Init(void);
+extern void FS_Shutdown(void);
+extern void PR_Cmd_Init(void);
+extern void COM_Init_Commands(void);
+extern void FS_Init_Commands(void);
+extern void COM_CheckRegistered(void);
+extern qboolean host_stuffcmdsrun;
/*
====================
void Host_Init (void)
{
int i;
+ const char* os;
// LordHavoc: quake never seeded the random number generator before... heh
srand(time(NULL));
+ // used by everything
+ Memory_Init();
+
+ // initialize console and logging
+ Con_Init();
+
+ // initialize console command/cvar/alias/command execution systems
+ Cmd_Init();
+
+ // parse commandline
+ COM_InitArgv();
+
+ // initialize console window (only used by sys_win.c)
+ Sys_InitConsole();
+
+ // detect gamemode from commandline options or executable name
+ COM_InitGameType();
+
+ // construct a version string for the corner of the console
+#if defined(__linux__)
+ os = "Linux";
+#elif defined(WIN32)
+ os = "Windows";
+#elif defined(__FreeBSD__)
+ os = "FreeBSD";
+#elif defined(__NetBSD__)
+ os = "NetBSD";
+#elif defined(__OpenBSD__)
+ os = "OpenBSD";
+#elif defined(MACOSX)
+ os = "Mac OS X";
+#else
+ os = "Unknown";
+#endif
+ dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
+
+// COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from
+ if (COM_CheckParm("-nostdout"))
+ sys_nostdout = 1;
+ else
+ Con_Printf("%s\n", engineversion);
+
// FIXME: this is evil, but possibly temporary
// COMMANDLINEOPTION: Console: -developer enables warnings and other notices (RECOMMENDED for mod developers)
if (COM_CheckParm("-developer"))
developer.value = 1;
}
- Cmd_Init();
+ // initialize filesystem (including fs_basedir, fs_gamedir, -path, -game, scr_screenshot_name)
+ FS_Init();
+
+ // initialize various cvars that could not be initialized earlier
Memory_Init_Commands();
- Con_Init();
- Cbuf_Init();
- R_Modules_Init();
- V_Init();
- COM_Init();
- Key_Init();
+ Con_Init_Commands();
+ Cmd_Init_Commands();
+ Sys_Init_Commands();
+ COM_Init_Commands();
+ FS_Init_Commands();
+ COM_CheckRegistered();
+
+ // initialize ixtable
+ Mathlib_Init();
+
+ NetConn_Init();
PR_Init();
+ PR_Cmd_Init();
PRVM_Init();
Mod_Init();
- NetConn_Init();
SV_Init();
+ Host_InitCommands();
Host_InitLocal();
-
- Con_Printf("Builddate: %s\n", buildstring);
+ Host_ServerOptions();
if (cls.state != ca_dedicated)
{
+ Con_Printf("Initializing client\n");
+
+ R_Modules_Init();
Palette_Init();
MR_Init_Commands();
VID_Shared_Init();
VID_Init();
-
Render_Init();
S_Init();
CDAudio_Init();
+ Key_Init();
+ V_Init();
CL_Init();
}
- Cbuf_Execute();
-
- // only cvars are executed when host_initialized == false
- if (gamemode == GAME_TEU)
- Cbuf_InsertText("exec teu.rc\n");
- else
- Cbuf_InsertText("exec quake.rc\n");
-
- Cbuf_Execute();
- Cbuf_Execute();
- Cbuf_Execute();
-
- host_initialized = true;
-
- Con_DPrint("========Initialized=========\n");
-
- if (cls.state != ca_dedicated)
- {
- VID_Open();
- CDAudio_Startup();
- CL_InitTEnts (); // We must wait after sound startup to load tent sounds
- SCR_BeginLoadingPlaque();
- MR_Init();
- }
-
- // set up the default startmap_sp and startmap_dm aliases, mods can
- // override these
+ // set up the default startmap_sp and startmap_dm aliases (mods can
+ // override these) and then execute the quake.rc startup script
if (gamemode == GAME_NEHAHRA)
- {
- Cbuf_InsertText ("alias startmap_sp \"map nehstart\"\n");
- Cbuf_InsertText ("alias startmap_dm \"map nehstart\"\n");
- }
+ Cbuf_InsertText("alias startmap_sp \"map nehstart\"\nalias startmap_dm \"map nehstart\"\nexec quake.rc\n");
else if (gamemode == GAME_TRANSFUSION)
- {
- Cbuf_InsertText ("alias startmap_sp \"map e1m1\"\n");
- Cbuf_InsertText ("alias startmap_dm \"map bb1\"\n");
- }
+ Cbuf_InsertText("alias startmap_sp \"map e1m1\"\n""alias startmap_dm \"map bb1\"\nexec quake.rc\n");
else if (gamemode == GAME_NEXUIZ)
- {
- Cbuf_InsertText ("alias startmap_sp \"map nexdm01\"\n");
- Cbuf_InsertText ("alias startmap_dm \"map nexdm01\"\n");
- }
+ Cbuf_InsertText("alias startmap_sp \"map nexdm01\"\nalias startmap_dm \"map nexdm01\"\nexec quake.rc\n");
+ else if (gamemode == GAME_TEU)
+ Cbuf_InsertText("alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec teu.rc\n");
else
- {
- Cbuf_InsertText ("alias startmap_sp \"map start\"\n");
- Cbuf_InsertText ("alias startmap_dm \"map start\"\n");
- }
+ Cbuf_InsertText("alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec quake.rc\n");
- // stuff it again so the first host frame will execute it again, this time
- // in its entirety
- if (gamemode == GAME_TEU)
- Cbuf_InsertText("exec teu.rc\n");
- else
- Cbuf_InsertText("exec quake.rc\n");
+ // if stuffcmds wasn't run, then quake.rc is probably missing, use default
+ if (!host_stuffcmdsrun)
+ Cbuf_InsertText("exec default.cfg\nexec config.cfg\nexec autoexec.cfg\nstuffcmds\nstartdemos\n");
Cbuf_Execute();
Cbuf_Execute();
Cbuf_Execute();
- // We must wait for the log_file cvar to be initialized to start the log
- Log_Start ();
-
- if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
- if (!sv.active && !cls.demoplayback && !cls.connect_trying)
- Cbuf_InsertText ("startmap_dm\n");
-
- Cbuf_Execute();
+ // save console log up to this point to log_file if it was set by configs
+ Log_Start();
// check for special benchmark mode
// COMMANDLINEOPTION: Client: -benchmark <demoname> runs a timedemo and quits, results of any timedemo can be found in gamedir/benchmark.log (for example id1/benchmark.log)
i = COM_CheckParm("-benchmark");
if (i && i + 1 < com_argc)
if (!sv.active && !cls.demoplayback && !cls.connect_trying)
+ {
Cbuf_InsertText(va("timedemo %s\n", com_argv[i + 1]));
+ Cbuf_Execute();
+ }
- Cbuf_Execute();
+ if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
+ if (!sv.active && !cls.demoplayback && !cls.connect_trying)
+ {
+ Cbuf_InsertText("startmap_dm\n");
+ Cbuf_Execute();
+ }
if (!sv.active && !cls.demoplayback && !cls.connect_trying)
{
Cbuf_InsertText("playvideo logo\n");
Cbuf_InsertText("cd loop 1\n");
}
+ Cbuf_Execute();
}
- Cbuf_Execute();
- Cbuf_Execute();
- Cbuf_Execute();
+ Con_DPrint("========Initialized=========\n");
+
+ Host_StartVideo();
}
S_Terminate ();
NetConn_Shutdown ();
PR_Shutdown ();
- Cbuf_Shutdown ();
if (cls.state != ca_dedicated)
{
Cmd_Shutdown();
CL_Shutdown();
Sys_Shutdown();
- Log_Close ();
- COM_Shutdown ();
+ Log_Close();
+ FS_Shutdown();
Memory_Shutdown();
}
extern cvar_t developer;
-// true if into command execution
-extern qboolean host_initialized;
extern double host_frametime;
// the real frametime, before slowmo and clamping are applied (used for console scrolling)
extern double host_realframetime;
void Host_InitCommands(void);
void Host_Init(void);
void Host_Shutdown(void);
+void Host_StartVideo(void);
void Host_Error(const char *error, ...);
void Host_Frame(float time);
void Host_Quit_f(void);
void Sys_UnloadLibrary (dllhandle_t* handle);
void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
-// called after Com_InitArgv
-void Sys_Shared_EarlyInit (void);
-// called after Host_init
-void Sys_Shared_LateInit (void);
+// called early in Host_Init
+void Sys_InitConsole (void);
+// called after command system is initialized but before first Con_Print
+void Sys_Init_Commands (void);
+
// returns current timestamp
char *Sys_TimeString(const char *timeformat);
return NULL;
}
+void Sys_InitConsole (void)
+{
+}
+
+void Sys_Init_Commands (void)
+{
+}
+
int main (int argc, char **argv)
{
double frameoldtime, framenewtime;
fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
#endif
- Sys_Shared_EarlyInit();
-
Host_Init();
- Sys_Shared_LateInit();
-
frameoldtime = Sys_DoubleTime () - 0.1;
while (1)
{
#include <SDL.h>
-#ifdef WIN32
-cvar_t sys_usetimegettime = {CVAR_SAVE, "sys_usetimegettime", "1"};
-#endif
-
// =======================================================================
// General routines
// =======================================================================
fflush(stdout);
SDL_Quit();
}
-
+
void Sys_Error (const char *error, ...)
{
static int first = true;
static double oldtime = 0.0, curtime = 0.0;
double newtime;
-#ifdef WIN32
- // LordHavoc: note to people modifying this code, DWORD is specifically defined as an unsigned 32bit number, therefore the 65536.0 * 65536.0 is fine.
- if (!sys_usetimegettime.integer)
- {
- // QueryPerformanceCounter
- // platform:
- // Windows 95/98/ME/NT/2000/XP
- // features:
- // very accurate (CPU cycles)
- // known issues:
- // does not necessarily match realtime too well (tends to get faster and faster in win98)
- // wraps around occasionally on some platforms (depends on CPU speed and probably other unknown factors)
- double timescale;
- LARGE_INTEGER PerformanceFreq;
- LARGE_INTEGER PerformanceCount;
-
- if (!QueryPerformanceFrequency (&PerformanceFreq))
- Sys_Error ("No hardware timer available");
- QueryPerformanceCounter (&PerformanceCount);
-
- #ifdef __BORLANDC__
- timescale = 1.0 / ((double) PerformanceFreq.u.LowPart + (double) PerformanceFreq.u.HighPart * 65536.0 * 65536.0);
- newtime = ((double) PerformanceCount.u.LowPart + (double) PerformanceCount.u.HighPart * 65536.0 * 65536.0) * timescale;
- #else
- timescale = 1.0 / ((double) PerformanceFreq.LowPart + (double) PerformanceFreq.HighPart * 65536.0 * 65536.0);
- newtime = ((double) PerformanceCount.LowPart + (double) PerformanceCount.HighPart * 65536.0 * 65536.0) * timescale;
- #endif
- } else
-#endif
newtime = (double) SDL_GetTicks() / 1000.0;
if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
{
- if ((cliptext = GlobalLock (hClipboardData)) != 0)
+ if ((cliptext = GlobalLock (hClipboardData)) != 0)
{
data = malloc (GlobalSize(hClipboardData)+1);
strcpy (data, cliptext);
#endif
}
+void Sys_InitConsole (void)
+{
+}
+
+void Sys_Init_Commands (void)
+{
+}
+
int main (int argc, char *argv[])
{
double frameoldtime, framenewtime;
fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
#endif
- Sys_Shared_EarlyInit();
-
-#ifdef WIN32
- Cvar_RegisterVariable(&sys_usetimegettime);
-#endif
-
Host_Init();
- Sys_Shared_LateInit();
-
frameoldtime = Sys_DoubleTime () - 0.1;
while (1)
{
# include <dlfcn.h>
#endif
-qboolean sys_nostdout = false;
-
static char sys_timestring[128];
char *Sys_TimeString(const char *timeformat)
{
exit(0);
}
-char engineversion[128];
-
-void Sys_Shared_EarlyInit(void)
-{
- const char* os;
-
- Memory_Init ();
- Log_Init ();
-
- COM_InitArgv();
- COM_InitGameType();
-
-#if defined(__linux__)
- os = "Linux";
-#elif defined(WIN32)
- os = "Windows";
-#elif defined(__FreeBSD__)
- os = "FreeBSD";
-#elif defined(__NetBSD__)
- os = "NetBSD";
-#elif defined(__OpenBSD__)
- os = "OpenBSD";
-#elif defined(MACOSX)
- os = "Mac OS X";
-#else
- os = "Unknown";
-#endif
- dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
-
-// COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from
- if (COM_CheckParm("-nostdout"))
- sys_nostdout = 1;
- else
- Con_Printf("%s\n", engineversion);
-}
-
-void Sys_Shared_LateInit(void)
-{
-}
-
/*
===============================================================================
if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
{
- if ((cliptext = GlobalLock (hClipboardData)) != 0)
+ if ((cliptext = GlobalLock (hClipboardData)) != 0)
{
data = malloc (GlobalSize(hClipboardData)+1);
strcpy (data, cliptext);
return data;
}
+void Sys_InitConsole (void)
+{
+ // initialize the windows dedicated server console if needed
+ tevent = CreateEvent(NULL, false, false, NULL);
+
+ if (!tevent)
+ Sys_Error ("Couldn't create event");
+
+ // LordHavoc: can't check cls.state because it hasn't been initialized yet
+ // if (cls.state == ca_dedicated)
+ if (COM_CheckParm("-dedicated"))
+ {
+ if (!AllocConsole ())
+ Sys_Error ("Couldn't create dedicated server console");
+
+ hinput = GetStdHandle (STD_INPUT_HANDLE);
+ houtput = GetStdHandle (STD_OUTPUT_HANDLE);
+
+ // give QHOST a chance to hook into the console
+ if ((t = COM_CheckParm ("-HFILE")) > 0)
+ {
+ if (t < com_argc)
+ hFile = (HANDLE)atoi (com_argv[t+1]);
+ }
+
+ if ((t = COM_CheckParm ("-HPARENT")) > 0)
+ {
+ if (t < com_argc)
+ heventParent = (HANDLE)atoi (com_argv[t+1]);
+ }
+
+ if ((t = COM_CheckParm ("-HCHILD")) > 0)
+ {
+ if (t < com_argc)
+ heventChild = (HANDLE)atoi (com_argv[t+1]);
+ }
+
+ InitConProc (hFile, heventParent, heventChild);
+ }
+
+// because sound is off until we become active
+ S_BlockSound ();
+}
+
+void Sys_Init_Commands (void)
+{
+ Cvar_RegisterVariable(&sys_usetimegettime);
+}
+
/*
==============================================================================
}
}
- Sys_Shared_EarlyInit();
-
- Cvar_RegisterVariable(&sys_usetimegettime);
-
- tevent = CreateEvent(NULL, false, false, NULL);
-
- if (!tevent)
- Sys_Error ("Couldn't create event");
-
- // LordHavoc: can't check cls.state because it hasn't been initialized yet
- // if (cls.state == ca_dedicated)
- if (COM_CheckParm("-dedicated"))
- {
- if (!AllocConsole ())
- Sys_Error ("Couldn't create dedicated server console");
-
- hinput = GetStdHandle (STD_INPUT_HANDLE);
- houtput = GetStdHandle (STD_OUTPUT_HANDLE);
-
- // give QHOST a chance to hook into the console
- if ((t = COM_CheckParm ("-HFILE")) > 0)
- {
- if (t < com_argc)
- hFile = (HANDLE)atoi (com_argv[t+1]);
- }
-
- if ((t = COM_CheckParm ("-HPARENT")) > 0)
- {
- if (t < com_argc)
- heventParent = (HANDLE)atoi (com_argv[t+1]);
- }
-
- if ((t = COM_CheckParm ("-HCHILD")) > 0)
- {
- if (t < com_argc)
- heventChild = (HANDLE)atoi (com_argv[t+1]);
- }
-
- InitConProc (hFile, heventParent, heventChild);
- }
-
-// because sound is off until we become active
- S_BlockSound ();
-
Host_Init ();
- Sys_Shared_LateInit();
-
frameoldtime = Sys_DoubleTime ();
-
+
/* main window message loop */
while (1)
{
extern void (*vid_menudrawfn)(void);
extern void (*vid_menukeyfn)(int key);
-extern int vid_hidden;
-extern int vid_activewindow;
+extern qboolean vid_hidden;
+extern qboolean vid_activewindow;
extern cvar_t vid_hardwaregammasupported;
-extern int vid_usinghwgamma;
+extern qboolean vid_usinghwgamma;
extern cvar_t vid_fullscreen;
extern cvar_t vid_width;
static XF86VidModeModeInfo **vidmodes;
static int num_vidmodes;
-static qboolean vidmode_active = false;
+static qboolean vid_isfullscreen = false;
static Visual *vidx11_visual;
static Colormap vidx11_colormap;
uninstall_grabs();
// FIXME: glXDestroyContext here?
- if (vidmode_active)
+ if (vid_isfullscreen)
XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, vidmodes[0]);
if (win)
XDestroyWindow(vidx11_display, win);
XCloseDisplay(vidx11_display);
}
- vidmode_active = false;
+ vid_isfullscreen = false;
vidx11_display = NULL;
win = 0;
ctx = NULL;
// handle the mouse state when windowed if that's changed
vid_usemouse = false;
- if (vid_mouse.integer && !key_consoleactive)
+ if (vid_mouse.integer && !key_consoleactive && !cls.demoplayback)
vid_usemouse = true;
- if (vidmode_active)
+ if (vid_isfullscreen)
vid_usemouse = true;
+ if (!vid_activewindow)
+ vid_usemouse = false;
if (vid_usemouse)
{
if (!vid_usingmouse)
// change to the mode
XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, vidmodes[best_fit]);
- vidmode_active = true;
+ vid_isfullscreen = true;
// Move the viewport to top left
XF86VidModeSetViewPort(vidx11_display, vidx11_screen, 0, 0);
// LordHavoc: save the colormap for later, too
vidx11_colormap = attr.colormap = XCreateColormap(vidx11_display, root, visinfo->visual, AllocNone);
attr.event_mask = X_MASK;
- if (vidmode_active)
+ if (vid_isfullscreen)
{
mask = CWBackPixel | CWColormap | CWSaveUnder | CWBackingStore | CWEventMask | CWOverrideRedirect;
attr.override_redirect = True;
wm_delete_window_atom = XInternAtom(vidx11_display, "WM_DELETE_WINDOW", false);
XSetWMProtocols(vidx11_display, win, &wm_delete_window_atom, 1);
- if (vidmode_active)
+ if (vid_isfullscreen)
{
XMoveWindow(vidx11_display, win, 0, 0);
XRaiseWindow(vidx11_display, win);
// Tell startup code that we have a client
int cl_available = true;
-static int vid_usingmouse;
-static int vid_isfullscreen;
+static qboolean vid_usingmouse;
+static qboolean vid_isfullscreen;
static SDL_Surface *screen;
#define tenoh 0,0,0,0,0, 0,0,0,0,0
#define fiftyoh tenoh, tenoh, tenoh, tenoh, tenoh
#define hundredoh fiftyoh, fiftyoh
-static unsigned int tbl_sdltoquake[] =
+static unsigned int tbl_sdltoquake[] =
{
0,0,0,0, //SDLK_UNKNOWN = 0,
0,0,0,0, //SDLK_FIRST = 0,
void IN_Move( void )
{
- IN_MouseMove();
+ IN_MouseMove();
}
static void IN_Init( void )
// Message Handling
////
-static int Sys_EventFilter( SDL_Event *event )
+static int Sys_EventFilter( SDL_Event *event )
{
//TODO: Add a quit query in linux, too - though linux user are more likely to know what they do
#ifdef WIN32
if( event->type == SDL_QUIT && MessageBox( NULL, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION ) == IDNO )
return 0;
- else
+ else
return 1;
#else
return 1;
Key_Event( MapKey( event.key.keysym.sym ), (char)event.key.keysym.unicode, (event.key.state == SDL_PRESSED) );
break;
case SDL_ACTIVEEVENT:
- if( event.active.state == SDL_APPACTIVE )
+ if( event.active.state == SDL_APPACTIVE )
{
if( event.active.gain )
vid_hidden = false;
}
break;
case SDL_MOUSEBUTTONDOWN:
- if( event.button.button == SDL_BUTTON_MIDDLE )
+ if( event.button.button == SDL_BUTTON_MIDDLE )
event.button.button = SDL_BUTTON_RIGHT;
else if( event.button.button == SDL_BUTTON_RIGHT )
event.button.button = SDL_BUTTON_MIDDLE;
Key_Event( K_MOUSE1 + event.button.button - 1, 0, true );
break;
case SDL_MOUSEBUTTONUP:
- if( event.button.button == SDL_BUTTON_MIDDLE )
+ if( event.button.button == SDL_BUTTON_MIDDLE )
event.button.button = SDL_BUTTON_RIGHT;
else if( event.button.button == SDL_BUTTON_RIGHT )
event.button.button = SDL_BUTTON_MIDDLE;
// set the caption
SDL_WM_SetCaption( gamename, NULL );
- // get the HWND handle
+ // get the HWND handle
SDL_VERSION( &info.version );
if( !SDL_GetWMInfo( &info ) )
return;
Con_Printf( "Linked against SDL version %d.%d.%d\n"
"Using SDL library version %d.%d.%d\n",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL,
- version->major, version->minor, version->patch );
+ version->major, version->minor, version->patch );
}
int VID_InitMode(int fullscreen, int width, int height, int bpp)
VID_OutputVersion();
- /*
- SDL Hack
+ /*
+ SDL Hack
We cant switch from one OpenGL video mode to another.
Thus we first switch to some stupid 2D mode and then back to OpenGL.
*/
if (i && i < com_argc - 1)
drivername = com_argv[i + 1];
if (SDL_GL_LoadLibrary(drivername) < 0)
- {
+ {
Con_Printf("Unable to load GL driver \"%s\": %s\n", drivername, SDL_GetError());
return false;
}
qglGetString = GL_GetProcAddress("glGetString");
-
+
// Knghtbrd: should do platform-specific extension string function here
if (qglGetString == NULL)
return false;
}
VID_SetCaption();
-
+
gl_renderer = qglGetString(GL_RENDERER);
gl_vendor = qglGetString(GL_VENDOR);
gl_version = qglGetString(GL_VERSION);
//TODO: maybe ;)
gl_platformextensions = "";
gl_videosyncavailable = false;
-
+
GL_Init();
vid_hidden = false;
void VID_Finish (void)
{
Uint8 appstate;
- int vid_usemouse;
+ qboolean vid_usemouse;
if (r_speeds.integer || gl_finish.integer)
qglFinish();
if( !( appstate & SDL_APPMOUSEFOCUS ) || !( appstate & SDL_APPINPUTFOCUS ) )
vid_activewindow = false;
- else
+ else
vid_activewindow = true;
vid_usemouse = false;
- if( vid_mouse.integer && !key_consoleactive )
+ if( vid_mouse.integer && !key_consoleactive && !cls.demoplayback )
vid_usemouse = true;
if( vid_isfullscreen )
vid_usemouse = true;
int gl_support_fragment_shader = false;
// LordHavoc: if window is hidden, don't update screen
-int vid_hidden = true;
+qboolean vid_hidden = true;
// LordHavoc: if window is not the active window, don't hog as much CPU time,
// let go of the mouse, turn off sound, and restore system gamma ramps...
-int vid_activewindow = true;
+qboolean vid_activewindow = true;
// we don't know until we try it!
cvar_t vid_hardwaregammasupported = {CVAR_READONLY,"vid_hardwaregammasupported","1"};
// whether hardware gamma ramps are currently in effect
-int vid_usinghwgamma = false;
+qboolean vid_usinghwgamma = false;
unsigned short vid_gammaramps[768];
unsigned short vid_systemgammaramps[768];
gl_support_fragment_shader = GL_CheckExtension("GL_ARB_fragment_shader", NULL, "-nofragmentshader", false);
}
-int vid_vertexarrays_are_var = false;
+qboolean vid_vertexarrays_are_var = false;
void *VID_AllocVertexArrays(mempool_t *pool, int size, int fast, float readfrequency, float writefrequency, float priority)
{
void *m;
R_Modules_Shutdown();
}
-int vid_commandlinecheck = true;
+qboolean vid_commandlinecheck = true;
void VID_Restart_f(void)
{
//HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
-static int vid_isfullscreen;
+static qboolean vid_isfullscreen;
//void VID_MenuDraw (void);
//void VID_MenuKey (int key);
// handle the mouse state when windowed if that's changed
vid_usemouse = false;
- if (vid_mouse.integer && !key_consoleactive)
+ if (vid_mouse.integer && !key_consoleactive && !cls.demoplayback)
vid_usemouse = true;
if (vid_isfullscreen)
vid_usemouse = true;
IN_ClearStates ();
}
-extern qboolean host_loopactive;
-
void AppActivate(BOOL fActive, BOOL minimize)
/****************************************************************************
*