VR-Forces 4.5 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Space Entity Repository

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


Components of a State Repository

In DtSpaceEntityStateRepository, we must implement the following functions for our class to work correctly in the context of a VR-Forces application:

The Constructor

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

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 creator() function

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".

Adding the New Data Member to the Class

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;
  }
  

Header file:

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: spaceSR.h,v $ $Revision: 1.12 $ $State: Exp $
*******************************************************************************/
//
//File: spaceSR.h
//
//Class: DtSpaceEntityStateRepository
//
//Description: This repository holds all information that is common to all the
//forms of space entities within the system. It contains a pointer
//to the space entity parameters, and provides accessors and mutators
//for all parameter values. In this example, we add a single new parameter,
//myCurrentHullTemperature, representing the current hull temperature of this
//(e.g. such as during reentry). Any future controller and actuator components
//we build to simulate the entity's behavior can view or set this new parameter as necessary.
//
#ifndef DtSpaceEntityStateRepository_H_
#define DtSpaceEntityStateRepository_H_
#include <vlutil/vlMachineTypes.h>
{
public:
//Constructor with parameters to set up read/writability correctly.
const DtString& name, DtReaderWriterRegistry* parentRegistry = 0);
//copy constructor
//assignment operator
//destructor
virtual bool init();
//Returns a unique string identifying the type of component,
//DtSpaceVehicleSRType (defined in spacetypes.h). Used a key in
//the state repository factory.
virtual DtString type() const;
//Override to create an instance DtSpaceEntityParameters and
//set it in myParameters data member.
virtual bool createParameters();
//Report hull temperature every 10 seconds
virtual void tick();
//Override to initialize space entity specific parameters from
//our parameters object.
virtual void initializeFromParameters();
//Implemented for convenience. Since we overrode createParameters()
//to create a DtSpaceEntityParameters object (a derived kind of
//DtSimObjectParameters), we provide an accessor casting it to the
//dervied type.
//Accessor/mutator for our new parameter, myCurrentHullTemperature.
//Set/get hull temperature this entity can sustain (degrees C).
virtual void setCurrentHullTemperature(DtReal temp);
virtual DtReal currentHullTemperature() const;
//Returns a newly created instance of this class. To be registered
//with the state repository factory.
//Returns a the pointer the repository, if the repository passed
//in is of type DtSpaceEntityStateRepository, 0 if not. Implmementation
//is optional - may be useful for safe type checking.
const DtVrfObjectStateRepository* repository);
protected:
//Current hull temperature (in degrees Celsius).
};
#endif

Implementation:

/*******************************************************************************
** Copyright (c) 2015 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include "spaceSR.h"
#include "spacePar.h"
#include "spaceTypes.h"
#include <matrix/vlVector.h>
//constructor with parameters to set up read/writability correctly
DtVrfObject* vrfObject, const DtObjectType& objectType,
DtVrfObjectParameters* parameters, const DtString& name,
DtReaderWriterRegistry* parentRegistry) :
DtFixedWingEntityStateRepository(vrfObject, objectType, parameters, name,
parentRegistry),
myCurrentHullTemperature("current-hull-temperature", 1260.0, &myRegistry),
myLastHullTemperatureTime(-1.)
{
}
//copy constructor
myCurrentHullTemperature(orig.myCurrentHullTemperature, &myRegistry)
{
}
//assignment operator
{
if (this == &orig)
{
return *this;
}
return *this;
}
//destructor
{
}
{
}
{
if ((myLastHullTemperatureTime == -1.) ||
{
mySimObject->objectConsoleDebug() << "Hull temperature: " << myCurrentHullTemperature << std::endl;
}
}
{
{
delete myParameters;
myParameters = NULL;
}
if (myParameters == NULL)
{
return false;
}
return true;
}
{
DtInfo << "Initializing DtSpaceEntityStateRepository..." << std::endl;
DtInfo << "Max hull temp retrieved from DtSpaceEntityParameters: '" << maxTemp
<< "'." << std::endl;
myCurrentHullTemperature = maxTemp / 2.0;
//Set the value specified to false to insure that it will be written to the
//order of battle file as "USE-DEFAULT" unless its value gets changed
//somewhere else.
DtInfo << "DtSpaceEntityStateRepository initialized hull temperature to: '" <<
myCurrentHullTemperature << "'." << std::endl;
}
{
//Use the parameters() accessor instead of myParameters member directly.
//(myParameters will be created on demand in the parameters() accessor.)
}
const DtVrfObjectStateRepository* repository)
{
if (repository->type() == DtSpaceVehicleSRType )
{
return (DtSpaceEntityStateRepository*) repository;
}
return 0;
}
{
}
const DtString& name, DtVrfObject* vrfObject,
const DtObjectType& objectType, DtVrfObjectParameters* parameters,
DtReaderWriterRegistry* parentRegistry)
{
return new DtSpaceEntityStateRepository((DtVrfObject*)vrfObject, objectType,
parameters, name, parentRegistry);
}
{
}
{
}

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)