[Orxonox-commit 6385] r11042 - code/branches/presentationHS15/src/modules/hover

landauf at orxonox.net landauf at orxonox.net
Mon Jan 4 18:31:29 CET 2016


Author: landauf
Date: 2016-01-04 18:31:29 +0100 (Mon, 04 Jan 2016)
New Revision: 11042

Modified:
   code/branches/presentationHS15/src/modules/hover/Hover.cc
   code/branches/presentationHS15/src/modules/hover/HoverFlag.cc
   code/branches/presentationHS15/src/modules/hover/HoverFlag.h
   code/branches/presentationHS15/src/modules/hover/HoverWall.cc
   code/branches/presentationHS15/src/modules/hover/HoverWall.h
Log:
use only default constructor (with context, but no other arguments)

Modified: code/branches/presentationHS15/src/modules/hover/Hover.cc
===================================================================
--- code/branches/presentationHS15/src/modules/hover/Hover.cc	2016-01-04 17:19:07 UTC (rev 11041)
+++ code/branches/presentationHS15/src/modules/hover/Hover.cc	2016-01-04 17:31:29 UTC (rev 11042)
@@ -74,20 +74,20 @@
 
             //Outer Walls
             for(int i = 0; i<numCells; i++){
-                new HoverWall(origin_->getContext(), 0,        i+1,      cellSize, cellHeight, 1);
-                new HoverWall(origin_->getContext(), numCells, i+1,      cellSize, cellHeight, 1);
-                new HoverWall(origin_->getContext(), i+1,      0,        cellSize, cellHeight, 2);
-                new HoverWall(origin_->getContext(), i+1,      numCells, cellSize, cellHeight, 2);
+                (new HoverWall(origin_->getContext()))->init(0,        i+1,      cellSize, cellHeight, 1);
+                (new HoverWall(origin_->getContext()))->init(numCells, i+1,      cellSize, cellHeight, 1);
+                (new HoverWall(origin_->getContext()))->init(i+1,      0,        cellSize, cellHeight, 2);
+                (new HoverWall(origin_->getContext()))->init(i+1,      numCells, cellSize, cellHeight, 2);
             }
 
             //Generate inner Walls according to levelcode
             for(int y=0; y<numCells; y++){
                 for(int x=0; x<numCells; x++){
                     switch(levelcode[ y * numCells + x ]){
-                        case 1: new HoverWall(origin_->getContext(), x+1, numCells-y, cellSize, cellHeight, 1);
+                        case 1: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1);
                                 break;
-                        case 3: new HoverWall(origin_->getContext(), x+1, numCells-y, cellSize, cellHeight, 1);
-                        case 2: new HoverWall(origin_->getContext(), x+1, numCells-y, cellSize, cellHeight, 0);
+                        case 3: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1);
+                        case 2: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 0);
                         default: break;
                     }
                 }   
@@ -95,7 +95,11 @@
 
             //Generate 5 flags randomly
             for ( int i = 0; i < 5; i++ )
-                flagVector_.push_back(new HoverFlag(origin_->getContext(), rand()%numCells, rand()%numCells, cellSize));
+            {
+                HoverFlag* flag = new HoverFlag(origin_->getContext());
+                flag->init(rand()%numCells, rand()%numCells, cellSize);
+                flagVector_.push_back(flag);
+            }
 
             flags_ = flagVector_.size();
 

Modified: code/branches/presentationHS15/src/modules/hover/HoverFlag.cc
===================================================================
--- code/branches/presentationHS15/src/modules/hover/HoverFlag.cc	2016-01-04 17:19:07 UTC (rev 11041)
+++ code/branches/presentationHS15/src/modules/hover/HoverFlag.cc	2016-01-04 17:31:29 UTC (rev 11042)
@@ -47,43 +47,38 @@
     HoverFlag::HoverFlag(Context* context) : StaticEntity(context)
     {
         RegisterObject(HoverFlag);
-        model_ = NULL;
-        cs_ = NULL;
+
+        this->model_ = NULL;
+        this->cs_ = NULL;
+        this->collided_ = false;
+
+        this->enableCollisionCallback();
+        this->setCollisionResponse(true);
+        this->setCollisionType(Static);
     }
 
     /**
     @brief
-        Constructor that expects two coordinate-values in the range 0-9
+        Initializes the flag.
     @param xCoordinate
         X-Coordinate of the flage, 0-9, origin is bottom left
     @param yCoordinate
         Y-Coordinate of the flage, 0-9, origin is bottom left
     */
