2017-03-01 01:46:03 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-03-07 23:34:08 +00:00
|
|
|
#include "vectors.h"
|
2017-03-07 14:58:22 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2017-03-01 01:46:03 +00:00
|
|
|
struct GPUNode
|
|
|
|
{
|
2017-03-07 14:58:22 +00:00
|
|
|
GPUNode(const FVector2 &aabb_min, const FVector2 &aabb_max, int line_index) : aabb_left(aabb_min.X), aabb_top(aabb_min.Y), aabb_right(aabb_max.X), aabb_bottom(aabb_max.Y), left(-1), right(-1), line_index(line_index) { }
|
|
|
|
GPUNode(const FVector2 &aabb_min, const FVector2 &aabb_max, int left, int right) : aabb_left(aabb_min.X), aabb_top(aabb_min.Y), aabb_right(aabb_max.X), aabb_bottom(aabb_max.Y), left(left), right(right), line_index(-1) { }
|
|
|
|
|
|
|
|
float aabb_left, aabb_top;
|
|
|
|
float aabb_right, aabb_bottom;
|
|
|
|
int left;
|
|
|
|
int right;
|
|
|
|
int line_index;
|
|
|
|
int padding;
|
2017-03-01 01:46:03 +00:00
|
|
|
};
|
|
|
|
|
2017-03-07 14:58:22 +00:00
|
|
|
struct GPULine
|
2017-03-01 01:46:03 +00:00
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
float dx, dy;
|
2017-03-07 14:58:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Level2DShape
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Level2DShape();
|
|
|
|
|
|
|
|
TArray<GPUNode> nodes;
|
2017-03-07 23:34:08 +00:00
|
|
|
TArray<GPULine> lines;
|
2017-03-07 14:58:22 +00:00
|
|
|
int root;
|
|
|
|
|
2017-03-07 23:34:08 +00:00
|
|
|
double RayTest(const DVector3 &ray_start, const DVector3 &ray_end);
|
|
|
|
|
2017-03-07 14:58:22 +00:00
|
|
|
private:
|
2017-03-07 23:34:08 +00:00
|
|
|
bool OverlapRayAABB(const DVector2 &ray_start2d, const DVector2 &ray_end2d, const GPUNode &node);
|
|
|
|
double IntersectRayLine(const DVector2 &ray_start, const DVector2 &ray_end, int line_index, const DVector2 &raydelta, double rayd, double raydist2);
|
|
|
|
|
|
|
|
int Subdivide(int *lines, int num_lines, const FVector2 *centroids, int *work_buffer);
|
2017-03-01 01:46:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FLightBSP
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FLightBSP() { }
|
|
|
|
~FLightBSP() { Clear(); }
|
|
|
|
|
|
|
|
int GetNodesBuffer();
|
2017-03-07 14:58:22 +00:00
|
|
|
int GetLinesBuffer();
|
2017-03-01 01:46:03 +00:00
|
|
|
void Clear();
|
|
|
|
|
2017-03-07 23:34:08 +00:00
|
|
|
bool ShadowTest(const DVector3 &light, const DVector3 &pos);
|
|
|
|
|
2017-03-01 01:46:03 +00:00
|
|
|
private:
|
|
|
|
void UpdateBuffers();
|
|
|
|
void GenerateBuffers();
|
|
|
|
void UploadNodes();
|
|
|
|
void UploadSegs();
|
|
|
|
|
|
|
|
FLightBSP(const FLightBSP &) = delete;
|
|
|
|
FLightBSP &operator=(FLightBSP &) = delete;
|
|
|
|
|
|
|
|
int NodesBuffer = 0;
|
2017-03-07 14:58:22 +00:00
|
|
|
int LinesBuffer = 0;
|
2017-03-01 01:46:03 +00:00
|
|
|
int NumNodes = 0;
|
|
|
|
int NumSegs = 0;
|
2017-03-07 14:58:22 +00:00
|
|
|
|
|
|
|
std::unique_ptr<Level2DShape> Shape;
|
2017-03-01 01:46:03 +00:00
|
|
|
};
|