Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2009, 10:23:58 PM (15 years ago)
Author:
rgrieder
Message:

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
Location:
code/trunk
Files:
2 deleted
89 edited
10 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/CMakeLists.txt

    r5929 r6417  
    2828  LevelManager.cc
    2929  Main.cc
     30  MoodManager.cc
    3031  PawnManager.cc
    3132  PlayerManager.cc
     
    5556  TOLUA_FILES
    5657    LevelManager.h
     58    MoodManager.h
     59    controllers/HumanController.h
    5760    pickup/BaseItem.h
    5861    pickup/PickupInventory.h
     62    sound/SoundManager.h
    5963  DEFINE_SYMBOL
    6064    "ORXONOX_SHARED_BUILD"
  • code/trunk/src/orxonox/CameraManager.cc

    r5929 r6417  
    4545namespace orxonox
    4646{
    47     CameraManager* CameraManager::singletonPtr_s = 0;
    4847    ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
    4948
  • code/trunk/src/orxonox/Level.cc

    r5929 r6417  
    141141    void Level::playerEntered(PlayerInfo* player)
    142142    {
    143         COUT(3) << "player entered level (id: " << player->getClientID() << ", name: " << player->getName() << ")" << std::endl;
     143        COUT(3) << "player entered level (id: " << player->getClientID() << ", name: " << player->getName() << ')' << std::endl;
    144144        player->setGametype(this->getGametype());
    145145    }
     
    147147    void Level::playerLeft(PlayerInfo* player)
    148148    {
    149         COUT(3) << "player left level (id: " << player->getClientID() << ", name: " << player->getName() << ")" << std::endl;
     149        COUT(3) << "player left level (id: " << player->getClientID() << ", name: " << player->getName() << ')' << std::endl;
    150150        player->setGametype(0);
    151151    }
  • code/trunk/src/orxonox/LevelManager.cc

    r6021 r6417  
    3030
    3131#include <map>
    32 #include <OgreResourceGroupManager.h>
    3332
    3433#include "core/CommandLineParser.h"
     
    3635#include "core/CoreIncludes.h"
    3736#include "core/Loader.h"
     37#include "core/Resource.h"
    3838#include "core/ScopedSingletonManager.h"
    3939#include "PlayerManager.h"
     
    4444    SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
    4545
    46     LevelManager* LevelManager::singletonPtr_s = 0;
    4746    ManageScopedSingleton(LevelManager, ScopeID::Root, false);
    4847
     
    6665    {
    6766        SetConfigValue(defaultLevelName_, "presentation_dm.oxw")
    68             .description("Sets the preselection of the level in the main menu.");
     67            .description("Sets the pre selection of the level in the main menu.");
    6968    }
    7069
     
    123122    }
    124123
    125     std::string LevelManager::getAvailableLevelListItem(unsigned int index) const
     124    const std::string& LevelManager::getAvailableLevelListItem(unsigned int index) const
    126125    {
    127126        if (index >= availableLevels_.size())
    128             return std::string();
     127            return BLANKSTRING;
    129128        else
    130129            return availableLevels_[index];
     
    133132    void LevelManager::compileAvailableLevelList()
    134133    {
    135         availableLevels_.clear();
    136 
    137         availableLevels_ = *Ogre::ResourceGroupManager::getSingleton().findResourceNames(
    138             Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "*.oxw");
    139 
     134        availableLevels_ = *Resource::findResourceNames("*.oxw");
    140135        for (std::vector<std::string>::iterator it = availableLevels_.begin(); it != availableLevels_.end();)
    141136            if (it->find("old/") == 0)
  • code/trunk/src/orxonox/LevelManager.h

    r5781 r6417  
    6060            const std::string& getDefaultLevel() const; //tolua_export
    6161            void compileAvailableLevelList(); //tolua_export
    62             std::string getAvailableLevelListItem(unsigned int index) const; //tolua_export
     62            const std::string& getAvailableLevelListItem(unsigned int index) const; //tolua_export
    6363
    6464            static LevelManager* getInstancePtr() { return singletonPtr_s; }
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r5929 r6417  
    152152    class AmbientSound;
    153153    class BaseSound;
     154    class SoundBuffer;
    154155    class SoundManager;
     156    class SoundStreamer;
    155157    class WorldSound;
    156158
     
    169171    class CameraPosition;
    170172    class ControllableEntity;
     173    class EffectContainer;
    171174    class ExplosionChunk;
    172175    class MobileEntity;
     
    176179    class TeamSpawnPoint;
    177180    class WorldEntity;
     181    class Rocket;
    178182    // worldentities, pawns
    179183    class Destroyer;
     
    209213typedef unsigned int ALuint;
    210214typedef int ALint;
     215typedef int ALenum;
    211216
    212217#endif /* _OrxonoxPrereqs_H__ */
  • code/trunk/src/orxonox/PlayerManager.cc

    r5966 r6417  
    3838namespace orxonox
    3939{
    40     PlayerManager* PlayerManager::singletonPtr_s = 0;
    4140    ManageScopedSingleton(PlayerManager, ScopeID::Root, false);
    4241
     
    9190        }
    9291    }
    93    
     92
    9493    void PlayerManager::disconnectAllClients()
    9594    {
  • code/trunk/src/orxonox/Radar.cc

    r5929 r6417  
    4040#include "core/ObjectList.h"
    4141#include "interfaces/RadarListener.h"
     42#include "controllers/HumanController.h"
     43#include "worldentities/pawns/Pawn.h"
    4244
    4345namespace orxonox
     
    4547
    4648    Radar::Radar()
    47         : focus_(0)
     49        : itFocus_(0)
     50        , focus_(0)
    4851        , objectTypeCounter_(0)
    4952    {
     
    8285    }
    8386
    84     RadarViewable::Shape Radar::addObjectDescription(const std::string name)
     87    RadarViewable::Shape Radar::addObjectDescription(const std::string& name)
    8588    {
    8689        std::map<std::string, RadarViewable::Shape>::iterator it = this->objectTypes_.find(name);
     
    118121    void Radar::cycleFocus()
    119122    {
    120         if (ObjectList<RadarViewable>::begin() == 0)
     123        if (ObjectList<RadarViewable>::begin() == ObjectList<RadarViewable>::end())
    121124        {
    122125            // list is empty
     
    124127            this->focus_ = 0;
    125128        }
    126 /*
    127         else if (this->owner_)
     129
     130        else if (HumanController::getLocalControllerEntityAsPawn())
    128131        {
    129             Vector3 localPosition = this->owner_->getPosition();
     132            Vector3 localPosition = HumanController::getLocalControllerEntityAsPawn()->getWorldPosition();
    130133            Vector3 targetPosition = localPosition;
    131             if (*(this->itFocus_))
     134            if (this->itFocus_ && *(this->itFocus_))
    132135                targetPosition = this->itFocus_->getRVWorldPosition();
    133136
    134             // find the closed object further away than targetPosition
     137            // find the closest object further away than targetPosition
    135138            float currentDistance = localPosition.squaredDistance(targetPosition);
    136139            float nextDistance = FLT_MAX;
     
    140143            for (ObjectList<RadarViewable>::iterator it = ObjectList<RadarViewable>::begin(); it; ++it)
    141144            {
    142                 if (*it == static_cast<RadarViewable*>(this)->owner_)
     145                if (*it == static_cast<RadarViewable*>(HumanController::getLocalControllerEntityAsPawn()))
    143146                    continue;
    144147
     
    167170            }
    168171        }
    169 */
    170172    }
    171173
  • code/trunk/src/orxonox/Radar.h

    r5929 r6417  
    5555
    5656        const RadarViewable* getFocus();
    57         RadarViewable::Shape addObjectDescription(const std::string name);
     57        RadarViewable::Shape addObjectDescription(const std::string& name);
    5858
    5959        void listObjects() const;
  • code/trunk/src/orxonox/Scene.cc

    r6064 r6417  
    5858        this->setScene(SmartPtr<Scene>(this, false), OBJECTID_UNKNOWN);
    5959        this->bShadows_ = true;
     60        this->soundReferenceDistance_ = 20.0;
    6061
    6162        if (GameMode::showsGraphics())
     
    113114        XMLPortParam(Scene, "ambientlight", setAmbientLight, getAmbientLight, xmlelement, mode).defaultValues(ColourValue(0.2f, 0.2f, 0.2f, 1.0f));
    114115        XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true);
     116        XMLPortParam(Scene, "soundReferenceDistance", setSoundReferenceDistance, getSoundReferenceDistance, xmlelement, mode);
    115117
    116118        XMLPortParam(Scene, "gravity", setGravity, getGravity, xmlelement, mode);
     
    334336    {
    335337        // get the WorldEntity pointers
    336         WorldEntity* object0 = static_cast<WorldEntity*>(colObj0->getUserPointer());
    337         assert(orxonox_cast<WorldEntity*>(object0));
    338         WorldEntity* object1 = static_cast<WorldEntity*>(colObj1->getUserPointer());
    339         assert(orxonox_cast<WorldEntity*>(object1));
     338        SmartPtr<WorldEntity> object0 = static_cast<WorldEntity*>(colObj0->getUserPointer());
     339        SmartPtr<WorldEntity> object1 = static_cast<WorldEntity*>(colObj1->getUserPointer());
    340340
    341341        // false means that bullet will assume we didn't modify the contact
  • code/trunk/src/orxonox/Scene.h

    r5929 r6417  
    7171                { return this->bShadows_; }
    7272
     73            inline void setSoundReferenceDistance(float distance)
     74                { this->soundReferenceDistance_ = distance; }
     75            inline float getSoundReferenceDistance() const
     76                { return this->soundReferenceDistance_; }
     77
    7378            inline Radar* getRadar()
    7479                { return this->radar_; }
    75            
     80
    7681            inline virtual uint32_t getSceneID() const { return this->getObjectID(); }
    7782
     
    96101            std::list<BaseObject*>   objects_;
    97102            bool                     bShadows_;
     103            float                    soundReferenceDistance_;
    98104            Radar*                   radar_;
    99105
  • code/trunk/src/orxonox/Test.cc

    r6084 r6417  
    3838    CreateFactory ( Test );
    3939 
    40   SetConsoleCommand(Test, printV1, true).accessLevel(AccessLevel::User);
    41   SetConsoleCommand(Test, printV2, true).accessLevel(AccessLevel::User);
    42   SetConsoleCommand(Test, printV3, true).accessLevel(AccessLevel::User);
    43   SetConsoleCommand(Test, printV4, true).accessLevel(AccessLevel::User);
    44   SetConsoleCommand(Test, call, true).accessLevel(AccessLevel::User);
    45   SetConsoleCommand(Test, call2, true).accessLevel(AccessLevel::User);
     40    SetConsoleCommand(Test, printV1, true).accessLevel(AccessLevel::User);
     41    SetConsoleCommand(Test, printV2, true).accessLevel(AccessLevel::User);
     42    SetConsoleCommand(Test, printV3, true).accessLevel(AccessLevel::User);
     43    SetConsoleCommand(Test, printV4, true).accessLevel(AccessLevel::User);
     44    SetConsoleCommand(Test, call, true).accessLevel(AccessLevel::User);
     45    SetConsoleCommand(Test, call2, true).accessLevel(AccessLevel::User);
    4646 
    4747 
     
    5050//   NetworkFunctionBase* NETWORK_FUNCTION_TEST_C = new NetworkFunctionStatic( createFunctor(&Test::printV1), "bla", NETWORK_FUNCTION_POINTER );
    5151 
    52   registerStaticNetworkFunction( &Test::printV1 );
    53   registerMemberNetworkFunction( Test, checkU1 );
    54   registerMemberNetworkFunction( Test, printBlaBla );
     52    registerStaticNetworkFunction( &Test::printV1 );
     53    registerMemberNetworkFunction( Test, checkU1 );
     54    registerMemberNetworkFunction( Test, printBlaBla );
    5555 
    56   Test* Test::instance_ = 0;
     56    Test* Test::instance_ = 0;
    5757
    5858    Test::Test(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
    5959    {
    60     assert(instance_==0);
    61     instance_=this;
     60        assert(instance_==0);
     61        instance_=this;
    6262        RegisterObject ( Test );
    63     setConfigValues();
    64     registerVariables();
     63        setConfigValues();
     64        registerVariables();
    6565        setSyncMode(0x3);
     66        this->pointer_ = 0;
    6667    }
    6768
    6869    Test::~Test()
    6970    {
    70     instance_=0;
     71        instance_=0;
    7172    }
    7273
     
    7475    {
    7576        SetConfigValue ( u1, 1 )/*.callback ( this, &Test::checkV1 )*/;
    76     SetConfigValue ( u2, 2 )/*.callback ( this, &Test::checkV2 )*/;
    77     SetConfigValue ( u3, 3 )/*.callback ( this, &Test::checkV3 )*/;
    78     SetConfigValue ( u4, 4 )/*.callback ( this, &Test::checkV4 )*/;
     77        SetConfigValue ( u2, 2 )/*.callback ( this, &Test::checkV2 )*/;
     78        SetConfigValue ( u3, 3 )/*.callback ( this, &Test::checkV3 )*/;
     79        SetConfigValue ( u4, 4 )/*.callback ( this, &Test::checkV4 )*/;
    7980   
    80     SetConfigValue ( s1, 1 )/*.callback ( this, &Test::checkV1 )*/;
    81     SetConfigValue ( s2, 2 )/*.callback ( this, &Test::checkV2 )*/;
    82     SetConfigValue ( s3, 3 )/*.callback ( this, &Test::checkV3 )*/;
    83     SetConfigValue ( s4, 4 )/*.callback ( this, &Test::checkV4 )*/;
     81        SetConfigValue ( s1, 1 )/*.callback ( this, &Test::checkV1 )*/;
     82        SetConfigValue ( s2, 2 )/*.callback ( this, &Test::checkV2 )*/;
     83        SetConfigValue ( s3, 3 )/*.callback ( this, &Test::checkV3 )*/;
     84        SetConfigValue ( s4, 4 )/*.callback ( this, &Test::checkV4 )*/;
    8485    }
    8586
    8687
    87   void Test::registerVariables()
    88   {
    89     registerVariable ( u1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
    90     registerVariable ( u2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkU2 ));
    91     registerVariable ( u3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
    92     registerVariable ( u4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
     88    void Test::registerVariables()
     89    {
     90        registerVariable ( u1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
     91        registerVariable ( u2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkU2 ));
     92        registerVariable ( u3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
     93        registerVariable ( u4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
    9394   
    94     registerVariable ( s1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
    95     registerVariable ( s2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkS2 ));
    96     registerVariable ( s3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
    97     registerVariable ( s4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
    98   }
     95        registerVariable ( s1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
     96        registerVariable ( s2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkS2 ));
     97        registerVariable ( s3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
     98        registerVariable ( s4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
     99   
     100        registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) );
     101    }
    99102 
    100103  void Test::call(unsigned int clientID)
    101   {
    102     callStaticNetworkFunction( &Test::printV1, clientID );
    103     callStaticNetworkFunction( &Test::printV1, clientID );
    104   }
     104    {
     105        callStaticNetworkFunction( &Test::printV1, clientID );
     106        callStaticNetworkFunction( &Test::printV1, clientID );
     107    }
    105108 
    106   void Test::call2(unsigned int clientID, std::string s1, std::string s2, std::string s3, std::string s4)
    107   {
    108     callMemberNetworkFunction( Test, printBlaBla, this->getObjectID(), clientID, s1, s2, s3, s4, s4 );
    109   }
     109    void Test::call2(unsigned int clientID, std::string s1, std::string s2, std::string s3, std::string s4)
     110    {
     111        callMemberNetworkFunction( Test, printBlaBla, this->getObjectID(), clientID, s1, s2, s3, s4, s4 );
     112    }
    110113 
    111   void Test::tick(float dt)
    112   {
    113 //     std::string str1 = "blub";
    114 //     //MultiType mt1(std::string("blub"));
    115 //     MultiType mt1(str1);
    116 //     uint8_t* mem = new uint8_t[mt1.getNetworkSize()];
    117 //     uint8_t* temp = mem;
    118 //     mt1.exportData( temp );
    119 //     assert( temp-mem == mt1.getNetworkSize() );
    120 //     MultiType mt2;
    121 //     temp = mem;
    122 //     mt2.importData( temp );
    123 //     assert( temp-mem == mt1.getNetworkSize() );
    124 //     COUT(0) << mt2 << endl;
    125     if(!Core::isMaster())
    126       call2(0, "bal", "a", "n", "ce");
    127 //       callMemberNetworkFunction( Test, checkU1, this->getObjectID(), 0 );
    128   }
    129  
    130   void Test::printBlaBla(std::string s1, std::string s2, std::string s3, std::string s4, std::string s5)
    131   {
    132     COUT(0) << s1 << s2 << s3 << s4 << s5 << endl;
    133   }
    134  
    135   void Test::checkU1(){ COUT(1) << "U1 changed: " << u1 << std::endl; }
    136   void Test::checkU2(){ COUT(1) << "U2 changed: " << u2 << std::endl; }
    137   void Test::checkU3(){ COUT(1) << "U3 changed: " << u3 << std::endl; }
    138   void Test::checkU4(){ COUT(1) << "U4 changed: " << u4 << std::endl; }
     114    void Test::tick(float dt)
     115    {
     116    //     std::string str1 = "blub";
     117    //     //MultiType mt1(std::string("blub"));
     118    //     MultiType mt1(str1);
     119    //     uint8_t* mem = new uint8_t[mt1.getNetworkSize()];
     120    //     uint8_t* temp = mem;
     121    //     mt1.exportData( temp );
     122    //     assert( temp-mem == mt1.getNetworkSize() );
     123    //     MultiType mt2;
     124    //     temp = mem;
     125    //     mt2.importData( temp );
     126    //     assert( temp-mem == mt1.getNetworkSize() );
     127    //     COUT(0) << mt2 << endl;
     128    //     if(!Core::isMaster())
     129    //       call2(0, "bal", "a", "n", "ce");
     130    //       callMemberNetworkFunction( Test, checkU1, this->getObjectID(), 0 );
     131    }
     132   
     133    void Test::printBlaBla(std::string s1, std::string s2, std::string s3, std::string s4, std::string s5)
     134    {
     135        COUT(0) << s1 << s2 << s3 << s4 << s5 << endl;
     136    }
     137   
     138    void Test::checkU1(){ COUT(1) << "U1 changed: " << u1 << std::endl; }
     139    void Test::checkU2(){ COUT(1) << "U2 changed: " << u2 << std::endl; }
     140    void Test::checkU3(){ COUT(1) << "U3 changed: " << u3 << std::endl; }
     141    void Test::checkU4(){ COUT(1) << "U4 changed: " << u4 << std::endl; }
    139142
    140   void Test::checkS1(){ COUT(1) << "S1 changed: " << s1 << std::endl; }
    141   void Test::checkS2(){ COUT(1) << "S2 changed: " << s2 << std::endl; }
    142   void Test::checkS3(){ COUT(1) << "S3 changed: " << s3 << std::endl; }
    143   void Test::checkS4(){ COUT(1) << "S4 changed: " << s4 << std::endl; }
     143    void Test::checkS1(){ COUT(1) << "S1 changed: " << s1 << std::endl; }
     144    void Test::checkS2(){ COUT(1) << "S2 changed: " << s2 << std::endl; }
     145    void Test::checkS3(){ COUT(1) << "S3 changed: " << s3 << std::endl; }
     146    void Test::checkS4(){ COUT(1) << "S4 changed: " << s4 << std::endl; }
     147   
     148    void Test::printPointer(){ CCOUT(1) << "pointer: " << this->pointer_ << endl; }
    144149
    145150}
  • code/trunk/src/orxonox/Test.h

    r5781 r6417  
    7676      void checkS4();
    7777
     78      void printPointer();
     79
    7880      static void printV1(){ instance_->checkU1(); }
    7981      static void printV2(){ instance_->checkU2(); }
     
    9496      TYPE s4;
    9597
     98      Test* pointer_;
     99
    96100      static Test* instance_;
    97101  };
  • code/trunk/src/orxonox/controllers/ArtificialController.cc

    r5929 r6417  
    4646        this->bHasTargetPosition_ = false;
    4747        this->targetPosition_ = Vector3::ZERO;
    48        
     48
    4949        this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
    5050    }
     
    143143        this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getPosition(), hardcoded_projectile_speed, this->target_->getPosition(), this->target_->getVelocity());
    144144        this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
     145
     146        Pawn* pawn = dynamic_cast<Pawn*>(this->getControllableEntity());
     147        if (pawn)
     148            pawn->setAimPosition(this->targetPosition_);
    145149    }
    146150
  • code/trunk/src/orxonox/controllers/ArtificialController.h

    r5929 r6417  
    4242            ArtificialController(BaseObject* creator);
    4343            virtual ~ArtificialController();
    44            
     44
    4545            void abandonTarget(Pawn* target);
    4646
  • code/trunk/src/orxonox/controllers/CMakeLists.txt

    r5781 r6417  
    22  Controller.cc
    33  HumanController.cc
     4  NewHumanController.cc
    45  ArtificialController.cc
    56  AIController.cc
  • code/trunk/src/orxonox/controllers/Controller.cc

    r5781 r6417  
    2929#include "Controller.h"
    3030#include "core/CoreIncludes.h"
     31#include "worldentities/ControllableEntity.h"
    3132
    3233namespace orxonox
     
    4041        this->player_ = 0;
    4142        this->controllableEntity_ = 0;
     43        this->bGodMode_ = false;
    4244    }
    4345
  • code/trunk/src/orxonox/controllers/Controller.h

    r5781 r6417  
    3737    class _OrxonoxExport Controller : public BaseObject
    3838    {
     39        // set friend classes to access setControllableEntity
     40        friend class PlayerInfo;
     41        friend class ControllableEntity;
     42
    3943        public:
    4044            Controller(BaseObject* creator);
     
    4650                { return this->player_; }
    4751
     52            virtual inline void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) {};
     53
     54            void setGodMode( bool mode ){ this->bGodMode_ = mode; }
     55            bool getGodMode(){ return this->bGodMode_; }
     56
     57            inline ControllableEntity* getControllableEntity() const
     58                { return this->controllableEntity_; }
     59            virtual void changedControllableEntity() {}
     60
     61        protected:
     62            // don't use this directly, use getPlayer()->startControl(entity) (unless you know exactly what you do)
    4863            inline void setControllableEntity(ControllableEntity* entity)
    4964            {
     
    5469                }
    5570            }
    56             inline ControllableEntity* getControllableEntity() const
    57                 { return this->controllableEntity_; }
    58             virtual void changedControllableEntity() {}
    5971
    6072        protected:
    6173            PlayerInfo* player_;
    6274            ControllableEntity* controllableEntity_;
     75        private:
     76            bool bGodMode_;
    6377    };
    6478}
  • code/trunk/src/orxonox/controllers/HumanController.cc

    r5929 r6417  
    3636#include "infos/PlayerInfo.h"
    3737#include "overlays/Map.h"
    38 #include "graphics/Camera.h"
    39 #include "sound/SoundManager.h"
    4038#include "Radar.h"
    4139#include "Scene.h"
     
    5654    SetConsoleCommand(HumanController, mouseLook,     true);
    5755    SetConsoleCommand(HumanController, suicide,       true);
     56    SetConsoleCommand(HumanController, toggleGodMode, true);
    5857    SetConsoleCommand(HumanController, addBots,       true).defaultValues(1);
    5958    SetConsoleCommand(HumanController, killBots,      true).defaultValues(0);
     
    7170        RegisterObject(HumanController);
    7271
     72        controlPaused_ = false;
     73
    7374        HumanController::localController_s = this;
    7475    }
     
    8384        if (GameMode::playsSound() && HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    8485        {
    85             // Update sound listener
    8686            Camera* camera = HumanController::localController_s->controllableEntity_->getCamera();
    87             if (camera)
    88             {
    89                 SoundManager::getInstance().setListenerPosition(camera->getWorldPosition());
    90                 SoundManager::getInstance().setListenerOrientation(camera->getWorldOrientation());
    91             }
    92             else
     87            if (!camera)
    9388                COUT(3) << "HumanController, Warning: Using a ControllableEntity without Camera" << std::endl;
    9489        }
     
    9792    void HumanController::moveFrontBack(const Vector2& value)
    9893    {
     94        if (HumanController::localController_s)
     95            HumanController::localController_s->frontback(value);
     96    }
     97
     98    void HumanController::frontback(const Vector2& value)
     99    {
    99100        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    100101            HumanController::localController_s->controllableEntity_->moveFrontBack(value);
     
    113114    }
    114115
    115     void HumanController::rotateYaw(const Vector2& value)
     116    void HumanController::yaw(const Vector2& value)
    116117    {
    117118        //Hack to enable mouselook in map
     
    125126    }
    126127
    127     void HumanController::rotatePitch(const Vector2& value)
     128    void HumanController::pitch(const Vector2& value)
    128129    {
    129130        //Hack to enable mouselook in map
     
    137138    }
    138139
     140    void HumanController::rotateYaw(const Vector2& value)
     141    {
     142        if (HumanController::localController_s)
     143            HumanController::localController_s->yaw(value);
     144    }
     145
     146    void HumanController::rotatePitch(const Vector2& value)
     147    {
     148        if (HumanController::localController_s)
     149            HumanController::localController_s->pitch(value);
     150    }
     151
    139152    void HumanController::rotateRoll(const Vector2& value)
    140153    {
     
    144157
    145158    void HumanController::fire(unsigned int firemode)
     159    {
     160        if (HumanController::localController_s)
     161            HumanController::localController_s->doFire(firemode);
     162    }
     163
     164    void HumanController::doFire(unsigned int firemode)
    146165    {
    147166        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     
    191210    }
    192211
     212    void HumanController::toggleGodMode()
     213    {
     214        HumanController::getLocalControllerSingleton()->setGodMode( !HumanController::getLocalControllerSingleton()->getGodMode() );
     215    }
     216
    193217    void HumanController::useItem()
    194218    {
     
    234258            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus();
    235259    }
     260
     261    void HumanController::pauseControl()
     262    {
     263        if (HumanController::localController_s)
     264            HumanController::localController_s->doPauseControl();
     265    }
     266
     267    void HumanController::resumeControl()
     268    {
     269        if (HumanController::localController_s)
     270            HumanController::localController_s->doResumeControl();
     271    }
    236272}
  • code/trunk/src/orxonox/controllers/HumanController.h

    r5929 r6417  
    3535#include "Controller.h"
    3636
     37// tolua_begin
    3738namespace orxonox
    3839{
    39     class _OrxonoxExport HumanController : public Controller, public Tickable
    40     {
     40    class _OrxonoxExport HumanController
     41// tolua_end
     42        : public Controller, public Tickable
     43    { // tolua_export
    4144        public:
    4245            HumanController(BaseObject* creator);
     
    5356            static void rotateRoll(const Vector2& value);
    5457
     58            virtual void frontback(const Vector2& value);
     59            virtual void yaw(const Vector2& value);
     60            virtual void pitch(const Vector2& value);
     61
    5562            static void fire(unsigned int firemode);
     63            virtual void doFire(unsigned int firemode);
    5664            static void reload();
    5765
     
    6674
    6775            static void suicide();
     76            static void toggleGodMode();
    6877
    6978            static void addBots(unsigned int amount);
    7079            static void killBots(unsigned int amount = 0);
     80
     81            static void pauseControl(); // tolua_export
     82            static void resumeControl(); // tolua_export
     83            virtual void doPauseControl() {};
     84            virtual void doResumeControl() {};
    7185
    7286            static inline HumanController* getLocalControllerSingleton()
     
    7690            friend class Map;
    7791
    78         private:
     92        protected:
    7993            static HumanController* localController_s;
    80     };
    81 }
     94            bool controlPaused_;
     95    }; // tolua_export
     96} // tolua_export
    8297
    8398#endif /* _HumanController_H__ */
  • code/trunk/src/orxonox/gamestates/GSGraphics.cc

    r5929 r6417  
    6464    void GSGraphics::activate()
    6565    {
    66         // add console command to toggle GUI
    67         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI"));
     66
    6867    }
    6968
     
    7877    }
    7978
    80     /**
    81     @brief
    82         Toggles the visibility of the current GUI
    83 
    84         This function just executes a Lua function in the main script of the GUI by accessing the GUIManager.
    85         For more details on this function check out the Lua code.
    86     */
    87     void GSGraphics::toggleGUI()
    88     {
    89         GUIManager::getInstance().executeCode("toggleGUI()");
    90     }
    91 
    9279    void GSGraphics::update(const Clock& time)
    9380    {
  • code/trunk/src/orxonox/gamestates/GSGraphics.h

    r5929 r6417  
    5757        void update(const Clock& time);
    5858
    59         void toggleGUI();
    60 
    6159    private:
    6260    };
  • code/trunk/src/orxonox/gamestates/GSLevel.cc

    r5966 r6417  
    5656        , guiKeysOnlyInputState_(0)
    5757        , startFile_(0)
     58        , bShowIngameGUI_(false)
    5859    {
    5960    }
     
    7879            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
    7980            guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
    80 
    81             CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSLevel::showIngameGUI, this), "showIngameGUI"));
    8281        }
    8382
     
    9190            // level is loaded: we can start capturing the input
    9291            InputManager::getInstance().enterState("game");
    93            
     92
    9493            // connect the HumanPlayer to the game
    9594            PlayerManager::getInstance().clientConnected(0);
    96         }
    97     }
    98 
    99     void GSLevel::showIngameGUI(bool show)
    100     {
    101         if (show)
    102         {
    103             GUIManager::getInstance().showGUI("inGameTest");
    104             GUIManager::getInstance().executeCode("showCursor()");
    105             InputManager::getInstance().enterState("guiMouseOnly");
    106         }
    107         else
    108         {
    109             GUIManager::getInstance().executeCode("hideGUI(\"inGameTest\")");
    110             GUIManager::getInstance().executeCode("hideCursor()");
    111             InputManager::getInstance().leaveState("guiMouseOnly");
    11295        }
    11396    }
     
    122105            InputManager::getInstance().leaveState("game");
    123106        }
    124        
     107
    125108        // disconnect all HumanPlayers
    126109        PlayerManager::getInstance().disconnectAllClients();
     
    152135        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
    153136            this->staticObjects_.insert(*it);
    154        
     137
    155138        // call the loader
    156139        COUT(0) << "Loading level..." << std::endl;
     
    171154            if (find == this->staticObjects_.end())
    172155            {
    173                 COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << ")" << std::endl;
     156                COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << ')' << std::endl;
    174157            }
    175158        }
  • code/trunk/src/orxonox/gamestates/GSLevel.h

    r5929 r6417  
    5252        void loadLevel();
    5353        void unloadLevel();
    54         void showIngameGUI(bool show);
    5554
    5655        InputState*              gameInputState_;          //!< input state for normal ingame playing
     
    6059        XMLFile* startFile_;
    6160        std::set<BaseObject*> staticObjects_;
     61        bool bShowIngameGUI_;
    6262    };
    6363}
  • code/trunk/src/orxonox/gamestates/GSMainMenu.cc

    r6105 r6417  
    3636#include "core/Game.h"
    3737#include "core/ConsoleCommand.h"
     38#include "core/ConfigValueIncludes.h"
     39#include "core/CoreIncludes.h"
    3840#include "core/GraphicsManager.h"
    3941#include "core/GUIManager.h"
     
    4951        , inputState_(0)
    5052    {
     53        RegisterRootObject(GSMainMenu);
    5154        inputState_ = InputManager::getInstance().createInputState("mainMenu");
    5255        inputState_->setMouseMode(MouseMode::Nonexclusive);
     
    6467            // Load sound
    6568            this->ambient_ = new AmbientSound(0);
    66             this->ambient_->setSource("ambient/mainmenu.wav");
     69            this->ambient_->setSyncMode(0x0);
    6770        }
    6871    }
     
    7174    {
    7275        if (GameMode::playsSound())
    73             delete this->ambient_;
     76            this->ambient_->destroy();
    7477
    7578        InputManager::getInstance().destroyState("mainMenu");
     
    8285    {
    8386        // show main menu
    84         GUIManager::getInstance().showGUI("MainMenu");
     87        GUIManager::getInstance().showGUI("MainMenu", true, GraphicsManager::getInstance().isFullScreen());
    8588        GUIManager::getInstance().setCamera(this->camera_);
     89        GUIManager::getInstance().setBackground("MainMenuBackground");
     90//         GUIManager::getInstance().setBackground("");
    8691        GraphicsManager::getInstance().setCamera(this->camera_);
    8792
     
    9297        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu), "startMainMenu"));
    9398
     99        // create command to change sound path
     100        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::setMainMenuSoundPath, this), "setMMSoundPath"));
     101
    94102        KeyBinderManager::getInstance().setToDefault();
    95103        InputManager::getInstance().enterState("mainMenu");
    96104
     105        this->setConfigValues();
     106
    97107        if (GameMode::playsSound())
    98108        {
    99             this->ambient_->setLoop(true);
    100             this->ambient_->play();
     109            this->ambient_->setLooping(true);
     110            this->ambient_->play(); // works without source
    101111        }
    102112    }
     
    112122
    113123        GUIManager::getInstance().setCamera(0);
     124        GUIManager::getInstance().setBackground("");
     125        GUIManager::hideGUI("MainMenu");
    114126        GraphicsManager::getInstance().setCamera(0);
    115127    }
     
    117129    void GSMainMenu::update(const Clock& time)
    118130    {
     131    }
     132
     133    void GSMainMenu::setConfigValues()
     134    {
     135        SetConfigValue(soundPathMain_, "mainmenu.ogg")
     136            .description("Contains the path to the main menu sound file.")
     137            .callback(this, &GSMainMenu::reloadSound);
     138    }
     139
     140    void GSMainMenu::reloadSound()
     141    {
     142        if (GameMode::playsSound())
     143        {
     144            this->ambient_->setAmbientSource(soundPathMain_);
     145        }
     146    }
     147
     148    const std::string& GSMainMenu::getMainMenuSoundPath()
     149    {
     150        return soundPathMain_;
     151    }
     152
     153    void GSMainMenu::setMainMenuSoundPath(const std::string& path)
     154    {
     155        ModifyConfigValue(soundPathMain_, set, path);
    119156    }
    120157
  • code/trunk/src/orxonox/gamestates/GSMainMenu.h

    r5929 r6417  
    3434#include "util/OgreForwardRefs.h"
    3535#include "core/GameState.h"
     36#include "core/OrxonoxClass.h"
    3637
    3738namespace orxonox
    3839{
    39     class _OrxonoxExport GSMainMenu : public GameState
     40    class _OrxonoxExport GSMainMenu : public GameState, public OrxonoxClass
    4041    {
    4142    public:
     
    4647        void deactivate();
    4748        void update(const Clock& time);
     49
     50        void setConfigValues();
     51        void reloadSound();
     52        const std::string& getMainMenuSoundPath();
     53        void setMainMenuSoundPath(const std::string& path);
    4854
    4955        static void startStandalone();
     
    6167        // ambient sound for the main menu
    6268        AmbientSound*     ambient_;
     69        std::string       soundPathMain_;
    6370    };
    6471}
  • code/trunk/src/orxonox/gamestates/GSRoot.cc

    r6105 r6417  
    3030
    3131#include "util/Clock.h"
     32#include "core/BaseObject.h"
    3233#include "core/ConsoleCommand.h"
    3334#include "core/Game.h"
     
    4546    GSRoot::GSRoot(const GameStateInfo& info)
    4647        : GameState(info)
    47         , timeFactor_(1.0f)
    4848        , bPaused_(false)
    4949        , timeFactorPauseBackup_(1.0f)
     
    5555        NetworkFunctionBase::destroyAllNetworkFunctions();
    5656    }
    57    
     57
    5858    void GSRoot::printObjects()
    5959    {
    6060        unsigned int nr=0;
    61         for(ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it; ++it){
    62             if( dynamic_cast<Synchronisable*>(*it) )
     61        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it; ++it)
     62        {
     63            if (dynamic_cast<Synchronisable*>(*it))
    6364                COUT(0) << "object: " << it->getIdentifier()->getName() << " id: " << dynamic_cast<Synchronisable*>(*it)->getObjectID() << std::endl;
    6465            else
     
    6768        }
    6869        COUT(0) << "currently got " << nr << " objects" << std::endl;
    69    
    7070    }
    7171
     
    7373    {
    7474        // reset game speed to normal
    75         this->timeFactor_ = 1.0f;
     75        TimeFactorListener::setTimeFactor(1.0f);
    7676
    7777        // time factor console command
     
    9191    {
    9292        for (ObjectList<Timer>::iterator it = ObjectList<Timer>::begin(); it; )
    93             (it++)->tick(time);
     93        {
     94            Timer* object = *it;
     95            ++it;
     96            object->tick(time);
     97        }
    9498
    9599        /*** HACK *** HACK ***/
     
    101105            leveldt = 0.0f;
    102106        }
     107        float realdt = leveldt * TimeFactorListener::getTimeFactor();
    103108        for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; )
    104             (it++)->tick(leveldt * this->timeFactor_);
     109        {
     110            Tickable* object = *it;
     111            ++it;
     112            object->tick(realdt);
     113        }
    105114        /*** HACK *** HACK ***/
    106115    }
     
    119128            if (!this->bPaused_)
    120129            {
    121                 TimeFactorListener::timefactor_s = factor;
    122 
    123                 for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
    124                     it->changedTimeFactor(factor, this->timeFactor_);
    125 
    126                 this->timeFactor_ = factor;
     130                TimeFactorListener::setTimeFactor(factor);
    127131            }
    128132            else
     
    137141            if (!this->bPaused_)
    138142            {
    139                 this->timeFactorPauseBackup_ = this->timeFactor_;
     143                this->timeFactorPauseBackup_ = TimeFactorListener::getTimeFactor();
    140144                this->setTimeFactor(0.0f);
    141145                this->bPaused_ = true;
     
    148152        }
    149153    }
     154
     155    float GSRoot::getTimeFactor()
     156    {
     157        return TimeFactorListener::getTimeFactor();
     158    }
    150159}
  • code/trunk/src/orxonox/gamestates/GSRoot.h

    r5929 r6417  
    5151        void setTimeFactor(float factor);
    5252        void pause();
    53         float getTimeFactor() { return this->timeFactor_; }
     53        float getTimeFactor();
    5454
    5555    private:
    56         float                 timeFactor_;              //!< A factor that sets the gamespeed. 1 is normal.
    5756        bool                  bPaused_;
    5857        float                 timeFactorPauseBackup_;
  • code/trunk/src/orxonox/gametypes/Asteroids.cc

    r5929 r6417  
    7272        Gametype::start();
    7373
    74         std::string message = "The match has started! Reach the first chekpoint within 15 seconds! But be aware, there may be pirates around...";
     74        std::string message("The match has started! Reach the first chekpoint within 15 seconds! But be aware, there may be pirates around...");
    7575        COUT(0) << message << std::endl;
    7676        Host::Broadcast(message);
     
    8181        Gametype::end();
    8282
    83         std::string message = "The match has ended.";
     83        std::string message("The match has ended.");
    8484        COUT(0) << message << std::endl;
    8585        Host::Broadcast(message);
  • code/trunk/src/orxonox/gametypes/Deathmatch.cc

    r5781 r6417  
    4747        Gametype::start();
    4848
    49         std::string message = "The match has started!";
     49        std::string message("The match has started!");
    5050        COUT(0) << message << std::endl;
    5151        Host::Broadcast(message);
     
    5656        Gametype::end();
    5757
    58         std::string message = "The match has ended.";
     58        std::string message("The match has ended.");
    5959        COUT(0) << message << std::endl;
    6060        Host::Broadcast(message);
     
    6565        Gametype::playerEntered(player);
    6666
    67         std::string message = player->getName() + " entered the game";
     67        const std::string& message = player->getName() + " entered the game";
    6868        COUT(0) << message << std::endl;
    6969        Host::Broadcast(message);
     
    7676        if (valid_player)
    7777        {
    78             std::string message = player->getName() + " left the game";
     78            const std::string& message = player->getName() + " left the game";
    7979            COUT(0) << message << std::endl;
    8080            Host::Broadcast(message);
     
    9090        if (valid_player)
    9191        {
    92             std::string message = player->getOldName() + " changed name to " + player->getName();
     92            const std::string& message = player->getOldName() + " changed name to " + player->getName();
    9393            COUT(0) << message << std::endl;
    9494            Host::Broadcast(message);
     
    126126        if (player)
    127127        {
    128             std::string message = player->getName() + " scores!";
     128            const std::string& message = player->getName() + " scores!";
    129129            COUT(0) << message << std::endl;
    130130            Host::Broadcast(message);
  • code/trunk/src/orxonox/gametypes/Gametype.cc

    r5929 r6417  
    5151    {
    5252        RegisterObject(Gametype);
    53        
     53
    5454        this->gtinfo_ = new GametypeInfo(creator);
    5555
     
    7171
    7272        // load the corresponding score board
    73         if (GameMode::showsGraphics() && this->scoreboardTemplate_ != "")
     73        if (GameMode::showsGraphics() && !this->scoreboardTemplate_.empty())
    7474        {
    7575            this->scoreboard_ = new OverlayGroup(this);
     
    7979        else
    8080            this->scoreboard_ = 0;
    81        
     81
    8282        /* HACK HACK HACK */
    8383        this->hackAddBots_ = createConsoleCommand( createFunctor(&Gametype::addBots, this), "hackAddBots");
     
    8787        /* HACK HACK HACK */
    8888    }
    89    
     89
    9090    Gametype::~Gametype()
    9191    {
  • code/trunk/src/orxonox/gametypes/Gametype.h

    r5929 r6417  
    184184            // Config Values
    185185            std::string scoreboardTemplate_;
    186            
     186
    187187            /* HACK HACK HACK */
    188188            ConsoleCommand* hackAddBots_;
  • code/trunk/src/orxonox/gametypes/TeamDeathmatch.cc

    r5929 r6417  
    6161        static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
    6262
    63         SetConfigValueVector(teamcolours_, defaultcolours);
     63        SetConfigValue(teamcolours_, defaultcolours);
    6464    }
    6565
  • code/trunk/src/orxonox/gametypes/UnderAttack.cc

    r5929 r6417  
    6969    {
    7070        this->end(); //end gametype
    71         std::string message = "Ship destroyed! Team 0 has won!";
     71        std::string message("Ship destroyed! Team 0 has won!");
    7272        COUT(0) << message << std::endl;
    7373        Host::Broadcast(message);
     
    152152                this->gameEnded_ = true;
    153153                this->end();
    154                 std::string message = "Time is up! Team 1 has won!";
     154                std::string message("Time is up! Team 1 has won!");
    155155                COUT(0) << message << std::endl;
    156156                Host::Broadcast(message);
     
    171171            if ( gameTime_ <= timesequence_ && gameTime_ > 0)
    172172            {
    173                 std::string message = multi_cast<std::string>(timesequence_) + " seconds left!";
     173                const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!";
    174174/*
    175175                COUT(0) << message << std::endl;
  • code/trunk/src/orxonox/graphics/Billboard.cc

    r5781 r6417  
    4242        RegisterObject(Billboard);
    4343
    44         this->material_ = "";
    4544        this->colour_ = ColourValue::White;
    4645//        this->rotation_ = 0;
     
    7675    void Billboard::changedMaterial()
    7776    {
    78         if (this->material_ == "")
     77        if (this->material_.empty())
    7978            return;
    8079
     
    9998        {
    10099/*
    101             if (this->getScene() && GameMode::showsGraphics() && (this->material_ != ""))
     100            if (this->getScene() && GameMode::showsGraphics() && !this->material_.empty())
    102101            {
    103102                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
  • code/trunk/src/orxonox/graphics/BlinkingBillboard.cc

    r5781 r6417  
    8181                this->setScale(this->amplitude_ * static_cast<float>(square(sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_))));
    8282            else
    83                 this->setScale(this->amplitude_ * static_cast<float>(sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_)));
     83                this->setScale(this->amplitude_ * static_cast<float>(fabs(sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_))));
    8484        }
    8585    }
  • code/trunk/src/orxonox/graphics/Camera.cc

    r5929 r6417  
    4242#include "Scene.h"
    4343#include "CameraManager.h"
     44#include "sound/SoundManager.h"
    4445
    4546namespace orxonox
     
    6162
    6263        this->camera_ = this->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
     64        this->camera_->setUserObject(this);
    6365        this->cameraNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode();
    6466        this->attachNode(this->cameraNode_);
     
    6870        this->bDrag_ = false;
    6971        this->nearClipDistance_ = 1;
     72        this->lastDtLagged_ = false;
    7073
    7174        this->setSyncMode(0x0);
     
    111114        {
    112115            // this stuff here may need some adjustments
    113             float coeff = std::min(1.0f, 15.0f * dt);
     116            float poscoeff = 15.0f * dt / this->getTimeFactor();
     117            float anglecoeff = 7.0f * dt / this->getTimeFactor();
     118            // Only clamp if fps rate is actually falling. Occasional high dts should
     119            // not be clamped to reducing lagging effects.
     120            if (poscoeff > 1.0f)
     121            {
     122                if (this->lastDtLagged_)
     123                    poscoeff = 1.0f;
     124                else
     125                    this->lastDtLagged_ = true;
     126            }
     127            else
     128                this->lastDtLagged_ = false;
     129
     130            if (anglecoeff > 1.0f)
     131            {
     132                if (this->lastDtLagged_)
     133                    anglecoeff = 1.0f;
     134                else
     135                    this->lastDtLagged_ = true;
     136            }
     137            else
     138                this->lastDtLagged_ = false;
    114139
    115140            Vector3 offset = this->getWorldPosition() - this->cameraNode_->_getDerivedPosition();
    116             this->cameraNode_->translate(coeff * offset);
     141            this->cameraNode_->translate(poscoeff * offset);
    117142
    118             this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->_getDerivedOrientation(), this->getWorldOrientation(), true));
    119             //this->cameraNode_->setOrientation(this->getWorldOrientation());
     143            this->cameraNode_->setOrientation(Quaternion::Slerp(anglecoeff, this->cameraNode_->_getDerivedOrientation(), this->getWorldOrientation(), true));
     144        }
     145
     146        // Update sound listener transformation
     147        if (GameMode::playsSound() && this->bHasFocus_)
     148        {
     149            SoundManager::getInstance().setListenerPosition(this->getWorldPosition());
     150            SoundManager::getInstance().setListenerOrientation(this->getWorldOrientation());
    120151        }
    121152    }
  • code/trunk/src/orxonox/graphics/Camera.h

    r5781 r6417  
    3434#include "util/OgreForwardRefs.h"
    3535#include "tools/interfaces/Tickable.h"
     36#include "tools/interfaces/TimeFactorListener.h"
    3637#include "worldentities/StaticEntity.h"
    3738
    3839namespace orxonox
    3940{
    40     class _OrxonoxExport Camera : public StaticEntity, public Tickable
     41    class _OrxonoxExport Camera : public StaticEntity, public Tickable, public TimeFactorListener
    4142    {
    4243        friend class CameraManager;
     
    5152            void requestFocus();
    5253            void releaseFocus();
     54
     55            inline Ogre::Camera* getOgreCamera()
     56               { return this->camera_; }
    5357
    5458            inline bool hasFocus()
     
    6973            bool             bHasFocus_;
    7074            bool             bDrag_;
     75            bool             lastDtLagged_;
    7176    };
    7277}
  • code/trunk/src/orxonox/infos/Bot.cc

    r5781 r6417  
    9494        static std::vector<std::string> defaultnames(names, names + sizeof(names) / sizeof(std::string));
    9595
    96         SetConfigValueVector(names_, defaultnames);
     96        SetConfigValue(names_, defaultnames);
    9797    }
    9898}
  • code/trunk/src/orxonox/infos/HumanPlayer.cc

    r5929 r6417  
    3535#include "network/Host.h"
    3636#include "controllers/HumanController.h"
     37#include "controllers/NewHumanController.h"
    3738#include "gametypes/Gametype.h"
    3839#include "overlays/OverlayGroup.h"
     
    5051
    5152        this->bHumanPlayer_ = true;
    52         this->defaultController_ = Class(HumanController);
     53        this->defaultController_ = Class(NewHumanController);
    5354
    5455        this->humanHud_ = 0;
     
    163164        if (this->isInitialized() && this->isLocalPlayer())
    164165        {
    165             if (this->getGametype() && this->getGametype()->getHUDTemplate() != "")
     166            if (this->getGametype() && !this->getGametype()->getHUDTemplate().empty())
    166167                this->setGametypeHUDTemplate(this->getGametype()->getHUDTemplate());
    167168            else
     
    178179        }
    179180
    180         if (this->isLocalPlayer() && this->humanHudTemplate_ != "" && GameMode::showsGraphics())
     181        if (this->isLocalPlayer() && !this->humanHudTemplate_.empty() && GameMode::showsGraphics())
    181182        {
    182183            this->humanHud_ = new OverlayGroup(this);
     
    194195        }
    195196
    196         if (this->isLocalPlayer() && this->gametypeHudTemplate_ != "")
     197        if (this->isLocalPlayer() && !this->gametypeHudTemplate_.empty())
    197198        {
    198199            this->gametypeHud_ = new OverlayGroup(this);
  • code/trunk/src/orxonox/infos/PlayerInfo.cc

    r5929 r6417  
    5050        this->controller_ = 0;
    5151        this->controllableEntity_ = 0;
    52         this->controllableEntityID_ = CLIENTID_UNKNOWN;
     52        this->controllableEntityID_ = OBJECTID_UNKNOWN;
     53        this->oldControllableEntity_ = 0;
    5354
    5455        this->gtinfo_ = 0;
     
    8081        registerVariable(this->name_,                 VariableDirection::ToClient, new NetworkCallback<PlayerInfo>(this, &PlayerInfo::changedName));
    8182        registerVariable(this->controllableEntityID_, VariableDirection::ToClient, new NetworkCallback<PlayerInfo>(this, &PlayerInfo::networkcallback_changedcontrollableentityID));
    82         registerVariable(this->bReadyToSpawn_,        VariableDirection::ToServer);
    8383        registerVariable(this->gtinfoID_,             VariableDirection::ToClient, new NetworkCallback<PlayerInfo>(this, &PlayerInfo::networkcallback_changedgtinfoID));
    8484    }
     
    139139        this->controller_->setPlayer(this);
    140140        if (this->controllableEntity_)
     141        {
    141142            this->controller_->setControllableEntity(this->controllableEntity_);
     143            this->controllableEntity_->setController(this->controller_);
     144        }
    142145        this->changedController();
    143146    }
     
    148151            return;
    149152
     153        if (this->oldControllableEntity_)
     154            this->stopTemporaryControl();
    150155        if (this->controllableEntity_)
    151156            this->stopControl();
     
    159164
    160165        if (this->controller_)
     166        {
    161167            this->controller_->setControllableEntity(entity);
     168            this->controllableEntity_->setController(this->controller_);
     169        }
     170
     171        this->changedControllableEntity();
     172    }
     173
     174    void PlayerInfo::startTemporaryControl(ControllableEntity* entity)
     175    {
     176        if (!entity)
     177            return;
     178
     179//         assert( this->temporaryControllableEntity_==0 );
     180
     181        this->oldControllableEntity_ = this->controllableEntity_;
     182        this->controllableEntity_ = entity;
     183        this->controllableEntityID_ = entity->getObjectID();
     184
     185        entity->setPlayer(this);
     186
     187        if (this->controller_)
     188            this->controller_->setControllableEntity(entity);
    162189
    163190        this->changedControllableEntity();
     
    166193    void PlayerInfo::stopControl()
    167194    {
     195        if ( this->oldControllableEntity_ )
     196            this->stopTemporaryControl();
     197
    168198        ControllableEntity* entity = this->controllableEntity_;
    169199
     
    171201            return;
    172202
     203        this->controllableEntity_->setController(0);
    173204        this->controllableEntity_ = 0;
    174205        this->controllableEntityID_ = OBJECTID_UNKNOWN;
     
    177208            this->controller_->setControllableEntity(0);
    178209
    179         entity->removePlayer();
     210        if ( GameMode::isMaster() )
     211            entity->removePlayer();
     212
     213        this->changedControllableEntity();
     214    }
     215
     216    void PlayerInfo::stopTemporaryControl()
     217    {
     218        ControllableEntity* entity = this->controllableEntity_;
     219
     220        assert( this->controllableEntity_ && this->oldControllableEntity_ );
     221        if( !entity || !this->oldControllableEntity_ )
     222            return;
     223
     224        this->controllableEntity_ = this->oldControllableEntity_;
     225        this->controllableEntityID_ = this->controllableEntity_->getObjectID();
     226        this->oldControllableEntity_ = 0;
     227
     228        if ( this->controllableEntity_ && this->controller_)
     229            this->controller_->setControllableEntity(this->controllableEntity_);
     230
     231        if ( GameMode::isMaster() )
     232            entity->removePlayer();
    180233
    181234        this->changedControllableEntity();
     
    196249    }
    197250
     251
    198252    void PlayerInfo::networkcallback_changedgtinfoID()
    199253    {
  • code/trunk/src/orxonox/infos/PlayerInfo.h

    r5929 r6417  
    6969            void startControl(ControllableEntity* entity);
    7070            void stopControl();
     71            void startTemporaryControl(ControllableEntity* entity);
     72            void stopTemporaryControl();
    7173
    7274            inline ControllableEntity* getControllableEntity() const
     
    9698            Controller* controller_;
    9799            ControllableEntity* controllableEntity_;
     100            ControllableEntity* oldControllableEntity_;
    98101            unsigned int controllableEntityID_;
    99102
  • code/trunk/src/orxonox/interfaces/RadarViewable.cc

    r5929 r6417  
    5151        , line_(NULL)
    5252        , LineNode_(NULL)
     53        , isHumanShip_(false)
     54        , bVisibility_(true)
    5355        , radarObjectCamouflage_(0.0f)
    5456        , radarObjectShape_(Dot)
     
    5658    {
    5759        RegisterRootObject(RadarViewable);
    58 
    59         this->bVisibility_ = true;
    60         this->isHumanShip_ = false;
    6160
    6261        this->uniqueId_=getUniqueNumberString();
     
    164163        if (!object)
    165164        {
    166             COUT(1) << "Assertation: Every RadarViewable has to be assigned a WorldEntity pointer!" << std::endl;
     165            COUT(1) << "Assertion: Every RadarViewable has to be assigned a WorldEntity pointer!" << std::endl;
    167166            assert(0);
    168167        }
  • code/trunk/src/orxonox/interfaces/Rewardable.h

    r5781 r6417  
    4343    @brief
    4444        Rewardable is an Interface, that can be implemented by any object to enable it to be given as reward to a player through QuestEffects. (With the AddReward effect.)
    45        
     45
    4646        It just needs to inherit form Rewardable, and implement the reward() method.
    4747    @author
  • code/trunk/src/orxonox/items/Engine.h

    r5929 r6417  
    106106            virtual const Vector3& getDirection() const;
    107107
    108             void loadSound(const std::string filename);
    109 
    110108        private:
    111109            void networkcallback_shipID();
  • code/trunk/src/orxonox/items/MultiStateEngine.cc

    r5929 r6417  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    2526 *      ...
     
    2930#include "MultiStateEngine.h"
    3031
     32extern "C" {
     33#include <lua.h>
     34}
     35
     36#include "util/Convert.h"
    3137#include "core/CoreIncludes.h"
    3238#include "core/GameMode.h"
     39#include "core/LuaState.h"
    3340#include "core/XMLPort.h"
     41#include "worldentities/EffectContainer.h"
    3442#include "worldentities/pawns/SpaceShip.h"
     43#include "sound/WorldSound.h"
    3544
    3645namespace orxonox
    3746{
    38     static const float FORWARD_EFFECT_VELOCITY_THRESHOLD = 20;
    39 
    40     static const unsigned char STATE_ACTIVE  = 1;
    41     static const unsigned char STATE_FORWARD = 2;
    42     static const unsigned char STATE_BOOST   = 4;
    43     static const unsigned char STATE_BRAKE   = 8;
     47    static const float FORWARD_EFFECT_VELOCITY_THRESHOLD = 0;
     48    static const float MAX_VELOCITY_NORMAL = 111;
     49    static const float MAX_VELOCITY_BOOST = 221;
    4450
    4551    CreateFactory(MultiStateEngine);
     
    4955        RegisterObject(MultiStateEngine);
    5056
     57        if (GameMode::isMaster())
     58        {
     59            this->defEngineSndNormal_ = new WorldSound(this);
     60            this->defEngineSndBoost_  = new WorldSound(this);
     61            this->defEngineSndNormal_->setLooping(true);
     62            this->defEngineSndBoost_->setLooping(true);
     63            this->lua_ = new LuaState();
     64        }
     65        else
     66        {
     67            this->defEngineSndBoost_ = 0;
     68            this->defEngineSndNormal_ = 0;
     69            this->lua_ = 0;
     70        }
    5171        this->state_ = 0;
    52 
     72        this->oldState_ = 0;
     73
     74        this->setSyncMode(ObjectDirection::Bidirectional);
    5375        this->registerVariables();
    5476    }
     
    5678    MultiStateEngine::~MultiStateEngine()
    5779    {
    58         if (this->isInitialized() && !this->getShip())
    59         {
    60             // We have no ship, so the effects are not attached and won't be destroyed automatically
    61             for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)
    62                 (*it)->destroy();
    63             for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it)
    64                 (*it)->destroy();
    65             for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it)
    66                 (*it)->destroy();
    67             for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it)
    68                 (*it)->destroy();
     80        if (this->isInitialized())
     81        {
     82            if (!this->getShip())
     83            {
     84                // We have no ship, so the effects are not attached and won't be destroyed automatically
     85                for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
     86                    for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsBegin(); ++it2)
     87                        (*it2)->destroy();
     88                if (this->defEngineSndNormal_)
     89                    this->defEngineSndNormal_->destroy();
     90                if (this->defEngineSndBoost_)
     91                    this->defEngineSndBoost_->destroy();
     92            }
     93            if (this->lua_)
     94                delete this->lua_;
    6995        }
    7096    }
     
    7399    {
    74100        SUPER(MultiStateEngine, XMLPort, xmlelement, mode);
    75 
    76         XMLPortObject(MultiStateEngine, WorldEntity, "active",  addActiveEffect,  getActiveEffect,  xmlelement, mode);
    77         XMLPortObject(MultiStateEngine, WorldEntity, "forward", addForwardEffect, getForwardEffect, xmlelement, mode);
    78         XMLPortObject(MultiStateEngine, WorldEntity, "boost",   addBoostEffect,   getBoostEffect,   xmlelement, mode);
    79         XMLPortObject(MultiStateEngine, WorldEntity, "brake",   addBrakeEffect,   getBrakeEffect,   xmlelement, mode);
     101        XMLPortObject(MultiStateEngine, EffectContainer, "",  addEffectContainer,  getEffectContainer,  xmlelement, mode);
     102        XMLPortParam(MultiStateEngine, "defEngineSndNormal",  setDefEngSndNormal,  getDefEngSndNormal,  xmlelement, mode);
     103        XMLPortParam(MultiStateEngine, "defEngineSndBoost",  setDefEngSndBoost,  getDefEngSndBoost,  xmlelement, mode);
    80104    }
    81105
     
    89113        if (this->getShip())
    90114        {
     115            const Vector3& velocity = this->getShip()->getLocalVelocity();
     116
    91117            if (this->getShip()->hasLocalController())
    92118            {
    93                 this->setSyncMode(ObjectDirection::Bidirectional);
    94 
    95119                const Vector3& direction = this->getDirection();
    96                 const Vector3& velocity = this->getShip()->getLocalVelocity();
    97 
    98                 bool forward = (direction.z < 0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD);
    99                 bool boost = (this->getShip()->getBoost() && forward);
    100                 bool brake = (direction.z > 0 && velocity.z < 0);
    101                 bool active = (direction != Vector3::ZERO && !brake);
    102 
    103                 if (active)
    104                     this->state_ |= STATE_ACTIVE;
     120                bool forward = (direction.z < 0.0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD);
     121
     122                this->state_ = 0;
     123                if (this->getShip()->getBoost() && forward)
     124                    this->state_ = Boost;
     125                else if (forward && !this->state_) // this->state_ == Boost
     126                    this->state_ = Normal;
     127                else if (direction.z > 0.0 && velocity.z < 0.0)
     128                    this->state_ = Brake;
    105129                else
    106                     this->state_ &= ~STATE_ACTIVE;
    107 
    108                 if (forward)
    109                     this->state_ |= STATE_FORWARD;
    110                 else
    111                     this->state_ &= ~STATE_FORWARD;
    112 
    113                 if (boost)
    114                     this->state_ |= STATE_BOOST;
    115                 else
    116                     this->state_ &= ~STATE_BOOST;
    117 
    118                 if (brake)
    119                     this->state_ |= STATE_BRAKE;
    120                 else
    121                     this->state_ &= ~STATE_BRAKE;
     130                    this->state_ = Idle;
    122131            }
    123132
    124133            if (GameMode::isMaster())
    125134            {
    126                 for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)
    127                     (*it)->setMainState(this->state_ & STATE_ACTIVE);
    128                 for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it)
    129                     (*it)->setMainState(this->state_ & STATE_FORWARD);
    130                 for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it)
    131                     (*it)->setMainState(this->state_ & STATE_BOOST);
    132                 for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it)
    133                     (*it)->setMainState(this->state_ & STATE_BRAKE);
     135                int changes = this->state_ | this->oldState_;
     136
     137                float pitch = velocity.length();
     138                if (this->state_ & Normal)
     139                    defEngineSndNormal_->setPitch(clamp(pitch/MAX_VELOCITY_NORMAL + 1, 0.5f, 2.0f));
     140                if (this->state_ & Boost)
     141                    defEngineSndBoost_->setPitch(clamp(pitch/MAX_VELOCITY_BOOST + 1, 0.5f, 2.0f));
     142
     143                if (changes & Idle)
     144                {
     145                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Idle);
     146                    lua_setglobal(this->lua_->getInternalLuaState(), "idle");
     147                }
     148                if (changes & Normal)
     149                {
     150                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Normal);
     151                    lua_setglobal(this->lua_->getInternalLuaState(), "normal");
     152                    if (this->state_ & Normal)
     153                        defEngineSndNormal_->play();
     154                    else
     155                        defEngineSndNormal_->stop();
     156                }
     157                if (changes & Brake)
     158                {
     159                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Brake);
     160                    lua_setglobal(this->lua_->getInternalLuaState(), "brake");
     161                }
     162                if (changes & Boost)
     163                {
     164                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Boost);
     165                    lua_setglobal(this->lua_->getInternalLuaState(), "boost");
     166                    if (this->state_ & Boost)
     167                        defEngineSndBoost_->play();
     168                    else
     169                        defEngineSndBoost_->stop();
     170                }
     171
     172                this->oldState_ = this->state_;
     173
     174                // Update all effect conditions
     175                for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
     176                    (*it)->updateCondition();
    134177            }
    135178        }
     
    145188            return;
    146189
    147         for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)
    148             ship->attach(*it);
    149         for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it)
    150             ship->attach(*it);
    151         for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it)
    152             ship->attach(*it);
    153         for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it)
    154             ship->attach(*it);
    155     }
    156 
    157     void MultiStateEngine::addActiveEffect(WorldEntity* effect)
    158     {
    159         this->activeEffects_.push_back(effect);
     190        if( this->defEngineSndNormal_ )
     191            this->getShip()->attach(defEngineSndNormal_);
     192        if( this->defEngineSndBoost_ )
     193            this->getShip()->attach(defEngineSndBoost_);
     194
     195        for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
     196            for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsEnd(); ++it2)
     197                this->getShip()->attach(*it2);
     198    }
     199
     200    void MultiStateEngine::addEffectContainer(EffectContainer* effect)
     201    {
     202        if (effect == NULL)
     203            return;
     204        effect->setLuaState(this->lua_, 'f' + multi_cast<std::string>(this->effectContainers_.size()));
     205        this->effectContainers_.push_back(effect);
    160206        if (this->getShip())
    161             this->getShip()->attach(effect);
    162     }
    163 
    164     void MultiStateEngine::addForwardEffect(WorldEntity* effect)
    165     {
    166         this->forwardEffects_.push_back(effect);
    167         if (this->getShip())
    168             this->getShip()->attach(effect);
    169     }
    170 
    171     void MultiStateEngine::addBoostEffect(WorldEntity* effect)
    172     {
    173         this->boostEffects_.push_back(effect);
    174         if (this->getShip())
    175             this->getShip()->attach(effect);
    176     }
    177 
    178     void MultiStateEngine::addBrakeEffect(WorldEntity* effect)
    179     {
    180         this->brakeEffects_.push_back(effect);
    181         if (this->getShip())
    182             this->getShip()->attach(effect);
    183     }
    184 
    185     WorldEntity* MultiStateEngine::getActiveEffect(unsigned int index) const
     207        {
     208            for (std::vector<WorldEntity*>::const_iterator it = effect->getEffectsBegin(); it != effect->getEffectsBegin(); ++it)
     209                this->getShip()->attach(*it);
     210        }
     211    }
     212
     213    EffectContainer* MultiStateEngine::getEffectContainer(unsigned int index) const
    186214    {
    187215        unsigned int i = 0;
    188         for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)
     216        for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
    189217        {
    190218            if (i == index)
    191219                return (*it);
    192             ++i;
    193         }
    194         return 0;
    195     }
    196 
    197     WorldEntity* MultiStateEngine::getForwardEffect(unsigned int index) const
    198     {
    199         unsigned int i = 0;
    200         for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it)
    201         {
    202             if (i == index)
    203                 return (*it);
    204             ++i;
    205         }
    206         return 0;
    207     }
    208 
    209     WorldEntity* MultiStateEngine::getBoostEffect(unsigned int index) const
    210     {
    211         unsigned int i = 0;
    212         for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it)
    213         {
    214             if (i == index)
    215                 return (*it);
    216             ++i;
    217         }
    218         return 0;
    219     }
    220 
    221     WorldEntity* MultiStateEngine::getBrakeEffect(unsigned int index) const
    222     {
    223         unsigned int i = 0;
    224         for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it)
    225         {
    226             if (i == index)
    227                 return (*it);
    228             ++i;
    229         }
    230         return 0;
     220        }
     221        return NULL;
     222    }
     223
     224    void MultiStateEngine::setDefEngSndNormal(const std::string &engineSound)
     225    {
     226        if( defEngineSndNormal_ )
     227            defEngineSndNormal_->setSource(engineSound);
     228        else
     229            assert(0); // This should never happen, because soundpointer is only available on master
     230    }
     231
     232    const std::string& MultiStateEngine::getDefEngSndNormal()
     233    {
     234        if( defEngineSndNormal_ )
     235            return defEngineSndNormal_->getSource();
     236        else
     237            assert(0);
     238        return BLANKSTRING;
     239    }
     240
     241    void MultiStateEngine::setDefEngSndBoost(const std::string &engineSound)
     242    {
     243        if( defEngineSndBoost_ )
     244            defEngineSndBoost_->setSource(engineSound);
     245        else
     246            assert(0);
     247    }
     248
     249    const std::string& MultiStateEngine::getDefEngSndBoost()
     250    {
     251        if( this->defEngineSndBoost_ )
     252            return defEngineSndBoost_->getSource();
     253        else
     254            assert(0);
     255        return BLANKSTRING;
    231256    }
    232257}
  • code/trunk/src/orxonox/items/MultiStateEngine.h

    r5781 r6417  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    2526 *      ...
     
    3233#include "OrxonoxPrereqs.h"
    3334
    34 #include <list>
     35#include <vector>
    3536#include "Engine.h"
    3637
     
    4041    {
    4142        public:
     43            enum EngineState
     44            {
     45                Idle    = 1,
     46                Normal  = 2,
     47                Brake   = 4,
     48                Boost   = 8
     49            };
     50
    4251            MultiStateEngine(BaseObject* creator);
    4352            virtual ~MultiStateEngine();
     
    5059            virtual void addToSpaceShip(SpaceShip* ship);
    5160
    52             void addActiveEffect(WorldEntity* effect);
    53             void addForwardEffect(WorldEntity* effect);
    54             void addBoostEffect(WorldEntity* effect);
    55             void addBrakeEffect(WorldEntity* effect);
     61            void addEffectContainer(EffectContainer* effect);
     62            EffectContainer* getEffectContainer(unsigned int index) const;
    5663
    57             WorldEntity* getActiveEffect(unsigned int index) const;
    58             WorldEntity* getForwardEffect(unsigned int index) const;
    59             WorldEntity* getBoostEffect(unsigned int index) const;
    60             WorldEntity* getBrakeEffect(unsigned int index) const;
     64            void setDefEngSndNormal(const std::string& engineSound);
     65            const std::string& getDefEngSndNormal();
     66            void setDefEngSndBoost(const std::string& engineSound);
     67            const std::string& getDefEngSndBoost();
    6168
    6269        private:
    63             unsigned char state_;
    64             std::list<WorldEntity*> activeEffects_;
    65             std::list<WorldEntity*> forwardEffects_;
    66             std::list<WorldEntity*> boostEffects_;
    67             std::list<WorldEntity*> brakeEffects_;
     70            int state_;
     71            int oldState_;
     72            LuaState* lua_;
     73            std::vector<EffectContainer*> effectContainers_;
     74            WorldSound* defEngineSndNormal_;
     75            WorldSound* defEngineSndBoost_;
    6876    };
    6977}
  • code/trunk/src/orxonox/overlays/InGameConsole.cc

    r6105 r6417  
    4444#include "util/Convert.h"
    4545#include "util/Math.h"
    46 #include "util/UTFStringConversions.h"
     46#include "util/DisplayStringConversions.h"
    4747#include "core/CoreIncludes.h"
    4848#include "core/ConfigValueIncludes.h"
     
    6161    SetConsoleCommand(InGameConsole, closeConsole, true);
    6262
    63     InGameConsole* InGameConsole::singletonPtr_s = 0;
    6463    ManageScopedSingleton(InGameConsole, ScopeID::Graphics, false);
    6564
     
    6867    */
    6968    InGameConsole::InGameConsole()
    70         : shell_(new Shell("InGameConsole", true, true))
     69        : shell_(new Shell("InGameConsole", true))
     70        , bShowCursor_(false)
    7171        , consoleOverlay_(0)
    7272        , consoleOverlayContainer_(0)
     
    218218        font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));
    219219
     220        // create noise
     221        this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
     222        this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
     223        this->consoleOverlayNoise_->setPosition(5,0);
     224        this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
     225        // comment following line to disable noise
     226        this->consoleOverlayBorder_->addChild(this->consoleOverlayNoise_);
     227
    220228        // create the text lines
    221229        this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];
     
    229237            this->consoleOverlayTextAreas_[i]->setLeft(8);
    230238            this->consoleOverlayTextAreas_[i]->setCaption("");
    231             this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
     239            this->consoleOverlayNoise_->addChild(this->consoleOverlayTextAreas_[i]);
    232240        }
    233241
     
    240248        this->consoleOverlayCursor_->setLeft(7);
    241249        this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));
    242         this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
    243 
    244         // create noise
    245         this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
    246         this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
    247         this->consoleOverlayNoise_->setPosition(5,0);
    248         this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
    249         // comment following line to disable noise
    250         this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
     250        this->consoleOverlayNoise_->addChild(this->consoleOverlayCursor_);
    251251
    252252        this->windowResized(this->getWindowWidth(), this->getWindowWidth());
     
    268268    void InGameConsole::linesChanged()
    269269    {
    270         std::list<std::string>::const_iterator it = this->shell_->getNewestLineIterator();
     270        Shell::LineList::const_iterator it = this->shell_->getNewestLineIterator();
    271271        int max = 0;
    272272        for (int i = 1; i < LINES; ++i)
     
    282282
    283283        for (int i = LINES - 1; i > max; --i)
    284             this->print("", i, true);
     284            this->print("", Shell::None, i, true);
    285285
    286286        for (int i = max; i >= 1; --i)
    287287        {
    288288            --it;
    289             this->print(*it, i, true);
     289            this->print(it->first, it->second, i, true);
    290290        }
    291291    }
     
    297297    {
    298298        if (LINES > 1)
    299             this->print(*this->shell_->getNewestLineIterator(), 1);
     299            this->print(this->shell_->getNewestLineIterator()->first, this->shell_->getNewestLineIterator()->second, 1);
    300300    }
    301301
     
    316316    {
    317317        if (LINES > 0)
    318             this->print(this->shell_->getInput(), 0);
    319 
    320         if (this->shell_->getInput() == "" || this->shell_->getInput().size() == 0)
     318            this->print(this->shell_->getInput(), Shell::Input, 0);
     319
     320        if (this->shell_->getInput().empty())
    321321            this->inputWindowStart_ = 0;
    322322    }
     
    340340    void InGameConsole::executed()
    341341    {
    342         this->shell_->addOutputLine(this->shell_->getInput());
     342        this->shell_->addOutput(this->shell_->getInput() + '\n', Shell::Command);
    343343    }
    344344
     
    358358        @brief Used to control the actual scrolling and the cursor.
    359359    */
    360     void InGameConsole::update(const Clock& time)
     360    void InGameConsole::preUpdate(const Clock& time)
    361361    {
    362362        if (this->scroll_ != 0)
     
    456456        @param s String to be printed
    457457    */
    458     void InGameConsole::print(const std::string& text, int index, bool alwaysShift)
    459     {
    460         char level = 0;
    461         if (text.size() > 0)
    462             level = text[0];
    463 
     458    void InGameConsole::print(const std::string& text, Shell::LineType type, int index, bool alwaysShift)
     459    {
    464460        std::string output = text;
    465 
    466         if (level >= -1 && level <= 5)
    467             output.erase(0, 1);
    468 
    469461        if (LINES > index)
    470462        {
    471             this->colourLine(level, index);
     463            this->colourLine(type, index);
    472464
    473465            if (index > 0)
     
    477469                {
    478470                    ++linesUsed;
    479                     this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::UTFString>(output.substr(0, this->maxCharsPerLine_)));
     471                    this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output.substr(0, this->maxCharsPerLine_)));
    480472                    output.erase(0, this->maxCharsPerLine_);
    481473                    output.insert(0, 1, ' ');
    482474                    if (linesUsed > numLinesShifted_ || alwaysShift)
    483475                        this->shiftLines();
    484                     this->colourLine(level, index);
     476                    this->colourLine(type, index);
    485477                }
    486                 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::UTFString>(output));
     478                this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output));
    487479                this->displayedText_ = output;
    488480                this->numLinesShifted_ = linesUsed;
     
    502494                  this->inputWindowStart_ = 0;
    503495                this->displayedText_ = output;
    504                 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::UTFString>(output));
     496                this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output));
    505497            }
    506498        }
     
    559551    }
    560552
    561     void InGameConsole::colourLine(int colourcode, int index)
    562     {
    563         if (colourcode == -1)
    564         {
    565             this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.90, 0.90, 0.90, 1.00));
    566             this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00));
    567         }
    568         else if (colourcode == 1)
    569         {
    570             this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.25, 0.25, 1.00));
    571             this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00));
    572         }
    573         else if (colourcode == 2)
    574         {
    575             this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.50, 0.20, 1.00));
    576             this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00));
    577         }
    578         else if (colourcode == 3)
    579         {
    580             this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.50, 0.50, 0.95, 1.00));
    581             this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00));
    582         }
    583         else if (colourcode == 4)
    584         {
    585             this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.65, 0.48, 0.44, 1.00));
    586             this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00));
    587         }
    588         else if (colourcode == 5)
    589         {
    590             this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.40, 0.20, 0.40, 1.00));
    591             this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00));
    592         }
    593         else
    594         {
    595             this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.21, 0.69, 0.21, 1.00));
    596             this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00));
    597         }
     553    void InGameConsole::colourLine(Shell::LineType type, int index)
     554    {
     555        ColourValue colourTop, colourBottom;
     556        switch (type)
     557        {
     558        case Shell::Error:   colourTop = ColourValue(0.95, 0.25, 0.25, 1.00);
     559                          colourBottom = ColourValue(1.00, 0.50, 0.50, 1.00); break;
     560
     561        case Shell::Warning: colourTop = ColourValue(0.95, 0.50, 0.20, 1.00);
     562                          colourBottom = ColourValue(1.00, 0.70, 0.50, 1.00); break;
     563
     564        case Shell::Info:    colourTop = ColourValue(0.50, 0.50, 0.95, 1.00);
     565                          colourBottom = ColourValue(0.80, 0.80, 1.00, 1.00); break;
     566
     567        case Shell::Debug:   colourTop = ColourValue(0.65, 0.48, 0.44, 1.00);
     568                          colourBottom = ColourValue(1.00, 0.90, 0.90, 1.00); break;
     569
     570        case Shell::Verbose: colourTop = ColourValue(0.40, 0.20, 0.40, 1.00);
     571                          colourBottom = ColourValue(0.80, 0.60, 0.80, 1.00); break;
     572
     573        case Shell::Ultra:   colourTop = ColourValue(0.21, 0.69, 0.21, 1.00);
     574                          colourBottom = ColourValue(0.80, 1.00, 0.80, 1.00); break;
     575
     576        case Shell::Command: colourTop = ColourValue(0.80, 0.80, 0.80, 1.00);
     577                          colourBottom = ColourValue(0.90, 0.90, 0.90, 0.90); break;
     578
     579        case Shell::Hint:    colourTop = ColourValue(0.80, 0.80, 0.80, 1.00);
     580                          colourBottom = ColourValue(0.90, 0.90, 0.90, 1.00); break;
     581
     582        default:             colourTop = ColourValue(0.90, 0.90, 0.90, 1.00);
     583                          colourBottom = ColourValue(1.00, 1.00, 1.00, 1.00); break;
     584        }
     585
     586        this->consoleOverlayTextAreas_[index]->setColourTop   (colourTop);
     587        this->consoleOverlayTextAreas_[index]->setColourBottom(colourBottom);
    598588    }
    599589
  • code/trunk/src/orxonox/overlays/InGameConsole.h

    r6105 r6417  
    5252        void setConfigValues();
    5353
    54         void update(const Clock& time);
     54        void preUpdate(const Clock& time);
    5555
    5656        static void openConsole();
     
    7272
    7373        void shiftLines();
    74         void colourLine(int colourcode, int index);
     74        void colourLine(Shell::LineType type, int index);
    7575        void setCursorPosition(unsigned int pos);
    76         void print(const std::string& text, int index, bool alwaysShift = false);
     76        void print(const std::string& text, Shell::LineType type, int index, bool alwaysShift = false);
    7777
    7878        void windowResized(unsigned int newWidth, unsigned int newHeight);
  • code/trunk/src/orxonox/overlays/Map.cc

    r5929 r6417  
    4949#include <OgreViewport.h>
    5050
     51#include "util/StringUtils.h"
    5152#include "core/ConsoleCommand.h"
    5253#include "core/CoreIncludes.h"
     
    9495
    9596        //Getting Scene Manager (Hack)
    96         if( !sManager_ )
    97         {
    98             ObjectList<Scene>::iterator it = ObjectList<Scene>::begin();
    99             this->sManager_ = it->getSceneManager();
    100         }
     97        ObjectList<Scene>::iterator it = ObjectList<Scene>::begin();
     98        this->sManager_ = it->getSceneManager();
    10199        if( !Map::getMapSceneManager() )
    102100        {
  • code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc

    r6057 r6417  
    3939#include <OgrePanelOverlayElement.h>
    4040#include <OgreRenderWindow.h>
     41#include <OgreMaterialManager.h>
     42#include <OgreTechnique.h>
     43#include <OgrePass.h>
    4144
    4245#include "util/Convert.h"
    4346#include "util/Exception.h"
    44 #include "util/StringUtils.h"
    4547#include "core/GameMode.h"
    4648#include "core/CoreIncludes.h"
     
    8385        // Get aspect ratio from the render window. Later on, we get informed automatically
    8486        this->windowAspectRatio_ = static_cast<float>(this->getWindowWidth()) / this->getWindowHeight();
    85         this->sizeCorrectionChanged();
    86 
    87         this->changedVisibility();
    88 
    89         setSize(Vector2(1.0f, 1.0f));
    90         setPickPoint(Vector2(0.0f, 0.0f));
    91         setPosition(Vector2(0.0f, 0.0f));
    92         setRotation(Degree(0.0));
    93         setAspectCorrection(false);
     87
     88        this->size_ = Vector2(1.0f, 1.0f);
     89        this->pickPoint_= Vector2(0.0f, 0.0f);
     90        this->position_ = Vector2(0.0f, 0.0f);
     91        this->angle_ = Degree(0.0);
     92        this->bCorrectAspect_ = false;
     93        this->rotState_ = Horizontal;
     94        this->angleChanged(); // updates all other values as well
     95
    9496        setBackgroundMaterial("");
    9597    }
     
    143145
    144146        if (OrxonoxOverlay::overlays_s.find(this->getName()) != OrxonoxOverlay::overlays_s.end())
    145             COUT(1) << "Overlay names should be unique or you cannnot access them via console. Name: \"" << this->getName() << "\"" << std::endl;
     147            COUT(1) << "Overlay names should be unique or you cannnot access them via console. Name: \"" << this->getName() << '"' << std::endl;
    146148
    147149        OrxonoxOverlay::overlays_s[this->getName()] = this;
     
    151153    void OrxonoxOverlay::setBackgroundMaterial(const std::string& material)
    152154    {
    153         if (this->background_ && material != "")
     155        if (this->background_ && !material.empty())
    154156            this->background_->setMaterialName(material);
    155157    }
     
    168170    {
    169171        SUPER( OrxonoxOverlay, changedVisibility );
    170        
     172
    171173        if (!this->overlay_)
    172174            return;
     
    309311        std::map<std::string, OrxonoxOverlay*>::const_iterator it = overlays_s.find(name);
    310312        if (it != overlays_s.end())
    311             (*it).second->scale(Vector2(scale, scale));
     313            it->second->scale(Vector2(scale, scale));
    312314    }
    313315
     
    324326        if (it != overlays_s.end())
    325327        {
    326             OrxonoxOverlay* overlay= (*it).second;
     328            OrxonoxOverlay* overlay= it->second;
    327329            if(overlay->isVisible())
    328330                overlay->hide();
     
    343345        std::map<std::string, OrxonoxOverlay*>::const_iterator it = overlays_s.find(name);
    344346        if (it != overlays_s.end())
    345             (*it).second->scroll(scroll);
     347            it->second->scroll(scroll);
    346348    }
    347349
     
    357359        std::map<std::string, OrxonoxOverlay*>::const_iterator it = overlays_s.find(name);
    358360        if (it != overlays_s.end())
    359             (*it).second->rotate(angle);
     361            it->second->rotate(angle);
    360362    }
    361363
     
    370372        }
    371373    }
     374
     375    void OrxonoxOverlay::setBackgroundAlpha(float alpha) {
     376        Ogre::MaterialPtr ptr = this->background_->getMaterial();
     377        Ogre::TextureUnitState* tempTx = ptr->getTechnique(0)->getPass(0)->getTextureUnitState(0);
     378        tempTx->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, alpha);
     379    }
    372380}
  • code/trunk/src/orxonox/overlays/OrxonoxOverlay.h

    r6057 r6417  
    155155        static void rotateOverlay(const std::string& name, const Degree& angle);
    156156
     157        void setBackgroundMaterial(const std::string& material);
     158        const std::string& getBackgroundMaterial() const;
     159
     160        void setBackgroundAlpha(float alpha);
     161
    157162        virtual void changedVisibility();
    158163
     
    172177        inline OverlayGroup* getOverlayGroup() const
    173178            { return this->group_; }
    174         virtual void changedOverlayGroup() 
     179        virtual void changedOverlayGroup()
    175180            { this->changedVisibility(); }
    176181
     
    180185        virtual void sizeChanged();
    181186        virtual void positionChanged();
    182 
    183         void setBackgroundMaterial(const std::string& material);
    184         const std::string& getBackgroundMaterial() const;
    185187
    186188        Ogre::Overlay* overlay_;                   //!< The overlay the entire class is about.
     
    205207        BaseObject* owner_;
    206208        OverlayGroup* group_;
     209        Ogre::Pass* backgroundAlphaPass_;
    207210  };
    208211
  • code/trunk/src/orxonox/overlays/OverlayGroup.cc

    r6054 r6417  
    144144    {
    145145        SUPER( OverlayGroup, changedVisibility );
    146        
     146
    147147        for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    148148            (*it)->changedVisibility(); //inform all Child Overlays that our visibility has changed
  • code/trunk/src/orxonox/pickup/DroppedItem.cc

    r5929 r6417  
    8383        if (this->item_)
    8484        {
    85             COUT(3) << "Delete DroppedItem with '" << this->item_->getPickupIdentifier() << "'" << std::endl;
     85            COUT(3) << "Delete DroppedItem with '" << this->item_->getPickupIdentifier() << '\'' << std::endl;
    8686            this->item_->destroy();
    8787        }
     
    112112        drop->createTimer();
    113113
    114         COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << "," << position.y << "," << position.z << ")." << std::endl;
     114        COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << ',' << position.y << ',' << position.z << ")." << std::endl;
    115115
    116116        return drop;
  • code/trunk/src/orxonox/pickup/ModifierPickup.cc

    r5929 r6417  
    9191            for (it = this->additiveModifiers_.begin(); it != this->additiveModifiers_.end(); it++)
    9292            {
    93                 pawn->getPickups().addAdditiveModifier((*it).first, (*it).second);
     93                pawn->getPickups().addAdditiveModifier(it->first, it->second);
    9494            }
    9595
    9696            for (it = this->multiplicativeModifiers_.begin(); it != this->multiplicativeModifiers_.end(); it++)
    9797            {
    98                 pawn->getPickups().addMultiplicativeModifier((*it).first, (*it).second);
     98                pawn->getPickups().addMultiplicativeModifier(it->first, it->second);
    9999            }
    100100
     
    128128            for (it = this->additiveModifiers_.begin(); it != this->additiveModifiers_.end(); it++)
    129129            {
    130                 pawn->getPickups().removeAdditiveModifier((*it).first, (*it).second);
     130                pawn->getPickups().removeAdditiveModifier(it->first, it->second);
    131131            }
    132132
    133133            for (it = this->multiplicativeModifiers_.begin(); it != this->multiplicativeModifiers_.end(); it++)
    134134            {
    135                 pawn->getPickups().removeMultiplicativeModifier((*it).first, (*it).second);
     135                pawn->getPickups().removeMultiplicativeModifier(it->first, it->second);
    136136            }
    137137
     
    162162        std::map<ModifierType::Value, float>::const_iterator it = this->additiveModifiers_.find(type);
    163163        if (it != this->additiveModifiers_.end())
    164             return (*it).second;
     164            return it->second;
    165165        else
    166166            return 0.0f;
     
    175175        std::map<ModifierType::Value, float>::const_iterator it = this->multiplicativeModifiers_.find(type);
    176176        if (it != this->multiplicativeModifiers_.end())
    177             return (*it).second;
     177            return it->second;
    178178        else
    179179            return 1.0f;
  • code/trunk/src/orxonox/pickup/ModifierPickup.h

    r5929 r6417  
    129129
    130130        void timerCallback(Pawn* pawn);     //!< Method called when the timer runs out.
    131        
     131
    132132    private:
    133133        float getAdditiveModifier(ModifierType::Value type) const;               //!< Get the additive modifier for a given ModifierType.
  • code/trunk/src/orxonox/pickup/PickupCollection.cc

    r5781 r6417  
    100100        for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++)
    101101        {
    102             if((*it).second && (*it).second->getOwner())
    103                 (*it).second->dropped((*it).second->getOwner());
     102            if(it->second && it->second->getOwner())
     103                it->second->dropped(it->second->getOwner());
    104104        }
    105105        this->currentUsable_ = NULL;
     
    124124            for (std::multimap<std::string, BaseItem*>::iterator it = bounds.first; it != bounds.second && it != this->items_.end(); it++)
    125125            {
    126                 if ((*it).second == item)
     126                if (it->second == item)
    127127                {
    128128                    return true;
     
    176176            for (std::multimap<std::string, BaseItem*>::iterator it = bounds.first; it != bounds.second && it != this->items_.end(); it++)
    177177            {
    178                 if ((*it).second == item)
     178                if (it->second == item)
    179179                {
    180180                    this->items_.erase(it);
     
    217217        for (std::multimap<ModifierType::Value, float>::iterator it = range.first; it != range.second && it != this->additiveModifiers_.end(); it++)
    218218        {
    219             v += (*it).second;
     219            v += it->second;
    220220        }
    221221
     
    232232        for (std::multimap<ModifierType::Value, float>::iterator it = range.first; it != range.second && it != this->additiveModifiers_.end(); it++)
    233233        {
    234             if ((*it).second == value)
     234            if (it->second == value)
    235235            {
    236236                this->additiveModifiers_.erase(it);
     
    260260        for (std::multimap<ModifierType::Value, float>::iterator it = range.first; it != range.second && it != this->multiplicativeModifiers_.end(); it++)
    261261        {
    262             v *= (*it).second;
     262            v *= it->second;
    263263        }
    264264
     
    275275        for (std::multimap<ModifierType::Value, float>::iterator it = range.first; it != range.second && it != this->multiplicativeModifiers_.end(); it++)
    276276        {
    277             if ((*it).second == value)
     277            if (it->second == value)
    278278            {
    279279                this->multiplicativeModifiers_.erase(it);
     
    335335        for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++)
    336336        {
    337             if ((*it).second->isA(ident))
    338                 ret.push_back(orxonox_cast<EquipmentItem*>((*it).second));
     337            if (it->second->isA(ident))
     338                ret.push_back(orxonox_cast<EquipmentItem*>(it->second));
    339339        }
    340340
     
    352352        for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++)
    353353        {
    354             if ((*it).second->isA(ident))
    355                 ret.push_back(orxonox_cast<PassiveItem*>((*it).second));
     354            if (it->second->isA(ident))
     355                ret.push_back(orxonox_cast<PassiveItem*>(it->second));
    356356        }
    357357
     
    369369        for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++)
    370370        {
    371             if ((*it).second->isA(ident))
    372                 ret.push_back(orxonox_cast<UsableItem*>((*it).second));
     371            if (it->second->isA(ident))
     372                ret.push_back(orxonox_cast<UsableItem*>(it->second));
    373373        }
    374374
  • code/trunk/src/orxonox/pickup/PickupInventory.cc

    r5781 r6417  
    8686    {
    8787        if(PickupInventory::getSingleton()->isVisible()) {
    88             GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")");
    89             GUIManager::getInstance().executeCode("hideCursor()");
    90             InputManager::getInstance().leaveState("guiMouseOnly");
    91         }
    92         else
    93         {
    94             GUIManager::getInstance().showGUI("PickupInventory");
    95             GUIManager::getInstance().executeCode("showCursor()");
    96             InputManager::getInstance().enterState("guiMouseOnly");
     88            GUIManager::hideGUI("PickupInventory");
     89        }
     90        else
     91        {
     92            GUIManager::showGUI("PickupInventory");
    9793        }
    9894        PickupInventory::getSingleton()->setVisible(!PickupInventory::getSingleton()->isVisible());
     
    200196            return "";
    201197
    202         std::string name = "pickup_" + item->getGUIImage();
     198        const std::string& name = "pickup_" + item->getGUIImage();
    203199
    204200        if(!CEGUI::ImagesetManager::getSingletonPtr()->isImagesetPresent(name))
     
    207203        }
    208204
    209         return "set:" + name + " image:full_image";
     205        return ("set:" + name + " image:full_image");
    210206    }
    211207
     
    336332        txt->setVisible(true);
    337333        txt->setProperty("Text", item->getGUIText());
    338         txt->setProperty("TextColours", "tl:" + textColour + " tr:" + textColour + " bl:" + textColour + " br:" + textColour + "");
    339 
    340         std::string image = PickupInventory::getImageForItem(item);
     334        txt->setProperty("TextColours", "tl:" + textColour + " tr:" + textColour + " bl:" + textColour + " br:" + textColour);
     335
     336        const std::string& image = PickupInventory::getImageForItem(item);
    341337        btn->setVisible(true);
    342338        btn->setProperty("NormalImage", image);
  • code/trunk/src/orxonox/pickup/PickupSpawner.cc

    r5929 r6417  
    9696        //  & load the GUI itself too, along with some empty windows
    9797        //   = even less delays
    98         GUIManager::getInstance().showGUI("PickupInventory");
    99         GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")");
     98        GUIManager::showGUI("PickupInventory");
     99        GUIManager::hideGUI("PickupInventory");
    100100        PickupInventory::getSingleton();
    101101    }
  • code/trunk/src/orxonox/pickup/UsableItem.cc

    r5781 r6417  
    2626 *
    2727 */
    28        
     28
    2929/**
    3030    @file
     
    4141        @param creator Pointer to the object which created this item.
    4242    */
    43     UsableItem::UsableItem(BaseObject* creator) : BaseItem(creator) 
     43    UsableItem::UsableItem(BaseObject* creator) : BaseItem(creator)
    4444    {
    4545        RegisterObject(UsableItem);
  • code/trunk/src/orxonox/sound/AmbientSound.cc

    r5929 r6417  
    3131#include "core/CoreIncludes.h"
    3232#include "core/EventIncludes.h"
     33#include "core/GameMode.h"
     34#include "core/Resource.h"
    3335#include "core/XMLPort.h"
     36#include "SoundManager.h"
    3437
    3538namespace orxonox
     
    3942    AmbientSound::AmbientSound(BaseObject* creator)
    4043        : BaseObject(creator)
     44        , Synchronisable(creator)
     45        , bPlayOnLoad_(false)
    4146    {
    4247        RegisterObject(AmbientSound);
     48
     49        // Ambient sounds always fade in
     50        this->setVolume(0);
     51        this->registerVariables();
    4352    }
    4453
    45     AmbientSound::~AmbientSound()
     54    void AmbientSound::preDestroy()
    4655    {
     56        if (GameMode::playsSound())
     57        {
     58            // Smoothly fade out by keeping a SmartPtr
     59            SoundManager::getInstance().unregisterAmbientSound(this);
     60        }
     61    }
     62
     63    void AmbientSound::registerVariables()
     64    {
     65        registerVariable(ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::ambientSourceChanged));
     66        registerVariable(bLooping_,      ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::loopingChanged));
     67        registerVariable(pitch_,         ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::pitchChanged));
     68        registerVariable(bPlayOnLoad_,   ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::playOnLoadChanged));
    4769    }
    4870
     
    5072    {
    5173        SUPER(AmbientSound, XMLPort, xmlelement, mode);
    52         XMLPortParamExtern(AmbientSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode);
    53         XMLPortParamExtern(AmbientSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode);
    54         XMLPortParamExtern(AmbientSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
     74        BaseSound::XMLPortExtern(xmlelement, mode);
     75        XMLPortParam(AmbientSound, "ambientSource", setAmbientSource, getAmbientSource, xmlelement, mode);
     76        XMLPortParam(AmbientSound, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
    5577    }
    5678
     
    6082        XMLPortEventState(AmbientSound, BaseObject, "play", play, xmlelement, mode);
    6183    }
     84
     85    void AmbientSound::play()
     86    {
     87        if (GameMode::playsSound())
     88            SoundManager::getInstance().registerAmbientSound(this);
     89    }
     90
     91    void AmbientSound::stop()
     92    {
     93        if (GameMode::playsSound())
     94            SoundManager::getInstance().unregisterAmbientSound(this);
     95    }
     96
     97    void AmbientSound::pause()
     98    {
     99        if (GameMode::playsSound())
     100            SoundManager::getInstance().pauseAmbientSound(this);
     101    }
     102
     103    float AmbientSound::getRealVolume()
     104    {
     105        assert(GameMode::playsSound());
     106        return SoundManager::getInstance().getRealVolume(SoundType::Music);
     107    }
     108
     109    void AmbientSound::setAmbientSource(const std::string& source)
     110    {
     111        this->ambientSource_ = source;
     112        this->moodChanged(this->getMood());
     113    }
     114
     115    void AmbientSound::moodChanged(const std::string& mood)
     116    {
     117        if (GameMode::playsSound())
     118        {
     119            const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + this->ambientSource_;
     120            shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
     121            if (fileInfo != NULL)
     122                this->setSource(path);
     123            else
     124                COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl;
     125        }
     126    }
     127
     128    void AmbientSound::setPlayOnLoad(bool val)
     129    {
     130        this->bPlayOnLoad_ = val;
     131        if (val)
     132            this->play();
     133    }
     134
     135    void AmbientSound::changedActivity()
     136    {
     137        SUPER(AmbientSound, changedActivity);
     138        if (this->isActive())
     139            this->play();
     140        else
     141            this->stop();
     142    }
    62143}
  • code/trunk/src/orxonox/sound/AmbientSound.h

    r5929 r6417  
    2222 *   Author:
    2323 *      Reto Grieder
     24 *      Kevin Young
    2425 *   Co-authors:
    2526 *      ...
    2627 *
    2728 */
     29
    2830#ifndef _AmbientSound_H__
    2931#define _AmbientSound_H__
     
    3234
    3335#include "core/BaseObject.h"
    34 #include "sound/BaseSound.h"
     36#include "network/synchronisable/Synchronisable.h"
     37#include "BaseSound.h"
     38#include "MoodManager.h"
    3539
    3640namespace orxonox
     
    4145     *
    4246     */
    43     class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject
     47    class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable, public MoodListener
    4448    {
     49        friend class SoundManager;
     50
    4551    public:
    4652        AmbientSound(BaseObject* creator);
    47         virtual ~AmbientSound();
    4853
    49         virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    50         virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
     54        void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     55        void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
     56        void changedActivity();
     57
     58        void play();
     59        void stop();
     60        void pause();
     61
     62        void setAmbientSource(const std::string& source);
     63        inline const std::string& getAmbientSource() const
     64            { return this->ambientSource_; }
     65
     66        void setPlayOnLoad(bool val);
     67        bool getPlayOnLoad() const
     68            { return this->bPlayOnLoad_; }
     69
     70    protected:
     71        ~AmbientSound() { }
    5172
    5273    private:
     74        void preDestroy();
     75        void registerVariables();
     76        float getRealVolume();
     77        void moodChanged(const std::string& mood);
     78        inline void ambientSourceChanged()
     79            { this->setAmbientSource(this->ambientSource_); }
     80        inline void playOnLoadChanged()
     81            { this->setPlayOnLoad(this->bPlayOnLoad_); }
     82
     83        std::string ambientSource_; //!< Analogous to source_, but mood independent
     84        bool        bPlayOnLoad_;   //!< Play the sound immediately when loaded
    5385    };
    5486}
  • code/trunk/src/orxonox/sound/BaseSound.cc

    r5929 r6417  
    2929#include "BaseSound.h"
    3030
     31#include <cassert>
    3132#include <vector>
    32 #include <AL/alut.h>
    33 #include <vorbis/vorbisfile.h>
     33#include <al.h>
    3434
    3535#include "core/CoreIncludes.h"
    3636#include "core/GameMode.h"
    3737#include "core/Resource.h"
     38#include "core/XMLPort.h"
     39#include "SoundBuffer.h"
     40#include "SoundManager.h"
    3841
    3942namespace orxonox
    4043{
    4144    BaseSound::BaseSound()
    42         : audioSource_(0)
    43         , audioBuffer_(0)
    44         , bPlayOnLoad_(false)
    45         , bLoop_(false)
     45        : bPooling_(false)
     46        , volume_(1.0)
     47        , bLooping_(false)
     48        , state_(Stopped)
     49        , pitch_ (1.0)
    4650    {
    4751        RegisterRootObject(BaseSound);
     52
     53        // Initialise audioSource_ to a value that is not a source
     54        // 0 is unfortunately not guaranteed to be no source ID.
     55        this->audioSource_ = 123456789;
     56        while (alIsSource(++this->audioSource_));
    4857    }
    4958
    5059    BaseSound::~BaseSound()
    5160    {
    52         this->setSource("");
    53     }
    54 
    55     void BaseSound::play()
    56     {
    57         if (alIsSource(this->audioSource_))
    58         {
    59             if (this->bLoop_)
    60                 alSourcei(this->audioSource_, AL_LOOPING, AL_TRUE);
    61             else
    62                 alSourcei(this->audioSource_, AL_LOOPING, AL_FALSE);
     61        this->stop();
     62        // Release buffer
     63        if (this->soundBuffer_ != NULL)
     64        {
     65            assert(GameMode::playsSound());
     66            SoundManager::getInstance().releaseSoundBuffer(this->soundBuffer_, this->bPooling_);
     67        }
     68    }
     69
     70    void BaseSound::XMLPortExtern(Element& xmlelement, XMLPort::Mode mode)
     71    {
     72        XMLPortParam(BaseSound, "volume",  setVolume,  getVolume,  xmlelement, mode);
     73        XMLPortParam(BaseSound, "looping", setLooping, getLooping, xmlelement, mode);
     74        XMLPortParam(BaseSound, "pitch",   setPitch,   getPitch,   xmlelement, mode);
     75        XMLPortParam(BaseSound, "source",  setSource,  getSource,  xmlelement, mode);
     76    }
     77
     78    void BaseSound::doPlay()
     79    {
     80        this->state_ = Playing;
     81        if (GameMode::playsSound() && this->getSourceState() != AL_PLAYING && this->soundBuffer_ != NULL)
     82        {
     83            if (!alIsSource(this->audioSource_))
     84            {
     85                this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
     86                if (!alIsSource(this->audioSource_))
     87                    return;
     88                this->initialiseSource();
     89            }
     90
    6391            alSourcePlay(this->audioSource_);
    64 
    65             if (alGetError() != AL_NO_ERROR)
    66             {
    67                  COUT(2) << "Sound: OpenAL: Error playin sound " << this->audioSource_ << std::endl;
    68             }
    69         }
    70     }
    71 
    72     void BaseSound::stop()
    73     {
    74         if (alIsSource(this->audioSource_))
     92            if (int error = alGetError())
     93                COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
     94        }
     95    }
     96
     97    void BaseSound::doStop()
     98    {
     99        this->state_ = Stopped;
     100        if (alIsSource(this->audioSource_))
     101        {
    75102            alSourceStop(this->audioSource_);
    76     }
    77 
    78     void BaseSound::pause()
    79     {
     103            // Release buffer
     104            alSourcei(this->audioSource_, AL_BUFFER, AL_NONE);
     105            // Release source again
     106            SoundManager::getInstance().releaseSoundSource(this->audioSource_);
     107            // Get a no source ID
     108            this->audioSource_ += 123455;
     109            while (alIsSource(++this->audioSource_));
     110        }
     111    }
     112
     113    void BaseSound::doPause()
     114    {
     115        if (this->isStopped())
     116            return;
     117        this->state_ = Paused;
    80118        if (alIsSource(this->audioSource_))
    81119            alSourcePause(this->audioSource_);
    82120    }
    83121
    84     bool BaseSound::isPlaying()
    85     {
    86         if (alIsSource(this->audioSource_))
    87             return getSourceState() == AL_PLAYING;
    88         return false;
    89     }
    90 
    91     bool BaseSound::isPaused()
    92     {
    93         if (alIsSource(this->audioSource_))
    94             return getSourceState() == AL_PAUSED;
    95         return true;
    96     }
    97 
    98     bool BaseSound::isStopped()
    99     {
    100         if (alIsSource(this->audioSource_))
    101             return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED;
    102         return true;
    103     }
    104 
    105     void BaseSound::setPlayOnLoad(bool val)
    106     {
    107         this->bPlayOnLoad_ = true;
    108         this->play();
     122    ALint BaseSound::getSourceState() const
     123    {
     124        if (alIsSource(this->audioSource_))
     125        {
     126            ALint state;
     127            alGetSourcei(this->audioSource_, AL_SOURCE_STATE, &state);
     128            return state;
     129        }
     130        else
     131            return AL_INITIAL;
     132    }
     133
     134    void BaseSound::initialiseSource()
     135    {
     136        this->updateVolume();
     137        this->setPitch(this->getPitch());
     138        this->setLooping(this->getLooping());
     139        alSource3f(this->audioSource_, AL_POSITION,  0, 0, 0);
     140        alSource3f(this->audioSource_, AL_VELOCITY,  0, 0, 0);
     141        alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0);
     142        if (ALint error = alGetError())
     143            COUT(2) << "Sound Warning: Setting source parameters to 0 failed: "
     144                    << SoundManager::getALErrorString(error) << std::endl;
     145        assert(this->soundBuffer_ != NULL);
     146        alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
     147        if (ALuint error = alGetError())
     148            COUT(1) << "Sound Error: Could not set buffer \"" << this->source_ << "\": " << SoundManager::getALErrorString(error) << std::endl;
     149    }
     150
     151    void BaseSound::setVolume(float vol)
     152    {
     153        this->volume_ = clamp(vol, 0.0f, 1.0f);
     154        if (this->volume_ != vol)
     155            COUT(2) << "Sound warning: volume out of range, clamping value." << std::endl;
     156        this->updateVolume();
     157    }
     158
     159    void BaseSound::updateVolume()
     160    {
     161        if (alIsSource(this->audioSource_))
     162        {
     163            float volume = this->volume_ * this->getRealVolume();
     164            alSourcef(this->audioSource_, AL_GAIN, volume);
     165            if (int error = alGetError())
     166                COUT(2) << "Sound: Error setting volume to " << volume
     167                        << ": " << SoundManager::getALErrorString(error) << std::endl;
     168        }
     169    }
     170
     171    void BaseSound::setLooping(bool val)
     172    {
     173        this->bLooping_ = val;
     174        if (alIsSource(this->audioSource_))
     175            alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE));
     176    }
     177
     178    void BaseSound::setPitch(float pitch)
     179    {
     180        if (pitch > 2 || pitch < 0.5)
     181        {
     182            COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl;
     183            pitch = pitch > 2 ? 2 : pitch;
     184            pitch = pitch < 0.5 ? 0.5 : pitch;
     185        }
     186        this->pitch_ = pitch;
     187        if (alIsSource(this->audioSource_))
     188        {
     189            alSourcef(this->audioSource_, AL_PITCH, pitch);
     190            if (int error = alGetError())
     191                COUT(2) << "Sound: Error setting pitch: " << SoundManager::getALErrorString(error) << std::endl;
     192        }
    109193    }
    110194
    111195    void BaseSound::setSource(const std::string& source)
    112196    {
     197        if (!GameMode::playsSound())
     198        {
     199            this->source_ = source;
     200            return;
     201        }
     202
     203        if (this->soundBuffer_ != NULL)
     204        {
     205            if (this->soundBuffer_->getFilename() == source)
     206            {
     207                assert(this->source_ == source_);
     208                return;
     209            }
     210            // Stopping is imperative here!
     211            if (alIsSource(this->audioSource_))
     212            {
     213                alSourceStop(this->audioSource_);
     214                alSourcei(this->audioSource_, AL_BUFFER, AL_NONE);
     215            }
     216            SoundManager::getInstance().releaseSoundBuffer(this->soundBuffer_, this->bPooling_);
     217            this->soundBuffer_.reset();
     218        }
     219
    113220        this->source_ = source;
    114         if (!GameMode::playsSound())
    115             return;
    116 
    117         if (source.empty() && alIsSource(this->audioSource_))
    118         {
    119             // Unload sound
    120             alSourcei(this->audioSource_, AL_BUFFER, 0);
    121             alDeleteSources(1, &this->audioSource_);
    122             alDeleteBuffers(1, &this->audioBuffer_);
    123             return;
    124         }
    125 
    126         COUT(3) << "Sound: OpenAL ALUT: loading file " << source << std::endl;
    127         // Get DataStream from the resources
    128         shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source);
    129         if (fileInfo == NULL)
    130         {
    131             COUT(2) << "Warning: Sound file '" << source << "' not found" << std::endl;
    132             return;
    133         }
    134         dataStream_ = Resource::open(source);
    135         // Read everything into a temporary buffer
    136         char* buffer = new char[fileInfo->size];
    137         dataStream_->read(buffer, fileInfo->size);
    138         dataStream_->seek(0);
    139 
    140         this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size);
    141         delete[] buffer;
    142 
    143         if (this->audioBuffer_ == AL_NONE)
    144         {
    145             COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
    146             if (source.find("ogg", 0) != std::string::npos)
    147             {
    148                 COUT(2) << "Sound: Trying fallback ogg loader" << std::endl;
    149                 this->audioBuffer_ = loadOggFile();
    150             }
    151 
    152             if (this->audioBuffer_ == AL_NONE)
    153             {
    154                 COUT(2) << "Sound: fallback ogg loader failed: " << alutGetErrorString(alutGetError()) << std::endl;
     221        // Don't load ""
     222        if (source_.empty())
     223            return;
     224
     225        // Get new sound buffer
     226        this->soundBuffer_ = SoundManager::getInstance().getSoundBuffer(this->source_);
     227        if (this->soundBuffer_ == NULL)
     228            return;
     229
     230        if (alIsSource(this->audioSource_)) // already playing or paused
     231        {
     232            // Set new buffer
     233            alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
     234            if (ALuint error = alGetError())
     235            {
     236                COUT(1) << "Sound Error: Could not set buffer \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl;
    155237                return;
    156238            }
    157         }
    158 
    159         alGenSources(1, &this->audioSource_);
    160         alSourcei(this->audioSource_, AL_BUFFER, this->audioBuffer_);
    161         if (alGetError() != AL_NO_ERROR)
    162         {
    163             COUT(2) << "Sound: OpenAL: Error loading sample file: " << source << std::endl;
    164             return;
    165         }
    166 
    167         alSource3f(this->audioSource_, AL_POSITION,  0, 0, 0);
    168 
    169         if (this->bPlayOnLoad_)
    170             this->play();
    171     }
    172 
    173     ALint BaseSound::getSourceState()
    174     {
    175         ALint state;
    176         alGetSourcei(this->audioSource_, AL_SOURCE_STATE, &state);
    177         return state;
    178     }
    179 
    180     size_t readVorbis(void* ptr, size_t size, size_t nmemb, void* datasource)
    181     {
    182         return static_cast<Ogre::DataStream*>(datasource)->read(ptr, size * nmemb);
    183     }
    184 
    185     int seekVorbis(void* datasource, ogg_int64_t offset, int whence)
    186     {
    187         Ogre::DataStream* stream = static_cast<Ogre::DataStream*>(datasource);
    188         int offset_beg = offset;
    189         if (whence == SEEK_CUR)
    190             offset_beg = stream->tell() + offset;
    191         else if (whence == SEEK_END)
    192             offset_beg = stream->size() + offset;
    193         else if (whence != SEEK_SET)
    194             return -1;
    195         stream->seek(offset_beg);
    196         return 0;
    197     }
    198 
    199     long tellVorbis(void* datasource)
    200     {
    201         return static_cast<long>(static_cast<Ogre::DataStream*>(datasource)->tell());
    202     }
    203 
    204     ALuint BaseSound::loadOggFile()
    205     {
    206         char inbuffer[4096];
    207         std::vector<char> outbuffer;
    208         OggVorbis_File vf;
    209         vorbis_info* vorbisInfo;
    210         int eof = false;
    211         int current_section;
    212         ALuint buffer;
    213         ALenum format;
    214 
    215         // Open file with custom streaming
    216         ov_callbacks vorbisCallbacks;
    217         vorbisCallbacks.read_func  = &readVorbis;
    218         vorbisCallbacks.seek_func  = &seekVorbis;
    219         vorbisCallbacks.tell_func  = &tellVorbis;
    220         vorbisCallbacks.close_func = NULL;
    221 
    222         int ret = ov_open_callbacks(dataStream_.get(), &vf, NULL, 0, vorbisCallbacks);
    223         if (ret < 0)
    224         {
    225             COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl;
    226             ov_clear(&vf);
    227             return AL_NONE;
    228         }
    229 
    230         while (!eof)
    231         {
    232             long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
    233             if (ret == 0)
    234             {
    235                 eof = true;
    236             }
    237             else if (ret < 0)
    238             {
    239                 COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
    240                 ov_clear(&vf);
    241                 return AL_NONE;
    242             }
    243             else
    244             {
    245                 outbuffer.insert(outbuffer.end(), inbuffer, inbuffer + sizeof(inbuffer));
    246             }
    247         }
    248 
    249         vorbisInfo = ov_info(&vf, -1);
    250         if (vorbisInfo->channels == 1)
    251             format = AL_FORMAT_MONO16;
    252         else
    253             format = AL_FORMAT_STEREO16;
    254 
    255         alGenBuffers(1, &buffer);
    256         alBufferData(buffer, format, &outbuffer[0], outbuffer.size(), vorbisInfo->rate);
    257         ov_clear(&vf);
    258 
    259         return buffer;
    260     }
    261 
    262 } // namespace: orxonox
     239
     240            // Sound was already playing or paused because there was a source acquired
     241            assert(this->isPlaying() || this->isPaused());
     242            alSourcePlay(this->audioSource_);
     243            if (int error = alGetError())
     244                COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
     245            if (this->isPaused())
     246                alSourcePause(this->audioSource_);
     247        }
     248        else // No source acquired so far, but might be set to playing or paused
     249        {
     250            State state = this->state_; // save
     251            if (this->isPlaying() || this->isPaused())
     252                doPlay();
     253            if (state == Paused)
     254            {
     255                this->state_ = Paused;
     256                doPause();
     257            }
     258        }
     259    }
     260
     261    void BaseSound::stateChanged()
     262    {
     263        switch (this->state_)
     264        {
     265            case Playing:
     266                this->play();
     267                break;
     268            case Paused:
     269                this->pause();
     270                break;
     271            case Stopped:
     272            default:
     273                this->stop();
     274                break;
     275        }
     276    }
     277}
  • code/trunk/src/orxonox/sound/BaseSound.h

    r5929 r6417  
    2626 *
    2727 */
     28
    2829#ifndef _BaseSound_H__
    2930#define _BaseSound_H__
     
    3233
    3334#include <string>
    34 #include <OgreSharedPtr.h>
     35#include <boost/shared_ptr.hpp>
    3536#include <OgreDataStream.h>
    3637#include "core/OrxonoxClass.h"
     
    4748    public:
    4849        BaseSound();
     50
     51        void XMLPortExtern(Element& xmlelement, XMLPort::Mode mode);
     52
     53        virtual void play()  { this->doPlay(); }
     54        virtual void stop()  { this->doStop(); }
     55        virtual void pause() { this->doPause(); }
     56
     57        bool isPlaying() const { return this->state_ == Playing; }
     58        bool isPaused()  const { return this->state_ == Paused; }
     59        bool isStopped() const { return this->state_ == Stopped; }
     60
     61        virtual void setSource(const std::string& source);
     62        virtual const std::string& getSource() const
     63            { return this->source_; }
     64
     65        void setVolume(float vol);
     66        float getVolume() const
     67            { return this->volume_; }
     68        void updateVolume();
     69
     70        bool getLooping() const
     71            { return this->bLooping_; }
     72        void setLooping(bool val);
     73
     74        float getPitch() const
     75            { return this->pitch_; }
     76        void setPitch(float pitch);
     77
     78    protected:
     79        enum State
     80        {
     81            Stopped,
     82            Playing,
     83            Paused
     84        };
     85
    4986        virtual ~BaseSound();
    5087
    51         void play();
    52         void stop();
    53         void pause();
     88        void doPlay();
     89        void doStop();
     90        void doPause();
    5491
    55         bool isPlaying();
    56         bool isPaused();
    57         bool isStopped();
     92        // network callbacks
     93        inline void pitchChanged()
     94            { this->setPitch(this->pitch_); }
     95        inline void loopingChanged()
     96            { this->setLooping(this->bLooping_); }
     97        inline void volumeChanged()
     98            { this->setVolume(this->volume_); }
     99        inline void sourceChanged()
     100            { this->setSource(this->source_); }
     101        void stateChanged();
    58102
    59         void setSource(const std::string& source);
    60         const std::string& getSource() { return this->source_; }
     103        virtual void initialiseSource();
     104        ALint getSourceState() const;
    61105
    62         bool getPlayOnLoad() { return this->bPlayOnLoad_; }
    63         void setPlayOnLoad(bool val);
     106        virtual float getRealVolume() = 0;
    64107
    65         bool getLoop() { return this->bLoop_; }
    66         void setLoop(bool val) { this->bLoop_ = val; }
    67 
    68     protected:
    69         ALuint loadOggFile();
    70         ALint getSourceState();
    71 
    72         ALuint audioSource_;
    73         ALuint audioBuffer_;
     108        ALuint          audioSource_;
     109        bool            bPooling_;
     110        shared_ptr<SoundBuffer> soundBuffer_;
     111        std::string     source_;
     112        float           volume_;
     113        bool            bLooping_;
     114        State           state_;
     115        float           pitch_;
    74116
    75117    private:
    76         std::string source_;
    77         bool bPlayOnLoad_;
    78         bool bLoop_;
    79         DataStreamPtr dataStream_;
     118        DataStreamPtr   dataStream_;
    80119    };
    81120}
  • code/trunk/src/orxonox/sound/CMakeLists.txt

    r5929 r6417  
    22    AmbientSound.cc
    33    BaseSound.cc
     4    SoundBuffer.cc
    45    SoundManager.cc
    56    WorldSound.cc
     7    SoundStreamer.cc
    68)
    79
  • code/trunk/src/orxonox/sound/SoundManager.cc

    r5929 r6417  
    2222 *   Author:
    2323 *       Erwin 'vaiursch' Herrsche
     24 *       Kevin Young
     25 *       Reto Grieder
    2426 *   Co-authors:
    2527 *      ...
     
    3032
    3133#include <AL/alut.h>
     34#include <utility>
    3235
    3336#include "util/Exception.h"
    3437#include "util/Math.h"
    3538#include "util/ScopeGuard.h"
     39#include "util/Clock.h"
     40#include "core/ConfigValueIncludes.h"
     41#include "core/CoreIncludes.h"
    3642#include "core/GameMode.h"
    3743#include "core/ScopedSingletonManager.h"
     44#include "core/Resource.h"
     45#include "SoundBuffer.h"
     46#include "BaseSound.h"
     47#include "AmbientSound.h"
     48#include "WorldSound.h"
    3849
    3950namespace orxonox
    4051{
    41     SoundManager* SoundManager::singletonPtr_s = NULL;
    4252    ManageScopedSingleton(SoundManager, ScopeID::Graphics, true);
    4353
     54    std::string SoundManager::getALErrorString(ALenum code)
     55    {
     56        switch (code)
     57        {
     58        case AL_NO_ERROR:          return "No error";
     59        case AL_INVALID_NAME:      return "Invalid AL parameter name";
     60        case AL_INVALID_ENUM:      return "Invalid AL enum";
     61        case AL_INVALID_VALUE:     return "Invalid AL value";
     62        case AL_INVALID_OPERATION: return "Invalid AL operation";
     63        case AL_OUT_OF_MEMORY:     return "AL reports out of memory";
     64        default:                   return "Unknown AL error";
     65        }
     66    }
     67
    4468    SoundManager::SoundManager()
    45     {
    46         if (!alutInitWithoutContext(NULL,NULL))
    47             ThrowException(InitialisationFailed, "OpenAL ALUT error: " << alutGetErrorString(alutGetError()));
     69        : effectsPoolSize_(0)
     70    {
     71        RegisterRootObject(SoundManager);
     72
     73        // See whether we even want to load
     74        bool bDisableSound_ = false;
     75        SetConfigValue(bDisableSound_, false);
     76        if (bDisableSound_)
     77            ThrowException(InitialisationAborted, "Sound: Not loading at all");
     78
     79        if (!alutInitWithoutContext(NULL, NULL))
     80            ThrowException(InitialisationFailed, "Sound Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
    4881        Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
    4982
    50         COUT(3) << "OpenAL: Opening sound device..." << std::endl;
     83/*
     84        // Get list of available sound devices and display them
     85        const char* devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
     86        char* device = new char[strlen(devices)+1];
     87        strcpy(device, devices);
     88        std::string renderDevice;
     89        SetConfigValue(renderDevice, std::string(device)).description("Sound device used for rendering");
     90        COUT(4) << "Sound: Available devices: ";
     91        while (true)
     92        {
     93            this->deviceNames_.push_back(devices);
     94            COUT(4) << '"' << devices << "\", ";
     95            devices += strlen(devices) + 1;
     96            if (*devices == '\0')
     97                break;
     98        }
     99        COUT(4) << std::endl;
     100
     101        // Open the selected device
     102        COUT(3) << "Sound: Opening device \"" << renderDevice << '\' << std::endl;
     103        this->device_ = alcOpenDevice(renderDevice.c_str());
     104*/
    51105        this->device_ = alcOpenDevice(NULL);
    52106        if (this->device_ == NULL)
    53107        {
    54             COUT(0) << "OpenaAL: Could not open sound device. Have you installed OpenAL?" << std::endl;
     108            COUT(1) << "Sound: Could not open sound device. Have you installed OpenAL?" << std::endl;
    55109#ifdef ORXONOX_PLATFORM_WINDOWS
    56             COUT(0) << "Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
     110            COUT(1) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
    57111#endif
    58             ThrowException(InitialisationFailed, "OpenAL error: Could not open sound device.");
     112            ThrowException(InitialisationFailed, "Sound Error: Could not open sound device.");
    59113        }
    60114        Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
    61115
    62         COUT(3) << "OpenAL: Sound device opened" << std::endl;
     116        // Create sound context and make it the currently used one
    63117        this->context_ = alcCreateContext(this->device_, NULL);
    64118        if (this->context_ == NULL)
    65             ThrowException(InitialisationFailed, "OpenAL error: Could not create sound context");
     119            ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context");
    66120        Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);
    67 
    68         if (alcMakeContextCurrent(this->context_) == AL_TRUE)
    69             COUT(3) << "OpenAL: Context " << this->context_ << " loaded" << std::endl;
    70 
    71         COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
    72 
    73         const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
    74         if (str == NULL)
    75             COUT(2) << "OpenAL ALUT error: " << alutGetErrorString(alutGetError()) << std::endl;
     121        if (!alcMakeContextCurrent(this->context_))
     122            ThrowException(InitialisationFailed, "Sound Error: Could not use ALC context");
     123
     124        GameMode::setPlaysSound(true);
     125        Loki::ScopeGuard resetPlaysSoundGuard = Loki::MakeGuard(&GameMode::setPlaysSound, false);
     126
     127        // Get some information about the sound
     128        if (const char* version = alGetString(AL_VERSION))
     129            COUT(4) << "Sound: --- OpenAL Version: " << version << std::endl;
     130        if (const char* vendor = alGetString(AL_VENDOR))
     131            COUT(4) << "Sound: --- OpenAL Vendor : " << vendor << std::endl;
     132        if (const char* types = alutGetMIMETypes(ALUT_LOADER_BUFFER))
     133            COUT(4) << "Sound: --- Supported MIME Types: " << types << std::endl;
    76134        else
    77             COUT(4) << "OpenAL ALUT supported MIME types: " << str << std::endl;
    78 
    79         GameMode::setPlaysSound(true);
     135            COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
     136
     137        this->mute_[SoundType::All]     = 1.0f;
     138        this->mute_[SoundType::Music]   = 1.0f;
     139        this->mute_[SoundType::Effects] = 1.0f;
     140
     141        this->setConfigValues();
     142
     143        // Try to get at least one source
     144        ALuint source;
     145        alGenSources(1, &source);
     146        if (!alGetError() && alIsSource(source))
     147            this->availableSoundSources_.push_back(source);
     148        else
     149            ThrowException(InitialisationFailed, "Sound Error: Could not create even a single source");
     150        // Create a few initial sources
     151        this->createSoundSources(this->minSources_ - 1);
     152
    80153        // Disarm guards
    81154        alutExitGuard.Dismiss();
    82155        closeDeviceGuard.Dismiss();
    83156        desroyContextGuard.Dismiss();
     157        resetPlaysSoundGuard.Dismiss();
     158
     159        COUT(4) << "Sound: Initialisation complete" << std::endl;
    84160    }
    85161
    86162    SoundManager::~SoundManager()
    87163    {
     164        // Erase fade lists because of the smart pointers
     165        this->fadeInList_.clear();
     166        this->fadeOutList_.clear();
     167
     168        // If there are still used buffers around, well, that's just very bad...
     169        if (this->soundBuffers_.size() != this->effectsPool_.size())
     170            COUT(1) << "Sound Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
     171        // Empty buffer pool and buffer list
     172        this->effectsPool_.clear();
     173        this->soundBuffers_.clear();
     174
     175        // There should not be any sources in use anymore
     176        if (!this->usedSoundSources_.empty())
     177            COUT(1) << "Sound Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
     178        while (!this->availableSoundSources_.empty())
     179        {
     180            alDeleteSources(1, &this->availableSoundSources_.back());
     181            this->availableSoundSources_.pop_back();
     182        }
     183
    88184        GameMode::setPlaysSound(false);
     185
     186        // Relieve context to destroy it
     187        if (!alcMakeContextCurrent(NULL))
     188            COUT(1) << "Sound Error: Could not unset ALC context" << std::endl;
    89189        alcDestroyContext(this->context_);
     190        if (ALCenum error = alcGetError(this->device_))
     191        {
     192            if (error == AL_INVALID_OPERATION)
     193                COUT(1) << "Sound Error: Could not destroy ALC context because it is the current one" << std::endl;
     194            else
     195                COUT(1) << "Sound Error: Could not destroy ALC context because it is invalid" << std::endl;
     196        }
     197#ifdef AL_VERSION_1_1
     198        if (!alcCloseDevice(this->device_))
     199            COUT(1) << "Sound Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
     200#else
    90201        alcCloseDevice(this->device_);
    91         alutExit();
     202#endif
     203        if (!alutExit())
     204            COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
     205    }
     206
     207    void SoundManager::setConfigValues()
     208    {
     209        SetConfigValue(crossFadeStep_, 0.2f)
     210            .description("Determines how fast sounds should fade, per second.")
     211            .callback(this, &SoundManager::checkFadeStepValidity);
     212
     213        SetConfigValueAlias(volume_[SoundType::All], "soundVolume_", 1.0f)
     214            .description("Defines the overall volume.")
     215            .callback(this, &SoundManager::checkSoundVolumeValidity);
     216        SetConfigValueAlias(volume_[SoundType::Music], "ambientVolume_", 1.0f)
     217            .description("Defines the ambient volume.")
     218            .callback(this, &SoundManager::checkAmbientVolumeValidity);
     219        SetConfigValueAlias(volume_[SoundType::Effects], "effectsVolume_", 1.0f)
     220            .description("Defines the effects volume.")
     221            .callback(this, &SoundManager::checkEffectsVolumeValidity);
     222
     223        SetConfigValue(minSources_, 16)
     224            .description("Minimum number of sources being generated (if possible)");
     225        SetConfigValue(maxSources_, 1024)
     226            .description("Maximum number of sources to be made available");
     227    }
     228
     229    void SoundManager::preUpdate(const Clock& time)
     230    {
     231        this->processCrossFading(time.getDeltaTime());
     232
     233        // Check whether a sound object has stopped playing
     234        for (unsigned int i = 0; i < this->usedSoundSources_.size(); ++i)
     235        {
     236            ALint state;
     237            alGetSourcei(this->usedSoundSources_[i].first, AL_SOURCE_STATE, &state);
     238            if (state == AL_STOPPED)
     239            {
     240                this->usedSoundSources_[i].second->stop();
     241                --i;
     242            }
     243        }
     244    }
     245
     246    void SoundManager::checkFadeStepValidity()
     247    {
     248        if (crossFadeStep_ <= 0.0 || crossFadeStep_ >= 1.0 )
     249        {
     250            COUT(2) << "Sound warning: fade step out of range, ignoring change." << std::endl;
     251            ResetConfigValue(crossFadeStep_);
     252        }
     253    }
     254
     255    void SoundManager::checkVolumeValidity(SoundType::Value type)
     256    {
     257        float clampedVolume = clamp(this->volume_[type], 0.0f, 1.0f);
     258        if (clampedVolume != this->volume_[type])
     259            COUT(2) << "Sound warning: Volume setting (" << type << ") out of range, clamping." << std::endl;
     260        this->updateVolume(type);
     261    }
     262
     263    void SoundManager::setVolume(float vol, SoundType::Value type)
     264    {
     265        if (type < 0 || type > SoundType::Effects)
     266            return;
     267        this->volume_[type] = vol;
     268        this->checkVolumeValidity(type);
     269    }
     270
     271    float SoundManager::getVolume(SoundType::Value type)
     272    {
     273        if (type < 0 || type > SoundType::Effects)
     274            return 0.0f;
     275        return this->volume_[type];
     276    }
     277
     278    float SoundManager::getRealVolume(SoundType::Value type)
     279    {
     280        if (type != SoundType::Music && type != SoundType::Effects)
     281            return 0.0f;
     282        return this->volume_[SoundType::All] * this->mute_[SoundType::All] * this->volume_[type] * this->mute_[type];
     283    }
     284
     285    void SoundManager::updateVolume(SoundType::Value type)
     286    {
     287        switch(type)
     288        {
     289        case SoundType::All:
     290            for (ObjectList<BaseSound>::iterator it = ObjectList<BaseSound>::begin(); it != ObjectList<BaseSound>::end(); ++it)
     291                (*it)->updateVolume();
     292            break;
     293        case SoundType::Music:
     294            for (ObjectList<AmbientSound>::iterator it = ObjectList<AmbientSound>::begin(); it != ObjectList<AmbientSound>::end(); ++it)
     295                (*it)->updateVolume();
     296            break;
     297        case SoundType::Effects:
     298            for (ObjectList<WorldSound>::iterator it = ObjectList<WorldSound>::begin(); it != ObjectList<WorldSound>::end(); ++it)
     299                (*it)->updateVolume();
     300            break;
     301        default:
     302            assert(false);
     303        }
     304    }
     305
     306    void SoundManager::toggleMute(SoundType::Value type)
     307    {
     308        if (type < 0 || type > SoundType::Effects)
     309            return;
     310        this->mute_[type] = (this->mute_[type] == 0) ? 1.0f : 0.0f;
     311        this->updateVolume(type);
     312    }
     313
     314    bool SoundManager::getMute(SoundType::Value type)
     315    {
     316        if (type < 0 || type > SoundType::Effects)
     317            return true;
     318        return (this->mute_[type] == 0);
    92319    }
    93320
     
    103330    {
    104331        // update listener orientation
    105         Vector3 up = orientation.xAxis(); // just a wild guess
    106         Vector3 at = orientation.zAxis();
    107 
    108         ALfloat orient[6] = { at.x, at.y, at.z,
    109                               up.x, up.y, up.z };
    110 
    111         alListenerfv(AL_POSITION, orient);
     332        const Vector3& direction = -orientation.zAxis();
     333        const Vector3& up = orientation.yAxis();
     334
     335        ALfloat orient[6] = { direction.x, direction.y, direction.z, up.x, up.y, up.z };
     336
     337        alListenerfv(AL_ORIENTATION, orient);
    112338        ALenum error = alGetError();
    113339        if (error == AL_INVALID_VALUE)
    114340            COUT(2) << "Sound: OpenAL: Invalid listener orientation" << std::endl;
    115341    }
     342
     343    void SoundManager::registerAmbientSound(AmbientSound* newAmbient)
     344    {
     345        if (newAmbient != NULL)
     346        {
     347            for (AmbientList::const_iterator it = this->ambientSounds_.begin(); it != this->ambientSounds_.end(); ++it)
     348            {
     349                if (it->first == newAmbient)
     350                {
     351                    COUT(2) << "Sound warning: Will not play an AmbientSound twice." << std::endl;
     352                    return;
     353                }
     354            }
     355
     356            if (!this->ambientSounds_.empty())
     357            {
     358                this->fadeOut(ambientSounds_.front().first);
     359            }
     360            this->ambientSounds_.push_front(std::make_pair(newAmbient, false));
     361            newAmbient->doPlay();
     362            this->fadeIn(newAmbient);
     363        }
     364    }
     365
     366    void SoundManager::unregisterAmbientSound(AmbientSound* oldAmbient)
     367    {
     368        if (oldAmbient == NULL || ambientSounds_.empty())
     369            return;
     370
     371        if (this->ambientSounds_.front().first == oldAmbient)
     372        {
     373            this->fadeOut(oldAmbient);
     374            this->ambientSounds_.pop_front();
     375            if (!this->ambientSounds_.empty())
     376            {
     377                if (!this->ambientSounds_.front().second) // Not paused before
     378                {
     379                    this->ambientSounds_.front().first->doPlay();
     380                }
     381                this->fadeIn(this->ambientSounds_.front().first);
     382            }
     383        }
     384        else
     385        {
     386            for (AmbientList::iterator it = this->ambientSounds_.begin(); it != this->ambientSounds_.end(); ++it)
     387            {
     388                if (it->first == oldAmbient)
     389                {
     390                    this->fadeOut(oldAmbient);
     391                    this->ambientSounds_.erase(it);
     392                    break;
     393                }
     394            }
     395        }
     396    }
     397
     398    void SoundManager::pauseAmbientSound(AmbientSound* ambient)
     399    {
     400        if (ambient != NULL)
     401        {
     402            for (AmbientList::iterator it = this->ambientSounds_.begin(); it != this->ambientSounds_.end(); ++it)
     403            {
     404                if (it->first == ambient)
     405                {
     406                    it->second = true;
     407                    this->fadeOut(it->first);
     408                    return;
     409                }
     410            }
     411        }
     412    }
     413
     414    void SoundManager::fadeIn(const SmartPtr<AmbientSound>& sound)
     415    {
     416        // If we're already fading out --> remove that
     417        for (std::list<SmartPtr<AmbientSound> >::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); it++)
     418        {
     419            if (*it == sound)
     420            {
     421                this->fadeOutList_.erase(it);
     422                break;
     423            }
     424        }
     425        // No duplicate entries
     426        if (std::find(this->fadeInList_.begin(), this->fadeInList_.end(), sound) == this->fadeInList_.end())
     427            this->fadeInList_.push_back(sound);
     428    }
     429
     430    void SoundManager::fadeOut(const SmartPtr<AmbientSound>& sound)
     431    {
     432        // If we're already fading in --> remove that
     433        for (std::list<SmartPtr<AmbientSound> >::iterator it = this->fadeInList_.begin(); it != this->fadeInList_.end(); it++)
     434        {
     435            if (*it == sound)
     436            {
     437                this->fadeInList_.erase(it);
     438                break;
     439            }
     440        }
     441        // No duplicate entries
     442        if (std::find(this->fadeOutList_.begin(), this->fadeOutList_.end(), sound) == this->fadeOutList_.end())
     443            this->fadeOutList_.push_back(sound);
     444    }
     445
     446    void SoundManager::processCrossFading(float dt)
     447    {
     448
     449        // Hacky solution to the fade delay while loading a level.
     450        if(dt > 0.2)
     451        {
     452            return;
     453        }
     454
     455        // FADE IN
     456        for (std::list<SmartPtr<AmbientSound> >::iterator it= this->fadeInList_.begin(); it != this->fadeInList_.end(); )
     457        {
     458            if ((*it)->getVolume() + this->crossFadeStep_*dt > 1.0f)
     459            {
     460                (*it)->setVolume(1.0f);
     461                this->fadeInList_.erase(it++);
     462            }
     463            else
     464            {
     465                (*it)->setVolume((*it)->getVolume() + this->crossFadeStep_*dt);
     466                ++it;
     467            }
     468        }
     469
     470        // FADE OUT
     471        for (std::list<SmartPtr<AmbientSound> >::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); )
     472        {
     473            if ((*it)->getVolume() - this->crossFadeStep_*dt < 0.0f)
     474            {
     475                (*it)->setVolume(0.0f);
     476
     477                // If sound is in the ambient list --> pause
     478                for (AmbientList::const_iterator it2 = this->ambientSounds_.begin(); it2 != this->ambientSounds_.end(); ++it2)
     479                {
     480                    if (it2->first == *it)
     481                    {
     482                        (*it)->doPause();
     483                        break;
     484                    }
     485                }
     486                // If not pause (by loop above for instance) --> stop
     487                if (!(*it)->isPaused())
     488                    (*it)->doStop();
     489
     490                this->fadeOutList_.erase(it++);
     491            }
     492            else
     493            {
     494                (*it)->setVolume((*it)->getVolume() - this->crossFadeStep_*dt);
     495                ++it;
     496            }
     497        }
     498    }
     499
     500    shared_ptr<SoundBuffer> SoundManager::getSoundBuffer(const std::string& filename)
     501    {
     502        shared_ptr<SoundBuffer> buffer;
     503        // Check active or pooled buffers
     504        SoundBufferMap::const_iterator it = this->soundBuffers_.find(filename);
     505        if (it != this->soundBuffers_.end())
     506        {
     507            buffer = it->second;
     508
     509            // Remove from effects pool if not active used before
     510            if (buffer->poolIterator_ != this->effectsPool_.end())
     511            {
     512                this->effectsPoolSize_ -= buffer->getSize();
     513                this->effectsPool_.erase(buffer->poolIterator_);
     514                buffer->poolIterator_ = this->effectsPool_.end();
     515            }
     516        }
     517        else
     518        {
     519            try
     520            {
     521                buffer.reset(new SoundBuffer(filename, this->effectsPool_.end()));
     522            }
     523            catch (...)
     524            {
     525                COUT(1) << Exception::handleMessage() << std::endl;
     526                return buffer;
     527            }
     528            this->soundBuffers_[filename] = buffer;
     529        }
     530        return buffer;
     531    }
     532
     533    void SoundManager::releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer)
     534    {
     535        // Check if others are still using the buffer
     536        if (buffer.use_count() != 2)
     537            return;
     538        SoundBufferMap::iterator it = this->soundBuffers_.find(buffer->getFilename());
     539        if (it != this->soundBuffers_.end())
     540        {
     541            if (bPoolBuffer)
     542            {
     543                // Pool already too large?
     544                while (this->effectsPoolSize_ + it->second->getSize() > this->maxEffectsPoolSize_s && !this->effectsPool_.empty())
     545                {
     546                    shared_ptr<SoundBuffer> bufferDel = this->effectsPool_.back();
     547                    this->effectsPoolSize_ -= bufferDel->getSize();
     548                    bufferDel->poolIterator_ = this->effectsPool_.end();
     549                    this->effectsPool_.pop_back();
     550                    // Remove from buffer map too
     551                    SoundBufferMap::iterator itDel = this->soundBuffers_.find(bufferDel->getFilename());
     552                    if (itDel != this->soundBuffers_.end())
     553                        this->soundBuffers_.erase(itDel);
     554                }
     555                // Put buffer into the pool
     556                this->effectsPoolSize_ += it->second->getSize();
     557                this->effectsPool_.push_front(it->second);
     558                it->second->poolIterator_ = this->effectsPool_.begin();
     559            }
     560            else
     561                this->soundBuffers_.erase(it);
     562        }
     563    }
     564
     565    ALuint SoundManager::getSoundSource(BaseSound* object)
     566    {
     567        if (!this->availableSoundSources_.empty())
     568        {
     569            ALuint source = this->availableSoundSources_.back();
     570            this->availableSoundSources_.pop_back();
     571            this->usedSoundSources_.push_back(std::make_pair(source, object));
     572            return source;
     573        }
     574        else
     575        {
     576            if (this->usedSoundSources_.size() < this->maxSources_)
     577            {
     578                ALuint source;
     579                alGenSources(1, &source);
     580                // Try to create new sources (50% more, but at least one)
     581                if (alIsSource(source) && !alGetError())
     582                {
     583                    this->usedSoundSources_.push_back(std::make_pair(source, object));
     584                    return source;
     585                }
     586            }
     587            // Return no source ID
     588            ALuint source = 123456789;
     589            while (alIsSource(++source));
     590            return source;
     591        }
     592    }
     593
     594    void SoundManager::releaseSoundSource(ALuint source)
     595    {
     596#ifndef NDEBUG
     597        for (std::vector<ALuint>::const_iterator it = this->availableSoundSources_.begin(); it != this->availableSoundSources_.end(); ++it)
     598            assert((*it) != source);
     599#endif
     600        this->availableSoundSources_.push_back(source);
     601        for (std::vector<std::pair<ALuint, BaseSound*> >::iterator it = this->usedSoundSources_.begin();
     602            it != this->usedSoundSources_.end(); ++it)
     603        {
     604            if (it->first == source)
     605            {
     606                this->usedSoundSources_.erase(it);
     607                break;
     608            }
     609        }
     610        int used = std::max((unsigned int)(this->usedSoundSources_.size()), this->minSources_);
     611        // Subtract those we added in the statement above trough std::max
     612        int available = (int)this->availableSoundSources_.size() - (used - (int)this->usedSoundSources_.size());
     613        // Delete sources again to free resources if appropriate (more than 50% more available than used)
     614        int toDelete = available - used / 2;
     615        while (toDelete-- > 0)
     616        {
     617            alDeleteSources(1, &this->availableSoundSources_.back());
     618            if (alGetError())
     619                COUT(1) << "Sound Error: Failed to delete a source --> lost forever" << std::endl;
     620            this->availableSoundSources_.pop_back();
     621        }
     622    }
     623
     624    unsigned int SoundManager::createSoundSources(unsigned int n)
     625    {
     626        unsigned int count = this->availableSoundSources_.size() + this->usedSoundSources_.size();
     627        while (count < this->maxSources_ && count <= n)
     628        {
     629            ALuint source;
     630            alGenSources(1, &source);
     631            if (alIsSource(source) && !alGetError())
     632                this->availableSoundSources_.push_back(source);
     633            else
     634                break;
     635            ++count;
     636        }
     637        return count - this->availableSoundSources_.size() - this->usedSoundSources_.size();
     638    }
    116639}
  • code/trunk/src/orxonox/sound/SoundManager.h

    r5929 r6417  
    2222 *   Author:
    2323 *       Erwin 'vaiursch' Herrsche
     24 *       Kevin Young
     25 *       Reto Grieder
    2426 *   Co-authors:
    2527 *      ...
    2628 */
     29
    2730#ifndef _SoundManager_H__
    2831#define _SoundManager_H__
     
    3033#include "OrxonoxPrereqs.h"
    3134
    32 #include <cassert>
    3335#include <list>
     36#include <map>
     37#include <string>
     38#include <boost/shared_ptr.hpp>
     39
    3440#include "util/Singleton.h"
    35 #include "tools/interfaces/Tickable.h"
     41#include "core/OrxonoxClass.h"
     42#include "core/SmartPtr.h"
    3643
     44// tolua_begin
    3745namespace orxonox
    3846{
    39     /**
    40      * The SoundManager class manages the OpenAL device, context and listener
    41      * position. It is a singleton.
    42      *
    43      */
    44     class _OrxonoxExport SoundManager : public Singleton<SoundManager>
     47    //! Enum for the sound type.
     48    namespace SoundType
    4549    {
     50        enum Value
     51        {
     52            All     = 0,
     53            Music   = 1,
     54            Effects = 2
     55        };
     56    }
     57
     58    //! The SoundManager class manages the OpenAL device, context and listener position.
     59    class _OrxonoxExport SoundManager
     60    // tolua_end
     61        : public Singleton<SoundManager>, public OrxonoxClass
     62    { // tolua_export
    4663        friend class Singleton<SoundManager>;
     64
    4765    public:
    4866        SoundManager();
    4967        ~SoundManager();
    5068
     69        void preUpdate(const Clock& time);
     70        void setConfigValues();
     71
     72        // tolua_begin
     73        static SoundManager& getInstance() { return Singleton<SoundManager>::getInstance(); }
     74
     75        std::string getDeviceName(unsigned int index) const
     76            { return index < this->deviceNames_.size() ? this->deviceNames_[index] : std::string(); }
     77        // tolua_end
     78
    5179        void setListenerPosition(const Vector3& position);
    5280        void setListenerOrientation(const Quaternion& orientation);
    5381
     82        void registerAmbientSound(AmbientSound* newAmbient);
     83        void unregisterAmbientSound(AmbientSound* oldAmbient);
     84        void pauseAmbientSound(AmbientSound* ambient);
     85
     86        // tolua_begin
     87        void setVolume(float vol, SoundType::Value type);
     88        float getVolume(SoundType::Value type);
     89        float getRealVolume(SoundType::Value type);
     90
     91        void toggleMute(SoundType::Value type);
     92        bool getMute(SoundType::Value type);
     93        // tolua_end
     94
     95        shared_ptr<SoundBuffer> getSoundBuffer(const std::string& filename);
     96        void releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer);
     97
     98        ALuint getSoundSource(BaseSound* object);
     99        void releaseSoundSource(ALuint source);
     100
     101        static std::string getALErrorString(ALenum error);
     102
    54103    private:
     104        void processCrossFading(float dt);
     105        void fadeIn(const SmartPtr<AmbientSound>& sound);
     106        void fadeOut(const SmartPtr<AmbientSound>& sound);
     107
     108        void checkFadeStepValidity();
     109
     110        void checkVolumeValidity(SoundType::Value type);
     111        void checkSoundVolumeValidity()   { this->checkVolumeValidity(SoundType::All); }
     112        void checkAmbientVolumeValidity() { this->checkVolumeValidity(SoundType::Music); }
     113        void checkEffectsVolumeValidity() { this->checkVolumeValidity(SoundType::Effects); }
     114        void updateVolume(SoundType::Value type);
     115
     116        unsigned int createSoundSources(unsigned int n);
     117
     118        // OpenAL device/context related
     119        std::vector<std::string> deviceNames_;
    55120        ALCdevice* device_;
    56121        ALCcontext* context_;
    57122
     123        // Ambient sound related
     124        typedef std::list<std::pair<AmbientSound*, bool> > AmbientList;
     125        AmbientList                        ambientSounds_;
     126        //! Absolute change per second (0.1 means 10% of the nominal volume) for cross fading
     127        float                              crossFadeStep_;
     128        std::list<SmartPtr<AmbientSound> > fadeInList_;
     129        std::list<SmartPtr<AmbientSound> > fadeOutList_;
     130
     131        // Volume related
     132        float volume_[3];
     133        float mute_[3];
     134
     135        // Sound buffer related
     136        static const unsigned int maxEffectsPoolSize_s = 40 * 1024 * 1024;
     137        unsigned int effectsPoolSize_;
     138        typedef std::list<shared_ptr<SoundBuffer> > EffectsPoolList;
     139        EffectsPoolList effectsPool_;
     140        typedef std::map<std::string, shared_ptr<SoundBuffer> > SoundBufferMap;
     141        SoundBufferMap soundBuffers_;
     142
     143        // Sound source related
     144        unsigned int minSources_;
     145        unsigned int maxSources_;
     146        std::vector<ALuint> availableSoundSources_;
     147        std::vector<std::pair<ALuint, BaseSound*> > usedSoundSources_;
     148
    58149        static SoundManager* singletonPtr_s;
    59     };
    60 }
     150    }; // tolua_export
     151} // tolua_export
    61152
    62153#endif /* _SoundManager_H__ */
  • code/trunk/src/orxonox/sound/WorldSound.cc

    r5929 r6417  
    3535#include "core/EventIncludes.h"
    3636#include "core/XMLPort.h"
     37#include "Scene.h"
     38#include "SoundManager.h"
     39#include <core/ConsoleCommandCompilation.h>
    3740
    3841namespace orxonox
     
    4447    {
    4548        RegisterObject(WorldSound);
     49        // WorldSound buffers should be pooled when they're not used anymore
     50        this->bPooling_ = true;
     51        this->registerVariables();
    4652    }
    4753
    48     WorldSound::~WorldSound()
     54    void WorldSound::registerVariables()
    4955    {
     56        registerVariable(volume_,   ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::volumeChanged));
     57        registerVariable(source_,   ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::sourceChanged));
     58        registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::loopingChanged));
     59        registerVariable(pitch_,    ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged));
     60        registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));
    5061    }
    5162
     
    5364    {
    5465        SUPER(WorldSound, XMLPort, xmlelement, mode);
    55         XMLPortParamExtern(WorldSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode);
    56         XMLPortParamExtern(WorldSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode);
    57         XMLPortParamExtern(WorldSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
     66        BaseSound::XMLPortExtern(xmlelement, mode);
    5867    }
    5968
     
    6271        SUPER(WorldSound, XMLEventPort, xmlelement, mode);
    6372        XMLPortEventState(WorldSound, BaseObject, "play", play, xmlelement, mode);
     73    }
     74
     75    void WorldSound::initialiseSource()
     76    {
     77        BaseSound::initialiseSource();
     78        if (this->getScene())
     79        {
     80            float refDist = this->getScene()->getSoundReferenceDistance();
     81            alSourcef(this->audioSource_, AL_REFERENCE_DISTANCE, refDist);
     82            // TODO: 500 is very magical here. Derive something better
     83            alSourcef(this->audioSource_, AL_MAX_DISTANCE, refDist * 500);
     84        }
     85        this->tick(0); // update position, orientation and velocity
    6486    }
    6587
     
    80102                COUT(2) << "Sound: OpenAL: Invalid sound velocity" << std::endl;
    81103
    82             const Quaternion& orient = this->getWorldOrientation();
    83             Vector3 at = orient.zAxis();
    84             alSource3f(this->audioSource_, AL_DIRECTION, at.x, at.y, at.z);
     104            const Vector3& direction = -this->getWorldOrientation().zAxis();
     105            alSource3f(this->audioSource_, AL_DIRECTION, direction.x, direction.y, direction.z);
    85106            error = alGetError();
    86107            if (error == AL_INVALID_VALUE)
     
    89110    }
    90111
     112    void WorldSound::changedActivity()
     113    {
     114        SUPER(WorldSound, changedActivity);
     115        if (this->isActive())
     116            this->play();
     117        else
     118            this->stop();
     119    }
     120
     121    float WorldSound::getRealVolume()
     122    {
     123        assert(GameMode::playsSound());
     124        return SoundManager::getInstance().getRealVolume(SoundType::Effects);
     125    }
    91126}
  • code/trunk/src/orxonox/sound/WorldSound.h

    r5929 r6417  
    2626 *
    2727 */
     28
    2829#ifndef _WorldSound_H__
    2930#define _WorldSound_H__
     
    4546    public:
    4647        WorldSound(BaseObject* creator);
    47         virtual ~WorldSound();
    4848
    49         virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    50         virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
     49        void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     50        void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
     51        void changedActivity();
    5152
    52         virtual void tick(float dt);
     53        void tick(float dt);
     54
     55    protected:
     56        ~WorldSound() {}
    5357
    5458    private:
     59        void registerVariables();
     60        void initialiseSource();
     61        float getRealVolume();
    5562    };
    5663}
  • code/trunk/src/orxonox/weaponsystem/WeaponMode.cc

    r5929 r6417  
    3232#include "core/CoreIncludes.h"
    3333#include "core/XMLPort.h"
     34#include "controllers/Controller.h"
     35#include "worldentities/pawns/Pawn.h"
    3436
    3537#include "Munition.h"
     
    3739#include "WeaponPack.h"
    3840#include "WeaponSystem.h"
     41#include "WeaponSlot.h"
     42
     43#include "sound/WorldSound.h"
    3944
    4045namespace orxonox
     
    6166
    6267        this->damage_ = 0;
     68
    6369        this->muzzleOffset_ = Vector3::ZERO;
     70        this->muzzlePosition_ = Vector3::ZERO;
     71        this->muzzleOrientation_ = Quaternion::IDENTITY;
     72
     73        if( GameMode::isMaster() )
     74        {
     75            this->defSndWpnFire_ = new WorldSound(this);
     76            this->defSndWpnFire_->setLooping(false);
     77            this->bSoundAttached_ = false;
     78        }
     79        else
     80            this->defSndWpnFire_ = 0;
    6481    }
    6582
    6683    WeaponMode::~WeaponMode()
    6784    {
     85        if (this->isInitialized())
     86        {
     87            if (this->defSndWpnFire_)
     88                this->defSndWpnFire_->destroy();
     89        }
    6890    }
    6991
     
    90112    {
    91113        (*reloadTime) = this->reloadTime_;
     114        if( !this->bSoundAttached_ && GameMode::isMaster() )
     115        {
     116            assert(this->getWeapon());
     117            this->getWeapon()->attach(this->defSndWpnFire_);
     118            this->bSoundAttached_ = true;
     119        }
    92120
    93121        if (!this->bReloading_ && this->munition_ && this->munition_->takeMunition(this->munitionPerShot_, this))
     
    108136            this->reloadTimer_.startTimer();
    109137
     138            if( this->defSndWpnFire_ && !(this->defSndWpnFire_->isPlaying()))
     139            {
     140                this->defSndWpnFire_->play();
     141            }
     142
    110143            this->fire();
    111144
     
    145178    {
    146179        this->munitionname_ = munitionname;
    147         this->munitiontype_ = ClassByString(this->munitionname_);
     180        Identifier* identifier = ClassByString(this->munitionname_);
     181        if (identifier)
     182            this->munitiontype_ = identifier;
     183        else
     184            COUT(2) << "Warning: No munition class defined in WeaponMode " << this->getName() << std::endl;
    148185        this->updateMunition();
    149186    }
     
    191228    void WeaponMode::reloaded()
    192229    {
     230        if( this->defSndWpnFire_ && this->defSndWpnFire_->isPlaying())
     231        {
     232            this->defSndWpnFire_->stop();
     233        }
    193234        this->bReloading_ = false;
    194235    }
    195236
    196     Vector3 WeaponMode::getMuzzlePosition() const
     237    void WeaponMode::computeMuzzleParameters(const Vector3& target)
    197238    {
    198239        if (this->weapon_)
    199             return (this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_);
    200         else
    201             return this->muzzleOffset_;
    202     }
    203 
    204     const Quaternion& WeaponMode::getMuzzleOrientation() const
     240        {
     241            this->muzzlePosition_ = this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_;
     242
     243            Vector3 muzzleDirection;
     244            muzzleDirection = target - this->muzzlePosition_;
     245//             COUT(0) << "muzzleDirection " << muzzleDirection << endl;
     246            this->muzzleOrientation_ = (this->weapon_->getWorldOrientation() * WorldEntity::FRONT).getRotationTo(muzzleDirection) * this->weapon_->getWorldOrientation();
     247        }
     248        else
     249        {
     250            this->muzzlePosition_ = this->muzzleOffset_;
     251            this->muzzleOrientation_ = Quaternion::IDENTITY;
     252        }
     253    }
     254
     255    Vector3 WeaponMode::getMuzzleDirection() const
    205256    {
    206257        if (this->weapon_)
    207             return this->weapon_->getWorldOrientation();
    208         else
    209             return Quaternion::IDENTITY;
    210     }
    211 
    212     Vector3 WeaponMode::getMuzzleDirection() const
    213     {
    214         if (this->weapon_)
    215             return (this->weapon_->getWorldOrientation() * WorldEntity::FRONT);
     258            return (this->getMuzzleOrientation() * WorldEntity::FRONT);
    216259        else
    217260            return WorldEntity::FRONT;
    218261    }
     262
     263    void WeaponMode::setDefaultSound(const std::string& soundPath)
     264    {
     265        if( this->defSndWpnFire_ )
     266            this->defSndWpnFire_->setSource(soundPath);
     267    }
     268
     269    const std::string& WeaponMode::getDefaultSound()
     270    {
     271        if( this->defSndWpnFire_ )
     272            return this->defSndWpnFire_->getSource();
     273        else
     274            return BLANKSTRING;
     275    }
    219276}
  • code/trunk/src/orxonox/weaponsystem/WeaponMode.h

    r5929 r6417  
    5151            bool fire(float* reloadTime);
    5252            bool reload();
     53
     54            // Interacting with the default Firing sound
     55            void setDefaultSound(const std::string& soundPath);
     56            const std::string& getDefaultSound();
    5357
    5458
     
    109113                { return this->muzzleOffset_; }
    110114
    111             Vector3 getMuzzlePosition() const;
    112             const Quaternion& getMuzzleOrientation() const;
     115            void computeMuzzleParameters(const Vector3& target);
     116            const Vector3& getMuzzlePosition() const
     117                { return this->muzzlePosition_; }
     118            const Quaternion& getMuzzleOrientation() const
     119                { return this->muzzleOrientation_; }
    113120            Vector3 getMuzzleDirection() const;
    114121
     
    124131            inline unsigned int getMode() const
    125132                { return this->mode_; }
     133
     134            Vector3 getTarget();
    126135
    127136        protected:
     
    152161            Timer reloadTimer_;
    153162            bool bReloading_;
     163
     164            Vector3 muzzlePosition_;
     165            Quaternion muzzleOrientation_;
     166
     167            WorldSound* defSndWpnFire_;
     168            bool        bSoundAttached_;
    154169    };
    155170}
  • code/trunk/src/orxonox/weaponsystem/WeaponPack.cc

    r5929 r6417  
    4949    WeaponPack::~WeaponPack()
    5050    {
    51         if (this->isInitialized() && this->weaponSystem_)
     51        if (this->isInitialized())
    5252        {
    53             this->weaponSystem_->removeWeaponPack(this);
     53            if( this->weaponSystem_ )
     54                this->weaponSystem_->removeWeaponPack(this);
    5455
    5556            while (!this->weapons_.empty())
     
    7172    void WeaponPack::fire(unsigned int weaponmode)
    7273    {
    73         for (std::set<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
     74        for (std::vector<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
    7475            (*it)->fire(weaponmode);
    7576    }
     
    7778    void WeaponPack::reload()
    7879    {
    79         for (std::set<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
     80        for (std::vector<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
    8081            (*it)->reload();
    8182    }
     
    8687            return;
    8788
    88         this->weapons_.insert(weapon);
     89        this->weapons_.push_back(weapon);
    8990        weapon->setWeaponPack(this);
    9091    }
     
    9596            return;
    9697
    97         this->weapons_.erase(weapon);
     98        std::vector<Weapon*>::iterator it = std::find(this->weapons_.begin(), this->weapons_.end(), weapon);
     99        assert(it != this->weapons_.end());
     100        this->weapons_.erase(it);
    98101        weapon->setWeaponPack(0);
    99102    }
     
    103106        unsigned int i = 0;
    104107
    105         for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
     108        for (std::vector<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
    106109        {
    107110            if (i == index)
     
    142145    void WeaponPack::notifyWeapons()
    143146    {
    144         for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
     147        for (std::vector<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
    145148            (*it)->setWeaponPack(this);
    146149    }
  • code/trunk/src/orxonox/weaponsystem/WeaponPack.h

    r5781 r6417  
    6969            void notifyWeapons();
    7070
    71             std::set<Weapon *> weapons_;
     71            std::vector<Weapon *> weapons_;
    7272            std::set<DefaultWeaponmodeLink *> links_;
    7373            WeaponSystem * weaponSystem_;
  • code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc

    r5929 r6417  
    202202        }
    203203
    204         this->weaponPacks_.insert(wPack);
     204        this->weaponPacks_.push_back(wPack);
    205205        wPack->setWeaponSystem(this);
    206206
     
    221221
    222222        // Remove the WeaponPack from the WeaponSystem
    223         this->weaponPacks_.erase(wPack);
     223        std::vector<WeaponPack*>::iterator it = std::find(this->weaponPacks_.begin(),this->weaponPacks_.end(), wPack);
     224        assert(it !=this->weaponPacks_.end());
     225        this->weaponPacks_.erase(it);
    224226    }
    225227
     
    227229    {
    228230        unsigned int i = 0;
    229         for (std::set<WeaponPack*>::const_iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it)
     231        for (std::vector<WeaponPack*>::const_iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it)
    230232        {
    231233            ++i;
     
    258260
    259261        // Check if the WeaponPack belongs to this WeaponSystem
    260         std::set<WeaponPack *>::iterator it1 = this->weaponPacks_.find(wPack);
     262        std::vector<WeaponPack *>::iterator it1 = std::find( this->weaponPacks_.begin(), this->weaponPacks_.end(), wPack );
    261263        if (it1 == this->weaponPacks_.end())
    262264            return;
  • code/trunk/src/orxonox/weaponsystem/WeaponSystem.h

    r5781 r6417  
    9292            std::map<unsigned int, WeaponSet *> weaponSets_;
    9393            std::vector<WeaponSlot *> weaponSlots_;
    94             std::set<WeaponPack *> weaponPacks_;
     94            std::vector<WeaponPack *> weaponPacks_;
    9595            std::map<Identifier *, Munition *> munitions_;
    9696            Pawn * pawn_;
  • code/trunk/src/orxonox/worldentities/CMakeLists.txt

    r5781 r6417  
    77
    88  BigExplosion.cc
     9  EffectContainer.cc
    910  ExplosionChunk.cc
    1011  CameraPosition.cc
  • code/trunk/src/orxonox/worldentities/ControllableEntity.cc

    r5929 r6417  
    3636#include "core/GameMode.h"
    3737#include "core/XMLPort.h"
     38#include "network/NetworkFunction.h"
    3839
    3940#include "Scene.h"
     
    4748{
    4849    CreateFactory(ControllableEntity);
     50
     51    registerMemberNetworkFunction( ControllableEntity, fire );
     52    registerMemberNetworkFunction( ControllableEntity, setTargetInternal );
    4953
    5054    ControllableEntity::ControllableEntity(BaseObject* creator) : MobileEntity(creator)
     
    6266        this->camera_ = 0;
    6367        this->xmlcontroller_ = 0;
     68        this->controller_ = 0;
    6469        this->reverseCamera_ = 0;
    6570        this->bDestroyWhenPlayerLeft_ = false;
    6671        this->cameraPositionRootNode_ = this->node_->createChildSceneNode();
     72        this->currentCameraPosition_ = 0;
    6773        this->bMouseLook_ = false;
    6874        this->mouseLookSpeed_ = 200;
     
    169175            {
    170176                this->cameraPositions_.front()->attachCamera(this->camera_);
     177                this->currentCameraPosition_ = this->cameraPositions_.front().get();
    171178            }
    172179            else if (this->cameraPositions_.size() > 0)
     
    178185                        ++it;
    179186                        if (it != this->cameraPositions_.end())
     187                        {
    180188                            (*it)->attachCamera(this->camera_);
     189                            this->currentCameraPosition_ = *it;
     190                        }
    181191                        else
     192                        {
    182193                            (*this->cameraPositions_.begin())->attachCamera(this->camera_);
     194                            this->currentCameraPosition_ = *this->cameraPositions_.begin();
     195                        }
    183196                        break;
    184197                    }
     
    188201            {
    189202                this->camera_->attachToNode(this->cameraPositionRootNode_);
     203                this->currentCameraPosition_ = 0;
    190204            }
    191205        }
     
    198212        if (!this->bMouseLook_)
    199213            this->cameraPositionRootNode_->setOrientation(Quaternion::IDENTITY);
     214        if (this->getCamera())
     215        {
     216            if (!this->bMouseLook_&& this->currentCameraPosition_->getDrag())
     217                this->getCamera()->setDrag(true);
     218            else
     219                this->getCamera()->setDrag(false);
     220        }
    200221    }
    201222
     
    216237        if (this->bMouseLook_)
    217238            this->cameraPositionRootNode_->roll(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL);
     239    }
     240
     241    void ControllableEntity::fire(unsigned int firemode)
     242    {
     243        if(GameMode::isMaster())
     244        {
     245            this->fired(firemode);
     246        }
     247        else
     248        {
     249            callMemberNetworkFunction(ControllableEntity, fire, this->getObjectID(), 0, firemode);
     250        }
     251    }
     252
     253    void ControllableEntity::setTarget( WorldEntity* target )
     254    {
     255        this->target_ = target;
     256        if ( !GameMode::isMaster() )
     257        {
     258            if ( target != 0 )
     259            {
     260                callMemberNetworkFunction(ControllableEntity, setTargetInternal, this->getObjectID(), 0, target->getObjectID() );
     261            }
     262           else
     263           {
     264                callMemberNetworkFunction(ControllableEntity, setTargetInternal, this->getObjectID(), 0, OBJECTID_UNKNOWN );
     265           }
     266        }
     267    }
     268
     269    void ControllableEntity::setTargetInternal( uint32_t targetID )
     270    {
     271        this->setTarget( orxonox_cast<WorldEntity*>(Synchronisable::getSynchronisable(targetID)) );
    218272    }
    219273
     
    279333            this->camera_ = new Camera(this);
    280334            this->camera_->requestFocus();
    281             if (this->cameraPositionTemplate_ != "")
     335            if (!this->cameraPositionTemplate_.empty())
    282336                this->addTemplate(this->cameraPositionTemplate_);
    283337            if (this->cameraPositions_.size() > 0)
     338            {
    284339                this->cameraPositions_.front()->attachCamera(this->camera_);
     340                this->currentCameraPosition_ = this->cameraPositions_.front();
     341            }
    285342            else
     343            {
    286344                this->camera_->attachToNode(this->cameraPositionRootNode_);
     345                this->currentCameraPosition_ = 0;
     346            }
    287347        }
    288348
    289349        if (!this->hud_ && GameMode::showsGraphics())
    290350        {
    291             if (this->hudtemplate_ != "")
     351            if (!this->hudtemplate_.empty())
    292352            {
    293353                this->hud_ = new OverlayGroup(this);
  • code/trunk/src/orxonox/worldentities/ControllableEntity.h

    r5929 r6417  
    8484                { this->rotateRoll(Vector2(value, 0)); }
    8585
    86             virtual void fire(unsigned int firemode) {}
     86            void fire(unsigned int firemode);
     87            virtual void fired(unsigned int firemode) {}
    8788            virtual void reload() {}
    8889
     
    139140            inline Controller* getXMLController() const
    140141                { return this->xmlcontroller_; }
     142
     143            inline Controller* getController() const
     144                { return this->controller_; }
     145            inline void setController(Controller* val)
     146                { this->controller_ = val; }
     147
     148            virtual void setTarget( WorldEntity* target );
     149            virtual WorldEntity* getTarget()
     150                { return this->target_.get(); }
     151            void setTargetInternal( uint32_t targetID );
    141152
    142153        protected:
     
    199210            Ogre::SceneNode* cameraPositionRootNode_;
    200211            std::list<SmartPtr<CameraPosition> > cameraPositions_;
     212            CameraPosition* currentCameraPosition_;
    201213            std::string cameraPositionTemplate_;
    202214            Controller* xmlcontroller_;
     215            Controller* controller_;
    203216            CameraPosition* reverseCamera_;
     217            WeakPtr<WorldEntity> target_;
    204218    };
    205219}
  • code/trunk/src/orxonox/worldentities/MovableEntity.cc

    r5929 r6417  
    7979            if (victim)
    8080            {
    81                 victim->damage(this->collisionDamage_ * (victim->getVelocity() - this->getVelocity()).length());
     81                float damage = this->collisionDamage_ * (victim->getVelocity() - this->getVelocity()).length();
     82                victim->hit(0, contactPoint, damage);
    8283            }
    8384        }
  • code/trunk/src/orxonox/worldentities/MovableEntity.h

    r5929 r6417  
    7070
    7171            inline void setEnableCollisionDamage(bool c)
    72             { 
    73                 this->enableCollisionDamage_ = c; 
     72            {
     73                this->enableCollisionDamage_ = c;
    7474                this->enableCollisionCallback();
    75             } 
     75            }
    7676
    7777            inline bool getEnableCollisionDamage()
  • code/trunk/src/orxonox/worldentities/StaticEntity.cc

    r5781 r6417  
    4242    {
    4343        RegisterObject(StaticEntity);
    44        
     44
    4545        this->setPriority(Priority::VeryLow);
    4646
  • code/trunk/src/orxonox/worldentities/WorldEntity.cc

    r5929 r6417  
    472472    //! Attaches an Ogre::MovableObject to this WorldEntity.
    473473    void WorldEntity::attachOgreObject(Ogre::MovableObject* object)
    474         { this->node_->attachObject(object); }
     474    {
     475        this->node_->attachObject(object);
     476        object->setUserObject(this);
     477    }
     478
    475479    void WorldEntity::attachOgreObject(Ogre::BillboardSet* object)
    476         { this->node_->attachObject(object); }
     480        { this->attachOgreObject(static_cast<Ogre::MovableObject*>(object)); }
    477481    void WorldEntity::attachOgreObject(Ogre::Camera* object)
    478         { this->node_->attachObject(object); }
     482        { this->attachOgreObject(static_cast<Ogre::MovableObject*>(object)); }
    479483    void WorldEntity::attachOgreObject(Ogre::Entity* object)
    480         { this->node_->attachObject(object); }
     484        { this->attachOgreObject(static_cast<Ogre::MovableObject*>(object)); }
    481485    void WorldEntity::attachOgreObject(Ogre::ParticleSystem* object)
    482         { this->node_->attachObject(object); }
     486        { this->attachOgreObject(static_cast<Ogre::MovableObject*>(object)); }
    483487
    484488    //! Detaches an Ogre::MovableObject from this WorldEntity.
    485489    void WorldEntity::detachOgreObject(Ogre::MovableObject* object)
    486         { this->node_->detachObject(object); }
     490    {
     491        object->setUserObject(NULL);
     492        this->node_->detachObject(object);
     493    }
     494
    487495    void WorldEntity::detachOgreObject(Ogre::BillboardSet* object)
    488         { this->node_->detachObject(object); }
     496        { this->detachOgreObject(static_cast<Ogre::MovableObject*>(object)); }
    489497    void WorldEntity::detachOgreObject(Ogre::Camera* object)
    490         { this->node_->detachObject(object); }
     498        { this->detachOgreObject(static_cast<Ogre::MovableObject*>(object)); }
    491499    void WorldEntity::detachOgreObject(Ogre::Entity* object)
    492         { this->node_->detachObject(object); }
     500        { this->detachOgreObject(static_cast<Ogre::MovableObject*>(object)); }
    493501    void WorldEntity::detachOgreObject(Ogre::ParticleSystem* object)
    494         { this->node_->detachObject(object); }
     502        { this->detachOgreObject(static_cast<Ogre::MovableObject*>(object)); }
    495503
    496504    //! Detaches an Ogre::MovableObject (by string) from this WorldEntity.
     
    646654    /**
    647655    @brief
    648         Makes this WorldEntity look a specific target location.
     656        Makes this WorldEntity look at a specific target location.
    649657    @param relativeTo
    650658        @see WorldEntity::TransformSpace
     
    806814    void WorldEntity::setCollisionTypeStr(const std::string& typeStr)
    807815    {
    808         std::string typeStrLower = getLowercase(typeStr);
     816        const std::string& typeStrLower = getLowercase(typeStr);
    809817        CollisionType type;
    810818        if (typeStrLower == "dynamic")
     
    913921    }
    914922
    915     //! Copies our own parameters for restitution, angular factor, dampings and friction to the bullet rigid body.
     923    //! Copies our own parameters for restitution, angular factor, damping and friction to the bullet rigid body.
    916924    void WorldEntity::internalSetPhysicsProps()
    917925    {
  • code/trunk/src/orxonox/worldentities/WorldEntity.h

    r5781 r6417  
    3333#include "OrxonoxPrereqs.h"
    3434
     35#include <OgreUserDefinedObject.h>
    3536#ifdef ORXONOX_RELEASE
    3637#  include <OgreSceneNode.h>
     
    5556
    5657        The basic task of the WorldEntity is provide a location, a direction and a scaling and the possibility
    57         to create an entire hierarchy of derivated objects.
     58        to create an entire hierarchy of derived objects.
    5859        It is also the basis for the physics interface to the Bullet physics engine.
    5960        Every WorldEntity can have a specific collision type: @see CollisionType
     
    6364        There is also support for attaching WorldEntities with physics to each other. Currently, the collision shape
    6465        of both objects simply get merged into one larger shape (for static collision type).
    65         The phyiscal body that is internally stored and administrated has the following supported properties:
    66         - Restitution, angular factor, linear damping, angular damping, fricition, mass and collision shape.
     66        The physical body that is internally stored and administrated has the following supported properties:
     67        - Restitution, angular factor, linear damping, angular damping, friction, mass and collision shape.
    6768        You can get more information at the corresponding set function.
    6869
    6970        Collision shapes: These are controlled by the internal WorldEntityCollisionShape. @see WorldEntityCollisionShape.
    7071    */
    71     class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState
     72    class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState, public Ogre::UserDefinedObject
    7273    {
    7374        friend class Scene;
     
    318319                Sets an artificial parameter that tells how much torque is applied when you apply a non-central force.
    319320
    320                 Normally the angular factor is 1, which means it's physically 'correct'. Howerver if you have a player
     321                Normally the angular factor is 1, which means it's physically 'correct'. However if you have a player
    321322                character that should not rotate when hit sideways, you can set the angular factor to 0.
    322323            */
     
    394395                You can override this function in a derived class to constrain the collision to e.g. None or Dynamic.
    395396                A projectile may not prove very useful if there is no physical body. Simply set the CollisionType
    396                 in its constructor and override this method. But be careful that a derived classe's virtual functions
     397                in its constructor and override this method. But be careful that a derived class's virtual functions
    397398                don't yet exist in the constructor if a base class.
    398399            */
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r5929 r6417  
    3838#include "PawnManager.h"
    3939#include "infos/PlayerInfo.h"
     40#include "controllers/Controller.h"
    4041#include "gametypes/Gametype.h"
    4142#include "graphics/ParticleSpawner.h"
     
    5253    CreateFactory(Pawn);
    5354
    54     registerMemberNetworkFunction( Pawn, doFire );
    55 
    5655    Pawn::Pawn(BaseObject* creator) : ControllableEntity(creator)
    5756    {
     
    6968
    7069        this->spawnparticleduration_ = 3.0f;
     70
     71        this->aimPosition_ = Vector3::ZERO;
    7172
    7273        this->getPickups().setOwner(this);
     
    110111        XMLPortObject(Pawn, WeaponSlot, "weaponslots", addWeaponSlot, getWeaponSlot, xmlelement, mode);
    111112        XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode);
    112         XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPack, getWeaponPack, xmlelement, mode);
     113        XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode);
    113114    }
    114115
     
    119120        registerVariable(this->initialHealth_, VariableDirection::ToClient);
    120121        registerVariable(this->bReload_,       VariableDirection::ToServer);
     122        registerVariable(this->aimPosition_,   Bidirectionality::ServerMaster, 0, true);
    121123    }
    122124
     
    166168    void Pawn::hit(Pawn* originator, const Vector3& force, float damage)
    167169    {
    168         if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator))
     170        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    169171        {
    170172            this->damage(damage, originator);
     
    175177    }
    176178
     179    void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     180    {
     181        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
     182        {
     183            this->damage(damage, originator);
     184
     185            if ( this->getController() )
     186                this->getController()->hit(originator, contactpoint, damage);
     187
     188            // play hit effect
     189        }
     190    }
     191
    177192    void Pawn::kill()
    178193    {
     
    184199    {
    185200        // play spawn effect
    186         if (this->spawnparticlesource_ != "")
     201        if (!this->spawnparticlesource_.empty())
    187202        {
    188203            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     
    263278    }
    264279
    265     void Pawn::fire(unsigned int firemode)
    266     {
    267         this->doFire(firemode);
    268     }
    269 
    270     void Pawn::doFire(uint8_t firemode)
    271     {
    272         if(GameMode::isMaster())
    273         {
    274             if (this->weaponSystem_)
    275                 this->weaponSystem_->fire(firemode);
    276         }
    277         else
    278         {
    279             callMemberNetworkFunction(Pawn, doFire, this->getObjectID(), 0, firemode);
    280             if (this->weaponSystem_)
    281                 this->weaponSystem_->fire(firemode);
    282         }
     280    void Pawn::fired(unsigned int firemode)
     281    {
     282        if (this->weaponSystem_)
     283            this->weaponSystem_->fire(firemode);
    283284    }
    284285
     
    341342    }
    342343
     344    void Pawn::addWeaponPackXML(WeaponPack * wPack)
     345    {
     346        if (this->weaponSystem_)
     347            if (!this->weaponSystem_->addWeaponPack(wPack))
     348                wPack->destroy();
     349    }
     350
    343351    WeaponPack * Pawn::getWeaponPack(unsigned int index) const
    344352    {
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.h

    r5781 r6417  
    7575                { return this->lastHitOriginator_; }
    7676
    77             virtual void damage(float damage, Pawn* originator = 0);
    7877            virtual void hit(Pawn* originator, const Vector3& force, float damage);
     78            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
    7979            virtual void kill();
    8080
    81             virtual void fire(unsigned int firemode);
     81            virtual void fired(unsigned int firemode);
    8282            virtual void reload();
    83             virtual void doFire(uint8_t firemode);
    8483            virtual void postSpawn();
    8584
     
    8988            WeaponSet * getWeaponSet(unsigned int index) const;
    9089            void addWeaponPack(WeaponPack * wPack);
     90            void addWeaponPackXML(WeaponPack * wPack);
    9191            WeaponPack * getWeaponPack(unsigned int index) const;
    9292
     
    117117            virtual void startLocalHumanControl();
    118118
     119            void setAimPosition( Vector3 position )
     120                { this->aimPosition_ = position; }
     121            Vector3 getAimPosition()
     122                { return this->aimPosition_; }
     123
    119124        protected:
    120125            virtual void setPlayer(PlayerInfo* player);
     
    125130            virtual void deatheffect();
    126131            virtual void spawneffect();
     132
     133            virtual void damage(float damage, Pawn* originator = 0);
    127134
    128135            bool bAlive_;
     
    146153            inline void setWeaponSystem(WeaponSystem* weaponsystem)
    147154                { this->weaponSystem_ = weaponsystem; }
     155
     156            Vector3 aimPosition_;
    148157    };
    149158}
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc

    r5929 r6417  
    187187    void SpaceShip::loadEngineTemplate()
    188188    {
    189         if (this->enginetemplate_ != "")
     189        if (!this->enginetemplate_.empty())
    190190        {
    191191            Template* temp = Template::getTemplate(this->enginetemplate_);
  • code/trunk/src/orxonox/worldentities/pawns/Spectator.cc

    r5929 r6417  
    189189    }
    190190
    191     void Spectator::fire(unsigned int firemode)
     191    void Spectator::fired(unsigned int firemode)
    192192    {
    193193        if (this->getPlayer())
  • code/trunk/src/orxonox/worldentities/pawns/Spectator.h

    r5781 r6417  
    5555            virtual void rotateRoll(const Vector2& value);
    5656
    57             virtual void fire(unsigned int firemode);
     57            virtual void fired(unsigned int firemode);
    5858            virtual void greet();
    5959
Note: See TracChangeset for help on using the changeset viewer.