MeteorMgr.cpp   MeteorMgr.cpp 
/* /*
* Stellarium * Stellarium
* This file Copyright (C) 2004 Robert Spearman * Copyright (C) 2004 Robert Spearman
* 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 <functional>
#include <cstdlib>
#include <QSettings>
#include "LandscapeMgr.hpp" #include "LandscapeMgr.hpp"
#include "Meteor.hpp" #include "Meteor.hpp"
#include "MeteorMgr.hpp" #include "MeteorMgr.hpp"
#include "renderer/StelRenderer.hpp" #include "SolarSystem.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelFileMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelProjector.hpp" #include "StelPainter.hpp"
#include "StelTextureMgr.hpp"
MeteorMgr::MeteorMgr(int zhr, int maxv ) : flagShow(true) #include <QSettings>
{
setObjectName("MeteorMgr");
ZHR = zhr; const double MeteorMgr::zhrToWsr = 1.6667f / 3600.f;
maxVelocity = maxv;
// calculate factor for meteor creation rate per second since visibl MeteorMgr::MeteorMgr(int zhr, int maxv )
e area ZHR is for : ZHR(zhr)
// estimated visible radius of 458km , maxVelocity(maxv)
// (calculated for average meteor magnitude of +2.5 and limiting mag , flagShow(true)
nitude of 5) {
setObjectName("MeteorMgr");
// zhrToWsr = 1.0f/3600.f;
zhrToWsr = 1.6667f/3600.f;
// this is a correction factor to adjust for the model as programmed
to match observed rates
} }
MeteorMgr::~MeteorMgr() MeteorMgr::~MeteorMgr()
{ {
for(std::vector<Meteor*>::iterator iter = active.begin(); iter != ac std::vector<Meteor*>::iterator iter;
tive.end(); ++iter) for(iter = active.begin(); iter != active.end(); ++iter)
{ {
delete *iter; delete *iter;
} }
active.clear(); active.clear();
Meteor::bolideTexture.clear();
} }
void MeteorMgr::init() void MeteorMgr::init()
{ {
Meteor::bolideTexture = StelApp::getInstance().getTextureManager().c
reateTextureThread(StelFileMgr::getInstallationDir()+"/textures/cometComa.p
ng", StelTexture::StelTextureParams(true, GL_LINEAR, 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());
} }
/************************************************************************* /*************************************************************************
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*************************************************************************/ *************************************************************************/
double MeteorMgr::getCallOrder(StelModuleActionName actionName) const double MeteorMgr::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Sola {
rSystem")->getCallOrder(actionName)+10; return GETSTELMODULE(SolarSystem)->getCallOrder(actionName)+
10.;
}
return 0; return 0;
} }
void MeteorMgr::setZHR(int zhr) void MeteorMgr::setZHR(int zhr)
{ {
ZHR = zhr; ZHR = zhr;
emit zhrChanged(zhr); emit zhrChanged(zhr);
} }
int MeteorMgr::getZHR() int MeteorMgr::getZHR()
skipping to change at line 95 skipping to change at line 96
{ {
maxVelocity = maxv; maxVelocity = maxv;
} }
void MeteorMgr::update(double deltaTime) void MeteorMgr::update(double deltaTime)
{ {
#ifdef _MSC_BUILD #ifdef _MSC_BUILD
return; return;
#endif #endif
if (!flagShow) if (!flagShow)
{
return; return;
}
deltaTime*=1000;
StelCore* core = StelApp::getInstance().getCore(); StelCore* core = StelApp::getInstance().getCore();
double tspeed = core->getTimeRate()*86400; // sky seconds per actua
l second
if (!tspeed) { // is paused?
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;
}
// step through and update all active meteors // step through and update all active meteors
for (std::vector<Meteor*>::iterator iter = active.begin(); iter != a std::vector<Meteor*>::iterator iter;
ctive.end(); ++iter) for (iter = active.begin(); iter != active.end(); ++iter)
{ {
if (!(*iter)->update(deltaTime)) if (!(*iter)->update(deltaTime))
{ {
// remove dead meteor
// qDebug("Meteor \tdied\n");
delete *iter; delete *iter;
active.erase(iter); iter = active.erase(iter);
iter--; // important! iter--; // important!
} }
} }
// only makes sense given lifetimes of meteors to draw when timeSpee d is realtime // only makes sense given lifetimes of meteors to draw when timeSpee d is realtime
// otherwise high overhead of large numbers of meteors // otherwise high overhead of large numbers of meteors
double tspeed = core->getTimeRate()*86400; // sky seconds per actua if (tspeed<0 || fabs(tspeed)>1.)
l second
if (tspeed<=0 || fabs(tspeed)>1.)
{ {
// don't start any more meteors // don't start any more meteors
return; return;
} }
// if stellarium has been suspended, don't create huge number of met
eors to
// make up for lost time!
if (deltaTime > 500)
{
deltaTime = 500;
}
// determine average meteors per frame needing to be created // determine average meteors per frame needing to be created
int mpf = (int)((double)ZHR*zhrToWsr*deltaTime/1000.0 + 0.5); int mpf = (int)((double)ZHR*zhrToWsr*deltaTime/1000.0 + 0.5);
if (mpf<1) if (mpf<1)
{
mpf = 1; mpf = 1;
}
int mlaunch = 0;
for (int i=0; i<mpf; ++i) for (int i=0; i<mpf; ++i)
{ {
// start new meteor based on ZHR time probability // start new meteor based on ZHR time probability
double prob = ((double)rand())/RAND_MAX; double prob = ((double)rand())/RAND_MAX;
if (ZHR>0 && prob<((double)ZHR*zhrToWsr*deltaTime/1000.0/(do uble)mpf) ) if (ZHR>0 && prob<((double)ZHR*zhrToWsr*deltaTime/1000.0/(do uble)mpf))
{ {
Meteor *m = new Meteor(StelApp::getInstance().getCor e(), maxVelocity); Meteor *m = new Meteor(core, maxVelocity);
active.push_back(m); active.push_back(m);
mlaunch++;
} }
} }
// qDebug("mpf: %d\tm launched: %d\t(mps: %f)\t%d\n", mpf, mlaunch, ZHR*zhrToWsr, deltaTime);
} }
void MeteorMgr::draw(StelCore* core, StelRenderer* renderer) void MeteorMgr::draw(StelCore* core)
{ {
if (!flagShow) if (!flagShow)
{
return; return;
}
LandscapeMgr* landmgr = (LandscapeMgr*)StelApp::getInstance().getMod uleMgr().getModule("LandscapeMgr"); LandscapeMgr* landmgr = GETSTELMODULE(LandscapeMgr);
if (landmgr->getFlagAtmosphere() && landmgr->getLuminance()>5) if (landmgr->getFlagAtmosphere() && landmgr->getLuminance()>5)
{
return; return;
}
renderer->setBlendMode(BlendMode_Alpha);
// step through and draw all active meteors // step through and draw all active meteors
for (std::vector<Meteor*>::iterator iter = active.begin(); iter != a StelPainter sPainter(core->getProjection(StelCore::FrameAltAz));
ctive.end(); ++iter) std::vector<Meteor*>::iterator iter;
for (iter = active.begin(); iter != active.end(); ++iter)
{ {
(*iter)->draw(core, core->getProjection(StelCore::FrameAltAz ), renderer); (*iter)->draw(core, sPainter);
} }
} }
 End of changes. 36 change blocks. 
56 lines changed or deleted 59 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/