1. Jason MacWilliams
  2. MAX

Commits

Jason MacWilliams  committed 0bda8c4

finished soundpool parser and make system load the soundpools

  • Participants
  • Parent commits 1edc024
  • Branches default

Comments (0)

Files changed (6)

File MAX/CursorManager.cpp

View file
   tinyxml2::XMLDocument doc;
   tinyxml2::XMLError err = doc.LoadFile(cursorXml.c_str());
   if (err != tinyxml2::XML_NO_ERROR) {
-    CGlobalLogger::GetSingleton()->write("CursorManager::init: xml error while parsing file");
+    CGlobalLogger::GetSingleton()->write("CursorManager::init: xml error while parsing file \"%s\"", cursorXml.c_str());
     return false;
   }
 
   const char * elemName = pElem->Value();
   if (_stricmp(elemName, "Cursors") != 0) {
     // invalid  file
-    CGlobalLogger::GetSingleton()->write("CursorManager::init invalid root element in file");
+    CGlobalLogger::GetSingleton()->write("CursorManager::init invalid root element in file \"%s\"", cursorXml.c_str());
     return false;
   }
 

File MAX/SceneManager.cpp

View file
     return false;
   }
 
+  // load the sound pools
+  err = SoundManager::GetSingleton()->loadSoundPools("sounds/voicedata.xml");
+  if (err > 0) {
+    CGlobalLogger::GetSingleton()->write("Failed to load sound pools with error %d", err);
+    return false;
+  }
+
   // generate reports
   TextureManager::GetSingleton()->printTextureLog();
   SoundManager::GetSingleton()->printSoundLog();

File MAX/SoundManager.cpp

View file
 // project level includes
 #include "SoundManager.h"
 #include "Logger.h"
+#include "tinyxml2/tinyxml2.h"
 #include "vorbis/vorbisenc.h"
 #include "vorbis/vorbisfile.h"
 
   sndPools.clear();
 
   // cleanup the playing list
