Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
BodyAccess.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#ifdef JPH_ENABLE_ASSERTS
8
10
11class JPH_EXPORT BodyAccess
12{
13public:
15 enum class EAccess : uint8
16 {
17 None = 0,
18 Read = 1,
19 ReadWrite = 3,
20 };
21
23 class Grant
24 {
25 public:
26 inline Grant(EAccess inVelocity, EAccess inPosition)
27 {
28 EAccess &velocity = sVelocityAccess();
29 EAccess &position = sPositionAccess();
30
31 JPH_ASSERT(velocity == EAccess::ReadWrite);
32 JPH_ASSERT(position == EAccess::ReadWrite);
33
34 velocity = inVelocity;
35 position = inPosition;
36 }
37
38 inline ~Grant()
39 {
40 sVelocityAccess() = EAccess::ReadWrite;
41 sPositionAccess() = EAccess::ReadWrite;
42 }
43 };
44
46 static inline bool sCheckRights(EAccess inRights, EAccess inDesiredRights)
47 {
48 return (uint8(inRights) & uint8(inDesiredRights)) == uint8(inDesiredRights);
49 }
50
52 static inline EAccess & sVelocityAccess()
53 {
54 static thread_local EAccess sAccess = BodyAccess::EAccess::ReadWrite;
55 return sAccess;
56 }
57
59 static inline EAccess & sPositionAccess()
60 {
61 static thread_local EAccess sAccess = BodyAccess::EAccess::ReadWrite;
62 return sAccess;
63 }
64};
65
67
68#endif // JPH_ENABLE_ASSERTS
@ None
No degrees of freedom are allowed. Note that this is not valid and will crash. Use a static body inst...
std::uint8_t uint8
Definition Core.h:454
#define JPH_EXPORT
Definition Core.h:236
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
#define JPH_ASSERT(...)
Definition IssueReporting.h:33