VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Modeling Resources in a System

Some models need to track consumption of resources, such as fuel or munitions.

Each DtSimComponentNetwork maintains its own set of resources in a DtSimResourceManager. Each component in a DtComponentSystem has a reference to this manager. A component that uses resources must look up the actual resource by name through its resourceManager() member. If no DtComponentSystem has been explicitly configured in an entity’s parameters, the resourceManager() function returns a pointer to the implicitly created base DtComponentSystem’s resource manager.

Once you have a pointer to the resource, you can determine its current level, and modify it as needed. For example, the DtAutomotiveActuatorComponent has a useFuel() member function, which is called in its tick() member function. It decrements the fuel in the entity by a given amount, as follows:

{
if (resource)
{
DtString resourceType = resource->type();
if (resourceType == DtRealResourceType)
{
DtRealResource * realResource = (DtRealResource *)resource;
if (realResource->amount() <= fuelUsed)
{
DtWarn("%s out of fuel.\n", entity()->markingText().string());
realResource->setAmount(0.);
}
else
{
realResource->setAmount(realResource->amount() - fuelUsed);
}
}
else if (resourceType == DtIntegerResourceType)
{
DtIntegerResource* intResource =
dynamic_cast<DtIntegerResource*>(resource);
assert(intResource);
if (intResource->amount() <= (int)fuelUsed)
{
DtWarn("%s out of fuel.\n", entity()->markingText().string());
intResource->setAmount(0);
}
else
{
intResource->setAmount(
static_cast<int> (intResource->amount() - fuelUsed));
}
}
}
}

The actual types and amounts of each resource are configured in the object parameter database. (For details, please see Resource Manager.)


Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)