diff --git a/src/server/distrend.c b/src/server/distrend.c --- a/src/server/distrend.c +++ b/src/server/distrend.c @@ -82,6 +82,9 @@ struct blendjob { int completed_frames; // number of completed frames for stats/etc int assigned_frames; // number of assigned frames (that are not yet completed) for stats/etc int total_frames; // how many frames are in the animation for stats/etc + int avg_render_time; // average seconds it took to render a frame + unsigned int time_remaining; // estimated seconds remaining till render is complete (up to 49, 710 days) + // we can have the client computer convert it into days, hours, etc if they wish to view it struct frameset *frameset; } blendjob[MAX_BLENDJOBS]; @@ -91,6 +94,8 @@ struct frameset { int frame_num; // frame number to render char slave_name; // user that frame is assigned to int frame_status; // status of frame, 0= unassigned, 1= taken, 2= done + clock_t start_time; // time the frame was started + int time_to_render; // the total seconds it took to render the frame } frameset[]; // Frameset array is generated by status_report_generator function // Using this method to save memory, because if animation starts on a high frame number, it would waste a lot of RAM on empty structures @@ -100,8 +105,10 @@ struct frameset { /* ********************** Functions ************************* */ // **** Finish-Setter: Sets a frame to the "completed" status. -void finish_frame(int frame){ +void finish_frame(int jobnum, int frame){ blendjob[jobnum].frameset[frame].frame_status = 2; + + blendjob[jobnum].frameset[frame].time_to_render = (clock() - blendjob[jobnum].frameset[frame].start_time); } @@ -131,35 +138,45 @@ void status_report_generator(){ hcfjob++; // adds 1 to the highest consecutively finished job and checks the next one, till the job after the hcfjob is not done int num1 = hcfjob+1; // to scan through jobs - int num2 = 0; // to scan through frames + while(num1 <= highest_jobnum){ if(blendjob[num1].priority != 0){ // If the job is not done, scan it + int num2 = 0; // to scan through frames float finished_frames = 0; // variable that counts the completed frames int pending_frames = 0; // variable that counts the assigned frames float percent = 0; // variable that stores the percent done of the blendjob + unsigned int total_time = 0; // total time taken to render all the completed frames for a job - while(num2 <= blendjob[jobnum].total_frames){ // If - if(blendjob[jobnum].frameset[num2].frame_status == 2) + while(num2 <= blendjob[num1].total_frames){ // scans through frames, based on their status it runs a statement(s) + if(blendjob[num1].frameset[num2].frame_status == 2){ // If the frame is done finished_frames++; + total_time = total_time + blendjob[num1].frameset[num2].time_to_render; + } - if(blendjob[jobnum].frameset[num2].frame_status == 1) + if(blendjob[num1].frameset[num2].frame_status == 1) // If the frame is assigned pending_frames++; num2++; } + // find the percent of completed frames percent = (finished_frames / blendjob[num1].total_frames) * 100; + // updates values in the blendjob struct for jobnum held by the variable num1 blendjob[num1].completed_frames = finished_frames; blendjob[num1].assigned_frames = pending_frames; blendjob[num1].percent_done = percent; + blendjob[num1].avg_render_time = (total_time / finished_frames); + blendjob[num1].time_remaining = (blendjob[num1].avg_render_time * (blendjob[num1].total_frames - finished_frames)); + + if(finished_frames == blendjob[num1].total_frames) // If all frames are complete, set priority to zero to indicate job is complete + blendjob[num1].priority = 0; } num1++; } - } @@ -226,10 +243,28 @@ your_frame = blendjob[jobnum].frameset[f if(your_frame == 0) // If that job had no open frames for some reason, run the status report generator so that status_report_generator(); //the job priority can be changed to 0 +blendjob[jobnum].frameset[frameset_count].start_time = clock(); + return your_frame; // your_frame is returned as the frame to be rendered } +void blend_frame_watchdog(){ + short int watchdog_forgiveness = 3; // Hours to wait on a frame before re-assigning it + int num1 = hcfjob + 1; + + while(num1 <= highest_jobnum){ // counts up through all the jobs + int num2 = 0; + + while(num2 <= blendjob[num1].total_frames){ // Counts up through all the frames + if((blendjob[num1].frameset[num2].start_time + (watchdog_forgiveness * 3600)) < clock()) // If frame is not completed within the number of hours specified by watchdog_forgiveness + blendjob[num1].frameset[num2].frame_status = 0; // Then change the frame status to unassigned + + num2++; + } + num1++; + } +} /* ************************** Main ************************* */