From: hackbard Date: Mon, 31 Mar 2003 14:52:58 +0000 (+0000) Subject: added event stuff, c conc and more ... X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=dcc213e7fef0a79e92d8548bd9a37461e91c9a5c;p=physik%2Fmorpheus.git added event stuff, c conc and more ... --- diff --git a/defines.h b/defines.h index 981ab45..17e83cf 100644 --- a/defines.h +++ b/defines.h @@ -18,8 +18,8 @@ #define DEFAULT_SLOPE_NEL 1 #define DEFAULT_START_NEL 0 -#define DEFAULT_A_P_RANGE 2 -#define DEFAULT_A_P_FAKTOR 1 +#define DEFAULT_A_P_RANGE 0.2 +#define DEFAULT_A_P_FAKTOR 0.2 #define DEFAULT_STEPS 5000 @@ -47,6 +47,8 @@ typedef struct __display { IDirectFB *dfb; /* pointer to dfb main construct */ IDirectFBSurface *primary_surface; /* pointer to dfb primary surface */ IDirectFBFont *font; /* the font */ + IDirectFBInputDevice *keyboard; /* for keyboard input */ + IDirectFBEventBuffer *keyboard_buffer; /* event buffer */ #endif int screen_height,screen_width; /* screen dimensions */ } display; diff --git a/display.c b/display.c index 7619be2..809b556 100644 --- a/display.c +++ b/display.c @@ -38,6 +38,7 @@ int display_init(int x,int y,int z,display *display,void *cell,int *argc,char ** int display_release(display *display) { #ifdef USE_DFB_API + display->font->Release(display->font); display->primary_surface->Release(display->primary_surface); display->dfb->Release(display->dfb); #endif @@ -63,11 +64,13 @@ int dfb_choose_color(u32 *cell_p,unsigned char *r,unsigned char *g,unsigned char } #endif -int display_draw(display *display,int x,int y,int z) +int display_draw(display *display,u32 x,u32 y,u32 z) { #ifdef USE_DFB_API int menu_x,menu_y,menu_w,menu_h; /* for the yellow box */ - int x_c,y_c,z_c; + DFBFontDescription font_dsc; + char text[MAX_TXT]; + u32 x_c,y_c,z_c; unsigned char r,g,b,a; int display_faktor_x,display_faktor_y; a=0xff; /* no alpha blending */ @@ -137,8 +140,49 @@ int display_draw(display *display,int x,int y,int z) display->primary_surface->FillRectangle(display->primary_surface,menu_x,menu_y,menu_w,menu_h); display->primary_surface->SetColor(display->primary_surface,r,g,b,a); display->primary_surface->DrawRectangle(display->primary_surface,menu_x,menu_y,menu_w,menu_h); + font_dsc.flags=DFDESC_HEIGHT; + font_dsc.height=menu_h/10; + display->dfb->CreateFont(display->dfb,DISPLAY_FONT,&font_dsc,&(display->font)); + display->primary_surface->SetFont(display->primary_surface,display->font); + display->primary_surface->SetColor(display->primary_surface,0x80,0x80,0xff,0xff); + sprintf(text,"x: %u",x); + display->primary_surface->DrawString(display->primary_surface,text,-1,menu_x+display_faktor_x,menu_y+display_faktor_y+menu_h/10,DSTF_LEFT); + sprintf(text,"y: %u",y); + display->primary_surface->DrawString(display->primary_surface,text,-1,menu_x+display_faktor_x,menu_y+display_faktor_y*2+menu_h/10*2,DSTF_LEFT); + sprintf(text,"z: %u",z); + display->primary_surface->DrawString(display->primary_surface,text,-1,menu_x+display_faktor_x,menu_y+display_faktor_y*3+menu_h/10*3,DSTF_LEFT); + sprintf(text,"status: %c",*(u32 *)(display->cell_p+x+y*(display->max_x-1)+z*(display->max_x-1)*(display->max_y-1))&AMORPH?'a':'c'); + display->primary_surface->DrawString(display->primary_surface,text,-1,menu_x+display_faktor_x,menu_y+display_faktor_y*5+menu_h/10*5,DSTF_LEFT); + sprintf(text,"C conc.: %u",(*(u32 *)(display->cell_p+x+y*(display->max_x-1)+z*(display->max_x-1)*(display->max_y-1))&C_CONC_MASK)>>1); + display->primary_surface->DrawString(display->primary_surface,text,-1,menu_x+display_faktor_x,menu_y+display_faktor_y*6+menu_h/10*6,DSTF_LEFT); /* flip all to surface */ display->primary_surface->Flip(display->primary_surface,NULL,0); #endif return 23; } + +int display_event_init(display *display) +{ +#ifdef USE_DFB_API + display->dfb->GetInputDevice(display->dfb,DIDID_KEYBOARD,&(display->keyboard)); + display->keyboard->CreateEventBuffer(display->keyboard,&(display->keyboard_buffer)); +#endif + return 23; +} + +int display_scan_event(display *display,u32 *x,u32 *y,u32 *z,int *quit) +{ + DFBInputEvent keyboard_event; + display->keyboard_buffer->GetEvent(display->keyboard_buffer,DFB_EVENT(&keyboard_event)); + if(keyboard_event.type==DIET_KEYPRESS) + { + if(keyboard_event.key_id==DIKI_LEFT && *x!=0) *x-=1; + if(keyboard_event.key_id==DIKI_RIGHT && *x!=(display->max_x)-1) *x+=1; + if(keyboard_event.key_id==DIKI_DOWN && *y!=0) *y-=1; + if(keyboard_event.key_id==DIKI_UP && *y!=(display->max_y)-1) *y+=1; + if(keyboard_event.key_id==DIKI_PAGE_UP && *z!=0) *z-=1; + if(keyboard_event.key_id==DIKI_PAGE_DOWN && *z!=(display->max_z)-1) *z+=1; + if(keyboard_event.key_id==DIKI_Q) *quit=1; + } + return 23; +} diff --git a/display.h b/display.h index 4beb565..f1f38a2 100644 --- a/display.h +++ b/display.h @@ -11,4 +11,6 @@ int display_release(display *display); int dfb_choose_color(u32 *cell_p,unsigned char *r,unsigned char *g,unsigned char *b); int display_draw(display *display,int x,int y,int z); +int display_event_init(display *display); +int display_scan_event(display *display,u32 *x,u32 *y,u32 *z,int *quit); diff --git a/main.c b/main.c index 66503ee..9438a32 100644 --- a/main.c +++ b/main.c @@ -45,8 +45,8 @@ int usage() puts("-Z \t display area intercept point z (default # z cells / 2)"); puts("-d \t refresh every loops (default 100)"); puts("-r \t pressure range from amorphous SiCx (default 2)"); - puts("-f \t (unused) faktor for pressure from amorphous SiCx (default 1)"); - puts("-p \t p0 for probability of cell getting amorph (default sum_range_rate / 4)"); + puts("-f \t faktor for pressure from amorphous SiCx (default 0.2)"); + puts("-p \t p0 for probability of cell getting amorph (default 0.2)"); return -23; } @@ -67,6 +67,7 @@ int process_cell(void *cell_p,u32 x,u32 y,u32 z,u32 x_max,u32 y_max,u32 z_max,in { u32 *cell; int i,j,k,count; + double pressure; // float count; cell=(u32 *)(cell_p+x+y*(x_max-1)+z*(x_max-1)*(y_max-1)); count=p0; @@ -78,7 +79,8 @@ int process_cell(void *cell_p,u32 x,u32 y,u32 z,u32 x_max,u32 y_max,u32 z_max,in { if(!(i==0 && j==0 && k==0)) { - if(*(u32 *)(cell_p+((x+x_max+i)%x_max)+((y+j+y_max)%y_max)*(x_max-1)+((z+k+z_max)%z_max)*(x_max-1)*(y_max-1))&AMORPH) count+=(3*range*range-i*i-j*j-k*k); + if(*(u32 *)(cell_p+((x+x_max+i)%x_max)+((y+j+y_max)%y_max)*(x_max-1)+((z+k+z_max)%z_max)*(x_max-1)*(y_max-1))&AMORPH) pressure+=faktor*URAND_2BYTE_MAX/(i*i+j*j+k*k); + // count+=(3*range*range-i*i-j*j-k*k); } } } @@ -99,14 +101,16 @@ int main(int argc,char **argv) { u32 x_cell,y_cell,z_cell; /* amount of segments */ u32 x,y,z; /* cells */ - int i,j,k; /* for counting */ + int i; /* for counting */ int slope_nel,start_nel; /* nuclear energy loss: slope, constant */ - int a_p_range,a_p_faktor,a_p_p0; /* p. range, p0 and faktor of amorphous sic */ + int a_p_range; /* p. range of amorphous sic */ + double a_p_faktor,a_p_p0; /* p0 and faktor of amorphous sic */ int steps; /* # steps */ void *cell_p; struct __display display; u32 display_x,display_y,display_z; /* intercept point of diplayed areas */ u32 display_refresh_rate; /* refresh rate for display */ + int quit=0; /* continue/quit status */ /* default values */ x_cell=DEFAULT_X_SEG; @@ -168,10 +172,10 @@ int main(int argc,char **argv) a_p_range=atoi(argv[++i]); break; case 'f': - a_p_faktor=atoi(argv[++i]); + a_p_faktor=atof(argv[++i]); break; case 'p': - a_p_p0=atoi(argv[++i]); + a_p_p0=atof(argv[++i]); break; default: usage(); @@ -191,22 +195,22 @@ int main(int argc,char **argv) sum_z_cells=0; for(i=1;i<=z_cell;i++) sum_z_cells+=(start_nel+i*slope_nel); printfd("debug: sum z cells -> %u\n",sum_z_cells); - sum_range_rate=0; - for(i=-a_p_range;i<=a_p_range;i++) - { - for(j=-a_p_range;j<=a_p_range;j++) - { - for(k=-a_p_range;k<=a_p_range;k++) - { - if(!(i==0 && j==0 && k==0)) - sum_range_rate+=((3*a_p_range*a_p_range)-i*i-j*j-k*k); - } - } - } - printfd("debug: sum range rate -> %u\n",sum_range_rate); - /* add a_p_p0 ... */ - if(a_p_p0==NOT_SPECIFIED) a_p_p0=sum_range_rate/4; - sum_range_rate+=a_p_p0; + // sum_range_rate=0; + // for(i=-a_p_range;i<=a_p_range;i++) + // { + // for(j=-a_p_range;j<=a_p_range;j++) + // { + // for(k=-a_p_range;k<=a_p_range;k++) + // { + // if(!(i==0 && j==0 && k==0)) + // sum_range_rate+=((3*a_p_range*a_p_range)-i*i-j*j-k*k); + // } + // } + // } + // printfd("debug: sum range rate -> %u\n",sum_range_rate); + // /* add a_p_p0 ... */ + // if(a_p_p0==NOT_SPECIFIED) a_p_p0=sum_range_rate/4; + // sum_range_rate+=a_p_p0; /* testing ... */ @@ -237,14 +241,19 @@ int main(int argc,char **argv) process_cell(cell_p,x,y,z,x_cell,y_cell,z_cell,a_p_range,a_p_faktor,a_p_p0); /* display stuff */ - if((i%display_refresh_rate)==0) + if((i%display_refresh_rate)==0) display_draw(&display,display_x,display_y,display_z); } - /* display again and quit when button hit */ + /* display again and listen for events */ display_draw(&display,display_x,display_y,display_z); - puts("hit button to quit ..."); - getchar(); + display_event_init(&display); + + while(!quit) + { + display_scan_event(&display,&display_x,&display_y,&display_z,&quit); + display_draw(&display,display_x,display_y,display_z); + } display_release(&display);