Commit fc3f9cd7 authored by Artem Fedoskin's avatar Artem Fedoskin
Browse files

Added mechanism for deleting unused nodes to reduce memory consumption.

parent 44963f08
......@@ -582,6 +582,7 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyitems/skynodes/constellationartnode.cpp
kstarslite/skyitems/skynodes/satellitenode.cpp
kstarslite/skyitems/skynodes/supernovanode.cpp
kstarslite/skyitems/skynodes/trixelnode.cpp
#Nodes
kstarslite/skyitems/skynodes/nodes/pointnode.cpp
kstarslite/skyitems/skynodes/nodes/polynode.cpp
......@@ -688,8 +689,6 @@ if(NOT BUILD_KSTARS_LITE)
)
endif(NOT BUILD_KSTARS_LITE)
set(kstars_SRCS ${kstarslite_SRCS} ${kstarslite_RESOURCE}
)
if(BUILD_KSTARS_LITE)
kconfig_add_kcfg_files(kstars_SRCS GENERATE_MOC ${kstars_KCFG_SRCS})
else()
......@@ -737,7 +736,7 @@ add_library( KStarsLib STATIC ${indi_SRCS} ${fits_SRCS} ${ekos_SRCS} ${onlinepar
${libkstarswidgets_SRCS} ${libkstarscomponents_SRCS} ${libkstarstools_SRCS}
${kstars_extra_SRCS} ${kstars_gl_SRCS} ${kstars_projection_SRCS} ${xplanet_SRCS}
${kstars_options_SRCS} ${kstars_skyobjects_SRCS} ${kstars_dialogs_SRCS} ${oal_SRCS}
${printing_SRCS} ${kstars_SRCS} ${kstarslite_RESOURCE})
${printing_SRCS} ${kstars_SRCS} ${kstarslite_SRCS})
# FIXME TODO
#target_include_directories(KStarsLib INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR}/>")
......@@ -777,6 +776,10 @@ else(BUILD_KSTARS_LITE)
)
endif(BUILD_KSTARS_LITE)
add_executable(kstars main.cpp)
target_link_libraries(kstars KStarsLib)
if(NOT WIN32)
target_link_libraries(KStarsLib m)
endif(NOT WIN32)
......@@ -812,9 +815,6 @@ ecm_add_app_icon(KSTARS_APP_SRCS ICONS
${CMAKE_CURRENT_SOURCE_DIR}/icons/128-apps-kstars.png
)
add_executable(kstars ${KSTARS_APP_SRCS})
target_link_libraries(kstars KStarsLib)
if(NOT BUILD_KSTARS_LITE)
install(TARGETS kstars ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
......
......@@ -95,14 +95,9 @@ DeepSkyItem::DeepSkyItem(DeepSkyComponent *dsoComp, RootNode *rootNode)
QSGNode *symbols = new QSGNode;
for(int c = 0; c < dsoList->size(); ++c) {
DeepSkyObject *dso = dsoList->at(c);
if(dso) {
DSOSymbolNode *dsoSymbol = new DSOSymbolNode(dso, indexNode->m_color);
symbols->appendChildNode(dsoSymbol);
DeepSkyNode *dsoNode = new DeepSkyNode(dso, dsoSymbol,i.key(), indexNode->m_labelType);
trixel->appendChildNode(dsoNode);
}
DeepSkyObject *dso = dsoList->at(c);
trixel->m_nodes.append(QPair<SkyObject *, SkyNode *>(dso, 0));
}
trixel->m_symbols = symbols;
......@@ -124,25 +119,53 @@ void DeepSkyItem::update() {
MeshIterator region( m_skyMesh, DRAW_BUF );
int count = 0;
drawFlag = Options::showMessier() &&
! ( Options::hideOnSlew() && Options::hideMessier() && SkyMapLite::IsSlewing() );
updateDeepSkyNode(m_Messier, drawFlag, "MessColor", &region, Options::showMessierImages() );
/*QSGNode *n = m_Messier->m_trixels->firstChild();
while(n != 0) {
count += n->childCount();
n = n->nextSibling();
}*/
drawFlag = Options::showNGC() &&
! ( Options::hideOnSlew() && Options::hideNGC() && SkyMapLite::IsSlewing() );
updateDeepSkyNode(m_NGC, drawFlag, "NGCColor", &region );
/*n = m_NGC->m_trixels->firstChild();
while(n != 0) {
count += n->childCount();
n = n->nextSibling();
}*/
drawFlag = Options::showIC() &&
! ( Options::hideOnSlew() && Options::hideIC() && SkyMapLite::IsSlewing() );
updateDeepSkyNode(m_IC, drawFlag, "ICColor", &region );
/*n = m_IC->m_trixels->firstChild();
while(n != 0) {
count += n->childCount();
n = n->nextSibling();
}*/
drawFlag = Options::showOther() &&
! ( Options::hideOnSlew() && Options::hideOther() && SkyMapLite::IsSlewing() );
updateDeepSkyNode(m_other, drawFlag, "NGCColor", &region );
/*n = m_other->m_trixels->firstChild();
while(n != 0) {
count += n->childCount();
n = n->nextSibling();
}
qDebug() << count << "DSO";*/
}
void DeepSkyItem::updateDeepSkyNode(DSOIndexNode *indexNode, bool drawObject, const QString& colorString,
......@@ -156,7 +179,7 @@ void DeepSkyItem::updateDeepSkyNode(DSOIndexNode *indexNode, bool drawObject, co
indexNode->show();
SkyMapLite *map = SkyMapLite::Instance();
//const Projector *proj = map->projector();
const Projector *projector = map->projector();
KStarsData *data = KStarsData::Instance();
UpdateID updateID = data->updateID();
......@@ -202,15 +225,31 @@ void DeepSkyItem::updateDeepSkyNode(DSOIndexNode *indexNode, bool drawObject, co
}*/
DSOTrixelNode *trixel = static_cast<DSOTrixelNode *>(indexNode->m_trixels->firstChild());
double delLim = SkyMapLite::deleteLimit();
while( trixel != 0 ) {
if(trixel->trixel < regionID) {
trixel->hide();
trixel->m_labels->hide();
//label->hide();
if(trixel->hideCount() > delLim) {
QLinkedList<QPair<SkyObject *, SkyNode *>>::iterator i = trixel->m_nodes.begin();
while(i != trixel->m_nodes.end()) {
DeepSkyNode *node = static_cast<DeepSkyNode *>((*i).second);
if(node) {
node->parent()->removeChildNode(node);
node->destroy();
*i = QPair<SkyObject *, SkyNode *>((*i).first, 0);
}
i++;
}
}
trixel = static_cast<DSOTrixelNode *>(trixel->nextSibling());
//label = static_cast<TrixelNode *>(label->nextSibling());
continue;
} else if(trixel->trixel > regionID) {
if (region->hasNext()) {
regionID = region->next();
......@@ -219,6 +258,21 @@ void DeepSkyItem::updateDeepSkyNode(DSOIndexNode *indexNode, bool drawObject, co
trixel->hide();
trixel->m_labels->hide();
if(trixel->hideCount() > delLim) {
QLinkedList<QPair<SkyObject *, SkyNode *>>::iterator i = trixel->m_nodes.begin();
while(i != trixel->m_nodes.end()) {
DeepSkyNode *node = static_cast<DeepSkyNode *>((*i).second);
if(node) {
node->parent()->removeChildNode(node);
node->destroy();
*i = QPair<SkyObject *, SkyNode *>((*i).first, 0);
}
i++;
}
}
trixel = static_cast<DSOTrixelNode *>(trixel->nextSibling());
}
break;
......@@ -231,50 +285,74 @@ void DeepSkyItem::updateDeepSkyNode(DSOIndexNode *indexNode, bool drawObject, co
if(region->hasNext()) {
regionID = region->next();
}
}
QSGNode *n = trixel->firstChild();
QLinkedList<QPair<SkyObject *, SkyNode *>> *nodes = &trixel->m_nodes;
while(n != 0 && n != trixel->m_symbols) {
DeepSkyNode *dsoNode = static_cast<DeepSkyNode *>(n);
n = n->nextSibling();
QLinkedList<QPair<SkyObject *, SkyNode *>>::iterator i = nodes->begin();
DeepSkyObject *obj = static_cast<DeepSkyObject *>(dsoNode->dsObject());
//if ( obj->drawID == drawID ) continue; // only draw each line once
//obj->drawID = drawID;
while(i != nodes->end()) {
DeepSkyObject *dsoObj = static_cast<DeepSkyObject *>((*i).first);
DeepSkyNode *dsoNode = static_cast<DeepSkyNode *>((*i).second);
if ( obj->updateID != updateID ) {
obj->updateID = updateID;
if ( obj->updateNumID != updateNumID) {
obj->updateCoords( data->updateNum() );
if ( dsoObj->updateID != updateID ) {
dsoObj->updateID = updateID;
if ( dsoObj->updateNumID != updateNumID) {
dsoObj->updateCoords( data->updateNum() );
}
dsoObj->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
}
obj->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
}
float mag = obj->mag();
float size = obj->a() * dms::PI * Options::zoomFactor() / 10800.0;
float mag = dsoObj->mag();
float size = dsoObj->a() * dms::PI * Options::zoomFactor() / 10800.0;
//only draw objects if flags set, it's bigger than 1 pixel (unless
//zoom > 2000.), and it's brighter than maglim (unless mag is
//undefined (=99.9)
bool sizeCriterion = (size > 1.0 || Options::zoomFactor() > 2000.);
bool magCriterion = ( mag < (float)maglim ) || ( showUnknownMagObjects && ( std::isnan( mag ) || mag > 36.0 ) );
//only draw objects if flags set, it's bigger than 1 pixel (unless
//zoom > 2000.), and it's brighter than maglim (unless mag is
//undefined (=99.9)
bool sizeCriterion = (size > 1.0 || Options::zoomFactor() > 2000.);
bool magCriterion = ( mag < (float)maglim ) || ( showUnknownMagObjects && ( std::isnan( mag ) || mag > 36.0 ) );
if ( sizeCriterion && magCriterion )
{
bool drawLabel = false;
if ( !( m_hideLabels || mag > labelMagLim ) ) drawLabel = true;
dsoNode->update(drawImage, drawLabel);
/*bool drawn = skyp->drawDeepSkyObject(obj, drawImage);
if ( !( m_hideLabels || mag > labelMagLim ) ) drawLabel = true;
//FIXME: find a better way to do above*/
} else {
dsoNode->hide();
if( dsoNode ) {
if( dsoNode->hideCount() > delLim ) {
//qDebug() << dsoNode->hideCount() << "hideCount";
trixel->removeChildNode(dsoNode);
dsoNode->destroy();
*i = QPair<SkyObject *, SkyNode *>((*i).first, 0);
} else {
if(sizeCriterion && magCriterion) {
dsoNode->update(drawImage, drawLabel);
} else {
dsoNode->hide();
}
}
} else {
if( sizeCriterion && magCriterion && projector->checkVisibility(dsoObj) ) {
QPointF pos;
bool visible = false;
pos = projector->toScreen(dsoObj,true,&visible);
if( visible && projector->onScreen(pos) ) {
DSOSymbolNode *dsoSymbol = new DSOSymbolNode(dsoObj, indexNode->m_color);
trixel->m_symbols->appendChildNode(dsoSymbol);
DeepSkyNode *dsoNode = new DeepSkyNode(dsoObj, dsoSymbol, trixel->trixel, indexNode->m_labelType);
trixel->appendChildNode(dsoNode);
*i = QPair<SkyObject *, SkyNode *>((*i).first, static_cast<SkyNode *>(dsoNode));
dsoNode->update(drawImage, drawLabel, pos);
}
}
}
i++;
}
}
trixel = static_cast<DSOTrixelNode *>(trixel->nextSibling());
//label = static_cast<TrixelNode *>(label->nextSibling());
}
region->reset();
}
......@@ -19,7 +19,7 @@
#include "skyitem.h"
#include "skyopacitynode.h"
#include "deepskycomponent.h"
#include "typedeflite.h"
#include "skynodes/trixelnode.h"
class DSOIndexNode : public SkyOpacityNode {
public:
......
......@@ -28,6 +28,8 @@
#include "skymesh.h"
#include "rootnode.h"
#include "skynodes/trixelnode.h"
DeepStarItem::DeepStarItem(DeepStarComponent *deepStarComp, RootNode *rootNode)
:SkyItem(LabelsItem::label_t::NO_LABEL, rootNode), m_deepStarComp(deepStarComp),
m_staticStars(deepStarComp->staticStars)
......@@ -53,9 +55,7 @@ DeepStarItem::DeepStarItem(DeepStarComponent *deepStarComp, RootNode *rootNode)
StarObject *star = &(block->star( j )->star);
if(star) {
PointSourceNode *point = new PointSourceNode(star, rootNode, LabelsItem::label_t::NO_LABEL, star->spchar(),
star->mag(), i);
trixel->appendChildNode(point);
trixel->m_nodes.append(QPair<SkyObject *, SkyNode *>(star, 0));
}
}
}
......@@ -110,8 +110,8 @@ void DeepStarItem::update() {
MeshIterator region(m_skyMesh, DRAW_BUF);
// If we are to hide the fainter stars (eg: while slewing), we set the magnitude limit to hideStarsMag.
if( hideFaintStars && maglim > hideStarsMag )
maglim = hideStarsMag;
//if( hideFaintStars && maglim > hideStarsMag )
//maglim = hideStarsMag;
StarBlockFactory *m_StarBlockFactory = StarBlockFactory::Instance();
// m_StarBlockFactory->drawID = m_skyMesh->drawID();
......@@ -157,30 +157,9 @@ void DeepStarItem::update() {
TrixelNode *trixel = static_cast<TrixelNode *>(firstTrixel);
while( trixel != 0 ) {
if(trixelID != regionID) {
trixel->hide();
trixel = static_cast<TrixelNode *>(trixel->nextSibling());
trixelID++;
continue;
} else {
trixel->show();
if(region.hasNext()) {
regionID = region.next();
}
}
if(m_staticStars) {
QSGNode *n = trixel->firstChild();
bool hide = false;
while(n != 0) {
/*while(n != 0) {
PointSourceNode *point = static_cast<PointSourceNode *>(n);
n = n->nextSibling();
......@@ -200,6 +179,94 @@ void DeepStarItem::update() {
} else {
point->hide();
}
}*/
const Projector *projector = SkyMapLite::Instance()->projector();
double delLim = SkyMapLite::deleteLimit();
if(trixelID != regionID) {
trixel->hide();
if(trixel->hideCount() > delLim) {
QLinkedList<QPair<SkyObject *, SkyNode *>>::iterator i = trixel->m_nodes.begin();
while(i != trixel->m_nodes.end()) {
SkyNode *node = (*i).second;
if(node) {
trixel->removeChildNode(node);
delete node;
*i = QPair<SkyObject *, SkyNode *>((*i).first, 0);
}
i++;
}
}
trixel = static_cast<TrixelNode *>(trixel->nextSibling());
trixelID++;
continue;
} else {
trixel->show();
if(region.hasNext()) {
regionID = region.next();
}
QLinkedList<QPair<SkyObject *, SkyNode *>> *nodes = &trixel->m_nodes;
QLinkedList<QPair<SkyObject *, SkyNode *>>::iterator i = nodes->begin();
while(i != nodes->end()) {
bool hide = false;
bool hideSlew = false;
bool drawLabel = false;
StarObject *starObj = static_cast<StarObject *>((*i).first);
SkyNode *node = (*i).second;
int mag = starObj->mag();
// break loop if maglim is reached
if ( mag > maglim ) hide = true;
if ( hideFaintStars && hideStarsMag) hideSlew = true;
if ( starObj->updateID != KStarsData::Instance()->updateID() )
starObj->JITupdate();
if( node ) {
if( node->hideCount() > delLim || hide) {
trixel->removeChildNode(node);
delete node;
*i = QPair<SkyObject *, SkyNode *>((*i).first, 0);
} else {
if(!hideSlew) {
node->update(drawLabel);
} else {
node->hide();
}
}
} else {
if( !hide && !hideSlew && projector->checkVisibility(starObj) ) {
QPointF pos;
bool visible = false;
pos = projector->toScreen(starObj,true,&visible);
if( visible && projector->onScreen(pos) ) {
PointSourceNode *point = new PointSourceNode(starObj, rootNode(), LabelsItem::label_t::STAR_LABEL, starObj->spchar(), starObj->mag(), trixelID);
trixel->appendChildNode(point);
*i = QPair<SkyObject *, SkyNode *>((*i).first, static_cast<SkyNode *>(point));
point->updatePos(pos, drawLabel);
}
}
}
i++;
}
}
} else if(false) {
if( !m_staticStars && !m_starBlockList->at( regionID )->fillToMag( maglim ) && maglim <= m_deepStarComp->m_FaintMagnitude * ( 1 - 1.5/16 ) ) {
......@@ -249,5 +316,16 @@ void DeepStarItem::update() {
}
m_skyMesh->inDraw( false );
}
/*int count = 0;
QSGNode *n = firstChild();
while(n != 0) {
count += n->childCount();
n = n->nextSibling();
}
qDebug() << count << "Nodes - DeepStars";*/
}
......@@ -18,7 +18,6 @@
#include "skyitem.h"
#include "skyopacitynode.h"
#include "typedeflite.h"
/** @class DeepStarItem
*
......
......@@ -25,6 +25,7 @@
#include "staritem.h"
#include "rootnode.h"
#include "skymesh.h"
#include "skynodes/trixelnode.h"
LabelsItem::LabelsItem()
:m_rootNode(0)
......@@ -224,7 +225,8 @@ void LabelsItem::deleteLabel(LabelNode *label) {
label_t type = label->labelType();
LabelTypeNode *node = m_labelsLists[type];
if(type == STAR_LABEL) {
if(type == STAR_LABEL || type == DSO_IC_LABEL || type == DSO_NGC_LABEL || type == DSO_MESSIER_LABEL ||
type == DSO_OTHER_LABEL) {
QSGNode *trixel = node->firstChild();
bool found = false;
......@@ -243,8 +245,15 @@ void LabelsItem::deleteLabel(LabelNode *label) {
trixel = trixel->nextSibling();
}
} else {
node->removeChildNode(label);
delete label;
QSGNode *n = node->firstChild();
while(n != 0) {
if(n == label) {
node->removeChildNode(label);
delete label;
break;
}
n = n->nextSibling();
}
}
}
}
......
......@@ -26,6 +26,7 @@ class StarItem;
class LabelNode;
class GuideLabelNode;
class RootNode;
class TrixelNode;
class SkyObject;
......
......@@ -21,6 +21,7 @@
#include "ecliptic.h"
#include "../skynodes/labelnode.h"
#include "../skynodes/nodes/linenode.h"
#include "../skynodes/trixelnode.h"
EclipticItem::EclipticItem(Ecliptic *eclipticComp, RootNode *rootNode)
:SkyItem(LabelsItem::label_t::ECLIPTIC_LABEL, rootNode), m_eclipticComp(eclipticComp)
......
......@@ -25,6 +25,7 @@
#include "../skynodes/nodes/linenode.h"
#include "../skynodes/labelnode.h"
#include "../skynodes/trixelnode.h"
EquatorItem::EquatorItem(Equator *equatorComp, RootNode *rootNode)
:SkyItem(LabelsItem::label_t::EQUATOR_LABEL, rootNode), m_equatorComp(equatorComp)
......
......@@ -22,6 +22,7 @@
#include "linelist.h"
#include "linelistindex.h"
#include "../skynodes/nodes/linenode.h"
#include "../skynodes/trixelnode.h"
LinesItem::LinesItem(RootNode *rootNode)
:SkyItem(LabelsItem::label_t::NO_LABEL, rootNode)
......
......@@ -18,7 +18,6 @@
#include "../skyitem.h"
#include "../skyopacitynode.h"
#include "../typedeflite.h"
class LineListIndex;
......
......@@ -24,6 +24,7 @@
#include "linelistindex.h"
#include "../skynodes/nodes/linenode.h"
#include "../skynodes/skypolygonnode.h"
#include "../skynodes/trixelnode.h"
MilkyWayItem::MilkyWayItem(MilkyWay *mwComp, RootNode *rootNode)
:SkyItem(LabelsItem::label_t::NO_LABEL, rootNode), m_MWComp(mwComp), m_filled(Options::fillMilkyWay())
......
......@@ -18,7 +18,6 @@
#include "../skyitem.h"
#include "../skyopacitynode.h"
#include "../typedeflite.h"
class LineListIndex;
class MilkyWay;
......
......@@ -41,6 +41,7 @@ RootNode::RootNode()
:m_skyMapLite(SkyMapLite::Instance()),
m_clipGeometry(0)
{
SkyMapLite::setRootNode(this);
genCachedTextures();
Options::setProjection(Projector::Lambert);
......@@ -61,7 +62,7 @@ RootNode::RootNode()
m_linesItem->addLinesComponent( m_skyComposite->constellationBoundary(), "CBoundColor", 1, Qt::SolidLine );
}
m_artItem = new ConstellationArtItem(m_skyComposite->constellationArt(), this);
//m_artItem = new ConstellationArtItem(m_skyComposite->constellationArt(), this);
m_linesItem->addLinesComponent( m_skyComposite->constellationLines(), "CLineColor", 1, Qt::SolidLine );
......@@ -84,15 +85,10 @@ RootNode::RootNode()
m_horizonItem = new HorizonItem(m_skyComposite->horizon(), this);