[Orxonox-commit 7119] r11736 - code/branches/Presentation_HS17_merge/src/modules/asteroidmining

landauf at orxonox.net landauf at orxonox.net
Sun Feb 11 22:31:46 CET 2018


Author: landauf
Date: 2018-02-11 22:31:46 +0100 (Sun, 11 Feb 2018)
New Revision: 11736

Modified:
   code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc
   code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.h
   code/branches/Presentation_HS17_merge/src/modules/asteroidmining/CMakeLists.txt
   code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc
   code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.h
   code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.cc
   code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.h
Log:
[AsteroidMining_HS17] some cleanup - Field and Belt should not depend on Pawn, should not be synchronized either (server-side logic). also removed additional constructors and replaced with regular setters.

Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc	2018-02-11 18:19:57 UTC (rev 11735)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc	2018-02-11 21:31:46 UTC (rev 11736)
@@ -70,10 +70,6 @@
 
 */
 
-
-#include "../../orxonox/worldentities/pawns/Pawn.h"
-#include "../../orxonox/worldentities/WorldEntity.h"
-
 #include "AsteroidMinable.h"
 
 #include <algorithm>
@@ -81,18 +77,15 @@
 #include "core/CoreIncludes.h"
 #include "core/GameMode.h"
 #include "core/XMLPort.h"
-#include "core/EventIncludes.h"
-#include "network/NetworkFunction.h" 
 #include "util/Convert.h"
 #include "util/Math.h"
 
-#include "../pickup/PickupSpawner.h"
-#include "../pickup/Pickup.h"
+#include "pickup/PickupSpawner.h"
+#include "pickup/Pickup.h"
 
-#include "../objects/collisionshapes/SphereCollisionShape.h"
-#include "../../orxonox/graphics/Model.h"
+#include "objects/collisionshapes/SphereCollisionShape.h"
+#include "graphics/Model.h"
 
-
 namespace orxonox{
 
     RegisterClass(AsteroidMinable);
@@ -101,14 +94,11 @@
     AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context){
 
         RegisterObject(AsteroidMinable);
-        this->context = context;
 
         // Default Values:
-        this->size = 10; 
+        this->size = 1;
         this->dropStuff = true; 
         this->generateSmaller = true; 
-        this->health_ = 15*size; 
-        this->maxHealth_ = this->health_;
         this->acceptsPickups_ = false; 
 
         this->setCollisionType(WorldEntity::CollisionType::Dynamic);
@@ -120,11 +110,20 @@
         this->initialised = false;
     }
 
-    // @brief Use this constructor with care. Mainly used internally, arguments are passed directly. 
-    AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position, bool dropStuff) : Pawn(c){
+    AsteroidMinable::~AsteroidMinable(){
 
-        RegisterObject(AsteroidMinable);
+    }
 
+    void AsteroidMinable::setSize(int s)
+    {
+        this->size = s;
+        this->health_ = 15*size;
+        this->maxHealth_ = this->health_;
+    }
+
+    // @brief Helper method.
+    void AsteroidMinable::putStuff(){
+
         // The radar is able to detect whether an asteroid contains resources....
         if(dropStuff){
             this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f));
@@ -135,69 +134,30 @@
             this->setRadarObjectShape(RadarViewable::Shape::Dot);
         }
 
-        this->context = c;
-        this->size = size;
-        this->health_ = 15*size; 
-        this->maxHealth_ = this->health_;
-        this->acceptsPickups_ = false; 
-        this->generateSmaller = true; 
-        this->dropStuff = dropStuff; 
-
-        this->setPosition(position);
-        //this->roll = rand()*5; //etwas Drehung. Richtige Variable?
-
-        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
-        this->enableCollisionCallback();
-
         // Add Model, random one of the 6 shapes
-        Model* hull = new Model(this->context);
+        Model* hull = new Model(this->getContext());
         hull->setMeshSource("ast" + multi_cast<std::string>(1 + (int)rnd(0, 6)) + ".mesh");
         hull->setScale(this->size);
         this->attach(hull);
 
         // Collision shape
