From dc58d1a61e6fd97c6a08b6284354eb66de6b71cd Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Wed, 15 Oct 2014 19:51:08 +0200 Subject: [PATCH 1/4] Shortened animation time between phases + changed from 50ms to 25ms between update calls. --- cockatrice/src/phasestoolbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cockatrice/src/phasestoolbar.cpp b/cockatrice/src/phasestoolbar.cpp index 9b22f611..35265ba8 100644 --- a/cockatrice/src/phasestoolbar.cpp +++ b/cockatrice/src/phasestoolbar.cpp @@ -65,7 +65,7 @@ void PhaseButton::setActive(bool _active) return; active = _active; - activeAnimationTimer->start(50); + activeAnimationTimer->start(25); } void PhaseButton::updateAnimation() From 2193d247d0d87a6c913a908560406f362a31d190 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Thu, 16 Oct 2014 01:31:53 +0200 Subject: [PATCH 2/4] Improved card animation performance + Cards now animate smoother and faster + removed redundant computations performed each frame --- cockatrice/src/carditem.cpp | 10 ++++++---- cockatrice/src/carditem.h | 3 +++ cockatrice/src/gamescene.cpp | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/carditem.cpp b/cockatrice/src/carditem.cpp index e7ce6482..cb0bcea5 100644 --- a/cockatrice/src/carditem.cpp +++ b/cockatrice/src/carditem.cpp @@ -17,6 +17,7 @@ #include "tab_game.h" #include "pb/serverinfo_card.pb.h" + CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, bool _revealedCard, QGraphicsItem *parent) : AbstractCardItem(_name, _owner, _cardid, parent), zone(0), revealedCard(_revealedCard), attacking(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0) { @@ -360,15 +361,16 @@ void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) event->accept(); } + bool CardItem::animationEvent() { - int delta = 18; + int delta = DELTA; if (!tapped) delta *= -1; - + tapAngle += delta; - - setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2)); + + setTransform(QTransform().translate(CARD_WIDTH_HALF, CARD_HEIGHT_HALF).rotate(tapAngle).translate(-CARD_WIDTH_HALF, -CARD_HEIGHT_HALF)); setHovered(false); update(); diff --git a/cockatrice/src/carditem.h b/cockatrice/src/carditem.h index 9952550d..0a9ab08f 100644 --- a/cockatrice/src/carditem.h +++ b/cockatrice/src/carditem.h @@ -12,6 +12,9 @@ class QAction; class QColor; const int MAX_COUNTERS_ON_CARD = 999; +const float CARD_WIDTH_HALF = CARD_WIDTH / 2; +const float CARD_HEIGHT_HALF = CARD_HEIGHT / 2; +const int DELTA = 10; class CardItem : public AbstractCardItem { Q_OBJECT diff --git a/cockatrice/src/gamescene.cpp b/cockatrice/src/gamescene.cpp index 8e777168..f5f11cef 100644 --- a/cockatrice/src/gamescene.cpp +++ b/cockatrice/src/gamescene.cpp @@ -262,7 +262,7 @@ void GameScene::registerAnimationItem(AbstractCardItem *card) { cardsToAnimate.insert(static_cast(card)); if (!animationTimer->isActive()) - animationTimer->start(50, this); + animationTimer->start(15, this); } void GameScene::unregisterAnimationItem(AbstractCardItem *card) From c130ee92fa4394979248e5e94afe8f5ccf0301b5 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Mon, 3 Nov 2014 14:39:51 +0100 Subject: [PATCH 3/4] Additional comment + Added additional comment explaining what DELTA is. --- cockatrice/src/carditem.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cockatrice/src/carditem.h b/cockatrice/src/carditem.h index 0a9ab08f..c9cbaefc 100644 --- a/cockatrice/src/carditem.h +++ b/cockatrice/src/carditem.h @@ -14,6 +14,7 @@ class QColor; const int MAX_COUNTERS_ON_CARD = 999; const float CARD_WIDTH_HALF = CARD_WIDTH / 2; const float CARD_HEIGHT_HALF = CARD_HEIGHT / 2; +// DELTA is the degrees of rotation that will animate between frames const int DELTA = 10; class CardItem : public AbstractCardItem { From 097090ac1c2334435f79dafc4bd80b004aff841e Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Mon, 3 Nov 2014 16:33:48 +0100 Subject: [PATCH 4/4] Updated static variable name + Updated DELTA variable to more suitable name: ROTATION_DEGREES_PER_FRAME --- cockatrice/src/carditem.cpp | 6 +++--- cockatrice/src/carditem.h | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/carditem.cpp b/cockatrice/src/carditem.cpp index cb0bcea5..be449fb9 100644 --- a/cockatrice/src/carditem.cpp +++ b/cockatrice/src/carditem.cpp @@ -364,11 +364,11 @@ void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) bool CardItem::animationEvent() { - int delta = DELTA; + int rotation = ROTATION_DEGREES_PER_FRAME; if (!tapped) - delta *= -1; + rotation *= -1; - tapAngle += delta; + tapAngle += rotation; setTransform(QTransform().translate(CARD_WIDTH_HALF, CARD_HEIGHT_HALF).rotate(tapAngle).translate(-CARD_WIDTH_HALF, -CARD_HEIGHT_HALF)); setHovered(false); diff --git a/cockatrice/src/carditem.h b/cockatrice/src/carditem.h index c9cbaefc..524c1695 100644 --- a/cockatrice/src/carditem.h +++ b/cockatrice/src/carditem.h @@ -14,8 +14,7 @@ class QColor; const int MAX_COUNTERS_ON_CARD = 999; const float CARD_WIDTH_HALF = CARD_WIDTH / 2; const float CARD_HEIGHT_HALF = CARD_HEIGHT / 2; -// DELTA is the degrees of rotation that will animate between frames -const int DELTA = 10; +const int ROTATION_DEGREES_PER_FRAME = 10; class CardItem : public AbstractCardItem { Q_OBJECT