Cogs.Core
TerrainSystem.h
1#pragma once
2
3#include "Systems/ComponentSystem.h"
4
5#include "TerrainComponent.h"
6#include "Resources/Resources.h"
7#include "Resources/MeshStreamsLayout.h"
8#include "Scene/RayPick.h"
9#include "Scene/GetBounds.h"
10
11#include "RenderContext.h"
12#include "Rendering/VertexFormat.h"
13
14namespace Cogs
15{
16 struct TerrainContext;
17
18 namespace Core
19 {
20 struct TerrainData;
21 class TerrainSystem;
22
24 {
25 public:
26 TerrainPicker(TerrainSystem* terrainSystem) : terrainSystem(terrainSystem) {}
27
28 bool pickCamera(Context* context,
29 const CameraComponent& camera,
30 const glm::vec2& normPosition,
31 float /*rayLength*/,
32 float /*radius*/,
33 PickingFlags pickingFlags,
34 PicksReturned returnFlag,
35 const RayPicking::RayPickFilter& filter,
36 std::vector<RayPicking::RayPickHit>& hits) override;
37
38 TerrainSystem* terrainSystem = nullptr;
39 };
40
42 {
43 public:
44 TerrainBounds(TerrainComponent * terrain, TerrainData * terrainData) : terrain(terrain), terrainData(terrainData) {}
45
46 void getBounds(Context * context, Cogs::Geometry::BoundingBox & bounds, float& nearPlaneLimit) final;
47
48 void getBounds(Context* context, Cogs::Geometry::BoundingBox& bounds) final { float ignored = 0.f; getBounds(context, bounds, ignored); }
49
50 private:
51 TerrainComponent * terrain;
52 TerrainData * terrainData;
53 };
54
56 {
57 TerrainData() = default;
58 TerrainData(const TerrainData &) = delete;
59
60 bool initialized = false;
61 bool visible = true;
62
63 glm::dvec3 offset;
64
65 TerrainContext * context = nullptr;
66
67 int maxTilesPerFrame = 16;
68
69 RenderContext renderContext;
70
71 MeshStreamsLayout terrainStreamsLayout;
72
74 MaterialInstanceHandle depthMaterial;
75
76 std::string customComputeColor;
77
78 std::unique_ptr<TerrainBounds> getBounds;
79
80 Geometry::BoundingBox bbox;
81
82 float nearPlaneLimit = 0.0f;
83
84 struct OceanData * oceanData = nullptr;
85
86 bool viewportFromTarget = true; // TODO set this somehow
87 };
88
89 class TerrainSystem final : public ComponentSystemWithDataPool<TerrainComponent, TerrainData>
90 {
91 public:
92 TerrainSystem(Memory::Allocator * allocator, SizeType capacity) : ComponentSystemWithDataPool(allocator, capacity) {}
93
94 void initialize(Context * context) override;
95 void update(Context * context) override;
96 void cleanup(Context* context) override;
97
99 void destroyComponent(ComponentHandle component) override;
100
101 private:
102 class TerrainRenderer * terrainRenderer = nullptr;
103
104 Cogs::VertexFormatHandle terrainFormat;
105
106 TerrainPicker* picker = nullptr;
107 };
108 }
109}
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
Interface for modules implementing custom picking.
Definition: RayPick.h:140
void getBounds(Context *context, Cogs::Geometry::BoundingBox &bounds) final
Expand bounds including bounds of all entities in this system in world coordinates.
Definition: TerrainSystem.h:48
void getBounds(Context *context, Cogs::Geometry::BoundingBox &bounds, float &nearPlaneLimit) final
bool pickCamera(Context *context, const CameraComponent &camera, const glm::vec2 &normPosition, float, float, PickingFlags pickingFlags, PicksReturned returnFlag, const RayPicking::RayPickFilter &filter, std::vector< RayPicking::RayPickHit > &hits) override
Do a ray pick from a normalized screen space position in the camera direction and return all hits.
ComponentModel::ComponentHandle createComponent() override
void cleanup(Context *context) override
Provided for custom cleanup logic in derived systems.
void destroyComponent(ComponentHandle component) override
void initialize(Context *context) override
Initialize the system.
Base allocator implementation.
Definition: Allocator.h:30
PicksReturned
  * Options for returning picking hits.
Definition: PickingFlags.h:40
PickingFlags
Options for COGS picking.
Definition: PickingFlags.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
Handle to a Component instance.
Definition: Component.h:67