summaryrefslogtreecommitdiff
path: root/Runtime/Network/NetworkViewIDAllocator.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/NetworkViewIDAllocator.h
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/Network/NetworkViewIDAllocator.h')
-rw-r--r--Runtime/Network/NetworkViewIDAllocator.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/Runtime/Network/NetworkViewIDAllocator.h b/Runtime/Network/NetworkViewIDAllocator.h
new file mode 100644
index 0000000..124feb5
--- /dev/null
+++ b/Runtime/Network/NetworkViewIDAllocator.h
@@ -0,0 +1,58 @@
+#pragma once
+
+#include "Configuration/UnityConfigure.h"
+
+#if ENABLE_NETWORK
+#include "NetworkEnums.h"
+
+class NetworkViewIDAllocator
+{
+
+ struct AvailableBatch
+ {
+ UInt32 first;
+ UInt32 count;
+ };
+
+ typedef std::vector<NetworkPlayer> AllocatedViewIDBatches;
+ AllocatedViewIDBatches m_AllocatedViewIDBatches; // Used by the server to track who own which NetworkViewID's
+
+ typedef std::vector<UInt32> ReceivedBatches;
+ ReceivedBatches m_ReceivedBatches; // Used by the client to track which batches were received by him.
+
+ typedef std::vector<AvailableBatch> AvailableBatches;
+ AvailableBatches m_AvailableBatches; // Used by client/server to allocate ViewID's from
+
+ int m_BatchSize;
+ int m_MinAvailableViewIDs; // We always make sure that m_MinAvailableViewIDs are around. If not we request more view id's
+ int m_RequestedBatches;
+ NetworkPlayer m_ClientPlayer;
+ NetworkPlayer m_ServerPlayer;
+
+ public:
+
+ NetworkViewIDAllocator();
+
+ void Clear (int batchSize, int minimumViewIDs, NetworkPlayer server, NetworkPlayer client);
+
+ NetworkViewID AllocateViewID ();
+
+ UInt32 AllocateBatch (NetworkPlayer player);
+
+ void FeedAvailableBatchOnClient (UInt32 batchIndex);
+ void FeedAvailableBatchOnServer (UInt32 batchIndex);
+ UInt32 GetBatchSize () { return m_BatchSize; }
+
+ // How many more view id batches should be requested!
+ // You are expected to actually request or allocate those view id's
+ int ShouldRequestMoreBatches ();
+ void AddRequestedBatches (int requestedBatches) { m_RequestedBatches += requestedBatches; }
+
+ void SetMinAvailableViewIDs(int size) { m_MinAvailableViewIDs = size; }
+
+ /// On Server: Find Owner returns the player who allocated the view id. If it hasn't been allocated, it returns kUndefindedPlayerIndex.
+ /// On Clients: FindOwner returns the clients player ID for its own objects and otherwise the server, since he can't possibly know the owner.
+ NetworkPlayer FindOwner (NetworkViewID viewID);
+};
+
+#endif \ No newline at end of file