Port away from deprecated KRandomSequence

GIT_SILENT
parent 2939ff7a
......@@ -8,8 +8,8 @@ set(RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_
project(kgoldrunner VERSION ${RELEASE_SERVICE_VERSION})
set (QT_MIN_VERSION "5.7.0")
set (KF5_MIN_VERSION "5.57.0")
set (QT_MIN_VERSION "5.10.0")
set (KF5_MIN_VERSION "5.55.0")
find_package(ECM ${KF5_MIN_VERSION} REQUIRED CONFIG)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
......
......@@ -36,7 +36,6 @@
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <QByteArray>
#include <QDate>
......@@ -53,17 +52,15 @@
#include <QTreeWidgetItem>
#include <QVBoxLayout>
#include <QFileInfo>
#include <QRandomGenerator>
#include <KConfigGroup>
#include <KGuiItem>
#include <KRandomSequence>
#include <KSharedConfig>
#include <KStandardGuiItem>
#include <KLocalizedString>
#include <KMessageBox>
#include <chrono>
#include "kgoldrunner_debug.h"
// TODO - Can we change over to KScoreDialog?
......@@ -117,9 +114,7 @@ KGrGame::KGrGame (KGrView * theView,
connect(dyingTimer, &QTimer::timeout, this, &KGrGame::finalBreath);
// Initialise random number generator.
const auto tse = std::chrono::system_clock::now().time_since_epoch();
const long int seed = std::chrono::duration_cast<std::chrono::seconds>(tse).count();
randomGen = new KRandomSequence (seed);
randomGen = new QRandomGenerator (QRandomGenerator::global()->generate());
//qCDebug(KGOLDRUNNER_LOG) << "RANDOM NUMBER GENERATOR INITIALISED";
scene->setReplayMessage (i18n("Click anywhere to begin live play"));
......
......@@ -39,7 +39,7 @@ class KGrSounds;
class KGrEditor;
class KGrLevelPlayer;
class KRandomSequence;
class QRandomGenerator;
class QTimer;
class KGrGame : public QObject
......@@ -182,7 +182,7 @@ private:
/************************** PLAYFIELD AND GAME DATA *************************/
/******************************************************************************/
KRandomSequence * randomGen; // Random number generator.
QRandomGenerator * randomGen; // Random number generator.
KGrLevelPlayer * levelPlayer; // Where the level is played.
KGrRecording * recording; // A recording of the play.
bool playback; // Play back or record?
......
......@@ -18,6 +18,8 @@
#include <cstdio>
#include <cstdlib>
#include <QRandomGenerator>
// Include kgrgame.h only to access flags KGrGame::bugFix and KGrGame::logging.
#include "kgrgame.h"
#include "kgrscene.h"
......@@ -32,9 +34,8 @@
#include "kgoldrunner_debug.h"
#include <KMessageBox> // TODO - Remove.
#include <KRandomSequence>
KGrLevelPlayer::KGrLevelPlayer (KGrGame * parent, KRandomSequence * pRandomGen)
KGrLevelPlayer::KGrLevelPlayer (KGrGame * parent, QRandomGenerator * pRandomGen)
:
QObject (parent),
game (parent),
......@@ -881,7 +882,7 @@ void KGrLevelPlayer::enemyReappear (int & gridI, int & gridJ)
uchar KGrLevelPlayer::randomByte (const uchar limit)
{
if (! playback) {
uchar value = randomGen->getLong ((unsigned long) limit);
uchar value = randomGen->bounded(limit);
// A zero-byte terminates recording->draws, so add 1 when recording ...
dbe2 "Draw %03d, index %04d, limit %02d\n", value, randIndex, limit);
recording->draws [randIndex++] = value + 1;
......
......@@ -34,7 +34,7 @@ class KGrHero;
class KGrGame;
class KGrEnemy;
class KRandomSequence;
class QRandomGenerator;
/**
* @short Class to play, record and play back a level of a game
......@@ -75,7 +75,7 @@ public:
* play.
* @param pRandomGen A shared source of random numbers for all enemies.
*/
KGrLevelPlayer (KGrGame * parent, KRandomSequence * pRandomGen);
KGrLevelPlayer (KGrGame * parent, QRandomGenerator * pRandomGen);
~KGrLevelPlayer();
/**
......@@ -391,7 +391,7 @@ private Q_SLOTS:
private:
KGrGame * game;
KRandomSequence * randomGen;
QRandomGenerator * randomGen;
KGrLevelGrid * grid;
KGrRuleBook * rules;
KGrHero * hero;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment