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())
45 cvar_t *cvar_vars = NULL;
47 /* Console specific cvars */
48 /* How discriminating we are about which messages are displayed */
49 cvar_t con_threshold = {"con_threshold", "0",};
51 /* Private console stuff */
52 #define CON_NUM_LINES 40
54 #define CON_LINE_LEN 40
55 static char con_display[40][40];
56 static int con_line; /* Current display line */
60 ConsoleInformation *Console;
62 void con_parse(ConsoleInformation *console, char *command);
67 * con_free - Free the console.
78 * con_init - Initialise the console.
83 grs_screen fake_screen;
86 fake_screen.sc_w = 320;
87 fake_screen.sc_h = 200;
91 Console = CON_Init(&fake_font, &fake_screen, CON_NUM_LINES, 0, 0, 320, 200);
93 CON_SetExecuteFunction(Console, con_parse);
94 CON_SetHideFunction(Console, con_hide);
96 /* Initialise the cvars */
97 cvar_registervariable (&con_threshold);
106 #define CON_BG_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
107 #define CON_BG_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
108 #define CON_BG ((SWIDTH>=640)?CON_BG_HIRES:CON_BG_LORES)
110 void con_background(char *filename)
116 gr_init_bitmap_data(&bmp);
117 pcx_error = pcx_read_bitmap(filename, &bmp, BM_LINEAR, pal);
118 Assert(pcx_error == PCX_ERROR_NONE);
119 gr_remap_bitmap_good(&bmp, pal, -1, -1);
120 CON_Background(Console, &bmp);
121 gr_free_bitmap_data(&bmp);
125 void con_init_gfx(void)
127 CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1);
128 CON_Transfer(Console, grd_curscreen, 0, 0, SWIDTH, SHEIGHT / 2);
130 con_background(CON_BG);
135 void con_resize(void)
138 CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1);
139 CON_Resize(Console, 0, 0, SWIDTH, SHEIGHT / 2);
140 con_background(CON_BG);
145 * con_printf - Print a message to the console.
148 void con_printf(int priority, char *fmt, ...)
153 if (priority <= ((int)con_threshold.value))
155 va_start (arglist, fmt);
156 vsprintf (buffer, fmt, arglist);
160 CON_Out(Console, buffer);
163 /* for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
165 memcpy(con_display, &buffer[i], min(80, l-i));
168 if (text_console_enabled)
170 /* Produce a sanitised version and send it to the console */
189 printf("%s", buffer);
195 * con_update - Check for new console input. If it's there, use it.
198 void con_update(void)
201 char buffer[CMD_MAX_LENGTH], *t;
203 /* Check for new input */
204 t = fgets(buffer, sizeof(buffer), stdin);
205 if (t == NULL) return;
213 int con_events(int key)
216 return CON_Events(key);
224 * cvar_registervariable - Register a CVar
227 void cvar_registervariable (cvar_t *cvar)
231 Assert(cvar != NULL);
234 cvar->value = strtod(cvar->string, (char **) NULL);
236 if (cvar_vars == NULL)
241 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
247 * cvar_set - Set a CVar's value
250 void cvar_set (char *cvar_name, char *value)
254 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
255 if (!strcmp(cvar_name, ptr->name)) break;
257 if (ptr == NULL) return; // If we didn't find the cvar, give up
259 ptr->value = strtod(value, (char **) NULL);
263 * cvar() - Get a CVar's value
266 float cvar (char *cvar_name)
270 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
271 if (!strcmp(cvar_name, ptr->name)) break;
273 if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
279 /* ==========================================================================
281 * ==========================================================================
286 CON_DrawConsole(Console);
289 char buffer[CON_LINE_LEN+1];
291 for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
293 memcpy(buffer, con_display[i], CON_LINE_LEN);
294 buffer[CON_LINE_LEN] = 0;
295 gr_string(1,j*10,buffer);
306 CON_Topmost(Console);
316 void con_parse(ConsoleInformation *console, char *command)