• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kgoldrunner

  • sources
  • kde-4.14
  • kdegames
  • kgoldrunner
  • src
kgrtimer.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright 2009 Ian Wadham <iandw.au@gmail.com> *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16  ****************************************************************************/
17 
18 #include "kgrtimer.h"
19 
20 #include <KDebug>
21 
22 KGrTimer::KGrTimer (QObject * parent, int pTickTime, float pScale)
23  :
24  QObject (parent),
25  t (QTime()),
26  ticker (new QTimer (parent)),
27  tickTime (pTickTime),
28  tickCount (0),
29  halfTick (pTickTime / 2),
30  expectedTime (0)
31 {
32  setScale (pScale);
33  connect (ticker, SIGNAL (timeout()), this, SLOT (internalSlot()));
34  ticker->start (tickTime);
35  t.start();
36 }
37 
38 KGrTimer::~KGrTimer()
39 {
40  ticker->stop();
41 }
42 
43 void KGrTimer::pause()
44 {
45  ticker->stop();
46 }
47 
48 void KGrTimer::resume()
49 {
50  ticker->start (tickTime);
51  t.start();
52  expectedTime = 0;
53 }
54 
55 void KGrTimer::step()
56 {
57  tickCount++;
58  expectedTime = expectedTime + tickTime;
59  emit tick (false, scaledTime);
60 }
61 
62 void KGrTimer::internalSlot()
63 {
64  // Check whether the QTimer::timeout() signal is on-time.
65  int timeOnClock = t.elapsed();
66 
67  // If the signal is too early, ignore it. If it is on-time +/-halfTick,
68  // trigger an internal signal. If it is late, trigger more internal
69  // signals, in order to "catch up".
70 
71  while (timeOnClock > (expectedTime + halfTick)) {
72  tickCount++;
73  expectedTime = expectedTime + tickTime;
74  emit tick ((timeOnClock >= (expectedTime + tickTime)), scaledTime);
75  }
76 }
77 
78 #include "kgrtimer.moc"
KGrTimer::setScale
void setScale(const float pScale)
Definition: kgrtimer.h:35
KGrTimer::tick
void tick(bool missed, int pScaledTime)
This signal powers the whole game.
kgrtimer.h
KGrTimer::KGrTimer
KGrTimer(QObject *parent, int pTick=20, float pScale=1.0)
Definition: kgrtimer.cpp:22
KGrTimer::step
void step()
Definition: kgrtimer.cpp:55
KGrTimer::resume
void resume()
Definition: kgrtimer.cpp:48
QTime
QTime::elapsed
int elapsed() const
QTimer
QObject
KGrTimer::~KGrTimer
~KGrTimer()
Definition: kgrtimer.cpp:38
QTimer::stop
void stop()
KGrTimer::pause
void pause()
Definition: kgrtimer.cpp:43
QTimer::start
void start(int msec)
QTime::start
void start()
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:24 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgoldrunner

Skip menu "kgoldrunner"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal