Create a proper ca_active state.

Yay, no more ugly "SIGNONS" hack for whether to render :)
This commit is contained in:
Bill Currie 2012-05-23 21:38:25 +09:00
parent 7d84800250
commit 82a41017ec
10 changed files with 64 additions and 46 deletions

View file

@ -61,12 +61,17 @@ typedef struct
int _colors;
} scoreboard_t;
#define NAME_LENGTH 64
// client_state_t should hold all pieces of the client state
#define SIGNONS 4 // signon messages to receive before connected
typedef enum {
so_none,
so_prespawn,
so_spawn,
so_begin,
so_active,
} signon_t;
#define MAX_DEMOS 8
#define MAX_DEMONAME 16
@ -75,7 +80,8 @@ typedef struct
typedef enum {
ca_dedicated, // a dedicated server with no ability to start a client
ca_disconnected, // full screen console with no connection
ca_connected // valid netcon, talking to a server
ca_connected, // valid netcon, talking to a server
ca_active, // fully connected
} cactive_t;
typedef enum {
@ -86,9 +92,6 @@ typedef enum {
dl_single
} dltype_t; // download type
// FIXME: A grotesque (temporary) hack. They're not the same thing to QW.
#define ca_active ca_connected
/*
the client_static_t structure is persistant through an arbitrary number
of server connections
@ -126,7 +129,7 @@ typedef struct
float td_starttime; // realtime at second frame of timedemo
// connection information
int signon; // 0 to SIGNONS
signon_t signon;
struct qsocket_s *netcon;
sizebuf_t message; // writing buffer to send to server
} client_static_t;

View file

@ -51,7 +51,7 @@
void
CL_Cmd_ForwardToServer (void)
{
if (cls.state != ca_connected) {
if (cls.state < ca_connected) {
Sys_Printf ("Can't \"%s\", not connected\n", Cmd_Argv (0));
return;
}

View file

@ -155,7 +155,7 @@ CL_GetDemoMessage (void)
float f;
// decide if it is time to grab the next message
if (cls.signon == SIGNONS) { // always grab until fully connected
if (cls.state == ca_active) { // always grab until fully connected
if (cls.timedemo) {
if (host_framecount == cls.td_lastframe)
return 0; // already read this frame's message
@ -280,7 +280,7 @@ CL_Record_f (void)
return;
}
if (c == 2 && cls.state == ca_connected) {
if (c == 2 && cls.state >= ca_connected) {
Sys_Printf
("Can not record - already connected to server\nClient demo recording must be started before connecting\n");
return;

View file

@ -476,7 +476,7 @@ CL_AdjustAngles (void)
void
CL_BaseMove (usercmd_t *cmd)
{
if (cls.signon != SIGNONS)
if (cls.state != ca_active)
return;
CL_AdjustAngles ();

View file

@ -254,7 +254,7 @@ CL_Disconnect (void)
// if running a local server, shut it down
if (cls.demoplayback)
CL_StopPlayback ();
else if (cls.state == ca_connected) {
else if (cls.state >= ca_connected) {
if (cls.demorecording)
CL_StopRecording ();
@ -270,7 +270,6 @@ CL_Disconnect (void)
Host_ShutdownServer (false);
}
cls.signon = 0;
cl.worldmodel = NULL;
}
@ -306,8 +305,6 @@ CL_EstablishConnection (const char *host)
cls.demonum = -1; // not in the demo loop now
CL_SetState (ca_connected);
cls.signon = 0; // need all the signon messages
// before playing
Key_SetKeyDest (key_game);
}
@ -324,12 +321,14 @@ CL_SignonReply (void)
Sys_MaskPrintf (SYS_DEV, "CL_SignonReply: %i\n", cls.signon);
switch (cls.signon) {
case 1:
case so_none:
break;
case so_prespawn:
MSG_WriteByte (&cls.message, clc_stringcmd);
MSG_WriteString (&cls.message, "prespawn");
break;
case 2:
case so_spawn:
MSG_WriteByte (&cls.message, clc_stringcmd);
MSG_WriteString (&cls.message, va ("name \"%s\"\n", cl_name->string));
MSG_WriteByte (&cls.message, clc_stringcmd);
@ -341,14 +340,15 @@ CL_SignonReply (void)
MSG_WriteString (&cls.message, str);
break;
case 3:
case so_begin:
MSG_WriteByte (&cls.message, clc_stringcmd);
MSG_WriteString (&cls.message, "begin");
Cache_Report (); // print remaining memory
break;
case 4:
case so_active:
cl.loading = false;
CL_SetState (ca_active);
break;
}
}
@ -420,7 +420,7 @@ CL_ReadFromServer (void)
cl.last_received_message = realtime;
CL_ParseServerMessage ();
} while (ret && cls.state == ca_connected);
} while (ret && cls.state >= ca_connected);
if (cl_shownet->int_val)
Sys_Printf ("\n");
@ -437,10 +437,10 @@ CL_SendCmd (void)
{
usercmd_t cmd;
if (cls.state != ca_connected)
if (cls.state < ca_connected)
return;
if (cls.signon == SIGNONS) {
if (cls.state == ca_active) {
CL_BaseMove (&cmd);
// send the unreliable message
@ -472,21 +472,35 @@ CL_SetState (cactive_t state)
{
cactive_t old_state = cls.state;
cls.state = state;
Sys_MaskPrintf (SYS_NET, "CL_SetState: %d -> %d\n", old_state, state);
if (old_state != state) {
if (state == ca_active) {
if (old_state == ca_active) {
// leaving active state
Key_SetKeyDest (key_console);
S_AmbientOff ();
}
switch (state) {
case ca_dedicated:
break;
case ca_disconnected:
cls.signon = so_none;
VID_SetCaption ("Disconnected");
break;
case ca_connected:
cls.signon = so_none; // need all the signon messages
// before playing
Key_SetKeyDest (key_game);
IN_ClearStates ();
VID_SetCaption ("Connected");
break;
case ca_active:
// entering active state
Key_SetKeyDest (key_game);
IN_ClearStates ();
VID_SetCaption ("");
} else if (old_state == ca_active) {
// leaving active state
Key_SetKeyDest (key_console);
VID_SetCaption ("Disconnected");
}
if (state == ca_connected)
S_AmbientOn ();
else
S_AmbientOff ();
break;
}
}
if (con_module)
con_module->data->console->force_commandline = (state != ca_active);

View file

@ -462,9 +462,9 @@ CL_ParseUpdate (int bits)
model_t *model;
qboolean forcelink;
if (cls.signon == SIGNONS - 1) {
if (cls.signon == so_begin) {
// first update is the final signon stage
cls.signon = SIGNONS;
cls.signon = so_active;
CL_SignonReply ();
}
@ -868,6 +868,7 @@ void
CL_ParseServerMessage (void)
{
int cmd = 0, i, j;
signon_t so;
const char *str;
// if recording demos, copy the message out
@ -1054,11 +1055,11 @@ CL_ParseServerMessage (void)
break;
case svc_signonnum:
i = MSG_ReadByte (net_message);
if (i <= cls.signon)
Host_Error ("Received signon %i when at %i", i,
so = MSG_ReadByte (net_message);
if (so <= cls.signon || so >= so_active)
Host_Error ("Received signon %i when at %i", so,
cls.signon);
cls.signon = i;
cls.signon = so;
CL_SignonReply ();
break;

View file

@ -81,7 +81,7 @@ SCR_CShift (void)
mleaf_t *leaf;
int contents = CONTENTS_EMPTY;
if (cls.signon == SIGNONS && cl.worldmodel) {
if (cls.state == ca_active && cl.worldmodel) {
leaf = Mod_PointInLeaf (r_data->refdef->vieworg, cl.worldmodel);
contents = leaf->contents;
}

View file

@ -728,7 +728,7 @@ V_CalcRefdef (void)
void
V_RenderView (void)
{
if (cls.signon != SIGNONS) //FIXME need proper state
if (cls.state != ca_active)
return;
// don't allow cheats in multiplayer

View file

@ -438,7 +438,7 @@ Host_ShutdownServer (qboolean crash)
sv.active = false;
// stop all client sounds immediately
if (cls.state == ca_connected)
if (cls.state >= ca_connected)
CL_Disconnect ();
// flush any pending messages - like the score!!!
@ -585,7 +585,7 @@ Host_ClientFrame (void)
host_time += host_frametime;
// fetch results from server
if (cls.state == ca_connected)
if (cls.state >= ca_connected)
CL_ReadFromServer ();
// update video
@ -603,7 +603,7 @@ Host_ClientFrame (void)
time2 = Sys_DoubleTime ();
// update audio
if (cls.signon == SIGNONS) {
if (cls.state == ca_active) {
mleaf_t *l;
byte *asl = 0;

View file

@ -750,7 +750,7 @@ Host_Name_f (void)
if (strcmp (cl_name->string, newName) == 0)
return;
Cvar_Set (cl_name, va ("%.15s", newName));
if (cls.state == ca_connected)
if (cls.state >= ca_connected)
CL_Cmd_ForwardToServer ();
return;
}