mirror of
https://github.com/ZDoom/ZDRay.git
synced 2025-01-24 00:31:07 +00:00
Remove worker class
This commit is contained in:
parent
e61f10af24
commit
955632f1f8
6 changed files with 34 additions and 50 deletions
|
@ -156,7 +156,6 @@ set( SOURCES
|
|||
src/nodebuilder/nodebuild_classify_nosse2.cpp
|
||||
src/lightmap/pngwriter.cpp
|
||||
src/lightmap/surfaces.cpp
|
||||
src/lightmap/worker.cpp
|
||||
src/lightmap/collision.cpp
|
||||
src/lightmap/delauneytriangulator.cpp
|
||||
src/lightmap/delauneytriangulator.h
|
||||
|
@ -216,7 +215,6 @@ set( HEADERS
|
|||
src/framework/binfile.h
|
||||
src/lightmap/pngwriter.h
|
||||
src/lightmap/surfaces.h
|
||||
src/lightmap/worker.h
|
||||
src/lightmap/collision.h
|
||||
src/math/mat.h
|
||||
src/math/quaternion.h
|
||||
|
|
|
@ -3,16 +3,17 @@
|
|||
#include "surfaces.h"
|
||||
#include "level/level.h"
|
||||
#include "cpuraytracer.h"
|
||||
#include "worker.h"
|
||||
#include "framework/binfile.h"
|
||||
#include "framework/templates.h"
|
||||
#include "framework/halffloat.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
#include <zlib.h>
|
||||
|
||||
extern bool VKDebug;
|
||||
extern int NumThreads;
|
||||
|
||||
CPURaytracer::CPURaytracer()
|
||||
{
|
||||
|
@ -60,7 +61,7 @@ void CPURaytracer::Raytrace(LevelMesh* level)
|
|||
|
||||
printf("Ray tracing with %d bounce(s)\n", mesh->map->LightBounce);
|
||||
|
||||
Worker::RunJob((int)tasks.size(), [=](int id) { RaytraceTask(tasks[id]); });
|
||||
RunJob((int)tasks.size(), [=](int id) { RaytraceTask(tasks[id]); });
|
||||
|
||||
printf("\nRaytrace complete\n");
|
||||
}
|
||||
|
@ -480,3 +481,30 @@ bool CPURaytracer::TraceAnyHit(const vec3& startVec, const vec3& endVec)
|
|||
{
|
||||
return TriangleMeshShape::find_any_hit(CollisionMesh.get(), startVec, endVec);
|
||||
}
|
||||
|
||||
void CPURaytracer::RunJob(int count, std::function<void(int)> callback)
|
||||
{
|
||||
int numThreads = NumThreads;
|
||||
if (numThreads <= 0)
|
||||
numThreads = std::thread::hardware_concurrency();
|
||||
if (numThreads <= 0)
|
||||
numThreads = 4;
|
||||
|
||||
numThreads = std::min(numThreads, count);
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
for (int threadIndex = 0; threadIndex < numThreads; threadIndex++)
|
||||
{
|
||||
threads.push_back(std::thread([=]() {
|
||||
|
||||
for (int i = threadIndex; i < count; i += numThreads)
|
||||
{
|
||||
callback(i);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < numThreads; i++)
|
||||
threads[i].join();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
class LevelMesh;
|
||||
|
||||
struct CPUTraceTask
|
||||
|
@ -87,6 +89,8 @@ private:
|
|||
static float RadicalInverse_VdC(uint32_t bits);
|
||||
static vec2 Hammersley(uint32_t i, uint32_t N);
|
||||
|
||||
static void RunJob(int count, std::function<void(int i)> callback);
|
||||
|
||||
const int coverageSampleCount = 256;
|
||||
const int bounceSampleCount = 2048;
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "surfaces.h"
|
||||
#include "level/level.h"
|
||||
#include "gpuraytracer.h"
|
||||
#include "worker.h"
|
||||
#include "framework/binfile.h"
|
||||
#include "framework/templates.h"
|
||||
#include "framework/halffloat.h"
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
|
||||
#include "worker.h"
|
||||
#include "math/mathlib.h"
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <algorithm>
|
||||
|
||||
extern int NumThreads;
|
||||
|
||||
void Worker::RunJob(int count, std::function<void(int)> callback)
|
||||
{
|
||||
int numThreads = NumThreads;
|
||||
if (numThreads <= 0)
|
||||
numThreads = std::thread::hardware_concurrency();
|
||||
if (numThreads <= 0)
|
||||
numThreads = 4;
|
||||
|
||||
numThreads = std::min(numThreads, count);
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
for (int threadIndex = 0; threadIndex < numThreads; threadIndex++)
|
||||
{
|
||||
threads.push_back(std::thread([=]() {
|
||||
|
||||
for (int i = threadIndex; i < count; i += numThreads)
|
||||
{
|
||||
callback(i);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < numThreads; i++)
|
||||
threads[i].join();
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
class Worker
|
||||
{
|
||||
public:
|
||||
static void RunJob(int count, std::function<void(int i)> callback);
|
||||
};
|
Loading…
Reference in a new issue