finally, the client console is merged

This commit is contained in:
Bill Currie 2002-01-16 21:53:42 +00:00
parent 778af4276e
commit c86c5a78bf
19 changed files with 300 additions and 1675 deletions

View file

@ -31,6 +31,7 @@
#include <stdarg.h> #include <stdarg.h>
#include "QF/keys.h"
#include "QF/qtypes.h" #include "QF/qtypes.h"
#include "QF/gcc_attr.h" #include "QF/gcc_attr.h"
@ -75,26 +76,19 @@ typedef struct {
int cur_line; // current line int cur_line; // current line
} con_buffer_t; } con_buffer_t;
extern old_console_t con_main;
extern old_console_t con_chat;
extern old_console_t *con; // point to either con_main or con_chat
extern int con_ormask;
extern int con_linewidth; extern int con_linewidth;
extern struct plugin_s *con_module;
extern int con_totallines; //extern int con_totallines;
extern qboolean con_initialized; //extern qboolean con_initialized;
extern byte *con_chars; //extern byte *con_chars;
extern int con_notifylines; // scan lines to clear for notify lines
void Con_CheckResize (void); void Con_CheckResize (void);
void Con_DrawConsole (int lines); void Con_DrawConsole (int lines);
void Con_DrawDownload (int lines);
void Con_Print (const char *fmt, va_list args); void Con_Print (const char *fmt, va_list args);
void Con_Printf (const char *fmt, ...) __attribute__((format(printf,1,2))); void Con_Printf (const char *fmt, ...) __attribute__((format(printf,1,2)));
void Con_DPrintf (const char *fmt, ...) __attribute__((format(printf,1,2))); void Con_DPrintf (const char *fmt, ...) __attribute__((format(printf,1,2)));
void Con_DrawNotify (void);
void Con_ToggleConsole_f (void); void Con_ToggleConsole_f (void);
// wrapper function to attempt to either complete the command line // wrapper function to attempt to either complete the command line
@ -110,6 +104,7 @@ void Con_DisplayList(const char **list, int con_linewidth);
inputline_t *Con_CreateInputLine (int lines, int width, char prompt); inputline_t *Con_CreateInputLine (int lines, int width, char prompt);
void Con_DestroyInputLine (inputline_t *inputline); void Con_DestroyInputLine (inputline_t *inputline);
void Con_ClearTyping (inputline_t *il);
void Con_ProcessInputLine (inputline_t *il, int ch); void Con_ProcessInputLine (inputline_t *il, int ch);
con_buffer_t *Con_CreateBuffer (size_t buffer_size, int max_lines); con_buffer_t *Con_CreateBuffer (size_t buffer_size, int max_lines);
@ -123,6 +118,8 @@ void Con_Init_Cvars (void);
void Con_Shutdown (void); void Con_Shutdown (void);
void Con_ProcessInput (void); void Con_ProcessInput (void);
void Con_KeyEvent (knum_t key, short unicode, qboolean down);
void Con_SetOrMask (int mask);
void Con_Maplist_f (void); void Con_Maplist_f (void);
void Con_Skinlist_f (void); void Con_Skinlist_f (void);

View file

@ -30,6 +30,7 @@
#ifndef _KEYS_H #ifndef _KEYS_H
#define _KEYS_H #define _KEYS_H
#include "QF/qtypes.h"
#include "QF/vfile.h" #include "QF/vfile.h"
// these are the key numbers that should be passed to Key_Event // these are the key numbers that should be passed to Key_Event

View file

@ -31,22 +31,30 @@
#include <stdarg.h> #include <stdarg.h>
#include <QF/keys.h>
#include <QF/qtypes.h> #include <QF/qtypes.h>
#include <QF/plugin.h> #include <QF/plugin.h>
typedef void (QFPLUGIN *P_C_Print) (const char *fmt, va_list args); typedef void (QFPLUGIN *P_C_Print) (const char *fmt, va_list args);
typedef void (QFPLUGIN *P_C_ProcessInput) (void); typedef void (QFPLUGIN *P_C_ProcessInput) (void);
typedef void (QFPLUGIN *P_C_KeyEvent) (key_t key, short unicode, qboolean down);
typedef void (QFPLUGIN *P_C_DrawConsole) (int lines);
typedef void (QFPLUGIN *P_C_CheckResize) (void);
typedef struct console_func_s { typedef struct console_func_s {
P_C_Print pC_Print; P_C_Print pC_Print;
P_C_ProcessInput pC_ProcessInput; P_C_ProcessInput pC_ProcessInput;
P_C_KeyEvent pC_KeyEvent;
P_C_DrawConsole pC_DrawConsole;
P_C_CheckResize pC_CheckResize;
} console_funcs_t; } console_funcs_t;
typedef struct console_data_s { typedef struct console_data_s {
const char *dl_name; const char *dl_name;
int dl_percent; int *dl_percent;
double realtime; double *realtime;
int force_commandline; int force_commandline;
int ormask;
} console_data_t; } console_data_t;
#endif // __QF_plugin_console_h_ #endif // __QF_plugin_console_h_

View file

