1 #ifndef _global_h
2 # include "global.h"
3 #endif
4
5 #ifndef _object_h
6 # include "object.h"
7 #endif
8 #ifndef _graph_h
9 # include "graph.h"
10 #endif
11 #ifndef _pball_h
12 # include "pball.h"
13 #endif
14
15 double world_x, world_y;
16 int max_x, max_y;
17 double w2n;
18 int wall_click = 0;
19
20
21
Inside(Vec2 * v)22 void Inside( Vec2 *v ) {
23 double x=v->X();
24 double y=v->Y();
25
26 if (x<0) x=0;
27 if (x>max_x) x=max_x;
28 if (y<0) y=0;
29 if (y>max_y) y=max_y;
30 *v = Vec2(x,y);
31 }
32
33 static const int MAX_BG = 7;
34 static const int MAX_BALL = 15;
35 static const int MAX_SHADE = 3;
36 static const int MAX_STAT = 128;
37
38 int nbg_cols=0;
39 static const char *bg_col[MAX_BG];
40 unsigned long bg_pix[MAX_BG]; // aus Planes zusammengesetzt
41 static unsigned long bg_mask; // alle bg-Planes
42
43 int nball_cols=1;
44 static const char *ball_col[MAX_BALL] = { "Background-Dummy" };
45 unsigned long ball_pix[MAX_BALL]; // allokierte Pixel
46 static unsigned long ball_mask;
47
48 int nball_ids =0;
49 ColorId ball_ids[MAX_BALL]; // f�r B�lle verteilte Farb-Ids
50
51 int nstat_cols =0;
52 static const char *stat_col[MAX_STAT];
53 unsigned long stat_pix[MAX_STAT]; // Static-Colors (unter Cursor)
54
55 static int nshade_cols=0;
56 static const char *shade_col[MAX_SHADE];
57 static int m[MAX_SHADE], d[MAX_SHADE]; // Anteil Original : Schatten
58 static unsigned long shade_pix[MAX_SHADE]; // aus Planes zusammengesetzt
59 static unsigned long shade_mask; // alle Shade-Planes
60
61 static const char *cursor_col=0;
62 static unsigned long cursor_mask; // Cursor-Plane
63
InitColors()64 void InitColors() {
65 nbg_cols = 0;
66 nball_cols = 1;
67 nstat_cols = 0;
68 nball_ids = 0;
69 nshade_cols= 0;
70 }
71
GetAllocatedPixel(const char * colorname)72 unsigned long GetAllocatedPixel( const char *colorname ) {
73 int i;
74 for (i=0;i<nbg_cols;i++)
75 if (!strcmp(bg_col[i],colorname)) return bg_pix[i]|ball_pix[0];
76 for (i=0;i<nball_cols;i++)
77 if (!strcmp(ball_col[i],colorname)) return ball_pix[i];
78 for (i=0;i<nstat_cols;i++)
79 if (!strcmp(stat_col[i],colorname)) return stat_pix[i];
80 return 0;
81 }
82
GetAllocatedPixel(ColorId col,int x,int y)83 unsigned long GetAllocatedPixel( ColorId col, int x, int y ) {
84 if (col&MIX_MASK) {
85 if ( (x^y)&0x01 ) {
86 col = (col>>COLOR_BITS);
87 }
88 }
89 if (col&BG_MASK) return bg_pix[ (int)(col&COLOR_MASK) ];
90 else return ball_pix[ (int)(col&COLOR_MASK) ];
91 }
92
AddBgColor(const char * colorname)93 ColorId AddBgColor( const char *colorname ) {
94 for (int i=0;i<nbg_cols;i++)
95 if (!strcmp(bg_col[i],colorname)) {
96 DBG2( ShowColors, " BG%d: '%s' (reused)\n", i, colorname );
97 return i|BG_MASK;
98 }
99
100 if (nbg_cols<MAX_BG) {
101 DBG2( ShowColors, " BG%d: '%s'\n", nbg_cols, colorname );
102 bg_col[nbg_cols] = colorname;
103 return (nbg_cols++)|BG_MASK;
104 }
105 else {
106 DBG2( ShowColors, " BG%d: '%s' *** TOO MANY COLORS\n",
107 nbg_cols, colorname );
108 return -1;
109 }
110 }
AddBallColor(const char * colorname)111 ColorId AddBallColor( const char *colorname ) {
112 for (int i=0;i<nball_cols;i++)
113 if (!strcmp(ball_col[i],colorname)) {
114 DBG2( ShowColors, " Ball%d: '%s' (reused)\n", i, colorname );
115 return i;
116 }
117
118 if (nball_cols<MAX_BALL) {
119 DBG2( ShowColors, " Ball%d: '%s'\n", nball_cols, colorname );
120 ball_col[nball_cols] = colorname;
121 ball_ids[nball_ids++] = nball_cols;
122 return nball_cols++;
123 }
124 else {
125 DBG2( ShowColors, " Ball%d: '%s' *** TOO MANY COLORS\n",
126 nball_cols, colorname );
127 return -1;
128 }
129 }
AddStatColor(const char * colorname)130 ColorId AddStatColor( const char *colorname ) {
131 for (int i=0;i<nstat_cols;i++)
132 if (!strcmp(stat_col[i],colorname)) {
133 DBG2( ShowColors, " Stat%d: '%s' (reused)\n", i, colorname );
134 return i|STAT_MASK;
135 }
136
137 if (nstat_cols<MAX_STAT) {
138 DBG2( ShowColors, " Stat%d: '%s'\n", nstat_cols, colorname );
139 stat_col[nstat_cols] = colorname;
140 return (nstat_cols++)|STAT_MASK;
141 }
142 else {
143 DBG2( ShowColors, " Stat%d: '%s' *** TOO MANY COLORS\n",
144 nstat_cols, colorname );
145 return -1;
146 }
147 }
AddShadeColor(const char * colorname,int mult,int divi)148 int AddShadeColor( const char *colorname, int mult, int divi ) {
149 for (int i=0;i<nshade_cols;i++)
150 if (!strcmp(shade_col[i],colorname)) return i;
151
152 if (nshade_cols<MAX_SHADE) {
153 DBG2( ShowColors, "Shade%d: '%s'\n", nshade_cols, colorname );
154 shade_col[nshade_cols] = colorname;
155 m[nshade_cols] = mult;
156 d[nshade_cols] = divi;
157 return nshade_cols++;
158 }
159 else {
160 DBG2( ShowColors, "Shade%d: '%s' *** TOO MANY COLORS\n",
161 nball_cols, colorname );
162 return -1;
163 }
164 }
SetCursorColor(const char * colorname)165 void SetCursorColor( const char *colorname ) {
166 cursor_col = colorname;
167 }
SetMainBgColor(const char * colorname)168 ColorId SetMainBgColor( const char *colorname ) {
169 ball_col[0] = colorname;
170 DBG1( ShowColors, "MainBg: '%s' (Ball0)\n", colorname );
171 return 0;
172 }
173
CreateColorMix(ColorId c1,ColorId c2,int fact)174 ColorId CreateColorMix( ColorId c1, ColorId c2, int fact ) {
175 ColorId mix = MIX_MASK | (c2<<COLOR_BITS) | c1
176 | ((fact<<RAND_SHIFT)&RAND_MASK);
177
178 if (!(c1&BG_MASK)&&!(c2&BG_MASK)) {
179 ball_ids[nball_ids++]=mix;
180 DBG4( ShowColors, " %d: Mix %lx + %lx (%d:1)\n",
181 nball_ids, c1, c2, fact );
182 }
183 else {
184 DBG3( ShowColors, " Mix %lx + %lx (%d:1)\n",
185 c1, c2, fact );
186 }
187 return mix;
188 }
189
190
ResetColor(ColorId id,const char * colorname)191 void ResetColor( ColorId id, const char *colorname ) {
192 if (id&MIX_MASK) {
193 printf( "error: mix-colors unchangeable\n" );
194 }
195 else {
196 if (id&BG_MASK) {
197 DBG2( ShowColors, " BG%ld: '%s' (Reset)\n", id-BG_MASK, colorname );
198 bg_col[(int)(id&COLOR_MASK)]=colorname;
199 }
200 else if (id&STAT_MASK) {
201 DBG2( ShowColors, " Stat%ld: '%s' (Reset)\n", id, colorname );
202 stat_col[(int)(id&COLOR_MASK)] = colorname;
203 }
204 else {
205 DBG2( ShowColors, " Ball%ld: '%s' (Reset)\n", id, colorname );
206 ball_col[(int)id] = colorname;
207 }
208 }
209 }
210
211 #ifndef __TURBOC__
212 # include "xgraph.C"
213 #else
214 # include "dosgraph.C"
215 #endif
216
217