From 1dbfea351ab41a29c2e05d19a873879e49e19be0 Mon Sep 17 00:00:00 2001 From: Ragnvald Maartmann-Moe IV Date: Fri, 18 May 2001 18:33:37 +0000 Subject: [PATCH] console.c mergable. Little bit of cleanup of client.h --- nq/include/client.h | 114 +++++++++++++++++++++++++------------------- nq/source/console.c | 111 ++++++++++++++++++++++++------------------ qw/include/client.h | 67 +++++++++++++------------- qw/source/console.c | 31 +++++------- 4 files changed, 173 insertions(+), 150 deletions(-) diff --git a/nq/include/client.h b/nq/include/client.h index 658626894..2c517dc18 100644 --- a/nq/include/client.h +++ b/nq/include/client.h @@ -38,12 +38,13 @@ #include "QF/quakefs.h" #include "QF/sound.h" -#include "protocol.h" #include "net.h" +#include "protocol.h" #include "r_local.h" #include "render.h" #include "game.h" + typedef struct usercmd_s { vec3_t viewangles; @@ -75,32 +76,38 @@ typedef struct #define NAME_LENGTH 64 -// -// client_state_t should hold all pieces of the client state -// +/* + client_state_t should hold all pieces of the client state +*/ #define SIGNONS 4 // signon messages to receive before connected -#define MAX_EFRAGS 640 - -#define MAX_MAPSTRING 2048 #define MAX_DEMOS 8 #define MAX_DEMONAME 16 +#define MAX_EFRAGS 640 +#define MAX_MAPSTRING 2048 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_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 } cactive_t; +typedef enum { + dl_none, + dl_model, + dl_sound, + dl_skin, + 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 -// +/* + the client_static_t structure is persistant through an arbitrary number + of server connections +*/ typedef struct { cactive_t state; @@ -109,6 +116,14 @@ typedef struct char mapstring[MAX_QPATH]; char spawnparms[MAX_MAPSTRING]; // to restart a level +// file transfer from server + QFile *download; + char downloadtempname[MAX_OSPATH]; + char downloadname[MAX_OSPATH]; + int downloadnumber; + dltype_t downloadtype; + int downloadpercent; + // demo loop control int demonum; // -1 = don't play demos char demos[MAX_DEMOS][MAX_DEMONAME]; // when not playing @@ -124,7 +139,6 @@ typedef struct int td_startframe; // host_framecount at start float td_starttime; // realtime at second frame of timedemo - // connection information int signon; // 0 to SIGNONS struct qsocket_s *netcon; @@ -134,10 +148,10 @@ typedef struct extern client_static_t cls; -// -// the client_state_t structure is wiped completely at every -// server signon -// +/* + the client_state_t structure is wiped completely at every + server signon +*/ typedef struct { int movemessages; // since connecting to this server @@ -195,9 +209,8 @@ typedef struct float last_received_message; // (realtime) for net trouble icon -// -// information that is static for the entire time connected to a server -// +/* information that is static for the entire time connected to a server */ + struct model_s *model_precache[MAX_MODELS]; struct sfx_s *sound_precache[MAX_SOUNDS]; @@ -219,17 +232,16 @@ typedef struct scoreboard_t *scores; // [cl.maxclients] #ifdef QUAKE2 -// light level at player's position including dlights -// this is sent back to the server each frame -// architectually ugly but it works +// light level at player's position including dlights this is sent back to the +// server each frame architectually ugly but it works int light_level; #endif } client_state_t; -// -// cvars -// +/* + cvars +*/ extern cvar_t *cl_name; extern cvar_t *cl_color; @@ -275,11 +287,10 @@ extern entity_t cl_static_entities[MAX_STATIC_ENTITIES]; extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES]; extern dlight_t cl_dlights[MAX_DLIGHTS]; -//============================================================================= -// -// cl_main -// +/* + cl_main +*/ dlight_t *CL_AllocDlight (int key); void CL_DecayLights (void); @@ -300,10 +311,10 @@ void CL_NextDemo (void); extern int cl_numvisedicts; extern entity_t *cl_visedicts[MAX_VISEDICTS]; -// -// cl_input -// +/* + cl_input +*/ void CL_InitInput (void); void CL_SendCmd (void); void CL_SendMove (usercmd_t *cmd); @@ -313,14 +324,14 @@ void CL_UpdateTEnts (void); void CL_ClearState (void); - int CL_ReadFromServer (void); void CL_WriteToServer (usercmd_t *cmd); void CL_BaseMove (usercmd_t *cmd); -// -// cl_demo.c -// + +/* + cl_demo.c +*/ void CL_StopPlayback (void); int CL_GetMessage (void); @@ -329,15 +340,17 @@ void CL_Record_f (void); void CL_PlayDemo_f (void); void CL_TimeDemo_f (void); -// -// cl_parse.c -// + +/* + cl_parse.c +*/ void CL_ParseServerMessage (void); void CL_NewTranslation (int slot); -// -// view -// + +/* + view +*/ void V_StartPitchDrift (void); void V_StopPitchDrift (void); @@ -348,9 +361,9 @@ void V_ParseDamage (void); void V_SetContentsColor (int contents); -// -// cl_tent -// +/* + cl_tent +*/ void CL_TEnts_Init (void); void CL_ClearEnts (void); void CL_ClearTEnts (void); @@ -359,6 +372,9 @@ struct entity_s **CL_NewTempEntity (void); void CL_ParseTEnt (void); void CL_SignonReply (void); + +extern double realtime; + void Cvar_Info (struct cvar_s *var); #endif // __client_h diff --git a/nq/source/console.c b/nq/source/console.c index a5693cab7..d63217492 100644 --- a/nq/source/console.c +++ b/nq/source/console.c @@ -39,6 +39,7 @@ #include #include "QF/cmd.h" +#include "QF/compat.h" #include "QF/console.h" #include "QF/draw.h" #include "QF/input.h" @@ -49,7 +50,6 @@ #include "QF/va.h" #include "client.h" -#include "host.h" int con_ormask; console_t con_main; @@ -61,7 +61,6 @@ int con_totallines; // total lines in console scrollback float con_cursorspeed = 4; - cvar_t *con_notifytime; // seconds #define NUM_CON_TIMES 4 @@ -74,13 +73,14 @@ int con_notifylines; // scan lines to clear for notify lines qboolean con_debuglog; #define MAXCMDLINE 256 + extern char key_lines[32][MAXCMDLINE]; extern int edit_line; extern int key_linepos; - qboolean con_initialized; + void Key_ClearTyping (void) { @@ -88,9 +88,7 @@ Key_ClearTyping (void) key_linepos = 1; } -/* - Con_ToggleConsole_f -*/ + void Con_ToggleConsole_f (void) { @@ -105,9 +103,7 @@ Con_ToggleConsole_f (void) Con_ClearNotify (); } -/* - Con_ToggleChat_f -*/ + void Con_ToggleChat_f (void) { @@ -122,9 +118,7 @@ Con_ToggleChat_f (void) Con_ClearNotify (); } -/* - Con_Clear_f -*/ + void Con_Clear_f (void) { @@ -136,9 +130,6 @@ Con_Clear_f (void) } -/* - Con_ClearNotify -*/ void Con_ClearNotify (void) { @@ -149,9 +140,6 @@ Con_ClearNotify (void) } -/* - Con_MessageMode_f -*/ void Con_MessageMode_f (void) { @@ -161,9 +149,7 @@ Con_MessageMode_f (void) key_dest = key_message; } -/* - Con_MessageMode2_f -*/ + void Con_MessageMode2_f (void) { @@ -173,9 +159,7 @@ Con_MessageMode2_f (void) key_dest = key_message; } -/* - Con_Resize -*/ + void Con_Resize (console_t *con) { @@ -239,9 +223,6 @@ Con_CheckResize (void) } -/* - Con_Init -*/ void Con_Init (void) { @@ -253,9 +234,7 @@ Con_Init (void) Con_Printf ("Console initialized.\n"); -// -// register our commands -// + // register our commands Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f, "Toggle the console up and down"); Cmd_AddCommand ("togglechat", Con_ToggleChat_f, @@ -268,6 +247,7 @@ Con_Init (void) con_initialized = true; } + void Con_Init_Cvars (void) { @@ -277,9 +257,6 @@ Con_Init_Cvars (void) } -/* - Con_Linefeed -*/ void Con_Linefeed (void) { @@ -293,6 +270,7 @@ Con_Linefeed (void) ' ', con_linewidth); } + /* Con_Print @@ -324,7 +302,6 @@ Con_Print (char *txt) } else mask = 0; - while ((c = *txt)) { // count word length for (l = 0; l < con_linewidth; l++) @@ -392,24 +369,23 @@ Con_DrawInput (void) char temp[MAXCMDLINE]; if (key_dest != key_console && cls.state == ca_active) - return; // don't draw anything (always draw - // if not active) + return; // don't draw anything (always draw if not active) text = strcpy (temp, key_lines[edit_line]); -// fill out remainder with spaces + // fill out remainder with spaces for (i = strlen (text); i < MAXCMDLINE; i++) text[i] = ' '; -// add the cursor frame + // add the cursor frame if ((int) (realtime * con_cursorspeed) & 1) text[key_linepos] = 11; -// prestep if horizontally scrolling + // prestep if horizontally scrolling if (key_linepos >= con_linewidth) text += 1 + key_linepos - con_linewidth; -// draw it + // draw it y = con_vislines - 22; for (i = 0; i < con_linewidth; i++) @@ -453,7 +429,6 @@ Con_DrawNotify (void) v += 8; } - if (key_dest == key_message) { clearnotify = 0; scr_copytop = 1; @@ -483,6 +458,7 @@ Con_DrawNotify (void) con_notifylines = v; } + /* Con_DrawConsole @@ -499,18 +475,18 @@ Con_DrawConsole (int lines) if (lines <= 0) return; -// draw the background + // draw the background Draw_ConsoleBackground (lines); -// draw the text + // draw the text con_vislines = lines; -// changed to line things up better + // changed to line things up better rows = (lines - 22) >> 3; // rows of text to draw y = lines - 30; -// draw from the bottom up + // draw from the bottom up if (con->display != con->current) { // draw arrows to show the buffer is backscrolled for (x = 0; x < con_linewidth; x += 4) @@ -533,12 +509,53 @@ Con_DrawConsole (int lines) Draw_Character8 ((x + 1) << 3, y, text[x]); } -// draw the input prompt, user text, and cursor if desired + // draw the input prompt, user text, and cursor if desired Con_DrawInput (); } + void Con_DrawDownload (int lines) { -} + int i, j, x, y, n; + char *text; + char dlbar[1024]; + if (!cls.download) + return; + + text = COM_SkipPath(cls.downloadname); + + x = con_linewidth - ((con_linewidth * 7) / 40); + y = x - strlen (text) - 8; + i = con_linewidth / 3; + if (strlen (text) > i) { + y = x - i - 11; + strncpy (dlbar, text, i); + dlbar[i] = 0; + strncat (dlbar, "...", sizeof (dlbar) - strlen (dlbar)); + } else + strncpy (dlbar, text, sizeof (dlbar)); + strncat (dlbar, ": ", sizeof (dlbar) - strlen (dlbar)); + i = strlen (dlbar); + dlbar[i++] = '\x80'; + // where's the dot go? + if (cls.downloadpercent == 0) + n = 0; + else + n = y * cls.downloadpercent / 100; + for (j = 0; j < y; j++) + if (j == n) + dlbar[i++] = '\x83'; + else + dlbar[i++] = '\x81'; + dlbar[i++] = '\x82'; + dlbar[i] = 0; + + snprintf (dlbar + strlen (dlbar), sizeof (dlbar) - strlen (dlbar), + " %02d%%", cls.downloadpercent); + // draw it + y = lines - 22 + 8; + for (i = 0; i < strlen (dlbar); i++) + Draw_Character8 ((i + 1) << 3, y, dlbar[i]); +} diff --git a/qw/include/client.h b/qw/include/client.h index 202b3d24a..744c3a1fe 100644 --- a/qw/include/client.h +++ b/qw/include/client.h @@ -39,8 +39,11 @@ #include "r_local.h" #include "render.h" -// player_state_t is the information needed by a player entity -// to do move prediction and to generate a drawable entity + +/* + player_state_t is the information needed by a player entity + to do move prediction and to generate a drawable entity +*/ typedef struct player_state_s { int messagenum; // all player's won't be updated each frame @@ -68,6 +71,7 @@ typedef struct player_state_s { #undef MAX_SCOREBOARDNAME #define MAX_SCOREBOARDNAME 16 + typedef struct player_info_s { int userid; @@ -102,17 +106,15 @@ typedef struct // received from server double receivedtime; // time message was received, or -1 - player_state_t playerstate[MAX_CLIENTS]; // message received that reflects performing - // the usercmd + player_state_t playerstate[MAX_CLIENTS]; // message received that + // reflects performing the + // usercmd packet_entities_t packet_entities; qboolean invalid; // true if the packet_entities delta was invalid } frame_t; -// // client_state_t should hold all pieces of the client state -// - typedef struct { int length; @@ -120,18 +122,17 @@ typedef struct } lightstyle_t; - -#define MAX_EFRAGS 512 - #define MAX_DEMOS 8 #define MAX_DEMONAME 16 +#define MAX_EFRAGS 512 + typedef enum { -ca_disconnected, // full screen console with no connection -ca_demostart, // starting up a demo -ca_connected, // netchan_t established, waiting for svc_serverdata -ca_onserver, // processing data lists, donwloading, etc -ca_active // everything is in, so frames can be rendered + ca_disconnected, // full screen console with no connection + ca_demostart, // starting up a demo + ca_connected, // netchan_t established, waiting for svc_serverdata + ca_onserver, // processing data lists, donwloading, etc + ca_active // everything is in, so frames can be rendered } cactive_t; typedef enum { @@ -142,10 +143,10 @@ typedef enum { dl_single } dltype_t; // download type -// -// the client_static_t structure is persistant through an arbitrary number -// of server connections -// +/* + the client_static_t structure is persistant through an arbitrary number + of server connections +*/ typedef struct { // connection information @@ -161,7 +162,8 @@ typedef struct int qport; - QFile *download; // file transfer from server +// file transfer from server + QFile *download; char downloadtempname[MAX_OSPATH]; char downloadname[MAX_OSPATH]; int downloadnumber; @@ -189,10 +191,9 @@ typedef struct extern client_static_t cls; -// -// the client_state_t structure is wiped completely at every -// server signon -// +/* + the client_state_t structure is wiped completely at every server signon +*/ typedef struct { int servercount; // server identification for prespawns @@ -224,9 +225,8 @@ typedef struct cshift_t cshifts[NUM_CSHIFTS]; // color shifts for damage, powerups cshift_t prev_cshifts[NUM_CSHIFTS]; // and content types -// the client maintains its own idea of view angles, which are -// sent to the server each frame. And only reset at level change -// and teleport times +// the client maintains its own idea of view angles, which are sent to the +// server each frame. And only reset at level change and teleport times vec3_t viewangles; // the client simulates or interpolates movement to get these values @@ -252,9 +252,8 @@ typedef struct int intermission; // don't change view angle, full screen, etc int completed_time; // latched ffrom time at intermission start -// -// information that is static for the entire time connected to a server -// +/* information that is static for the entire time connected to a server */ + char model_name[MAX_MODELS][MAX_QPATH]; char sound_name[MAX_SOUNDS][MAX_QPATH]; @@ -281,9 +280,9 @@ typedef struct } client_state_t; -// -// cvars -// +/* + cvars +*/ extern struct cvar_s *cl_warncmd; extern struct cvar_s *cl_upspeed; extern struct cvar_s *cl_forwardspeed; @@ -329,8 +328,6 @@ extern char *server_version; // version of server we connected to extern double realtime; -//============================================================================= - void Cvar_Info (struct cvar_s *var); diff --git a/qw/source/console.c b/qw/source/console.c index 9745b266e..5c2487c89 100644 --- a/qw/source/console.c +++ b/qw/source/console.c @@ -61,7 +61,6 @@ int con_totallines; // total lines in console scrollback float con_cursorspeed = 4; - cvar_t *con_notifytime; // seconds #define NUM_CON_TIMES 4 @@ -74,11 +73,11 @@ int con_notifylines; // scan lines to clear for notify lines qboolean con_debuglog; #define MAXCMDLINE 256 + extern char key_lines[32][MAXCMDLINE]; extern int edit_line; extern int key_linepos; - qboolean con_initialized; @@ -235,9 +234,7 @@ Con_Init (void) Con_Printf ("Console initialized.\n"); -// -// register our commands -// + // register our commands Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f, "Toggle the console up and down"); Cmd_AddCommand ("togglechat", Con_ToggleChat_f, @@ -305,7 +302,6 @@ Con_Print (char *txt) } else mask = 0; - while ((c = *txt)) { // count word length for (l = 0; l < con_linewidth; l++) @@ -373,24 +369,23 @@ Con_DrawInput (void) char temp[MAXCMDLINE]; if (key_dest != key_console && cls.state == ca_active) - return; // don't draw anything (always draw - // if not active) + return; // don't draw anything (always draw if not active) text = strcpy (temp, key_lines[edit_line]); -// fill out remainder with spaces + // fill out remainder with spaces for (i = strlen (text); i < MAXCMDLINE; i++) text[i] = ' '; -// add the cursor frame + // add the cursor frame if ((int) (realtime * con_cursorspeed) & 1) text[key_linepos] = 11; -// prestep if horizontally scrolling + // prestep if horizontally scrolling if (key_linepos >= con_linewidth) text += 1 + key_linepos - con_linewidth; -// draw it + // draw it y = con_vislines - 22; for (i = 0; i < con_linewidth; i++) @@ -434,7 +429,6 @@ Con_DrawNotify (void) v += 8; } - if (key_dest == key_message) { clearnotify = 0; scr_copytop = 1; @@ -481,18 +475,18 @@ Con_DrawConsole (int lines) if (lines <= 0) return; -// draw the background + // draw the background Draw_ConsoleBackground (lines); -// draw the text + // draw the text con_vislines = lines; -// changed to line things up better + // changed to line things up better rows = (lines - 22) >> 3; // rows of text to draw y = lines - 30; -// draw from the bottom up + // draw from the bottom up if (con->display != con->current) { // draw arrows to show the buffer is backscrolled for (x = 0; x < con_linewidth; x += 4) @@ -515,7 +509,7 @@ Con_DrawConsole (int lines) Draw_Character8 ((x + 1) << 3, y, text[x]); } -// draw the input prompt, user text, and cursor if desired + // draw the input prompt, user text, and cursor if desired Con_DrawInput (); } @@ -565,4 +559,3 @@ Con_DrawDownload (int lines) for (i = 0; i < strlen (dlbar); i++) Draw_Character8 ((i + 1) << 3, y, dlbar[i]); } -