Die Konsole in Sachen Formatierung und Kommentaren aufgeräumt

This commit is contained in:
Yamagi Burmeister 2010-06-19 07:15:35 +00:00
parent 179b5d541c
commit a80fc2949c
2 changed files with 241 additions and 336 deletions

View File

@ -1,83 +1,73 @@
/*
Copyright (C) 1997-2001 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 the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// console.c
* Copyright (C) 1997-2001 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 the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* This file implements the console
*
* =======================================================================
*/
#include "../header/client.h"
#include <time.h>
console_t con;
cvar_t *con_notifytime;
#define MAXCMDLINE 256
#define MAXCMDLINE 256
extern char key_lines[32][MAXCMDLINE];
extern int edit_line;
extern int key_linepos;
void DrawString (int x, int y, char *s)
{
while (*s)
{
void DrawString (int x, int y, char *s) {
while (*s) {
re.DrawChar (x, y, *s);
x+=8;
s++;
}
}
void DrawAltString (int x, int y, char *s)
{
while (*s)
{
void DrawAltString (int x, int y, char *s) {
while (*s) {
re.DrawChar (x, y, *s ^ 0x80);
x+=8;
s++;
}
}
void Key_ClearTyping (void)
{
key_lines[edit_line][1] = 0; // clear any typing
void Key_ClearTyping (void) {
key_lines[edit_line][1] = 0; /* clear any typing */
key_linepos = 1;
}
/*
================
Con_ToggleConsole_f
================
*/
void Con_ToggleConsole_f (void)
{
SCR_EndLoadingPlaque (); // get rid of loading plaque
void Con_ToggleConsole_f (void) {
SCR_EndLoadingPlaque (); /* get rid of loading plaque */
if (cl.attractloop)
{
if (cl.attractloop) {
Cvar_SetValue("windowed_mouse", 0);
Cbuf_AddText("killserver\n");
return;
}
if (cls.state == ca_disconnected)
{ // start the demo loop again
if (cls.state == ca_disconnected) {
/* start the demo loop again */
Cvar_SetValue("windowed_mouse", 1);
Cbuf_AddText ("d1\n");
return;
@ -86,73 +76,50 @@ void Con_ToggleConsole_f (void)
Key_ClearTyping ();
Con_ClearNotify ();
if (cls.key_dest == key_console)
{
if (cls.key_dest == key_console) {
M_ForceMenuOff ();
Cvar_Set ("paused", "0");
}
else
{
} else {
M_ForceMenuOff ();
cls.key_dest = key_console;
if (Cvar_VariableValue ("maxclients") == 1
&& Com_ServerState ())
&& Com_ServerState ())
Cvar_Set ("paused", "1");
}
}
/*
================
Con_ToggleChat_f
================
*/
void Con_ToggleChat_f (void)
{
void Con_ToggleChat_f (void) {
Key_ClearTyping ();
if (cls.key_dest == key_console)
{
if (cls.state == ca_active)
{
if (cls.key_dest == key_console) {
if (cls.state == ca_active) {
M_ForceMenuOff ();
cls.key_dest = key_game;
}
}
else
} else
cls.key_dest = key_console;
Con_ClearNotify ();
}
/*
================
Con_Clear_f
================
*/
void Con_Clear_f (void)
{
void Con_Clear_f (void) {
memset (con.text, ' ', CON_TEXTSIZE);
}
/*
================
Con_Dump_f
Save the console contents out to a file
================
*/
void Con_Dump_f (void)
{
* Save the console contents out to a file
*/
void Con_Dump_f (void) {
int l, x;
char *line;
FILE *f;
char buffer[1024];
char name[MAX_OSPATH];
if (Cmd_Argc() != 2)
{
if (Cmd_Argc() != 2) {
Com_Printf ("usage: condump <filename>\n");
return;
}
@ -162,36 +129,39 @@ void Con_Dump_f (void)
Com_Printf ("Dumped console text to %s.\n", name);
FS_CreatePath (name);
f = fopen (name, "w");
if (!f)
{
if (!f) {
Com_Printf ("ERROR: couldn't open.\n");
return;
}
// skip empty lines
for (l = con.current - con.totallines + 1 ; l <= con.current ; l++)
{
/* skip empty lines */
for (l = con.current - con.totallines + 1 ; l <= con.current ; l++) {
line = con.text + (l%con.totallines)*con.linewidth;
for (x=0 ; x<con.linewidth ; x++)
if (line[x] != ' ')
break;
if (x != con.linewidth)
break;
}
// write the remaining lines
/* write the remaining lines */
buffer[con.linewidth] = 0;
for ( ; l <= con.current ; l++)
{
for ( ; l <= con.current ; l++) {
line = con.text + (l%con.totallines)*con.linewidth;
strncpy (buffer, line, con.linewidth);
for (x=con.linewidth-1 ; x>=0 ; x--)
{
for (x=con.linewidth-1 ; x>=0 ; x--) {
if (buffer[x] == ' ')
buffer[x] = 0;
else
break;
}
for (x=0; buffer[x]; x++)
buffer[x] &= 0x7f;
@ -201,52 +171,27 @@ void Con_Dump_f (void)
fclose (f);
}
/*
================
Con_ClearNotify
================
*/
void Con_ClearNotify (void)
{
void Con_ClearNotify (void) {
int i;
for (i=0 ; i<NUM_CON_TIMES ; i++)
con.times[i] = 0;
}
/*
================
Con_MessageMode_f
================
*/
void Con_MessageMode_f (void)
{
void Con_MessageMode_f (void) {
chat_team = false;
cls.key_dest = key_message;
}
/*
================
Con_MessageMode2_f
================
*/
void Con_MessageMode2_f (void)
{
void Con_MessageMode2_f (void) {
chat_team = true;
cls.key_dest = key_message;
}
/*
================
Con_CheckResize
If the line width has changed, reformat the buffer.
================
*/
void Con_CheckResize (void)
{
* If the line width has changed, reformat the buffer.
*/
void Con_CheckResize (void) {
int i, j, width, oldwidth, oldtotallines, numlines, numchars;
char tbuf[CON_TEXTSIZE];
@ -255,15 +200,14 @@ void Con_CheckResize (void)
if (width == con.linewidth)
return;
if (width < 1) // video hasn't been initialized yet
{
/* video hasn't been initialized yet */
if (width < 1) {
width = 38;
con.linewidth = width;
con.totallines = CON_TEXTSIZE / con.linewidth;
memset (con.text, ' ', CON_TEXTSIZE);
}
else
{
} else {
oldwidth = con.linewidth;
con.linewidth = width;
oldtotallines = con.totallines;
@ -281,13 +225,11 @@ void Con_CheckResize (void)
memcpy (tbuf, con.text, CON_TEXTSIZE);
memset (con.text, ' ', CON_TEXTSIZE);
for (i=0 ; i<numlines ; i++)
{
for (j=0 ; j<numchars ; j++)
{
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];
tbuf[((con.current - i + oldtotallines) %
oldtotallines) * oldwidth + j];
}
}
@ -298,23 +240,14 @@ void Con_CheckResize (void)
con.display = con.current;
}
/*
================
Con_Init
================
*/
void Con_Init (void)
{
void Con_Init (void) {
con.linewidth = -1;
Con_CheckResize ();
Com_Printf ("Console initialized.\n");
//
// register our commands
//
/* register our commands */
con_notifytime = Cvar_Get ("con_notifytime", "3", 0);
Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f);
@ -326,33 +259,23 @@ void Con_Init (void)
con.initialized = true;
}
/*
===============
Con_Linefeed
===============
*/
void Con_Linefeed (void)
{
void Con_Linefeed (void) {
con.x = 0;
if (con.display == con.current)
con.display++;
con.current++;
memset (&con.text[(con.current%con.totallines)*con.linewidth]
, ' ', 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 text will appear at the top of the game window
================
*/
void Con_Print (char *txt)
{
* 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 text will appear at the top of the game window
*/
void Con_Print (char *txt) {
int y;
int c, l;
static int cr;
@ -361,81 +284,74 @@ void Con_Print (char *txt)
if (!con.initialized)
return;
if (txt[0] == 1 || txt[0] == 2)
{
mask = 128; // go to colored text
if (txt[0] == 1 || txt[0] == 2) {
mask = 128; /* go to colored text */
txt++;
}
else
} else
mask = 0;
while ( (c = *txt) )
{
// count word length
while ( (c = *txt) ) {
/* count word length */
for (l=0 ; l< con.linewidth ; l++)
if ( txt[l] <= ' ')
break;
// word wrap
/* word wrap */
if (l != con.linewidth && (con.x + l > con.linewidth) )
con.x = 0;
txt++;
if (cr)
{
if (cr) {
con.current--;
cr = false;
}
if (!con.x)
{
if (!con.x) {
Con_Linefeed ();
// mark time for transparent overlay
/* mark time for transparent overlay */
if (con.current >= 0)
con.times[con.current % NUM_CON_TIMES] = cls.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)
switch (c) {
case '\n':
con.x = 0;
break;
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;
}
}
}
/*
==============
Con_CenteredPrint
==============
*/
void Con_CenteredPrint (char *text)
{
void Con_CenteredPrint (char *text) {
int l;
char buffer[1024];
l = strlen(text);
l = (con.linewidth-l)/2;
if (l < 0)
l = 0;
memset (buffer, ' ', l);
strcpy (buffer+l, text);
strcat (buffer, "\n");
@ -443,65 +359,49 @@ void Con_CenteredPrint (char *text)
}
/*
==============================================================================
DRAWING
==============================================================================
*/
/*
================
Con_DrawInput
The input line scrolls horizontally if typing goes beyond the right edge
================
*/
void Con_DrawInput (void)
{
* The input line scrolls horizontally if
* typing goes beyond the right edge
*/
void Con_DrawInput (void) {
int y;
int i;
char *text;
if (cls.key_dest == key_menu)
return;
/* don't draw anything (always draw if not active) */
if (cls.key_dest != key_console && cls.state == ca_active)
return; // don't draw anything (always draw if not active)
return;
text = key_lines[edit_line];
// add the cursor frame
/* add the cursor frame */
text[key_linepos] = 10+((int)(cls.realtime>>8)&1);
// fill out remainder with spaces
/* fill out remainder with spaces */
for (i=key_linepos+1 ; i< con.linewidth ; i++)
text[i] = ' ';
// 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-16;
for (i=0 ; i<con.linewidth ; i++)
re.DrawChar ( (i+1)<<3, con.vislines - 22, text[i]);
re.DrawChar ( (i+1)<<3, con.vislines - 22, text[i]);
// remove cursor
/* remove cursor */
key_lines[edit_line][key_linepos] = 0;
}
/*
================
Con_DrawNotify
Draws the last few lines of output transparently over the game top
================
*/
void Con_DrawNotify (void)
{
* Draws the last few lines of output transparently over the game top
*/
void Con_DrawNotify (void) {
int x, v;
char *text;
int i;
@ -510,67 +410,65 @@ void Con_DrawNotify (void)
int skip;
v = 0;
for (i= con.current-NUM_CON_TIMES+1 ; i<=con.current ; i++)
{
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 = cls.realtime - time;
if (time > con_notifytime->value*1000)
continue;
text = con.text + (i % con.totallines)*con.linewidth;
for (x = 0 ; x < con.linewidth ; x++)
re.DrawChar ( (x+1)<<3, v, text[x]);
re.DrawChar ( (x+1)<<3, v, text[x]);
v += 8;
}
if (cls.key_dest == key_message)
{
if (chat_team)
{
if (cls.key_dest == key_message) {
if (chat_team) {
DrawString (8, v, "say_team:");
skip = 11;
}
else
{
} else {
DrawString (8, v, "say:");
skip = 5;
}
s = chat_buffer;
if (chat_bufferlen > (viddef.width>>3)-(skip+1))
s += chat_bufferlen - ((viddef.width>>3)-(skip+1));
x = 0;
while(s[x])
{
while(s[x]) {
re.DrawChar ( (x+skip)<<3, v, s[x]);
x++;
}
re.DrawChar ( (x+skip)<<3, v, 10+((cls.realtime>>8)&1));
v += 8;
}
if (v)
{
if (v) {
SCR_AddDirtyPoint (0,0);
SCR_AddDirtyPoint (viddef.width-1, v);
}
}
/*
================
Con_DrawConsole
Draws the console with the solid background
================
*/
void Con_DrawConsole (float frac)
{
* Draws the console with the solid background
*/
void Con_DrawConsole (float frac) {
int i, j, x, y, n;
int rows;
char *text;
@ -578,60 +476,64 @@ void Con_DrawConsole (float frac)
int lines;
char version[48];
char dlbar[1024];
char timebuf[48];
char timebuf[48];
char tmpbuf[48];
time_t t;
struct tm *today;
struct tm *today;
lines = viddef.height * frac;
if (lines <= 0)
return;
if (lines > viddef.height)
lines = viddef.height;
// draw the background
/* draw the background */
re.DrawStretchPic (0, -viddef.height+lines, viddef.width, viddef.height, "conback");
SCR_AddDirtyPoint (0,0);
SCR_AddDirtyPoint (viddef.width-1,lines-1);
Com_sprintf (version, sizeof(version), "Yamagi Quake II v%4.2f",VERSION);
for (x=0 ; x<21 ; x++)
re.DrawChar (viddef.width-173+x*8, lines-35, 128 + version[x] );
t = time(NULL);
t = time(NULL);
today = localtime(&t);
strftime (timebuf, sizeof(timebuf), "%H:%M:%S - %m/%d/%Y", today);
Com_sprintf (tmpbuf, sizeof(tmpbuf), "%s",timebuf);
for (x=0 ; x<21 ; x++)
re.DrawChar (viddef.width-173+x*8, lines-25, 128 + tmpbuf[x] );
// draw the text
/* draw the text */
con.vislines = lines;
rows = (lines-22)>>3; // rows of text to draw
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
/* 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)
re.DrawChar ( (x+1)<<3, y, '^');
y -= 8;
rows--;
}
row = con.display;
for (i=0 ; i<rows ; i++, y-=8, row--)
{
for (i=0 ; i<rows ; i++, y-=8, row--) {
if (row < 0)
break;
if (con.current - row >= con.totallines)
break; // past scrollback wrap point
break; /* past scrollback wrap point */
text = con.text + (row % con.totallines)*con.linewidth;
@ -639,53 +541,57 @@ void Con_DrawConsole (float frac)
re.DrawChar ( (x+1)<<3, y, text[x]);
}
//ZOID
// draw the download bar
// figure out width
/* draw the download bar, figure out width */
if (cls.download) {
if ((text = strrchr(cls.downloadname, '/')) != NULL)
text++;
else
text = 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;
strcat(dlbar, "...");
} else
strcpy(dlbar, text);
strcat(dlbar, ": ");
i = strlen(dlbar);
dlbar[i++] = '\x80';
// where's the dot go?
/* where's the dot gone? */
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;
sprintf(dlbar + strlen(dlbar), " %02d%%", cls.downloadpercent);
// draw it
/* draw it */
y = con.vislines-12;
for (i = 0; i < strlen(dlbar); i++)
re.DrawChar ( (i+1)<<3, y, dlbar[i]);
}
//ZOID
// draw the input prompt, user text, and cursor if desired
/* draw the input prompt, user text, and cursor if desired */
Con_DrawInput ();
}

View File

@ -1,56 +1,55 @@
/*
Copyright (C) 1997-2001 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 the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//
// console
//
#define NUM_CON_TIMES 4
* Copyright (C) 1997-2001 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 the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* Header file for the console
*
* =======================================================================
*/
#define NUM_CON_TIMES 4
#define CON_TEXTSIZE 32768
typedef struct
{
typedef struct {
qboolean initialized;
char text[CON_TEXTSIZE];
int current; // line where next message will be printed
int x; // offset in current line for next print
int display; // bottom of console displays this line
int current; /* line where next message will be printed */
int x; /* offset in current line for next print */
int display; /* bottom of console displays this line */
int ormask; // high bit mask for colored characters
int ormask; /* high bit mask for colored characters */
int linewidth; // characters across screen
int totallines; // total lines in console scrollback
int linewidth; /* characters across screen */
int totallines; /* total lines in console scrollback */
float cursorspeed;
int vislines;
float times[NUM_CON_TIMES]; // cls.realtime time the line was generated
// for transparent notify lines
float times[NUM_CON_TIMES]; /* cls.realtime time the line was generated */
} console_t;
extern console_t con;
void Con_DrawCharacter (int cx, int line, int num);
void Con_CheckResize (void);
void Con_Init (void);
void Con_DrawConsole (float frac);