载入中...
搜索中...
未找到
PhysicsHandles.cpp
浏览该文件的文档.
2#include "common/Exception.h"
3#include "common/Identity.h"
4
5#include <atomic>
6#include <limits>
7
8namespace eve::physics::detail {
9
11 using Handle = PhysicsWorldHandle;
12 using Index = Handle::index_type;
13
14 static std::atomic<Index> nextIndex{1u};
15 Index current = nextIndex.load(std::memory_order_relaxed);
16 for (;;) {
17 if (current == Handle::invalidIndex)
18 throw eve::Exception("Physics: process-local world handle space exhausted");
19 const Index next = static_cast<Index>(current + 1u);
20 if (nextIndex.compare_exchange_weak(current, next, std::memory_order_relaxed, std::memory_order_relaxed)) {
21 return Handle(current, 1u);
22 }
23 }
24}
25
28 const std::uint64_t packed = runtimeHandle.packed();
29 static std::atomic<std::uint64_t> sequence{1u};
30 const std::uint64_t serial = sequence.fetch_add(1u, std::memory_order_relaxed);
31 for (std::size_t i = 0; i < 8; ++i) {
32 bytes[i] = static_cast<std::uint8_t>((packed >> (i * 8u)) & 0xffu);
33 bytes[8 + i] = static_cast<std::uint8_t>((serial >> (i * 8u)) & 0xffu);
34 }
35 bytes[6] = static_cast<std::uint8_t>(0x40u | (bytes[6] & 0x0fu));
36 bytes[8] = static_cast<std::uint8_t>(0x80u | (bytes[8] & 0x3fu));
38}
39
40} // namespace eve::physics::detail
Strong identity values shared by persistence, content and logical-name APIs.
std::uint64_t bytes
std::unique_ptr< gpgpu::Sequence > sequence
Definition OnnxGpgpu.cpp:43
Process-local, generation-qualified handles owned by the physics domain.
double current
uint64_t serial
Definition UISystem.cpp:68
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
constexpr std::uint64_t packed() const noexcept
Encodes the two coordinates for a legacy integer boundary.
Id128 public API.
Definition Identity.h:112
std::array< std::uint8_t, 16 > Bytes
Definition Identity.h:114
PhysicsWorldHandle allocatePhysicsWorldHandle()
Allocates a process-local world handle from the physics owner.
eve::PersistentId makePhysicsWorldPersistentId(PhysicsWorldHandle runtimeHandle)
Creates a non-nil process-local generated identity for a world without an injected persistent ID.
eve::RuntimeHandle< PhysicsWorldHandleTag > PhysicsWorldHandle
Generation-qualified runtime identity for a physics world.
StrongUuid< detail::PersistentIdTag > PersistentId
Stable instance identity for persistence, networking and process boundaries.
Definition Identity.h:254