@ -38,6 +38,7 @@ static const char rcsid[] =
#endif #endif
#include <stdarg.h> #include <stdarg.h>
#include <errno.h>
#include "QF/cmd.h" #include "QF/cmd.h"
#include "QF/console.h" #include "QF/console.h"
@ -59,27 +60,32 @@ static general_data_t plugin_info_general_data;
static console_data_t plugin_info_console_data; static console_data_t plugin_info_console_data;
#define con_data plugin_info_console_data #define con_data plugin_info_console_data
float con_cursorspeed = 4; static old_console_t con_main;
static old_console_t con_chat;
static old_console_t *con;
cvar_t *con_notifytime; // seconds static float con_cursorspeed = 4;
static cvar_t *con_notifytime; // seconds
#define NUM_CON_TIMES 4 #define NUM_CON_TIMES 4
float con_times[NUM_CON_TIMES]; // realtime time the line was generated static float con_times[NUM_CON_TIMES]; // realtime time the line was generated
// for transparent notify lines // for transparent notify lines
int con_vislines; static int con_totallines; // total lines in console scrollback
int con_notifylines; // scan lines to clear for notify lines static int con_vislines;
static int con_notifylines; // scan lines to clear for notify lines
qboolean con_debuglog; static qboolean con_debuglog;
#define MAXCMDLINE 256 #define MAXCMDLINE 256
static inputline_t *input_line;
static qboolean con_initialized;
qboolean con_initialized; static void
ClearNotify (void)
void
Con_ClearNotify (void)
{ {
int i; int i;
@ -87,45 +93,41 @@ Con_ClearNotify (void)
con_times[i] = 0; con_times[i] = 0;
} }
void
Con_ToggleConsole_f (void) static void
ToggleConsole_f (void)
{ {
Key_ClearTyping (); Con_ClearTyping (input_line);
if (key_dest == key_console) { if (key_dest == key_console && !con_data.force_commandline) {
if (con_data.force_commandline) key_dest = key_game;
key_dest = key_console; game_target = IMT_0;
else
key_dest = key_game;
} else
key_dest = key_console;
Con_ClearNotify ();
}
void
Con_ToggleChat_f (void)
{
Key_ClearTyping ();
if (key_dest == key_console) {
if (con_data.force_commandline) {
key_dest = key_console;
game_target = IMT_CONSOLE;
} else {
key_dest = key_game;
game_target = IMT_0;
}
} else { } else {
key_dest = key_console; key_dest = key_console;
game_target = IMT_CONSOLE; game_target = IMT_CONSOLE;
} }
Con_ClearNotify (); ClearNotify ();
} }
void static void
Con_Clear_f (void) ToggleChat_f (void)
{
Con_ClearTyping (input_line);
if (key_dest == key_console && !con_data.force_commandline) {
key_dest = key_game;
game_target = IMT_0;
} else {
key_dest = key_console;
game_target = IMT_CONSOLE;
}
ClearNotify ();
}
static void
Clear_f (void)
{ {
con_main.numlines = 0; con_main.numlines = 0;
con_chat.numlines = 0; con_chat.numlines = 0;
@ -134,8 +136,8 @@ Con_Clear_f (void)
con_main.display = con_main.current; con_main.display = con_main.current;
} }
void static void
Con_MessageMode_f (void) MessageMode_f (void)
{ {
if (con_data.force_commandline) if (con_data.force_commandline)
return; return;
@ -143,8 +145,8 @@ Con_MessageMode_f (void)
key_dest = key_message; key_dest = key_message;
} }
void static void
Con_MessageMode2_f (void) MessageMode2_f (void)
{ {
if (con_data.force_commandline) if (con_data.force_commandline)
return; return;
@ -152,9 +154,8 @@ Con_MessageMode2_f (void)
key_dest = key_message; key_dest = key_message;
} }
/* static void
void Resize (old_console_t *con)
Con_Resize (console_t *con)
{ {
char tbuf[CON_TEXTSIZE]; char tbuf[CON_TEXTSIZE];
int width, oldwidth, oldtotallines, numlines, numchars, i, j; int width, oldwidth, oldtotallines, numlines, numchars, i, j;
@ -167,11 +168,13 @@ Con_Resize (console_t *con)
if (width < 1) { // video hasn't been initialized yet if (width < 1) { // video hasn't been initialized yet
width = 38; width = 38;
con_linewidth = width; con_linewidth = width;
input_line->width = con_linewidth;
con_totallines = CON_TEXTSIZE / con_linewidth; con_totallines = CON_TEXTSIZE / con_linewidth;
memset (con->text, ' ', CON_TEXTSIZE); memset (con->text, ' ', CON_TEXTSIZE);
} else { } else {
oldwidth = con_linewidth; oldwidth = con_linewidth;
con_linewidth = width; con_linewidth = width;
input_line->width = con_linewidth;
oldtotallines = con_totallines; oldtotallines = con_totallines;
con_totallines = CON_TEXTSIZE / con_linewidth; con_totallines = CON_TEXTSIZE / con_linewidth;
numlines = oldtotallines; numlines = oldtotallines;
@ -195,26 +198,71 @@ Con_Resize (console_t *con)
} }
} }
Con_ClearNotify (); ClearNotify ();
} }
con->current = con_totallines - 1; con->current = con_totallines - 1;
con->display = con->current; con->display = con->current;
} }
*/
/* /*
Con_CheckResize C_CheckResize
If the line width has changed, reformat the buffer. If the line width has changed, reformat the buffer.
*/ */
void static void
Con_CheckResize (void) C_CheckResize (void)
{ {
//XXX Con_Resize (&con_main); Resize (&con_main);
//XXX Con_Resize (&con_chat); Resize (&con_chat);
} }
static void
Condump_f (void)
{
int line = con->current - con->numlines;
const char *start, *end;
VFile *file;
char name[MAX_OSPATH];
if (Cmd_Argc () != 2) {
Con_Printf ("usage: condump <filename>\n");
return;
}
if (strchr (Cmd_Argv (1), '/') || strchr (Cmd_Argv (1), '\\')) {
Con_Printf ("invalid character in filename\n");
return;
}
snprintf (name, sizeof (name), "%s/%s.txt", com_gamedir, Cmd_Argv (1));
if (!(file = Qopen (name, "wt"))) {
Con_Printf ("could not open %s for writing: %s\n", name,
strerror (errno));
return;
}
while (line < con->current) {
start = &con->text[(line % con_totallines) * con_linewidth];
end = start + con_linewidth;
while (end > start && end[-1] != ' ')
end--;
Qprintf (file, "%.*s\n", (int)(end - start), start);
line++;
}
Qclose (file);
}
static void
C_ExecLine (const char *line)
{
if (line[0] == '/')
line++;
Cbuf_AddText (line);
}
static void static void
C_Init (void) C_Init (void)
{ {
@ -226,20 +274,30 @@ C_Init (void)
con = &con_main; con = &con_main;
con_linewidth = -1; con_linewidth = -1;
Con_CheckResize ();
input_line = Con_CreateInputLine (32, MAXCMDLINE, ']');
input_line->complete = Con_BasicCompleteCommandLine;
input_line->enter = C_ExecLine;
input_line->width = con_linewidth;
input_line->user_data = 0;
input_line->draw = 0;//C_DrawInput;
C_CheckResize ();
Con_Printf ("Console initialized.\n"); Con_Printf ("Console initialized.\n");
// register our commands // register our commands
Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f, Cmd_AddCommand ("toggleconsole", ToggleConsole_f,
"Toggle the console up and down"); "Toggle the console up and down");
Cmd_AddCommand ("togglechat", Con_ToggleChat_f, Cmd_AddCommand ("togglechat", ToggleChat_f,
"Toggle the console up and down"); "Toggle the console up and down");
Cmd_AddCommand ("messagemode", Con_MessageMode_f, Cmd_AddCommand ("messagemode", MessageMode_f,
"Prompt to send a message to everyone"); "Prompt to send a message to everyone");
Cmd_AddCommand ("messagemode2", Con_MessageMode2_f, Cmd_AddCommand ("messagemode2", MessageMode2_f,
"Prompt to send a message to only people on your team"); "Prompt to send a message to only people on your team");
Cmd_AddCommand ("clear", Con_Clear_f, "Clear the console"); Cmd_AddCommand ("clear", Clear_f, "Clear the console");
Cmd_AddCommand ("condump", Condump_f, "dump the console text to a "
"file");
con_initialized = true; con_initialized = true;
} }
@ -248,8 +306,8 @@ C_Shutdown (void)
{ {
} }
void static void
Con_Linefeed (void) Linefeed (void)
{ {
con->x = 0; con->x = 0;
if (con->display == con->current) if (con->display == con->current)
@ -271,10 +329,10 @@ Con_Linefeed (void)
void void
C_Print (const char *fmt, va_list args) C_Print (const char *fmt, va_list args)
{ {
const char *txt; char *s;
static char *buffer; static char *buffer;
int mask, size, c, l, y; int mask, size, c, l, y;
static int buffer_size, cr; static int buffer_size, cr;
size = vsnprintf (buffer, buffer_size, fmt, args); size = vsnprintf (buffer, buffer_size, fmt, args);
if (size + 1 > buffer_size) { if (size + 1 > buffer_size) {
@ -285,35 +343,33 @@ C_Print (const char *fmt, va_list args)
buffer_size); buffer_size);
vsnprintf (buffer, buffer_size, fmt, args); vsnprintf (buffer, buffer_size, fmt, args);
} }
txt = buffer;
// echo to debugging console
Sys_Printf ("%s", buffer);
// log all messages to file // log all messages to file
if (con_debuglog) if (con_debuglog)
Sys_DebugLog (va ("%s/qconsole.log", com_gamedir), "%s", txt); Sys_DebugLog (va ("%s/qconsole.log", com_gamedir), "%s", buffer);
if (!con_initialized) if (!con_initialized)
return; return;
if (txt[0] == 1 || txt[0] == 2) { s = buffer;
if (s[0] == 1 || s[0] == 2) {
mask = 128; // go to colored text mask = 128; // go to colored text
txt++; s++;
} else } else
mask = 0; mask = 0;
while ((c = *txt)) { while ((c = (byte)*s)) {
// count word length // count word length
for (l = 0; l < con_linewidth; l++) for (l = 0; l < con_linewidth; l++)
if (txt[l] <= ' ') if (s[l] <= ' ')
break; break;
// word wrap // word wrap
if (l != con_linewidth && (con->x + l > con_linewidth)) if (l != con_linewidth && (con->x + l > con_linewidth))
con->x = 0; con->x = 0;
txt++; *s++ = sys_char_map[c];
if (cr) { if (cr) {
con->current--; con->current--;
@ -321,10 +377,10 @@ C_Print (const char *fmt, va_list args)
} }
if (!con->x) { if (!con->x) {
Con_Linefeed (); Linefeed ();
// mark time for transparent overlay // mark time for transparent overlay
if (con->current >= 0) if (con->current >= 0)
con_times[con->current % NUM_CON_TIMES] = con_data.realtime; con_times[con->current % NUM_CON_TIMES] = *con_data.realtime;
} }
switch (c) { switch (c) {
@ -339,7 +395,7 @@ C_Print (const char *fmt, va_list args)
default: // display character and advance default: // display character and advance
y = con->current % con_totallines; y = con->current % con_totallines;
con->text[y * con_linewidth + con->x] = c | mask | con_ormask; con->text[y * con_linewidth + con->x] = c | mask | con_data.ormask;
con->x++; con->x++;
if (con->x >= con_linewidth) if (con->x >= con_linewidth)
con->x = 0; con->x = 0;
@ -347,18 +403,31 @@ C_Print (const char *fmt, va_list args)
} }
} }
// echo to debugging console
if ((byte)buffer[0] > 2)
fputs (buffer, stdout);
else if ((byte)buffer[0])
fputs (buffer + 1, stdout);
}
static void
C_KeyEvent (key_t key, short unicode, qboolean down)
{
if (!down)
return;
Con_ProcessInputLine (input_line, key);
} }
/* DRAWING */ /* DRAWING */
/* /*
Con_DrawInput DrawInput
The input line scrolls horizontally if typing goes beyond the right edge The input line scrolls horizontally if typing goes beyond the right edge
*/ */
void static void
Con_DrawInput (void) DrawInput (void)
{ {
int i, y; int i, y;
char temp[MAXCMDLINE]; char temp[MAXCMDLINE];
@ -367,34 +436,30 @@ Con_DrawInput (void)
if (key_dest != key_console && !con_data.force_commandline) if (key_dest != key_console && !con_data.force_commandline)
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]); text = strcpy (temp, input_line->lines[input_line->edit_line]
+ input_line->scroll);
// fill out remainder with spaces // fill out remainder with spaces
for (i = strlen (text); i < MAXCMDLINE; i++) for (i = strlen (text); i < MAXCMDLINE; i++)
text[i] = ' '; text[i] = ' ';
// add the cursor frame // add the cursor frame
if ((int) (con_data.realtime * con_cursorspeed) & 1) if ((int) (*con_data.realtime * con_cursorspeed) & 1)
text[key_linepos] = 11; text[input_line->linepos - input_line->scroll] = 11;
// prestep if horizontally scrolling
if (key_linepos >= con_linewidth)
text += 1 + key_linepos - con_linewidth;
// draw it // draw it
y = con_vislines - 22; y = con_vislines - 22;
for (i = 0; i < con_linewidth; i++) Draw_nString (8, y, text, con_linewidth);
Draw_Character ((i + 1) << 3, con_vislines - 22, text[i]);
} }
/* /*
Con_DrawNotify DrawNotify
Draws the last few lines of output transparently over the game top Draws the last few lines of output transparently over the game top
*/ */
void static void
Con_DrawNotify (void) DrawNotify (void)
{ {
int skip, i, v, x; int skip, i, v, x;
char *text, *s; char *text, *s;
@ -407,7 +472,7 @@ Con_DrawNotify (void)
time = con_times[i % NUM_CON_TIMES]; time = con_times[i % NUM_CON_TIMES];
if (time == 0) if (time == 0)
continue; continue;
time = con_data.realtime - time; time = *con_data.realtime - time;
if (time > con_notifytime->value) if (time > con_notifytime->value)
continue; continue;
text = con->text + (i % con_totallines) * con_linewidth; text = con->text + (i % con_totallines) * con_linewidth;
@ -415,9 +480,7 @@ Con_DrawNotify (void)
clearnotify = 0; clearnotify = 0;
scr_copytop = 1; scr_copytop = 1;
for (x = 0; x < con_linewidth; x++) Draw_nString (8, v, text, con_linewidth);
Draw_Character ((x + 1) << 3, v, text[x]);
v += 8; v += 8;
} }
@ -437,12 +500,10 @@ Con_DrawNotify (void)
if (chat_bufferlen > (vid.width >> 3) - (skip + 1)) if (chat_bufferlen > (vid.width >> 3) - (skip + 1))
s += chat_bufferlen - ((vid.width >> 3) - (skip + 1)); s += chat_bufferlen - ((vid.width >> 3) - (skip + 1));
x = 0; x = 0;
while (s[x]) { Draw_String (skip << 3, v, s);
Draw_Character ((x + skip) << 3, v, s[x]); Draw_Character ((strlen(s) + skip) << 3, v,
x++; 10 + ((int) (*con_data.realtime
} * con_cursorspeed) & 1));
Draw_Character ((x + skip) << 3, v,
10 + ((int) (con_data.realtime * con_cursorspeed) & 1));
v += 8; v += 8;
} }
@ -451,12 +512,12 @@ Con_DrawNotify (void)
} }
/* /*
Con_DrawConsole DrawConsole
Draws the console with the solid background Draws the console with the solid background
*/ */
void static void
Con_DrawConsole (int lines) DrawConsole (int lines)
{ {
char *text; char *text;
int row, rows, i, x, y; int row, rows, i, x, y;
@ -494,22 +555,21 @@ Con_DrawConsole (int lines)
text = con->text + (row % con_totallines) * con_linewidth; text = con->text + (row % con_totallines) * con_linewidth;
for (x = 0; x < con_linewidth; x++) Draw_nString(8, y, text, con_linewidth);
Draw_Character ((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 (); DrawInput ();
} }
void static void
Con_DrawDownload (int lines) DrawDownload (int lines)
{ {
char dlbar[1024]; char dlbar[1024];
const char *text; const char *text;
int i, j, x, y, n; int i, j, x, y, n;
if (!con_data.dl_name) if (!con_data.dl_name || !*con_data.dl_name)
return; return;
text = COM_SkipPath(con_data.dl_name); text = COM_SkipPath(con_data.dl_name);
@ -531,8 +591,7 @@ Con_DrawDownload (int lines)
if (con_data.dl_percent == 0) if (con_data.dl_percent == 0)
n = 0; n = 0;
else else
n = y * con_data.dl_percent / 100; n = y * *con_data.dl_percent / 100;
for (j = 0; j < y; j++) for (j = 0; j < y; j++)
if (j == n) if (j == n)
dlbar[i++] = '\x83'; dlbar[i++] = '\x83';
@ -542,7 +601,7 @@ Con_DrawDownload (int lines)
dlbar[i] = 0; dlbar[i] = 0;
snprintf (dlbar + strlen (dlbar), sizeof (dlbar) - strlen (dlbar), snprintf (dlbar + strlen (dlbar), sizeof (dlbar) - strlen (dlbar),
" %02d%%", con_data.dl_percent); " %02d%%", *con_data.dl_percent);
// draw it // draw it
y = lines - 22 + 8; y = lines - 22 + 8;
@ -550,6 +609,18 @@ Con_DrawDownload (int lines)
Draw_Character ((i + 1) << 3, y, dlbar[i]); Draw_Character ((i + 1) << 3, y, dlbar[i]);
} }
static void
C_DrawConsole (int lines)
{
if (lines) {
DrawConsole (lines);
DrawDownload (lines);
} else {
if (key_dest == key_game || key_dest == key_message)
DrawNotify (); // only draw notify in game
}
}
static void static void
C_ProcessInput (void) C_ProcessInput (void)
{ {
@ -563,6 +634,9 @@ static general_funcs_t plugin_info_general_funcs = {
static console_funcs_t plugin_info_console_funcs = { static console_funcs_t plugin_info_console_funcs = {
C_Print, C_Print,
C_ProcessInput, C_ProcessInput,
C_KeyEvent,
C_DrawConsole,
C_CheckResize,
}; };
static plugin_funcs_t plugin_info_funcs = { static plugin_funcs_t plugin_info_funcs = {

View file

@ -45,7 +45,7 @@ static const char rcsid[] =
int con_linewidth; // characters across screen int con_linewidth; // characters across screen
static plugin_t *con_module; plugin_t *con_module;
static con_buffer_t *(*const buffer) (size_t, int) = Con_CreateBuffer; static con_buffer_t *(*const buffer) (size_t, int) = Con_CreateBuffer;
static void (*const complete)(inputline_t *) = Con_BasicCompleteCommandLine; static void (*const complete)(inputline_t *) = Con_BasicCompleteCommandLine;
@ -119,3 +119,31 @@ Con_ProcessInput (void)
} }
} }
} }
void
Con_KeyEvent (knum_t key, short unicode, qboolean down)
{
if (con_module)
con_module->functions->console->pC_KeyEvent (key, unicode, down);
}
void
Con_SetOrMask (int mask)
{
if (con_module)
con_module->data->console->ormask = mask;
}
void
Con_DrawConsole (int lines)
{
if (con_module)
con_module->functions->console->pC_DrawConsole (lines);
}
void
Con_CheckResize (void)
{
if (con_module)
con_module->functions->console->pC_CheckResize ();
}

View file

@ -84,6 +84,13 @@ Con_DestroyInputLine (inputline_t *inputline)
free (inputline); free (inputline);
} }
void
Con_ClearTyping (inputline_t *il)
{
il->lines[il->edit_line][1] = 0;
il->linepos = 1;
}
void void
Con_ProcessInputLine (inputline_t *il, int ch) Con_ProcessInputLine (inputline_t *il, int ch)
{ {

View file

@ -434,6 +434,9 @@ static general_data_t plugin_info_general_data;
static console_funcs_t plugin_info_console_funcs = { static console_funcs_t plugin_info_console_funcs = {
C_Print, C_Print,
C_ProcessInput, C_ProcessInput,
0,
0,
0,
}; };
static console_data_t plugin_info_console_data; static console_data_t plugin_info_console_data;

View file

@ -509,25 +509,14 @@ SCR_SetUpToDrawConsole (void)
scr_con_current = scr_conlines; scr_con_current = scr_conlines;
} }
if (clearconsole++ < vid.numpages) { if (clearconsole++ < vid.numpages)
Sbar_Changed (); Sbar_Changed ();
} else if (clearnotify++ < vid.numpages) {
} else
con_notifylines = 0;
} }
void void
SCR_DrawConsole (void) SCR_DrawConsole (void)
{ {
if (scr_con_current) { Con_DrawConsole (scr_con_current);
scr_copyeverything = 1;
Con_DrawConsole (scr_con_current);
Con_DrawDownload (scr_con_current);
clearconsole = 0;
} else {
if (key_dest == key_game || key_dest == key_message)
Con_DrawNotify (); // only draw notify in game
}
} }
/* SCREEN SHOTS */ /* SCREEN SHOTS */
@ -793,8 +782,8 @@ SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
} }
} }
if (!scr_initialized || !con_initialized) // not initialized yet if (!scr_initialized)
return; return; // not initialized yet
if (oldviewsize != scr_viewsize->int_val) { if (oldviewsize != scr_viewsize->int_val) {
oldviewsize = scr_viewsize->int_val; oldviewsize = scr_viewsize->int_val;

View file

@ -561,25 +561,14 @@ SCR_SetUpToDrawConsole (void)
scr_con_current = scr_conlines; scr_con_current = scr_conlines;
} }
if (clearconsole++ < vid.numpages) { if (clearconsole++ < vid.numpages)
Sbar_Changed (); Sbar_Changed ();
} else if (clearnotify++ < vid.numpages) {
} else
con_notifylines = 0;
} }
void void
SCR_DrawConsole (void) SCR_DrawConsole (void)
{ {
if (scr_con_current) { Con_DrawConsole (scr_con_current);
scr_copyeverything = 1;
Con_DrawConsole (scr_con_current);
Con_DrawDownload (scr_con_current);
clearconsole = 0;
} else {
if (key_dest == key_game || key_dest == key_message)
Con_DrawNotify (); // only draw notify in game
}
} }
/* /*
@ -820,7 +809,7 @@ SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
scr_copytop = 0; scr_copytop = 0;
scr_copyeverything = 0; scr_copyeverything = 0;
if (!scr_initialized || !con_initialized) if (!scr_initialized)
return; // not initialized yet return; // not initialized yet
if (scr_viewsize->int_val != oldscr_viewsize) { if (scr_viewsize->int_val != oldscr_viewsize) {

View file

@ -628,25 +628,14 @@ SCR_SetUpToDrawConsole (void)
scr_con_current = scr_conlines; scr_con_current = scr_conlines;
} }
if (clearconsole++ < vid.numpages) { if (clearconsole++ < vid.numpages)
Sbar_Changed (); Sbar_Changed ();
} else if (clearnotify++ < vid.numpages) {
} else
con_notifylines = 0;
} }
void void
SCR_DrawConsole (void) SCR_DrawConsole (void)
{ {
if (scr_con_current) { Con_DrawConsole (scr_con_current);
scr_copyeverything = 1;
Con_DrawConsole (scr_con_current);
Con_DrawDownload (scr_con_current);
clearconsole = 0;
} else {
if (key_dest == key_game || key_dest == key_message)
Con_DrawNotify (); // only draw notify in game
}
} }
/* /*
@ -838,7 +827,7 @@ SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
scr_copytop = 0; scr_copytop = 0;
scr_copyeverything = 0; scr_copyeverything = 0;
if (!scr_initialized || !con_initialized) if (!scr_initialized)
return; // not initialized yet return; // not initialized yet
if (scr_viewsize->int_val != oldscr_viewsize) { if (scr_viewsize->int_val != oldscr_viewsize) {

View file

@ -57,8 +57,6 @@ static const char rcsid[] =
cvar_t *cl_chatmode; cvar_t *cl_chatmode;
cvar_t *in_bind_imt; cvar_t *in_bind_imt;
char key_lines[32][MAXCMDLINE];
int key_linepos;
int key_lastpress; int key_lastpress;
int edit_line = 0; int edit_line = 0;
@ -385,34 +383,6 @@ keyname_t keynames[] = {
}; };
/*
LINE TYPING INTO THE CONSOLE
*/
qboolean
CheckForCommand (void)
{
char command[128];
const char *cmd, *s;
int i;
s = key_lines[edit_line] + 1;
for (i = 0; i < 127; i++)
if (s[i] <= ' ')
break;
else
command[i] = s[i];
command[i] = 0;
cmd = Cmd_CompleteCommand (command);
if (!cmd || strcmp (cmd, command))
cmd = Cvar_CompleteVariable (command);
if (!cmd || strcmp (cmd, command))
return false; // just a chat message
return true;
}
/* /*
Key_Game Key_Game
@ -460,133 +430,10 @@ Key_Game (knum_t key, short unicode)
void void
Key_Console (knum_t key, short unicode) Key_Console (knum_t key, short unicode)
{ {
int i; if (keydown[key] == 1 && Key_Game (key, unicode))
if (keydown[key] != 1)
return; return;
if (Key_Game (key, unicode)) Con_KeyEvent (key, unicode, keydown[key]);
return;
if (unicode == '\x0D' || key == QFK_RETURN) {
// backslash text are commands, else
if (!strncmp(key_lines[edit_line], "//", 2))
goto no_lf;
else if (key_lines[edit_line][1] == '\\' ||
key_lines[edit_line][1] == '/')
Cbuf_AddText (key_lines[edit_line] + 2); // skip the >
else if (cl_chatmode->int_val != 1 && CheckForCommand ())
Cbuf_AddText (key_lines[edit_line] + 1); // valid command
else if (cl_chatmode->int_val) { // convert to a chat message
Cbuf_AddText ("say ");
Cbuf_AddText (key_lines[edit_line] + 1); // skip the >
} else
Cbuf_AddText (key_lines[edit_line] + 1); // skip the >
Cbuf_AddText ("\n");
no_lf:
Con_Printf ("%s\n", key_lines[edit_line]);
edit_line = (edit_line + 1) & 31;
history_line = edit_line;
key_lines[edit_line][0] = ']';
key_lines[edit_line][1] = '\0';
key_linepos = 1;
return;
}
if (unicode == '\t') { // command completion
Con_CompleteCommandLine ();
return;
}
if (unicode == '\x08') {
if (key_linepos > 1) {
memmove(key_lines[edit_line] + key_linepos - 1,
key_lines[edit_line] + key_linepos,
strlen(key_lines[edit_line] + key_linepos) + 1);
key_linepos--;
}
return;
}
if (key == QFK_DELETE) {
if (key_linepos < strlen (key_lines[edit_line])) {
memmove(key_lines[edit_line] + key_linepos,
key_lines[edit_line] + key_linepos + 1,
strlen(key_lines[edit_line] + key_linepos + 1) + 1);
}
return;
}
if (key == QFK_RIGHT) {
if (key_linepos < strlen (key_lines[edit_line]))
key_linepos++;
return;
}
if (key == QFK_LEFT) {
if (key_linepos > 1)
key_linepos--;
return;
}
if (key == QFK_UP) {
do {
history_line = (history_line - 1) & 31;
} while (history_line != edit_line && !key_lines[history_line][1]);
if (history_line == edit_line)
history_line = (edit_line + 1) & 31;
strcpy (key_lines[edit_line], key_lines[history_line]);
key_linepos = strlen (key_lines[edit_line]);
return;
}
if (key == QFK_DOWN) {
if (history_line == edit_line)
return;
do {
history_line = (history_line + 1) & 31;
}
while (history_line != edit_line && !key_lines[history_line][1]);
if (history_line == edit_line) {
key_lines[edit_line][0] = ']';
key_linepos = 1;
} else {
strcpy (key_lines[edit_line], key_lines[history_line]);
key_linepos = strlen (key_lines[edit_line]);
}
return;
}
if (key == QFK_PAGEUP || key == QFM_WHEEL_UP) {
con->display -= 2;
return;
}
if (key == QFK_PAGEDOWN || key == QFM_WHEEL_DOWN) {
con->display += 2;
if (con->display > con->current)
con->display = con->current;
return;
}
if (key == QFK_HOME) {
key_linepos = 1;
return;
}
if (key == QFK_END) {
key_linepos = strlen (key_lines[edit_line]);
return;
}
if (unicode < 32 || unicode > 127)
return; // non printable
i = strlen (key_lines[edit_line]);
if (i >= MAXCMDLINE - 1)
return;
// This also moves the ending \0
memmove (key_lines[edit_line] + key_linepos + 1,
key_lines[edit_line] + key_linepos, i - key_linepos + 1);
key_lines[edit_line][key_linepos] = unicode;
key_linepos++;
} }
void void
@ -947,7 +794,7 @@ Key_Event (knum_t key, short unicode, qboolean down)
break; break;
case key_game: case key_game:
case key_console: case key_console:
Con_ToggleConsole_f (); Cbuf_AddText ("toggleconsole\n");
break; break;
default: default:
Sys_Error ("Bad key_dest"); Sys_Error ("Bad key_dest");
@ -989,16 +836,8 @@ Key_ClearStates (void)
void void
Key_Init (void) Key_Init (void)
{ {
int i;
OK_Init (); OK_Init ();
for (i = 0; i < 32; i++) {
key_lines[i][0] = ']';
key_lines[i][1] = 0;
}
key_linepos = 1;
// register our functions // register our functions
Cmd_AddCommand ("in_bind", Key_In_Bind_f, "Assign a command or a set of " Cmd_AddCommand ("in_bind", Key_In_Bind_f, "Assign a command or a set of "
"commands to a key.\n" "commands to a key.\n"
@ -1027,13 +866,6 @@ Key_Init_Cvars (void)
"unbind wrappers to in_bind and in_unbind"); "unbind wrappers to in_bind and in_unbind");
} }
void
Key_ClearTyping (void)
{
key_lines[edit_line][1] = 0; // clear any typing
key_linepos = 1;
}
char * char *
Key_GetBinding (imt_t imt, knum_t key) Key_GetBinding (imt_t imt, knum_t key)
{ {

View file

@ -65,10 +65,10 @@ EXTRA_libqfnet_la_SOURCES= \
net_wipx.c net_udp.c net_wipx.c net_udp.c
client_LIBFILES= \ client_LIBFILES= \
$(CLIENT_PLUGIN_STATIC_LIBS) \
$(top_builddir)/libs/video/targets/libQFjs.la \ $(top_builddir)/libs/video/targets/libQFjs.la \
$(top_builddir)/libs/audio/libQFcd.la \ $(top_builddir)/libs/audio/libQFcd.la \
$(top_builddir)/libs/audio/libQFsound.la \ $(top_builddir)/libs/audio/libQFsound.la
$(top_builddir)/libs/console/filelist.o
server_LIBFILES= \ server_LIBFILES= \
$(SERVER_PLUGIN_STATIC_LIBS) \ $(SERVER_PLUGIN_STATIC_LIBS) \
@ -78,6 +78,7 @@ server_LIBFILES= \
common_LIBFILES= \ common_LIBFILES= \
libasm.la \ libasm.la \
libqfnet.la \ libqfnet.la \
$(top_builddir)/libs/console/libQFconsole.la \
$(top_builddir)/libs/gamecode/engine/libQFgamecode.la \ $(top_builddir)/libs/gamecode/engine/libQFgamecode.la \
$(top_builddir)/libs/gamecode/builtins/libQFgamecode_builtins.la \ $(top_builddir)/libs/gamecode/builtins/libQFgamecode_builtins.la \
$(top_builddir)/libs/gib/libQFgib.la \ $(top_builddir)/libs/gib/libQFgib.la \
@ -91,7 +92,7 @@ server_LIB_DEPS=$(server_LIBFILES) $(common_LIBFILES)
client_sources= cl_cam.c cl_cmd.c cl_demo.c cl_input.c cl_main.c cl_screen.c \ client_sources= cl_cam.c cl_cmd.c cl_demo.c cl_input.c cl_main.c cl_screen.c \
cl_parse.c cl_tent.c cl_view.c host_skin.c skin.c \ cl_parse.c cl_tent.c cl_view.c host_skin.c skin.c \
console.c locs.c sbar.c locs.c sbar.c
server_sources= host.c host_cmd.c pr_cmds.c sv_cvar.c sv_main.c \ server_sources= host.c host_cmd.c pr_cmds.c sv_cvar.c sv_main.c \
sv_move.c sv_phys.c sv_progs.c sv_user.c sv_move.c sv_phys.c sv_progs.c sv_user.c

View file

@ -1,648 +0,0 @@
/*
console.c
(description)
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
static const char rcsid[] =
"$Id$";
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <stdarg.h>
#include "QF/cmd.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/draw.h"
#include "QF/input.h"
#include "QF/keys.h"
#include "QF/qargs.h"
#include "QF/screen.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "client.h"
#include "compat.h"
old_console_t con_main;
old_console_t con_chat;
old_console_t *con; // point to either con_main or con_chat
int con_linewidth; // characters across screen
int con_ormask;
int con_totallines; // total lines in console scrollback
float con_cursorspeed = 4;
cvar_t *con_notifytime; // seconds
#define NUM_CON_TIMES 4
float con_times[NUM_CON_TIMES]; // realtime time the line was generated
// for transparent notify lines
int con_vislines;
int con_notifylines; // scan lines to clear for notify lines
qboolean con_debuglog;
#define MAXCMDLINE 256
qboolean con_initialized;
void
Con_ClearNotify (void)
{
int i;
for (i = 0; i < NUM_CON_TIMES; i++)
con_times[i] = 0;
}
void
Con_ToggleConsole_f (void)
{
Key_ClearTyping ();
if (key_dest == key_console) {
if (cls.state == ca_active) {
key_dest = key_game;
game_target = IMT_0;
}
} else {
key_dest = key_console;
game_target = IMT_CONSOLE;
}
Con_ClearNotify ();
}
void
Con_ToggleChat_f (void)
{
Key_ClearTyping ();
if (key_dest == key_console) {
if (cls.state == ca_active)
key_dest = key_game;
} else
key_dest = key_console;
Con_ClearNotify ();
}
void
Con_Clear_f (void)
{
con_main.numlines = 0;
con_chat.numlines = 0;
memset (con_main.text, ' ', CON_TEXTSIZE);
memset (con_chat.text, ' ', CON_TEXTSIZE);
con_main.display = con_main.current;
}
void
Con_MessageMode_f (void)
{
if (cls.state != ca_active)
return;
chat_team = false;
key_dest = key_message;
}
void
Con_MessageMode2_f (void)
{
if (cls.state != ca_active)
return;
chat_team = true;
key_dest = key_message;
}
void
Con_Resize (old_console_t *con)
{
char tbuf[CON_TEXTSIZE];
int i, j, width, oldwidth, oldtotallines, numlines, numchars;
width = (vid.width >> 3) - 2;
if (width == con_linewidth)
return;
if (width < 1) { // video hasn't been initialized yet
width = 38;
con_linewidth = width;
con_totallines = CON_TEXTSIZE / con_linewidth;
memset (con->text, ' ', CON_TEXTSIZE);
} else {
oldwidth = con_linewidth;
con_linewidth = width;
oldtotallines = con_totallines;
con_totallines = CON_TEXTSIZE / con_linewidth;
numlines = oldtotallines;
if (con_totallines < numlines)
numlines = con_totallines;
numchars = oldwidth;
if (con_linewidth < numchars)
numchars = con_linewidth;
memcpy (tbuf, con->text, CON_TEXTSIZE);
memset (con->text, ' ', CON_TEXTSIZE);
for (i = 0; i < numlines; i++) {
for (j = 0; j < numchars; j++) {
con->text[(con_totallines - 1 - i) * con_linewidth + j] =
tbuf[((con->current - i + oldtotallines) %
oldtotallines) * oldwidth + j];
}
}
Con_ClearNotify ();
}
con->current = con_totallines - 1;
con->display = con->current;
}
/*
Con_CheckResize
If the line width has changed, reformat the buffer.
*/
void
Con_CheckResize (void)
{
Con_Resize (&con_main);
Con_Resize (&con_chat);
}
void
Con_Init (const char *plugin_name)
{
con_debuglog = COM_CheckParm ("-condebug");
con = &con_main;
con_linewidth = -1;
Con_CheckResize ();
Sys_SetPrintf (Con_Print);
Con_Printf ("Console initialized.\n");
// register our commands
Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f,
"Toggle the console up and down");
Cmd_AddCommand ("togglechat", Con_ToggleChat_f,
"Toggle the console up and down");
Cmd_AddCommand ("messagemode", Con_MessageMode_f,
"Prompt to send a message to everyone");
Cmd_AddCommand ("messagemode2", Con_MessageMode2_f,
"Prompt to send a message to only people on your team");
Cmd_AddCommand ("clear", Con_Clear_f, "Clear the console");
con_initialized = true;
}
void
Con_Init_Cvars (void)
{
con_notifytime = Cvar_Get ("con_notifytime", "3", CVAR_NONE, NULL,
"How long in seconds messages are displayed "
"on screen");
}
void
Con_Linefeed (void)
{
con->x = 0;
if (con->display == con->current)
con->display++;
con->current++;
if (con->numlines < con_totallines)
con->numlines++;
memset (&con->text[(con->current % con_totallines) * con_linewidth],
' ', con_linewidth);
}
/*
Con_Print
Handles cursor positioning, line wrapping, etc
All console printing must go through this in order to be logged to disk
If no console is visible, the notify window will pop up.
*/
void
Con_Print (const char *fmt, va_list args)
{
int mask, c, l, y;
static int cr;
char txt[1024];
const char *s;
vsnprintf (txt, sizeof (txt), fmt, args);
// echo to debugging console
for (s = txt; *s; s++)
fputc (sys_char_map[(byte)*s], stdout);
// log all messages to file
if (con_debuglog)
Sys_DebugLog (va ("%s/qconsole.log", com_gamedir), "%s", txt);
if (!con_initialized)
return;
s = txt;
if (s[0] == 1 || s[0] == 2) {
mask = 128; // go to colored text
s++;
} else
mask = 0;
while ((c = *s)) {
// count word length
for (l = 0; l < con_linewidth; l++)
if (s[l] <= ' ')
break;
// word wrap
if (l != con_linewidth && (con->x + l > con_linewidth))
con->x = 0;
s++;
if (cr) {
con->current--;
cr = false;
}
if (!con->x) {
Con_Linefeed ();
// mark time for transparent overlay
if (con->current >= 0)
con_times[con->current % NUM_CON_TIMES] = realtime;
}
switch (c) {
case '\n':
con->x = 0;
break;
case '\r':
con->x = 0;
cr = 1;
break;
default: // display character and advance
y = con->current % con_totallines;
con->text[y * con_linewidth + con->x] = c | mask | con_ormask;
con->x++;
if (con->x >= con_linewidth)
con->x = 0;
break;
}
}
}
/* DRAWING */
/*
Con_DrawInput
The input line scrolls horizontally if typing goes beyond the right edge
*/
void
Con_DrawInput (void)
{
char temp[MAXCMDLINE];
char *text;
int i, y;
if (key_dest != key_console && cls.state == ca_active)
return; // don't draw anything (always draw if not active)
text = strcpy (temp, key_lines[edit_line]);
// fill out remainder with spaces
for (i = strlen (text); i < MAXCMDLINE; i++)
text[i] = ' ';
// add the cursor frame
if ((int) (realtime * con_cursorspeed) & 1)
text[key_linepos] = 11;
// prestep if horizontally scrolling
if (key_linepos >= con_linewidth)
text += 1 + key_linepos - con_linewidth;
// draw it
y = con_vislines - 22;
Draw_nString (8, y, text, con_linewidth);
}
/*
Con_DrawNotify
Draws the last few lines of output transparently over the game top
*/
void
Con_DrawNotify (void)
{
char *s, *text;
int skip, i, x, v;
float time;
v = 0;
for (i = con->current - NUM_CON_TIMES + 1; i <= con->current; i++) {
if (i < 0)
continue;
time = con_times[i % NUM_CON_TIMES];
if (time == 0)
continue;
time = realtime - time;
if (time > con_notifytime->value)
continue;
text = con->text + (i % con_totallines) * con_linewidth;
clearnotify = 0;
scr_copytop = 1;
Draw_nString (8, v, text, con_linewidth);
v += 8;
}
if (key_dest == key_message) {
clearnotify = 0;
scr_copytop = 1;
if (chat_team) {
Draw_String (8, v, "say_team:");
skip = 11;
} else {
Draw_String (8, v, "say:");
skip = 5;
}
s = chat_buffer;
if (chat_bufferlen > (vid.width >> 3) - (skip + 1))
s += chat_bufferlen - ((vid.width >> 3) - (skip + 1));
x = 0;
Draw_String (skip << 3, v, s);
Draw_Character ((strlen(s) + skip) << 3, v,
10 + ((int) (realtime * con_cursorspeed) & 1));
v += 8;
}
if (v > con_notifylines)
con_notifylines = v;
}
/*
Con_DrawConsole
Draws the console with the solid background
*/
void
Con_DrawConsole (int lines)
{
char *text;
int row, rows, i, x, y;
if (lines <= 0)
return;
// draw the background
Draw_ConsoleBackground (lines);
// draw the text
con_vislines = lines;
// changed to line things up better
rows = (lines - 22) >> 3; // rows of text to draw
y = lines - 30;
// 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)
Draw_Character ((x + 1) << 3, y, '^');
y -= 8;
rows--;
}
row = con->display;
for (i = 0; i < rows; i++, y -= 8, row--) {
if (row < 0)
break;
if (con->current - row >= con_totallines)
break; // past scrollback wrap point
text = con->text + (row % con_totallines) * con_linewidth;
Draw_nString (8, y, text, con_linewidth);
}
// draw the input prompt, user text, and cursor if desired
Con_DrawInput ();
}
void
Con_DrawDownload (int lines)
{
char dlbar[1024];
const char *text;
int i, j, x, y, n;
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;
Draw_nString (8, y, dlbar, strlen (dlbar));
}
/*
Con_CompleteCommandLine
New function for tab-completion system
Added by EvilTypeGuy
Thanks to Fett erich@heintz.com
Thanks to taniwha
*/
void
Con_CompleteCommandLine (void)
{
char *s;
const char *cmd = "";
const char **list[3] = {0, 0, 0};
int cmd_len, c, v, a, i;
s = key_lines[edit_line] + 1;
if (*s == '\\' || *s == '/')
s++;
// Count number of possible matches
c = Cmd_CompleteCountPossible(s);
v = Cvar_CompleteCountPossible(s);
a = Cmd_CompleteAliasCountPossible(s);
if (!(c + v + a)) // No possible matches
return;
if (c + v + a == 1) {
if (c)
list[0] = Cmd_CompleteBuildList(s);
else if (v)
list[0] = Cvar_CompleteBuildList(s);
else
list[0] = Cmd_CompleteAliasBuildList(s);
cmd = *list[0];
cmd_len = strlen (cmd);
} else {
if (c)
cmd = *(list[0] = Cmd_CompleteBuildList(s));
if (v)
cmd = *(list[1] = Cvar_CompleteBuildList(s));
if (a)
cmd = *(list[2] = Cmd_CompleteAliasBuildList(s));
cmd_len = strlen (s);
do {
for (i = 0; i < 3; i++) {
char ch = cmd[cmd_len];
const char **l = list[i];
if (l) {
while (*l && (*l)[cmd_len] == ch)
l++;
if (*l)
break;
}
}
if (i == 3)
cmd_len++;
} while (i == 3);
// 'quakebar'
Con_Printf("\n\35");
for (i = 0; i < con_linewidth - 4; i++)
Con_Printf("\36");
Con_Printf("\37\n");
// Print Possible Commands
if (c) {
Con_Printf("%i possible command%s\n", c, (c > 1) ? "s: " : ":");
Con_DisplayList(list[0], con_linewidth);
}
if (v) {
Con_Printf("%i possible variable%s\n", v, (v > 1) ? "s: " : ":");
Con_DisplayList(list[1], con_linewidth);
}
if (a) {
Con_Printf("%i possible aliases%s\n", a, (a > 1) ? "s: " : ":");
Con_DisplayList(list[2], con_linewidth);
}
}
if (cmd) {
key_lines[edit_line][1] = '/';
strncpy(key_lines[edit_line] + 2, cmd, cmd_len);
key_linepos = cmd_len + 2;
if (c + v + a == 1) {
key_lines[edit_line][key_linepos] = ' ';
key_linepos++;
}
key_lines[edit_line][key_linepos] = 0;
}
for (i = 0; i < 3; i++)
if (list[i])
free (list[i]);
}
void
Con_ProcessInput (void)
{
const char *cmd;
while (1) {
cmd = Sys_ConsoleInput ();
if (!cmd)
break;
Cbuf_AddText (cmd);
}
}
void
Con_Shutdown (void)
{
}

