Toast Engine
Loading...
Searching...
No Matches
voxel_change_history.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
7#include "frustum.hpp"
8
9#include <algorithm>
10#include <cstdint>
11#include <functional>
12#include <glm/glm.hpp>
13#include <iterator>
14#include <memory>
15#include <optional>
16#include <span>
18#include <vector>
19
20namespace renderer {
21
24 uint64_t node_rid = 0;
25 glm::vec3 min {0.0f};
26 glm::vec3 max {0.0f};
27};
28
31public:
32 struct Entry {
33 uint64_t generation = 0;
34 std::shared_ptr<const std::vector<VoxelRegion>> regions;
35 };
36
37 static constexpr size_t k_max_entries = 32;
38
39 [[nodiscard]]
40 static auto extend(const VoxelChangeHistory& previous, uint64_t generation, std::vector<VoxelRegion> regions)
42
44 template<typename Visit>
45 auto forEachSince(uint64_t generation, Visit&& visit) const -> bool {
46 const auto known = std::ranges::find(m_entries, generation, &Entry::generation);
47 if (known == m_entries.end()) {
48 return false;
49 }
50 for (auto entry = std::next(known); entry != m_entries.end(); ++entry) {
51 for (const VoxelRegion& region : *entry->regions) {
52 visit(region);
53 }
54 }
55 return true;
56 }
57
58private:
59 std::vector<Entry> m_entries;
60};
61
63 uint64_t node_rid = 0;
64 const voxel::Volume* volume = nullptr;
65};
66
68using PublishedDims = std::function<std::optional<glm::uvec3>(uint64_t)>;
69
72 uint64_t node_rid = 0;
73
75 bool unknown = false;
76
78 std::vector<uint32_t> bricks;
79};
80
83public:
85 void observe(
86 std::span<const TrackedVolume> volumes, const PublishedDims& published_dims, std::vector<VolumeDelta>* deltas = nullptr
87 );
88
90 auto packed(uint64_t generation) -> VoxelChangeHistory;
91
93 void published();
94
95 void reset();
96
97private:
98 struct Seen {
99 uint64_t node_rid = 0;
100 uint64_t volume_id = 0;
101 uint32_t content = 0;
102 };
103
104 std::vector<Seen> m_seen;
105 VoxelChangeHistory m_published;
106 VoxelChangeHistory m_pending;
107 std::vector<VoxelRegion> m_unpublished;
108 bool m_has_pending = false;
109};
110
112 uint64_t node_rid = 0;
113 glm::mat4 model {1.0f};
114};
115
117[[nodiscard]]
118auto regionsReach(
119 const VoxelChangeHistory& history, uint64_t generation, std::span<const VoxelCaster> casters,
120 std::span<const FrustumPlanes> views
121) -> bool;
122
123}
Regions each published voxel storage brought oldest first.
Definition voxel_change_history.hpp:30
auto forEachSince(uint64_t generation, Visit &&visit) const -> bool
Definition voxel_change_history.hpp:45
Finds what changed in each volume between packs and keeps it until a storage carrying it is published...
Definition voxel_change_history.hpp:82
void observe(std::span< const TrackedVolume > volumes, const PublishedDims &published_dims, std::vector< VolumeDelta > *deltas=nullptr)
Call with the voxel lock held since it reads and then discards the dirty bricks of every volume.
Definition voxel_change_history.cpp:96
void published()
The storage from the last packed() is now the one frames use.
Definition voxel_change_history.cpp:154
auto packed(uint64_t generation) -> VoxelChangeHistory
Definition voxel_change_history.cpp:144
Definition voxel_volume.hpp:21
Definition voxel_change_history.hpp:62
What one volume changed since the observe before.
Definition voxel_change_history.hpp:71
bool unknown
New or replaced or its history was discarded so only a full pack describes it.
Definition voxel_change_history.hpp:75
std::vector< uint32_t > bricks
Grid indices of the bricks written.
Definition voxel_change_history.hpp:78
Definition voxel_change_history.hpp:111
Definition voxel_change_history.hpp:32
A box that changed in the voxel space of one volume.
Definition voxel_change_history.hpp:23
auto regionsReach(const VoxelChangeHistory &history, uint64_t generation, std::span< const VoxelCaster > casters, std::span< const FrustumPlanes > views) -> bool
True when a region published after generation reaches one of the views or when that generation is gon...
Definition voxel_change_history.cpp:172
std::function< std::optional< glm::uvec3 >(uint64_t)> PublishedDims
Brick dims of a volume in the storage frames use or nullopt when it is not in there.
Definition voxel_change_history.hpp:68