File: graph.C

package info (click to toggle)
flying 6.20-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 752 kB
  • ctags: 1,873
  • sloc: cpp: 10,966; makefile: 189
file content (216 lines) | stat: -rw-r--r-- 5,489 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
#ifndef _global_h
#	include "global.h"
#endif

#ifndef _object_h
#	include "object.h"
#endif
#ifndef _graph_h
#	include "graph.h"
#endif
#ifndef _pball_h
#	include "pball.h"
#endif

double	world_x, world_y;
int		max_x, max_y;
double	w2n;
int		wall_click = 0;



void Inside( Vec2 *v ) {
double x=v->X();
double y=v->Y();

	if (x<0)				x=0;
	if (x>max_x)		x=max_x;
	if (y<0)				y=0;
	if (y>max_y)		y=max_y;
	*v = Vec2(x,y);
}

static const int MAX_BG		= 7;
static const int MAX_BALL	= 15;
static const int MAX_SHADE = 3;
static const int MAX_STAT	= 128;

		 int				nbg_cols=0;
static const char 	*bg_col[MAX_BG];
		 unsigned long	bg_pix[MAX_BG];			// aus Planes zusammengesetzt
static unsigned long bg_mask;						// alle bg-Planes

		 int				nball_cols=1;
static const char 	*ball_col[MAX_BALL] = { "Background-Dummy" };
		 unsigned long	ball_pix[MAX_BALL];		// allokierte Pixel
static unsigned long ball_mask;

		 int				nball_ids =0;
		 ColorId			ball_ids[MAX_BALL];		// f�r B�lle verteilte Farb-Ids

       int           nstat_cols =0;
static const char		*stat_col[MAX_STAT];
       unsigned long stat_pix[MAX_STAT];		// Static-Colors (unter Cursor)

static int				nshade_cols=0;
static const char 	*shade_col[MAX_SHADE];
static int m[MAX_SHADE], d[MAX_SHADE];			// Anteil Original : Schatten
static unsigned long	shade_pix[MAX_SHADE];	// aus Planes zusammengesetzt
static unsigned long shade_mask;    			// alle Shade-Planes

static const char 	*cursor_col=0;
static unsigned long	cursor_mask;				// Cursor-Plane

void InitColors() {
	nbg_cols   = 0;
	nball_cols = 1;
	nstat_cols = 0;
	nball_ids  = 0;
	nshade_cols= 0;
}

unsigned long GetAllocatedPixel( const char *colorname ) {
int i;
	for (i=0;i<nbg_cols;i++)
		if	(!strcmp(bg_col[i],colorname))		return bg_pix[i]|ball_pix[0];
	for (i=0;i<nball_cols;i++)
		if	(!strcmp(ball_col[i],colorname))		return ball_pix[i];
	for (i=0;i<nstat_cols;i++)
		if	(!strcmp(stat_col[i],colorname))		return stat_pix[i];
	return 0;
}

unsigned long GetAllocatedPixel( ColorId col, int x, int y ) {
	if (col&MIX_MASK) {
		if ( (x^y)&0x01 ) {
			col = (col>>COLOR_BITS);
		}
	}
	if (col&BG_MASK)			return bg_pix[ (int)(col&COLOR_MASK) ];
	else							return ball_pix[ (int)(col&COLOR_MASK) ];
}

