Clean up the startup file diffs.

This also makes functionality consistent across the platforms, such as
adding support for -dedicated to sdl based nq, and various timing
calculations are now consistent.
This commit is contained in:
Bill Currie 2011-09-03 19:58:03 +09:00
parent db8eee502f
commit cca9983a48
12 changed files with 204 additions and 281 deletions

View file

@ -34,6 +34,6 @@
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] =
"$Id$"; "$Id$";
extern int noconinput; extern int qf_sdl_link;
static __attribute__ ((used)) int *const _noconinput = &noconinput; static __attribute__ ((used)) int *const _qf_sdl_link = &qf_sdl_link;

View file

@ -31,12 +31,6 @@
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] =
"$Id$"; "$Id$";
#ifdef HAVE_CONIO_H
# include <conio.h>
#endif
#ifdef HAVE_IO_H
# include <io.h>
#endif
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
# include <string.h> # include <string.h>
#endif #endif
@ -47,35 +41,29 @@ static __attribute__ ((used)) const char rcsid[] =
# include <unistd.h> # include <unistd.h>
#endif #endif
#include <errno.h> #ifdef HAVE_FCNTL_H
#include <fcntl.h> # include <fcntl.h>
#include <limits.h> #else
#include <stdio.h> # include <sys/fcntl.h>
#include <stdlib.h>
#ifndef _WIN32
# include <signal.h>
#endif #endif
#include <SDL.h> #include <SDL.h>
#include <SDL_main.h> #include <SDL_main.h>
#include "QF/console.h" #include "QF/cvar.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "client.h" #include "client.h"
#include "compat.h"
#include "host.h" #include "host.h"
qboolean isDedicated = false;
int noconinput;
#ifdef _WIN32 #ifdef _WIN32
# include "winquake.h" # include "winquake.h"
#endif #endif
int qf_sdl_link;
qboolean isDedicated = false;
static void static void
startup (void) startup (void)
{ {
@ -103,7 +91,9 @@ static void
shutdown_f (void) shutdown_f (void)
{ {
#ifndef _WIN32 #ifndef _WIN32
// change stdin to blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
fflush (stdout);
#endif #endif
} }
@ -112,7 +102,7 @@ shutdown_f (void)
#endif #endif
int int
SDL_main (int c, char **v) SDL_main (int argc, const char **argv)
{ {
double time, oldtime, newtime; double time, oldtime, newtime;
@ -120,29 +110,43 @@ SDL_main (int c, char **v)
memset (&host_parms, 0, sizeof (host_parms)); memset (&host_parms, 0, sizeof (host_parms));
COM_InitArgv (c, (const char **)v); COM_InitArgv (argc, argv);
host_parms.argc = com_argc; host_parms.argc = com_argc;
host_parms.argv = com_argv; host_parms.argv = com_argv;
#ifndef _WIN32 isDedicated = (COM_CheckParm ("-dedicated") != 0);
noconinput = COM_CheckParm ("-noconinput");
if (!noconinput)
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
#endif
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown_f); Sys_RegisterShutdown (shutdown_f);
Host_Init (); Host_Init ();
oldtime = Sys_DoubleTime (); #ifndef _WIN32
while (1) { if (!sys_nostdout->int_val) {
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
Sys_Printf ("Quake -- Version %s\n", NQ_VERSION);
}
#endif
oldtime = Sys_DoubleTime () - 0.1;
while (1) { // Main message loop
// find time spent rendering last frame // find time spent rendering last frame
newtime = Sys_DoubleTime (); newtime = Sys_DoubleTime ();
time = newtime - oldtime; time = newtime - oldtime;
if (cls.state == ca_dedicated) { // play vcrfiles at max speed
if (time < sys_ticrate->value && (!vcrFile || recording)) {
usleep (1);
continue; // not time to run a server-only tic yet
}
time = sys_ticrate->value;
}
if (time > sys_ticrate->value * 2)
oldtime = newtime;
else
oldtime += time;
Host_Frame (time); Host_Frame (time);
oldtime = newtime;
} }
return 0; // shouldn't be reachable, but mingw gcc 3.1 is being weird
} }

View file

@ -29,7 +29,7 @@
# include "config.h" # include "config.h"
#endif #endif
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] =
"$Id$"; "$Id$";
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
@ -42,14 +42,11 @@ static __attribute__ ((used)) const char rcsid[] =
# include <unistd.h> # include <unistd.h>
#endif #endif
#include <errno.h> #ifdef HAVE_FCNTL_H
#include <fcntl.h> # include <fcntl.h>
#include <signal.h> #else
#include <stdio.h> # include <sys/fcntl.h>
#include <stdlib.h> #endif
#include <time.h>
#include <sys/stat.h>
#include <sys/time.h>
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/qargs.h" #include "QF/qargs.h"
@ -57,7 +54,6 @@ static __attribute__ ((used)) const char rcsid[] =
#include "client.h" #include "client.h"
#include "host.h" #include "host.h"
#include "server.h"
qboolean isDedicated = false; qboolean isDedicated = false;
@ -66,24 +62,22 @@ shutdown_f (void)
{ {
// change stdin to blocking // change stdin to blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
fflush (stdout);
} }
int int
main (int c, const char *v[]) main (int argc, const char **argv)
{ {
double time, oldtime, newtime; double time, oldtime, newtime;
memset (&host_parms, 0, sizeof (host_parms)); memset (&host_parms, 0, sizeof (host_parms));
COM_InitArgv (c, v); COM_InitArgv (argc, argv);
host_parms.argc = com_argc; host_parms.argc = com_argc;
host_parms.argv = com_argv; host_parms.argv = com_argv;
isDedicated = (COM_CheckParm ("-dedicated") != 0); isDedicated = (COM_CheckParm ("-dedicated") != 0);
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown_f); Sys_RegisterShutdown (shutdown_f);
@ -95,7 +89,7 @@ main (int c, const char *v[])
} }
oldtime = Sys_DoubleTime () - 0.1; oldtime = Sys_DoubleTime () - 0.1;
while (1) { while (1) { // Main message loop
// find time spent rendering last frame // find time spent rendering last frame
newtime = Sys_DoubleTime (); newtime = Sys_DoubleTime ();
time = newtime - oldtime; time = newtime - oldtime;

View file

@ -1,7 +1,7 @@
/* /*
sys_unixd.c sys_unixd.c
@description@ (description)
Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 1996-1997 Id Software, Inc.
@ -28,7 +28,7 @@
# include "config.h" # include "config.h"
#endif #endif
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] =
"$Id$"; "$Id$";
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
@ -49,19 +49,16 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/qtypes.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "client.h"
#include "host.h" #include "host.h"
qboolean isDedicated = true; qboolean isDedicated = true;
int nostdout = 0;
static void static void
shutdown_f (void) shutdown_f (void)
{ {
// change stdin to blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
fflush (stdout); fflush (stdout);
} }
@ -92,13 +89,13 @@ main (int argc, const char **argv)
host_parms.argc = com_argc; host_parms.argc = com_argc;
host_parms.argv = com_argv; host_parms.argv = com_argv;
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown_f); Sys_RegisterShutdown (shutdown_f);
Host_Init (); Host_Init ();
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
oldtime = Sys_DoubleTime () - 0.1; oldtime = Sys_DoubleTime () - 0.1;
while (1) { // Main message loop while (1) { // Main message loop
Sys_CheckInput (0, -1); Sys_CheckInput (0, -1);
@ -108,7 +105,7 @@ main (int argc, const char **argv)
time = newtime - oldtime; time = newtime - oldtime;
if (time < sys_ticrate->value) { if (time < sys_ticrate->value) {
usleep (1); usleep (1);
continue; continue; // not time to run a server-only tic yet
} }
time = sys_ticrate->value; time = sys_ticrate->value;
@ -119,5 +116,4 @@ main (int argc, const char **argv)
Host_Frame (time); Host_Frame (time);
} }
return true; // return success
} }

View file

@ -28,24 +28,22 @@
# include "config.h" # include "config.h"
#endif #endif
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] =
"$Id$"; "$Id$";
#include "winquake.h" #include "winquake.h"
#include "win32/resources/resource.h" #include "win32/resources/resource.h"
#include "QF/console.h"
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/quakeio.h"
#include "QF/screen.h" #include "QF/screen.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "client.h" #include "client.h"
#include "compat.h"
#include "game.h"
#include "host.h" #include "host.h"
qboolean isDedicated = false;
#define MINIMUM_WIN_MEMORY 0x0880000 #define MINIMUM_WIN_MEMORY 0x0880000
#define MAXIMUM_WIN_MEMORY 0x1000000 #define MAXIMUM_WIN_MEMORY 0x1000000
@ -59,11 +57,8 @@ qboolean WinNT;
static double pfreq; static double pfreq;
static int lowshift; static int lowshift;
qboolean isDedicated;
HANDLE hinput, houtput; HANDLE hinput, houtput;
static const char tracking_tag[] = "Clams & Mooses";
static HANDLE tevent; static HANDLE tevent;
// SYSTEM IO ================================================================== // SYSTEM IO ==================================================================
@ -132,60 +127,11 @@ const char *argv[MAX_NUM_ARGVS];
static const char *empty_string = ""; static const char *empty_string = "";
HWND hwnd_dialog; HWND hwnd_dialog;
int WINAPI static void
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, init_handles (HINSTANCE hInstance)
int nCmdShow)
{ {
double time, oldtime, newtime;
MEMORYSTATUS lpBuffer;
static char cwd[1024];
RECT rect; RECT rect;
// previous instances do not exist in Win32
if (hPrevInstance)
return 0;
startup ();
global_hInstance = hInstance;
global_nCmdShow = nCmdShow;
lpBuffer.dwLength = sizeof (MEMORYSTATUS);
GlobalMemoryStatus (&lpBuffer);
if (!GetCurrentDirectory (sizeof (cwd), cwd))
Sys_Error ("Couldn't determine current directory");
if (cwd[strlen (cwd) - 1] == '/')
cwd[strlen (cwd) - 1] = 0;
host_parms.argc = 1;
argv[0] = empty_string;
while (*lpCmdLine && (host_parms.argc < MAX_NUM_ARGVS)) {
while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
lpCmdLine++;
if (*lpCmdLine) {
argv[host_parms.argc] = lpCmdLine;
host_parms.argc++;
while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
lpCmdLine++;
if (*lpCmdLine) {
*lpCmdLine = 0;
lpCmdLine++;
}
}
}
COM_InitArgv (host_parms.argc, argv);
host_parms.argc = com_argc;
host_parms.argv = com_argv;
isDedicated = (COM_CheckParm ("-dedicated") != 0);
if (!isDedicated) { if (!isDedicated) {
hwnd_dialog = CreateDialog (hInstance, MAKEINTRESOURCE (IDD_DIALOG1), hwnd_dialog = CreateDialog (hInstance, MAKEINTRESOURCE (IDD_DIALOG1),
NULL, NULL); NULL, NULL);
@ -210,26 +156,68 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
if (!tevent) if (!tevent)
Sys_Error ("Couldn't create event"); Sys_Error ("Couldn't create event");
}
Host_Init (); int WINAPI
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
double time, oldtime, newtime;
MEMORYSTATUS lpBuffer;
int argc;
// previous instances do not exist in Win32
if (hPrevInstance)
return 0;
startup ();
global_hInstance = hInstance;
global_nCmdShow = nCmdShow;
lpBuffer.dwLength = sizeof (MEMORYSTATUS);
GlobalMemoryStatus (&lpBuffer);
argc = 1;
argv[0] = empty_string;
while (*lpCmdLine && (argc < MAX_NUM_ARGVS)) {
while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
lpCmdLine++;
if (*lpCmdLine) {
argv[argc] = lpCmdLine;
argc++;
while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
lpCmdLine++;
if (*lpCmdLine) {
*lpCmdLine = 0;
lpCmdLine++;
}
}
}
memset (&host_parms, 0, sizeof (host_parms));
COM_InitArgv (argc, argv);
host_parms.argc = com_argc;
host_parms.argv = com_argv;
isDedicated = (COM_CheckParm ("-dedicated") != 0);
if (!isDedicated)
init_handles (hInstance);
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown_f); Sys_RegisterShutdown (shutdown_f);
oldtime = Sys_DoubleTime (); Host_Init ();
// main window message loop oldtime = Sys_DoubleTime () - 0.1;
while (1) { while (1) { // Main message loop
if (isDedicated) { if (!isDedicated) {
newtime = Sys_DoubleTime ();
time = newtime - oldtime;
while (time < sys_ticrate->value) {
Sleep (1);
newtime = Sys_DoubleTime ();
time = newtime - oldtime;
}
} else {
// yield the CPU for a little while when paused, minimized, or // yield the CPU for a little while when paused, minimized, or
// not the focus // not the focus
if ((cl.paused && !ActiveApp) || Minimized) { if ((cl.paused && !ActiveApp) || Minimized) {
@ -238,15 +226,24 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
} else if (!ActiveApp) { } else if (!ActiveApp) {
SleepUntilInput (NOT_FOCUS_SLEEP); SleepUntilInput (NOT_FOCUS_SLEEP);
} }
}
// find time spent rendering last frame
newtime = Sys_DoubleTime ();
time = newtime - oldtime;
newtime = Sys_DoubleTime (); if (cls.state == ca_dedicated) { // play vcrfiles at max speed
time = newtime - oldtime; if (time < sys_ticrate->value && (!vcrFile || recording)) {
Sleep (1);
continue; // not time to run a server-only tic yet
}
time = sys_ticrate->value;
} }
Host_Frame (time); if (time > sys_ticrate->value * 2)
oldtime = newtime; oldtime = newtime;
} else
oldtime += time;
// return success of application Host_Frame (time);
return TRUE; }
} }

View file

@ -1,7 +1,7 @@
/* /*
sys_wind.c sys_wind.c
@description@ (description)
Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 1996-1997 Id Software, Inc.
@ -28,24 +28,18 @@
# include "config.h" # include "config.h"
#endif #endif
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] =
"$Id$"; "$Id$";
#include <sys/types.h> #include "winquake.h"
#include <sys/timeb.h>
#include <conio.h>
#include "QF/console.h"
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "game.h"
#include "host.h" #include "host.h"
#include "winquake.h"
qboolean isDedicated = true;
qboolean isDedicated = true;
static void static void
shutdown_f (void) shutdown_f (void)
@ -55,16 +49,11 @@ shutdown_f (void)
int int
main (int argc, const char **argv) main (int argc, const char **argv)
{ {
double time, oldtime; double time, oldtime, newtime;
int i; int i;
memset (&host_parms, 0, sizeof (host_parms)); memset (&host_parms, 0, sizeof (host_parms));
#if 0
_getcwd (cwd, sizeof (cwd));
if (cwd[Q_strlen (cwd) - 1] == '\\')
cwd[Q_strlen (cwd) - 1] = 0;
#endif
// dedicated server ONLY! // dedicated server ONLY!
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
if (!strcmp (argv[i], "-dedicated")) if (!strcmp (argv[i], "-dedicated"))
@ -72,8 +61,8 @@ main (int argc, const char **argv)
if (i == argc) { if (i == argc) {
const char **newargv; const char **newargv;
newargv = malloc ((argc + 2) * sizeof (*newargv)); newargv = malloc ((argc + 2) * sizeof (char *));
memcpy (newargv, argv, argc * 4); memcpy (newargv, argv, argc * sizeof (char *));
newargv[argc++] = "-dedicated"; newargv[argc++] = "-dedicated";
newargv[argc] = 0; newargv[argc] = 0;
argv = newargv; argv = newargv;
@ -88,20 +77,22 @@ main (int argc, const char **argv)
Host_Init (); Host_Init ();
oldtime = Sys_DoubleTime (); oldtime = Sys_DoubleTime () - 0.1;
while (1) { // Main message loop
/* main window message loop */ // find time spent rendering last frame
while (1) { newtime = Sys_DoubleTime ();
time = Sys_DoubleTime (); time = newtime - oldtime;
if (time - oldtime < sys_ticrate->value) { if (time < sys_ticrate->value) {
Sleep (1); Sleep (1);
continue; continue; // not time to run a server-only tic yet
} }
time = sys_ticrate->value;
Host_Frame (time - oldtime); if (time > sys_ticrate->value * 2)
oldtime = time; oldtime = newtime;
else
oldtime += time;
Host_Frame (time);
} }
/* return success of application */
return TRUE;
} }

