VR-Engage  2.2
Loading...
Searching...
No Matches
vortexIntegrationModule.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2024 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vortexIntegrationModule.h
7//! \brief Integration module for connecting VR-Forces with the Vortex physics engine
8//! \ingroup vreVrfVortex
9
10#pragma once
11
12#include <vreVrfVortex/export.h>
13
14#include <VxSim/VxSmartInterface.h>
15#include <VxSim/ISimulatorModule.h>
16#include <VxSim/EventManager.h>
17#include <VxSim/EventData.h>
18#include <VxSim/VxApplicationMode.h>
19
20#include <deque>
21
22namespace VxContent
23{
24class Scene;
25}
26
27namespace VxDynamics
28{
29class Mechanism;
30}
31
32namespace VxSim
33{
34class VxApplication;
35}
36
37namespace makVre
38{
39//! \brief Simulator module that integrates VR-Forces with the Vortex physics engine
40//!
41//! This module manages the communication between VR-Forces and the Vortex physics engine.
42//! It handles the synchronization of extension updates and parts updates, allowing for
43//! controlled modification of Vortex entities during simulation.
44class VREVRFVORTEX_DLL DtVxSimModule : public VxSim::ISimulatorModule
45{
46public:
47 //! \brief Factory key for the DtVxSimModule
48 //!
49 //! Unique identifier used to register and create instances of this module.
50 static const VxSim::VxFactoryKey kModuleKey;
51
52 //! \brief Event ID for extension update operations
53 //!
54 //! Used to register and trigger extension update events.
55 static const VxSim::EventId kExtensionUpdate;
56
57 //! \brief Event ID for parts update operations
58 //!
59 //! Used to register and trigger parts update events.
60 static const VxSim::EventId kPartsUpdate;
61
62 //! \brief Operation types that can be queued for processing
63 enum class Operation
64 {
65 PARTS_UPDATE = 0, //!< Update operation for Vortex parts
66 EXTENSION_UPDATE //!< Update operation for Vortex extensions
67 };
68
69 //! \brief Pair of operation type and event data for queued operations
70 using OperationEvent = std::pair<Operation, VxSim::EventData>;
71
72public:
73 //! \brief Constructor
74 //!
75 //! Initializes the module with the provided simulator module proxy.
76 //!
77 //! \param iProxy Pointer to the simulator module proxy
78 DtVxSimModule(VxSim::VxSimulatorModule* iProxy);
79
80 //! \brief Destructor
81 virtual ~DtVxSimModule() override;
82
83 //! \brief Handles application mode changes
84 //!
85 //! Called when the Vortex application transitions between modes (e.g., edit mode, simulation mode).
86 //!
87 //! \param previous Previous application mode
88 //! \param next New application mode
89 virtual void onApplicationModeChange(VxSim::eApplicationMode previous, VxSim::eApplicationMode next) override;
90
91 //! \brief Called when this module is added to the Vortex application
92 //!
93 //! Registers event listeners for extension and parts update events.
94 //!
95 //! \param application Pointer to the Vortex application
96 virtual void onAddToApplication(VxSim::VxApplication* application) override;
97
98 //! \brief Called when this module is removed from the Vortex application
99 //!
100 //! Unregisters event listeners and performs cleanup.
101 //!
102 //! \param application Pointer to the Vortex application
103 virtual void onRemoveFromApplication(VxSim::VxApplication* application) override;
104
105 //! \brief Called before each simulation update
106 //!
107 //! Processes a limited number of queued operations per frame to avoid performance issues.
108 //!
109 //! \param mode Current application mode
110 virtual void onPreUpdate(VxSim::eApplicationMode mode) override;
111
112protected:
113 //! \brief Processes an extension update operation
114 //!
115 //! Enables or disables a Vortex extension based on the event data.
116 //!
117 //! \param data Event data containing extension information and enable/disable flag
118 void processExtensionUpdate(const VxSim::EventData& data);
119
120 //! \brief Callback for extension update events
121 //!
122 //! Queues extension update operations for processing.
123 //!
124 //! \param data Event data for the extension update
125 void extensionUpdateCallback(const VxSim::EventData& data);
126
127 //! \brief Processes a parts update operation
128 //!
129 //! Updates the control type of Vortex parts based on the event data.
130 //!
131 //! \param data Event data containing part information and control type
132 void processPartsUpdate(const VxSim::EventData& data);
133
134 //! \brief Callback for parts update events
135 //!
136 //! Queues parts update operations for processing.
137 //!
138 //! \param data Event data for the parts update
139 void partsUpdateCallback(const VxSim::EventData& data);
140
141protected:
142 std::deque<OperationEvent> myQueuedOperations; //!< Queue of operations to be processed
143
144 int myNumberOfOperationsPerFrame; //!< Maximum number of operations to process per frame
145
146 VxSim::EventListener myExtensionUpdateListener; //!< Listener for extension update events
147 VxSim::EventListener myPartsUpdateListener; //!< Listener for parts update events
148};
149} // namespace makVre
void extensionUpdateCallback(const VxSim::EventData &data)
Callback for extension update events.
void processExtensionUpdate(const VxSim::EventData &data)
Processes an extension update operation.
std::pair< Operation, VxSim::EventData > OperationEvent
Pair of operation type and event data for queued operations.
Definition vortexIntegrationModule.h:70
static const VxSim::EventId kPartsUpdate
Event ID for parts update operations.
Definition vortexIntegrationModule.h:60
virtual ~DtVxSimModule() override
Destructor.
DtVxSimModule(VxSim::VxSimulatorModule *iProxy)
Constructor.
int myNumberOfOperationsPerFrame
Maximum number of operations to process per frame.
Definition vortexIntegrationModule.h:144
void partsUpdateCallback(const VxSim::EventData &data)
Callback for parts update events.
static const VxSim::VxFactoryKey kModuleKey
Factory key for the DtVxSimModule.
Definition vortexIntegrationModule.h:50
Operation
Operation types that can be queued for processing.
Definition vortexIntegrationModule.h:64
@ EXTENSION_UPDATE
Update operation for Vortex extensions.
Definition vortexIntegrationModule.h:66
@ PARTS_UPDATE
Update operation for Vortex parts.
Definition vortexIntegrationModule.h:65
virtual void onApplicationModeChange(VxSim::eApplicationMode previous, VxSim::eApplicationMode next) override
Handles application mode changes.
virtual void onRemoveFromApplication(VxSim::VxApplication *application) override
Called when this module is removed from the Vortex application.
virtual void onAddToApplication(VxSim::VxApplication *application) override
Called when this module is added to the Vortex application.
static const VxSim::EventId kExtensionUpdate
Event ID for extension update operations.
Definition vortexIntegrationModule.h:55
VxSim::EventListener myExtensionUpdateListener
Listener for extension update events.
Definition vortexIntegrationModule.h:146
VxSim::EventListener myPartsUpdateListener
Listener for parts update events.
Definition vortexIntegrationModule.h:147
void processPartsUpdate(const VxSim::EventData &data)
Processes a parts update operation.
virtual void onPreUpdate(VxSim::eApplicationMode mode) override
Called before each simulation update.
std::deque< OperationEvent > myQueuedOperations
Queue of operations to be processed.
Definition vortexIntegrationModule.h:142
Export macros for the VR-Forces Vortex extension library.
#define VREVRFVORTEX_DLL
Export macro for non-Windows platforms.
Definition export.h:30
Definition vortexIntegrationModule.h:23
Definition vortexIntegrationModule.h:28
Definition vortexConfiguration.h:29
Include export definitions for this library.
Definition glsVreMessageUtil.h:49