VR-Engage  2.2
Loading...
Searching...
No Matches
lightsSirensControlLogic.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file lightsSirensControlLogic.h
7//! \brief Component for controlling vehicle emergency lights and sirens
8//! \ingroup vreCommonComponents
9
10#pragma once
11
13
15
17
18namespace makVre
19{
20class DtInitTable;
21
23{
24//! \ingroup RoleConfigParams
25//! \defgroup LightsSirensControlLogicRoleParams Lights Sirens Control Logic Role Parameters
26//! \roleInherits{PlayerComponentRoleParams}
27//! Configuration Options for lights and sirens control logic role.
28//! @{
29
30//! \vreRoleParam{lights,table,{},lightsSirensControlLogic,Table of light configuration entries defining available emergency lights and their properties.}
31constexpr const char* lights = "lights";
32
33//! \vreRoleParam{sirens,table,{},lightsSirensControlLogic,Table of siren names for creating siren control state attributes.}
34constexpr const char* sirens = "sirens";
35
36//! @}
37} // namespace LightsSirensControlLogicConfig
38}
39
40//! \brief Type identifier for DtLightsSirensControlLogic component
41constexpr const char* DtLightsSirensControlLogicType = "DtLightsSirensControlLogic";
42
43//! \brief Component that provides control of vehicle emergency lights and sirens
44//!
45//! DtLightsSirensControlLogic allows toggling of emergency lights and sirens
46//! on vehicles. It maintains the state of various light types and sirens,
47//! handles menu actions for toggling them, and updates their states based on
48//! player inputs.
50{
51public:
52 //! \brief Constructor for DtLightsSirensControlLogic
53 //!
54 //! Initializes the component with default values
56
57 //! \brief Virtual destructor for DtLightsSirensControlLogic
58 virtual ~DtLightsSirensControlLogic() override;
59
60 //! \brief Initializes the lights and sirens control component
61 //! \param player Pointer to the player station this component belongs to
62 //! \param config Configuration table containing lights and sirens settings
63 //! \return True if initialization succeeded, false otherwise
64 //!
65 //! Configures the available lights and sirens from the configuration table,
66 //! initializes state attributes, and sets up message handlers for menu actions
68
69 //! \brief Called every frame to update lights and sirens states
70 //! \param dt Delta time since the last frame in seconds
71 //!
72 //! Updates player attributes for all configured lights based on the entity's
73 //! current appearance and light states
74 virtual void tick(double dt) override;
75
76 //! \brief Shuts down the lights and sirens control component
77 //!
78 //! Removes message handlers and performs cleanup operations
79 virtual void shutdown() override;
80
81 //! \brief Returns the component type identifier
82 //! \return The component type string
83 virtual const char* type() const override;
84
85 //! \brief Toggles the state of a specific siren
86 //! \param sirenName Name of the siren to toggle
87 //!
88 //! Inverts the current state of the specified siren and updates
89 //! the corresponding player attribute
90 virtual void toggleSiren(const std::string& sirenName);
91
92 //! \brief Toggles the state of a specific light
93 //! \param lightName Name of the light to toggle
94 //!
95 //! Inverts the current state of the specified light, updates the
96 //! corresponding player attribute, and sends a VrfSetLightStateMessage
97 //! to update the visual appearance of the vehicle
98 virtual void toggleLight(const std::string& lightName);
99
100protected:
101 //! \brief Type definition for mapping light names to their light type IDs
102 using LightMap = std::map<std::string, int>;
103
104 //! \brief Map associating light names with their corresponding light type IDs
105 //!
106 //! Maps configuration-defined light names (e.g., "headlights", "brake_lights")
107 //! to their corresponding DtLightType enumeration values
109
110 //! \brief Handles menu action messages for lights and sirens
111 //! \param msg The message to handle
112 //! \return Message handling result indicating if the message was handled
113 //!
114 //! Processes "toggleSiren" and "toggleLights" menu actions with a parameter
115 //! indicating which specific light or siren to toggle
117};
std::map< std::string, int > LightMap
Type definition for mapping light names to their light type IDs.
Definition lightsSirensControlLogic.h:102
virtual void tick(double dt) override
Called every frame to update lights and sirens states.
virtual void shutdown() override
Shuts down the lights and sirens control component.
LightMap myLightMap
Map associating light names with their corresponding light type IDs.
Definition lightsSirensControlLogic.h:108
virtual makVre::DtVreMessageResult handleMenuMessage(makVre::DtVreMessage *msg)
Handles menu action messages for lights and sirens.
virtual ~DtLightsSirensControlLogic() override
Virtual destructor for DtLightsSirensControlLogic.
DtLightsSirensControlLogic()
Constructor for DtLightsSirensControlLogic.
virtual void toggleLight(const std::string &lightName)
Toggles the state of a specific light.
virtual void toggleSiren(const std::string &sirenName)
Toggles the state of a specific siren.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the lights and sirens control component.
virtual const char * type() const override
Returns the component type identifier.
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Base class for all role components in VR-Engage.
Definition playerComponent.h:78
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
constexpr const char * sirens
Definition lightsSirensControlLogic.h:34
constexpr const char * lights
Definition lightsSirensControlLogic.h:31
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
constexpr const char * DtLightsSirensControlLogicType
Type identifier for DtLightsSirensControlLogic component.
Definition lightsSirensControlLogic.h:41
Definition lightsSirensControlLogic.h:23
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines the DtPlayerComponent base class for VR-Engage role components.
Defines the base class for all VREngage messages.