/// ***** Private Variables *****
typedef std::queue<Ball*> queBall;
+typedef std::queue<Polygon*> quePoly;
-queBall startBalls;
-queBall mouseBalls;
+static queBall s_startBalls;
+static queBall s_mouseBalls;
+
+static quePoly s_startPolys;
/// ***** Private Method Headers *****
-Ball* addBall(const Vector2& pos,
- float radius,
- const float* color,
- queBall& que);
+static Ball* addBall(const Vector2& vecPos,
+ float fRadius,
+ const float* color,
+ queBall& que);
+
+static Polygon* addPoly(const vector<Vector2>& vecPoints,
+ const float* color,
+ quePoly& que);
-void removeBall(queBall& que);
-void removeAllBalls(queBall& que);
+static void removeBall(queBall& que);
+static void removeAllBalls(queBall& que);
+
+static void removePoly(quePoly& que);
+static void removeAllPolys(quePoly& que);
/// ***** Initializers/Cleaners *****
void creator::init()
{
- Ball* ball;
- float startMass = 5;
+ Ball* pBall;
+ float fStartMass = 5;
+
+ pBall = addBall(Vector2(50, 50), 20, cWhite, s_startBalls);
+ pBall->mass = fStartMass;
- ball = addBall(Vector2(50, 50), 20, cWhite, startBalls);
- ball->mass = startMass;
+ pBall = addBall(Vector2(150, 50), 20, cGrey, s_startBalls);
+ pBall->mass = fStartMass;
- ball = addBall(Vector2(150, 50), 20, cGrey, startBalls);
- ball->mass = startMass;
+ pBall = addBall(Vector2(50, 100), 20, cRed, s_startBalls);
+ pBall->mass = fStartMass;
- ball = addBall(Vector2(50, 100), 20, cRed, startBalls);
- ball->mass = startMass;
+ pBall = addBall(Vector2(100, 100), 20, cGreen, s_startBalls);
+ pBall->mass = fStartMass;
- ball = addBall(Vector2(100, 100), 20, cGreen, startBalls);
- ball->mass = startMass;
+ pBall = addBall(Vector2(150, 100), 20, cBlue, s_startBalls);
+ pBall->mass = fStartMass;
- ball = addBall(Vector2(150, 100), 20, cBlue, startBalls);
- ball->mass = startMass;
+ pBall = addBall(Vector2(50, 150), 20, cYellow, s_startBalls);
+ pBall->mass = fStartMass;
- ball = addBall(Vector2(50, 150), 20, cYellow, startBalls);
- ball->mass = startMass;
+ pBall = addBall(Vector2(100, 150), 20, cMagenta, s_startBalls);
+ pBall->mass = fStartMass;
- ball = addBall(Vector2(100, 150), 20, cMagenta, startBalls);
- ball->mass = startMass;
+ pBall = addBall(Vector2(150, 150), 20, cCyan, s_startBalls);
+ pBall->mass = fStartMass;
- ball = addBall(Vector2(150, 150), 20, cCyan, startBalls);
- ball->mass = startMass;
- for( int i = 0; i<50; i++)
+ for( int i = 0; i < 50; i++)
{
- addBall(Vector2(200+i*2, 200+i*2), 10, cCyan);
+ addBall(Vector2(200 + i * 2, 200 + i * 2), 10, cCyan);
}
- // HACK
- // add a polygon into the mix (currently not cleaned up)
+
vector<Vector2> points;
points.push_back(Vector2(500,500));
points.push_back(Vector2(300,500));
points.push_back(Vector2(500,300));
- manager::add(new Polygon(points, cRed));
+ addPoly(points, cRed, s_startPolys);
}
void creator::clean()
{
- removeAllBalls(startBalls);
- removeAllBalls(mouseBalls);
+ removeAllBalls(s_startBalls);
+ removeAllBalls(s_mouseBalls);
+
+ removeAllPolys(s_startPolys);
}
/// ***** Public Methods *****
void creator::addBall(const Vector2& pos, float radius, const float* color)
{
- addBall(pos, radius, color, mouseBalls);
+ addBall(pos, radius, color, s_mouseBalls);
}
void creator::removeBall()
{
- removeBall(mouseBalls);
+ removeBall(s_mouseBalls);
}
void creator::removeAllBalls()
{
- removeAllBalls(mouseBalls);
+ removeAllBalls(s_mouseBalls);
}
void creator::handleInput()
if(input::mouseLeft())
addBall(input::mousePosition(), 10, cCyan);
- if(input::mouseRight() && ! mouseBalls.empty())
+ if(input::mouseRight() && ! s_mouseBalls.empty())
removeBall();
}
/// ***** Private Methods *****
-Ball* addBall(const Vector2& pos,
- float radius,
- const float* color,
- queBall& que)
+Ball* addBall(const Vector2& vecPos,
+ float fRadius,
+ const float* color,
+ queBall& que)
+{
+ Ball* pBall = new Ball(vecPos, fRadius, color);
+
+ que.push(pBall);
+ manager::add(pBall);
+
+ return pBall;
+}
+Polygon* addPoly(const vector<Vector2>& vecPoints,
+ const float* color,
+ quePoly& que)
{
- Ball* ball = new Ball(pos, radius, color);
+ Polygon* pPoly = new Polygon(vecPoints, color);
- que.push(ball);
- manager::add(ball);
+ que.push(pPoly);
+ manager::add(pPoly);
- return ball;
+ return pPoly;
}
void removeBall(queBall& que)
{
- Ball* ball = que.front();
+ Ball* pBall = que.front();
- manager::remove(ball);
+ manager::remove(pBall);
que.pop();
- delete ball;
+ delete pBall;
}
void removeAllBalls(queBall& que)
{
while(! que.empty() )
{
- Ball* ball = que.front();
- que.pop();
- manager::remove(ball);
+ removeBall(que);
+ }
+}
- delete ball;
+static void removePoly(quePoly& que)
+{
+ Polygon* pPoly = que.front();
+
+ manager::remove(pPoly);
+ que.pop();
+
+ delete pPoly;
+}
+static void removeAllPolys(quePoly& que)
+{
+ while(! que.empty() )
+ {
+ removePoly(que);
}
}