View file

@ -47,11 +47,11 @@ static __attribute__ ((used)) const char rcsid[] =
# include <unistd.h> # include <unistd.h>
#endif #endif
#include <errno.h> #ifdef HAVE_FCNTL_H
#include <fcntl.h> # include <fcntl.h>
#include <limits.h> #else
#include <stdio.h> # include <sys/fcntl.h>
#include <stdlib.h> #endif
#ifndef _WIN32 #ifndef _WIN32
# include <signal.h> # include <signal.h>
@ -60,20 +60,18 @@ static __attribute__ ((used)) const char rcsid[] =
#include <SDL.h> #include <SDL.h>
#include <SDL_main.h> #include <SDL_main.h>
#include "QF/console.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "client.h"
#include "compat.h"
#include "host.h" #include "host.h"
#include "netchan.h"
int noconinput;
#ifdef _WIN32 #ifdef _WIN32
# include "winquake.h" # include "winquake.h"
#endif #endif
int qf_sdl_link;
static void static void
startup (void) startup (void)
{ {
@ -98,10 +96,12 @@ startup (void)
} }
static void static void
shutdown (void) shutdown_f (void)
{ {
#ifndef _WIN32 #ifndef _WIN32
// change stdin to blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
fflush (stdout);
#endif #endif
} }
@ -110,7 +110,7 @@ shutdown (void)
#endif #endif
int int
SDL_main (int c, char **v) SDL_main (int argc, const char **argv)
{ {
double time, oldtime, newtime; double time, oldtime, newtime;
@ -118,24 +118,21 @@ SDL_main (int c, char **v)
memset (&host_parms, 0, sizeof (host_parms)); memset (&host_parms, 0, sizeof (host_parms));
COM_InitArgv (c, (const char **)v); COM_InitArgv (argc, argv);
host_parms.argc = com_argc; host_parms.argc = com_argc;
host_parms.argv = com_argv; host_parms.argv = com_argv;
#ifndef _WIN32 if (!COM_CheckParm ("-noconinput"))
noconinput = COM_CheckParm ("-noconinput");
if (!noconinput)
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
#endif
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (Net_LogStop); Sys_RegisterShutdown (Net_LogStop);
Sys_RegisterShutdown (shutdown); Sys_RegisterShutdown (shutdown_f);
Host_Init (); Host_Init ();
oldtime = Sys_DoubleTime (); oldtime = Sys_DoubleTime ();
while (1) { while (1) { // Main message loop
// find time spent rendering last frame // find time spent rendering last frame
newtime = Sys_DoubleTime (); newtime = Sys_DoubleTime ();
time = newtime - oldtime; time = newtime - oldtime;
@ -143,5 +140,4 @@ SDL_main (int c, char **v)
Host_Frame (time); Host_Frame (time);
oldtime = newtime; oldtime = newtime;
} }
return 0; // shouldn't be reachable, but mingw gcc 3.1 is being weird
} }

