File: xtrojka.c

package info (click to toggle)
xtrojka 123-16
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 492 kB
  • ctags: 443
  • sloc: ansic: 3,087; makefile: 133; sh: 19
file content (348 lines) | stat: -rw-r--r-- 7,300 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
 *	xtrojka (c) 1994,1995,1996 Maarten Los
 *
 *	#include "COPYRIGHT"	
 *
 *	created:	26.xi.1995
 *	modified:	27.xii.1995
 *
 *	The main program
 */


#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>

#include "xtrojka.h"
#include "scores.h"
#include "options.h"
#include "preferences.h"
#include "sh_slist.h"
#include "sh_stat.h"
#include "game.h"
#include "menu_tool.h"
#include "menu.h"
#include "window.h"
#include "pics.h"
#include "slist.h"
#include "actions.h"

#include "debug.h"
#include "tr_core.h"
#include "_strdefs.h"

extern Widget screen;
extern Widget slist_shell;

extern Widget main_screen;	/* the mother of all widgets */

XtAppContext	app_context;
Colormap	the_colormap;	/* the colormap of the application */
int		the_depth;	/* the colormap of the application */
Visual		*the_visual;
Colormap	my_colormap;

GAME_STATE game_state;

static char *COPYRIGHT = "@(#) xtrojka (c) 1994,1995,1996 Maarten Los";


flag	is_color;
flag	is_NOcolor;
flag	is_debug_info;
flag	is_wizard;
flag	is_slick;

int 	speed;
int	starting_speed;


static String fallback_resources[] = {

#include "_resdefs.h"

};

static XtResource resources[] = {
	{ "color0", "Color0", XtRPixel, sizeof(Pixel),
	  XtOffsetOf(AppData, color[0]), XtRString, (caddr_t)"black" },
	{ "color1", "Color1", XtRPixel, sizeof(Pixel),
	  XtOffsetOf(AppData, color[1]), XtRString, (caddr_t)"magenta" },
	{ "color2", "Color2", XtRPixel, sizeof(Pixel),
	  XtOffsetOf(AppData, color[2]), XtRString, (caddr_t)"blue" },
	{ "color3", "Color3", XtRPixel, sizeof(Pixel),
	  XtOffsetOf(AppData, color[3]), XtRString, (caddr_t)"cyan" },
	{ "color4", "Color4", XtRPixel, sizeof(Pixel),
	  XtOffsetOf(AppData, color[4]), XtRString, (caddr_t)"yellow" },
	{ "color5", "Color5", XtRPixel, sizeof(Pixel),
	  XtOffsetOf(AppData, color[5]), XtRString, (caddr_t)"green" },
	{ "color6", "Color6", XtRPixel, sizeof(Pixel),
	  XtOffsetOf(AppData, color[6]), XtRString, (caddr_t)"red" },
	{ "color7", "Color7", XtRPixel, sizeof(Pixel),
	  XtOffsetOf(AppData, color[7]), XtRString, (caddr_t)"purple" },
	{ "color8", "Color8", XtRPixel, sizeof(Pixel),
	  XtOffsetOf(AppData, color[8]), XtRString, (caddr_t)"white" },

	{ "slist_font", "Slist_font", XtRString, sizeof(String),
	  XtOffsetOf(AppData, slist_font), XtRString, (caddr_t)"7x13" },

	{ "game_font", "Game_font", XtRString, sizeof(String),
	  XtOffsetOf(AppData, game_font), XtRString, (caddr_t)"7x13bold" },

	{ "str_best_players", "Str_best_players", XtRString, sizeof(String),
	  XtOffsetOf(AppData, str_best_players), XtRString, (caddr_t)"<undef>" },

	{ "wstr_stat", "Wstr_stat", XtRString, sizeof(String),
	  XtOffsetOf(AppData, wstr_stat), XtRString, (caddr_t)"<undef>" },

	{ "wstr_open_prefs", "Wstr_open_prefs", XtRString, sizeof(String),
	  XtOffsetOf(AppData, wstr_open_prefs), XtRString, (caddr_t)"<undef>" },

	{ "wstr_create_prefs", "Wstr_create_prefs", XtRString, sizeof(String),
	  XtOffsetOf(AppData, wstr_create_prefs), XtRString, (caddr_t)"<undef>" },

	{ "wstr_write_prefs", "Wstr_write_prefs", XtRString, sizeof(String),
	  XtOffsetOf(AppData, wstr_write_prefs), XtRString, (caddr_t)"<undef>" },

	{ "wstr_read_prefs", "Wstr_read_prefs", XtRString, sizeof(String),
	  XtOffsetOf(AppData, wstr_read_prefs), XtRString, (caddr_t)"<undef>" },
};

AppData app_data;


