1 /* $Id: console.c,v 1.12 2003-06-02 06:15:41 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;
79 Con_rect.w = Con_rect.h = 300;
81 Console = CON_Init("ConsoleFont.png", screen, CON_NUM_LINES, Con_rect);
85 CON_SetExecuteFunction(Console, con_parse);
92 * con_printf - Print a message to the console.
95 void con_printf(int priority, char *fmt, ...)
100 if (priority <= ((int)con_threshold.value))
102 va_start (arglist, fmt);
103 vsprintf (buffer, fmt, arglist);
105 if (text_console_enabled) {
106 va_start (arglist, fmt);
107 vprintf(fmt, arglist);
112 CON_Out(Console, buffer);
115 /* for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
117 memcpy(con_display, &buffer[i], min(80, l-i));
123 * con_update - Check for new console input. If it's there, use it.
126 void con_update(void)
129 char buffer[CMD_MAX_LENGTH], *t;
131 /* Check for new input */
132 t = fgets(buffer, sizeof(buffer), stdin);
133 if (t == NULL) return;
141 * cvar_registervariable - Register a CVar
144 void cvar_registervariable (cvar_t *cvar)
148 Assert(cvar != NULL);
151 cvar->value = strtod(cvar->string, (char **) NULL);
153 if (cvar_vars == NULL)
158 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
164 * cvar_set - Set a CVar's value
167 void cvar_set (char *cvar_name, char *value)
171 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
172 if (!strcmp(cvar_name, ptr->name)) break;
174 if (ptr == NULL) return; // If we didn't find the cvar, give up
176 ptr->value = strtod(value, (char **) NULL);
180 * cvar() - Get a CVar's value
183 float cvar (char *cvar_name)
187 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
188 if (!strcmp(cvar_name, ptr->name)) break;
190 if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
196 /* ==========================================================================
198 * ==========================================================================
203 CON_DrawConsole(Console);
206 char buffer[CON_LINE_LEN+1];
208 for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
210 memcpy(buffer, con_display[i], CON_LINE_LEN);
211 buffer[CON_LINE_LEN] = 0;
212 gr_string(1,j*10,buffer);
221 if (!con_initialized)
225 CON_Topmost(Console);
230 void con_parse(ConsoleInformation *console, char *command)