BodyAccess.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #ifdef JPH_ENABLE_ASSERTS
  5. JPH_NAMESPACE_BEGIN
  6. class BodyAccess
  7. {
  8. public:
  9. /// Access rules, used to detect race conditions during simulation
  10. enum class EAccess : uint8
  11. {
  12. None = 0,
  13. Read = 1,
  14. ReadWrite = 3,
  15. };
  16. /// Grant a scope specific access rights on the current thread
  17. class Grant
  18. {
  19. public:
  20. inline Grant(EAccess inVelocity, EAccess inPosition)
  21. {
  22. sVelocityAccess = inVelocity;
  23. sPositionAccess = inPosition;
  24. }
  25. inline ~Grant()
  26. {
  27. sVelocityAccess = EAccess::ReadWrite;
  28. sPositionAccess = EAccess::ReadWrite;
  29. }
  30. };
  31. /// Check if we have permission
  32. static bool sCheckRights(EAccess inRights, EAccess inDesiredRights)
  33. {
  34. return (uint8(inRights) & uint8(inDesiredRights)) == uint8(inDesiredRights);
  35. }
  36. // Various permissions that can be granted
  37. static thread_local EAccess sVelocityAccess;
  38. static thread_local EAccess sPositionAccess;
  39. };
  40. JPH_NAMESPACE_END
  41. #endif // JPH_ENABLE_ASSERTS