1 /* $Id: console.c,v 1.10 2003-06-02 01:55:03 btb Exp $ */
4 * FIXME: put description here
20 #include "CON_console.h"
30 int text_console_enabled = 1;
33 #define text_console_enabled (!isvga())
36 cvar_t *cvar_vars = NULL;
38 /* Console specific cvars */
39 /* How discriminating we are about which messages are displayed */
40 cvar_t con_threshold = {"con_threshold", "0",};
42 /* Private console stuff */
43 #define CON_NUM_LINES 40
44 #define CON_LINE_LEN 40
46 static char con_display[40][40];
47 static int con_line; /* Current display line */
50 static int con_initialized;
52 ConsoleInformation *Console;
53 extern SDL_Surface *screen;
55 void con_parse(ConsoleInformation *console, char *command);
59 * con_init - Initialise the console.
64 /* Initialise the cvars */
65 cvar_registervariable (&con_threshold);
69 void real_con_init(void)
73 Con_rect.x = Con_rect.y = 0;
74 Con_rect.w = Con_rect.h = 300;
76 Console = CON_Init("ConsoleFont.png", screen, CON_NUM_LINES, Con_rect);
80 CON_SetExecuteFunction(Console, con_parse);
86 * con_printf - Print a message to the console.
89 void con_printf(int priority, char *fmt, ...)
94 if (priority <= ((int)con_threshold.value))
96 va_start (arglist, fmt);
97 vsprintf (buffer, fmt, arglist);
99 if (text_console_enabled) {
100 va_start (arglist, fmt);
101 vprintf(fmt, arglist);
105 CON_Out(Console, buffer);
107 /* for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
109 memcpy(con_display, &buffer[i], min(80, l-i));
115 * con_update - Check for new console input. If it's there, use it.
118 void con_update(void)
121 char buffer[CMD_MAX_LENGTH], *t;
123 /* Check for new input */
124 t = fgets(buffer, sizeof(buffer), stdin);
125 if (t == NULL) return;
133 * cvar_registervariable - Register a CVar
136 void cvar_registervariable (cvar_t *cvar)
140 Assert(cvar != NULL);
143 cvar->value = strtod(cvar->string, (char **) NULL);
145 if (cvar_vars == NULL)
150 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
156 * cvar_set - Set a CVar's value
159 void cvar_set (char *cvar_name, char *value)
163 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
164 if (!strcmp(cvar_name, ptr->name)) break;
166 if (ptr == NULL) return; // If we didn't find the cvar, give up
168 ptr->value = strtod(value, (char **) NULL);
172 * cvar() - Get a CVar's value
175 float cvar (char *cvar_name)
179 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
180 if (!strcmp(cvar_name, ptr->name)) break;
182 if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
188 /* ==========================================================================
190 * ==========================================================================
195 CON_DrawConsole(Console);
197 char buffer[CON_LINE_LEN+1];
199 for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
201 memcpy(buffer, con_display[i], CON_LINE_LEN);
202 buffer[CON_LINE_LEN] = 0;
203 gr_string(1,j*10,buffer);
210 if (!con_initialized)
214 CON_Topmost(Console);
217 void con_parse(ConsoleInformation *console, char *command)