2#include "EntityStore.h"
3#include "Components/Core/MeshComponent.h"
4#include "Components/Core/SubMeshRenderComponent.h"
5#include "Systems/Core/TransformSystem.h"
6#include "Resources/MeshManager.h"
7#include "Resources/MaterialManager.h"
8#include "Services/TaskManager.h"
10#include "../Components/DataSetComponent.h"
11#include "../Components/DataRefComponent.h"
12#include "../Components/LocationComponent.h"
13#include "../Components/BeamGroupComponent.h"
15#include "../Systems/DataSetSystem.h"
16#include "../Tasks/SinglePingIsoSurfacesTasks.h"
17#include "PingIsoSystem.h"
20#include "Foundation/Logging/Logger.h"
28using namespace Cogs::Core::EchoSounder;
33 surfaceMaterial =
context->materialManager->loadMaterial(
"ParametricGrid.material");
34 context->materialManager->processLoading();
35 rangeKey = surfaceMaterial->getVec4Key(
"range");
36 opacityKey = surfaceMaterial->getFloatKey(
"opacity");
41 bool activateMeshes =
false;
42 for (
auto & isoComp :
pool) {
43 auto & isoData = getData(&isoComp);
47 if (!getDataSet(&dataComp, &dataData, isoComp, dataSetSystem)) {
49 isoData.dataComp =
nullptr;
53 if (!groupComp || !groupComp->sane) {
59 if (isoData.dataComp != dataComp) {
60 isoData.dataComp = dataComp;
61 isoData.reIssue =
true;
65 if (isoData.index != locComp->index) {
66 isoData.index = locComp->index;
67 isoData.reIssue =
true;
71 isoData.reIssue =
true;
74 bool updateMaterials = isoComp.hasChanged();
77 if (!isoData.reIssue) {
78 if (isoComp.hasChanged()) {
79 const Reflection::FieldId firstNonTriggeringField = isoComp.getType().getFieldId(&PingIsoComponent::material);
81 if (isoComp.hasFieldChanged(fieldId)) {
82 isoData.reIssue =
true;
87 if (groupComp->hasChanged()) {
88 isoData.reIssue =
true;
92 bool tasksAreRunning = isoData.persistent->runningTasks > 0;
93 bool triggerUpdate =
false;
95 if (!tasksAreRunning) {
98 if (isoData.persistent->issuedMesh) {
99 if (isoData.persistent->issuedMesh->isActive()) {
101 meshComp->
meshHandle = isoData.persistent->issuedMesh;
102 meshComp->setChanged();
105 trComp->
position = isoData.persistent->issuedPosition;
106 trComp->rotation = isoData.persistent->issuedOrientation;
107 trComp->setChanged();
111 while (isoData.layerMaterialInstances.size() < isoData.thresholds.size()) {
112 isoData.layerMaterialInstances.push_back(
context->materialInstanceManager->createMaterialInstance(surfaceMaterial));
114 isoData.layerMaterialInstances.resize(isoData.thresholds.size());
117 mshRndCmp->
materials.resize(isoData.layerMaterialInstances.size());
118 for (
size_t i = 0; i < isoData.layerMaterialInstances.size(); i++) {
119 mshRndCmp->materials[i] = isoData.layerMaterialInstances[i];
121 mshRndCmp->setChanged();
123 updateMaterials =
true;
124 activateMeshes =
true;
128 triggerUpdate =
true;
133 if (isoData.reIssue) {
136 if (16 < isoComp.thresholds.size()) {
137 isoComp.thresholds.resize(16);
139 isoData.thresholds = isoComp.thresholds;
140 isoData.seabedClipOffset = isoComp.seabedClipOffset;
142 isoData.persistent->runningTasks++;
148 dataComp, dataData));
151 isoData.reIssue =
false;
152 triggerUpdate =
true;
158 if (updateMaterials && isoComp.material) {
159 for (
size_t i = 0; i < isoData.layerMaterialInstances.size(); i++) {
160 isoData.layerMaterialInstances[i]->clone(isoComp.material.resolve());
162 if (isoComp.innerLayerOpaque && i + 1 == isoData.layerMaterialInstances.size()) {
163 isoData.layerMaterialInstances[i]->setOpaque();
166 isoData.layerMaterialInstances[i]->setTransparent();
168 isoData.layerMaterialInstances[i]->setVec4Property(rangeKey, glm::vec4(0, 1, 0, 1));
169 isoData.layerMaterialInstances[i]->setFloatProperty(opacityKey, isoComp.opacity);
170 isoData.layerMaterialInstances[i]->options.depthBiasEnabled =
true;
171 isoData.layerMaterialInstances[i]->options.depthBias.slope = 0.f;
172 isoData.layerMaterialInstances[i]->options.depthBias.constant = i*isoComp.layerDepthBiasStep;
173 isoData.layerMaterialInstances[i]->options.depthBias.clamp = 100000.f;
177 if (tasksAreRunning || triggerUpdate) {
182 if (activateMeshes) {
void setChanged()
Sets the component to the ComponentFlags::Changed state with carry.
ComponentType * getComponent() const
virtual void cleanup(Context *)
Provided for custom cleanup logic in derived systems.
Context * context
Pointer to the Context instance the system lives in.
virtual void initialize(Context *context)
Initialize the system.
void update()
Updates the system state to that of the current frame.
ComponentPool< ComponentType > pool
Pool of components managed by the system.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
std::unique_ptr< class TaskManager > taskManager
TaskManager service instance.
std::unique_ptr< class Engine > engine
Engine instance.
Contains a handle to a Mesh resource to use when rendering using the MeshRenderComponent.
MeshHandle meshHandle
Handle to a Mesh resource to use when rendering.
Renders a mesh with flexible submesh usage.
std::vector< MaterialInstanceHandle > materials
Materials used to render individual sub-meshes.
Log implementation class.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
uint16_t FieldId
Type used to index fields.
void cleanup(Context *context) override
Provided for custom cleanup logic in derived systems.
void initialize(Context *context) override
Initialize the system.
static const ResourceHandle_t NoHandle
Handle representing a default (or none if default not present) resource.