Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11736 for code/branches


Ignore:
Timestamp:
Feb 11, 2018, 10:31:46 PM (7 years ago)
Author:
landauf
Message:

[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.

Location:
code/branches/Presentation_HS17_merge/src/modules/asteroidmining
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc

    r11735 r11736  
    7171*/
    7272
    73 
    74 #include "../../orxonox/worldentities/pawns/Pawn.h"
    75 #include "../../orxonox/worldentities/WorldEntity.h"
    76 
    7773#include "AsteroidMinable.h"
    7874
     
    8278#include "core/GameMode.h"
    8379#include "core/XMLPort.h"
    84 #include "core/EventIncludes.h"
    85 #include "network/NetworkFunction.h"
    8680#include "util/Convert.h"
    8781#include "util/Math.h"
    8882
    89 #include "../pickup/PickupSpawner.h"
    90 #include "../pickup/Pickup.h"
    91 
    92 #include "../objects/collisionshapes/SphereCollisionShape.h"
    93 #include "../../orxonox/graphics/Model.h"
    94 
     83#include "pickup/PickupSpawner.h"
     84#include "pickup/Pickup.h"
     85
     86#include "objects/collisionshapes/SphereCollisionShape.h"
     87#include "graphics/Model.h"
    9588
    9689namespace orxonox{
     
    10295
    10396        RegisterObject(AsteroidMinable);
    104         this->context = context;
    10597
    10698        // Default Values:
    107         this->size = 10;
     99        this->size = 1;
    108100        this->dropStuff = true;
    109101        this->generateSmaller = true;
    110         this->health_ = 15*size;
    111         this->maxHealth_ = this->health_;
    112102        this->acceptsPickups_ = false;
    113103
     
    121111    }
    122112
    123     // @brief Use this constructor with care. Mainly used internally, arguments are passed directly.
    124     AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position, bool dropStuff) : Pawn(c){
    125 
    126         RegisterObject(AsteroidMinable);
     113    AsteroidMinable::~AsteroidMinable(){
     114
     115    }
     116
     117    void AsteroidMinable::setSize(int s)
     118    {
     119        this->size = s;
     120        this->health_ = 15*size;
     121        this->maxHealth_ = this->health_;
     122    }
     123
     124    // @brief Helper method.
     125    void AsteroidMinable::putStuff(){
    127126
    128127        // The radar is able to detect whether an asteroid contains resources....
     
    136135        }
    137136
    138         this->context = c;
    139         this->size = size;
    140         this->health_ = 15*size;
    141         this->maxHealth_ = this->health_;
    142         this->acceptsPickups_ = false;
    143         this->generateSmaller = true;
    144         this->dropStuff = dropStuff;
    145 
    146         this->setPosition(position);
    147         //this->roll = rand()*5; //etwas Drehung. Richtige Variable?
    148 
    149         this->setCollisionType(WorldEntity::CollisionType::Dynamic);
    150         this->enableCollisionCallback();
    151 
    152137        // Add Model, random one of the 6 shapes
    153         Model* hull = new Model(this->context);
     138        Model* hull = new Model(this->getContext());
    154139        hull->setMeshSource("ast" + multi_cast<std::string>(1 + (int)rnd(0, 6)) + ".mesh");
    155140        hull->setScale(this->size);
     
    157142
    158143        // Collision shape
    159         SphereCollisionShape* cs = new SphereCollisionShape(this->context);
     144        SphereCollisionShape* cs = new SphereCollisionShape(this->getContext());
    160145        cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien.
    161146        this->attachCollisionShape(cs);
    162147
    163         this->registerVariables();
    164 
    165148        this->initialised=true;
    166 
    167     }
    168 
    169     AsteroidMinable::~AsteroidMinable(){
    170 
    171     }
    172 
    173     // @brief Helper method.
    174     void AsteroidMinable::putStuff(){
    175 
    176         AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->dropStuff);
    177         reborn->setVelocity(this->getVelocity());
    178         // reborn->setAngularVelocity(this->getAngularVelocity()); // Add all other stuff, too?
    179 
    180         this->bAlive_ = false;
    181         this->destroyLater();
    182 
    183149    }
    184150
     
    188154
    189155        XMLPortParam(AsteroidMinable, "size", setSize, getSize, xmlelement, mode);
    190         XMLPortParam(AsteroidMinable, "generateSmaller", toggleShattering, doesShatter, xmlelement, mode);
    191         XMLPortParam(AsteroidMinable, "dropStuff", toggleDropStuff, doesDropStuff, xmlelement, mode);
    192 
    193     }
    194 
    195     void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
    196 
    197         SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode);
     156        XMLPortParam(AsteroidMinable, "generateSmaller", setShattering, doesShatter, xmlelement, mode);
     157        XMLPortParam(AsteroidMinable, "dropStuff", setDropStuff, doesDropStuff, xmlelement, mode);
    198158
    199159    }
     
    228188        // Pickups which can be harvested. It's munition at the moment, could be changed/extended.
    229189        if(dropStuff){
    230             PickupSpawner* thingy = new PickupSpawner(this->context);
     190            PickupSpawner* thingy = new PickupSpawner(this->getContext());
    231191
    232192            std::string tname;
     
    366326        }
    367327       
    368         AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + pos, this->dropStuff);
     328        AsteroidMinable* child = new AsteroidMinable(this->getContext());
     329        child->setSize(masses[fisch]);
     330        child->setPosition(this->getPosition() + pos);
    369331        child->setVelocity(this->getVelocity());
    370 
     332        child->setDropStuff(this->dropStuff);
    371333    }
    372334    // orxout() << "Leaving spawnChildren() method. " << endl;
  • code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.h

    r11732 r11736  
    7676#include "AsteroidMiningPrereqs.h"
    7777
    78 #include <string>
    79 #include <vector>
    80 #include "interfaces/PickupCarrier.h"
    81 #include "interfaces/RadarViewable.h"
    82 #include "worldentities/ControllableEntity.h"
    83 #include "worldentities/ExplosionPart.h"
    84 
    85 #include "../../orxonox/worldentities/pawns/Pawn.h"
     78#include "worldentities/pawns/Pawn.h"
    8679
    8780namespace orxonox{
    8881
    8982
    90     class _AsteroidMiningExport AsteroidMinable : public Pawn{
     83    class _AsteroidMiningExport AsteroidMinable : public Pawn
     84    {
     85        public:
     86            AsteroidMinable(Context* context);
     87            virtual ~AsteroidMinable();
    9188
    92         public:
    93             // @brief This constructor is for XML access only!
    94             AsteroidMinable(Context* context);
    95             // @brief Call this Constructor from other C-files.
    96             AsteroidMinable(Context* c, float size, Vector3 position, bool dS);
    97 
    98             virtual ~AsteroidMinable();
    9989            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    100             virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override;
    10190            virtual void tick(float dt) override;
    10291
     
    10594            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
    10695
    107             inline void setSize(int s){this->size = s;}
     96            void setSize(int s);
    10897            inline int getSize(){return this->size;}
    10998
    110             inline void toggleShattering(bool b){this->generateSmaller = b;}
     99            inline void setShattering(bool b){this->generateSmaller = b;}
    111100            inline bool doesShatter(){return this->generateSmaller;}
    112101
    113             inline void toggleDropStuff(bool b){this->dropStuff = b;}
     102            inline void setDropStuff(bool b){this->dropStuff = b;}
    114103            inline bool doesDropStuff(){return this->dropStuff;}
    115104
    116105        protected:
    117 
    118             Context* context;
    119106
    120107            int size; //!< Implies health and type of dropped pickups
  • code/branches/Presentation_HS17_merge/src/modules/asteroidmining/CMakeLists.txt

    r11664 r11736  
    1313
    1414  LINK_LIBRARIES
    15     overlays
    1615    orxonox
    1716    pickup
  • code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc

    r11735 r11736  
    4545
    4646
    47 #include "../../orxonox/worldentities/pawns/Pawn.h"
    48 #include "../../orxonox/worldentities/WorldEntity.h"
    49 
    5047#include "SpicedAsteroidBelt.h"
    5148#include "SpicedAsteroidField.h"
     
    5451
    5552#include "core/CoreIncludes.h"
    56 #include "core/GameMode.h"
    5753#include "core/XMLPort.h"
    58 #include "core/EventIncludes.h"
    59 #include "network/NetworkFunction.h"
    6054#include "util/Math.h"
    6155
     
    6458    RegisterClass(SpicedAsteroidBelt);
    6559
    66     SpicedAsteroidBelt::SpicedAsteroidBelt(Context* context) : Pawn(context) {
     60    SpicedAsteroidBelt::SpicedAsteroidBelt(Context* context) : BaseObject(context) {
    6761
    6862        RegisterObject(SpicedAsteroidBelt);
    69 
    70         this->context = context;
    7163
    7264        // Default Values:
     
    8577        this->tiltAt = 0.0;
    8678        this->tiltBy = 0.0; 
    87 
    88         this->registerVariables();
    8979
    9080    }
     
    115105           
    116106            Vector3 pos(radius*cos(sepp)*sin(globi), radius*sin(sepp)*sin(globi), radius*cos(globi));
    117             new SpicedAsteroidField(this->context, this->position + pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
    118            
     107
     108            SpicedAsteroidField* field = new SpicedAsteroidField(this->getContext());
     109            field->setPosition(this->position + pos);
     110            field->setMinSize(this->minSize);
     111            field->setMaxSize(this->maxSize);
     112            field->setRadius(width);
     113            field->setCount(segmentCount);
     114            field->setFog(this->foggy);
     115            field->setMineralDensity(this->mDensity);
     116            field->setFogDensity(this->fogDensity);
    119117        }
    120        
    121118    }
    122119
     
    142139    }
    143140
    144     void SpicedAsteroidBelt::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
    145 
    146     }
    147 
    148     void SpicedAsteroidBelt::registerVariables(){
    149 
    150         registerVariable(this->count, VariableDirection::ToClient);
    151         registerVariable(this->mDensity, VariableDirection::ToClient);
    152         registerVariable(this->position, VariableDirection::ToClient);
    153         registerVariable(this->segments, VariableDirection::ToClient);
    154 
    155         registerVariable(this->maxSize, VariableDirection::ToClient);
    156         registerVariable(this->minSize, VariableDirection::ToClient);
    157         registerVariable(this->radius0, VariableDirection::ToClient);
    158         registerVariable(this->radius1, VariableDirection::ToClient);
    159         registerVariable(this->foggy, VariableDirection::ToClient);
    160         registerVariable(this->fogDensity, VariableDirection::ToClient);
    161 
    162         registerVariable(this->tiltAt, VariableDirection::ToClient);
    163         registerVariable(this->tiltBy, VariableDirection::ToClient);
    164 
    165     }
    166 
    167141    void SpicedAsteroidBelt::tick(float dt){
    168142
    169143        this->create();
    170         this->bAlive_ = false;
    171144        this->destroyLater();
    172145
  • code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.h

    r11731 r11736  
    4949#include "AsteroidMiningPrereqs.h"
    5050
    51 #include <string>
    52 #include <vector>
    53 #include "worldentities/ControllableEntity.h"
    54 
    55 #include "../../orxonox/worldentities/pawns/Pawn.h"
     51#include "core/BaseObject.h"
     52#include "tools/interfaces/Tickable.h"
    5653
    5754namespace orxonox // tolua_export
     
    5956
    6057    // tolua_export
    61     class _AsteroidMiningExport SpicedAsteroidBelt : public Pawn // need pawn to get tick for clean argument passing
     58    class _AsteroidMiningExport SpicedAsteroidBelt : public BaseObject, public Tickable
    6259    { // tolua_export
    6360
    6461        public:
    6562            SpicedAsteroidBelt(Context* context);// This constructor is for XML access only!
     63            virtual ~SpicedAsteroidBelt();
    6664
    67             virtual ~SpicedAsteroidBelt();
    6865            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    69             virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override;
    7066            virtual void tick(float dt) override;
    71 
    7267
    7368            inline void setCount(float s){this->count = s;}
     
    109104        protected:
    110105
    111             Context* context;
    112 
    113106            float count; //!< Approximate number of asteroids
    114107            float mDensity; //!< Approximate commonness of asteroids that yield stuff, value between 0 and 1;
     
    131124
    132125        private:
    133             void registerVariables();
    134            
    135126            virtual void create();
    136127
  • code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.cc

    r11735 r11736  
    4040
    4141
    42 #include "../../orxonox/worldentities/pawns/Pawn.h"
    43 #include "../../orxonox/worldentities/WorldEntity.h"
    44 
    4542#include "SpicedAsteroidField.h"
    4643#include "AsteroidMinable.h"
     
    4946
    5047#include "core/CoreIncludes.h"
    51 #include "core/GameMode.h"
    5248#include "core/XMLPort.h"
    53 #include "core/EventIncludes.h"
    54 #include "network/NetworkFunction.h"
    5549#include "util/Math.h"
    5650
    57 #include "../../orxonox/graphics/Billboard.h"
     51#include "graphics/Billboard.h"
    5852
    5953
     
    6256    RegisterClass(SpicedAsteroidField);
    6357
    64     SpicedAsteroidField::SpicedAsteroidField(Context* context) : Pawn(context) {
     58    SpicedAsteroidField::SpicedAsteroidField(Context* context) : BaseObject(context) {
    6559
    6660        RegisterObject(SpicedAsteroidField);
    67         this->context = context;
    6861
    6962        // Default Values:
     
    7669        this->foggy = true;
    7770        this->fogDensity = 0.5;
    78 
    79         this->registerVariables();
    8071    }
    81 
    82     SpicedAsteroidField::SpicedAsteroidField(Context* c, Vector3 p, int minS, int maxS, int w, int count, bool f, float mD, float fD): Pawn(c){
    83 
    84         this->context = c;
    85         this->position = p;
    86         this->minSize = minS;
    87         this->maxSize = maxS;
    88         this->radius = w;
    89         this->count = count;
    90         this->foggy = f;
    91 
    92         this->mDensity = mD;
    93         this->fogDensity = fD;
    94 
    95     }
    96 
    9772
    9873    SpicedAsteroidField::~SpicedAsteroidField(){
     
    10984        for(int gertrud = 0; gertrud<count; ++gertrud){
    11085
    111             AsteroidMinable* a = new AsteroidMinable(this->context);
     86            AsteroidMinable* a = new AsteroidMinable(this->getContext());
    11287
    11388            size = round(rnd()*(this->maxSize - this->minSize)) + this->minSize;
     
    12196
    12297            bool spiced = (rnd() < (this->mDensity)); // Whether the asteroid does drop pickups etc.
    123             a->toggleDropStuff(spiced);
    124            
    125             a->setVelocity(this->getVelocity());
     98            a->setDropStuff(spiced);
    12699           
    127100            // Fog is iplemented with billboards (as in asteroidField.lua, that bloke had the idea)
    128101            if(this->foggy && mod(gertrud, 5) == 0){
    129                 Billboard* bb = new Billboard(this->context);
     102                Billboard* bb = new Billboard(this->getContext());
    130103                bb->setPosition(this->position + relPos);
    131104                bb->setMaterial("Smoke/Smoke");
     
    151124    }
    152125
    153 
    154     void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
    155 
    156     }
    157 
    158     void SpicedAsteroidField::registerVariables(){
    159 
    160         registerVariable(this->count, VariableDirection::ToClient);
    161         registerVariable(this->mDensity, VariableDirection::ToClient);
    162         registerVariable(this->position, VariableDirection::ToClient);
    163         registerVariable(this->maxSize, VariableDirection::ToClient);
    164         registerVariable(this->minSize, VariableDirection::ToClient);
    165         registerVariable(this->radius, VariableDirection::ToClient);
    166         registerVariable(this->foggy, VariableDirection::ToClient);
    167         registerVariable(this->fogDensity, VariableDirection::ToClient);
    168 
    169     }
    170 
    171126    void SpicedAsteroidField::tick(float dt){
    172127
    173128        this->create();
    174         this->bAlive_ = false;
    175129        this->destroyLater();
    176130    }
  • code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.h

    r11731 r11736  
    4343#include "AsteroidMiningPrereqs.h"
    4444
    45 #include <string>
    46 #include <vector>
    47 
    48 #include "worldentities/ControllableEntity.h"
    49 #include "../../orxonox/worldentities/pawns/Pawn.h"
     45#include "core/BaseObject.h"
     46#include "tools/interfaces/Tickable.h"
    5047
    5148namespace orxonox // tolua_export
     
    5350
    5451    // tolua_export
    55     class _AsteroidMiningExport SpicedAsteroidField : public Pawn // need pawn to get tick for clean argument passing
     52    class _AsteroidMiningExport SpicedAsteroidField : public BaseObject, public Tickable
    5653    { // tolua_export
    5754
    5855        public:
    59             SpicedAsteroidField(Context* context);// This constructor is for XML access only!
    60             SpicedAsteroidField(Context* c, Vector3 p, int minS, int maxS, int w, int count, bool f, float mD, float fD);
     56            SpicedAsteroidField(Context* context);
     57            virtual ~SpicedAsteroidField();
    6158
    62             virtual ~SpicedAsteroidField();
    6359            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    64             virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override;
    6560            virtual void tick(float dt) override;
    66 
    6761
    6862            inline void setCount(float s){this->count = s;}
     
    9286        protected:
    9387
    94             Context* context;
    95 
    9688            float count; //!< Number of asteroids generated
    9789            float mDensity; //!< Mineral density, between 0 and 1;
     
    108100
    109101        private:
    110             void registerVariables();
    111 
    112102            virtual void create();
    113103
Note: See TracChangeset for help on using the changeset viewer.