Changeset 4883 in orxonox.OLD for orxonox/branches/weaponSystem/src
- Timestamp:
- Jul 17, 2005, 4:02:36 PM (19 years ago)
- Location:
- orxonox/branches/weaponSystem/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/weaponSystem/src/lib/sound/sound_engine.cc
r4880 r4883 91 91 * creates a SoundSource at position sourceNode with the SoundBuffer buffer 92 92 */ 93 SoundSource::SoundSource( SoundBuffer* buffer, PNode* sourceNode)93 SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer) 94 94 { 95 95 this->setClassID(CL_SOUND_SOURCE, "SoundSource"); … … 106 106 if ((result = alGetError()) != AL_NO_ERROR) 107 107 SoundEngine::PrintALErrorString(result); 108 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 108 if (this->buffer != NULL) 109 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 109 110 alSourcef (this->sourceID, AL_PITCH, 1.0 ); 110 111 alSourcef (this->sourceID, AL_GAIN, 1.0 ); … … 127 128 { 128 129 alSourcePlay(this->sourceID); 130 } 131 132 /** 133 * Plays back buffer on this Source 134 * @param buffer the buffer to play back on this Source 135 */ 136 void SoundSource::play(const SoundBuffer* buffer) 137 { 138 alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); 139 alSourcePlay(this->sourceID); 140 // printf("playing sound\n"); 129 141 } 130 142 … … 229 241 SoundSource* SoundEngine::createSource(const char* fileName, PNode* sourceNode) 230 242 { 231 return new SoundSource( (SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL), sourceNode);243 return new SoundSource(sourceNode, (SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL)); 232 244 } 233 245 -
orxonox/branches/weaponSystem/src/lib/sound/sound_engine.h
r4878 r4883 27 27 28 28 /** @returns the ID of the buffer used in this SoundBuffer */ 29 inline ALuint getID() { return this->bufferID; }29 inline ALuint getID() const { return this->bufferID; } 30 30 31 31 private: … … 37 37 38 38 //! A class that represents a SoundSource 39 /**40 * @todo ability to play back different SoundBuffers on the same SounSource41 */42 39 class SoundSource : public BaseObject 43 40 { 44 41 public: 45 SoundSource( SoundBuffer* buffer, PNode* sourceNode= NULL);42 SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL); 46 43 ~SoundSource(); 47 44 48 45 // user interaction 49 46 void play(); 47 void play(const SoundBuffer* buffer); 50 48 void stop(); 51 49 void pause(); … … 56 54 inline ALuint getID() const { return this->sourceID; } 57 55 /** @returns the SoundBuffer of this Source */ 58 inline SoundBuffer* getBuffer() const { return this->buffer; }56 inline const SoundBuffer* getBuffer() const { return this->buffer; } 59 57 /** @returns the SourceNode of this Source */ 60 inline PNode* getNode() const { return this->sourceNode;}58 inline const PNode* getNode() const { return this->sourceNode;} 61 59 62 60 void setRolloffFactor(ALfloat rolloffFactor); 63 61 64 62 private: 65 ALuint sourceID; //!< The ID of the Source66 SoundBuffer* buffer; //!< The buffer to play in this source.67 PNode* sourceNode; //!< The SourceNode represente the position/velocity... of this source.63 ALuint sourceID; //!< The ID of the Source 64 const SoundBuffer* buffer; //!< The buffer to play in this source. 65 const PNode* sourceNode; //!< The SourceNode represente the position/velocity... of this source. 68 66 }; 69 67 -
orxonox/branches/weaponSystem/src/util/animation/t_animation.h
r4837 r4883 205 205 this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame); 206 206 207 printf("%p from:%f to:%f\n", this->currentKeyFrame,this->currentKeyFrame->value, this->nextKeyFrame->value);207 //printf("%p from:%f to:%f\n", this->currentKeyFrame,this->currentKeyFrame->value, this->nextKeyFrame->value); 208 208 this->setAnimFunc(this->currentKeyFrame->animFunc); 209 209 } -
orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc
r4882 r4883 96 96 this->weaponSource->setRolloffFactor(.1);*/ 97 97 Projectile* p = new TestBullet(this); 98 // ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p); 98 99 // ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p); 99 100 //ObjectManager::getInstance()->debug(); 100 101 101 this->setStateDuration(WS_SHOOTING, 2);102 this->setStateDuration(WS_SHOOTING, .2); 102 103 103 104 this->energy = 100; 104 105 this->minCharge = 2; 106 107 this->setActionSound(WA_SHOOT, "sound/shot1.wav"); 105 108 } 106 109 … … 150 153 { 151 154 this->energyLoaded -= this->minCharge; 155 if (this->soundBuffers[WA_SHOOT] != NULL) 156 this->soundSource->play(this->soundBuffers[WA_SHOOT]); 157 152 158 153 159 Projectile* pj = new TestBullet(this);//dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS)); -
orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc
r4882 r4883 53 53 for (int i = 0; i < WA_ACTION_COUNT; i++) 54 54 if (this->soundBuffers[i]) 55 delete this->soundBuffers[i];55 ResourceManager::getInstance()->unload(this->soundBuffers[i]); 56 56 } 57 57 … … 73 73 74 74 this->requestedAction = WA_NONE; 75 this-> weaponSource = NULL;75 this->soundSource = new SoundSource(this); 76 76 77 77 this->active = true; … … 86 86 } 87 87 88 /** 89 * sets a new projectile to the weapon 90 * @param new projectile for this weapon 88 89 void Weapon::setActionSound(WeaponAction action, const char* soundFile) 90 { 91 if (action >= WA_ACTION_COUNT) 92 return; 93 else 94 { 95 this->soundBuffers[action] = (SoundBuffer*)ResourceManager::getInstance()->load(soundFile, WAV); 96 if (this->soundBuffers[action] != NULL) 97 { 98 PRINTF(4)("Loaded sound %s to action %s\n", soundFile, actionToChar(action)); 99 } 100 else 101 { 102 PRINTF(4)("failed to load sound %s to %s\n", soundFile, actionToChar(action)); 103 } 104 105 } 106 } 107 108 /** 109 * request an action that should be executed, 110 * @param action the next action to take 91 111 * 92 * weapon an projectile are independent, so you can combine them as you want 93 */ 94 void Weapon::setProjectile(Projectile* projectile) 95 { 96 this->projectile = projectile; 97 } 98 99 100 /** 101 * sets a new projectile to the weapon 102 * @returns the current projectile of this weapon 103 * 104 * weapon an projectile are independent, so you can combine them as you want 105 */ 106 Projectile* Weapon::getProjectile() 107 { 108 return this->projectile; 109 } 110 111 112 * This function must be called instead of the actions (like fire/reload...) 113 * to make all the checks needed to have a usefull WeaponSystem. 114 */ 112 115 void Weapon::requestAction(WeaponAction action) 113 116 { … … 187 190 { 188 191 PRINTF(4)("Activating the Weapon %s\n", this->getName()); 192 193 if (this->soundBuffers[WA_ACTIVATE] != NULL) 194 this->soundSource->play(this->soundBuffers[WA_ACTIVATE]); 189 195 } 190 196 … … 196 202 { 197 203 PRINTF(4)("Deactivating the Weapon %s\n", this->getName()); 204 205 if (this->soundBuffers[WA_DEACTIVATE] != NULL) 206 this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]); 198 207 } 199 208 … … 201 210 { 202 211 this->energyLoaded -= this->minCharge; 212 213 if (this->soundBuffers[WA_SHOOT] != NULL) 214 this->soundSource->play(this->soundBuffers[WA_SHOOT]); 203 215 } 204 216 … … 226 238 this->energy -= chargeSize; 227 239 } 240 if (this->soundBuffers[WA_RELOAD] != NULL) 241 this->soundSource->play(this->soundBuffers[WA_RELOAD]); 242 228 243 } 229 244 230 245 void Weapon::charge() 231 246 { 247 if (this->soundBuffers[WA_CHARGE] != NULL) 248 this->soundSource->play(this->soundBuffers[WA_CHARGE]); 249 232 250 } 233 251 -
orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h
r4882 r4883 85 85 86 86 // FUNCTIONS TO SET THE WEAPONS PROPERTIES. 87 void setProjectile(Projectile* projectile); 88 Projectile* getProjectile(); 87 /** @param projectile a projectile for this weapon */ 88 void setProjectile(Projectile* projectile) { this->projectile = projectile; }; 89 /** @returns The projectile if availiable */ 90 Projectile* getProjectile() { return this->projectile; }; 89 91 90 92 /** @param state the State to time @param duration the duration of the State */ … … 98 100 /** @returns the current State of the Weapon */ 99 101 inline WeaponState getCurrentState() const { return this->currentState; }; 102 /** @param energyMax the maximum energy the Weapon can have @param energyLoadedMax the maximum energy in the weapon buffers */ 103 inline void setMaximumEnergy(float energyMax, float energyLoadedMax = 0.0) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; }; 100 104 101 inline void setMaximumEnergy(float energyMax, float energyLoadedMax = 0.0) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; }; 105 void setActionSound(WeaponAction action, const char* soundFile); 106 /** @see void setActionSound(WeaponAction action, const char* soundFile); */ 107 void setActionSound(const char* action, const char* soundFile) { this->setActionSound(charToAction(action), soundFile); }; 102 108 103 109 virtual void destroy(); … … 129 135 130 136 protected: 131 SoundSource* weaponSource;137 SoundSource* soundSource; 132 138 // it is all about energy 133 139 float energy; … … 145 151 float stateDuration; //!< how long the state has taken until now. 146 152 float times[WS_STATE_COUNT]; //!< Times to stay in the different States @see WeaponState. 153 Animation3D* animation[WS_STATE_COUNT]; //!< Animations for all the States (you can say yourself on what part of the gun this animation acts). 147 154 SoundBuffer* soundBuffers[WA_ACTION_COUNT]; //!< SoundBuffers for all actions @see WeaponAction. 148 Animation3D* animation[WS_STATE_COUNT]; //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).149 155 150 156
Note: See TracChangeset
for help on using the changeset viewer.