VR-Engage  2.3
Loading...
Searching...
No Matches
vortexPagedTerrainProducer.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2024 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vortexPagedTerrainProducer.h
7//! \brief Producer that manages terrain insertion into the Vortex physics universe
8//! \ingroup vreVrfVortex
9
10#pragma once
11
12#include <vreVrfVortex/export.h>
13
14#include <VxTerrain/VxPagedTerrainProducer.h>
15
16#include <tbb/spin_mutex.h>
17
18#include <memory>
19
20namespace Vx
21{
22class VxCollisionGeometry;
23}
24
25namespace makVre
26{
27//! \brief Producer that manages terrain in the Vortex physics universe
28//!
29//! This class manages the terrain being inserted into the Vortex universe,
30//! maintaining a collection of paged cells with collision geometries.
31//! It also handles dynamic terrain within Vortex.
32class VREVRFVORTEX_DLL DtVortexPagedTerrainProducer : public VxTerrain::VxPagedTerrainProducer
33{
34public:
35 //! \brief Structure for managing paged terrain cells
36 //!
37 //! Represents a single cell of terrain in the paged terrain system,
38 //! with its request information and collision geometry.
39 struct PagedCell
40 {
41 //! \brief Constructor
43
44 //! \brief Destructor
46
47 int requestId; //!< Request ID of this paged cell
48 VxMath::BoundingBox requestBoundingBox; //!< Bounding box of this request
49 Vx::VxCollisionGeometry* collisionGeometry; //!< Collision geometry of the paged cell
50 };
51
52 //! \brief Map type for storing paged cells indexed by source ID
53 using PagedCells = std::unordered_map<int, PagedCell*>;
54
55public:
56 //! \brief Constructor
57 //!
58 //! Initializes a new terrain producer with default settings.
60
61 //! \brief Destructor
62 //!
63 //! Cleans up terrain cells and resources.
65
66 //! \brief Performs pre-step operations
67 //!
68 //! Gets collision geometries of parts, maps terrain requests, and sets request
69 //! priorities before stepping. Also manages the PagedCells being tracked.
70 virtual void preStep() override;
71
72 //! \brief Inserts terrain with new collision geometry
73 //!
74 //! Adds the specified parts and collision geometries to the area of a given request
75 //! with the received source ID. Use when the terrain element is not already present.
76 //! Also inserts this into the myPagedCells map.
77 //!
78 //! \param sourceId Source ID to link this collision geometry to
79 //! \param requestId Request ID to link this collision geometry to
80 //! \param requestBounds Request bounds of this terrain request
81 //! \param cg Collision geometry to insert
82 void insertTerrain(int sourceId, int requestId, VxMath::BoundingBox requestBounds, Vx::VxCollisionGeometry* cg);
83
84 //! \brief Inserts terrain with existing source ID
85 //!
86 //! Calls default insertTerrain where a request ID shares the same source ID as another request.
87 //!
88 //! \param sourceId Source ID to link this collision geometry to
89 //! \param requestId Request ID to link this collision geometry to
90 void insertTerrain(int sourceId, int requestId);
91
92 //! \brief Gets the paged cell for a source ID
93 //!
94 //! \param sourceId The source ID to look up
95 //! \return Pointer to the paged cell, or nullptr if not found
97
98 //! \brief Gets all paged cells
99 //!
100 //! \return Map of all paged cells indexed by source ID
102
103 //! \brief Gets all collision geometries
104 //!
105 //! \return Vector of all collision geometries in the terrain
106 virtual std::vector<Vx::VxCollisionGeometry*> getAllCollisionGeometries();
107
108 //! \brief Checks if terrain is available below coordinates
109 //!
110 //! \param inputCords Position to check for terrain
111 //! \return True if terrain exists below the coordinates, false otherwise
112 bool isTerrainAvailable(const VxMath::Vector3& inputCords);
113
114 //! \brief Sets the terrain cell size
115 //!
116 //! \param cellSize The new cell size in meters
117 void setTerrainCellSize(double cellSize);
118
119 //! \brief Gets the terrain cell size
120 //!
121 //! \return The current cell size in meters
122 double getTerrainCellSize() const;
123
124protected:
125 //! \brief Initializes the paged terrain producer
126 //!
127 //! Internal method called during initialization.
128 virtual void _initialize() override;
129
130protected:
131 double myPagedTerrainCellSize; //!< Size of terrain cells in meters
132 PagedCells myPagedCells; //!< Map of all paged cells by source ID
133 tbb::spin_mutex myInsertMutex; //!< Mutex for thread-safe insertion
134
135 //! \brief Alive token captured by value into VxCollisionGeometry destruction
136 //! callbacks. Cleared in the destructor so callbacks that fire after this
137 //! producer has been torn down (e.g. CGs still refcounted elsewhere) can
138 //! detect the dangling case and skip touching this instance.
139 std::shared_ptr<bool> myAlive;
140};
141} // namespace makVre
std::shared_ptr< bool > myAlive
Alive token captured by value into VxCollisionGeometry destruction callbacks. Cleared in the destruct...
Definition vortexPagedTerrainProducer.h:139
tbb::spin_mutex myInsertMutex
Mutex for thread-safe insertion.
Definition vortexPagedTerrainProducer.h:133
PagedCells getPagedCells()
Gets all paged cells.
void setTerrainCellSize(double cellSize)
Sets the terrain cell size.
PagedCell * getPagedCellForSourceID(int sourceId)
Gets the paged cell for a source ID.
void insertTerrain(int sourceId, int requestId)
Inserts terrain with existing source ID.
PagedCells myPagedCells
Map of all paged cells by source ID.
Definition vortexPagedTerrainProducer.h:132
virtual std::vector< Vx::VxCollisionGeometry * > getAllCollisionGeometries()
Gets all collision geometries.
virtual void preStep() override
Performs pre-step operations.
bool isTerrainAvailable(const VxMath::Vector3 &inputCords)
Checks if terrain is available below coordinates.
virtual ~DtVortexPagedTerrainProducer() override
Destructor.
double myPagedTerrainCellSize
Size of terrain cells in meters.
Definition vortexPagedTerrainProducer.h:131
double getTerrainCellSize() const
Gets the terrain cell size.
virtual void _initialize() override
Initializes the paged terrain producer.
void insertTerrain(int sourceId, int requestId, VxMath::BoundingBox requestBounds, Vx::VxCollisionGeometry *cg)
Inserts terrain with new collision geometry.
std::unordered_map< int, PagedCell * > PagedCells
Map type for storing paged cells indexed by source ID.
Definition vortexPagedTerrainProducer.h:53
Export macros for the VR-Forces Vortex extension library.
#define VREVRFVORTEX_DLL
Export macro for non-Windows platforms.
Definition export.h:30
Wheel articulated part IDs used in the system.
Definition surfaceToVxMaterialMapper.h:20
!
Definition glsVreMessageUtil.h:50
Structure for managing paged terrain cells.
Definition vortexPagedTerrainProducer.h:40
int requestId
Request ID of this paged cell.
Definition vortexPagedTerrainProducer.h:47
Vx::VxCollisionGeometry * collisionGeometry
Collision geometry of the paged cell.
Definition vortexPagedTerrainProducer.h:49
VxMath::BoundingBox requestBoundingBox
Bounding box of this request.
Definition vortexPagedTerrainProducer.h:48