home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Game_Audio / audio_sdk / src / AudioScript / Theme.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-06-21  |  3.5 KB  |  126 lines

  1. /***********************************************************\
  2. Copyright (C) James Boer, 2002. 
  3. All rights reserved worldwide.
  4.  
  5. This software is provided "as is" without express or implied
  6. warranties. You may freely copy and compile this source into
  7. applications you distribute provided that the copyright text
  8. below is included in the resulting source code, for example:
  9. "Portions Copyright (C) James Boer, 2002"
  10. \***********************************************************/
  11.  
  12. #include "Audio.h"
  13. #include "Theme.h"
  14.  
  15. using namespace std;
  16. using namespace Audio;
  17.  
  18. //------------------------------------------------------------------------//
  19. Theme::Theme()
  20. {
  21.     Clear();
  22. }
  23.  
  24. //------------------------------------------------------------------------//
  25. Theme::~Theme()
  26. {
  27.     SegmentTransitionMap::iterator itr;
  28.     for(itr = m_SegmentMap.begin(); itr != m_SegmentMap.end(); ++itr)
  29.     {
  30.         SAFE_DELETE(itr->second);
  31.     }
  32.     ThemeTransitionMap::iterator itor;
  33.     for(itor = m_ThemeMap.begin(); itor != m_ThemeMap.end(); ++itor)
  34.     {
  35.         SAFE_DELETE(itor->second);
  36.     }
  37. }
  38.  
  39. //------------------------------------------------------------------------//
  40. void Theme::Clear()
  41. {
  42.     m_pDefaultSegment = 0;
  43.     m_SegmentMap.clear();
  44.     m_ThemeMap.clear();
  45.     m_bInterlude = false;
  46.     m_bFirstTransition = false;
  47. }
  48.  
  49. //------------------------------------------------------------------------//
  50. bool Theme::CreateNode(ISegment* pSegment)
  51. {
  52.     if(!pSegment)
  53.         return false;
  54.  
  55.     if(!m_pDefaultSegment)
  56.         m_pDefaultSegment = pSegment;
  57.  
  58.     ISegmentVector* pList = new ISegmentVector;
  59.     if(!m_SegmentMap.insert(make_pair(pSegment, pList)).second)
  60.         return false;
  61.     return true;
  62. }
  63.  
  64. //------------------------------------------------------------------------//
  65. bool Theme::CreateNode(Theme* pTheme)
  66. {
  67.     if(!pTheme)
  68.         return false;
  69.  
  70.     ISegmentVector* pList = new ISegmentVector;
  71.     if(!m_ThemeMap.insert(make_pair(pTheme, pList)).second)
  72.         return false;
  73.     return true;
  74. }
  75.  
  76. //------------------------------------------------------------------------//
  77. bool Theme::CreateTransition(ISegment* pFrom, ISegment* pTo)
  78. {
  79.     SegmentTransitionMap::iterator itr = m_SegmentMap.find(pFrom);
  80.     if(itr == m_SegmentMap.end() || (!itr->second))
  81.         return false;
  82.     itr->second->push_back(pTo);
  83.     return true;
  84. }
  85.  
  86. //------------------------------------------------------------------------//
  87. bool Theme::CreateTransition(Theme* pFrom, ISegment* pTo)
  88. {
  89.     ThemeTransitionMap::iterator itr = m_ThemeMap.find(pFrom);
  90.     if(itr == m_ThemeMap.end() || (!itr->second))
  91.         return false;
  92.     itr->second->push_back(pTo);
  93.     return true;
  94. }
  95.  
  96. //------------------------------------------------------------------------//
  97. bool Theme::GetTransition(Theme* pTheme, ISegment* pFrom, ISegment*& pTo)
  98. {
  99.     bool bFirstTransition = m_bFirstTransition;
  100.     m_bFirstTransition = false;
  101.     pTo = 0;
  102.  
  103.     // First check to see if we can find a specific transition based on the
  104.     // pFrom Segment
  105.     SegmentTransitionMap::iterator itr = m_SegmentMap.find(pFrom);
  106.     if(itr == m_SegmentMap.end() || !itr->second->size())
  107.     {
  108.         // If we can't find a segment-based transition, look for a
  109.         // theme-based transition instead
  110.         ThemeTransitionMap::iterator itor = m_ThemeMap.find(pTheme);
  111.         if(itor != m_ThemeMap.end() && itor->second->size())
  112.         {
  113.             pTo = itor->second->at(rand() % itor->second->size());
  114.             return true;
  115.         }
  116.  
  117.         if(!m_pDefaultSegment || !bFirstTransition)
  118.             return false;
  119.         pTo = m_pDefaultSegment;
  120.         DebugOut(1, "Returning default segment as To target");
  121.         return true;
  122.     }
  123.     pTo = itr->second->at(rand() % itr->second->size());
  124.     return true;
  125. }
  126.