![]() |
VR-Forces 4.1 Class Documentation
|
This subclass of DtVrfMovingObjectStateRepository adds reader/writer variables that will store new entity information so it can be written to the order of battle file
In DtSpaceEntityStateRepository, we must implement the following functions for our class to work correctly in the context of a VR-Forces application:
The constructor sets up the object to be readable and writable. State repository classes derive from DtReaderWriter, which gives them the ability to be read from file a and write to a file. The default constructor is not used.
DtSpaceEntityParameters::DtSpaceEntityParameters(const DtString& name, DtReaderWriterRegistry* parentRegistry) : DtMovingObjectParameters(name, parentRegistry) { }
The type() function returns a string that uniquely identifies the state repository class. It is used as a key in the state repository factory. State repository types are defined in vrfSRTypes.h. Make sure the string returned by your type() function does not conflict with an existing type.
const char DtSpaceVehicleSRType[] = "space-vehicle-state-repository"; DtString DtSpaceEntityParameters::type() const { return DtSpaceVehicleParamType; }
The static creator() function is registered with the state repository factory. It should return a newly created instance of the derived class.
DtSimObjectStateRepository* DtSpaceEntityStateRepository::creator( const DtString& name, DtVrfObject* vrfObject, const DtObjectType& objectType, DtVrfObjectParameters* parameters, DtReaderWriterRegistry* parentRegistry) { return new DtSpaceEntityStateRepository((DtVrfObject*)vrfObject, ObjectType, parameters, name, parentRegistry); }
The creator function must be registered with the DtSpaceVehicleStateRepository type with the state repository factory. For details, see "Adding the New State Repository and Parameters to VR-Forces".
In this example, we add one member variable, myMaxHullTemperature and accessor and mutator methods for this variable. This makes it possible for any controller and actuator components to view or modify this state in the entity.
class DtSpaceEntityStateRepository : public DtVrfMovingObjectStateRepository { public: . . . virtual void setMaxHullTemperature(DtReal temp); virtual DtReal maxHullTemperature() const; protected: DtReal myMaxHullTemperature; }; void DtSpaceEntityStateRepository::setMaxHullTemperature(DtReal temp) { myMaxHullTemperature = temp; } DtReal DtSpaceEntityStateRepository::maxHullTemperature() const { return myMaxHullTemperature; }