26#include <vrfmsgs/setDataRequestMessage.h>
28#include <vrfobjcore/physicalWorld.h>
29#include <vrfobjcore/setDataManager.h>
30#include <vrfobjcore/localObject.h>
31#include <vrfobjcore/vrfMovingObjectStateRepository.h>
32#include <vrfobjcore/attachedTerrain.h>
34#include <vrftasks/setAltitudeRequest.h>
35#include <vrftasks/setDataRequest.h>
37#include <vrfutil/kinematicTools.h>
39#include <terrainCS/coordSystem.h>
41#include <vlutil/vlString.h>
43class DtSimulationServices;
44class DtComponentDescriptor;
45class DtReaderWriterRegistry;
63template <
typename SetControllerBase>
77 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0)
78 :
DtVreSimComponent<SetControllerBase>(name, owner, simManager, desc, parentRegistry)
89 this->entity()->setDataManager()->removeSetDataCallback(
101 SetControllerBase::setRadio(radio);
103 this->entity()->setDataManager()->addSetDataProcessorCallback(
133 DtSetDataRequestMessage* drMsg =
static_cast<DtSetDataRequestMessage*
>(msg);
146 std::vector<std::string> keys = change.
myRoles;
152 if (thisStation.isEmpty())
155 <<
"VRE set role controlled request has blank station id. Unable to identify controlling station."
157 thisStation =
"UNKNOWN";
161 thisStation =
"{" + thisStation +
"}";
163 for (
int i = 0; i < keys.size(); i++)
165 std::string stations = this->entity()
166 ->getStateComponent<makVrf::DtVrfStateComponent>()
167 ->extendedData(
"role-" + keys[i])
171 if (stations.find(thisStation) == -1)
174 this->entity()->getNextFrameStateComponent<makVrf::DtVrfStateComponent>()->setExtendedData(
175 "role-" + keys[i], stations + thisStation);
182 if (thisStation.isEmpty())
185 <<
"VRE set role controlled request has blank station id. Unable to identify controlling station."
187 thisStation =
"UNKNOWN";
189 thisStation =
"{" + thisStation +
"}";
191 for (
int i = 0; i < keys.size(); i++)
193 std::string stations = this->entity()
194 ->getStateComponent<makVrf::DtVrfStateComponent>()
195 ->extendedData(
"role-" + keys[i])
198 int foundAt = stations.find(thisStation);
202 std::string pre = stations.substr(0, foundAt);
203 std::string post = stations.substr(foundAt + thisStation.length());
204 stations = pre + post;
206 if (stations.empty())
208 this->entity()->getNextFrameStateComponent<makVrf::DtVrfStateComponent>()->removeExtendedData(
213 this->entity()->getNextFrameStateComponent<makVrf::DtVrfStateComponent>()->setExtendedData(
214 "role-" + keys[i], stations);
230 for (
const std::pair<DtString, DtString>& data :
231 this->entity()->getStateComponent<makVrf::DtVrfStateComponent>()->extendedData())
233 if (data.first.findString(
"role-") == 0)
235 this->entity()->getNextFrameStateComponent<makVrf::DtVrfStateComponent>()->removeExtendedData(data.first);
274 DtSetDataRequestMessage* drMsg = (DtSetDataRequestMessage*)msg;
275 DtSetAltitudeRequest* req = (DtSetAltitudeRequest*)drMsg->setDataRequest();
278 DtVrfObjectStateRepository* vrfObjSR = this->localStateRepository();
284 double altitude = req->altitude();
286 DtTerrainIntersectStatus status;
288 double terrainHeight = this->physicalWorld()->terrainHeight(this->entity()->nextFrameLocalPosition(), status,
289 DtTerrainIntersectOptions::nonBlocking().withMask(
290 this->entity()->parameters()->movementTerrainCategoryMask()));
292 if (status.dataAvailable())
298 if (status.dataAvailable())
300 altitude = terrainHeight;
305 if (status.dataAvailable())
307 altitude += terrainHeight;
314 if (status.dataAvailable())
316 if (DtALMOST(terrainHeight, altitude, 1.0))
323 DtGeodeticCoord newGeodeticPosition;
324 newGeodeticPosition.setGeocentric(this->entity()->nextFrameWorldPosition());
325 newGeodeticPosition.setAlt(altitude);
326 this->objectConsoleDebug(this->type()) <<
"Setting altitude: " << altitude << std::endl;
328 DtVector newLocalPosition;
329 this->terrainAttachedTo()->coordinateSystem()->dis2local(newGeodeticPosition.geocentric(), newLocalPosition);
332 DtVrfMovingObjectStateRepository* movingSR = vrfObjSR->as<DtVrfMovingObjectStateRepository>();
336 movingSR->setAmClampedToGround(clamp);
339 this->entity()->internalState()->place(newLocalPosition);
363 static DtSimComponent*
creator(
const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
364 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0)
Provides assertion macros and functions for error detection and handling.
Request to set the VREngage control state of an entity.
Definition setVreControlled.h:38
virtual unsigned stationId() const
Gets the published ID of the player station.
virtual bool playerStationControlled() const
Gets the player station control state.
virtual std::vector< std::string > roles() const
Gets the controlled roles for the entity.
std::list< SetVreControlledContent > myPendingControlChanges
Definition vreSetController.h:396
virtual void setRadio(DtSimRadio *radio)
Sets the simulation radio and registers callbacks.
Definition vreSetController.h:99
DtVreSetController()
Default constructor (not implemented)
virtual ~DtVreSetController() override
Virtual destructor.
Definition vreSetController.h:87
virtual void processSetPlayerControlled(DtSimMessage *msg)
Processes a VR-Engage control assignment message.
Definition vreSetController.h:131
virtual void updatePlayerControlled(const SetVreControlledContent &change)
Definition vreSetController.h:144
bool myWarnedAboutResource
Flag indicating if a resource warning has been logged.
Definition vreSetController.h:394
virtual void processSetAltitude(DtSimMessage *msg)
Processes altitude setting messages with enhanced terrain handling.
Definition vreSetController.h:272
static DtSimComponent * creator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Factory method to create a new instance of this component.
Definition vreSetController.h:363
DtVreSetController(const DtVreSetController &orig)
Copy constructor (not implemented)
virtual void tick()
Updates the controller state each simulation frame.
Definition vreSetController.h:248
const DtVreSetController & operator=(const DtVreSetController &orig)
Assignment operator (not implemented)
static void setPlayerControlledCallback(DtSimMessage *msg, void *usrData)
Static callback function for player control messages.
Definition vreSetController.h:113
DtVreSetController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
Definition vreSetController.h:76
virtual void preFirstTickInit()
Initializes the controller before the first tick.
Definition vreSetController.h:227
DtVreSimComponent(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Definition vreSimComponent.h:54
bool isPlayerControlled(const std::string &role="") const
Definition vreSimComponent.h:76
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
Provides logging functionality with various severity levels and channels.
#define LOG_WARN(channel)
Macro to log a warning message to log files.
Definition logger.h:69
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
const DtSetMessageType DtSetVreControlledType("set-vre-controlled")
Message type for VREngage control state requests.
VREngage control state request message.
Definition vreSetController.h:119
std::vector< std::string > myRoles
Definition vreSetController.h:122
DtString myStationId
Definition vreSetController.h:121
bool myControlled
Definition vreSetController.h:120
Base template class for VR-Engage simulation components.