CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
clone_UnreliableCloneElementBase.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/clone/clone_Definitions.h>
17 #include <nn/pia/clone/clone_CloneElementBase.h>
18 
19 
20 namespace nn
21 {
22 namespace pia
23 {
24 namespace clone
25 {
26 
27 
28 class IDataPacker;
29 
30 /*!
31  @brief 到達保証されない値の送受信を管理する基底クラスです。
32  */
34 {
35 protected:
36  /*!
37  @brief デフォルトコンストラクタです。
38  */
40 
41 public:
42  /*!
43  @brief デストラクタです。
44  */
46 
47 
48  /*!
49  @brief @ref UnreliableCloneElement::GetValue "GetValue()" で有効な値が取得できるかどうかを取得します。
50  @return @ref UnreliableCloneElement::GetValue "GetValue()" で有効な値を取得できる場合は true を返します。
51  */
52  bool IsValidValue() const
53  {
54  return m_IsValidValue;
55  }
56 
57 
58  /*!
59  @brief 値が設定された時刻を取得します。
60  @return 値が設定された時刻です。 @ref IsValidValue() が false の場合に取得できる値は不定です。
61  */
63  {
64  return m_Clock;
65  }
66 
67 
68  /*!
69  @brief デバッグに有用な情報をプリントします。
70 
71  @param[in] flag トレースフラグの論理和。詳細は @ref TraceFlag 型を参照してください。
72  */
73  void Trace(uint64_t flag) const;
74 
75 
76  //! @cond PRIVATE
77 
78 public:
79  virtual Type GetType() const
80  {
81  return GetTypeStatic();
82  }
83 
84  static Type GetTypeStatic()
85  {
86  return Type_Unreliable;
87  }
88  static bool Receive(CloneElementBase* pElement, IDataPacker* pAckPacker, const void* cpChunk, uint16_t chunkSize, Id elementId, StationIndex src, StationIndex localStationIndex, uint32_t dispatchCount);
89  static uint32_t GetDataChunkHeaderSize();
90 
91 private:
92  void ReceiveData(const void* cpData, uint32_t size, ClockValue clock);
93 
94 public:
95  virtual void ClearData();
96  virtual void RemoveDest(StationIndex stationIndex)
97  {
98  // n3492: UnreliableCloneElementBase では宛先の bitmap をメンバとして持っておらず、
99  // CloneBase の bitmap を参照しているだけなので、ここでフラグを降ろす処理は必要ありません。
100  // 宛先のフラグが全て降りているときに Clone の m_SendDataList からトークンを削除する処理が無いため
101  // LAN 切断が発生した場合などに m_SendDataList が残ってしまいますが、
102  // アプリ側で CloneProtocol::UpdateClock() を呼ぶことで残ったデータが処理されるので問題ありません。
103  NN_PIA_UNUSED(stationIndex);
104  }
105 
106 private:
107  class UnreliableSendToken : public CloneElementBase::ISendToken
108  {
109  public:
110  explicit UnreliableSendToken(UnreliableCloneElementBase* pElement)
111  : CloneElementBase::ISendToken(), m_pElement(pElement)
112  {
113  }
114  virtual Type GetElementType() const
115  {
116  return Type_Unreliable;
117  }
118  virtual uint32_t GetDestBitmap() const;
119  virtual uint32_t GetChunkSize() const;
120  virtual void WriteChunk(void* pChunkBuffer) const;
121  virtual CloneElementBase* GetElement()
122  {
123  return m_pElement;
124  }
125  virtual void TraceTokenType()
126  {
127  PIA_TRACE_EX(common::TraceFlagClone, "TokenType: UnreliableSendToken");
128  };
129 
130  private:
131  Id GetId() const
132  {
133  return m_pElement->GetId();
134  }
135  uint32_t GetSize() const
136  {
137  return m_pElement->GetSize();
138  }
139  ClockValue GetClock() const
140  {
141  return m_pElement->m_Clock;
142  }
143  void Serialize(void* pBuffer) const
144  {
145  m_pElement->Serialize(pBuffer);
146  }
147 
148  private:
149  UnreliableCloneElementBase* m_pElement;
150  };
151 
152 protected:
153  Result SetValueCore(bool* pIsCopyValue);
154 
155  virtual void Serialize(void* pBuffer) const = 0;
156  virtual void Deserialize(const void* cpData) = 0;
157  virtual void ClearValue() = 0;
158 
159 private:
160  bool m_IsValidValue;
161  ClockValue m_Clock;
162  UnreliableSendToken m_SendDataToken;
163 
164  static Definition<UnreliableCloneElementBase> s_Definition;
165 
166 public:
167  template <int TEST_ID, typename Arg>
168  static void Test(const UnreliableCloneElementBase& obj, Arg* pArg = NULL);
169 
170  NN_PIA_DISALLOW_COPY(UnreliableCloneElementBase);
171  //! @endcond
172 };
173 }
174 }
175 } // end of namespace nn::pia::clone