summaryrefslogtreecommitdiff
path: root/Runtime/GfxDevice/threaded/ClientIDMapper.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/GfxDevice/threaded/ClientIDMapper.h
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/GfxDevice/threaded/ClientIDMapper.h')
-rw-r--r--Runtime/GfxDevice/threaded/ClientIDMapper.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/Runtime/GfxDevice/threaded/ClientIDMapper.h b/Runtime/GfxDevice/threaded/ClientIDMapper.h
new file mode 100644
index 0000000..4156701
--- /dev/null
+++ b/Runtime/GfxDevice/threaded/ClientIDMapper.h
@@ -0,0 +1,46 @@
+#ifndef CLIENTIDMAPPER_H
+#define CLIENTIDMAPPER_H
+
+#include "Runtime/Utilities/dynamic_array.h"
+#include "Runtime/GfxDevice/GfxDevice.h"
+
+#if ENABLE_GFXDEVICE_REMOTE_PROCESS
+#define ClientIDWrapper(type) ClientIDMapper::ClientID
+#define ClientIDWrapperHandle(type) ClientIDMapper::ClientID
+#else
+#define ClientIDWrapper(type) type*
+#define ClientIDWrapperHandle(type) type
+#endif
+
+class ClientIDMapper {
+public:
+ typedef UInt32 ClientID;
+
+ ClientIDMapper() :
+ m_HighestAllocatedID(0)
+ {
+ }
+
+ ClientID CreateID()
+ {
+ if (m_FreeIDs.empty())
+ return ++m_HighestAllocatedID;
+ else
+ {
+ ClientID retval = m_FreeIDs.back();
+ m_FreeIDs.pop_back();
+ return retval;
+ }
+ }
+
+ void FreeID(ClientID cid)
+ {
+ m_FreeIDs.push_back(cid);
+ }
+
+private:
+ ClientID m_HighestAllocatedID;
+ dynamic_array<ClientID> m_FreeIDs;
+};
+
+#endif \ No newline at end of file