SuperDex Physics C++ API
Loading...
Searching...
No Matches
mochi_handle.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19/********************************************************************************
20 IMPORTANT: PLEASE KEEP HEADER INCLUDES TO A MINIMUM.
21 If you must include a mochi_core header, then please make sure that it only
22 declares the data types (not containing other implementation details).
23*********************************************************************************/
24
25#include <cstdint>
26
27namespace superdex {
28
29inline constexpr uint64_t kInvalidHandle = 0;
30
31struct Handle {
32 using ValueType = uint64_t;
33 Handle() = default;
34 explicit Handle(ValueType raw);
36
37 bool IsValid() const;
38 bool operator==(Handle const& rhs) const;
39 bool operator!=(Handle const& rhs) const;
40 bool operator<(Handle const& rhs) const; // for ordered containers
41 uint64_t GetHash() const; // for unordered containers
42};
43
44// Strongly typed handles
45
46struct SceneHandle : public Handle {
47 using Handle::Handle;
48};
49
50struct ActorHandle : public Handle {
51 using Handle::Handle;
52};
53
54// ShapeHandle is reference-counted in C++/Python via a private cleanup token that has
55// no DSL counterpart, so its definition is hand-written in mochi_handle_inl.h (the
56// DSL marks it [no_cpp_definition]). Forward-declared here to keep this header aligned
57// 1:1 with mochi_physics_handle.mochi_gen.
58struct ShapeHandle;
59
60struct CallbackHandle : public Handle {
61 using Handle::Handle;
62};
63
64struct ConstraintHandle : public Handle {
65 using Handle::Handle;
66};
67
68struct StateHandle : public Handle {
69 using Handle::Handle;
70};
71
72struct QueryHandle : public Handle {
73 using Handle::Handle;
74};
75
76// PrefabHandle is a std::shared_ptr subclass (to a loaded prefab) that has no DSL counterpart,
77// so its definition is hand-written in mochi_handle_inl.h (the DSL marks it [no_cpp_definition]).
78// Forward-declared here to keep this header aligned with mochi_physics_handle.mochi_gen.
79struct PrefabHandle;
80
81} // namespace superdex
82
constexpr uint64_t kInvalidHandle
Default value for an invalid handle.
Unique identifier for an Actor within a Scene.
Unique identifier for a callback registration within a Scene.
Unique identifier for a Constraint within a Scene.
uint64_t GetHash() const
Compute a hash of the handle for use in unordered containers.
bool operator<(Handle const &rhs) const
uint64_t ValueType
Raw 64-bit identifier type.
ValueType value
Raw 64-bit identifier.
Handle()=default
bool operator!=(Handle const &rhs) const
bool operator==(Handle const &rhs) const
bool IsValid() const
Check whether the handle is valid (i.e., its value is non-zero).
Runtime handle to a loaded nested prefab (the resolved target of a prefab::PrefabReference).
Unique identifier for a query within a Scene.
Unique identifier for a Scene within a Context.
Handle to a shape (mesh, sphere, plane, etc.) within a Context.
Unique identifier for a captured simulation state within a Scene.