- route the StartScreen#::Net... functions through a global interface.

These will require different treatment later, so best only have one place where each method is called.
This commit is contained in:
Christoph Oelckers 2022-05-18 21:20:41 +02:00
parent 21c60c931e
commit d6886ed44f
9 changed files with 73 additions and 86 deletions

View file

@ -294,7 +294,7 @@ void PacketGet (void)
if (StartScreen != NULL) if (StartScreen != NULL)
{ {
StartScreen->NetMessage ("The connection from %s was dropped.\n", I_NetMessage ("The connection from %s was dropped.\n",
GetPlayerName(node).GetChars()); GetPlayerName(node).GetChars());
} }
else else
@ -511,7 +511,7 @@ static void SendConAck (int num_connected, int num_needed)
{ {
PreSend (&packet, 4, &sendaddress[node]); PreSend (&packet, 4, &sendaddress[node]);
} }
StartScreen->NetProgress (doomcom.numnodes); I_NetProgress (doomcom.numnodes);
} }
bool Host_CheckForConnects (void *userdata) bool Host_CheckForConnects (void *userdata)
@ -536,7 +536,7 @@ bool Host_CheckForConnects (void *userdata)
if (node == -1) if (node == -1)
{ {
const uint8_t *s_addr_bytes = (const uint8_t *)&from->sin_addr; const uint8_t *s_addr_bytes = (const uint8_t *)&from->sin_addr;
StartScreen->NetMessage ("Got extra connect from %d.%d.%d.%d:%d", I_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], s_addr_bytes[0], s_addr_bytes[1], s_addr_bytes[2], s_addr_bytes[3],
from->sin_port); from->sin_port);
packet.Message = PRE_ALLFULL; packet.Message = PRE_ALLFULL;
@ -549,7 +549,7 @@ bool Host_CheckForConnects (void *userdata)
{ {
node = doomcom.numnodes++; node = doomcom.numnodes++;
sendaddress[node] = *from; sendaddress[node] = *from;
StartScreen->NetMessage ("Got connect from node %d.", node); I_NetMessage ("Got connect from node %d.", node);
} }
// Let the new guest (and everyone else) know we got their message. // Let the new guest (and everyone else) know we got their message.
@ -561,7 +561,7 @@ bool Host_CheckForConnects (void *userdata)
node = FindNode (from); node = FindNode (from);
if (node >= 0) if (node >= 0)
{ {
StartScreen->NetMessage ("Got disconnect from node %d.", node); I_NetMessage ("Got disconnect from node %d.", node);
doomcom.numnodes--; doomcom.numnodes--;
while (node < doomcom.numnodes) while (node < doomcom.numnodes)
{ {
@ -708,10 +708,10 @@ bool HostGame (int i)
doomcom.numnodes = 1; doomcom.numnodes = 1;
StartScreen->NetInit ("Waiting for players", numplayers); I_NetInit ("Waiting for players", numplayers);
// Wait for numplayers-1 different connections // Wait for numplayers-1 different connections
if (!StartScreen->NetLoop (Host_CheckForConnects, (void *)(intptr_t)numplayers)) if (!I_NetLoop (Host_CheckForConnects, (void *)(intptr_t)numplayers))
{ {
SendAbort(); SendAbort();
return false; return false;
@ -719,17 +719,17 @@ bool HostGame (int i)
// Now inform everyone of all machines involved in the game // Now inform everyone of all machines involved in the game
memset (gotack, 0, sizeof(gotack)); memset (gotack, 0, sizeof(gotack));
StartScreen->NetMessage ("Sending all here."); I_NetMessage ("Sending all here.");
StartScreen->NetInit ("Done waiting", 1); I_NetInit ("Done waiting", 1);
if (!StartScreen->NetLoop (Host_SendAllHere, (void *)gotack)) if (!I_NetLoop (Host_SendAllHere, (void *)gotack))
{ {
SendAbort(); SendAbort();
return false; return false;
} }
// Now go // Now go
StartScreen->NetMessage ("Go"); I_NetMessage ("Go");
packet.Fake = PRE_FAKE; packet.Fake = PRE_FAKE;
packet.Message = PRE_GO; packet.Message = PRE_GO;
for (node = 1; node < doomcom.numnodes; node++) for (node = 1; node < doomcom.numnodes; node++)
@ -742,7 +742,7 @@ bool HostGame (int i)
} }
} }
StartScreen->NetMessage ("Total players: %d", doomcom.numnodes); I_NetMessage ("Total players: %d", doomcom.numnodes);
doomcom.id = DOOMCOM_ID; doomcom.id = DOOMCOM_ID;
doomcom.numplayers = doomcom.numnodes; doomcom.numplayers = doomcom.numnodes;
@ -776,9 +776,9 @@ bool Guest_ContactHost (void *userdata)
{ {
if (packet.Message == PRE_CONACK) if (packet.Message == PRE_CONACK)
{ {
StartScreen->NetMessage ("Total players: %d", packet.NumNodes); I_NetMessage ("Total players: %d", packet.NumNodes);
StartScreen->NetInit ("Waiting for other players", packet.NumNodes); I_NetInit ("Waiting for other players", packet.NumNodes);
StartScreen->NetProgress (packet.NumPresent); I_NetProgress (packet.NumPresent);
return true; return true;
} }
else if (packet.Message == PRE_DISCONNECT) else if (packet.Message == PRE_DISCONNECT)
@ -795,7 +795,7 @@ bool Guest_ContactHost (void *userdata)
} }
// In case the progress bar could not be marqueed, bump it. // In case the progress bar could not be marqueed, bump it.
StartScreen->NetProgress (0); I_NetProgress (0);
return false; return false;
} }
@ -814,7 +814,7 @@ bool Guest_WaitForOthers (void *userdata)
switch (packet.Message) switch (packet.Message)
{ {
case PRE_CONACK: case PRE_CONACK:
StartScreen->NetProgress (packet.NumPresent); I_NetProgress (packet.NumPresent);
break; break;
case PRE_ALLHERE: case PRE_ALLHERE:
@ -825,7 +825,7 @@ bool Guest_WaitForOthers (void *userdata)
doomcom.numnodes = packet.NumNodes + 2; doomcom.numnodes = packet.NumNodes + 2;
sendplayer[0] = packet.ConsoleNum; // My player number sendplayer[0] = packet.ConsoleNum; // My player number
doomcom.consoleplayer = packet.ConsoleNum; doomcom.consoleplayer = packet.ConsoleNum;
StartScreen->NetMessage ("Console player number: %d", doomcom.consoleplayer); I_NetMessage ("Console player number: %d", doomcom.consoleplayer);
for (node = 0; node < packet.NumNodes; node++) for (node = 0; node < packet.NumNodes; node++)
{ {
sendaddress[node+2].sin_addr.s_addr = packet.machines[node].address; sendaddress[node+2].sin_addr.s_addr = packet.machines[node].address;
@ -839,14 +839,14 @@ bool Guest_WaitForOthers (void *userdata)
} }
} }
StartScreen->NetMessage ("Received All Here, sending ACK."); I_NetMessage ("Received All Here, sending ACK.");
packet.Fake = PRE_FAKE; packet.Fake = PRE_FAKE;
packet.Message = PRE_ALLHEREACK; packet.Message = PRE_ALLHEREACK;
PreSend (&packet, 2, &sendaddress[1]); PreSend (&packet, 2, &sendaddress[1]);
break; break;
case PRE_GO: case PRE_GO:
StartScreen->NetMessage ("Received \"Go.\""); I_NetMessage ("Received \"Go.\"");
return true; return true;
case PRE_DISCONNECT: case PRE_DISCONNECT:
@ -878,22 +878,22 @@ bool JoinGame (int i)
// Let host know we are here // Let host know we are here
StartScreen->NetInit ("Contacting host", 0); I_NetInit ("Contacting host", 0);
if (!StartScreen->NetLoop (Guest_ContactHost, NULL)) if (!I_NetLoop (Guest_ContactHost, NULL))
{ {
SendAbort(); SendAbort();
return false; return false;
} }
// Wait for everyone else to connect // Wait for everyone else to connect
if (!StartScreen->NetLoop (Guest_WaitForOthers, 0)) if (!I_NetLoop (Guest_WaitForOthers, 0))
{ {
SendAbort(); SendAbort();
return false; return false;
} }
StartScreen->NetMessage ("Total players: %d", doomcom.numnodes); I_NetMessage ("Total players: %d", doomcom.numnodes);
doomcom.id = DOOMCOM_ID; doomcom.id = DOOMCOM_ID;
doomcom.numplayers = doomcom.numnodes; doomcom.numplayers = doomcom.numnodes;
@ -1026,6 +1026,43 @@ void I_NetCmd (void)
I_Error ("Bad net cmd: %i\n",doomcom.command); I_Error ("Bad net cmd: %i\n",doomcom.command);
} }
void I_NetMessage(const char* text, ...)
{
// todo: use better abstraction once everything is migrated to in-game start screens.
#if defined _WIN32 || defined __APPLE__
va_list ap;
va_start(ap, text);
VPrintf(PRINT_HIGH, text, ap);
Printf("\n");
va_end(ap);
#else
FString str;
va_list argptr;
va_start(argptr, format);
str.VFormat(format, argptr);
va_end(argptr);
fprintf(stderr, "\r%-40s\n", str.GetChars());
#endif
}
// todo: later these must be dispatched by the main menu, not the start screen.
void I_NetProgress(int val)
{
StartScreen->NetProgress(val);
}
void I_NetInit(const char* msg, int num)
{
StartScreen->NetInit(msg, num);
}
bool I_NetLoop(bool (*timer_callback)(void*), void* userdata)
{
return StartScreen->NetLoop(timer_callback, userdata);
}
void I_NetDone()
{
StartScreen->NetDone();
}
#ifdef __WIN32__ #ifdef __WIN32__
const char *neterror (void) const char *neterror (void)
{ {

View file

@ -6,6 +6,11 @@
// Called by D_DoomMain. // Called by D_DoomMain.
int I_InitNetwork (void); int I_InitNetwork (void);
void I_NetCmd (void); void I_NetCmd (void);
void I_NetMessage(const char*, ...);
void I_NetProgress(int val);
void I_NetInit(const char* msg, int num);
bool I_NetLoop(bool (*timer_callback)(void*), void* userdata);
void I_NetDone();
enum ENetConstants enum ENetConstants
{ {

View file

@ -54,7 +54,6 @@ public:
virtual void NetInit(const char *message, int num_players) {} virtual void NetInit(const char *message, int num_players) {}
virtual void NetProgress(int count) {} virtual void NetProgress(int count) {}
virtual void NetMessage(const char *format, ...) {} // cover for printf
virtual void NetDone() {} virtual void NetDone() {}
virtual bool NetLoop(bool (*timer_callback)(void *), void *userdata) { return false; } virtual bool NetLoop(bool (*timer_callback)(void *), void *userdata) { return false; }
virtual void AppendStatusLine(const char* status) {} virtual void AppendStatusLine(const char* status) {}

View file

@ -121,18 +121,6 @@ void FBasicStartupScreen::NetProgress(const int count)
FConsoleWindow::GetInstance().NetProgress(count); FConsoleWindow::GetInstance().NetProgress(count);
} }
void FBasicStartupScreen::NetMessage(const char* const format, ...)
{
va_list args;
va_start(args, format);
FString message;
message.VFormat(format, args);
va_end(args);
Printf("%s\n", message.GetChars());
}
void FBasicStartupScreen::NetDone() void FBasicStartupScreen::NetDone()
{ {
FConsoleWindow::GetInstance().NetDone(); FConsoleWindow::GetInstance().NetDone();

View file

@ -56,7 +56,6 @@ class FTTYStartupScreen : public FStartupScreen
void Progress(); void Progress();
void NetInit(const char *message, int num_players); void NetInit(const char *message, int num_players);
void NetProgress(int count); void NetProgress(int count);
void NetMessage(const char *format, ...); // cover for printf
void NetDone(); void NetDone();
bool NetLoop(bool (*timer_callback)(void *), void *userdata); bool NetLoop(bool (*timer_callback)(void *), void *userdata);
protected: protected:
@ -214,27 +213,6 @@ void FTTYStartupScreen::NetDone()
} }
} }
//===========================================================================
//
// FTTYStartupScreen :: NetMessage
//
// Call this between NetInit() and NetDone() instead of Printf() to
// display messages, because the progress meter is mixed in the same output
// stream as normal messages.
//
//===========================================================================
void FTTYStartupScreen::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());
}
//=========================================================================== //===========================================================================
// //
// FTTYStartupScreen :: NetProgress // FTTYStartupScreen :: NetProgress

