• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 #include <sys/types.h>
21 #include <sys/timeb.h>
22 #include "qwsvdef.h"
23 #include <winsock.h>
24 #include <conio.h>
25 
26 
27 cvar_t	sys_nostdout = {"sys_nostdout","0"};
28 
29 /*
30 ================
31 Sys_FileTime
32 ================
33 */
Sys_FileTime(char * path)34 int	Sys_FileTime (char *path)
35 {
36 	FILE	*f;
37 
38 	f = fopen(path, "rb");
39 	if (f)
40 	{
41 		fclose(f);
42 		return 1;
43 	}
44 
45 	return -1;
46 }
47 
48 /*
49 ================
50 Sys_mkdir
51 ================
52 */
Sys_mkdir(char * path)53 void Sys_mkdir (char *path)
54 {
55 	_mkdir(path);
56 }
57 
58 
59 /*
60 ================
61 Sys_Error
62 ================
63 */
Sys_Error(char * error,...)64 void Sys_Error (char *error, ...)
65 {
66 	va_list		argptr;
67 	char		text[1024];
68 
69 	va_start (argptr,error);
70 	vsprintf (text, error,argptr);
71 	va_end (argptr);
72 
73 //    MessageBox(NULL, text, "Error", 0 /* MB_OK */ );
74 	printf ("ERROR: %s\n", text);
75 
76 	exit (1);
77 }
78 
79 
80 /*
81 ================
82 Sys_DoubleTime
83 ================
84 */
Sys_DoubleTime(void)85 double Sys_DoubleTime (void)
86 {
87 	double t;
88     struct _timeb tstruct;
89 	static int	starttime;
90 
91 	_ftime( &tstruct );
92 
93 	if (!starttime)
94 		starttime = tstruct.time;
95 	t = (tstruct.time-starttime) + tstruct.millitm*0.001;
96 
97 	return t;
98 }
99 
100 
101 /*
102 ================
103 Sys_ConsoleInput
104 ================
105 */
Sys_ConsoleInput(void)106 char *Sys_ConsoleInput (void)
107 {
108 	static char	text[256];
109 	static int		len;
110 	int		c;
111 
112 	// read a line out
113 	while (_kbhit())
114 	{
115 		c = _getch();
116 		putch (c);
117 		if (c == '\r')
118 		{
119 			text[len] = 0;
120 			putch ('\n');
121 			len = 0;
122 			return text;
123 		}
124 		if (c == 8)
125 		{
126 			if (len)
127 			{
128 				putch (' ');
129 				putch (c);
130 				len--;
131 				text[len] = 0;
132 			}
133 			continue;
134 		}
135 		text[len] = c;
136 		len++;
137 		text[len] = 0;
138 		if (len == sizeof(text))
139 			len = 0;
140 	}
141 
142 	return NULL;
143 }
144 
145 
146 /*
147 ================
148 Sys_Printf
149 ================
150 */
Sys_Printf(char * fmt,...)151 void Sys_Printf (char *fmt, ...)
152 {
153 	va_list		argptr;
154 
155 	if (sys_nostdout.value)
156 		return;
157 
158 	va_start (argptr,fmt);
159 	vprintf (fmt,argptr);
160 	va_end (argptr);
161 }
162 
163 /*
164 ================
165 Sys_Quit
166 ================
167 */
Sys_Quit(void)168 void Sys_Quit (void)
169 {
170 	exit (0);
171 }
172 
173 
174 /*
175 =============
176 Sys_Init
177 
178 Quake calls this so the system can register variables before host_hunklevel
179 is marked
180 =============
181 */
Sys_Init(void)182 void Sys_Init (void)
183 {
184 	Cvar_RegisterVariable (&sys_nostdout);
185 }
186 
187 /*
188 ==================
189 main
190 
191 ==================
192 */
193 char	*newargv[256];
194 
main(int argc,char ** argv)195 int main (int argc, char **argv)
196 {
197 	quakeparms_t	parms;
198 	double			newtime, time, oldtime;
199 	static	char	cwd[1024];
200 	struct timeval	timeout;
201 	fd_set			fdset;
202 	int				t;
203 
204 	COM_InitArgv (argc, argv);
205 
206 	parms.argc = com_argc;
207 	parms.argv = com_argv;
208 
209 	parms.memsize = 16*1024*1024;
210 
211 	if ((t = COM_CheckParm ("-heapsize")) != 0 &&
212 		t + 1 < com_argc)
213 		parms.memsize = Q_atoi (com_argv[t + 1]) * 1024;
214 
215 	if ((t = COM_CheckParm ("-mem")) != 0 &&
216 		t + 1 < com_argc)
217 		parms.memsize = Q_atoi (com_argv[t + 1]) * 1024 * 1024;
218 
219 	parms.membase = malloc (parms.memsize);
220 
221 	if (!parms.membase)
222 		Sys_Error("Insufficient memory.\n");
223 
224 	parms.basedir = ".";
225 	parms.cachedir = NULL;
226 
227 	SV_Init (&parms);
228 
229 // run one frame immediately for first heartbeat
230 	SV_Frame (0.1);
231 
232 //
233 // main loop
234 //
235 	oldtime = Sys_DoubleTime () - 0.1;
236 	while (1)
237 	{
238 	// select on the net socket and stdin
239 	// the only reason we have a timeout at all is so that if the last
240 	// connected client times out, the message would not otherwise
241 	// be printed until the next event.
242 		FD_ZERO(&fdset);
243 		FD_SET(net_socket, &fdset);
244 		timeout.tv_sec = 0;
245 		timeout.tv_usec = 100;
246 		if (select (net_socket+1, &fdset, NULL, NULL, &timeout) == -1)
247 			continue;
248 
249 	// find time passed since last cycle
250 		newtime = Sys_DoubleTime ();
251 		time = newtime - oldtime;
252 		oldtime = newtime;
253 
254 		SV_Frame (time);
255 	}
256 
257 	return true;
258 }
259 
260 
261