#include #include #include #include #include #include #include int scw = 800; int sch = 600; int mapw = 512; int maph = 512; char* my_itoa(unsigned int val) { static char buf[11]; short i=10; for(;val&&i;--i,val/=10)buf[i]="0123456789"[val%10]; return &buf[i+1]; } double mygettime() { struct timeval tv; if(gettimeofday(&tv, 0) < 0) { perror("oops"); } return (double)tv.tv_sec + (0.000001 * (double)tv.tv_usec); } void filldata (int *hei) { int p = 0; int x,y; for (y=0; ypixels; int posx = 0; int posy = 0; float ang = 0; int k = 4; int dd = 65536; int de = dd * 128; // 228 is the max "distance" int d; long x,y,z; float amax = M_PI/3.4; float a; float da; int sx; int maxh; int bin1 = (mapw*(maph-1))<<16; int bin2 = ((maph-1))<<16; double time1 = mygettime(); double time2; int frames = 0; // long foo = d/200; // int bar = dd/200; while (1) { SDL_LockSurface(screen); blacken_screen (screen); int startidx = ((posx*mapw) & bin1) + (posy&bin2); int starth = hei[startidx]; int posz = 100; a = -amax; da = 2*amax/scw; int dx = dd*(cos(ang)-a*sin(ang)); int dy = -dd*(sin(ang)+a*cos(ang)); int ddx = dd*sin(ang)*da; int ddy = dd*cos(ang)*da; for (sx=0;sx>16; int h = hei[idx]<<16; Uint8 color = col[idx]; while (h>z) { *((Uint8*)screen->pixels+p) = color; z += d/200; dz -= dd/100; p -= scw; } } a += da; dx += ddx; dy += ddy; } SDL_UnlockSurface(screen); SDL_BlitSurface (textrend, NULL, screen, &dest); SDL_Flip (screen); checkevents (&ang, &posx, &posy, &k); frames++; time2 = mygettime() - time1; if (time2 > 1.0) { SDL_FreeSurface (textrend); char fpsstring[30] = "FPS: "; strcat (fpsstring, my_itoa (frames)); textrend = TTF_RenderText_Solid (font, fpsstring, fontcolor); frames = 0; time1 = mygettime(); } } }