View file

@ -9,6 +9,7 @@
#include "version.h" #include "version.h"
#include "utf8.h" #include "utf8.h"
#include "v_font.h" #include "v_font.h"
#include "i_net.h"
#include <richedit.h> #include <richedit.h>
#include <shellapi.h> #include <shellapi.h>
#include <commctrl.h> #include <commctrl.h>
@ -151,7 +152,7 @@ void MainWindow::ShowErrorPane(const char* text)
if (StartScreen != NULL) // Ensure that the network pane is hidden. if (StartScreen != NULL) // Ensure that the network pane is hidden.
{ {
StartScreen->NetDone(); I_NetDone();
} }
if (text != NULL) if (text != NULL)
{ {

View file

@ -217,27 +217,6 @@ void FBasicStartupScreen::NetDone()
mainwindow.HideNetStartPane(); mainwindow.HideNetStartPane();
} }
//==========================================================================
//
// FBasicStartupScreen :: NetMessage
//
// Call this between NetInit() and NetDone() instead of Printf() to
// display messages, in case the progress meter is mixed in the same output
// stream as normal messages.
//
//==========================================================================
void FBasicStartupScreen::NetMessage(const char *format, ...)
{
FString str;
va_list argptr;
va_start (argptr, format);
str.VFormat (format, argptr);
va_end (argptr);
Printf ("%s\n", str.GetChars());
}
//========================================================================== //==========================================================================
// //
// FBasicStartupScreen :: NetProgress // FBasicStartupScreen :: NetProgress

