Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickspriteengine.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | static const int NINF = -1000000; | - | ||||||||||||
4 | QQuickStochasticEngine::QQuickStochasticEngine(QObject *parent) : | - | ||||||||||||
5 | QObject(parent), m_timeOffset(0), m_addAdvance(false) | - | ||||||||||||
6 | { | - | ||||||||||||
7 | - | |||||||||||||
8 | setCount(1); | - | ||||||||||||
9 | } executed 102 times by 6 tests: end of block Executed by:
| 102 | ||||||||||||
10 | - | |||||||||||||
11 | QQuickStochasticEngine::QQuickStochasticEngine(const QList<QQuickStochasticState *> &states, QObject *parent) : | - | ||||||||||||
12 | QObject(parent), m_states(states), m_timeOffset(0), m_addAdvance(false) | - | ||||||||||||
13 | { | - | ||||||||||||
14 | - | |||||||||||||
15 | setCount(1); | - | ||||||||||||
16 | } never executed: end of block | 0 | ||||||||||||
17 | - | |||||||||||||
18 | QQuickStochasticEngine::~QQuickStochasticEngine() | - | ||||||||||||
19 | { | - | ||||||||||||
20 | } | - | ||||||||||||
21 | - | |||||||||||||
22 | QQuickSpriteEngine::QQuickSpriteEngine(QObject *parent) | - | ||||||||||||
23 | : QQuickStochasticEngine(parent), m_startedImageAssembly(false), m_loaded(false) | - | ||||||||||||
24 | { | - | ||||||||||||
25 | } executed 96 times by 5 tests: end of block Executed by:
| 96 | ||||||||||||
26 | - | |||||||||||||
27 | QQuickSpriteEngine::QQuickSpriteEngine(const QList<QQuickSprite *> &sprites, QObject *parent) | - | ||||||||||||
28 | : QQuickSpriteEngine(parent) | - | ||||||||||||
29 | { | - | ||||||||||||
30 | for (QQuickSprite* sprite : sprites) | - | ||||||||||||
31 | m_states << (QQuickStochasticState*)sprite; executed 166 times by 5 tests: m_states << (QQuickStochasticState*)sprite; Executed by:
| 166 | ||||||||||||
32 | } executed 96 times by 5 tests: end of block Executed by:
| 96 | ||||||||||||
33 | - | |||||||||||||
34 | QQuickSpriteEngine::~QQuickSpriteEngine() | - | ||||||||||||
35 | { | - | ||||||||||||
36 | } | - | ||||||||||||
37 | - | |||||||||||||
38 | - | |||||||||||||
39 | int QQuickSpriteEngine::maxFrames() const | - | ||||||||||||
40 | { | - | ||||||||||||
41 | return executed 312 times by 1 test: m_maxFrames;return m_maxFrames; Executed by:
executed 312 times by 1 test: return m_maxFrames; Executed by:
| 312 | ||||||||||||
42 | } | - | ||||||||||||
43 | int QQuickSpriteEngine::pseudospriteProgress(int sprite, int state, int* rowDuration) const | - | ||||||||||||
44 | { | - | ||||||||||||
45 | int myRowDuration = m_duration[sprite] * m_sprites[state]->m_framesPerRow / m_sprites[state]->m_frames; | - | ||||||||||||
46 | if (rowDuration
| 1168-2840 | ||||||||||||
47 | * executed 1168 times by 1 test: rowDuration = myRowDuration;*rowDuration = myRowDuration; Executed by:
executed 1168 times by 1 test: *rowDuration = myRowDuration; Executed by:
| 1168 | ||||||||||||
48 | - | |||||||||||||
49 | if (m_sprites[state]->reverse()
| 0-4008 | ||||||||||||
50 | return never executed: (m_timeOffset - (m_startTimes[sprite] - (myRowDuration - (m_duration[sprite] % myRowDuration))) )return (m_timeOffset - (m_startTimes[sprite] - (myRowDuration - (m_duration[sprite] % myRowDuration))) ) / myRowDuration; never executed: return (m_timeOffset - (m_startTimes[sprite] - (myRowDuration - (m_duration[sprite] % myRowDuration))) ) / myRowDuration; | 0 | ||||||||||||
51 | / myRowDuration; never executed: return (m_timeOffset - (m_startTimes[sprite] - (myRowDuration - (m_duration[sprite] % myRowDuration))) ) / myRowDuration; | 0 | ||||||||||||
52 | else | - | ||||||||||||
53 | return executed 4008 times by 1 test: (m_timeOffset - m_startTimes[sprite]) / myRowDuration;return (m_timeOffset - m_startTimes[sprite]) / myRowDuration; Executed by:
executed 4008 times by 1 test: return (m_timeOffset - m_startTimes[sprite]) / myRowDuration; Executed by:
| 4008 | ||||||||||||
54 | } | - | ||||||||||||
55 | - | |||||||||||||
56 | int QQuickSpriteEngine::spriteState(int sprite) const | - | ||||||||||||
57 | { | - | ||||||||||||
58 | if (!m_loaded
| 0-1200 | ||||||||||||
59 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
60 | int state = m_things[sprite]; | - | ||||||||||||
61 | if (!m_sprites[state]->m_generatedCount
| 0-1200 | ||||||||||||
62 | return executed 1200 times by 1 test: state;return state; Executed by:
executed 1200 times by 1 test: return state; Executed by:
| 1200 | ||||||||||||
63 | - | |||||||||||||
64 | int extra; | - | ||||||||||||
65 | if (m_sprites[state]->frameSync()
| 0 | ||||||||||||
66 | extra = m_startTimes[sprite]; never executed: extra = m_startTimes[sprite]; | 0 | ||||||||||||
67 | else if (!m_duration[sprite]
| 0 | ||||||||||||
68 | return never executed: state;return state; never executed: return state; | 0 | ||||||||||||
69 | else | - | ||||||||||||
70 | extra = pseudospriteProgress(sprite, state); never executed: extra = pseudospriteProgress(sprite, state); | 0 | ||||||||||||
71 | if (m_sprites[state]->reverse()
| 0 | ||||||||||||
72 | extra = (m_sprites[state]->m_generatedCount - 1) - extra; never executed: extra = (m_sprites[state]->m_generatedCount - 1) - extra; | 0 | ||||||||||||
73 | - | |||||||||||||
74 | return never executed: state + extra;return state + extra; never executed: return state + extra; | 0 | ||||||||||||
75 | } | - | ||||||||||||
76 | - | |||||||||||||
77 | int QQuickSpriteEngine::spriteStart(int sprite) const | - | ||||||||||||
78 | { | - | ||||||||||||
79 | if (!m_duration[sprite]
| 0-2893 | ||||||||||||
80 | return executed 326 times by 2 tests: m_timeOffset;return m_timeOffset; Executed by:
executed 326 times by 2 tests: return m_timeOffset; Executed by:
| 326 | ||||||||||||
81 | int state = m_things[sprite]; | - | ||||||||||||
82 | if (!m_sprites[state]->m_generatedCount
| 580-2313 | ||||||||||||
83 | return executed 2313 times by 3 tests: m_startTimes[sprite];return m_startTimes[sprite]; Executed by:
executed 2313 times by 3 tests: return m_startTimes[sprite]; Executed by:
| 2313 | ||||||||||||
84 | int rowDuration; | - | ||||||||||||
85 | int extra = pseudospriteProgress(sprite, state, &rowDuration); | - | ||||||||||||
86 | if (m_sprites[state]->reverse()
| 0-580 | ||||||||||||
87 | return never executed: m_startTimes[sprite] + (extra ? (extra - 1)*rowDuration + (m_duration[sprite] % rowDuration) : 0);return m_startTimes[sprite] + (extra ? (extra - 1)*rowDuration + (m_duration[sprite] % rowDuration) : 0); never executed: return m_startTimes[sprite] + (extra ? (extra - 1)*rowDuration + (m_duration[sprite] % rowDuration) : 0); | 0 | ||||||||||||
88 | return executed 580 times by 1 test: m_startTimes[sprite] + extra*rowDuration;return m_startTimes[sprite] + extra*rowDuration; Executed by:
executed 580 times by 1 test: return m_startTimes[sprite] + extra*rowDuration; Executed by:
| 580 | ||||||||||||
89 | } | - | ||||||||||||
90 | - | |||||||||||||
91 | int QQuickSpriteEngine::spriteFrames(int sprite) const | - | ||||||||||||
92 | { | - | ||||||||||||
93 | if (!m_loaded
| 0-6604 | ||||||||||||
94 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||
95 | int state = m_things[sprite]; | - | ||||||||||||
96 | if (!m_sprites[state]->m_generatedCount
| 1626-4978 | ||||||||||||
97 | return executed 4978 times by 4 tests: m_sprites[state]->frames();return m_sprites[state]->frames(); Executed by:
executed 4978 times by 4 tests: return m_sprites[state]->frames(); Executed by:
| 4978 | ||||||||||||
98 | - | |||||||||||||
99 | int extra; | - | ||||||||||||
100 | if (m_sprites[state]->frameSync()
| 490-1136 | ||||||||||||
101 | extra = m_startTimes[sprite]; executed 490 times by 2 tests: extra = m_startTimes[sprite]; Executed by:
| 490 | ||||||||||||
102 | else if (!m_duration[sprite]
| 0-1136 | ||||||||||||
103 | return never executed: m_sprites[state]->frames();return m_sprites[state]->frames(); never executed: return m_sprites[state]->frames(); | 0 | ||||||||||||
104 | else | - | ||||||||||||
105 | extra = pseudospriteProgress(sprite, state); executed 1136 times by 1 test: extra = pseudospriteProgress(sprite, state); Executed by:
| 1136 | ||||||||||||
106 | if (m_sprites[state]->reverse()
| 0-1626 | ||||||||||||
107 | extra = (m_sprites[state]->m_generatedCount - 1) - extra; never executed: extra = (m_sprites[state]->m_generatedCount - 1) - extra; | 0 | ||||||||||||
108 | - | |||||||||||||
109 | - | |||||||||||||
110 | if (extra == m_sprites[state]->m_generatedCount - 1
| 326-1300 | ||||||||||||
111 | const int framesRemaining = m_sprites[state]->frames() % m_sprites[state]->m_framesPerRow; | - | ||||||||||||
112 | if (framesRemaining > 0
| 0-326 | ||||||||||||
113 | return executed 326 times by 1 test: framesRemaining;return framesRemaining; Executed by:
executed 326 times by 1 test: return framesRemaining; Executed by:
| 326 | ||||||||||||
114 | } never executed: end of block | 0 | ||||||||||||
115 | return executed 1300 times by 2 tests: m_sprites[state]->m_framesPerRow;return m_sprites[state]->m_framesPerRow; Executed by:
executed 1300 times by 2 tests: return m_sprites[state]->m_framesPerRow; Executed by:
| 1300 | ||||||||||||
116 | } | - | ||||||||||||
117 | - | |||||||||||||
118 | int QQuickSpriteEngine::spriteDuration(int sprite) const | - | ||||||||||||
119 | { | - | ||||||||||||
120 | if (!m_duration[sprite]
| 12-9037 | ||||||||||||
121 | return executed 338 times by 2 tests: m_duration[sprite];return m_duration[sprite]; Executed by:
executed 338 times by 2 tests: return m_duration[sprite]; Executed by:
| 338 | ||||||||||||
122 | int state = m_things[sprite]; | - | ||||||||||||
123 | if (!m_sprites[state]->m_generatedCount
| 588-8437 | ||||||||||||
124 | return executed 8437 times by 4 tests: m_duration[sprite];return m_duration[sprite]; Executed by:
executed 8437 times by 4 tests: return m_duration[sprite]; Executed by:
| 8437 | ||||||||||||
125 | int rowDuration; | - | ||||||||||||
126 | int extra = pseudospriteProgress(sprite, state, &rowDuration); | - | ||||||||||||
127 | if (m_sprites[state]->reverse()
| 0-588 | ||||||||||||
128 | extra = (m_sprites[state]->m_generatedCount - 1) - extra; never executed: extra = (m_sprites[state]->m_generatedCount - 1) - extra; | 0 | ||||||||||||
129 | - | |||||||||||||
130 | if (extra == m_sprites[state]->m_generatedCount - 1
| 121-467 | ||||||||||||
131 | const int durationRemaining = m_duration[sprite] % rowDuration; | - | ||||||||||||
132 | if (durationRemaining > 0
| 0-121 | ||||||||||||
133 | return executed 121 times by 1 test: durationRemaining;return durationRemaining; Executed by:
executed 121 times by 1 test: return durationRemaining; Executed by:
| 121 | ||||||||||||
134 | } never executed: end of block | 0 | ||||||||||||
135 | return executed 467 times by 1 test: rowDuration;return rowDuration; Executed by:
executed 467 times by 1 test: return rowDuration; Executed by:
| 467 | ||||||||||||
136 | } | - | ||||||||||||
137 | - | |||||||||||||
138 | int QQuickSpriteEngine::spriteY(int sprite) const | - | ||||||||||||
139 | { | - | ||||||||||||
140 | if (!m_loaded
| 0-6352 | ||||||||||||
141 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
142 | int state = m_things[sprite]; | - | ||||||||||||
143 | if (!m_sprites[state]->m_generatedCount
| 1398-4954 | ||||||||||||
144 | return executed 4954 times by 4 tests: m_sprites[state]->m_rowY;return m_sprites[state]->m_rowY; Executed by:
executed 4954 times by 4 tests: return m_sprites[state]->m_rowY; Executed by:
| 4954 | ||||||||||||
145 | - | |||||||||||||
146 | int extra; | - | ||||||||||||
147 | if (m_sprites[state]->frameSync()
| 262-1136 | ||||||||||||
148 | extra = m_startTimes[sprite]; executed 262 times by 2 tests: extra = m_startTimes[sprite]; Executed by:
| 262 | ||||||||||||
149 | else if (!m_duration[sprite]
| 0-1136 | ||||||||||||
150 | return never executed: m_sprites[state]->m_rowY;return m_sprites[state]->m_rowY; never executed: return m_sprites[state]->m_rowY; | 0 | ||||||||||||
151 | else | - | ||||||||||||
152 | extra = pseudospriteProgress(sprite, state); executed 1136 times by 1 test: extra = pseudospriteProgress(sprite, state); Executed by:
| 1136 | ||||||||||||
153 | if (m_sprites[state]->reverse()
| 0-1398 | ||||||||||||
154 | extra = (m_sprites[state]->m_generatedCount - 1) - extra; never executed: extra = (m_sprites[state]->m_generatedCount - 1) - extra; | 0 | ||||||||||||
155 | - | |||||||||||||
156 | - | |||||||||||||
157 | return executed 1398 times by 2 tests: m_sprites[state]->m_rowY + m_sprites[state]->m_frameHeight * extra;return m_sprites[state]->m_rowY + m_sprites[state]->m_frameHeight * extra; Executed by:
executed 1398 times by 2 tests: return m_sprites[state]->m_rowY + m_sprites[state]->m_frameHeight * extra; Executed by:
| 1398 | ||||||||||||
158 | } | - | ||||||||||||
159 | - | |||||||||||||
160 | int QQuickSpriteEngine::spriteX(int sprite) const | - | ||||||||||||
161 | { | - | ||||||||||||
162 | if (!m_loaded
| 0-5729 | ||||||||||||
163 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
164 | int state = m_things[sprite]; | - | ||||||||||||
165 | if (!m_sprites[state]->m_generatedCount
| 830-4899 | ||||||||||||
166 | return executed 4899 times by 4 tests: m_sprites[state]->m_rowStartX;return m_sprites[state]->m_rowStartX; Executed by:
executed 4899 times by 4 tests: return m_sprites[state]->m_rowStartX; Executed by:
| 4899 | ||||||||||||
167 | - | |||||||||||||
168 | int extra; | - | ||||||||||||
169 | if (m_sprites[state]->frameSync()
| 262-568 | ||||||||||||
170 | extra = m_startTimes[sprite]; executed 262 times by 2 tests: extra = m_startTimes[sprite]; Executed by:
| 262 | ||||||||||||
171 | else if (!m_duration[sprite]
| 0-568 | ||||||||||||
172 | return never executed: m_sprites[state]->m_rowStartX;return m_sprites[state]->m_rowStartX; never executed: return m_sprites[state]->m_rowStartX; | 0 | ||||||||||||
173 | else | - | ||||||||||||
174 | extra = pseudospriteProgress(sprite, state); executed 568 times by 1 test: extra = pseudospriteProgress(sprite, state); Executed by:
| 568 | ||||||||||||
175 | if (m_sprites[state]->reverse()
| 0-830 | ||||||||||||
176 | extra = (m_sprites[state]->m_generatedCount - 1) - extra; never executed: extra = (m_sprites[state]->m_generatedCount - 1) - extra; | 0 | ||||||||||||
177 | - | |||||||||||||
178 | if (extra
| 344-486 | ||||||||||||
179 | return executed 486 times by 1 test: 0;return 0; Executed by:
executed 486 times by 1 test: return 0; Executed by:
| 486 | ||||||||||||
180 | return executed 344 times by 2 tests: m_sprites[state]->m_rowStartX;return m_sprites[state]->m_rowStartX; Executed by:
executed 344 times by 2 tests: return m_sprites[state]->m_rowStartX; Executed by:
| 344 | ||||||||||||
181 | } | - | ||||||||||||
182 | - | |||||||||||||
183 | QQuickSprite* QQuickSpriteEngine::sprite(int sprite) const | - | ||||||||||||
184 | { | - | ||||||||||||
185 | return executed 137521 times by 4 tests: m_sprites[m_things[sprite]];return m_sprites[m_things[sprite]]; Executed by:
executed 137521 times by 4 tests: return m_sprites[m_things[sprite]]; Executed by:
| 137521 | ||||||||||||
186 | } | - | ||||||||||||
187 | - | |||||||||||||
188 | int QQuickSpriteEngine::spriteWidth(int sprite) const | - | ||||||||||||
189 | { | - | ||||||||||||
190 | int state = m_things[sprite]; | - | ||||||||||||
191 | return executed 6634 times by 4 tests: m_sprites[state]->m_frameWidth;return m_sprites[state]->m_frameWidth; Executed by:
executed 6634 times by 4 tests: return m_sprites[state]->m_frameWidth; Executed by:
| 6634 | ||||||||||||
192 | } | - | ||||||||||||
193 | - | |||||||||||||
194 | int QQuickSpriteEngine::spriteHeight(int sprite) const | - | ||||||||||||
195 | { | - | ||||||||||||
196 | int state = m_things[sprite]; | - | ||||||||||||
197 | return executed 5699 times by 4 tests: m_sprites[state]->m_frameHeight;return m_sprites[state]->m_frameHeight; Executed by:
executed 5699 times by 4 tests: return m_sprites[state]->m_frameHeight; Executed by:
| 5699 | ||||||||||||
198 | } | - | ||||||||||||
199 | - | |||||||||||||
200 | int QQuickSpriteEngine::spriteCount() const | - | ||||||||||||
201 | { | - | ||||||||||||
202 | return never executed: m_imageStateCount;return m_imageStateCount; never executed: return m_imageStateCount; | 0 | ||||||||||||
203 | } | - | ||||||||||||
204 | - | |||||||||||||
205 | void QQuickStochasticEngine::setGoal(int state, int sprite, bool jump) | - | ||||||||||||
206 | { | - | ||||||||||||
207 | if (sprite >= m_things.count()
| 0-1206 | ||||||||||||
208 | || sprite < 0
| 0-1206 | ||||||||||||
209 | return; never executed: return; | 0 | ||||||||||||
210 | if (!jump
| 4-1202 | ||||||||||||
211 | m_goals[sprite] = state; | - | ||||||||||||
212 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||
213 | } | - | ||||||||||||
214 | - | |||||||||||||
215 | if (m_things.at(sprite) == state
| 0-1202 | ||||||||||||
216 | return; never executed: return; | 0 | ||||||||||||
217 | m_things[sprite] = state; | - | ||||||||||||
218 | m_duration[sprite] = m_states.at(state)->variedDuration(); | - | ||||||||||||
219 | m_goals[sprite] = -1; | - | ||||||||||||
220 | restart(sprite); | - | ||||||||||||
221 | stateChanged(sprite); | - | ||||||||||||
222 | m_states.at(state)->entered(); | - | ||||||||||||
223 | return; executed 1202 times by 2 tests: return; Executed by:
| 1202 | ||||||||||||
224 | } | - | ||||||||||||
225 | - | |||||||||||||
226 | QQuickPixmap::Status QQuickSpriteEngine::status() const | - | ||||||||||||
227 | { | - | ||||||||||||
228 | if (!m_startedImageAssembly
| 40-128 | ||||||||||||
229 | return executed 40 times by 5 tests: QQuickPixmap::Null;return QQuickPixmap::Null; Executed by:
executed 40 times by 5 tests: return QQuickPixmap::Null; Executed by:
| 40 | ||||||||||||
230 | int null, loading, ready; | - | ||||||||||||
231 | null = loading = ready = 0; | - | ||||||||||||
232 | for (QQuickSprite* s : m_sprites) { | - | ||||||||||||
233 | switch (s->m_pix.status()) { | - | ||||||||||||
234 | - | |||||||||||||
235 | case never executed: QQuickPixmap::Null :case QQuickPixmap::Null : never executed: null++; break;case QQuickPixmap::Null : never executed: break; | 0 | ||||||||||||
236 | case never executed: QQuickPixmap::Loading :case QQuickPixmap::Loading : never executed: loading++; break;case QQuickPixmap::Loading : never executed: break; | 0 | ||||||||||||
237 | case never executed: QQuickPixmap::Error :case QQuickPixmap::Error : never executed: returncase QQuickPixmap::Error : never executed: QQuickPixmap::Error;return QQuickPixmap::Error; never executed: return QQuickPixmap::Error; | 0 | ||||||||||||
238 | case executed 144 times by 4 tests: QQuickPixmap::Ready :case QQuickPixmap::Ready : Executed by:
executed 144 times by 4 tests: ready++; break;case QQuickPixmap::Ready : Executed by:
executed 144 times by 4 tests: break; Executed by:
| 144 | ||||||||||||
239 | } | - | ||||||||||||
240 | } executed 144 times by 4 tests: end of block Executed by:
| 144 | ||||||||||||
241 | if (null
| 0-128 | ||||||||||||
242 | return never executed: QQuickPixmap::Null;return QQuickPixmap::Null; never executed: return QQuickPixmap::Null; | 0 | ||||||||||||
243 | if (loading
| 0-128 | ||||||||||||
244 | return never executed: QQuickPixmap::Loading;return QQuickPixmap::Loading; never executed: return QQuickPixmap::Loading; | 0 | ||||||||||||
245 | if (ready
| 0-128 | ||||||||||||
246 | return executed 128 times by 4 tests: QQuickPixmap::Ready;return QQuickPixmap::Ready; Executed by:
executed 128 times by 4 tests: return QQuickPixmap::Ready; Executed by:
| 128 | ||||||||||||
247 | return never executed: QQuickPixmap::Null;return QQuickPixmap::Null; never executed: return QQuickPixmap::Null; | 0 | ||||||||||||
248 | } | - | ||||||||||||
249 | - | |||||||||||||
250 | void QQuickSpriteEngine::startAssemblingImage() | - | ||||||||||||
251 | { | - | ||||||||||||
252 | if (m_startedImageAssembly
| 0-44 | ||||||||||||
253 | return; never executed: return; | 0 | ||||||||||||
254 | m_loaded = false; | - | ||||||||||||
255 | m_errorsPrinted = false; | - | ||||||||||||
256 | - | |||||||||||||
257 | - | |||||||||||||
258 | - | |||||||||||||
259 | QList<QQuickStochasticState*> removals; | - | ||||||||||||
260 | - | |||||||||||||
261 | for (QQuickStochasticState* s : qAsConst(m_states)) { | - | ||||||||||||
262 | QQuickSprite* sprite = qobject_cast<QQuickSprite*>(s); | - | ||||||||||||
263 | if (sprite
| 0-50 | ||||||||||||
264 | m_sprites << sprite; | - | ||||||||||||
265 | } executed 50 times by 5 tests: else {end of block Executed by:
| 50 | ||||||||||||
266 | removals << s; | - | ||||||||||||
267 | QMessageLogger(__FILE__, 368, __PRETTY_FUNCTION__).debug() << "Error: Non-sprite in QQuickSpriteEngine"; | - | ||||||||||||
268 | } never executed: end of block | 0 | ||||||||||||
269 | } | - | ||||||||||||
270 | for (QQuickStochasticState* s : qAsConst(removals)) | - | ||||||||||||
271 | m_states.removeAll(s); never executed: m_states.removeAll(s); | 0 | ||||||||||||
272 | m_startedImageAssembly = true; | - | ||||||||||||
273 | } executed 44 times by 5 tests: end of block Executed by:
| 44 | ||||||||||||
274 | - | |||||||||||||
275 | QImage QQuickSpriteEngine::assembledImage(int maxSize) | - | ||||||||||||
276 | { | - | ||||||||||||
277 | QQuickPixmap::Status stat = status(); | - | ||||||||||||
278 | if (!m_errorsPrinted
| 0-44 | ||||||||||||
279 | for (QQuickSprite* s : qAsConst(m_sprites)) | - | ||||||||||||
280 | if (s->m_pix.isError()
| 0 | ||||||||||||
281 | qmlWarning(s) << s->m_pix.error(); never executed: qmlWarning(s) << s->m_pix.error(); | 0 | ||||||||||||
282 | m_errorsPrinted = true; | - | ||||||||||||
283 | } never executed: end of block | 0 | ||||||||||||
284 | - | |||||||||||||
285 | if (stat != QQuickPixmap::Ready
| 0-44 | ||||||||||||
286 | return never executed: QImage();return QImage(); never executed: return QImage(); | 0 | ||||||||||||
287 | - | |||||||||||||
288 | int h = 0; | - | ||||||||||||
289 | int w = 0; | - | ||||||||||||
290 | m_maxFrames = 0; | - | ||||||||||||
291 | m_imageStateCount = 0; | - | ||||||||||||
292 | qreal pixelRatio = 1.0; | - | ||||||||||||
293 | - | |||||||||||||
294 | for (QQuickSprite* state : qAsConst(m_sprites)) { | - | ||||||||||||
295 | if (state->frames() > m_maxFrames
| 4-46 | ||||||||||||
296 | m_maxFrames = state->frames(); executed 46 times by 4 tests: m_maxFrames = state->frames(); Executed by:
| 46 | ||||||||||||
297 | - | |||||||||||||
298 | QImage img = state->m_pix.image(); | - | ||||||||||||
299 | - | |||||||||||||
300 | { | - | ||||||||||||
301 | const QSize frameSize(state->m_frameWidth, state->m_frameHeight); | - | ||||||||||||
302 | if (!(img.size() - frameSize).isValid()
| 10-40 | ||||||||||||
303 | qmlWarning(state).nospace() << "SpriteEngine: Invalid frame size " << frameSize << "." | - | ||||||||||||
304 | " It's bigger than image size " << img.size() << "."; | - | ||||||||||||
305 | return executed 10 times by 1 test: QImage();return QImage(); Executed by:
executed 10 times by 1 test: return QImage(); Executed by:
| 10 | ||||||||||||
306 | } | - | ||||||||||||
307 | } | - | ||||||||||||
308 | - | |||||||||||||
309 | - | |||||||||||||
310 | if (!state->m_frameWidth
| 6-34 | ||||||||||||
311 | state->m_frameWidth = img.width() / state->frames(); executed 34 times by 4 tests: state->m_frameWidth = img.width() / state->frames(); Executed by:
| 34 | ||||||||||||
312 | - | |||||||||||||
313 | if (!state->m_frameHeight
| 6-34 | ||||||||||||
314 | state->m_frameHeight = img.height(); executed 34 times by 4 tests: state->m_frameHeight = img.height(); Executed by:
| 34 | ||||||||||||
315 | - | |||||||||||||
316 | pixelRatio = qMax(pixelRatio, state->devicePixelRatio()); | - | ||||||||||||
317 | - | |||||||||||||
318 | if (state->frames() * state->frameWidth() > maxSize
| 6-34 | ||||||||||||
319 | struct helper{ | - | ||||||||||||
320 | static int divRoundUp(int a, int b){return executed 6 times by 2 tests: (a+b-1)/b;return (a+b-1)/b; Executed by:
executed 6 times by 2 tests: }return (a+b-1)/b; Executed by:
| 6 | ||||||||||||
321 | }; | - | ||||||||||||
322 | int rowsNeeded = helper::divRoundUp(state->frames(), (maxSize / state->frameWidth())); | - | ||||||||||||
323 | if (h + rowsNeeded * state->frameHeight() > maxSize
| 0-6 | ||||||||||||
324 | if (rowsNeeded * state->frameHeight() > maxSize
| 0 | ||||||||||||
325 | qmlWarning(state) << "SpriteEngine: Animation too large to fit in one texture:" << state->source().toLocalFile(); never executed: qmlWarning(state) << "SpriteEngine: Animation too large to fit in one texture:" << state->source().toLocalFile(); | 0 | ||||||||||||
326 | else | - | ||||||||||||
327 | qmlWarning(state) << "SpriteEngine: Animations too large to fit in one texture, pushed over the edge by:" << state->source().toLocalFile(); never executed: qmlWarning(state) << "SpriteEngine: Animations too large to fit in one texture, pushed over the edge by:" << state->source().toLocalFile(); | 0 | ||||||||||||
328 | qmlWarning(state) << "SpriteEngine: Your texture max size today is " << maxSize; | - | ||||||||||||
329 | return never executed: QImage();return QImage(); never executed: return QImage(); | 0 | ||||||||||||
330 | } | - | ||||||||||||
331 | state->m_generatedCount = rowsNeeded; | - | ||||||||||||
332 | h += state->frameHeight() * rowsNeeded; | - | ||||||||||||
333 | w = qMax(w, ((int)(maxSize / state->frameWidth())) * state->frameWidth()); | - | ||||||||||||
334 | m_imageStateCount += rowsNeeded; | - | ||||||||||||
335 | } executed 6 times by 2 tests: else{end of block Executed by:
| 6 | ||||||||||||
336 | h += state->frameHeight(); | - | ||||||||||||
337 | w = qMax(w, state->frameWidth() * state->frames()); | - | ||||||||||||
338 | m_imageStateCount++; | - | ||||||||||||
339 | } executed 34 times by 4 tests: end of block Executed by:
| 34 | ||||||||||||
340 | } | - | ||||||||||||
341 | - | |||||||||||||
342 | if (h > maxSize
| 0-34 | ||||||||||||
343 | QMessageLogger(__FILE__, 444, __PRETTY_FUNCTION__).warning() << "SpriteEngine: Too many animations to fit in one texture..."; | - | ||||||||||||
344 | QMessageLogger(__FILE__, 445, __PRETTY_FUNCTION__).warning() << "SpriteEngine: Your texture max size today is " << maxSize; | - | ||||||||||||
345 | return never executed: QImage();return QImage(); never executed: return QImage(); | 0 | ||||||||||||
346 | } | - | ||||||||||||
347 | - | |||||||||||||
348 | - | |||||||||||||
349 | QImage image(w * pixelRatio, h * pixelRatio, QImage::Format_ARGB32_Premultiplied); | - | ||||||||||||
350 | image.setDevicePixelRatio(pixelRatio); | - | ||||||||||||
351 | image.fill(0); | - | ||||||||||||
352 | QPainter p(&image); | - | ||||||||||||
353 | int y = 0; | - | ||||||||||||
354 | for (QQuickSprite* state : qAsConst(m_sprites)) { | - | ||||||||||||
355 | QImage img(state->m_pix.image()); | - | ||||||||||||
356 | const int frameWidth = state->m_frameWidth; | - | ||||||||||||
357 | const int frameHeight = state->m_frameHeight; | - | ||||||||||||
358 | const int imgHeight = img.height() / img.devicePixelRatioF(); | - | ||||||||||||
359 | const int imgWidth = img.width() / img.devicePixelRatioF(); | - | ||||||||||||
360 | if (imgHeight == frameHeight
| 2-36 | ||||||||||||
361 | p.drawImage(QRect(0, y, state->m_frames * frameWidth, frameHeight), | - | ||||||||||||
362 | img, | - | ||||||||||||
363 | QRect(state->m_frameX * img.devicePixelRatioF(), 0, state->m_frames * frameWidth * img.devicePixelRatioF(), frameHeight * img.devicePixelRatioF())); | - | ||||||||||||
364 | state->m_rowStartX = 0; | - | ||||||||||||
365 | state->m_rowY = y; | - | ||||||||||||
366 | y += frameHeight; | - | ||||||||||||
367 | } executed 34 times by 4 tests: else {end of block Executed by:
| 34 | ||||||||||||
368 | state->m_framesPerRow = w/frameWidth; | - | ||||||||||||
369 | state->m_rowY = y; | - | ||||||||||||
370 | int x = 0; | - | ||||||||||||
371 | int curX = state->m_frameX; | - | ||||||||||||
372 | int curY = state->m_frameY; | - | ||||||||||||
373 | int framesLeft = state->frames(); | - | ||||||||||||
374 | while (framesLeft > 0
| 6-224 | ||||||||||||
375 | if (w - x + curX <= imgWidth
| 72-152 | ||||||||||||
376 | int copied = w - x; | - | ||||||||||||
377 | framesLeft -= copied/frameWidth; | - | ||||||||||||
378 | p.drawImage(QRect(x, y, copied, frameHeight), | - | ||||||||||||
379 | img, | - | ||||||||||||
380 | QRect(curX * img.devicePixelRatioF(), curY * img.devicePixelRatioF(), copied * img.devicePixelRatioF(), frameHeight * img.devicePixelRatioF())); | - | ||||||||||||
381 | y += frameHeight; | - | ||||||||||||
382 | curX += copied; | - | ||||||||||||
383 | x = 0; | - | ||||||||||||
384 | if (curX == imgWidth
| 10-62 | ||||||||||||
385 | curX = 0; | - | ||||||||||||
386 | curY += frameHeight; | - | ||||||||||||
387 | } executed 10 times by 2 tests: end of block Executed by:
| 10 | ||||||||||||
388 | } executed 72 times by 2 tests: else{end of block Executed by:
| 72 | ||||||||||||
389 | int copied = imgWidth - curX; | - | ||||||||||||
390 | framesLeft -= copied/frameWidth; | - | ||||||||||||
391 | p.drawImage(QRect(x, y, copied, frameHeight), | - | ||||||||||||
392 | img, | - | ||||||||||||
393 | QRect(curX * img.devicePixelRatioF(), curY * img.devicePixelRatioF(), copied * img.devicePixelRatioF(), frameHeight * img.devicePixelRatioF())); | - | ||||||||||||
394 | curY += frameHeight; | - | ||||||||||||
395 | x += copied; | - | ||||||||||||
396 | curX = 0; | - | ||||||||||||
397 | } executed 152 times by 1 test: end of block Executed by:
| 152 | ||||||||||||
398 | } | - | ||||||||||||
399 | if (x
| 2-4 | ||||||||||||
400 | y += frameHeight; executed 4 times by 1 test: y += frameHeight; Executed by:
| 4 | ||||||||||||
401 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||
402 | } | - | ||||||||||||
403 | m_loaded = true; | - | ||||||||||||
404 | m_startedImageAssembly = false; | - | ||||||||||||
405 | return executed 34 times by 4 tests: image;return image; Executed by:
executed 34 times by 4 tests: return image; Executed by:
| 34 | ||||||||||||
406 | } | - | ||||||||||||
407 | - | |||||||||||||
408 | - | |||||||||||||
409 | void QQuickStochasticEngine::setCount(int c) | - | ||||||||||||
410 | { | - | ||||||||||||
411 | m_things.resize(c); | - | ||||||||||||
412 | m_goals.resize(c); | - | ||||||||||||
413 | m_duration.resize(c); | - | ||||||||||||
414 | m_startTimes.resize(c); | - | ||||||||||||
415 | } executed 127 times by 6 tests: end of block Executed by:
| 127 | ||||||||||||
416 | - | |||||||||||||
417 | void QQuickStochasticEngine::start(int index, int state) | - | ||||||||||||
418 | { | - | ||||||||||||
419 | if (index >= m_things.count()
| 0-5184 | ||||||||||||
420 | return; never executed: return; | 0 | ||||||||||||
421 | m_things[index] = state; | - | ||||||||||||
422 | m_duration[index] = m_states.at(state)->variedDuration(); | - | ||||||||||||
423 | if (m_states.at(state)->randomStart()
| 0-5184 | ||||||||||||
424 | m_startTimes[index] = NINF; never executed: m_startTimes[index] = NINF; | 0 | ||||||||||||
425 | else | - | ||||||||||||
426 | m_startTimes[index] = 0; executed 5184 times by 5 tests: m_startTimes[index] = 0; Executed by:
| 5184 | ||||||||||||
427 | m_goals[index] = -1; | - | ||||||||||||
428 | m_addAdvance = false; | - | ||||||||||||
429 | restart(index); | - | ||||||||||||
430 | m_addAdvance = true; | - | ||||||||||||
431 | } executed 5184 times by 5 tests: end of block Executed by:
| 5184 | ||||||||||||
432 | - | |||||||||||||
433 | void QQuickStochasticEngine::stop(int index) | - | ||||||||||||
434 | { | - | ||||||||||||
435 | if (index >= m_things.count()
| 0-380 | ||||||||||||
436 | return; never executed: return; | 0 | ||||||||||||
437 | - | |||||||||||||
438 | for (int i=0; i<m_stateUpdates.count()
| 380-5024 | ||||||||||||
439 | m_stateUpdates[i].second.removeAll(index); executed 5024 times by 1 test: m_stateUpdates[i].second.removeAll(index); Executed by:
| 5024 | ||||||||||||
440 | } executed 380 times by 2 tests: end of block Executed by:
| 380 | ||||||||||||
441 | - | |||||||||||||
442 | void QQuickStochasticEngine::restart(int index) | - | ||||||||||||
443 | { | - | ||||||||||||
444 | bool randomStart = (m_startTimes.at(index) == NINF); | - | ||||||||||||
445 | m_startTimes[index] = m_timeOffset; | - | ||||||||||||
446 | if (m_addAdvance
| 2771-18349 | ||||||||||||
447 | m_startTimes[index] += m_advanceTime.elapsed(); executed 18349 times by 1 test: m_startTimes[index] += m_advanceTime.elapsed(); Executed by:
| 18349 | ||||||||||||
448 | if (randomStart
| 0-21120 | ||||||||||||
449 | m_startTimes[index] -= QRandomGenerator::global()->bounded(m_duration.at(index)); never executed: m_startTimes[index] -= QRandomGenerator::global()->bounded(m_duration.at(index)); | 0 | ||||||||||||
450 | int time = m_duration.at(index) + m_startTimes.at(index); | - | ||||||||||||
451 | for (int i=0; i<m_stateUpdates.count()
| 21120-345041 | ||||||||||||
452 | m_stateUpdates[i].second.removeAll(index); executed 345041 times by 1 test: m_stateUpdates[i].second.removeAll(index); Executed by:
| 345041 | ||||||||||||
453 | if (m_duration.at(index) >= 0
| 0-21120 | ||||||||||||
454 | addToUpdateList(time, index); executed 21120 times by 1 test: addToUpdateList(time, index); Executed by:
| 21120 | ||||||||||||
455 | } executed 21120 times by 1 test: end of block Executed by:
| 21120 | ||||||||||||
456 | - | |||||||||||||
457 | void QQuickSpriteEngine::restart(int index) | - | ||||||||||||
458 | { | - | ||||||||||||
459 | bool randomStart = (m_startTimes.at(index) == NINF); | - | ||||||||||||
460 | if (m_loaded
| 12-3722 | ||||||||||||
461 | m_startTimes[index] = 0; | - | ||||||||||||
462 | if (randomStart
| 0-38 | ||||||||||||
463 | m_startTimes[index] += QRandomGenerator::global()->bounded(m_sprites.at(m_things.at(index))->m_generatedCount); never executed: m_startTimes[index] += QRandomGenerator::global()->bounded(m_sprites.at(m_things.at(index))->m_generatedCount); | 0 | ||||||||||||
464 | } executed 38 times by 2 tests: else {end of block Executed by:
| 38 | ||||||||||||
465 | m_startTimes[index] = m_timeOffset; | - | ||||||||||||
466 | if (m_addAdvance
| 1200-2496 | ||||||||||||
467 | m_startTimes[index] += m_advanceTime.elapsed(); executed 1200 times by 1 test: m_startTimes[index] += m_advanceTime.elapsed(); Executed by:
| 1200 | ||||||||||||
468 | if (randomStart
| 0-3696 | ||||||||||||
469 | m_startTimes[index] -= QRandomGenerator::global()->bounded(m_duration.at(index)); never executed: m_startTimes[index] -= QRandomGenerator::global()->bounded(m_duration.at(index)); | 0 | ||||||||||||
470 | int time = spriteDuration(index) + m_startTimes.at(index); | - | ||||||||||||
471 | if (randomStart
| 0-3696 | ||||||||||||
472 | int curTime = m_timeOffset + (m_addAdvance
| 0 | ||||||||||||
473 | while (time < curTime
| 0 | ||||||||||||
474 | time += spriteDuration(index); never executed: time += spriteDuration(index); | 0 | ||||||||||||
475 | } never executed: end of block | 0 | ||||||||||||
476 | - | |||||||||||||
477 | for (int i=0; i<m_stateUpdates.count()
| 3696-130735 | ||||||||||||
478 | m_stateUpdates[i].second.removeAll(index); executed 130735 times by 4 tests: m_stateUpdates[i].second.removeAll(index); Executed by:
| 130735 | ||||||||||||
479 | addToUpdateList(time, index); | - | ||||||||||||
480 | } executed 3696 times by 4 tests: end of block Executed by:
| 3696 | ||||||||||||
481 | } | - | ||||||||||||
482 | - | |||||||||||||
483 | void QQuickStochasticEngine::advance(int idx) | - | ||||||||||||
484 | { | - | ||||||||||||
485 | if (idx >= m_things.count()
| 0-18432 | ||||||||||||
486 | return; never executed: return; | 0 | ||||||||||||
487 | int nextIdx = nextState(m_things.at(idx), idx); | - | ||||||||||||
488 | m_things[idx] = nextIdx; | - | ||||||||||||
489 | m_duration[idx] = m_states.at(nextIdx)->variedDuration(); | - | ||||||||||||
490 | restart(idx); | - | ||||||||||||
491 | m_states.at(nextIdx)->entered(); | - | ||||||||||||
492 | stateChanged(idx); | - | ||||||||||||
493 | } executed 18432 times by 1 test: end of block Executed by:
| 18432 | ||||||||||||
494 | - | |||||||||||||
495 | void QQuickSpriteEngine::advance(int idx) | - | ||||||||||||
496 | { | - | ||||||||||||
497 | if (!m_loaded
| 0-60 | ||||||||||||
498 | QMessageLogger(__FILE__, 608, __PRETTY_FUNCTION__).warning() << QLatin1String("QQuickSpriteEngine: Trying to advance sprites before sprites finish loading. Ignoring directive"); | - | ||||||||||||
499 | return; never executed: return; | 0 | ||||||||||||
500 | } | - | ||||||||||||
501 | - | |||||||||||||
502 | if (idx >= m_things.count()
| 0-60 | ||||||||||||
503 | return; never executed: return; | 0 | ||||||||||||
504 | if (m_duration.at(idx) == 0
| 28-32 | ||||||||||||
505 | if (m_sprites.at(m_things.at(idx))->frameSync()
| 0-32 | ||||||||||||
506 | - | |||||||||||||
507 | m_startTimes[idx]++; | - | ||||||||||||
508 | if (m_startTimes.at(idx) < m_sprites.at(m_things.at(idx))->m_generatedCount
| 12-20 | ||||||||||||
509 | - | |||||||||||||
510 | stateChanged(idx); | - | ||||||||||||
511 | return; executed 12 times by 1 test: return; Executed by:
| 12 | ||||||||||||
512 | } | - | ||||||||||||
513 | } executed 20 times by 2 tests: end of block Executed by:
| 20 | ||||||||||||
514 | - | |||||||||||||
515 | } executed 20 times by 2 tests: else if (m_startTimes.at(idx) + m_duration.at(idx)end of block Executed by:
| 12-20 | ||||||||||||
516 | > int(m_timeOffset + (m_addAdvance ? m_advanceTime.elapsed() : 0))
| 12-16 | ||||||||||||
517 | - | |||||||||||||
518 | stateChanged(idx); | - | ||||||||||||
519 | addToUpdateList(spriteStart(idx) + spriteDuration(idx) + (m_addAdvance ? m_advanceTime.elapsed() : 0), idx); | - | ||||||||||||
520 | return; executed 12 times by 1 test: return; Executed by:
| 12 | ||||||||||||
521 | } | - | ||||||||||||
522 | int nextIdx = nextState(m_things.at(idx), idx); | - | ||||||||||||
523 | m_things[idx] = nextIdx; | - | ||||||||||||
524 | m_duration[idx] = m_states.at(nextIdx)->variedDuration(); | - | ||||||||||||
525 | restart(idx); | - | ||||||||||||
526 | m_states.at(nextIdx)->entered(); | - | ||||||||||||
527 | stateChanged(idx); | - | ||||||||||||
528 | } executed 36 times by 2 tests: end of block Executed by:
| 36 | ||||||||||||
529 | - | |||||||||||||
530 | int QQuickStochasticEngine::nextState(int curState, int curThing) | - | ||||||||||||
531 | { | - | ||||||||||||
532 | int nextIdx = -1; | - | ||||||||||||
533 | int goalPath = goalSeek(curState, curThing); | - | ||||||||||||
534 | if (goalPath == -1
| 0-18468 | ||||||||||||
535 | qreal r = QRandomGenerator::global()->generateDouble(); | - | ||||||||||||
536 | qreal total = 0.0; | - | ||||||||||||
537 | for (QVariantMap::const_iterator iter=m_states.at(curState)->m_to.constBegin(); | - | ||||||||||||
538 | iter!=m_states.at(curState)->m_to.constEnd()
| 1330-18468 | ||||||||||||
539 | total += (*iter).toReal(); executed 1330 times by 2 tests: total += (*iter).toReal(); Executed by:
| 1330 | ||||||||||||
540 | r*=total; | - | ||||||||||||
541 | for (QVariantMap::const_iterator iter= m_states.at(curState)->m_to.constBegin(); | - | ||||||||||||
542 | iter!=m_states.at(curState)->m_to.constEnd()
| 1330-17138 | ||||||||||||
543 | if (r < (*iter).toReal()
| 0-1330 | ||||||||||||
544 | bool superBreak = false; | - | ||||||||||||
545 | for (int i=0; i<m_states.count()
| 0-1332 | ||||||||||||
546 | if (m_states.at(i)->name() == iter.key()
| 2-1330 | ||||||||||||
547 | nextIdx = i; | - | ||||||||||||
548 | superBreak = true; | - | ||||||||||||
549 | break; executed 1330 times by 2 tests: break; Executed by:
| 1330 | ||||||||||||
550 | } | - | ||||||||||||
551 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
552 | if (superBreak
| 0-1330 | ||||||||||||
553 | break; executed 1330 times by 2 tests: break; Executed by:
| 1330 | ||||||||||||
554 | } never executed: end of block | 0 | ||||||||||||
555 | r -= (*iter).toReal(); | - | ||||||||||||
556 | } never executed: end of block | 0 | ||||||||||||
557 | } executed 18468 times by 3 tests: else{end of block Executed by:
| 18468 | ||||||||||||
558 | nextIdx = goalPath; | - | ||||||||||||
559 | } never executed: end of block | 0 | ||||||||||||
560 | if (nextIdx == -1
| 1330-17138 | ||||||||||||
561 | nextIdx = curState; executed 17138 times by 3 tests: nextIdx = curState; Executed by:
| 17138 | ||||||||||||
562 | return executed 18468 times by 3 tests: nextIdx;return nextIdx; Executed by:
executed 18468 times by 3 tests: return nextIdx; Executed by:
| 18468 | ||||||||||||
563 | } | - | ||||||||||||
564 | - | |||||||||||||
565 | uint QQuickStochasticEngine::updateSprites(uint time) | - | ||||||||||||
566 | { | - | ||||||||||||
567 | - | |||||||||||||
568 | m_timeOffset = time; | - | ||||||||||||
569 | m_addAdvance = false; | - | ||||||||||||
570 | int i = 0; | - | ||||||||||||
571 | for (; i < m_stateUpdates.count()
| 357-2660 | ||||||||||||
572 | const auto copy = m_stateUpdates.at(i).second; | - | ||||||||||||
573 | for (int idx : copy) | - | ||||||||||||
574 | advance(idx); executed 18460 times by 3 tests: advance(idx); Executed by:
| 18460 | ||||||||||||
575 | } executed 638 times by 3 tests: end of block Executed by:
| 638 | ||||||||||||
576 | - | |||||||||||||
577 | m_stateUpdates.remove(0, i); | - | ||||||||||||
578 | m_advanceTime.start(); | - | ||||||||||||
579 | m_addAdvance = true; | - | ||||||||||||
580 | if (m_stateUpdates.isEmpty()
| 357-2022 | ||||||||||||
581 | return executed 357 times by 5 tests: uint(-1);return uint(-1); Executed by:
executed 357 times by 5 tests: return uint(-1); Executed by:
| 357 | ||||||||||||
582 | return executed 2022 times by 5 tests: m_stateUpdates.constFirst().first;return m_stateUpdates.constFirst().first; Executed by:
executed 2022 times by 5 tests: return m_stateUpdates.constFirst().first; Executed by:
| 2022 | ||||||||||||
583 | } | - | ||||||||||||
584 | - | |||||||||||||
585 | int QQuickStochasticEngine::goalSeek(int curIdx, int spriteIdx, int dist) | - | ||||||||||||
586 | { | - | ||||||||||||
587 | QString goalName; | - | ||||||||||||
588 | if (m_goals.at(spriteIdx) != -1
| 0-18468 | ||||||||||||
589 | goalName = m_states.at(m_goals.at(spriteIdx))->name(); never executed: goalName = m_states.at(m_goals.at(spriteIdx))->name(); | 0 | ||||||||||||
590 | else | - | ||||||||||||
591 | goalName = m_globalGoal; executed 18468 times by 3 tests: goalName = m_globalGoal; Executed by:
| 18468 | ||||||||||||
592 | if (goalName.isEmpty()
| 0-18468 | ||||||||||||
593 | return executed 18468 times by 3 tests: -1;return -1; Executed by:
executed 18468 times by 3 tests: return -1; Executed by:
| 18468 | ||||||||||||
594 | - | |||||||||||||
595 | - | |||||||||||||
596 | for (int i=0; i<m_states.count()
| 0 | ||||||||||||
597 | if (m_states.at(curIdx)->name() == goalName
| 0 | ||||||||||||
598 | return never executed: curIdx;return curIdx; never executed: return curIdx; | 0 | ||||||||||||
599 | if (dist < 0
| 0 | ||||||||||||
600 | dist = m_states.count(); never executed: dist = m_states.count(); | 0 | ||||||||||||
601 | QQuickStochasticState* curState = m_states.at(curIdx); | - | ||||||||||||
602 | for (QVariantMap::const_iterator iter = curState->m_to.constBegin(); | - | ||||||||||||
603 | iter!=curState->m_to.constEnd()
| 0 | ||||||||||||
604 | if (iter.key() == goalName
| 0 | ||||||||||||
605 | for (int i=0; i<m_states.count()
| 0 | ||||||||||||
606 | if (m_states.at(i)->name() == goalName
| 0 | ||||||||||||
607 | return never executed: i;return i; never executed: return i; | 0 | ||||||||||||
608 | } never executed: end of block | 0 | ||||||||||||
609 | QSet<int> options; | - | ||||||||||||
610 | for (int i=1; i<dist
| 0 | ||||||||||||
611 | for (QVariantMap::const_iterator iter = curState->m_to.constBegin(); | - | ||||||||||||
612 | iter!=curState->m_to.constEnd()
| 0 | ||||||||||||
613 | int option = -1; | - | ||||||||||||
614 | for (int j=0; j<m_states.count()
| 0 | ||||||||||||
615 | if (m_states.at(j)->name() == iter.key()
| 0 | ||||||||||||
616 | if (goalSeek(j, spriteIdx, i) != -1
| 0 | ||||||||||||
617 | option = j; never executed: option = j; | 0 | ||||||||||||
618 | if (option != -1
| 0 | ||||||||||||
619 | options << option; never executed: options << option; | 0 | ||||||||||||
620 | } never executed: end of block | 0 | ||||||||||||
621 | if (!options.isEmpty()
| 0 | ||||||||||||
622 | if (options.count()==1
| 0 | ||||||||||||
623 | return never executed: *(options.begin());return *(options.begin()); never executed: return *(options.begin()); | 0 | ||||||||||||
624 | int option = -1; | - | ||||||||||||
625 | qreal r = QRandomGenerator::global()->generateDouble(); | - | ||||||||||||
626 | qreal total = 0; | - | ||||||||||||
627 | for (QSet<int>::const_iterator iter=options.constBegin(); | - | ||||||||||||
628 | iter!=options.constEnd()
| 0 | ||||||||||||
629 | total += curState->m_to.value(m_states.at((*iter))->name()).toReal(); never executed: total += curState->m_to.value(m_states.at((*iter))->name()).toReal(); | 0 | ||||||||||||
630 | r *= total; | - | ||||||||||||
631 | for (QVariantMap::const_iterator iter = curState->m_to.constBegin(); | - | ||||||||||||
632 | iter!=curState->m_to.constEnd()
| 0 | ||||||||||||
633 | bool superContinue = true; | - | ||||||||||||
634 | for (int j=0; j<m_states.count()
| 0 | ||||||||||||
635 | if (m_states.at(j)->name() == iter.key()
| 0 | ||||||||||||
636 | if (options.contains(j)
| 0 | ||||||||||||
637 | superContinue = false; never executed: superContinue = false; | 0 | ||||||||||||
638 | if (superContinue
| 0 | ||||||||||||
639 | continue; never executed: continue; | 0 | ||||||||||||
640 | if (r < (*iter).toReal()
| 0 | ||||||||||||
641 | bool superBreak = false; | - | ||||||||||||
642 | for (int j=0; j<m_states.count()
| 0 | ||||||||||||
643 | if (m_states.at(j)->name() == iter.key()
| 0 | ||||||||||||
644 | option = j; | - | ||||||||||||
645 | superBreak = true; | - | ||||||||||||
646 | break; never executed: break; | 0 | ||||||||||||
647 | } | - | ||||||||||||
648 | } never executed: end of block | 0 | ||||||||||||
649 | if (superBreak
| 0 | ||||||||||||
650 | break; never executed: break; | 0 | ||||||||||||
651 | } never executed: end of block | 0 | ||||||||||||
652 | r-=(*iter).toReal(); | - | ||||||||||||
653 | } never executed: end of block | 0 | ||||||||||||
654 | return never executed: option;return option; never executed: return option; | 0 | ||||||||||||
655 | } | - | ||||||||||||
656 | } never executed: end of block | 0 | ||||||||||||
657 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
658 | } | - | ||||||||||||
659 | - | |||||||||||||
660 | void QQuickStochasticEngine::addToUpdateList(uint t, int idx) | - | ||||||||||||
661 | { | - | ||||||||||||
662 | for (int i=0; i<m_stateUpdates.count()
| 770-447545 | ||||||||||||
663 | if (m_stateUpdates.at(i).first == t
| 23896-423649 | ||||||||||||
664 | m_stateUpdates[i].second << idx; | - | ||||||||||||
665 | return; executed 23896 times by 4 tests: return; Executed by:
| 23896 | ||||||||||||
666 | } else if (m_stateUpdates.at(i).first > t
| 162-423487 | ||||||||||||
667 | QVector<int> tmpList; | - | ||||||||||||
668 | tmpList << idx; | - | ||||||||||||
669 | m_stateUpdates.insert(i, qMakePair(t, tmpList)); | - | ||||||||||||
670 | return; executed 162 times by 1 test: return; Executed by:
| 162 | ||||||||||||
671 | } | - | ||||||||||||
672 | } executed 423487 times by 5 tests: end of block Executed by:
| 423487 | ||||||||||||
673 | QVector<int> tmpList; | - | ||||||||||||
674 | tmpList << idx; | - | ||||||||||||
675 | m_stateUpdates << qMakePair(t, tmpList); | - | ||||||||||||
676 | } executed 770 times by 5 tests: end of block Executed by:
| 770 | ||||||||||||
677 | - | |||||||||||||
678 | - | |||||||||||||
679 | - | |||||||||||||
Switch to Source code | Preprocessed file |