-    HoverFlag::HoverFlag(Context* context, int xCoordinate, int yCoordinate, int cellSize) : StaticEntity(context)
+    void HoverFlag::init(int xCoordinate, int yCoordinate, int cellSize)
     {
-        RegisterObject(HoverFlag);
-        enableCollisionCallback();
-        model_ = NULL;
-        cs_ = NULL;
-
-        model_ = new Model(context);
+        model_ = new Model(this->getContext());
         model_->setMeshSource("ss_flag_eu.mesh");
         model_->setScale3D(Vector3(5, 5, 5));
         model_->setPosition(Vector3(xCoordinate*cellSize*1.0f + cellSize/2,10.0f,yCoordinate*cellSize*1.0f + cellSize/2));
 
         this->attach(model_);
 
-        this->enableCollisionCallback();
-        this->setCollisionResponse(true);
-        this->setCollisionType(Static);
-
-        cs_ = new BoxCollisionShape(context);
+        cs_ = new BoxCollisionShape(this->getContext());
         cs_->setHalfExtents(Vector3(5, 5, 5));
         cs_->setPosition(Vector3(xCoordinate*cellSize*1.0f + cellSize/2,0.0f,yCoordinate*cellSize*1.0f + cellSize/2));
 
         this->attachCollisionShape(cs_);
-        this->collided_ = false;
-
     }
 
     /**

Modified: code/branches/presentationHS15/src/modules/hover/HoverFlag.h
===================================================================
--- code/branches/presentationHS15/src/modules/hover/HoverFlag.h	2016-01-04 17:19:07 UTC (rev 11041)
+++ code/branches/presentationHS15/src/modules/hover/HoverFlag.h	2016-01-04 17:31:29 UTC (rev 11042)
@@ -46,9 +46,10 @@
     {
         public:
             HoverFlag(Context* context);
-            HoverFlag(Context* context, int xCoordinate, int yCoordinate, int cellSize);
             virtual ~HoverFlag();
 
+            void init(int xCoordinate, int yCoordinate, int cellSize);
+
             virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint);            
 
             inline bool getCollided() const

Modified: code/branches/presentationHS15/src/modules/hover/HoverWall.cc
===================================================================
--- code/branches/presentationHS15/src/modules/hover/HoverWall.cc	2016-01-04 17:19:07 UTC (rev 11041)
+++ code/branches/presentationHS15/src/modules/hover/HoverWall.cc	2016-01-04 17:31:29 UTC (rev 11042)
@@ -44,14 +44,27 @@
     HoverWall::HoverWall(Context* context) : StaticEntity(context)
     {
         RegisterObject(HoverWall);
-        model_ = NULL;
-        cs_ = NULL;
+
+        this->model_ = NULL;
+        this->cs_ = NULL;
+
+        this->enableCollisionCallback();
+        this->setCollisionResponse(true);
+        this->setCollisionType(Static);
     }
 
+    /**
+    @brief
+        Destructor.
+    */
+    HoverWall::~HoverWall()
+    {
 
+    }
+
     /**
     @brief
-        Constructor of a HoverWall
+        Initializes a HoverWall
     @param x
         x-Coordinate of the Square that the Wall is attached to, 0-9, Origin is Bottom left
     @param y
@@ -59,10 +72,8 @@
     @param orientation
             Wall on the right side (1) or on top (2) of this square, 0-1        
     */
-    HoverWall::HoverWall(Context* context, int x, int y, int cellSize, int cellHeight, int orientation) : StaticEntity(context)
+    void HoverWall::init(int x, int y, int cellSize, int cellHeight, int orientation)
     {
-        RegisterObject(HoverWall);
-
         int xSize_, zSize_, xPos_, zPos_;
 
         if(orientation == 1){
@@ -79,30 +90,17 @@
         }
 
 
-        model_ = new Model(context);
+        model_ = new Model(this->getContext());
         model_->setMeshSource("CuboidBody.mesh");
         model_->setScale3D(Vector3(xSize_*1.0f, cellHeight*1.0f, zSize_*1.0f));
         model_->setPosition(Vector3(xPos_*1.0f, 0.0f, zPos_*1.0f));
 
         this->attach(model_);
 
-        this->enableCollisionCallback();
-        this->setCollisionResponse(true);
-        this->setCollisionType(Static);
-
-        cs_ = new BoxCollisionShape(context);
+        cs_ = new BoxCollisionShape(this->getContext());
         cs_->setHalfExtents(Vector3(xSize_*1.0f, cellHeight*1.0f, zSize_*1.0f));
         cs_->setPosition(Vector3(xPos_*1.0f, 0.0f, zPos_*1.0f));
 
         this->attachCollisionShape(cs_);
     }
-
-    /**
-    @brief
-        Destructor.
-    */
-    HoverWall::~HoverWall()
-    {
-
-    }
 }

Modified: code/branches/presentationHS15/src/modules/hover/HoverWall.h
===================================================================
--- code/branches/presentationHS15/src/modules/hover/HoverWall.h	2016-01-04 17:19:07 UTC (rev 11041)
+++ code/branches/presentationHS15/src/modules/hover/HoverWall.h	2016-01-04 17:31:29 UTC (rev 11042)
@@ -45,10 +45,11 @@
     class _HoverExport HoverWall : public StaticEntity
     {
         public:
-            HoverWall(Context* context);            
-            HoverWall(Context* context, int x, int y, int cellSize, int cellHeight, int orientation);
+            HoverWall(Context* context);
             virtual ~HoverWall();
 
+            void init(int x, int y, int cellSize, int cellHeight, int orientation);
+
         private:
             Model* model_;
             BoxCollisionShape* cs_;




More information about the Orxonox-commit mailing list