Cogs.Core
OctProviderSystem.h
1#pragma once
2
3#include "EntityDefinition.h"
4#include "Scene/GetBounds.h"
5#include "Systems/ComponentSystem.h"
6
7#include "../Components/OctProviderComponent.h"
8#include "../Systems/DataSetSystem.h"
9
10#include "Rendering/Common.h"
11
12#include "Foundation/Memory/MemoryBuffer.h"
13
14#include <unordered_map>
15#include <memory.h>
16#include <glm/glm.hpp>
17
18namespace Cogs
19{
20 namespace Core
21 {
22 namespace Volumetric
23 {
24 struct TileResponse;
25 }
26
27 namespace EchoSounder
28 {
29
30 inline uint64_t encodeKey2(const uint32_t source, const uint32_t slice)
31 {
32 return (uint64_t(source) << 32u) | uint64_t(slice);
33 }
34
35
36 inline void decodeKey2(uint32_t& source, uint32_t& slice, const uint64_t regionKey)
37 {
38 source = uint32_t(regionKey >> 32u);
39 slice = uint32_t(regionKey);
40 }
41
42
44 {
45 int64_t timestamp = 0;
46 PingMetaData metaPing;
47 uint32_t beamCount = 0;
48 uint32_t sampleCount = 0;
49 float depthOffset = 0;
50 float depthStep = 0;
51 glm::vec3 transducerAlpha;
52 glm::vec3 transducerOffset;
53
54 uint32_t age = 0;
55 bool linearized = false;
58 Memory::TypedBuffer<float> bottomDepths;
59
60 };
61
63 {
64 uint32_t dataId = 0;
65 uint32_t majorCount = 0;
66 uint32_t minorCount = 0;
67 std::vector<float> directionX;
68 std::vector<float> directionY;
69 float minDirectionX = 0.0f;
70 float maxDirectionX = 0.0f;
71 float minDirectionY = 0.0f;
72 float maxDirectionY = 0.0f;
73 float maxBeamWidthX = 0.0f;
74 float maxBeamWidthY = 0.0f;
75 };
76
77
81 {
82 Context * context = nullptr;
83
85 std::vector<unsigned> taskCount;
86
88 std::vector<Volumetric::TileResponse*> responses;
89
91 std::vector<CachedBeamGroup> groupCache;
92
94 std::unordered_map<uint64_t, std::unique_ptr<CachedPing>> pingCache;
95 std::vector<std::unique_ptr<CachedPing>> pingCacheUnused;
96
98 std::vector<CachedPing*> needsLinearization;
99
101 bool tasksRunning = false;
102
104 bool tainted = false;
105 };
106
108 {
109 EntityPtr entity;
110 uint32_t grpGen = 0;
111 uint32_t dataGen = 0;
112 uint32_t sliceBegin = 0;
113 uint32_t sliceCount = 0;
114 bool sane = false;
115 };
116
117
119 {
120 uint64_t mostRecentTimestamp = 0;
121
122 unsigned history = 1;
123 std::shared_ptr<OctProviderPersistent> persistent;
124
125 std::vector<OctProviderSource> sources;
126 unsigned callbackCount = 0;
127
128 bool doFlush = true;
129 };
130
132 : public ComponentSystemWithDataPool<OctProviderComponent, OctProviderData>
133 {
134 OctProviderSystem(Memory::Allocator * allocator, SizeType capacity) : ComponentSystemWithDataPool(allocator, capacity) {}
135
136 void callback(Context* context, OctProviderComponent * comp);
137
138 static float alphaCallback(void* data, uint64_t clientData);
139
140 void preUpdate(Context * context) override;
141
142 void update(Context * context) override;
143 };
144
145 }
146 }
147}
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
void preUpdate()
Run the pre-update method of the system.
Component system with parallel data per component stored in a pool similar to how the components them...
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Base allocator implementation.
Definition: Allocator.h:30
std::shared_ptr< ComponentModel::Entity > EntityPtr
Smart pointer for Entity access.
Definition: EntityPtr.h:12
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
ComponentIndex SizeType
Type used to track the size of pools.
Definition: Component.h:19
std::vector< unsigned > taskCount
Number of tasks to split each request into.
std::vector< CachedBeamGroup > groupCache
Beam group data cached while tile builder task is running.
std::unordered_map< uint64_t, std::unique_ptr< CachedPing > > pingCache
Cache of beam data for both while tile builder is running, and between runs to avoid re-copying and r...
bool tainted
True if the groups or data have changed to an extent that responses in flight and all cached data mus...
std::vector< CachedPing * > needsLinearization
List of new pings that must be linearized next time tile builder runs.
bool tasksRunning
True if the tile builder is running.
std::vector< Volumetric::TileResponse * > responses
List of responses to be processed by tile builder.