Changeset 6417 for code/trunk/src/orxonox
- Timestamp:
- Dec 25, 2009, 10:23:58 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 deleted
- 89 edited
- 10 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/CMakeLists.txt
r5929 r6417 28 28 LevelManager.cc 29 29 Main.cc 30 MoodManager.cc 30 31 PawnManager.cc 31 32 PlayerManager.cc … … 55 56 TOLUA_FILES 56 57 LevelManager.h 58 MoodManager.h 59 controllers/HumanController.h 57 60 pickup/BaseItem.h 58 61 pickup/PickupInventory.h 62 sound/SoundManager.h 59 63 DEFINE_SYMBOL 60 64 "ORXONOX_SHARED_BUILD" -
code/trunk/src/orxonox/CameraManager.cc
r5929 r6417 45 45 namespace orxonox 46 46 { 47 CameraManager* CameraManager::singletonPtr_s = 0;48 47 ManageScopedSingleton(CameraManager, ScopeID::Graphics, false); 49 48 -
code/trunk/src/orxonox/Level.cc
r5929 r6417 141 141 void Level::playerEntered(PlayerInfo* player) 142 142 { 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; 144 144 player->setGametype(this->getGametype()); 145 145 } … … 147 147 void Level::playerLeft(PlayerInfo* player) 148 148 { 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; 150 150 player->setGametype(0); 151 151 } -
code/trunk/src/orxonox/LevelManager.cc
r6021 r6417 30 30 31 31 #include <map> 32 #include <OgreResourceGroupManager.h>33 32 34 33 #include "core/CommandLineParser.h" … … 36 35 #include "core/CoreIncludes.h" 37 36 #include "core/Loader.h" 37 #include "core/Resource.h" 38 38 #include "core/ScopedSingletonManager.h" 39 39 #include "PlayerManager.h" … … 44 44 SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)"); 45 45 46 LevelManager* LevelManager::singletonPtr_s = 0;47 46 ManageScopedSingleton(LevelManager, ScopeID::Root, false); 48 47 … … 66 65 { 67 66 SetConfigValue(defaultLevelName_, "presentation_dm.oxw") 68 .description("Sets the pre selection of the level in the main menu.");67 .description("Sets the pre selection of the level in the main menu."); 69 68 } 70 69 … … 123 122 } 124 123 125 std::stringLevelManager::getAvailableLevelListItem(unsigned int index) const124 const std::string& LevelManager::getAvailableLevelListItem(unsigned int index) const 126 125 { 127 126 if (index >= availableLevels_.size()) 128 return std::string();127 return BLANKSTRING; 129 128 else 130 129 return availableLevels_[index]; … … 133 132 void LevelManager::compileAvailableLevelList() 134 133 { 135 availableLevels_.clear(); 136 137 availableLevels_ = *Ogre::ResourceGroupManager::getSingleton().findResourceNames( 138 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "*.oxw"); 139 134 availableLevels_ = *Resource::findResourceNames("*.oxw"); 140 135 for (std::vector<std::string>::iterator it = availableLevels_.begin(); it != availableLevels_.end();) 141 136 if (it->find("old/") == 0) -
code/trunk/src/orxonox/LevelManager.h
r5781 r6417 60 60 const std::string& getDefaultLevel() const; //tolua_export 61 61 void compileAvailableLevelList(); //tolua_export 62 std::stringgetAvailableLevelListItem(unsigned int index) const; //tolua_export62 const std::string& getAvailableLevelListItem(unsigned int index) const; //tolua_export 63 63 64 64 static LevelManager* getInstancePtr() { return singletonPtr_s; } -
code/trunk/src/orxonox/OrxonoxPrereqs.h
r5929 r6417 152 152 class AmbientSound; 153 153 class BaseSound; 154 class SoundBuffer; 154 155 class SoundManager; 156 class SoundStreamer; 155 157 class WorldSound; 156 158 … … 169 171 class CameraPosition; 170 172 class ControllableEntity; 173 class EffectContainer; 171 174 class ExplosionChunk; 172 175 class MobileEntity; … … 176 179 class TeamSpawnPoint; 177 180 class WorldEntity; 181 class Rocket; 178 182 // worldentities, pawns 179 183 class Destroyer; … … 209 213 typedef unsigned int ALuint; 210 214 typedef int ALint; 215 typedef int ALenum; 211 216 212 217 #endif /* _OrxonoxPrereqs_H__ */ -
code/trunk/src/orxonox/PlayerManager.cc
r5966 r6417 38 38 namespace orxonox 39 39 { 40 PlayerManager* PlayerManager::singletonPtr_s = 0;41 40 ManageScopedSingleton(PlayerManager, ScopeID::Root, false); 42 41 … … 91 90 } 92 91 } 93 92 94 93 void PlayerManager::disconnectAllClients() 95 94 { -
code/trunk/src/orxonox/Radar.cc
r5929 r6417 40 40 #include "core/ObjectList.h" 41 41 #include "interfaces/RadarListener.h" 42 #include "controllers/HumanController.h" 43 #include "worldentities/pawns/Pawn.h" 42 44 43 45 namespace orxonox … … 45 47 46 48 Radar::Radar() 47 : focus_(0) 49 : itFocus_(0) 50 , focus_(0) 48 51 , objectTypeCounter_(0) 49 52 { … … 82 85 } 83 86 84 RadarViewable::Shape Radar::addObjectDescription(const std::string name)87 RadarViewable::Shape Radar::addObjectDescription(const std::string& name) 85 88 { 86 89 std::map<std::string, RadarViewable::Shape>::iterator it = this->objectTypes_.find(name); … … 118 121 void Radar::cycleFocus() 119 122 { 120 if (ObjectList<RadarViewable>::begin() == 0)123 if (ObjectList<RadarViewable>::begin() == ObjectList<RadarViewable>::end()) 121 124 { 122 125 // list is empty … … 124 127 this->focus_ = 0; 125 128 } 126 /* 127 else if ( this->owner_)129 130 else if (HumanController::getLocalControllerEntityAsPawn()) 128 131 { 129 Vector3 localPosition = this->owner_->getPosition();132 Vector3 localPosition = HumanController::getLocalControllerEntityAsPawn()->getWorldPosition(); 130 133 Vector3 targetPosition = localPosition; 131 if ( *(this->itFocus_))134 if (this->itFocus_ && *(this->itFocus_)) 132 135 targetPosition = this->itFocus_->getRVWorldPosition(); 133 136 134 // find the close dobject further away than targetPosition137 // find the closest object further away than targetPosition 135 138 float currentDistance = localPosition.squaredDistance(targetPosition); 136 139 float nextDistance = FLT_MAX; … … 140 143 for (ObjectList<RadarViewable>::iterator it = ObjectList<RadarViewable>::begin(); it; ++it) 141 144 { 142 if (*it == static_cast<RadarViewable*>( this)->owner_)145 if (*it == static_cast<RadarViewable*>(HumanController::getLocalControllerEntityAsPawn())) 143 146 continue; 144 147 … … 167 170 } 168 171 } 169 */170 172 } 171 173 -
code/trunk/src/orxonox/Radar.h
r5929 r6417 55 55 56 56 const RadarViewable* getFocus(); 57 RadarViewable::Shape addObjectDescription(const std::string name);57 RadarViewable::Shape addObjectDescription(const std::string& name); 58 58 59 59 void listObjects() const; -
code/trunk/src/orxonox/Scene.cc
r6064 r6417 58 58 this->setScene(SmartPtr<Scene>(this, false), OBJECTID_UNKNOWN); 59 59 this->bShadows_ = true; 60 this->soundReferenceDistance_ = 20.0; 60 61 61 62 if (GameMode::showsGraphics()) … … 113 114 XMLPortParam(Scene, "ambientlight", setAmbientLight, getAmbientLight, xmlelement, mode).defaultValues(ColourValue(0.2f, 0.2f, 0.2f, 1.0f)); 114 115 XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true); 116 XMLPortParam(Scene, "soundReferenceDistance", setSoundReferenceDistance, getSoundReferenceDistance, xmlelement, mode); 115 117 116 118 XMLPortParam(Scene, "gravity", setGravity, getGravity, xmlelement, mode); … … 334 336 { 335 337 // 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()); 340 340 341 341 // false means that bullet will assume we didn't modify the contact -
code/trunk/src/orxonox/Scene.h
r5929 r6417 71 71 { return this->bShadows_; } 72 72 73 inline void setSoundReferenceDistance(float distance) 74 { this->soundReferenceDistance_ = distance; } 75 inline float getSoundReferenceDistance() const 76 { return this->soundReferenceDistance_; } 77 73 78 inline Radar* getRadar() 74 79 { return this->radar_; } 75 80 76 81 inline virtual uint32_t getSceneID() const { return this->getObjectID(); } 77 82 … … 96 101 std::list<BaseObject*> objects_; 97 102 bool bShadows_; 103 float soundReferenceDistance_; 98 104 Radar* radar_; 99 105 -
code/trunk/src/orxonox/Test.cc
r6084 r6417 38 38 CreateFactory ( Test ); 39 39 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); 46 46 47 47 … … 50 50 // NetworkFunctionBase* NETWORK_FUNCTION_TEST_C = new NetworkFunctionStatic( createFunctor(&Test::printV1), "bla", NETWORK_FUNCTION_POINTER ); 51 51 52 registerStaticNetworkFunction( &Test::printV1 );53 registerMemberNetworkFunction( Test, checkU1 );54 registerMemberNetworkFunction( Test, printBlaBla );52 registerStaticNetworkFunction( &Test::printV1 ); 53 registerMemberNetworkFunction( Test, checkU1 ); 54 registerMemberNetworkFunction( Test, printBlaBla ); 55 55 56 Test* Test::instance_ = 0;56 Test* Test::instance_ = 0; 57 57 58 58 Test::Test(BaseObject* creator) : BaseObject(creator), Synchronisable(creator) 59 59 { 60 assert(instance_==0);61 instance_=this;60 assert(instance_==0); 61 instance_=this; 62 62 RegisterObject ( Test ); 63 setConfigValues();64 registerVariables();63 setConfigValues(); 64 registerVariables(); 65 65 setSyncMode(0x3); 66 this->pointer_ = 0; 66 67 } 67 68 68 69 Test::~Test() 69 70 { 70 instance_=0;71 instance_=0; 71 72 } 72 73 … … 74 75 { 75 76 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 )*/; 79 80 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 )*/; 84 85 } 85 86 86 87 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 ); 93 94 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 } 99 102 100 103 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 } 105 108 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 } 110 113 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; } 139 142 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; } 144 149 145 150 } -
code/trunk/src/orxonox/Test.h
r5781 r6417 76 76 void checkS4(); 77 77 78 void printPointer(); 79 78 80 static void printV1(){ instance_->checkU1(); } 79 81 static void printV2(){ instance_->checkU2(); } … … 94 96 TYPE s4; 95 97 98 Test* pointer_; 99 96 100 static Test* instance_; 97 101 }; -
code/trunk/src/orxonox/controllers/ArtificialController.cc
r5929 r6417 46 46 this->bHasTargetPosition_ = false; 47 47 this->targetPosition_ = Vector3::ZERO; 48 48 49 49 this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this)); 50 50 } … … 143 143 this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getPosition(), hardcoded_projectile_speed, this->target_->getPosition(), this->target_->getVelocity()); 144 144 this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO); 145 146 Pawn* pawn = dynamic_cast<Pawn*>(this->getControllableEntity()); 147 if (pawn) 148 pawn->setAimPosition(this->targetPosition_); 145 149 } 146 150 -
code/trunk/src/orxonox/controllers/ArtificialController.h
r5929 r6417 42 42 ArtificialController(BaseObject* creator); 43 43 virtual ~ArtificialController(); 44 44 45 45 void abandonTarget(Pawn* target); 46 46 -
code/trunk/src/orxonox/controllers/CMakeLists.txt
r5781 r6417 2 2 Controller.cc 3 3 HumanController.cc 4 NewHumanController.cc 4 5 ArtificialController.cc 5 6 AIController.cc -
code/trunk/src/orxonox/controllers/Controller.cc
r5781 r6417 29 29 #include "Controller.h" 30 30 #include "core/CoreIncludes.h" 31 #include "worldentities/ControllableEntity.h" 31 32 32 33 namespace orxonox … … 40 41 this->player_ = 0; 41 42 this->controllableEntity_ = 0; 43 this->bGodMode_ = false; 42 44 } 43 45 -
code/trunk/src/orxonox/controllers/Controller.h
r5781 r6417 37 37 class _OrxonoxExport Controller : public BaseObject 38 38 { 39 // set friend classes to access setControllableEntity 40 friend class PlayerInfo; 41 friend class ControllableEntity; 42 39 43 public: 40 44 Controller(BaseObject* creator); … … 46 50 { return this->player_; } 47 51 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) 48 63 inline void setControllableEntity(ControllableEntity* entity) 49 64 { … … 54 69 } 55 70 } 56 inline ControllableEntity* getControllableEntity() const57 { return this->controllableEntity_; }58 virtual void changedControllableEntity() {}59 71 60 72 protected: 61 73 PlayerInfo* player_; 62 74 ControllableEntity* controllableEntity_; 75 private: 76 bool bGodMode_; 63 77 }; 64 78 } -
code/trunk/src/orxonox/controllers/HumanController.cc
r5929 r6417 36 36 #include "infos/PlayerInfo.h" 37 37 #include "overlays/Map.h" 38 #include "graphics/Camera.h"39 #include "sound/SoundManager.h"40 38 #include "Radar.h" 41 39 #include "Scene.h" … … 56 54 SetConsoleCommand(HumanController, mouseLook, true); 57 55 SetConsoleCommand(HumanController, suicide, true); 56 SetConsoleCommand(HumanController, toggleGodMode, true); 58 57 SetConsoleCommand(HumanController, addBots, true).defaultValues(1); 59 58 SetConsoleCommand(HumanController, killBots, true).defaultValues(0); … … 71 70 RegisterObject(HumanController); 72 71 72 controlPaused_ = false; 73 73 74 HumanController::localController_s = this; 74 75 } … … 83 84 if (GameMode::playsSound() && HumanController::localController_s && HumanController::localController_s->controllableEntity_) 84 85 { 85 // Update sound listener86 86 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) 93 88 COUT(3) << "HumanController, Warning: Using a ControllableEntity without Camera" << std::endl; 94 89 } … … 97 92 void HumanController::moveFrontBack(const Vector2& value) 98 93 { 94 if (HumanController::localController_s) 95 HumanController::localController_s->frontback(value); 96 } 97 98 void HumanController::frontback(const Vector2& value) 99 { 99 100 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 100 101 HumanController::localController_s->controllableEntity_->moveFrontBack(value); … … 113 114 } 114 115 115 void HumanController:: rotateYaw(const Vector2& value)116 void HumanController::yaw(const Vector2& value) 116 117 { 117 118 //Hack to enable mouselook in map … … 125 126 } 126 127 127 void HumanController:: rotatePitch(const Vector2& value)128 void HumanController::pitch(const Vector2& value) 128 129 { 129 130 //Hack to enable mouselook in map … … 137 138 } 138 139 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 139 152 void HumanController::rotateRoll(const Vector2& value) 140 153 { … … 144 157 145 158 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) 146 165 { 147 166 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) … … 191 210 } 192 211 212 void HumanController::toggleGodMode() 213 { 214 HumanController::getLocalControllerSingleton()->setGodMode( !HumanController::getLocalControllerSingleton()->getGodMode() ); 215 } 216 193 217 void HumanController::useItem() 194 218 { … … 234 258 HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus(); 235 259 } 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 } 236 272 } -
code/trunk/src/orxonox/controllers/HumanController.h
r5929 r6417 35 35 #include "Controller.h" 36 36 37 // tolua_begin 37 38 namespace orxonox 38 39 { 39 class _OrxonoxExport HumanController : public Controller, public Tickable 40 { 40 class _OrxonoxExport HumanController 41 // tolua_end 42 : public Controller, public Tickable 43 { // tolua_export 41 44 public: 42 45 HumanController(BaseObject* creator); … … 53 56 static void rotateRoll(const Vector2& value); 54 57 58 virtual void frontback(const Vector2& value); 59 virtual void yaw(const Vector2& value); 60 virtual void pitch(const Vector2& value); 61 55 62 static void fire(unsigned int firemode); 63 virtual void doFire(unsigned int firemode); 56 64 static void reload(); 57 65 … … 66 74 67 75 static void suicide(); 76 static void toggleGodMode(); 68 77 69 78 static void addBots(unsigned int amount); 70 79 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() {}; 71 85 72 86 static inline HumanController* getLocalControllerSingleton() … … 76 90 friend class Map; 77 91 78 pr ivate:92 protected: 79 93 static HumanController* localController_s; 80 }; 81 } 94 bool controlPaused_; 95 }; // tolua_export 96 } // tolua_export 82 97 83 98 #endif /* _HumanController_H__ */ -
code/trunk/src/orxonox/gamestates/GSGraphics.cc
r5929 r6417 64 64 void GSGraphics::activate() 65 65 { 66 // add console command to toggle GUI 67 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI")); 66 68 67 } 69 68 … … 78 77 } 79 78 80 /**81 @brief82 Toggles the visibility of the current GUI83 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 92 79 void GSGraphics::update(const Clock& time) 93 80 { -
code/trunk/src/orxonox/gamestates/GSGraphics.h
r5929 r6417 57 57 void update(const Clock& time); 58 58 59 void toggleGUI();60 61 59 private: 62 60 }; -
code/trunk/src/orxonox/gamestates/GSLevel.cc
r5966 r6417 56 56 , guiKeysOnlyInputState_(0) 57 57 , startFile_(0) 58 , bShowIngameGUI_(false) 58 59 { 59 60 } … … 78 79 guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly"); 79 80 guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr()); 80 81 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSLevel::showIngameGUI, this), "showIngameGUI"));82 81 } 83 82 … … 91 90 // level is loaded: we can start capturing the input 92 91 InputManager::getInstance().enterState("game"); 93 92 94 93 // connect the HumanPlayer to the game 95 94 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 else108 {109 GUIManager::getInstance().executeCode("hideGUI(\"inGameTest\")");110 GUIManager::getInstance().executeCode("hideCursor()");111 InputManager::getInstance().leaveState("guiMouseOnly");112 95 } 113 96 } … … 122 105 InputManager::getInstance().leaveState("game"); 123 106 } 124 107 125 108 // disconnect all HumanPlayers 126 109 PlayerManager::getInstance().disconnectAllClients(); … … 152 135 for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it) 153 136 this->staticObjects_.insert(*it); 154 137 155 138 // call the loader 156 139 COUT(0) << "Loading level..." << std::endl; … … 171 154 if (find == this->staticObjects_.end()) 172 155 { 173 COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << ")"<< std::endl;156 COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << ')' << std::endl; 174 157 } 175 158 } -
code/trunk/src/orxonox/gamestates/GSLevel.h
r5929 r6417 52 52 void loadLevel(); 53 53 void unloadLevel(); 54 void showIngameGUI(bool show);55 54 56 55 InputState* gameInputState_; //!< input state for normal ingame playing … … 60 59 XMLFile* startFile_; 61 60 std::set<BaseObject*> staticObjects_; 61 bool bShowIngameGUI_; 62 62 }; 63 63 } -
code/trunk/src/orxonox/gamestates/GSMainMenu.cc
r6105 r6417 36 36 #include "core/Game.h" 37 37 #include "core/ConsoleCommand.h" 38 #include "core/ConfigValueIncludes.h" 39 #include "core/CoreIncludes.h" 38 40 #include "core/GraphicsManager.h" 39 41 #include "core/GUIManager.h" … … 49 51 , inputState_(0) 50 52 { 53 RegisterRootObject(GSMainMenu); 51 54 inputState_ = InputManager::getInstance().createInputState("mainMenu"); 52 55 inputState_->setMouseMode(MouseMode::Nonexclusive); … … 64 67 // Load sound 65 68 this->ambient_ = new AmbientSound(0); 66 this->ambient_->setS ource("ambient/mainmenu.wav");69 this->ambient_->setSyncMode(0x0); 67 70 } 68 71 } … … 71 74 { 72 75 if (GameMode::playsSound()) 73 delete this->ambient_;76 this->ambient_->destroy(); 74 77 75 78 InputManager::getInstance().destroyState("mainMenu"); … … 82 85 { 83 86 // show main menu 84 GUIManager::getInstance().showGUI("MainMenu" );87 GUIManager::getInstance().showGUI("MainMenu", true, GraphicsManager::getInstance().isFullScreen()); 85 88 GUIManager::getInstance().setCamera(this->camera_); 89 GUIManager::getInstance().setBackground("MainMenuBackground"); 90 // GUIManager::getInstance().setBackground(""); 86 91 GraphicsManager::getInstance().setCamera(this->camera_); 87 92 … … 92 97 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu), "startMainMenu")); 93 98 99 // create command to change sound path 100 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::setMainMenuSoundPath, this), "setMMSoundPath")); 101 94 102 KeyBinderManager::getInstance().setToDefault(); 95 103 InputManager::getInstance().enterState("mainMenu"); 96 104 105 this->setConfigValues(); 106 97 107 if (GameMode::playsSound()) 98 108 { 99 this->ambient_->setLoop (true);100 this->ambient_->play(); 109 this->ambient_->setLooping(true); 110 this->ambient_->play(); // works without source 101 111 } 102 112 } … … 112 122 113 123 GUIManager::getInstance().setCamera(0); 124 GUIManager::getInstance().setBackground(""); 125 GUIManager::hideGUI("MainMenu"); 114 126 GraphicsManager::getInstance().setCamera(0); 115 127 } … … 117 129 void GSMainMenu::update(const Clock& time) 118 130 { 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); 119 156 } 120 157 -
code/trunk/src/orxonox/gamestates/GSMainMenu.h
r5929 r6417 34 34 #include "util/OgreForwardRefs.h" 35 35 #include "core/GameState.h" 36 #include "core/OrxonoxClass.h" 36 37 37 38 namespace orxonox 38 39 { 39 class _OrxonoxExport GSMainMenu : public GameState 40 class _OrxonoxExport GSMainMenu : public GameState, public OrxonoxClass 40 41 { 41 42 public: … … 46 47 void deactivate(); 47 48 void update(const Clock& time); 49 50 void setConfigValues(); 51 void reloadSound(); 52 const std::string& getMainMenuSoundPath(); 53 void setMainMenuSoundPath(const std::string& path); 48 54 49 55 static void startStandalone(); … … 61 67 // ambient sound for the main menu 62 68 AmbientSound* ambient_; 69 std::string soundPathMain_; 63 70 }; 64 71 } -
code/trunk/src/orxonox/gamestates/GSRoot.cc
r6105 r6417 30 30 31 31 #include "util/Clock.h" 32 #include "core/BaseObject.h" 32 33 #include "core/ConsoleCommand.h" 33 34 #include "core/Game.h" … … 45 46 GSRoot::GSRoot(const GameStateInfo& info) 46 47 : GameState(info) 47 , timeFactor_(1.0f)48 48 , bPaused_(false) 49 49 , timeFactorPauseBackup_(1.0f) … … 55 55 NetworkFunctionBase::destroyAllNetworkFunctions(); 56 56 } 57 57 58 58 void GSRoot::printObjects() 59 59 { 60 60 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)) 63 64 COUT(0) << "object: " << it->getIdentifier()->getName() << " id: " << dynamic_cast<Synchronisable*>(*it)->getObjectID() << std::endl; 64 65 else … … 67 68 } 68 69 COUT(0) << "currently got " << nr << " objects" << std::endl; 69 70 70 } 71 71 … … 73 73 { 74 74 // reset game speed to normal 75 this->timeFactor_ = 1.0f;75 TimeFactorListener::setTimeFactor(1.0f); 76 76 77 77 // time factor console command … … 91 91 { 92 92 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 } 94 98 95 99 /*** HACK *** HACK ***/ … … 101 105 leveldt = 0.0f; 102 106 } 107 float realdt = leveldt * TimeFactorListener::getTimeFactor(); 103 108 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 } 105 114 /*** HACK *** HACK ***/ 106 115 } … … 119 128 if (!this->bPaused_) 120 129 { 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); 127 131 } 128 132 else … … 137 141 if (!this->bPaused_) 138 142 { 139 this->timeFactorPauseBackup_ = this->timeFactor_;143 this->timeFactorPauseBackup_ = TimeFactorListener::getTimeFactor(); 140 144 this->setTimeFactor(0.0f); 141 145 this->bPaused_ = true; … … 148 152 } 149 153 } 154 155 float GSRoot::getTimeFactor() 156 { 157 return TimeFactorListener::getTimeFactor(); 158 } 150 159 } -
code/trunk/src/orxonox/gamestates/GSRoot.h
r5929 r6417 51 51 void setTimeFactor(float factor); 52 52 void pause(); 53 float getTimeFactor() { return this->timeFactor_; }53 float getTimeFactor(); 54 54 55 55 private: 56 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal.57 56 bool bPaused_; 58 57 float timeFactorPauseBackup_; -
code/trunk/src/orxonox/gametypes/Asteroids.cc
r5929 r6417 72 72 Gametype::start(); 73 73 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..."); 75 75 COUT(0) << message << std::endl; 76 76 Host::Broadcast(message); … … 81 81 Gametype::end(); 82 82 83 std::string message = "The match has ended.";83 std::string message("The match has ended."); 84 84 COUT(0) << message << std::endl; 85 85 Host::Broadcast(message); -
code/trunk/src/orxonox/gametypes/Deathmatch.cc
r5781 r6417 47 47 Gametype::start(); 48 48 49 std::string message = "The match has started!";49 std::string message("The match has started!"); 50 50 COUT(0) << message << std::endl; 51 51 Host::Broadcast(message); … … 56 56 Gametype::end(); 57 57 58 std::string message = "The match has ended.";58 std::string message("The match has ended."); 59 59 COUT(0) << message << std::endl; 60 60 Host::Broadcast(message); … … 65 65 Gametype::playerEntered(player); 66 66 67 std::stringmessage = player->getName() + " entered the game";67 const std::string& message = player->getName() + " entered the game"; 68 68 COUT(0) << message << std::endl; 69 69 Host::Broadcast(message); … … 76 76 if (valid_player) 77 77 { 78 std::stringmessage = player->getName() + " left the game";78 const std::string& message = player->getName() + " left the game"; 79 79 COUT(0) << message << std::endl; 80 80 Host::Broadcast(message); … … 90 90 if (valid_player) 91 91 { 92 std::stringmessage = player->getOldName() + " changed name to " + player->getName();92 const std::string& message = player->getOldName() + " changed name to " + player->getName(); 93 93 COUT(0) << message << std::endl; 94 94 Host::Broadcast(message); … … 126 126 if (player) 127 127 { 128 std::stringmessage = player->getName() + " scores!";128 const std::string& message = player->getName() + " scores!"; 129 129 COUT(0) << message << std::endl; 130 130 Host::Broadcast(message); -
code/trunk/src/orxonox/gametypes/Gametype.cc
r5929 r6417 51 51 { 52 52 RegisterObject(Gametype); 53 53 54 54 this->gtinfo_ = new GametypeInfo(creator); 55 55 … … 71 71 72 72 // load the corresponding score board 73 if (GameMode::showsGraphics() && this->scoreboardTemplate_ != "")73 if (GameMode::showsGraphics() && !this->scoreboardTemplate_.empty()) 74 74 { 75 75 this->scoreboard_ = new OverlayGroup(this); … … 79 79 else 80 80 this->scoreboard_ = 0; 81 81 82 82 /* HACK HACK HACK */ 83 83 this->hackAddBots_ = createConsoleCommand( createFunctor(&Gametype::addBots, this), "hackAddBots"); … … 87 87 /* HACK HACK HACK */ 88 88 } 89 89 90 90 Gametype::~Gametype() 91 91 { -
code/trunk/src/orxonox/gametypes/Gametype.h
r5929 r6417 184 184 // Config Values 185 185 std::string scoreboardTemplate_; 186 186 187 187 /* HACK HACK HACK */ 188 188 ConsoleCommand* hackAddBots_; -
code/trunk/src/orxonox/gametypes/TeamDeathmatch.cc
r5929 r6417 61 61 static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue)); 62 62 63 SetConfigValue Vector(teamcolours_, defaultcolours);63 SetConfigValue(teamcolours_, defaultcolours); 64 64 } 65 65 -
code/trunk/src/orxonox/gametypes/UnderAttack.cc
r5929 r6417 69 69 { 70 70 this->end(); //end gametype 71 std::string message = "Ship destroyed! Team 0 has won!";71 std::string message("Ship destroyed! Team 0 has won!"); 72 72 COUT(0) << message << std::endl; 73 73 Host::Broadcast(message); … … 152 152 this->gameEnded_ = true; 153 153 this->end(); 154 std::string message = "Time is up! Team 1 has won!";154 std::string message("Time is up! Team 1 has won!"); 155 155 COUT(0) << message << std::endl; 156 156 Host::Broadcast(message); … … 171 171 if ( gameTime_ <= timesequence_ && gameTime_ > 0) 172 172 { 173 std::stringmessage = multi_cast<std::string>(timesequence_) + " seconds left!";173 const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!"; 174 174 /* 175 175 COUT(0) << message << std::endl; -
code/trunk/src/orxonox/graphics/Billboard.cc
r5781 r6417 42 42 RegisterObject(Billboard); 43 43 44 this->material_ = "";45 44 this->colour_ = ColourValue::White; 46 45 // this->rotation_ = 0; … … 76 75 void Billboard::changedMaterial() 77 76 { 78 if (this->material_ == "")77 if (this->material_.empty()) 79 78 return; 80 79 … … 99 98 { 100 99 /* 101 if (this->getScene() && GameMode::showsGraphics() && (this->material_ != ""))100 if (this->getScene() && GameMode::showsGraphics() && !this->material_.empty()) 102 101 { 103 102 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1); -
code/trunk/src/orxonox/graphics/BlinkingBillboard.cc
r5781 r6417 81 81 this->setScale(this->amplitude_ * static_cast<float>(square(sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_)))); 82 82 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_)))); 84 84 } 85 85 } -
code/trunk/src/orxonox/graphics/Camera.cc
r5929 r6417 42 42 #include "Scene.h" 43 43 #include "CameraManager.h" 44 #include "sound/SoundManager.h" 44 45 45 46 namespace orxonox … … 61 62 62 63 this->camera_ = this->getScene()->getSceneManager()->createCamera(getUniqueNumberString()); 64 this->camera_->setUserObject(this); 63 65 this->cameraNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode(); 64 66 this->attachNode(this->cameraNode_); … … 68 70 this->bDrag_ = false; 69 71 this->nearClipDistance_ = 1; 72 this->lastDtLagged_ = false; 70 73 71 74 this->setSyncMode(0x0); … … 111 114 { 112 115 // 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; 114 139 115 140 Vector3 offset = this->getWorldPosition() - this->cameraNode_->_getDerivedPosition(); 116 this->cameraNode_->translate( coeff * offset);141 this->cameraNode_->translate(poscoeff * offset); 117 142 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()); 120 151 } 121 152 } -
code/trunk/src/orxonox/graphics/Camera.h
r5781 r6417 34 34 #include "util/OgreForwardRefs.h" 35 35 #include "tools/interfaces/Tickable.h" 36 #include "tools/interfaces/TimeFactorListener.h" 36 37 #include "worldentities/StaticEntity.h" 37 38 38 39 namespace orxonox 39 40 { 40 class _OrxonoxExport Camera : public StaticEntity, public Tickable 41 class _OrxonoxExport Camera : public StaticEntity, public Tickable, public TimeFactorListener 41 42 { 42 43 friend class CameraManager; … … 51 52 void requestFocus(); 52 53 void releaseFocus(); 54 55 inline Ogre::Camera* getOgreCamera() 56 { return this->camera_; } 53 57 54 58 inline bool hasFocus() … … 69 73 bool bHasFocus_; 70 74 bool bDrag_; 75 bool lastDtLagged_; 71 76 }; 72 77 } -
code/trunk/src/orxonox/infos/Bot.cc
r5781 r6417 94 94 static std::vector<std::string> defaultnames(names, names + sizeof(names) / sizeof(std::string)); 95 95 96 SetConfigValue Vector(names_, defaultnames);96 SetConfigValue(names_, defaultnames); 97 97 } 98 98 } -
code/trunk/src/orxonox/infos/HumanPlayer.cc
r5929 r6417 35 35 #include "network/Host.h" 36 36 #include "controllers/HumanController.h" 37 #include "controllers/NewHumanController.h" 37 38 #include "gametypes/Gametype.h" 38 39 #include "overlays/OverlayGroup.h" … … 50 51 51 52 this->bHumanPlayer_ = true; 52 this->defaultController_ = Class( HumanController);53 this->defaultController_ = Class(NewHumanController); 53 54 54 55 this->humanHud_ = 0; … … 163 164 if (this->isInitialized() && this->isLocalPlayer()) 164 165 { 165 if (this->getGametype() && this->getGametype()->getHUDTemplate() != "")166 if (this->getGametype() && !this->getGametype()->getHUDTemplate().empty()) 166 167 this->setGametypeHUDTemplate(this->getGametype()->getHUDTemplate()); 167 168 else … … 178 179 } 179 180 180 if (this->isLocalPlayer() && this->humanHudTemplate_ != ""&& GameMode::showsGraphics())181 if (this->isLocalPlayer() && !this->humanHudTemplate_.empty() && GameMode::showsGraphics()) 181 182 { 182 183 this->humanHud_ = new OverlayGroup(this); … … 194 195 } 195 196 196 if (this->isLocalPlayer() && this->gametypeHudTemplate_ != "")197 if (this->isLocalPlayer() && !this->gametypeHudTemplate_.empty()) 197 198 { 198 199 this->gametypeHud_ = new OverlayGroup(this); -
code/trunk/src/orxonox/infos/PlayerInfo.cc
r5929 r6417 50 50 this->controller_ = 0; 51 51 this->controllableEntity_ = 0; 52 this->controllableEntityID_ = CLIENTID_UNKNOWN; 52 this->controllableEntityID_ = OBJECTID_UNKNOWN; 53 this->oldControllableEntity_ = 0; 53 54 54 55 this->gtinfo_ = 0; … … 80 81 registerVariable(this->name_, VariableDirection::ToClient, new NetworkCallback<PlayerInfo>(this, &PlayerInfo::changedName)); 81 82 registerVariable(this->controllableEntityID_, VariableDirection::ToClient, new NetworkCallback<PlayerInfo>(this, &PlayerInfo::networkcallback_changedcontrollableentityID)); 82 registerVariable(this->bReadyToSpawn_, VariableDirection::ToServer);83 83 registerVariable(this->gtinfoID_, VariableDirection::ToClient, new NetworkCallback<PlayerInfo>(this, &PlayerInfo::networkcallback_changedgtinfoID)); 84 84 } … … 139 139 this->controller_->setPlayer(this); 140 140 if (this->controllableEntity_) 141 { 141 142 this->controller_->setControllableEntity(this->controllableEntity_); 143 this->controllableEntity_->setController(this->controller_); 144 } 142 145 this->changedController(); 143 146 } … … 148 151 return; 149 152 153 if (this->oldControllableEntity_) 154 this->stopTemporaryControl(); 150 155 if (this->controllableEntity_) 151 156 this->stopControl(); … … 159 164 160 165 if (this->controller_) 166 { 161 167 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); 162 189 163 190 this->changedControllableEntity(); … … 166 193 void PlayerInfo::stopControl() 167 194 { 195 if ( this->oldControllableEntity_ ) 196 this->stopTemporaryControl(); 197 168 198 ControllableEntity* entity = this->controllableEntity_; 169 199 … … 171 201 return; 172 202 203 this->controllableEntity_->setController(0); 173 204 this->controllableEntity_ = 0; 174 205 this->controllableEntityID_ = OBJECTID_UNKNOWN; … … 177 208 this->controller_->setControllableEntity(0); 178 209 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(); 180 233 181 234 this->changedControllableEntity(); … … 196 249 } 197 250 251 198 252 void PlayerInfo::networkcallback_changedgtinfoID() 199 253 { -
code/trunk/src/orxonox/infos/PlayerInfo.h
r5929 r6417 69 69 void startControl(ControllableEntity* entity); 70 70 void stopControl(); 71 void startTemporaryControl(ControllableEntity* entity); 72 void stopTemporaryControl(); 71 73 72 74 inline ControllableEntity* getControllableEntity() const … … 96 98 Controller* controller_; 97 99 ControllableEntity* controllableEntity_; 100 ControllableEntity* oldControllableEntity_; 98 101 unsigned int controllableEntityID_; 99 102 -
code/trunk/src/orxonox/interfaces/RadarViewable.cc
r5929 r6417 51 51 , line_(NULL) 52 52 , LineNode_(NULL) 53 , isHumanShip_(false) 54 , bVisibility_(true) 53 55 , radarObjectCamouflage_(0.0f) 54 56 , radarObjectShape_(Dot) … … 56 58 { 57 59 RegisterRootObject(RadarViewable); 58 59 this->bVisibility_ = true;60 this->isHumanShip_ = false;61 60 62 61 this->uniqueId_=getUniqueNumberString(); … … 164 163 if (!object) 165 164 { 166 COUT(1) << "Assert ation: 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; 167 166 assert(0); 168 167 } -
code/trunk/src/orxonox/interfaces/Rewardable.h
r5781 r6417 43 43 @brief 44 44 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 46 46 It just needs to inherit form Rewardable, and implement the reward() method. 47 47 @author -
code/trunk/src/orxonox/items/Engine.h
r5929 r6417 106 106 virtual const Vector3& getDirection() const; 107 107 108 void loadSound(const std::string filename);109 110 108 private: 111 109 void networkcallback_shipID(); -
code/trunk/src/orxonox/items/MultiStateEngine.cc
r5929 r6417 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 29 30 #include "MultiStateEngine.h" 30 31 32 extern "C" { 33 #include <lua.h> 34 } 35 36 #include "util/Convert.h" 31 37 #include "core/CoreIncludes.h" 32 38 #include "core/GameMode.h" 39 #include "core/LuaState.h" 33 40 #include "core/XMLPort.h" 41 #include "worldentities/EffectContainer.h" 34 42 #include "worldentities/pawns/SpaceShip.h" 43 #include "sound/WorldSound.h" 35 44 36 45 namespace orxonox 37 46 { 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; 44 50 45 51 CreateFactory(MultiStateEngine); … … 49 55 RegisterObject(MultiStateEngine); 50 56 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 } 51 71 this->state_ = 0; 52 72 this->oldState_ = 0; 73 74 this->setSyncMode(ObjectDirection::Bidirectional); 53 75 this->registerVariables(); 54 76 } … … 56 78 MultiStateEngine::~MultiStateEngine() 57 79 { 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_; 69 95 } 70 96 } … … 73 99 { 74 100 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); 80 104 } 81 105 … … 89 113 if (this->getShip()) 90 114 { 115 const Vector3& velocity = this->getShip()->getLocalVelocity(); 116 91 117 if (this->getShip()->hasLocalController()) 92 118 { 93 this->setSyncMode(ObjectDirection::Bidirectional);94 95 119 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; 105 129 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; 122 131 } 123 132 124 133 if (GameMode::isMaster()) 125 134 { 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(); 134 177 } 135 178 } … … 145 188 return; 146 189 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); 160 206 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 186 214 { 187 215 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) 189 217 { 190 218 if (i == index) 191 219 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; 231 256 } 232 257 } -
code/trunk/src/orxonox/items/MultiStateEngine.h
r5781 r6417 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 32 33 #include "OrxonoxPrereqs.h" 33 34 34 #include < list>35 #include <vector> 35 36 #include "Engine.h" 36 37 … … 40 41 { 41 42 public: 43 enum EngineState 44 { 45 Idle = 1, 46 Normal = 2, 47 Brake = 4, 48 Boost = 8 49 }; 50 42 51 MultiStateEngine(BaseObject* creator); 43 52 virtual ~MultiStateEngine(); … … 50 59 virtual void addToSpaceShip(SpaceShip* ship); 51 60 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; 56 63 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(); 61 68 62 69 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_; 68 76 }; 69 77 } -
code/trunk/src/orxonox/overlays/InGameConsole.cc
r6105 r6417 44 44 #include "util/Convert.h" 45 45 #include "util/Math.h" 46 #include "util/ UTFStringConversions.h"46 #include "util/DisplayStringConversions.h" 47 47 #include "core/CoreIncludes.h" 48 48 #include "core/ConfigValueIncludes.h" … … 61 61 SetConsoleCommand(InGameConsole, closeConsole, true); 62 62 63 InGameConsole* InGameConsole::singletonPtr_s = 0;64 63 ManageScopedSingleton(InGameConsole, ScopeID::Graphics, false); 65 64 … … 68 67 */ 69 68 InGameConsole::InGameConsole() 70 : shell_(new Shell("InGameConsole", true, true)) 69 : shell_(new Shell("InGameConsole", true)) 70 , bShowCursor_(false) 71 71 , consoleOverlay_(0) 72 72 , consoleOverlayContainer_(0) … … 218 218 font->addCodePointRange(Ogre::Font::CodePointRange(161, 255)); 219 219 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 220 228 // create the text lines 221 229 this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES]; … … 229 237 this->consoleOverlayTextAreas_[i]->setLeft(8); 230 238 this->consoleOverlayTextAreas_[i]->setCaption(""); 231 this->consoleOverlay Container_->addChild(this->consoleOverlayTextAreas_[i]);239 this->consoleOverlayNoise_->addChild(this->consoleOverlayTextAreas_[i]); 232 240 } 233 241 … … 240 248 this->consoleOverlayCursor_->setLeft(7); 241 249 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_); 251 251 252 252 this->windowResized(this->getWindowWidth(), this->getWindowWidth()); … … 268 268 void InGameConsole::linesChanged() 269 269 { 270 std::list<std::string>::const_iterator it = this->shell_->getNewestLineIterator();270 Shell::LineList::const_iterator it = this->shell_->getNewestLineIterator(); 271 271 int max = 0; 272 272 for (int i = 1; i < LINES; ++i) … … 282 282 283 283 for (int i = LINES - 1; i > max; --i) 284 this->print("", i, true);284 this->print("", Shell::None, i, true); 285 285 286 286 for (int i = max; i >= 1; --i) 287 287 { 288 288 --it; 289 this->print( *it, i, true);289 this->print(it->first, it->second, i, true); 290 290 } 291 291 } … … 297 297 { 298 298 if (LINES > 1) 299 this->print( *this->shell_->getNewestLineIterator(), 1);299 this->print(this->shell_->getNewestLineIterator()->first, this->shell_->getNewestLineIterator()->second, 1); 300 300 } 301 301 … … 316 316 { 317 317 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()) 321 321 this->inputWindowStart_ = 0; 322 322 } … … 340 340 void InGameConsole::executed() 341 341 { 342 this->shell_->addOutput Line(this->shell_->getInput());342 this->shell_->addOutput(this->shell_->getInput() + '\n', Shell::Command); 343 343 } 344 344 … … 358 358 @brief Used to control the actual scrolling and the cursor. 359 359 */ 360 void InGameConsole:: update(const Clock& time)360 void InGameConsole::preUpdate(const Clock& time) 361 361 { 362 362 if (this->scroll_ != 0) … … 456 456 @param s String to be printed 457 457 */ 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 { 464 460 std::string output = text; 465 466 if (level >= -1 && level <= 5)467 output.erase(0, 1);468 469 461 if (LINES > index) 470 462 { 471 this->colourLine( level, index);463 this->colourLine(type, index); 472 464 473 465 if (index > 0) … … 477 469 { 478 470 ++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_))); 480 472 output.erase(0, this->maxCharsPerLine_); 481 473 output.insert(0, 1, ' '); 482 474 if (linesUsed > numLinesShifted_ || alwaysShift) 483 475 this->shiftLines(); 484 this->colourLine( level, index);476 this->colourLine(type, index); 485 477 } 486 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre:: UTFString>(output));478 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output)); 487 479 this->displayedText_ = output; 488 480 this->numLinesShifted_ = linesUsed; … … 502 494 this->inputWindowStart_ = 0; 503 495 this->displayedText_ = output; 504 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre:: UTFString>(output));496 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output)); 505 497 } 506 498 } … … 559 551 } 560 552 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); 598 588 } 599 589 -
code/trunk/src/orxonox/overlays/InGameConsole.h
r6105 r6417 52 52 void setConfigValues(); 53 53 54 void update(const Clock& time);54 void preUpdate(const Clock& time); 55 55 56 56 static void openConsole(); … … 72 72 73 73 void shiftLines(); 74 void colourLine( int colourcode, int index);74 void colourLine(Shell::LineType type, int index); 75 75 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); 77 77 78 78 void windowResized(unsigned int newWidth, unsigned int newHeight); -
code/trunk/src/orxonox/overlays/Map.cc
r5929 r6417 49 49 #include <OgreViewport.h> 50 50 51 #include "util/StringUtils.h" 51 52 #include "core/ConsoleCommand.h" 52 53 #include "core/CoreIncludes.h" … … 94 95 95 96 //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(); 101 99 if( !Map::getMapSceneManager() ) 102 100 { -
code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc
r6057 r6417 39 39 #include <OgrePanelOverlayElement.h> 40 40 #include <OgreRenderWindow.h> 41 #include <OgreMaterialManager.h> 42 #include <OgreTechnique.h> 43 #include <OgrePass.h> 41 44 42 45 #include "util/Convert.h" 43 46 #include "util/Exception.h" 44 #include "util/StringUtils.h"45 47 #include "core/GameMode.h" 46 48 #include "core/CoreIncludes.h" … … 83 85 // Get aspect ratio from the render window. Later on, we get informed automatically 84 86 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 94 96 setBackgroundMaterial(""); 95 97 } … … 143 145 144 146 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; 146 148 147 149 OrxonoxOverlay::overlays_s[this->getName()] = this; … … 151 153 void OrxonoxOverlay::setBackgroundMaterial(const std::string& material) 152 154 { 153 if (this->background_ && material != "")155 if (this->background_ && !material.empty()) 154 156 this->background_->setMaterialName(material); 155 157 } … … 168 170 { 169 171 SUPER( OrxonoxOverlay, changedVisibility ); 170 172 171 173 if (!this->overlay_) 172 174 return; … … 309 311 std::map<std::string, OrxonoxOverlay*>::const_iterator it = overlays_s.find(name); 310 312 if (it != overlays_s.end()) 311 (*it).second->scale(Vector2(scale, scale));313 it->second->scale(Vector2(scale, scale)); 312 314 } 313 315 … … 324 326 if (it != overlays_s.end()) 325 327 { 326 OrxonoxOverlay* overlay= (*it).second;328 OrxonoxOverlay* overlay= it->second; 327 329 if(overlay->isVisible()) 328 330 overlay->hide(); … … 343 345 std::map<std::string, OrxonoxOverlay*>::const_iterator it = overlays_s.find(name); 344 346 if (it != overlays_s.end()) 345 (*it).second->scroll(scroll);347 it->second->scroll(scroll); 346 348 } 347 349 … … 357 359 std::map<std::string, OrxonoxOverlay*>::const_iterator it = overlays_s.find(name); 358 360 if (it != overlays_s.end()) 359 (*it).second->rotate(angle);361 it->second->rotate(angle); 360 362 } 361 363 … … 370 372 } 371 373 } 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 } 372 380 } -
code/trunk/src/orxonox/overlays/OrxonoxOverlay.h
r6057 r6417 155 155 static void rotateOverlay(const std::string& name, const Degree& angle); 156 156 157 void setBackgroundMaterial(const std::string& material); 158 const std::string& getBackgroundMaterial() const; 159 160 void setBackgroundAlpha(float alpha); 161 157 162 virtual void changedVisibility(); 158 163 … … 172 177 inline OverlayGroup* getOverlayGroup() const 173 178 { return this->group_; } 174 virtual void changedOverlayGroup() 179 virtual void changedOverlayGroup() 175 180 { this->changedVisibility(); } 176 181 … … 180 185 virtual void sizeChanged(); 181 186 virtual void positionChanged(); 182 183 void setBackgroundMaterial(const std::string& material);184 const std::string& getBackgroundMaterial() const;185 187 186 188 Ogre::Overlay* overlay_; //!< The overlay the entire class is about. … … 205 207 BaseObject* owner_; 206 208 OverlayGroup* group_; 209 Ogre::Pass* backgroundAlphaPass_; 207 210 }; 208 211 -
code/trunk/src/orxonox/overlays/OverlayGroup.cc
r6054 r6417 144 144 { 145 145 SUPER( OverlayGroup, changedVisibility ); 146 146 147 147 for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it) 148 148 (*it)->changedVisibility(); //inform all Child Overlays that our visibility has changed -
code/trunk/src/orxonox/pickup/DroppedItem.cc
r5929 r6417 83 83 if (this->item_) 84 84 { 85 COUT(3) << "Delete DroppedItem with '" << this->item_->getPickupIdentifier() << "'"<< std::endl;85 COUT(3) << "Delete DroppedItem with '" << this->item_->getPickupIdentifier() << '\'' << std::endl; 86 86 this->item_->destroy(); 87 87 } … … 112 112 drop->createTimer(); 113 113 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; 115 115 116 116 return drop; -
code/trunk/src/orxonox/pickup/ModifierPickup.cc
r5929 r6417 91 91 for (it = this->additiveModifiers_.begin(); it != this->additiveModifiers_.end(); it++) 92 92 { 93 pawn->getPickups().addAdditiveModifier( (*it).first, (*it).second);93 pawn->getPickups().addAdditiveModifier(it->first, it->second); 94 94 } 95 95 96 96 for (it = this->multiplicativeModifiers_.begin(); it != this->multiplicativeModifiers_.end(); it++) 97 97 { 98 pawn->getPickups().addMultiplicativeModifier( (*it).first, (*it).second);98 pawn->getPickups().addMultiplicativeModifier(it->first, it->second); 99 99 } 100 100 … … 128 128 for (it = this->additiveModifiers_.begin(); it != this->additiveModifiers_.end(); it++) 129 129 { 130 pawn->getPickups().removeAdditiveModifier( (*it).first, (*it).second);130 pawn->getPickups().removeAdditiveModifier(it->first, it->second); 131 131 } 132 132 133 133 for (it = this->multiplicativeModifiers_.begin(); it != this->multiplicativeModifiers_.end(); it++) 134 134 { 135 pawn->getPickups().removeMultiplicativeModifier( (*it).first, (*it).second);135 pawn->getPickups().removeMultiplicativeModifier(it->first, it->second); 136 136 } 137 137 … … 162 162 std::map<ModifierType::Value, float>::const_iterator it = this->additiveModifiers_.find(type); 163 163 if (it != this->additiveModifiers_.end()) 164 return (*it).second;164 return it->second; 165 165 else 166 166 return 0.0f; … … 175 175 std::map<ModifierType::Value, float>::const_iterator it = this->multiplicativeModifiers_.find(type); 176 176 if (it != this->multiplicativeModifiers_.end()) 177 return (*it).second;177 return it->second; 178 178 else 179 179 return 1.0f; -
code/trunk/src/orxonox/pickup/ModifierPickup.h
r5929 r6417 129 129 130 130 void timerCallback(Pawn* pawn); //!< Method called when the timer runs out. 131 131 132 132 private: 133 133 float getAdditiveModifier(ModifierType::Value type) const; //!< Get the additive modifier for a given ModifierType. -
code/trunk/src/orxonox/pickup/PickupCollection.cc
r5781 r6417 100 100 for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++) 101 101 { 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()); 104 104 } 105 105 this->currentUsable_ = NULL; … … 124 124 for (std::multimap<std::string, BaseItem*>::iterator it = bounds.first; it != bounds.second && it != this->items_.end(); it++) 125 125 { 126 if ( (*it).second == item)126 if (it->second == item) 127 127 { 128 128 return true; … … 176 176 for (std::multimap<std::string, BaseItem*>::iterator it = bounds.first; it != bounds.second && it != this->items_.end(); it++) 177 177 { 178 if ( (*it).second == item)178 if (it->second == item) 179 179 { 180 180 this->items_.erase(it); … … 217 217 for (std::multimap<ModifierType::Value, float>::iterator it = range.first; it != range.second && it != this->additiveModifiers_.end(); it++) 218 218 { 219 v += (*it).second;219 v += it->second; 220 220 } 221 221 … … 232 232 for (std::multimap<ModifierType::Value, float>::iterator it = range.first; it != range.second && it != this->additiveModifiers_.end(); it++) 233 233 { 234 if ( (*it).second == value)234 if (it->second == value) 235 235 { 236 236 this->additiveModifiers_.erase(it); … … 260 260 for (std::multimap<ModifierType::Value, float>::iterator it = range.first; it != range.second && it != this->multiplicativeModifiers_.end(); it++) 261 261 { 262 v *= (*it).second;262 v *= it->second; 263 263 } 264 264 … … 275 275 for (std::multimap<ModifierType::Value, float>::iterator it = range.first; it != range.second && it != this->multiplicativeModifiers_.end(); it++) 276 276 { 277 if ( (*it).second == value)277 if (it->second == value) 278 278 { 279 279 this->multiplicativeModifiers_.erase(it); … … 335 335 for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++) 336 336 { 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)); 339 339 } 340 340 … … 352 352 for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++) 353 353 { 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)); 356 356 } 357 357 … … 369 369 for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++) 370 370 { 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)); 373 373 } 374 374 -
code/trunk/src/orxonox/pickup/PickupInventory.cc
r5781 r6417 86 86 { 87 87 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"); 97 93 } 98 94 PickupInventory::getSingleton()->setVisible(!PickupInventory::getSingleton()->isVisible()); … … 200 196 return ""; 201 197 202 std::stringname = "pickup_" + item->getGUIImage();198 const std::string& name = "pickup_" + item->getGUIImage(); 203 199 204 200 if(!CEGUI::ImagesetManager::getSingletonPtr()->isImagesetPresent(name)) … … 207 203 } 208 204 209 return "set:" + name + " image:full_image";205 return ("set:" + name + " image:full_image"); 210 206 } 211 207 … … 336 332 txt->setVisible(true); 337 333 txt->setProperty("Text", item->getGUIText()); 338 txt->setProperty("TextColours", "tl:" + textColour + " tr:" + textColour + " bl:" + textColour + " br:" + textColour + "");339 340 std::stringimage = PickupInventory::getImageForItem(item);334 txt->setProperty("TextColours", "tl:" + textColour + " tr:" + textColour + " bl:" + textColour + " br:" + textColour); 335 336 const std::string& image = PickupInventory::getImageForItem(item); 341 337 btn->setVisible(true); 342 338 btn->setProperty("NormalImage", image); -
code/trunk/src/orxonox/pickup/PickupSpawner.cc
r5929 r6417 96 96 // & load the GUI itself too, along with some empty windows 97 97 // = even less delays 98 GUIManager:: getInstance().showGUI("PickupInventory");99 GUIManager:: getInstance().executeCode("hideGUI(\"PickupInventory\")");98 GUIManager::showGUI("PickupInventory"); 99 GUIManager::hideGUI("PickupInventory"); 100 100 PickupInventory::getSingleton(); 101 101 } -
code/trunk/src/orxonox/pickup/UsableItem.cc
r5781 r6417 26 26 * 27 27 */ 28 28 29 29 /** 30 30 @file … … 41 41 @param creator Pointer to the object which created this item. 42 42 */ 43 UsableItem::UsableItem(BaseObject* creator) : BaseItem(creator) 43 UsableItem::UsableItem(BaseObject* creator) : BaseItem(creator) 44 44 { 45 45 RegisterObject(UsableItem); -
code/trunk/src/orxonox/sound/AmbientSound.cc
r5929 r6417 31 31 #include "core/CoreIncludes.h" 32 32 #include "core/EventIncludes.h" 33 #include "core/GameMode.h" 34 #include "core/Resource.h" 33 35 #include "core/XMLPort.h" 36 #include "SoundManager.h" 34 37 35 38 namespace orxonox … … 39 42 AmbientSound::AmbientSound(BaseObject* creator) 40 43 : BaseObject(creator) 44 , Synchronisable(creator) 45 , bPlayOnLoad_(false) 41 46 { 42 47 RegisterObject(AmbientSound); 48 49 // Ambient sounds always fade in 50 this->setVolume(0); 51 this->registerVariables(); 43 52 } 44 53 45 AmbientSound::~AmbientSound()54 void AmbientSound::preDestroy() 46 55 { 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)); 47 69 } 48 70 … … 50 72 { 51 73 SUPER(AmbientSound, XMLPort, xmlelement, mode); 52 XMLPortParamExtern(AmbientSound, BaseSound, this, "source", setSource, getSource,xmlelement, mode);53 XMLPortParam Extern(AmbientSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode);54 XMLPortParam Extern(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); 55 77 } 56 78 … … 60 82 XMLPortEventState(AmbientSound, BaseObject, "play", play, xmlelement, mode); 61 83 } 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 } 62 143 } -
code/trunk/src/orxonox/sound/AmbientSound.h
r5929 r6417 22 22 * Author: 23 23 * Reto Grieder 24 * Kevin Young 24 25 * Co-authors: 25 26 * ... 26 27 * 27 28 */ 29 28 30 #ifndef _AmbientSound_H__ 29 31 #define _AmbientSound_H__ … … 32 34 33 35 #include "core/BaseObject.h" 34 #include "sound/BaseSound.h" 36 #include "network/synchronisable/Synchronisable.h" 37 #include "BaseSound.h" 38 #include "MoodManager.h" 35 39 36 40 namespace orxonox … … 41 45 * 42 46 */ 43 class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject 47 class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable, public MoodListener 44 48 { 49 friend class SoundManager; 50 45 51 public: 46 52 AmbientSound(BaseObject* creator); 47 virtual ~AmbientSound();48 53 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() { } 51 72 52 73 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 53 85 }; 54 86 } -
code/trunk/src/orxonox/sound/BaseSound.cc
r5929 r6417 29 29 #include "BaseSound.h" 30 30 31 #include <cassert> 31 32 #include <vector> 32 #include <AL/alut.h> 33 #include <vorbis/vorbisfile.h> 33 #include <al.h> 34 34 35 35 #include "core/CoreIncludes.h" 36 36 #include "core/GameMode.h" 37 37 #include "core/Resource.h" 38 #include "core/XMLPort.h" 39 #include "SoundBuffer.h" 40 #include "SoundManager.h" 38 41 39 42 namespace orxonox 40 43 { 41 44 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) 46 50 { 47 51 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_)); 48 57 } 49 58 50 59 BaseSound::~BaseSound() 51 60 { 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 63 91 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 { 75 102 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; 80 118 if (alIsSource(this->audioSource_)) 81 119 alSourcePause(this->audioSource_); 82 120 } 83 121 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 } 109 193 } 110 194 111 195 void BaseSound::setSource(const std::string& source) 112 196 { 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 113 220 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; 155 237 return; 156 238 } 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, ¤t_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 26 26 * 27 27 */ 28 28 29 #ifndef _BaseSound_H__ 29 30 #define _BaseSound_H__ … … 32 33 33 34 #include <string> 34 #include < OgreSharedPtr.h>35 #include <boost/shared_ptr.hpp> 35 36 #include <OgreDataStream.h> 36 37 #include "core/OrxonoxClass.h" … … 47 48 public: 48 49 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 49 86 virtual ~BaseSound(); 50 87 51 void play();52 void stop();53 void pause();88 void doPlay(); 89 void doStop(); 90 void doPause(); 54 91 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(); 58 102 59 v oid setSource(const std::string& source);60 const std::string& getSource() { return this->source_; }103 virtual void initialiseSource(); 104 ALint getSourceState() const; 61 105 62 bool getPlayOnLoad() { return this->bPlayOnLoad_; } 63 void setPlayOnLoad(bool val); 106 virtual float getRealVolume() = 0; 64 107 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_; 74 116 75 117 private: 76 std::string source_; 77 bool bPlayOnLoad_; 78 bool bLoop_; 79 DataStreamPtr dataStream_; 118 DataStreamPtr dataStream_; 80 119 }; 81 120 } -
code/trunk/src/orxonox/sound/CMakeLists.txt
r5929 r6417 2 2 AmbientSound.cc 3 3 BaseSound.cc 4 SoundBuffer.cc 4 5 SoundManager.cc 5 6 WorldSound.cc 7 SoundStreamer.cc 6 8 ) 7 9 -
code/trunk/src/orxonox/sound/SoundManager.cc
r5929 r6417 22 22 * Author: 23 23 * Erwin 'vaiursch' Herrsche 24 * Kevin Young 25 * Reto Grieder 24 26 * Co-authors: 25 27 * ... … … 30 32 31 33 #include <AL/alut.h> 34 #include <utility> 32 35 33 36 #include "util/Exception.h" 34 37 #include "util/Math.h" 35 38 #include "util/ScopeGuard.h" 39 #include "util/Clock.h" 40 #include "core/ConfigValueIncludes.h" 41 #include "core/CoreIncludes.h" 36 42 #include "core/GameMode.h" 37 43 #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" 38 49 39 50 namespace orxonox 40 51 { 41 SoundManager* SoundManager::singletonPtr_s = NULL;42 52 ManageScopedSingleton(SoundManager, ScopeID::Graphics, true); 43 53 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 44 68 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())); 48 81 Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit); 49 82 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 */ 51 105 this->device_ = alcOpenDevice(NULL); 52 106 if (this->device_ == NULL) 53 107 { 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; 55 109 #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; 57 111 #endif 58 ThrowException(InitialisationFailed, " OpenAL error: Could not open sound device.");112 ThrowException(InitialisationFailed, "Sound Error: Could not open sound device."); 59 113 } 60 114 Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_); 61 115 62 COUT(3) << "OpenAL: Sound device opened" << std::endl;116 // Create sound context and make it the currently used one 63 117 this->context_ = alcCreateContext(this->device_, NULL); 64 118 if (this->context_ == NULL) 65 ThrowException(InitialisationFailed, " OpenAL error: Could not create soundcontext");119 ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context"); 66 120 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; 76 134 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 80 153 // Disarm guards 81 154 alutExitGuard.Dismiss(); 82 155 closeDeviceGuard.Dismiss(); 83 156 desroyContextGuard.Dismiss(); 157 resetPlaysSoundGuard.Dismiss(); 158 159 COUT(4) << "Sound: Initialisation complete" << std::endl; 84 160 } 85 161 86 162 SoundManager::~SoundManager() 87 163 { 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 88 184 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; 89 189 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 90 201 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); 92 319 } 93 320 … … 103 330 { 104 331 // 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); 112 338 ALenum error = alGetError(); 113 339 if (error == AL_INVALID_VALUE) 114 340 COUT(2) << "Sound: OpenAL: Invalid listener orientation" << std::endl; 115 341 } 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 } 116 639 } -
code/trunk/src/orxonox/sound/SoundManager.h
r5929 r6417 22 22 * Author: 23 23 * Erwin 'vaiursch' Herrsche 24 * Kevin Young 25 * Reto Grieder 24 26 * Co-authors: 25 27 * ... 26 28 */ 29 27 30 #ifndef _SoundManager_H__ 28 31 #define _SoundManager_H__ … … 30 33 #include "OrxonoxPrereqs.h" 31 34 32 #include <cassert>33 35 #include <list> 36 #include <map> 37 #include <string> 38 #include <boost/shared_ptr.hpp> 39 34 40 #include "util/Singleton.h" 35 #include "tools/interfaces/Tickable.h" 41 #include "core/OrxonoxClass.h" 42 #include "core/SmartPtr.h" 36 43 44 // tolua_begin 37 45 namespace orxonox 38 46 { 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 45 49 { 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 46 63 friend class Singleton<SoundManager>; 64 47 65 public: 48 66 SoundManager(); 49 67 ~SoundManager(); 50 68 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 51 79 void setListenerPosition(const Vector3& position); 52 80 void setListenerOrientation(const Quaternion& orientation); 53 81 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 54 103 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_; 55 120 ALCdevice* device_; 56 121 ALCcontext* context_; 57 122 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 58 149 static SoundManager* singletonPtr_s; 59 }; 60 } 150 }; // tolua_export 151 } // tolua_export 61 152 62 153 #endif /* _SoundManager_H__ */ -
code/trunk/src/orxonox/sound/WorldSound.cc
r5929 r6417 35 35 #include "core/EventIncludes.h" 36 36 #include "core/XMLPort.h" 37 #include "Scene.h" 38 #include "SoundManager.h" 39 #include <core/ConsoleCommandCompilation.h> 37 40 38 41 namespace orxonox … … 44 47 { 45 48 RegisterObject(WorldSound); 49 // WorldSound buffers should be pooled when they're not used anymore 50 this->bPooling_ = true; 51 this->registerVariables(); 46 52 } 47 53 48 WorldSound::~WorldSound()54 void WorldSound::registerVariables() 49 55 { 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)); 50 61 } 51 62 … … 53 64 { 54 65 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); 58 67 } 59 68 … … 62 71 SUPER(WorldSound, XMLEventPort, xmlelement, mode); 63 72 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 64 86 } 65 87 … … 80 102 COUT(2) << "Sound: OpenAL: Invalid sound velocity" << std::endl; 81 103 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); 85 106 error = alGetError(); 86 107 if (error == AL_INVALID_VALUE) … … 89 110 } 90 111 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 } 91 126 } -
code/trunk/src/orxonox/sound/WorldSound.h
r5929 r6417 26 26 * 27 27 */ 28 28 29 #ifndef _WorldSound_H__ 29 30 #define _WorldSound_H__ … … 45 46 public: 46 47 WorldSound(BaseObject* creator); 47 virtual ~WorldSound();48 48 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(); 51 52 52 virtual void tick(float dt); 53 void tick(float dt); 54 55 protected: 56 ~WorldSound() {} 53 57 54 58 private: 59 void registerVariables(); 60 void initialiseSource(); 61 float getRealVolume(); 55 62 }; 56 63 } -
code/trunk/src/orxonox/weaponsystem/WeaponMode.cc
r5929 r6417 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/XMLPort.h" 34 #include "controllers/Controller.h" 35 #include "worldentities/pawns/Pawn.h" 34 36 35 37 #include "Munition.h" … … 37 39 #include "WeaponPack.h" 38 40 #include "WeaponSystem.h" 41 #include "WeaponSlot.h" 42 43 #include "sound/WorldSound.h" 39 44 40 45 namespace orxonox … … 61 66 62 67 this->damage_ = 0; 68 63 69 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; 64 81 } 65 82 66 83 WeaponMode::~WeaponMode() 67 84 { 85 if (this->isInitialized()) 86 { 87 if (this->defSndWpnFire_) 88 this->defSndWpnFire_->destroy(); 89 } 68 90 } 69 91 … … 90 112 { 91 113 (*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 } 92 120 93 121 if (!this->bReloading_ && this->munition_ && this->munition_->takeMunition(this->munitionPerShot_, this)) … … 108 136 this->reloadTimer_.startTimer(); 109 137 138 if( this->defSndWpnFire_ && !(this->defSndWpnFire_->isPlaying())) 139 { 140 this->defSndWpnFire_->play(); 141 } 142 110 143 this->fire(); 111 144 … … 145 178 { 146 179 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; 148 185 this->updateMunition(); 149 186 } … … 191 228 void WeaponMode::reloaded() 192 229 { 230 if( this->defSndWpnFire_ && this->defSndWpnFire_->isPlaying()) 231 { 232 this->defSndWpnFire_->stop(); 233 } 193 234 this->bReloading_ = false; 194 235 } 195 236 196 Vector3 WeaponMode::getMuzzlePosition() const237 void WeaponMode::computeMuzzleParameters(const Vector3& target) 197 238 { 198 239 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 205 256 { 206 257 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); 216 259 else 217 260 return WorldEntity::FRONT; 218 261 } 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 } 219 276 } -
code/trunk/src/orxonox/weaponsystem/WeaponMode.h
r5929 r6417 51 51 bool fire(float* reloadTime); 52 52 bool reload(); 53 54 // Interacting with the default Firing sound 55 void setDefaultSound(const std::string& soundPath); 56 const std::string& getDefaultSound(); 53 57 54 58 … … 109 113 { return this->muzzleOffset_; } 110 114 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_; } 113 120 Vector3 getMuzzleDirection() const; 114 121 … … 124 131 inline unsigned int getMode() const 125 132 { return this->mode_; } 133 134 Vector3 getTarget(); 126 135 127 136 protected: … … 152 161 Timer reloadTimer_; 153 162 bool bReloading_; 163 164 Vector3 muzzlePosition_; 165 Quaternion muzzleOrientation_; 166 167 WorldSound* defSndWpnFire_; 168 bool bSoundAttached_; 154 169 }; 155 170 } -
code/trunk/src/orxonox/weaponsystem/WeaponPack.cc
r5929 r6417 49 49 WeaponPack::~WeaponPack() 50 50 { 51 if (this->isInitialized() && this->weaponSystem_)51 if (this->isInitialized()) 52 52 { 53 this->weaponSystem_->removeWeaponPack(this); 53 if( this->weaponSystem_ ) 54 this->weaponSystem_->removeWeaponPack(this); 54 55 55 56 while (!this->weapons_.empty()) … … 71 72 void WeaponPack::fire(unsigned int weaponmode) 72 73 { 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) 74 75 (*it)->fire(weaponmode); 75 76 } … … 77 78 void WeaponPack::reload() 78 79 { 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) 80 81 (*it)->reload(); 81 82 } … … 86 87 return; 87 88 88 this->weapons_. insert(weapon);89 this->weapons_.push_back(weapon); 89 90 weapon->setWeaponPack(this); 90 91 } … … 95 96 return; 96 97 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); 98 101 weapon->setWeaponPack(0); 99 102 } … … 103 106 unsigned int i = 0; 104 107 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) 106 109 { 107 110 if (i == index) … … 142 145 void WeaponPack::notifyWeapons() 143 146 { 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) 145 148 (*it)->setWeaponPack(this); 146 149 } -
code/trunk/src/orxonox/weaponsystem/WeaponPack.h
r5781 r6417 69 69 void notifyWeapons(); 70 70 71 std:: set<Weapon *> weapons_;71 std::vector<Weapon *> weapons_; 72 72 std::set<DefaultWeaponmodeLink *> links_; 73 73 WeaponSystem * weaponSystem_; -
code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc
r5929 r6417 202 202 } 203 203 204 this->weaponPacks_. insert(wPack);204 this->weaponPacks_.push_back(wPack); 205 205 wPack->setWeaponSystem(this); 206 206 … … 221 221 222 222 // 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); 224 226 } 225 227 … … 227 229 { 228 230 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) 230 232 { 231 233 ++i; … … 258 260 259 261 // 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 ); 261 263 if (it1 == this->weaponPacks_.end()) 262 264 return; -
code/trunk/src/orxonox/weaponsystem/WeaponSystem.h
r5781 r6417 92 92 std::map<unsigned int, WeaponSet *> weaponSets_; 93 93 std::vector<WeaponSlot *> weaponSlots_; 94 std:: set<WeaponPack *> weaponPacks_;94 std::vector<WeaponPack *> weaponPacks_; 95 95 std::map<Identifier *, Munition *> munitions_; 96 96 Pawn * pawn_; -
code/trunk/src/orxonox/worldentities/CMakeLists.txt
r5781 r6417 7 7 8 8 BigExplosion.cc 9 EffectContainer.cc 9 10 ExplosionChunk.cc 10 11 CameraPosition.cc -
code/trunk/src/orxonox/worldentities/ControllableEntity.cc
r5929 r6417 36 36 #include "core/GameMode.h" 37 37 #include "core/XMLPort.h" 38 #include "network/NetworkFunction.h" 38 39 39 40 #include "Scene.h" … … 47 48 { 48 49 CreateFactory(ControllableEntity); 50 51 registerMemberNetworkFunction( ControllableEntity, fire ); 52 registerMemberNetworkFunction( ControllableEntity, setTargetInternal ); 49 53 50 54 ControllableEntity::ControllableEntity(BaseObject* creator) : MobileEntity(creator) … … 62 66 this->camera_ = 0; 63 67 this->xmlcontroller_ = 0; 68 this->controller_ = 0; 64 69 this->reverseCamera_ = 0; 65 70 this->bDestroyWhenPlayerLeft_ = false; 66 71 this->cameraPositionRootNode_ = this->node_->createChildSceneNode(); 72 this->currentCameraPosition_ = 0; 67 73 this->bMouseLook_ = false; 68 74 this->mouseLookSpeed_ = 200; … … 169 175 { 170 176 this->cameraPositions_.front()->attachCamera(this->camera_); 177 this->currentCameraPosition_ = this->cameraPositions_.front().get(); 171 178 } 172 179 else if (this->cameraPositions_.size() > 0) … … 178 185 ++it; 179 186 if (it != this->cameraPositions_.end()) 187 { 180 188 (*it)->attachCamera(this->camera_); 189 this->currentCameraPosition_ = *it; 190 } 181 191 else 192 { 182 193 (*this->cameraPositions_.begin())->attachCamera(this->camera_); 194 this->currentCameraPosition_ = *this->cameraPositions_.begin(); 195 } 183 196 break; 184 197 } … … 188 201 { 189 202 this->camera_->attachToNode(this->cameraPositionRootNode_); 203 this->currentCameraPosition_ = 0; 190 204 } 191 205 } … … 198 212 if (!this->bMouseLook_) 199 213 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 } 200 221 } 201 222 … … 216 237 if (this->bMouseLook_) 217 238 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)) ); 218 272 } 219 273 … … 279 333 this->camera_ = new Camera(this); 280 334 this->camera_->requestFocus(); 281 if ( this->cameraPositionTemplate_ != "")335 if (!this->cameraPositionTemplate_.empty()) 282 336 this->addTemplate(this->cameraPositionTemplate_); 283 337 if (this->cameraPositions_.size() > 0) 338 { 284 339 this->cameraPositions_.front()->attachCamera(this->camera_); 340 this->currentCameraPosition_ = this->cameraPositions_.front(); 341 } 285 342 else 343 { 286 344 this->camera_->attachToNode(this->cameraPositionRootNode_); 345 this->currentCameraPosition_ = 0; 346 } 287 347 } 288 348 289 349 if (!this->hud_ && GameMode::showsGraphics()) 290 350 { 291 if ( this->hudtemplate_ != "")351 if (!this->hudtemplate_.empty()) 292 352 { 293 353 this->hud_ = new OverlayGroup(this); -
code/trunk/src/orxonox/worldentities/ControllableEntity.h
r5929 r6417 84 84 { this->rotateRoll(Vector2(value, 0)); } 85 85 86 virtual void fire(unsigned int firemode) {} 86 void fire(unsigned int firemode); 87 virtual void fired(unsigned int firemode) {} 87 88 virtual void reload() {} 88 89 … … 139 140 inline Controller* getXMLController() const 140 141 { 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 ); 141 152 142 153 protected: … … 199 210 Ogre::SceneNode* cameraPositionRootNode_; 200 211 std::list<SmartPtr<CameraPosition> > cameraPositions_; 212 CameraPosition* currentCameraPosition_; 201 213 std::string cameraPositionTemplate_; 202 214 Controller* xmlcontroller_; 215 Controller* controller_; 203 216 CameraPosition* reverseCamera_; 217 WeakPtr<WorldEntity> target_; 204 218 }; 205 219 } -
code/trunk/src/orxonox/worldentities/MovableEntity.cc
r5929 r6417 79 79 if (victim) 80 80 { 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); 82 83 } 83 84 } -
code/trunk/src/orxonox/worldentities/MovableEntity.h
r5929 r6417 70 70 71 71 inline void setEnableCollisionDamage(bool c) 72 { 73 this->enableCollisionDamage_ = c; 72 { 73 this->enableCollisionDamage_ = c; 74 74 this->enableCollisionCallback(); 75 } 75 } 76 76 77 77 inline bool getEnableCollisionDamage() -
code/trunk/src/orxonox/worldentities/StaticEntity.cc
r5781 r6417 42 42 { 43 43 RegisterObject(StaticEntity); 44 44 45 45 this->setPriority(Priority::VeryLow); 46 46 -
code/trunk/src/orxonox/worldentities/WorldEntity.cc
r5929 r6417 472 472 //! Attaches an Ogre::MovableObject to this WorldEntity. 473 473 void WorldEntity::attachOgreObject(Ogre::MovableObject* object) 474 { this->node_->attachObject(object); } 474 { 475 this->node_->attachObject(object); 476 object->setUserObject(this); 477 } 478 475 479 void WorldEntity::attachOgreObject(Ogre::BillboardSet* object) 476 { this-> node_->attachObject(object); }480 { this->attachOgreObject(static_cast<Ogre::MovableObject*>(object)); } 477 481 void WorldEntity::attachOgreObject(Ogre::Camera* object) 478 { this-> node_->attachObject(object); }482 { this->attachOgreObject(static_cast<Ogre::MovableObject*>(object)); } 479 483 void WorldEntity::attachOgreObject(Ogre::Entity* object) 480 { this-> node_->attachObject(object); }484 { this->attachOgreObject(static_cast<Ogre::MovableObject*>(object)); } 481 485 void WorldEntity::attachOgreObject(Ogre::ParticleSystem* object) 482 { this-> node_->attachObject(object); }486 { this->attachOgreObject(static_cast<Ogre::MovableObject*>(object)); } 483 487 484 488 //! Detaches an Ogre::MovableObject from this WorldEntity. 485 489 void WorldEntity::detachOgreObject(Ogre::MovableObject* object) 486 { this->node_->detachObject(object); } 490 { 491 object->setUserObject(NULL); 492 this->node_->detachObject(object); 493 } 494 487 495 void WorldEntity::detachOgreObject(Ogre::BillboardSet* object) 488 { this-> node_->detachObject(object); }496 { this->detachOgreObject(static_cast<Ogre::MovableObject*>(object)); } 489 497 void WorldEntity::detachOgreObject(Ogre::Camera* object) 490 { this-> node_->detachObject(object); }498 { this->detachOgreObject(static_cast<Ogre::MovableObject*>(object)); } 491 499 void WorldEntity::detachOgreObject(Ogre::Entity* object) 492 { this-> node_->detachObject(object); }500 { this->detachOgreObject(static_cast<Ogre::MovableObject*>(object)); } 493 501 void WorldEntity::detachOgreObject(Ogre::ParticleSystem* object) 494 { this-> node_->detachObject(object); }502 { this->detachOgreObject(static_cast<Ogre::MovableObject*>(object)); } 495 503 496 504 //! Detaches an Ogre::MovableObject (by string) from this WorldEntity. … … 646 654 /** 647 655 @brief 648 Makes this WorldEntity look a specific target location.656 Makes this WorldEntity look at a specific target location. 649 657 @param relativeTo 650 658 @see WorldEntity::TransformSpace … … 806 814 void WorldEntity::setCollisionTypeStr(const std::string& typeStr) 807 815 { 808 std::stringtypeStrLower = getLowercase(typeStr);816 const std::string& typeStrLower = getLowercase(typeStr); 809 817 CollisionType type; 810 818 if (typeStrLower == "dynamic") … … 913 921 } 914 922 915 //! Copies our own parameters for restitution, angular factor, damping sand friction to the bullet rigid body.923 //! Copies our own parameters for restitution, angular factor, damping and friction to the bullet rigid body. 916 924 void WorldEntity::internalSetPhysicsProps() 917 925 { -
code/trunk/src/orxonox/worldentities/WorldEntity.h
r5781 r6417 33 33 #include "OrxonoxPrereqs.h" 34 34 35 #include <OgreUserDefinedObject.h> 35 36 #ifdef ORXONOX_RELEASE 36 37 # include <OgreSceneNode.h> … … 55 56 56 57 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 deriv ated objects.58 to create an entire hierarchy of derived objects. 58 59 It is also the basis for the physics interface to the Bullet physics engine. 59 60 Every WorldEntity can have a specific collision type: @see CollisionType … … 63 64 There is also support for attaching WorldEntities with physics to each other. Currently, the collision shape 64 65 of both objects simply get merged into one larger shape (for static collision type). 65 The phy iscal body that is internally stored and administrated has the following supported properties:66 - Restitution, angular factor, linear damping, angular damping, fric ition, 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. 67 68 You can get more information at the corresponding set function. 68 69 69 70 Collision shapes: These are controlled by the internal WorldEntityCollisionShape. @see WorldEntityCollisionShape. 70 71 */ 71 class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState 72 class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState, public Ogre::UserDefinedObject 72 73 { 73 74 friend class Scene; … … 318 319 Sets an artificial parameter that tells how much torque is applied when you apply a non-central force. 319 320 320 Normally the angular factor is 1, which means it's physically 'correct'. Howe rver if you have a player321 Normally the angular factor is 1, which means it's physically 'correct'. However if you have a player 321 322 character that should not rotate when hit sideways, you can set the angular factor to 0. 322 323 */ … … 394 395 You can override this function in a derived class to constrain the collision to e.g. None or Dynamic. 395 396 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 class e's virtual functions397 in its constructor and override this method. But be careful that a derived class's virtual functions 397 398 don't yet exist in the constructor if a base class. 398 399 */ -
code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
r5929 r6417 38 38 #include "PawnManager.h" 39 39 #include "infos/PlayerInfo.h" 40 #include "controllers/Controller.h" 40 41 #include "gametypes/Gametype.h" 41 42 #include "graphics/ParticleSpawner.h" … … 52 53 CreateFactory(Pawn); 53 54 54 registerMemberNetworkFunction( Pawn, doFire );55 56 55 Pawn::Pawn(BaseObject* creator) : ControllableEntity(creator) 57 56 { … … 69 68 70 69 this->spawnparticleduration_ = 3.0f; 70 71 this->aimPosition_ = Vector3::ZERO; 71 72 72 73 this->getPickups().setOwner(this); … … 110 111 XMLPortObject(Pawn, WeaponSlot, "weaponslots", addWeaponSlot, getWeaponSlot, xmlelement, mode); 111 112 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); 113 114 } 114 115 … … 119 120 registerVariable(this->initialHealth_, VariableDirection::ToClient); 120 121 registerVariable(this->bReload_, VariableDirection::ToServer); 122 registerVariable(this->aimPosition_, Bidirectionality::ServerMaster, 0, true); 121 123 } 122 124 … … 166 168 void Pawn::hit(Pawn* originator, const Vector3& force, float damage) 167 169 { 168 if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) )170 if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) 169 171 { 170 172 this->damage(damage, originator); … … 175 177 } 176 178 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 177 192 void Pawn::kill() 178 193 { … … 184 199 { 185 200 // play spawn effect 186 if ( this->spawnparticlesource_ != "")201 if (!this->spawnparticlesource_.empty()) 187 202 { 188 203 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); … … 263 278 } 264 279 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); 283 284 } 284 285 … … 341 342 } 342 343 344 void Pawn::addWeaponPackXML(WeaponPack * wPack) 345 { 346 if (this->weaponSystem_) 347 if (!this->weaponSystem_->addWeaponPack(wPack)) 348 wPack->destroy(); 349 } 350 343 351 WeaponPack * Pawn::getWeaponPack(unsigned int index) const 344 352 { -
code/trunk/src/orxonox/worldentities/pawns/Pawn.h
r5781 r6417 75 75 { return this->lastHitOriginator_; } 76 76 77 virtual void damage(float damage, Pawn* originator = 0);78 77 virtual void hit(Pawn* originator, const Vector3& force, float damage); 78 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage); 79 79 virtual void kill(); 80 80 81 virtual void fire (unsigned int firemode);81 virtual void fired(unsigned int firemode); 82 82 virtual void reload(); 83 virtual void doFire(uint8_t firemode);84 83 virtual void postSpawn(); 85 84 … … 89 88 WeaponSet * getWeaponSet(unsigned int index) const; 90 89 void addWeaponPack(WeaponPack * wPack); 90 void addWeaponPackXML(WeaponPack * wPack); 91 91 WeaponPack * getWeaponPack(unsigned int index) const; 92 92 … … 117 117 virtual void startLocalHumanControl(); 118 118 119 void setAimPosition( Vector3 position ) 120 { this->aimPosition_ = position; } 121 Vector3 getAimPosition() 122 { return this->aimPosition_; } 123 119 124 protected: 120 125 virtual void setPlayer(PlayerInfo* player); … … 125 130 virtual void deatheffect(); 126 131 virtual void spawneffect(); 132 133 virtual void damage(float damage, Pawn* originator = 0); 127 134 128 135 bool bAlive_; … … 146 153 inline void setWeaponSystem(WeaponSystem* weaponsystem) 147 154 { this->weaponSystem_ = weaponsystem; } 155 156 Vector3 aimPosition_; 148 157 }; 149 158 } -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc
r5929 r6417 187 187 void SpaceShip::loadEngineTemplate() 188 188 { 189 if ( this->enginetemplate_ != "")189 if (!this->enginetemplate_.empty()) 190 190 { 191 191 Template* temp = Template::getTemplate(this->enginetemplate_); -
code/trunk/src/orxonox/worldentities/pawns/Spectator.cc
r5929 r6417 189 189 } 190 190 191 void Spectator::fire (unsigned int firemode)191 void Spectator::fired(unsigned int firemode) 192 192 { 193 193 if (this->getPlayer()) -
code/trunk/src/orxonox/worldentities/pawns/Spectator.h
r5781 r6417 55 55 virtual void rotateRoll(const Vector2& value); 56 56 57 virtual void fire (unsigned int firemode);57 virtual void fired(unsigned int firemode); 58 58 virtual void greet(); 59 59
Note: See TracChangeset
for help on using the changeset viewer.