# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

env_effect.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "stdsound.h"
00027 
00028 #include "env_effect.h"
00029 
00030 using namespace NLMISC;
00031 
00032 
00033 namespace NLSOUND {
00034 
00035 
00036 /*
00037  * Constructor
00038  */
00039 CEnvEffect::CEnvEffect() : _Current(0), _BoundingShape(NULL)
00040 {
00041 }
00042 
00043 
00044 /*
00045  * Serialize file header
00046  */
00047 void                    CEnvEffect::serialFileHeader( NLMISC::IStream& s, uint32& nb )
00048 {
00049         s.serialCheck( (uint32)'FEN' ); // NeL Environment FX
00050         if ( s.serialVersion( 2 ) < 2 )
00051         {
00052                 throw EOlderStream(s);
00053         }
00054         
00055         s.serial( nb );
00056 }
00057 
00058 
00059 /*
00060  * Load several EnvEffects
00061  */
00062 uint32                  CEnvEffect::load( std::vector<CEnvEffect*>& container, NLMISC::IStream& s )
00063 {
00064         if ( s.isReading() )
00065         {
00066                 uint32 i, nb;
00067                 serialFileHeader( s, nb );
00068                 for ( i=0; i!=nb; i++ )
00069                 {
00070                         CEnvEffect *enveffect = new CEnvEffect();
00071                         s.serial( *enveffect );
00072                         container.push_back( enveffect );
00073                 }
00074                 return nb;
00075         }
00076         else
00077         {
00078                 nlstop;
00079                 return 0;
00080         }
00081 }
00082 
00083 
00084 /*
00085  * Set the environment type (EDIT)
00086  */
00087 void                    CEnvEffect::addEnvNum( TEnvEffectPreset num, const std::string& tag, float customsize )
00088 {
00089         _EnvNums.push_back( TEnvEffectRoom(num,customsize) );
00090         _Tags.push_back( tag );
00091 }
00092 
00093 
00094 /*
00095  * Return the environment size
00096  */
00097 float                   CEnvEffect::getEnvSize() const
00098 {
00099         if ( _EnvNums[_Current].Size > 0 )
00100         {
00101                 return _EnvNums[_Current].Size;
00102         }
00103         else
00104         {
00105                 return _BoundingShape->getDiameter();
00106         }
00107 }
00108 
00109 
00110 /*
00111  * Select the current environment
00112  */
00113 void                    CEnvEffect::selectEnv( const std::string& tag )
00114 {
00115         uint i;
00116         for ( i=0; i!= _Tags.size(); i++ )
00117         {
00118                 if ( _Tags[i] == tag )
00119                 {
00120                         _Current = i;
00121                         nldebug( "AM: EnvEffect: Environment changed to %s", tag.c_str() );
00122                         return;
00123                 }
00124         }
00125         nldebug( "AM: EnvEffect: Environment %s not found", tag.c_str() );
00126         // Don't change _Current if not found
00127 }
00128 
00129 
00130 /*
00131  * Save (output stream only) (EDIT)
00132  */
00133 void                    CEnvEffect::save( const std::vector<CEnvEffect>& container, NLMISC::IStream& s )
00134 {
00135         nlassert( ! s.isReading() );
00136 
00137         uint32 nb=container.size(), i;
00138         serialFileHeader( s, nb );
00139         for ( i=0; i!=nb; i++ )
00140         {
00141                 s.serial( const_cast<CEnvEffect&>(container[i]) );
00142         }
00143 }
00144 
00145 
00146 } // NLSOUND