Skip to content

Commit

Permalink
Cleanup|Map|Client: Moved all client only methods of Map to map.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jan 10, 2014
1 parent fcfec83 commit 9c9edea
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 292 deletions.
20 changes: 11 additions & 9 deletions doomsday/client/src/client/cl_infine.cpp
Expand Up @@ -26,8 +26,10 @@
#include "network/net_main.h"
#include "network/net_msg.h"

static finaleid_t currentFinale = 0;
static finaleid_t remoteFinale = 0;
#include <de/memory.h>

static finaleid_t currentFinale;
static finaleid_t remoteFinale;

finaleid_t Cl_CurrentFinale()
{
Expand All @@ -36,19 +38,19 @@ finaleid_t Cl_CurrentFinale()

void Cl_Finale(Reader *msg)
{
int flags = Reader_ReadByte(msg);
LOG_AS("Cl_Finale");

byte *script = 0;
int len;
finaleid_t finaleId = Reader_ReadUInt32(msg);

LOG_AS("Cl_Finale");
int const flags = Reader_ReadByte(msg);
finaleid_t const finaleId = Reader_ReadUInt32(msg);

if(flags & FINF_SCRIPT)
{
// Read the script into map-scope memory. It will be freed
// when the next map is loaded.
len = Reader_ReadUInt32(msg);
script = (byte *) malloc(len + 1);
int len = Reader_ReadUInt32(msg);
script = (byte *) M_Malloc(len + 1);
Reader_Read(msg, script, len);
script[len] = 0;
}
Expand Down Expand Up @@ -76,7 +78,7 @@ void Cl_Finale(Reader *msg)
FI_ScriptRequestSkip(currentFinale);
}

if(script) free(script);
if(script) M_Free(script);
}

void Cl_RequestFinaleSkip()
Expand Down
97 changes: 41 additions & 56 deletions doomsday/client/src/client/cl_main.cpp
Expand Up @@ -37,18 +37,15 @@
using namespace de;

ident_t clientID;
boolean handshakeReceived = false;
int gameReady = false;
boolean handshakeReceived;
int gameReady;
int serverTime;
boolean netLoggedIn = false; // Logged in to the server.
int clientPaused = false; // Set by the server.
boolean netLoggedIn; // Logged in to the server.
int clientPaused; // Set by the server.