View file

@ -66,6 +66,11 @@ static const char rcsid[] =
Memory is cleared/released when a server or client begins, not when they end. Memory is cleared/released when a server or client begins, not when they end.
*/ */
CLIENT_PLUGIN_PROTOS
static plugin_list_t client_plugin_list[] = {
CLIENT_PLUGIN_LIST
};
qboolean msg_suppress_1 = 0; qboolean msg_suppress_1 = 0;
qboolean host_initialized; // true if into command execution qboolean host_initialized; // true if into command execution
@ -925,10 +930,15 @@ Host_Init (quakeparms_t *parms)
PI_Init (); PI_Init ();
PI_RegisterPlugins (client_plugin_list);
if (isDedicated) if (isDedicated)
Con_Init ("server"); Con_Init ("server");
else else
Con_Init ("client"); Con_Init ("client");
if (con_module) {
con_module->data->console->realtime = &realtime;
}
V_Init (); V_Init ();
COM_Init (); COM_Init ();

View file

@ -36,6 +36,7 @@ static const char rcsid[] =
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/keys.h" #include "QF/keys.h"
#include "QF/plugin.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "client.h" #include "client.h"
@ -295,3 +296,10 @@ void
V_Init_Cvars (void) V_Init_Cvars (void)
{ {
} }
QFPLUGIN plugin_t *
console_client_PluginInfo (void)
{
return 0;
}

