VR-Engage  2.2
Loading...
Searching...
No Matches
minimapUpdater.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file minimapUpdater.h
7//! \brief Component that provides minimap functionality in a separate channel
8//! \ingroup vreCommonComponents
9
10#pragma once
11
14
16
17#include <vreUtil/color.h>
18
19namespace makVrv
20{
21class DtOsgChannel;
22class DtWindowConfiguration;
23class DtLineSegment;
24class DtCameraNode;
25} // namespace makVrv
26
27namespace makVre
28{
29class DtVrvOverlay;
30
31//! \brief Type identifier for DtMinimapUpdater component
32constexpr const char* DtMinimapUpdaterType = "DtMinimapUpdater";
33
34//! \brief Component that creates, updates, and manages a minimap display
35//!
36//! Creates, updates, and destroys a new channel, "Minimap", to display a 2D map in the main window.
37//! The minimap can be configured with multiple view modes, ownship indicators, compass overlays,
38//! and can be toggled on and off. It also adjusts visibility when binoculars are in use.
40{
41public:
42 //! \brief Constructor for DtMinimapUpdater
43 //!
44 //! Initializes component state with default values
46
47 //! \brief Virtual destructor for DtMinimapUpdater
48 virtual ~DtMinimapUpdater() override;
49
50 //! \brief Initializes the minimap updater component
51 //! \param player Pointer to the player station this component belongs to
52 //! \param config Configuration table containing minimap settings
53 //! \return True if initialization succeeded, false otherwise
54 //!
55 //! Processes configuration data and sets up the minimap channel based on the specified
56 //! view modes. Configures position, size, frame properties, and ownship indicators.
58
59 //! \brief Performs post-initialization tasks after all components are initialized
60 //! \return True if post-initialization succeeded, false otherwise
61 //!
62 //! Adds a callback to monitor changes to the binoculars state so the minimap
63 //! can be hidden when binoculars are active
64 virtual bool postInitialize() override;
65
66 //! \brief Called every frame to update the minimap
67 //! \param dt Delta time since the last frame in seconds
68 //!
69 //! Updates the heading of the compass overlay to match the player's current heading
70 //! when the minimap is displayed
71 virtual void tick(double dt) override;
72
73 //! \brief Shuts down the minimap updater component
74 //!
75 //! Destroys the minimap channel, cleans up resources, and removes callbacks
76 //! and message handlers. Restores the original icon scale setting.
77 virtual void shutdown() override;
78
79 //! \brief Returns the type identifier for this component
80 //! \return The type string for DtMinimapUpdater
81 virtual const char* type() const override;
82
83protected:
84 //! \brief Creates the overlay for displaying ownship indicators
85 //!
86 //! Sets up the VRV overlay that will contain the ownship dot and compass indicators
87 //! on top of the minimap display
88 virtual void createOverlay();
89
90 //! \brief Handles changes to the usingBinoculars attribute
91 //! \param usingBinoculars New value of the usingBinoculars attribute
92 //!
93 //! Shows or hides the minimap when the binoculars state changes,
94 //! hiding the minimap when binoculars are in use
95 virtual void handleUsingBinocularsChanged(bool usingBinoculars);
96
97 //! \brief Structure defining a minimap view mode configuration
98 struct ViewMode
99 {
100 //! \brief Name of the view mode for identification
101 std::string name;
102
103 //! \brief Left edge position (0.0-1.0 in normalized screen coordinates)
104 double left;
105
106 //! \brief Right edge position (0.0-1.0 in normalized screen coordinates)
107 double right;
108
109 //! \brief Bottom edge position (0.0-1.0 in normalized screen coordinates)
110 double bottom;
111
112 //! \brief Top edge position (0.0-1.0 in normalized screen coordinates)
113 double top;
114
115 //! \brief Flag indicating if the minimap should maintain a square aspect ratio
116 bool square;
117
118 //! \brief Flag indicating if this view mode is visible or off-screen
120 };
121
122 //! \brief Switches to the next minimap view mode
123 //!
124 //! Cycles through the view modes defined in the configuration,
125 //! updating the minimap's position, size, and visibility
126 virtual void cycleMinimapMode();
127
128 //! \brief Handles window creation messages
129 //! \param msg The window created message
130 //! \return Message handling result indicating if the message was handled
131 //!
132 //! Captures the minimap channel when it's created and sets up node masks and observer settings
134
135 //! \brief Handles window destruction messages
136 //! \param msg The window destroyed message
137 //! \return Message handling result indicating if the message was handled
138 //!
139 //! Clears references to the destroyed minimap channel
141
142 //! \brief Handles minimap-specific messages
143 //! \param msg The minimap message (cycle or reset zoom)
144 //! \return Message handling result indicating if the message was handled
145 //!
146 //! Processes messages to cycle minimap view modes or reset the zoom level
148
149 //! \brief Callback for window configuration change events
150 //! \param deName Name of the distributed environment
151 //! \param windowName Name of the window that changed
152 //! \param windowConfig New window configuration
153 //!
154 //! Updates the minimap channel's viewport when the window is resized
155 //! to maintain the correct position and proportions
157 const std::string& deName, const std::string& windowName, const makVrv::DtWindowConfiguration& windowConfig);
158
159 //! \brief Creates the minimap channel using the specified view mode
160 //! \param mode The view mode configuration to use for the minimap
161 //!
162 //! Creates a new minimap channel with the appropriate position and size
163 virtual void createMinimap(const ViewMode& mode);
164
165 //! \brief Modifies an existing minimap channel using the specified view mode
166 //! \param mode The view mode configuration to apply to the minimap
167 //!
168 //! Updates the position, size, and visibility of the minimap channel
169 virtual void modifyMinimap(const ViewMode& mode);
170
171 //! \brief Destroys the minimap channel
172 //!
173 //! Removes the minimap channel from the window manager
174 virtual void destroyMinimap();
175
176 //! \brief Registers message handlers for minimap-related messages
177 //!
178 //! Sets up handlers for window creation/destruction and minimap control messages
179 virtual void registerHandlers();
180
181 //! \brief Unregisters message handlers
182 //!
183 //! Removes all handlers for minimap-related messages
184 virtual void unregisterHandlers();
185
186 //! \brief Adds channel event processor association
187 //!
188 //! Associates the minimap channel with a target channel for event processing
190
191 //! \brief Removes channel event processor association
192 //!
193 //! Removes the association between the minimap channel and the target channel
195
196 //! \brief Builds frame elements around the minimap
197 //! \param elements Configuration table containing element definitions
198 //!
199 //! Overrides the base class function to programmatically create a frame
200 //! around the minimap based on the current view mode
201 virtual void buildElements(DtInitTable& elements) override;
202
203 //! \brief Calculates screen coordinates for a minimap view mode
204 //! \param mode The view mode to calculate coordinates for
205 //! \param left Output parameter for the left coordinate
206 //! \param right Output parameter for the right coordinate
207 //! \param bottom Output parameter for the bottom coordinate
208 //! \param top Output parameter for the top coordinate
209 //!
210 //! Calculates the actual screen coordinates for the minimap based on the view mode settings.
211 //! If square is true, the right coordinate is adjusted to maintain a square aspect ratio.
212 //! If visible is false, coordinates are set to place the channel off-screen.
214 const ViewMode& mode, double& left, double& right, double& bottom, double& top);
215
216 //! \brief Updates the minimap visibility based on current state
217 //!
218 //! Shows or hides the minimap only when the visibility state changes,
219 //! avoiding redundant calls to showMinimap or hideMinimap
221
222 //! \brief Shows the minimap by enabling rendering
223 //!
224 //! Restores the node masks for the minimap cameras to make the minimap visible
225 virtual void showMinimap();
226
227 //! \brief Hides the minimap by disabling rendering
228 //!
229 //! Sets the node masks for the minimap cameras to zero to hide the minimap
230 virtual void hideMinimap();
231
232 //! \brief Handles resizing of the map overlay
233 //!
234 //! Adjusts the position and size of the ownship indicators
235 //! when the map overlay is resized
237
238 //! \brief Sets the node mask on a camera node
239 //! \param node The camera node to modify
240 //! \param newMode The new node mask to apply
241 //! \param currentExpected The expected current node mask
242 //! \param setIfUnexpected Whether to set the mask if the current value is unexpected
243 //!
244 //! Sets the node mask on the specified camera node, with validation to detect
245 //! if the node mask has been changed by another component
246 virtual void setNodeMask(
247 makVrv::DtCameraNode* node, unsigned int newMode, unsigned int currentExpected, bool setIfUnexpected = true);
248
249 //! \brief Collection of available minimap view modes
250 std::vector<ViewMode> myModes;
251
252 //! \brief Index of the currently active view mode
253 unsigned int myCurrentMode;
254
255 //! \brief Initial map scale to restore on shutdown
257
258 //! \brief Color of the frame around the minimap
260
261 //! \brief Width of the frame around the minimap in pixels
263
264 //! \brief Name of the minimap channel
266
267 //! \brief Name of the window containing the minimap
268 std::string myWindowName;
269
270 //! \brief Name of the channel that will receive events from the minimap
272
273 //! \brief Flag indicating if the minimap is currently visible
275
276 //! \brief Flag indicating if the minimap is disabled
278
279 //! \brief Flag indicating if the minimap should be created at engagement
281
282 //! \brief Pointer to the OSG channel used for the minimap
283 makVrv::DtOsgChannel* myMinimapChannel;
284
285 //! \brief Width of the map in screen coordinates
287
288 //! \brief Height of the map in screen coordinates
290
291 //! \brief Reference height for sizing ownship indicators
293
294 //! \brief Filename of the texture for the ownship dot indicator
296
297 //! \brief Filename of the texture for the ownship compass indicator
299
300 //! \brief Size of the ownship dot indicator as a fraction of map height
302
303 //! \brief Size of the ownship compass indicator as a fraction of map height
305
306 //! \brief Color of the ownship dot indicator
308
309 //! \brief Overlay for displaying ownship indicators on the minimap
311
312 //! \brief Quad proxy for the ownship dot indicator
313 makVrv::DtQuadProxy* myOwnshipDotQuadProxy;
314
315 //! \brief Quad proxy for the ownship compass indicator
316 makVrv::DtQuadProxy* myOwnshipCompassQuadProxy;
317
318 //! \brief Initial icon scale value to restore on shutdown
320
321 //! \brief Cached node mask for the scene camera
322 unsigned int mySceneNodeMask;
323
324 //! \brief Cached node mask for the RTT camera
325 unsigned int myRttNodeMask;
326
327 //! \brief Cached node mask for the overlay camera
328 unsigned int myOverlayNodeMask;
329
330 //! \brief Cached node mask for the normalized overlay camera
332};
333} // namespace makVre
Class for representing and manipulating RGBA colors.
Definition color.h:22
Table-based access to Lua state for configuration data.
Definition initializer.h:38
virtual void destroyMinimap()
Destroys the minimap channel.
bool myDisableMinimap
Flag indicating if the minimap is disabled.
Definition minimapUpdater.h:277
double myFrameWidth
Width of the frame around the minimap in pixels.
Definition minimapUpdater.h:262
virtual void handleMapOverlayResized()
Handles resizing of the map overlay.
double myMapHeight
Height of the map in screen coordinates.
Definition minimapUpdater.h:289
virtual void getViewModeScreenCoordinates(const ViewMode &mode, double &left, double &right, double &bottom, double &top)
Calculates screen coordinates for a minimap view mode.
virtual void cycleMinimapMode()
Switches to the next minimap view mode.
virtual void registerHandlers()
Registers message handlers for minimap-related messages.
makVrv::DtOsgChannel * myMinimapChannel
Pointer to the OSG channel used for the minimap.
Definition minimapUpdater.h:283
double myOwnshipDotSize
Size of the ownship dot indicator as a fraction of map height.
Definition minimapUpdater.h:301
virtual void updateMinimapVisibility()
Updates the minimap visibility based on current state.
virtual const char * type() const override
Returns the type identifier for this component.
virtual void hideMinimap()
Hides the minimap by disabling rendering.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the minimap updater component.
unsigned int myCurrentMode
Index of the currently active view mode.
Definition minimapUpdater.h:253
virtual DtVreMessageResult handleMinimapMessage(DtVreMessage *msg)
Handles minimap-specific messages.
virtual void handleUsingBinocularsChanged(bool usingBinoculars)
Handles changes to the usingBinoculars attribute.
virtual void addChannelEventProcessorAssociation()
Adds channel event processor association.
std::string myWindowName
Name of the window containing the minimap.
Definition minimapUpdater.h:268
double myReferenceHeight
Reference height for sizing ownship indicators.
Definition minimapUpdater.h:292
virtual void setNodeMask(makVrv::DtCameraNode *node, unsigned int newMode, unsigned int currentExpected, bool setIfUnexpected=true)
Sets the node mask on a camera node.
makVrv::DtQuadProxy * myOwnshipCompassQuadProxy
Quad proxy for the ownship compass indicator.
Definition minimapUpdater.h:316
float myInitialIconScale
Initial icon scale value to restore on shutdown.
Definition minimapUpdater.h:319
DtColor myOwnshipDotColor
Color of the ownship dot indicator.
Definition minimapUpdater.h:307
virtual void tick(double dt) override
Called every frame to update the minimap.
double myMapWidth
Width of the map in screen coordinates.
Definition minimapUpdater.h:286
virtual void createMinimap(const ViewMode &mode)
Creates the minimap channel using the specified view mode.
DtMinimapUpdater()
Constructor for DtMinimapUpdater.
virtual void slot_onWindowConfigurationChanged(const std::string &deName, const std::string &windowName, const makVrv::DtWindowConfiguration &windowConfig)
Callback for window configuration change events.
virtual bool postInitialize() override
Performs post-initialization tasks after all components are initialized.
bool myInitializeMinimapOnEngage
Flag indicating if the minimap should be created at engagement.
Definition minimapUpdater.h:280
unsigned int myNormalizedOverlayNodeMask
Cached node mask for the normalized overlay camera.
Definition minimapUpdater.h:331
virtual DtVreMessageResult handleWindowCreated(DtVreMessage *msg)
Handles window creation messages.
virtual void buildElements(DtInitTable &elements) override
Builds frame elements around the minimap.
int myInitialMapScale
Initial map scale to restore on shutdown.
Definition minimapUpdater.h:256
std::string myOwnshipDotTextureFilename
Filename of the texture for the ownship dot indicator.
Definition minimapUpdater.h:295
virtual void shutdown() override
Shuts down the minimap updater component.
virtual void modifyMinimap(const ViewMode &mode)
Modifies an existing minimap channel using the specified view mode.
virtual void removeChannelEventProcessorAssociation()
Removes channel event processor association.
virtual void createOverlay()
Creates the overlay for displaying ownship indicators.
unsigned int myOverlayNodeMask
Cached node mask for the overlay camera.
Definition minimapUpdater.h:328
bool myIsMinimapVisible
Flag indicating if the minimap is currently visible.
Definition minimapUpdater.h:274
unsigned int mySceneNodeMask
Cached node mask for the scene camera.
Definition minimapUpdater.h:322
virtual void showMinimap()
Shows the minimap by enabling rendering.
DtVrvOverlay * myMapOverlay
Overlay for displaying ownship indicators on the minimap.
Definition minimapUpdater.h:310
unsigned int myRttNodeMask
Cached node mask for the RTT camera.
Definition minimapUpdater.h:325
std::string myMinimapChannelName
Name of the minimap channel.
Definition minimapUpdater.h:265
virtual DtVreMessageResult handleWindowDestroyed(DtVreMessage *msg)
Handles window destruction messages.
double myOwnshipCompassSize
Size of the ownship compass indicator as a fraction of map height.
Definition minimapUpdater.h:304
virtual void unregisterHandlers()
Unregisters message handlers.
std::vector< ViewMode > myModes
Collection of available minimap view modes.
Definition minimapUpdater.h:250
DtColor myFrameColor
Color of the frame around the minimap.
Definition minimapUpdater.h:259
makVrv::DtQuadProxy * myOwnshipDotQuadProxy
Quad proxy for the ownship dot indicator.
Definition minimapUpdater.h:313
virtual ~DtMinimapUpdater() override
Virtual destructor for DtMinimapUpdater.
std::string myOwnshipCompassTextureFilename
Filename of the texture for the ownship compass indicator.
Definition minimapUpdater.h:298
std::string myEventProcessorTargetChannel
Name of the channel that will receive events from the minimap.
Definition minimapUpdater.h:271
DtOverlayComponent()
Constructor for DtOverlayComponent.
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Class for creating and managing 2D overlays on a 3D scene.
Definition vrvOverlay.h:79
Provides color representation and manipulation functionality.
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtMinimapUpdaterType
Type identifier for DtMinimapUpdater component.
Definition minimapUpdater.h:32
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition appLauncherComponent.h:28
Component for creating and managing HUD elements in overlay channels.
Structure defining a minimap view mode configuration.
Definition minimapUpdater.h:99
double left
Left edge position (0.0-1.0 in normalized screen coordinates)
Definition minimapUpdater.h:104
double right
Right edge position (0.0-1.0 in normalized screen coordinates)
Definition minimapUpdater.h:107
std::string name
Name of the view mode for identification.
Definition minimapUpdater.h:101
double bottom
Bottom edge position (0.0-1.0 in normalized screen coordinates)
Definition minimapUpdater.h:110
bool square
Flag indicating if the minimap should maintain a square aspect ratio.
Definition minimapUpdater.h:116
double top
Top edge position (0.0-1.0 in normalized screen coordinates)
Definition minimapUpdater.h:113
bool visible
Flag indicating if this view mode is visible or off-screen.
Definition minimapUpdater.h:119
Defines the base class for all VREngage messages.