mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
more sys cleanup. server consoles may be broken for non-curses.
This commit is contained in:
parent
0f94fd64e7
commit
4039452297
9 changed files with 131 additions and 313 deletions
|
@ -61,6 +61,7 @@ void Sys_Shutdown (void);
|
|||
void Sys_RegisterShutdown (void (*func) (void));
|
||||
double Sys_DoubleTime (void);
|
||||
|
||||
int Sys_CheckInput (int idle, int net_socket);
|
||||
const char *Sys_ConsoleInput (void);
|
||||
|
||||
void Sys_Sleep (void);
|
||||
|
|
150
libs/util/sys.c
150
libs/util/sys.c
|
@ -85,6 +85,9 @@ typedef struct shutdown_list_s {
|
|||
|
||||
static shutdown_list_t *shutdown_list;
|
||||
|
||||
static int do_stdin = 1;
|
||||
qboolean stdin_ready;
|
||||
|
||||
/* The translation table between the graphical font and plain ASCII --KB */
|
||||
const char sys_char_map[256] = {
|
||||
'\0', '#', '#', '#', '#', '.', '#', '#',
|
||||
|
@ -125,6 +128,33 @@ const char sys_char_map[256] = {
|
|||
#define MAXPRINTMSG 4096
|
||||
|
||||
|
||||
#ifndef USE_INTEL_ASM
|
||||
void
|
||||
Sys_HighFPPrecision (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Sys_LowFPPrecision (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Sys_SetFPCW (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Sys_PushFPCW_SetHigh (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Sys_PopFPCW (void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
Sys_mkdir (const char *path)
|
||||
{
|
||||
|
@ -430,29 +460,105 @@ Sys_DebugLog (const char *file, const char *fmt, ...)
|
|||
close (fd);
|
||||
}
|
||||
|
||||
#ifndef USE_INTEL_ASM
|
||||
void
|
||||
Sys_HighFPPrecision (void)
|
||||
int
|
||||
Sys_CheckInput (int idle, int net_socket)
|
||||
{
|
||||
}
|
||||
fd_set fdset;
|
||||
struct timeval _timeout;
|
||||
struct timeval *timeout = 0;
|
||||
|
||||
void
|
||||
Sys_LowFPPrecision (void)
|
||||
{
|
||||
}
|
||||
#ifdef _WIN32
|
||||
// Now we want to give some processing time to other applications,
|
||||
// such as qw_client, running on this machine.
|
||||
sleep_msec = sys_sleep->int_val;
|
||||
if (sleep_msec > 0) {
|
||||
if (sleep_msec > 13)
|
||||
sleep_msec = 13;
|
||||
Sleep (sleep_msec);
|
||||
}
|
||||
|
||||
void
|
||||
Sys_SetFPCW (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Sys_PushFPCW_SetHigh (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Sys_PopFPCW (void)
|
||||
{
|
||||
}
|
||||
_timeout.tv_sec = 0;
|
||||
_timeout.tv_usec = 100;
|
||||
#else
|
||||
_timeout.tv_sec = 0;
|
||||
_timeout.tv_usec = 10000;
|
||||
#endif
|
||||
// select on the net socket and stdin
|
||||
// the only reason we have a timeout at all is so that if the last
|
||||
// connected client times out, the message would not otherwise
|
||||
// be printed until the next event.
|
||||
FD_ZERO (&fdset);
|
||||
if (do_stdin)
|
||||
FD_SET (0, &fdset);
|
||||
FD_SET (net_socket, &fdset);
|
||||
|
||||
if (!idle || !sys_dead_sleep->int_val)
|
||||
timeout = &_timeout;
|
||||
|
||||
if (select (net_socket + 1, &fdset, NULL, NULL, timeout) == -1
|
||||
&& errno != EINTR)
|
||||
return 0;
|
||||
stdin_ready = FD_ISSET (0, &fdset);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Sys_ConsoleInput
|
||||
|
||||
Checks for a complete line of text typed in at the console, then forwards
|
||||
it to the host command processor
|
||||
*/
|
||||
const char *
|
||||
Sys_ConsoleInput (void)
|
||||
{
|
||||
static char text[256];
|
||||
int len;
|
||||
|
||||
#ifdef _WIN32
|
||||
int c;
|
||||
|
||||
// read a line out
|
||||
while (kbhit ()) {
|
||||
c = _getch ();
|
||||
putch (c);
|
||||
if (c == '\r') {
|
||||
text[len] = 0;
|
||||
putch ('\n');
|
||||
len = 0;
|
||||
return text;
|
||||
}
|
||||
if (c == 8) {
|
||||
if (len) {
|
||||
putch (' ');
|
||||
putch (c);
|
||||
len--;
|
||||
text[len] = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
text[len] = c;
|
||||
len++;
|
||||
text[len] = 0;
|
||||
if (len == sizeof (text))
|
||||
len = 0;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
#else
|
||||
if (!stdin_ready || !do_stdin)
|
||||
return NULL; // the select didn't say it was ready
|
||||
stdin_ready = false;
|
||||
|
||||
len = read (0, text, sizeof (text));
|
||||
if (len == 0) {
|
||||
// end of file
|
||||
do_stdin = 0;
|
||||
return NULL;
|
||||
}
|
||||
if (len < 1)
|
||||
return NULL;
|
||||
text[len - 1] = 0; // rip off the \n and terminate
|
||||
|
||||
return text;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -118,18 +118,6 @@ shutdown (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
Sys_ConsoleInput
|
||||
|
||||
Checks for a complete line of text typed in at the console, then forwards
|
||||
it to the host command processor
|
||||
*/
|
||||
const char *
|
||||
Sys_ConsoleInput (void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef SDL_main
|
||||
# define SDL_main main
|
||||
#endif
|
||||
|
|
|
@ -85,38 +85,6 @@ floating_point_exception_handler (int whatever)
|
|||
signal (SIGFPE, floating_point_exception_handler);
|
||||
}
|
||||
|
||||
/*
|
||||
Sys_ConsoleInput
|
||||
|
||||
Checks for a complete line of text typed in at the console, then forwards
|
||||
it to the host command processor
|
||||
*/
|
||||
const char *
|
||||
Sys_ConsoleInput (void)
|
||||
{
|
||||
static char text[256];
|
||||
int len;
|
||||
fd_set fdset;
|
||||
struct timeval timeout;
|
||||
|
||||
if (cls.state == ca_dedicated) {
|
||||
FD_ZERO (&fdset);
|
||||
FD_SET (0, &fdset); // stdin
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 0;
|
||||
if (select (1, &fdset, NULL, NULL, &timeout) == -1
|
||||
|| !FD_ISSET (0, &fdset)) return NULL;
|
||||
|
||||
len = read (0, text, sizeof (text));
|
||||
if (len < 1)
|
||||
return NULL;
|
||||
text[len - 1] = 0; // rip off the \n and terminate
|
||||
|
||||
return text;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main (int c, const char *v[])
|
||||
{
|
||||
|
|
|
@ -84,32 +84,6 @@ Sys_Init (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
const char *
|
||||
Sys_ConsoleInput (void)
|
||||
{
|
||||
static char text[256];
|
||||
int len;
|
||||
fd_set fdset;
|
||||
struct timeval timeout;
|
||||
|
||||
if (cls.state == ca_dedicated) {
|
||||
FD_ZERO (&fdset);
|
||||
FD_SET (0, &fdset); // stdin
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 0;
|
||||
if (select (1, &fdset, NULL, NULL, &timeout) == -1
|
||||
|| !FD_ISSET (0, &fdset)) return NULL;
|
||||
|
||||
len = read (0, text, sizeof (text));
|
||||
if (len < 1)
|
||||
return NULL;
|
||||
text[len - 1] = 0; // rip off the /n and terminate
|
||||
|
||||
return text;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, const char **argv)
|
||||
{
|
||||
|
|
|
@ -165,79 +165,6 @@ shutdown (void)
|
|||
DeinitConProc ();
|
||||
}
|
||||
|
||||
const char *
|
||||
Sys_ConsoleInput (void)
|
||||
{
|
||||
static char text[256];
|
||||
static int len;
|
||||
INPUT_RECORD recs[1024];
|
||||
DWORD dummy;
|
||||
int ch;
|
||||
DWORD numread;
|
||||
DWORD numevents;
|
||||
|
||||
if (!isDedicated)
|
||||
return NULL;
|
||||
|
||||
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 (len) {
|
||||
text[len] = 0;
|
||||
len = 0;
|
||||
return text;
|
||||
} else if (sc_return_on_enter) {
|
||||
// special case to allow exiting from the error
|
||||
// handler on Enter
|
||||
text[0] = '\r';
|
||||
len = 0;
|
||||
return text;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case '\b':
|
||||
WriteFile (houtput, "\b \b", 3, &dummy, NULL);
|
||||
if (len) {
|
||||
len--;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (ch >= ' ') {
|
||||
WriteFile (houtput, &ch, 1, &dummy, NULL);
|
||||
text[len] = ch;
|
||||
len = (len + 1) & 0xff;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// WINDOWS CRAP ===============================================================
|
||||
|
||||
void
|
||||
|
|
|
@ -47,40 +47,6 @@ static const char rcsid[] =
|
|||
|
||||
qboolean isDedicated = true;
|
||||
|
||||
const char *
|
||||
Sys_ConsoleInput (void)
|
||||
{
|
||||
static char text[256];
|
||||
static int len;
|
||||
int c;
|
||||
|
||||
// read a line out
|
||||
while (_kbhit ()) {
|
||||
c = _getch ();
|
||||
putch (c);
|
||||
if (c == '\r') {
|
||||
text[len] = 0;
|
||||
putch ('\n');
|
||||
len = 0;
|
||||
return text;
|
||||
}
|
||||
if (c == 8) {
|
||||
putch (' ');
|
||||
putch (c);
|
||||
len--;
|
||||
text[len] = 0;
|
||||
continue;
|
||||
}
|
||||
text[len] = c;
|
||||
len++;
|
||||
text[len] = 0;
|
||||
if (len == sizeof (text))
|
||||
len = 0;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
shutdown (void)
|
||||
{
|
||||
|
|
|
@ -59,7 +59,6 @@ static const char rcsid[] =
|
|||
#endif
|
||||
|
||||
qboolean is_server = true;
|
||||
qboolean stdin_ready;
|
||||
server_static_t svs;
|
||||
info_t **svs_info = &svs.info;
|
||||
|
||||
|
@ -122,42 +121,10 @@ Sys_Init (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static int do_stdin = 1;
|
||||
|
||||
/*
|
||||
Sys_ConsoleInput
|
||||
|
||||
Checks for a complete line of text typed in at the console, then forwards
|
||||
it to the host command processor
|
||||
*/
|
||||
const char *
|
||||
Sys_ConsoleInput (void)
|
||||
{
|
||||
static char text[256];
|
||||
int len;
|
||||
|
||||
if (!stdin_ready || !do_stdin)
|
||||
return NULL; // the select didn't say it was ready
|
||||
stdin_ready = false;
|
||||
|
||||
len = read (0, text, sizeof (text));
|
||||
if (len == 0) {
|
||||
// end of file
|
||||
do_stdin = 0;
|
||||
return NULL;
|
||||
}
|
||||
if (len < 1)
|
||||
return NULL;
|
||||
text[len - 1] = 0; // rip off the \n and terminate
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
{
|
||||
double time, oldtime, newtime;
|
||||
fd_set fdset;
|
||||
|
||||
memset (&host_parms, 0, sizeof (host_parms));
|
||||
|
||||
|
@ -175,26 +142,8 @@ main (int argc, const char *argv[])
|
|||
// main loop
|
||||
oldtime = Sys_DoubleTime () - 0.1;
|
||||
while (1) {
|
||||
struct timeval _timeout;
|
||||
struct timeval *timeout = 0;
|
||||
// select on the net socket and stdin
|
||||
// the only reason we have a timeout at all is so that if the last
|
||||
// connected client times out, the message would not otherwise
|
||||
// be printed until the next event.
|
||||
FD_ZERO (&fdset);
|
||||
if (do_stdin)
|
||||
FD_SET (0, &fdset);
|
||||
FD_SET (net_socket, &fdset);
|
||||
|
||||
_timeout.tv_sec = 0;
|
||||
_timeout.tv_usec = 10000;
|
||||
if (svs.num_clients || !sys_dead_sleep->int_val)
|
||||
timeout = &_timeout;
|
||||
|
||||
if (select (net_socket + 1, &fdset, NULL, NULL, timeout) == -1
|
||||
&& errno != EINTR)
|
||||
if (!Sys_CheckInput (!svs.num_clients, net_socket))
|
||||
continue;
|
||||
stdin_ready = FD_ISSET (0, &fdset);
|
||||
|
||||
// find time passed since last cycle
|
||||
newtime = Sys_DoubleTime ();
|
||||
|
|
|
@ -77,58 +77,13 @@ Sys_Init (void)
|
|||
WinNT = false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Sys_ConsoleInput
|
||||
|
||||
Checks for a complete line of text typed in at the console, then forwards
|
||||
it to the host command processor
|
||||
*/
|
||||
const char *
|
||||
Sys_ConsoleInput (void)
|
||||
{
|
||||
static char text[256];
|
||||
static int len;
|
||||
int c;
|
||||
|
||||
// read a line out
|
||||
while (kbhit ()) {
|
||||
c = _getch ();
|
||||
putch (c);
|
||||
if (c == '\r') {
|
||||
text[len] = 0;
|
||||
putch ('\n');
|
||||
len = 0;
|
||||
return text;
|
||||
}
|
||||
if (c == 8) {
|
||||
if (len) {
|
||||
putch (' ');
|
||||
putch (c);
|
||||
len--;
|
||||
text[len] = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
text[len] = c;
|
||||
len++;
|
||||
text[len] = 0;
|
||||
if (len == sizeof (text))
|
||||
len = 0;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *newargv[256];
|
||||
|
||||
int
|
||||
main (int argc, const char **argv)
|
||||
{
|
||||
double newtime, time, oldtime;
|
||||
fd_set fdset;
|
||||
int sleep_msec;
|
||||
struct timeval timeout;
|
||||
|
||||
COM_InitArgv (argc, argv);
|
||||
|
||||
|
@ -158,23 +113,7 @@ main (int argc, const char **argv)
|
|||
// main loop
|
||||
oldtime = Sys_DoubleTime () - 0.1;
|
||||
while (1) {
|
||||
// Now we want to give some processing time to other applications,
|
||||
// such as qw_client, running on this machine.
|
||||
sleep_msec = sys_sleep->int_val;
|
||||
if (sleep_msec > 0) {
|
||||
if (sleep_msec > 13)
|
||||
sleep_msec = 13;
|
||||
Sleep (sleep_msec);
|
||||
}
|
||||
// select on the net socket and stdin
|
||||
// the only reason we have a timeout at all is so that if the last
|
||||
// connected client times out, the message would not otherwise
|
||||
// be printed until the next event.
|
||||
FD_ZERO (&fdset);
|
||||
FD_SET (net_socket, &fdset);
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 100;
|
||||
if (select (net_socket + 1, &fdset, NULL, NULL, &timeout) == -1)
|
||||
if (!Sys_CheckInput (!svs.num_clients, net_socket))
|
||||
continue;
|
||||
|
||||
// find time passed since last cycle
|
||||
|
|
Loading…
Reference in a new issue