ZoneArray.cpp   ZoneArray.cpp 
skipping to change at line 101 skipping to change at line 101
ZoneArray* ZoneArray::create(const QString& catalogFilePath, bool use_mmap) ZoneArray* ZoneArray::create(const QString& catalogFilePath, bool use_mmap)
{ {
QString dbStr; // for debugging output. QString dbStr; // for debugging output.
QFile* file = new QFile(catalogFilePath); QFile* file = new QFile(catalogFilePath);
if (!file->open(QIODevice::ReadOnly)) if (!file->open(QIODevice::ReadOnly))
{ {
qWarning() << "Error while loading " << QDir::toNativeSepara tors(catalogFilePath) << ": failed to open file."; qWarning() << "Error while loading " << QDir::toNativeSepara tors(catalogFilePath) << ": failed to open file.";
return 0; return 0;
} }
dbStr = "Loading \"" + QDir::toNativeSeparators(catalogFilePath) + " \": "; dbStr = "Loading " + QDir::toNativeSeparators(catalogFilePath) + ": ";
unsigned int magic,major,minor,type,level,mag_min,mag_range,mag_step s; unsigned int magic,major,minor,type,level,mag_min,mag_range,mag_step s;
if (ReadInt(*file,magic) < 0 || if (ReadInt(*file,magic) < 0 ||
ReadInt(*file,type) < 0 || ReadInt(*file,type) < 0 ||
ReadInt(*file,major) < 0 || ReadInt(*file,major) < 0 ||
ReadInt(*file,minor) < 0 || ReadInt(*file,minor) < 0 ||
ReadInt(*file,level) < 0 || ReadInt(*file,level) < 0 ||
ReadInt(*file,mag_min) < 0 || ReadInt(*file,mag_min) < 0 ||
ReadInt(*file,mag_range) < 0 || ReadInt(*file,mag_range) < 0 ||
ReadInt(*file,mag_steps) < 0) ReadInt(*file,mag_steps) < 0)
{ {
skipping to change at line 165 skipping to change at line 165
else if (magic == FILE_MAGIC_NATIVE) else if (magic == FILE_MAGIC_NATIVE)
{ {
// ok, will work for any architecture and any compiler // ok, will work for any architecture and any compiler
} }
else else
{ {
dbStr += "error - not a catalogue file."; dbStr += "error - not a catalogue file.";
qDebug() << dbStr; qDebug() << dbStr;
return 0; return 0;
} }
ZoneArray *rval = 0; ZoneArray *rval = Q_NULLPTR;
dbStr += QString("%1_%2v%3_%4; ").arg(level).arg(type).arg(major).ar g(minor); dbStr += QString("%1_%2v%3_%4; ").arg(level).arg(type).arg(major).ar g(minor);
switch (type) switch (type)
{ {
case 0: case 0:
if (major > MAX_MAJOR_FILE_VERSION) if (major > MAX_MAJOR_FILE_VERSION)
{ {
dbStr += "warning - unsupported version "; dbStr += "warning - unsupported version ";
} }
else else
skipping to change at line 204 skipping to change at line 204
else else
{ {
// When this assertion fails you must redefi ne Star2 // When this assertion fails you must redefi ne Star2
// for your compiler. // for your compiler.
// Because your compiler does not pack the d ata, // Because your compiler does not pack the d ata,
// which is crucial for this application. // which is crucial for this application.
#ifndef _MSC_BUILD #ifndef _MSC_BUILD
Q_ASSERT(sizeof(Star2) == 10); Q_ASSERT(sizeof(Star2) == 10);
#endif #endif
rval = new SpecialZoneArray<Star2>(file, byt e_swap, use_mmap, level, mag_min, mag_range, mag_steps); rval = new SpecialZoneArray<Star2>(file, byt e_swap, use_mmap, level, mag_min, mag_range, mag_steps);
if (rval == 0) if (rval == Q_NULLPTR)
{ {
dbStr += "error - no memory "; dbStr += "error - no memory ";
} }
} }
break; break;
case 2: case 2:
if (major > MAX_MAJOR_FILE_VERSION) if (major > MAX_MAJOR_FILE_VERSION)
{ {
dbStr += "warning - unsupported version "; dbStr += "warning - unsupported version ";
} }
else else
{ {
// When this assertion fails you must redefi ne Star3 // When this assertion fails you must redefi ne Star3
// for your compiler. // for your compiler.
// Because your compiler does not pack the d ata, // Because your compiler does not pack the d ata,
// which is crucial for this application. // which is crucial for this application.
#ifndef _MSC_BUILD #ifndef _MSC_BUILD
Q_ASSERT(sizeof(Star3) == 6); Q_ASSERT(sizeof(Star3) == 6);
#endif #endif
rval = new SpecialZoneArray<Star3>(file, byt e_swap, use_mmap, level, mag_min, mag_range, mag_steps); rval = new SpecialZoneArray<Star3>(file, byt e_swap, use_mmap, level, mag_min, mag_range, mag_steps);
if (rval == 0) if (rval == Q_NULLPTR)
{ {
dbStr += "error - no memory "; dbStr += "error - no memory ";
} }
} }
break; break;
default: default:
dbStr += "error - bad file type "; dbStr += "error - bad file type ";
break; break;
} }
if (rval && rval->isInitialized()) if (rval && rval->isInitialized())
skipping to change at line 247 skipping to change at line 247
dbStr += QString("%1").arg(rval->getNrOfStars()); dbStr += QString("%1").arg(rval->getNrOfStars());
qDebug() << dbStr; qDebug() << dbStr;
} }
else else
{ {
dbStr += " - initialization failed"; dbStr += " - initialization failed";
qDebug() << dbStr; qDebug() << dbStr;
if (rval) if (rval)
{ {
delete rval; delete rval;
rval = 0; rval = Q_NULLPTR;
} }
} }
return rval; return rval;
} }
ZoneArray::ZoneArray(const QString& fname, QFile* file, int level, int mag_ min, ZoneArray::ZoneArray(const QString& fname, QFile* file, int level, int mag_ min,
int mag_range, int mag_steps) int mag_range, int mag_steps)
: fname(fname), level(level), mag_min(mag_min), : fname(fname), level(level), mag_min(mag_min),
mag_range(mag_range), mag_steps(mag_steps), mag_range(mag_range), mag_steps(mag_steps),
star_position_scale(0.0), nr_of_stars(0), zones(0) , file(file) star_position_scale(0.0), nr_of_stars(0), zones(Q_ NULLPTR), file(file)
{ {
nr_of_zones = StelGeodesicGrid::nrOfZones(level); nr_of_zones = StelGeodesicGrid::nrOfZones(level);
} }
bool ZoneArray::readFile(QFile& file, void *data, qint64 size) bool ZoneArray::readFile(QFile& file, void *data, qint64 size)
{ {
int parts = 256; int parts = 256;
int part_size = (size + (parts>>1)) / parts; int part_size = (size + (parts>>1)) / parts;
if (part_size < 64*1024) if (part_size < 64*1024)
{ {
skipping to change at line 326 skipping to change at line 326
template<class Star> template<class Star>
SpecialZoneArray<Star>::SpecialZoneArray(QFile* file, bool byte_swap,bool u se_mmap, SpecialZoneArray<Star>::SpecialZoneArray(QFile* file, bool byte_swap,bool u se_mmap,
int level, int mag_min, int mag_ran ge, int mag_steps) int level, int mag_min, int mag_ran ge, int mag_steps)
: ZoneArray(file->fileName(), file, level, mag_min, mag_rang e, mag_steps), : ZoneArray(file->fileName(), file, level, mag_min, mag_rang e, mag_steps),
stars(0), mmap_start(0) stars(0), mmap_start(0)
{ {
if (nr_of_zones > 0) if (nr_of_zones > 0)
{ {
zones = new SpecialZoneData<Star>[nr_of_zones]; zones = new SpecialZoneData<Star>[nr_of_zones];
if (zones == 0) if (zones == Q_NULLPTR)
{ {
qDebug() << "ERROR: SpecialZoneArray(" << level qDebug() << "ERROR: SpecialZoneArray(" << level
<< ")::SpecialZoneArray: no memory (1)"; << ")::SpecialZoneArray: no memory (1)";
exit(1); exit(1);
} }
unsigned int *zone_size = new unsigned int[nr_of_zones]; unsigned int *zone_size = new unsigned int[nr_of_zones];
if (zone_size == 0) if (zone_size == Q_NULLPTR)
{ {
qDebug() << "ERROR: SpecialZoneArray(" << level qDebug() << "ERROR: SpecialZoneArray(" << level
<< ")::SpecialZoneArray: no memory (2)"; << ")::SpecialZoneArray: no memory (2)";
exit(1); exit(1);
} }
if ((qint64)(sizeof(unsigned int)*nr_of_zones) != file->read ((char*)zone_size, sizeof(unsigned int)*nr_of_zones)) if ((qint64)(sizeof(unsigned int)*nr_of_zones) != file->read ((char*)zone_size, sizeof(unsigned int)*nr_of_zones))
{ {
qDebug() << "Error reading zones from catalog:" qDebug() << "Error reading zones from catalog:"
<< file->fileName(); << file->fileName();
delete[] getZones(); delete[] getZones();
zones = 0; zones = Q_NULLPTR;
nr_of_zones = 0; nr_of_zones = 0;
} }
else else
{ {
const unsigned int *tmp = zone_size; const unsigned int *tmp = zone_size;
for (unsigned int z=0;z<nr_of_zones;z++,tmp++) for (unsigned int z=0;z<nr_of_zones;z++,tmp++)
{ {
const unsigned int tmp_spu_int32 = byte_swap ?stel_bswap_32(*tmp):*tmp; const unsigned int tmp_spu_int32 = byte_swap ?stel_bswap_32(*tmp):*tmp;
nr_of_stars += tmp_spu_int32; nr_of_stars += tmp_spu_int32;
getZones()[z].size = tmp_spu_int32; getZones()[z].size = tmp_spu_int32;
} }
} }
// delete zone_size before allocating stars // delete zone_size before allocating stars
// in order to avoid memory fragmentation: // in order to avoid memory fragmentation:
delete[] zone_size; delete[] zone_size;
if (nr_of_stars == 0) if (nr_of_stars == 0)
{ {
// no stars ? // no stars ?
if (zones) delete[] getZones(); if (zones) delete[] getZones();
zones = 0; zones = Q_NULLPTR;
nr_of_zones = 0; nr_of_zones = 0;
} }
else else
{ {
if (use_mmap) if (use_mmap)
{ {
mmap_start = file->map(file->pos(), sizeof(S tar)*nr_of_stars); mmap_start = file->map(file->pos(), sizeof(S tar)*nr_of_stars);
if (mmap_start == 0) if (mmap_start == Q_NULLPTR)
{ {
qDebug() << "ERROR: SpecialZoneArray (" << level qDebug() << "ERROR: SpecialZoneArray (" << level
<< ")::SpecialZoneArray: QF ile(" << file->fileName() << ")::SpecialZoneArray: QF ile(" << file->fileName()
<< ".map(" << file->pos() << ".map(" << file->pos()
<< ',' << sizeof(Star)*nr_o f_stars << ',' << sizeof(Star)*nr_o f_stars
<< ") failed: " << file->er rorString(); << ") failed: " << file->er rorString();
stars = 0; stars = Q_NULLPTR;
nr_of_stars = 0; nr_of_stars = 0;
delete[] getZones(); delete[] getZones();
zones = 0; zones = Q_NULLPTR;
nr_of_zones = 0; nr_of_zones = 0;
} }
else else
{ {
stars = (Star*)mmap_start; stars = (Star*)mmap_start;
Star *s = stars; Star *s = stars;
for (unsigned int z=0;z<nr_of_zones; z++) for (unsigned int z=0;z<nr_of_zones; z++)
{ {
getZones()[z].stars = s; getZones()[z].stars = s;
s += getZones()[z].size; s += getZones()[z].size;
} }
} }
file->close(); file->close();
} }
else else
{ {
stars = new Star[nr_of_stars]; stars = new Star[nr_of_stars];
if (stars == 0) if (stars == Q_NULLPTR)
{ {
qDebug() << "ERROR: SpecialZoneArray (" << level qDebug() << "ERROR: SpecialZoneArray (" << level
<< ")::SpecialZoneArray: no memory (3)"; << ")::SpecialZoneArray: no memory (3)";
exit(1); exit(1);
} }
if (!readFile(*file,stars,sizeof(Star)*nr_of _stars)) if (!readFile(*file,stars,sizeof(Star)*nr_of _stars))
{ {
delete[] stars; delete[] stars;
stars = 0; stars = Q_NULLPTR;
nr_of_stars = 0; nr_of_stars = 0;
delete[] getZones(); delete[] getZones();
zones = 0; zones = Q_NULLPTR;
nr_of_zones = 0; nr_of_zones = 0;
} }
else else
{ {
Star *s = stars; Star *s = stars;
for (unsigned int z=0;z<nr_of_zones; z++) for (unsigned int z=0;z<nr_of_zones; z++)
{ {
getZones()[z].stars = s; getZones()[z].stars = s;
s += getZones()[z].size; s += getZones()[z].size;
} }
skipping to change at line 440 skipping to change at line 440
// GZ: Some diagnostics to understand the undocumented vars around mag. // GZ: Some diagnostics to understand the undocumented vars around mag.
// qDebug() << "SpecialZoneArray: mag_min=" << mag_min << ", mag_steps=" << mag_steps << ", mag_range=" << mag_range ; // qDebug() << "SpecialZoneArray: mag_min=" << mag_min << ", mag_steps=" << mag_steps << ", mag_range=" << mag_range ;
} }
} }
template<class Star> template<class Star>
SpecialZoneArray<Star>::~SpecialZoneArray(void) SpecialZoneArray<Star>::~SpecialZoneArray(void)
{ {
if (stars) if (stars)
{ {
if (mmap_start != 0) if (mmap_start != Q_NULLPTR)
{ {
file->unmap(mmap_start); file->unmap(mmap_start);
} }
else else
{ {
delete[] stars; delete[] stars;
} }
delete file; delete file;
stars = 0; stars = Q_NULLPTR;
} }
if (zones) if (zones)
{ {
delete[] getZones(); delete[] getZones();
zones = NULL; zones = Q_NULLPTR;
} }
nr_of_zones = 0; nr_of_zones = 0;
nr_of_stars = 0; nr_of_stars = 0;
} }
template<class Star> template<class Star>
void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool is InsideViewport, const RCMag* rcmag_table, void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool is InsideViewport, const RCMag* rcmag_table,
int limitMagIndex, StelCore* core, int max MagStarName, float names_brightness, int limitMagIndex, StelCore* core, int max MagStarName, float names_brightness,
const QVector<SphericalCap> &boundingCaps) const const QVector<SphericalCap> &boundingCaps) const
{ {
StelSkyDrawer* drawer = core->getSkyDrawer(); StelSkyDrawer* drawer = core->getSkyDrawer();
Vec3f vf; Vec3f vf;
static const double d2000 = 2451545.0; static const double d2000 = 2451545.0;
const float movementFactor = (M_PI/180)*(0.0001/3600) * ((core->getJ DE()-d2000)/365.25) / star_position_scale; const float movementFactor = (M_PI/180.)*(0.0001/3600.) * ((core->ge tJDE()-d2000)/365.25) / star_position_scale;
// GZ, added for extinction // GZ, added for extinction
const Extinction& extinction=core->getSkyDrawer()->getExtinction(); const Extinction& extinction=core->getSkyDrawer()->getExtinction();
const bool withExtinction=drawer->getFlagHasAtmosphere() && extincti on.getExtinctionCoefficient()>=0.01f; const bool withExtinction=drawer->getFlagHasAtmosphere() && extincti on.getExtinctionCoefficient()>=0.01f;
const float k = 0.001f*mag_range/mag_steps; // from StarMgr.cpp line 654 const float k = 0.001f*mag_range/mag_steps; // from StarMgr.cpp line 654
// Allow artificial cutoff: // Allow artificial cutoff:
// find the (integer) mag at which is just bright enough to be drawn . // find the (integer) mag at which is just bright enough to be drawn .
int cutoffMagStep=limitMagIndex; int cutoffMagStep=limitMagIndex;
if (drawer->getFlagStarMagnitudeLimit()) if (drawer->getFlagStarMagnitudeLimit())
 End of changes. 20 change blocks. 
20 lines changed or deleted 20 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/