From: hackbard Date: Thu, 3 Apr 2003 13:32:42 +0000 (+0000) Subject: - X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=6ee2d4c247b82dc4aea6e9e5e6aecd7d857aaafd;p=physik%2Fmorpheus.git - --- diff --git a/Makefile b/Makefile index e2b0539..ad7af49 100644 --- a/Makefile +++ b/Makefile @@ -14,3 +14,5 @@ all: morpheus clean: rm $(OBJS) $(OBJS2) + +remake: clean all diff --git a/defines.h b/defines.h index 58befa1..a886a60 100644 --- a/defines.h +++ b/defines.h @@ -28,6 +28,8 @@ #define DEFAULT_STEPS 5000 +#define RAND_BUF_SIZE 1048576 /* 1 MB */ + /* program defines, dont touch ;) */ #define URAND_MAX 0xffffffff diff --git a/main.c b/main.c index 2e9cc0c..6916f22 100644 --- a/main.c +++ b/main.c @@ -26,6 +26,7 @@ #include "display.h" /* global variables */ +u32 *rand_buf,*rand_current; u32 gr; int random_fd; /* /dev/urandom file descriptor */ @@ -65,10 +66,8 @@ int make_cryst(cell *cell) int distrib_c_conc(cell *cell_p,int c_c0,int c_slope,u32 c_conc,u32 x_max,u32 y_max,u32 z_max) { - /* cryst. c to distribute */ - int i,j; - u32 area,c_area,total; + u32 area,c_area,total,count; u32 x,y,z,sum_c_z; total=0; @@ -77,17 +76,22 @@ int distrib_c_conc(cell *cell_p,int c_c0,int c_slope,u32 c_conc,u32 x_max,u32 y_ for(i=0;istatus&AMORPH) count++; + } + for(j=0;jstatus&AMORPH) { - (cell_p+j+i*area)->conc=c_area/area; - total+=c_area/area; + (cell_p+j+i*area)->conc=c_area/count; + total+=c_area/count; } } j=0; - while(jconc; if(this_cell->status&AMORPH) { /* wrong probability! just test by now ...*/ @@ -271,11 +278,20 @@ int main(int argc,char **argv) for(i=1;i<=z_cell;i++) gr+=i; printfd("debug: gr = %d\n",gr); + /* allocate random number buffer */ + printf("malloc will free %d bytes now ...\n",RAND_BUF_SIZE); + if((rand_buf=(u32 *)malloc(RAND_BUF_SIZE))==NULL) + { + puts("failed allocating memory for random numbers"); + return -23; + } + rand_current=rand_buf+RAND_BUF_SIZE; + /* allocate cells */ printf("malloc will free %d bytes now ...\n",x_cell*y_cell*z_cell*sizeof(cell)); if((cell_p=(cell *)malloc(x_cell*y_cell*z_cell*sizeof(cell)))==NULL) { - puts("failed allocating memory for cells\n"); + puts("failed allocating memory for cells"); return -23; } memset(cell_p,0,x_cell*y_cell*z_cell*sizeof(cell)); @@ -291,9 +307,10 @@ int main(int argc,char **argv) x=rand_get(x_cell); y=rand_get(y_cell); z=rand_get_lgp(slope_nel,start_nel,z_cell); + printfd("x = %u, y = %u, z = %u\n",x,y,z); /* todo */ - // distrib_c_conc(cell_p,c_dist_c0,c_dist_slope,c_conc,x_cell,y_cell,z_cell); + distrib_c_conc(cell_p,c_dist_c0,c_dist_slope,c_conc,x_cell,y_cell,z_cell); // process_cell(cell_p+x+y*x_cell+z*x_cell*y_cell); process_cell(cell_p,x,y,z,x_cell,y_cell,z_cell,a_p_range,a_p_faktor,a_p_p0,&c_conc); diff --git a/random.c b/random.c index 51f6774..5657eed 100644 --- a/random.c +++ b/random.c @@ -12,18 +12,23 @@ /* global and extern variables */ extern u32 gr; extern int random_fd; +extern u32 *rand_buf,*rand_current; /* return random integer between 0 - max-1 */ u32 rand_get(u32 max) { - u32 rand_int; - if(read(random_fd,&rand_int,4)!=4) + if(rand_current==rand_buf+RAND_BUF_SIZE) { - puts("failed reading 4 bytes of random data"); - return -23; + printfd("debug: reading new random bytes\n"); + if(read(random_fd,rand_buf,RAND_BUF_SIZE)!=RAND_BUF_SIZE) + { + puts("failed reading viel bytes of random data"); + return -23; + } + rand_current=rand_buf; } /* cells numbered 0...max-1 */ - return((u32)(rand_int*(max*1.0/URAND_MAX))); + return((u32)(*(rand_current++)*(max*1.0/URAND_MAX))); } /* get z value (linear growth of probability with depths) */ @@ -40,4 +45,3 @@ u32 rand_get_lgp(int slope_nel,int start_nel,u32 z_max) return(i-1); /* return values 0...z_cell-1 */ } -