]> icculus.org git repositories - btb/d2x.git/blob - main/console.c
initial movie support
[btb/d2x.git] / main / console.c
1 /*
2  * $Source: /cvs/cvsroot/d2x/main/console.c,v $
3  * $Revision: 1.6 $
4  * $Author: btb $
5  * $Date: 2002-07-22 02:17:10 $
6  *
7  * FIXME: put description here
8  *
9  * $Log: not supported by cvs2svn $
10  * Revision 1.5  2001/10/19 09:47:34  bradleyb
11  * RCS headers added
12  *
13  *
14  */
15
16 #ifdef HAVE_CONFIG_H
17 #include <conf.h>
18 #endif
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <stdarg.h>
23 #include <string.h>
24 #include <fcntl.h>
25 #include "pstypes.h"
26 #include "u_mem.h"
27 #include "error.h"
28 #include "console.h"
29 #include "cmd.h"
30
31 #ifndef __MSDOS__
32 int text_console_enabled = 1;
33 #else
34 int isvga();
35 #define text_console_enabled (!isvga())
36 #endif
37
38 cvar_t *cvar_vars = NULL;
39
40 /* Console specific cvars */
41 /* How discriminating we are about which messages are displayed */
42 cvar_t con_threshold = {"con_threshold", "0",};
43
44 /* Private console stuff */
45 #define CON_NUM_LINES 40
46 #define CON_LINE_LEN 40
47 static char con_display[40][40];
48 static int  con_line; /* Current display line */
49
50 /* ======
51  * con_init - Initialise the console.
52  * ======
53  */
54 int con_init(void)
55 {
56         /* Make sure the output is unbuffered */
57         if (text_console_enabled) {
58                 setbuf (stdout, NULL);
59                 setbuf (stderr, NULL);
60         }
61
62         memset(con_display, ' ', sizeof(con_display));
63         con_line = 0;
64
65         /* Initialise the cvars */
66         cvar_registervariable (&con_threshold);
67         return 0;       
68 }
69
70 /* ======
71  * con_printf - Print a message to the console.
72  * ======
73  */
74 void con_printf(int priority, char *fmt, ...)
75 {
76         va_list arglist;
77         char buffer[2048];
78
79         if (priority <= ((int)con_threshold.value))
80         {
81                 va_start (arglist, fmt);
82                 vsprintf (buffer,  fmt, arglist);
83                 if (text_console_enabled) vprintf(fmt, arglist);
84                 va_end (arglist);
85
86 /*              for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
87                 {
88                         memcpy(con_display, &buffer[i], min(80, l-i));  
89                 }*/
90         }
91 }
92
93 /* ======
94  * con_update - Check for new console input. If it's there, use it.
95  * ======
96  */
97 void con_update(void)
98 {
99 //      char buffer[CMD_MAX_LENGTH], *t;
100
101         /* Check for new input */
102 /*      t = fgets(buffer, sizeof(buffer), stdin);
103         if (t == NULL) return;
104
105         cmd_parse(buffer);*/
106 //      con_draw();
107 }
108
109 /* ======
110  * cvar_registervariable - Register a CVar
111  * ======
112  */
113 void cvar_registervariable (cvar_t *cvar)
114 {
115         cvar_t *ptr;
116         
117         Assert(cvar != NULL);
118
119         cvar->next = NULL;
120         cvar->value = strtod(cvar->string, (char **) NULL);
121
122         if (cvar_vars == NULL)
123         {
124                 cvar_vars = cvar;
125         } else
126         {
127                 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
128                 ptr->next = cvar;
129         }
130 }
131
132 /* ======
133  * cvar_set - Set a CVar's value
134  * ======
135  */
136 void cvar_set (char *cvar_name, char *value)
137 {
138         cvar_t *ptr;
139
140         for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
141                 if (!strcmp(cvar_name, ptr->name)) break;
142
143         if (ptr == NULL) return; // If we didn't find the cvar, give up
144
145         ptr->value = strtod(value, (char **) NULL);
146 }
147
148 /* ======
149  * cvar() - Get a CVar's value
150  * ======
151  */
152 float cvar (char *cvar_name)
153 {
154         cvar_t *ptr;
155
156         for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
157                 if (!strcmp(cvar_name, ptr->name)) break;
158
159         if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
160
161         return ptr->value;
162 }
163
164
165 /* ==========================================================================
166  * DRAWING
167  * ==========================================================================
168  */
169 void con_draw(void)
170 {
171 /*      char buffer[CON_LINE_LEN+1];
172         int i,j; */
173 /*      for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
174         {
175                 memcpy(buffer, con_display[i], CON_LINE_LEN);
176                 buffer[CON_LINE_LEN] = 0;
177                 gr_string(1,j*10,buffer);
178         }*/
179 }