View file

@ -29,7 +29,7 @@
# include "config.h" # include "config.h"
#endif #endif
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] =
"$Id$"; "$Id$";
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
@ -42,59 +42,48 @@ static __attribute__ ((used)) const char rcsid[] =
# include <unistd.h> # include <unistd.h>
#endif #endif
#include <ctype.h> #ifdef HAVE_FCNTL_H
#include <errno.h> # include <fcntl.h>
#include <fcntl.h> #else
#include <limits.h> # include <sys/fcntl.h>
#include <signal.h> #endif
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include "QF/console.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "host.h" #include "host.h"
#include "netchan.h" #include "netchan.h"
int noconinput = 0;
static void static void
shutdown (void) shutdown_f (void)
{ {
// change stdin to blocking // change stdin to blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
fflush (stdout);
} }
int skipframes;
int int
main (int c, const char *v[]) main (int argc, const char **argv)
{ {
// static char cwd[1024];
double time, oldtime, newtime; double time, oldtime, newtime;
memset (&host_parms, 0, sizeof (host_parms)); memset (&host_parms, 0, sizeof (host_parms));
COM_InitArgv (c, v); COM_InitArgv (argc, argv);
host_parms.argc = com_argc; host_parms.argc = com_argc;
host_parms.argv = com_argv; host_parms.argv = com_argv;
noconinput = COM_CheckParm ("-noconinput"); if (!COM_CheckParm ("-noconinput"))
if (!noconinput)
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (Net_LogStop); Sys_RegisterShutdown (Net_LogStop);
Sys_RegisterShutdown (shutdown); Sys_RegisterShutdown (shutdown_f);
Host_Init (); Host_Init ();
oldtime = Sys_DoubleTime (); oldtime = Sys_DoubleTime ();
while (1) { while (1) { // Main message loop
// find time spent rendering last frame // find time spent rendering last frame
newtime = Sys_DoubleTime (); newtime = Sys_DoubleTime ();
time = newtime - oldtime; time = newtime - oldtime;

View file

@ -28,33 +28,17 @@
# include "config.h" # include "config.h"
#endif #endif
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] =
"$Id$"; "$Id$";
#ifdef HAVE_CONIO_H
# include <conio.h>
#endif
#ifdef HAVE_IO_H
# include <io.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include "winquake.h" #include "winquake.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/screen.h" #include "QF/screen.h"
#include "QF/sound.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "QF/vid.h"
#include "client.h" #include "client.h"
#include "compat.h"
#include "host.h" #include "host.h"
#include "netchan.h"
#include "win32/resources/resource.h"
#define MAXIMUM_WIN_MEMORY 0x1000000 #define MAXIMUM_WIN_MEMORY 0x1000000
#define MINIMUM_WIN_MEMORY 0x0c00000 #define MINIMUM_WIN_MEMORY 0x0c00000
@ -112,7 +96,7 @@ startup (void)
} }
static void static void
shutdown (void) shutdown_f (void)
{ {
if (tevent) if (tevent)
CloseHandle (tevent); CloseHandle (tevent);
@ -129,18 +113,17 @@ SleepUntilInput (int time)
HINSTANCE global_hInstance; HINSTANCE global_hInstance;
int global_nCmdShow; int global_nCmdShow;
const char *argv[MAX_NUM_ARGVS];
static const char *empty_string = ""; static const char *empty_string = "";
int WINAPI int WINAPI
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow) int nCmdShow)
{ {
// MSG msg; int argc;
static char cwd[1024]; const char *argv[MAX_NUM_ARGVS];
double time, oldtime, newtime; double time, oldtime, newtime;
#ifdef SPLASH_SCREEN #ifdef SPLASH_SCREEN
RECT rect; RECT rect;
#endif #endif
// previous instances do not exist in Win32 // previous instances do not exist in Win32
@ -152,22 +135,16 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
global_hInstance = hInstance; global_hInstance = hInstance;
global_nCmdShow = nCmdShow; global_nCmdShow = nCmdShow;
if (!GetCurrentDirectory (sizeof (cwd), cwd)) argc = 1;
Sys_Error ("Couldn't determine current directory");
if (cwd[strlen (cwd) - 1] == '/')
cwd[strlen (cwd) - 1] = 0;
host_parms.argc = 1;
argv[0] = empty_string; argv[0] = empty_string;
while (*lpCmdLine && (host_parms.argc < MAX_NUM_ARGVS)) { while (*lpCmdLine && (argc < MAX_NUM_ARGVS)) {
while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126))) while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
lpCmdLine++; lpCmdLine++;
if (*lpCmdLine) { if (*lpCmdLine) {
argv[host_parms.argc] = lpCmdLine; argv[argc] = lpCmdLine;
host_parms.argc++; argc++;
while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126))) while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
lpCmdLine++; lpCmdLine++;
@ -179,7 +156,7 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
} }
} }
COM_InitArgv (host_parms.argc, argv); COM_InitArgv (argc, argv);
host_parms.argc = com_argc; host_parms.argc = com_argc;
host_parms.argv = com_argv; host_parms.argv = com_argv;
@ -207,17 +184,14 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
if (!tevent) if (!tevent)
Sys_Error ("Couldn't create event"); Sys_Error ("Couldn't create event");
Sys_Printf ("Host_Init\n");
Host_Init ();
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (Net_LogStop); Sys_RegisterShutdown (Net_LogStop);
Sys_RegisterShutdown (shutdown); Sys_RegisterShutdown (shutdown_f);
Host_Init ();
oldtime = Sys_DoubleTime (); oldtime = Sys_DoubleTime ();
while (1) { // Main message loop
// main window message loop
while (1) {
// yield CPU for a little bit when paused, minimized, or not the focus // yield CPU for a little bit when paused, minimized, or not the focus
if ((cl.paused && (!ActiveApp)) || Minimized) { if ((cl.paused && (!ActiveApp)) || Minimized) {
SleepUntilInput (PAUSE_SLEEP); SleepUntilInput (PAUSE_SLEEP);
@ -228,10 +202,8 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
newtime = Sys_DoubleTime (); newtime = Sys_DoubleTime ();
time = newtime - oldtime; time = newtime - oldtime;
Host_Frame (time); Host_Frame (time);
oldtime = newtime; oldtime = newtime;
} }
// return success of application
return TRUE;
} }

