Reorganize files for platform-specific code:

* sys_sdl_win.c: Copied from sys_sdl.c. Windows-only. Remove unix code.
(Sys_Init): New procedure. Call AllocConsole() and get input and output
handles for dedicated servers.
(Sys_ConsoleInput): Add a windows version.
(Sys_Error): Adjust for the allocated console and use windows api.
Adjust message output. Remove the console timeout, doesn't work somehow.
Just display the console for 3 seconds and then exit. Rely on SDL that
it redirects/logs the stdout/stderr to files.
* sys_sdl_unix.c: Rename from sys_sdl.c. Unix-only. Remove windows code.
(Sys_Init): New procedure.
(Sys_Error): Remove Windows-oriented dedicated server specific code.
Adjust message output.
* sys_sdl.c: Delete.
* sys.h (Sys_Init): Add prototype.
* main_sdl.c (main): Call Sys_Init().
* pl_linux.c (PL_ErrorDialog): Remove terminal printing which Sys_Error
already does.
* pl_osx.m (PL_ErrorDialog): Update from uhexen2.
* pl_win.c: Make icon handle static. whitespace and formatting tidy-up.
* Makefile, Makefile.darwin, Makefile.w32, Makefile.w64: Adjust for the
sys_sdl.c name change to sys_sdl_unix.c and sys_sdl_win.c.


git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@223 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2010-06-22 11:01:24 +00:00
parent fa6bc1ca0d
commit b65383bf2d
11 changed files with 405 additions and 108 deletions

View File

@ -142,7 +142,7 @@ SYSOBJ_NET := net_sdl.o net_sdlnet.o
else
SYSOBJ_NET := net_bsd.o net_udp.o
endif
SYSOBJ_SYS := pl_linux.o sys_sdl.o
SYSOBJ_SYS := pl_linux.o sys_sdl_unix.o
SYSOBJ_MAIN:= main_sdl.o
SYSOBJ_RES :=

View File

@ -150,7 +150,7 @@ SYSOBJ_NET := net_sdl.o net_sdlnet.o
else
SYSOBJ_NET := net_bsd.o net_udp.o
endif
SYSOBJ_SYS := pl_osx.o sys_sdl.o
SYSOBJ_SYS := pl_osx.o sys_sdl_unix.o
SYSOBJ_MAIN:= main_sdl.o
SYSOBJ_RES :=

View File

@ -107,7 +107,7 @@ SYSOBJ_NET := net_sdl.o net_sdlnet.o
else
SYSOBJ_NET := net_win.o net_wins.o net_wipx.o
endif
SYSOBJ_SYS := pl_win.o sys_sdl.o
SYSOBJ_SYS := pl_win.o sys_sdl_win.o
SYSOBJ_MAIN:= main_sdl.o
SYSOBJ_RES := QuakeSpasm.res

View File

@ -107,7 +107,7 @@ SYSOBJ_NET := net_sdl.o net_sdlnet.o
else
SYSOBJ_NET := net_win.o net_wins.o net_wipx.o
endif
SYSOBJ_SYS := pl_win.o sys_sdl.o
SYSOBJ_SYS := pl_win.o sys_sdl_win.o
SYSOBJ_MAIN:= main_sdl.o
SYSOBJ_RES := QuakeSpasm.res

View File

@ -43,6 +43,8 @@ int main(int argc, char *argv[])
isDedicated = (COM_CheckParm("-dedicated") != 0);
Sys_Init();
// default memory size
parms.memsize = DEFAULT_MEMORY;

View File

@ -48,10 +48,9 @@ void PL_VID_Shutdown (void)
{
}
void PL_ErrorDialog(const char *text)
void PL_ErrorDialog (const char *errorMsg)
{
// TODO: we can dlopen gtk for an error
// dialog window. would it be worth it?
fprintf(stderr, "%s\n", text);
}

View File

