10#include <QRandomGenerator>
42static const int NINF = -1000000;
44#ifdef SPRITE_IMAGE_DEBUG
106int QQuickSpriteEngine::pseudospriteProgress(
int sprite,
int state,
int* rowDuration)
const
110 *rowDuration = myRowDuration;
112 if (m_sprites[
state]->reverse())
124 if (!m_sprites[
state]->m_generatedCount)
128 if (m_sprites[
state]->frameSync())
134 if (m_sprites[
state]->reverse())
135 extra = (m_sprites[
state]->m_generatedCount - 1) - extra;
137 return state + extra;
145 if (!m_sprites[
state]->m_generatedCount)
148 int extra = pseudospriteProgress(
sprite,
state, &rowDuration);
149 if (m_sprites[
state]->reverse())
159 if (!m_sprites[
state]->m_generatedCount)
160 return m_sprites[
state]->frames();
163 if (m_sprites[
state]->frameSync())
166 return m_sprites[
state]->frames();
169 if (m_sprites[
state]->reverse())
170 extra = (m_sprites[
state]->m_generatedCount - 1) - extra;
173 if (extra == m_sprites[
state]->m_generatedCount - 1) {
174 const int framesRemaining = m_sprites[
state]->frames() % m_sprites[
state]->m_framesPerRow;
175 if (framesRemaining > 0)
176 return framesRemaining;
178 return m_sprites[
state]->m_framesPerRow;
183 if (!m_duration[sprite] || !m_loaded)
184 return m_duration[sprite];
185 int state = m_things[sprite];
186 if (!m_sprites[
state]->m_generatedCount)
187 return m_duration[sprite];
189 int extra = pseudospriteProgress(sprite,
state, &rowDuration);
190 if (m_sprites[
state]->reverse())
191 extra = (m_sprites[
state]->m_generatedCount - 1) - extra;
193 if (extra == m_sprites[
state]->m_generatedCount - 1) {
194 const int durationRemaining = m_duration[sprite] % rowDuration;
195 if (durationRemaining > 0)
196 return durationRemaining;
206 if (!m_sprites[
state]->m_generatedCount)
207 return m_sprites[
state]->m_rowY;
210 if (m_sprites[
state]->frameSync())
213 return m_sprites[
state]->m_rowY;
216 if (m_sprites[
state]->reverse())
217 extra = (m_sprites[
state]->m_generatedCount - 1) - extra;
220 return m_sprites[
state]->m_rowY + m_sprites[
state]->m_frameHeight * extra;
228 if (!m_sprites[
state]->m_generatedCount)
229 return m_sprites[
state]->m_rowStartX;
232 if (m_sprites[
state]->frameSync())
235 return m_sprites[
state]->m_rowStartX;
238 if (m_sprites[
state]->reverse())
239 extra = (m_sprites[
state]->m_generatedCount - 1) - extra;
243 return m_sprites[
state]->m_rowStartX;
254 return m_sprites[
state]->m_frameWidth;
260 return m_sprites[
state]->m_frameHeight;
271 || sprite < 0 ||
state < 0)
291 if (!m_startedImageAssembly)
293 int null, loading, ready;
294 null = loading = ready = 0;
296 switch (
s->m_pix.status()) {
315 if (m_startedImageAssembly)
318 m_errorsPrinted =
false;
331 qDebug() <<
"Error: Non-sprite in QQuickSpriteEngine";
336 m_startedImageAssembly =
true;
344 if (
s->m_pix.isError())
346 m_errorsPrinted =
true;
356 qreal pixelRatio = 1.0;
368 " It's bigger than image size " <<
img.size() <<
".";
374 if (!
state->m_frameWidth)
377 if (!
state->m_frameHeight)
378 state->m_frameHeight =
img.height();
380 pixelRatio =
qMax(pixelRatio,
state->devicePixelRatio());
382 if (
state->frames() *
state->frameWidth() > maxSize){
384 static int divRoundUp(
int a,
int b){
return (
a+
b-1)/
b;}
386 int rowsNeeded = helper::divRoundUp(
state->frames(), (maxSize /
state->frameWidth()));
387 if (
h + rowsNeeded *
state->frameHeight() > maxSize){
388 if (rowsNeeded *
state->frameHeight() > maxSize)
389 qmlWarning(
state) <<
"SpriteEngine: Animation too large to fit in one texture:" <<
state->source().toLocalFile();
391 qmlWarning(
state) <<
"SpriteEngine: Animations too large to fit in one texture, pushed over the edge by:" <<
state->source().toLocalFile();
392 qmlWarning(
state) <<
"SpriteEngine: Your texture max size today is " << maxSize;
395 state->m_generatedCount = rowsNeeded;
396 h +=
state->frameHeight() * rowsNeeded;
400 h +=
state->frameHeight();
407 qWarning() <<
"SpriteEngine: Too many animations to fit in one texture...";
408 qWarning() <<
"SpriteEngine: Your texture max size today is " << maxSize;
414 image.setDevicePixelRatio(pixelRatio);
420 const int frameWidth =
state->m_frameWidth;
421 const int frameHeight =
state->m_frameHeight;
422 const int imgHeight =
img.height() /
img.devicePixelRatio();
423 const int imgWidth =
img.width() /
img.devicePixelRatio();
424 if (imgHeight == frameHeight && imgWidth < maxSize){
425 p.drawImage(
QRect(0,
y,
state->m_frames * frameWidth, frameHeight),
427 QRect(
state->m_frameX *
img.devicePixelRatio(), 0,
state->m_frames * frameWidth *
img.devicePixelRatio(), frameHeight *
img.devicePixelRatio()));
428 state->m_rowStartX = 0;
432 state->m_framesPerRow =
w/frameWidth;
435 int curX =
state->m_frameX;
436 int curY =
state->m_frameY;
437 int framesLeft =
state->frames();
438 while (framesLeft > 0){
439 if (
w -
x + curX <= imgWidth){
441 framesLeft -= copied/frameWidth;
442 p.drawImage(
QRect(
x,
y, copied, frameHeight),
444 QRect(curX *
img.devicePixelRatio(), curY *
img.devicePixelRatio(), copied *
img.devicePixelRatio(), frameHeight *
img.devicePixelRatio()));
448 if (curX == imgWidth){
453 int copied = imgWidth - curX;
454 framesLeft -= copied/frameWidth;
455 p.drawImage(
QRect(
x,
y, copied, frameHeight),
457 QRect(curX *
img.devicePixelRatio(), curY *
img.devicePixelRatio(), copied *
img.devicePixelRatio(), frameHeight *
img.devicePixelRatio()));
468#ifdef SPRITE_IMAGE_DEBUG
473 qDebug() <<
"Assembled image output to: " << fPath.
arg(acc);
477 m_startedImageAssembly =
false;
546 while (
time < curTime)
571 qWarning() <<
QLatin1String(
"QQuickSpriteEngine: Trying to advance sprites before sprites finish loading. Ignoring directive");
612 total += (*iter).toReal();
616 if (
r < (*iter).toReal()){
617 bool superBreak =
false;
628 r -= (*iter).toReal();
661 if (
m_goals.at(spriteIdx) != -1)
675 for (QVariantMap::const_iterator
iter =
curState->m_to.constBegin();
677 if (
iter.key() == goalName)
684 for (QVariantMap::const_iterator
iter =
curState->m_to.constBegin();
695 if (options.
size()==1)
696 return *(options.
begin());
704 for (QVariantMap::const_iterator
iter =
curState->m_to.constBegin();
706 bool superContinue =
true;
710 superContinue =
false;
713 if (
r < (*iter).toReal()){
714 bool superBreak =
false;
753#include "moc_qquickspriteengine_p.cpp"
static QString tempPath()
Returns the absolute canonical path of the system's temporary directory.
qint64 elapsed() const noexcept
Returns the number of milliseconds since this QElapsedTimer was last started.
void start() noexcept
Starts this timer.
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
@ Format_ARGB32_Premultiplied
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
qsizetype removeAll(const AT &t)
const_iterator constBegin() const
const_iterator constEnd() const
The QPainter class performs low-level painting on widgets and other paint devices.
int spriteDuration(int sprite=0) const
QQuickSprite * sprite(int sprite=0) const
~QQuickSpriteEngine() override
int spriteFrames(int sprite=0) const
QQuickPixmap::Status status() const
int spriteStart(int sprite=0) const
int spriteX(int sprite=0) const
void advance(int index=0) override
void startAssemblingImage()
int spriteState(int sprite=0) const
void restart(int index=0) override
int spriteHeight(int sprite=0) const
int spriteWidth(int sprite=0) const
QQmlListProperty< QQuickSprite > sprites
QQuickSpriteEngine(QObject *parent=nullptr)
int spriteY(int sprite=0) const
QImage assembledImage(int maxSize=2048)
QElapsedTimer m_advanceTimer
void stateChanged(int idx)
void start(int index=0, int state=0)
QQuickStochasticEngine(QObject *parent=nullptr)
QVector< QPair< uint, QVector< int > > > m_stateUpdates
QList< QQuickStochasticState * > m_states
int goalSeek(int curState, int idx, int dist=-1)
QVector< int > m_duration
virtual void advance(int index=0)
uint updateSprites(uint time)
~QQuickStochasticEngine() override
int curState(int index=0) const
void addToUpdateList(uint t, int idx)
QVector< int > m_startTimes
void setGoal(int state, int sprite=0, bool jump=false)
int nextState(int curState, int idx=0)
virtual void restart(int index=0)
virtual int variedDuration() const
double generateDouble()
Generates one random qreal in the canonical range [0, 1) (that is, inclusive of zero and exclusive of...
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
\threadsafe
double bounded(double highest)
Generates one random double in the range between 0 (inclusive) and highest (exclusive).
\inmodule QtCore\reentrant
const_iterator constBegin() const noexcept
const_iterator constEnd() const noexcept
bool contains(const T &value) const
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Combined button and popup list for selecting options.
static jboolean copy(JNIEnv *, jobject)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter * iter
static void jump(QtMsgType t, const QMessageLogContext &context, const QString &m)
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLfloat GLfloat GLfloat GLfloat h
constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
static constexpr QSize frameSize(const T &frame)
static QT_BEGIN_NAMESPACE const int NINF
QLatin1StringView QLatin1String
std::uniform_real_distribution dist(1, 2.5)
[2]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent