CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
reckoning_Simple3dReckoningStrategy.h
1 /*--------------------------------------------------------------------------------*
2  Copyright (C)Nintendo All rights reserved.
3 
4  These coded instructions, statements, and computer programs contain proprietary
5  information of Nintendo and/or its licensed developers and are protected by
6  national and international copyright laws. They may not be disclosed to third
7  parties or copied or duplicated in any form, in whole or in part, without the
8  prior written consent of Nintendo.
9 
10  The content herein is highly confidential and should be handled accordingly.
11  *--------------------------------------------------------------------------------*/
12 
13 
14 #pragma once
15 
16 #include <nn/pia/reckoning/reckoning_Definitions.h>
17 #include <nn/pia/reckoning/reckoning_Vector3f.h>
18 #include <nn/pia/reckoning/reckoning_ReckoningCloneElementBase.h>
19 #include <nn/pia/clone/clone_CloneBase.h>
20 #include <nn/pia/clone/clone_SerializePolicyDefinition.h>
21 
22 namespace nn
23 {
24 namespace pia
25 {
26 namespace reckoning
27 {
28 
29 /*!
30  @brief 線形の評価関数を用いて3次元ベクトルを補間するReckoningStrategyクラスです。
31  */
33 {
34 public:
35  typedef Vector3f Value; //!< SetValue(), GetValue() で設定/取得する値の型です。
36 
37  /*!
38  @brief 値と停止フラグをセットにした構造体です。
39  */
40  struct SampleValue
41  {
42  Value m_Value;
43  bool m_IsStop;
44  };
45  typedef SampleValue Sample; //!< 実際に送受信される標本値の型です。
46 
47  typedef bool SetValueArg; //!< SetValue() 呼び出し時に、 CheckSample(), MakeSample() に渡すデータの型です。
48 
49  /*!
50  @brief 推測の計算のための事前計算結果を保持しておく構造体です。
51  */
52  struct Work
53  {
54  Value m_Param;
55  Value m_ParamBase;
56  nn::pia::clone::ClockValue m_BaseClock;
57  };
58 
59  static const uint32_t BufferSize = 10; //!< 標本値を保持しておくバッファのサイズです。
60 
61  typedef ReckoningCloneElementBase::SampleAccessor<Sample> Accessor; //!< 標本値バッファへのアクセサです。
62 
63  /*!
64  @brief デフォルトコンストラクタです。
65  @param[in] threshold 判定の際に用いる閾値の値
66  */
67  Simple3dReckoningStrategy(float threshold);
68 
69  /*!
70  @brief SetValue() で設定した値 value を標本値として採用するかどうかを判定する際に使用する閾値の値を設定します。
71  @param[in] threshold 判定の際に用いる閾値の値
72  */
73  void SetThreshold(float threshold);
74 
75  /*!
76  @brief SetValue() で設定した値 value を標本値として採用するかどうかを判定する際に使用する閾値の値を返します。
77  @return 判定の際に用いる閾値の値
78  */
79  float GetThreshold()
80  {
81  return m_Threshold;
82  }
83 
84  /*!
85  @brief 推測値を計算します。
86  @param[out] pValue 推測値を出力します。
87  @param[in] accessor 標本値バッファへのアクセサです。
88  @param[in] clock 現在の時刻を与えます。
89  @param[in] cpWork 推測の計算のための事前計算結果を与えます。
90  @return 推測値が計算できた場合、pValueに値を格納し、trueを返します。
91  */
92  bool Estimate(Value* pValue, const Accessor& accessor, nn::pia::clone::ClockValue clock, const Work* cpWork) const;
93 
94  /*!
95  @brief SetValue() で設定した値 value を標本値として採用するかどうかを判定します。
96  @param[out] pIsReliable 標本値の送信にあたり到達保証をする必要があるかどうかを出力します。
97  @param[in] value SetValue() で設定した値を与えます。
98  @param[in] cpSetValueArg SetValue() の第2引数に設定した値を与えます。valueが停止しているかどうかのフラグを与えます。
99  @param[in] accessor 標本値バッファへのアクセサです。
100  @param[in] clock 現在の時刻を渡します。
101  @param[in] cpWork 推測の計算のための事前計算結果を渡します。
102  @return 標本値として採用する場合、trueを返します。
103  */
104  bool CheckSample(bool* pIsReliable, const Value& value, const SetValueArg* cpSetValueArg, const Accessor& accessor, nn::pia::clone::ClockValue clock, const Work* cpWork) const;
105 
106  /*!
107  @brief 標本値として保存する値を計算します。
108  @details CheckSample() で標本値として採用するよう判定され、実際にバッファが確保できた場合に呼び出されます。
109  @param[out] pSample 標本値を出力します。
110  @param[in] value SetValue() で設定した値を与えます。
111  @param[in] cpSetValueArg SetValue() の第2引数に設定した値を与えます。valueが停止しているかどうかのフラグを与えます。
112  @param[in] accessor 標本値バッファへのアクセサです。
113  @param[in] clock 現在の時刻を渡します。
114  @param[in] cpWork 推測の計算のための事前計算結果を渡します。
115  */
116  void MakeSample(Sample* pSample, const Value& value, const SetValueArg* cpSetValueArg, const Accessor& accessor, nn::pia::clone::ClockValue clock, const Work* cpWork) const;
117 
118  /*!
119  @brief 標本値が追加された場合に呼び出されます。
120  @details 推測の計算のために使用するパラメータを更新します。
121  @param[in] accessor 標本値バッファへのアクセサです。
122  @param[in] index 標本値のインデックスです。
123  @param[in] pWork 推測の計算のための事前計算結果を渡します。
124  */
125  void OnUpdateSample(const Accessor& accessor, int index, Work* pWork) const;
126 
127  /*!
128  @brief デバッグに有用な情報をプリントします。
129 
130  @param[in] flag トレースフラグの論理和。詳細は @ref TraceFlag 型を参照してください。
131  */
132  void Trace(uint64_t flag) const;
133 
134 protected:
135 private:
136  float m_Threshold;
137  int32_t m_DelayClock;
138 
139  NN_PIA_DISALLOW_COPY(Simple3dReckoningStrategy);
140 };
141 } // end of namespace reckoning
142 
143 // シリアル化のために SerializePolicy の各関数を定義します。
144 namespace clone
145 {
146 template<>
147 inline void SerializePolicy<reckoning::Simple3dReckoningStrategy::Sample>::Serialize(void* pBuffer, const Type& value)
148 {
149  uint8_t* offset = reinterpret_cast<uint8_t*>(pBuffer);
150  SerializePolicy<float>::Serialize(offset, value.m_Value.x);
151  offset += sizeof(float);
152  SerializePolicy<float>::Serialize(offset, value.m_Value.y);
153  offset += sizeof(float);
154  SerializePolicy<float>::Serialize(offset, value.m_Value.z);
155  offset += sizeof(float);
156  SerializePolicy<uint8_t>::Serialize(offset, value.m_IsStop);
157  offset += 1;
158 }
159 
160 template<>
161 inline void SerializePolicy<reckoning::Simple3dReckoningStrategy::Sample>::Deserialize(Type* pValue, const void* cpData)
162 {
163  const uint8_t* offset = reinterpret_cast<const uint8_t*>(cpData);
164  SerializePolicy<float>::Deserialize(&pValue->m_Value.x, offset);
165  offset += 4;
166  SerializePolicy<float>::Deserialize(&pValue->m_Value.y, offset);
167  offset += 4;
168  SerializePolicy<float>::Deserialize(&pValue->m_Value.z, offset);
169  offset += 4;
170  SerializePolicy<uint8_t>::Deserialize(reinterpret_cast<uint8_t*>(&pValue->m_IsStop), offset);
171  offset += 1;
172 }
173 
174 template<>
176 {
177  return 4 * 3 + 1;
178 }
179 } // end of namespace clone
180 
181 }
182 } // end of namespace nn::pia