@ -33,9 +33,10 @@ void PL_VID_Shutdown (void)
{
}
void PL_ErrorDialog(const char *text)
void PL_ErrorDialog(const char *errorMsg)
{
NSString *msg = [NSString stringWithCString:text encoding:NSASCIIStringEncoding];
NSRunAlertPanel(nil, msg, nil, nil, nil);
NSRunCriticalAlertPanel(@"Quake Error",
[NSString stringWithUTF8String:errorMsg],
@"OK", nil, nil);
}

View File

@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "SDL.h"
#include "SDL_syswm.h"
HICON icon;
static HICON icon;
void PL_SetWindowIcon (void)
{
@ -37,12 +37,12 @@ void PL_SetWindowIcon (void)
icon = LoadIcon(handle, "icon");
if (!icon)
return; // no icon in executable
return; /* no icon in the exe */
SDL_VERSION(&wminfo.version);
if (SDL_GetWMInfo(&wminfo) != 1)
return; // wrong SDL version
return; /* wrong SDL version */
hwnd = wminfo.window;
#ifdef _WIN64
@ -57,8 +57,9 @@ void PL_VID_Shutdown (void)
DestroyIcon(icon);
}
void PL_ErrorDialog(const char *text)
void PL_ErrorDialog(const char *errorMsg)
{
MessageBox(NULL, text, "Quake Error", MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
MessageBox (NULL, errorMsg, "Quake Error",
MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
}

View File

@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// sys.h -- non-portable functions
void Sys_Init (void);
//
// file IO
//

View File

@ -23,36 +23,31 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h"
#include <sys/types.h>
#ifdef _WIN32
#include <io.h>
#include <direct.h>
#include <errno.h>
#else
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <time.h>
#endif
#include "SDL.h"
#define CONSOLE_ERROR_TIMEOUT 60.0 /* # of seconds to wait on Sys_Error running */
qboolean isDedicated;
static qboolean sc_return_on_enter = false;
#define MAX_HANDLES 32 /* johnfitz -- was 10 */
FILE *sys_handles[MAX_HANDLES];
static FILE *sys_handles[MAX_HANDLES];
int findhandle (void)
static int findhandle (void)
{
int i;
for (i=1 ; i<MAX_HANDLES ; i++)
for (i = 1; i < MAX_HANDLES; i++)
{
if (!sys_handles[i])
return i;
}
Sys_Error ("out of handles");
return -1;
}
@ -144,80 +139,38 @@ int Sys_FileTime (char *path)
return -1;
}
void Sys_Init (void)
{
}
void Sys_mkdir (char *path)
{
#ifdef _WIN32
int rc = _mkdir (path);
#else
int rc = mkdir (path, 0777);
#endif
if (rc != 0 && errno != EEXIST)
Sys_Error("Unable to create directory %s", path);
}
static const char errortxt1[] = "\nERROR-OUT BEGIN\n\n";
static const char errortxt2[] = "\nQUAKE ERROR: ";
void Sys_Error (const char *error, ...)
{
va_list argptr;
char text[1024], text2[1024];
const char text3[] = "Press Enter to exit\n";
const char text4[] = "***********************************\n";
const char text5[] = "\n";
double starttime;
static int in_sys_error1 = 0;
static int in_sys_error2 = 0;
static int in_sys_error3 = 0;
char text[1024];
if (!in_sys_error3)
{
in_sys_error3 = 1;
}
fputs (errortxt1, stderr);
Host_Shutdown ();
//TODO: use OS messagebox here if possible
// (windows, os x and linux shouldn't be a problem)
//implement this in pl_*, which contains all the
// platform dependent code
va_start (argptr, error);
vsprintf (text, error, argptr);
va_end (argptr);
if (isDedicated)
{
sprintf (text2, "ERROR: %s\n", text);
printf ("%s", text5);
printf ("%s", text4);
printf ("%s", text2);
printf ("%s", text3);
printf ("%s", text4);
starttime = Sys_FloatTime ();
sc_return_on_enter = true; // so Enter will get us out of here
while (!Sys_ConsoleInput () &&
((Sys_FloatTime () - starttime) < CONSOLE_ERROR_TIMEOUT))
{
}
if (!in_sys_error1)
{
in_sys_error1 = 1;
Host_Shutdown ();
}
}
else
{
fputs (errortxt2, stderr);
fputs (text, stderr);
fputs ("\n\n", stderr);
if (!isDedicated)
PL_ErrorDialog(text);
}
// shut down QHOST hooks if necessary
if (!in_sys_error2)
{
in_sys_error2 = 1;
// DeinitConProc ();
}
exit (1);
}
@ -226,25 +179,15 @@ void Sys_Printf (const char *fmt, ...)
{
va_list argptr;
// always print to the console
// if (isDedicated)
// {
va_start(argptr, fmt);
vprintf(fmt, argptr);
va_end(argptr);
// }
}
void Sys_Quit (void)
{
Host_Shutdown();
// if (isDedicated)
// FreeConsole ();
// shut down QHOST hooks if necessary
// DeinitConProc ();
exit (0);
}
@ -255,7 +198,6 @@ double Sys_FloatTime (void)
char *Sys_ConsoleInput (void)
{
#if !defined(_WIN32)
static char con_text[256];
static int textlen;
char c;
@ -301,7 +243,6 @@ char *Sys_ConsoleInput (void)
break;
}
}
#endif /* ! _WIN32 */
return NULL;
}

