[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-11-10 23:57:38
Message-ID: 20101110235738.56497AC89E () svn ! kde ! org
[Download RAW message or body]

SVN commit 1195406 by majewsky:

Remove a big bunch of unused methods from CanvasItem.

Also, rename CanvasItem::physicalVelocity to CanvasItem::velocity. (This name
is now free again.)

 M  +2 -7      ball.cpp  
 M  +0 -3      ball.h  
 M  +3 -3      canvasitem.cpp  
 M  +2 -29     canvasitem.h  
 M  +4 -83     game.cpp  
 M  +0 -1      game.h  
 M  +2 -2      objects.cpp  
 M  +4 -5      obstacles.cpp  
 M  +1 -1      obstacles.h  


--- trunk/KDE/kdegames/kolf/ball.cpp #1195405:1195406
@@ -98,11 +98,6 @@
 		game->ballMoved();
 }
 
-void Ball::setVelocity(const Vector& velocity)
-{
-	CanvasItem::setPhysicalVelocity(velocity);
-}
-
 void Ball::collisionDetect()
 {
 	if (!isVisible() || state == Holed || !m_doDetect)
@@ -113,7 +108,7 @@
 	if (m_collisionId == 1 && !velocity().isNull())
 		friction();
 
-	const double initialVelocity = velocity().magnitude();
+	const double initialVelocity = Vector(velocity()).magnitude();
 	const double minSpeed = .06;
 
 	QList<QGraphicsItem *> items = collidingItems();
@@ -158,7 +153,7 @@
 		}
 	}
 
-	const double currentVelocity = velocity().magnitude();
+	const double currentVelocity = Vector(velocity()).magnitude();
 	const double velocityChange = qAbs(initialVelocity - currentVelocity);
 
 	if(currentVelocity < minSpeed && velocityChange < minSpeed && currentVelocity)
--- trunk/KDE/kdegames/kolf/ball.h #1195405:1195406
@@ -48,9 +48,6 @@
 	void friction();
 	void collisionDetect();
 
-	virtual void setVelocity(const Vector& velocity);
-	Vector velocity() const { return CanvasItem::physicalVelocity(); }
-
 	int addStroke() const { return m_addStroke; }
 	bool placeOnGround(Vector &v) { v = m_pogOldVelocity; return m_placeOnGround; }
 	void setAddStroke(int newStrokes) { m_addStroke = newStrokes; }
--- trunk/KDE/kdegames/kolf/canvasitem.cpp #1195405:1195406
@@ -136,15 +136,15 @@
 	}
 }
 
-QPointF CanvasItem::physicalVelocity() const
+QPointF CanvasItem::velocity() const
 {
 	b2Vec2 v = m_body->GetLinearVelocity();
 	return QPointF(v.x, v.y);
 }
 
-void CanvasItem::setPhysicalVelocity(const QPointF& newVelocity)
+void CanvasItem::setVelocity(const QPointF& newVelocity)
 {
-	const QPointF currentVelocity = this->physicalVelocity();
+	const QPointF currentVelocity = this->velocity();
 	if (newVelocity != currentVelocity)
 	{
 		const qreal mass = m_body->GetMass();
--- trunk/KDE/kdegames/kolf/canvasitem.h #1195405:1195406
@@ -50,26 +50,14 @@
 	virtual ~CanvasItem();
 	///load your settings from the KConfigGroup, which represents a course.
 	virtual void load(KConfigGroup *) {}
-	///returns a bool that is true if your item needs to load after other items
-	virtual bool loadLast() const { return false; }
-	///called if the item is made by user while editing, with the item that was \
                selected on the hole;
-	virtual void selectedItem(QGraphicsItem * /*item*/) {}
 	///save your settings.
 	virtual void save(KConfigGroup *cfg);
 	///called for information when shot started
 	virtual void shotStarted() {}
-	///called right before any items are saved.
-	virtual void aboutToSave() {}
-	///called right after all items are saved.
-	virtual void savingDone() {}
 	///called when the edit mode has been changed.
 	virtual void editModeChanged(bool editing);
-	///The item should delete any other objects it's created. DO NOT DO THIS KIND OF \
                STUFF IN THE DESTRUCTOR!
-	virtual void aboutToDie() {}
 	///Returns the object to get rid of when the delete button is pressed on this item.
 	virtual CanvasItem *itemToDelete() { return this; }
-	///called when user presses delete key while editing. This is very rarely \
                reimplemented, and generally shouldn't be.
-	virtual void aboutToDelete() {}
 	///Returns whether this item should be able to be deleted by user while editing.
 	virtual bool deleteable() const { return true; }
 	///called if fastAdvance is enabled
@@ -80,16 +68,12 @@
 	virtual bool vStrut() const { return false; }
 	///update your Z value (this is called by various things when perhaps the value \
should change) if this is called by a vStrut, it will pass 'this'.  virtual void \
                updateZ(QGraphicsItem * /*vStrut*/ = 0) {}
-	///clean up for prettyness
-	virtual void clean() {}
 	///returns whether this item can be moved by others (if you want to move an item, \
you should honor this!)  virtual bool canBeMovedByOthers() const { return false; }
 	///Returns a Config that can be used to configure this item by the user. The \
