From 4899fa91f14ca7accd6040461d73f70000349552 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 29 Dec 2006 01:48:47 +0000 Subject: [PATCH] - Fixed the new network status display for the Linux terminal. SVN r428 (trunk) --- docs/rh-log.txt | 3 ++ src/d_net.cpp | 2 +- src/doomtype.h | 2 + src/i_net.cpp | 37 +++++++-------- src/m_random.cpp | 2 +- src/sdl/sdlvideo.cpp | 2 +- src/sdl/st_start.cpp | 110 ++++++++++++++++++++++++++----------------- src/st_start.h | 3 +- 8 files changed, 95 insertions(+), 66 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 4cd3327cb..64aab70ea 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,6 @@ +December 28, 2006 +- Fixed the new network status display for the Linux terminal. + December 25, 2006 (Changes by Graf Zahl) - Converted the Communicator to DECORATE. - Renamed the new armor properties to use the same names as Skulltag to avoid diff --git a/src/d_net.cpp b/src/d_net.cpp index a6e0a8d87..452b37abc 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -1356,7 +1356,7 @@ bool DoArbitrate (void *userdata) D_ReadUserInfoStrings (netbuffer[1], &stream, false); - Printf ("Found %s (node %d, player %d)\n", + ST_NetMessage ("Found %s (node %d, player %d)", players[netbuffer[1]].userinfo.netname, node, netbuffer[1]+1); } diff --git a/src/doomtype.h b/src/doomtype.h index ed2315267..8f397b4f3 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -70,6 +70,8 @@ #define NOVTABLE #endif +typedef long long __int64; + #ifdef _MSC_VER typedef __int8 SBYTE; typedef unsigned __int8 BYTE; diff --git a/src/i_net.cpp b/src/i_net.cpp index 2c3b1216a..ecbf66d62 100644 --- a/src/i_net.cpp +++ b/src/i_net.cpp @@ -224,7 +224,7 @@ void PacketGet (void) if (err == WSAECONNRESET) { // The remote node aborted unexpectedly, so pretend it sent an exit packet - Printf (PRINT_BOLD, "The connection from %s was dropped\n", + ST_NetMessage ("The connection from %s was dropped.\n", players[sendplayer[node]].userinfo.netname); doomcom.data[0] = 0x80; // NCMD_EXIT @@ -309,7 +309,7 @@ void BuildAddress (sockaddr_in *address, char *name) if (!isnamed) { address->sin_addr.s_addr = inet_addr (name); - Printf ("Node number, %d address %s\n", doomcom.numnodes, name); + Printf ("Node number %d, address %s\n", doomcom.numnodes, name); } else { @@ -317,7 +317,7 @@ void BuildAddress (sockaddr_in *address, char *name) if (!hostentry) I_FatalError ("gethostbyname: couldn't find %s\n%s", name, neterror()); address->sin_addr.s_addr = *(int *)hostentry->h_addr_list[0]; - Printf ("Node number %d hostname %s\n", + Printf ("Node number %d, hostname %s\n", doomcom.numnodes, hostentry->h_name); } @@ -425,11 +425,9 @@ bool Host_CheckForConnects (void *userdata) { if (node == -1) { - Printf ("Got extra connect from %d.%d.%d.%d:%d\n", - from->sin_addr.S_un.S_un_b.s_b1, - from->sin_addr.S_un.S_un_b.s_b2, - from->sin_addr.S_un.S_un_b.s_b3, - from->sin_addr.S_un.S_un_b.s_b4, + const BYTE *s_addr_bytes = (const BYTE *)&from->sin_addr; + ST_NetMessage ("Got extra connect from %d.%d.%d.%d:%d", + s_addr_bytes[0], s_addr_bytes[1], s_addr_bytes[2], s_addr_bytes[3], from->sin_port); packet.Message = PRE_ALLFULL; PreSend (&packet, 2, from); @@ -441,8 +439,8 @@ bool Host_CheckForConnects (void *userdata) { node = doomcom.numnodes++; sendaddress[node] = *from; + ST_NetMessage ("Got connect from node %d.", node); } - Printf ("Got connect from node %d\n", node); // Let the new guest (and everyone else) know we got their message. SendConAck (doomcom.numnodes, numplayers); @@ -453,7 +451,7 @@ bool Host_CheckForConnects (void *userdata) node = FindNode (from); if (node >= 0) { - Printf ("Got disconnect from node %d\n", node); + ST_NetMessage ("Got disconnect from node %d.", node); doomcom.numnodes--; while (node < doomcom.numnodes) { @@ -589,7 +587,6 @@ void HostGame (int i) Printf ("Console player number: %d\n", doomcom.consoleplayer); doomcom.numnodes = 1; - Printf ("Waiting for players...\n"); atterm (SendAbort); @@ -603,7 +600,7 @@ void HostGame (int i) // Now inform everyone of all machines involved in the game memset (gotack, 0, sizeof(gotack)); - Printf ("Sending all here\n"); + ST_NetMessage ("Sending all here."); ST_NetInit ("Done waiting", 1); if (!ST_NetLoop (Host_SendAllHere, (void *)gotack)) @@ -614,7 +611,7 @@ void HostGame (int i) popterm (); // Now go - Printf ("Go\n"); + ST_NetMessage ("Go"); packet.Fake = PRE_FAKE; packet.Message = PRE_GO; for (node = 1; node < doomcom.numnodes; node++) @@ -627,7 +624,7 @@ void HostGame (int i) } } - Printf ("Total players: %d\n", doomcom.numnodes); + ST_NetMessage ("Total players: %d", doomcom.numnodes); doomcom.id = DOOMCOM_ID; doomcom.numplayers = doomcom.numnodes; @@ -660,7 +657,7 @@ bool Guest_ContactHost (void *userdata) { if (packet.Message == PRE_CONACK) { - Printf ("Total players: %d\n", packet.NumNodes); + ST_NetMessage ("Total players: %d", packet.NumNodes); ST_NetInit ("Waiting for other players", packet.NumNodes); ST_NetProgress (packet.NumPresent); return true; @@ -670,7 +667,7 @@ bool Guest_ContactHost (void *userdata) doomcom.numnodes = 0; I_FatalError ("The host cancelled the game."); } - else if (packet.Message = PRE_ALLFULL) + else if (packet.Message == PRE_ALLFULL) { doomcom.numnodes = 0; I_FatalError ("The game is full."); @@ -710,7 +707,7 @@ bool Guest_WaitForOthers (void *userdata) doomcom.numnodes = packet.NumNodes + 2; sendplayer[0] = packet.ConsoleNum; // My player number doomcom.consoleplayer = packet.ConsoleNum; - Printf ("Console player number: %d\n", doomcom.consoleplayer); + ST_NetMessage ("Console player number: %d", doomcom.consoleplayer); for (node = 0; node < packet.NumNodes; node++) { sendaddress[node+2].sin_addr.s_addr = packet.machines[node].address; @@ -724,14 +721,14 @@ bool Guest_WaitForOthers (void *userdata) } } - Printf ("Received All Here, sending ACK\n"); + ST_NetMessage ("Received All Here, sending ACK."); packet.Fake = PRE_FAKE; packet.Message = PRE_ALLHEREACK; PreSend (&packet, 2, &sendaddress[1]); break; case PRE_GO: - Printf ("Go\n"); + ST_NetMessage ("Received \"Go.\""); return true; case PRE_DISCONNECT: @@ -775,7 +772,7 @@ void JoinGame (int i) popterm (); - Printf ("Total players: %d\n", doomcom.numnodes); + ST_NetMessage ("Total players: %d", doomcom.numnodes); doomcom.id = DOOMCOM_ID; doomcom.numplayers = doomcom.numnodes; diff --git a/src/m_random.cpp b/src/m_random.cpp index 3ebcd2dd7..7583faabd 100644 --- a/src/m_random.cpp +++ b/src/m_random.cpp @@ -304,7 +304,7 @@ void FRandom::StaticPrintSeeds () while (rng != NULL) { - Printf ("%s: %08lx\n", rng->Name, rng->Seed); + Printf ("%s: %08x\n", rng->Name, rng->Seed); rng = rng->Next; } } diff --git a/src/sdl/sdlvideo.cpp b/src/sdl/sdlvideo.cpp index af636cf5c..60f27a8ad 100644 --- a/src/sdl/sdlvideo.cpp +++ b/src/sdl/sdlvideo.cpp @@ -60,7 +60,7 @@ private: SDLFB () {} }; -IMPLEMENT_CLASS(SDLFB, DFrameBuffer) +IMPLEMENT_CLASS(SDLFB) struct MiniModeInfo { diff --git a/src/sdl/st_start.cpp b/src/sdl/st_start.cpp index 2975cb105..c8cc85cd4 100644 --- a/src/sdl/st_start.cpp +++ b/src/sdl/st_start.cpp @@ -38,12 +38,14 @@ #include #include "st_start.h" -#include "doomdef.h" +#include "doomdef.h" +#include "i_system.h" -termios OldTermIOS; -bool DidNetInit; -int NetProgressMax, NetProgressTicker; -char SpinnyProgressChars[8] = { '|', '/', '-', '\\', '|', '/', '-', '\\' }; +static termios OldTermIOS; +static bool DidNetInit; +static int NetProgressMax, NetProgressTicker; +static const char *NetMessage; +static char SpinnyProgressChars[8] = { '|', '/', '-', '\\', '|', '/', '-', '\\' }; void ST_Init(int maxProgress) { @@ -58,41 +60,62 @@ void ST_Progress() } void ST_NetInit(const char *message, int numplayers) -{ - if (DidNetInit) - { - if (numplayers == 1) - { - // Status message without any real progress info. - printf ("\n%s.", message); - } - else - { - printf ("\n%s: ", message); - } - } - else - { +{ + if (!DidNetInit) + { termios rawtermios; - printf ("Press 'Q' to abort network game synchronization.\n%s: ", message); + fprintf (stderr, "Press 'Q' to abort network game synchronization."); // Set stdin to raw mode so we can get keypresses in ST_CheckNetAbort() // immediately without waiting for an EOL. tcgetattr (STDIN_FILENO, &OldTermIOS); - rawtermios = OldTermIOS; - tcsetattr (STDIN_FILENO, &rawtermios); + rawtermios = OldTermIOS; + rawtermios.c_lflag &= ~(ICANON | ECHO); + tcsetattr (STDIN_FILENO, TCSANOW, &rawtermios); + DidNetInit = true; + atterm (ST_NetDone); + } + if (numplayers == 1) + { + // Status message without any real progress info. + fprintf (stderr, "\n%s.", message); } + else + { + fprintf (stderr, "\n%s: ", message); + } + fflush (stderr); + NetMessage = message; NetProgressMax = numplayers; NetProgressTicker = 0; - ST_NetProgress(); // You always know about yourself + ST_NetProgress(1); // You always know about yourself } void ST_NetDone() { - // Restore stdin settings - tcsetattr (STDIN_FILENO, &OldTermIOS); - printf ("\n"); + // Restore stdin settings + if (DidNetInit) + { + tcsetattr (STDIN_FILENO, TCSANOW, &OldTermIOS); + printf ("\n"); + DidNetInit = false; + } } + +void ST_NetMessage(const char *format, ...) +{ + FString str; + va_list argptr; + + va_start (argptr, format); + str.VFormat (format, argptr); + va_end (argptr); + fprintf (stderr, "\r%-40s\n", str.GetChars()); + if (NetMessage == 0) + { + NetMessage = 0; + } +} void ST_NetProgress(int count) { @@ -102,24 +125,26 @@ void ST_NetProgress(int count) { NetProgressTicker++; } - else + else if (count > 0) { NetProgressTicker = count; } if (NetProgressMax == 0) { - // Spinny-type progress meter, because we're a guest. - printf ("%c\b", SpinnyProgressChars[NetProgressTicker & 7]); + // Spinny-type progress meter, because we're a guest waiting for the host. + fprintf (stderr, "\r%s: %c", NetMessage, SpinnyProgressChars[NetProgressTicker & 7]); + fflush (stderr); } else if (NetProgressMax > 1) { - // Dotty-type progress meter, because we're a host. - printf (".%*c[%2d/%2d]", MAXPLAYERS + 1 - NetProgressTicker, NetProgressMax); - printf ("\b\b\b\b\b\b\b"); - for (i = NetProgressTicker; i < MAXPLAYERS + 1; ++i) - { - printf ("\b"); - } + // Dotty-type progress meter. + fprintf (stderr, "\r%s: ", NetMessage); + for (i = 0; i < NetProgressTicker; ++i) + { + fputc ('.', stderr); + } + fprintf (stderr, "%*c[%2d/%2d]", NetProgressMax + 1 - NetProgressTicker, ' ', NetProgressTicker, NetProgressMax); + fflush (stderr); } } @@ -130,15 +155,15 @@ bool ST_NetLoop(bool (*timer_callback)(void *), void *userdata) int retval; char k; - FD_ZERO (&rfds); - FD_SET (STDIN_FILENO, &rfds); - for (;;) { // Don't flood the network with packets on startup. tv.tv_sec = 0; tv.tv_usec = 500000; + FD_ZERO (&rfds); + FD_SET (STDIN_FILENO, &rfds); + retval = select (1, &rfds, NULL, NULL, &tv); if (retval == -1) @@ -148,7 +173,8 @@ bool ST_NetLoop(bool (*timer_callback)(void *), void *userdata) else if (retval == 0) { if (timer_callback (userdata)) - { + { + fputc ('\n', stderr); return true; } } @@ -157,7 +183,7 @@ bool ST_NetLoop(bool (*timer_callback)(void *), void *userdata) // Check input on stdin if (k == 'q' || k == 'Q') { - fprintf (stderr, "Network game synchronization aborted."); + fprintf (stderr, "\nNetwork game synchronization aborted."); return false; } } diff --git a/src/st_start.h b/src/st_start.h index 782f658ef..eb8bd7834 100644 --- a/src/st_start.h +++ b/src/st_start.h @@ -38,6 +38,7 @@ extern void ST_Init(int maxProgress); extern void ST_Done(); extern void ST_Progress(); extern void ST_NetInit(const char *message, int numplayers); -extern void ST_NetProgress(int count); +extern void ST_NetProgress(int count); +extern void ST_NetMessage(const char *format, ...); // cover for printf() extern void ST_NetDone(); extern bool ST_NetLoop(bool (*timer_callback)(void *), void *userdata);