Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TQuery.ipp
Go to the documentation of this file.
1#pragma once
2
5
6#include <Common/logging.h>
7
8namespace ph::editor
9{
10
11template<typename Target, typename Performer>
12inline TQuery<Target, Performer>::TQuery(std::shared_ptr<Performer> performer, EQuery mode)
13 : m_performer(std::move(performer))
14 , m_numRetries(0)
15 , m_mode(mode)
16{
17 PH_ASSERT(m_performer);
18}
19
20template<typename Target, typename Performer>
21template<CDerived<Performer> DerivedPerformer>
23 : m_performer(derivedQuery.m_performer)
24 , m_numRetries(derivedQuery.m_numRetries)
25 , m_mode(derivedQuery.m_mode)
26{}
27
28template<typename Target, typename Performer>
29template<CDerived<Performer> DerivedPerformer>
31 : m_performer(std::move(derivedQuery.m_performer))
32 , m_numRetries(derivedQuery.m_numRetries)
33 , m_mode(derivedQuery.m_mode)
34{}
35
36template<typename Target, typename Performer>
37inline TQuery<Target, Performer>::~TQuery() = default;
39template<typename Target, typename Performer>
40inline bool TQuery<Target, Performer>::run(Target& target)
41{
42 PH_ASSERT(m_performer);
43 PH_ASSERT(!m_performer->isReady());
44
45 // A limit that will be reached in 1 minute, assuming 60 FPS and one try per frame
46 constexpr uint32 maxRetries = 60 * 60;
47
48 bool isDone = m_performer->performQuery(target);
49
50 // Modify the done flag according to query mode
51 switch(m_mode)
52 {
53 case EQuery::Once:
54 isDone = true;
55 break;
56
58 if(m_numRetries >= maxRetries)
59 {
60 PH_DEFAULT_LOG(Warning,
61 "Detected hanging graphics query ({} retries), canceling",
62 m_numRetries);
63
64 isDone = true;
65 }
66 break;
67 }
68
69 if(isDone)
70 {
71 m_performer->queryDone();
72 }
73
74 ++m_numRetries;
75 return isDone;
76}
77
78template<typename Target, typename Performer>
80{
81 if(m_performer)
82 {
83 m_performer->cancel();
84 }
85}
86
87template<typename Target, typename Performer>
89{
90 PH_ASSERT(m_performer);
91 return m_performer->isCanceled();
92}
93
94}// end namespace ph::editor
Definition TQuery.h:29
bool isCanceled() const
Whether the query is canceled.
Definition TQuery.ipp:88
friend class TQuery
Definition TQuery.h:95
void cancel()
Cancel the query. Does nothing if isEmpty() is true.
Definition TQuery.ipp:79
bool run(Target &target)
Definition TQuery.ipp:40
Definition ph_editor.h:10
EQuery
Definition fwd.h:7
@ AutoRetry
Definition fwd.h:9
@ Once
Definition fwd.h:8
Definition TWeakHandle.h:113