1 #ifndef _global_h
2 #	include "global.h"
3 #endif
4 
5 
6 #ifndef _dynobj_h
7 #	include "dynobj.h"
8 #endif
9 #ifndef _object_h
10 #	include "object.h"
11 #endif
12 
13 #ifndef _graph_h
14 #	include "graph.h"
15 #endif
16 #ifndef _mover_h
17 #	include "mover.h"
18 #endif
19 
20 #ifndef _game_h
21 #	include "game.h"
22 #endif
23 #ifndef _snooker_h
24 #	include "snooker.h"
25 #endif
26 #ifndef _cannon_h
27 #	include "cannon.h"
28 #endif
29 #ifndef _pool8_h
30 #	include "pool8.h"
31 #endif
32 #ifndef _carrom_h
33 #	include "carrom.h"
34 #endif
35 #ifndef _hockey_h
36 #	include "hockey.h"
37 #endif
38 #ifndef _curling_h
39 #	include "curling.h"
40 #endif
41 #ifndef _pball_h
42 #	include "pball.h"
43 #endif
44 
45 //
46 // Stackgr��e in Turbo-C
47 //
48 #ifdef __TURBOC__
49 // #	include <dos.h>
50 unsigned _stklen = 24000;
51 #endif
52 
53 
54 #ifdef DEBUG
55 #	ifdef __TURBOC__
56 		long debug = TCTrace;			// globale Variable
57 #	else
58 		long debug = UnixTrace;
59 #	endif
60 #endif
61 
62 #ifdef __TURBOC__
start_log(const char *)63 void start_log( const char * /* name */ )	{}
end_log()64 void end_log() {}
65 #else
66 void start_log( const char *name );
67 void end_log();
68 void main_xbench( int argc, char **argv );
69 #endif
70 
71 double current_time;
72 
73 int	deluxe =   2;						// Luxus-Ausf�hrung bei Pool-Billard
74                                     //         half full
75 												// case 1:  4    0   Intro
76 												// case 2:  4    3   game
77 												// case 3:  2    1   old game
78 int	size				= 800;			// Default-Gr��e
79 int	sound_request	= 0;				// Wunsch nach Sound
80 int	light_flag		= 1;				// Light-Source
81 int	color_flag		= 0;				// Desired table color
82 int	nohint_flag		= 0;				// Dont draw arrows for hints
83 int	enhanced_mover = 2;
84 int	frames_per_sec = 0;				// limit frames per seconds
85 int	no_server_grabs= 0;				// never grab server
86 int	no_override    = 0;				// 'pseudo'-root as normal window
87 int	nine_ball      = 0;				// special parameter for 9ball pool-game
88 
89 #ifdef STATISTICS
90 int	showmeter      = 0;
91 #endif
92 
usage()93 void usage() {
94 	printf("usage: flying <options>\n" );
95 	printf("options:\n" );
96 	printf("    select game:\n" );
97 	printf("       -snooker      Snooker      (xsnooker)\n" );
98 	printf("       -pool         Pool-Billard (xpool)\n" );
99 	printf("       -pool9        9-ball Pool\n" );
100 	printf("       -cannon       Karambolage  (xcannon)\n" );
101 	printf("       -carrom       Carrom       (xcarrom)\n" );
102 	printf("       -hockey       Air-Hockey   (xhockey)\n" );
103 	printf("       -curling      Curling      (xcurling)\n" );
104 //	printf("       -bowling      Bowling\n" );
105 //	printf("       -golf         Miniature-Golf\n" );
106 	printf("       -ft <n>       table size in feet [6...9]\n" );
107 	printf("       -deluxe       special version of pool (default)\n" );
108 	printf("       -tv           normal version of pool with TV-balls\n" );
109 //	printf("       -light <n>    0 - static, 1 moving light\n" );
110 	printf("       -[red|green|blue] select billard table color\n" );
111 	printf("       -nohints      turn off hint arrows\n" );
112 	printf("       -demo         demonstration (no pockets)\n" );
113 	printf("       -presets      show preset variables\n" );
114 #ifndef __TURBOC__
115 	printf("    X11 options:\n");
116 	printf("       -size <n>     window size\n" );
117 	printf("       -root         full screen (default)\n" );
118 	printf("       -no_override  don't let the pseudo-root be of OverrideRedirect\n" );
119 	printf("       -no_grabs     never grab the server\n" );
120 	printf("       -display      ouput-display (def: $DISPLAY)\n" );
121 	printf("       -in1          input-display (def: = output-display)\n" );
122 	printf("       -in2          alternate input-display\n" );
123 	printf("       -mode <n>     select update mode 1/2/3 with default 2\n" );
124 	printf("       -chkmode      run a benchmark with the 3 update modes\n" );
125 #endif
126 #if (SOUND_SUBSYSTEM)
127 	printf("       -sound        clicks when hitting balls\n" );
128 #endif
129 	printf("    for time measurements:\n");
130 	printf("       -frames <n>   limit update to <n> frames per sec (def: full speed)\n" );
131 	printf("       -time <n>     stop after n seconds\n");
132 	printf("       -maxspeed     jump from collision to collision (asynchronous)\n" );
133 
134 #ifdef STATISTICS
135 	printf("    for debugging:\n");
136 	printf("       -meter        performance meter\n" );
137 #endif
138 #ifdef DEBUG
139 	printf("       -debug <n>    verbose messages at stdout\n" );
140 	printf("\ndebug-flags:\n");
141 	show_flags();
142 #endif
143 
144 
145 	printf("\nsmail (for gifts):\n");
146 	printf("        Helmut Hoenig\n");
147 	printf("        Hopfenstrasse 8a\n");
148 	printf("        65520 Bad Camberg\n");
149 	printf("        GERMANY\n");
150 	printf("\n");
151 	printf( "                By the way, I am collecting banknotes!!\n");
152 	printf( "    If you want to join into my collection, get any bill of your country,\n");
153 	printf( " sign it on the backside and send it to me so I will pin it on my world map.\n");
154 	printf( "             (Don't forget the exact location for the pin :-)\n");
155 	printf( "    Anyway, you can also send me a picture postcard or anything else ...\n\n" );
156 	exit(-1);
157 }
158 
main(int argc,char ** argv)159 int main(int argc, char **argv)
160 {
161 char		*disp=0l;	// Ausgabe
162 char		*in1=0l;		// Eingabe1
163 char		*in2=0l;		// Eingabe2
164 double	stop_time=0.0;
165 long		all_cycles=0l;
166 int		max_speed	= 0;
167 double	ft = 0.0;
168 
169 			size = ON_ROOT;
170 int			game_flag  = 0;
171 PBallType	game_pball = BillardQueue;
172 int		demo_flag  = 0;
173 double	demo_param = 0.0;
174 char		pressed_key=0;
175 
176 	srand( (unsigned)GetCurrentTime() );
177 	load_konfi();
178 
179 	if (!strcmp(argv[0],"xsnooker"))					game_flag = 1;
180 	else if (!strcmp(argv[0],"xpool"))				game_flag = 2;
181 	else if (!strcmp(argv[0],"xcannon"))			game_flag = 3;
182 	else if (!strcmp(argv[0],"xcarrom"))			game_flag = 4;
183 	else if (!strcmp(argv[0],"xhockey"))			game_flag = 5;
184 	else if (!strcmp(argv[0],"xcurling"))			game_flag = 6;
185 	else if (!strcmp(argv[0],"xbowling"))			game_flag = 7;
186 	else if (!strcmp(argv[0],"xgolf"))				game_flag = 8;
187 
188 	for (int i=1; i<argc; i++ ) {
189 		if (!strcmp(argv[i],"-snooker"))				game_flag = 1;
190 		else if (!strcmp(argv[i],"-pool"))			game_flag = 2;
191 		else if (!strcmp(argv[i],"-pool9")) {		game_flag = 2; nine_ball = 1; }
192 		else if (!strcmp(argv[i],"-cannon"))		game_flag = 3;
193 		else if (!strcmp(argv[i],"-carrom"))		game_flag = 4;
194 		else if (!strcmp(argv[i],"-hockey"))		game_flag = 5;
195 		else if (!strcmp(argv[i],"-curling"))		game_flag = 6;
196 		else if (!strcmp(argv[i],"-bowling"))		game_flag = 7;
197 		else if (!strcmp(argv[i],"-golf"))			game_flag = 8;
198 		else if (!strcmp(argv[i],"-deluxe")) {
199 					deluxe    = (i<argc-1)?atoi(argv[i+1]):0;
200 					if (deluxe) { i++; } else { deluxe = 2; }
201 					game_flag = 2;
202 					if (!ft)		ft = 8.0;
203 		}
204 		else if (!strcmp(argv[i],"-tv")) {
205 					deluxe    = 0;
206 					game_flag = 2;
207 		}
208 		else if (!strcmp(argv[i],"-light"))		light_flag = atoi(argv[++i]);
209 		else if (!strcmp(argv[i],"-mode"))		enhanced_mover = atoi(argv[++i]);
210 #ifndef __TURBOC__
211 		else if (!strcmp(argv[i],"-chkmode"))	{ main_xbench(0,0L);	exit(0); }
212 #endif
213 		else if (!strcmp(argv[i],"-red"))		color_flag = 1;
214 		else if (!strcmp(argv[i],"-green"))		color_flag = 2;
215 		else if (!strcmp(argv[i],"-blue"))		color_flag = 3;
216 		else if (!strcmp(argv[i],"-nohints"))	nohint_flag = 1;
217 		else if (!strcmp(argv[i],"-demo"))			{
218 				demo_flag=1;
219 				if (i<argc-1)			demo_param = atof(argv[i+1]);	// read param
220 				else						demo_param = 0.0;					// no param
221 				if (demo_param>0.0) 	i++;									// skip arg
222 		}
223 #if (SOUND_SUBSYSTEM)
224 		else if (!strcmp(argv[i],"-sound"))			sound_request = 1;
225 #endif
226 		else if (!strcmp(argv[i],"-time"))			stop_time = atof(argv[++i]);
227 		else if (!strcmp(argv[i],"-size"))			size = atoi(argv[++i]);
228 		else if (!strcmp(argv[i],"-ft"))				ft = atof(argv[++i]);
229 		else if (!strcmp(argv[i],"-display"))		disp = argv[++i];
230 		else if (!strcmp(argv[i],"-in1"))			in1 = argv[++i];
231 		else if (!strcmp(argv[i],"-in2"))			in2 = argv[++i];
232 		else if (!strcmp(argv[i],"-root"))			size = ON_ROOT;
233 		else if (!strcmp(argv[i],"-no_override"))	no_override = 1;
234 		else if (!strcmp(argv[i],"-no_grabs"))		no_server_grabs = 1;
235 		else if (!strcmp(argv[i],"-frames"))		frames_per_sec=atoi(argv[++i]);
236 		else if (!strcmp(argv[i],"-maxspeed")) {
237 				if (!stop_time)		stop_time = 5.0;
238 				max_speed = 1;
239 				demo_flag = 1;
240 		}
241 		else if (!strcmp(argv[i],"-presets"))	{	show_defaults();	exit(0);	}
242 
243 #ifdef STATISTICS
244 		else if (!strcmp(argv[i],"-meter"))			showmeter = 1;
245 #endif
246 #ifdef DEBUG
247 		else if (!strcmp(argv[i],"-debug"))			debug= atoi(argv[++i]);
248 		else if (!set_debug(argv[i]))					;
249 #endif
250 		else if (argv[i][0]=='-')						usage();
251 		else usage();
252 	}
253 
254 #ifdef DEBUG
255 	if (debug&Intro) {
256 		debug |= __ShowAll | ForceCalc;
257 		size			= 600;
258 		deluxe		= 1;
259 		game_flag	=   2;
260 		ft				= 8.0;
261 	}
262 	if ((size==ON_ROOT)&&
263 		( debug&ShowColors||debug&ShowLight||debug&ShowRings||debug&ShowTurns
264 		||debug&GameState))
265 	{
266 		size			= 600;
267 	}
268 	if (debug&xdb) {
269 		size			= 600;
270 		in1			= "hgr49:0.0";
271 	}
272 #endif
273 
274 	if (game_flag!=2)		deluxe=0;
275 	if (nine_ball)			deluxe=2;
276 
277 do {
278 	PBall	*p1=0;
279 	PBall	*p2=0;
280 	InitColors();
281 
282 #ifdef DEBUG
283 	if (debug&Motion) {
284 		ft = 8.0;
285 		game_flag = 2;
286 		deluxe    = 2;
287 		g=(Game*) new Pool8Test(ft,demo_param);
288 	}
289 	else
290 #endif
291 	switch(game_flag) {
292 	case 1:		if (demo_flag) {
293 						if (demo_param)	g=(Game*) new SnookerDemo(demo_param);
294 						else					g=(Game*) new SnookerDemo();
295 						break;
296 					}
297 					g = (Game*)new Snooker;
298 					start_log( "Snooker" );
299 					break;
300 	case 2:
301 					if (deluxe)				if (!ft)		ft = 8.0;
302 #ifdef DEBUG
303 					if ((ft<1||ft>9))		ft = 6.0 + (rand()%30) / 10;
304 #else
305 					if ((ft<6||ft>9))		ft = 6.0 + (rand()%30) / 10;
306 #endif
307 					if (demo_flag) {
308 						if (demo_param)	g=(Game*) new Pool8Demo(ft,demo_param);
309 						else					g=(Game*) new Pool8Demo(ft);
310 						break;
311 					}
312 					if (!nine_ball) {
313 						g = (Game*)new Pool8(ft);
314 						start_log( "8-Ball" );
315 					}
316 					else {
317 						g = (Game*)new Pool9(ft);
318 						start_log( "9-Ball" );
319 					}
320 					break;
321 	case 3:		g = (Game*)new Cannon;
322 					start_log( "Cannon" );
323 					break;
324 	case 4:		if (demo_flag) {
325 						if (demo_param)	g=(Game*) new CarromDemo(demo_param);
326 						else					g=(Game*) new CarromDemo();
327 						break;
328 					}
329 					g = (Game*)new Carrom;
330 					start_log( "Carrom" );
331 					break;
332 	case 5:		if (demo_flag) {
333 						if (demo_param)	g=(Game*) new TestHockey(demo_param);
334 						else					g=(Game*) new TestHockey();
335 						break;
336 					}
337 					g = (Game*)new Hockey;
338 					start_log( "Hockey" );
339 					break;
340 	case 6:		g = (Game*)new Curling;
341 					start_log( "Curling" );
342 					break;
343 	default:		if (demo_flag) {
344 						if (demo_param)	g=(Game*) new CarromDemo(demo_param);
345 						else					g=(Game*) new CarromDemo();
346 						break;
347 					}
348 					usage();						break;
349 	};
350 
351 //
352 // Durch das Instanziieren der Game-Klasse entstanden Farbanfordungen
353 // welche nun befriedigt werden m�ssen, bevor sie in den InitPlayground
354 // Routinen verwendet werden k�nnen.
355 	AllocColors();
356 //
357 // Die f�r die einzelnen Spiele notwendigen Objekte werden nun angelegt.
358 	g->InitPlayground();
359 	MapMainWindow();
360 
361 	switch(game_flag) {
362 	case 5:	game_pball = DiscSlider; 	break;
363 	case 6:	game_pball = DiscThrower;	break;
364 	default:	game_pball = BillardQueue;	break;
365 	}
366 
367 	if (in1) 					p1 = new PBall( game_pball, in1 );
368 	if (in2)						p2 = new PBall( game_pball, in2 );
369 	if (!demo_flag&&!p1)		p1 = new PBall( game_pball, (disp)?disp:(char *)"" );
370 
371 
372 	g->DrawBackground();
373 	DynObj::DynInitAll();
374 #ifdef DEBUG
375 	if (debug&ObjectInfo)	Object::ForAll(&Object::Info);
376 #endif
377 	current_time = GetCurrentTime();
378 	DynObj::ForAllDyn(&DynObj::Reset);
379 	DynObj::ForAllDyn(&DynObj::Redraw);
380 	current_time = GetCurrentTime();
381 	DynObj::ForAllDyn(&DynObj::CollisionCalc);
382 	if (stop_time)		stop_time+=current_time;		// Jetzt geht's los ...
383 
384 
385 	while(1) {
386 		double	collision_step;
387 		collision_step = DynObj::CollisionAll();	// n�chste Kollisionszeit
388 
389 		double	current_step   = GetCurrentTime()-current_time;
390 
391 		if ((!max_speed)&&collision_step>current_step) {
392 			// Zwischenschritt einlegen
393 #ifdef DEBUG
394 			if (debug&MoveAll) {
395 					printf("MOVE intermediate: +%f = %f (OFF: %f, Collide: %f)\n",
396 								current_step, current_time+current_step,
397 								0.0,
398 								(collision_step!=MAX_TIME)?collision_step:-1 );
399 			}
400 #endif
401 			current_time += current_step;
402 			DynObj::ForAllDyn(&DynObj::Move,current_step);
403 		}
404 		else {
405 			// Kollisionsschritt einlegen
406 #ifdef DEBUG
407 			if (debug&MoveAll) {
408 					printf("MOVE to collision: +%f = %f (OFF: %f)\n",
409 								collision_step, current_time+collision_step,
410 								current_step-collision_step );
411 			}
412 #endif
413 			current_time+=collision_step;
414 			DynObj::ForAllDyn(&DynObj::Move,collision_step);
415 			DynObj::Collide();							// Kollision ausf�hren
416 		}
417 
418 #ifdef STATISTICS
419 {
420 static double next_rate		= 0.0;
421 static double cycle_start	= 0.0;
422 static int off					= 0;
423 static int cycle_count		= 0;
424 
425 		double check_time = GetCurrentTime();
426 		cycle_count++;
427 		if (next_rate<check_time)
428 		{  char	buffer[30];
429 			double			time_step = check_time - cycle_start;
430 
431 			sprintf( buffer, "Rate:%7.1f/s", cycle_count/time_step );
432 			showinfo( CycleRate, buffer );
433 			if (showmeter)	graphinfo((int)(cycle_count/time_step));
434 
435 			cycle_count=0;
436 			sprintf( buffer, "Moves:%7.1f/s", BallMover::moves/time_step );
437 			showinfo( MoveRate, buffer );
438 			BallMover::moves=0;
439 
440 			if (check_time-current_time>0.05) {
441 				sprintf( buffer, "Offset:%7.1f/s", check_time-current_time );
442 				showinfo(OffsetInfo,buffer);
443 				off=1;
444 			}
445 			else if (off) {
446 				showinfo(OffsetInfo,"");
447 				off=0;
448 			}
449 			cycle_start=check_time;
450 			next_rate  =check_time+0.50;
451 		}
452 }
453 #endif
454 		PBallTop::ForAll(&PBallTop::Update);
455 		all_cycles++;
456 		pressed_key = GetKey();
457 #ifdef DEBUG
458 		if (pressed_key=='0')	enhanced_mover=0;
459 		if (pressed_key=='1')	enhanced_mover=1;
460 		if (pressed_key=='2')	enhanced_mover=2;
461 #endif
462 
463 		if (pressed_key==' ')	g->ResetGame();
464 		if (pressed_key=='q'||pressed_key=='\033'||pressed_key=='\n'||pressed_key=='r'||((stop_time)&&(GetCurrentTime()>stop_time)))		break;
465 	};
466 
467 	UnlockGraphic();
468 	if (p2)		delete p2;
469 	if (p1)		delete p1;
470 	delete g;
471 	CloseGraphic();
472 	printf( "end after %ld cycles\n", all_cycles );
473 	Object::ForAll(&Object::Info);
474 }
475 while( pressed_key=='r' );
476 
477 	end_log();
478 	return 0;
479 }
480 
481