1 /* $Id: console.c,v 1.13 2003-06-02 20:45:32 btb Exp $ */
4 * FIXME: put description here
21 #include "CON_console.h"
32 int text_console_enabled = 1;
35 #define text_console_enabled (!isvga())
38 cvar_t *cvar_vars = NULL;
40 /* Console specific cvars */
41 /* How discriminating we are about which messages are displayed */
42 cvar_t con_threshold = {"con_threshold", "0",};
44 /* Private console stuff */
45 #define CON_NUM_LINES 40
46 #define CON_LINE_LEN 40
48 static char con_display[40][40];
49 static int con_line; /* Current display line */
53 static int con_initialized;
55 ConsoleInformation *Console;
56 extern SDL_Surface *screen;
58 void con_parse(ConsoleInformation *console, char *command);
63 * con_init - Initialise the console.
68 /* Initialise the cvars */
69 cvar_registervariable (&con_threshold);
74 void real_con_init(void)
78 Con_rect.x = Con_rect.y = 0;
82 Console = CON_Init("ConsoleFont.png", screen, CON_NUM_LINES, Con_rect);
86 CON_SetExecuteFunction(Console, con_parse);
87 CON_Background(Console, "scores.pcx", 0, 0);
94 * con_printf - Print a message to the console.
97 void con_printf(int priority, char *fmt, ...)
102 if (priority <= ((int)con_threshold.value))
104 va_start (arglist, fmt);
105 vsprintf (buffer, fmt, arglist);
107 if (text_console_enabled) {
108 va_start (arglist, fmt);
109 vprintf(fmt, arglist);
114 CON_Out(Console, buffer);
117 /* for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
119 memcpy(con_display, &buffer[i], min(80, l-i));
125 * con_update - Check for new console input. If it's there, use it.
128 void con_update(void)
131 char buffer[CMD_MAX_LENGTH], *t;
133 /* Check for new input */
134 t = fgets(buffer, sizeof(buffer), stdin);
135 if (t == NULL) return;
143 * cvar_registervariable - Register a CVar
146 void cvar_registervariable (cvar_t *cvar)
150 Assert(cvar != NULL);
153 cvar->value = strtod(cvar->string, (char **) NULL);
155 if (cvar_vars == NULL)
160 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
166 * cvar_set - Set a CVar's value
169 void cvar_set (char *cvar_name, char *value)
173 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
174 if (!strcmp(cvar_name, ptr->name)) break;
176 if (ptr == NULL) return; // If we didn't find the cvar, give up
178 ptr->value = strtod(value, (char **) NULL);
182 * cvar() - Get a CVar's value
185 float cvar (char *cvar_name)
189 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
190 if (!strcmp(cvar_name, ptr->name)) break;
192 if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
198 /* ==========================================================================
200 * ==========================================================================
205 CON_DrawConsole(Console);
208 char buffer[CON_LINE_LEN+1];
210 for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
212 memcpy(buffer, con_display[i], CON_LINE_LEN);
213 buffer[CON_LINE_LEN] = 0;
214 gr_string(1,j*10,buffer);
223 if (!con_initialized)
227 CON_Topmost(Console);
232 void con_parse(ConsoleInformation *console, char *command)