AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
LazyTrigger.h
Go to the documentation of this file.
1/*
2Copyright 2007-2026. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16#pragma once
17#include <agx/Integer.h>
18
19#include <atomic>
20
21#ifndef SWIG
22namespace agxSensor
23{
27 class LazyTrigger final
28 {
29 public:
34 inline LazyTrigger(bool triggerInitially = false)
35 : m_triggerState {static_cast<agx::UInt8>(triggerInitially ? 2u : 0u)}
36 {
37 }
38
42 LazyTrigger(const LazyTrigger&) = delete;
43
48
49 public:
53 inline bool shouldTrigger() const noexcept { return m_triggerState > 0u; }
54
58 inline operator bool() const noexcept { return shouldTrigger(); }
59
63 inline void trigger()
64 {
65 auto value = m_triggerState.load();
66 while (value < 2u)
67 m_triggerState.compare_exchange_weak(value, 2u, std::memory_order_relaxed);
68 }
69
73 inline void flagTriggered()
74 {
75 auto value = m_triggerState.load();
76 while (value > 1u)
77 m_triggerState.compare_exchange_weak(value, 1u, std::memory_order_relaxed);
78 }
79
83 inline void softResetTrigger()
84 {
85 auto value = m_triggerState.load();
86 while (value == 1u)
87 m_triggerState.compare_exchange_weak(value, 0u, std::memory_order_relaxed);
88 }
89
93 inline void hardResetTrigger() { m_triggerState = 0u; }
94
95 private:
96 std::atomic<agx::UInt8> m_triggerState;
97 };
98}
99#endif
Type for triggering effects at a later point in time.
Definition: LazyTrigger.h:28
LazyTrigger(bool triggerInitially=false)
Initialize a lazy trigger.
Definition: LazyTrigger.h:34
void softResetTrigger()
Reset the trigger state, only if it has triggered.
Definition: LazyTrigger.h:83
LazyTrigger(const LazyTrigger &)=delete
Trigger is unique.
void flagTriggered()
Tell the trigger that it has triggered.
Definition: LazyTrigger.h:73
bool shouldTrigger() const noexcept
Definition: LazyTrigger.h:53
void trigger()
Set the trigger to the trigger state.
Definition: LazyTrigger.h:63
LazyTrigger & operator=(const LazyTrigger &)=delete
Trigger is unique.
void hardResetTrigger()
Reset the trigger state, no matter if it has triggered or not.
Definition: LazyTrigger.h:93
The agxSensor namespace contains components to model real-time sensors connected to the physics of AG...
The agx namespace contains the dynamics/math part of the AGX Dynamics API.