View file

@ -99,12 +99,13 @@ qw_master_LDADD= $(NET_LIBS)
qw_master_LDFLAGS= $(common_ldflags) qw_master_LDFLAGS= $(common_ldflags)
qf_client_LIBS= \ qf_client_LIBS= \
$(CLIENT_PLUGIN_STATIC_LIBS) \
$(top_builddir)/libs/console/libQFconsole.la \
$(top_builddir)/libs/video/targets/libQFjs.la \ $(top_builddir)/libs/video/targets/libQFjs.la \
$(top_builddir)/libs/gamecode/engine/libQFgamecode.la \ $(top_builddir)/libs/gamecode/engine/libQFgamecode.la \
$(top_builddir)/libs/gamecode/builtins/libQFgamecode_builtins.la \ $(top_builddir)/libs/gamecode/builtins/libQFgamecode_builtins.la \
$(top_builddir)/libs/audio/libQFcd.la \ $(top_builddir)/libs/audio/libQFcd.la \
$(top_builddir)/libs/audio/libQFsound.la \ $(top_builddir)/libs/audio/libQFsound.la \
$(top_builddir)/libs/console/filelist.o \
$(top_builddir)/libs/util/libQFutil.la $(top_builddir)/libs/util/libQFutil.la
client_LIBS= libqfnet.la libasm.la $(qf_client_LIBS) $(NET_LIBS) client_LIBS= libqfnet.la libasm.la $(qf_client_LIBS) $(NET_LIBS)
@ -114,7 +115,7 @@ client_LIB_DEPS= libqfnet.la libasm.la $(qf_client_LIBS)
client_sources= cl_cam.c cl_cmd.c cl_cvar.c cl_demo.c cl_ents.c cl_input.c \ client_sources= cl_cam.c cl_cmd.c cl_cvar.c cl_demo.c cl_ents.c cl_input.c \
cl_main.c cl_misc.c cl_ngraph.c cl_parse.c cl_pred.c \ cl_main.c cl_misc.c cl_ngraph.c cl_parse.c cl_pred.c \
cl_screen.c cl_skin.c cl_slist.c cl_tent.c cl_view.c \ cl_screen.c cl_skin.c cl_slist.c cl_tent.c cl_view.c \
console.c locs.c sbar.c skin.c teamplay.c locs.c sbar.c skin.c teamplay.c
# Software-rendering clients # Software-rendering clients

