--- founts-11.old/Makefile +++ founts-11/Makefile @@ -2,7 +2,7 @@ CFLAGS = -O3 -I/usr/local/include/SDL -D_REENTRANT founts: founts.o - gcc -o founts founts.o -lm -lpthread -lSDL -ldl + gcc -o founts founts.o -lm -lpthread -lSDL -lSDL_image -ldl founts.o: founts.c founts.h --- founts-11.old/founts.c +++ founts-11/founts.c @@ -1,5 +1,4 @@ /* - Founts by David Ashley http://www.xdr.com/dash dash@xdr.com @@ -12,19 +11,18 @@ */ - - - #include #include #include #include #include "founts.h" -#include "SDL.h" + +#include +#include + #include "math.h" #include - #define PI 3.1415926535897932 #define VIRTX 640 @@ -244,8 +242,7 @@ return put; } - -myrand1() +int myrand1() { int i; int val; @@ -256,14 +253,15 @@ if(myrandtake==TAP1) myrandtake=0; return val; } -myrand() + +int myrand() { int v; v=myrand1(); return (v<<8) | myrand1(); } -initmyrand() +void initmyrand() { int i,j; char *p; @@ -294,27 +292,24 @@ } - - long longind(unsigned char *p) { return (p[0]<<24L) | (p[1]<<16L) | (p[2]<<8) | p[3]; } + short shortind(unsigned char *p) { return (p[0]<<8L) | p[1]; } - -nomem(char *str) +void nomem(char *str) { printf("No memory!!![%s]\n",str); closex(); exit(1); } - -vsync() +void vsync() { scrunlock(); scrlock(); @@ -346,7 +341,6 @@ return *itake++; } - int dopcxreal(char *name,gfxset *gs) { int xs,ys; @@ -439,17 +433,21 @@ memset(entry,0,thingsize); return entry; } + void freeentry(void *entry) { ((list *)entry)->next=((list *)things)->next; ((list *)things)->next=entry; } + void addtail(void *header,void *entry) { - while(((list *)header)->next) ((list *)header)=((list *)header)->next; - ((list *)header)->next=entry; + list *hp = (list *) header; + while(hp->next) hp = hp->next; + hp->next = entry; ((list *)entry)->next=0; } + void delink(void *header,void *entry) { while(((list *)header)->next != entry) header=((list *)header)->next; @@ -457,6 +455,7 @@ ((list *)entry)->next=0; freeentry(entry); } + void initlist(void *first,int size,int num) { unsigned char *p; @@ -487,14 +486,16 @@ hc++; return time; } -pulseon() + +void pulseon() { if(havepulse) return; havepulse=1; SDL_SetTimer(10,sdlhandler); hc=interrupted=0; } -pulseoff() + +void pulseoff() { if(!havepulse) return; havepulse=0; @@ -502,7 +503,7 @@ } -initballs() +void initballs() { int i; balls=malloc(MAXBALLS*sizeof(struct ball)); @@ -513,7 +514,8 @@ firstball=balls; activeballs=0; } -inithoses() + +void inithoses() { int i; hoses=malloc(MAXHOSES*sizeof(struct hose)); @@ -529,7 +531,8 @@ fakehose.red=fakehose.green=fakehose.blue=255; fakehose.index=511; } -initblocks() + +void initblocks() { int i; blocks=malloc(MAXBLOCKS*sizeof(struct block)); @@ -543,6 +546,7 @@ fakeblock.y=VIRTY<next=firstball; firstball=aball; } + struct hose *allochose() { struct hose *ahose; @@ -595,11 +601,13 @@ memset(ahose,0,sizeof(struct hose)); return ahose; } -freehose(struct hose *ahose) + +void freehose(struct hose *ahose) { ahose->next=firsthose; firsthose=ahose; } + struct block *allocblock() { struct block *ablock; @@ -609,7 +617,8 @@ memset(ablock,0,sizeof(struct block)); return ablock; } -freeblock(struct block *ablock) + +void freeblock(struct block *ablock) { ablock->next=firstblock; firstblock=ablock; @@ -619,7 +628,7 @@ #define HOSESIZE 30 #define BLOCKSIZE 12 -dohoses() +void dohoses() { struct hose *ahose; struct ball *aball; @@ -657,12 +666,13 @@ } } -hosecontrol1(struct point *p,struct hose *ahose) +void hosecontrol1(struct point *p,struct hose *ahose) { p->x=ahose->x>>FRACTION; p->y=ahose->y>>FRACTION; } -hosecontrol2(struct point *p,struct hose *ahose) + +void hosecontrol2(struct point *p,struct hose *ahose) { float a; int x,y; @@ -673,17 +683,20 @@ p->x=x-HOSESIZE*3/4*cos(a); p->y=y-HOSESIZE*3/4*sin(a); } + int near(int v1,int v2) { v1-=v2; if(v1<0) v1=-v1; return v1<8; } + int nearrad(int dx,int dy,int rad) { return dx*dx+dy*dy>2) | ((blue&0xe0)>>5); } @@ -692,7 +705,7 @@ { struct hose *ahose; ahose=allochose(); - if(!ahose) return; + if(!ahose) return (struct hose *) 0; ahose->next=activehoses; activehoses=ahose; ahose->angle=384; @@ -704,6 +717,7 @@ ahose->index=makeindex(red,green,blue); return ahose; } + struct block *addblock() { struct block *ablock; @@ -716,7 +730,6 @@ return ablock; } - int checkhose(struct hose *ahose) { struct point p; @@ -728,10 +741,12 @@ return 2; return 0; } + struct point colorpoints[NUMTYPES]; int colorindexes[NUMTYPES]; unsigned short *colorfigs[NUMTYPES]; -initcolors() + +void initcolors() { int i,j,k,r,g,b; for(i=0;ix=ablock->x>>FRACTION; p->y=ablock->y>>FRACTION; } -blockcontrol2(struct point *p,struct block *ablock) + +void blockcontrol2(struct point *p,struct block *ablock) { float a; int x,y; @@ -950,6 +966,7 @@ p->x=x+BLOCKSIZE*3*cos(a); p->y=y+BLOCKSIZE*3*sin(a); } + int checkblock(struct block *ablock) { struct point p; @@ -961,22 +978,26 @@ return 2; return 0; } -blockpoint1(struct fpoint *fp,struct block *ablock) + +void blockpoint1(struct fpoint *fp,struct block *ablock) { float a; a=ablock->angle*PI/512; fp->x=BLOCKSIZE*cos(a); fp->y=BLOCKSIZE*sin(a); } -blockpoint2(struct point *p,struct block *ablock) + +void blockpoint2(struct point *p,struct block *ablock) { float a; a=(ablock->angle-40)*PI/512; p->x=BLOCKRAD*cos(a); p->y=BLOCKRAD*sin(a); } + #define BLOCKFACTOR 4 -plotblock(struct block *ablock) + +void plotblock(struct block *ablock) { int x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x,y; float a; @@ -985,7 +1006,6 @@ float dx,dy; struct fpoint fp; - x=(float)ablock->x*IXSIZE/VIRTX; y=(float)ablock->y*IYSIZE/VIRTY; x>>=FRACTION; @@ -1020,17 +1040,20 @@ blockcontrol2(&p,ablock); drawfigure(p.x*IXSIZE/VIRTX,p.y*IYSIZE/VIRTY,dummyball); } -initbbm() + +void initbbm() { bbm=malloc(VIRTX*VIRTY); if(!bbm) nomem("initbitmap"); clearbbm(); } -clearbbm() + +void clearbbm() { memset(bbm,0,VIRTX*VIRTY); } + void bbmscan(int x1,int y,int x2,long color) { unsigned char *p1; @@ -1052,7 +1075,7 @@ float blockangles[256]; -makebbm() +void makebbm() { struct block *ablock; int x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x,y; @@ -1109,7 +1132,7 @@ } #define ELAST 1.7 -bbmball(struct ball *aball) +void bbmball(struct ball *aball) { int x,y; int id; @@ -1138,9 +1161,7 @@ } - - -plotblocks() +void plotblocks() { struct block *ablock; @@ -1152,8 +1173,8 @@ } plotblock(&fakeblock); } - -drawcolors() + +void drawcolors() { int x,y; int dx,dy; @@ -1185,7 +1206,7 @@ 128 }; -drawsolid(int x,int y,char *p,uchar red,uchar green,uchar blue) +void drawsolid(int x,int y,char *p,uchar red,uchar green,uchar blue) { int tx,ty,tl; unsigned short *put,color; @@ -1219,7 +1240,7 @@ } } -plotballs() +void plotballs() { struct ball *aball; int x,y; @@ -1296,7 +1317,7 @@ } } -moveballs() +void moveballs() { struct ball *aball; float s,c,a,x,y,dx,dy,v; @@ -1308,14 +1329,12 @@ while(aball) { bbmball(aball); - aball->dy+=gravity; - aball=aball->next; } } -cullballs() +void cullballs() { struct ball *aball, **aballptr; aballptr=&activeballs; @@ -1332,8 +1351,7 @@ } } - -tritest() +void tritest() { float angle1,angle2,angle3; int i; @@ -1342,6 +1360,7 @@ #define CX (IXSIZE/2) #define CY (IYSIZE/2) #define R 192 + for(i=0;i<256;++i) { scrlock(); @@ -1361,7 +1380,7 @@ } -onetri() +void onetri() { float angle1,angle2,angle3; static int i; @@ -1389,7 +1408,7 @@ } -minitri(int x,int y,int a) +void minitri(int x,int y,int a) { int x1,y1,x2,y2,x3,y3; int r; @@ -1408,8 +1427,7 @@ tri(x1,y1,x3,y3,x,y,scanfunc,0); } - -dots() +void dots() { float angle,r,f; int x,y; @@ -1474,7 +1492,7 @@ #define MAXPRESETS 10 -makepresetname(char *dest,int num) +void makepresetname(char *dest,int num) { char *p; p=getenv("HOME"); @@ -1484,11 +1502,12 @@ sprintf(dest,"founts%d",num); } -loadpresets() +void loadpresets() { int i; int file,len; char temp[256]; + for(i=0;i=SDLK_1 && key<=SDLK_9) { @@ -1674,13 +1694,13 @@ } } -processmouse() +void processmouse() { hosehit(); blockhit(); } -putcolors() +void putcolors() { static unsigned short setup=0,cmap[512],*p; int i,j,k,t,r,g,b,x,y,c; @@ -1723,10 +1743,7 @@ } } - - - -doballs() +void doballs() { char redraw; int selected; @@ -1793,7 +1810,7 @@ } } -updatemap() +void updatemap() { SDL_SetColors(thescreen, themap, 0, 256); } @@ -1811,14 +1828,15 @@ } return 0; } -scrunlock() + +void scrunlock() { if(SDL_MUSTLOCK(thescreen)) SDL_UnlockSurface(thescreen); SDL_UpdateRect(thescreen, 0, 0, 0, 0); } -drawsphere(int r,int bx,int by,int vx,int vy,int vz,int rt,int gt,int bt) +void drawsphere(int r,int bx,int by,int vx,int vy,int vz,int rt,int gt,int bt) { float x,y,y2,z,radius; int i,j,j2,k,rint,rint2; @@ -1864,7 +1882,6 @@ tvy/=radius; tvz/=radius; - bx=bx*IXSIZE/640; by=by*IYSIZE/480; r=r*IXSIZE/640; @@ -1908,6 +1925,7 @@ } } } + unsigned char rt[256],bt[256],gt[256]; initeyes() { @@ -1920,7 +1938,7 @@ } } -sphere() +void sphere() { int i=0; float a; @@ -1982,8 +2000,7 @@ unsigned char (*fractarr)[ASQR]=0; - -diamond(int x,int y1,int y2,int y,int x1,int x2,int delta) +void diamond(int x,int y1,int y2,int y,int x1,int x2,int delta) { int c,average; if(x<0 || x>ASQR || y<0 || y>ASQR) return; @@ -2013,7 +2030,8 @@ if(average>255) average=255; fractarr[x][y]=average; } -fcenter(int step,int delta) + +void fcenter(int step,int delta) { int i,j; int average; @@ -2031,7 +2049,8 @@ fractarr[i+step2][j+step2]=average; } } -fdiamond(int step,int delta) + +void fdiamond(int step,int delta) { int i,j,average; int step2; @@ -2046,7 +2065,7 @@ int fmap=0; -copyfract() +void copyfract() { unsigned char *p,*pb,*fbtake,*fbput; unsigned short *ps; @@ -2136,8 +2155,7 @@ } } - -fractal() +void fractal() { int i,j,k; unsigned char *p,*pb,*fbtake,*fbput; @@ -2168,8 +2186,7 @@ copyfract(); } - -makeballs() +void makeballs() { int i,j,k,t,r,g,b; t=0; @@ -2189,8 +2206,7 @@ dummyball=makeball(3,255,255,255); } - -main(int argc,char **argv) +int main(int argc,char **argv) { int i,j,k,t; long t1,t2; @@ -2204,17 +2220,18 @@ printf("dash@xdr.com\n"); printf("Use: founts [screenwidth]\n"); printf("screenwidth is optional argument 100-2048 (default 640)\n"); - printf("c Change background colors\n"); - printf("e Eye demo\n"); - printf("f New fractal background\n"); - printf("h Hide/unhide the non-ball objects\n"); - printf("m Turn on/off mixing\n"); - printf("p Pause movement\n"); - printf("r Rotate hoses\n"); - printf("s Spiral pattern (escape to exit)\n"); - printf("x Delete everything\n"); - printf("1-9 Load preset\n"); - printf("shift 1-9 Store preset\n"); + printf("c Change background colors\n"); + printf("e Eye demo\n"); + printf("f New fractal background\n"); + printf("h Hide/unhide the non-ball objects\n"); + printf("m Turn on/off mixing\n"); + printf("p Pause movement\n"); + printf("q or ESCAPE Quit\n"); + printf("r Rotate hoses\n"); + printf("s Spiral pattern (escape to exit)\n"); + printf("x Delete everything\n"); + printf("1-9 Load preset\n"); + printf("shift 1-9 Store preset\n"); printf("Drag the fountains over the colors to change their color\n"); if(argc>1) @@ -2252,20 +2269,22 @@ closex(); printf("fps = %d\n",1000*frames/starttime); + exit (0); } -drawfigure(int x,int y,unsigned short *take) +void drawfigure(int x,int y,unsigned short *take) { unsigned short *p1,*p2; int run; int dx,dy; int xsize,ysize; unsigned char *pc; +signed short ssvtake; if(!take) take=dummyball; - dx=*((signed short *)take)++; - dy=*((signed short *)take)++; + ssvtake = *take++; dx = ssvtake; + ssvtake = *take++; dy = ssvtake; xsize=*take++; ysize=*take++; x+=dx; @@ -2274,8 +2293,9 @@ { while(run=*take++) { - dx=*((signed short *)take)++; - dy=*((signed short *)take)++; + ssvtake = *take++; dx = ssvtake; + ssvtake = *take++; dy = ssvtake; + if(bitsperpixel==16) { p1=(unsigned short *)(videomem+stridemult[y+dy]+(x+dx<<1)); @@ -2292,8 +2312,8 @@ { while(run=*take++) { - dx=*((signed short *)take)++; - dy=*((signed short *)take)++; + ssvtake = *take++; dx = ssvtake; + ssvtake = *take++; dy = ssvtake; dx+=x; dy+=y; p2=take; @@ -2322,12 +2342,14 @@ } } -closex() + +void closex() { if(sdlloaded) SDL_Quit(); } -openx() + +void openx() { unsigned long videoflags; int i; @@ -2344,9 +2366,13 @@ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); exit(1); } - videoflags = SDL_SWSURFACE|SDL_HWPALETTE|SDL_ANYFORMAT; - thescreen = SDL_SetVideoMode(IXSIZE, IYSIZE, 16, videoflags); + SDL_WM_SetCaption ("founts", "founts"); + SDL_WM_SetIcon (IMG_Load ("__META_PREFIX__/data/founts.png"), NULL); + + videoflags = SDL_SWSURFACE|SDL_HWPALETTE; + thescreen = SDL_SetVideoMode (IXSIZE, IYSIZE, 16, videoflags); + if ( thescreen == NULL ) { fprintf(stderr, "Couldn't set display mode: %s\n", @@ -2362,7 +2388,8 @@ updatemap(); SDL_ShowCursor(0); } -scaninput() + +void scaninput() { SDL_Event event; int key,mod; @@ -2374,9 +2401,14 @@ case SDL_KEYDOWN: key=event.key.keysym.sym; mod=event.key.keysym.mod; - if(key==SDLK_ESCAPE) - exitflag=1; - else processkey(key,mod); + + if ((key == SDLK_ESCAPE) || (key == SDLK_q)) + exitflag = 1; + else if ((key == SDLK_c) && ((mod & KMOD_CTRL) != 0)) + exitflag = 1; + else + processkey (key, mod); + break; case SDL_MOUSEBUTTONUP: buttonstate=NOTDOWN; @@ -2396,7 +2428,8 @@ } } } -clear() + +void clear() { unsigned char *p1,*p2; int i,w;