Cogs.Core
SeaCurrentsSystem.h
1#pragma once
2
3#include "SeaCurrentsComponent.h"
4
5#include "Resources/Resources.h"
6#include "Resources/MeshStreamsLayout.h"
7#include "Systems/ComponentSystem.h"
8#include "Scene/GetBounds.h"
9
10#include "Rendering/VertexFormat.h"
11#include "Foundation/Geometry/Glm.hpp"
12
13namespace Cogs {
14 namespace Core {
15 class Context;
16 class SeaCurrentsRenderer;
17 class SeaCurrentsSystem;
18
19 struct InstanceData {
20 glm::vec4 pos; // x,y = position. z = scale. w = angle.
21 uint32_t colour = 0;
22 };
23
25 class SeaCurrentsBounds final : public IGetBounds {
26 public:
27 explicit SeaCurrentsBounds(SeaCurrentsSystem* seaCurrentSystem) : seaCurrentSystem(seaCurrentSystem) {}
28
29 virtual void getBounds(Context* context, Cogs::Geometry::BoundingBox& bounds) override;
30 virtual bool getBounds(Context* context, const ComponentModel::Entity* entity, Cogs::Geometry::BoundingBox& bounds, bool ignoreVisibility) const override;
31
32 private:
33 SeaCurrentsSystem* seaCurrentSystem = nullptr;
34 };
35
37 SeaCurrentsSystem* mSystem = nullptr;
38 std::vector<InstanceData> mData;
39 BufferHandle mBufferHandle;
40 size_t mBufferSize = 0;
41 Cogs::Geometry::BoundingBox mBounds;
42 Cogs::Geometry::BoundingBox mTransformedBounds;
43 glm::mat4 mWorldMatrix;
44 };
45
49 class SeaCurrentsSystem : public ComponentSystemWithDataPool<SeaCurrentsComponent, SeaCurrentsData> {
51 public:
52 SeaCurrentsSystem(Memory::Allocator* allocator, SizeType capacity) : ComponentSystemWithDataPool(allocator, capacity) {}
53
54 float minScale = 0.2f; // The minimum speed related arrow scaling factor
55 float maxScale = 1.0f; // The maximum speed related arrow scaling factor
56 float lowestSpeed = 0.01f; // The lowest speed used for arrow scaling
57 float highestSpeed = 13.0f; // The highest speed used for arrow scaling
58
59 virtual void initialize(Context* context) override;
60 virtual void update(Context* /*context*/) override;
61 virtual void cleanup(Context* context) override;
62
63 virtual ComponentHandle createComponent() override;
64 virtual void destroyComponent(ComponentHandle component) override;
65
66 const MeshHandle& getArrowMesh() const { return mArrowMesh; }
67 const VertexFormat& getVertexFormat() const { return mVertexFormat; }
68 const VertexFormatHandle& getVertexFormatHandle() const { return mVertexFormatHandle; }
69 const MaterialInstanceHandle& getMaterialHandle() const { return mMaterial; }
70 const MeshStreamsLayout& getArrowInstancesStreamsLayout() const { return arrowInstancesStreamsLayout; }
71
73 Cogs::Geometry::BoundingBox getWorldBounds(const SeaCurrentsComponent& seaCurrentsComponent, bool ignoreVisibility) const;
74
75 private:
76 MeshStreamsLayout arrowInstancesStreamsLayout;
77 MeshHandle mArrowMesh;
78 VertexFormat mVertexFormat = {};
79 VertexFormatHandle mVertexFormatHandle;
80 MaterialInstanceHandle mMaterial;
81 SeaCurrentsRenderer* mRenderer = nullptr;
82 std::unique_ptr<SeaCurrentsBounds> bounds;
83 };
84 }
85}
Container for components, providing composition of dynamic entities.
Definition: Entity.h:18
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
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
Needs custom bounds calculation.
virtual void getBounds(Context *context, Cogs::Geometry::BoundingBox &bounds) override
Expand bounds including bounds of all entities in this system in world coordinates.
The sea currents system manages and displays sea currents per the S-111 specification.
virtual void destroyComponent(ComponentHandle component) override
Cogs::Geometry::BoundingBox getWorldBounds(const SeaCurrentsComponent &seaCurrentsComponent, bool ignoreVisibility) const
Used by SeaCurrentsBounds::getBounds.
virtual void initialize(Context *context) override
Initialize the system.
virtual void cleanup(Context *context) override
Provided for custom cleanup logic in derived systems.
virtual ComponentHandle createComponent() override
Base allocator implementation.
Definition: Allocator.h:30
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
ComponentIndex SizeType
Type used to track the size of pools.
Definition: Component.h:19
Handle to a Component instance.
Definition: Component.h:67
Component for displaying surface currents based on the IHO S111 standard.
Vertex format structure used to describe a single vertex for the input assembler.
Definition: VertexFormat.h:60