-        SphereCollisionShape* cs = new SphereCollisionShape(this->context);
+        SphereCollisionShape* cs = new SphereCollisionShape(this->getContext());
         cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien. 
         this->attachCollisionShape(cs); 
 
-        this->registerVariables();
-
         this->initialised=true; 
-
     }
 
-    AsteroidMinable::~AsteroidMinable(){
-
-    }
-
-    // @brief Helper method. 
-    void AsteroidMinable::putStuff(){
-
-        AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->dropStuff);
-        reborn->setVelocity(this->getVelocity());
-        // reborn->setAngularVelocity(this->getAngularVelocity()); // Add all other stuff, too?
-
-        this->bAlive_ = false;
-        this->destroyLater();
-
-    }
-
     void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode){
 
         SUPER(AsteroidMinable, XMLPort, xmlelement, mode); 
 
         XMLPortParam(AsteroidMinable, "size", setSize, getSize, xmlelement, mode);
-        XMLPortParam(AsteroidMinable, "generateSmaller", toggleShattering, doesShatter, xmlelement, mode);
-        XMLPortParam(AsteroidMinable, "dropStuff", toggleDropStuff, doesDropStuff, xmlelement, mode); 
+        XMLPortParam(AsteroidMinable, "generateSmaller", setShattering, doesShatter, xmlelement, mode);
+        XMLPortParam(AsteroidMinable, "dropStuff", setDropStuff, doesDropStuff, xmlelement, mode);
 
     }
 
-    void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
-
-        SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode);
-
-    }
-
     void AsteroidMinable::registerVariables(){
 
         registerVariable(this->size, VariableDirection::ToClient);
@@ -227,7 +187,7 @@
 
         // Pickups which can be harvested. It's munition at the moment, could be changed/extended. 
         if(dropStuff){
-            PickupSpawner* thingy = new PickupSpawner(this->context);
+            PickupSpawner* thingy = new PickupSpawner(this->getContext());
 
             std::string tname;
             if(this->size <= 5){
@@ -365,9 +325,11 @@
             pos = Vector3(r*sin(theta[fisch])*cos(phi[fisch]), r*sin(theta[fisch])*sin(phi[fisch]), r*cos(theta[fisch])); // convert spheric coordinates to vector
         }
         
-        AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + pos, this->dropStuff);
+        AsteroidMinable* child = new AsteroidMinable(this->getContext());
+        child->setSize(masses[fisch]);
+        child->setPosition(this->getPosition() + pos);
         child->setVelocity(this->getVelocity());
-
+        child->setDropStuff(this->dropStuff);
     }
     // orxout() << "Leaving spawnChildren() method. " << endl;
 }

Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.h
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.h	2018-02-11 18:19:57 UTC (rev 11735)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.h	2018-02-11 21:31:46 UTC (rev 11736)
@@ -75,29 +75,18 @@
 
 #include "AsteroidMiningPrereqs.h"
 
-#include <string>
-#include <vector>
-#include "interfaces/PickupCarrier.h"
-#include "interfaces/RadarViewable.h"
-#include "worldentities/ControllableEntity.h"
-#include "worldentities/ExplosionPart.h"
+#include "worldentities/pawns/Pawn.h"
 