ColorId AddBgColor( const char *colorname ) {
	for (int i=0;i<nbg_cols;i++)
		if	(!strcmp(bg_col[i],colorname)) {
			DBG2( ShowColors, "   BG%d: '%s' (reused)\n", i, colorname );
			return i|BG_MASK;
		}

	if (nbg_cols<MAX_BG) {
		DBG2( ShowColors, "   BG%d: '%s'\n", nbg_cols, colorname );
		bg_col[nbg_cols] = colorname;
		return (nbg_cols++)|BG_MASK;
	}
	else {
		DBG2( ShowColors, "   BG%d: '%s' *** TOO MANY COLORS\n",
																	nbg_cols, colorname );
		return -1;
	}
}
ColorId AddBallColor( const char *colorname ) {
	for (int i=0;i<nball_cols;i++)
		if	(!strcmp(ball_col[i],colorname)) {
			DBG2( ShowColors, " Ball%d: '%s' (reused)\n", i, colorname );
			return i;
		}

	if (nball_cols<MAX_BALL) {
		DBG2( ShowColors, " Ball%d: '%s'\n", nball_cols, colorname );
		ball_col[nball_cols]		= colorname;
		ball_ids[nball_ids++]	= nball_cols;
		return nball_cols++;
	}
	else {
		DBG2( ShowColors, " Ball%d: '%s' *** TOO MANY COLORS\n",
																	nball_cols, colorname );
		return -1;
	}
}
ColorId AddStatColor( const char *colorname ) {
	for (int i=0;i<nstat_cols;i++)
		if	(!strcmp(stat_col[i],colorname)) {
			DBG2( ShowColors, " Stat%d: '%s' (reused)\n", i, colorname );
			return i|STAT_MASK;
		}

	if (nstat_cols<MAX_STAT) {
		DBG2( ShowColors, " Stat%d: '%s'\n", nstat_cols, colorname );
		stat_col[nstat_cols]		= colorname;
		return (nstat_cols++)|STAT_MASK;
	}
	else {
		DBG2( ShowColors, " Stat%d: '%s' *** TOO MANY COLORS\n",
																	nstat_cols, colorname );
		return -1;
	}
}
int AddShadeColor( const char *colorname, int mult, int divi ) {
	for (int i=0;i<nshade_cols;i++)
		if	(!strcmp(shade_col[i],colorname))		return i;

	if (nshade_cols<MAX_SHADE) {
		DBG2( ShowColors, "Shade%d: '%s'\n", nshade_cols, colorname );
		shade_col[nshade_cols] = colorname;
		m[nshade_cols] = mult;
		d[nshade_cols] = divi;
		return nshade_cols++;
	}
	else {
		DBG2( ShowColors, "Shade%d: '%s' *** TOO MANY COLORS\n",
																	nball_cols, colorname );
		return -1;
	}
}
void SetCursorColor( const char *colorname ) {
	cursor_col = colorname;
}
ColorId SetMainBgColor( const char *colorname ) {
	ball_col[0] = colorname;
	DBG1( ShowColors, "MainBg: '%s' (Ball0)\n", colorname );
	return 0;
}

ColorId CreateColorMix( ColorId c1, ColorId c2, int fact ) {
	ColorId	mix = MIX_MASK | (c2<<COLOR_BITS) | c1
						| ((fact<<RAND_SHIFT)&RAND_MASK);

	if (!(c1&BG_MASK)&&!(c2&BG_MASK)) {
		ball_ids[nball_ids++]=mix;
		DBG4( ShowColors, "     %d: Mix %lx + %lx (%d:1)\n",
												nball_ids, c1, c2, fact );
	}
	else {
		DBG3( ShowColors, "         Mix %lx + %lx (%d:1)\n",
												c1, c2, fact );
	}
	return mix;
}


void ResetColor( ColorId id, const char *colorname ) {
	if (id&MIX_MASK) {
		printf( "error: mix-colors unchangeable\n" );
	}
	else {
		if (id&BG_MASK) {
			DBG2( ShowColors, "   BG%ld: '%s' (Reset)\n", id-BG_MASK, colorname );
			bg_col[(int)(id&COLOR_MASK)]=colorname;
		}
		else if (id&STAT_MASK) {
			DBG2( ShowColors, " Stat%ld: '%s' (Reset)\n", id, colorname );
			stat_col[(int)(id&COLOR_MASK)] = colorname;
		}
		else {
			DBG2( ShowColors, " Ball%ld: '%s' (Reset)\n", id, colorname );
			ball_col[(int)id] = colorname;
		}
	}
}

#ifndef __TURBOC__
#	include "xgraph.C"
#else
#	include "dosgraph.C"
#endif