vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
visibility_system.h
1#pragma once
2
3#include <cstdint>
4#include <vector>
5
6#include <glm/glm.hpp>
7#include <glm/gtc/quaternion.hpp>
8
9#include "core/system.h"
10#include "system/visibility/visibility.h"
11
12namespace Vkm::Engine {
13
14struct Camera;
15
25class VisibilitySystem : public System {
26 public:
29 static constexpr uint32_t FIXED_CHECK_STRIDE = 64;
30
31 public:
32 VisibilitySystem() = default;
33 ~VisibilitySystem() override = default;
34
35 VisibilitySystem(const VisibilitySystem& other) = delete;
36 VisibilitySystem& operator=(const VisibilitySystem& other) = delete;
37
38 VisibilitySystem(VisibilitySystem && other) = delete;
39 VisibilitySystem& operator=(VisibilitySystem && other) = delete;
40
41 public:
42 void update(FrameContext& ctx) override;
43
44 private:
51 struct ObjectSources {
52 uint64_t sceneEpoch = 0;
53 uint64_t assetEpoch = 0;
54 uint64_t meshAssets = 0;
55 uint64_t materialAssets = 0;
56 bool sea = false;
57 bool throughAnEye = false;
58
59 bool operator==(const ObjectSources& other) const {
60 return sceneEpoch == other.sceneEpoch && assetEpoch == other.assetEpoch
61 && meshAssets == other.meshAssets && materialAssets == other.materialAssets
62 && sea == other.sea && throughAnEye == other.throughAnEye;
63 }
64
65 bool operator!=(const ObjectSources& other) const { return !(*this == other); }
66 };
67
73 struct ObjectMemberships {
74 uint64_t transforms = 0;
75 uint64_t worldTransforms = 0;
76 uint64_t lods = 0;
77
78 bool operator==(const ObjectMemberships& other) const {
79 return transforms == other.transforms && worldTransforms == other.worldTransforms
80 && lods == other.lods;
81 }
82
83 bool operator!=(const ObjectMemberships& other) const { return !(*this == other); }
84 };
85
86 private:
99 bool resolveCamera(const FrameContext& ctx, float viewportAspect);
100
110 void publishCamera(
111 const Camera& camera,
112 const glm::vec3& position,
113 const glm::quat& rotation,
114 float viewportAspect,
115 EntityId entity
116 );
117
118 private:
119 EntityId m_cachedCameraEntity{};
120 uint64_t m_cameraEpoch = 0;
121 Visibility m_result;
122 bool m_noCameraLogged = false;
123
124 std::vector<uint8_t> m_state;
125
127 std::vector<uint8_t> m_fixed;
128 std::vector<uint64_t> m_stamps;
129
130 ObjectSources m_sources;
131 ObjectMemberships m_memberships;
132 bool m_sourcesValid = false;
133 uint32_t m_checkPhase = 0;
134 uint32_t m_lastTotal = 0;
135 uint64_t m_plantsRevision = 0;
136 uint32_t m_plantFirst = 0;
137 uint32_t m_plantCount = 0;
138
140 uint64_t m_fixedMovedEpoch = UINT64_MAX;
141};
142
143} // namespace Vkm::Engine
void update(FrameContext &ctx) override
Execute this system for the current frame.
static constexpr uint32_t FIXED_CHECK_STRIDE
Definition visibility_system.h:29
Component representing a camera, containing projection and view parameters.
Definition camera.h:25
Per-frame state bundle passed to every system.
Definition system.h:57