-#include "../../orxonox/worldentities/pawns/Pawn.h"
-
 namespace orxonox{
 
 
-    class _AsteroidMiningExport AsteroidMinable : public Pawn{
-
+    class _AsteroidMiningExport AsteroidMinable : public Pawn
+    {
         public:
-            // @brief This constructor is for XML access only!
             AsteroidMinable(Context* context);
-            // @brief Call this Constructor from other C-files.
-            AsteroidMinable(Context* c, float size, Vector3 position, bool dS);
+            virtual ~AsteroidMinable();
 
-            virtual ~AsteroidMinable();
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-            virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override;
             virtual void tick(float dt) override;
 
             // @brief overloading that to prevent asteroids from taking damage from each other (domino effect etc. ) 
@@ -104,19 +93,17 @@
             virtual void hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
             virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
 
-            inline void setSize(int s){this->size = s;}
+            void setSize(int s);
             inline int getSize(){return this->size;}
 
-            inline void toggleShattering(bool b){this->generateSmaller = b;}
+            inline void setShattering(bool b){this->generateSmaller = b;}
             inline bool doesShatter(){return this->generateSmaller;}
 
-            inline void toggleDropStuff(bool b){this->dropStuff = b;}
+            inline void setDropStuff(bool b){this->dropStuff = b;}
             inline bool doesDropStuff(){return this->dropStuff;}
 
         protected:
 
-            Context* context;
-
             int size; //!< Implies health and type of dropped pickups
             bool generateSmaller; //!< Whether this asteroid leaves fragments
             bool dropStuff; //!< Whether this asteroid yields valuable stuff

Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/CMakeLists.txt
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/CMakeLists.txt	2018-02-11 18:19:57 UTC (rev 11735)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/CMakeLists.txt	2018-02-11 21:31:46 UTC (rev 11736)
@@ -12,7 +12,6 @@
   PCH_FILE
 
   LINK_LIBRARIES
-    overlays
     orxonox
     pickup
   SOURCE_FILES ${PICKUP_SRC_FILES}

Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc	2018-02-11 18:19:57 UTC (rev 11735)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc	2018-02-11 21:31:46 UTC (rev 11736)
@@ -44,9 +44,6 @@
 */
 
 
-#include "../../orxonox/worldentities/pawns/Pawn.h"
-#include "../../orxonox/worldentities/WorldEntity.h"
-
 #include "SpicedAsteroidBelt.h"
 #include "SpicedAsteroidField.h"
 
@@ -53,10 +50,7 @@
 #include <algorithm>
 
 #include "core/CoreIncludes.h"
-#include "core/GameMode.h"
 #include "core/XMLPort.h"
-#include "core/EventIncludes.h"
-#include "network/NetworkFunction.h"
 #include "util/Math.h"
 
 namespace orxonox{
@@ -63,12 +57,10 @@
 
     RegisterClass(SpicedAsteroidBelt);
 
-    SpicedAsteroidBelt::SpicedAsteroidBelt(Context* context) : Pawn(context) {
+    SpicedAsteroidBelt::SpicedAsteroidBelt(Context* context) : BaseObject(context) {
 
         RegisterObject(SpicedAsteroidBelt);
 
-        this->context = context; 
-
         // Default Values:
         this->count = 250; 
         this->position = Vector3(0,0,0);
@@ -85,8 +77,6 @@
         this->tiltAt = 0.0; 
         this->tiltBy = 0.0;  
 
-        this->registerVariables();
-
     }
 
     SpicedAsteroidBelt::~SpicedAsteroidBelt(){
@@ -114,10 +104,17 @@
             }
             
             Vector3 pos(radius*cos(sepp)*sin(globi), radius*sin(sepp)*sin(globi), radius*cos(globi));
-            new SpicedAsteroidField(this->context, this->position + pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
-            
+
+            SpicedAsteroidField* field = new SpicedAsteroidField(this->getContext());
+            field->setPosition(this->position + pos);
+            field->setMinSize(this->minSize);
+            field->setMaxSize(this->maxSize);
+            field->setRadius(width);
+            field->setCount(segmentCount);
+            field->setFog(this->foggy);
+            field->setMineralDensity(this->mDensity);
+            field->setFogDensity(this->fogDensity);
         }
-        
     }
 
     void SpicedAsteroidBelt::XMLPort(Element& xmlelement, XMLPort::Mode mode){
@@ -141,33 +138,9 @@
 
     }
 
-    void SpicedAsteroidBelt::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
-
-    }
-
-    void SpicedAsteroidBelt::registerVariables(){
-
-        registerVariable(this->count, VariableDirection::ToClient);
-        registerVariable(this->mDensity, VariableDirection::ToClient);
-        registerVariable(this->position, VariableDirection::ToClient);
-        registerVariable(this->segments, VariableDirection::ToClient);
-
-        registerVariable(this->maxSize, VariableDirection::ToClient);
-        registerVariable(this->minSize, VariableDirection::ToClient);
-        registerVariable(this->radius0, VariableDirection::ToClient);
-        registerVariable(this->radius1, VariableDirection::ToClient);
-        registerVariable(this->foggy, VariableDirection::ToClient);
-        registerVariable(this->fogDensity, VariableDirection::ToClient);
-
-        registerVariable(this->tiltAt, VariableDirection::ToClient);
-        registerVariable(this->tiltBy, VariableDirection::ToClient);
-
-    }
-
     void SpicedAsteroidBelt::tick(float dt){
 
         this->create();
-        this->bAlive_ = false;
         this->destroyLater();
 
     }

Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.h
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.h	2018-02-11 18:19:57 UTC (rev 11735)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.h	2018-02-11 21:31:46 UTC (rev 11736)
@@ -48,28 +48,23 @@
 
 #include "AsteroidMiningPrereqs.h"
 
-#include <string>
-#include <vector>
-#include "worldentities/ControllableEntity.h"
+#include "core/BaseObject.h"
+#include "tools/interfaces/Tickable.h"
 
-#include "../../orxonox/worldentities/pawns/Pawn.h"
-
 namespace orxonox // tolua_export
 {
 
     // tolua_export
-    class _AsteroidMiningExport SpicedAsteroidBelt : public Pawn // need pawn to get tick for clean argument passing
+    class _AsteroidMiningExport SpicedAsteroidBelt : public BaseObject, public Tickable
     { // tolua_export
 
         public:
             SpicedAsteroidBelt(Context* context);// This constructor is for XML access only!
+            virtual ~SpicedAsteroidBelt();
 
-            virtual ~SpicedAsteroidBelt();
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-            virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override;
             virtual void tick(float dt) override;
 
-
             inline void setCount(float s){this->count = s;}
             inline float getCount(){return this->count;}
 
@@ -108,8 +103,6 @@
 
         protected:
 
-            Context* context;
-
             float count; //!< Approximate number of asteroids
             float mDensity; //!< Approximate commonness of asteroids that yield stuff, value between 0 and 1;
 
@@ -130,8 +123,6 @@
             float tiltBy; //!< angle at z-axis
 
         private:
-            void registerVariables();
-            
             virtual void create();
 
     }; // tolua_export

Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.cc
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.cc	2018-02-11 18:19:57 UTC (rev 11735)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.cc	2018-02-11 21:31:46 UTC (rev 11736)
@@ -39,9 +39,6 @@
 */
 
 
-#include "../../orxonox/worldentities/pawns/Pawn.h"
-#include "../../orxonox/worldentities/WorldEntity.h"
-
 #include "SpicedAsteroidField.h"
 #include "AsteroidMinable.h"
 
@@ -48,13 +45,10 @@
 #include <algorithm>
 
 #include "core/CoreIncludes.h"
-#include "core/GameMode.h"
 #include "core/XMLPort.h"
-#include "core/EventIncludes.h"
-#include "network/NetworkFunction.h"
 #include "util/Math.h"
 
-#include "../../orxonox/graphics/Billboard.h"
+#include "graphics/Billboard.h"
 
 
 namespace orxonox{
@@ -61,10 +55,9 @@
 
     RegisterClass(SpicedAsteroidField);
 
-    SpicedAsteroidField::SpicedAsteroidField(Context* context) : Pawn(context) {
+    SpicedAsteroidField::SpicedAsteroidField(Context* context) : BaseObject(context) {
 
         RegisterObject(SpicedAsteroidField);
-        this->context = context;
 
         // Default Values: 
         this->count = 30; 
@@ -75,26 +68,8 @@
         this->radius = 1000;
         this->foggy = true; 
         this->fogDensity = 0.5;
-
-        this->registerVariables();
     }
 
-    SpicedAsteroidField::SpicedAsteroidField(Context* c, Vector3 p, int minS, int maxS, int w, int count, bool f, float mD, float fD): Pawn(c){
-
-        this->context = c;
-        this->position = p; 
-        this->minSize = minS; 
-        this->maxSize = maxS; 
-        this->radius = w; 
-        this->count = count; 
-        this->foggy = f; 
-
-        this->mDensity = mD;
-        this->fogDensity = fD; 
-
-    }
-
-
     SpicedAsteroidField::~SpicedAsteroidField(){
 
     }
@@ -108,7 +83,7 @@
 
         for(int gertrud = 0; gertrud<count; ++gertrud){
 
-            AsteroidMinable* a = new AsteroidMinable(this->context);
+            AsteroidMinable* a = new AsteroidMinable(this->getContext());
 
             size = round(rnd()*(this->maxSize - this->minSize)) + this->minSize;
             a->setSize(size); 
@@ -120,13 +95,11 @@
             a->setPosition(this->position + relPos);
 
             bool spiced = (rnd() < (this->mDensity)); // Whether the asteroid does drop pickups etc. 
-            a->toggleDropStuff(spiced);
+            a->setDropStuff(spiced);
             
-            a->setVelocity(this->getVelocity()); 
-            
             // Fog is iplemented with billboards (as in asteroidField.lua, that bloke had the idea)
             if(this->foggy && mod(gertrud, 5) == 0){
-                Billboard* bb = new Billboard(this->context);
+                Billboard* bb = new Billboard(this->getContext());
                 bb->setPosition(this->position + relPos);
                 bb->setMaterial("Smoke/Smoke");
                 bb->setScale(size);
@@ -150,28 +123,9 @@
 
     }
 
-
-    void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
-
-    }
-
-    void SpicedAsteroidField::registerVariables(){
-
-        registerVariable(this->count, VariableDirection::ToClient);
-        registerVariable(this->mDensity, VariableDirection::ToClient);
-        registerVariable(this->position, VariableDirection::ToClient);
-        registerVariable(this->maxSize, VariableDirection::ToClient);
-        registerVariable(this->minSize, VariableDirection::ToClient);
-        registerVariable(this->radius, VariableDirection::ToClient);
-        registerVariable(this->foggy, VariableDirection::ToClient);
-        registerVariable(this->fogDensity, VariableDirection::ToClient);
-
-    }
-
     void SpicedAsteroidField::tick(float dt){
 
         this->create();
-        this->bAlive_ = false;
         this->destroyLater();
     }
 

Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.h
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.h	2018-02-11 18:19:57 UTC (rev 11735)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.h	2018-02-11 21:31:46 UTC (rev 11736)
@@ -42,29 +42,23 @@
 
 #include "AsteroidMiningPrereqs.h"
 
-#include <string>
-#include <vector>
+#include "core/BaseObject.h"
+#include "tools/interfaces/Tickable.h"
 
-#include "worldentities/ControllableEntity.h"
-#include "../../orxonox/worldentities/pawns/Pawn.h"
-
 namespace orxonox // tolua_export
 {
 
     // tolua_export
-    class _AsteroidMiningExport SpicedAsteroidField : public Pawn // need pawn to get tick for clean argument passing
+    class _AsteroidMiningExport SpicedAsteroidField : public BaseObject, public Tickable
     { // tolua_export
 
         public:
-            SpicedAsteroidField(Context* context);// This constructor is for XML access only!
-            SpicedAsteroidField(Context* c, Vector3 p, int minS, int maxS, int w, int count, bool f, float mD, float fD); 
+            SpicedAsteroidField(Context* context);
+            virtual ~SpicedAsteroidField();
 
-            virtual ~SpicedAsteroidField();
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-            virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override;
             virtual void tick(float dt) override;
 
-
             inline void setCount(float s){this->count = s;}
             inline float getCount(){return this->count;}
 
@@ -91,8 +85,6 @@
 
         protected:
 
-            Context* context;
-
             float count; //!< Number of asteroids generated
             float mDensity; //!< Mineral density, between 0 and 1;
 
@@ -107,8 +99,6 @@
 
 
         private:
-            void registerVariables();
-
             virtual void create();
 
 



More information about the Orxonox-commit mailing list