351
Quake/sys_sdl_win.c Normal file
View File

@ -0,0 +1,351 @@
/*
Copyright (C) 1996-2001 Id Software, Inc.
Copyright (C) 2002-2005 John Fitzgibbons and others
Copyright (C) 2007-2008 Kristian Duske
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.
*/
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include "quakedef.h"
#include <sys/types.h>
#include <errno.h>
#include <io.h>
#include <direct.h>
#include "SDL.h"
qboolean isDedicated;
static HANDLE hinput, houtput;
#define MAX_HANDLES 32 /* johnfitz -- was 10 */
static FILE *sys_handles[MAX_HANDLES];
static int findhandle (void)
{
int i;
for (i = 1; i < MAX_HANDLES; i++)
{
if (!sys_handles[i])
return i;
}
Sys_Error ("out of handles");
return -1;
}
int Sys_filelength (FILE *f)
{
int pos;
int end;
pos = ftell (f);
fseek (f, 0, SEEK_END);
end = ftell (f);
fseek (f, pos, SEEK_SET);
return end;
}
int Sys_FileOpenRead (char *path, int *hndl)
{
FILE *f;
int i, retval;
i = findhandle ();
f = fopen(path, "rb");
if (!f)
{
*hndl = -1;
retval = -1;
}
else
{
sys_handles[i] = f;
*hndl = i;
retval = Sys_filelength(f);
}
return retval;
}
int Sys_FileOpenWrite (char *path)
{
FILE *f;
int i;
i = findhandle ();
f = fopen(path, "wb");
if (!f)
Sys_Error ("Error opening %s: %s", path, strerror(errno));
sys_handles[i] = f;
return i;
}
void Sys_FileClose (int handle)
{
fclose (sys_handles[handle]);
sys_handles[handle] = NULL;
}
void Sys_FileSeek (int handle, int position)
{
fseek (sys_handles[handle], position, SEEK_SET);
}
int Sys_FileRead (int handle, void *dest, int count)
{
return fread (dest, 1, count, sys_handles[handle]);
}
int Sys_FileWrite (int handle, void *data, int count)
{
return fwrite (data, 1, count, sys_handles[handle]);
}
int Sys_FileTime (char *path)
{
FILE *f;
f = fopen(path, "rb");
if (f)
{
fclose(f);
return 1;
}
return -1;
}
void Sys_Init (void)
{
if (isDedicated)
{
if (!AllocConsole ())
{
isDedicated = false; /* so that we have a graphical error dialog */
Sys_Error ("Couldn't create dedicated server console");
}
hinput = GetStdHandle (STD_INPUT_HANDLE);
houtput = GetStdHandle (STD_OUTPUT_HANDLE);
}
}
void Sys_mkdir (char *path)
{
int rc = _mkdir (path);
if (rc != 0 && errno != EEXIST)
Sys_Error("Unable to create directory %s", path);
}
static const char errortxt1[] = "\nERROR-OUT BEGIN\n\n";
static const char errortxt2[] = "\nQUAKE ERROR: ";
void Sys_Error (const char *error, ...)
{
va_list argptr;
char text[1024];
DWORD dummy;
va_start (argptr, error);
vsprintf (text, error, argptr);
va_end (argptr);
if (isDedicated)
WriteFile (houtput, errortxt1, strlen(errortxt1), &dummy, NULL);
/* SDL will put these into its own stderr log,
so print to stderr even in graphical mode. */
fputs (errortxt1, stderr);
Host_Shutdown ();
fputs (errortxt2, stderr);
fputs (text, stderr);
fputs ("\n\n", stderr);
if (!isDedicated)
PL_ErrorDialog(text);
else
{
WriteFile (houtput, errortxt2, strlen(errortxt2), &dummy, NULL);
WriteFile (houtput, text, strlen(text), &dummy, NULL);
WriteFile (houtput, "\r\n", 2, &dummy, NULL);
SDL_Delay (3000); /* show the console 3 more seconds */
}
// shut down QHOST hooks if necessary
// DeinitConProc ();
exit (1);
}
void Sys_Printf (const char *fmt, ...)
{
va_list argptr;
char text[1024];
DWORD dummy;
va_start (argptr,fmt);
vsprintf (text, fmt, argptr);
va_end (argptr);
if (isDedicated)
{
WriteFile(houtput, text, strlen(text), &dummy, NULL);
}
else
{
/* SDL will put these into its own stdout log,
so print to stdout even in graphical mode. */
fputs (text, stdout);
}
}
void Sys_Quit (void)
{
Host_Shutdown();
if (isDedicated)
FreeConsole ();
exit (0);
}
double Sys_FloatTime (void)
{
return SDL_GetTicks() / 1000.0;
}
char *Sys_ConsoleInput (void)
{
static char con_text[256];
static int textlen;
INPUT_RECORD recs[1024];
int ch;
DWORD dummy, numread, numevents;
if (!isDedicated)
return NULL; // no stdin necessary in graphical mode
for ( ;; )
{
if (!GetNumberOfConsoleInputEvents (hinput, &numevents))
Sys_Error ("Error getting # of console events");
if (numevents <= 0)
break;
if (!ReadConsoleInput(hinput, recs, 1, &numread))
Sys_Error ("Error reading console input");
if (numread != 1)
Sys_Error ("Couldn't read console input");
if (recs[0].EventType == KEY_EVENT)
{
if (!recs[0].Event.KeyEvent.bKeyDown)
{
ch = recs[0].Event.KeyEvent.uChar.AsciiChar;
switch (ch)
{
case '\r':
WriteFile(houtput, "\r\n", 2, &dummy, NULL);
if (textlen)
{
con_text[textlen] = 0;
textlen = 0;
return con_text;
}
break;
case '\b':
WriteFile(houtput, "\b \b", 3, &dummy, NULL);
if (textlen)
{
textlen--;
}
break;
default:
if (ch >= ' ')
{
WriteFile(houtput, &ch, 1, &dummy, NULL);
con_text[textlen] = ch;
textlen = (textlen + 1) & 0xff;
}
break;
}
}
}
}
return NULL;
}
void Sys_Sleep (void)
{
}
void Sys_SendKeyEvents (void)
{
SDL_Event event;
SDL_PumpEvents();
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
case SDL_KEYUP:
Key_Event(Key_Map(&(event.key)), event.key.type == SDL_KEYDOWN);
return;
case SDL_QUIT:
Sys_Quit();
break;
default:
SDL_PumpEvents();
break;
}
}
}
void Sys_LowFPPrecision (void)
{
}
void Sys_HighFPPrecision (void)
{
}
void Sys_SetFPCW (void)
{
}