View file

@ -34,6 +34,6 @@
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] =
"$Id$"; "$Id$";
extern int noconinput; extern int qf_sdl_link;
static __attribute__ ((used)) int *const _noconinput = &noconinput; static __attribute__ ((used)) int *const _sdl_link = &qf_sdl_link;

View file

@ -29,7 +29,7 @@
# include "config.h" # include "config.h"
#endif #endif
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] =
"$Id$"; "$Id$";
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
@ -42,13 +42,6 @@ static __attribute__ ((used)) const char rcsid[] =
# include <unistd.h> # include <unistd.h>
#endif #endif
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/sys.h" #include "QF/sys.h"
@ -118,7 +111,7 @@ startup (void)
} }
int int
main (int argc, const char *argv[]) main (int argc, const char **argv)
{ {
double time, oldtime, newtime; double time, oldtime, newtime;
@ -137,9 +130,8 @@ main (int argc, const char *argv[])
// run one frame immediately for first heartbeat // run one frame immediately for first heartbeat
SV_Frame (0.1); SV_Frame (0.1);
// main loop
oldtime = Sys_DoubleTime () - 0.1; oldtime = Sys_DoubleTime () - 0.1;
while (1) { while (1) { // Main message loop
Sys_CheckInput (!svs.num_clients, net_socket); Sys_CheckInput (!svs.num_clients, net_socket);
// find time passed since last cycle // find time passed since last cycle
@ -154,5 +146,4 @@ main (int argc, const char *argv[])
if (sys_extrasleep->int_val) if (sys_extrasleep->int_val)
usleep (sys_extrasleep->int_val); usleep (sys_extrasleep->int_val);
} }
return 1;
} }

