BSPParser
Simple and modern library for parsing the Valve BSP format
Loading...
Searching...
No Matches
sub-edge-iterator.hpp
1#pragma once
2
3// Ripped straight from https://github.com/ValveSoftware/source-sdk-2013/blob/master/sp/src/public/disp_common.h#L48
4
5#include "./triangulated-displacement.hpp"
6
7namespace BspParser::Internal {
8 struct VertexCoordinate {
9 enum class Axis : uint8_t { X, Y };
10
11 int32_t x = 0;
12 int32_t y = 0;
13
14 int32_t& operator[](const Axis axis) {
15 return axis == Axis::X ? x : y;
16 }
17
18 const int32_t& operator[](const Axis axis) const {
19 return axis == Axis::X ? x : y;
20 }
21 };
22
23 class SubEdgeIterator {
24 public:
25 SubEdgeIterator(
26 const TriangulatedDisplacement& displacement,
27 const Structs::DispSubNeighbour& subNeighbour,
28 const TriangulatedDisplacement& neighbour,
29 int32_t edgeIndex,
30 int32_t subNeighbourIndex,
31 bool shouldTouchCorners = false
32 );
33
34 bool next();
35
36 [[nodiscard]] const VertexCoordinate& getVertexCoordinate() const;
37 [[nodiscard]] int32_t getVertexIndex() const;
38 [[nodiscard]] int32_t getNeighbourVertexIndex() const;
39
40 [[nodiscard]] bool isLastVertex() const;
41
42 [[nodiscard]] VertexCoordinate::Axis getFreeAxis() const;
43
44 private:
45 const TriangulatedDisplacement* displacement = nullptr;
46 const TriangulatedDisplacement* neighbour = nullptr;
47
48 uint8_t neighbourOrientation = 0;
49
50 uint8_t span = 0;
51 uint8_t neighbourSpan = 0;
52
53 VertexCoordinate coordinate{};
54 VertexCoordinate increment{};
55
56 VertexCoordinate neighbourCoordinate{};
57 VertexCoordinate neighbourIncrement{};
58
59 int32_t end = 0;
60 VertexCoordinate::Axis freeAxis = VertexCoordinate::Axis::X;
61 VertexCoordinate::Axis neighbourFreeAxis = VertexCoordinate::Axis::X;
62
63 void setupEdgeIncrements(int32_t edgeIndex, int32_t subNeighbourIndex);
64 [[nodiscard]] VertexCoordinate transformIntoSubNeighbour(int32_t edgeIndex, const VertexCoordinate& toTransform);
65 };
66}