View file

@ -106,6 +106,11 @@ static const char rcsid[] =
#include "sbar.h" #include "sbar.h"
#include "view.h" #include "view.h"
CLIENT_PLUGIN_PROTOS
static plugin_list_t client_plugin_list[] = {
CLIENT_PLUGIN_LIST
};
void CL_RemoveQFInfoKeys (); void CL_RemoveQFInfoKeys ();
// we need to declare some mouse variables here, because the menu system // we need to declare some mouse variables here, because the menu system
@ -1681,7 +1686,13 @@ Host_Init (void)
W_LoadWadFile ("gfx.wad"); W_LoadWadFile ("gfx.wad");
Key_Init (); Key_Init ();
PI_RegisterPlugins (client_plugin_list);
Con_Init ("client"); Con_Init ("client");
if (con_module) {
con_module->data->console->dl_name = cls.downloadname;
con_module->data->console->dl_percent = &cls.downloadpercent;
con_module->data->console->realtime = &realtime;
}
Mod_Init (); Mod_Init ();
CL_TimeFrames_Init(); CL_TimeFrames_Init();

View file

@ -1180,12 +1180,12 @@ CL_ParseServerMessage (void)
} }
s = p; s = p;
} }
con_ormask = 128; Con_SetOrMask (128);
S_LocalSound ("misc/talk.wav"); S_LocalSound ("misc/talk.wav");
Team_ParseChat(s); Team_ParseChat(s);
} }
Con_Printf ("%s", s); Con_Printf ("%s", s);
con_ormask = 0; Con_SetOrMask (0);
break; break;
} }
case svc_centerprint: case svc_centerprint:

