Skip to content

Commit

Permalink
Cleanup|Network: Client-specific code out of net_main.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 17, 2020
1 parent a5d3ced commit 1b32ca8
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 190 deletions.
5 changes: 0 additions & 5 deletions doomsday/apps/client/include/network/net_main.h
Expand Up @@ -166,11 +166,6 @@ void Net_Update(void);
void Net_ResetTimer(void);
void Net_Ticker(timespan_t time);

/**
* Does drawing for the engine's HUD, not just the net.
*/
void Net_Drawer(void);

dd_bool Net_IsLocalPlayer(int pNum);

#ifdef __cplusplus
Expand Down
5 changes: 5 additions & 0 deletions doomsday/apps/client/include/network/sys_network.h
Expand Up @@ -44,4 +44,9 @@ void N_Register(void);
void N_PrintInfo(void);
void N_PrintNetworkStatus(void);

/**
* Does drawing for the engine's HUD, not just the net.
*/
void Net_Drawer(void);

#endif // CLIENT_SYSTEM_NETWORK_H
183 changes: 3 additions & 180 deletions doomsday/apps/client/src/network/base/net_main.cpp
Expand Up @@ -572,179 +572,6 @@ void Net_WriteChatMessage(int from, int toMask, const char *message)
}

#ifdef __CLIENT__

/**
* Returns @c true if a demo is currently being recorded.
*/
static dd_bool recordingDemo()
{
for(int i = 0; i < DDMAXPLAYERS; ++i)
{
if(DD_Player(i)->publicData().inGame && DD_Player(i)->recording)
return true;
}
return false;
}

static void Net_DrawDemoOverlay()
{
const int x = DE_GAMEVIEW_WIDTH - 10;
const int y = 10;

if(!recordingDemo() || !(SECONDS_TO_TICKS(::gameTime) & 8))
return;

char buf[160];
strcpy(buf, "[");
{
int count = 0;
for(int i = 0; i < DDMAXPLAYERS; ++i)
{
auto *plr = DD_Player(i);
if(plr->publicData().inGame && plr->recording)
{
// This is a "real" player (or camera).
if(count++)
strcat(buf, ",");

char tmp[40]; sprintf(tmp, "%i:%s", i, plr->recordPaused ? "-P-" : "REC");
strcat(buf, tmp);
}
}
}
strcat(buf, "]");

DE_ASSERT_IN_MAIN_THREAD();
DE_ASSERT_GL_CONTEXT_ACTIVE();

// Go into screen projection mode.
DGL_MatrixMode(DGL_PROJECTION);
DGL_PushMatrix();
DGL_LoadIdentity();
DGL_Ortho(0, 0, DE_GAMEVIEW_WIDTH, DE_GAMEVIEW_HEIGHT, -1, 1);

DGL_Enable(DGL_TEXTURE_2D);

FR_SetFont(::fontFixed);
FR_LoadDefaultAttrib();
FR_SetColorAndAlpha(1, 1, 1, 1);
FR_DrawTextXY3(buf, x, y, ALIGN_TOPRIGHT, DTF_NO_EFFECTS);

DGL_Disable(DGL_TEXTURE_2D);

// Restore original matrix.
DGL_MatrixMode(DGL_PROJECTION);
DGL_PopMatrix();
}

void Net_Drawer()
{
// Draw the blockmap debug display.
Rend_BlockmapDebug();

// Draw the light range debug display.
Rend_DrawLightModMatrix();

# ifdef DE_DEBUG
// Draw the input debug display.
I_DebugDrawer();
# endif

// Draw the demo recording overlay.
Net_DrawDemoOverlay();

# if defined (DE_DEBUG) && defined (DE_OPENGL)
Z_DebugDrawer();
# endif
}

D_CMD(SetName)
{
DE_UNUSED(src, argc);

Con_SetString("net-name", argv[1]);

if(!netState.netGame) return true;

// The server does not have a name.
if(!netState.isClient) return false;

auto &cl = *DD_Player(::consolePlayer);
std::memset(cl.name, 0, sizeof(cl.name));
strncpy(cl.name, argv[1], PLAYERNAMELEN - 1);

Net_SendPlayerInfo(::consolePlayer, 0);
return true;
}

D_CMD(SetConsole)
{
DE_UNUSED(src, argc);

int cp = String(argv[1]).toInt();
if(cp < 0 || cp >= DDMAXPLAYERS)
{
LOG_SCR_ERROR("Invalid player #%i") << cp;
return false;
}

if(DD_Player(cp)->publicData().inGame)
{
::consolePlayer = ::displayPlayer = cp;
}

// Update the viewports.
R_SetViewGrid(0, 0);
return true;
}

int Net_StartConnection(const char *address, int port)
{
LOG_AS("Net_StartConnection");
LOG_NET_MSG("Connecting to %s (port %i)...") << address << port;

// Start searching at the specified location.
Net_ServerLink().connectDomain(Stringf("%s:%i", address, port), 7.0 /*timeout*/);
return true;
}

/**
* Intelligently connect to a server. Just provide an IP address and the rest is automatic.
*/
D_CMD(Connect)
{
DE_UNUSED(src);

if(argc < 2 || argc > 3)
{
LOG_SCR_NOTE("Usage: %s (ip-address) [port]") << argv[0];
LOG_SCR_MSG("A TCP/IP connection is created to the given server. If a port is not "
"specified port zero will be used");
return true;
}

if(netState.netGame)
{
LOG_NET_ERROR("Already connected");
return false;
}

// If there is a port specified in the address, use it.
int port = 0;
char *ptr;
if((ptr = strrchr(argv[1], ':')))
{
port = strtol(ptr + 1, 0, 0);
*ptr = 0;
}
if(argc == 3)
{
port = strtol(argv[2], 0, 0);
}

return Net_StartConnection(argv[1], port);
}

#endif // __CLIENT__

/**
Expand Down Expand Up @@ -1029,11 +856,11 @@ D_CMD(Ping); // net_ping.cpp
void Net_Register()
{
#ifdef DE_DEBUG
C_VAR_FLOAT ("net-dev-latency", &netState.simulatedLatencySeconds, CVF_NO_MAX, 0, 0);
C_VAR_FLOAT ("net-dev-latency", &netState.simulatedLatencySeconds, CVF_NO_MAX, 0, 0);
#endif

C_VAR_BYTE ("net-queue-show", &monitorMsgQueue, 0, 0, 1);
C_VAR_BYTE ("net-dev", &netDev, 0, 0, 1);
C_VAR_BYTE ("net-queue-show", &monitorMsgQueue, 0, 0, 1);
C_VAR_BYTE ("net-dev", &netDev, 0, 0, 1);

C_CMD_FLAGS ("chat", nullptr, Chat, CMDF_NO_NULLGAME);
C_CMD_FLAGS ("chatnum", nullptr, Chat, CMDF_NO_NULLGAME);
Expand All @@ -1047,10 +874,6 @@ void Net_Register()
C_CMD ("settics", "i", SetTicks);

#ifdef __CLIENT__
C_CMD_FLAGS ("connect", nullptr, Connect, CMDF_NO_NULLGAME | CMDF_NO_DEDICATED);
C_CMD ("setname", "s", SetName);
C_CMD ("setcon", "i", SetConsole);

N_Register();
#endif

Expand Down

0 comments on commit 1b32ca8

Please sign in to comment.