Mon, 10 Apr 2023 14:21:17 +0300
rename some functions
3 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
24 | 3 | * Copyright (C) 2013 - 2020 Teemu Piippo |
3 | 4 | * |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #pragma once | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
20 | #include <algorithm> |
3 | 21 | #include <cmath> |
309
d862721d19a3
Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
300
diff
changeset
|
22 | #include <cinttypes> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
23 | #include <compare> |
213
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
24 | #include <deque> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
25 | #include <memory> |
53 | 26 | #include <optional> |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
27 | #include <set> |
96 | 28 | #include <type_traits> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
29 | #include <QDataStream> |
235
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
30 | #include <QDateTime> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
31 | #include <QDebug> |
3 | 32 | #include <QObject> |
33 | #include <QPointF> | |
34 | #include <QSet> | |
35 | #include <QString> | |
36 | #include <QStringList> | |
37 | #include <QVariant> | |
38 | #include <QVector> | |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
237
diff
changeset
|
39 | #include <QMdiArea> |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
40 | #include <glm/glm.hpp> |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
261
diff
changeset
|
41 | #include "src/geometry.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
261
diff
changeset
|
42 | #include "src/typeconversions.h" |
339 | 43 | #define SIG(A, B) (A), &std::decay_t<decltype(*(A))>::B |
3 | 44 | |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
45 | template<typename T> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
46 | using opt = std::optional<T>; |
313
c24d87f64bed
Improve click handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
309
diff
changeset
|
47 | using std::chrono::steady_clock; |
26 | 48 | |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
237
diff
changeset
|
49 | //! \brief Return type of qHash. unsigned int on Qt5, unsigned long on Qt6. |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
237
diff
changeset
|
50 | using hash_t = decltype(qHash(0)); |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
237
diff
changeset
|
51 | |
300
3a4b132b8353
Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
299
diff
changeset
|
52 | //! \brief Index type of QVector, int on Qt5, qsizetype on Qt6 |
3a4b132b8353
Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
299
diff
changeset
|
53 | using index_t = QVector<int>::size_type; |
3a4b132b8353
Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
299
diff
changeset
|
54 | |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
55 | Q_DECLARE_METATYPE(glm::vec3) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
56 | Q_DECLARE_METATYPE(glm::mat4) |
3 | 57 | |
309
d862721d19a3
Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
300
diff
changeset
|
58 | struct ModelId |
d862721d19a3
Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
300
diff
changeset
|
59 | { |
d862721d19a3
Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
300
diff
changeset
|
60 | std::int32_t value; |
d862721d19a3
Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
300
diff
changeset
|
61 | constexpr auto operator<=>(const ModelId&) const = default; |
d862721d19a3
Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
300
diff
changeset
|
62 | }; |
d862721d19a3
Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
300
diff
changeset
|
63 | |
333
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
64 | struct ElementId |
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
65 | { |
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
66 | std::int32_t value; |
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
67 | constexpr auto operator<=>(const ElementId& other) const = default; |
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
68 | }; |
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
69 | |
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
70 | constexpr auto qHash(ElementId id) |
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
71 | { |
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
72 | return qHash(id.value); |
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
73 | } |
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
74 | |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
75 | //! \brief count the amount of elements in a basic array |
21 | 76 | template<typename T, int N> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
77 | constexpr int countof(T(&)[N]) |
21 | 78 | { |
79 | return N; | |
80 | } | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
81 | |
55 | 82 | template<int N, typename T, glm::qualifier Q> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
83 | constexpr QPointF toQPointF(const glm::vec<N, T, Q>& vec) |
55 | 84 | { |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
85 | return {double_cast(vec.x), double_cast(vec.y)}; |
55 | 86 | } |
87 | ||
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
88 | constexpr glm::vec2 toVec2(const QPointF& point) |
55 | 89 | { |
90 | return {point.x(), point.y()}; | |
91 | } | |
92 | ||
96 | 93 | |
148 | 94 | template<typename T, typename R, typename K> |
95 | const R* findInMap(const std::map<T, R>& map, K&& key) | |
96 | { | |
97 | auto pair = map.find(key); | |
98 | if (pair != map.end()) | |
99 | { | |
100 | return &pair->second; | |
101 | } | |
102 | else | |
103 | { | |
104 | return nullptr; | |
105 | } | |
106 | } | |
107 | ||
108 | template<typename T, typename R, typename K> | |
109 | R* findInMap(std::map<T, R>& map, K&& key) | |
110 | { | |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
111 | static_assert(std::is_convertible_v<K, T>, "bad type for key parameter"); |
148 | 112 | auto pair = map.find(key); |
113 | if (pair != map.end()) | |
114 | { | |
115 | return &pair->second; | |
116 | } | |
117 | else | |
118 | { | |
119 | return nullptr; | |
120 | } | |
121 | } | |
122 | ||
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
123 | template<typename T, typename R> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
124 | void removeFromMap(std::map<T, R>& map, T&& key) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
125 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
126 | const auto it = map.find(key); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
127 | if (it != map.end()) { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
128 | map.erase(it); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
129 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
130 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
131 | |
261
6a875faebde2
pi is no longer a template
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
259
diff
changeset
|
132 | constexpr float pi = M_PIf; |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
133 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
134 | inline QSizeF sizeToSizeF(const QSize& size) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
135 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
136 | return {static_cast<qreal>(size.width()), static_cast<qreal>(size.height())}; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
137 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
138 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
139 | //! \brief Hints to the specified vector that a certain amount of new elements |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
140 | //! are going to be added. |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
141 | template<typename T> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
142 | void reserveMore(std::vector<T>& vector, std::size_t amount) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
143 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
144 | vector.reserve(vector.size() + amount); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
145 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
146 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
147 | inline QString vectorToString(const glm::vec2& vec) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
148 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
149 | return QStringLiteral("(%1, %2)") |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
150 | .arg(double_cast(vec.x)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
151 | .arg(double_cast(vec.y)); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
152 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
153 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
154 | inline QString vectorToString(const glm::vec3& vec) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
155 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
156 | return QStringLiteral("(%1, %2, %3)") |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
157 | .arg(double_cast(vec.x)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
158 | .arg(double_cast(vec.y)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
159 | .arg(double_cast(vec.z)); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
160 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
161 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
162 | inline QString vectorToString(const glm::vec4& vec) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
163 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
164 | return QStringLiteral("%1, %2, %3, %4)") |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
165 | .arg(double_cast(vec.x)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
166 | .arg(double_cast(vec.y)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
167 | .arg(double_cast(vec.z)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
168 | .arg(double_cast(vec.w)); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
169 | } |
196 | 170 | |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
171 | template<typename T, typename IdentifierType> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
172 | struct TypeValue |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
173 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
174 | T value; |
213
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
175 | auto operator<=>(const TypeValue& other) const = default; |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
176 | }; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
177 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
178 | template<typename T, typename R> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
179 | int qHash(TypeValue<T, R> value) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
180 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
181 | return qHash(value.value); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
182 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
183 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
184 | /** |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
185 | * Iterates a @c glm::mat |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
186 | */ |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
187 | template<int X, int Y, typename T, glm::qualifier Q, typename Fn> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
188 | void iter_matrix(const glm::mat<X, Y, T, Q>& matrix, Fn&& fn) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
189 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
190 | for (int i = 0; i < X; ++i) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
191 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
192 | for (int j = 0; j < Y; ++j) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
193 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
194 | fn(i, j, matrix[i][j]); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
195 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
196 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
197 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
198 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
199 | inline QDataStream& operator<<(QDataStream& stream, const glm::vec3& vec) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
200 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
201 | return stream << vec.x << vec.y << vec.z; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
202 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
203 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
204 | inline QDataStream& operator>>(QDataStream& stream, glm::vec3& vec) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
205 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
206 | return stream >> vec.x >> vec.y >> vec.z; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
207 | } |
70 | 208 | |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
209 | template<int X, int Y, typename T, glm::qualifier Q> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
210 | QDataStream& operator<<(QDataStream& stream, const glm::mat<X, Y, T, Q>& mat) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
211 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
212 | iter_matrix(mat, [&stream](int, int, float x) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
213 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
214 | stream << x; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
215 | }); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
216 | return stream; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
217 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
218 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
219 | template<int X, int Y, typename T, glm::qualifier Q> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
220 | QDataStream& operator>>(QDataStream& stream, glm::mat<X, Y, T, Q>& mat) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
221 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
222 | iter_matrix(mat, [&stream](int, int, float x) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
223 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
224 | stream >> x; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
225 | }); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
226 | return stream; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
227 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
228 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
229 | //! \brief Converts a pointer value to an \c std::optional value. If p has a |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
230 | //! value, it will be copied into the result value. |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
231 | template<typename T> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
232 | std::optional<T> pointerToOptional(const T* p) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
233 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
234 | std::optional<T> result; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
235 | if (p != nullptr) { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
236 | result = *p; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
237 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
238 | return result; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
239 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
240 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
241 | // some magic code from https://en.cppreference.com/w/cpp/utility/variant/visit |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
242 | // for use with std::visit |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
243 | template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; }; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
244 | template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
245 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
246 | // http://stackoverflow.com/a/18204188/3629665 |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
247 | template<typename T> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
248 | constexpr T rotl10(T x) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
249 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
250 | return (x << 10) | ((x >> 22) & 0x000000ff); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
251 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
252 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
253 | template<typename T> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
254 | constexpr T rotl20(T x) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
255 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
256 | return (x << 20) | ((x >> 12) & 0x000000ff); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
257 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
258 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
259 | inline QString quoted(QString string) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
260 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
261 | if (string.contains("'")) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
262 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
263 | string.replace("\"", "\\\""); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
264 | string = "\"" + string + "\""; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
265 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
266 | else |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
267 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
268 | string = "'" + string + "'"; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
269 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
270 | return string; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
271 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
272 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
273 | inline QString vertexToString(const glm::vec3& vertex) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
274 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
275 | return QStringLiteral("%1 %2 %3").arg(vertex.x).arg(vertex.y).arg(vertex.z); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
276 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
277 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
278 | inline QString vertexToStringParens(const glm::vec3& vertex) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
279 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
280 | return QStringLiteral("(%1 %2 %3)").arg(vertex.x).arg(vertex.y).arg(vertex.z); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
281 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
282 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
283 | inline QString transformToString(const glm::mat4& matrix) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
284 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
285 | return QStringLiteral("%1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12") |
207
5315358a7d91
well that's embarrassing
Teemu Piippo <teemu@hecknology.net>
parents:
206
diff
changeset
|
286 | .arg(matrix[3][0]).arg(matrix[3][1]).arg(matrix[3][2]) |
5315358a7d91
well that's embarrassing
Teemu Piippo <teemu@hecknology.net>
parents:
206
diff
changeset
|
287 | .arg(matrix[0][0]).arg(matrix[1][0]).arg(matrix[2][0]) |
5315358a7d91
well that's embarrassing
Teemu Piippo <teemu@hecknology.net>
parents:
206
diff
changeset
|
288 | .arg(matrix[0][1]).arg(matrix[1][1]).arg(matrix[2][1]) |
5315358a7d91
well that's embarrassing
Teemu Piippo <teemu@hecknology.net>
parents:
206
diff
changeset
|
289 | .arg(matrix[0][2]).arg(matrix[1][2]).arg(matrix[2][2]); |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
290 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
291 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
292 | template<typename T, glm::qualifier Q> |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
237
diff
changeset
|
293 | constexpr auto qHash(const glm::vec<3, T, Q>& key) |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
294 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
295 | return qHash(key.x) ^ rotl10(qHash(key.y)) ^ rotl20(qHash(key.z)); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
296 | } |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
297 | |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
213
diff
changeset
|
298 | template<typename T, typename Fn> |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
213
diff
changeset
|
299 | void forValueInMap(T&& map, Fn&& fn) |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
300 | { |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
301 | for (const auto& it : map) { |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
302 | fn(it.second); |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
303 | } |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
304 | } |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
305 | |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
306 | inline QString joined(QString value, const QString& separator, const QString& element) |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
307 | { |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
308 | if (not value.isEmpty()) { |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
309 | value += separator; |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
310 | } |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
311 | value += element; |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
312 | return value; |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
313 | } |
213
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
314 | |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
315 | template<typename T> |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
316 | struct GraphEdge |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
317 | { |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
318 | T from; |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
319 | T to; |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
320 | }; |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
321 | |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
322 | template<typename T> |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
323 | using Graph = std::deque<GraphEdge<T>>; |
235
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
324 | |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
325 | struct Message |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
326 | { |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
327 | QDateTime time; |
237
10a6298f636f
Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
235
diff
changeset
|
328 | enum Type { Info, Warning, Error } type; |
235
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
329 | QString text; |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
330 | }; |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
331 | |
237
10a6298f636f
Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
235
diff
changeset
|
332 | Q_DECLARE_METATYPE(Message) |
10a6298f636f
Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
235
diff
changeset
|
333 | |
235
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
334 | inline Message logInfo(const QString text) |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
335 | { |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
336 | return Message{.time = QDateTime::currentDateTime(), .type = Message::Info, .text = text}; |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
337 | } |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
338 | |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
339 | inline Message logWarning(const QString text) |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
340 | { |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
341 | return Message{.time = QDateTime::currentDateTime(), .type = Message::Warning, .text = text}; |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
342 | } |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
343 | |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
344 | inline Message logError(const QString text) |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
345 | { |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
346 | return Message{.time = QDateTime::currentDateTime(), .type = Message::Error, .text = text}; |
7ef03c2b46ab
Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
347 | } |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
339
diff
changeset
|
348 | |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
339
diff
changeset
|
349 | template<typename BaseType, typename MemberType, typename DataType> |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
339
diff
changeset
|
350 | struct MemberData |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
339
diff
changeset
|
351 | { |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
339
diff
changeset
|
352 | std::size_t member; |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
339
diff
changeset
|
353 | DataType payload; |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
339
diff
changeset
|
354 | constexpr MemberType memberInstance(BaseType* instance) const |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
339
diff
changeset
|
355 | { |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
339
diff
changeset
|
356 | return *reinterpret_cast<MemberType*>(reinterpret_cast<char*>(instance) + this->member); |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
339
diff
changeset
|
357 | } |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
339
diff
changeset
|
358 | }; |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
354
diff
changeset
|
359 | |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
354
diff
changeset
|
360 | constexpr glm::mat4 DEFAULT_GRID_MATRIX = {{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}}; |