StelApp.cpp   StelApp.cpp 
skipping to change at line 24 skipping to change at line 24
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelTextureMgr.hpp"
#include "StelLoadingBar.hpp" #include "StelLoadingBar.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "ConstellationMgr.hpp" #include "ConstellationMgr.hpp"
#include "NebulaMgr.hpp" #include "NebulaMgr.hpp"
#include "LandscapeMgr.hpp" #include "LandscapeMgr.hpp"
#include "GridLinesMgr.hpp" #include "GridLinesMgr.hpp"
#include "MilkyWay.hpp" #include "MilkyWay.hpp"
#include "MeteorMgr.hpp" #include "MeteorMgr.hpp"
#include "LabelMgr.hpp" #include "LabelMgr.hpp"
#include "StarMgr.hpp" #include "StarMgr.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelLocationMgr.hpp" #include "StelLocationMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelShortcutMgr.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "StelSkyLayerMgr.hpp" #include "StelSkyLayerMgr.hpp"
#include "StelAudioMgr.hpp" #include "StelAudioMgr.hpp"
#include "StelVideoMgr.hpp" #include "StelVideoMgr.hpp"
#include "StelGuiBase.hpp" #include "StelGuiBase.hpp"
#include "StelPainter.hpp"
#include "renderer/StelRenderer.hpp"
#include <cstdlib>
#include <iostream> #include <iostream>
#include <QStringList> #include <QDebug>
#include <QString>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QTextStream> #include <QMessageBox>
#include <QMouseEvent> #include <QMouseEvent>
#include <QDebug>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QSysInfo>
#include <QNetworkProxy>
#include <QMessageBox>
#include <QNetworkDiskCache> #include <QNetworkDiskCache>
#include <QNetworkProxy>
#include <QNetworkReply> #include <QNetworkReply>
#include <cstdlib> #include <QString>
#include <QStringList>
#include <QSysInfo>
#include <QTextStream>
#include <QTimer>
// Initialize static variables // Initialize static variables
StelApp* StelApp::singleton = NULL; StelApp* StelApp::singleton = NULL;
QTime* StelApp::qtime = NULL; QTime* StelApp::qtime = NULL;
void StelApp::initStatic() void StelApp::initStatic()
{ {
StelApp::qtime = new QTime(); StelApp::qtime = new QTime();
StelApp::qtime->start(); StelApp::qtime->start();
} }
void StelApp::deinitStatic() void StelApp::deinitStatic()
{ {
delete StelApp::qtime; delete StelApp::qtime;
StelApp::qtime = NULL; StelApp::qtime = NULL;
} }
bool StelApp::getRenderSolarShadows() const
{
return renderSolarShadows;
}
/************************************************************************* /*************************************************************************
Create and initialize the main Stellarium application. Create and initialize the main Stellarium application.
*************************************************************************/ *************************************************************************/
StelApp::StelApp(QObject* parent) StelApp::StelApp(QObject* parent)
: QObject(parent), core(NULL), stelGui(NULL), fps(0), : QObject(parent), core(NULL), stelGui(NULL), fps(0),
frame(0), timefr(0.), timeBase(0.), flagNightVision(false), frame(0), timefr(0.), timeBase(0.), flagNightVision(false), render SolarShadows(false),
confSettings(NULL), initialized(false), saveProjW(-1), saveProjH(- 1), drawState(0) confSettings(NULL), initialized(false), saveProjW(-1), saveProjH(- 1), drawState(0)
{ {
// Stat variables // Stat variables
nbDownloadedFiles=0; nbDownloadedFiles=0;
totalDownloadedSize=0; totalDownloadedSize=0;
nbUsedCache=0; nbUsedCache=0;
totalUsedCacheSize=0; totalUsedCacheSize=0;
setObjectName("StelApp"); setObjectName("StelApp");
skyCultureMgr=NULL; skyCultureMgr=NULL;
localeMgr=NULL; localeMgr=NULL;
stelObjectMgr=NULL; stelObjectMgr=NULL;
textureMgr=NULL;
moduleMgr=NULL;
networkAccessManager=NULL; networkAccessManager=NULL;
shortcutMgr = NULL;
// Can't create 2 StelApp instances // Can't create 2 StelApp instances
Q_ASSERT(!singleton); Q_ASSERT(!singleton);
singleton = this; singleton = this;
moduleMgr = new StelModuleMgr(); moduleMgr = new StelModuleMgr();
wheelEventTimer = new QTimer(this);
wheelEventTimer->setInterval(25);
wheelEventTimer->setSingleShot(TRUE);
} }
/************************************************************************* /*************************************************************************
Deinitialize and destroy the main Stellarium application. Deinitialize and destroy the main Stellarium application.
*************************************************************************/ *************************************************************************/
StelApp::~StelApp() StelApp::~StelApp()
{ {
qDebug() << qPrintable(QString("Downloaded %1 files (%2 kbytes) in a session of %3 sec (average of %4 kB/s + %5 files from cache (%6 kB)).").ar g(nbDownloadedFiles).arg(totalDownloadedSize/1024).arg(getTotalRunTime()).a rg((double)(totalDownloadedSize/1024)/getTotalRunTime()).arg(nbUsedCache).a rg(totalUsedCacheSize/1024)); qDebug() << qPrintable(QString("Downloaded %1 files (%2 kbytes) in a session of %3 sec (average of %4 kB/s + %5 files from cache (%6 kB)).").ar g(nbDownloadedFiles).arg(totalDownloadedSize/1024).arg(getTotalRunTime()).a rg((double)(totalDownloadedSize/1024)/getTotalRunTime()).arg(nbUsedCache).a rg(totalUsedCacheSize/1024));
stelObjectMgr->unSelect(); stelObjectMgr->unSelect();
skipping to change at line 133 skipping to change at line 143
StelModuleMgr* tmp = moduleMgr; StelModuleMgr* tmp = moduleMgr;
moduleMgr = new StelModuleMgr(); // Create a secondary instance to a void crashes at other deinit moduleMgr = new StelModuleMgr(); // Create a secondary instance to a void crashes at other deinit
delete tmp; tmp=NULL; delete tmp; tmp=NULL;
delete skyImageMgr; skyImageMgr=NULL; delete skyImageMgr; skyImageMgr=NULL;
delete core; core=NULL; delete core; core=NULL;
delete skyCultureMgr; skyCultureMgr=NULL; delete skyCultureMgr; skyCultureMgr=NULL;
delete localeMgr; localeMgr=NULL; delete localeMgr; localeMgr=NULL;
delete audioMgr; audioMgr=NULL; delete audioMgr; audioMgr=NULL;
delete videoMgr; videoMgr=NULL; delete videoMgr; videoMgr=NULL;
delete stelObjectMgr; stelObjectMgr=NULL; // Delete the module by ha nd afterward delete stelObjectMgr; stelObjectMgr=NULL; // Delete the module by ha nd afterward
delete textureMgr; textureMgr=NULL;
delete planetLocationMgr; planetLocationMgr=NULL; delete planetLocationMgr; planetLocationMgr=NULL;
delete moduleMgr; moduleMgr=NULL; // Delete the secondary instance delete moduleMgr; moduleMgr=NULL; // Delete the secondary instance
delete shortcutMgr; shortcutMgr = NULL;
Q_ASSERT(singleton); Q_ASSERT(singleton);
singleton = NULL; singleton = NULL;
} }
void StelApp::setupHttpProxy() void StelApp::setupHttpProxy()
{ {
QString proxyHost = confSettings->value("proxy/host_name").toString( ); QString proxyHost = confSettings->value("proxy/host_name").toString( );
QString proxyPort = confSettings->value("proxy/port").toString(); QString proxyPort = confSettings->value("proxy/port").toString();
QString proxyUser = confSettings->value("proxy/user").toString(); QString proxyUser = confSettings->value("proxy/user").toString();
skipping to change at line 208 skipping to change at line 218
if (!proxyPass.isEmpty()) if (!proxyPass.isEmpty())
proxy.setPassword(proxyPass); proxy.setPassword(proxyPass);
QString ppDisp = proxyPass; QString ppDisp = proxyPass;
ppDisp.fill('*'); ppDisp.fill('*');
qDebug() << "Using HTTP proxy:" << proxyUser << ppDisp << pr oxyHost << proxyPort; qDebug() << "Using HTTP proxy:" << proxyUser << ppDisp << pr oxyHost << proxyPort;
QNetworkProxy::setApplicationProxy(proxy); QNetworkProxy::setApplicationProxy(proxy);
} }
} }
void StelApp::init(QSettings* conf) void StelApp::init(QSettings* conf, StelRenderer* renderer)
{ {
confSettings = conf; confSettings = conf;
core = new StelCore(); core = new StelCore();
if (saveProjW!=-1 && saveProjH!=-1) if (saveProjW!=-1 && saveProjH!=-1)
core->windowHasBeenResized(0, 0, saveProjW, saveProjH); core->windowHasBeenResized(0, 0, saveProjW, saveProjH);
#ifndef USE_OPENGL_ES2 renderSolarShadows = renderer->areFloatTexturesSupported();
// Avoid using GL Shaders by default since it causes so many problem
s with broken drivers.
useGLShaders = confSettings->value("main/use_glshaders", false).toBo
ol();
useGLShaders = useGLShaders && QGLShaderProgram::hasOpenGLShaderProg
rams() && !qApp->property("onetime_safe_mode").isValid();
// We use OpenGL 2.1 features in our shaders
useGLShaders = useGLShaders && (QGLFormat::openGLVersionFlags().test
Flag(QGLFormat::OpenGL_Version_2_1) || QGLFormat::openGLVersionFlags().test
Flag(QGLFormat::OpenGL_ES_Version_2_0));
#else
useGLShaders = true;
#endif
// Initialize AFTER creation of openGL context
textureMgr = new StelTextureMgr();
textureMgr->init();
QString splashFileName = "textures/logo24bits.png"; QString splashFileName = "textures/logo24bits.png";
#ifdef BUILD_FOR_MAEMO #ifdef BUILD_FOR_MAEMO
StelLoadingBar loadingBar(splashFileName, "", 25, 320, 101, 800, 400 ); StelLoadingBar loadingBar(splashFileName, "", 25, 320, 101, 800, 400 );
#else #else
#ifdef BZR_REVISION #ifdef BZR_REVISION
StelLoadingBar loadingBar(splashFileName, QString("BZR r%1").arg(BZR _REVISION), 25, 320, 101); StelLoadingBar loadingBar(splashFileName, QString("BZR r%1").arg(BZR _REVISION), 25, 320, 101);
#elif SVN_REVISION #elif SVN_REVISION
StelLoadingBar loadingBar(splashFileName, QString("SVN r%1").arg(SVN _REVISION), 25, 320, 101); StelLoadingBar loadingBar(splashFileName, QString("SVN r%1").arg(SVN _REVISION), 25, 320, 101);
#else #else
StelLoadingBar loadingBar(splashFileName, PACKAGE_VERSION, 45, 320, 121); StelLoadingBar loadingBar(splashFileName, PACKAGE_VERSION, 45, 320, 121);
#endif
#endif #endif
loadingBar.draw(); #endif
loadingBar.draw(renderer);
networkAccessManager = new QNetworkAccessManager(this); networkAccessManager = new QNetworkAccessManager(this);
// Activate http cache if Qt version >= 4.5 // Activate http cache if Qt version >= 4.5
QNetworkDiskCache* cache = new QNetworkDiskCache(networkAccessManage r); QNetworkDiskCache* cache = new QNetworkDiskCache(networkAccessManage r);
QString cachePath = StelFileMgr::getCacheDir(); QString cachePath = StelFileMgr::getCacheDir();
qDebug() << "Cache directory is: " << cachePath; qDebug() << "Cache directory is: " << cachePath;
cache->setCacheDirectory(cachePath); cache->setCacheDirectory(cachePath);
networkAccessManager->setCache(cache); networkAccessManager->setCache(cache);
connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)), this , SLOT(reportFileDownloadFinished(QNetworkReply*))); connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)), this , SLOT(reportFileDownloadFinished(QNetworkReply*)));
// Stel Object Data Base manager // Stel Object Data Base manager
stelObjectMgr = new StelObjectMgr(); stelObjectMgr = new StelObjectMgr();
stelObjectMgr->init(); stelObjectMgr->init();
getModuleMgr().registerModule(stelObjectMgr); getModuleMgr().registerModule(stelObjectMgr);
localeMgr = new StelLocaleMgr(); localeMgr = new StelLocaleMgr();
skyCultureMgr = new StelSkyCultureMgr(); skyCultureMgr = new StelSkyCultureMgr();
planetLocationMgr = new StelLocationMgr(); planetLocationMgr = new StelLocationMgr();
shortcutMgr = new StelShortcutMgr();
localeMgr->init(); localeMgr->init();
shortcutMgr->init();
// Init the solar system first // Init the solar system first
SolarSystem* ssystem = new SolarSystem(); SolarSystem* ssystem = new SolarSystem();
ssystem->init(); ssystem->init();
getModuleMgr().registerModule(ssystem); getModuleMgr().registerModule(ssystem);
// Load hipparcos stars & names // Load hipparcos stars & names
StarMgr* hip_stars = new StarMgr(); StarMgr* hip_stars = new StarMgr();
hip_stars->init(); hip_stars->init();
getModuleMgr().registerModule(hip_stars); getModuleMgr().registerModule(hip_stars);
core->init(); core->init(renderer);
// Init nebulas // Init nebulas
NebulaMgr* nebulas = new NebulaMgr(); NebulaMgr* nebulas = new NebulaMgr();
nebulas->init(); nebulas->init();
getModuleMgr().registerModule(nebulas); getModuleMgr().registerModule(nebulas);
// Init milky way // Init milky way
MilkyWay* milky_way = new MilkyWay(); MilkyWay* milky_way = new MilkyWay();
milky_way->init(); milky_way->init();
getModuleMgr().registerModule(milky_way); getModuleMgr().registerModule(milky_way);
skipping to change at line 358 skipping to change at line 357
if (m!=NULL) if (m!=NULL)
{ {
moduleMgr->registerModule(m, true); moduleMgr->registerModule(m, true);
m->init(); m->init();
} }
} }
} }
void StelApp::update(double deltaTime) void StelApp::update(double deltaTime)
{ {
if (!initialized) if (!initialized)
return; return;
++frame; ++frame;
timefr+=deltaTime; timefr+=deltaTime;
if (timefr-timeBase > 1.) if (timefr-timeBase > 1.)
{ {
// Calc the FPS rate every seconds // Calc the FPS rate every seconds
fps=(double)frame/(timefr-timeBase); fps=(double)frame/(timefr-timeBase);
frame = 0; frame = 0;
timeBase+=1.; timeBase+=1.;
skipping to change at line 385 skipping to change at line 384
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionU pdate)) foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionU pdate))
{ {
i->update(deltaTime); i->update(deltaTime);
} }
stelObjectMgr->update(deltaTime); stelObjectMgr->update(deltaTime);
} }
//! Iterate through the drawing sequence. //! Iterate through the drawing sequence.
bool StelApp::drawPartial() bool StelApp::drawPartial(StelRenderer* renderer)
{ {
if (drawState == 0) if (drawState == 0)
{ {
if (!initialized) if (!initialized)
return false; return false;
core->preDraw(); core->preDraw();
drawState = 1; drawState = 1;
return true; return true;
} }
const QList<StelModule*> modules = moduleMgr->getCallOrders(StelModu le::ActionDraw); const QList<StelModule*> modules = moduleMgr->getCallOrders(StelModu le::ActionDraw);
int index = drawState - 1; int index = drawState - 1;
if (index < modules.size()) if (index < modules.size())
{ {
if (modules[index]->drawPartial(core)) if (modules[index]->drawPartial(core, renderer))
return true; return true;
drawState++; drawState++;
return true; return true;
} }
core->postDraw(); core->postDraw(renderer);
drawState = 0; drawState = 0;
return false; return false;
} }
//! Main drawing function called at each frame
void StelApp::draw()
{
Q_ASSERT(drawState == 0);
while (drawPartial()) {}
Q_ASSERT(drawState == 0);
}
/************************************************************************* /*************************************************************************
Call this when the size of the GL window has changed Call this when the size of the window has changed
*************************************************************************/ *************************************************************************/
void StelApp::glWindowHasBeenResized(float x, float y, float w, float h) void StelApp::windowHasBeenResized(float x, float y, float w, float h)
{ {
if (core) if (core)
core->windowHasBeenResized(x, y, w, h); core->windowHasBeenResized(x, y, w, h);
else else
{ {
saveProjW = w; saveProjW = w;
saveProjH = h; saveProjH = h;
} }
} }
skipping to change at line 446 skipping to change at line 437
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseClicks)) foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseClicks))
{ {
i->handleMouseClicks(event); i->handleMouseClicks(event);
if (event->isAccepted()) if (event->isAccepted())
return; return;
} }
} }
// Handle mouse wheel. // Handle mouse wheel.
// This deltaEvent is a work-around for QTBUG-22269
void StelApp::handleWheel(QWheelEvent* event) void StelApp::handleWheel(QWheelEvent* event)
{ {
// variables used to track the changes
static int delta = 0;
event->setAccepted(false); event->setAccepted(false);
// Send the event to every StelModule if (wheelEventTimer->isActive()) {
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH // Collect the values; we only care about the fianl position
andleMouseClicks)) values, but we want to accumalate the delta.
{ delta += event->delta();
i->handleMouseWheel(event); } else {
if (event->isAccepted()) // The first time in, the values will not have been set.
return; if (delta == 0) {
delta += event->delta();
}
wheelEventTimer->start();
QWheelEvent deltaEvent(event->pos(), event->globalPos(), del
ta, event->buttons(), event->modifiers(), event->orientation());
deltaEvent.setAccepted(FALSE);
// Send the event to every StelModule
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule:
:ActionHandleMouseClicks)) {
i->handleMouseWheel(&deltaEvent);
if (deltaEvent.isAccepted()) {
event->accept();
break;
}
}
// Reset the collected values
delta = 0;
} }
} }
// Handle mouse move // Handle mouse move
void StelApp::handleMove(int x, int y, Qt::MouseButtons b) void StelApp::handleMove(int x, int y, Qt::MouseButtons b)
{ {
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseMoves)) foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseMoves))
{ {
if (i->handleMouseMoves(x, y, b)) if (i->handleMouseMoves(x, y, b))
skipping to change at line 482 skipping to change at line 493
event->setAccepted(false); event->setAccepted(false);
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleKeys)) foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleKeys))
{ {
i->handleKeys(event); i->handleKeys(event);
if (event->isAccepted()) if (event->isAccepted())
return; return;
} }
} }
void StelApp::setRenderSolarShadows(bool b)
{
renderSolarShadows = b;
}
//! Set flag for activating night vision mode //! Set flag for activating night vision mode
void StelApp::setVisionModeNight(bool b) void StelApp::setVisionModeNight(bool b)
{ {
if (flagNightVision!=b) if (flagNightVision!=b)
{ {
flagNightVision=b; flagNightVision=b;
emit(colorSchemeChanged(b ? "night_color" : "color")); emit(colorSchemeChanged(b ? "night_color" : "color"));
} }
} }
 End of changes. 38 change blocks. 
61 lines changed or deleted 74 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/