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 <boost/shared_ptr.hpp>
24 
25 #include <vlutil/vlHashlist.h>
26 #include <vlutil/vlString.h>
27 #include <vlutil/vlList.h>
28 
29 #include <list>
30 
32 class DtInputPort;
33 class DtOutputPort;
34 class DtInputPortGroup;
35 class DtOutputPortGroup;
36 class DtPhysicalWorld;
37 class Coordinate_System;
38 class DtComponentSystem;
42 class DtLocalObject;
43 class DtSimObject;
45 class DtSimMessage;
46 class DtAttachedTerrain;
51 class DtTimedTickLogic;
52 
55  void* userData);
56 
59 #define CACHED_NEXT_FRAME_STATE_PROPERTY(property) \
60  DtPropertyInterface* myNextFrame##property = 0;
61 #define SET_CACHED_STATE_PROPERTY(property, value) \
62  setCachedNextFrameStatePropertyValue(&myNextFrame##property, #property, value);
63 
64 #define CACHED_CURRENT_FRAME_STATE_PROPERTY(property) \
65  const DtPropertyInterface* myCurrFrame##property = 0;
66 #define GET_CACHED_STATE_PROPERTY_VALUE(property, value) \
67  getCachedCurrentFrameStatePropertyValue(&myCurrFrame##property, #property, value);
68 
69 
70 
92 #ifdef DtObjectDebugger_Enable
93  , public DtObjectDebugger<DtSimComponent>
94 #endif
95 {
96 public:
97 
105  DtSimComponent(const DtString& name,
106  DtLocalObject* owner,
107  DtSimulationServices* simServices,
108  DtComponentDescriptor* desc = 0,
109  DtReaderWriterRegistry* parentRegistry = 0);
110 
112  virtual ~DtSimComponent();
113 
118  virtual void setParentSystem(DtComponentSystem* system);
119  DtComponentSystem * parentSystem() const;
120 
123  virtual bool init();
124 
128  virtual bool postAddComponentsInit() { return true; }
129 
133  virtual void registerAttributeFunctions(){}
134 
138  virtual void enable();
139  virtual void disable();
140  virtual bool isEnabled();
141  virtual void setIsEnabled(bool yesNo);
143 
147  virtual void preFirstTickInit();
148 
152  virtual void tick();
153 
157  virtual void postTick();
158 
166  virtual void timedTick();
167 
171  virtual void setMinTickPeriod(double minTickPeriod, double minTickPeriodVariance);
172 
175  virtual void setupFirstTickTime();
176 
183  virtual const char* type() const = 0;
184 
191  virtual void setEntity(DtLocalObject* entity);
192 
194  virtual DtSimComponent* nextComponent();
195  virtual DtSimComponent* prevComponent();
196 
198  virtual void setListItem(DtListItem* item);
199  virtual DtListItem* listItem();
200 
203  virtual void putData(std::string& fp, int indentLevel = 0);
204 
207  virtual DtlObjPtr getData(DtlObjPtr args, const DtReaderWriter::SearchPaths& searchPaths,
208  const DtVariableBindingsList& variableBindings);
209 
212  virtual void addInputPort(DtInputPort* port);
213  virtual void removeInputPort(DtInputPort* port);
214 
220  virtual DtInputPort* lookupInputPort(const DtString& portName);
221 
223  virtual DtList inputPortList() const;
224 
227  virtual void addOutputPort(DtOutputPort* port);
228  virtual void removeOutputPort(DtOutputPort* port);
229 
235  virtual DtOutputPort* lookupOutputPort(const DtString& portName);
236 
238  virtual DtList outputPortList() const;
239 
242  virtual void addInputPortGroup(DtInputPortGroup* group);
243  virtual void removeInputPortGroup(DtInputPortGroup* group);
244 
247  virtual DtInputPortGroup* lookupInputPortGroup(const DtString& groupName);
248 
250  virtual DtList inputPortGroupList() const;
251 
254  virtual void addOutputPortGroup(DtOutputPortGroup* group);
255  virtual void removeOutputPortGroup(DtOutputPortGroup* group);
256 
259  virtual DtOutputPortGroup* lookupOutputPortGroup(const DtString& groupName);
260 
262  virtual DtList outputPortGroupList() const;
263 
270  virtual int priority() const;
276  virtual void setPriority(int priority);
277 
281  double dT() const;
282 
287  virtual void setDT(double deltaT);
288 
292  virtual void setComponentDescriptor(DtComponentDescriptor* componentDescriptor);
293  virtual const DtComponentDescriptor* componentDescriptor() const;
294 
299  virtual bool tickWhileDestroyed() const;
300 
306  virtual DtOutputStream& objectConsoleDebug(const DtString& channel = "") const;
308  virtual DtOutputStream& objectConsoleVerbose(const DtString& channel = "") const;
310  virtual DtOutputStream& objectConsoleInfo(const DtString& channel = "") const;
312  virtual DtOutputStream& objectConsoleWarn(const DtString& channel = "") const;
314  virtual DtOutputStream& objectConsoleError(const DtString& channel = "") const;
315  virtual int notifyLevel() const;
317 
323 
326 
327  virtual DtSimResourceManager& resourceManager();
328  virtual const DtSimResourceManager& resourceManager() const;
330 
334  virtual const DtSymbolString& componentFullName() const;
335 
339  static DtSimComponentFactory* factory();
340  static void setFactory(DtSimComponentFactory* factory);
341 
344  static DtSimComponent* createComponent(const DtString& name,
345  const DtString& type, DtLocalObject* owner, DtSimulationServices* simManager, DtComponentSystem* parentSystem,
346  DtComponentDescriptor* desc = 0,
347  DtReaderWriterRegistry* parentRegistry = 0);
348 
354  static void addSimComponentCreatorFcn(const DtString& type,
356 
358  DtPhysicalWorld* physicalWorld();
359  const DtPhysicalWorld* physicalWorld() const;
360 
362  const DtAttachedTerrain* terrainAttachedTo() const;
363 
365  DtLocalObject* entity() { return myEntity; }
366  const DtLocalObject* entity() const { return myEntity; };
367 
369  DtSimulationServices* simulationServices();
370  const DtSimulationServices* simulationServices() const;
371 
376  const Coordinate_System* coordinateSystem() const;
377 
379  virtual void isClutterChanged();
380 
384  virtual bool taskVisualizationsActive() const;
385 
391  virtual bool taskVisualizationsEnabled() const;
392 
394  virtual void onRestore();
395 
397  {
398  return myTaskVisualizations;
399  }
400 
401 protected:
402 
403  virtual void setupTimedTickLogic(double minTickPeriod, double minTickPeriodVariance);
404 
406  virtual double computeCurrentTime();
407 
412  bool testInvariant() const;
413 
417  virtual bool createPortGroups();
418 
422  virtual bool createPorts();
423 
432  DtVrfProcessStateRepository* createComponentPsr(const DtString& defaultPsrType,
433  const DtString& defaultPsrName, bool useDescriptorParams = true);
434 
437  virtual void updateTaskVisualizations() {};
438 
440  virtual void destroyTaskVisualizations();
441 
443  virtual void destroyTaskVisualization(const DtString& name);
444 
446  virtual makVrf::DtPointTaskVisualizationPtr pointTaskVisualization(const DtString& name);
447 
449  virtual makVrf::DtLineTaskVisualizationPtr lineTaskVisualization(const DtString& name);
450 
452  virtual makVrf::DtAreaTaskVisualizationPtr areaTaskVisualization(const DtString& name);
453 
455  virtual makVrf::DtTextTaskVisualizationPtr textTaskVisualization(const DtString& name);
456 
458  double calculateNextTaskVisTickTime() const;
459 
461  DtVrfObjectStateRepository* localStateRepository();
462 
465  const DtVrfObjectStateRepository* localStateRepository() const;
466 
467  inline DtPropertyInterface* cachedNextFrameStateProperty(DtPropertyInterface** prop, const DtString& propName);
468 
469  template<typename ValType>
470  inline void setCachedNextFrameStatePropertyValue(DtPropertyInterface** prop, const DtString& propName, ValType value);
471 
472  inline const DtPropertyInterface* cachedCurrentFrameStateProperty(const DtPropertyInterface** prop, const DtString& propName) const;
473 
474  template<typename ValType>
475  bool getCachedCurrentFrameStatePropertyValue(const DtPropertyInterface** prop, const DtString& propName, ValType& value) const;
476 
480 
484  void addSimObjectPredicateCallback(DtSimObjectReference,
486  const DtVrfObjectPredicate& predicate, DtTime evaluationPeriod = 0,
487  void* userData = 0);
488  void removeSimObjectPredicateCallback(const DtSimObject*,
490  const DtVrfObjectPredicate& predicate, DtTime evaluationPeriod = 0,
491  void* userData = 0);
492 
497  void invokeSimObjectPredicateCallbacks();
498 
501  virtual void clearPredicateCallbacks();
503 
504 private:
507  DtSimComponent();
508 
510  DtSimComponent(const DtSimComponent& orig);
511 
514 
515 protected:
517 
520  DtListItem* myListItem;
521 
522  typedef std::map<DtString, DtInputPort*> DtInputPortMap;
523  typedef std::map<DtString, DtOutputPort*> DtOutputPortMap;
524  typedef std::map<DtString, DtInputPortGroup*> DtInputPortGroupMap;
525  typedef std::map<DtString, DtOutputPortGroup*> DtOutputPortGroupMap;
526 
531 
533 
535 
537  std::unique_ptr<DtTimedTickLogic> myTimedTickLogic;
538  double myDT;
539 
543 
547 
549 
552  std::list<DtVrfProcessStateRepository*> myComponentPsrs;
553 
556 
559 
561 
564 
565  boost::signals2::scoped_connection myIsClutterChangedConnection;
566 
567 public:
572 
574  VRF4API_METHOD const DtSimulationServices* simManager() const { return simulationServices(); };
577 };
578 
579 inline double DtSimComponent::dT() const
580 {
581  return myDT;
582 }
583 
585 {
586  if (!*prop)
587  {
589  }
590 
591  return *prop;
592 }
593 
594 template<typename ValType>
595 inline void DtSimComponent::setCachedNextFrameStatePropertyValue(DtPropertyInterface** prop, const DtString& propName, ValType value)
596 {
597  DtPropertyInterface* propIf = cachedNextFrameStateProperty(prop, propName);
598  if (propIf)
599  {
600  propIf->setPropertyValue(value);
601  }
602 }
603 
605 {
606  if (!*prop)
607  {
608  *prop = entity()->stateProperties().findPropertyInterface(propName);
609  }
610 
611  return *prop;
612 }
613 
614 template<typename ValType>
615 bool DtSimComponent::getCachedCurrentFrameStatePropertyValue(const DtPropertyInterface** prop, const DtString& propName, ValType& value) const
616 {
617  const DtPropertyInterface* propIf = cachedCurrentFrameStateProperty(prop, propName);
618  if (propIf)
619  {
620  auto propVal = propIf->propertyValue<ValType>();
621  if (propVal)
622  {
623  value = *propVal;
624  return true;
625  }
626  }
627  else
628  {
629  objectConsoleWarn() << "Could not find state property: " << propName << std::endl;
630  }
631 
632  return false;
633 }
634 
const DtComponentDescriptor * myComponentDescriptor
Definition: simComponent.h:548
virtual bool postAddComponentsInit()
Called after all components have been created, initialized and added to the component manager...
Definition: simComponent.h:128
Definition: attachedTerrain.h:46
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:595
const DtPropertyInterface * cachedCurrentFrameStateProperty(const DtPropertyInterface **prop, const DtString &propName) const
Definition: simComponent.h:604
virtual const DtRwProperties & stateProperties() const
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:530
virtual DtlObjPtr getData(DtlObjPtr args, const SearchPaths &searchPaths, const DtVariableBindingsList &variableBindings)
Deriving class overrides these to get/put class specific data.
The DtSimObjectReference is a shared pointer that can be used amongst many object for access to the u...
Definition: simObjectReference.h:26
Definition: readerWriter.h:85
class DtSimResourceManager:
Definition: simResourceManager.h:38
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:522
int myPriority
Definition: simComponent.h:534
Definition: readerWriterRegistry.h:39
double myDT
Definition: simComponent.h:538
class DtSimComponentFactory:
Definition: simComponentFactory.h:36
class DtVrfProcessStateRepositoryManager:
Definition: vrfProcessStateRepositoryManager.h:49
const DtLocalObject * entity() const
Definition: simComponent.h:366
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:516
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:563
static DtSimComponentFactory * myFactory
Definition: simComponent.h:532
virtual DtOutputStream & objectConsoleWarn(const DtString &channel="") const
Interface class used to define minimal interface for a property. The DtPropertyInterface class provid...
Definition: propertyInterface.h:48
virtual void updateTaskVisualizations()
Called to update task visualizations after every tick. Implemented by subclasses. ...
Definition: simComponent.h:437
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:555
DtListItem * myListItem
Definition: simComponent.h:520
DtComponentSystem * mySystem
Pointer to the DtComponentSystem that this component belongs.
Definition: simComponent.h:519
DtInputPortGroupMap myInputPortGroupList
Definition: simComponent.h:529
boost::signals2::scoped_connection myIsClutterChangedConnection
Definition: simComponent.h:565
The DtPhysicalWorld is the primary interface to and manager of all of the &quot;physical&quot; aspects of the s...
Definition: physicalWorld.h:102
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:536
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:579
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:575
std::map< DtString, DtOutputPortGroup * > DtOutputPortGroupMap
Definition: simComponent.h:525
DtSimComponent *(* DtSimComponentCreatorFcn)(const DtString &name, DtLocalObject *owner, DtSimulationServices *simServices, DtComponentDescriptor *compDescriptor, DtReaderWriterRegistry *registry)
Definition: simComponentFactory.h:25
DtInputPortMap myInputPortList
Definition: simComponent.h:527
std::list< DtVrfProcessStateRepository * > myComponentPsrs
List of PSRs made using createComponentPsr() that will be deleted by this component when it is destro...
Definition: simComponent.h:552
double myNextTaskVisTickTime
The next tick time for updating the task visualizations.
Definition: simComponent.h:558
bool myFirstTick
Initialized to true in the constructor, set to false by the first call to postTick.
Definition: simComponent.h:546
bool myIsEnabled
Indicates whether this component should be enabled for ticking or not.
Definition: simComponent.h:542
DtOutputPortMap myOutputPortList
Definition: simComponent.h:528
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:94
The DtSimComponent class is the base class for the entire simulation model component hierarchy...
Definition: simComponent.h:91
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:88
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:574
virtual DtRwProperties & nextFrameStateProperties()
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:365
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:133
bool getCachedCurrentFrameStatePropertyValue(const DtPropertyInterface **prop, const DtString &propName, ValType &value) const
Definition: simComponent.h:615
const DtReaderWriter & operator=(const DtReaderWriter &orig)
assignment operator
std::map< DtString, DtOutputPort * > DtOutputPortMap
Definition: simComponent.h:523
std::unique_ptr< DtTimedTickLogic > myTimedTickLogic
Definition: simComponent.h:537
void(* DtVrfObjectPredicateCallbackFunction)(DtSimObjectReference obj, DtVrfObjectPredicateEvaluator *predicateEval, void *userData)
Definition: simComponent.h:53
makVrf::DtTaskVisualizationMap & taskVisualizations()
Definition: simComponent.h:396
std::map< DtString, DtInputPortGroup * > DtInputPortGroupMap
Definition: simComponent.h:524
DtSimulationServices * mySimServices
Definition: simComponent.h:562
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:22
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:560
std::map< DtTaskVisualizationId, DtTaskVisualizationStateComponent * > DtTaskVisualizationMap
Definition: taskVisualizationForwards.h:20
DtPropertyInterface * cachedNextFrameStateProperty(DtPropertyInterface **prop, const DtString &propName)
Definition: simComponent.h:584
boost::optional< ValueType > propertyValue() const
Returns the value of this property. If the value cannot be converted to the specified type...
A locally simulated VRF object. Holds all internal and external data for the object, and provides access to both the current frame and next frame state data for the object. All current frame data is read-only, and next-frame data can be written to. No thread safety guarantees are made on this object during the simulation frame and it should only be accessed by the thread that is simulating the object.
Definition: localObject.h:86
virtual const DtPropertyInterface * findPropertyInterface(const DtString &propertyName) const

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)