2015-08-23 18:22:37 +00:00
|
|
|
#include "RenderProgress.h"
|
|
|
|
|
|
|
|
#include "Mutex.h"
|
2015-09-13 20:38:44 +00:00
|
|
|
#include "Time.h"
|
|
|
|
#include "Logs.h"
|
2015-08-23 18:22:37 +00:00
|
|
|
|
|
|
|
RenderProgress::RenderProgress(int count)
|
|
|
|
{
|
|
|
|
lock = new Mutex();
|
|
|
|
global = 0.0;
|
|
|
|
step = 1.0 / (double)count;
|
2015-09-13 20:38:44 +00:00
|
|
|
start_time = Time::getRelativeTimeMs();
|
|
|
|
end_time = 0;
|
2015-08-23 18:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
paysages::software::RenderProgress::~RenderProgress()
|
|
|
|
{
|
|
|
|
delete lock;
|
|
|
|
}
|
|
|
|
|
2015-09-09 22:40:47 +00:00
|
|
|
void RenderProgress::reset()
|
|
|
|
{
|
|
|
|
lock->acquire();
|
|
|
|
|
|
|
|
global = 0.0;
|
|
|
|
while (not subs.empty())
|
|
|
|
{
|
|
|
|
subs.pop();
|
|
|
|
}
|
|
|
|
|
2015-09-13 20:38:44 +00:00
|
|
|
start_time = Time::getRelativeTimeMs();
|
|
|
|
|
2015-09-09 22:40:47 +00:00
|
|
|
lock->release();
|
|
|
|
}
|
|
|
|
|
2015-08-23 18:22:37 +00:00
|
|
|
void RenderProgress::add(int value)
|
|
|
|
{
|
|
|
|
lock->acquire();
|
|
|
|
|
|
|
|
global += step * (double)value;
|
|
|
|
|
|
|
|
lock->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderProgress::enterSub(int count)
|
|
|
|
{
|
|
|
|
struct RenderSub sub;
|
|
|
|
sub.start = global;
|
|
|
|
sub.end = global + step;
|
|
|
|
sub.count = count;
|
|
|
|
sub.previous_step = step;
|
|
|
|
|
|
|
|
lock->acquire();
|
|
|
|
|
|
|
|
subs.push(sub);
|
|
|
|
step /= (double)count;
|
|
|
|
|
|
|
|
lock->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderProgress::exitSub()
|
|
|
|
{
|
|
|
|
lock->acquire();
|
|
|
|
|
|
|
|
struct RenderSub sub = subs.top();
|
|
|
|
|
|
|
|
global = sub.end;
|
|
|
|
step = sub.previous_step;
|
|
|
|
|
|
|
|
subs.pop();
|
|
|
|
|
|
|
|
lock->release();
|
|
|
|
}
|
2015-09-13 20:38:44 +00:00
|
|
|
|
|
|
|
void RenderProgress::end()
|
|
|
|
{
|
|
|
|
if (subs.size() > 0)
|
|
|
|
{
|
|
|
|
Logs::error() << subs.size() << " progress subs remaining at the end of render" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
end_time = Time::getRelativeTimeMs();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long RenderProgress::getDuration() const
|
|
|
|
{
|
|
|
|
if (end_time)
|
|
|
|
{
|
|
|
|
return end_time - start_time;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Time::getRelativeTimeMs() - start_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long RenderProgress::estimateRemainingTime() const
|
|
|
|
{
|
|
|
|
if (global < 0.00001)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned long done = getDuration();
|
|
|
|
unsigned long total = (unsigned long)((double)done / global);
|
|
|
|
return total - done;
|
|
|
|
}
|
|
|
|
}
|