void Cl_InitID()
{
int i;
FILE *file;

if((i = CommandLine_CheckWith("-id", 1)) != 0)
if(int i = CommandLine_CheckWith("-id", 1))
{
clientID = strtoul(CommandLine_At(i + 1), 0, 0);
LOG_NET_NOTE("Using custom client ID: 0x%08x") << clientID;
Expand All @@ -57,7 +54,7 @@ void Cl_InitID()

// Read the client ID number file.
srand(time(NULL));
if((file = fopen("client.id", "rb")) != NULL)
if(FILE *file = fopen("client.id", "rb"))
{
if(fread(&clientID, sizeof(clientID), 1, file))
{
Expand All @@ -67,12 +64,14 @@ void Cl_InitID()
}
fclose(file);
}

// Ah-ha, we need to generate a new ID.
clientID = (ident_t)
ULONG(Timer_RealMilliseconds() * rand() + (rand() & 0xfff) +
((rand() & 0xfff) << 12) + ((rand() & 0xff) << 24));

// Write it to the file.
if((file = fopen("client.id", "wb")) != NULL)
if(FILE *file = fopen("client.id", "wb"))
{
fwrite(&clientID, sizeof(clientID), 1, file);
fclose(file);
Expand Down Expand Up @@ -121,16 +120,15 @@ void Cl_SendHello()
Net_SendBuffer(0, 0);
}

void Cl_AnswerHandshake(void)
void Cl_AnswerHandshake()
{
byte remoteVersion = Reader_ReadByte(msgReader);
byte myConsole = Reader_ReadByte(msgReader);
uint playersInGame = Reader_ReadUInt32(msgReader);
float remoteGameTime = Reader_ReadFloat(msgReader);
int i;

LOG_AS("Cl_AnswerHandshake");

byte remoteVersion = Reader_ReadByte(msgReader);
byte myConsole = Reader_ReadByte(msgReader);
uint playersInGame = Reader_ReadUInt32(msgReader);
float remoteGameTime = Reader_ReadFloat(msgReader);

// Immediately send an acknowledgement. This lets the server evaluate
// an approximate ping time.
Msg_Begin(PCL_ACK_SHAKE);
Expand All @@ -150,7 +148,7 @@ void Cl_AnswerHandshake(void)

// Update time and player ingame status.
gameTime = remoteGameTime;
for(i = 0; i < DDMAXPLAYERS; ++i)
for(int i = 0; i < DDMAXPLAYERS; ++i)
{
/// @todo With multiple local players, must clear only the appropriate flags.
ddPlayers[i].shared.flags &= ~DDPF_LOCAL;
Expand Down Expand Up @@ -184,7 +182,7 @@ void Cl_AnswerHandshake(void)
LOGDEV_NET_MSG("Answering handshake: myConsole:%i, remoteGameTime:%.2f")
<< myConsole << remoteGameTime;

/**
/*
* Tell the game that we have arrived. The map will be changed when the
* game's handshake arrives (handled in the game).
*/
Expand All @@ -200,16 +198,14 @@ void Cl_AnswerHandshake(void)
Con_Executef(CMDS_DDAY, true, "setcon %i", consolePlayer);
}

void Cl_HandlePlayerInfo(void)
void Cl_HandlePlayerInfo()
{
player_t* plr;
boolean present;
byte console = Reader_ReadByte(msgReader);
size_t len = Reader_ReadUInt16(msgReader);
char name[PLAYERNAMELEN];

size_t len = Reader_ReadUInt16(msgReader);
len = MIN_OF(PLAYERNAMELEN - 1, len);
memset(name, 0, sizeof(name));

char name[PLAYERNAMELEN]; zap(name);
Reader_Read(msgReader, name, len);

LOG_NET_VERBOSE("Player %i named \"%s\"") << console << name;
Expand All @@ -218,8 +214,8 @@ void Cl_HandlePlayerInfo(void)
if(console >= DDMAXPLAYERS)
return;

plr = &ddPlayers[console];
present = plr->shared.inGame;
player_t *plr = &ddPlayers[console];
bool present = plr->shared.inGame;
plr->shared.inGame = true;

strcpy(clients[console].name, name);
Expand Down Expand Up @@ -251,27 +247,20 @@ void Cl_GetPackets()
// a game is in progress.
if(Cl_GameReady())
{
boolean handled = true;

switch(netBuffer.msg.type)
{
case PSV_FIRST_FRAME2:
case PSV_FRAME2:
Cl_Frame2Received(netBuffer.msg.type);
break;
Msg_EndRead();
continue; // Get the next packet.

case PSV_SOUND:
Cl_Sound();
break;

default:
handled = false;
}

if(handled)
{
Msg_EndRead();
continue; // Get the next packet.

default: break;
}
}

Expand Down Expand Up @@ -323,8 +312,7 @@ void Cl_GetPackets()
Cl_PlayerLeaves(Reader_ReadByte(msgReader));
break;

case PKT_CHAT:
{
case PKT_CHAT: {
int msgfrom = Reader_ReadByte(msgReader);
int mask = Reader_ReadUInt32(msgReader);
DENG_UNUSED(mask);
Expand All @@ -335,25 +323,22 @@ void Cl_GetPackets()
Net_ShowChatMessage(msgfrom, msg);
gx.NetPlayerEvent(msgfrom, DDPE_CHAT_MESSAGE, msg);
M_Free(msg);
break;
}
break; }

case PSV_SERVER_CLOSE: // We should quit?
netLoggedIn = false;
Con_Execute(CMDS_DDAY, "net disconnect", true, false);
break;

case PSV_CONSOLE_TEXT:
{
case PSV_CONSOLE_TEXT: {
uint32_t conFlags = Reader_ReadUInt32(msgReader);
uint16_t textLen = Reader_ReadUInt16(msgReader);
char *text = (char *) M_Malloc(textLen + 1);
Reader_Read(msgReader, text, textLen);
text[textLen] = 0;
Con_FPrintf(conFlags, "%s", text);
M_Free(text);
break;
}
break; }

case PKT_LOGIN:
// Server responds to our login request. Let's see if we
Expand Down Expand Up @@ -385,11 +370,13 @@ void Cl_GetPackets()
* Check the state of the client on engineside. This is a debugging utility
* and only gets called when _DEBUG is defined.
*/
void Cl_Assertions(int plrNum)
static void assertPlayerIsValid(int plrNum)
{
player_t *plr;
mobj_t *clmo, *mo;
clplayerstate_t *s;
LOG_AS("Client.assertPlayerIsValid");

player_t *plr;
mobj_t *clmo, *mo;
clplayerstate_t *s;

if(!isClient || !Cl_GameReady() || clientPaused) return;
if(plrNum < 0 || plrNum >= DDMAXPLAYERS) return;
Expand All @@ -401,12 +388,10 @@ void Cl_Assertions(int plrNum)
if(!s->clMobjId || !plr->shared.mo)
return;

LOG_AS("Cl_Assertions");

clmo = ClMobj_Find(s->clMobjId);
if(!clmo)
{
LOGDEV_NET_NOTE("Client %i does not have a clmobj yet [%i]") << plrNum << s->clMobjId;
LOGDEV_NET_NOTE("Player %i does not have a clmobj yet [%i]") << plrNum << s->clMobjId;
return;
}
mo = plr->shared.mo;
Expand All @@ -418,11 +403,11 @@ void Cl_Assertions(int plrNum)
// Make sure the flags are correctly set for a client.
if(mo->ddFlags & DDMF_REMOTE)
{
LOGDEV_NET_NOTE("Client %i's mobj should not be remote") << plrNum;
LOGDEV_NET_NOTE("Player %i's mobj should not be remote") << plrNum;
}
if(clmo->ddFlags & DDMF_SOLID)
{
LOGDEV_NET_NOTE("Client %i's clmobj should not be solid (when player is alive)") << plrNum;
LOGDEV_NET_NOTE("Player %i's clmobj should not be solid (when player is alive)") << plrNum;
}
}

Expand Down Expand Up @@ -460,7 +445,7 @@ void Cl_Ticker(timespan_t ticLength)
ClPlayer_UpdateOrigin(i);

#ifdef DENG_DEBUG
Cl_Assertions(i);
assertPlayerIsValid(i);
#endif
}

Expand Down
16 changes: 7 additions & 9 deletions doomsday/client/src/client/cl_mobj.cpp
@@ -1,4 +1,4 @@
/** @file cl_mobj.cpp Client map objects.
/** @file cl_mobj.cpp Client map objects.
* @ingroup client
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
Expand All @@ -19,13 +19,11 @@
* 02110-1301 USA</small>
*/

#include <math.h>

#define DENG_NO_API_MACROS_CLIENT

#include <de/vector1.h>

#include "de_base.h"
#include "client/cl_mobj.h"

#include "de_defs.h"
#include "de_system.h"
#include "de_console.h"
Expand All @@ -34,6 +32,8 @@
#include "de_audio.h"

#include "world/thinkers.h"
#include <de/vector1.h>
#include <cmath>

using namespace de;

Expand All @@ -50,8 +50,6 @@ using namespace de;
/// allow the missile to move free of the shooter. (Quite a hack!)
#define MISSILE_FREE_MOVE_TIME 1000

extern int gotFrame; ///< @todo Remove this...

/**
* @return Pointer to the hash chain with the specified id.
*/
Expand All @@ -67,8 +65,8 @@ static cmhash_t *ClMobj_Hash(thid_t id)
return Map_ClMobjHash(App_World().map(), id);
}

#ifdef _DEBUG
void checkMobjHash()
#ifdef DENG_DEBUG
static void checkMobjHash()
{
Map &map = App_World().map();
for(int i = 0; i < CLIENT_MOBJ_HASH_SIZE; ++i)
Expand Down

0 comments on commit 9c9edea

Please sign in to comment.