PeriDyno 1.0.0
Loading...
Searching...
No Matches
PSimulationThread.h
Go to the documentation of this file.
1#ifndef PSIMULATIONTHREAD_H
2#define PSIMULATIONTHREAD_H
3
4#include <QThread>
5#include <QMutex>
6#include <QWaitCondition>
7#include <atomic>
8#include <chrono>
9#include <mutex>
10#include <condition_variable>
11
12#include <nodes/QNode>
13
14namespace dyno
15{
16 class Node;
17 class SceneGraph;
18
19 class PSimulationThread : public QThread
20 {
21 Q_OBJECT
22
23 public:
25
26 void pause();
27 void resume();
28 void stop();
29
30 void createNewScene();
31 void createNewScene(std::shared_ptr<SceneGraph> scn);
32
33 void closeCurrentScene();
34
35 void closeAllScenes();
36
37 void run() override;
38
42 void reset(int num);
43
47 void proceed(int num);
48
51
52 void setTotalFrames(int num);
53 inline int getTotalFrames() { return mTotalFrame; }
54
55 void takeOneStep();
56
58
59 bool isPaused() {
60 return mPaused;
61 }
62
63 bool isRunning() {
64 return mRunning;
65 }
66
67 Q_SIGNALS:
68 //Note: should not be emitted from the user
69
71
72 void oneFrameFinished(int frame);
74
75 public slots:
76 void resetNode(std::shared_ptr<Node> node);
77 void resetQtNode(Qt::QtNode& node);
78
79 void syncNode(std::shared_ptr<Node> node);
80
81 private:
83
84 static std::atomic<PSimulationThread*> pInstance;
85 static std::mutex mInstanceMutex;
86
87 void notify();
88
89 std::atomic<int> mTotalFrame;
90
91 bool mReset;
93 bool mOneStep = false;
94
95 std::atomic<bool> mPaused;
96 std::atomic<bool> mRunning;
97
98 std::atomic<bool> mUpdatingGraphicsContext;
99
100 std::shared_ptr<Node> mActiveNode;
101
102 std::chrono::milliseconds mTimeOut;
103 std::timed_mutex mMutex;
104 std::condition_variable_any mCond;
105 };
106}
107
108
109#endif // PSIMULATIONTHREAD_H
static std::atomic< PSimulationThread * > pInstance
void reset(int num)
Reset the simulation.
std::atomic< bool > mPaused
void oneFrameFinished(int frame)
std::shared_ptr< Node > mActiveNode
std::atomic< bool > mUpdatingGraphicsContext
std::condition_variable_any mCond
static PSimulationThread * instance()
void syncNode(std::shared_ptr< Node > node)
void resetQtNode(Qt::QtNode &node)
std::chrono::milliseconds mTimeOut
std::atomic< bool > mRunning
void proceed(int num)
Continue the simulation from the current frame.
void resetNode(std::shared_ptr< Node > node)
static std::mutex mInstanceMutex
std::atomic< int > mTotalFrame
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25