-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackgroundTracer.cpp
43 lines (38 loc) · 943 Bytes
/
BackgroundTracer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "BackgroundTracer.hpp"
#include "Assert.hpp"
#include "Scene.hpp"
BackgroundTracer::BackgroundTracer(const RayTracer::Config& config)
: running(false)
, engine(config)
, canvas(config.width, config.height, Image::FORMAT_ARGB)
{
}
BackgroundTracer::~BackgroundTracer()
{
running = false;
engine.cancel();
if (thread.joinable()) { thread.join(); }
}
void BackgroundTracer::startTrace(const Scene& scene, const Camera& camera)
{
ASSERT(this->scene == nullptr);
this->scene.reset(new Scene(scene));
this->camera.reset(new Camera(camera));
if (!running)
{
if (thread.joinable()) { thread.join(); }
running = true;
thread = std::thread(threadRunner, this);
}
}
void BackgroundTracer::traceAsync()
{
std::this_thread::yield();
if (scene)
{
engine.trace(*scene, *camera, &canvas);
scene.reset();
camera.reset();
}
running = false;
}