default implementation returns one that says 'No configuration options'.  virtual \
Config *config(QWidget *parent) { return new DefaultConfig(parent); }  ///Returns \
other items that should be moveable (besides this one of course).  virtual \
                QList<QGraphicsItem *> moveableItems() const { return \
                QList<QGraphicsItem *>(); }
-	///Returns whether this can be moved by the user while editing.
-	virtual bool moveable() const { return true; }
 
 	void setId(int newId) { m_id = newId; }
 	int curId() const { return m_id; }
@@ -103,18 +87,10 @@
 	///Reimplement if you want extra items to have access to the game object. \
playSound() relies on having this.  virtual void setGame(KolfGame *game) { this->game \
= game; }  
-	///returns whether this is a corner resizer
-	virtual bool cornerResize() const { return false; }
-
 	QString name() const { return m_name; }
 	void setName(const QString &newname) { m_name = newname; }
 	virtual void setSize(const QSizeF&) {}
 
-	///custom animation code
-	bool isAnimated() const { return m_animated; }
-	void setAnimated(bool animated) { m_animated = animated; }
-	virtual void setVelocity(const Vector& velocity) { m_velocity = velocity; }
-	Vector velocity() const { return m_velocity; }
 	virtual void moveBy(double , double) { kDebug(12007) << "Warning, empty moveBy \
used";} //needed so that float can call the own custom moveBy()s of everything on it  \
  //The following is needed temporarily while CanvasItem is not a QGraphicsItem by \
itself. @@ -129,9 +105,6 @@
 private:
 	QString m_name;
 	int m_id;
-	///custom animation code
-	bool m_animated;
-	Vector m_velocity;
 
 //AFTER THIS LINE follows what I have inserted during the refactoring
 	public:
@@ -163,8 +136,8 @@
 
 		///This is the velocity used by the physics engine: In each time step,
 		///the position of this canvas item changes by the value of this property.
-		QPointF physicalVelocity() const;
-		void setPhysicalVelocity(const QPointF& physicalVelocity);
+		QPointF velocity() const;
+		void setVelocity(const QPointF& velocity);
 	protected:
 		void addShape(Kolf::Shape* shape);
 		///Configure how this object will participate in physical simulation.
--- trunk/KDE/kdegames/kolf/game.cpp #1195405:1195406
@@ -530,7 +530,6 @@
 			highestLog = (*it).scores().count();
 
 		(*it).ball()->setGame(this);
-		(*it).ball()->setAnimated(true);
 	}
 
 	// here only for saved games
@@ -609,13 +608,8 @@
 	foreach (QGraphicsItem* item, itemsCopy)
 	{
 		CanvasItem* citem = dynamic_cast<CanvasItem*>(item);
-		if (citem)
-		{
-			citem->aboutToDelete();
-			citem->aboutToDie();
 			delete citem;
 		}
-	}
 
 	delete cfg;
 #ifdef SOUND
@@ -721,7 +715,7 @@
 		}
 
 		CanvasItem *citem = dynamic_cast<CanvasItem *>(list.first());
-		if (!citem || !citem->moveable())
+		if (!citem)
 		{
 			emit newSelectedItem(&holeInfo);
 			return;
@@ -736,10 +730,6 @@
 					movingItem = selectedItem;
 					movingCanvasItem = dynamic_cast<CanvasItem *>(movingItem);
 					moving = true;
-
-					if (citem->cornerResize())
-						setCursor(Qt::SizeFDiagCursor);
-					else
 						setCursor(Qt::SizeAllCursor);
 
 					emit newSelectedItem(citem);
@@ -1031,8 +1021,6 @@
 				highlighter->setVisible(false);
 				m_topLevelQItems.removeAll(item);
 				m_moveableQItems.removeAll(item);
-				citem->aboutToDelete();
-				citem->aboutToDie();
 				delete citem;
 				selectedItem = 0;
 				emit newSelectedItem(&holeInfo);
@@ -1107,7 +1095,7 @@
 	}
 
 	for (PlayerList::Iterator it = players->begin(); it != players->end(); ++it)
