[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegames/kolf
From:       Stefan Majewsky <majewsky () gmx ! net>
Date:       2010-10-31 23:23:49
Message-ID: 20101031232349.97A91AC8AC () svn ! kde ! org
[Download RAW message or body]

SVN commit 1191722 by majewsky:

The shotgun approach to object cleanup: Destroy everything!

Up to now, I had problems with "ghost walls". Turns out that these are
the objects from the previous games (i.e. the intro game), which are not
correctly cleaned up by the KolfGame dtor. Because the CanvasItems have
so many interdependencies and stuff, I'll just delete items with a shape
for now. This needs to be replaced by proper cleanup somewhen.

 M  +24 -1     game.cpp  


--- trunk/KDE/kdegames/kolf/game.cpp #1191721:1191722
@@ -1083,7 +1083,7 @@
 	const int diameter = 16;
 	setSize(QSizeF(diameter, diameter));
 	addShape(new Kolf::EllipseShape(QRectF(-diameter / 2, -diameter / 2, diameter, diameter)));
-	setSimulationType(CanvasItem::CollisionSimulation);
+	setSimulationType(CanvasItem::NoSimulation);
 
 	setZValue(998.1);
 }
@@ -2157,6 +2157,29 @@
 
 KolfGame::~KolfGame()
 {
+	//HACK: destroy everything which has a shape, except for balls
+	bool destroyedSomething = true;
+	while (destroyedSomething)
+	{
+		destroyedSomething = false;
+		//find first item which is not a ball, and delete that
+		for (b2Body* body = g_world->GetBodyList(); body; body = body->GetNext())
+		{
+			CanvasItem* citem = static_cast<CanvasItem*>(body->GetUserData());
+			if (citem && !citem->m_shapes.isEmpty() && !dynamic_cast<Ball*>(citem))
+			{
+				citem->aboutToDelete();
+				citem->aboutToDie();
+				delete citem;
+				//because this has invalidated the b2Body* iterator and possibly
+				//destroyed more bodies, we start over with the iteration
+				destroyedSomething = true;
+				break;
+			}
+		}
+	}
+	//NOTE: Before I introduced this code, the items were actually not deleted at
+
 	for (PlayerList::Iterator it = players->begin(); it != players->end(); ++it)
 		(*it).ball()->setGame(0);
 	delete cfg;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic