VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
roleDefinitionStore.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2026 MAK Technologies, Inc.
3  * All rights reserved.
4  ******************************************************************************/
5 
6 #pragma once
7 
8 #include <string>
9 #include <vector>
10 #include <map>
11 #include <atomic>
12 #include <random>
13 #include <tbb/spin_rw_mutex.h>
14 #include <json/json.h>
15 
18 
21 {
22  std::string uuid;
23  bool includeSubordinates = false;
24 };
25 
29 {
30  bool all = false;
31  std::vector<int> forces;
32  std::vector<DtRoleUuidEntry> uuids;
33 };
34 
38 {
39  bool all = false;
40  bool allCommanded = false;
41  bool contactsFromViewed = false;
42  bool contactsFromCommanded = false;
43  std::vector<int> forces;
44  std::vector<DtRoleUuidEntry> uuids;
45  std::vector<int> contactsFromForce;
46  std::vector<DtRoleUuidEntry> contactsFromUUID;
47 };
48 
53 {
54  bool viewAll = false;
55  bool editAll = false;
56  std::vector<std::string> viewOverlays;
57  std::vector<std::string> editOverlays;
58  std::string defaultOverlay;
59  std::vector<int> viewNonOverlayByForce;
60  std::vector<int> editNonOverlayByForce;
61 };
62 
65 {
66  std::string roleName;
67  std::string description;
71 };
72 
76 {
77  std::string name;
78  std::string definitionId;
79  std::string scenarioName;
80  std::string description;
81 };
82 
134 {
135 public:
138 
150  void initialize(const std::string& defsDir,
151  const std::string& defaultDefsDir = std::string(),
152  const std::string& scenarioFilename = std::string());
153 
155  std::vector<DtRoleDefSummary> listDefinitions() const;
156 
159  bool loadDefinition(const std::string& name);
160 
168  bool saveDefinition(const std::string& name, const Json::Value& defJson, std::string& outError);
169 
171  std::string activeDefinitionName() const;
172 
174  std::string activeDefinitionId() const;
175 
177  std::string activeDefinitionDescription() const;
178 
181  bool addRole(const DtRoleDefinition& role, std::string& outError);
182 
185  bool removeRole(const std::string& roleName, std::string& outError);
186 
189  bool updateRolePolicy(const std::string& roleName, const Json::Value& partialPolicies, std::string& outError);
190 
193  bool updateRoleDescription(const std::string& roleName, const std::string& description, std::string& outError);
194 
196  void setActiveAllowSelfAssignment(bool allow);
197 
200 
203  bool loadDefinitionById(const std::string& definitionId);
204 
207  bool saveActiveToSourceDefinition(std::string& outError);
208 
213  std::string saveActiveAsNewDefinition(const std::string& name,
214  const std::string& scenarioName,
215  const std::string& description,
216  std::string& outError);
217 
222  bool setDefinitionScenario(const std::string& definitionId,
223  const std::string& scenarioName,
224  std::string& outError);
225 
228  bool setDefinitionDescription(const std::string& definitionId,
229  const std::string& description,
230  std::string& outError);
231 
234  bool deleteDefinition(const std::string& definitionId, std::string& outError);
235 
237  std::vector<DtRoleDefSummary> listDefinitionsForScenario(const std::string& scenarioFilename) const;
238 
241  bool getDefinitionById(const std::string& definitionId, Json::Value& outJson, std::string& outError) const;
242 
245  std::vector<std::string> roleNames() const;
246 
249  bool getRole(const std::string& roleName, DtRoleDefinition& outRole) const;
250 
252  std::vector<DtRoleDefinition> activeRoles() const;
253 
256  bool allowSelfAssignment() const;
257 
260  uint64_t definitionGeneration() const;
261 
271  bool entityMatchesRoles(const std::string& objectName,
272  int forceId,
273  const std::vector<std::string>& roleNames) const;
274 
278  bool isEntityCommanded(const std::string& objectName,
279  int forceId,
280  const std::vector<std::string>& roleNames) const;
281 
290  bool isTacticalGraphicViewable(const std::string& overlayName,
291  int forceId,
292  const std::vector<std::string>& roleNames) const;
293 
301  bool isTacticalGraphicEditable(const std::string& overlayName,
302  int forceId,
303  const std::vector<std::string>& roleNames) const;
304 
307  std::string defaultOverlayForRoles(const std::vector<std::string>& roleNames) const;
308 
311  static DtRoleDefinition parseRoleJson(const Json::Value& roleJson);
312 
314  void setSubordinateResolver(const DtSubordinateResolver* resolver, tbb::spin_rw_mutex* vrfDataMutex = nullptr);
315 
316 private:
317  DtRoleDefinitionStore() = default;
318 
320  static std::vector<std::string> scanDirectory(const std::string& dir);
321 
326 
328  static std::string generateUuid();
329 
333 
334  mutable tbb::spin_rw_mutex myMutex;
335 
336  std::string myDefsDir;
337  std::map<std::string, std::string> myNameToFilePath;
338  std::map<std::string, DtRoleDefSummary> myIndex;
339  std::map<std::string, std::string> myIdToName;
340 
342  std::string myActiveDefinitionId;
343  std::string myActiveScenarioName;
345  std::map<std::string, DtRoleDefinition> myActiveRoles;
347  std::atomic<uint64_t> myDefinitionGeneration{0};
349  tbb::spin_rw_mutex* myVrfDataMutex = nullptr;
350 };
uint64_t definitionGeneration() const
Monotonically increasing counter incremented each time a new definition is activated. Listeners compare against a cached value to detect changes without polling.
bool allowSelfAssignment() const
Returns whether player self-assignment is allowed by the active definition. Returns true when no defi...
bool addRole(const DtRoleDefinition &role, std::string &outError)
Adds a role to the active runtime configuration.
std::string myActiveDefinitionId
UUID of the currently loaded definition, or empty.
Definition: roleDefinitionStore.h:342
tbb::spin_rw_mutex myMutex
Definition: roleDefinitionStore.h:334
std::string myActiveScenarioName
scenarioName from the loaded file, or empty.
Definition: roleDefinitionStore.h:343
Json::Value serializeActiveDefinition() const
Serializes the active configuration to a complete JSON definition object. Caller must hold at least a...
void clearActiveConfiguration()
Resets the active configuration to empty (no roles, no source definition).
std::string myDefsDir
Definition: roleDefinitionStore.h:336
std::string defaultOverlayForRoles(const std::vector< std::string > &roleNames) const
Returns the default overlay name for the first assigned role that specifies one, or an empty string i...
bool isTacticalGraphicEditable(const std::string &overlayName, int forceId, const std::vector< std::string > &roleNames) const
Returns true if the tactical graphic is editable by at least one of the given roles. Returns true when roleNames is empty (permissive default).
std::string activeDefinitionId() const
Returns the definitionId of the currently active definition, or empty string if unsaved.
bool all
If true, the role may command all entities.
Definition: roleDefinitionStore.h:30
std::string scenarioName
Value of the &quot;scenarioName&quot; field (informational).
Definition: roleDefinitionStore.h:79
std::vector< DtRoleDefinition > activeRoles() const
Returns a snapshot of all role definitions in the active definition set.
std::string roleName
Definition: roleDefinitionStore.h:66
DtRoleCommandPolicy — defines which entities a role is authorised to command. Properties are additive...
Definition: roleDefinitionStore.h:28
Summary information for one role definition file — used to build the index without fully parsing ever...
Definition: roleDefinitionStore.h:75
std::vector< int > viewNonOverlayByForce
Force IDs — non-overlay graphics of these forces are viewable.
Definition: roleDefinitionStore.h:59
std::vector< int > forces
DIS force IDs — all entities belonging to these forces are commanded.
Definition: roleDefinitionStore.h:31
bool editAll
If true, all overlays (and non-overlay graphics) are editable.
Definition: roleDefinitionStore.h:55
bool loadDefinitionById(const std::string &definitionId)
Loads a definition by its definitionId (UUID) instead of by name.
bool updateRolePolicy(const std::string &roleName, const Json::Value &partialPolicies, std::string &outError)
Deep-merges partial policy fields into an existing role.
DtRoleDefinitionStore — process-wide singleton for role definition files.
Definition: roleDefinitionStore.h:133
DtRoleOverlayPolicy — defines which tactical graphic overlays a role can view and edit...
Definition: roleDefinitionStore.h:52
std::map< std::string, DtRoleDefSummary > myIndex
name -&gt; summary
Definition: roleDefinitionStore.h:338
bool getRole(const std::string &roleName, DtRoleDefinition &outRole) const
Populates outRole with the definition for the named role in the active definition.
bool isEntityCommanded(const std::string &objectName, int forceId, const std::vector< std::string > &roleNames) const
Returns true if the entity is commanded by at least one of the given roles. A role commands an entity...
std::vector< std::string > roleNames() const
Returns the names of all roles in the active definition. Returns an empty vector if no definition is ...
void setSubordinateResolver(const DtSubordinateResolver *resolver, tbb::spin_rw_mutex *vrfDataMutex=nullptr)
Sets the subordinate resolver used to expand includeSubordinates entries.
std::vector< int > contactsFromForce
(Future) DIS force IDs whose contact reports are visible.
Definition: roleDefinitionStore.h:45
bool saveDefinition(const std::string &name, const Json::Value &defJson, std::string &outError)
Saves a new role definition to disk and registers it in the index.
std::string activeDefinitionDescription() const
Returns the description of the currently active definition, or empty string if none.
std::vector< DtRoleUuidEntry > uuids
Specific entity UUIDs this role may command.
Definition: roleDefinitionStore.h:32
bool setDefinitionScenario(const std::string &definitionId, const std::string &scenarioName, std::string &outError)
Updates the scenarioName field for an existing saved definition by definitionId. Policy: &quot;Default&quot; ma...
std::vector< DtRoleDefSummary > listDefinitionsForScenario(const std::string &scenarioFilename) const
Lists definitions filtered by scenarioName matching the given filename.
DtRoleDefinition — a named role with separate commanded, viewed, and overlay policies.
Definition: roleDefinitionStore.h:64
bool removeRole(const std::string &roleName, std::string &outError)
Removes a role from the active runtime configuration.
bool entityMatchesRoles(const std::string &objectName, int forceId, const std::vector< std::string > &roleNames) const
Returns true if the entity passes the visibility filter for at least one of the given roles...
tbb::spin_rw_mutex * myVrfDataMutex
Definition: roleDefinitionStore.h:349
std::vector< DtRoleUuidEntry > contactsFromUUID
UUIDs whose contact reports are visible.
Definition: roleDefinitionStore.h:46
std::string defaultOverlay
Default overlay name for creating new graphics.
Definition: roleDefinitionStore.h:58
static std::string generateUuid()
Generates a random UUID in 8-4-4-4-12 lowercase hex format.
bool myAllowSelfAssignment
Definition: roleDefinitionStore.h:346
std::string myActiveDefinitionName
Definition: roleDefinitionStore.h:341
std::vector< DtRoleUuidEntry > uuids
Specific entity UUIDs that are always visible.
Definition: roleDefinitionStore.h:44
std::vector< int > forces
DIS force IDs whose entities are always visible.
Definition: roleDefinitionStore.h:43
bool contactsFromViewed
Also sees contact reports from all entities this role can view.
Definition: roleDefinitionStore.h:41
std::string description
Optional user-facing description for this role.
Definition: roleDefinitionStore.h:67
bool contactsFromCommanded
Also sees contact reports from all entities this role can command.
Definition: roleDefinitionStore.h:42
std::vector< int > editNonOverlayByForce
Force IDs — non-overlay graphics of these forces are editable.
Definition: roleDefinitionStore.h:60
void initialize(const std::string &defsDir, const std::string &defaultDefsDir=std::string(), const std::string &scenarioFilename=std::string())
Scans defsDir for *.json role definition files and builds the index. Must be called from main() befor...
DtRoleDefinitionStore()=default
bool saveActiveToSourceDefinition(std::string &outError)
Saves the active runtime configuration back to its source definition file.
IMGUI_API void Value(const char *prefix, bool b)
static DtRoleDefinitionStore & getInstance()
Returns the process-wide singleton instance.
bool setDefinitionDescription(const std::string &definitionId, const std::string &description, std::string &outError)
Updates the description field for an existing saved definition by definitionId.
std::string name
Value of the &quot;name&quot; field in the file.
Definition: roleDefinitionStore.h:77
std::string myActiveDefinitionDescription
Description from the loaded file, or empty.
Definition: roleDefinitionStore.h:344
DtWebServerObjectList — thread-safe container for tracked VRF objects.
Definition: webServerObjectList.h:25
bool all
If true, the session sees every entity and contact.
Definition: roleDefinitionStore.h:39
DtRoleViewPolicy — defines which entities a role&#39;s player session can see. Properties are additive: a...
Definition: roleDefinitionStore.h:37
bool allCommanded
Also sees all entities the role commands.
Definition: roleDefinitionStore.h:40
std::string saveActiveAsNewDefinition(const std::string &name, const std::string &scenarioName, const std::string &description, std::string &outError)
Saves the active runtime configuration as a new definition with the given name. Generates a new defin...
std::string activeDefinitionName() const
Returns the name of the currently active definition, or an empty string if none.
DtRoleCommandPolicy commanded
What this role may command.
Definition: roleDefinitionStore.h:68
void setActiveAllowSelfAssignment(bool allow)
Changes the allowSelfAssignment setting in the active configuration.
bool deleteDefinition(const std::string &definitionId, std::string &outError)
Deletes a saved definition file by its definitionId.
std::map< std::string, DtRoleDefinition > myActiveRoles
roleName -&gt; DtRoleDefinition
Definition: roleDefinitionStore.h:345
std::vector< DtRoleDefSummary > listDefinitions() const
Returns summary information for all available definition files.
std::string uuid
Definition: roleDefinitionStore.h:22
Represents a UUID entry in a role policy that may optionally include all subordinates recursively...
Definition: roleDefinitionStore.h:20
std::map< std::string, std::string > myIdToName
definitionId -&gt; name
Definition: roleDefinitionStore.h:339
bool getDefinitionById(const std::string &definitionId, Json::Value &outJson, std::string &outError) const
Reads and returns the full JSON content of a saved definition by its definitionId.
static DtRoleDefinition parseRoleJson(const Json::Value &roleJson)
Parses a role definition from a JSON object using the standard role definition file format...
std::string description
Optional user-provided description for this definition.
Definition: roleDefinitionStore.h:80
std::string definitionId
Unique UUID for this definition.
Definition: roleDefinitionStore.h:78
bool includeSubordinates
Definition: roleDefinitionStore.h:23
DtRoleViewPolicy viewed
What entities this role can see.
Definition: roleDefinitionStore.h:69
std::vector< std::string > editOverlays
Overlay names whose graphics are editable.
Definition: roleDefinitionStore.h:57
bool viewAll
If true, all overlays (and non-overlay graphics) are viewable.
Definition: roleDefinitionStore.h:54
static std::vector< std::string > scanDirectory(const std::string &dir)
Returns full file paths for every *.json file found directly in dir.
DtRoleOverlayPolicy overlays
Which tactical graphic overlays this role can view and edit.
Definition: roleDefinitionStore.h:70
bool updateRoleDescription(const std::string &roleName, const std::string &description, std::string &outError)
Updates the optional user-facing description for an existing role.
std::atomic< uint64_t > myDefinitionGeneration
Definition: roleDefinitionStore.h:347
Abstract interface for resolving subordinate relationships between entities.
Definition: subordinateResolver.h:12
const DtSubordinateResolver * mySubordinateResolver
Definition: roleDefinitionStore.h:348
std::vector< std::string > viewOverlays
Overlay names whose graphics are viewable.
Definition: roleDefinitionStore.h:56
void createDefaultDefinition()
Activates a built-in default definition containing &quot;Blue&quot; (friendly force) and &quot;Red&quot; (opposing force)...
std::map< std::string, std::string > myNameToFilePath
name -&gt; absolute file path
Definition: roleDefinitionStore.h:337
bool isTacticalGraphicViewable(const std::string &overlayName, int forceId, const std::vector< std::string > &roleNames) const
Returns true if the tactical graphic is viewable by at least one of the given roles. Returns true when roleNames is empty or no definition is active (permissive default).
bool loadDefinition(const std::string &name)
Loads and activates the named definition. Replaces any previously active definition.

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)