Exemplo n.º 1
0
        /// <summary>Adds a particle system to be processed by the manager</summary>
        /// <typeparam name="ParticleType">
        ///   Type of particles being stored in the particle system
        /// </typeparam>
        /// <typeparam name="VertexType">
        ///   Type of vertices that will be generated from the particles
        /// </typeparam>
        /// <param name="particleSystem">
        ///   Particle system that will be added to the manager
        /// </param>
        /// <param name="pruneDelegate">Method used to detect dead particles</param>
        /// <param name="renderer">
        ///   Particle renderer that will turn the particles into vertices and send
        ///   them to a primitive batch for rendering
        /// </param>
        public void AddParticleSystem <ParticleType, VertexType>(
            ParticleSystem <ParticleType> particleSystem,
            ParticleSystem <ParticleType> .PrunePredicate pruneDelegate,
            IParticleRenderer <ParticleType, VertexType> renderer
            )
            where ParticleType : struct
            where VertexType : struct
#if XNA_4
        , IVertexType
#endif
        {
            PrimitiveBatchHolder <VertexType> holder;

            holder = getOrCreatePrimitiveBatch <VertexType>();
            try {
                this.particleSystems.Add(
                    particleSystem,
                    new ParticleSystemHolder <ParticleType, VertexType>(
                        particleSystem,
                        pruneDelegate,
                        renderer,
                        holder
                        )
                    );
                this.holderArraysDirty = true;
            }
            catch (Exception) {
                holder.Release();
                throw;
            }
        }
Exemplo n.º 2
0
            /// <summary>Initializes a new particle system holder</summary>
            /// <param name="particleSystem">Particle system the holder will manage</param>
            /// <param name="renderer">
            ///   Renderer through which the particles are sent to the primitive batch
            /// </param>
            /// <param name="pruneDelegate">
            ///   Method which will be used to detect dead particles
            /// </param>
            /// <param name="primitiveBatchHolder">
            ///   Primitive batch holder that manages the primitive batch used to
            ///   render the vertices generated by this particle system
            /// </param>
            public ParticleSystemHolder(
                ParticleSystem <ParticleType> particleSystem,
                ParticleSystem <ParticleType> .PrunePredicate pruneDelegate,
                IParticleRenderer <ParticleType, VertexType> renderer,
                PrimitiveBatchHolder <VertexType> primitiveBatchHolder
                )
            {
                if (renderer == null)
                {
                    throw new ArgumentException("You must specify a renderer", "renderer");
                }

                this.particleSystem       = particleSystem;
                this.pruneDelegate        = pruneDelegate;
                this.renderer             = renderer;
                this.primitiveBatchHolder = primitiveBatchHolder;
            }
 public void TestThrowOnAddParticleSystemWithNullRenderer()
 {
     using (
         ParticleSystemManager manager = new ParticleSystemManager(
             this.mockedGraphicsDeviceService
             )
         ) {
         IParticleRenderer <SimpleParticle> nullRenderer = null;
         Assert.Throws <ArgumentException>(
             delegate() {
             manager.AddParticleSystem(
                 new ParticleSystem <SimpleParticle>(100), dontPrune, nullRenderer
                 );
         }
             );
     }
 }
Exemplo n.º 4
0
        public static bool TryCreateRender(string name, IKeyValueCollection rendererInfo, VrfGuiContext vrfGuiContext, out IParticleRenderer renderer)
        {
            if (RendererDictionary.TryGetValue(name, out var factory))
            {
                renderer = factory(rendererInfo, vrfGuiContext);
                return(true);
            }

            renderer = default;
            return(false);
        }
Exemplo n.º 5
0
 public ParticleType(Polygon polygon, IDistribution <int> lifetimeDistribution)
 {
     _renderer     = new ColoredParticleRenderer(polygon);
     this.Lifetime = lifetimeDistribution;
 }
Exemplo n.º 6
0
 public ParticleType(Sprite sprite, IDistribution <int> lifetimeDistribution, double animationSpeed = 1.0)
 {
     _renderer     = new TexturedParticleRenderer(sprite, animationSpeed);
     this.Lifetime = lifetimeDistribution;
 }
Exemplo n.º 7
0
 public ParticleSystem(IParticleEmitter emitter, IParticleRenderer renderer)
 {
     _particles = new List <Particle>();
     _emitter   = emitter;
     _renderer  = renderer;
 }