1 /* $Id: console.c,v 1.18 2003-11-26 12:39:00 btb Exp $ */
4 * Code for controlling the console
24 #include "CON_console.h"
38 int text_console_enabled = 1;
41 #define text_console_enabled (!isvga())
44 cvar_t *cvar_vars = NULL;
46 /* Console specific cvars */
47 /* How discriminating we are about which messages are displayed */
48 cvar_t con_threshold = {"con_threshold", "0",};
50 /* Private console stuff */
51 #define CON_NUM_LINES 40
53 #define CON_LINE_LEN 40
54 static char con_display[40][40];
55 static int con_line; /* Current display line */
59 static int con_initialized;
61 ConsoleInformation *Console;
63 void con_parse(ConsoleInformation *console, char *command);
67 * con_free - Free the console.
80 * con_init - Initialise the console.
85 /* Initialise the cvars */
86 cvar_registervariable (&con_threshold);
92 #define CON_BG_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
93 #define CON_BG_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
94 #define CON_BG ((SWIDTH>=640)?CON_BG_HIRES:CON_BG_LORES)
96 void con_background(char *filename)
102 gr_init_bitmap_data(&bmp);
103 pcx_error = pcx_read_bitmap(filename, &bmp, BM_LINEAR, pal);
104 Assert(pcx_error == PCX_ERROR_NONE);
105 gr_remap_bitmap_good(&bmp, pal, -1, -1);
106 CON_Background(Console, &bmp);
107 gr_free_bitmap_data(&bmp);
111 void con_init_real(void)
113 Console = CON_Init(SMALL_FONT, grd_curscreen, CON_NUM_LINES, 0, 0, SWIDTH, SHEIGHT / 2);
117 CON_SetExecuteFunction(Console, con_parse);
119 con_background(CON_BG);
128 void con_resize(void)
131 if (!con_initialized)
134 CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1);
135 CON_Resize(Console, 0, 0, SWIDTH, SHEIGHT / 2);
136 con_background(CON_BG);
141 * con_printf - Print a message to the console.
144 void con_printf(int priority, char *fmt, ...)
149 if (priority <= ((int)con_threshold.value))
151 va_start (arglist, fmt);
152 vsprintf (buffer, fmt, arglist);
157 CON_Out(Console, buffer);
160 /* for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
162 memcpy(con_display, &buffer[i], min(80, l-i));
165 if (text_console_enabled)
167 /* Produce a sanitised version and send it to the console */
192 * con_update - Check for new console input. If it's there, use it.
195 void con_update(void)
198 char buffer[CMD_MAX_LENGTH], *t;
200 /* Check for new input */
201 t = fgets(buffer, sizeof(buffer), stdin);
202 if (t == NULL) return;
210 int con_events(int key)
213 return CON_Events(key);
221 * cvar_registervariable - Register a CVar
224 void cvar_registervariable (cvar_t *cvar)
228 Assert(cvar != NULL);
231 cvar->value = strtod(cvar->string, (char **) NULL);
233 if (cvar_vars == NULL)
238 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
244 * cvar_set - Set a CVar's value
247 void cvar_set (char *cvar_name, char *value)
251 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
252 if (!strcmp(cvar_name, ptr->name)) break;
254 if (ptr == NULL) return; // If we didn't find the cvar, give up
256 ptr->value = strtod(value, (char **) NULL);
260 * cvar() - Get a CVar's value
263 float cvar (char *cvar_name)
267 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
268 if (!strcmp(cvar_name, ptr->name)) break;
270 if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
276 /* ==========================================================================
278 * ==========================================================================
283 CON_DrawConsole(Console);
286 char buffer[CON_LINE_LEN+1];
288 for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
290 memcpy(buffer, con_display[i], CON_LINE_LEN);
291 buffer[CON_LINE_LEN] = 0;
292 gr_string(1,j*10,buffer);
301 if (!con_initialized)
305 CON_Topmost(Console);
310 void con_parse(ConsoleInformation *console, char *command)