Mercurial > sdl-ios-xcode
comparison test/testpalette.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | 14717b52abc0 |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
34 /* | 34 /* |
35 * wave colours: Made by taking a narrow cross-section of a wave picture | 35 * wave colours: Made by taking a narrow cross-section of a wave picture |
36 * in Gimp, saving in PPM ascii format and formatting with Emacs macros. | 36 * in Gimp, saving in PPM ascii format and formatting with Emacs macros. |
37 */ | 37 */ |
38 static SDL_Color wavemap[] = { | 38 static SDL_Color wavemap[] = { |
39 {0,2,103}, {0,7,110}, {0,13,117}, {0,19,125}, | 39 {0, 2, 103}, {0, 7, 110}, {0, 13, 117}, {0, 19, 125}, |
40 {0,25,133}, {0,31,141}, {0,37,150}, {0,43,158}, | 40 {0, 25, 133}, {0, 31, 141}, {0, 37, 150}, {0, 43, 158}, |
41 {0,49,166}, {0,55,174}, {0,61,182}, {0,67,190}, | 41 {0, 49, 166}, {0, 55, 174}, {0, 61, 182}, {0, 67, 190}, |
42 {0,73,198}, {0,79,206}, {0,86,214}, {0,96,220}, | 42 {0, 73, 198}, {0, 79, 206}, {0, 86, 214}, {0, 96, 220}, |
43 {5,105,224}, {12,112,226}, {19,120,227}, {26,128,229}, | 43 {5, 105, 224}, {12, 112, 226}, {19, 120, 227}, {26, 128, 229}, |
44 {33,135,230}, {40,143,232}, {47,150,234}, {54,158,236}, | 44 {33, 135, 230}, {40, 143, 232}, {47, 150, 234}, {54, 158, 236}, |
45 {61,165,238}, {68,173,239}, {75,180,241}, {82,188,242}, | 45 {61, 165, 238}, {68, 173, 239}, {75, 180, 241}, {82, 188, 242}, |
46 {89,195,244}, {96,203,246}, {103,210,248}, {112,218,250}, | 46 {89, 195, 244}, {96, 203, 246}, {103, 210, 248}, {112, 218, 250}, |
47 {124,224,250}, {135,226,251}, {146,229,251}, {156,231,252}, | 47 {124, 224, 250}, {135, 226, 251}, {146, 229, 251}, {156, 231, 252}, |
48 {167,233,252}, {178,236,252}, {189,238,252}, {200,240,252}, | 48 {167, 233, 252}, {178, 236, 252}, {189, 238, 252}, {200, 240, 252}, |
49 {211,242,252}, {222,244,252}, {233,247,252}, {242,249,252}, | 49 {211, 242, 252}, {222, 244, 252}, {233, 247, 252}, {242, 249, 252}, |
50 {237,250,252}, {209,251,252}, {174,251,252}, {138,252,252}, | 50 {237, 250, 252}, {209, 251, 252}, {174, 251, 252}, {138, 252, 252}, |
51 {102,251,252}, {63,250,252}, {24,243,252}, {7,225,252}, | 51 {102, 251, 252}, {63, 250, 252}, {24, 243, 252}, {7, 225, 252}, |
52 {4,203,252}, {3,181,252}, {2,158,252}, {1,136,251}, | 52 {4, 203, 252}, {3, 181, 252}, {2, 158, 252}, {1, 136, 251}, |
53 {0,111,248}, {0,82,234}, {0,63,213}, {0,50,192}, | 53 {0, 111, 248}, {0, 82, 234}, {0, 63, 213}, {0, 50, 192}, |
54 {0,39,172}, {0,28,152}, {0,17,132}, {0,7,114} | 54 {0, 39, 172}, {0, 28, 152}, {0, 17, 132}, {0, 7, 114} |
55 }; | 55 }; |
56 | 56 |
57 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | 57 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
58 static void quit(int rc) | 58 static void |
59 { | 59 quit (int rc) |
60 SDL_Quit(); | 60 { |
61 exit(rc); | 61 SDL_Quit (); |
62 } | 62 exit (rc); |
63 | 63 } |
64 static void sdlerr(char *when) | 64 |
65 { | 65 static void |
66 fprintf(stderr, "SDL error: %s: %s\n", when, SDL_GetError()); | 66 sdlerr (char *when) |
67 quit(1); | 67 { |
68 fprintf (stderr, "SDL error: %s: %s\n", when, SDL_GetError ()); | |
69 quit (1); | |
68 } | 70 } |
69 | 71 |
70 /* create a background surface */ | 72 /* create a background surface */ |
71 static SDL_Surface *make_bg(SDL_Surface *screen, int startcol) | 73 static SDL_Surface * |
74 make_bg (SDL_Surface * screen, int startcol) | |
72 { | 75 { |
73 int i; | 76 int i; |
74 SDL_Surface *bg = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h, | 77 SDL_Surface *bg = |
75 8, 0, 0, 0, 0); | 78 SDL_CreateRGBSurface (SDL_SWSURFACE, screen->w, screen->h, |
76 if(!bg) | 79 8, 0, 0, 0, 0); |
77 sdlerr("creating background surface"); | 80 if (!bg) |
81 sdlerr ("creating background surface"); | |
78 | 82 |
79 /* set the palette to the logical screen palette so that blits | 83 /* set the palette to the logical screen palette so that blits |
80 won't be translated */ | 84 won't be translated */ |
81 SDL_SetColors(bg, screen->format->palette->colors, 0, 256); | 85 SDL_SetColors (bg, screen->format->palette->colors, 0, 256); |
82 | 86 |
83 /* Make a wavy background pattern using colours 0-63 */ | 87 /* Make a wavy background pattern using colours 0-63 */ |
84 if(SDL_LockSurface(bg) < 0) | 88 if (SDL_LockSurface (bg) < 0) |
85 sdlerr("locking background"); | 89 sdlerr ("locking background"); |
86 for(i = 0; i < SCRH; i++) { | 90 for (i = 0; i < SCRH; i++) { |
87 Uint8 *p = (Uint8 *)bg->pixels + i * bg->pitch; | 91 Uint8 *p = (Uint8 *) bg->pixels + i * bg->pitch; |
88 int j, d; | 92 int j, d; |
89 d = 0; | 93 d = 0; |
90 for(j = 0; j < SCRW; j++) { | 94 for (j = 0; j < SCRW; j++) { |
91 int v = MAX(d, -2); | 95 int v = MAX (d, -2); |
92 v = MIN(v, 2); | 96 v = MIN (v, 2); |
93 if(i > 0) | 97 if (i > 0) |
94 v += p[-bg->pitch] + 65 - startcol; | 98 v += p[-bg->pitch] + 65 - startcol; |
95 p[j] = startcol + (v & 63); | 99 p[j] = startcol + (v & 63); |
96 d += ((rand() >> 3) % 3) - 1; | 100 d += ((rand () >> 3) % 3) - 1; |
97 } | 101 } |
98 } | 102 } |
99 SDL_UnlockSurface(bg); | 103 SDL_UnlockSurface (bg); |
100 return(bg); | 104 return (bg); |
101 } | 105 } |
102 | 106 |
103 /* | 107 /* |
104 * Return a surface flipped horisontally. Only works for 8bpp; | 108 * Return a surface flipped horisontally. Only works for 8bpp; |
105 * extension to arbitrary bitness is left as an exercise for the reader. | 109 * extension to arbitrary bitness is left as an exercise for the reader. |
106 */ | 110 */ |
107 static SDL_Surface *hflip(SDL_Surface *s) | 111 static SDL_Surface * |
112 hflip (SDL_Surface * s) | |
108 { | 113 { |
109 int i; | 114 int i; |
110 SDL_Surface *z = SDL_CreateRGBSurface(SDL_SWSURFACE, s->w, s->h, 8, | 115 SDL_Surface *z = SDL_CreateRGBSurface (SDL_SWSURFACE, s->w, s->h, 8, |
111 0, 0, 0, 0); | 116 0, 0, 0, 0); |
112 /* copy palette */ | 117 /* copy palette */ |
113 SDL_SetColors(z, s->format->palette->colors, | 118 SDL_SetColors (z, s->format->palette->colors, |
114 0, s->format->palette->ncolors); | 119 0, s->format->palette->ncolors); |
115 if(SDL_LockSurface(s) < 0 || SDL_LockSurface(z) < 0) | 120 if (SDL_LockSurface (s) < 0 || SDL_LockSurface (z) < 0) |
116 sdlerr("locking flip images"); | 121 sdlerr ("locking flip images"); |
117 | 122 |
118 for(i = 0; i < s->h; i++) { | 123 for (i = 0; i < s->h; i++) { |
119 int j; | 124 int j; |
120 Uint8 *from = (Uint8 *)s->pixels + i * s->pitch; | 125 Uint8 *from = (Uint8 *) s->pixels + i * s->pitch; |
121 Uint8 *to = (Uint8 *)z->pixels + i * z->pitch + s->w - 1; | 126 Uint8 *to = (Uint8 *) z->pixels + i * z->pitch + s->w - 1; |
122 for(j = 0; j < s->w; j++) | 127 for (j = 0; j < s->w; j++) |
123 to[-j] = from[j]; | 128 to[-j] = from[j]; |
124 } | 129 } |
125 | 130 |
126 SDL_UnlockSurface(z); | 131 SDL_UnlockSurface (z); |
127 SDL_UnlockSurface(s); | 132 SDL_UnlockSurface (s); |
128 return z; | 133 return z; |
129 } | 134 } |
130 | 135 |
131 int main(int argc, char **argv) | 136 int |
137 main (int argc, char **argv) | |
132 { | 138 { |
133 SDL_Color cmap[256]; | 139 SDL_Color cmap[256]; |
134 SDL_Surface *screen; | 140 SDL_Surface *screen; |
135 SDL_Surface *bg; | 141 SDL_Surface *bg; |
136 SDL_Surface *boat[2]; | 142 SDL_Surface *boat[2]; |
141 int boatcols, frames, i, red; | 147 int boatcols, frames, i, red; |
142 int boatx[NBOATS], boaty[NBOATS], boatdir[NBOATS]; | 148 int boatx[NBOATS], boaty[NBOATS], boatdir[NBOATS]; |
143 int gamma_fade = 0; | 149 int gamma_fade = 0; |
144 int gamma_ramp = 0; | 150 int gamma_ramp = 0; |
145 | 151 |
146 if(SDL_Init(SDL_INIT_VIDEO) < 0) | 152 if (SDL_Init (SDL_INIT_VIDEO) < 0) |
147 sdlerr("initialising SDL"); | 153 sdlerr ("initialising SDL"); |
148 | 154 |
149 while(--argc) { | 155 while (--argc) { |
150 ++argv; | 156 ++argv; |
151 if(strcmp(*argv, "-hw") == 0) | 157 if (strcmp (*argv, "-hw") == 0) |
152 vidflags |= SDL_HWSURFACE; | 158 vidflags |= SDL_HWSURFACE; |
153 else if(strcmp(*argv, "-fullscreen") == 0) | 159 else if (strcmp (*argv, "-fullscreen") == 0) |
154 vidflags |= SDL_FULLSCREEN; | 160 vidflags |= SDL_FULLSCREEN; |
155 else if(strcmp(*argv, "-nofade") == 0) | 161 else if (strcmp (*argv, "-nofade") == 0) |
156 fade_max = 1; | 162 fade_max = 1; |
157 else if(strcmp(*argv, "-gamma") == 0) | 163 else if (strcmp (*argv, "-gamma") == 0) |
158 gamma_fade = 1; | 164 gamma_fade = 1; |
159 else if(strcmp(*argv, "-gammaramp") == 0) | 165 else if (strcmp (*argv, "-gammaramp") == 0) |
160 gamma_ramp = 1; | 166 gamma_ramp = 1; |
161 else { | 167 else { |
162 fprintf(stderr, | 168 fprintf (stderr, |
163 "usage: testpalette " | 169 "usage: testpalette " |
164 " [-hw] [-fullscreen] [-nofade] [-gamma] [-gammaramp]\n"); | 170 " [-hw] [-fullscreen] [-nofade] [-gamma] [-gammaramp]\n"); |
165 quit(1); | 171 quit (1); |
166 } | 172 } |
167 } | 173 } |
168 | 174 |
169 /* Ask explicitly for 8bpp and a hardware palette */ | 175 /* Ask explicitly for 8bpp and a hardware palette */ |
170 if((screen = SDL_SetVideoMode(SCRW, SCRH, 8, vidflags | SDL_HWPALETTE)) == NULL) { | 176 if ((screen = |
171 fprintf(stderr, "error setting %dx%d 8bpp indexed mode: %s\n", | 177 SDL_SetVideoMode (SCRW, SCRH, 8, vidflags | SDL_HWPALETTE)) == NULL) |
172 SCRW, SCRH, SDL_GetError()); | 178 { |
173 quit(1); | 179 fprintf (stderr, "error setting %dx%d 8bpp indexed mode: %s\n", |
174 } | 180 SCRW, SCRH, SDL_GetError ()); |
175 | 181 quit (1); |
176 if (vidflags & SDL_FULLSCREEN) SDL_ShowCursor (SDL_FALSE); | 182 } |
177 | 183 |
178 if((boat[0] = SDL_LoadBMP("sail.bmp")) == NULL) | 184 if (vidflags & SDL_FULLSCREEN) |
179 sdlerr("loading sail.bmp"); | 185 SDL_ShowCursor (SDL_FALSE); |
186 | |
187 if ((boat[0] = SDL_LoadBMP ("sail.bmp")) == NULL) | |
188 sdlerr ("loading sail.bmp"); | |
180 /* We've chosen magenta (#ff00ff) as colour key for the boat */ | 189 /* We've chosen magenta (#ff00ff) as colour key for the boat */ |
181 SDL_SetColorKey(boat[0], SDL_SRCCOLORKEY | SDL_RLEACCEL, | 190 SDL_SetColorKey (boat[0], SDL_SRCCOLORKEY | SDL_RLEACCEL, |
182 SDL_MapRGB(boat[0]->format, 0xff, 0x00, 0xff)); | 191 SDL_MapRGB (boat[0]->format, 0xff, 0x00, 0xff)); |
183 boatcols = boat[0]->format->palette->ncolors; | 192 boatcols = boat[0]->format->palette->ncolors; |
184 boat[1] = hflip(boat[0]); | 193 boat[1] = hflip (boat[0]); |
185 SDL_SetColorKey(boat[1], SDL_SRCCOLORKEY | SDL_RLEACCEL, | 194 SDL_SetColorKey (boat[1], SDL_SRCCOLORKEY | SDL_RLEACCEL, |
186 SDL_MapRGB(boat[1]->format, 0xff, 0x00, 0xff)); | 195 SDL_MapRGB (boat[1]->format, 0xff, 0x00, 0xff)); |
187 | 196 |
188 /* | 197 /* |
189 * First set the physical screen palette to black, so the user won't | 198 * First set the physical screen palette to black, so the user won't |
190 * see our initial drawing on the screen. | 199 * see our initial drawing on the screen. |
191 */ | 200 */ |
192 memset(cmap, 0, sizeof(cmap)); | 201 memset (cmap, 0, sizeof (cmap)); |
193 SDL_SetPalette(screen, SDL_PHYSPAL, cmap, 0, 256); | 202 SDL_SetPalette (screen, SDL_PHYSPAL, cmap, 0, 256); |
194 | 203 |
195 /* | 204 /* |
196 * Proper palette management is important when playing games with the | 205 * Proper palette management is important when playing games with the |
197 * colormap. We have divided the palette as follows: | 206 * colormap. We have divided the palette as follows: |
198 * | 207 * |
199 * index 0..(boatcols-1): used for the boat | 208 * index 0..(boatcols-1): used for the boat |
200 * index boatcols..(boatcols+63): used for the waves | 209 * index boatcols..(boatcols+63): used for the waves |
201 */ | 210 */ |
202 SDL_SetPalette(screen, SDL_LOGPAL, | 211 SDL_SetPalette (screen, SDL_LOGPAL, |
203 boat[0]->format->palette->colors, 0, boatcols); | 212 boat[0]->format->palette->colors, 0, boatcols); |
204 SDL_SetPalette(screen, SDL_LOGPAL, wavemap, boatcols, 64); | 213 SDL_SetPalette (screen, SDL_LOGPAL, wavemap, boatcols, 64); |
205 | 214 |
206 /* | 215 /* |
207 * Now the logical screen palette is set, and will remain unchanged. | 216 * Now the logical screen palette is set, and will remain unchanged. |
208 * The boats already have the same palette so fast blits can be used. | 217 * The boats already have the same palette so fast blits can be used. |
209 */ | 218 */ |
210 memcpy(cmap, screen->format->palette->colors, 256 * sizeof(SDL_Color)); | 219 memcpy (cmap, screen->format->palette->colors, 256 * sizeof (SDL_Color)); |
211 | 220 |
212 /* save the index of the red colour for later */ | 221 /* save the index of the red colour for later */ |
213 red = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00); | 222 red = SDL_MapRGB (screen->format, 0xff, 0x00, 0x00); |
214 | 223 |
215 bg = make_bg(screen, boatcols); /* make a nice wavy background surface */ | 224 bg = make_bg (screen, boatcols); /* make a nice wavy background surface */ |
216 | 225 |
217 /* initial screen contents */ | 226 /* initial screen contents */ |
218 if(SDL_BlitSurface(bg, NULL, screen, NULL) < 0) | 227 if (SDL_BlitSurface (bg, NULL, screen, NULL) < 0) |
219 sdlerr("blitting background to screen"); | 228 sdlerr ("blitting background to screen"); |
220 SDL_Flip(screen); /* actually put the background on screen */ | 229 SDL_Flip (screen); /* actually put the background on screen */ |
221 | 230 |
222 /* determine initial boat placements */ | 231 /* determine initial boat placements */ |
223 for(i = 0; i < NBOATS; i++) { | 232 for (i = 0; i < NBOATS; i++) { |
224 boatx[i] = (rand() % (SCRW + boat[0]->w)) - boat[0]->w; | 233 boatx[i] = (rand () % (SCRW + boat[0]->w)) - boat[0]->w; |
225 boaty[i] = i * (SCRH - boat[0]->h) / (NBOATS - 1); | 234 boaty[i] = i * (SCRH - boat[0]->h) / (NBOATS - 1); |
226 boatdir[i] = ((rand() >> 5) & 1) * 2 - 1; | 235 boatdir[i] = ((rand () >> 5) & 1) * 2 - 1; |
227 } | 236 } |
228 | 237 |
229 start = SDL_GetTicks(); | 238 start = SDL_GetTicks (); |
230 frames = 0; | 239 frames = 0; |
231 fade_dir = 1; | 240 fade_dir = 1; |
232 fade_level = 0; | 241 fade_level = 0; |
233 do { | 242 do { |
234 SDL_Event e; | 243 SDL_Event e; |
235 SDL_Rect updates[NBOATS]; | 244 SDL_Rect updates[NBOATS]; |
236 SDL_Rect r; | 245 SDL_Rect r; |
237 int redphase; | 246 int redphase; |
238 | 247 |
239 /* A small event loop: just exit on any key or mouse button event */ | 248 /* A small event loop: just exit on any key or mouse button event */ |
240 while(SDL_PollEvent(&e)) { | 249 while (SDL_PollEvent (&e)) { |
241 if(e.type == SDL_KEYDOWN || e.type == SDL_QUIT | 250 if (e.type == SDL_KEYDOWN || e.type == SDL_QUIT |
242 || e.type == SDL_MOUSEBUTTONDOWN) { | 251 || e.type == SDL_MOUSEBUTTONDOWN) { |
243 if(fade_dir < 0) | 252 if (fade_dir < 0) |
244 fade_level = 0; | 253 fade_level = 0; |
245 fade_dir = -1; | 254 fade_dir = -1; |
246 } | 255 } |
247 } | 256 } |
248 | 257 |
249 /* move boats */ | 258 /* move boats */ |
250 for(i = 0; i < NBOATS; i++) { | 259 for (i = 0; i < NBOATS; i++) { |
251 int old_x = boatx[i]; | 260 int old_x = boatx[i]; |
252 /* update boat position */ | 261 /* update boat position */ |
253 boatx[i] += boatdir[i] * SPEED; | 262 boatx[i] += boatdir[i] * SPEED; |
254 if(boatx[i] <= -boat[0]->w || boatx[i] >= SCRW) | 263 if (boatx[i] <= -boat[0]->w || boatx[i] >= SCRW) |
255 boatdir[i] = -boatdir[i]; | 264 boatdir[i] = -boatdir[i]; |
256 | 265 |
257 /* paint over the old boat position */ | 266 /* paint over the old boat position */ |
258 r.x = old_x; | 267 r.x = old_x; |
259 r.y = boaty[i]; | 268 r.y = boaty[i]; |
260 r.w = boat[0]->w; | 269 r.w = boat[0]->w; |
261 r.h = boat[0]->h; | 270 r.h = boat[0]->h; |
262 if(SDL_BlitSurface(bg, &r, screen, &r) < 0) | 271 if (SDL_BlitSurface (bg, &r, screen, &r) < 0) |
263 sdlerr("blitting background"); | 272 sdlerr ("blitting background"); |
264 | 273 |
265 /* construct update rectangle (bounding box of old and new pos) */ | 274 /* construct update rectangle (bounding box of old and new pos) */ |
266 updates[i].x = MIN(old_x, boatx[i]); | 275 updates[i].x = MIN (old_x, boatx[i]); |
267 updates[i].y = boaty[i]; | 276 updates[i].y = boaty[i]; |
268 updates[i].w = boat[0]->w + SPEED; | 277 updates[i].w = boat[0]->w + SPEED; |
269 updates[i].h = boat[0]->h; | 278 updates[i].h = boat[0]->h; |
270 /* clip update rectangle to screen */ | 279 /* clip update rectangle to screen */ |
271 if(updates[i].x < 0) { | 280 if (updates[i].x < 0) { |
272 updates[i].w += updates[i].x; | 281 updates[i].w += updates[i].x; |
273 updates[i].x = 0; | 282 updates[i].x = 0; |
274 } | 283 } |
275 if(updates[i].x + updates[i].w > SCRW) | 284 if (updates[i].x + updates[i].w > SCRW) |
276 updates[i].w = SCRW - updates[i].x; | 285 updates[i].w = SCRW - updates[i].x; |
277 } | 286 } |
278 | 287 |
279 for(i = 0; i < NBOATS; i++) { | 288 for (i = 0; i < NBOATS; i++) { |
280 /* paint boat on new position */ | 289 /* paint boat on new position */ |
281 r.x = boatx[i]; | 290 r.x = boatx[i]; |
282 r.y = boaty[i]; | 291 r.y = boaty[i]; |
283 if(SDL_BlitSurface(boat[(boatdir[i] + 1) / 2], NULL, | 292 if (SDL_BlitSurface (boat[(boatdir[i] + 1) / 2], NULL, |
284 screen, &r) < 0) | 293 screen, &r) < 0) |
285 sdlerr("blitting boat"); | 294 sdlerr ("blitting boat"); |
286 } | 295 } |
287 | 296 |
288 /* cycle wave palette */ | 297 /* cycle wave palette */ |
289 for(i = 0; i < 64; i++) | 298 for (i = 0; i < 64; i++) |
290 cmap[boatcols + ((i + frames) & 63)] = wavemap[i]; | 299 cmap[boatcols + ((i + frames) & 63)] = wavemap[i]; |
291 | 300 |
292 if(fade_dir) { | 301 if (fade_dir) { |
293 /* Fade the entire palette in/out */ | 302 /* Fade the entire palette in/out */ |
294 fade_level += fade_dir; | 303 fade_level += fade_dir; |
295 | 304 |
296 if(gamma_fade) { | 305 if (gamma_fade) { |
297 /* Fade linearly in gamma level (lousy) */ | 306 /* Fade linearly in gamma level (lousy) */ |
298 float level = (float)fade_level / fade_max; | 307 float level = (float) fade_level / fade_max; |
299 if(SDL_SetGamma(level, level, level) < 0) | 308 if (SDL_SetGamma (level, level, level) < 0) |
300 sdlerr("setting gamma"); | 309 sdlerr ("setting gamma"); |
301 | 310 |
302 } else if(gamma_ramp) { | 311 } else if (gamma_ramp) { |
303 /* Fade using gamma ramp (better) */ | 312 /* Fade using gamma ramp (better) */ |
304 Uint16 ramp[256]; | 313 Uint16 ramp[256]; |
305 for(i = 0; i < 256; i++) | 314 for (i = 0; i < 256; i++) |
306 ramp[i] = (i * fade_level / fade_max) << 8; | 315 ramp[i] = (i * fade_level / fade_max) << 8; |
307 if(SDL_SetGammaRamp(ramp, ramp, ramp) < 0) | 316 if (SDL_SetGammaRamp (ramp, ramp, ramp) < 0) |
308 sdlerr("setting gamma ramp"); | 317 sdlerr ("setting gamma ramp"); |
309 | 318 |
310 } else { | 319 } else { |
311 /* Fade using direct palette manipulation (best) */ | 320 /* Fade using direct palette manipulation (best) */ |
312 memcpy(cmap, screen->format->palette->colors, | 321 memcpy (cmap, screen->format->palette->colors, |
313 boatcols * sizeof(SDL_Color)); | 322 boatcols * sizeof (SDL_Color)); |
314 for(i = 0; i < boatcols + 64; i++) { | 323 for (i = 0; i < boatcols + 64; i++) { |
315 cmap[i].r = cmap[i].r * fade_level / fade_max; | 324 cmap[i].r = cmap[i].r * fade_level / fade_max; |
316 cmap[i].g = cmap[i].g * fade_level / fade_max; | 325 cmap[i].g = cmap[i].g * fade_level / fade_max; |
317 cmap[i].b = cmap[i].b * fade_level / fade_max; | 326 cmap[i].b = cmap[i].b * fade_level / fade_max; |
318 } | 327 } |
319 } | 328 } |
320 if(fade_level == fade_max) | 329 if (fade_level == fade_max) |
321 fade_dir = 0; | 330 fade_dir = 0; |
322 } | 331 } |
323 | 332 |
324 /* pulse the red colour (done after the fade, for a night effect) */ | 333 /* pulse the red colour (done after the fade, for a night effect) */ |
325 redphase = frames % 64; | 334 redphase = frames % 64; |
326 cmap[red].r = (int)(255 * sin(redphase * M_PI / 63)); | 335 cmap[red].r = (int) (255 * sin (redphase * M_PI / 63)); |
327 | 336 |
328 SDL_SetPalette(screen, SDL_PHYSPAL, cmap, 0, boatcols + 64); | 337 SDL_SetPalette (screen, SDL_PHYSPAL, cmap, 0, boatcols + 64); |
329 | 338 |
330 /* update changed areas of the screen */ | 339 /* update changed areas of the screen */ |
331 SDL_UpdateRects(screen, NBOATS, updates); | 340 SDL_UpdateRects (screen, NBOATS, updates); |
332 frames++; | 341 frames++; |
333 } while(fade_level > 0); | 342 } |
334 | 343 while (fade_level > 0); |
335 printf("%d frames, %.2f fps\n", | 344 |
336 frames, 1000.0 * frames / (SDL_GetTicks() - start)); | 345 printf ("%d frames, %.2f fps\n", |
337 | 346 frames, 1000.0 * frames / (SDL_GetTicks () - start)); |
338 if (vidflags & SDL_FULLSCREEN) SDL_ShowCursor (SDL_TRUE); | 347 |
339 SDL_Quit(); | 348 if (vidflags & SDL_FULLSCREEN) |
349 SDL_ShowCursor (SDL_TRUE); | |
350 SDL_Quit (); | |
340 return 0; | 351 return 0; |
341 } | 352 } |
342 |