Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4883 in orxonox.OLD


Ignore:
Timestamp:
Jul 17, 2005, 4:02:36 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/weaponSystem: connecting sounds to the weapon works fine now

Location:
orxonox/branches/weaponSystem/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/weaponSystem/src/lib/sound/sound_engine.cc

    r4880 r4883  
    9191 *  creates a SoundSource at position sourceNode with the SoundBuffer buffer
    9292*/
    93 SoundSource::SoundSource(SoundBuffer* buffer, PNode* sourceNode)
     93SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer)
    9494{
    9595  this->setClassID(CL_SOUND_SOURCE, "SoundSource");
     
    106106  if ((result = alGetError()) != AL_NO_ERROR)
    107107    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());
    109110  alSourcef (this->sourceID, AL_PITCH,    1.0      );
    110111  alSourcef (this->sourceID, AL_GAIN,     1.0      );
     
    127128{
    128129  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 */
     136void SoundSource::play(const SoundBuffer* buffer)
     137{
     138  alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     139  alSourcePlay(this->sourceID);
     140//  printf("playing sound\n");
    129141}
    130142
     
    229241SoundSource* SoundEngine::createSource(const char* fileName, PNode* sourceNode)
    230242{
    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));
    232244}
    233245
  • orxonox/branches/weaponSystem/src/lib/sound/sound_engine.h

    r4878 r4883  
    2727
    2828  /** @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; }
    3030
    3131 private:
     
    3737
    3838//! A class that represents a SoundSource
    39 /**
    40  * @todo ability to play back different SoundBuffers on the same SounSource
    41  */
    4239class SoundSource : public BaseObject
    4340{
    4441 public:
    45   SoundSource(SoundBuffer* buffer, PNode* sourceNode = NULL);
     42  SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL);
    4643  ~SoundSource();
    4744
    4845  // user interaction
    4946  void play();
     47  void play(const SoundBuffer* buffer);
    5048  void stop();
    5149  void pause();
     
    5654  inline ALuint getID() const { return this->sourceID; }
    5755  /** @returns the SoundBuffer of this Source */
    58   inline SoundBuffer* getBuffer() const { return this->buffer; }
     56  inline const SoundBuffer* getBuffer() const { return this->buffer; }
    5957  /** @returns the SourceNode of this Source */
    60   inline PNode* getNode() const { return this->sourceNode;}
     58  inline const PNode* getNode() const { return this->sourceNode;}
    6159
    6260  void setRolloffFactor(ALfloat rolloffFactor);
    6361
    6462 private:
    65   ALuint           sourceID;              //!< The ID of the Source
    66   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.
    6866};
    6967
  • orxonox/branches/weaponSystem/src/util/animation/t_animation.h

    r4837 r4883  
    205205              this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame);
    206206
    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);
    208208              this->setAnimFunc(this->currentKeyFrame->animFunc);
    209209            }
  • orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc

    r4882 r4883  
    9696  this->weaponSource->setRolloffFactor(.1);*/
    9797  Projectile* p = new TestBullet(this);
    98 //  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
     98
     99  //  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
    99100  //ObjectManager::getInstance()->debug();
    100101
    101   this->setStateDuration(WS_SHOOTING, 2);
     102  this->setStateDuration(WS_SHOOTING, .2);
    102103
    103104  this->energy = 100;
    104105  this->minCharge = 2;
     106
     107  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
    105108}
    106109
     
    150153{
    151154  this->energyLoaded -= this->minCharge;
     155  if (this->soundBuffers[WA_SHOOT] != NULL)
     156    this->soundSource->play(this->soundBuffers[WA_SHOOT]);
     157
    152158
    153159  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  
    5353  for (int i = 0; i < WA_ACTION_COUNT; i++)
    5454    if (this->soundBuffers[i])
    55       delete this->soundBuffers[i];
     55      ResourceManager::getInstance()->unload(this->soundBuffers[i]);
    5656}
    5757
     
    7373
    7474  this->requestedAction = WA_NONE;
    75   this->weaponSource = NULL;
     75  this->soundSource = new SoundSource(this);
    7676
    7777  this->active = true;
     
    8686}
    8787
    88 /**
    89  * sets a new projectile to the weapon
    90  * @param new projectile for this weapon
     88
     89void 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
    91111 *
    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 */
    112115void Weapon::requestAction(WeaponAction action)
    113116{
     
    187190{
    188191  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]);
    189195}
    190196
     
    196202{
    197203  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]);
    198207}
    199208
     
    201210{
    202211  this->energyLoaded -= this->minCharge;
     212
     213  if (this->soundBuffers[WA_SHOOT] != NULL)
     214    this->soundSource->play(this->soundBuffers[WA_SHOOT]);
    203215}
    204216
     
    226238    this->energy -= chargeSize;
    227239  }
     240  if (this->soundBuffers[WA_RELOAD] != NULL)
     241    this->soundSource->play(this->soundBuffers[WA_RELOAD]);
     242
    228243}
    229244
    230245void Weapon::charge()
    231246{
     247  if (this->soundBuffers[WA_CHARGE] != NULL)
     248    this->soundSource->play(this->soundBuffers[WA_CHARGE]);
     249
    232250}
    233251
  • orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h

    r4882 r4883  
    8585
    8686    // 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; };
    8991
    9092    /** @param state the State to time @param duration the duration of the State */
     
    98100    /** @returns the current State of the Weapon */
    99101    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; };
    100104
    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); };
    102108
    103109    virtual void destroy();
     
    129135
    130136  protected:
    131     SoundSource*         weaponSource;
     137    SoundSource*         soundSource;
    132138    // it is all about energy
    133139    float                energy;
     
    145151    float                stateDuration;                    //!< how long the state has taken until now.
    146152    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).
    147154    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).
    149155
    150156
Note: See TracChangeset for help on using the changeset viewer.