From: hackbard Date: Wed, 14 May 2003 16:53:28 +0000 (+0000) Subject: - X-Git-Tag: fpb~57 X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=ac3628afff01679dfa9da69cf010764970e40be7;p=physik%2Fnlsop.git - --- diff --git a/dfbapi.c b/dfbapi.c index aeb6cff..dfb3ae8 100644 --- a/dfbapi.c +++ b/dfbapi.c @@ -275,17 +275,17 @@ int d3_lattice_draw(d3_lattice *d3_l,int x,int y,int z,int arg_c,char **arg_v) return 1; } -int 2d_event_init(2d_lattice *2d_l) +int d2_event_init(d2_lattice *d2_l) { - 2d_l->dfb->GetInputDevice(2d_l->dfb,DIDID_KEYBOARD,&(2d_l->keyboard)); - 2d_l->keyboard->CreateEventBuffer(2d_l->keyboard,&(2d_l->k_buffer)); + d2_l->dfb->GetInputDevice(d2_l->dfb,DIDID_KEYBOARD,&(d2_l->keyboard)); + d2_l->keyboard->CreateEventBuffer(d2_l->keyboard,&(d2_l->k_buffer)); return 1; } int d3_event_init(d3_lattice *d3_l) { - d3_l->dfb->GetInputDevice(d3_l->dfb,DIDID_KEYBOARD,&(3d_l->keyboard)); + d3_l->dfb->GetInputDevice(d3_l->dfb,DIDID_KEYBOARD,&(d3_l->keyboard)); d3_l->keyboard->CreateEventBuffer(d3_l->keyboard,&(d3_l->k_buffer)); return 1; @@ -300,11 +300,11 @@ int scan_event(d3_lattice *d3_l,int *x,int *y,int *z,int *q,int *esc) { if(ke.key_id==DIKI_LEFT && *x!=0) *x-=1; if(ke.key_id==DIKI_RIGHT && *x!=d3_l->max_x-1) *x+=1; - if(ke.key_id==DIET_DOWN && *y!=0) *y-=1; - if(ke.key_id==DIET_UP && *y!=d3_l->max_y-1) *y+=1; - if(ke.key_id==DIET_PAGE_DOWN && *z!=0) *z-=1; - if(ke.key_id==DIET_PAGE_UP && *z!=d3_l->mac_z-1) *z+=1; - if(ke.key_id==DIKI_Q) *quit=1; + if(ke.key_id==DIKI_DOWN && *y!=0) *y-=1; + if(ke.key_id==DIKI_UP && *y!=d3_l->max_y-1) *y+=1; + if(ke.key_id==DIKI_PAGE_DOWN && *z!=0) *z-=1; + if(ke.key_id==DIKI_PAGE_UP && *z!=d3_l->max_z-1) *z+=1; + if(ke.key_id==DIKI_Q) *q=1; if(ke.key_id==DIKI_ESCAPE) *esc=1; } diff --git a/dfbapi.h b/dfbapi.h index c51bfe4..54ab56b 100644 --- a/dfbapi.h +++ b/dfbapi.h @@ -40,7 +40,7 @@ typedef struct __d3_lattice int info_w,info_h; int font_h; unsigned char *status; /* status&1 -> red, else blue */ - int *extra /* store extra values */ + int *extra; /* store extra values */ void *v_ptr; /* void ptr, for any use */ IDirectFB *dfb; IDirectFBSurface *p_surface; diff --git a/nlsop.c b/nlsop.c index 9e4c3bf..030db9f 100644 --- a/nlsop.c +++ b/nlsop.c @@ -56,15 +56,15 @@ int usage(void) return 1; } -int process_cell(3d_lattice *3d_l,u32 x,u32 y,u32 z,int r,double a,double b,int *t_c) +int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,int r,double a,double b,int *t_c) { unsigned char *thiz; int *conc; int i,j; double p; - thiz=3d_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; - conc=3d_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; + thiz=d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; + conc=d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; p=b*URAND_MAX; for(i=-r;i<=r;i++) { @@ -97,7 +97,7 @@ int process_cell(3d_lattice *3d_l,u32 x,u32 y,u32 z,int r,double a,double b,int return 1; } -int distrib_c(3d_lattice *3d_l,int t_c,double a,double b) +int distrib_c(d3_lattice *d3_l,int t_c,double a,double b) { int i,j,k,total,area,sum; int temp,left; @@ -135,7 +135,7 @@ int distrib_c(3d_lattice *3d_l,int t_c,double a,double b) } } } - left=(((i+1)*a+b)*t_c/sum)%area_h[i]; + left=(int)(((i+1)*a+b)*t_c/sum)%area_h[i]; while(left) { x=get_rand(d3_l->max_x); @@ -164,7 +164,7 @@ int distrib_c(3d_lattice *3d_l,int t_c,double a,double b) return 1; } -int save_to_file(char *sf,3d_lattice *3d_l) +int save_to_file(char *sf,d3_lattice *d3_l) { int sf_fd,c; @@ -173,18 +173,18 @@ int save_to_file(char *sf,3d_lattice *3d_l) puts("cannot open save file"); return -1; } - if(write(sf_fd,3d_l,sizeof(3d_lattice))max_x*d3_l->max_y*d3_l->max_z; - if(write(sf_fd,3d_l->status,c*sizeof(unsigned char)status,c*sizeof(unsigned char))extra,c*sizeof(int)extra,c*sizeof(int))status,c*sizeof(unsigned char))status,c*sizeof(unsigned char))extra,c*sizeof(int))extra,c*sizeof(int))status=(unsigned char *)malloc(i*sizeof(unsigned char)))==NULL) + if((d3_l.status=(unsigned char *)malloc(i*sizeof(unsigned char)))==NULL) { puts("failed allocating status buffer"); return -1; } - memset(d3_l->status,0,i*sizeof(unsigned char)); - if((d3_l->extra=(int *)malloc(i*sizeof(int)))==NULL) + memset(d3_l.status,0,i*sizeof(unsigned char)); + if((d3_l.extra=(int *)malloc(i*sizeof(int)))==NULL) { puts("failed allocating concentration buffer"); return -1; } - memset(d3_l->extra,0,i*sizeof(int)); + memset(d3_l.extra,0,i*sizeof(int)); } else { load_from_file(l_file,&d3_l); - d3_lattice_init(&argc,argv,&d3_l,d3_l->max_x,d3_l->max_y,d3_l->max_z); + d3_lattice_init(&argc,argv,&d3_l,d3_l.max_x,d3_l.max_y,d3_l.max_z); } d3_event_init(&d3_l); @@ -381,18 +381,18 @@ int main(int argc,char **argv) { while((imax_x); - y_c=rand_get(d3_l->max_y); - z_c=rand_get_lgp(d3_l->max_z,a_el,b_el); - distrib_c(&3d_l,cc,a_cd,b_cd); - process_cell(&3d_l,x_c,y_c,z_c,range,a_ap,b_ap,&cc); + x_c=rand_get(d3_l.max_x); + y_c=rand_get(d3_l.max_y); + z_c=rand_get_lgp(d3_l.max_z,a_el,b_el); + distrib_c(&d3_l,cc,a_cd,b_cd); + process_cell(&d3_l,x_c,y_c,z_c,range,a_ap,b_ap,&cc); if(i%refresh==0) { sprintf(x_txt,"x: %d",x); sprintf(y_txt,"y: %d",y); sprintf(z_txt,"z: %d",z); - sprintf(status_txt,"status: %c",(*(d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?'a':'c'); - sprintf(conc_txt,"conc: %d",*(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)); + sprintf(status_txt,"status: %c",(*(d3_l.status+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y)&AMORPH)?'a':'c'); + sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y)); sprintf(steps_txt,"step: %d",i); sprintf(cc_txt,"total c: %d",cc); arg_v[1]=x_txt; @@ -417,8 +417,8 @@ int main(int argc,char **argv) sprintf(x_txt,"x: %d",x); sprintf(y_txt,"y: %d",y); sprintf(z_txt,"z: %d",z); - sprintf(status_txt,"status: %c",(*(d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?'a':'c'); - sprintf(conc_txt,"conc: %d",*(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)); + sprintf(status_txt,"status: %c",(*(d3_l.status+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y)&AMORPH)?'a':'c'); + sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y)); strcpy(steps_txt,"step: end!"); sprintf(cc_txt,"total c: %d",cc); arg_v[1]=x_txt; diff --git a/nlsop.h b/nlsop.h index 528c1c4..4700010 100644 --- a/nlsop.h +++ b/nlsop.h @@ -29,3 +29,4 @@ typedef unsigned int u32; #define B_AP .2 #define MAX_CHARS 64 +#define MAX_TXT 32 diff --git a/random.c b/random.c index 17cbd73..6694317 100644 --- a/random.c +++ b/random.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "random.h" diff --git a/random.h b/random.h index 4fa9aae..54d0f78 100644 --- a/random.h +++ b/random.h @@ -12,8 +12,8 @@ /* function prototypes */ int rand_init(char *rf); int rand_close(void); -int get_rand(u32 max); -int get_rand_lgp(u32 max,double a,double b); +u32 get_rand(u32 max); +u32 get_rand_lgp(u32 max,double a,double b); #define BUFSIZE (16*1048576) /* 64 MByte */ #define URAND_MAX 0xffffffff