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);
117  DtComponentSystem * parentSystem() const;
118 
121  virtual bool init();
122 
126  virtual bool postAddComponentsInit() { return true; }
127 
131  virtual void registerAttributeFunctions(){}
132 
136  virtual void enable();
137  virtual void disable();
138  virtual bool isEnabled();
139  virtual void setIsEnabled(bool yesNo);
141 
145  virtual void preFirstTickInit();
146 
150  virtual void tick();
151 
155  virtual void postTick();
156 
164  virtual void timedTick();
165 
169  virtual void setMinTickPeriod(double minTickPeriod, double minTickPeriodVariance);
170 
173  virtual void setupFirstTickTime();
174 
181  virtual const char* type() const = 0;
182 
189  virtual void setEntity(DtLocalObject* entity);
190 
192  virtual DtSimComponent* nextComponent();
193  virtual DtSimComponent* prevComponent();
194 
196  virtual void setListItem(DtListItem* item);
197  virtual DtListItem* listItem();
198 
201  virtual void putData(std::string& fp, int indentLevel = 0) override;
202 
205  virtual DtlObjPtr getData(DtlObjPtr args, const DtReaderWriter::SearchPaths& searchPaths,
206  const DtVariableBindingsList& variableBindings) override;
207 
210  virtual void addInputPort(DtInputPort* port);
211  virtual void removeInputPort(DtInputPort* port);
212 
218  virtual DtInputPort* lookupInputPort(const DtString& portName);
219 
221  virtual DtList inputPortList() const;
222 
225  virtual void addOutputPort(DtOutputPort* port);
226  virtual void removeOutputPort(DtOutputPort* port);
227 
233  virtual DtOutputPort* lookupOutputPort(const DtString& portName);
234 
236  virtual DtList outputPortList() const;
237 
240  virtual void addInputPortGroup(DtInputPortGroup* group);
241  virtual void removeInputPortGroup(DtInputPortGroup* group);
242 
245  virtual DtInputPortGroup* lookupInputPortGroup(const DtString& groupName);
246 
248  virtual DtList inputPortGroupList() const;
249 
252  virtual void addOutputPortGroup(DtOutputPortGroup* group);
253  virtual void removeOutputPortGroup(DtOutputPortGroup* group);
254 
257  virtual DtOutputPortGroup* lookupOutputPortGroup(const DtString& groupName);
258 
260  virtual DtList outputPortGroupList() const;
261 
268  virtual int priority() const;
274  virtual void setPriority(int priority);
275 
279  double dT() const;
280 
285  virtual void setDT(double deltaT);
286 
290  virtual void setComponentDescriptor(DtComponentDescriptor* componentDescriptor);
291  virtual const DtComponentDescriptor* componentDescriptor() const;
292 
297  virtual bool tickWhileDestroyed() const;
298 
304  virtual DtOutputStream& objectConsoleDebug(const DtString& channel = "") const;
306  virtual DtOutputStream& objectConsoleVerbose(const DtString& channel = "") const;
308  virtual DtOutputStream& objectConsoleInfo(const DtString& channel = "") const;
310  virtual DtOutputStream& objectConsoleWarn(const DtString& channel = "") const;
312  virtual DtOutputStream& objectConsoleError(const DtString& channel = "") const;
313  virtual int notifyLevel() const;
315 
321 
324 
325  virtual DtSimResourceManager& resourceManager();
326  virtual const DtSimResourceManager& resourceManager() const;
328 
332  virtual const DtSymbolString& componentFullName() const;
333 
337  static DtSimComponentFactory* factory();
338  static void setFactory(DtSimComponentFactory* factory);
339 
342  static DtSimComponent* createComponent(const DtString& name,
343  const DtString& type, DtLocalObject* owner, DtSimulationServices* simManager, DtComponentSystem* parentSystem,
344  DtComponentDescriptor* desc = 0,
345  DtReaderWriterRegistry* parentRegistry = 0);
346 
352  static void addSimComponentCreatorFcn(const DtString& type,
354 
356  DtPhysicalWorld* physicalWorld();
357  const DtPhysicalWorld* physicalWorld() const;
358 
360  const DtAttachedTerrain* terrainAttachedTo() const;
361 
363  DtLocalObject* entity() { return myEntity; }
364  const DtLocalObject* entity() const { return myEntity; };
365 
367  DtSimulationServices* simulationServices();
368  const DtSimulationServices* simulationServices() const;
369 
374  const Coordinate_System* coordinateSystem() const;
375 
377  virtual void isClutterChanged();
378 
382  virtual bool taskVisualizationsActive() const;
383 
389  virtual bool taskVisualizationsEnabled() const;
390 
392  virtual void onRestore();
393 
395  {
396  return myTaskVisualizations;
397  }
398 
401  virtual void updateImgui();
402 
405  virtual bool debugActive() const;
406 
407 protected:
408 
409  virtual void setupTimedTickLogic(double minTickPeriod, double minTickPeriodVariance);
410 
412  virtual double computeCurrentTime();
413 
418  bool testInvariant() const;
419 
423  virtual bool createPortGroups();
424 
428  virtual bool createPorts();
429 
438  DtVrfProcessStateRepository* createComponentPsr(const DtString& defaultPsrType,
439  const DtString& defaultPsrName, bool useDescriptorParams = true);
440 
443  virtual void updateTaskVisualizations() {};
444 
446  virtual void destroyTaskVisualizations();
447 
449  virtual void destroyTaskVisualization(const DtString& name);
450 
452  virtual makVrf::DtPointTaskVisualizationPtr pointTaskVisualization(const DtString& name);
453 
455  virtual makVrf::DtLineTaskVisualizationPtr lineTaskVisualization(const DtString& name);
456 
458  virtual makVrf::DtAreaTaskVisualizationPtr areaTaskVisualization(const DtString& name);
459 
461  virtual makVrf::DtTextTaskVisualizationPtr textTaskVisualization(const DtString& name);
462 
464  double calculateNextTaskVisTickTime() const;
465 
467  DtVrfObjectStateRepository* localStateRepository();
468 
471  const DtVrfObjectStateRepository* localStateRepository() const;
472 
473  inline DtPropertyInterface* cachedNextFrameStateProperty(DtPropertyInterface** prop, const DtString& propName);
474 
475  template<typename ValType>
476  inline void setCachedNextFrameStatePropertyValue(DtPropertyInterface** prop, const DtString& propName, ValType value);
477 
478  inline const DtPropertyInterface* cachedCurrentFrameStateProperty(const DtPropertyInterface** prop, const DtString& propName) const;
479 
480  template<typename ValType>
481  bool getCachedCurrentFrameStatePropertyValue(const DtPropertyInterface** prop, const DtString& propName, ValType& value) const;
482 
486 
490  void addSimObjectPredicateCallback(DtSimObjectReference,
492  const DtVrfObjectPredicate& predicate, DtTime evaluationPeriod = 0,
493  void* userData = 0);
494  void removeSimObjectPredicateCallback(const DtSimObject*,
496  const DtVrfObjectPredicate& predicate, DtTime evaluationPeriod = 0,
497  void* userData = 0);
498 
503  void invokeSimObjectPredicateCallbacks();
504 
507  virtual void clearPredicateCallbacks();
509 
510 private:
513  DtSimComponent();
514 
516  DtSimComponent(const DtSimComponent& orig);
517 
520 
521 protected:
523 
526  DtListItem* myListItem;
527 
528  typedef std::map<DtString, DtInputPort*> DtInputPortMap;
529  typedef std::map<DtString, DtOutputPort*> DtOutputPortMap;
530  typedef std::map<DtString, DtInputPortGroup*> DtInputPortGroupMap;
531  typedef std::map<DtString, DtOutputPortGroup*> DtOutputPortGroupMap;
532 
537 
539 
541 
543  std::unique_ptr<DtTimedTickLogic> myTimedTickLogic;
544  double myDT;
545 
549 
553 
555 
558  std::list<DtVrfProcessStateRepository*> myComponentPsrs;
559 
562 
565 
567 
570 
571  boost::signals2::scoped_connection myIsClutterChangedConnection;
572 
575 
576 public:
581 
583  VRF4API_METHOD const DtSimulationServices* simManager() const { return simulationServices(); };
586 };
587 
588 inline double DtSimComponent::dT() const
589 {
590  return myDT;
591 }
592 
594 {
595  if (!*prop)
596  {
598  }
599 
600  return *prop;
601 }
602 
603 template<typename ValType>
604 inline void DtSimComponent::setCachedNextFrameStatePropertyValue(DtPropertyInterface** prop, const DtString& propName, ValType value)
605 {
606  DtPropertyInterface* propIf = cachedNextFrameStateProperty(prop, propName);
607  if (propIf)
608  {
609  propIf->setPropertyValue(value);
610  }
611 }
612 
614 {
615  if (!*prop)
616  {
617  *prop = entity()->stateProperties().findPropertyInterface(propName);
618  }
619 
620  return *prop;
621 }
622 
623 template<typename ValType>
624 bool DtSimComponent::getCachedCurrentFrameStatePropertyValue(const DtPropertyInterface** prop, const DtString& propName, ValType& value) const
625 {
626  const DtPropertyInterface* propIf = cachedCurrentFrameStateProperty(prop, propName);
627  if (propIf)
628  {
629  auto propVal = propIf->propertyValue<ValType>();
630  if (propVal)
631  {
632  value = *propVal;
633  return true;
634  }
635  }
636  else
637  {
638  objectConsoleWarn() << "Could not find state property: " << propName << std::endl;
639  }
640 
641  return false;
642 }
643 
const DtComponentDescriptor * myComponentDescriptor
Definition: simComponent.h:554
virtual bool postAddComponentsInit()
Called after all components have been created, initialized and added to the component manager...
Definition: simComponent.h:126
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)
Definition: simComponent.h:604
const DtPropertyInterface * cachedCurrentFrameStateProperty(const DtPropertyInterface **prop, const DtString &propName) const
Definition: simComponent.h:613
virtual const DtRwProperties & stateProperties() const
Gets current frame state properties, unless there are none, in which case it returns the next frame s...
bool myLocalDebug
Local debug flag for this component instance. If true, debugActive() will return true.
Definition: simComponent.h:574
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
Definition: simComponent.h:536
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
class DtSimResourceManager:
Definition: simResourceManager.h:19
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:528
int myPriority
Definition: simComponent.h:540
Definition: readerWriterRegistry.h:39
double myDT
Definition: simComponent.h:544
class DtSimComponentFactory:
Definition: simComponentFactory.h:36
class DtVrfProcessStateRepositoryManager:
Definition: vrfProcessStateRepositoryManager.h:49
const DtLocalObject * entity() const
Definition: simComponent.h:364
DtOutputPortGroup is a data port group of a data provider. It may contain any number of DtOutputPorts...
Definition: outputPortGroup.h:34
DtLocalObject * myEntity
Definition: simComponent.h:522
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:91
DtPredicateCallbackManager * myPredicateCallbackManager
Definition: simComponent.h:569
static DtSimComponentFactory * myFactory
Definition: simComponent.h:538
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:443
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:561
DtListItem * myListItem
Definition: simComponent.h:526
DtComponentSystem * mySystem
Pointer to the DtComponentSystem that this component belongs.
Definition: simComponent.h:525
DtInputPortGroupMap myInputPortGroupList
Definition: simComponent.h:535
boost::signals2::scoped_connection myIsClutterChangedConnection
Definition: simComponent.h:571
The DtPhysicalWorld is the primary interface to and manager of all of the &quot;physical&quot; aspects of the s...
Definition: physicalWorld.h:112
Definition: coordSystem.h:54
#define DT_DLL_vrfobjcore
This file is used to determine how to build.
Definition: vrfobjcoreDefines.h:24
double myLastTickSimTime
Definition: simComponent.h:542
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:588
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:584
std::map< DtString, DtOutputPortGroup * > DtOutputPortGroupMap
Definition: simComponent.h:531
DtSimComponent *(* DtSimComponentCreatorFcn)(const DtString &name, DtLocalObject *owner, DtSimulationServices *simServices, DtComponentDescriptor *compDescriptor, DtReaderWriterRegistry *registry)
Definition: simComponentFactory.h:25
DtInputPortMap myInputPortList
Definition: simComponent.h:533
std::list< DtVrfProcessStateRepository * > myComponentPsrs
List of PSRs made using createComponentPsr() that will be deleted by this component when it is destro...
Definition: simComponent.h:558
double myNextTaskVisTickTime
The next tick time for updating the task visualizations.
Definition: simComponent.h:564
bool myFirstTick
Initialized to true in the constructor, set to false by the first call to postTick.
Definition: simComponent.h:552
bool myIsEnabled
Indicates whether this component should be enabled for ticking or not.
Definition: simComponent.h:548
DtOutputPortMap myOutputPortList
Definition: simComponent.h:534
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:96
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:583
virtual DtRwProperties & nextFrameStateProperties()
Returns the full list of the next frame external state properties. NB: To get the internal state prop...
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:363
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:131
bool getCachedCurrentFrameStatePropertyValue(const DtPropertyInterface **prop, const DtString &propName, ValType &value) const
Definition: simComponent.h:624
const DtReaderWriter & operator=(const DtReaderWriter &orig)
assignment operator
std::map< DtString, DtOutputPort * > DtOutputPortMap
Definition: simComponent.h:529
std::unique_ptr< DtTimedTickLogic > myTimedTickLogic
Definition: simComponent.h:543
void(* DtVrfObjectPredicateCallbackFunction)(DtSimObjectReference obj, DtVrfObjectPredicateEvaluator *predicateEval, void *userData)
Definition: simComponent.h:51
makVrf::DtTaskVisualizationMap & taskVisualizations()
Definition: simComponent.h:394
std::map< DtString, DtInputPortGroup * > DtInputPortGroupMap
Definition: simComponent.h:530
DtSimulationServices * mySimServices
Definition: simComponent.h:568
1) Define the interface class that will be used to represent the next and current frames...
Definition: taskVisualizationStateComponent.h:260
#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
Definition: simComponent.h:566
std::map< DtTaskVisualizationId, DtTaskVisualizationStateComponent * > DtTaskVisualizationMap
Definition: taskVisualizationForwards.h:20
DtPropertyInterface * cachedNextFrameStateProperty(DtPropertyInterface **prop, const DtString &propName)
Definition: simComponent.h:593
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 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)