MeteorMgr.cpp   SporadicMeteorMgr.cpp 
/* /*
* Stellarium * Stellarium
* Copyright (C) 2004 Robert Spearman * Copyright (C) 2015 Marcos Cardinot
* Copyright (C) 2014 Marcos Cardinot
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* 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 "LandscapeMgr.hpp" #include "LandscapeMgr.hpp"
#include "Meteor.hpp"
#include "MeteorMgr.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "SporadicMeteorMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include <QSettings> #include <QSettings>
const double MeteorMgr::zhrToWsr = 1.6667f / 3600.f; SporadicMeteorMgr::SporadicMeteorMgr(int zhr, int maxv)
: m_zhr(zhr)
MeteorMgr::MeteorMgr(int zhr, int maxv ) , m_maxVelocity(maxv)
: ZHR(zhr) , m_flagShow(true)
, maxVelocity(maxv)
, flagShow(true)
{ {
setObjectName("MeteorMgr"); setObjectName("SporadicMeteorMgr");
qsrand (QDateTime::currentMSecsSinceEpoch()); qsrand(QDateTime::currentMSecsSinceEpoch());
} }
MeteorMgr::~MeteorMgr() SporadicMeteorMgr::~SporadicMeteorMgr()
{ {
std::vector<Meteor*>::iterator iter; qDeleteAll(activeMeteors);
for(iter = active.begin(); iter != active.end(); ++iter) activeMeteors.clear();
{ m_bolideTexture.clear();
delete *iter;
}
active.clear();
Meteor::bolideTexture.clear();
} }
void MeteorMgr::init() void SporadicMeteorMgr::init()
{ {
Meteor::bolideTexture = StelApp::getInstance().getTextureManager().c m_bolideTexture = StelApp::getInstance().getTextureManager().createT
reateTextureThread(StelFileMgr::getInstallationDir()+"/textures/cometComa.p extureThread(
ng", StelTexture::StelTextureParams(true, GL_LINEAR, GL_CLAMP_TO_EDGE)); StelFileMgr::getInstallationDir() + "/textur
es/cometComa.png",
StelTexture::StelTextureParams(true, GL_LINE
AR, GL_CLAMP_TO_EDGE));
setZHR(StelApp::getInstance().getSettings()->value("astro/meteor_rat e", 10).toInt()); setZHR(StelApp::getInstance().getSettings()->value("astro/meteor_rat e", 10).toInt());
} }
/************************************************************************* double SporadicMeteorMgr::getCallOrder(StelModuleActionName actionName) con
Reimplementation of the getCallOrder method st
*************************************************************************/
double MeteorMgr::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName == StelModule::ActionDraw)
{ {
return GETSTELMODULE(SolarSystem)->getCallOrder(actionName)+ 10.; return GETSTELMODULE(SolarSystem)->getCallOrder(actionName) + 10.;
} }
return 0; return 0;
} }
void MeteorMgr::setZHR(int zhr) void SporadicMeteorMgr::update(double deltaTime)
{
ZHR = zhr;
emit zhrChanged(zhr);
}
int MeteorMgr::getZHR()
{
return ZHR;
}
void MeteorMgr::setMaxVelocity(int maxv)
{
maxVelocity = maxv;
}
void MeteorMgr::update(double deltaTime)
{ {
if (!flagShow) if (!m_flagShow)
{ {
return; return;
} }
StelCore* core = StelApp::getInstance().getCore(); StelCore* core = StelApp::getInstance().getCore();
double tspeed = core->getTimeRate()*86400; // sky seconds per actua // is paused?
l second // freeze meteors at the current position
if (!tspeed) { // is paused? if (!core->getTimeRate())
return; // freeze meteors at the current position
}
deltaTime*=1000;
// if stellarium has been suspended, don't create
// huge number of meteors to make up for lost time!
if (deltaTime > 500)
{ {
deltaTime = 500; return;
} }
// step through and update all active meteors // step through and update all active meteors
std::vector<Meteor*>::iterator iter; foreach (SporadicMeteor* m, activeMeteors)
for (iter = active.begin(); iter != active.end(); )
{ {
if (!(*iter)->update(deltaTime)) if (!m->update(deltaTime))
{ {
delete *iter; activeMeteors.removeOne(m);
iter = active.erase(iter);
}
else
{
++iter;
} }
} }
// only makes sense given lifetimes of meteors to draw when timeSpee // going forward/backward OR current ZHR is zero ?
d is realtime // don't create new meteors
// otherwise high overhead of large numbers of meteors if(!core->getRealTimeSpeed() || m_zhr < 1)
if (tspeed<0 || fabs(tspeed)>1.)
{ {
// don't start any more meteors
return; return;
} }
// determine average meteors per frame needing to be created // average meteors per frame
int mpf = (int)((double)ZHR*zhrToWsr*deltaTime/1000.0 + 0.5); float mpf = m_zhr * deltaTime / 3600.f;
if (mpf<1)
{ // maximum amount of meteors for the current frame
mpf = 1; int maxMpf = qRound(mpf);
} maxMpf = maxMpf < 1 ? 1 : maxMpf;
for (int i=0; i<mpf; ++i) float rate = mpf / (float) maxMpf;
for (int i = 0; i < maxMpf; ++i)
{ {
// start new meteor based on ZHR time probability float prob = (float) qrand() / (float) RAND_MAX;
double prob = ((double)qrand())/RAND_MAX; if (prob < rate)
if (ZHR>0 && prob<((double)ZHR*zhrToWsr*deltaTime/1000.0/(do
uble)mpf))
{ {
Meteor *m = new Meteor(core, maxVelocity); SporadicMeteor* m = new SporadicMeteor(core, m_maxVe
active.push_back(m); locity, m_bolideTexture);
if (m->isAlive())
{
activeMeteors.append(m);
}
} }
} }
} }
void MeteorMgr::draw(StelCore* core) void SporadicMeteorMgr::draw(StelCore* core)
{ {
if (!flagShow || !core->getSkyDrawer()->getFlagHasAtmosphere()) if (!m_flagShow || !core->getSkyDrawer()->getFlagHasAtmosphere())
{ {
return; return;
} }
LandscapeMgr* landmgr = GETSTELMODULE(LandscapeMgr); LandscapeMgr* landmgr = GETSTELMODULE(LandscapeMgr);
if (landmgr->getFlagAtmosphere() && landmgr->getLuminance()>5) if (landmgr->getFlagAtmosphere() && landmgr->getLuminance() > 5.f)
{ {
return; return;
} }
// step through and draw all active meteors // step through and draw all active meteors
StelPainter sPainter(core->getProjection(StelCore::FrameAltAz)); StelPainter sPainter(core->getProjection(StelCore::FrameAltAz));
std::vector<Meteor*>::iterator iter; foreach (SporadicMeteor* m, activeMeteors)
for (iter = active.begin(); iter != active.end(); ++iter)
{ {
(*iter)->draw(core, sPainter); m->draw(core, sPainter);
} }
} }
void SporadicMeteorMgr::setZHR(int zhr)
{
m_zhr = zhr;
emit zhrChanged(zhr);
}
 End of changes. 31 change blocks. 
92 lines changed or deleted 56 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/