Commits

Jason MacWilliams committed a0db528

soundpool updates and vehicle sound calls

Comments (0)

Files changed (5)

MAX/SoundManager.cpp

 /**
  * @file SoundManager.cpp
  * @author Jason MacWilliams
- * @date Jun 26, 2014
+ * @date Aug 18, 2014
  *
  * The implementation of the SoundManager class.
  *
 }
 
 /**
+ * Get the soundpool with the given name.  If there is no soundpool with the
+ * given name then return NULL.
+ * @param name The name of the SoundPool to retrieve.
+ * @return The SoundPool with the given name, or NULL if the pool does not exist.
+ */
+SoundPool * SoundManager::getSoundPool(const std::string & name) {
+  for (unsigned int i=0; i<sndPools.size(); i++) {
+    if (name.compare(sndPools[i]->getName()) == 0) {
+      return sndPools[i];
+    }
+  }
+  return NULL;
+}
+
+/**
  * Tell this Sound Manager to play the sound specified by the given ID.
  * Configure a 3D sound to emit from the given position moving with the given
  * speed (for doppler effects).  The sound will play once (non looping).
   return playSound(pool->getRandomSound(), loop, gain, group, x, y, z, vx, vy, vz);
 }
 
+PlayingSound * SoundManager::playSound(const std::string & pool, bool loop, ALfloat gain, AUDIO_GROUP group, ALfloat x, ALfloat y, ALfloat z, ALfloat vx, ALfloat vy, ALfloat vz) {
+  for (unsigned int i=0; i<sndPools.size(); i++) {
+    if (pool.compare(sndPools[i]->getName()) == 0) {
+      return playSound(sndPools[i]->getRandomSound(), loop, gain, group, x, y, z, vx, vy, vz);
+    }
+  }
+  return NULL;
+}
+
 /**
  * Stop playback of a currently playing sound.  First we tell the source to stop
  * playing, then we find all the buffers that are queued up for the source in

MAX/SoundManager.h

 /**
  * @file SoundManager.h
  * @author Jason MacWilliams
- * @date Jun 25, 2014
+ * @date Aug 18, 2014
  *
  * The implementation of the SoundManager class.
  *
 
   SoundPool * createSoundPool(const std::string & name);
   int loadSoundPools(const std::string & filename);
+  SoundPool * getSoundPool(const std::string & name);
 
   // start a sound
   PlayingSound * playSound(ALuint sndID, bool loop, ALfloat gain, AUDIO_GROUP group, ALfloat x, ALfloat y, ALfloat z, ALfloat vx, ALfloat vy, ALfloat vz);
   PlayingSound * playSound(SoundPool * pool, bool loop, ALfloat gain, AUDIO_GROUP group, ALfloat x, ALfloat y, ALfloat z, ALfloat vx, ALfloat vy, ALfloat vz);
+  PlayingSound * playSound(const std::string & pool, bool loop, ALfloat gain, AUDIO_GROUP group, ALfloat x, ALfloat y, ALfloat z, ALfloat vx, ALfloat vy, ALfloat vz);
+
   // stop a sound
   void stopSound(PlayingSound * sound);
   // update all the currently playing sounds

MAX/VehicleBase.cpp

 /**
  * @file VehicleBase.cpp
  * @author Jason MacWilliams
- * @date Jun 27, 2014
+ * @date Aug 18, 2014
  *
  * The impementation of the VehicleBase class.
  *
 #include "SoundManager.h"
 #include "Game.h"
 #include "Logger.h"
+#include "Player.h"
 #include "AStarWorkerPool.h"
 #include "Prefab.h"
 #include "UnitOrders.h"
 };
 
 // =============================================================================
-// AUDIO VARIABLES
-static int ready[4] = { 0, 0, 0, 0 };
-
-static void initSounds() {
-  if (!ready[0]) {
-    ready[0] = SoundManager::GetSingleton()->loadSound("assets/voices/ready1.wav");
-    ready[1] = SoundManager::GetSingleton()->loadSound("assets/voices/ready2.wav");
-    ready[2] = SoundManager::GetSingleton()->loadSound("assets/voices/ready3.wav");
-    ready[3] = SoundManager::GetSingleton()->loadSound("assets/voices/ready4.wav");
-  }
-}
-
-// =============================================================================
 // VehicleBase class
 
 /**
   pathCalculator(NULL) {
   // function body
   type = OBJ_VEHICLE;
-  // initialize common sound values
-  initSounds();
 }
 
 /**
   // function body
   type = OBJ_VEHICLE;
   // initialize common sound values
-  initSounds();
   if (prefab->shots > 0) {
     menuOptions.push_back("Attack");
   }
   GameObject::onSelected(player, map);
 
   // its possible one of my subclasses will override this and this should not fire
-
-  // play the selected unit sound ("ready")
-  int sndID = ready[rand()%4];
-  if (sndID) {
-    PlayingSound * snd = SoundManager::GetSingleton()->playSound(sndID, false, 0.75f, AUDIO_VOICE, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
-    playingSounds.push_back(snd);
+  if (owner->getPlayerNumber() == player->getPlayerNumber()) {
+    // play the selected unit sound ("ready")
+    PlayingSound * snd = SoundManager::GetSingleton()->playSound("ready", false, 0.75f, AUDIO_VOICE, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+    if (snd) playingSounds.push_back(snd);
   }
 }
 

MAX/VehicleBase.h

 /**
  * @file VehicleBase.h
  * @author Jason MacWilliams
- * @date Jun 27, 2014
+ * @date Aug 18, 2014
  *
  * The declaration of the VehicleBase class.
  *
 #include "GameObject.h"
 
 class UnitOrder;
+class AStarWorker;
 struct PrefabVehicle;
-class AStarWorker;
 
 /**
  * @class VehicleBase VehicleBase.h "VehicleBase.h"

MAX/VehicleSurveyor.cpp

 /**
  * @file VehicleSurveyor.cpp
  * @author Jason MacWilliams
- * @date Jun 11, 2014
+ * @date Aug 18, 2014
  *
  * The implementation of the VehicleSurveyor class.
  *
 #include "Player.h"
 #include "SoundManager.h"
 
-// =============================================================================
-// AUDIO VARIABLES
-static int surveying[2] = { 0, 0 };
-
-static void initSounds() {
-  if (!surveying[0]) {
-    surveying[0] = SoundManager::GetSingleton()->loadSound("assets/voices/surveying1.wav");
-    surveying[1] = SoundManager::GetSingleton()->loadSound("assets/voices/surveying2.wav");
-  }
-}
-
 /**
  * Default constructor.  Does nothing, just initializes an empty (prefab-less)
  * surveyor.
 VehicleSurveyor::VehicleSurveyor() : VehicleBase() {
   type |= VHCL_SURVEYOR;
   menuOptions.push_back("Auto");
-  initSounds();
 }
 
 /**
 VehicleSurveyor::VehicleSurveyor(const PrefabVehicle * prefab) : VehicleBase(prefab) {
   type |= VHCL_SURVEYOR;
   menuOptions.push_back("Auto");
-  initSounds();
 }
 
 VehicleSurveyor::~VehicleSurveyor() {
  * @param fromY The y coordinate of the old cell.
  * @param toX The x coordinate of the new cell.
  * @param toY The y coordinate of the new cell.
- * @see VehicleBase#onMove for the base function that updates movement
+ * @see VehicleBase#onMove for the base function that updates movement.
  */
 void VehicleSurveyor::onMove(int fromX, int fromY, int toX, int toY) {
   VehicleBase::onMove(fromX, fromY, toX, toY);
   onMove(x, y, x, y);
 }
 
+/**
+ * This surveyor has just become the actively selected unit by the given player.
+ * It should perform the required functions - mostly notably, playing its
+ * "status" sound.  The player is also supplied to the function so the unit
+ * can tell if it is supposed to respond to messages.
+ * @param player The Player who sent the onSelected message.  If the sending
+ *               player is not my owner then I probably want to ignore the
+ *               message.
+ * @param map The map data which can be used to determine if the unit is on
+ *            ground or in the water.
+ * @note Possibly return a message response structure?
+ * @todo It sounds like this function is not being called.  Fix this.
+ */
 void VehicleSurveyor::onSelected(const Player * player, const IMovementAccess * map) {
 
   int index = rand()%6;
     GameObject::onSelected(player, map);
 
     // play the selected unit sound ("surveying")
-    int sndID = surveying[index-4];
-    if (sndID) {
-      PlayingSound * snd = SoundManager::GetSingleton()->playSound(sndID, false, 1.0f, AUDIO_FX, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
-      playingSounds.push_back(snd);
-    }
+    PlayingSound * snd = SoundManager::GetSingleton()->playSound("surveying", false, 1.0f, AUDIO_FX, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+    if (snd) playingSounds.push_back(snd);
   }
 }