[Kstars-devel] Questions about planet skycomponents

Thomas Kabelmann thomas.kabelmann at gmx.de
Mon Sep 26 10:13:00 CEST 2005


Hi Jason,

for design reasons it would be the best that every component knows if it has a 
trail and draws itself. But I fully agree with you, that this is a big 
performance hit. Putting a list in KStarsData with all objects would mess up 
KStarsData. Your idea, putting a list to each component sounds reasonable. 
For this purpose I suggest to implement an own class Trailable and all 
classes which need this functionality can inherit it.

Here is some pseudo code to sketch my idea:
class Trailable {
	public:
		void addTrail(SkyObject *o) { trailObjects->append(o); }
		void removeTrail(SkyObject *o) { trailObjects->remove(o); }
		void drawTrails() {
			foreach (SkyObject *object; trailObjects)
				object->drawTrail();
		}
	private:
		QList<SkyObjects> *trailObjects;
}

So now every Component can inherit from Trailable and call drawTrails:
class AsteroidComponent : SkyComponent, Trailable {
	public:
		void draw()
		{
			drawTrails();
			// draw asteroids
		}
}

Another issue, as you mentioned, is to find the skyobject. This is needed by 
adding trails too. Adding a generic find(SkyObject*) method is one 
possibility. But I personally prefer another way. I would like to add 
iterators to the component structure, so we could traverse all components. 
The big advantage is, that we can perform several actions on specific 
components and don't need to check all components. This is useful for 
operations, which are not included by all components, for example find(). 
HorizonComponent doesn't need find() and we don't want to mess up the 
interface of the components. Currently I have no exact solution for this 
issue, but I'm evaluating 2 different approaches and will post my ideas soon.

Thomas


More information about the Kstars-devel mailing list