# 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  

ps_attrib_maker.h

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 #ifndef NL_PS_ATTRIB_MAKER_H
00027 #define NL_PS_ATTRIB_MAKER_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "3d/ps_attrib.h"
00031 #include "3d/ps_located.h"
00032 #include "nel/misc/stream.h"
00033 
00034  
00035 
00036 
00037 
00038 
00039 namespace NL3D {
00040 
00041 
00045 struct CPSInputType
00046 {
00048         CPSInputType() : InputType(attrDate)
00049         {
00050         }
00051 
00053         enum TInputType
00054         {
00055                 attrDate = 0,
00056                 attrPosition = 1,
00057                 attrInverseMass = 2,
00058                 attrSpeed = 3,
00059                 attrUniformRandom = 4,
00060                 attrUserParam = 5, // a parameter user that was set in the system
00061                 attrLOD = 6,    
00062                 attrSquareLOD = 7,
00063                 attrClampedLOD = 8,
00064                 attrClampedSquareLOD = 9,
00065         } InputType ;
00066 
00067         union
00068         {
00070                 uint32 UserParamNum ;
00071         } ;
00072 
00073         void serial(NLMISC::IStream &f) throw(NLMISC::EStream)
00074         {
00075                 f.serialEnum(InputType) ;
00076                 switch(InputType)
00077                 {
00078                         case attrUserParam:
00079                                 f.serial(UserParamNum) ;
00080                                 break ;
00081                         default: break;
00082                 }
00083         }
00084 } ;
00085 
00086 
00095 // The max value for inputs of an attribute maker.
00096 const float MaxInputValue = 1.0f ;
00097 
00102 class CPSAttribMakerBase : public NLMISC::IStreamable
00103 {
00104 public:
00105         // get the type of this attribute maker
00106         virtual const char *getType() = 0;
00107         // duplicate this attribute maker
00108         virtual CPSAttribMakerBase *clone() const = 0;
00109 };
00110 
00111 
00112 
00113 
00122 template <typename T> class CPSAttribMaker : public CPSAttribMakerBase
00123 {       
00124 public:
00126 
00127 
00130                 CPSAttribMaker(float nbCycles = 1.f) : _NbCycles(nbCycles), _HasMemory(false)
00131                 {               
00132                 }
00133 
00135                 virtual void serial(NLMISC::IStream &f) throw(NLMISC::EStream)
00136                 {
00137                         f.serialVersion(1) ;
00138                         f.serial(_NbCycles) ;   
00139                 }
00140 
00142                 virtual const char *getType() { return "UNKNOWN"; }
00143 
00145                 virtual ~CPSAttribMaker() {}
00147 
00149 
00150 
00151                 virtual T get(CPSLocated *loc, uint32 index) = 0 ;
00152 
00156                 virtual T get(float input) { nlassert(0); return T(); /* not supported by default */ }
00157 
00158 
00174                   virtual void *make(CPSLocated *loc,
00175                                                          uint32 startIndex,
00176                                                          void *tab,
00177                                                          uint32 stride,
00178                                                          uint32 numAttrib,
00179                                                          bool   allowNoCopy = false,
00180                                                          uint32 srcStep = (1 << 16)
00181                                                         ) const = 0 ;
00182 
00186                   virtual void make4(CPSLocated *loc,
00187                                                          uint32 startIndex,
00188                                                          void *tab,
00189                                                          uint32 stride,
00190                                                          uint32 numAttrib,
00191                                                          uint32 srcStep = (1 << 16)
00192                                                         ) const = 0 ;
00193 
00197                  virtual void makeN(CPSLocated *loc,
00198                                                     uint32 startIndex,
00199                                                         void *tab,
00200                                                         uint32 stride,
00201                                                         uint32 numAttrib,
00202                                                         uint32 nbReplicate,
00203                                                         uint32 srcStep = (1 << 16)
00204                                                    ) const = 0 ;
00206 
00207         
00208 
00210         virtual T getMaxValue(void) const { return T() ; /* no mean by default */ }
00211 
00212 
00214 
00215 
00220                 void setNbCycles(float nbCycles) 
00221                 { 
00222                         nlassert(nbCycles >= 0) ;
00223                         _NbCycles = nbCycles ; 
00224                 }
00225 
00229                 float getNbCycles(void) const { return _NbCycles ; }
00230 
00232                 virtual bool hasCustomInput(void) { return false ; }
00233                         
00234 
00238                 virtual void setInput(const CPSInputType &input) {}
00239 
00240 
00244                 virtual CPSInputType getInput(void) const { return CPSInputType() ; }
00245                 
00246 
00247 
00251                 virtual bool isClampingSupported(void) const { return false ; }
00252 
00253 
00258                 virtual void setClamping(bool enable = true) {} ;
00259 
00260 
00265                 virtual bool getClamping(void) const  { return false  ; }
00267 
00268 
00270 
00271 
00275                 bool hasMemory(void) const { return _HasMemory ; }
00276 
00278                 virtual void deleteElement(uint32 index) { nlassert(false) ; }
00279 
00283                 virtual void newElement(CPSLocated *emitterLocated, uint32 emitterIndex) { nlassert(false) ; }
00284 
00289                 virtual void resize(uint32 capacity, uint32 nbPresentElements) { nlassert(false) ; }
00291 
00292 protected:      
00293 
00294         float _NbCycles ;
00295 
00296         // set to true if the attribute maker owns its own memory for each particle attribute
00297         bool _HasMemory ;
00298 
00299 };
00300 
00301 
00302 
00303 
00304 
00305 
00306 } // NL3D
00307 
00308 
00309 
00310 #endif // NL_PS_ATTRIB_MAKER_H
00311 
00312 /* End of ps_attrib_maker.h */