VR-Engage  2.3
Loading...
Searching...
No Matches
playerCreationPalette.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6#pragma once
7
8//! \file playerCreationPalette.h
9//! \brief Defines the DtPlayerCreationPalette class for managing available entity roles
10//!
11//! This file contains the DtPlayerCreationPalette class, which manages information about
12//! all available roles and entities that users can engage with in VR-Engage. It serves
13//! as a catalog of the playable options and provides methods for finding and accessing
14//! role definitions and configuration data.
15//!
16//! The class maintains its own DtInitializer for accessing Lua role files, as the
17//! initializer is not thread-safe and must be accessed from multiple threads.
18
20
22
23#include "vreUtil/initializer.h"
24
25#include <vlpi/entityType.h>
26#include <vlpi/disEnums.h>
27
28#include <string>
29#include <vector>
30#include <set>
31
32#include <tbb/mutex.h>
33#include <tbb/task_arena.h>
34#include <memory>
35
36namespace makVre
37{
38//! \brief Forward declaration of the initialization table class
39class DtInitTable;
40
41//! \brief Forward declaration of the player station application class
43
44//! \brief Forward declaration of the SMS load complete message class
46
48
49//! \brief Class for managing available entities and roles for engagement
50//!
51//! DtPlayerCreationPalette serves as a catalog of all entities and roles that
52//! can be played in VR-Engage. It loads entity definitions from simulation model
53//! sets (SMS) files and provides methods for accessing role configurations, display
54//! layouts, and other metadata necessary for creating player stations.
55//!
56//! This class maintains its own thread-safe access to role definition files and
57//! provides asynchronous loading capabilities for better performance.
59{
60public:
61 //! \brief Structure containing information about an entity in the palette
62 //!
63 //! DtPaletteEntry stores all metadata about a specific entity type that can
64 //! be engaged with in VR-Engage, including its roles, categories, and origin.
66 {
67 std::string myLabel; //!< Display name for the entity
68 std::vector<DtForceType> myForceTypes; //!< Force types this entity belongs to
69 std::vector<DtString> myCategories; //!< Categories this entity belongs to
70 std::vector<DtString> myCountries; //!< Countries this entity is associated with
71 DtEntityRoleMap myRoles; //!< Map of roles available for this entity
72 std::string myFilename; //!< Source filename (for hot-reloading)
73 };
74
75 //! \brief Type definition for a map of entity types to palette entries
76 using DtEntityMap = std::map<DtEntityType, std::shared_ptr<DtPaletteEntry>>;
77
78 //! \brief Type definition for an iterator over the entity map
79 using DtIterator = DtEntityMap::iterator;
80
81public:
82 //! \brief Constructor
83 //! \param app Pointer to the player station application
84 //!
85 //! Creates a new palette instance associated with the application.
86 //! Initializes the palette but does not load entity data automatically.
88
89 //! \brief Virtual destructor
90 //!
91 //! Cleans up resources, including the initializer and any loaded entity data.
93
94 //! \brief Updates the palette state
95 //!
96 //! Called once per frame to update the palette, handling any asynchronous
97 //! loading operations and processing completed loads.
98 virtual void tick();
99
100 //! \brief Sets the list of simulation model sets (SMS) to load
101 //! \param smsList Vector of SMS filenames to load
102 //!
103 //! Updates the list of simulation model sets from which to load entity
104 //! definitions. This will trigger an asynchronous reload of the palette.
105 virtual void setSmsList(const std::vector<DtFilename>& smsList);
106
107 //! \brief Gets an iterator to the beginning of the entity map
108 //! \return Iterator positioned at the start of the entity map
109 //!
110 //! Returns an iterator for traversing all entities in the palette.
112
113 //! \brief Advances to the next entity in the palette
114 //! \param iter Iterator to advance
115 //! \param nextType Optional pointer to receive the next entity type
116 //! \param nextEntry Optional pointer to receive the next palette entry
117 //! \return True if advanced successfully, false if reached the end
118 //!
119 //! Advances the iterator to the next entity and optionally retrieves the
120 //! type and entry information for that entity.
121 virtual bool getNext(
122 DtIterator& iter, DtEntityType* nextType = NULL, std::shared_ptr<DtPaletteEntry>* nextEntry = NULL);
123
124 //! \brief Finds an entity by its type
125 //! \param type Entity type to search for
126 //! \return Shared pointer to the palette entry, or null if not found
127 //!
128 //! Looks up an entity in the palette by its entity type identifier.
129 std::shared_ptr<DtPaletteEntry> findEntry(const DtEntityType& type);
130
131 //! \brief Checks if an entity type, role, and display layout combination is valid
132 //! \param type Entity type to check
133 //! \param role Optional role name to check (empty to check only entity type)
134 //! \param display Optional display layout to check (empty to check only entity and role)
135 //! \return True if the combination is valid, false otherwise
136 //!
137 //! Verifies whether a specific entity type exists in the palette and optionally
138 //! whether it supports the specified role and display layout.
139 virtual bool isValid(const DtEntityType& type, const std::string& role = "", const std::string& display = "");
140
141 //! \brief Gets the list of available roles for an entity type
142 //! \param type Entity type to get roles for
143 //! \return Vector of role names available for the entity
144 //!
145 //! Returns a list of all roles that can be played for the specified entity type.
146 virtual const std::vector<std::string> getRoleList(const DtEntityType& type);
147
148 //! \brief Finds a role that corresponds to a slot name
149 //! \param type Entity type to search in
150 //! \param slotName Name of the slot to find the role for
151 //! \return Role name that corresponds to the slot, or empty string if not found
152 //!
153 //! Maps from a slot name (used in embarkation) to the corresponding role name.
154 virtual std::string findRoleForSlot(const DtEntityType& type, const std::string& slotName);
155
156 //! \brief Finds a slot that corresponds to a role name
157 //! \param type Entity type to search in
158 //! \param roleName Name of the role to find the slot for
159 //! \return Slot name that corresponds to the role, or empty string if not found
160 //!
161 //! Maps from a role name to the corresponding slot name (used in embarkation).
162 virtual std::string findSlotForRole(const DtEntityType& type, const std::string& roleName);
163
164 //! \brief Gets the descriptor for a specific role
165 //! \param type Entity type to look up
166 //! \param role Role name to get the descriptor for
167 //! \return Shared pointer to the role descriptor, or null if not found
168 //!
169 //! Returns detailed information about a specific role, including file paths,
170 //! display layouts, and other configuration metadata.
171 virtual std::shared_ptr<DtEntityRoleDescriptor> getRoleDescriptor(const DtEntityType& type, const std::string& role);
172
173 //! \brief Gets the base template for a role
174 //! \param type Entity type to look up
175 //! \param role Role name to get the template for
176 //! \return Initialization table containing the role template
177 //!
178 //! Returns the base template configuration for a role before any display-specific
179 //! settings are applied.
180 virtual DtInitTable getRoleTemplate(const DtEntityType& type, const std::string& role);
181
182 //! \brief Gets the complete configuration for a player station
183 //! \param type Entity type to configure
184 //! \param role Role name to configure
185 //! \param display Display layout to use
186 //! \return Initialization table with the complete player configuration
187 //!
188 //! Returns the complete configuration for a player station, combining the
189 //! role template with display-specific settings and other overrides.
191 const DtEntityType& type, const std::string& role, const std::string& display);
192
193 //! \brief Checks whether a role configuration declares takeOwnership
194 //! \param type Entity type to look up
195 //! \param role Role name to check
196 //! \param display Display layout name (reserved for future per-layout overrides)
197 //! \return True if the role's Lua configuration sets takeOwnership = true
198 //!
199 //! Reads the top-level \c takeOwnership boolean from the role template file.
200 //! Returns false when the field is absent or the role template cannot be loaded.
201 virtual bool shouldTakeOwnership(const DtEntityType& type, const std::string& role, const std::string& display);
202
203 //! \brief Gets all categories in the palette
204 //! \return Reference to the set of all categories
205 //!
206 //! Returns a set of all unique categories across all entities in the palette.
207 //! Categories are used for filtering and organizing entities in the UI.
208 virtual const std::set<std::string>& categories() const { return myAllCategories; }
209
210 //! \brief Gets all countries in the palette
211 //! \return Reference to the set of all countries
212 //!
213 //! Returns a set of all unique countries across all entities in the palette.
214 //! Countries are used for filtering and organizing entities in the UI.
215 virtual const std::set<std::string>& countries() const { return myAllCountries; }
216
217 //! \brief Reloads the role configuration for an entity type
218 //! \param entityType Entity type to reload
219 //!
220 //! Reloads the role configuration data found in the .entity file for a specific
221 //! entity type. This is used for hot-reloading when entity files are modified.
222 virtual void reloadRoleConfig(const DtEntityType& entityType);
223
224 //! \brief Gets the current list of simulation model sets
225 //! \return Reference to the vector of SMS filenames
226 //!
227 //! Returns the list of simulation model set (SMS) files that are currently
228 //! being used to populate the palette.
229 virtual const std::vector<DtFilename>& getSMSList() const;
230
231 //! \brief Finds a file in the SMS directories
232 //! \param file Name of the file to find
233 //! \return Full path to the file, or empty if not found
234 //!
235 //! Searches for a file in all SMS directories and returns its full path.
236 //! This is used to locate role definition files, entity files, and other resources.
237 virtual DtFilename findFile(const std::string& file);
238
239 //! \brief Gets the palette's initializer
240 //! \return Pointer to the initializer
241 //!
242 //! Returns a pointer to the DtInitializer owned by this class, which is used for
243 //! interfacing with Lua role definitions. This initializer can be accessed from
244 //! both the player creation palette and the choose role panel.
246
247protected:
248 //! \brief Initiates asynchronous building of the palette from SMS files
249 //!
250 //! Starts an asynchronous task to rebuild the palette from the current
251 //! set of SMS files. This is used to avoid blocking the main thread during
252 //! palette loading.
253 virtual void buildFromSMSAsync();
254
255 //! \brief Builds the palette from SMS files
256 //! \param app Pointer to the player station application
257 //! \param smsList List of SMS files to load from
258 //! \return True if building was successful, false otherwise
259 //!
260 //! Loads all entity definitions from the specified SMS files and
261 //! populates the palette with the resulting entities and roles.
262 virtual bool buildFromSMS(DtPlayerStationApp*, const std::vector<DtFilename>& smsList);
263
264 //! \brief Lua callback to get data paths for SMS
265 //! \param L Lua state pointer
266 //! \return Number of return values on the Lua stack
267 //!
268 //! Callback function for Lua to retrieve the SMS data paths.
269 static int getDataPathsForSms(lua_State* L);
270
271 //! \brief Sets the data paths for SMS
272 //! \param paths Vector of path strings to set
273 //!
274 //! Sets the list of data paths used for locating SMS resources.
275 void setDataPathsForSms(std::vector<std::string> paths);
276
277 //! \brief Adds a data path for SMS
278 //! \param path Path string to add
279 //!
280 //! Appends a new data path to the list of SMS resource locations.
281 void appendDataPathsForSms(std::string path);
282
283 //! \brief Removes all SMS data paths
284 //!
285 //! Clears the list of data paths used for locating SMS resources.
287
288 //! \brief Gets the list of SMS files to search
289 //! \param smsList Vector to populate with SMS file names
290 //!
291 //! Populates the provided vector with the list of SMS files to search when
292 //! loading an entity file. Returns the contents of mySmsList if specified,
293 //! or the app's default SMS list otherwise.
294 virtual void getSMSList(std::vector<DtString>& smsList) const;
295
296 //! \brief Gets the search paths for model set entries
297 //! \param searchPaths Vector to populate with search paths
298 //!
299 //! Populates the provided vector with the list of SMS paths (including inherited ones)
300 //! to search when loading a model set entry.
301 virtual void getSMSSearchPaths(std::vector<DtFilename>& searchPaths) const;
302
303 //! \brief Loads a model set entry
304 //! \param filename Name of the file to load
305 //! \return Shared pointer to the loaded model set entry
306 //!
307 //! Loads and parses a model set entry from the specified filename.
308 virtual std::shared_ptr<makVre::DtVreModelSetEntry> loadModelSetEntry(const std::string& filename);
309
310 //! \brief Finds a role in a palette entry by name
311 //! \param entry Palette entry to search in
312 //! \param role Name of the role to find
313 //! \return Shared pointer to the role descriptor, or null if not found
314 //!
315 //! Searches for a specific role within a palette entry by name.
316 std::shared_ptr<DtEntityRoleDescriptor> findRole(const DtPaletteEntry& entry, const std::string& role);
317
318 //! \brief Finds any role in a palette entry
319 //! \param entry Palette entry to search in
320 //! \return Shared pointer to the first role descriptor, or null if none exist
321 //!
322 //! Returns the first available role within a palette entry.
323 std::shared_ptr<DtEntityRoleDescriptor> findRole(const DtPaletteEntry& entry);
324
325protected:
326 //! \brief Static instance of SMS role search paths (for Lua access)
327 static std::vector<std::string> theSmsRoleSearchPaths;
328
329 //! \brief Map of entity types to palette entries
331
332 //! \brief Default palette entry (used when a specific entry is not found)
333 std::shared_ptr<DtPaletteEntry> myDefaultPaletteEntry;
334
335 //! \brief Set of all unique categories across all entities
336 std::set<std::string> myAllCategories;
337
338 //! \brief Set of all unique countries across all entities
339 std::set<std::string> myAllCountries;
340
341 //! \brief Pointer to the player station application
343
344 //! \brief Initializer for Lua role definitions
346
347 //! \brief Current list of SMS files to load from
348 std::vector<DtFilename> mySmsList;
349
350 //! \brief Incoming list of SMS files for the next rebuild
351 std::vector<DtFilename> myIncomingSmsList;
352
353 //! \brief Mutex for synchronizing build operations
354 tbb::mutex myBuildMutex;
355
356 //! \brief Flag indicating whether an asynchronous build is in progress
358
359 //! \brief Message to send when SMS loading completes
360 std::unique_ptr<SmsLoadCompleteMessage> mySmsLoadCompleteMessage;
361
362 //! \brief Task arena for asynchronous operations
363 tbb::task_arena myArena;
364};
365} // namespace makVre
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Configuration initializer for VREngage components.
Definition initializer.h:80
virtual std::shared_ptr< makVre::DtVreModelSetEntry > loadModelSetEntry(const std::string &filename)
Loads a model set entry.
virtual std::string findSlotForRole(const DtEntityType &type, const std::string &roleName)
Finds a slot that corresponds to a role name.
std::shared_ptr< DtPaletteEntry > myDefaultPaletteEntry
Default palette entry (used when a specific entry is not found)
Definition playerCreationPalette.h:333
virtual DtInitTable getRoleTemplate(const DtEntityType &type, const std::string &role)
Gets the base template for a role.
virtual const std::vector< DtFilename > & getSMSList() const
Gets the current list of simulation model sets.
virtual std::shared_ptr< DtEntityRoleDescriptor > getRoleDescriptor(const DtEntityType &type, const std::string &role)
Gets the descriptor for a specific role.
void setDataPathsForSms(std::vector< std::string > paths)
Sets the data paths for SMS.
DtInitializer * myInitializer
Initializer for Lua role definitions.
Definition playerCreationPalette.h:345
DtPlayerCreationPalette(DtPlayerStationApp *app)
Constructor.
virtual DtIterator getIterator()
Gets an iterator to the beginning of the entity map.
virtual DtInitializer * initializer()
Gets the palette's initializer.
std::set< std::string > myAllCategories
Set of all unique categories across all entities.
Definition playerCreationPalette.h:336
static std::vector< std::string > theSmsRoleSearchPaths
Static instance of SMS role search paths (for Lua access)
Definition playerCreationPalette.h:327
std::unique_ptr< SmsLoadCompleteMessage > mySmsLoadCompleteMessage
Message to send when SMS loading completes.
Definition playerCreationPalette.h:360
virtual const std::vector< std::string > getRoleList(const DtEntityType &type)
Gets the list of available roles for an entity type.
std::shared_ptr< DtEntityRoleDescriptor > findRole(const DtPaletteEntry &entry)
Finds any role in a palette entry.
virtual bool buildFromSMS(DtPlayerStationApp *, const std::vector< DtFilename > &smsList)
Builds the palette from SMS files.
virtual const std::set< std::string > & categories() const
Gets all categories in the palette.
Definition playerCreationPalette.h:208
DtPlayerStationApp * myApp
Pointer to the player station application.
Definition playerCreationPalette.h:342
std::shared_ptr< DtPaletteEntry > findEntry(const DtEntityType &type)
Finds an entity by its type.
void appendDataPathsForSms(std::string path)
Adds a data path for SMS.
virtual bool getNext(DtIterator &iter, DtEntityType *nextType=NULL, std::shared_ptr< DtPaletteEntry > *nextEntry=NULL)
Advances to the next entity in the palette.
virtual bool shouldTakeOwnership(const DtEntityType &type, const std::string &role, const std::string &display)
Checks whether a role configuration declares takeOwnership.
std::map< DtEntityType, std::shared_ptr< DtPaletteEntry > > DtEntityMap
Type definition for a map of entity types to palette entries.
Definition playerCreationPalette.h:76
virtual void setSmsList(const std::vector< DtFilename > &smsList)
Sets the list of simulation model sets (SMS) to load.
virtual void buildFromSMSAsync()
Initiates asynchronous building of the palette from SMS files.
std::set< std::string > myAllCountries
Set of all unique countries across all entities.
Definition playerCreationPalette.h:339
static int getDataPathsForSms(lua_State *L)
Lua callback to get data paths for SMS.
virtual std::string findRoleForSlot(const DtEntityType &type, const std::string &slotName)
Finds a role that corresponds to a slot name.
virtual DtInitTable getPlayerConfiguration(const DtEntityType &type, const std::string &role, const std::string &display)
Gets the complete configuration for a player station.
tbb::task_arena myArena
Task arena for asynchronous operations.
Definition playerCreationPalette.h:363
DtEntityMap::iterator DtIterator
Type definition for an iterator over the entity map.
Definition playerCreationPalette.h:79
virtual void getSMSSearchPaths(std::vector< DtFilename > &searchPaths) const
Gets the search paths for model set entries.
std::vector< DtFilename > mySmsList
Current list of SMS files to load from.
Definition playerCreationPalette.h:348
DtEntityMap myCreationPaletteMap
Map of entity types to palette entries.
Definition playerCreationPalette.h:330
virtual bool isValid(const DtEntityType &type, const std::string &role="", const std::string &display="")
Checks if an entity type, role, and display layout combination is valid.
virtual DtFilename findFile(const std::string &file)
Finds a file in the SMS directories.
std::shared_ptr< DtEntityRoleDescriptor > findRole(const DtPaletteEntry &entry, const std::string &role)
Finds a role in a palette entry by name.
virtual void reloadRoleConfig(const DtEntityType &entityType)
Reloads the role configuration for an entity type.
virtual ~DtPlayerCreationPalette()
Virtual destructor.
void clearDataPathsForSms()
Removes all SMS data paths.
tbb::mutex myBuildMutex
Mutex for synchronizing build operations.
Definition playerCreationPalette.h:354
std::vector< DtFilename > myIncomingSmsList
Incoming list of SMS files for the next rebuild.
Definition playerCreationPalette.h:351
virtual void getSMSList(std::vector< DtString > &smsList) const
Gets the list of SMS files to search.
bool myAsyncBuilding
Flag indicating whether an asynchronous build is in progress.
Definition playerCreationPalette.h:357
virtual void tick()
Updates the palette state.
virtual const std::set< std::string > & countries() const
Gets all countries in the palette.
Definition playerCreationPalette.h:215
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:155
VR-Engage specific model set entry with role information.
Definition vreModelSetEntry.h:67
Sent when a component is done responding to a Simulation Model Set change.
Definition smsLoadComplete.h:32
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
Provides configuration initialization for VREngage components.
!
Definition glsVreMessageUtil.h:50
std::vector< std::pair< std::string, std::shared_ptr< DtEntityRoleDescriptor > > > DtEntityRoleMap
Map of role names to role descriptor objects.
Definition entityRoleDescriptorStructs.h:81
Utility functions for working with role configuration files.
Structure containing information about an entity in the palette.
Definition playerCreationPalette.h:66
std::string myFilename
Source filename (for hot-reloading)
Definition playerCreationPalette.h:72
std::vector< DtString > myCategories
Categories this entity belongs to.
Definition playerCreationPalette.h:69
std::vector< DtForceType > myForceTypes
Force types this entity belongs to.
Definition playerCreationPalette.h:68
DtEntityRoleMap myRoles
Map of roles available for this entity.
Definition playerCreationPalette.h:71
std::string myLabel
Display name for the entity.
Definition playerCreationPalette.h:67
std::vector< DtString > myCountries
Countries this entity is associated with.
Definition playerCreationPalette.h:70