VR-Engage  2.3
Loading...
Searching...
No Matches
vreJoystickControllerInterface.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2026 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6#pragma once
7
8//! \file vreJoystickControllerInterface.h
9//! \ingroup vreVrfmodel
10//! \brief Internal-state persistence for VRE joystick controllers.
11
12#include "vreVrfmodel/export.h"
13
14#include <vrfmodel/joystickControllerInterface.h>
15
16class DtRwProperties;
17class DtRwPropertiesMap;
18class DtRwPropertiesStructure;
19class DtSimComponent;
20
21namespace makVre
22{
23//! \brief Preserves a controller's joystick connection across ownership handoff.
24//!
25//! Connection hooks persist enabled-state transitions. Device-request overrides persist
26//! count-only changes without duplicating the hook writes. Concrete controllers restore
27//! the saved flag and exact request count during first-tick
28//! initialization after incoming ownership transfer. No handoff listeners are used.
29//! State helpers create VreJoystickControllers.Controllers and its Enabled/RequestCount
30//! structure prototype on demand. SMS internal-state-data declarations are not required.
31//! The ownership-transfer archive carries the property types, prototype, and values.
32//! Static overloads share state persistence with controllers that already inherit
33//! the VRF joystick interface, without adding a second interface subobject.
34class VREVRFMODEL_DLL DtVreJoystickControllerInterface : public DtJoystickControllerInterface
35{
36public:
37 //! \brief Constructs an interface alongside an existing component base.
38 //! \param component Non-null, non-owning component pointer used for controller identity.
39 //! \param owner The owning local object.
40 //! \param simManager Simulation services.
41 //! \param desc The joystick controller descriptor.
43 DtSimComponent* component, DtLocalObject* owner, DtSimulationServices* simManager, DtComponentDescriptor* desc);
44
45 //! \brief Destroys the interface; the VRF base removes its message callbacks.
47
48 //! \brief Writes joystick state for a controller with an existing VRF interface.
49 //! \param component The component whose full name identifies the state entry.
50 //! \param owner The owning local object.
51 //! \param enabled The existing interface's enabled flag.
52 //! \param requestCount The existing interface's exact request count.
53 //! \note Creates missing internal-state storage without replacing restored properties.
54 static void updateJoystickState(DtSimComponent& component, DtLocalObject& owner, bool enabled, int requestCount);
55
56 //! \brief Restores state without accessing another controller's protected interface members.
57 //! \param component The component whose full name identifies the state entry.
58 //! \param owner The owning local object.
59 //! \param incomingTransfer True only for the first initialization after incoming ownership transfer.
60 //! \param enabled The existing interface's enabled flag, updated on restoration.
61 //! \param requestCount The existing interface's request count, updated on restoration.
62 //! \param hasDescriptor Whether the existing interface has a valid joystick descriptor.
63 //! \return True if enabled state was restored. The caller must then register its original
64 //! joystick-input callback with its adjusted VRF interface pointer and call joystickConnected().
65 //! False means no reconnection is required; malformed state is logged and left unchanged.
66 static bool restoreJoystickState(DtSimComponent& component,
67 DtLocalObject& owner,
68 bool incomingTransfer,
69 bool& enabled,
70 int& requestCount,
71 bool hasDescriptor);
72
73 //! \brief Deleted copy constructor and assignment operator to prevent copying.
78
79protected:
80 //! \brief Writes the current enabled flag and request count to this controller's internal-state entry.
81 //! \note Call from joystickConnected() and joystickDisconnected().
83
84 //! \brief Restores an incoming controller's saved state during first-tick initialization.
85 //! \note Does not reconnect on ordinary construction, scenario loading, or rewind.
87
88 //! \brief Keeps the saved count current for requests that do not invoke connection hooks.
89 //! \param msg The original joystick device request message.
90 //! \note Calls the VRF handler once; connection transitions are persisted by their hooks.
91 virtual void processJoyDeviceRequest(DtSimMessage* msg) override;
92
93private:
94 //! \brief Creates the typed controller-state map in the supplied context.
95 //! \return Non-owning pointer to the map owned by context, or nullptr if creation fails.
96 static DtRwPropertiesMap* createJoystickStateMap(DtRwProperties& context, DtLocalObject& owner);
97
98 //! \brief Finds and validates a controller's state, creating missing storage only when requested.
99 //! \return Non-owning pointer to the entity-owned state, or nullptr if absent or invalid.
100 static DtRwPropertiesStructure* joystickStateProperties(
101 DtSimComponent& component, DtLocalObject& owner, bool create);
102
103 //! \brief Non-owning reference used to identify this controller's state entry.
104 DtSimComponent& myJoystickComponent;
105
106 //! \brief Remembers incoming conversion because the owner clears it before first-tick initialization.
108};
109} // namespace makVre
bool myRestoreJoystickState
Remembers incoming conversion because the owner clears it before first-tick initialization.
Definition vreJoystickControllerInterface.h:107
virtual ~DtVreJoystickControllerInterface() override
Destroys the interface; the VRF base removes its message callbacks.
void restoreJoystickState()
Restores an incoming controller's saved state during first-tick initialization.
static bool restoreJoystickState(DtSimComponent &component, DtLocalObject &owner, bool incomingTransfer, bool &enabled, int &requestCount, bool hasDescriptor)
Restores state without accessing another controller's protected interface members.
DtSimComponent & myJoystickComponent
Non-owning reference used to identify this controller's state entry.
Definition vreJoystickControllerInterface.h:104
DtVreJoystickControllerInterface(const DtVreJoystickControllerInterface &)=delete
Deleted copy constructor and assignment operator to prevent copying.
virtual void processJoyDeviceRequest(DtSimMessage *msg) override
Keeps the saved count current for requests that do not invoke connection hooks.
static DtRwPropertiesStructure * joystickStateProperties(DtSimComponent &component, DtLocalObject &owner, bool create)
Finds and validates a controller's state, creating missing storage only when requested.
DtVreJoystickControllerInterface & operator=(const DtVreJoystickControllerInterface &)=delete
DtVreJoystickControllerInterface & operator=(DtVreJoystickControllerInterface &&)=delete
static void updateJoystickState(DtSimComponent &component, DtLocalObject &owner, bool enabled, int requestCount)
Writes joystick state for a controller with an existing VRF interface.
static DtRwPropertiesMap * createJoystickStateMap(DtRwProperties &context, DtLocalObject &owner)
Creates the typed controller-state map in the supplied context.
DtVreJoystickControllerInterface(DtVreJoystickControllerInterface &&)=delete
void updateJoystickState()
Writes the current enabled flag and request count to this controller's internal-state entry.
DtVreJoystickControllerInterface(DtSimComponent *component, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc)
Constructs an interface alongside an existing component base.
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
!
Definition glsVreMessageUtil.h:50