main(argc, argv)
int argc;
char **argv;
{
	/*
	 *	set default values
	 */
	is_debug_info = False;
	is_NOcolor = False;

	/*
	 *	get the command line options
	 */
	get_options(argc, argv);
	if(is_debug_info)
		show_startup_string();

	/*
	 *	initialize the scores
	 */
	init_scores();


	/*
	 *	initialize the application
	 */
	DEBUG("xtrojka.c", "main/1")
	main_screen = XtVaAppInitialize(
		&app_context,	/* application context */
		"XTrojka",	/* application class */
		NULL,0,		/* commandlineoptionlist */
		&argc, argv,	/* command line arguments */
		fallback_resources,	/* fallback resources*/
		NULL);		/* terminate varargslist */

	/*
	 *	check if we have color
	 */
	DEBUG("xtrojka.c", "main/2")

	the_depth = DefaultDepthOfScreen(XtScreen(main_screen));
	is_color = the_depth > 1;

	the_colormap = DefaultColormap(XtDisplay(main_screen),
		DefaultScreen(XtDisplay(main_screen)));

	/*
	 *	now set the properties for the toplevel widget
	 */
	XtVaSetValues(main_screen,
		XtNcolormap, the_colormap,
		XtNdepth, the_depth,
		NULL
	);
	XSetWindowColormap(XtDisplay(main_screen), DefaultRootWindow(XtDisplay(main_screen)), the_colormap);

	/*
	 *	get the application resource from hardcoded data
	 */
	DEBUG("xtrojka.c", "main/3")
	XtGetApplicationResources(main_screen, &app_data, resources,
		XtNumber(resources), NULL, 0);

	/*
	 *	read the preferences
	 */
	init_preferences();

	/*
	 *	intialize menu's, windows, shells
	 */
	init_uif();

	/*
	 *	this is the last manual initialization before
	 *	the application is realized
	 */
	init_xtrojka();


	/*
	 *	Now install the routine that will catch the
	 *	'MapNotify' event
	 */
	init_map_catcher();

	/*
	 *	Realize the application. As soon as the application
	 *	is realized, a 'MapNotify' event will be generated
	 *	which will be caught by 'i_just_got_mapped_hlr()'.
	 */

	DEBUG("xtrojka.c", "main/4");
	XtRealizeWidget(main_screen);

	/*
	 *	Finally, start the game loop
	 */
	show_slist();
	show_stat();
	mainloop();
}



void quit_appl_action(w, unused, event, continue_to_dispatch)
Widget w;
XtPointer unused;
XEvent *event;
Boolean *continue_to_dispatch;
/*
 *	this callback is called on 'Alt-Q'
 */
{
	quit_appl();
}


void quit_appl(void)
{
	DEBUG("xtrojka.c", "quit_appl")

	write_prefs();	
	exit(0);
}


void init_xtrojka(void)
{
	DEBUG("xtrojka.c", "initialize")

	check_wizard_item(is_wizard);	
	check_slick_item(is_slick);	
	set_speed_item(speed);
}


void init_uif()
{
	/*
	 *	first initialize the basic widget system
	 */
	init_windows();

	/*
	 *	now initialize the subsystem
	 */
	init_menu_sys();

	init_bitmaps();


	set_icons();
}


void init_map_catcher(void)
/*
 *	install a map handler. Call just before 'XtAppRealize'
 */
{
	XtAddEventHandler(main_screen,
		StructureNotifyMask,
		False,
		(XtEventHandler)i_just_got_mapped_hlr,
		(Opaque)NULL
	);
}


void i_just_got_mapped_hlr(w, p, me, continue_to_dispatch)
Widget w;
XtPointer p;
XMapEvent *me;
Boolean *continue_to_dispatch;
{
	*continue_to_dispatch = TRUE;


	if(me->type != MapNotify)
		return;

	fix_dimensions(main_screen);
	fix_dimensions(slist_shell);

	init_slist_mgr();
	init_actions();
	init_event_handlers();
}


void show_no_debug(void)
{
	fprintf(stderr,"%s\n", STR_NO_DEBUG);
}


void show_help(void)
{
	fprintf(stderr,"%s: xtrojka [-scores] [-help] [-debug] ", STR_USAGE);
	fprintf(stderr,"[%s] \n\n", STR_X11_OPTIONS);
	fprintf(stderr,"-scores\t%s\n", STR_DISP_SCORE);
	fprintf(stderr,"-help\t%s\n", 	STR_THIS_HELP);
	fprintf(stderr,"-debug\t%s\n",	STR_SHOW_DEBUG);
	fprintf(stderr,"%s.\n\n", 	STR_FOR_X11);
	fflush(stderr);
}	


void show_startup_string(void)
{
	fprintf(stderr,"Xtrojka %s\n", VERSION);

	fprintf(stderr,"%s:\n",STR_COM_OPT);
#ifdef LOCKING
	fprintf(stderr,"\tLOCKING\n");
#endif
#ifdef DEBUG_INFO
	fprintf(stderr,"\tDEBUG_INFO\n");
#endif
#ifdef XPM
	fprintf(stderr,"\tXPM\n");
#endif
	fputc('\n', stderr);

	fprintf(stderr,"%s: %s\n", STR_SCOREFILE, SCOREFILE);

	fflush(stderr);
}