View file

@ -28,7 +28,7 @@
# include "config.h" # include "config.h"
#endif #endif
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] =
"$Id$"; "$Id$";
#include "winquake.h" #include "winquake.h"
@ -36,11 +36,9 @@ static __attribute__ ((used)) const char rcsid[] =
#include <winsock.h> #include <winsock.h>
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/info.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "compat.h"
#include "server.h" #include "server.h"
qboolean WinNT; qboolean WinNT;
@ -70,12 +68,10 @@ startup (void)
WinNT = false; WinNT = false;
} }
char *newargv[256];
int int
main (int argc, const char **argv) main (int argc, const char **argv)
{ {
double newtime, time, oldtime; double time, oldtime, newtime;
startup (); startup ();
@ -105,9 +101,8 @@ main (int argc, const char **argv)
// run one frame immediately for first heartbeat // run one frame immediately for first heartbeat
SV_Frame (0.1); SV_Frame (0.1);
// main loop
oldtime = Sys_DoubleTime () - 0.1; oldtime = Sys_DoubleTime () - 0.1;
while (1) { while (1) { // Main message loop
Sys_CheckInput (!svs.num_clients, net_socket); Sys_CheckInput (!svs.num_clients, net_socket);
// find time passed since last cycle // find time passed since last cycle
@ -117,6 +112,4 @@ main (int argc, const char **argv)
SV_Frame (time); SV_Frame (time);
} }
return true;
} }