-		if ((*it).ball()->forceStillGoing() || ((*it).ball()->curState() == Rolling && \
(*it).ball()->velocity().magnitude() > 0 && (*it).ball()->isVisible())) +		if \
((*it).ball()->forceStillGoing() || ((*it).ball()->curState() == Rolling && \
Vector((*it).ball()->velocity()).magnitude() > 0 && (*it).ball()->isVisible()))  \
return;  
 	int curState = curBall->curState();
@@ -1186,8 +1174,8 @@
 		}
 	}
 	//step world
-	//NOTE: I previously set timeStep to 1.0 so that CItem's physicalVelocity()
-	//corresponds to the position change per step. In this case, the physical
+	//NOTE: I previously set timeStep to 1.0 so that CItem's velocity()
+	//corresponds to the position change per step. In this case, the
 	//velocity would be scaled by Kolf::Box2DScaleFactor, which would result in
 	//very small velocities (below Box2D's internal cutoff thresholds!) for
 	//usual movements. Therefore, we apply the scaling to the timestep instead.
@@ -1806,7 +1794,6 @@
 		CanvasItem *citem = dynamic_cast<CanvasItem *>(qitem);
 		if (citem)
 		{
-			citem->aboutToDie();
 			delete citem;
 		}
 	}
@@ -1829,7 +1816,6 @@
 	holeInfo.setPar(curPar);
 	holeInfo.borderWallsChanged(cfgGroup.readEntry("borderWalls", \
holeInfo.borderWalls()));  holeInfo.setMaxStrokes(cfgGroup.readEntry("maxstrokes", \
                10));
-	bool hasFinalLoad = cfgGroup.readEntry("hasFinalLoad", true);
 
 	QStringList missingPlugins;
 
@@ -1901,12 +1887,9 @@
 			newItem->setVisible(true);
 
 			// make things actually show
-			if (!hasFinalLoad)
-			{
 				cfgGroup = KConfigGroup(cfg->group(makeGroup(id, curHole, sceneItem->name(), x, \
y)));  sceneItem->load(&cfgGroup);
 			}
-		}
 		else if (name != "hole" && !missingPlugins.contains(name))
 			missingPlugins.append(name);
 
@@ -1942,39 +1925,7 @@
 	QList<QGraphicsItem *>::const_iterator qsceneItem;
 	QList<CanvasItem *> todo;
 	QList<QGraphicsItem *> qtodo;
-	if (hasFinalLoad)
-	{
-		for (qsceneItem = m_topLevelQItems.constBegin(); qsceneItem != \
                m_topLevelQItems.constEnd(); ++qsceneItem)
-		{
-			if (dynamic_cast<Ball*>(*qsceneItem)) continue; //skip balls
-			CanvasItem *item = dynamic_cast<CanvasItem *>(*qsceneItem);
-			if (item)
-			{
-				if (item->loadLast())
-				{
-					qtodo.append(*qsceneItem);
-					todo.append(item);
-				}
-				else
-				{
-					QString group = makeGroup(item->curId(), curHole, item->name(), \
                (int)(*qsceneItem)->x(), (int)(*qsceneItem)->y());
-					cfgGroup = KConfigGroup(cfg->group(group));
-					item->load(&cfgGroup);
-				}
-			}
-		}
 
-		QList<CanvasItem *>::const_iterator citem;
-		qsceneItem = qtodo.constBegin();
-		for (citem = todo.constBegin(); citem != todo.constEnd(); ++citem)
-		{
-			cfgGroup = KConfigGroup(cfg->group(makeGroup((*citem)->curId(), curHole, \
                (*citem)->name(), (int)(*qsceneItem)->x(), \
                (int)(*qsceneItem)->y())));
-			(*citem)->load(&cfgGroup);
-
-			qsceneItem++;
-		}
-	}
-
 	for (qsceneItem = m_topLevelQItems.constBegin(); qsceneItem != \
m_topLevelQItems.constEnd(); ++qsceneItem)  {
 		if (dynamic_cast<Ball*>(*qsceneItem)) continue; //skip balls
@@ -2057,9 +2008,6 @@
 	sceneItem->moveBy(0, 0);
 	sceneItem->setSize(newItem->boundingRect().size());
 
-	if (selectedItem)
-		sceneItem->selectedItem(selectedItem);
-
 	setModified(true);
 }
 
@@ -2162,7 +2110,6 @@
 		CanvasItem *citem = dynamic_cast<CanvasItem *>(qitem);
 		if (citem)
 		{
-			citem->aboutToDie();
 			delete citem;
 		}
 	}
@@ -2252,21 +2199,6 @@
 	emit parChanged(curHole, holeInfo.par());
 	emit titleChanged(holeInfo.name());
 
