diff --git a/src/server/distrend.c b/src/server/distrend.c --- a/src/server/distrend.c +++ b/src/server/distrend.c @@ -68,6 +68,7 @@ struct general_info { unsigned int highest_jobnum; short int hibernate; unsigned int timestamp; + unsigned long int total_render_power; } general_info; @@ -418,6 +419,95 @@ int find_jobframe(struct distrenjob *hea return 0; } +int find_jobframe_from_job(struct distrenjob *head, struct distrenjob *distrenjob_ptr, struct distrenjob **job, struct frameset **frame) +{ + unsigned int frame_counter; + unsigned short int found; + + found = 0; + for(frame_counter = (distrenjob_ptr->prev_frame_index + 1); frame_counter < distrenjob_ptr->total_frames; frame_counter ++) + { + if(distrenjob_ptr->frameset[frame_counter].status == FRAMESETSTATUS_UNASSIGNED) // jobframe found + { + found = 1; + distrenjob_ptr->frameset[frame_counter].status = FRAMESETSTATUS_ASSIGNED; + distrenjob_ptr->frameset[frame_counter].start_time = clock(); + distrenjob_ptr->assigned_frames++; + distrenjob_ptr->prev_frame_index = frame_counter; + updateJobStatsXML(distrenjob_ptr); + } + + if(found) + break; + } + + + if(!found) + { + fprintf(stderr, "No more frames in this job number %d", distrenjob_ptr->jobnum); + sleep(1); /*< @todo eliminate the need for this line*/ + return 1; + } + + *job = distrenjob_ptr; + *frame = &distrenjob_ptr->frameset[frame_counter]; + + return 0; +} + +// find a frame to render when the job that the last frame was for no longer exists +int find_jobframe_new(struct distrenjob *head, int rend_pwr, struct distrenjob **job, struct frameset **frame) +{ + if(general_info.hibernate) + return 1; + + unsigned short int found; + struct distrenjob *job_to_render; + + struct distrenjob *distrenjob_ptr; + + found = 0; + /* iterate through jobs from first to last */ + for(distrenjob_ptr = head->next; distrenjob_ptr && !distrenjob_ptr->hibernate; distrenjob_ptr = distrenjob_ptr->next) + { + + job_to_render = distrenjob_ptr; + } + + find_jobframe_from_job(head, job_to_render, job, frame); + + if(!found) + { + fprintf(stderr, "No more jobs to render\n"); + sleep(1); /*< @todo eliminate the need for this line*/ + return 1; + } + + return 0; +} + +// gets a frame to render from the same job that the previously rendered frame was from +int find_jobframe_again(struct distrenjob *head, int jobnum, int rend_pwr, struct distrenjob **job, struct frameset **frame) +{ + if(general_info.hibernate) + return 1; + + struct distrenjob *distrenjob_ptr; + + distrenjob_ptr = distrenjob_get(head, jobnum); + + if(!distrenjob_ptr) + { + fprintf(stderr, "Job number %d has been finished, finding new job\n", jobnum); + sleep(1); /*< @todo eliminate the need for this line*/ + return 1; + } + + find_jobframe_new(head, rend_pwr, job, frame); + + return 0; +} + /** Checks for dead, latent, or stale slaves */ void frame_watchdog(struct distrenjob *distrenjob_head) {