View file

@ -103,7 +103,7 @@ FGenericStartScreen::FGenericStartScreen(int max_progress)
bool FGenericStartScreen::DoProgress(int advance) bool FGenericStartScreen::DoProgress(int advance)
{ {
int notch_pos, x, y; int notch_pos;
if (CurPos < MaxPos) if (CurPos < MaxPos)
{ {

View file

@ -1452,7 +1452,7 @@ bool DoArbitrate (void *userdata)
data->playersdetected[0] |= 1 << netbuffer[1]; data->playersdetected[0] |= 1 << netbuffer[1];
StartScreen->NetMessage ("Found %s (node %d, player %d)", I_NetMessage ("Found %s (node %d, player %d)",
players[netbuffer[1]].userinfo.GetName(), players[netbuffer[1]].userinfo.GetName(),
node, netbuffer[1]+1); node, netbuffer[1]+1);
} }
@ -1600,8 +1600,8 @@ bool D_ArbitrateNetStart (void)
data.gotsetup[0] = 0x80; data.gotsetup[0] = 0x80;
} }
StartScreen->NetInit ("Exchanging game information", 1); I_NetInit ("Exchanging game information", 1);
if (!StartScreen->NetLoop (DoArbitrate, &data)) if (!I_NetLoop (DoArbitrate, &data))
{ {
return false; return false;
} }
@ -1619,7 +1619,7 @@ bool D_ArbitrateNetStart (void)
fprintf (debugfile, "player %d is on node %d\n", i, nodeforplayer[i]); fprintf (debugfile, "player %d is on node %d\n", i, nodeforplayer[i]);
} }
} }
StartScreen->NetDone(); I_NetDone();
return true; return true;
} }