-	// we use this bool for optimization
-	// in openFile().
-	bool hasFinalLoad = false;
-
-	foreach (QGraphicsItem* qitem, m_topLevelQItems)
-	{
-		CanvasItem *citem = dynamic_cast<CanvasItem *>(qitem);
-		if (citem)
-		{
-			citem->aboutToSave();
-			if (citem->loadLast())
-				hasFinalLoad = true;
-		}
-	}
-
 	const QStringList groups = cfg->groupList();
 
 	// wipe out all groups from this hole
@@ -2281,8 +2213,6 @@
 		CanvasItem *citem = dynamic_cast<CanvasItem *>(qitem);
 		if (citem)
 		{
-			citem->clean();
-
 			cfgGroup = KConfigGroup(cfg->group(makeGroup(citem->curId(), curHole, \
citem->name(), (int)qitem->x(), (int)qitem->y())));  citem->save(&cfgGroup);
 		}
@@ -2301,18 +2231,9 @@
 	cfgGroup.writeEntry("par", holeInfo.par());
 	cfgGroup.writeEntry("maxstrokes", holeInfo.maxStrokes());
 	cfgGroup.writeEntry("borderWalls", holeInfo.borderWalls());
-	cfgGroup.writeEntry("hasFinalLoad", hasFinalLoad);
 
 	cfg->sync();
 
-	foreach (QGraphicsItem* qitem, m_topLevelQItems)
-	{
-		if (!dynamic_cast<Ball*>(qitem)) continue;
-		CanvasItem *citem = dynamic_cast<CanvasItem *>(qitem);
-		if (citem)
-			citem->savingDone();
-	}
-
 	setModified(false);
 }
 
--- trunk/KDE/kdegames/kolf/game.h #1195405:1195406
@@ -263,7 +263,6 @@
 	void updateMouse();
 	void ballMoved();
 	void updateHighlighter();
-	QGraphicsItem *curSelectedItem() const { return selectedItem; }
 	void setBorderWalls(bool);
 	void setInPlay(bool yes) { inPlay = yes; }
 	bool isInPlay() { return inPlay; }
--- trunk/KDE/kdegames/kolf/objects.cpp #1195405:1195406
@@ -147,7 +147,7 @@
 bool Kolf::BlackHole::collision(Ball* ball)
 {
 	//miss if speed too high
-	const double speed = ball->velocity().magnitude();
+	const double speed = Vector(ball->velocity()).magnitude();
 	if (speed > 3.75)
 		return true;
 	// is center of ball in cup?
@@ -339,7 +339,7 @@
 bool Kolf::Cup::collision(Ball* ball)
 {
 	//miss if speed too high
-	const double speed = ball->velocity().magnitude();
+	const double speed = Vector(ball->velocity()).magnitude();
 	if (speed > 3.75)
 		return true;
 	//miss if center of ball not inside cup
--- trunk/KDE/kdegames/kolf/obstacles.cpp #1195405:1195406
@@ -45,7 +45,7 @@
 bool Kolf::Bumper::collision(Ball* ball)
 {
 	const double maxSpeed = ball->getMaxBumperBounceSpeed();
-	const double speed = qMin(maxSpeed, 1.8 + ball->velocity().magnitude() * .9);
+	const double speed = qMin(maxSpeed, 1.8 + Vector(ball->velocity()).magnitude() * \
.9);  ball->reduceMaxBumperBounceSpeed();
 
 	Vector betweenVector(ball->pos() - pos());
@@ -512,15 +512,15 @@
 	, m_velocity(0)
 	, m_position(0)
 	, m_moveByMovesMotionLine(true)
+	, m_animated(true)
 {
 	setMlPosition(m_position);
-	setAnimated(true);
 }
 
 void Kolf::Floater::editModeChanged(bool editing)
 {
 	Kolf::RectangleItem::editModeChanged(editing);
-	setAnimated(!editing);
+	m_animated = !editing;
 	if (editing)
 		setMlPosition(0);
 }
@@ -622,7 +622,7 @@
 
 void Kolf::Floater::advance(int phase)
 {
-	if (phase != 1 || !isAnimated())
+	if (phase != 1 || !m_animated)
 		return;
 	//determine movement step
 	const qreal mlLength = m_motionLine.length();
@@ -792,7 +792,6 @@
 	setWallAllowed(Kolf::BottomWallIndex, false);
 	m_guardWall->setLine(QLineF());
 	updateWallPosition();
-	setAnimated(true);
 }
 
 bool Kolf::Windmill::guardAtTop() const
--- trunk/KDE/kdegames/kolf/obstacles.h #1195405:1195406
@@ -185,7 +185,7 @@
 			int m_speed;
 			qreal m_velocity;
 			qreal m_position; //parameter on motion line (see QLineF::pointAt)
-			bool m_moveByMovesMotionLine;
+			bool m_moveByMovesMotionLine, m_animated;
 	};
 
 	class FloaterOverlay : public Kolf::RectangleOverlay


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

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