VR-Engage  2.2
Loading...
Searching...
No Matches
vreScriptReactiveTaskController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreScriptReactiveTaskController.h
7//! \ingroup vreVrfmodel
8//! \brief Controller for managing role-based reactive task scripts
9//!
10//! This file defines the DtVreScriptReactiveTaskController class which extends
11//! the script reactive task controller to provide role-based filtering of
12//! reactive tasks. It enables or disables reactive task scripts based on the
13//! currently engaged roles on an entity.
14
15#pragma once
16
17#include "vreVrfmodel/export.h"
19
20#include <vrfobjcore/scriptReactiveTaskController.h>
21
22namespace makVre
23{
25
26//! \brief Type identifier for the VRE script reactive task controller component
27const char DtVreScriptReactiveTaskControllerType[] = "vre-script-reactive-task-controller";
28
29//! \brief Controller for managing role-based reactive task scripts
30//!
31//! DtVreScriptReactiveTaskController extends the script reactive task controller
32//! to provide role-based filtering of reactive tasks. It tracks which roles are
33//! currently engaged on an entity and enables or disables reactive task scripts
34//! based on role permissions defined in the component's descriptor. This allows
35//! for dynamic adjustment of entity behavior based on current role assignments.
36class VREVRFMODEL_DLL DtVreScriptReactiveTaskController : public DtVreSimComponent<DtScriptReactiveTaskController>
37{
38public:
39 //! \brief Constructor
40 //! \param name The name of this component
41 //! \param owner The local object that owns this component
42 //! \param simManager The simulation services manager
43 //! \param desc Component descriptor with configuration parameters
44 //! \param parentRegistry Optional parent registry for reader/writer functionality
45 //!
46 //! Creates a new script reactive task controller component with the specified parameters.
47 //! Initializes the role-based reactive task management system.
48 DtVreScriptReactiveTaskController(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
49 DtComponentDescriptor* desc, DtReaderWriterRegistry* parentRegistry);
50
51 //! \brief Updates the controller state each simulation frame
52 //!
53 //! Overridden to check if any reactive tasks should be enabled or disabled
54 //! based on what roles are currently engaged on the entity. If the engaged
55 //! roles have changed since the last tick, updates the reactive tasks accordingly.
56 virtual void tick() override;
57
58 //! \brief Factory method to create a new instance of this component
59 //! \param name The name for the new component
60 //! \param owner The local object that will own this component
61 //! \param simManager The simulation services manager
62 //! \param desc Optional component descriptor
63 //! \param parentRegistry Optional parent registry for reader/writer functionality
64 //! \return Pointer to the newly created component
65 //!
66 //! Static factory method used by the component creation system to instantiate
67 //! new instances of this component type.
68 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
69 DtComponentDescriptor* desc, DtReaderWriterRegistry* parentRegistry);
70
71 //! \brief Determines if a reactive task script should be enabled
72 //! \param scriptName The name of the script to check
73 //! \param currentRoles The set of roles currently engaged on the entity
74 //! \return True if the script should be enabled, false otherwise
75 //!
76 //! Determines whether a reactive task script should be enabled or disabled
77 //! based on the allowed scripts configuration passed in through the descriptor
78 //! and the currently engaged roles. A script is enabled if any of the current
79 //! roles match the roles allowed for that script.
80 virtual bool shouldScriptBeEnabled(const DtString& scriptName, const std::set<std::string>& currentRoles) const;
81
82protected:
83 //! \brief Updates all reactive tasks based on current roles
84 //! \param currentRoles The set of roles currently engaged on the entity
85 //!
86 //! Updates all the reactive tasks for the current entity by iterating through
87 //! each task and calling shouldScriptBeEnabled() to determine if it should be
88 //! enabled or disabled. Then applies those settings to the reactive tasks.
89 virtual void updateReactiveTasks(const std::set<std::string>& currentRoles);
90
91 //! \brief Retrieves the set of roles currently engaged on the entity
92 //! \param roles Output parameter to be populated with the current roles
93 //!
94 //! Populates the provided set with the names of all roles currently
95 //! engaged on the entity. This information is used to determine which
96 //! reactive tasks should be enabled.
97 virtual void getRolesEngagedOnEntity(std::set<std::string>& roles);
98
99private:
100 //! \brief Default constructor (not implemented)
101 //!
102 //! Default constructor is private and not implemented to prevent
103 //! creation of instances without proper initialization.
105
106 //! \brief Copy constructor (not implemented)
107 //!
108 //! Copy constructor is private and not implemented to prevent
109 //! copy construction.
111
112 //! \brief Assignment operator (not implemented)
113 //! \return Reference to this object
114 //!
115 //! Assignment operator is private and not implemented to prevent assignment.
117
118protected:
119 //! \brief Pointer to the component's descriptor
120 //!
121 //! Contains the configuration parameters for this component, including
122 //! the mapping of scripts to their allowed roles.
124
125 //! \brief Set of roles that were engaged during the last tick
126 //!
127 //! Stores the set of role names that were engaged on the entity during
128 //! the previous simulation frame. Used to detect changes in engaged roles.
129 std::set<std::string> myLastTickRolesEngaged;
130
131 //! \brief Mapping of script IDs to their allowed roles
132 //!
133 //! Maps each script ID to a vector of role names that are allowed to
134 //! enable that script. A script is enabled if any of the current roles
135 //! match any of the allowed roles for that script.
136 std::map<DtString, std::vector<std::string>> myScriptIdsWithRolesToAllow;
137};
138
139} // namespace makVre
Script reactive task controller descriptor for VREngage.
Definition vreScriptReactiveTaskControllerDescriptor.h:42
DtVreScriptReactiveTaskController()
Default constructor (not implemented)
DtVreScriptReactiveTaskController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *parentRegistry)
Constructor.
virtual void updateReactiveTasks(const std::set< std::string > &currentRoles)
Updates all reactive tasks based on current roles.
std::set< std::string > myLastTickRolesEngaged
Set of roles that were engaged during the last tick.
Definition vreScriptReactiveTaskController.h:129
virtual void tick() override
Updates the controller state each simulation frame.
virtual bool shouldScriptBeEnabled(const DtString &scriptName, const std::set< std::string > &currentRoles) const
Determines if a reactive task script should be enabled.
DtVreScriptReactiveTaskController(const DtVreScriptReactiveTaskController &other)
Copy constructor (not implemented)
DtVreScriptReactiveTaskControllerDescriptor * myDescriptor
Pointer to the component's descriptor.
Definition vreScriptReactiveTaskController.h:123
virtual void getRolesEngagedOnEntity(std::set< std::string > &roles)
Retrieves the set of roles currently engaged on the entity.
std::map< DtString, std::vector< std::string > > myScriptIdsWithRolesToAllow
Mapping of script IDs to their allowed roles.
Definition vreScriptReactiveTaskController.h:136
DtVreScriptReactiveTaskController & operator=(const DtVreScriptReactiveTaskController &other)
Assignment operator (not implemented)
static DtSimComponent * creator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *parentRegistry)
Factory method to create a new instance of this component.
DtVreSimComponent(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Definition vreSimComponent.h:54
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
const char DtVreScriptReactiveTaskControllerType[]
Type identifier for the VRE script reactive task controller component.
Definition vreScriptReactiveTaskController.h:27
Base template class for VR-Engage simulation components.