summaryrefslogtreecommitdiff
path: root/Runtime/Network/NetworkViewID.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-14 22:50:43 +0800
committerchai <chaifix@163.com>2019-08-14 22:50:43 +0800
commit15740faf9fe9fe4be08965098bbf2947e096aeeb (patch)
treea730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Network/NetworkViewID.h
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/Network/NetworkViewID.h')
-rw-r--r--Runtime/Network/NetworkViewID.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/Runtime/Network/NetworkViewID.h b/Runtime/Network/NetworkViewID.h
new file mode 100644
index 0000000..903a953
--- /dev/null
+++ b/Runtime/Network/NetworkViewID.h
@@ -0,0 +1,56 @@
+#pragma once
+
+#include "Configuration/UnityConfigure.h"
+
+#if ENABLE_NETWORK
+#include "External/RakNet/builds/include/BitStream.h"
+#include "Runtime/Serialize/SerializeUtility.h"
+
+struct NetworkViewID
+{
+ private:
+
+ UInt32 m_LevelPrefix;
+ UInt32 m_ID;
+ UInt32 m_Type;///< enum { Allocated = 0, Scene = 1 }
+
+ public:
+
+ DECLARE_SERIALIZE(NetworkViewID)
+
+ NetworkViewID () :
+ m_LevelPrefix (0),
+ m_ID (0),
+ m_Type (0)
+ { }
+
+ enum { kAllocatedID = 0, kSceneID = 1 };
+
+ // Pack the view id into a 16 bit or 32 bit number based on how big the number is
+ void Write (RakNet::BitStream& stream);
+ bool Read (RakNet::BitStream& stream);
+
+ friend bool operator < (const NetworkViewID& lhs, const NetworkViewID& rhs);
+ friend bool operator != (const NetworkViewID& lhs, const NetworkViewID& rhs);
+ friend bool operator == (const NetworkViewID& lhs, const NetworkViewID& rhs);
+
+ void SetSceneID (UInt32 sceneID);
+ void SetAllocatedID (UInt32 sceneID);
+ bool IsSceneID() { return m_Type == kSceneID; }
+ void ReplaceLevelPrefix (UInt32 levelPrefix);
+
+ UInt32 GetIndex () const { return m_ID; }
+
+ std::string ToString() const;
+
+ static NetworkViewID GetUnassignedViewID() { NetworkViewID viewID; return viewID; }
+};
+
+template<class TransferFunc>
+void NetworkViewID::Transfer (TransferFunc& transfer)
+{
+ TRANSFER(m_ID);
+ TRANSFER(m_Type);
+}
+
+#endif