From kde-commits Fri Jul 31 22:41:28 2009 From: Stefan Majewsky Date: Fri, 31 Jul 2009 22:41:28 +0000 To: kde-commits Subject: playground/games/kolf-ng Message-Id: <1249080088.712452.29181.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=124908009406117 SVN commit 1005390 by majewsky: Replace the weird instances list from Kolf::CourseMetaObject with a proper solution, thereby fixing a bug with the ball positioning. M +0 -4 elements/object-coursemeta.cpp M +0 -3 elements/object-coursemeta.h M +9 -2 elements/scene.cpp M +0 -6 engine/player.cpp --- trunk/playground/games/kolf-ng/elements/object-coursemeta.cpp #1005389:1005390 @@ -24,19 +24,15 @@ BIND_KOLF_OBJECT(Kolf::CourseMetaObject) -QList Kolf::CourseMetaObject::Instances; //initialization - Kolf::CourseMetaObject::CourseMetaObject(dWorldID worldID, dSpaceID spaceID) : Kolf::Object(worldID, spaceID) , m_hasCourseBoundary(false) { - Instances << this; } Kolf::CourseMetaObject::~CourseMetaObject() { qDeleteAll(m_courseBoundaryComponents); - Instances.removeAll(this); } bool Kolf::CourseMetaObject::hasCourseBoundary() const --- trunk/playground/games/kolf-ng/elements/object-coursemeta.h #1005389:1005390 @@ -40,8 +40,6 @@ CourseMetaObject(dWorldID worldID, dSpaceID spaceID); virtual ~CourseMetaObject(); - static QList Instances; - bool hasCourseBoundary() const; void setCourseBoundary(bool hasCourseBoundary); protected: @@ -49,7 +47,6 @@ private: bool m_hasCourseBoundary; QList m_courseBoundaryComponents; - }; } --- trunk/playground/games/kolf-ng/elements/scene.cpp #1005389:1005390 @@ -19,7 +19,7 @@ #include "scene.h" #include "ball.h" #include "managedobjectgroup.h" -#include "objectfactory.h" +#include "object-coursemeta.h" #include @@ -81,10 +81,17 @@ Kolf::Ball* Kolf::Scene::addBall() { - Kolf::Ball* ball = reinterpret_cast(Kolf::ObjectFactory::create("Kolf::Ball", this)); + //create ball + Kolf::Ball* ball = new Kolf::Ball(m_worldID, m_spaceID); addItem(ball); m_balls << ball; m_objects << ball; + //set ball to the position specified in the course meta object (if there is one) + Kolf::CourseMetaObject* cmObject = m_objects.allOfType().value(0); + if (cmObject) + ball->setPosition(cmObject->position()); + else + ball->setPosition(Kolf::PointF(500, 500, 100)); //a sane fallback above the middle of the scene return ball; } --- trunk/playground/games/kolf-ng/engine/player.cpp #1005389:1005390 @@ -18,7 +18,6 @@ #include "player.h" #include "../elements/ball.h" -#include "../elements/object-coursemeta.h" #include "../elements/scene.h" Kolf::Player::Player(const QString& name, unsigned int holeCount) @@ -43,11 +42,6 @@ { m_ball = m_scene->addBall(); m_ball->setColor(QColor::fromHsv(m_hue, 255, 255)); - //find position of ball in course meta object - if (Kolf::CourseMetaObject::Instances.isEmpty()) - m_ball->setPosition(Kolf::PointF(500, 500, 0)); //a sane fallback on the middle of the scene - else - m_ball->setPosition(Kolf::CourseMetaObject::Instances[0]->position()); } return m_ball; }