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 ConsoleInformation *Console;
61 void con_parse(ConsoleInformation *console, char *command);
65 * con_free - Free the console.
76 * con_init - Initialise the console.
81 grs_screen fake_screen;
84 fake_screen.sc_w = 200;
85 fake_screen.sc_h = 100;
89 Console = CON_Init(&fake_font, &fake_screen, CON_NUM_LINES, 0, 0, 320, 200);
91 CON_SetExecuteFunction(Console, con_parse);
94 /* Initialise the cvars */
95 cvar_registervariable (&con_threshold);
104 #define CON_BG_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
105 #define CON_BG_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
106 #define CON_BG ((SWIDTH>=640)?CON_BG_HIRES:CON_BG_LORES)
108 void con_background(char *filename)
114 gr_init_bitmap_data(&bmp);
115 pcx_error = pcx_read_bitmap(filename, &bmp, BM_LINEAR, pal);
116 Assert(pcx_error == PCX_ERROR_NONE);
117 gr_remap_bitmap_good(&bmp, pal, -1, -1);
118 CON_Background(Console, &bmp);
119 gr_free_bitmap_data(&bmp);
123 void con_init_gfx(void)
125 CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1);
126 CON_Transfer(Console, grd_curscreen, 0, 0, SWIDTH, SHEIGHT / 2);
128 con_background(CON_BG);
133 void con_resize(void)
136 CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1);
137 CON_Resize(Console, 0, 0, SWIDTH, SHEIGHT / 2);
138 con_background(CON_BG);
143 * con_printf - Print a message to the console.
146 void con_printf(int priority, char *fmt, ...)
151 if (priority <= ((int)con_threshold.value))
153 va_start (arglist, fmt);
154 vsprintf (buffer, fmt, arglist);
158 CON_Out(Console, buffer);
161 /* for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
163 memcpy(con_display, &buffer[i], min(80, l-i));
166 if (text_console_enabled)
168 /* Produce a sanitised version and send it to the console */
187 printf("%s", buffer);
193 * con_update - Check for new console input. If it's there, use it.
196 void con_update(void)
199 char buffer[CMD_MAX_LENGTH], *t;
201 /* Check for new input */
202 t = fgets(buffer, sizeof(buffer), stdin);
203 if (t == NULL) return;
211 int con_events(int key)
214 return CON_Events(key);
222 * cvar_registervariable - Register a CVar
225 void cvar_registervariable (cvar_t *cvar)
229 Assert(cvar != NULL);
232 cvar->value = strtod(cvar->string, (char **) NULL);
234 if (cvar_vars == NULL)
239 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
245 * cvar_set - Set a CVar's value
248 void cvar_set (char *cvar_name, char *value)
252 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
253 if (!strcmp(cvar_name, ptr->name)) break;
255 if (ptr == NULL) return; // If we didn't find the cvar, give up
257 ptr->value = strtod(value, (char **) NULL);
261 * cvar() - Get a CVar's value
264 float cvar (char *cvar_name)
268 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
269 if (!strcmp(cvar_name, ptr->name)) break;
271 if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
277 /* ==========================================================================
279 * ==========================================================================
284 CON_DrawConsole(Console);
287 char buffer[CON_LINE_LEN+1];
289 for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
291 memcpy(buffer, con_display[i], CON_LINE_LEN);
292 buffer[CON_LINE_LEN] = 0;
293 gr_string(1,j*10,buffer);
303 CON_Topmost(Console);
308 void con_parse(ConsoleInformation *console, char *command)