AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzActorParticles.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if !defined(_CZ_ACTOR_PARTICLES_H_)
00015 #define _CZ_ACTOR_PARTICLES_H_
00016 
00017 #include "CzUtil.h"
00018 #include "CzActor.h"
00019 #include "CzBitmapSprite.h"
00020 #include "CzAnim.h"
00021 #include "CzString.h"
00022 #include "CzXoml.h"
00023 #include "CzBox2d.h"
00024 #include "CzShapes.h"
00025 #include "CzActions.h"
00026 
00027 class CzScene;
00028 class CzActorParticles;
00029 
00030 /**
00031  @addtogroup Actors
00032  @{
00033  */
00034  
00035 /**
00036  @struct    CzActorParticle
00037 
00038  @brief A particle.
00039 
00040  */
00041 
00042 struct CzActorParticle
00043 {
00044     CzActorParticles*       Parent;                 ///< Particles parent emitter
00045     CzBitmapSprite*         Visual;                 ///< Visual element that represents the particle
00046     CzVec2                  Position;               ///< Position relative to particle system actor
00047     CzVec2                  Velocity;               ///< Velocity of particle
00048     CzVec2                  VelocityDamping;        ///< Velocity damping for particle
00049     CzVec2                  Gravity;                ///< Gravitational acceleration
00050     CzVec2                  Scale;                  ///< Scale of particle
00051     CzVec2                  ScaleVelocity;          ///< Scale velocity of particle
00052     CzVec2                  ScaleVelocityDamping;   ///< Scale velocity of particle
00053     float                   Angle;                  ///< Rotation of particle
00054     float                   AngularVelocity;        ///< Rotation of particle
00055     float                   AngularVelocityDamping; ///< Rotation of particle
00056     CzVec4                  Colour;                 ///< Particle colour
00057     CzVec4                  ColourVelocity;         ///< Particle colour velocity
00058     CzVec4                  ColourVelocityDamping;  ///< Particle colour velocity damping
00059     float                   Depth;                  ///< Depth of particle
00060     float                   DepthVelocity;          ///< Depth velocity of particle
00061     float                   DepthVelocityDamping;   ///< Depth velocity damping of particle
00062     bool                    Active;                 ///< Active state
00063     bool                    Visible;                ///< Visible state
00064     float                   LifeSpan;               ///< Total duration of particle in seconds
00065     float                   SpawnDelay;             ///< Amount of time to wait before spawning in seconds
00066     float                   LifeTime;               ///< Current life time in seconds
00067     int                     Lives;                  ///< Number of lives for particle (how time it will be respawned)
00068     CzVec2                  OPosition;              ///< Original Position relative to particle system actor
00069     CzVec2                  OVelocity;              ///< Original Velocity of particle
00070     CzVec2                  OScale;                 ///< Original Scale of particle
00071     CzVec2                  OScaleVelocity;         ///< Original Scale velocity of particle
00072     float                   OAngle;                 ///< Original Rotation of particle
00073     float                   OAngularVelocity;       ///< Original Rotation veloxity of particle
00074     CzVec4                  OColour;                ///< Original Particle colour
00075     CzVec4                  OColourVelocity;        ///< Original Particle colour velocity
00076     float                   ODepth;                 ///< Original Depth of particle
00077     float                   ODepthVelocity;         ///< Original Depth velocity of particle
00078     bool                    Attached;               ///< Attached particles will follow the particle actor
00079 
00080     CzActorParticle() : Parent(NULL), Visual(NULL), VelocityDamping(1.0f, 1.0f), Scale(1.0f, 1.0f), ScaleVelocityDamping(1.0f, 1.0f), 
00081                                 Angle(0), AngularVelocity(0), AngularVelocityDamping(1.0f), Colour(255, 255, 255, 255), ColourVelocityDamping(1, 1, 1, 1), 
00082                                 LifeSpan(2), SpawnDelay(0), LifeTime(0), Lives(-1), Visible(false), Active(true), Depth(0), DepthVelocity(0),DepthVelocityDamping(1), Attached(true)
00083     {
00084     }
00085     virtual ~CzActorParticle();
00086 
00087     void    Update(float dt);
00088     void    CopyToOld();
00089     void    CopyFromOld();
00090 
00091     CzActorParticle* Clone();
00092 
00093     bool            setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta);
00094     bool            setProperty(unsigned int property_name, const CzString& data, bool delta);
00095     bool            getProperty(unsigned int property_name, CzXomlProperty& prop);
00096 
00097     // Internal (used by XOML system to setup and cleanup the XOML class properties system)
00098 protected:
00099     static CzXomlClassDef*  ActorParticleClassDef;                              // XOML class definition
00100 
00101 public:
00102     static void             InitClass();
00103     static void             ReleaseClass();
00104 
00105     static bool             _setPosition(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00106     static CzXomlProperty   _getPosition(IzXomlResource* target);
00107     static bool             _setSize(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00108     static CzXomlProperty   _getSize(IzXomlResource* target);
00109     static bool             _setVelocity(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00110     static CzXomlProperty   _getVelocity(IzXomlResource* target);
00111     static bool             _setVelocityDamping(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00112     static CzXomlProperty   _getVelocityDamping(IzXomlResource* target);
00113     static bool             _setGravity(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00114     static CzXomlProperty   _getGravity(IzXomlResource* target);
00115     static bool             _setScale(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00116     static CzXomlProperty   _getScale(IzXomlResource* target);
00117     static bool             _setScaleVelocity(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00118     static CzXomlProperty   _getScaleVelocity(IzXomlResource* target);
00119     static bool             _setScaleVelocityDamping(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00120     static CzXomlProperty   _getScaleVelocityDamping(IzXomlResource* target);
00121     static bool             _setAngle(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00122     static CzXomlProperty   _getAngle(IzXomlResource* target);
00123     static bool             _setAngularVelocity(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00124     static CzXomlProperty   _getAngularVelocity(IzXomlResource* target);
00125     static bool             _setAngularVelocityDamping(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00126     static CzXomlProperty   _getAngularVelocityDamping(IzXomlResource* target);
00127     static bool             _setColour(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00128     static CzXomlProperty   _getColour(IzXomlResource* target);
00129     static bool             _setColourVelocity(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00130     static CzXomlProperty   _getColourVelocity(IzXomlResource* target);
00131     static bool             _setColourVelocityDamping(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00132     static CzXomlProperty   _getColourVelocityDamping(IzXomlResource* target);
00133     static bool             _setDepth(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00134     static CzXomlProperty   _getDepth(IzXomlResource* target);
00135     static bool             _setDepthVelocity(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00136     static CzXomlProperty   _getDepthVelocity(IzXomlResource* target);
00137     static bool             _setDepthVelocityDamping(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00138     static CzXomlProperty   _getDepthVelocityDamping(IzXomlResource* target);
00139     static bool             _setActive(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00140     static CzXomlProperty   _getActive(IzXomlResource* target);
00141     static bool             _setVisible(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00142     static CzXomlProperty   _getVisible(IzXomlResource* target);
00143     static bool             _setLifeSpan(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00144     static CzXomlProperty   _getLifeSpan(IzXomlResource* target);
00145     static bool             _setSpawnDelay(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00146     static CzXomlProperty   _getSpawnDelay(IzXomlResource* target);
00147     static bool             _setLifeTime(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00148     static CzXomlProperty   _getLifeTime(IzXomlResource* target);
00149     static bool             _setLives(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00150     static CzXomlProperty   _getLives(IzXomlResource* target);
00151     static bool             _setOPosition(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00152     static CzXomlProperty   _getOPosition(IzXomlResource* target);
00153     static bool             _setOVelocity(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00154     static CzXomlProperty   _getOVelocity(IzXomlResource* target);
00155     static bool             _setOScale(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00156     static CzXomlProperty   _getOScale(IzXomlResource* target);
00157     static bool             _setOScaleVelocity(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00158     static CzXomlProperty   _getOScaleVelocity(IzXomlResource* target);
00159     static bool             _setOAngle(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00160     static CzXomlProperty   _getOAngle(IzXomlResource* target);
00161     static bool             _setOAngularVelocity(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00162     static CzXomlProperty   _getOAngularVelocity(IzXomlResource* target);
00163     static bool             _setOColour(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00164     static CzXomlProperty   _getOColour(IzXomlResource* target);
00165     static bool             _setOColourVelocity(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00166     static CzXomlProperty   _getOColourVelocity(IzXomlResource* target);
00167     static bool             _setODepth(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00168     static CzXomlProperty   _getODepth(IzXomlResource* target);
00169     static bool             _setODepthVelocity(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00170     static CzXomlProperty   _getODepthVelocity(IzXomlResource* target);
00171     static bool             _setAttached(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00172     static CzXomlProperty   _getAttached(IzXomlResource* target);
00173     static bool             _setSrcRect(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00174     static CzXomlProperty   _getSrcRect(IzXomlResource* target);
00175 
00176 };
00177 
00178 /**
00179  @class CzActorParticles
00180 
00181  @brief A particle system based actor.
00182 
00183  Many games and in fact some apps make use of a special effects. One method of generating special effects is using a particle system. A particle system is a system that generates a 
00184  group of particles over time using a particle generator. Particle systems are great for producing effects such as fireworks, sparkles, fire and smoke trails etc..
00185 
00186  In XOML a particle actor is declared using the ActorParticles tag. The ActorParticles example has been provided to show how they work. Lets take a quick look at some example XOML:
00187 
00188   @code
00189 <ActorParticles Name="SnowyParticles" Image="Particle" Position="0, 0" Scale="1.0" Depth="1.0" Layer="1" PosMode="random" AngVelMode="random" VelMode="random" AngMode="random" 
00190   ScaleMode="random" DepthMode="random" DepthVelMode="random" PositionRange="1000, 1000" AngleRange="0, 360" AngVelRange="-25, 25" ScaleRange="0.25, 0.5" DepthRange="0.1, 2.0" 
00191   VelRange="-4, 4, -14, 0" ScaleVelRange="0, -0.1" DepthVelRange="-0.03, 0.01">
00192     <Particle Count="1000" Position="0, 0" VelocityDamping="0.99, 0.99" SrcRect="0, 0, 128, 128" ColourVelocity="0, 0, 0, -2" Duration="3" Repeat="-1" SpawnDelay="0.01" Gravity="15" />
00193 </ActorParticles>
00194   @endcode
00195 
00196  In this example we create a particle actor generator that generates 1000 random spinning / flying particles over time that fall to the ground under the affect of gravity.
00197  In addition to the basic actor properties particle actors have a number of new properties, which include:
00198 
00199  <b>General</b>
00200  - Size (x, y) - Size of the particle actor (used to clip the actor)
00201  - Anchor (topleft or centre) - Sets the draw anchor (topleft causes the actor to be displayed relative to its top-left cornr whilst centre will use the actors centre)
00202 
00203  <b>Regeneration Modes</b>
00204  - PosMode (mode) - Determines how the position property of the particle will be regenerated when the particle comes to the end of its life.
00205  - AngMode (mode) - Determines how the angle property of the particle will be regenerated when the particle comes to the end of its life.
00206  - ScaleMode (mode) - Determines how the scale property of the particle will be regenerated when the particle comes to the end of its life.
00207  - DepthMode (mode) - Determines how the depth property of the particle will be regenerated when the particle comes to the end of its life.
00208  - VelMode (mode) - Determines how the velocity property of the particle will be regenerated when the particle comes to the end of its life.
00209  - AngVelMode (mode) - Determines how the angular velocity property of the particle will be regenerated when the particle comes to the end of its life.
00210  - ScaleVelMode (mode) - Determines how the scale velocity property of the particle will be regenerated when the particle comes to the end of its life.
00211  - DepthVelMode (mode) - Determines how the depth velocity property of the particle will be regenerated when the particle comes to the end of its life. 
00212  
00213  The mode parameter can be either:
00214  - random - The property will be randomly generated
00215  - normal - The property will not reset back to its original value Random Generation Ranges:
00216 
00217  <b>Random Generation Ranges</b>
00218  - PositionRange (x, y) - Sets the range for which positional coordinates can be randomly generated on the x and y axis. For example, setting a value of 50, 100 will generate random 
00219  coordinates between -50 and 50 for the x axis as well as -100 to 100 for the y axis
00220  - AngleRange (lower, upper) - Sets the range for which angle values can be generated from lower degrees to upper degrees. For example setting values of 10, 50 will generate random angles 
00221  between 10 and 50 degrees.
00222  - ScaleRange (lower, upper) - Sets the range for which scale values can be generated from lower to upper. For example setting values of 0.1, 2.0 will generate random scaling factors 
00223  between 0.1 and 2.0
00224  - DepthRange (lower, upper) - Sets the range for which depth values can be generated from lower to upper depth. For example setting values of 0.1, 10.0 will generate random depths 
00225  between 0.1 and 10.0
00226  - VelRange (lower x, upper x, lower y, upper y) - Sets the range for which velocity values can be generated from lower x to upper x, lower y to upper y. For example setting values 
00227  of -1, 1, -2, 2 will generate random velocities between -1 and 1 on the x axis and -2 and 2 on the y axis
00228  - AngVelRange - (lower, upper) - Sets the range for which angular velocity values can be generated from lower degrees/sec to upper degrees/sec. For example setting values of -0.1, 0.1 
00229  will generate random angular velocities between -0.1 and 0.1
00230  - ScaleVelRange (lower, upper) - Sets the range for which scale velocity values can be generated from lower to upper. For example setting values of 0.1, 0.2 will generate random scale 
00231  velocities between 0.1 and 0.2
00232  - DepthVelRange (lower, upper) - Sets the range for which depth velocity values can be generated from lower to upper. For example setting values of -0.01, 0.02 will generate random depth 
00233  velocities between -0.01 and 0.02 
00234 
00235 Random generators are used when particular modes are set to random. For example, when PosMode=”random” PositionRange will be used to provide the range between which positional coordinates are generated. 
00236 
00237 Individual particles are added as children of the particle actor. In addition, a number of particles can be automatically generated for you. The inner Particle tag has the following properties:
00238  - Attached (boolean) – When set to true particles will be attached to the emitter and will follow it, when set to false particles will remain where they are created (default is true)
00239  - Count (number) - The number of particles to generate
00240  - Position (x, y) - The position of the particle relative to the generator
00241  - Angle (degrees) - The angle of the particle
00242  - Scale (x, y) - The scale of the particle
00243  - Depth (depth) - The depth of the particle, the greater the value of depth the farther away the actor appears
00244  - Velocity (x, y) - Initial velocity of the particle
00245  - Colour (r, g, b, a) - Initial colour and opacity of the particle
00246  - VelocityDamping (x, y) - The rate at which to slow velocity down or speed it up. Values greater than 1 will increase velocity over time whilst values less than 1.0 will reduce the 
00247  velocity over time • AngularVelocity (number) - Initial angular velocity of the particle (degrees / sec)
00248  - AngularVelocityDamping (number) - The rate at which to slow angular velocity down or speed it up. Values greater than 1 will increase angular velocity over time whilst values less 
00249  than 1.0 will reduce the angular velocity over time
00250  - DepthVelocity (number) - Initial depth velocity of the particle
00251  - DepthVelocityDamping (number) - The rate at which to slow depth velocity down or speed it up. Values greater than 1 will increase depth velocity over time whilst values less than 1.0 
00252  will reduce the depth velocity over time
00253  - ScaleVelocity (x, y) - Initial scale velocity of the particle
00254  - ScaleVelocityDamping (x, y) - The rate at which to slow scale velocity down or speed it up. Values greater than 1 will increase scale velocity over time whilst values less than 1.0 will 
00255  reduce the scale velocity over time
00256  - ColourVelocity (r, g, b, a) - Initial colour velocity of the particle
00257  - ColourVelocityDamping (r, g, b, a) - The rate at which to slow colour velocity down or speed it up. Values greater than 1 will increase colour velocity over time whilst values less 
00258  than 1.0 will reduce the colour velocity over time
00259  - SrcRect (x, y, width, height) - Sets a part of the image to draw instead of the whole image (used in sprite atlases where multiple images are contained within the same image)
00260  - Repeat (number) - The number of times to repeat a particle (can be thought of its number of lives). Particles that run out of lives will be removed from the generator. Using a value 
00261  of -1 will regenerate the particle whilst the generator is active
00262  - SpawnDelay (seconds) - Sets an amount of time to wait before spawning this particle. If count is more than 1 then then the spawn delay of each consecutive particle will be compounded. 
00263  For example if you generate 3 particles with a spawn delay of 1.0 then the first particle will be generated after 1 second, the secnod particle after 2 seconds and the 3rd particle 
00264  after seconds.
00265  - Duration (seconds) - This represents the life time of the particle. For example, if you set the duration to 5 seconds, it will be regenerated after 5 seconds (deleted if repeat is 1)
00266  - Gravity (number) - The gravity property is used to add a gravitational affect to particles.
00267 
00268  */
00269 
00270 class CzActorParticles : public CzActor
00271 {
00272 public:
00273     enum eParticleMode
00274     {
00275         PAM_Normal,
00276         PAM_Random,
00277     };
00278 
00279     // Properties
00280 protected:
00281     CzImage*                        Image;              ///< Image used by the particles
00282     CzSlotArray<CzActorParticle*>*  Particles;          ///< Particles in this system
00283     eParticleMode                   PositionMode;       ///< Mode of operatiuon for position
00284     eParticleMode                   AngleMode;          ///< Mode of operatiuon for angle
00285     eParticleMode                   ScaleMode;          ///< Mode of operatiuon for scale
00286     eParticleMode                   DepthMode;          ///< Mode of operatiuon for depth
00287     eParticleMode                   VelocityMode;       ///< Mode of operatiuon for velocity
00288     eParticleMode                   AngVelocityMode;    ///< Mode of operatiuon for angular velocity
00289     eParticleMode                   ScaleVelocityMode;  ///< Mode of operatiuon for scale velocity
00290     eParticleMode                   DepthVelocityMode;  ///< Mode of operatiuon for depth velocity
00291     CzVec2                          PositionRange;      ///< Range of spawn positions
00292     CzVec2                          AngleRange;         ///< Range of spawn angles - x = min angle, y = max angle
00293     CzVec2                          ScaleRange;         ///< Range of scales - x = min scale, y = max scale
00294     CzVec2                          DepthRange;         ///< Range of depth - x = min depth, y = max depth
00295     CzVec4                          VelocityRange;      ///< Range of spawn velocities - min_x, max_y, min_y, max_y
00296     CzVec2                          AngVelocityRange;   ///< Range of angular velocities - x = min ang velocity, y = max ang velocity
00297     CzVec2                          ScaleVelocityRange; ///< Range of scale velocities - x = min scale velocity, y = max scale velocity
00298     CzVec2                          DepthVelocityRange; ///< Range of depth velocities - x = min depth velocity, y = max depth velocity
00299     bool                            AutoDelete;         ///< Wehn set to true the actor will be automatically deleted when the particle system finishes running
00300 
00301 public:
00302     bool            addParticle(CzActorParticle* particle, const CzIRect& src_rect, int count = 0, float spawn_delay = 0.0f, CzSprite::eAnchor anchor = CzSprite::Centre);
00303     void            removeParticle(CzActorParticle* particle)       { Particles->remove(particle); delete particle; }
00304     void            removeAllParticles();
00305 
00306     int             getParticleCount() const                        { return Particles->getSize(); }
00307     CzActorParticle* getParticle(int index);
00308     CzImage*        getImage()                                      { return Image; }
00309     void            setImage(CzImage* image)                        { Image = image; }
00310     void            setPositionMode(eParticleMode mode)             { PositionMode = mode; }
00311     void            setAngleMode(eParticleMode mode)                { AngleMode = mode; }
00312     void            setScaleMode(eParticleMode mode)                { ScaleMode = mode; }
00313     void            setVelocityMode(eParticleMode mode)             { VelocityMode = mode; }
00314     void            setAngVelocityMode(eParticleMode mode)          { AngVelocityMode = mode; }
00315     void            setScaleVelocityMode(eParticleMode mode)        { ScaleVelocityMode = mode; }
00316     void            setDepthMode(eParticleMode mode)                { DepthMode = mode; }
00317     void            setDepthVelocityMode(eParticleMode mode)        { DepthVelocityMode = mode; }
00318     void            setPositionRange(CzVec2& range)                 { PositionRange = range; }
00319     CzVec2          getPositionRange() const                        { return PositionRange; }
00320     void            setAngleRange(CzVec2& range)                    { AngleRange = range; }
00321     CzVec2          getAngleRange() const                           { return AngleRange; }
00322     void            setScaleRange(CzVec2& range)                    { ScaleRange = range; }
00323     CzVec2          getScaleRange() const                           { return ScaleRange; }
00324     void            setDepthRange(CzVec2& range)                    { DepthRange = range; }
00325     CzVec2          getDepthRange() const                           { return DepthRange; }
00326     void            setVelocityRange(CzVec4& range)                 { VelocityRange = range; }
00327     CzVec4          getVelocityRange() const                        { return VelocityRange; }
00328     void            setAngVelocityRange(CzVec2& range)              { AngVelocityRange = range; }
00329     CzVec2          getAngVelocityRange() const                     { return AngVelocityRange; }
00330     void            setScaleVelocityRange(CzVec2& range)            { ScaleVelocityRange = range; }
00331     CzVec2          getScaleVelocityRange() const                   { return ScaleVelocityRange; }
00332     void            setDepthVelocityRange(CzVec2& range)            { DepthVelocityRange = range; }
00333     CzVec2          getDepthVelocityRange() const                   { return DepthVelocityRange; }
00334     void            SetDestSize(int w, int h)                       { Size.x = w; Size.y = h; }
00335     bool            setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta);
00336     bool            setProperty(unsigned int property_name, const CzString& data, bool delta);
00337     bool            getProperty(unsigned int property_name, CzXomlProperty& prop);
00338     void            setAutoDelete(bool enable)                      { AutoDelete = enable; }
00339     bool            isAutoDelete() const                            { return AutoDelete; }
00340     // Properties end
00341 protected:
00342     void            setParticlesVisibility(bool visible);
00343     bool            UpdateBinding(unsigned int property_name, CzXomlVariable* var);
00344 public:
00345     CzActorParticles() :    CzActor(), Particles(NULL), Image(NULL), PositionMode(PAM_Normal), AngleMode(PAM_Normal), ScaleMode(PAM_Normal), VelocityMode(PAM_Normal), 
00346                                 AngVelocityMode(PAM_Normal), ScaleVelocityMode(PAM_Normal), DepthMode(PAM_Normal), DepthVelocityMode(PAM_Normal), DepthRange(0, 0), 
00347                                 PositionRange(0, 0), AngleRange(0, 360), ScaleRange(1.0, 1.0), VelocityRange(0, 0, 0, 0), AngVelocityRange(0, 0), ScaleVelocityRange(0, 0), DepthVelocityRange(0, 0), 
00348                                 AutoDelete(true) { setActualClassType("actorparticles"); }
00349     virtual ~CzActorParticles()
00350     {
00351         if (Particles != NULL)
00352         {
00353             for (int t = 0; t < Particles->getSize(); t++)
00354             {
00355                 CzActorParticle* particle = Particles->element_at(t);
00356                 if (particle != NULL)
00357                     delete particle;
00358             }
00359             SAFE_DELETE(Particles)
00360         }
00361     }
00362 
00363     bool                Init(int max_particles);
00364     bool                Update(float dt);
00365     bool                UpdateVisual();
00366 
00367     // Implementation of IzXomlClass interface
00368     int                 LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00369 
00370     // Implementation of IzAnimTarget interface
00371     bool                UpdateFromAnimation(CzAnimInstance *animation);
00372 
00373     // Generates a bunch of randmo particles using the ranges and modes previously set
00374     void                GenerateRandomParticles(int count, const CzIRect& src_rect, const CzVec4& colour, const CzVec4& colour_velocity, CzVec2& gravity, float duration, int repeat_count = 0, float spawn_delay_change = 0);
00375     // Generates a bunch of randmo particles using the ranges and modes previously set, using particle as a basis
00376     void                GenerateRandomParticles(int count, CzActorParticle* particle, const CzIRect& src_rect, float duration, int repeat_count = 0, float spawn_delay_change = 0);
00377 
00378     // Utility
00379     void                setVelocityAll(float x, float y, bool delta);
00380 
00381     // Internal
00382     void                RegenParticle(CzActorParticle* particle);
00383 
00384     // Internal (used by XOML system to setup and cleanup the XOML class properties system
00385 protected:
00386     static CzXomlClassDef*  ActorParticlesClassDef;                             // XOML class definition
00387 
00388 public:
00389     static void             InitClass();
00390     static void             ReleaseClass();
00391 
00392     static CzXomlProperty   _getParticleCount(IzXomlResource* target);
00393     static bool             _setSize(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00394     static CzXomlProperty   _getSize(IzXomlResource* target);
00395     static bool             _setImage(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00396     static CzXomlProperty   _getImage(IzXomlResource* target);
00397     static bool             _setPosMode(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00398     static bool             _setAngMode(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00399     static bool             _setScaleMode(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00400     static bool             _setDepthMode(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00401     static bool             _setAngVelMode(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00402     static bool             _setVelMode(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00403     static bool             _setScaleVelMode(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00404     static bool             _setDepthVelMode(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00405     static bool             _setPositionRange(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00406     static bool             _setAngleRange(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00407     static bool             _setScaleRange(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00408     static bool             _setDepthRange(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00409     static bool             _setVelRange(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00410     static bool             _setAngVelRange(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00411     static bool             _setScaleVelRange(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00412     static bool             _setDepthVelRange(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00413     static bool             _setVelocityAll(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00414     static bool             _setAutoDelete(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00415     static CzXomlProperty   _getAutoDelete(IzXomlResource* target);
00416 };
00417 
00418 /// @}
00419 
00420 /**
00421  @class CzActorParticlesCreator
00422 
00423  @brief Creates an instance of a particles based actor object.
00424 
00425  Used by the XOML system to instantiate a CzActorParticles object.
00426 
00427 
00428  */
00429 
00430 class CzActorParticlesCreator : public IzXomlClassCreator
00431 {
00432 public:
00433     CzActorParticlesCreator()
00434     {
00435         setClassName("actorparticles");
00436     }
00437     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzActorParticles(); }
00438 };
00439 
00440 
00441 #endif // _CZ_ACTOR_PARTICLES_H_