View file

@ -1,675 +0,0 @@
/*
console.c
(description)
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
static const char rcsid[] =
"$Id$";
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif
#include <stdarg.h>
#include "QF/cmd.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/draw.h"
#include "QF/input.h"
#include "QF/keys.h"
#include "QF/qargs.h"
#include "QF/screen.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/vfs.h"
#include "client.h"
#include "compat.h"
old_console_t con_main;
old_console_t con_chat;
old_console_t *con; // point to either con_main or con_chat
int con_ormask;
int con_linewidth; // characters across screen
int con_totallines; // total lines in console scrollback
int con_notifylines; // scan lines to clear for notify lines
int con_vislines;
cvar_t *con_notifytime; // seconds
#define NUM_CON_TIMES 4
float con_cursorspeed = 4;
float con_times[NUM_CON_TIMES]; // realtime time the line was generated
// for transparent notify lines
qboolean con_debuglog;
qboolean con_initialized;
#define MAXCMDLINE 256
void
Con_ClearNotify (void)
{
int i;
for (i = 0; i < NUM_CON_TIMES; i++)
con_times[i] = 0;
}
void
Con_ToggleConsole_f (void)
{
Key_ClearTyping ();
if (key_dest == key_console) {
if (cls.state == ca_active) {
key_dest = key_game;
game_target = IMT_0;
}
} else {
key_dest = key_console;
game_target = IMT_CONSOLE;
}
Con_ClearNotify ();
}
void
Con_ToggleChat_f (void)
{
Key_ClearTyping ();
if (key_dest == key_console) {
if (cls.state == ca_active) {
key_dest = key_game;
game_target = IMT_0;
}
} else {
key_dest = key_console;
game_target = IMT_CONSOLE;
}
Con_ClearNotify ();
}
void
Con_Clear_f (void)
{
con_main.numlines = 0;
con_chat.numlines = 0;
memset (con_main.text, ' ', CON_TEXTSIZE);
memset (con_chat.text, ' ', CON_TEXTSIZE);
con_main.display = con_main.current;
}
void
Con_MessageMode_f (void)
{
if (cls.state != ca_active)
return;
chat_team = false;
key_dest = key_message;
}
void
Con_MessageMode2_f (void)
{
if (cls.state != ca_active)
return;
chat_team = true;
key_dest = key_message;
}
void
Con_Resize (old_console_t *con)
{
char tbuf[CON_TEXTSIZE];
int i, j, width, oldwidth, oldtotallines, numlines, numchars;
width = (vid.width >> 3) - 2;
if (width == con_linewidth)
return;
if (width < 1) { // video hasn't been initialized yet
width = 38;
con_linewidth = width;
con_totallines = CON_TEXTSIZE / con_linewidth;
memset (con->text, ' ', CON_TEXTSIZE);
} else {
oldwidth = con_linewidth;
con_linewidth = width;
oldtotallines = con_totallines;
con_totallines = CON_TEXTSIZE / con_linewidth;
numlines = oldtotallines;
if (con_totallines < numlines)
numlines = con_totallines;
numchars = oldwidth;
if (con_linewidth < numchars)
numchars = con_linewidth;
memcpy (tbuf, con->text, CON_TEXTSIZE);
memset (con->text, ' ', CON_TEXTSIZE);
for (i = 0; i < numlines; i++) {
for (j = 0; j < numchars; j++) {
con->text[(con_totallines - 1 - i) * con_linewidth + j] =
tbuf[((con->current - i + oldtotallines) %
oldtotallines) * oldwidth + j];
}
}
Con_ClearNotify ();
}
con->current = con_totallines - 1;
con->display = con->current;
}
/*
Con_CheckResize
If the line width has changed, reformat the buffer.
*/
void
Con_CheckResize (void)
{
Con_Resize (&con_main);
Con_Resize (&con_chat);
}
static void
Con_Condump_f (void)
{
int line = con->current - con->numlines;
const char *start, *end;
VFile *file;
char name[MAX_OSPATH];
if (Cmd_Argc () != 2) {
Con_Printf ("usage: condump <filename>\n");
return;
}
if (strchr (Cmd_Argv (1), '/') || strchr (Cmd_Argv (1), '\\')) {
Con_Printf ("invalid character in filename\n");
return;
}
snprintf (name, sizeof (name), "%s/%s.txt", com_gamedir, Cmd_Argv (1));
if (!(file = Qopen (name, "wt"))) {
Con_Printf ("could not open %s for writing: %s\n", name,
strerror (errno));
return;
}
while (line < con->current) {
start = &con->text[(line % con_totallines) * con_linewidth];
end = start + con_linewidth;
while (end > start && end[-1] != ' ')
end--;
Qprintf (file, "%.*s\n", (int)(end - start), start);
line++;
}
Qclose (file);
}
void
Con_Init (const char *plugin_name)
{
con_debuglog = COM_CheckParm ("-condebug");
con = &con_main;
con_linewidth = -1;
Con_CheckResize ();
Sys_SetPrintf (Con_Print);
Con_Printf ("Console initialized.\n");
// register our commands
Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f,
"Toggle the console up and down");
Cmd_AddCommand ("togglechat", Con_ToggleChat_f,
"Toggle the console up and down");
Cmd_AddCommand ("messagemode", Con_MessageMode_f,
"Prompt to send a message to everyone");
Cmd_AddCommand ("messagemode2", Con_MessageMode2_f,
"Prompt to send a message to only people on your team");
Cmd_AddCommand ("clear", Con_Clear_f, "Clear the console");
Cmd_AddCommand ("condump", Con_Condump_f, "dump the console text to a "
"file");
con_initialized = true;
}
void
Con_Init_Cvars (void)
{
con_notifytime = Cvar_Get ("con_notifytime", "3", CVAR_NONE, NULL,
"How long in seconds messages are displayed on "
"screen");
}
void
Con_Linefeed (void)
{
con->x = 0;
if (con->display == con->current)
con->display++;
con->current++;
if (con->numlines < con_totallines)
con->numlines++;
memset (&con->text[(con->current % con_totallines) * con_linewidth],
' ', con_linewidth);
}
/*
Con_Print
Handles cursor positioning, line wrapping, etc
All console printing must go through this in order to be logged to disk
If no console is visible, the notify window will pop up.
*/
void
Con_Print (const char *fmt, va_list args)
{
int mask, c, l, y;
static int cr;
static char txt[1024];
char *s;
vsnprintf (txt, sizeof (txt), fmt, args);
// log all messages to file
if (con_debuglog)
Sys_DebugLog (va ("%s/qconsole.log", com_gamedir), "%s", txt);
if (!con_initialized)
return;
s = txt;
if (s[0] == 1 || s[0] == 2) {
mask = 128; // go to colored text
s++;
} else
mask = 0;
while ((c = (byte)*s)) {
// count word length
for (l = 0; l < con_linewidth; l++)
if (s[l] <= ' ')
break;
// word wrap
if (l != con_linewidth && (con->x + l > con_linewidth))
con->x = 0;
*s++ = sys_char_map[c];
if (cr) {
con->current--;
cr = false;
}
if (!con->x) {
Con_Linefeed ();
// mark time for transparent overlay
if (con->current >= 0)
con_times[con->current % NUM_CON_TIMES] = realtime;
}
switch (c) {
case '\n':
con->x = 0;
break;
case '\r':
con->x = 0;
cr = 1;
break;
default: // display character and advance
y = con->current % con_totallines;
con->text[y * con_linewidth + con->x] = c | mask | con_ormask;
con->x++;
if (con->x >= con_linewidth)
con->x = 0;
break;
}
}
// echo to debugging console
if (txt[0] > 2)
fputs (txt, stdout);
else if (txt[0])
fputs (txt + 1, stdout);
}
/* DRAWING */
/*
Con_DrawInput
The input line scrolls horizontally if typing goes beyond the right edge
*/
void
Con_DrawInput (void)
{
char temp[MAXCMDLINE];
char *text;
int i, y;
if (key_dest != key_console && cls.state == ca_active)
return; // don't draw anything (always draw if not active)
text = strcpy (temp, key_lines[edit_line]);
// fill out remainder with spaces
for (i = strlen (text); i < MAXCMDLINE; i++)
text[i] = ' ';
// add the cursor frame
if ((int) (realtime * con_cursorspeed) & 1)
text[key_linepos] = 11;
// prestep if horizontally scrolling
if (key_linepos >= con_linewidth)
text += 1 + key_linepos - con_linewidth;
// draw it
y = con_vislines - 22;
Draw_nString (8, y, text, con_linewidth);
}
/*
Con_DrawNotify
Draws the last few lines of output transparently over the game top
*/
void
Con_DrawNotify (void)
{
char *s, *text;
float time;
int skip, i, x, v;
v = 0;
for (i = con->current - NUM_CON_TIMES + 1; i <= con->current; i++) {
if (i < 0)
continue;
time = con_times[i % NUM_CON_TIMES];
if (time == 0)
continue;
time = realtime - time;
if (time > con_notifytime->value)
continue;
text = con->text + (i % con_totallines) * con_linewidth;
clearnotify = 0;
scr_copytop = 1;
Draw_nString (8, v, text, con_linewidth);
v += 8;
}
if (key_dest == key_message) {
clearnotify = 0;
scr_copytop = 1;
if (chat_team) {
Draw_String (8, v, "say_team:");
skip = 10;
} else {
Draw_String (8, v, "say:");
skip = 5;
}
s = chat_buffer;
if (chat_bufferlen > (vid.width >> 3) - (skip + 1))
s += chat_bufferlen - ((vid.width >> 3) - (skip + 1));
x = 0;
Draw_String (skip << 3, v, s);
Draw_Character ((strlen(s) + skip) << 3, v,
10 + ((int) (realtime * con_cursorspeed) & 1));
v += 8;
}
if (v > con_notifylines)
con_notifylines = v;
}
/*
Con_DrawConsole
Draws the console with the solid background
*/
void
Con_DrawConsole (int lines)
{
char *text;
int row, rows, i, x, y;
if (lines <= 0)
return;
// draw the background
Draw_ConsoleBackground (lines);
// draw the text
con_vislines = lines;
// changed to line things up better
rows = (lines - 22) >> 3; // rows of text to draw
y = lines - 30;
// 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)
Draw_Character ((x + 1) << 3, y, '^');
y -= 8;
rows--;
}
row = con->display;
for (i = 0; i < rows; i++, y -= 8, row--) {
if (row < 0)
break;
if (con->current - row >= con_totallines)
break; // past scrollback wrap point
text = con->text + (row % con_totallines) * con_linewidth;
Draw_nString(8, y, text, con_linewidth);
}
// draw the input prompt, user text, and cursor if desired
Con_DrawInput ();
}
void
Con_DrawDownload (int lines)
{
char dlbar[1024];
const char *text;
int i, j, x, y, n;
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;
Draw_nString (8, y, dlbar, strlen (dlbar));
}
/*
Con_CompleteCommandLine
New function for tab-completion system
Added by EvilTypeGuy
Thanks to Fett erich@heintz.com
Thanks to taniwha
*/
void
Con_CompleteCommandLine (void)
{
char *s;
const char *cmd = "";
int cmd_len, c, v, a, i;
const char **list[3] = {0, 0, 0};
s = key_lines[edit_line] + 1;
if (*s == '\\' || *s == '/')
s++;
// Count number of possible matches
c = Cmd_CompleteCountPossible(s);
v = Cvar_CompleteCountPossible(s);
a = Cmd_CompleteAliasCountPossible(s);
if (!(c + v + a)) // No possible matches
return;
if (c + v + a == 1) {
if (c)
list[0] = Cmd_CompleteBuildList(s);
else if (v)
list[0] = Cvar_CompleteBuildList(s);
else
list[0] = Cmd_CompleteAliasBuildList(s);
cmd = *list[0];
cmd_len = strlen (cmd);
} else {
if (c)
cmd = *(list[0] = Cmd_CompleteBuildList(s));
if (v)
cmd = *(list[1] = Cvar_CompleteBuildList(s));
if (a)
cmd = *(list[2] = Cmd_CompleteAliasBuildList(s));
cmd_len = strlen (s);
do {
for (i = 0; i < 3; i++) {
char ch = cmd[cmd_len];
const char **l = list[i];
if (l) {
while (*l && (*l)[cmd_len] == ch)
l++;
if (*l)
break;
}
}
if (i == 3)
cmd_len++;
} while (i == 3);
// 'quakebar'
Con_Printf("\n\35");
for (i = 0; i < con_linewidth - 4; i++)
Con_Printf("\36");
Con_Printf("\37\n");
// Print Possible Commands
if (c) {
Con_Printf("%i possible command%s\n", c, (c > 1) ? "s: " : ":");
Con_DisplayList(list[0], con_linewidth);
}
if (v) {
Con_Printf("%i possible variable%s\n", v, (v > 1) ? "s: " : ":");
Con_DisplayList(list[1], con_linewidth);
}
if (a) {
Con_Printf("%i possible aliases%s\n", a, (a > 1) ? "s: " : ":");
Con_DisplayList(list[2], con_linewidth);
}
}
if (cmd) {
key_lines[edit_line][1] = '/';
strncpy(key_lines[edit_line] + 2, cmd, cmd_len);
key_linepos = cmd_len + 2;
if (c + v + a == 1) {
key_lines[edit_line][key_linepos] = ' ';
key_linepos++;
}
key_lines[edit_line][key_linepos] = 0;
}
for (i = 0; i < 3; i++)
if (list[i])
free (list[i]);
}