Improved estimated rendering time

This commit is contained in:
Michaël Lemaire 2015-11-02 23:39:34 +01:00
parent ca7bd84308
commit dc27590496
4 changed files with 32 additions and 10 deletions

2
.gitignore vendored
View file

@ -24,3 +24,5 @@ ui_*.h
/paysages3d-linux.tar.bz2 /paysages3d-linux.tar.bz2
/config.vim /config.vim
/callgrind.out.* /callgrind.out.*
*.p3d

View file

@ -211,9 +211,9 @@ void RenderProcess::timerEvent(QTimerEvent *)
if (rendering) if (rendering)
{ {
unsigned long remaining = renderer->getProgressHelper()->estimateRemainingTime(); unsigned long remaining = renderer->getProgressHelper()->estimateRemainingTime();
if (remaining > 10000) if (remaining > 0)
{ {
t = QTime(0, 0, 0).addMSecs(remaining); t = QTime(0, 0, 0).addMSecs(999 + remaining);
info += " - Remaining: ~" + t.toString("hh:mm:ss"); info += " - Remaining: ~" + t.toString("hh:mm:ss");
} }
} }

View file

@ -9,8 +9,9 @@ RenderProgress::RenderProgress(int count)
lock = new Mutex(); lock = new Mutex();
global = 0.0; global = 0.0;
step = 1.0 / (double)count; step = 1.0 / (double)count;
start_time = Time::getRelativeTimeMs(); start_time = 0;
end_time = 0; end_time = 0;
reset();
} }
paysages::software::RenderProgress::~RenderProgress() paysages::software::RenderProgress::~RenderProgress()
@ -30,6 +31,10 @@ void RenderProgress::reset()
start_time = Time::getRelativeTimeMs(); start_time = Time::getRelativeTimeMs();
prev_est_spent = 0;
prev_est_done = 0.0;
prev_est_speed = 0.0;
lock->release(); lock->release();
} }
@ -94,16 +99,24 @@ unsigned long RenderProgress::getDuration() const
} }
} }
unsigned long RenderProgress::estimateRemainingTime() const unsigned long RenderProgress::estimateRemainingTime()
{ {
if (global < 0.00001) unsigned long spent = getDuration();
double speed = (global - prev_est_done) / (double)(spent - prev_est_spent);
prev_est_speed = prev_est_speed ? (prev_est_speed * 0.8 + speed * 0.2) : speed;
if (spent - prev_est_spent > 5000)
{ {
return 0; prev_est_spent = spent;
prev_est_done = global;
}
if (prev_est_speed > 0.0000000001)
{
return (unsigned long)((1.0 - global) / prev_est_speed);
} }
else else
{ {
unsigned long done = getDuration(); return 0;
unsigned long total = (unsigned long)((double)done / global);
return total - done;
} }
} }

View file

@ -42,14 +42,21 @@ public:
* *
* Returns 0 if unknown. * Returns 0 if unknown.
*/ */
unsigned long estimateRemainingTime() const; unsigned long estimateRemainingTime();
private: private:
Mutex *lock; Mutex *lock;
double global; double global;
double step; double step;
unsigned long start_time; unsigned long start_time;
unsigned long end_time; unsigned long end_time;
unsigned long prev_est_spent;
double prev_est_done;
double prev_est_speed;
std::stack<RenderSub> subs; std::stack<RenderSub> subs;
}; };