Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2008, 6:01:13 PM (15 years ago)
Author:
landauf
Message:

Merged objecthierarchy2 into presentation branch

Couln't merge 2 lines in Gamestate.cc and a whole block of code in GSDedicated.cc (it seems like oli implemented in both branches something like a network-tick-limiter but with different approaches)

Not yet tested in network mode and with bots
The SpaceShips movement is also not yet fully adopted to the new physics (see Engine class)

Location:
code/branches/presentation
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2371 r2485  
    3030#include "Pawn.h"
    3131
     32#include "core/Core.h"
    3233#include "core/CoreIncludes.h"
    3334#include "core/XMLPort.h"
    3435#include "util/Math.h"
     36#include "PawnManager.h"
    3537#include "objects/infos/PlayerInfo.h"
    3638#include "objects/gametypes/Gametype.h"
    3739#include "objects/weaponSystem/WeaponSystem.h"
     40#include "objects/worldentities/ParticleSpawner.h"
     41#include "objects/worldentities/ExplosionChunk.h"
    3842
    3943namespace orxonox
     
    4549        RegisterObject(Pawn);
    4650
    47         this->bAlive_ = false;
     51        PawnManager::touch();
     52
     53        this->bAlive_ = true;
    4854
    4955        this->health_ = 0;
     
    5359        this->lastHitOriginator_ = 0;
    5460        this->weaponSystem_ = 0;
     61
     62        this->spawnparticleduration_ = 3.0f;
    5563
    5664        /*
     
    6270        */
    6371
     72        this->setRadarObjectColour(ColourValue::Red);
     73        this->setRadarObjectShape(RadarViewable::Dot);
     74
    6475        this->registerVariables();
    6576    }
     
    6778    Pawn::~Pawn()
    6879    {
     80        if (this->isInitialized())
     81        {
     82            for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it)
     83                it->destroyedPawn(this);
     84        }
    6985    }
    7086
     
    7389        SUPER(Pawn, XMLPort, xmlelement, mode);
    7490
    75         XMLPortParam(Pawn, "health", setHealth, getHealht, xmlelement, mode).defaultValues(100);
     91        XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
    7692        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
    7793        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
     94        XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode);
     95        XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f);
     96        XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
    7897    }
    7998
    8099    void Pawn::registerVariables()
    81100    {
    82         registerVariable(this->bAlive_, variableDirection::toclient);
    83         registerVariable(this->health_, variableDirection::toclient);
     101        registerVariable(this->bAlive_,        variableDirection::toclient);
     102        registerVariable(this->health_,        variableDirection::toclient);
     103        registerVariable(this->initialHealth_, variableDirection::toclient);
    84104    }
    85105
     
    119139    }
    120140
    121     void Pawn::spawn()
     141    void Pawn::spawneffect()
    122142    {
    123143        // play spawn effect
     144        if (this->spawnparticlesource_ != "")
     145        {
     146            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     147            effect->setPosition(this->getPosition());
     148            effect->setOrientation(this->getOrientation());
     149            effect->setDestroyAfterLife(true);
     150            effect->setSource(this->spawnparticlesource_);
     151            effect->setLifetime(this->spawnparticleduration_);
     152        }
    124153    }
    125154
    126155    void Pawn::death()
    127156    {
     157        // Set bAlive_ to false and wait for PawnManager to do the destruction
    128158        this->bAlive_ = false;
     159
     160        this->setDestroyWhenPlayerLeft(false);
     161
    129162        if (this->getGametype())
    130163            this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
     164
    131165        if (this->getPlayer())
    132166            this->getPlayer()->stopControl(this);
    133167
    134         delete this;
    135 
     168        if (Core::isMaster())
     169            this->deatheffect();
     170    }
     171
     172    void Pawn::deatheffect()
     173    {
    136174        // play death effect
     175        {
     176            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     177            effect->setPosition(this->getPosition());
     178            effect->setOrientation(this->getOrientation());
     179            effect->setDestroyAfterLife(true);
     180            effect->setSource("Orxonox/explosion2b");
     181            effect->setLifetime(4.0f);
     182        }
     183        {
     184            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     185            effect->setPosition(this->getPosition());
     186            effect->setOrientation(this->getOrientation());
     187            effect->setDestroyAfterLife(true);
     188            effect->setSource("Orxonox/smoke6");
     189            effect->setLifetime(4.0f);
     190        }
     191        {
     192            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     193            effect->setPosition(this->getPosition());
     194            effect->setOrientation(this->getOrientation());
     195            effect->setDestroyAfterLife(true);
     196            effect->setSource("Orxonox/sparks");
     197            effect->setLifetime(4.0f);
     198        }
     199        for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)
     200        {
     201            ExplosionChunk* chunk = new ExplosionChunk(this->getCreator());
     202            chunk->setPosition(this->getPosition());
     203
     204        }
    137205    }
    138206
     
    146214    {
    147215        this->setHealth(this->initialHealth_);
    148         this->spawn();
     216        if (Core::isMaster())
     217            this->spawneffect();
     218    }
     219
     220    ///////////////////
     221    // Pawn Listener //
     222    ///////////////////
     223    PawnListener::PawnListener()
     224    {
     225        RegisterRootObject(PawnListener);
    149226    }
    150227}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Pawn.h

    r2098 r2485  
    3333
    3434#include "objects/worldentities/ControllableEntity.h"
     35#include "objects/RadarViewable.h"
    3536
    3637namespace orxonox
    3738{
    38     class _OrxonoxExport Pawn : public ControllableEntity
     39    class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable
    3940    {
    4041        public:
     
    5455            inline void removeHealth(float health)
    5556                { this->setHealth(this->health_ - health); }
    56             inline float getHealht() const
     57            inline float getHealth() const
    5758                { return this->health_; }
    5859
     
    7879            virtual void postSpawn();
    7980
     81            inline const WorldEntity* getWorldEntity() const
     82                { return (WorldEntity*)this; }
     83
     84            inline void setSpawnParticleSource(const std::string& source)
     85                { this->spawnparticlesource_ = source; }
     86            inline const std::string& getSpawnParticleSource() const
     87                { return this->spawnparticlesource_; }
     88
     89            inline void setSpawnParticleDuration(float duration)
     90                { this->spawnparticleduration_ = duration; }
     91            inline float getSpawnParticleDuration() const
     92                { return this->spawnparticleduration_; }
     93
     94            inline void setExplosionChunks(unsigned int chunks)
     95                { this->numexplosionchunks_ = chunks; }
     96            inline unsigned int getExplosionChunks() const
     97                { return this->numexplosionchunks_; }
     98
    8099        protected:
    81             virtual void spawn();
    82100            virtual void death();
     101            virtual void deatheffect();
     102            virtual void spawneffect();
    83103
    84104            bool bAlive_;
     
    91111
    92112            WeaponSystem* weaponSystem_;
     113
     114            std::string spawnparticlesource_;
     115            float spawnparticleduration_;
     116            unsigned int numexplosionchunks_;
     117    };
     118
     119    class _OrxonoxExport PawnListener : public OrxonoxClass
     120    {
     121        friend class Pawn;
     122
     123        public:
     124            PawnListener();
     125            virtual ~PawnListener() {}
     126
     127        protected:
     128            virtual void destroyedPawn(Pawn* pawn) = 0;
    93129    };
    94130}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.cc

    r2475 r2485  
    3636#include "core/CoreIncludes.h"
    3737#include "core/ConfigValueIncludes.h"
     38#include "core/Template.h"
    3839#include "core/XMLPort.h"
     40#include "objects/items/Engine.h"
    3941
    4042namespace orxonox
     
    5355        this->localLinearAcceleration_.setValue(0, 0, 0);
    5456        this->localAngularAcceleration_.setValue(0, 0, 0);
     57        this->bBoost_ = false;
     58        this->steering_ = Vector3::ZERO;
     59        this->engine_ = 0;
     60
    5561
    5662        this->bInvertYAxis_ = false;
     
    7076    SpaceShip::~SpaceShip()
    7177    {
     78        if (this->isInitialized() && this->engine_)
     79            delete this->engine_;
    7280    }
    7381
     
    7684        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    7785
     86        XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
    7887        XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
    7988        XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
     
    109118        SUPER(SpaceShip, tick, dt);
    110119
    111         if (this->isLocallyControlled())
     120        if (this->hasLocalController())
    112121        {
    113             this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
    114             this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
    115             if (this->localLinearAcceleration_.z() > 0)
    116                 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
    117             else
    118                 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
    119             this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
    120             this->localLinearAcceleration_.setValue(0, 0, 0);
     122            if (!this->isInMouseLook())
     123            {
     124                this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
     125                this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
     126                if (this->localLinearAcceleration_.z() > 0)
     127                    this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
     128                else
     129                    this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
     130                this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
     131                this->localLinearAcceleration_.setValue(0, 0, 0);
     132            }
    121133
    122134            this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
     
    129141    {
    130142        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
     143        this->steering_.z = -value.x;
    131144    }
    132145
     
    134147    {
    135148        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
     149        this->steering_.x = value.x;
    136150    }
    137151
     
    139153    {
    140154        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
     155        this->steering_.y = value.x;
    141156    }
    142157
     
    144159    {
    145160        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x);
     161
     162        Pawn::rotateYaw(value);
    146163    }
    147164
     
    149166    {
    150167        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
     168
     169        Pawn::rotatePitch(value);
    151170    }
    152171
     
    154173    {
    155174        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
     175
     176        Pawn::rotateRoll(value);
    156177    }
    157178
     
    159180    {
    160181    }
     182
     183    void SpaceShip::boost()
     184    {
     185        this->bBoost_ = true;
     186    }
     187
     188    void SpaceShip::loadEngineTemplate()
     189    {
     190        if (this->enginetemplate_ != "")
     191        {
     192            Template* temp = Template::getTemplate(this->enginetemplate_);
     193
     194            if (temp)
     195            {
     196                Identifier* identifier = temp->getBaseclassIdentifier();
     197
     198                if (identifier)
     199                {
     200                    BaseObject* object = identifier->fabricate(this);
     201                    this->engine_ = dynamic_cast<Engine*>(object);
     202
     203                    if (this->engine_)
     204                    {
     205                        this->engine_->addTemplate(temp);
     206                        this->engine_->addToSpaceShip(this);
     207                    }
     208                    else
     209                    {
     210                        delete object;
     211                    }
     212                }
     213            }
     214        }
     215    }
     216
     217    void SpaceShip::setEngine(Engine* engine)
     218    {
     219        this->engine_ = engine;
     220        if (engine && engine->getShip() != this)
     221            engine->addToSpaceShip(this);
     222    }
    161223}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.h

    r2459 r2485  
    5858
    5959            virtual void fire();
     60            virtual void boost();
     61
     62            void setEngine(Engine* engine);
     63            inline Engine* getEngine() const
     64                { return this->engine_; }
     65
     66            inline void setSteeringDirection(const Vector3& direction)
     67                { this->steering_ = direction; }
     68            inline const Vector3& getSteeringDirection() const
     69                { return this->steering_; }
     70
     71            inline void setBoost(bool bBoost)
     72                { this->bBoost_ = bBoost; }
     73            inline bool getBoost() const
     74                { return this->bBoost_; }
     75
     76            inline void setEngineTemplate(const std::string& temp)
     77                { this->enginetemplate_ = temp; this->loadEngineTemplate(); }
     78            inline const std::string& getEngineTemplate() const
     79                { return this->enginetemplate_; }
    6080
    6181        protected:
    6282            bool bInvertYAxis_;
    6383
     84            bool bBoost_;
     85            Vector3 steering_;
    6486            float primaryThrust_;
    6587            float auxilaryThrust_;
     
    7193        private:
    7294            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
     95
     96        private:
     97            void loadEngineTemplate();
     98
     99            std::string enginetemplate_;
     100            Engine* engine_;
    73101    };
    74102}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.cc

    r2480 r2485  
    3333
    3434#include "core/CoreIncludes.h"
     35#include "core/ConfigValueIncludes.h"
    3536#include "core/Core.h"
    3637#include "objects/worldentities/Model.h"
     
    5152        RegisterObject(Spectator);
    5253
    53         this->speed_ = 100;
    54         this->rotationGain_ = 3;
     54        this->speed_ = 200;
    5555
    5656        this->yaw_ = 0;
     
    5959        this->localVelocity_ = Vector3::ZERO;
    6060        this->setHudTemplate("spectatorhud");
    61         this->hudmode_ = 0;
     61        this->greetingFlare_ = 0;
    6262
    6363        this->setDestroyWhenPlayerLeft(true);
    6464
    65         if ( Core::showsGraphics() )
    66         {
     65        if (Core::showsGraphics())
     66        {
    6767            this->greetingFlare_ = new BillboardSet();
    6868            this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);
     
    7171            this->greetingFlare_->setVisible(false);
    7272        }
    73         else
    74             this->greetingFlare_ = 0;
     73
    7574        this->bGreetingFlareVisible_ = false;
    7675        this->bGreeting_ = false;
    7776
     77        this->setConfigValues();
    7878        this->registerVariables();
    7979    }
     
    8787                if (this->greetingFlare_->getBillboardSet())
    8888                    this->detachOgreObject(this->greetingFlare_->getBillboardSet());
     89
    8990                delete this->greetingFlare_;
    9091            }
     
    9293    }
    9394
     95    void Spectator::setConfigValues()
     96    {
     97        SetConfigValue(speed_, 200.0f);
     98    }
     99
    94100    void Spectator::registerVariables()
    95101    {
    96102        registerVariable(this->bGreetingFlareVisible_, variableDirection::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility));
    97103        registerVariable(this->bGreeting_,             variableDirection::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting));
    98         registerVariable(this->hudmode_,               variableDirection::toclient);
    99104    }
    100105
     
    107112    void Spectator::changedFlareVisibility()
    108113    {
    109         if ( this->greetingFlare_ )             
     114        if ( this->greetingFlare_ )
    110115            this->greetingFlare_->setVisible(this->bGreetingFlareVisible_);
    111116    }
     
    113118    void Spectator::tick(float dt)
    114119    {
    115         this->updateHUD();
    116 
    117         if (this->isLocallyControlled())
     120        if (this->hasLocalController())
    118121        {
    119122            float localSpeedSquared = this->localVelocity_.squaredLength();
     
    132135            this->localVelocity_.z = 0;
    133136
    134             this->yaw  (Radian(this->yaw_   * this->rotationGain_));
    135             this->pitch(Radian(this->pitch_ * this->rotationGain_));
    136             this->roll (Radian(this->roll_  * this->rotationGain_));
     137            if (!this->isInMouseLook())
     138            {
     139                this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()));
     140                this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
     141                this->roll(Radian(this->roll_ * this->getMouseLookSpeed()));
     142            }
    137143
    138144            this->yaw_ = this->pitch_ = this->roll_ = 0;
     
    146152        ControllableEntity::setPlayer(player);
    147153
    148 //        this->setObjectMode(direction::toclient);
    149     }
    150 
    151     void Spectator::startLocalControl()
    152     {
    153         ControllableEntity::startLocalControl();
    154 //        if (this->isLocallyControlled())
    155 //            this->testmesh_->setVisible(false);
     154//        this->setObjectMode(objectDirection::toclient);
     155    }
     156
     157    void Spectator::startLocalHumanControl()
     158    {
     159        ControllableEntity::startLocalHumanControl();
    156160    }
    157161
     
    174178    {
    175179        this->yaw_ += value.y;
     180
     181        ControllableEntity::rotateYaw(value);
    176182    }
    177183
     
    179185    {
    180186        this->pitch_ += value.y;
     187
     188        ControllableEntity::rotatePitch(value);
    181189    }
    182190
     
    184192    {
    185193        this->roll_ += value.y;
     194
     195        ControllableEntity::rotateRoll(value);
    186196    }
    187197
     
    202212        }
    203213    }
    204 
    205     void Spectator::updateHUD()
    206     {
    207         // <hack>
    208         if (Core::isMaster())
    209         {
    210             if (this->getPlayer() && this->getGametype())
    211             {
    212                 if (!this->getGametype()->hasStarted() && !this->getGametype()->isStartCountdownRunning())
    213                 {
    214                     if (!this->getPlayer()->isReadyToSpawn())
    215                         this->hudmode_ = 0;
    216                     else
    217                         this->hudmode_ = 1;
    218                 }
    219                 else if (!this->getGametype()->hasEnded())
    220                 {
    221                     if (this->getGametype()->isStartCountdownRunning())
    222                         this->hudmode_ = 2 + 10*(int)ceil(this->getGametype()->getStartCountdown());
    223                     else
    224                         this->hudmode_ = 3;
    225                 }
    226                 else
    227                     this->hudmode_ = 4;
    228             }
    229             else
    230                 return;
    231         }
    232 
    233         if (this->getHUD())
    234         {
    235             std::string text;
    236             int hudmode = this->hudmode_ % 10;
    237 
    238             switch (hudmode)
    239             {
    240                 case 0:
    241                     text = "Press [Fire] to start the match";
    242                     break;
    243                 case 1:
    244                     text = "Waiting for other players";
    245                     break;
    246                 case 2:
    247                     text = convertToString((this->hudmode_ - 2) / 10);
    248                     break;
    249                 case 3:
    250                     text = "Press [Fire] to respawn";
    251                     break;
    252                 case 4:
    253                     text = "Game has ended";
    254                     break;
    255                 default:;
    256             }
    257 
    258             std::map<std::string, OrxonoxOverlay*>::const_iterator it = this->getHUD()->getOverlays().begin();
    259             for (; it != this->getHUD()->getOverlays().end(); ++it)
    260             {
    261                 if (it->second->isA(Class(OverlayText)) && it->second->getName() == "state")
    262                 {
    263                     OverlayText* overlay = dynamic_cast<OverlayText*>(it->second);
    264                     if (overlay)
    265                         overlay->setCaption(text);
    266                     break;
    267                 }
    268             }
    269         }
    270         // </hack>
    271     }
    272214}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.h

    r2459 r2485  
    4242            virtual ~Spectator();
    4343
     44            void setConfigValues();
    4445            void registerVariables();
    4546            virtual void tick(float dt);
    4647
    4748            virtual void setPlayer(PlayerInfo* player);
    48             virtual void startLocalControl();
     49            virtual void startLocalHumanControl();
    4950
    5051            virtual void moveFrontBack(const Vector2& value);
     
    6263            void changedGreeting();
    6364            void changedFlareVisibility();
    64             void updateHUD();
    6565
    6666            BillboardSet* greetingFlare_;
     
    6969
    7070            float speed_;
    71             float rotationGain_;
    7271
    7372            float yaw_;
     
    7675
    7776            Vector3 localVelocity_;
    78 
    79             int hudmode_;
    8077    };
    8178}
Note: See TracChangeset for help on using the changeset viewer.