# HG changeset patch # User Matti Hamalainen # Date 1363320490 -7200 # Node ID 84d7bc7dfaeb3dba45790da28b51cd6e3f3b22c7 # Parent bbc901af24fb5b681792e42da3169081839a23e0 More cleanup work. diff -r bbc901af24fb -r 84d7bc7dfaeb 3x666.c --- a/3x666.c Fri Mar 15 05:12:26 2013 +0200 +++ b/3x666.c Fri Mar 15 06:08:10 2013 +0200 @@ -1,5 +1,5 @@ +#include #include -#include #include #include #include @@ -10,14 +10,15 @@ typedef struct { - signed int x, y, z; + int x, y, z; } vec3d; int TIKLGT; -char *ruutu; +SDL_Color pal[256]; +Uint8 *ruutu; + int *mxbuf; - int *ballz; /**************** tEXT dRAWiNG rOUTiNES ********** @@ -45,7 +46,7 @@ } if (w > 0 && h > 0) { - char *b = ruutu + y * BUFW + x; + Uint8 *b = ruutu + y * BUFW + x; for (; h; h--) { memset(b, 122, w); @@ -85,14 +86,14 @@ } } -void drawtxtscr(char *z) +void drawtxtscr(char *str) { int x = BUFW >> 4, y = BUFH >> 3; - while (*z) + while (*str) { - if (*z >= 32) + if (*str >= 32) { - drawchar(x, y, phont[*z - 32], BUFW / 50, BUFW / 80); + drawchar(x, y, phont[*str - 32], BUFW / 50, BUFW / 80); x += BUFW / 10; } else @@ -100,17 +101,17 @@ x = BUFW >> 4; y += BUFW / 10; } - z++; + str++; } } -void flashtxt(char *txt) +void flashtxt(char *str) { - int x = (BUFW >> 1) - (strlen(txt) + 1) * 3 * BUFW / 80; - while (*txt) + int x = (BUFW >> 1) - (strlen(str) + 1) * 3 * BUFW / 80; + while (*str) { - drawchar(x, BUFH >> 1, phont[*txt++ - 32], BUFW / 50, BUFW / 80); + drawchar(x, BUFH >> 1, phont[*str++ - 32], BUFW / 50, BUFW / 80); x += BUFW / 10; } } @@ -144,9 +145,9 @@ ***/ #if (BUFH < BUFW) -# define maxR (BUFH>>1) +# define maxR (BUFH >> 1) #else -# define maxR (BUFW>>1) +# define maxR (BUFW >> 1) #endif struct @@ -178,14 +179,8 @@ balltab[49].tab = balltab[48].tab = balltab[47].tab; } -/** - The i386 innerloop compiled by gcc sucked a bit so here's another - one. Hope it runs faster :) I tried to optimize it for the 386, - maybe 486 (not pentium kos it suxx) -**/ - -inline void drawball_inloop(char *d, int dotxyz, int ddot, int dddot, int x) +void drawball_inloop(Uint8 *d, int dotxyz, int ddot, int dddot, int x) { for (; x; x--) { @@ -195,7 +190,7 @@ } } -void drawball(char *d, vec3d * l, int relR) +void drawball(Uint8 *d, vec3d * l, int relR) { int R = balltab[relR].R, *s = balltab[relR].tab; @@ -205,6 +200,7 @@ d += (BUFW >> 1) - R + ((BUFH >> 1) - R) * BUFW; if (y) + { for (; y; y--) { int halfw = *s++; @@ -216,6 +212,7 @@ d += BUFW; doty += l->y; } + } } /* some extra for freaks: a plasma made with the phongball innerloop :) @@ -238,7 +235,7 @@ /************************ oTHA FX ***************/ -void rotochess(char *d, int du, int dv, int iu, int iv) +void rotochess(Uint8 *d, int du, int dv, int iu, int iv) { int hu = iu - (dv * (BUFH >> 1)) - (du * (BUFW >> 1)), hv = iv + (du * (BUFH >> 1)) - (dv * (BUFW >> 1)); @@ -262,16 +259,16 @@ /***************************************************************/ -rgb pal[256], pal2[256]; + void setpal() { int i, a = 3, b = 0; for (i = 255; i; i--) { - rgb *d = &pal[(i + 128) & 255]; - d->r = (abs(i - 140) >> a) & 255; + SDL_Color *d = &pal[(i + 128) & 255]; + d->r = (abs(i - 140) >> a) & 255; d->g = ((abs(i - 128) >> b) & 255) ^ 1; - d->b = (abs(i - 96) >> b) & 255; + d->b = (abs(i - 96) >> b) & 255; if (i == 128) { a = 0; @@ -281,6 +278,7 @@ oxl_setpalette(pal); } + void unitvec(vec3d * v, float a, float b, float c, float m) { float cam = cos(a) * m, sam = sin(a) * m, sbcam = sin(b) * cam; @@ -295,7 +293,7 @@ /* This table was ripped (and reduced and rudely integerized) from the Maube tracker by K .. keep on the good work man! ;) */ -const int noterate[3 * 12] = +const Sint16 noterate[3 * 12] = { 1000, 1059, 1122, 1189, 1259, 1334, 1414, 1498, 1587, 1681, 1781, 1887, @@ -336,6 +334,7 @@ signed int *drum0, *drum1; + /* sampling sucks! */ void audio_precalcs() { @@ -369,7 +368,8 @@ a += da; da -= dda; vol -= dvol; -}} + } +} /* mixes the next row of music into b */ @@ -390,10 +390,13 @@ if (!note) note = basstrak[((rowno >> 1) & 31) - 1]; - else if (rowno & 1) + else + if (rowno & 1) note = 0; + if ((rowno & 3) == 3) note = 0; + if (note) { int ps = 16384, dps; @@ -406,8 +409,10 @@ } } else + { for (i = rowlgt; i; i--) *d++ = 16384; + } /* MELODY (sawtooth as well :) */ @@ -432,8 +437,8 @@ } } } + /* DRUMS (rave on!!!) */ - { int *s = drum1; d = mxbuf + 1; @@ -453,7 +458,7 @@ it's 1024+ bytes for every phukken switch statement! in this case we can prefer size to speed, can't we? */ - if (!(rowno & 63)) + if ((rowno & 63) == 0) { int r = rowno >> 6; if (r == 2) @@ -760,19 +765,19 @@ #define DEMOEND 0x1000 const short dezign[] = { - 0, BLACKBG | OCSALOGO | SCROLL0, - 256, FLASHBG | BALLIE | BALLJUMPS | COUNTAH, - 384, BLACKBG | BALLIE | BALLJUMPS | COUNTAH | OCSALOGO, - 400, BLACKBG | BALLIE | COUNTAH | OCSALOGO, - 416, BLACKBG | BALLIE, - 448, BLACKBG | BALLIE | TXTSCR, - 512, CHESSBG | BALLIE | BALLJUMPS | TXTSCR, - 576, CHESSBG | BALLIE | BALLJUMPS | TXTSCR, - 640, CHESSBG | BALLIE | BALLJUMPS | TXTSCR, - 704, CHESSBG | BALLIE | BALLJUMPS | TXTSCR, - 768, FLASHBG | FLASHTXT, - 896, FLASHBG | FLASHTXT | TXTSCR, - 962, FLASHBG | FLASHTXT | TXTSCR | BALLIE | BALLJUMPS, + 0 , BLACKBG | OCSALOGO | SCROLL0, + 256 , FLASHBG | BALLIE | BALLJUMPS | COUNTAH, + 384 , BLACKBG | BALLIE | BALLJUMPS | COUNTAH | OCSALOGO, + 400 , BLACKBG | BALLIE | COUNTAH | OCSALOGO, + 416 , BLACKBG | BALLIE, + 448 , BLACKBG | BALLIE | TXTSCR, + 512 , CHESSBG | BALLIE | BALLJUMPS | TXTSCR, + 576 , CHESSBG | BALLIE | BALLJUMPS | TXTSCR, + 640 , CHESSBG | BALLIE | BALLJUMPS | TXTSCR, + 704 , CHESSBG | BALLIE | BALLJUMPS | TXTSCR, + 768 , FLASHBG | FLASHTXT, + 896 , FLASHBG | FLASHTXT | TXTSCR, + 962 , FLASHBG | FLASHTXT | TXTSCR | BALLIE | BALLJUMPS, 1024, BLACKBG | BALLIE | ENDSCR, 1152, CHESSBG | BALLIE | BALLJUMPS | ENDSCR, 1344, FLASHBG | BALLIE | BALLJUMPS | ENDSCR, @@ -791,19 +796,13 @@ char *phiword = NULL, *dizainword = NULL; int flixtim = 0; - ruutu = malloc(BUFH * BUFW * sizeof(char)); preball(); - srand((int) time(NULL)); - oxl_init_audio(ROWTIX); TIKLGT = AUFREQ / DEMOHZ; mxbuf = malloc(MAXROWLGT * sizeof(int)); audio_precalcs(); - oxl_init_video(); - oxl_init_timer(); - setpal(); for (;;) @@ -888,9 +887,9 @@ if (flagz & FLASHTXT) flashtxt(phiword); - if (flagz & TXTSCR) - if ((t / ROWTIX) & 2) - drawtxtscr(dizainword); + + if ((flagz & TXTSCR) && ((t / ROWTIX) & 2)) + drawtxtscr(dizainword); if (flagz & ENDSCR) doendscroll(t - 1024 * ROWTIX); @@ -918,12 +917,10 @@ /* blitzz */ - oxl_doframe(ruutu); - oxl_doaudio(audio_mix); - while (t == oxl_timer()) - { - usleep(250000 / DEMOHZ); - } + SDL_flip(...); + + SDL_Delay(25); } - oxl_end(); + + SDL_Quit(); }