CTR Pia  4.11.3
Game Communication Engine
reckoning_Simple3dReckoningStrategy.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: reckoning_Simple3dReckoningStrategy.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/reckoning/reckoning_definitions.h>
18 #include <pia/reckoning/reckoning_Vector3f.h>
19 #include <pia/reckoning/reckoning_ReckoningCloneElementBase.h>
20 #include <pia/clone/clone_CloneBase.h>
21 
22 namespace nn
23 {
24 namespace pia
25 {
26 namespace reckoning
27 {
28 
29 /*!
30 @brief The <tt>ReckoningStrategy</tt> class interpolates 3D vectors using linear evaluation functions.
31 
32 @date 2013-10-29 Initial version.
33 */
35 {
36 public:
37  typedef Vector3f Value; //!< Specifies the type of value that is set and retrieved using <tt>SetValue</tt> and <tt>GetValue</tt>.
38 
39 /*!
40 @brief Contains a value and a stop flag as a set.
41 */
42  struct SampleValue
43  {
44  Value m_Value;
45  bool m_IsStop;
46  };
47  typedef SampleValue Sample; //!< Specifies the actual type of the sample that is sent and received.
48 
49  typedef bool SetValueArg; //!< Specifies the type of data to pass to <tt>CheckSample</tt> and <tt>MakeSample</tt> when calling <tt>SetValue</tt>.
50 
51 /*!
52 @brief Stores the pre-calculated result for prediction.
53 */
54  struct Work {
55  Value m_Param;
56  Value m_ParamBase;
57  nn::pia::clone::ClockValue m_BaseClock;
58  };
59 
60  static const size_t BUFFER_SIZE = 10; //!< Specifies the size of the buffer that holds samples.
61 
62  typedef ReckoningCloneElementBase::SampleAccessor<Sample> Accessor; //!< Defines the accessor for the sample buffer.
63 
64 /*!
65 @brief Instantiates the object with default parameters (default constructor).
66 @param[in] threshold Specifies the threshold value to use for determination.
67 */
68  Simple3dReckoningStrategy(f32 threshold);
69 
70 /*!
71 @brief Sets the threshold to use when determining whether to use the <tt><var>value</var></tt> set using <tt>SetValue</tt> as a sample.
72 @param[in] threshold Specifies the threshold value to use for determination.
73 */
74  void SetThreshold(f32 threshold);
75 
76 /*!
77 @brief Gets the threshold to use when determining whether to use the <tt><var>value</var></tt> set using <tt>SetValue</tt> as a sample.
78 @return Returns the threshold value to use for determination.
79 */
81  {
82  return m_Threshold;
83  }
84 
85 /*!
86 @brief Calculates the prediction.
87 @param[out] pValue Outputs the prediction.
88 @param[in] accessor Specifies the accessor for the sample buffer.
89 @param[in] clock Specifies the current clock.
90 @param[in] cpWork Specifies the pre-calculated result for calculating the prediction.
91 @return Returns <tt>true</tt> and stores the prediction in <tt><var>pValue</var></tt> if successful.
92 */
93  bool Estimate(Value* pValue, const Accessor& accessor, nn::pia::clone::ClockValue clock, const Work* cpWork) const;
94 
95 /*!
96 @brief Determines whether to use the <tt><var>value</var></tt> set with <tt>SetValue</tt> as a sample.
97 @param[out] pIsReliable Outputs whether reliable communication needs to be used when sending the sample.
98 @param[in] value Specify the value that was set with <tt>SetValue</tt>.
99 @param[in] cpSetValueArg Specify the value that was set in the second parameter of <tt>SetValue</tt>. This flag specifies whether <tt><var>value</var></tt> is stopped.
100 @param[in] accessor Specifies the accessor for the sample buffer.
101 @param[in] clock Specifies the current clock.
102 @param[in] cpWork Specifies the pre-calculated result for calculating the prediction.
103 @return Returns <tt>true</tt> if the value will be used as a sample.
104 */
105  bool CheckSample(bool* pIsReliable, const Value& value, const SetValueArg* cpSetValueArg, const Accessor& accessor, nn::pia::clone::ClockValue clock, const Work* cpWork) const;
106 
107 /*!
108 @brief Calculates the value to save as a sample.
109 @details This is called when <tt>CheckSample</tt> determines the value is to be used as a sample and the buffer was successfully allocated.
110 @param[out] pSample Outputs the sample.
111 @param[in] value Specify the value that was set with <tt>SetValue</tt>.
112 @param[in] cpSetValueArg Specify the value that was set in the second parameter of <tt>SetValue</tt>. This flag specifies whether <tt><var>value</var></tt> is stopped.
113 @param[in] accessor Specifies the accessor for the sample buffer.
114 @param[in] clock Specifies the current clock.
115 @param[in] cpWork Specifies the pre-calculated result for calculating the prediction.
116 */
117  void MakeSample(Sample* pSample, const Value& value, const SetValueArg* cpSetValueArg, const Accessor& accessor, nn::pia::clone::ClockValue clock, const Work* cpWork) const;
118 
119 /*!
120 @brief This is called when a sample is added.
121 @details This function updates the parameters used to calculate the prediction.
122 @param[in] accessor Specifies the accessor for the sample buffer.
123 @param[in] index Specifies the index of the sample.
124 @param[in] pWork Specifies the pre-calculated result for calculating the prediction.
125 */
126  void OnUpdateSample(const Accessor& accessor, int index, Work* pWork) const;
127 
128 /*!
129 @brief Prints information that is useful for debugging.
130 
131 @param[in] flag Specifies the bitwise OR of trace flags. For more information, see the <tt>@ref TraceFlag</tt> type.
132 */
133  void Trace(u64 flag) const;
134 
135 protected:
136 private:
137  f32 m_Threshold;
138  s32 m_DelayClock;
139 };
140 }
141 }
142 } // end of namespace nn::pia::reckoning
Stores the pre-calculated result for prediction.
Definition: reckoning_Simple3dReckoningStrategy.h:54
void MakeSample(Sample *pSample, const Value &value, const SetValueArg *cpSetValueArg, const Accessor &accessor, nn::pia::clone::ClockValue clock, const Work *cpWork) const
Calculates the value to save as a sample.
u32 ClockValue
Defines a type that holds a clock value.
Definition: clone_definitions.h:44
static const size_t BUFFER_SIZE
Specifies the size of the buffer that holds samples.
Definition: reckoning_Simple3dReckoningStrategy.h:60
The ReckoningStrategy class interpolates 3D vectors using linear evaluation functions.
Definition: reckoning_Simple3dReckoningStrategy.h:34
void OnUpdateSample(const Accessor &accessor, int index, Work *pWork) const
This is called when a sample is added.
Definition: assert.h:115
bool SetValueArg
Specifies the type of data to pass to CheckSample and MakeSample when calling SetValue.
Definition: reckoning_Simple3dReckoningStrategy.h:49
Contains member functions used to access values in the sample buffer.
Definition: reckoning_ReckoningCloneElementBase.h:261
Contains a value and a stop flag as a set.
Definition: reckoning_Simple3dReckoningStrategy.h:42
bool CheckSample(bool *pIsReliable, const Value &value, const SetValueArg *cpSetValueArg, const Accessor &accessor, nn::pia::clone::ClockValue clock, const Work *cpWork) const
Determines whether to use the value set with SetValue as a sample.
bool Estimate(Value *pValue, const Accessor &accessor, nn::pia::clone::ClockValue clock, const Work *cpWork) const
Calculates the prediction.
Vector3f Value
Specifies the type of value that is set and retrieved using SetValue and GetValue.
Definition: reckoning_Simple3dReckoningStrategy.h:37
The Vector3f class provides functionality for the strategy used to handle 3D vectors.
Definition: reckoning_Vector3f.h:32
Simple3dReckoningStrategy(f32 threshold)
Instantiates the object with default parameters (default constructor).
void Trace(u64 flag) const
Prints information that is useful for debugging.
SampleValue Sample
Specifies the actual type of the sample that is sent and received.
Definition: reckoning_Simple3dReckoningStrategy.h:47
ReckoningCloneElementBase::SampleAccessor< Sample > Accessor
Defines the accessor for the sample buffer.
Definition: reckoning_Simple3dReckoningStrategy.h:62
f32 GetThreshold()
Gets the threshold to use when determining whether to use the value set using SetValue as a sample...
Definition: reckoning_Simple3dReckoningStrategy.h:80
void SetThreshold(f32 threshold)
Sets the threshold to use when determining whether to use the value set using SetValue as a sample...