VR-Forces 4.1.1 Class Documentation
4.10 - The Resource Manager

Table of Contents

Entities simulated by VR-Forces can track and manage arbitrary resources.

Each VR-Forces entity has a Resource Manager, which is an instance of the class DtObjectResourceManager (objectResourceManager.h). It is accessible through the entity's DtVrfObjectStateRepository, for example:

entity->vrfState()->objectResourceManager()

The DtObjectResourceManager is the top-level resource manager for the entity. The actual resources are stored in DtSimResourceManager instances owned by the DtComponentSystems on the entity, but this manager has access to all these sub-managers, and is able to look up resources in any of them. The DtSimResourceManager associated with a given DtComponentSystem can be reached through the resourceManager() accessor of any of its DtSimComponents. The rest of this section describes the capabilities of DtSimResourceManager. DtSimResourceManager provides an interface for adding, removing, and modifying the resources associated with a DtComponentSystem.

When you use the DtObjectResourceManager to look up resources that are owned by a DtSimResourceManager, the name of the system must be prefixed to the resource name, separated by a period. For example, to get the fuel resource for a ground vehicle, the string would be movement.fuel.

The Resource Manager tracks all consumable resources, which are instances of DtSimResources (simRsrc.h). Resources include such items as fuel, ammunition, water, and whatever else is modeled. The resources are known by a DtString name, so it is easy to support almost any kind of resource you want. The Resource Manager keeps track of the quantity of each resource the entity has, as well as the total amount of each type of resource the entity can hold. During initialization, resource capacity and starting values specified in any DtVrfObjectParameters are copied to the DtSimResourceManager.

The Resource Manager supports subresources. Resources can be grouped to form hierarchical resource lists. For example, an entity could have a resource named ammunition, which has main-gun-ammunition and machine-gun-ammunition as subresources. The main-gun-ammunition resource might have APDS and HEAT as further subresources. In this scheme, a plan or any piece of code could test the amount (or percentage amount) of available ammunition, main-gun-ammunition, APDS, or HEAT. A user could also give 50 rounds of main-gun-ammunition to the entity, which would automatically be distributed between the APDS and HEAT resources.

The DtSimResourceManager maintains a hashlist of all resource names under its control. Given the resources described in the previous paragraph, the Resource Manager would maintain separate hashlist entries for ammunition, main-gun-ammunition, machine-gun-ammunition, APDS, and HEAT. Any of these resources could be looked up by name using the member function lookupResource(). Resources can be added to a DtSimResourceManager using addResource() and removeResource().

The Resource Manager interface allows a DtSimResource to be:

The Resource Manager can report the current amount as a real number or as a percentage. If a resource type that has subresources is filled, the Resource Manager distributes the total resource allotment among the subresources. The individual subresources can be filled, changed, incremented, or decremented, within the limits of the total amount of the parent resource allowed.

The initial resource levels and the organization of resources into subresources are specified as parameters of the entity. The data is saved and restored as part of an entity’s state in the order of battle file. When you load a scenario, each entity’s resource levels are restored to the state they were in when the scenario was saved.

For more information about the Resource Manager, please see 5.6 - Modeling Resource Consumption.

4.10.1 Managing Resources

All resources derive from the abstract class DtSimResource. Since resources can be read from parameter files, DtSimResource provides the standard factory mechanisms, such as:

DtSimResource also provides the basic framework that derived classes can use to create and manage hierarchical resources. These include:

DtSimResource declares several pure virtual functions that derived classes must implement to provide the standard functionality. Whenever the amount of a resource is changed, that resource is responsible for updating its subresources, if any, its parent resource, or both. Call the distributeAmountToChildren() member function to update subresources, if any. If the resource’s parent pointer is non-null, call the parent’s updateAmountFromChildren().

All resources can have a capacity, or ‘full-amount’, specified. If this capacity is changed, a parent resource and any subresources should be updated using the member functions distributeFullAmountToChildren() and updateFullAmountFromChildren().

A resource can be set to have a percentage of its full capacity by calling setPercentageFull() with a value between 0.0 and 1.0. You can find the ratio of the current value over the capacity by calling percentageFull(). These two member functions must also be implemented by derived classes.

For an example of modeling resources, please see 5.6 - Modeling Resource Consumption.

[<< The Set Data Manager] [Home] [Top of Page] [Embarkation >>]


Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)