VR-Engage  2.2
Loading...
Searching...
No Matches
vreMunitionLoader.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreMunitionLoader.h
7//! \ingroup vreVrfobjcore
8//! \brief Munition loader class for VREngage
9//!
10//! This file defines the DtVreMunitionLoader class, which extends the basic VRF munition
11//! loader to provide VREngage-specific munition loading behavior. It manages weapon
12//! ammunition loading states and related state properties for displaying ammunition
13//! counts in user interfaces.
14#pragma once
15
17
18#include <vrfobjcore/vrfMunitionLoader.h>
19
20namespace makVre
21{
22//! \brief Extended munition loader with VREngage-specific functionality
23//!
24//! This class extends the basic VRF munition loader to provide VREngage-specific
25//! munition loading behavior. It adds support for controlling weapon state during
26//! loading (such as lowering/raising the weapon), managing ammunition-related
27//! state properties for UI display, and handling weapon state restoration when
28//! loading from saved scenarios.
29class VREVRFOBJCORE_DLL DtVreMunitionLoader : public DtVrfMunitionLoader
30{
31public:
32 //! \brief Constructor with optional name
33 //! \param rwName Optional reader/writer name
34 //! \param parentRegistry Optional parent registry for reader/writer functionality
35 //!
36 //! Creates a new munition loader with the specified name.
37 DtVreMunitionLoader(const DtString& rwName = DtString::nullString(), DtReaderWriterRegistry* parentRegistry = 0);
38
39 //! \brief Copy constructor
40 //! \param orig The source munition loader to copy from
41 //! \param rwName Optional reader/writer name
42 //! \param parentRegistry Optional parent registry for reader/writer functionality
43 //!
44 //! Creates a new munition loader as a copy of the provided original.
45 DtVreMunitionLoader(const DtVreMunitionLoader& orig, const DtString& rwName = DtString::nullString(),
46 DtReaderWriterRegistry* parentRegistry = 0);
47
48 //! \brief Assignment operator
49 //! \param orig The source munition loader to copy from
50 //! \return Reference to this munition loader after assignment
51 //!
52 //! Assigns the contents of the provided munition loader to this one.
54
55 //! \brief Virtual destructor
56 //!
57 //! Cleans up resources used by the munition loader.
58 virtual ~DtVreMunitionLoader() override;
59
60 //! \brief Initializes the munition loader with an entity
61 //! \param entity Pointer to the entity this loader is associated with
62 //! \return True if initialization was successful, false otherwise
63 //!
64 //! Initializes the munition loader and sets up callbacks for state restoration.
65 //! Adds the setRestoredCallback to reinitialize AmmoInClips state properties
66 //! when the entity is restored from a saved scenario.
67 virtual bool init(DtLocalObject* entity);
68
69 //! \brief Updates the munition loader state
70 //! \param correctMunition The current munition type
71 //! \param correctFuze The current fuze type
72 //! \param currentTime The current simulation time
73 //! \param roundsAvailable Number of rounds available to load (default: 1)
74 //!
75 //! Updates the munition loader state based on the current time and availability.
76 //! Overridden to implement VREngage-specific behavior such as lowering the gun
77 //! while loading and raising it once done.
78 virtual void tick(const DtSimMunition& correctMunition,
79 DtDetonatorFuze correctFuze,
80 DtTime currentTime,
81 int roundsAvailable = 1) override;
82
83 //! \brief Uses a specified number of rounds from the magazine
84 //! \param nRounds The number of rounds to consume
85 //!
86 //! Decrements the ammunition count by the specified number of rounds.
87 //! Overridden to update the state properties with the number of rounds
88 //! left in the clip for UI display and networking purposes.
89 virtual void useRounds(const int nRounds) override;
90
91 //! \brief Initializes a clip state property
92 //! \param name The name of the weapon system for this clip
93 //!
94 //! Initializes the state property used to track and display the ammunition count
95 //! for the specified weapon system. This property will be used for UI display
96 //! and networking to clients.
98
99 //! \brief Disables thresholding for ammunition state properties
100 //!
101 //! Disables the thresholding setting for clip state properties to send updates
102 //! every frame. This ensures that player-controlled entities receive the most
103 //! accurate data for displaying ammunition counts in the HUD.
105
106 //! \brief Enables thresholding for ammunition state properties
107 //!
108 //! Enables the thresholding setting for clip state properties to reduce network
109 //! traffic. Updates are not sent as frequently for entities that are not under
110 //! player control since precise ammunition display is less critical.
112
113 //! \brief Begins loading a munition into the weapon system.
114 //! \param startLoadTime The simulation time at which loading begins.
115 //! \param munition The munition type to be loaded.
116 //! \param fuze The fuze type to be used with the munition.
117 //!
118 //! Starts the loading process for the specified munition and fuze at the given simulation time.
119 //! This overrides the base implementation to also initialize the clip state property, ensuring
120 //! that ammunition counts are properly tracked and updated for UI and networking. This is
121 //! important for accurate display of ammunition status in the HUD and for synchronizing state
122 //! across clients.
123 virtual void load(DtTime startLoadTime, const DtSimMunition& munition, DtDetonatorFuze fuze) override;
124
125protected:
126 //! \brief Sets the thresholding algorithm for ammunition state properties
127 //! \param thresholdAlgorithm The threshold algorithm to use (DtThresholdPercent or DtThresholdNone)
128 //!
129 //! Sets the thresholding approach for clip state properties. Set thresholdAlgorithm
130 //! to DtThresholdPercent to throttle sending of state updates, or DtThresholdNone
131 //! to send updates every frame.
132 virtual void setAmmoStatePropertiesThresholdAlgorithm(int thresholdAlgorithm);
133
134 //! \brief Static callback for state restoration
135 //! \param msg Pointer to the simulation message
136 //! \param usrData User data pointer containing the munition loader instance
137 //!
138 //! Static callback function called when the entity is restored from a saved
139 //! scenario. Sets the myReinitialize flag to true to trigger state property
140 //! reinitialization on the next tick.
141 static void setRestoredCallback(DtSimMessage* msg, void* usrData);
142
143 //! \brief Processes a state restoration message
144 //! \param msg Pointer to the simulation message
145 //!
146 //! Processes a state restoration message by setting the reinitialization flag.
147 virtual void processSetRestored(DtSimMessage* msg);
148
149 //! \brief Pointer to the associated entity
150 //!
151 //! Stores a pointer to the entity this munition loader is associated with.
152 DtLocalObject* myEntity;
153
154 //! \brief Reinitialization flag
155 //!
156 //! When true, the state properties will be reinitialized on the next tick.
157 //! This is typically set after a state restoration operation.
159};
160} // namespace makVre
DtVreMunitionLoader(const DtVreMunitionLoader &orig, const DtString &rwName=DtString::nullString(), DtReaderWriterRegistry *parentRegistry=0)
Copy constructor.
virtual void useRounds(const int nRounds) override
Uses a specified number of rounds from the magazine.
virtual ~DtVreMunitionLoader() override
Virtual destructor.
virtual void tick(const DtSimMunition &correctMunition, DtDetonatorFuze correctFuze, DtTime currentTime, int roundsAvailable=1) override
Updates the munition loader state.
virtual void setAmmoStatePropertiesThresholdAlgorithm(int thresholdAlgorithm)
Sets the thresholding algorithm for ammunition state properties.
virtual void enableAmmoStatePropertiesThresholding()
Enables thresholding for ammunition state properties.
virtual void processSetRestored(DtSimMessage *msg)
Processes a state restoration message.
bool myReinitialize
Reinitialization flag.
Definition vreMunitionLoader.h:158
virtual void initializeClipStateProperty()
Initializes a clip state property.
virtual void load(DtTime startLoadTime, const DtSimMunition &munition, DtDetonatorFuze fuze) override
Begins loading a munition into the weapon system.
const DtVreMunitionLoader & operator=(const DtVreMunitionLoader &orig)
Assignment operator.
static void setRestoredCallback(DtSimMessage *msg, void *usrData)
Static callback for state restoration.
DtLocalObject * myEntity
Pointer to the associated entity.
Definition vreMunitionLoader.h:152
virtual bool init(DtLocalObject *entity)
Initializes the munition loader with an entity.
DtVreMunitionLoader(const DtString &rwName=DtString::nullString(), DtReaderWriterRegistry *parentRegistry=0)
Constructor with optional name.
virtual void disableAmmoStatePropertiesThresholding()
Disables thresholding for ammunition state properties.
Export macros for the VREngage Object Core library.
#define VREVRFOBJCORE_DLL
Platform-specific DLL export/import declaration.
Definition export.h:27
Include export definitions for this library.
Definition glsVreMessageUtil.h:49