-  for (unsigned int i=0; i<playingList.size();; i++) {
+  for (unsigned int i=0; i<playingList.size(); i++) {
     if (playingList[i]) {
       delete playingList[i];
     }
  */
 SoundPool * SoundManager::createSoundPool(const std::string & name) {
   // check to see if we already have a pool with this name
-  for (int i=0; i<sndPools.size(); i++) {
+  for (unsigned int i=0; i<sndPools.size(); i++) {
     if (name.compare(sndPools[i]->getName()) == 0) {
       return sndPools[i];
     }
   return pool;
 }
 
+/**
+ *
+ */
 int SoundManager::loadSoundPools(const std::string & filename) {
-  return sndPools.size();
+  tinyxml2::XMLDocument doc;
+  tinyxml2::XMLError err = doc.LoadFile(filename.c_str());
+  if (err != tinyxml2::XML_NO_ERROR) {
+    CGlobalLogger::GetSingleton()->write("SoundManager::loadSoundPools: could not open file \"%s\"", filename.c_str());
+    return 1;
+  }
+
+  tinyxml2::XMLElement * root = doc.RootElement();
+  const char * value = root->Value();
+  if (_stricmp(value, "SoundPools") != 0) {
+    // invalid file
+    CGlobalLogger::GetSingleton()->write("SoundManager::loadSoundPools: invalid root element in file \"%s\"", filename.c_str());
+    return 2;
+  }
+
+  const tinyxml2::XMLElement * child = NULL;
+  for (child=root->FirstChildElement(); child; child=child->NextSiblingElement()) {
+    // this should be a soundpool
+    value = child->Attribute("name");
+    if (!value) value = child->Attribute("Name");
+    if (value) {
+      SoundPool * pool = createSoundPool(value);
+      for (const tinyxml2::XMLElement * file = child->FirstChildElement("File"); file; file=file->NextSiblingElement("File")) {
+        const char * text = file->GetText();
+        pool->addSound(loadSound(text));
+      }
+    }
+  }
+
+  return 0;
 }
 
 /**
 }
 
 PlayingSound * SoundManager::playSound(SoundPool * pool, bool loop, ALfloat gain, AUDIO_GROUP group, ALfloat x, ALfloat y, ALfloat z, ALfloat vx, ALfloat vy, ALfloat vz) {
-  return playSound(pool->getRandomSound()->sndID, loop, gain, group, x, y, z, vx, vy, vz);
+  return playSound(pool->getRandomSound(), loop, gain, group, x, y, z, vx, vy, vz);
 }
 
 /**

File MAX/SoundUtils.cpp

View file
 // =============================================================================
 // SOUNDPOOL
 
-SoundPool::SoundPool() : name(""), sounds(std::vector<Sound *>()) {
+SoundPool::SoundPool() : name(""), sounds(std::vector<ALuint>()) {
 }
 
-SoundPool::SoundPool(std::string name) : name(name), sounds(std::vector<Sound *>()) {
+SoundPool::SoundPool(std::string name) : name(name), sounds(std::vector<ALuint>()) {
 }
 
 SoundPool::~SoundPool() {
   return name;
 }
 
-unsigned int SoundPool::addSound(Sound * sound) {
-  if (sound)
+unsigned int SoundPool::addSound(ALuint sound) {
+  // early return in case we already include this sound
+  for (unsigned int i=0; i<sounds.size(); i++) {
+    if (sounds[i] == sound) return sounds.size();
+  }
+  if (sound != 0)
     sounds.push_back(sound);
   return sounds.size();
 }
 
-Sound * SoundPool::getRandomSound() const {
+ALuint SoundPool::getRandomSound() const {
   if (sounds.size() == 0) {
     return NULL;
   }

File MAX/SoundUtils.h

View file
 class SoundPool {
 private:
   std::string name;
-  std::vector<Sound *> sounds;
+  std::vector<ALuint> sounds;
 
 public:
   SoundPool();
   virtual ~SoundPool();
 
   std::string getName() const;
-  unsigned int addSound(Sound * sound);
-  Sound * getRandomSound() const;
+  unsigned int addSound(ALuint sound);
+  ALuint getRandomSound() const;
 };

File MAX/sounds/voicedata.xml

View file
-<Voices>
-  <SoundPool id="20secondsleft">
+<SoundPools>
+  <SoundPool name="20secondsleft">
     <File>assets/voices/20_seconds_left1.WAV</File>
     <File>assets/voices/20_seconds_left2.WAV</File>
   </SoundPool>
 
-  <SoundPool id="noammo">
+  <SoundPool name="noammo">
     <File>assets/voices/ammo_depleted.WAV</File>
   </SoundPool>
 
-  <SoundPool id="lowammo">
+  <SoundPool name="lowammo">
     <File>assets/voices/ammo_low1.WAV</File>
     <File>assets/voices/ammo_low2.WAV</File>
     <File>assets/voices/ammo_low3.WAV</File>
   </SoundPool>
 
-  <SoundPool id="attacking">
+  <SoundPool name="attacking">
     <File>assets/voices/attacking1.WAV</File>
     <File>assets/voices/attacking2.WAV</File>
   </SoundPool>
 
-  <SoundPool id="beginturn">
+  <SoundPool name="beginturn">
     <File>assets/voices/begin.WAV</File>
   </SoundPool>
 
-  <SoundPool id="building">
+  <SoundPool name="building">
     <File>assets/voices/building.WAV</File>
   </SoundPool>
 
-  <SoundPool id="clearingarea">
+  <SoundPool name="clearingarea">
     <File>assets/voices/clearing_area.WAV</File>
   </SoundPool>
 
-  <SoundPool id="constructioncomplete">
+  <SoundPool name="constructioncomplete">
     <File>assets/voices/construction_complete1.WAV</File>
     <File>assets/voices/construction_complete2.WAV</File>
     <File>assets/voices/construction_complete3.WAV</File>
     <File>assets/voices/construction_complete6.WAV</File>
   </SoundPool>
 
-  <SoundPool id="enemyspotted">
+  <SoundPool name="enemyspotted">
     <File>assets/voices/enemy_spotted1.WAV</File>
     <File>assets/voices/enemy_spotted2.WAV</File>
   </SoundPool>
 
-  <SoundPool id="firing">
+  <SoundPool name="firing">
     <File>assets/voices/firing1.WAV</File>
     <File>assets/voices/firing2.WAV</File>
   </SoundPool>
 
-  <SoundPool id="gamesaved">
+  <SoundPool name="gamesaved">
     <File>assets/voices/game_saved.WAV</File>
   </SoundPool>
 
-  <SoundPool id="infiltratorfail">
+  <SoundPool name="infiltratorfail">
     <File>assets/voices/infiltrator_fail1.WAV</File>
     <File>assets/voices/infiltrator_fail2.WAV</File>
     <File>assets/voices/infiltrator_fail3.WAV</File>
   </SoundPool>
 
-  <SoundPool id="missionsuccess">
+  <SoundPool name="missionsuccess">
     <File>assets/voices/mission_success.WAV</File>
   </SoundPool>
 
-  <SoundPool id="movementexhausted">
+  <SoundPool name="movementexhausted">
     <File>assets/voices/movement_exhausted.WAV</File>
   </SoundPool>
 
-  <SoundPool id="newunits">
+  <SoundPool name="newunits">
     <File>assets/voices/new_unit.WAV</File>
     <File>assets/voices/new_units_this_turn.WAV</File>
     <File>assets/voices/new_units1.WAV</File>
     <File>assets/voices/new_units2.WAV</File>
   </SoundPool>
 
-  <SoundPool id="nopath">
+  <SoundPool name="nopath">
     <File>assets/voices/no_path1.WAV</File>
     <File>assets/voices/no_path2.WAV</File>
   </SoundPool>
 
-  <SoundPool id="layingmines">
+  <SoundPool name="layingmines">
     <File>assets/voices/placing_mines1.WAV</File>
     <File>assets/voices/placing_mines2.WAV</File>
   </SoundPool>
 
-  <SoundPool id="ready">
+  <SoundPool name="ready">
     <File>assets/voices/ready1.WAV</File>
     <File>assets/voices/ready2.WAV</File>
     <File>assets/voices/ready3.WAV</File>
   </SoundPool>
 
   <!-- single unit reload -->
-  <SoundPool id="reloaded">
+  <SoundPool name="reloaded">
     <File>assets/voices/reloaded.WAV</File>
   </SoundPool>
   <!-- mass init reload -->
-  <SoundPool id="massreloaded">
+  <SoundPool name="massreloaded">
     <File>assets/voices/mass_reload.WAV</File>
     <File>assets/voices/reloaded.WAV</File>
   </SoundPool>
 
   <!-- single unit repair -->
-  <SoundPool id="unitrepaired">
+  <SoundPool name="unitrepaired">
     <File>assets/voices/unit_repaired1.WAV</File>
     <File>assets/voices/unit_repaired2.WAV</File>
   </SoundPool>
   <!-- multi unit repair -->
-  <SoundPool id="massrepair">
+  <SoundPool name="massrepair">
     <File>assets/voices/mass_repair1.WAV</File>
     <File>assets/voices/mass_repair2.WAV</File>
   </SoundPool>
 
 
-  <SoundPool id="removingmines">
+  <SoundPool name="removingmines">
     <File>assets/voices/removing_mines1.WAV</File>
     <File>assets/voices/removing_mines2.WAV</File>
   </SoundPool>
 
     <File>assets/voices/research_complete.WAV</File>
 
-  <SoundPool id="selectlandingsite">
+  <SoundPool name="selectlandingsite">
     <File>assets/voices/select_landing_site.WAV</File>
   </SoundPool>
 
-  <SoundPool id="selectbuildingsite">
+  <SoundPool name="selectbuildingsite">
     <File>assets/voices/select_site1.WAV</File>
     <File>assets/voices/select_site2.WAV</File>
   </SoundPool>
 
-  <SoundPool id="onsentry">
+  <SoundPool name="onsentry">
     <File>assets/voices/sentry.WAV</File>
   </SoundPool>
 
-  <SoundPool id="statusred">
+  <SoundPool name="statusred">
     <File>assets/voices/status_red1.WAV</File>
     <File>assets/voices/status_red2.WAV</File>
   </SoundPool>
 
-  <SoundPool id="statusyellow">
+  <SoundPool name="statusyellow">
     <File>assets/voices/status_yellow1.WAV</File>
     <File>assets/voices/status_yellow2.WAV</File>
   </SoundPool>
 
-  <SoundPool id="submarinedetected">
+  <SoundPool name="submarinedetected">
     <File>assets/voices/submarine_detected.WAV</File>
   </SoundPool>
 
-  <SoundPool id="surveying">
+  <SoundPool name="surveying">
     <File>assets/voices/surveying1.WAV</File>
     <File>assets/voices/surveying2.WAV</File>
   </SoundPool>
 
-  <SoundPool id="underattack">
+  <SoundPool name="underattack">
     <File>assets/voices/under_attack1.WAV</File>
     <File>assets/voices/under_attack2.WAV</File>
     <File>assets/voices/under_attack3.WAV</File>
     <File>assets/voices/under_attack6.WAV</File>
   </SoundPool>
 
-  <SoundPool id="unitdisabled">
+  <SoundPool name="unitdisabled">
     <File>assets/voices/unit_disabled.WAV</File>
   </SoundPool>
 
-  <SoundPool id="unitlost">
+  <SoundPool name="unitlost">
     <File>assets/voices/unit_lost1.WAV</File>
     <File>assets/voices/unit_lost2.WAV</File>
     <File>assets/voices/unit_lost3.WAV</File>
   </SoundPool>
 
-  <SoundPool id="unitready">
+  <SoundPool name="unitready">
     <File>assets/voices/unit_ready.WAV</File>
   </SoundPool>
 
-  <SoundPool id="xfercomplete">
+  <SoundPool name="xfercomplete">
     <File>assets/voices/xfer_complete.WAV</File>
   </SoundPool>
 
   <!-- "colony started" -->
-  <SoundPool id="bluecolony">
+  <SoundPool name="bluecolony">
     <File>assets/voices/blue_team_colony_started.WAV</File>
   </SoundPool>
-  <SoundPool id="redcolony">
+  <SoundPool name="redcolony">
     <File>assets/voices/red_team_colony_started.WAV</File>
   </SoundPool>
-  <SoundPool id="greencolony">
+  <SoundPool name="greencolony">
     <File>assets/voices/green_team_colony_started.WAV</File>
   </SoundPool>
-  <SoundPool id="greycolony">
+  <SoundPool name="greycolony">
     <File>assets/voices/grey_team_colony_started.WAV</File>
   </SoundPool>
 
   <!-- "has left the planet" -->
-  <SoundPool id="blueleft">
+  <SoundPool name="blueleft">
     <File>assets/voices/blue_team_left1.WAV</File>
     <File>assets/voices/blue_team_left2.WAV</File>
   </SoundPool>
-  <SoundPool id="redleft">
+  <SoundPool name="redleft">
     <File>assets/voices/red_team_left1.WAV</File>
     <File>assets/voices/red_team_left2.WAV</File>
   </SoundPool>
-  <SoundPool id="greenleft">
+  <SoundPool name="greenleft">
     <File>assets/voices/green_team_left1.WAV</File>
     <File>assets/voices/green_team_left2.WAV</File>
   </SoundPool>
-  <SoundPool id="greyleft">
+  <SoundPool name="greyleft">
     <File>assets/voices/grey_team_left1.WAV</File>
     <File>assets/voices/grey_team_left2.WAV</File>
   </SoundPool>
 
-</Voices>
+</SoundPools>