VR-Engage  2.2
Loading...
Searching...
No Matches
savedViewUpdater.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file savedViewUpdater.h
7//! \brief Component for managing predefined observer views and positions in vehicles
8//! \ingroup vreCommonComponents
9
10
11#pragma once
12
16
18
19#include <vrvCore/DtUniqueID.h>
20#include <vlutil/vlFilename.h>
21
22#include <makArchives/DtObserverStateRecordsList.h>
23
24namespace makVrv
25{
26class DtDe;
27class DtEntityFacade;
28class DtObserver;
29class DtChannel;
30class DtSceneObject;
31}; // namespace makVrv
32
34{
35//! \ingroup RoleConfigParams
36//! \defgroup SavedViewUpdaterRoleParams Saved View Updater Role Parameters
37//! \roleInherits{ObserverUpdaterRoleParams}
38//! Configuration Options for saved view updater role.
39//! @{
40
41//! \vreRoleParam{allowChangingViews,bool,true,savedViewUpdater,Determines whether the player is allowed to change between saved views.}
42constexpr const char* allowChangingViews = "allowChangingViews";
43
44//! \vreRoleParam{channelName,string,"Channel 1",savedViewUpdater,Name of the channel to update with view keywords.}
45constexpr const char* channelName = "channelName";
46
47//! \vreRoleParam{hideHumanInSavedViews,table,"",savedViewUpdater,Table specifying which saved views should hide the human model during walk-on embarkation.}
48constexpr const char* hideHumanInSavedViews = "hideHumanInSavedViews";
49
50//! \vreRoleParam{initialView,string,"",savedViewUpdater,Name of the initial saved view to activate on startup.}
51constexpr const char* initialView = "initialView";
52
53//! \vreRoleParam{observerName,string,"Observer 1",savedViewUpdater,Name of the observer to use for saved view management.}
54constexpr const char* observerName = "observerName";
55
56//! \vreRoleParam{savedViews,string,"",savedViewUpdater,Path to the file containing saved view definitions.}
57constexpr const char* savedViews = "savedViews";
58
59//! \vreRoleParam{showCockpits,bool,false,savedViewUpdater,Determines whether cockpit models should be visible in saved views.}
60constexpr const char* showCockpits = "showCockpits";
61
62//! \vreRoleParam{viewChannelKeywordMap,table,"",savedViewUpdater,Table mapping saved view names to channel keywords for view-specific display settings.}
63constexpr const char* viewChannelKeywordMap = "viewChannelKeywordMap";
64
65//! \vreRoleParam{windowName,string,"Window 1",savedViewUpdater,Name of the window containing the channel to update.}
66constexpr const char* windowName = "windowName";
67
68//! @}
69} // namespace SavedViewUpdaterConfig
70
71namespace makVre
72{
73class DtSavedViewInputLogic;
74
75//! \brief Type identifier for DtSavedViewUpdater component
76constexpr const char* DtSavedViewUpdaterType = "DtSavedViewUpdater";
77
78//! \brief Component for managing predefined observer views and positions in vehicles
79//!
80//! DtSavedViewUpdater loads and manages a set of saved viewpoints for a vehicle or role,
81//! allowing the player to switch between different positions (driver, gunner, etc.)
82//! and sensor modes (visual, NVG, thermal). It handles observer attachment, view positioning,
83//! human model visibility, and channel configuration for each view.
85{
86public:
87 //! \brief Constructor for DtSavedViewUpdater
88 //!
89 //! Initializes the saved view updater with default settings
91
92 //! \brief Virtual destructor for DtSavedViewUpdater
93 virtual ~DtSavedViewUpdater() override;
94
95 //! \brief Initializes the saved view updater component
96 //! \param player Pointer to the player station this component belongs to
97 //! \param config Configuration table containing saved view settings
98 //! \return True if initialization succeeded, false otherwise
99 //!
100 //! Sets up the saved view system, loads view definitions from a file, configures
101 //! input handlers, and establishes observer attachment parameters
103 //! \brief Called every frame to update the saved view system
104 //! \param dt Delta time since the last frame in seconds
105 //!
106 //! Updates sensor modes, handles view orientation adjustments for VR,
107 //! and manages destruction state changes
108 virtual void tick(double dt) override;
109 //! \brief Shuts down the saved view updater component
110 //!
111 //! Restores human model visibility to its original state, disconnects message handlers,
112 //! shuts down input logic, and resets observer attachments
113 virtual void shutdown() override;
114
115 //! \brief Returns the type identifier for this component
116 //! \return The type string for DtSavedViewUpdater
117 virtual const char* type() const override;
118
119 //! \brief Gets the input logic component for saved views
120 //! \return Shared pointer to the saved view input logic component
121 //!
122 //! Provides access to the input logic component that handles saved view input bindings
123 std::shared_ptr<DtSavedViewInputLogic> getInputLogic();
124
125 //! \brief Switches to a specific saved view by index
126 //! \param viewIndex Index of the view to activate
127 //!
128 //! Changes the observer's position and orientation to the specified saved view,
129 //! updates channel keywords, and handles human model visibility
130 virtual void gotoView(unsigned int viewIndex);
131
132 //! \brief Switches to the next saved view in sequence
133 //!
134 //! Increments the current view index and activates that view
135 virtual void nextView();
136
137 //! \brief Switches to the previous saved view in sequence
138 //!
139 //! Decrements the current view index and activates that view
140 virtual void previousView();
141
142 //! \brief Toggles between a named view and a previously active view
143 //! \param viewName Name of the view to toggle to/from
144 //! \param allowPartialMatch If true, allows partial matching of view names
145 //!
146 //! If the named view is not the current view, sets myViewToReturnTo to the current view
147 //! and switches to the named view. If the named view is already the current view and
148 //! myViewToReturnTo is valid, switches back to the previously stored view.
149 //! Note: myViewToReturnTo is reset to -1 by gotoView.
150 virtual void toggleView(const std::string& viewName, bool allowPartialMatch);
151
152 //! \brief Gets the observer being managed by this component
153 //! \return Pointer to the observer object
154 //!
155 //! Provides access to the VRV observer object for direct manipulation
156 makVrv::DtObserver* getObserver();
157
158
159 //! \brief Loads saved views from a file
160 //! \param filename Path to the file containing saved view definitions
161 //!
162 //! Reads and processes observer state records from the specified file
163 virtual void loadSavedViews(DtFilename filename);
164
165 //! \brief Gets the list of loaded saved view records
166 //! \return List of observer state records representing the saved views
167 //!
168 //! Provides access to the cached observer state records loaded from the file
169 virtual makArchives::DtObserverStateRecordsList getSavedViewsRecords();
170
171 //! \brief Gets the filename of the currently loaded saved views file
172 //! \return Filename of the saved views file
173 //!
174 //! Returns the path to the file from which saved views were loaded
175 virtual DtFilename getSavedViewsFileName();
176
177protected:
178 //! \brief Handles menu action messages related to saved views
179 //! \param msg The menu action message
180 //! \return Message handling result indicating if the message was handled
181 //!
182 //! Processes menu actions for next/previous view and explicit view selection
184
185 //! \brief Updates channel keywords based on the current view name
186 //! \param viewName Name of the current view
187 //!
188 //! Applies or removes channel keywords based on the view-to-keyword mapping
189 void updateChannelForViewName(const std::string& viewName);
190
191 //! \brief Updates the observer's sensor mode based on current state
192 //!
193 //! Changes the observer's sensor based on the currentSensor attribute,
194 //! handling transitions between visual, NVG, and thermal modes
196
197 //! \brief Updates view settings when the vehicle is destroyed
198 //!
199 //! Handles special cases for observer settings when damage state is "destroyed"
201
202 //! \brief Handles player creation messages
203 //! \param msg The player created message
204 //! \return Message handling result indicating if the message was handled
205 //!
206 //! Calls setupObserver() to establish the observer attachment details
207 //! when the player entity is created in the simulation
209
210 //! \brief Sets up the observer attachment configuration
211 //!
212 //! Configures the observer with AttachTypeMimic attachment to the player entity
213 //! and activates the initial view specified in the configuration
214 virtual void setupObserver();
215
216 //! \brief Determines if the human model should be hidden for a specific view
217 //! \param viewName Name of the view to check
218 //! \return True if the human model should be hidden, false otherwise
219 //!
220 //! Checks if the specified view is in the list of views that should hide
221 //! the human model (relevant for walk-on embarkation)
222 virtual bool shouldHideHumanModel(std::string viewName) const;
223
224 //! \brief Shows the human model if it exists
225 //!
226 //! Makes the human model visible by sending a visibility message
227 virtual void showHumanModel();
228
229 //! \brief Hides the human model if it exists
230 //!
231 //! Makes the human model invisible by sending a visibility message
232 virtual void hideHumanModel();
233
234 //! \brief Finds the human player station if walk-on embarkation was used
235 //! \return Pointer to the human player station if found, nullptr otherwise
236 //!
237 //! Locates the suspended human player station that corresponds to this vehicle role
238 //! when the player has performed walk-on embarkation
240
241 //! \brief Slot called when the human scene object is about to be deleted
242 //! \param id Unique ID of the scene object being deleted
243 //!
244 //! Clears the human scene object reference when the object is destroyed
245 virtual void slot_disSceneObjectToBeDeleted(const makVrv::DtUniqueID& id);
246
247 //! \brief Provides an interactive ImGui debug interface for saved views management
248 //!
249 //! Creates a collapsible debug panel that displays the current saved views file,
250 //! lists all available views (selectable to switch views), and provides interactive
251 //! controls for real-time adjustment of observer position and rotation offsets.
252 //! Also includes functionality to save modified views back to the file or create
253 //! new saved view files. Used by the VRE debug system for saved view development
254 //! and troubleshooting.
255 virtual void debugSavedViews();
256
257protected:
258 //! \brief Input logic component that handles saved view input bindings
259 std::shared_ptr<DtSavedViewInputLogic> myInputLogic;
260
261 //! \brief Pointer to the observer being managed by this component
262 makVrv::DtObserver* myObserver;
263
264 //! \brief Index of the currently active saved view
266
267 //! \brief Index of the view to return to when toggling views
269
270 //! \brief Total number of available saved views
272
273 //! \brief Name of the gunner seat view
274 std::string myGunnerSeatView;
275
276 //! \brief Flag indicating if the current view is a gunner seat view
278
279 //! \brief Last sensor view mode that was applied
281
282 //! \brief Names of the saved views
283 std::vector<std::string> mySavedViews;
284
285 //! \brief Type definition for mapping view names to channel keywords
286 using ViewChannelKeywordMap = std::map<std::string, std::string>;
287
288 //! \brief Mapping from view names to channel keywords
290
291 //! \brief List of channel keywords applied for the current view
292 std::vector<std::string> myLastChannelKeywords;
293
294 //! \brief Index of the initial view to activate on startup
296
297 //! \brief Flag indicating if view changes are allowed
299
300 //! \brief Flag indicating if the model should be hidden
302
303 //! \brief Name of the observer to use
304 std::string myObserverName;
305
306 //! \brief Name of the channel to update with view keywords
307 std::string myChannelName;
308
309 //! \brief Name of the window containing the channel
310 std::string myWindowName;
311
312 //! \brief Path to the file containing saved view definitions
314
315 //! \brief List of observer state records loaded from the saved views file
316 makArchives::DtObserverStateRecordsList myCachedObserverViews;
317
318 //! \brief List of view names for which the human model should be hidden
319 std::vector<std::string> myHideHumanModelInSavedViews;
320
321 //! \brief Pointer to the human scene object for walk-on embarkation
322 makVrv::DtSceneObject* myHumanSceneObject;
323
324 //! \brief Initial visibility state of the human scene object
326};
327} // namespace makVre
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Base component for managing observer view parameters and display settings.
Definition observerUpdater.h:83
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
int myInitialView
Index of the initial view to activate on startup.
Definition savedViewUpdater.h:295
virtual void loadSavedViews(DtFilename filename)
Loads saved views from a file.
void updateSensor()
Updates the observer's sensor mode based on current state.
virtual void toggleView(const std::string &viewName, bool allowPartialMatch)
Toggles between a named view and a previously active view.
virtual makVre::DtVreMessageResult handleMenuMessage(makVre::DtVreMessage *msg)
Handles menu action messages related to saved views.
std::vector< std::string > myLastChannelKeywords
List of channel keywords applied for the current view.
Definition savedViewUpdater.h:292
std::string myObserverName
Name of the observer to use.
Definition savedViewUpdater.h:304
int myNumViews
Total number of available saved views.
Definition savedViewUpdater.h:271
virtual void nextView()
Switches to the next saved view in sequence.
virtual void showHumanModel()
Shows the human model if it exists.
std::map< std::string, std::string > ViewChannelKeywordMap
Type definition for mapping view names to channel keywords.
Definition savedViewUpdater.h:286
SensorViews myLastSensorViewMode
Last sensor view mode that was applied.
Definition savedViewUpdater.h:280
DtSavedViewUpdater()
Constructor for DtSavedViewUpdater.
makVrv::DtObserver * getObserver()
Gets the observer being managed by this component.
makArchives::DtObserverStateRecordsList myCachedObserverViews
List of observer state records loaded from the saved views file.
Definition savedViewUpdater.h:316
virtual ~DtSavedViewUpdater() override
Virtual destructor for DtSavedViewUpdater.
virtual void slot_disSceneObjectToBeDeleted(const makVrv::DtUniqueID &id)
Slot called when the human scene object is about to be deleted.
bool myHideModel
Flag indicating if the model should be hidden.
Definition savedViewUpdater.h:301
void updateDestroyed()
Updates view settings when the vehicle is destroyed.
std::vector< std::string > mySavedViews
Names of the saved views.
Definition savedViewUpdater.h:283
void updateChannelForViewName(const std::string &viewName)
Updates channel keywords based on the current view name.
virtual DtFilename getSavedViewsFileName()
Gets the filename of the currently loaded saved views file.
bool myAllowChangingViews
Flag indicating if view changes are allowed.
Definition savedViewUpdater.h:298
virtual void previousView()
Switches to the previous saved view in sequence.
makVrv::DtObserver * myObserver
Pointer to the observer being managed by this component.
Definition savedViewUpdater.h:262
virtual makArchives::DtObserverStateRecordsList getSavedViewsRecords()
Gets the list of loaded saved view records.
virtual bool shouldHideHumanModel(std::string viewName) const
Determines if the human model should be hidden for a specific view.
virtual void setupObserver()
Sets up the observer attachment configuration.
std::shared_ptr< DtSavedViewInputLogic > getInputLogic()
Gets the input logic component for saved views.
virtual void shutdown() override
Shuts down the saved view updater component.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the saved view updater component.
ViewChannelKeywordMap myViewChannelKeywordMap
Mapping from view names to channel keywords.
Definition savedViewUpdater.h:289
bool myInGunnerSeat
Flag indicating if the current view is a gunner seat view.
Definition savedViewUpdater.h:277
DtFilename mySavedViewsFileName
Path to the file containing saved view definitions.
Definition savedViewUpdater.h:313
int myCurrentView
Index of the currently active saved view.
Definition savedViewUpdater.h:265
std::shared_ptr< DtSavedViewInputLogic > myInputLogic
Input logic component that handles saved view input bindings.
Definition savedViewUpdater.h:259
virtual void hideHumanModel()
Hides the human model if it exists.
int myViewToReturnTo
Index of the view to return to when toggling views.
Definition savedViewUpdater.h:268
virtual void tick(double dt) override
Called every frame to update the saved view system.
virtual makVre::DtVreMessageResult handlePlayerCreated(makVre::DtVreMessage *msg)
Handles player creation messages.
std::vector< std::string > myHideHumanModelInSavedViews
List of view names for which the human model should be hidden.
Definition savedViewUpdater.h:319
virtual void debugSavedViews()
Provides an interactive ImGui debug interface for saved views management.
std::string myWindowName
Name of the window containing the channel.
Definition savedViewUpdater.h:310
std::string myChannelName
Name of the channel to update with view keywords.
Definition savedViewUpdater.h:307
virtual DtPlayerStation * findHumanPlayer() const
Finds the human player station if walk-on embarkation was used.
bool myHumanSceneObjectInitiallyVisible
Initial visibility state of the human scene object.
Definition savedViewUpdater.h:325
virtual void gotoView(unsigned int viewIndex)
Switches to a specific saved view by index.
makVrv::DtSceneObject * myHumanSceneObject
Pointer to the human scene object for walk-on embarkation.
Definition savedViewUpdater.h:322
std::string myGunnerSeatView
Name of the gunner seat view.
Definition savedViewUpdater.h:274
virtual const char * type() const override
Returns the type identifier for this component.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Base component for managing observer parameters and view settings.
constexpr const char * channelName
Definition savedViewUpdater.h:45
constexpr const char * initialView
Definition savedViewUpdater.h:51
constexpr const char * windowName
Definition savedViewUpdater.h:66
constexpr const char * savedViews
Definition savedViewUpdater.h:57
constexpr const char * allowChangingViews
Definition savedViewUpdater.h:42
constexpr const char * viewChannelKeywordMap
Definition savedViewUpdater.h:63
constexpr const char * showCockpits
Definition savedViewUpdater.h:60
constexpr const char * hideHumanInSavedViews
Definition savedViewUpdater.h:48
constexpr const char * observerName
Definition savedViewUpdater.h:54
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Definition savedViewUpdater.h:34
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtSavedViewUpdaterType
Type identifier for DtSavedViewUpdater component.
Definition savedViewUpdater.h:76
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
SensorViews
Enumeration of available sensor view modes.
Definition stateDefines.h:18
Definition appLauncherComponent.h:28
Common enumeration definitions used throughout the VREngage system.
Defines the base class for all VREngage messages.