ken@turtleva.UUCP (Ken Turkowski) (12/22/83)
echo x - hsalgs/task_master.c cat >hsalgs/task_master.c <<'!Funky!Stuff!' /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ task_master.c - distributes display tasks to various processes based on priority information from obj_sort and program names and file names gathered by scn_assmblr +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ #include "scn_assmblr.h" extern short ramp_lnth; /* scn_assmblr globals */ extern double view_angle,ambient_lite; static char *dvc; /* i/o and device characteristics globals */ static short bits,divisions,frmnum; static FILE *popen(),*stream; /* ++++++++++++++++++++++++++ TASK_MASTER ++++++++++++++++++++++++++++++++++ */ task_master(obj_array,p_list,device,num_bits,screen_divs,frame_num) object_def obj_array[]; char *device; short num_bits,screen_divs,frame_num; struct { short obj,insep; } p_list[]; { short i,cnt,cluster,pseudo_color; object_def *object; dvc = device; bits = num_bits; /* get globals */ divisions = screen_divs; frmnum = frame_num; if ((bits == 8) || (bits == 10)) pseudo_color = TRUE; else pseudo_color = FALSE; if (!bits) stream = popen("poly_drawl","w"); /* start line_drawer */ cluster = FALSE; cnt = 0; while (p_list[cnt].obj != 0) cnt++; /* count displayed objs */ /* ------------ call rendering algorithms in priority order ----------- */ for (i=0; i<cnt; i++) { short j,k; j = (pseudo_color)? cnt-1 - i : i; /* reverse order if pseudo_color */ k = (pseudo_color)? j-1 : j; object = &obj_array[p_list[j].obj]; /* start up display process for object and pipe input to it */ if ((bits) && (!cluster)) /* separable object */ { stream = popen(object->display,"w"); /* start up new process */ if (stream == NULL) fprintf(stderr," can't execute %s \n",object->display); } printf(" %s ",object->name); if (p_list[k].insep) printf("clustered with\n"); else printf("\n"); object_output(obj_array,object,cluster); /* write stream for process */ object->new_mtx = FALSE; /* tag to save later work */ cluster = p_list[k].insep; /* tag if clustered with next object */ if (!bits) cluster = TRUE; /* line drawings treated as single cluster */ if ((bits) && (!cluster)) pclose(stream); } if (!bits) pclose(stream); /* close stream if lines */ } /* +++++++++++++++++++++++++++ OBJECT_OUTPUT +++++++++++++++++++++++++++++++ */ object_output(obj_array,object,cluster) /* send object to display program */ object_def obj_array[],*object; short cluster; { short k,l; float light_postn[3]; /* ------------------- initialize display if new cluster --------------- */ if (!cluster) { if (strcmp(dvc,"bb") == 0) /* display on big buffer */ fprintf(stream,"device\t\t%s %d %d %d\n",dvc,bits,divisions,frmnum); else if (strcmp(dvc,"fb") == 0) /* display on frame buffer */ fprintf(stream,"device\t\t%s %d\n",dvc,frmnum); else if (strcmp(dvc,"aed") == 0) /* display on AED terminal */ fprintf(stream,"device\t\t%s\n",dvc); else if (!bits) /* line drawing */ fprintf(stream,"device\t\t%s\n",dvc); else /* unknown device */ fprintf(stream,"device\t\t%s %d %d %d\n",dvc,bits,divisions,frmnum); } /* --------------------- set up light sources --------------------------- */ for (l=0; l<16; l++) if (obj_array[LIT+l].name[0] != NULLCHAR) { double sqrt(),dist; k = LIT + l; light_postn[0] = light_postn[1] = light_postn[2] = 0.; transform(light_postn,obj_array[k].comp_mtx,light_postn); /* check if within range of light */ dist = sqrt(sqr(light_postn[0] - object->centroid[0]) + sqr(light_postn[1] - object->centroid[1]) + sqr(light_postn[2] - object->centroid[2])); if (dist < (obj_array[k].radius + object->radius)) fprintf(stream,"light\t\t%g %g %g %g %g %g %g\n", light_postn[0],light_postn[1],light_postn[2], obj_array[k].clr[0],obj_array[k].clr[1], obj_array[k].clr[2],obj_array[k].radius); } /* send ambient light if not default */ if (ambient_lite != .3) fprintf(stream,"ambient_light\t%g\n",ambient_lite); /* send angle included in field of view */ fprintf(stream,"view_angle\t%g\n",view_angle); /* send object filename */ fprintf(stream,"object\t\t%s\n",object->filename); /* clipped? */ if (!object->clipped) fprintf(stream,"no_clipping\n"); if ((bits == 8) || (bits == 10)) /* pseudocolor */ fprintf(stream,"color\t\t%d %d\n",ramp_lnth, object->clr_num*ramp_lnth+1); else /* full color */ fprintf(stream,"color\t\t%f %f %f\n",object->clr[0], object->clr[1],object->clr[2]); fprintf(stream,"transform\n "); /* transform matrix */ for (k=0; k<4; k++) fprintf(stream,"\t\t%g %g %g %g \n", object->comp_mtx[k][0],object->comp_mtx[k][1], object->comp_mtx[k][2],object->comp_mtx[k][3]); } !Funky!Stuff!