VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
simComponent.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2022 MAK Technologies, Inc.
3  * All rights reserved.
4  ****************************************************************************/
5 
9 
10 #pragma once
11 
14 #include <vrfobjcore/localObject.h>
15 
19 
20 //#include <vrfutil/objectConsole.h>
21 #include <vrfutil/vrf4XAPI.h>
22 
23 #include <vlutil/vlHashlist.h>
24 #include <vlutil/vlString.h>
25 #include <vlutil/vlList.h>
26 
27 #include <list>
28 
30 class DtInputPort;
31 class DtOutputPort;
32 class DtInputPortGroup;
33 class DtOutputPortGroup;
34 class DtPhysicalWorld;
35 class Coordinate_System;
36 class DtComponentSystem;
40 class DtLocalObject;
41 class DtSimObject;
43 class DtSimMessage;
44 class DtAttachedTerrain;
49 class DtTimedTickLogic;
50 
53  void* userData);
54 
57 #define CACHED_NEXT_FRAME_STATE_PROPERTY(property) \
58  DtPropertyInterface* myNextFrame##property = 0;
59 #define SET_CACHED_STATE_PROPERTY(property, value) \
60  setCachedNextFrameStatePropertyValue(&myNextFrame##property, #property, value);
61 
62 #define CACHED_CURRENT_FRAME_STATE_PROPERTY(property) \
63  const DtPropertyInterface* myCurrFrame##property = 0;
64 #define GET_CACHED_STATE_PROPERTY_VALUE(property, value) \
65  getCachedCurrentFrameStatePropertyValue(&myCurrFrame##property, #property, value);
66 
67 
68 
90 #ifdef DtObjectDebugger_Enable
91  , public DtObjectDebugger<DtSimComponent>
92 #endif
93 {
94 public:
95 
103  DtSimComponent(const DtString& name,
104  DtLocalObject* owner,
105  DtSimulationServices* simServices,
106  DtComponentDescriptor* desc = 0,
107  DtReaderWriterRegistry* parentRegistry = 0);
108 
110  virtual ~DtSimComponent() override;
111 
116  virtual void setParentSystem(DtComponentSystem* system);
118  DtComponentSystem * parentSystem() const;
119 
122  virtual bool init();
123 
127  virtual bool postAddComponentsInit() { return true; }
128 
132  virtual void registerAttributeFunctions(){}
133 
137  virtual void enable();
138  virtual void disable();
139  virtual bool isEnabled();
140  virtual void setIsEnabled(bool yesNo);
142 
146  virtual void preFirstTickInit();
147 
151  virtual void tick();
152 
156  virtual void postTick();
157 
165  virtual void timedTick();
166 
172  virtual void setMinTickPeriod(double minTickPeriod, double minTickPeriodVariance);
173 
176  virtual void setupFirstTickTime();
177 
184  virtual const char* type() const = 0;
185 
191  virtual void setEntity(DtLocalObject* entity);
192 
194  virtual DtSimComponent* nextComponent();
196  virtual DtSimComponent* prevComponent();
197 
201  virtual void setListItem(DtListItem* item);
203  virtual DtListItem* listItem();
204 
207  virtual void putData(std::string& fp, int indentLevel = 0) override;
208 
211  virtual DtlObjPtr getData(DtlObjPtr args, const DtReaderWriter::SearchPaths& searchPaths,
212  const DtVariableBindingsList& variableBindings) override;
213 
216  virtual void addInputPort(DtInputPort* port);
219  virtual void removeInputPort(DtInputPort* port);
220 
226  virtual DtInputPort* lookupInputPort(const DtString& portName);
227 
229  virtual DtList inputPortList() const;
230 
233  virtual void addOutputPort(DtOutputPort* port);
236  virtual void removeOutputPort(DtOutputPort* port);
237 
243  virtual DtOutputPort* lookupOutputPort(const DtString& portName);
244 
246  virtual DtList outputPortList() const;
247 
250  virtual void addInputPortGroup(DtInputPortGroup* group);
253  virtual void removeInputPortGroup(DtInputPortGroup* group);
254 
257  virtual DtInputPortGroup* lookupInputPortGroup(const DtString& groupName);
258 
260  virtual DtList inputPortGroupList() const;
261 
264  virtual void addOutputPortGroup(DtOutputPortGroup* group);
267  virtual void removeOutputPortGroup(DtOutputPortGroup* group);
268 
271  virtual DtOutputPortGroup* lookupOutputPortGroup(const DtString& groupName);
272 
274  virtual DtList outputPortGroupList() const;
275 
282  virtual int priority() const;
288  virtual void setPriority(int priority);
289 
293  double dT() const;
294 
298  virtual void setDT(double deltaT);
299 
303  virtual void setComponentDescriptor(DtComponentDescriptor* componentDescriptor);
304  virtual const DtComponentDescriptor* componentDescriptor() const;
305 
310  virtual bool tickWhileDestroyed() const;
311 
317  virtual DtOutputStream& objectConsoleDebug(const DtString& channel = "") const;
319  virtual DtOutputStream& objectConsoleVerbose(const DtString& channel = "") const;
321  virtual DtOutputStream& objectConsoleInfo(const DtString& channel = "") const;
323  virtual DtOutputStream& objectConsoleWarn(const DtString& channel = "") const;
325  virtual DtOutputStream& objectConsoleError(const DtString& channel = "") const;
327  virtual int notifyLevel() const;
329 
333  DtString toString(const DtEntityType& entityType) const;
334 
340 
343 
344  virtual DtSimResourceManager& resourceManager();
345  virtual const DtSimResourceManager& resourceManager() const;
347 
351  virtual const DtSymbolString& componentFullName() const;
352 
356  static DtSimComponentFactory* factory();
357  static void setFactory(DtSimComponentFactory* factory);
358 
361  static DtSimComponent* createComponent(const DtString& name,
362  const DtString& type, DtLocalObject* owner, DtSimulationServices* simManager, DtComponentSystem* parentSystem,
363  DtComponentDescriptor* desc = 0,
364  DtReaderWriterRegistry* parentRegistry = 0);
365 
371  static void addSimComponentCreatorFcn(const DtString& type,
373 
375  DtPhysicalWorld* physicalWorld();
376  const DtPhysicalWorld* physicalWorld() const;
377 
379  const DtAttachedTerrain* terrainAttachedTo() const;
380 
382  DtLocalObject* entity() { return myEntity; }
383  const DtLocalObject* entity() const { return myEntity; };
384 
386  DtSimulationServices* simulationServices();
387  const DtSimulationServices* simulationServices() const;
388 
393  const Coordinate_System* coordinateSystem() const;
394 
396  virtual void isClutterChanged();
397 
401  virtual bool taskVisualizationsActive() const;
402 
408  virtual bool taskVisualizationsEnabled() const;
409 
411  virtual void onRestore();
412 
415  {
416  return myTaskVisualizations;
417  }
418 
423  virtual void updateImgui();
424 
428  virtual bool debugActive() const;
429 
430 protected:
431 
436  virtual void setupTimedTickLogic(double minTickPeriod, double minTickPeriodVariance);
437 
440  virtual double computeCurrentTime();
441 
446  bool testInvariant() const;
447 
451  virtual bool createPortGroups();
452 
456  virtual bool createPorts();
457 
466  DtVrfProcessStateRepository* createComponentPsr(const DtString& defaultPsrType,
467  const DtString& defaultPsrName, bool useDescriptorParams = true);
468 
471  virtual void updateTaskVisualizations() {};
472 
474  virtual void destroyTaskVisualizations();
475 
477  virtual void destroyTaskVisualization(const DtString& name);
478 
480  virtual makVrf::DtPointTaskVisualizationPtr pointTaskVisualization(const DtString& name);
481 
483  virtual makVrf::DtLineTaskVisualizationPtr lineTaskVisualization(const DtString& name);
484 
486  virtual makVrf::DtAreaTaskVisualizationPtr areaTaskVisualization(const DtString& name);
487 
489  virtual makVrf::DtTextTaskVisualizationPtr textTaskVisualization(const DtString& name);
490 
492  double calculateNextTaskVisTickTime() const;
493 
495  DtVrfObjectStateRepository* localStateRepository();
496 
499  const DtVrfObjectStateRepository* localStateRepository() const;
500 
506  inline DtPropertyInterface* cachedNextFrameStateProperty(DtPropertyInterface** prop, const DtString& propName);
507 
513  template<typename ValType>
514  inline void setCachedNextFrameStatePropertyValue(DtPropertyInterface** prop, const DtString& propName, ValType value);
515 
521  inline const DtPropertyInterface* cachedCurrentFrameStateProperty(const DtPropertyInterface** prop, const DtString& propName) const;
522 
530  template<typename ValType>
531  bool getCachedCurrentFrameStatePropertyValue(const DtPropertyInterface** prop, const DtString& propName, ValType& value) const;
532 
536 
544  void addSimObjectPredicateCallback(DtSimObjectReference simObject,
546  const DtVrfObjectPredicate& predicate, DtTime evaluationPeriod = 0,
547  void* userData = 0);
554  void removeSimObjectPredicateCallback(const DtSimObject* simObject,
556  const DtVrfObjectPredicate& predicate, DtTime evaluationPeriod = 0,
557  void* userData = 0);
558 
563  void invokeSimObjectPredicateCallbacks();
564 
567  virtual void clearPredicateCallbacks();
569 
570 private:
573  DtSimComponent();
574 
576  DtSimComponent(const DtSimComponent& orig);
577 
580 
581 protected:
584 
588  DtListItem* myListItem;
589 
590  typedef std::map<DtString, DtInputPort*> DtInputPortMap;
591  typedef std::map<DtString, DtOutputPort*> DtOutputPortMap;
592  typedef std::map<DtString, DtInputPortGroup*> DtInputPortGroupMap;
593  typedef std::map<DtString, DtOutputPortGroup*> DtOutputPortGroupMap;
594 
603 
606 
609 
613  std::unique_ptr<DtTimedTickLogic> myTimedTickLogic;
615  double myDT;
616 
620 
624 
627 
630  std::list<DtVrfProcessStateRepository*> myComponentPsrs;
631 
634 
637 
640 
645 
647  boost::signals2::scoped_connection myIsClutterChangedConnection;
648 
651 
652 public:
657 
659  VRF4API_METHOD const DtSimulationServices* simManager() const { return simulationServices(); };
662 };
663 
664 inline double DtSimComponent::dT() const
665 {
666  return myDT;
667 }
668 
670 {
671  if (!*prop)
672  {
674  }
675 
676  return *prop;
677 }
678 
679 template<typename ValType>
680 inline void DtSimComponent::setCachedNextFrameStatePropertyValue(DtPropertyInterface** prop, const DtString& propName, ValType value)
681 {
682  DtPropertyInterface* propIf = cachedNextFrameStateProperty(prop, propName);
683  if (propIf)
684  {
685  propIf->setPropertyValue(value);
686  }
687 }
688 
690 {
691  if (!*prop)
692  {
693  *prop = entity()->stateProperties().findPropertyInterface(propName);
694  }
695 
696  return *prop;
697 }
698 
699 template<typename ValType>
700 bool DtSimComponent::getCachedCurrentFrameStatePropertyValue(const DtPropertyInterface** prop, const DtString& propName, ValType& value) const
701 {
702  const DtPropertyInterface* propIf = cachedCurrentFrameStateProperty(prop, propName);
703  if (propIf)
704  {
705  auto propVal = propIf->propertyValue<ValType>();
706  if (propVal)
707  {
708  value = *propVal;
709  return true;
710  }
711  }
712  else
713  {
714  objectConsoleWarn() << "Could not find state property: " << propName << std::endl;
715  }
716 
717  return false;
718 }
719 
const DtComponentDescriptor * myComponentDescriptor
The descriptor used to configure this component, typically read from an OPD file. ...
Definition: simComponent.h:626
virtual bool postAddComponentsInit()
Called after all components have been created, initialized and added to the component manager...
Definition: simComponent.h:127
This class is used to interface with the terrain a particular entity is &quot;attached&quot; to...
Definition: attachedTerrain.h:57
This class allows one to collect and compare strings using an index number instead of having to do st...
Definition: symbolString.h:27
void setCachedNextFrameStatePropertyValue(DtPropertyInterface **prop, const DtString &propName, ValType value)
Sets the value of a next-frame state property via a cached property interface. The cache pointer is p...
Definition: simComponent.h:680
const DtPropertyInterface * cachedCurrentFrameStateProperty(const DtPropertyInterface **prop, const DtString &propName) const
Returns the cached read-only property interface for a current-frame state property, looking it up and caching the result on first access.
Definition: simComponent.h:689
virtual const DtRwProperties & stateProperties() const
Gets current frame external state properties, unless there are none, in which case it returns the nex...
bool myLocalDebug
Local debug flag for this component instance. If true, debugActive() will return true.
Definition: simComponent.h:650
A DtComponentSystem is a collection of DtSimComponents that are associated with each other...
Definition: componentSystem.h:35
Abstract base class for a small class that tracks the tick period for DtSimComponent.
Definition: timedTickLogic.h:9
DtOutputPortGroupMap myOutputPortGroupList
Map of output port groups registered on this component, keyed by group name.
Definition: simComponent.h:602
virtual DtlObjPtr getData(DtlObjPtr args, const SearchPaths &searchPaths, const DtVariableBindingsList &variableBindings)
Deriving class overrides these to get/put class specific data.
Definition: readerWriter.h:85
The DtSimResourceManager is responsible for managing all of the resources for a given entity...
Definition: simResourceManager.h:18
A readable, writable type whose name is the name of a component and that has a list of component name...
Definition: componentDescriptor.h:49
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:31
Default on in debug, off in release.
Definition: objectCounter.h:27
std::map< DtString, DtInputPort * > DtInputPortMap
Definition: simComponent.h:590
int myPriority
The connection priority of this component; lower values take precedence.
Definition: simComponent.h:608
Definition: readerWriterRegistry.h:39
double myDT
The time delta since the last tick, in seconds.
Definition: simComponent.h:615
class DtSimComponentFactory:
Definition: simComponentFactory.h:36
class DtVrfProcessStateRepositoryManager:
Definition: vrfProcessStateRepositoryManager.h:48
const DtLocalObject * entity() const
Definition: simComponent.h:383
DtOutputPortGroup is a data port group of a data provider. It may contain any number of DtOutputPorts...
Definition: outputPortGroup.h:34
DtLocalObject * myEntity
The local object (entity) that owns this component.
Definition: simComponent.h:583
Description: This repository is an internal repository accessible only by local objects. It holds all information that is common to all the forms of all entity/aggregate/control objects within VR-Forces.
Definition: vrfObjectStateRepository.h:92
DtPredicateCallbackManager * myPredicateCallbackManager
Manages the registered predicate callbacks that are invoked each tick.
Definition: simComponent.h:644
static DtSimComponentFactory * myFactory
The factory used to create DtSimComponent instances.
Definition: simComponent.h:605
virtual DtOutputStream & objectConsoleWarn(const DtString &channel="") const
Interface class used to define minimal interface for a property. The DtPropertyInterface class provid...
Definition: propertyInterface.h:53
virtual void updateTaskVisualizations()
Called to update task visualizations after every tick. Implemented by subclasses. ...
Definition: simComponent.h:471
Contains the DtVrfObjectPredicate class declaration.
Definition: vrfObjectPredicate.h:20
static DtReaderWriterFactory * factory()
makVrf::DtTaskVisualizationMap myTaskVisualizations
The visualization objects to be drawn for this component.
Definition: simComponent.h:633
DtListItem * myListItem
The list item node used for intrusive list membership in DtComponentList.
Definition: simComponent.h:588
DtComponentSystem * mySystem
Pointer to the DtComponentSystem that this component belongs.
Definition: simComponent.h:586
DtInputPortGroupMap myInputPortGroupList
Map of input port groups registered on this component, keyed by group name.
Definition: simComponent.h:600
boost::signals2::scoped_connection myIsClutterChangedConnection
Connection to the entity&#39;s isClutterChanged signal, used to re-enable when clutter state changes...
Definition: simComponent.h:647
The DtPhysicalWorld is the primary interface to and manager of all of the &quot;physical&quot; aspects of the s...
Definition: physicalWorld.h:114
Definition: coordSystem.h:54
#define DT_DLL_vrfobjcore
This file is used to determine how to build.
Definition: vrfobjcoreDefines.h:24
double myLastTickSimTime
The simulation time at which this component was last ticked.
Definition: simComponent.h:611
std::list< const DtRwVariableBindings * > DtVariableBindingsList
Definition: readerWriterRegistry.h:29
File: simMsg.h.
Definition: simMessage.h:35
std::vector< DtFilename > SearchPaths
Definition: readerWriter.h:92
The predicate callback manager allows for registration of callbacks by sim object for predicates...
Definition: predicateCallbackManager.h:20
double dT() const
This is the delta-t for this component, which may or may not be the same as the exerciseClock dT...
Definition: simComponent.h:664
static VRF4API_METHOD DtSimComponent * MarkThreadSafe(DtSimComponent *comp)
This is the deprecated API that can be used as a reference to migrate 4.X code to 5...
Definition: simComponent.h:660
std::map< DtString, DtOutputPortGroup * > DtOutputPortGroupMap
Definition: simComponent.h:593
DtSimComponent *(* DtSimComponentCreatorFcn)(const DtString &name, DtLocalObject *owner, DtSimulationServices *simServices, DtComponentDescriptor *compDescriptor, DtReaderWriterRegistry *registry)
Definition: simComponentFactory.h:25
DtInputPortMap myInputPortList
Map of input ports registered on this component, keyed by port name.
Definition: simComponent.h:596
std::list< DtVrfProcessStateRepository * > myComponentPsrs
List of PSRs created via createComponentPsr() that will be automatically unregistered and deleted whe...
Definition: simComponent.h:630
double myNextTaskVisTickTime
The next tick time for updating the task visualizations.
Definition: simComponent.h:636
bool myFirstTick
Initialized to true in the constructor, set to false by the first call to postTick.
Definition: simComponent.h:623
bool myIsEnabled
Indicates whether this component should be enabled for ticking or not.
Definition: simComponent.h:619
DtOutputPortMap myOutputPortList
Map of output ports registered on this component, keyed by port name.
Definition: simComponent.h:598
DtOutputPorts are data ports owned by data producers. They are connected to DtPortConnections and sen...
Definition: outputPort.h:42
Instances of DtInputPort are are data ports owned by data consumers. They receive data from a DtPortC...
Definition: inputPort.h:42
Central access point of all non-object-specific the services and managers that are available for use ...
Definition: simulationServices.h:97
The DtSimComponent class is the base class for the entire simulation model component hierarchy...
Definition: simComponent.h:89
Definition: vrfObjectPredicateEvaluator.h:17
Represents a single simulation object in the exercise. Object may be VRF simulation, or non-VRF simulated, and may be simulated by the local sim engine, or by a remote sim engine. Only public (external) state of the object is available. All data is read-only. All access to data of the object is thread safe within the simulation frame.
Definition: simObject.h:80
virtual void putData(std::string &fp, int indentLevel=0)
Deriving class overrides these to get/put class specific data.
Class DtVrfProcessStateRepository: Abstract base class for all process state repositories. Process state repositories represent (potentially) shared, savable information for one or more components functioning together to achieve some process or set of processes; such as aiming and firing a weapon; moving an object; or just waiting a specified amount of time.
Definition: vrfProcessStateRepository.h:45
VRF4API_METHOD const DtSimulationServices * simManager() const
This is the deprecated API that can be used as a reference to migrate 4.X code to 5...
Definition: simComponent.h:659
virtual DtRwProperties & nextFrameStateProperties()
Returns the full list of the next frame external state properties. To get the internal state properti...
DT_DLL_DEBUGDRAWRENDERER void init(makVrv::DtDe &de)
Work function for the plugin initialization.
DtInputPortGroup is a data port group of a data consumer. It may contain any number of DtInputPorts a...
Definition: inputPortGroup.h:35
DtLocalObject * entity()
Gets the entity.
Definition: simComponent.h:382
virtual void registerAttributeFunctions()
Called to register functions that provide system attribute values. Called by init(). Empty in this class. Overridden in different components to add attribute provider functions.
Definition: simComponent.h:132
bool getCachedCurrentFrameStatePropertyValue(const DtPropertyInterface **prop, const DtString &propName, ValType &value) const
Gets the value of a current-frame state property via a cached property interface. The cache pointer i...
Definition: simComponent.h:700
const DtReaderWriter & operator=(const DtReaderWriter &orig)
assignment operator
std::map< DtString, DtOutputPort * > DtOutputPortMap
Definition: simComponent.h:591
std::unique_ptr< DtTimedTickLogic > myTimedTickLogic
The logic object that determines when this component should be ticked.
Definition: simComponent.h:613
void(* DtVrfObjectPredicateCallbackFunction)(DtSimObjectReference obj, DtVrfObjectPredicateEvaluator *predicateEval, void *userData)
Definition: simComponent.h:51
makVrf::DtTaskVisualizationMap & taskVisualizations()
Definition: simComponent.h:414
std::map< DtString, DtInputPortGroup * > DtInputPortGroupMap
Definition: simComponent.h:592
DtSimulationServices * mySimServices
Pointer to the simulation services, providing access to the clock, terrain, and messaging.
Definition: simComponent.h:642
1) Define the interface class that will be used to represent the next and current frames...
Definition: taskVisualizationStateComponent.h:300
#define VRF4API_METHOD
Include this header file to allow for the definition/usage of the ability to mark something as deprec...
Definition: vrf4XAPI.h:23
bool setPropertyValue(ValueType val)
Sets the value of this property. If the value cannot be converted from the specified type...
DtSymbolString myFullComponentName
The fully-qualified name of this component, composed of the containing system hierarchy and component...
Definition: simComponent.h:639
std::map< DtTaskVisualizationId, DtTaskVisualizationStateComponent * > DtTaskVisualizationMap
Map from task visualization identifier to its state component pointer.
Definition: taskVisualizationForwards.h:26
DtPropertyInterface * cachedNextFrameStateProperty(DtPropertyInterface **prop, const DtString &propName)
Returns the cached property interface for a next-frame state property, looking it up and caching the ...
Definition: simComponent.h:669
virtual const DtPropertyInterface * findPropertyInterface(const DtString &propertyName) const override
boost::optional< ValueType > propertyValue() const
Returns the value of this property. You can only retrieve the value of properties which can contain s...
A locally simulated VRF object.
Definition: localObject.h:98

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)