1 /* $Id: console.c,v 1.14 2003-06-06 19:04:27 btb Exp $ */
4 * FIXME: put description here
21 #include "CON_console.h"
35 int text_console_enabled = 1;
38 #define text_console_enabled (!isvga())
41 cvar_t *cvar_vars = NULL;
43 /* Console specific cvars */
44 /* How discriminating we are about which messages are displayed */
45 cvar_t con_threshold = {"con_threshold", "0",};
47 /* Private console stuff */
48 #define CON_NUM_LINES 40
50 #define CON_LINE_LEN 40
51 static char con_display[40][40];
52 static int con_line; /* Current display line */
56 static int con_initialized;
58 ConsoleInformation *Console;
60 void con_parse(ConsoleInformation *console, char *command);
65 * con_free - Free the console.
76 * con_init - Initialise the console.
81 /* Initialise the cvars */
82 cvar_registervariable (&con_threshold);
88 #define CON_BG_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
89 #define CON_BG_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
90 #define CON_BG ((SWIDTH>=640)?CON_BG_HIRES:CON_BG_LORES)
92 void con_background(char *filename)
98 gr_init_bitmap_data(&bmp);
99 pcx_error = pcx_read_bitmap(filename, &bmp, BM_LINEAR, pal);
100 Assert(pcx_error == PCX_ERROR_NONE);
101 gr_remap_bitmap_good(&bmp, pal, -1, -1);
102 CON_Background(Console, &bmp);
103 gr_free_bitmap_data(&bmp);
107 void con_init_real(void)
109 Console = CON_Init(SMALL_FONT, grd_curscreen, CON_NUM_LINES, 0, 0, SWIDTH, SHEIGHT / 2);
113 CON_SetExecuteFunction(Console, con_parse);
115 con_background(CON_BG);
122 void con_resize(void)
124 if (!con_initialized)
127 CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1);
128 CON_Resize(Console, 0, 0, SWIDTH, SHEIGHT / 2);
129 con_background(CON_BG);
134 * con_printf - Print a message to the console.
137 void con_printf(int priority, char *fmt, ...)
142 if (priority <= ((int)con_threshold.value))
144 va_start (arglist, fmt);
145 vsprintf (buffer, fmt, arglist);
147 if (text_console_enabled)
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));
163 * con_update - Check for new console input. If it's there, use it.
166 void con_update(void)
169 char buffer[CMD_MAX_LENGTH], *t;
171 /* Check for new input */
172 t = fgets(buffer, sizeof(buffer), stdin);
173 if (t == NULL) return;
181 int con_events(int key)
183 return CON_Events(key);
188 * cvar_registervariable - Register a CVar
191 void cvar_registervariable (cvar_t *cvar)
195 Assert(cvar != NULL);
198 cvar->value = strtod(cvar->string, (char **) NULL);
200 if (cvar_vars == NULL)
205 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
211 * cvar_set - Set a CVar's value
214 void cvar_set (char *cvar_name, char *value)
218 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
219 if (!strcmp(cvar_name, ptr->name)) break;
221 if (ptr == NULL) return; // If we didn't find the cvar, give up
223 ptr->value = strtod(value, (char **) NULL);
227 * cvar() - Get a CVar's value
230 float cvar (char *cvar_name)
234 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
235 if (!strcmp(cvar_name, ptr->name)) break;
237 if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
243 /* ==========================================================================
245 * ==========================================================================
250 CON_DrawConsole(Console);
253 char buffer[CON_LINE_LEN+1];
255 for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
257 memcpy(buffer, con_display[i], CON_LINE_LEN);
258 buffer[CON_LINE_LEN] = 0;
259 gr_string(1,j*10,buffer);
268 if (!con_initialized)
272 CON_Topmost(Console);
277 void con_parse(ConsoleInformation *console, char *command)