added 2 newview modes: c conc & a pressure
authorhackbard <hackbard>
Wed, 9 Jul 2003 16:55:35 +0000 (16:55 +0000)
committerhackbard <hackbard>
Wed, 9 Jul 2003 16:55:35 +0000 (16:55 +0000)
dfbapi.c
dfbapi.h
nlsop.c
nlsop.h

index 3b0c895..3dfecda 100644 (file)
--- a/dfbapi.c
+++ b/dfbapi.c
@@ -93,28 +93,40 @@ int d3_lattice_release(d3_lattice *d3_l)
  return 1;
 }
 
-int dx_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b)
+int dx_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b,unsigned char mode)
 {
- if((*status)&RED)
+ *g=0;
+ if(!mode)
  {
-  *r=0xff;
-  *g=0;
-  *b=0;
- } else
+  if((*status)&RED)
+  {
+   *r=0xff;
+   *b=0;
+  } else
+  {
+   *r=0;
+   *b=0xff;
+  }
+ } else if(mode==1)
+ {
+  *r=*status;
+  *g=*status;
+  *b=0xff;
+ } else if(mode==2)
  {
-  *r=0;
-  *g=0;
+  *r=*status;
   *b=0xff;
  }
  
  return 1;
 }
 
-int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v)
+int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v,unsigned char mode)
 {
  int x_c,y_c;
  int i;
  unsigned char r,g,b,a;
+ unsigned char foobar;
 
  a=0xff; /* no alpha blending */
  
@@ -122,7 +134,17 @@ int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v)
  {
   for(y_c=0;y_c<d2_l->max_y;y_c++)
   {
-   dx_lattice_get_color((*d2_l).status+x_c+y_c*d2_l->max_x,&r,&g,&b);
+   if(!mode) dx_lattice_get_color((*d2_l).status+x_c+y_c*d2_l->max_x,&r,&g,&b,mode);
+   if(mode==1)
+   {
+    foobar=(unsigned char)(*(d2_l->extra+x_c+y_c*d2_l->max_x)*255/MAX_EXTRA);
+    dx_lattice_get_color(&foobar,&r,&g,&b,mode);
+   }
+   if(mode==2)
+   {
+    foobar=(*(unsigned char *)(d2_l->v_ptr+x_c+y_c*d2_l->max_x));
+    dx_lattice_get_color(&foobar,&r,&g,&b,mode);
+   }
    if(x_c==x && y_c==y)
    {
     r=0xff;
@@ -162,10 +184,11 @@ int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v)
  return 1;
 }
 
-int d3_lattice_draw(d3_lattice *d3_l,int x,int y,int z,int arg_c,char **arg_v)  
+int d3_lattice_draw(d3_lattice *d3_l,int x,int y,int z,int arg_c,char **arg_v,unsigned char mode)
 {
  int x_c,y_c,z_c;
  int i;
+ unsigned char foobar;
  unsigned char r,g,b,a;
 
  a=0xff; /* no alpha blending */
@@ -175,7 +198,17 @@ int d3_lattice_draw(d3_lattice *d3_l,int x,int y,int z,int arg_c,char **arg_v)
  {
   for(z_c=0;z_c<d3_l->max_z;z_c++)
   {
-   dx_lattice_get_color((*d3_l).status+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y,&r,&g,&b);
+   if(!mode) dx_lattice_get_color((*d3_l).status+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y,&r,&g,&b,mode);
+   if(mode==1)
+   {
+    foobar=(unsigned char)(*(d3_l->extra+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y)*255/MAX_EXTRA);
+    dx_lattice_get_color(&foobar,&r,&g,&b,mode);
+   }
+   if(mode==2)
+   {
+    foobar=(*(unsigned char *)(d3_l->v_ptr+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y));
+    dx_lattice_get_color(&foobar,&r,&g,&b,mode);
+   }
    if(x_c==x && z_c==z)
    {
     r=0xff;
@@ -195,7 +228,17 @@ int d3_lattice_draw(d3_lattice *d3_l,int x,int y,int z,int arg_c,char **arg_v)
  {
   for(z_c=0;z_c<d3_l->max_z;z_c++)
   {
-   dx_lattice_get_color((*d3_l).status+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y,&r,&g,&b);
+   if(!mode) dx_lattice_get_color((*d3_l).status+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y,&r,&g,&b,mode);
+   if(mode==1)
+   {
+    foobar=(unsigned char)(*(d3_l->extra+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y)*255/MAX_EXTRA);
+    dx_lattice_get_color(&foobar,&r,&g,&b,mode);
+   }
+   if(mode==2)
+   {
+    foobar=(*(unsigned char *)(d3_l->v_ptr+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y));
+    dx_lattice_get_color(&foobar,&r,&g,&b,mode);
+   }
    if(y_c==y && z_c==z)
    {
     r=0xff;
@@ -215,7 +258,17 @@ int d3_lattice_draw(d3_lattice *d3_l,int x,int y,int z,int arg_c,char **arg_v)
  {
   for(y_c=0;y_c<d3_l->max_y;y_c++)
   {
-   dx_lattice_get_color((*d3_l).status+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y,&r,&g,&b);
+   if(!mode) dx_lattice_get_color((*d3_l).status+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y,&r,&g,&b,mode);
+   if(mode==1)
+   {
+    foobar=(unsigned char)(*(d3_l->extra+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y)*255/MAX_EXTRA);
+    dx_lattice_get_color(&foobar,&r,&g,&b,mode);
+   }
+   if(mode==2)
+   {
+    foobar=(*(unsigned char *)(d3_l->v_ptr+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y));
+    dx_lattice_get_color(&foobar,&r,&g,&b,mode);
+   }
    if(x_c==x && y_c==y)
    {
     r=0xff;
@@ -287,7 +340,7 @@ int d3_event_init(d3_lattice *d3_l)
  return 1;                                                           
 }         
 
-int scan_event(d3_lattice *d3_l,int *x,int *y,int *z,int *q,int *esc)
+int scan_event(d3_lattice *d3_l,int *x,int *y,int *z,int *q,int *esc,int *switchmode)
 {
  DFBInputEvent ke;
 
@@ -303,6 +356,7 @@ int scan_event(d3_lattice *d3_l,int *x,int *y,int *z,int *q,int *esc)
   if(ke.key_id==DIKI_PAGE_DOWN && *z!=d3_l->max_z-1) *z+=1;
   if(ke.key_id==DIKI_Q) *q=1;
   if(ke.key_id==DIKI_ESCAPE) *esc=1;
+  if(ke.key_id==DIKI_M) *switchmode=(*switchmode+1)%3;
  }
 
  return 1;
index 51786bc..e5333cb 100644 (file)
--- a/dfbapi.h
+++ b/dfbapi.h
@@ -17,6 +17,7 @@
 #define X_GAP 5
 #define Y_GAP X_GAP
 #define RED 1
+#define MAX_EXTRA 20
 
 typedef struct __d2_lattice
 {
@@ -65,13 +66,13 @@ typedef struct __d3_lattice
 /* function prototypes */
 int d2_lattice_init(int *argc,char **argv,d2_lattice *d2_l);
 int d2_lattice_release(d2_lattice *d2_l);
-int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v);
+int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v,unsigned char mode);
 int d3_lattice_init(int *argc,char **argv,d3_lattice *d3_l);
 int d3_lattice_release(d3_lattice *d3_l);
-int d3_lattice_draw(d3_lattice *d3_l,int x,int y,int z,int arg_c,char **arg_v);
+int d3_lattice_draw(d3_lattice *d3_l,int x,int y,int z,int arg_c,char **arg_v,unsigned char mode);
 int d2_event_init(d2_lattice *d2_l);
 int d3_event_init(d3_lattice *d3_l);
-int scan_event(d3_lattice *d3_l,int *x,int *y,int *z,int *q,int *esc);
-int dx_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b);
+int scan_event(d3_lattice *d3_l,int *x,int *y,int *z,int *q,int *esc,int *switchmode);
+int dx_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b,unsigned char mode);
 
 #endif /* DFBAPI_H */
diff --git a/nlsop.c b/nlsop.c
index d61d2ac..e9d72ab 100644 (file)
--- a/nlsop.c
+++ b/nlsop.c
@@ -87,7 +87,7 @@ int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,int r,double a,double b,int
    } 
   }
  }
// printf("debug: p = %f\n",p);
+ printf("debug: p = %f\n",p);
  if(!(*thiz&AMORPH))
  {
   if(get_rand(URAND_MAX)<=p) MAKE_AMORPH(thiz);
@@ -233,6 +233,38 @@ int distrib_c(d3_lattice *d3_l,double d_r,double a,double b,char z_diff)
  return 1;
 }
 
+int calc_pressure(d3_lattice *d3_l,int range)
+{
+ int i,j,off;
+ double count;
+ int x,y,z;
+
+ for(x=0;x<d3_l->max_x;x++)
+ {
+  for(y=0;y<d3_l->max_y;y++)
+  {
+   for(z=0;z<d3_l->max_z;z++)
+   {
+    count=0;
+    for(i=-range;i<=range;i++)
+    {
+     for(j=-range;j<=range;j++)
+     {
+      if(i!=0 && j!=0)
+      {
+       off=((x+d3_l->max_x+i)%d3_l->max_x)+((y+d3_l->max_y+j)%d3_l->max_x)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
+       if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
+      }
+     }
+    }
+    *(unsigned char *)(d3_l->v_ptr+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)=(unsigned char)(count*255/MAX_VPTR);
+   }
+  }
+ }
+
+ return 1;
+}
+
 int distrib_c_old(d3_lattice *d3_l,int t_c,double a,double b)
 {
  int i,j,k,total,area;
@@ -404,7 +436,7 @@ int convert_file(char *cf,d3_lattice *d3_l)
 int main(int argc,char **argv)
 {
  u32 x,y,z,x_c,y_c,z_c;
- int i,quit,escape,nowait;
+ int i,quit,escape,switchmode,nowait;
  int refresh,resave;
  char z_diff;
  char s_file[MAX_CHARS];
@@ -431,10 +463,12 @@ int main(int argc,char **argv)
  char cd2_txt[MAX_TXT];
  char el2_txt[MAX_TXT];
  char dr_txt[MAX_TXT];
+ char mode_txt[MAX_TXT];
  char *arg_v[MAX_ARGV];
 #endif
  d3_lattice d3_l;
  info my_info;
+ unsigned char mode;
 
  d3_l.max_x=X;
  d3_l.max_y=Y;
@@ -455,11 +489,13 @@ int main(int argc,char **argv)
  nowait=0;
  quit=0;
  escape=0;
+ switchmode=0;
  strcpy(s_file,"");
  strcpy(l_file,"");
  strcpy(c_file,"");
  convert=0;
  strcpy(r_file,"");
+ mode=0;
 
  for(i=1;i<argc;i++)
  {
@@ -617,6 +653,7 @@ int main(int argc,char **argv)
  sprintf(cd_txt,"c distrib slope: %.2f",my_info.a_cd);
  sprintf(cd2_txt,"c distrib offset: %.2f",my_info.b_cd);
  sprintf(dr_txt,"diffusion rate: %.2f",my_info.d_r);
+ strcpy(mode_txt,"view: a/c mode");
  arg_v[1]=x_txt;
  arg_v[2]=y_txt;
  arg_v[3]=z_txt;
@@ -624,7 +661,7 @@ int main(int argc,char **argv)
  arg_v[5]=status_txt;
  arg_v[6]=conc_txt;
  arg_v[7]=NULL;
- arg_v[8]=NULL;
+ arg_v[8]=mode_txt;
  arg_v[9]=NULL;
  arg_v[10]=steps_txt;;
  arg_v[11]=cc_txt;
@@ -663,7 +700,7 @@ int main(int argc,char **argv)
     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",my_info.cc);
-    d3_lattice_draw(&d3_l,x,y,z,24,arg_v);
+    d3_lattice_draw(&d3_l,x,y,z,24,arg_v,mode);
    }
 #endif
    if(i%resave==0 && strcmp(s_file,"") && resave!=0)
@@ -685,8 +722,22 @@ int main(int argc,char **argv)
  }
 
 #ifdef USE_DFB_API
+ /* allocating buffer for pressure values */
+ if((d3_l.v_ptr=malloc(d3_l.max_x*d3_l.max_y*d3_l.max_z*sizeof(unsigned char)))==NULL)
+ {
+  puts("cannot allocate buffer for pressure values");
+  return -1;
+ }
+ /* calc values */
+ calc_pressure(&d3_l,my_info.range);
+
  while((quit==0) && (escape==0) && (nowait==0))
  {
+  /* bahh! */
+  if(switchmode==0) mode=0;
+  if(switchmode==1) mode=1;
+  if(switchmode==2) mode=2;
+  /* end of bahh! */
   sprintf(x_txt,"x: %d",x+1);
   sprintf(y_txt,"y: %d",y+1);
   sprintf(z_txt,"z: %d",z+1);
@@ -694,8 +745,11 @@ int main(int argc,char **argv)
   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",my_info.cc);
-  d3_lattice_draw(&d3_l,x,y,z,24,arg_v);
-  scan_event(&d3_l,&x,&y,&z,&quit,&escape);
+  if(switchmode==0) strcpy(mode_txt,"view: a/c mode");
+  if(switchmode==1) strcpy(mode_txt,"view: c conc mode");
+  if(switchmode==2) strcpy(mode_txt,"view: a pressure mode");
+  d3_lattice_draw(&d3_l,x,y,z,24,arg_v,mode);
+  scan_event(&d3_l,&x,&y,&z,&quit,&escape,&switchmode);
  }
 
  d3_lattice_release(&d3_l);
diff --git a/nlsop.h b/nlsop.h
index 979d425..1b8e4ca 100644 (file)
--- a/nlsop.h
+++ b/nlsop.h
@@ -44,4 +44,6 @@ typedef struct __info
 #define MAX_TXT 32
 #define MAX_ARGV 27
 
+#define MAX_VPTR 50
+
 #endif /* NLSOP_H */