VR-Engage  2.2
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 Gets all categories in the palette
194 //! \return Reference to the set of all categories
195 //!
196 //! Returns a set of all unique categories across all entities in the palette.
197 //! Categories are used for filtering and organizing entities in the UI.
198 virtual const std::set<std::string>& categories() const { return myAllCategories; }
199
200 //! \brief Gets all countries in the palette
201 //! \return Reference to the set of all countries
202 //!
203 //! Returns a set of all unique countries across all entities in the palette.
204 //! Countries are used for filtering and organizing entities in the UI.
205 virtual const std::set<std::string>& countries() const { return myAllCountries; }
206
207 //! \brief Reloads the role configuration for an entity type
208 //! \param entityType Entity type to reload
209 //!
210 //! Reloads the role configuration data found in the .entity file for a specific
211 //! entity type. This is used for hot-reloading when entity files are modified.
212 virtual void reloadRoleConfig(const DtEntityType& entityType);
213
214 //! \brief Gets the current list of simulation model sets
215 //! \return Reference to the vector of SMS filenames
216 //!
217 //! Returns the list of simulation model set (SMS) files that are currently
218 //! being used to populate the palette.
219 virtual const std::vector<DtFilename>& getSMSList() const;
220
221 //! \brief Finds a file in the SMS directories
222 //! \param file Name of the file to find
223 //! \return Full path to the file, or empty if not found
224 //!
225 //! Searches for a file in all SMS directories and returns its full path.
226 //! This is used to locate role definition files, entity files, and other resources.
227 virtual DtFilename findFile(const std::string& file);
228
229 //! \brief Gets the palette's initializer
230 //! \return Pointer to the initializer
231 //!
232 //! Returns a pointer to the DtInitializer owned by this class, which is used for
233 //! interfacing with Lua role definitions. This initializer can be accessed from
234 //! both the player creation palette and the choose role panel.
236
237protected:
238 //! \brief Initiates asynchronous building of the palette from SMS files
239 //!
240 //! Starts an asynchronous task to rebuild the palette from the current
241 //! set of SMS files. This is used to avoid blocking the main thread during
242 //! palette loading.
243 virtual void buildFromSMSAsync();
244
245 //! \brief Builds the palette from SMS files
246 //! \param app Pointer to the player station application
247 //! \param smsList List of SMS files to load from
248 //! \return True if building was successful, false otherwise
249 //!
250 //! Loads all entity definitions from the specified SMS files and
251 //! populates the palette with the resulting entities and roles.
252 virtual bool buildFromSMS(DtPlayerStationApp*, const std::vector<DtFilename>& smsList);
253
254 //! \brief Lua callback to get data paths for SMS
255 //! \param L Lua state pointer
256 //! \return Number of return values on the Lua stack
257 //!
258 //! Callback function for Lua to retrieve the SMS data paths.
259 static int getDataPathsForSms(lua_State* L);
260
261 //! \brief Sets the data paths for SMS
262 //! \param paths Vector of path strings to set
263 //!
264 //! Sets the list of data paths used for locating SMS resources.
265 void setDataPathsForSms(std::vector<std::string> paths);
266
267 //! \brief Adds a data path for SMS
268 //! \param path Path string to add
269 //!
270 //! Appends a new data path to the list of SMS resource locations.
271 void appendDataPathsForSms(std::string path);
272
273 //! \brief Removes all SMS data paths
274 //!
275 //! Clears the list of data paths used for locating SMS resources.
277
278 //! \brief Gets the list of SMS files to search
279 //! \param smsList Vector to populate with SMS file names
280 //!
281 //! Populates the provided vector with the list of SMS files to search when
282 //! loading an entity file. Returns the contents of mySmsList if specified,
283 //! or the app's default SMS list otherwise.
284 virtual void getSMSList(std::vector<DtString>& smsList) const;
285
286 //! \brief Gets the search paths for model set entries
287 //! \param searchPaths Vector to populate with search paths
288 //!
289 //! Populates the provided vector with the list of SMS paths (including inherited ones)
290 //! to search when loading a model set entry.
291 virtual void getSMSSearchPaths(std::vector<DtFilename>& searchPaths) const;
292
293 //! \brief Loads a model set entry
294 //! \param filename Name of the file to load
295 //! \return Shared pointer to the loaded model set entry
296 //!
297 //! Loads and parses a model set entry from the specified filename.
298 virtual std::shared_ptr<makVre::DtVreModelSetEntry> loadModelSetEntry(const std::string& filename);
299
300 //! \brief Finds a role in a palette entry by name
301 //! \param entry Palette entry to search in
302 //! \param role Name of the role to find
303 //! \return Shared pointer to the role descriptor, or null if not found
304 //!
305 //! Searches for a specific role within a palette entry by name.
306 std::shared_ptr<DtEntityRoleDescriptor> findRole(const DtPaletteEntry& entry, const std::string& role);
307
308 //! \brief Finds any role in a palette entry
309 //! \param entry Palette entry to search in
310 //! \return Shared pointer to the first role descriptor, or null if none exist
311 //!
312 //! Returns the first available role within a palette entry.
313 std::shared_ptr<DtEntityRoleDescriptor> findRole(const DtPaletteEntry& entry);
314
315protected:
316 //! \brief Static instance of SMS role search paths (for Lua access)
317 static std::vector<std::string> theSmsRoleSearchPaths;
318
319 //! \brief Map of entity types to palette entries
321
322 //! \brief Default palette entry (used when a specific entry is not found)
323 std::shared_ptr<DtPaletteEntry> myDefaultPaletteEntry;
324
325 //! \brief Set of all unique categories across all entities
326 std::set<std::string> myAllCategories;
327
328 //! \brief Set of all unique countries across all entities
329 std::set<std::string> myAllCountries;
330
331 //! \brief Pointer to the player station application
333
334 //! \brief Initializer for Lua role definitions
336
337 //! \brief Current list of SMS files to load from
338 std::vector<DtFilename> mySmsList;
339
340 //! \brief Incoming list of SMS files for the next rebuild
341 std::vector<DtFilename> myIncomingSmsList;
342
343 //! \brief Mutex for synchronizing build operations
344 tbb::mutex myBuildMutex;
345
346 //! \brief Flag indicating whether an asynchronous build is in progress
348
349 //! \brief Message to send when SMS loading completes
350 std::unique_ptr<SmsLoadCompleteMessage> mySmsLoadCompleteMessage;
351
352 //! \brief Task arena for asynchronous operations
353 tbb::task_arena myArena;
354};
355} // 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:323
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:335
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:326
static std::vector< std::string > theSmsRoleSearchPaths
Static instance of SMS role search paths (for Lua access)
Definition playerCreationPalette.h:317
std::unique_ptr< SmsLoadCompleteMessage > mySmsLoadCompleteMessage
Message to send when SMS loading completes.
Definition playerCreationPalette.h:350
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:198
DtPlayerStationApp * myApp
Pointer to the player station application.
Definition playerCreationPalette.h:332
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.
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:329
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:353
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:338
DtEntityMap myCreationPaletteMap
Map of entity types to palette entries.
Definition playerCreationPalette.h:320
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:344
std::vector< DtFilename > myIncomingSmsList
Incoming list of SMS files for the next rebuild.
Definition playerCreationPalette.h:341
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:347
virtual void tick()
Updates the palette state.
virtual const std::set< std::string > & countries() const
Gets all countries in the palette.
Definition playerCreationPalette.h:205
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:163
VR-Engage specific model set entry with role information.
Definition vreModelSetEntry.h:60
Definition smsLoadComplete.h:28
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
Provides configuration initialization for VREngage components.
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
std::map< 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