Mercurial > hg > forks > 3x666-SDL
comparison 3x666.c @ 11:fcae85b39931
Slowly getting closer. Does not compile yet, and it's messy.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 15 Mar 2013 15:47:20 +0200 |
parents | 84d7bc7dfaeb |
children | 3a358d053ffc |
comparison
equal
deleted
inserted
replaced
10:fee680bb71fd | 11:fcae85b39931 |
---|---|
4 #include <unistd.h> | 4 #include <unistd.h> |
5 #include <string.h> | 5 #include <string.h> |
6 #include "config.h" | 6 #include "config.h" |
7 #include "3xfont.h" | 7 #include "3xfont.h" |
8 | 8 |
9 | |
9 /** typedefs **/ | 10 /** typedefs **/ |
11 #if !defined(FALSE) && !defined(TRUE) && !defined(BOOL) | |
12 typedef enum { FALSE = 0, TRUE = 1 } BOOL; | |
13 #endif | |
14 | |
15 #ifndef BOOL | |
16 # ifdef bool | |
17 # define BOOL bool | |
18 # else | |
19 # define BOOL int | |
20 # endif | |
21 #endif | |
22 | |
23 struct | |
24 { | |
25 int tickLen; | |
26 int frameTime, frameCount, | |
27 startTime, endTime; | |
28 | |
29 BOOL exitFlag; | |
30 | |
31 int optVFlags; | |
32 SDL_Surface *screen; | |
33 SDL_Event event; | |
34 SDL_AudioSpec optAfmt; | |
35 } engine; | |
36 | |
37 | |
10 | 38 |
11 typedef struct | 39 typedef struct |
12 { | 40 { |
13 int x, y, z; | 41 int x, y, z; |
14 } vec3d; | 42 } vec3d; |
15 | 43 |
16 int TIKLGT; | 44 |
17 | |
18 SDL_Color pal[256]; | |
19 Uint8 *ruutu; | |
20 | |
21 int *mxbuf; | |
22 int *ballz; | 45 int *ballz; |
23 | 46 |
47 | |
48 static inline int dmClamp(const int v, const int min, const int max) | |
49 { | |
50 return (v < min ? min : (v > max ? max : v)); | |
51 } | |
52 | |
24 /**************** tEXT dRAWiNG rOUTiNES ********** | 53 /**************** tEXT dRAWiNG rOUTiNES ********** |
25 | 54 |
26 bitmaps are for lamers :) let's use a little 12-segment calculator font... | 55 bitmaps are for lamers :) let's use a little 12-segment calculator font... |
27 ascii chars 32..90, 16 bits per char unpacked -> 114 bytes for the whole | 56 ascii chars 32..90, 16 bits per char unpacked -> 114 bytes for the whole |
28 font ;) let's credit karl/nooon for the original idea. */ | 57 font ;) let's credit karl/nooon for the original idea. */ |
29 | 58 |
30 void drawseg(int y, int x, int w, int h) | 59 void drawseg(int y, int x, int w, int h) |
31 { | 60 { |
32 /* clip clip clip */ | 61 /* clip clip clip */ |
33 if (x + w > BUFW) | 62 if (x + w > SET_VID_BUFW) |
34 w = BUFW - x; | 63 w = SET_VID_BUFW - x; |
35 if (x < 0) | 64 if (x < 0) |
36 { | 65 { |
37 w += x; | 66 w += x; |
38 x = 0; | 67 x = 0; |
39 } | 68 } |
40 if (y + h > BUFH) | 69 if (y + h > SET_VID_BUFH) |
41 h = BUFH - y; | 70 h = SET_VID_BUFH - y; |
42 if (y < 0) | 71 if (y < 0) |
43 { | 72 { |
44 h += y; | 73 h += y; |
45 y = 0; | 74 y = 0; |
46 } | 75 } |
47 if (w > 0 && h > 0) | 76 if (w > 0 && h > 0) |
48 { | 77 { |
49 Uint8 *b = ruutu + y * BUFW + x; | 78 Uint8 *b = engine.screen->pixels + (y * engine.screen->pitch) + x; |
50 for (; h; h--) | 79 for (; h; h--) |
51 { | 80 { |
52 memset(b, 122, w); | 81 memset(b, 122, w); |
53 b += BUFW; | 82 b += engine.screen->pitch; |
54 } | 83 } |
55 } | 84 } |
56 } | 85 } |
57 | 86 |
58 void drawchar(int x, int y, int c, int xunit, int yunit) | 87 void drawchar(int x, int y, int c, int xunit, int yunit) |
86 } | 115 } |
87 } | 116 } |
88 | 117 |
89 void drawtxtscr(char *str) | 118 void drawtxtscr(char *str) |
90 { | 119 { |
91 int x = BUFW >> 4, y = BUFH >> 3; | 120 int x = SET_VID_BUFW >> 4, y = SET_VID_BUFH >> 3; |
92 while (*str) | 121 while (*str) |
93 { | 122 { |
94 if (*str >= 32) | 123 if (*str >= 32) |
95 { | 124 { |
96 drawchar(x, y, phont[*str - 32], BUFW / 50, BUFW / 80); | 125 drawchar(x, y, phont[*str - 32], SET_VID_BUFW / 50, SET_VID_BUFW / 80); |
97 x += BUFW / 10; | 126 x += SET_VID_BUFW / 10; |
98 } | 127 } |
99 else | 128 else |
100 { | 129 { |
101 x = BUFW >> 4; | 130 x = SET_VID_BUFW >> 4; |
102 y += BUFW / 10; | 131 y += SET_VID_BUFW / 10; |
103 } | 132 } |
104 str++; | 133 str++; |
105 } | 134 } |
106 } | 135 } |
107 | 136 |
108 | 137 |
109 void flashtxt(char *str) | 138 void flashtxt(char *str) |
110 { | 139 { |
111 int x = (BUFW >> 1) - (strlen(str) + 1) * 3 * BUFW / 80; | 140 int x = (SET_VID_BUFW >> 1) - (strlen(str) + 1) * 3 * SET_VID_BUFW / 80; |
112 while (*str) | 141 while (*str) |
113 { | 142 { |
114 drawchar(x, BUFH >> 1, phont[*str++ - 32], BUFW / 50, BUFW / 80); | 143 drawchar(x, SET_VID_BUFH >> 1, phont[*str++ - 32], SET_VID_BUFW / 50, SET_VID_BUFW / 80); |
115 x += BUFW / 10; | 144 x += SET_VID_BUFW / 10; |
116 } | 145 } |
117 } | 146 } |
118 | 147 |
119 /*************************** DA PHONGBALL HEAVEN ************** | 148 /*************************** DA PHONGBALL HEAVEN ************** |
120 | 149 |
142 of the form f(x)=a*x^2+c. This approximation makes the ball look a bit | 171 of the form f(x)=a*x^2+c. This approximation makes the ball look a bit |
143 "twisty" but who cares, it just looks damn cool ;) | 172 "twisty" but who cares, it just looks damn cool ;) |
144 | 173 |
145 ***/ | 174 ***/ |
146 | 175 |
147 #if (BUFH < BUFW) | 176 #if (SET_VID_BUFH < SET_VID_BUFW) |
148 # define maxR (BUFH >> 1) | 177 # define maxR (SET_VID_BUFH >> 1) |
149 #else | 178 #else |
150 # define maxR (BUFW >> 1) | 179 # define maxR (SET_VID_BUFW >> 1) |
151 #endif | 180 #endif |
152 | 181 |
153 struct | 182 struct |
154 { | 183 { |
155 int *tab; | 184 int *tab; |
195 int R = balltab[relR].R, *s = balltab[relR].tab; | 224 int R = balltab[relR].R, *s = balltab[relR].tab; |
196 | 225 |
197 signed int doty = (-(R - 1) * l->y); | 226 signed int doty = (-(R - 1) * l->y); |
198 signed int y = R * 2 - 2; | 227 signed int y = R * 2 - 2; |
199 | 228 |
200 d += (BUFW >> 1) - R + ((BUFH >> 1) - R) * BUFW; | 229 d += (SET_VID_BUFW >> 1) - R + ((SET_VID_BUFH >> 1) - R) * SET_VID_BUFW; |
201 | 230 |
202 if (y) | 231 if (y) |
203 { | 232 { |
204 for (; y; y--) | 233 for (; y; y--) |
205 { | 234 { |
207 if (halfw) | 236 if (halfw) |
208 drawball_inloop(d + R - halfw, | 237 drawball_inloop(d + R - halfw, |
209 (doty - (l->x * halfw)) << 8, | 238 (doty - (l->x * halfw)) << 8, |
210 (l->x + l->z) << 8, | 239 (l->x + l->z) << 8, |
211 0 - ((l->z << 8) / halfw), halfw << 1); | 240 0 - ((l->z << 8) / halfw), halfw << 1); |
212 d += BUFW; | 241 d += SET_VID_BUFW; |
213 doty += l->y; | 242 doty += l->y; |
214 } | 243 } |
215 } | 244 } |
216 } | 245 } |
217 | 246 |
218 /* some extra for freaks: a plasma made with the phongball innerloop :) | 247 /* some extra for freaks: a plasma made with the phongball innerloop :) |
219 looks ugly. | 248 looks ugly. |
220 | 249 |
221 void drawplasma(char *d,float t) | 250 void drawplasma(char *d,float t) |
222 { | 251 { |
223 int y=BUFH; float u=0,du=500/BUFH; | 252 int y=SET_VID_BUFH; float u=0,du=500/SET_VID_BUFH; |
224 | 253 |
225 for(;y;y--){ | 254 for(;y;y--){ |
226 drawball_inloop(d, | 255 drawball_inloop(d, |
227 sin(t*0.02+0+u*0.033)*65536*256, | 256 sin(t*0.02+0+u*0.033)*65536*256, |
228 cos(t*0.04+1+u*0.022)*65536*4096/BUFW, | 257 cos(t*0.04+1+u*0.022)*65536*4096/SET_VID_BUFW, |
229 -2*cos(t*0.04+1+u*0.022)*65536*4096/(BUFW*BUFW), BUFW); | 258 -2*cos(t*0.04+1+u*0.022)*65536*4096/(SET_VID_BUFW*SET_VID_BUFW), SET_VID_BUFW); |
230 d+=BUFW; | 259 d+=SET_VID_BUFW; |
231 u+=du; | 260 u+=du; |
232 } | 261 } |
233 } | 262 } |
234 */ | 263 */ |
235 | 264 |
236 /************************ oTHA FX ***************/ | 265 /************************ oTHA FX ***************/ |
237 | 266 |
238 void rotochess(Uint8 *d, int du, int dv, int iu, int iv) | 267 void rotochess(SDL_Surface *screen, int du, int dv, int iu, int iv) |
239 { | 268 { |
240 int hu = iu - (dv * (BUFH >> 1)) - (du * (BUFW >> 1)), | 269 int hu = iu - (dv * (SET_VID_BUFH >> 1)) - (du * (SET_VID_BUFW >> 1)), |
241 hv = iv + (du * (BUFH >> 1)) - (dv * (BUFW >> 1)); | 270 hv = iv + (du * (SET_VID_BUFH >> 1)) - (dv * (SET_VID_BUFW >> 1)); |
242 | 271 |
243 int y; | 272 int y; |
244 for (y = BUFH; y; y--) | 273 Uint8 *dp = screen->pixels; |
245 { | 274 |
246 { | 275 for (y = SET_VID_BUFH; y; y--) |
247 register int u = hu, v = hv, x = BUFW; | 276 { |
248 for (; x; x--) | 277 Uint8 *d = dp; |
249 { | 278 int u = hu, v = hv, x; |
250 u += du; | 279 for (x = SET_VID_BUFW; x; x--) |
251 v += dv; | 280 { |
252 *d++ = ((u ^ v) >> 8) & 0xb1; | 281 u += du; |
253 } | 282 v += dv; |
254 } | 283 *d++ = ((u ^ v) >> 8) & 0xb1; |
284 } | |
285 dp += screen->pitch; | |
255 hu += dv; | 286 hu += dv; |
256 hv -= du; | 287 hv -= du; |
257 } | 288 } |
258 } | 289 } |
259 | 290 |
260 /***************************************************************/ | 291 /***************************************************************/ |
261 | 292 |
262 | 293 |
263 void setpal() | 294 void setpal() |
264 { | 295 { |
296 SDL_Color pal[SET_VID_COLORS]; | |
265 int i, a = 3, b = 0; | 297 int i, a = 3, b = 0; |
298 | |
266 for (i = 255; i; i--) | 299 for (i = 255; i; i--) |
267 { | 300 { |
268 SDL_Color *d = &pal[(i + 128) & 255]; | 301 int n = (i + 128) & 255; |
269 d->r = (abs(i - 140) >> a) & 255; | 302 pal[n].r = (abs(i - 140) >> a) & 255; |
270 d->g = ((abs(i - 128) >> b) & 255) ^ 1; | 303 pal[n].g = ((abs(i - 128) >> b) & 255) ^ 1; |
271 d->b = (abs(i - 96) >> b) & 255; | 304 pal[n].b = (abs(i - 96) >> b) & 255; |
272 if (i == 128) | 305 if (i == 128) |
273 { | 306 { |
274 a = 0; | 307 a = 0; |
275 b = 1; | 308 b = 1; |
276 } | 309 } |
277 } | 310 } |
278 oxl_setpalette(pal); | 311 |
312 SDL_SetColors(engine.screen, pal, 0, SET_VID_COLORS); | |
279 } | 313 } |
280 | 314 |
281 | 315 |
282 void unitvec(vec3d * v, float a, float b, float c, float m) | 316 void unitvec(vec3d * v, float a, float b, float c, float m) |
283 { | 317 { |
336 | 370 |
337 | 371 |
338 /* sampling sucks! */ | 372 /* sampling sucks! */ |
339 void audio_precalcs() | 373 void audio_precalcs() |
340 { | 374 { |
341 int drumlgt = TIKLGT * ROWTIX * 4; | 375 int drumlgt = engine.tickLen * SET_ROWTIX * 4; |
342 int *d = drum0 = malloc(drumlgt * sizeof(int)), | 376 int *d = drum0 = malloc(drumlgt * sizeof(int)), |
343 *e = drum1 = malloc(drumlgt * sizeof(int)), i, | 377 *e = drum1 = malloc(drumlgt * sizeof(int)), i, |
344 vol = 24680, dvol = 35000 / (float) drumlgt; | 378 vol = 24680, dvol = 35000 / (float) drumlgt; |
345 int o = 0, oo = 0; | 379 int o = 0, oo = 0; |
346 float a = 0, da = 386 / (float) drumlgt, dda = da / (float) drumlgt; | 380 float a = 0, da = 386 / (float) drumlgt, dda = da / (float) drumlgt; |
370 vol -= dvol; | 404 vol -= dvol; |
371 } | 405 } |
372 } | 406 } |
373 | 407 |
374 | 408 |
375 /* mixes the next row of music into b */ | 409 static void engineAudioCallback(void *userdata, Uint8 *stream, int len) |
376 int *audio_mix(void) | 410 { |
377 { | 411 #if 0 |
412 (void) userdata; | |
378 static int rowno = 0; | 413 static int rowno = 0; |
379 static signed int delta = -5; | 414 static signed int delta = -5; |
380 static char ismelody = 0, silend = 0; | 415 static char ismelody = 0, silend = 0; |
381 | 416 |
382 int rowlgt = TIKLGT * ROWTIX, i; | 417 int rowlgt = engine.tickLen * SET_ROWTIX, i; |
383 int *d = mxbuf, note; | 418 int *d = mxbuf, note; |
384 | 419 |
385 /* BASS (sawtooth ofcoz) */ | 420 /* BASS (sawtooth ofcoz) */ |
386 | 421 |
387 *d++ = rowlgt; | 422 *d++ = rowlgt; |
399 | 434 |
400 if (note) | 435 if (note) |
401 { | 436 { |
402 int ps = 16384, dps; | 437 int ps = 16384, dps; |
403 note += delta; | 438 note += delta; |
404 dps = ((noterate[note] << 10) / AUFREQ); | 439 dps = ((noterate[note] << 10) / SET_AUDIO_FREQ); |
405 for (i = rowlgt; i; i--) | 440 for (i = rowlgt; i; i--) |
406 { | 441 { |
407 *d++ = ps; | 442 *d++ = ps; |
408 ps = (ps + dps) & 32767; | 443 ps = (ps + dps) & 32767; |
409 } | 444 } |
427 note = melody[(rowno >> 1) & 31]; | 462 note = melody[(rowno >> 1) & 31]; |
428 if (note) | 463 if (note) |
429 { | 464 { |
430 int ps = 16384, dps; /* this loop is different */ | 465 int ps = 16384, dps; /* this loop is different */ |
431 note += delta; | 466 note += delta; |
432 dps = ((noterate[note] << 12) / AUFREQ); | 467 dps = ((noterate[note] << 12) / engine.optAfmt.freq); |
433 for (i = rowlgt; i; i--) | 468 for (i = rowlgt; i; i--) |
434 { | 469 { |
435 *d++ += ps; | 470 *d++ += ps; |
436 ps = (ps + dps) & 32767; | 471 ps = (ps + dps) & 32767; |
437 } | 472 } |
475 { | 510 { |
476 rowno = ismelody = silend = 0; | 511 rowno = ismelody = silend = 0; |
477 delta = -5; | 512 delta = -5; |
478 } | 513 } |
479 } | 514 } |
480 return mxbuf; | 515 |
516 // if (engine.dev != NULL) | |
517 // jvmRenderAudio(engine.dev, stream, len / jvmGetSampleSize(engine.dev)); | |
518 #endif | |
481 } | 519 } |
482 | 520 |
483 | 521 |
484 /**************** tEXT gENERATORS eTC ***************/ | 522 /**************** tEXT gENERATORS eTC ***************/ |
485 | 523 |
486 char skrtxt[] = { | 524 char skrtxt[] = |
525 { | |
487 " HI THERE ! THIS IS THE FIRST OCSA RELEASE FOR LINUX ! " | 526 " HI THERE ! THIS IS THE FIRST OCSA RELEASE FOR LINUX ! " |
488 "IT'S A STUPID INTRO CALLED 3X666 ! " | 527 "IT'S A STUPID INTRO CALLED 3X666 ! " |
489 }; | 528 }; |
490 | 529 |
491 | 530 |
493 #define CHPSCR 8 | 532 #define CHPSCR 8 |
494 | 533 |
495 void plainscroll(int t) | 534 void plainscroll(int t) |
496 { | 535 { |
497 int chno = t / CHTIME; | 536 int chno = t / CHTIME; |
498 int x = 0 - ((t % CHTIME) * (BUFW / CHPSCR)) / CHTIME; | 537 int x = 0 - ((t % CHTIME) * (SET_VID_BUFW / CHPSCR)) / CHTIME; |
499 int h = (abs((t % 48) - 24) * BUFH) / 256, i; | 538 int h = (abs((t % 48) - 24) * SET_VID_BUFH) / 256, i; |
500 char *c = skrtxt + chno; | 539 char *c = skrtxt + chno; |
501 | 540 |
502 for (i = 0; i < CHPSCR + 1; i++) | 541 for (i = 0; i < CHPSCR + 1; i++) |
503 { | 542 { |
504 drawchar(x, (BUFH * 3) / 4, phont[*c++ - 32], BUFW / (6 * CHPSCR), h); | 543 drawchar(x, (SET_VID_BUFH * 3) / 4, phont[*c++ - 32], SET_VID_BUFW / (6 * CHPSCR), h); |
505 x += BUFW / CHPSCR; | 544 x += SET_VID_BUFW / CHPSCR; |
506 } | 545 } |
507 } | 546 } |
508 | 547 |
509 char *lyrix(void) | 548 char *lyrix(void) |
510 { | 549 { |
727 | 766 |
728 | 767 |
729 void doendscroll(int t) | 768 void doendscroll(int t) |
730 { | 769 { |
731 const char *s = endscroll; | 770 const char *s = endscroll; |
732 int y = BUFH - (BUFH * t / 512), x = BUFW / 24; | 771 int y = SET_VID_BUFH - (SET_VID_BUFH * t / 512), x = SET_VID_BUFW / 24; |
733 | 772 |
734 while (*s) | 773 while (*s) |
735 { | 774 { |
736 if (*s < 32) | 775 if (*s < 32) |
737 { | 776 { |
738 x = BUFW / 24; | 777 x = SET_VID_BUFW / 24; |
739 y += BUFH / 8; | 778 y += SET_VID_BUFH / 8; |
740 } | 779 } |
741 else | 780 else |
742 if (y >= 0 - (BUFH / 8) && y < BUFH) | 781 if (y >= 0 - (SET_VID_BUFH / 8) && y < SET_VID_BUFH) |
743 { | 782 { |
744 drawchar(x, y, phont[*s - 32], BUFW / 60, BUFH / 60); | 783 drawchar(x, y, phont[*s - 32], SET_VID_BUFW / 60, SET_VID_BUFH / 60); |
745 x += BUFW / 13; | 784 x += SET_VID_BUFW / 13; |
746 } | 785 } |
747 s++; | 786 s++; |
748 } | 787 } |
749 } | 788 } |
750 | 789 |
787 | 826 |
788 /* don't look at the rest of the code, it just sucks :) */ | 827 /* don't look at the rest of the code, it just sucks :) */ |
789 | 828 |
790 int main(int argc, char *argv[]) | 829 int main(int argc, char *argv[]) |
791 { | 830 { |
831 BOOL initSDL = FALSE; | |
792 vec3d joo; | 832 vec3d joo; |
793 const int U = BUFW / 40; | 833 const int U = SET_VID_BUFW / 40; |
794 int flagz = 0; | 834 int flagz = 0; |
795 const short *dez = dezign; | 835 const short *dez = dezign; |
796 char *phiword = NULL, *dizainword = NULL; | 836 char *phiword = NULL, *dizainword = NULL; |
797 int flixtim = 0; | 837 int flixtim = 0; |
798 | 838 |
839 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) | |
840 { | |
841 dmError("Could not initialize SDL: %s\n", SDL_GetError()); | |
842 goto error_exit; | |
843 } | |
844 initSDL = TRUE; | |
845 | |
846 engine.optAfmt.freq = SET_AUDIO_FREQ; | |
847 engine.optAfmt.format = AUDIO_S16SYS; | |
848 engine.optAfmt.channels = SET_AUDIO_CHN; | |
849 engine.optAfmt.samples = engine.optAfmt.freq / 16; | |
850 engine.optAfmt.callback = engineAudioCallback; | |
851 | |
852 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0) | |
853 { | |
854 dmError("Couldn't open SDL audio: %s\n", SDL_GetError()); | |
855 } | |
856 | |
857 // foo | |
858 engine.screen = SDL_SetVideoMode(SET_VID_BUFW, SET_VID_BUFH, 8, engine.optVFlags); | |
859 if (engine.screen == NULL) | |
860 { | |
861 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); | |
862 return FALSE; | |
863 } | |
864 | |
865 SDL_ShowCursor(SDL_DISABLE); | |
866 SDL_WM_SetCaption(SET_WIN_NAME, SET_WIN_NAME); | |
867 | |
799 preball(); | 868 preball(); |
800 srand((int) time(NULL)); | 869 srand(0); |
801 | 870 |
802 TIKLGT = AUFREQ / DEMOHZ; | 871 engine.tickLen = engine.optAfmt.freq / SET_DEMOHZ; |
803 mxbuf = malloc(MAXROWLGT * sizeof(int)); | |
804 audio_precalcs(); | 872 audio_precalcs(); |
805 | |
806 setpal(); | 873 setpal(); |
807 | 874 |
808 for (;;) | 875 SDL_LockAudio(); |
809 { | 876 SDL_PauseAudio(0); |
810 int t = oxl_timer(); | 877 SDL_UnlockAudio(); |
811 | 878 engine.startTime = SDL_GetTicks(); |
812 while ((t / ROWTIX >= *dez) && (flagz & DEMOEND) == 0) | 879 |
880 while (!engine.exitFlag) | |
881 { | |
882 while (SDL_PollEvent(&engine.event)) | |
883 switch (engine.event.type) | |
884 { | |
885 case SDL_KEYDOWN: | |
886 switch (engine.event.key.keysym.sym) | |
887 { | |
888 case SDLK_ESCAPE: | |
889 engine.exitFlag = TRUE; | |
890 break; | |
891 | |
892 case SDLK_f: | |
893 engine.optVFlags ^= SDL_FULLSCREEN; | |
894 if (!engineInitializeVideo()) | |
895 goto error_exit; | |
896 break; | |
897 | |
898 case SDLK_RETURN: | |
899 if (engine.event.key.keysym.mod & KMOD_ALT) | |
900 { | |
901 engine.optVFlags ^= SDL_FULLSCREEN; | |
902 if (!engineInitializeVideo()) | |
903 goto error_exit; | |
904 } | |
905 break; | |
906 | |
907 default: | |
908 break; | |
909 } | |
910 | |
911 break; | |
912 | |
913 case SDL_VIDEOEXPOSE: | |
914 break; | |
915 | |
916 case SDL_QUIT: | |
917 engine.exitFlag = TRUE; | |
918 break; | |
919 } | |
920 | |
921 // Draw frame | |
922 engine.frameTime = SDL_GetTicks(); | |
923 | |
924 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0) | |
925 { | |
926 dmError("Can't lock surface.\n"); | |
927 goto error_exit; | |
928 } | |
929 | |
930 // Main rendering code | |
931 | |
932 while ((engine.frameTime / SET_ROWTIX >= *dez) && (flagz & DEMOEND) == 0) | |
813 { | 933 { |
814 dez++; | 934 dez++; |
815 flagz = *dez++; | 935 flagz = *dez++; |
816 if (flagz & FLASHTXT) | 936 if (flagz & FLASHTXT) |
817 flixtim = *(dez - 2); | 937 flixtim = *(dez - 2); |
819 dizainword = dotxtscr(); | 939 dizainword = dotxtscr(); |
820 } | 940 } |
821 | 941 |
822 if (flagz & FLASHTXT) | 942 if (flagz & FLASHTXT) |
823 { | 943 { |
824 while ((t / ROWTIX) >= flixtim) | 944 while ((engine.frameTime / SET_ROWTIX) >= flixtim) |
825 { | 945 { |
826 phiword = lyrix(); | 946 phiword = lyrix(); |
827 flixtim += 4; | 947 flixtim += 4; |
828 } | 948 } |
829 } | 949 } |
830 | 950 |
831 if (flagz & DEMOEND) | 951 if (flagz & DEMOEND) |
832 break; | 952 engine.exitFlag = TRUE; |
833 | 953 |
834 if (flagz & BLACKBG) | 954 if (flagz & BLACKBG) |
835 { | 955 { |
836 memset(ruutu, 0, BUFH * BUFW); | 956 SDL_FillRect(engine.screen, NULL, 0); |
837 } | 957 } |
838 else | 958 else |
839 if (flagz & FLASHBG) | 959 if (flagz & FLASHBG) |
840 { | 960 { |
841 unsigned char col = 130 + (t % 48) * 2; | 961 unsigned char col = 130 + (t % 48) * 2; |
842 memset(ruutu, col, BUFH * BUFW); | 962 SDL_FillRect(engine.screen, NULL, col); |
843 } | 963 } |
844 | 964 |
845 if (flagz & CHESSBG) | 965 if (flagz & CHESSBG) |
846 { | 966 { |
847 int zoom = ((10 + abs(((t >> 1) % 96) - 48)) * 4096 / BUFW); | 967 int zoom = (10 + abs(((t >> 1) % 96) - 48)) * 4096 / SET_VID_BUFW; |
848 rotochess(ruutu, | 968 rotochess(engine.screen, sin(t * 0.03) * zoom, cos(t * 0.03) * zoom, 0, 0); |
849 sin(t * 0.03) * zoom, cos(t * 0.03) * zoom, 0, 0); | |
850 } | 969 } |
851 | 970 |
852 /* if(flagz&PLASMABG) drawplasma(ruutu,t); */ | 971 /* if(flagz&PLASMABG) drawplasma(ruutu,t); */ |
853 | 972 |
854 if (flagz & OCSALOGO) | 973 if (flagz & OCSALOGO) |
871 int zoom; | 990 int zoom; |
872 if (flagz & BALLJUMPS) | 991 if (flagz & BALLJUMPS) |
873 zoom = abs((t % 96) - 48); | 992 zoom = abs((t % 96) - 48); |
874 else | 993 else |
875 zoom = 47; | 994 zoom = 47; |
876 if (zoom < 0) | 995 |
877 zoom = 0; | 996 zoom = dmClamp(zoom, 0, 47); |
878 else if (zoom > 47) | |
879 zoom = 47; | |
880 | 997 |
881 unitvec(&joo, 0.038 * t, 0.023 * t, 0.011 * t, | 998 unitvec(&joo, 0.038 * t, 0.023 * t, 0.011 * t, |
882 32000 / balltab[zoom].R); | 999 32000 / balltab[zoom].R); |
883 joo.z <<= 1; | 1000 joo.z <<= 1; |
884 | 1001 |
885 drawball(ruutu, &joo, zoom); | 1002 drawball(engine.screen, &joo, zoom); |
886 } | 1003 } |
887 | 1004 |
888 if (flagz & FLASHTXT) | 1005 if (flagz & FLASHTXT) |
889 flashtxt(phiword); | 1006 flashtxt(phiword); |
890 | 1007 |
891 if ((flagz & TXTSCR) && ((t / ROWTIX) & 2)) | 1008 if ((flagz & TXTSCR) && ((t / SET_ROWTIX) & 2)) |
892 drawtxtscr(dizainword); | 1009 drawtxtscr(dizainword); |
893 | 1010 |
894 if (flagz & ENDSCR) | 1011 if (flagz & ENDSCR) |
895 doendscroll(t - 1024 * ROWTIX); | 1012 doendscroll(t - 1024 * SET_ROWTIX); |
896 | 1013 |
897 if (flagz & COUNTAH) | 1014 if (flagz & COUNTAH) |
898 { | 1015 { |
899 int n = ((t * 50 / 48) - 256 * 6); | 1016 int n = ((t * 50 / 48) - 256 * 6); |
900 int dis = (rand() % U) >> 1; | 1017 int dis = (rand() % U) >> 1; |
901 if (n > 666) | 1018 if (n > 666) |
902 n = 666; | 1019 n = 666; |
1020 | |
903 if (n > 600) | 1021 if (n > 600) |
904 { | 1022 { |
905 drawchar(U * 12 + dis, (BUFH >> 1) + dis + U * 6, | 1023 drawchar(U * 12 + dis, (SET_VID_BUFH >> 1) + dis + U * 6, |
906 phont['X' - 32], U, U); | 1024 phont['X' - 32], U, U); |
907 drawchar(U * 22 + dis, (BUFH >> 1) + dis + U * 6, | 1025 drawchar(U * 22 + dis, (SET_VID_BUFH >> 1) + dis + U * 6, |
908 phont['3' - 32], U, U); | 1026 phont['3' - 32], U, U); |
909 } | 1027 } |
910 drawchar(U * 28 + dis, BUFH >> 1, phont[16 + (n % 10)], U, U); | 1028 |
1029 drawchar(U * 28 + dis, SET_VID_BUFH >> 1, phont[16 + (n % 10)], U, U); | |
911 n /= 10; | 1030 n /= 10; |
912 drawchar(U * 18 + dis, BUFH >> 1, phont[16 + (n % 10)], U, U); | 1031 drawchar(U * 18 + dis, SET_VID_BUFH >> 1, phont[16 + (n % 10)], U, U); |
913 n /= 10; | 1032 n /= 10; |
914 drawchar(U * 8 + dis, BUFH >> 1, phont[16 + (n % 10)], U, U); | 1033 drawchar(U * 8 + dis, SET_VID_BUFH >> 1, phont[16 + (n % 10)], U, U); |
915 n /= 10; | 1034 n /= 10; |
916 } | 1035 } |
917 | 1036 |
918 /* blitzz */ | 1037 // Flip screen |
919 | 1038 if (SDL_MUSTLOCK(engine.screen) != 0) |
920 SDL_flip(...); | 1039 SDL_UnlockSurface(engine.screen); |
921 | 1040 |
922 SDL_Delay(25); | 1041 engine.frameCount++; |
923 } | 1042 SDL_Flip(engine.screen); |
924 | 1043 SDL_Delay(20); |
925 SDL_Quit(); | 1044 } |
926 } | 1045 |
1046 error_exit: | |
1047 // Shutdown | |
1048 SDL_ShowCursor(SDL_ENABLE); | |
1049 if (engine.screen) | |
1050 SDL_FreeSurface(engine.screen); | |
1051 | |
1052 SDL_LockAudio(); | |
1053 SDL_PauseAudio(1); | |
1054 SDL_UnlockAudio(); | |
1055 | |
1056 if (initSDL) | |
1057 SDL_Quit(); | |
1058 | |
1059 return 0; | |
1060 } |