Changeset - 7fa6b34e407e
[Not reviewed]
default
0 1 0
LordOfWar - 16 years ago 2009-09-12 17:33:11

updated queue function, it now creates the job, then passes it to the add_job_to_queue function which properly places it in the queue based on its priority... but currently it only creates blender jobs, although I plan on using a switch statement to create different job types in the future.
1 file changed with 43 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -155,29 +155,47 @@ int start_data(){
 
void finish_frame(struct distrenjob *distrenjob, int frame){
 
  distrenjob->frameset[frame].status = 2;
 
  distrenjob->frameset[frame].time_to_render = (clock() - distrenjob[jobnum].frameset[frame].start_time); // Consider changing time-to-render to time-for-frame or something?
 
  general_info.total_frames_rendered++; // Increase total frames var for stats
 
}
 

	
 
/* This @TODO: replace queue function*/
 
/* This function creates a structure from starting data, then calls another function to actually add that struct to the queue
 
void make_blendjob(char *name, char *submitter, char *email, int priority, int start_frame, int end_frame){
 
  struct distrenjob *new_distrenjob;
 
  distrenjob->type = 1; /*@TODO: add type to blendjob struct
 

	
 
// This function creates a structure from starting data, then calls another function to actually add that struct to the queue
 
void queue(int type, char *name, char *submitter, char *email, int priority, int start_frame, int end_frame){
 
  struct distrenjob *distrenjob;
 
  distrenjob->type = 1; /*@TODO: add type to blendjob struct*/
 
  distrenjob->name = name;
 
  distrenjob->submitter = submitter;
 
  distrenjob->email = email;
 
  distrenjob->priority = priority;
 
  distrenjob->frameset = frameset[end_frame - start_frame + 1];
 
  distrenjob->total_frames = (end_frame - start_frame + 1); // sets the total number of frames in animation for status purposes
 

	
 
  /* @TODO: change frame_num_struct_builder to add_blendjob_to_queue
 
  add_blendjob_to_queue(new_distrenjob);
 
}
 
  /* @TODO: what does this do? frameset array is declared above */
 
  /*
 
  distrenjob->frameset = malloc(sizeof(struct frameset) * numframes);
 
  if(!job->frameset)
 
    fprintf(stderr, "Error allocating memory\n");
 
 */
 

	
 
/** Queuer: Adds files to the queue */
 
  /* prepares all the frames by setting that status to "unassigned" */
 
  int counter2 = start_frame;
 
  for(int counter = 0; counter <= (end_frame- start_frame + 1); counter++){
 
    distrenjob->frameset[counter].num = counter2;
 
    distrenjob->frameset[counter].status = 0;
 

	
 
    counter2++;
 
  }
 

	
 
  /* @TODO: change frame_num_struct_builder to add_blendjob_to_queue */
 
  add_job_to_queue(distrenjob);
 

	
 
  general_info.jobs_in_queue++;
 
}
 

	
 
/** -- OLD -- Queuer: Adds files to the queue
 
int queue(struct distrenjob *distrenjob, int type, char *name, char *submitter, char *email, int priority, int mode, int spp, struct frameset *frameset) {
 
  // Type: 1 = blender, add more types later
 
  // jobnum is the next available job number
 
  if(type == 1){
 
    distrenjob->name = name;
 
    distrenjob->submitter = submitter;
 
@@ -189,13 +207,13 @@ int queue(struct distrenjob *distrenjob,
 
    // Throw error.
 
    fprintf(stderr,"You tried to queue a job type that isn't supported by this version of DistRen.\nI have no idea how this would happen, but it just did.\n");
 
    return 0; // fail
 
  }
 
jobnum++; // Advance the jobnumber for the next queued job
 
return 0; // OK
 
}
 
}*/
 

	
 

	
 
/**
 
  Status Report Generator:
 
  -figures out how much of the job is done, where jobnum corresponds to the job number
 
  -removes finished jobs
 
@@ -286,28 +304,28 @@ void status_report_generator(struct dist
 

	
 
  general_info.jobs_in_queue = (highest_jobnum - general_info.total_finished_jobs); /*< extraneous parentheses! */
 
}
 

	
 

	
 
/** Structure Builder: This function creates frame array based on the total number of frames to be rendered, which will then be parsed by function frame_farmer. */
 
void frame_num_struct_builder(struct distrenjob *job, unsigned int startframe, unsigned int numframes) {
 
  int jobnum_new = highest_jobnum + 1; /* global vars will someday leave us  */
 
  unsigned int counter;
 

	
 
  job->frameset = malloc(sizeof(struct frameset) * numframes);
 
  if(!job->frameset)
 
    fprintf(stderr, "Error allocating memory\n");
 
void add_job_to_queue(struct distrenjob *job) {
 
  struct distrenjob *prev_job = head; // create pointer to previous job
 
  struct distrenjob *current_job;     // create pointer to current_job (which job is being compared to)
 

	
 
  job->total_frames = numframes; // sets the total number of frames in animation for status purposes
 
  job->jobnum = jobnum_new;
 

	
 
  for(counter = 0; counter < numframes; counter ++)
 
    /* This builds the array, with the array starting at zero and the frameset.num starting at sframe */
 
    job->frameset[counter].num = counter + startframe;
 

	
 
  highest_jobnum++; // After it has created the job, it adds one to the highest_jobnum interger
 
  // iterate through linked list of jobs
 
  for(current_job = head; current_job != NULL; current_job = current_job.next){
 
    if(current_job == NULL){ // if it has reached the end of the list, add job there
 
      current_job = job;
 
      break;
 
    }
 
    else if(job.priority < current_job.priority){ // if job's priority is less than current_job's priority, insert job
 
      prev_job.next = job;                        // keep in mind 1 is the lowest priority
 
      job.next = current_job;
 
      break;
 
    }
 
  } // end of for statement
 
}
 

	
 

	
 

	
 
/**
 
  Frame Finder: matches your computer up with a lovely frame to render
0 comments (0 inline, 0 general)