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);
66 /* Free the console */
74 /* Initialise the console */
77 grs_screen fake_screen;
80 fake_screen.sc_w = 320;
81 fake_screen.sc_h = 200;
85 Console = CON_Init(&fake_font, &fake_screen, CON_NUM_LINES, 0, 0, 320, 200);
87 CON_SetExecuteFunction(Console, con_parse);
88 CON_SetHideFunction(Console, con_hide);
93 /* Initialise the cvars */
94 cvar_registervariable (&con_threshold);
101 #define CON_BG_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
102 #define CON_BG_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
103 #define CON_BG ((SWIDTH>=640)?CON_BG_HIRES:CON_BG_LORES)
105 void con_background(char *filename)
111 gr_init_bitmap_data(&bmp);
112 pcx_error = pcx_read_bitmap(filename, &bmp, BM_LINEAR, pal);
113 Assert(pcx_error == PCX_ERROR_NONE);
114 gr_remap_bitmap_good(&bmp, pal, -1, -1);
115 CON_Background(Console, &bmp);
116 gr_free_bitmap_data(&bmp);
120 void con_init_gfx(void)
122 CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1);
123 CON_Transfer(Console, grd_curscreen, 0, 0, SWIDTH, SHEIGHT / 2);
125 con_background(CON_BG);
130 void con_resize(void)
133 CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1);
134 CON_Resize(Console, 0, 0, SWIDTH, SHEIGHT / 2);
135 con_background(CON_BG);
139 /* Print a message to the console */
140 void con_printf(int priority, char *fmt, ...)
145 if (priority <= ((int)con_threshold.value))
147 va_start (arglist, fmt);
148 vsprintf (buffer, fmt, arglist);
152 CON_Out(Console, buffer);
155 /* for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
157 memcpy(con_display, &buffer[i], min(80, l-i));
160 if (text_console_enabled)
162 /* Produce a sanitised version and send it to the standard output */
181 printf("%s", buffer);
186 /* Check for new console input. If it's there, use it */
187 void con_update(void)
190 char buffer[CMD_MAX_LENGTH], *t;
192 /* Check for new input */
193 t = fgets(buffer, sizeof(buffer), stdin);
194 if (t == NULL) return;
202 int con_events(int key)
205 return CON_Events(key);
212 /* Register a CVar */
213 void cvar_registervariable (cvar_t *cvar)
217 Assert(cvar != NULL);
220 cvar->value = strtod(cvar->string, (char **) NULL);
222 if (cvar_vars == NULL)
227 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
232 /* Set a CVar's value */
233 void cvar_set (char *cvar_name, char *value)
237 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
238 if (!strcmp(cvar_name, ptr->name)) break;
240 if (ptr == NULL) return; // If we didn't find the cvar, give up
242 ptr->value = strtod(value, (char **) NULL);
245 /* Get a CVar's value */
246 float cvar (char *cvar_name)
250 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
251 if (!strcmp(cvar_name, ptr->name)) break;
253 if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
259 /* Draw the console */
263 CON_DrawConsole(Console);
266 char buffer[CON_LINE_LEN+1];
268 for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
270 memcpy(buffer, con_display[i], CON_LINE_LEN);
271 buffer[CON_LINE_LEN] = 0;
272 gr_string(1,j*10,buffer);
278 /* Show the console */
284 CON_Topmost(Console);
294 void con_parse(ConsoleInformation *console, char *command)