VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgBallisticManager.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2026 MAK Technologies, Inc.
3  * All rights reserved.
4  *****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
19 
21 #include <vrvMath/DtVector3.h>
22 
24 #include <vrvCore/DtUniqueID.h>
25 
26 #include <tbb/concurrent_hash_map.h>
27 #include <tbb/concurrent_unordered_map.h>
28 
29 #include <deque>
30 #include <map>
31 #include <mutex>
32 #include <string>
33 #include <unordered_map>
34 #include <utility>
35 #include <vector>
36 #include <functional>
37 #include <memory>
38 
39 namespace osg
40 {
41  class StateSet;
42  class Group;
43 }
44 
45 namespace makVrv
46 {
47  class DtBallisticProjectilePool;
48  class DtBallisticProjectile;
49  class DtBallisticGeometry;
50  class DtBallisticRunTimeSettings;
51  class DtBallisticComputeComponent;
52  class DtObserver;
53 
59  {
60  public:
62  using BallisticGeometryMap = tbb::concurrent_unordered_map<unsigned int, DtBallisticGeometry*>;
63 
65  static const std::string& theClassName();
66 
68  DtBallisticSoundProxy& soundProxy();
69 
75  void setSoundQueryMaxResults(int n);
76 
77  public:
79  virtual ~DtOsgBallisticManager();
80 
83  static void registerInstance(DtDe& de);
84 
88  static DtOsgBallisticManager& instance(DtDe& de);
89 
90  protected:
93 
95  DtOsgBallisticManager() = delete;
96 
99 
101  DtOsgBallisticManager& operator=(const DtOsgBallisticManager&) = delete;
102 
103  public:
105  virtual void tick(void) override;
106 
110  virtual void createProjectiles(const BallisticIdentifier& id, const BallisticData& data) override;
111 
114  virtual void removeProjectiles(const BallisticIdentifier& id) override;
115 
117  virtual void slot_atcGlobalModelEnableChanged();
118 
120  virtual void slot_releaseResources();
121 
123  virtual void slot_postTick();
124 
126  virtual void slot_postInit();
127 
131  virtual void slot_currentObserverChanged(DtObserver* observer);
132 
135  virtual void slot_windSpeedChanged(float metersPerSecond);
136 
139  virtual void slot_windDirectionChanged(float radians);
140 
142  const BallisticGeometryMap& ballisticGeometryMap() const;
143 
147  void setDefaultProjectileLifetime(double seconds);
148 
151  virtual double defaultProjectileLifetime() const;
152 
157  boost::signalslib::signal<void(osg::Node*)> signal_ballisticRenderNodeAdded;
158 
162  boost::signalslib::signal<void(osg::Node*)> signal_ballisticRenderNodeToBeRemoved;
163 
167  boost::signalslib::signal<void(DtTracerEffectEntry&)> signal_tracerEffectEntryAdded;
168 
171  boost::signalslib::signal<void(DtTracerEffectEntry&)> signal_tracerEffectEntryToBeRemoved;
172 
175  osg::Node* ballisticRenderNode() const;
176 
184  void registerPipPerObjectData(const std::string& pipFilename, const osg::Vec4& perObjectData);
185 
188  int tracerEffectEntryCount() const;
189 
196  DtTracerEffectEntry* tracerEffectEntryAt(int index);
197 
204  const DtTracerEffectEntry* tracerEffectEntryAt(int index) const;
205 
206  protected:
209  {
212 
213  uint64_t myId;
216  double myTimeAccum;
217  double myInterval;
218  bool myCancelled;
221  };
222 
225  {
228 
233 
236  {
239 
241  ActiveProjectileInfo(bool isActive, DtBallisticProjectile* projectile);
242 
243  bool myActive;
245  };
246 
247  std::map<int, ActiveProjectileInfo> myActiveProjectileMap;
248  };
249 
250 
251  protected:
252 
258  virtual void computeDirectionVectors(DtVector position, DtVector& east, DtVector& north, DtVector& up);
259 
270  virtual DtBallisticBurstHandle fire(const DtBallisticFireRequest& request, DtBallisticProjectileInstance& instance, DtBallisticGeometry* geometry);
271 
278  virtual void cancelBurst(const DtBallisticBurstHandle& handle);
279 
288  virtual DtBallisticProjectile* spawnOneRound(DtBallisticBurstRecord& record, double currentSimTime);
289 
291  virtual void reset();
292 
294  void setupRootNodes();
295 
297  virtual void updateStats();
298 
302  virtual void setAlpha2Coverage(osg::Node* node, bool on);
303 
304  public:
306  DtBallisticComputeComponent* computeComponent() const;
307 
309  DtBallisticSpatialGrid* grid() const;
310 
315  std::mutex& observerPositionMutex() { return myObserverPositionMutex; }
316 
320  DtVector observerWorldPosition() const { return myObserverWorldPosition; }
321 
325  bool observerPositionValid() const { return myObserverPositionValid; }
326 
327  protected:
330  float myWindSpeed;
332 
333  boost::signalslib::connection myPostInitializeConnection;
334 
337 
339  std::unique_ptr<DtBallisticProjectilePool> myProjectilePool;
340 
343 
346 
350 
352  using MapUniqueIdsToBallisticProjectileInstances = tbb::concurrent_hash_map<DtUniqueID, DtBallisticProjectileInstance>;
354 
359  std::deque<DtBallisticBurstRecord> myBurstRecords;
360 
361  double myLastTickTime;
363 
365  std::unordered_map<std::string, osg::Vec4> myPipFilenameToPerObjectData;
366 
369  std::unordered_map<std::string, std::unique_ptr<DtTracerEffectEntry>> myTracerEffectEntries;
370 
376 
384 
388 
391 
394 
397  };
398 }
BallisticGeometryMap myBallisticGeometryMap
Map of geometry cell index to active ballistic geometry. Supports concurrent traversal; removal is si...
Definition: DtOsgBallisticManager.h:349
DtVector myObserverWorldPosition
Cached observer world-space position, updated each simulation tick.
Definition: DtOsgBallisticManager.h:393
osg::ref_ptr< DtBallisticDebugGeometry > myDebugGeometry
Always-on debug geometry node that draws position-only green spheres for all active projectiles when ...
Definition: DtOsgBallisticManager.h:375
std::unordered_map< std::string, osg::Vec4 > myPipFilenameToPerObjectData
Maps pip filename to the SensorFX per-object data vec4.
Definition: DtOsgBallisticManager.h:365
bool myActive
Whether this slot is currently in use.
Definition: DtOsgBallisticManager.h:243
uint64_t myId
Identifier matching the associated burst handle.
Definition: DtOsgBallisticManager.h:213
tbb::concurrent_unordered_map< unsigned int, DtBallisticGeometry * > BallisticGeometryMap
Type definition for the ballistic geometry map, which maps unique integer IDs to geometry instances...
Definition: DtOsgBallisticManager.h:62
osg::ref_ptr< osg::Group > myDebugGroup
Owning group that parents myDebugGeometry under the model-set roots. Held as a member (not a local) s...
Definition: DtOsgBallisticManager.h:381
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
Definition: featureContext.h:36
Contains the makVrv::DtBallisticDebugGeometry class declaration.
DtBallisticBurstHandle myBurstHandle
Handle to the associated burst sequence.
Definition: DtOsgBallisticManager.h:231
Tracks the live state of a single projectile slot.
Definition: DtOsgBallisticManager.h:235
double myTimeAccum
Accumulated seconds toward the next round.
Definition: DtOsgBallisticManager.h:216
vrvCore singleton base class for the ballistic manager.
Definition: DtBallisticManager.h:27
bool myObserverPositionValid
True when myObserverWorldPosition holds a valid observer position.
Definition: DtOsgBallisticManager.h:396
int32_t myTracerTypeIndex
Tracer definition slot index registered for this burst; -1 if none.
Definition: DtOsgBallisticManager.h:220
std::mutex myObserverPositionMutex
Mutex protecting myObserverWorldPosition and myObserverPositionValid.
Definition: DtOsgBallisticManager.h:390
Parameters describing a ballistic burst to be spawned.
Definition: DtBallisticManager.h:38
Parameters for a single projectile burst fired via DtOsgBallisticManager.
Definition: DtBallisticFireRequest.h:26
DtString mySourceId
Source ID string used to detect hash collisions.
Definition: DtOsgBallisticManager.h:230
OSG Drawable that drives per-camera GPU cull and draw for a ballistic spatial cell.
Definition: DtBallisticGeometry.h:58
double myDefaultProjectileLifetime
Fallback projectile lifetime in seconds.
Definition: DtOsgBallisticManager.h:362
int myRoundsFired
Number of rounds already spawned.
Definition: DtOsgBallisticManager.h:215
DtObserver * myCurrentObserver
Active observer, updated via DtInputDriverSignaler::signal_currentObserverChanged. Accessed only from the simulation thread; no additional mutex required.
Definition: DtOsgBallisticManager.h:387
float myWindDirection
Current wind direction in radians.
Definition: DtOsgBallisticManager.h:331
boost::signalslib::connection myPostInitializeConnection
Connection for the post-init signal; disconnected when slot_postInit() fires.
Definition: DtOsgBallisticManager.h:333
3 dimensional vector
DtUniqueID myUniqueId
Unique identifier for the firing event.
Definition: DtOsgBallisticManager.h:229
Contains makVrv::DtBallisticBurstHandle class.
Contains the DtBallisticSoundProxy class declaration.
Internal record tracking one in-flight burst sequence.
Definition: DtOsgBallisticManager.h:208
int32_t myTracerTypeIndex
Tracer definition slot index registered for this instance; -1 if none.
Definition: DtOsgBallisticManager.h:232
DtBallisticComputeComponent * myComputeComponent
Shared compute component responsible for all trajectory computation.
Definition: DtOsgBallisticManager.h:342
A facade for a DtObserverObject.
Definition: DtObserver.h:38
std::map< int, ActiveProjectileInfo > myActiveProjectileMap
Map of slot index to projectile state.
Definition: DtOsgBallisticManager.h:247
DtSignalConnectionManager myConnections
Manages signal/slot lifetime connections.
Definition: DtOsgBallisticManager.h:329
Pure data and signal container that decouples DtOsgBallisticManager from the audio subsystem...
Definition: DtBallisticSoundProxy.h:41
Contains makVrv::DtBallisticSpatialGrid class.
DtBallisticFireRequest myRequest
Original fire parameters.
Definition: DtOsgBallisticManager.h:214
std::deque< DtBallisticBurstRecord > myBurstRecords
Active bursts with rounds still pending. NOT thread-safe: accessed only from the simulation thread (t...
Definition: DtOsgBallisticManager.h:359
CPU-side pool slot descriptor for a single GPU-simulated bullet.
Definition: DtBallisticProjectile.h:23
Contains the DtBallisticManager class declaration.
DtBallisticSpatialGrid * myGrid
Spatial grid routing per-camera cull, draw, and proximity queries.
Definition: DtOsgBallisticManager.h:345
bool observerPositionValid() const
Returns true if the cached observer position is valid (observer exists).
Definition: DtOsgBallisticManager.h:325
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
Represents a single effect-system registration for a ballistic tracer effect variant.
Definition: DtTracerEffectEntry.h:27
Contains makVrv::DtTracerEffectEntry class.
Spatial grid that owns and manages DtBallisticGeometry cells.
Definition: DtBallisticSpatialGrid.h:50
DtBallisticGeometry * myGeometry
Non-owning pointer to the cell geometry that owns this burst&#39;s slots.
Definition: DtOsgBallisticManager.h:219
float myWindSpeed
Current wind speed in metres per second.
Definition: DtOsgBallisticManager.h:330
unsigned long long DtUniqueID
Definition: DtUniqueID.h:19
double myLastTickTime
Simulation time at the last tick, or -1 if not yet ticked.
Definition: DtOsgBallisticManager.h:361
Interface for GPU compute operations driving the ballistic simulation pipeline.
Definition: DtBallisticComputeComponent.h:71
Contains makVrv::DtBallisticFireRequest class.
Internal record tracking all active projectiles for a unique firing event.
Definition: DtOsgBallisticManager.h:224
std::unique_ptr< DtBallisticProjectilePool > myProjectilePool
Shared pool that supplies GPU slots for all active projectiles.
Definition: DtOsgBallisticManager.h:339
DtVector observerWorldPosition() const
Returns the cached observer world-space position.
Definition: DtOsgBallisticManager.h:320
boost::signalslib::signal< void(osg::Node *)> signal_ballisticRenderNodeToBeRemoved
Signal emitted from reset() before the ballistic grid renderer node is removed from the scene graph a...
Definition: DtOsgBallisticManager.h:162
Base class to provide boost signal/slot management.
std::unordered_map< std::string, std::unique_ptr< DtTracerEffectEntry > > myTracerEffectEntries
One DtTracerEffectEntry per unique non-empty pip filename encountered during createProjectiles(). Keyed by pip filename string.
Definition: DtOsgBallisticManager.h:369
MapUniqueIdsToBallisticProjectileInstances myMapUniqueIdsToBallisticProjectileInstances
Definition: DtOsgBallisticManager.h:353
Singleton holding runtime-tweakable settings for the ballistic system.
Definition: DtBallisticRunTimeSettings.h:43
Contains makVrv::DtUniqueID type.
Contains DLL export macros.
std::mutex & observerPositionMutex()
Returns the mutex guarding the cached observer world-space position.
Definition: DtOsgBallisticManager.h:315
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:76
DtBallisticProjectile * myProjectile
Pointer to the projectile, or null.
Definition: DtOsgBallisticManager.h:244
Identifies a single burst sequence so callers can cancel pending (not-yet-spawned) rounds...
Definition: DtBallisticBurstHandle.h:24
double myInterval
Seconds between consecutive rounds.
Definition: DtOsgBallisticManager.h:217
boost::signalslib::signal< void(osg::Node *)> signal_ballisticRenderNodeAdded
Signal emitted from setupRootNodes() after the ballistic grid renderer node has been added to the sce...
Definition: DtOsgBallisticManager.h:157
Ballistic manager that owns the projectile pool, compute component, and spatial grid.
Definition: DtOsgBallisticManager.h:58
DtBallisticSoundProxy mySoundProxy
Sound coupling proxy: query settings, index resolver, and trigger signal.
Definition: DtOsgBallisticManager.h:383
bool myCancelled
When true, no further rounds will be spawned.
Definition: DtOsgBallisticManager.h:218
const DtBallisticRunTimeSettings & myBallisticRunTimeSettings
Reference to the active ballistic runtime settings.
Definition: DtOsgBallisticManager.h:336
Identifies the source entity associated with a ballistic burst.
Definition: DtBallisticManager.h:31
boost::signalslib::signal< void(DtTracerEffectEntry &)> signal_tracerEffectEntryToBeRemoved
Signal emitted from reset() before each DtTracerEffectEntry is destroyed. JrmSensorModule connects to...
Definition: DtOsgBallisticManager.h:171
boost::signalslib::signal< void(DtTracerEffectEntry &)> signal_tracerEffectEntryAdded
Signal emitted from fire() the first time a new pip filename is encountered. JrmSensorModule connects...
Definition: DtOsgBallisticManager.h:167
tbb::concurrent_hash_map< DtUniqueID, DtBallisticProjectileInstance > MapUniqueIdsToBallisticProjectileInstances
Map of unique firing-event identifiers to their projectile instance records.
Definition: DtOsgBallisticManager.h:352

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)