00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef NVBLASTTKGUID_H
00030 #define NVBLASTTKGUID_H
00031
00032 #include "NvPreprocessor.h"
00033
00034 #if NV_WINDOWS_FAMILY
00035 #include <rpc.h>
00036 #else
00037
00038 #include "NvBlastTime.h"
00039 #endif
00040
00041 #include "PsHash.h"
00042
00043 namespace Nv
00044 {
00045 namespace Blast
00046 {
00047
00048 #if NV_WINDOWS_FAMILY
00049
00050 NV_INLINE NvBlastID TkGenerateGUID(void* ptr)
00051 {
00052 NV_UNUSED(ptr);
00053
00054 NV_COMPILE_TIME_ASSERT(sizeof(UUID) == sizeof(NvBlastID));
00055
00056 NvBlastID guid;
00057 UuidCreate(reinterpret_cast<UUID*>(&guid));
00058
00059 return guid;
00060 }
00061
00062 #else
00063
00064 NV_INLINE NvBlastID TkGenerateGUID(void* ptr)
00065 {
00066
00067 Time time;
00068
00069 NvBlastID guid;
00070
00071
00072 *reinterpret_cast<uint64_t*>(guid.data) = reinterpret_cast<uintptr_t>(ptr);
00073 *reinterpret_cast<int64_t*>(guid.data + 8) = time.getLastTickCount();
00074
00075 return guid;
00076 }
00077
00078 #endif
00079
00080
00089 NV_INLINE bool TkGUIDsEqual(const NvBlastID* id1, const NvBlastID* id2)
00090 {
00091 return !memcmp(id1, id2, sizeof(NvBlastID));
00092 }
00093
00094
00100 NV_INLINE void TkGUIDReset(NvBlastID* id)
00101 {
00102 memset(id, 0, sizeof(NvBlastID));
00103 }
00104
00105
00112 NV_INLINE bool TkGUIDIsZero(const NvBlastID* id)
00113 {
00114 return *reinterpret_cast<const uint64_t*>(&id->data[0]) == 0 && *reinterpret_cast<const uint64_t*>(&id->data[8]) == 0;
00115 }
00116
00117 }
00118 }
00119
00120
00121 namespace physx
00122 {
00123 namespace shdfnd
00124 {
00125
00126
00127 template <>
00128 struct Hash<NvBlastID>
00129 {
00130 uint32_t operator()(const NvBlastID& k) const
00131 {
00132
00133 uint32_t h = 5381;
00134 for (uint32_t i = 0; i < sizeof(k.data) / sizeof(k.data[0]); ++i)
00135 h = ((h << 5) + h) ^ uint32_t(k.data[i]);
00136 return h;
00137 }
00138 bool equal(const NvBlastID& k0, const NvBlastID& k1) const
00139 {
00140 return Nv::Blast::TkGUIDsEqual(&k0, &k1);
00141 }
00142 };
00143
00144 }
00145 }
00146
00147
00148 #endif // #ifndef NVBLASTTKGUID_H