summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorSimon <simon@hardwired.org.uk>2010-09-01 10:40:29 (GMT)
committer Simon <simon@hardwired.org.uk>2010-09-01 10:40:29 (GMT)
commitcf85eabee95be1e4947935183d1366cba6f42245 (patch)
tree74169763bd8a27fad15d601110a9579e7f96bbd8 /main.c
parent75d3e18fbfb3dfb8f757cbe3d36d5953c2621956 (diff)
downloadpowder-cf85eabee95be1e4947935183d1366cba6f42245.zip
powder-cf85eabee95be1e4947935183d1366cba6f42245.tar.gz
Fixed zoom, removed plastic, fixed oil, more moving around. Experimental Neutron behaviour
Diffstat (limited to 'main.c')
-rw-r--r--main.c797
1 files changed, 0 insertions, 797 deletions
diff --git a/main.c b/main.c
index 1d818a8..7d20ff2 100644
--- a/main.c
+++ b/main.c
@@ -102,10 +102,6 @@ int amd = 1;
sign signs[MAXSIGNS];
-/***********************************************************
- * AIR FLOW SIMULATOR *
- ***********************************************************/
-
int numCores = 4;
int core_count()
@@ -133,18 +129,8 @@ int core_count()
return numCPU;
}
-/***********************************************************
- * PARTICLE SIMULATOR *
- ***********************************************************/
int mousex, mousey = 0; //They contain mouse position
-
-
-
-/***********************************************************
- * SDL OUTPUT *
- ***********************************************************/
-
void sdl_seticon(void)
{
#ifdef WIN32
@@ -161,30 +147,6 @@ void sdl_seticon(void)
#endif
}
-void sdl_open(void)
-{
- if(SDL_Init(SDL_INIT_VIDEO)<0)
- {
- fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError());
- exit(1);
- }
- atexit(SDL_Quit);
-#ifdef PIX16
- sdl_scrn=SDL_SetVideoMode(XRES*sdl_scale + BARSIZE*sdl_scale,YRES*sdl_scale + MENUSIZE*sdl_scale,16,SDL_SWSURFACE);
-#else
- sdl_scrn=SDL_SetVideoMode(XRES*sdl_scale + BARSIZE*sdl_scale,YRES*sdl_scale + MENUSIZE*sdl_scale,32,SDL_SWSURFACE);
-#endif
- if(!sdl_scrn)
- {
- fprintf(stderr, "Creating window: %s\n", SDL_GetError());
- exit(1);
- }
- SDL_WM_SetCaption("The Powder Toy", "Powder Toy");
- sdl_seticon();
- SDL_EnableUNICODE(1);
- //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-}
-
int frame_idx=0;
void dump_frame(pixel *src, int w, int h, int pitch)
{
@@ -265,93 +227,6 @@ void *build_thumb(int *size, int bzip2)
return d;
}
-int render_thumb(void *thumb, int size, int bzip2, pixel *vid_buf, int px, int py, int scl)
-{
- unsigned char *d,*c=thumb;
- int i,j,x,y,a,t,r,g,b,sx,sy;
-
- if(bzip2)
- {
- if(size<16)
- return 1;
- if(c[3]!=0x74 || c[2]!=0x49 || c[1]!=0x68 || c[0]!=0x53)
- return 1;
- if(c[4]>PT_NUM)
- return 2;
- if(c[5]!=CELL || c[6]!=XRES/CELL || c[7]!=YRES/CELL)
- return 3;
- i = XRES*YRES;
- d = malloc(i);
- if(!d)
- return 1;
-
- if(BZ2_bzBuffToBuffDecompress((char *)d, (unsigned *)&i, (char *)(c+8), size-8, 0, 0))
- return 1;
- size = i;
- }
- else
- d = c;
-
- if(size < XRES*YRES)
- {
- if(bzip2)
- free(d);
- return 1;
- }
-
- sy = 0;
- for(y=0; y+scl<=YRES; y+=scl)
- {
- sx = 0;
- for(x=0; x+scl<=XRES; x+=scl)
- {
- a = 0;
- r = g = b = 0;
- for(j=0; j<scl; j++)
- for(i=0; i<scl; i++)
- {
- t = d[(y+j)*XRES+(x+i)];
- if(t==0xFF)
- {
- r += 256;
- g += 256;
- b += 256;
- a += 2;
- }
- else if(t)
- {
- if(t>=PT_NUM)
- goto corrupt;
- r += PIXR(ptypes[t].pcolors);
- g += PIXG(ptypes[t].pcolors);
- b += PIXB(ptypes[t].pcolors);
- a ++;
- }
- }
- if(a)
- {
- a = 256/a;
- r = (r*a)>>8;
- g = (g*a)>>8;
- b = (b*a)>>8;
- }
-
- drawpixel(vid_buf, px+sx, py+sy, r, g, b, 255);
- sx++;
- }
- sy++;
- }
-
- if(bzip2)
- free(d);
- return 0;
-
-corrupt:
- if(bzip2)
- free(d);
- return 1;
-}
-
void *build_save(int *size, int x0, int y0, int w, int h)
{
unsigned char *d=calloc(1,3*(XRES/CELL)*(YRES/CELL)+(XRES*YRES)*7+MAXSIGNS*262), *c;
@@ -788,144 +663,6 @@ corrupt:
return 1;
}
-pixel *prerender_save(void *save, int size, int *width, int *height)
-{
- unsigned char *d,*c=save;
- int i,j,k,x,y,rx,ry,p=0;
- int bw,bh,w,h;
- pixel *fb;
-
- if(size<16)
- return NULL;
- if(c[2]!=0x43 || c[1]!=0x75 || c[0]!=0x66)
- return NULL;
- if(c[4]>SAVE_VERSION)
- return NULL;
-
- bw = c[6];
- bh = c[7];
- w = bw*CELL;
- h = bh*CELL;
-
- if(c[5]!=CELL)
- return NULL;
-
- i = (unsigned)c[8];
- i |= ((unsigned)c[9])<<8;
- i |= ((unsigned)c[10])<<16;
- i |= ((unsigned)c[11])<<24;
- d = malloc(i);
- if(!d)
- return NULL;
- fb = calloc(w*h, PIXELSIZE);
- if(!fb)
- {
- free(d);
- return NULL;
- }
-
- if(BZ2_bzBuffToBuffDecompress((char *)d, (unsigned *)&i, (char *)(c+12), size-12, 0, 0))
- goto corrupt;
- size = i;
-
- if(size < bw*bh)
- goto corrupt;
-
- k = 0;
- for(y=0; y<bh; y++)
- for(x=0; x<bw; x++)
- {
- rx = x*CELL;
- ry = y*CELL;
- switch(d[p])
- {
- case 1:
- for(j=0; j<CELL; j++)
- for(i=0; i<CELL; i++)
- fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080);
- break;
- case 2:
- for(j=0; j<CELL; j+=2)
- for(i=(j>>1)&1; i<CELL; i+=2)
- fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080);
- break;
- case 3:
- for(j=0; j<CELL; j++)
- for(i=0; i<CELL; i++)
- if(!(j%2) && !(i%2))
- fb[(ry+j)*w+(rx+i)] = PIXPACK(0xC0C0C0);
- break;
- case 4:
- for(j=0; j<CELL; j+=2)
- for(i=(j>>1)&1; i<CELL; i+=2)
- fb[(ry+j)*w+(rx+i)] = PIXPACK(0x8080FF);
- k++;
- break;
- case 6:
- for(j=0; j<CELL; j+=2)
- for(i=(j>>1)&1; i<CELL; i+=2)
- fb[(ry+j)*w+(rx+i)] = PIXPACK(0xFF8080);
- break;
- case 7:
- for(j=0; j<CELL; j++)
- for(i=0; i<CELL; i++)
- if(!(i&j&1))
- fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080);
- break;
- case 8:
- for(j=0; j<CELL; j++)
- for(i=0; i<CELL; i++)
- if(!(j%2) && !(i%2))
- fb[(ry+j)*w+(rx+i)] = PIXPACK(0xC0C0C0);
- else
- fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080);
- break;
- }
- p++;
- }
- p += 2*k;
- if(p>=size)
- goto corrupt;
-
- for(y=0; y<h; y++)
- for(x=0; x<w; x++)
- {
- if(p >= size)
- goto corrupt;
- j=d[p++];
- if(j<PT_NUM && j>0)
- {
- if(j==PT_STKM) //Stickman should be drawed another way
- {
- //Stickman drawing
- for(k=-2; k<=1; k++)
- {
- fb[(y-2)*w+x+k] = PIXRGB(255, 224, 178);
- fb[(y+2)*w+x+k+1] = PIXRGB(255, 224, 178);
- fb[(y+k+1)*w+x-2] = PIXRGB(255, 224, 178);
- fb[(y+k)*w+x+2] = PIXRGB(255, 224, 178);
- }
- draw_line(fb , x, y+3, x-1, y+6, 255, 255, 255, w);
- draw_line(fb , x-1, y+6, x-3, y+12, 255, 255, 255, w);
- draw_line(fb , x, y+3, x+1, y+6, 255, 255, 255, w);
- draw_line(fb , x+1, y+6, x+3, y+12, 255, 255, 255, w);
- }
- else
- fb[y*w+x] = ptypes[j].pcolors;
- }
- }
-
- free(d);
- *width = w;
- *height = h;
- return fb;
-
-corrupt:
- free(d);
- free(fb);
- return NULL;
-}
-
// stamps library
stamp stamps[STAMP_MAX];//[STAMP_X*STAMP_Y];
@@ -948,27 +685,6 @@ void stamp_gen_name(char *fn)
sprintf(fn, "%08x%02x", last_time, last_name);
}
-void *file_load(char *fn, int *size)
-{
- FILE *f = fopen(fn, "rb");
- void *s;
-
- if(!f)
- return NULL;
- fseek(f, 0, SEEK_END);
- *size = ftell(f);
- fseek(f, 0, SEEK_SET);
- s = malloc(*size);
- if(!s)
- {
- fclose(f);
- return NULL;
- }
- fread(s, *size, 1, f);
- fclose(f);
- return s;
-}
-
void stamp_update(void)
{
FILE *f;
@@ -1118,222 +834,8 @@ void del_stamp(int d)
stamp_init();
}
-int execute_tagop(pixel *vid_buf, char *op, char *tag)
-{
- int status;
- char *result;
-
- char *names[] = {"ID", "Tag", NULL};
- char *parts[2];
-
- char *uri = malloc(strlen(SERVER)+strlen(op)+36);
- sprintf(uri, "http://" SERVER "/Tag.api?Op=%s", op);
-
- parts[0] = svf_id;
- parts[1] = tag;
-
- result = http_multipart_post(
- uri,
- names, parts, NULL,
- svf_user, svf_pass,
- &status, NULL);
-
- free(uri);
-
- if(status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if(result)
- free(result);
- return 1;
- }
- if(result && strncmp(result, "OK", 2))
- {
- error_ui(vid_buf, 0, result);
- free(result);
- return 1;
- }
-
- if(result[2])
- {
- strncpy(svf_tags, result+3, 255);
- svf_id[15] = 0;
- }
-
- if(result)
- free(result);
-
- return 0;
-}
-
void thumb_cache_inval(char *id);
-void execute_save(pixel *vid_buf)
-{
- int status;
- char *result;
-
- char *names[] = {"Name", "Data:save.bin", "Thumb:thumb.bin", "Publish", "ID", NULL};
- char *parts[5];
- int plens[5];
-
- parts[0] = svf_name;
- plens[0] = strlen(svf_name);
- parts[1] = build_save(plens+1, 0, 0, XRES, YRES);
- parts[2] = build_thumb(plens+2, 1);
- parts[3] = (svf_publish==1)?"Public":"Private";
- plens[3] = strlen((svf_publish==1)?"Public":"Private");
-
- if(svf_id[0])
- {
- parts[4] = svf_id;
- plens[4] = strlen(svf_id);
- }
- else
- names[4] = NULL;
-
- result = http_multipart_post(
- "http://" SERVER "/Save.api",
- names, parts, plens,
- svf_user, svf_pass,
- &status, NULL);
-
- if(svf_last)
- free(svf_last);
- svf_last = parts[1];
- svf_lsize = plens[1];
-
- free(parts[2]);
-
- if(status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if(result)
- free(result);
- return;
- }
- if(result && strncmp(result, "OK", 2))
- {
- error_ui(vid_buf, 0, result);
- free(result);
- return;
- }
-
- if(result[2])
- {
- strncpy(svf_id, result+3, 15);
- svf_id[15] = 0;
- }
-
- if(!svf_id[0])
- {
- error_ui(vid_buf, 0, "No ID supplied by server");
- free(result);
- return;
- }
-
- thumb_cache_inval(svf_id);
-
- svf_own = 1;
- if(result)
- free(result);
-}
-
-void execute_delete(pixel *vid_buf, char *id)
-{
- int status;
- char *result;
-
- char *names[] = {"ID", NULL};
- char *parts[1];
-
- parts[0] = id;
-
- result = http_multipart_post(
- "http://" SERVER "/Delete.api",
- names, parts, NULL,
- svf_user, svf_pass,
- &status, NULL);
-
- if(status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if(result)
- free(result);
- return;
- }
- if(result && strncmp(result, "OK", 2))
- {
- error_ui(vid_buf, 0, result);
- free(result);
- return;
- }
-
- if(result)
- free(result);
-}
-
-int execute_vote(pixel *vid_buf, char *id, char *action)
-{
- int status;
- char *result;
-
- char *names[] = {"ID", "Action", NULL};
- char *parts[2];
-
- parts[0] = id;
- parts[1] = action;
-
- result = http_multipart_post(
- "http://" SERVER "/Vote.api",
- names, parts, NULL,
- svf_user, svf_pass,
- &status, NULL);
-
- if(status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if(result)
- free(result);
- return 0;
- }
- if(result && strncmp(result, "OK", 2))
- {
- error_ui(vid_buf, 0, result);
- free(result);
- return 0;
- }
-
- if(result)
- free(result);
- return 1;
-}
-
-static char hex[] = "0123456789ABCDEF";
-
-void strcaturl(char *dst, char *src)
-{
- char *d;
- unsigned char *s;
-
- for(d=dst; *d; d++) ;
-
- for(s=(unsigned char *)src; *s; s++)
- {
- if((*s>='0' && *s<='9') ||
- (*s>='a' && *s<='z') ||
- (*s>='A' && *s<='Z'))
- *(d++) = *s;
- else
- {
- *(d++) = '%';
- *(d++) = hex[*s>>4];
- *(d++) = hex[*s&15];
- }
- }
- *d = 0;
-}
-
char *thumb_cache_id[THUMB_CACHE_SIZE];
void *thumb_cache_data[THUMB_CACHE_SIZE];
int thumb_cache_size[THUMB_CACHE_SIZE];
@@ -1399,309 +901,10 @@ int thumb_cache_find(char *id, void **thumb, int *size)
return 1;
}
-int search_results(char *str, int votes)
-{
- int i,j;
- char *p,*q,*r,*s,*vu,*vd,*pu;
-
- for(i=0; i<GRID_X*GRID_Y; i++)
- {
- if(search_ids[i])
- {
- free(search_ids[i]);
- search_ids[i] = NULL;
- }
- if(search_names[i])
- {
- free(search_names[i]);
- search_names[i] = NULL;
- }
- if(search_owners[i])
- {
- free(search_owners[i]);
- search_owners[i] = NULL;
- }
- if(search_thumbs[i])
- {
- free(search_thumbs[i]);
- search_thumbs[i] = NULL;
- search_thsizes[i] = 0;
- }
- }
- for(j=0; j<TAG_MAX; j++)
- if(tag_names[j])
- {
- free(tag_names[j]);
- tag_names[j] = NULL;
- }
-
- if(!str || !*str)
- return 0;
-
- i = 0;
- j = 0;
- s = NULL;
- do_open = 0;
- while(1)
- {
- if(!*str)
- break;
- p = strchr(str, '\n');
- if(!p)
- p = str + strlen(str);
- else
- *(p++) = 0;
- if(!strncmp(str, "OPEN ", 5))
- {
- do_open = 1;
- if(i>=GRID_X*GRID_Y)
- break;
- if(votes)
- {
- pu = strchr(str+5, ' ');
- if(!pu)
- return i;
- *(pu++) = 0;
- s = strchr(pu, ' ');
- if(!s)
- return i;
- *(s++) = 0;
- vu = strchr(s, ' ');
- if(!vu)
- return i;
- *(vu++) = 0;
- vd = strchr(vu, ' ');
- if(!vd)
- return i;
- *(vd++) = 0;
- q = strchr(vd, ' ');
- }
- else
- {
- pu = strchr(str+5, ' ');
- if(!pu)
- return i;
- *(pu++) = 0;
- vu = strchr(pu, ' ');
- if(!vu)
- return i;
- *(vu++) = 0;
- vd = strchr(vu, ' ');
- if(!vd)
- return i;
- *(vd++) = 0;
- q = strchr(vd, ' ');
- }
- if(!q)
- return i;
- *(q++) = 0;
- r = strchr(q, ' ');
- if(!r)
- return i;
- *(r++) = 0;
- search_ids[i] = mystrdup(str+5);
-
- search_publish[i] = atoi(pu);
- search_scoreup[i] = atoi(vu);
- search_scoredown[i] = atoi(vd);
-
- search_owners[i] = mystrdup(q);
- search_names[i] = mystrdup(r);
-
- if(s)
- search_votes[i] = atoi(s);
- thumb_cache_find(str, search_thumbs+i, search_thsizes+i);
- i++;
- }
- else if(!strncmp(str, "TAG ", 4))
- {
- if(j >= TAG_MAX)
- {
- str = p;
- continue;
- }
- q = strchr(str+4, ' ');
- if(!q)
- {
- str = p;
- continue;
- }
- *(q++) = 0;
- tag_names[j] = mystrdup(str+4);
- tag_votes[j] = atoi(q);
- j++;
- }
- else
- {
- if(i>=GRID_X*GRID_Y)
- break;
- if(votes)
- {
- pu = strchr(str, ' ');
- if(!pu)
- return i;
- *(pu++) = 0;
- s = strchr(pu, ' ');
- if(!s)
- return i;
- *(s++) = 0;
- vu = strchr(s, ' ');
- if(!vu)
- return i;
- *(vu++) = 0;
- vd = strchr(vu, ' ');
- if(!vd)
- return i;
- *(vd++) = 0;
- q = strchr(vd, ' ');
- }
- else
- {
- pu = strchr(str, ' ');
- if(!pu)
- return i;
- *(pu++) = 0;
- vu = strchr(pu, ' ');
- if(!vu)
- return i;
- *(vu++) = 0;
- vd = strchr(vu, ' ');
- if(!vd)
- return i;
- *(vd++) = 0;
- q = strchr(vd, ' ');
- }
- if(!q)
- return i;
- *(q++) = 0;
- r = strchr(q, ' ');
- if(!r)
- return i;
- *(r++) = 0;
- search_ids[i] = mystrdup(str);
-
- search_publish[i] = atoi(pu);
- search_scoreup[i] = atoi(vu);
- search_scoredown[i] = atoi(vd);
-
- search_owners[i] = mystrdup(q);
- search_names[i] = mystrdup(r);
-
- if(s)
- search_votes[i] = atoi(s);
- thumb_cache_find(str, search_thumbs+i, search_thsizes+i);
- i++;
- }
- str = p;
- }
- if(*str)
- i++;
- return i;
-}
-
-/***********************************************************
- * MESSAGE SIGNS *
- ***********************************************************/
-
-/***********************************************************
- * CONFIG FILE *
- ***********************************************************/
-
char http_proxy_string[256] = "";
unsigned char last_major=0, last_minor=0, update_flag=0;
-void render_cursor(pixel *vid, int x, int y, int t, int r)
-{
- int i,j,c;
- if(t<PT_NUM||t==SPC_AIR||t==SPC_HEAT||t==SPC_COOL||t==SPC_VACUUM)
- {
- if(r<=0)
- xor_pixel(x, y, vid);
- else
- for(j=0; j<=r; j++)
- for(i=0; i<=r; i++)
- if(i*i+j*j<=r*r && ((i+1)*(i+1)+j*j>r*r || i*i+(j+1)*(j+1)>r*r))
- {
- xor_pixel(x+i, y+j, vid);
- if(j) xor_pixel(x+i, y-j, vid);
- if(i) xor_pixel(x-i, y+j, vid);
- if(i&&j) xor_pixel(x-i, y-j, vid);
- }
- }
- else
- {
- int tc;
- c = (r/CELL) * CELL;
- x = (x/CELL) * CELL;
- y = (y/CELL) * CELL;
-
- tc = !((c%(CELL*2))==0);
-
- x -= c/2;
- y -= c/2;
-
- x += tc*(CELL/2);
- y += tc*(CELL/2);
-
- for(i=0; i<CELL+c; i++)
- {
- xor_pixel(x+i, y, vid);
- xor_pixel(x+i, y+CELL+c-1, vid);
- }
- for(i=1; i<CELL+c-1; i++)
- {
- xor_pixel(x, y+i, vid);
- xor_pixel(x+CELL+c-1, y+i, vid);
- }
- }
-}
-
-#ifdef WIN32
-#define x86_cpuid(func,af,bf,cf,df) \
- do {\
- __asm mov eax, func\
- __asm cpuid\
- __asm mov af, eax\
- __asm mov bf, ebx\
- __asm mov cf, ecx\
- __asm mov df, edx\
- } while(0)
-#else
-#define x86_cpuid(func,af,bf,cf,df) \
-__asm__ __volatile ("cpuid":\
- "=a" (af), "=b" (bf), "=c" (cf), "=d" (df) : "a" (func));
-#endif
-
-
-int cpu_check(void)
-{
-#ifdef MACOSX
- return 0;
-#else
-#ifdef X86
- unsigned af,bf,cf,df;
- x86_cpuid(0, af, bf, cf, df);
- if(bf==0x68747541 && cf==0x444D4163 && df==0x69746E65)
- amd = 1;
- x86_cpuid(1, af, bf, cf, df);
-#ifdef X86_SSE
- if(!(df&(1<<25)))
- return 1;
-#endif
-#ifdef X86_SSE2
- if(!(df&(1<<26)))
- return 1;
-#endif
-#ifdef X86_SSE3
- if(!(cf&1))
- return 1;
-#endif
-#endif
-#endif
- return 0;
-}
-
char *tag = "(c) 2008-9 Stanislaw Skowronek";
int itc = 0;
char itc_msg[64] = "[?]";