added usages of trim to lists
[physics.git] / src / entityCreator.cpp
index 5e0edaa..f44eda0 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "entityCreator.h"
 
-#include <queue>
+#include <bear/Queue.h>
 
 #include "entityManager.h"
 #include "input/inputManager.h"
@@ -29,8 +29,8 @@
 
 /// ***** Private Variables *****
 
-typedef std::queue<Ball*> queBall;
-typedef std::queue<Polygon*> quePoly;
+typedef bear::Queue<Ball*>      queBall;
+typedef bear::Queue<Polygon*>   quePoly;
 
 static queBall s_startBalls;
 static queBall s_mouseBalls;
@@ -61,6 +61,11 @@ void creator::init()
     Ball* pBall;
     float fStartMass = 5;
 
+    s_startBalls.init();
+    s_mouseBalls.init();
+
+    s_startPolys.init();
+
     pBall = addBall(Vector2(50, 50), 20, cWhite, s_startBalls);
     pBall->mass = fStartMass;
 
@@ -98,13 +103,21 @@ void creator::init()
     points.push_back(Vector2(500,300));
 
     addPoly(points, cRed, s_startPolys);
+
+
+    s_startPolys.trim();
+    s_startBalls.trim();
 }
 void creator::clean()
 {
-    removeAllBalls(s_startBalls);
+    removeAllPolys(s_startPolys);
+    s_startPolys.fini();
+
     removeAllBalls(s_mouseBalls);
+    s_mouseBalls.fini();
 
-    removeAllPolys(s_startPolys);
+    removeAllBalls(s_startBalls);
+    s_startBalls.fini();
 }
 
 /// ***** Public Methods *****
@@ -127,7 +140,7 @@ void creator::handleInput()
     if(input::mouseLeft())
         addBall(input::mousePosition(), 10, cCyan);
 
-    if(input::mouseRight() && ! s_mouseBalls.empty())
+    if(input::mouseRight() && ! s_mouseBalls.isEmpty())
         removeBall();
 }
 
@@ -140,7 +153,7 @@ Ball* addBall(const Vector2& vecPos,
 {
     Ball* pBall = new Ball(vecPos, fRadius, color);
 
-    que.push(pBall);
+    que.pushBack(pBall);
     manager::add(pBall);
 
     return pBall;
@@ -151,7 +164,7 @@ Polygon* addPoly(const vector<Vector2>& vecPoints,
 {
     Polygon* pPoly = new Polygon(vecPoints, color);
 
-    que.push(pPoly);
+    que.pushBack(pPoly);
     manager::add(pPoly);
 
     return pPoly;
@@ -159,16 +172,16 @@ Polygon* addPoly(const vector<Vector2>& vecPoints,
 
 void removeBall(queBall& que)
 {
-    Ball* pBall = que.front();
+    Ball* pBall = que.getFront();
 
     manager::remove(pBall);
-    que.pop();
+    que.popFront();
 
     delete pBall;
 }
 void removeAllBalls(queBall& que)
 {
-    while(! que.empty() )
+    while(! que.isEmpty() )
     {
         removeBall(que);
     }
@@ -176,16 +189,16 @@ void removeAllBalls(queBall& que)
 
 static void removePoly(quePoly& que)
 {
-    Polygon* pPoly = que.front();
+    Polygon* pPoly = que.getFront();
 
     manager::remove(pPoly);
-    que.pop();
+    que.popFront();
 
     delete pPoly;
 }
 static void removeAllPolys(quePoly& que)
 {
-    while(! que.empty() )
+    while(! que.isEmpty() )
     {
         removePoly(que);
     }