summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasem Mutlaq <mutlaqja@ikarustech.com>2016-11-06 10:48:31 (GMT)
committerJasem Mutlaq <mutlaqja@ikarustech.com>2016-11-06 10:48:31 (GMT)
commita4751fe5550c3b678c8df8e073112088183bd905 (patch)
tree4e017c43700191bacd13d278cff7bb0f155ec669
parent09f7929799b17d2655029a5bdcd9bd83834d15b9 (diff)
SIGNIFICANT boost in startup speed from using a combination of delayed image loading, which also saves RAM, and QtConcurrent. The usage of QtConcurrent has to be carefully examined since we do want out-of-sequence loading where data cannot be read properly. So far it seems to work well but have to try it on Raspberry PI and also on Android
-rw-r--r--kstars/kstarsdata.cpp20
-rw-r--r--kstars/skycomponents/constellationnamescomponent.cpp14
-rw-r--r--kstars/skycomponents/constellationnamescomponent.h2
-rw-r--r--kstars/skycomponents/milkyway.cpp13
-rw-r--r--kstars/skycomponents/satellitescomponent.cpp18
-rw-r--r--kstars/skycomponents/satellitescomponent.h2
-rw-r--r--kstars/skycomponents/starcomponent.cpp6
-rw-r--r--kstars/skyobjects/constellationsart.cpp8
-rw-r--r--kstars/skyobjects/constellationsart.h3
-rw-r--r--kstars/skyobjects/deepskyobject.cpp9
-rw-r--r--kstars/skyobjects/deepskyobject.h3
11 files changed, 70 insertions, 28 deletions
diff --git a/kstars/kstarsdata.cpp b/kstars/kstarsdata.cpp
index 3253873..5c21ec0 100644
--- a/kstars/kstarsdata.cpp
+++ b/kstars/kstarsdata.cpp
@@ -23,6 +23,7 @@
#include <QTextStream>
#include <QDebug>
#include <QStandardPaths>
+#include <QtConcurrent>
#ifndef KSTARS_LITE
#include <KMessageBox>
#endif
@@ -70,7 +71,9 @@ namespace {
// Report non-fatal error during data loading to user and ask
// whether he wants to continue.
// Calls QApplication::exit if he don't
- bool nonFatalErrorMessage(QString fname) {
+#if 0
+ bool nonFatalErrorMessage(QString fname)
+ {
#ifdef KSTARS_LITE
Q_UNUSED(fname)
#else
@@ -88,6 +91,7 @@ namespace {
#endif
return true;
}
+#endif
}
KStarsData* KStarsData::pinstance = 0;
@@ -177,15 +181,19 @@ bool KStarsData::initialize() {
//#ifndef Q_OS_ANDROID
//On Android these 2 calls produce segfault. WARNING
emit progressText( i18n("Loading Image URLs" ) );
- if( !readURLData( "image_url.dat", 0 ) && !nonFatalErrorMessage( "image_url.dat" ) )
- return false;
+
+ //if( !readURLData( "image_url.dat", 0 ) && !nonFatalErrorMessage( "image_url.dat" ) )
+ // return false;
+ QtConcurrent::run(this, &KStarsData::readURLData, QString("image_url.dat"), 0, false);
//Load Information URLs//
emit progressText( i18n("Loading Information URLs" ) );
- if( !readURLData( "info_url.dat", 1 ) && !nonFatalErrorMessage( "info_url.dat" ) )
- return false;
+ //if( !readURLData( "info_url.dat", 1 ) && !nonFatalErrorMessage( "info_url.dat" ) )
+ // return false;
+ QtConcurrent::run(this, &KStarsData::readURLData, QString("info_url.dat"), 1, false);
+
//#endif
- emit progressText( i18n("Loading Variable Stars" ) );
+ //emit progressText( i18n("Loading Variable Stars" ) );
//Update supernovae list if enabled
if( Options::updateSupernovaeOnStartup() ) {
diff --git a/kstars/skycomponents/constellationnamescomponent.cpp b/kstars/skycomponents/constellationnamescomponent.cpp
index 7ac5a96..db789c0 100644
--- a/kstars/skycomponents/constellationnamescomponent.cpp
+++ b/kstars/skycomponents/constellationnamescomponent.cpp
@@ -17,6 +17,7 @@
#include "constellationnamescomponent.h"
#include <QTextStream>
+#include <QtConcurrent>
#include "kstarsdata.h"
#ifndef KSTARS_LITE
@@ -33,6 +34,14 @@
ConstellationNamesComponent::ConstellationNamesComponent(SkyComposite *parent, CultureList* cultures )
: ListComponent( parent )
{
+ QtConcurrent::run(this, &ConstellationNamesComponent::loadData, cultures);
+}
+
+ConstellationNamesComponent::~ConstellationNamesComponent()
+{}
+
+void ConstellationNamesComponent::loadData(CultureList* cultures)
+{
uint i = 0;
bool culture = false;
KSFileReader fileReader;
@@ -42,7 +51,7 @@ ConstellationNamesComponent::ConstellationNamesComponent(SkyComposite *parent, C
return;
emitProgressText( i18n("Loading constellation names" ) );
-
+
localCNames = Options::useLocalConstellNames();
while ( fileReader.hasMoreLines() ) {
@@ -93,9 +102,6 @@ ConstellationNamesComponent::ConstellationNamesComponent(SkyComposite *parent, C
}
}
-ConstellationNamesComponent::~ConstellationNamesComponent()
-{}
-
bool ConstellationNamesComponent::selected()
{
#ifndef KSTARS_LITE
diff --git a/kstars/skycomponents/constellationnamescomponent.h b/kstars/skycomponents/constellationnamescomponent.h
index d3e76ff..ad66e0d 100644
--- a/kstars/skycomponents/constellationnamescomponent.h
+++ b/kstars/skycomponents/constellationnamescomponent.h
@@ -69,6 +69,8 @@ public:
virtual bool selected();
+ void loadData(CultureList* cultures);
+
private:
bool localCNames;
};
diff --git a/kstars/skycomponents/milkyway.cpp b/kstars/skycomponents/milkyway.cpp
index 1ebb16a..05dd36a 100644
--- a/kstars/skycomponents/milkyway.cpp
+++ b/kstars/skycomponents/milkyway.cpp
@@ -20,6 +20,7 @@
#include <QList>
#include <QPointF>
#include <QPolygonF>
+#include <QtConcurrent>
#include <KLocalizedString>
@@ -45,11 +46,15 @@ MilkyWay::MilkyWay( SkyComposite *parent ) :
{
intro();
// Milky way
- loadContours("milkyway.dat", i18n("Loading Milky Way"));
+ //loadContours("milkyway.dat", i18n("Loading Milky Way"));
// Magellanic clouds
- loadContours("lmc.dat", i18n("Loading Large Magellanic Clouds"));
- loadContours("smc.dat", i18n("Loading Small Magellanic Clouds"));
- summary();
+ //loadContours("lmc.dat", i18n("Loading Large Magellanic Clouds"));
+ //loadContours("smc.dat", i18n("Loading Small Magellanic Clouds"));
+ //summary();
+
+ QtConcurrent::run(this, &MilkyWay::loadContours, QString("milkyway.dat"), i18n("Loading Milky Way"));
+ QtConcurrent::run(this, &MilkyWay::loadContours, QString("lmc.dat"), i18n("Loading Large Magellanic Clouds"));
+ QtConcurrent::run(this, &MilkyWay::loadContours, QString("smc.dat"), i18n("Loading Small Magellanic Clouds"));
}
const IndexHash& MilkyWay::getIndexHash(LineList* lineList ) {
diff --git a/kstars/skycomponents/satellitescomponent.cpp b/kstars/skycomponents/satellitescomponent.cpp
index f1d889e..fcc3177 100644
--- a/kstars/skycomponents/satellitescomponent.cpp
+++ b/kstars/skycomponents/satellitescomponent.cpp
@@ -22,6 +22,7 @@
#include <QProgressDialog>
#include <QNetworkAccessManager>
#include <QNetworkReply>
+#include <QtConcurrent>
#ifndef KSTARS_LITE
#include <KJobUiDelegate>
@@ -37,10 +38,20 @@
SatellitesComponent::SatellitesComponent( SkyComposite *parent ) :
SkyComponent( parent )
{
+ QtConcurrent::run(this, &SatellitesComponent::loadData);
+}
+
+SatellitesComponent::~SatellitesComponent()
+{
+
+}
+
+void SatellitesComponent::loadData()
+{
KSFileReader fileReader;
QString line;
QStringList group_infos;
-
+
if ( ! fileReader.open( "satellites.dat" ) ) return;
emitProgressText( i18n("Loading satellites" ) );
@@ -71,11 +82,6 @@ SatellitesComponent::SatellitesComponent( SkyComposite *parent ) :
}
}
-SatellitesComponent::~SatellitesComponent()
-{
-
-}
-
bool SatellitesComponent::selected() {
return Options::showSatellites();
}
diff --git a/kstars/skycomponents/satellitescomponent.h b/kstars/skycomponents/satellitescomponent.h
index 508d251..3749bd8 100644
--- a/kstars/skycomponents/satellitescomponent.h
+++ b/kstars/skycomponents/satellitescomponent.h
@@ -103,6 +103,8 @@ public:
*/
SkyObject* findByName( const QString &name );
+ void loadData();
+
protected:
virtual void drawTrails( SkyPainter* skyp );
diff --git a/kstars/skycomponents/starcomponent.cpp b/kstars/skycomponents/starcomponent.cpp
index 9194560..1511e64 100644
--- a/kstars/skycomponents/starcomponent.cpp
+++ b/kstars/skycomponents/starcomponent.cpp
@@ -20,6 +20,7 @@
#endif
#include "starcomponent.h"
+#include <QtConcurrent>
#include <qplatformdefs.h>
#include "Options.h"
@@ -73,9 +74,14 @@ StarComponent::StarComponent(SkyComposite *parent )
// Actually load data
emitProgressText( i18n("Loading stars" ) );
+
loadStaticData();
// Load any deep star catalogs that are available
loadDeepStarCatalogs();
+
+ // The following works but can cause crashes sometimes
+ //QtConcurrent::run(this, &StarComponent::loadDeepStarCatalogs);
+
//In KStars Lite star images are initialized in SkyMapLite
#ifndef KSTARS_LITE
SkyQPainter::initStarImages();
diff --git a/kstars/skyobjects/constellationsart.cpp b/kstars/skyobjects/constellationsart.cpp
index 266a9b2..a2fd934 100644
--- a/kstars/skyobjects/constellationsart.cpp
+++ b/kstars/skyobjects/constellationsart.cpp
@@ -26,7 +26,8 @@ ConstellationsArt::ConstellationsArt(dms midpointra, dms midpointdec, double pa,
width = w;
height = h;
- loadImage();
+
+ //loadImage();
//This sets both current and J2000 RA/DEC to the values ra and dec.
setRA(midpointra);
@@ -39,7 +40,6 @@ ConstellationsArt::~ConstellationsArt()
void ConstellationsArt::loadImage()
{
- constellationArtImage = TextureManager::getImage( imageFileName );
- // qDebug()<<"The Unscaled image is"<<unscaled.width()<<unscaled.height();
- // qDebug()<<"The scaled image is"<<constellationArtImage.width(),constellationArtImage.height();
+ constellationArtImage = TextureManager::getImage( imageFileName );
+ imageLoaded=true;
}
diff --git a/kstars/skyobjects/constellationsart.h b/kstars/skyobjects/constellationsart.h
index ad65b6c..fce5841 100644
--- a/kstars/skyobjects/constellationsart.h
+++ b/kstars/skyobjects/constellationsart.h
@@ -49,6 +49,7 @@ private:
QString abbrev, imageFileName;
QImage constellationArtImage;
double positionAngle, width, height;
+ bool imageLoaded=false;
public:
@@ -68,7 +69,7 @@ public:
~ConstellationsArt();
/** @return an object's image */
- const QImage& image() const { return constellationArtImage; }
+ const QImage& image() { if (imageLoaded) return constellationArtImage; else { loadImage(); return constellationArtImage;}}
/** Load the object's image. This also scales the object's image to 1024x1024 pixels. */
void loadImage();
diff --git a/kstars/skyobjects/deepskyobject.cpp b/kstars/skyobjects/deepskyobject.cpp
index 60f990e..27fda13 100644
--- a/kstars/skyobjects/deepskyobject.cpp
+++ b/kstars/skyobjects/deepskyobject.cpp
@@ -71,7 +71,9 @@ DeepSkyObject::DeepSkyObject( int t, dms r, dms d, float m,
updateID = updateNumID = 0;
customCat = NULL;
Flux = 0;
- loadImage();
+
+ // Disable image loading on init
+ //loadImage();
}
DeepSkyObject::DeepSkyObject( const CatalogEntryData &data, CatalogComponent *cat )
@@ -99,7 +101,9 @@ DeepSkyObject::DeepSkyObject( const CatalogEntryData &data, CatalogComponent *ca
updateID = updateNumID = 0;
customCat = cat;
Flux = data.flux;
- loadImage();
+
+ // Disable image loading on init
+ //loadImage();
}
DeepSkyObject* DeepSkyObject::clone() const
@@ -138,6 +142,7 @@ void DeepSkyObject::loadImage()
{
QString tname = name().toLower().remove(' ');
m_image = TextureManager::getImage( tname );
+ imageLoaded=true;
}
double DeepSkyObject::labelOffset() const {
diff --git a/kstars/skyobjects/deepskyobject.h b/kstars/skyobjects/deepskyobject.h
index 48393a3..6a8f2cd 100644
--- a/kstars/skyobjects/deepskyobject.h
+++ b/kstars/skyobjects/deepskyobject.h
@@ -161,7 +161,7 @@ public:
inline int pgc() const { return PGC; }
/** @return an object's image */
- const QImage& image() const { return m_image; }
+ const QImage& image() { if (imageLoaded) return m_image; else { loadImage(); return m_image;} }
/** Try to load the object's image */
void loadImage();
@@ -210,6 +210,7 @@ private:
int UGC, PGC;
float MajorAxis, MinorAxis, Flux;
unsigned char Catalog;
+ bool imageLoaded=false;
};
#endif