1 /* $Id: console.c,v 1.16 2003-06-18 08:05:17 btb Exp $ */
4 * FIXME: put description here
22 #include "CON_console.h"
36 int text_console_enabled = 1;
39 #define text_console_enabled (!isvga())
42 cvar_t *cvar_vars = NULL;
44 /* Console specific cvars */
45 /* How discriminating we are about which messages are displayed */
46 cvar_t con_threshold = {"con_threshold", "0",};
48 /* Private console stuff */
49 #define CON_NUM_LINES 40
51 #define CON_LINE_LEN 40
52 static char con_display[40][40];
53 static int con_line; /* Current display line */
57 static int con_initialized;
59 ConsoleInformation *Console;
61 void con_parse(ConsoleInformation *console, char *command);
65 * con_free - Free the console.
78 * con_init - Initialise the console.
83 /* Initialise the cvars */
84 cvar_registervariable (&con_threshold);
90 #define CON_BG_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
91 #define CON_BG_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
92 #define CON_BG ((SWIDTH>=640)?CON_BG_HIRES:CON_BG_LORES)
94 void con_background(char *filename)
100 gr_init_bitmap_data(&bmp);
101 pcx_error = pcx_read_bitmap(filename, &bmp, BM_LINEAR, pal);
102 Assert(pcx_error == PCX_ERROR_NONE);
103 gr_remap_bitmap_good(&bmp, pal, -1, -1);
104 CON_Background(Console, &bmp);
105 gr_free_bitmap_data(&bmp);
109 void con_init_real(void)
111 Console = CON_Init(SMALL_FONT, grd_curscreen, CON_NUM_LINES, 0, 0, SWIDTH, SHEIGHT / 2);
115 CON_SetExecuteFunction(Console, con_parse);
117 con_background(CON_BG);
126 void con_resize(void)
129 if (!con_initialized)
132 CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1);
133 CON_Resize(Console, 0, 0, SWIDTH, SHEIGHT / 2);
134 con_background(CON_BG);
139 * con_printf - Print a message to the console.
142 void con_printf(int priority, char *fmt, ...)
147 if (priority <= ((int)con_threshold.value))
149 va_start (arglist, fmt);
150 vsprintf (buffer, fmt, arglist);
155 CON_Out(Console, buffer);
158 /* for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
160 memcpy(con_display, &buffer[i], min(80, l-i));
163 if (text_console_enabled)
165 /* Produce a sanitised version and send it to the console */
190 * con_update - Check for new console input. If it's there, use it.
193 void con_update(void)
196 char buffer[CMD_MAX_LENGTH], *t;
198 /* Check for new input */
199 t = fgets(buffer, sizeof(buffer), stdin);
200 if (t == NULL) return;
208 int con_events(int key)
211 return CON_Events(key);
219 * cvar_registervariable - Register a CVar
222 void cvar_registervariable (cvar_t *cvar)
226 Assert(cvar != NULL);
229 cvar->value = strtod(cvar->string, (char **) NULL);
231 if (cvar_vars == NULL)
236 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
242 * cvar_set - Set a CVar's value
245 void cvar_set (char *cvar_name, char *value)
249 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
250 if (!strcmp(cvar_name, ptr->name)) break;
252 if (ptr == NULL) return; // If we didn't find the cvar, give up
254 ptr->value = strtod(value, (char **) NULL);
258 * cvar() - Get a CVar's value
261 float cvar (char *cvar_name)
265 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
266 if (!strcmp(cvar_name, ptr->name)) break;
268 if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
274 /* ==========================================================================
276 * ==========================================================================
281 CON_DrawConsole(Console);
284 char buffer[CON_LINE_LEN+1];
286 for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
288 memcpy(buffer, con_display[i], CON_LINE_LEN);
289 buffer[CON_LINE_LEN] = 0;
290 gr_string(1,j*10,buffer);
299 if (!con_initialized)
303 CON_Topmost(Console);
308 void con_parse(ConsoleInformation *console, char *command)