Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fxEvent"></param>
        public FXInstance RunFX(FXEvent fxEvent, bool looped)
        {
            var fxAtomID = fxEvent.FXAtom;

            if (fxAtomID < 0)
            {
                Log.Warning("RunFX: negative atom ID");
                return(null);
            }

            var className = world.Atoms[fxAtomID];

            if (className == null)
            {
                Log.Warning("RunFX: bad atom ID");
                return(null);
            }


            var factory = world.Content.Load <FXFactory>(Path.Combine("fx", className), (FXFactory)null);

            if (factory == null)
            {
                return(null);
            }

            var fxInstance = factory.CreateFXInstance(this, fxEvent, looped);

            runningSFXes.Add(fxInstance);

            return(fxInstance);
        }
Esempio n. 2
0
            public override void Update(float dt, FXEvent fxEvent)
            {
                timer += dt;


                while (timer > stageDesc.Period)
                {
                    timer -= period;

                    if (!looped)
                    {
                        stopped = true;
                        Kill();
                    }
                    else
                    {
                        counter++;
                        UpdatePeriodIntensity();
                    }
                }

                UpdateLightStyle();

                light.Position = FXFactory.GetPosition(stageDesc.OffsetDirection, stageDesc.OffsetFactor, fxEvent);
            }
Esempio n. 3
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="p"></param>
            /// <param name="fxEvent"></param>
            void Emit(ref Particle p, FXEvent fxEvent)
            {
                p.Effects = stage.Effect;

                p.ImageIndex = spriteIndex;

                p.Color0 = stage.Color0;
                p.Color1 = stage.Color1;

                p.LifeTime = stage.Lifetime.GetLifetime(rand);

                p.FadeIn  = stage.Timing.FadeIn;
                p.FadeOut = stage.Timing.FadeOut;

                float a, b;

                stage.Shape.GetAngles(rand, p.LifeTime, out a, out b);
                p.Rotation0 = a;
                p.Rotation1 = b;

                p.Size0 = stage.Shape.Size0;
                p.Size1 = stage.Shape.Size1;

                p.Position = stage.Position.GetPosition(fxEvent, rand);

                p.Velocity = stage.Velocity.GetVelocity(fxEvent, rand);

                var turbulence = rand.GaussRadialDistribution(0, stage.Acceleration.Turbulence);

                p.Acceleration = stage.Acceleration.DragForce * p.Velocity + turbulence;
                p.Damping      = stage.Acceleration.Damping;
                p.Gravity      = stage.Acceleration.GravityFactor;
            }
Esempio n. 4
0
        public Vector3 GetPosition(FXEvent fxEvent, Random rand)
        {
            var position = FXFactory.GetPosition(OffsetDirection, OffsetFactor, fxEvent);
            var radial   = FXFactory.GetRadialDistribution(rand, Distribution, MinSize, MaxSize);

            return(position + radial);
        }
Esempio n. 5
0
 public override void Update(float dt, FXEvent fxEvent)
 {
     if (emitter != null)
     {
         emitter.Position = fxEvent.Origin;
         emitter.Velocity = fxEvent.Velocity;
     }
 }
Esempio n. 6
0
        public Vector3 GetVelocity(FXEvent fxEvent, Random rand)
        {
            var velocityValue = FXFactory.GetLinearDistribution(rand, LinearDistribution, LinearVelocityMin, LinearVelocityMax);
            var velocity      = FXFactory.GetDirection(Direction, velocityValue, fxEvent);
            var addition      = FXFactory.GetRadialDistribution(rand, RadialDistribution, RadialVelocityMin, RadialVelocityMax);
            var advection     = fxEvent.Velocity * Advection;

            return(velocity + addition + advection);
        }
Esempio n. 7
0
        public void AddSoundStage(FXSoundStage stageDesc, FXEvent fxEvent, bool looped)
        {
            if (!stageDesc.Enabled)
            {
                return;
            }

            stages.Add(new SoundStage(this, stageDesc, fxEvent, looped));
        }
Esempio n. 8
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="dt"></param>
            public override void Update(float dt, FXEvent fxEvent)
            {
                var old_time = time;
                var new_time = time + dt;
                var fxOrigin = fxEvent.Origin;


                if (!stopped)
                {
                    for (int part = emitCount; true; part++)
                    {
                        float prt_time = GetParticleEmitTime(part);
                        float prt_dt   = prt_time - old_time;


                        if (prt_time <= new_time)
                        {
                            float addTime = new_time - prt_time;

                            fxEvent.Origin = fxOrigin - fxEvent.Velocity * addTime;

                            var p = new Particle();
                            p.TimeLag    = addTime;
                            p.ImageIndex = spriteIndex;
                            p.Position   = fxEvent.Origin;

                            if (looped || emitCount < stage.Count)
                            {
                                Emit(ref p, fxEvent);
                                fxInstance.rw.ParticleSystem.InjectParticle(p);
                            }
                            else
                            {
                                stopped = true;
                                break;
                            }

                            emitCount++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    //if ( !looped && ( emitCount >= stage.Count ) ) {
                    //	stopped = true;
                    //}

                    time += dt;
                }

                fxEvent.Origin = fxOrigin;
            }
Esempio n. 9
0
        public void AddLightStage(FXLightStage stageDesc, FXEvent fxEvent, bool looped)
        {
            if (!stageDesc.Enabled)
            {
                return;
            }

            var stage = new LightStage(this, stageDesc, fxEvent, looped);

            stages.Add(stage);
        }
Esempio n. 10
0
        /*-----------------------------------------------------------------------------------------
        *
        *	Stage creation functions :
        *
        *  -----------------------------------------------------------------------------------------*/

        /// <summary>
        ///
        /// </summary>
        /// <param name="spriteName"></param>
        /// <param name="delay"></param>
        /// <param name="period"></param>
        /// <param name="sleep"></param>
        /// <param name="count"></param>
        /// <param name="emit"></param>
        public void AddParticleStage(FXParticleStage stageDesc, FXEvent fxEvent, bool looped)
        {
            if (!stageDesc.Enabled)
            {
                return;
            }
            if (stageDesc.Count == 0)
            {
                return;
            }
            var stage = new ParticleStage(this, stageDesc, fxEvent, looped);

            stages.Add(stage);
        }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sfxSystem"></param>
        /// <param name="fxEvent"></param>
        public FXInstance(FXPlayback sfxSystem, FXEvent fxEvent, FXFactory fxFactory, bool looped)
        {
            this.fxAtom     = fxEvent.FXAtom;
            this.fxPlayback = sfxSystem;
            this.rw         = sfxSystem.rw;
            this.sw         = sfxSystem.sw;
            this.fxEvent    = fxEvent;

            AddParticleStage(fxFactory.ParticleStage1, fxEvent, looped);
            AddParticleStage(fxFactory.ParticleStage2, fxEvent, looped);
            AddParticleStage(fxFactory.ParticleStage3, fxEvent, looped);
            AddParticleStage(fxFactory.ParticleStage4, fxEvent, looped);

            AddLightStage(fxFactory.LightStage, fxEvent, looped);
            AddSoundStage(fxFactory.SoundStage, fxEvent, looped);
        }
Esempio n. 12
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="instance"></param>
            /// <param name="position"></param>
            /// <param name="soundPath"></param>
            public SoundStage(FXInstance instance, FXSoundStage stageDesc, FXEvent fxEvent, bool looped) : base(instance)
            {
                var sound = instance.fxPlayback.LoadSound(stageDesc.Sound);

                if (sound == null)
                {
                    return;
                }

                emitter               = instance.sw.AllocEmitter();
                emitter.Position      = fxEvent.Origin;
                emitter.DistanceScale = FXFactory.GetRadius(stageDesc.Attenuation);
                emitter.DopplerScale  = 1;
                emitter.VolumeCurve   = null;
                emitter.LocalSound    = false;

                emitter.PlaySound(sound, looped ? PlayOptions.Looped : PlayOptions.None);
            }
Esempio n. 13
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="instance"></param>
            /// <param name="position"></param>
            /// <param name="color"></param>
            /// <param name="radius"></param>
            /// <param name="fadeInRate"></param>
            /// <param name="fadeOutRate"></param>
            public LightStage(FXInstance instance, FXLightStage stageDesc, FXEvent fxEvent, bool looped) : base(instance)
            {
                light          = new OmniLight();
                this.stageDesc = stageDesc;

                light.Position = FXFactory.GetPosition(stageDesc.OffsetDirection, stageDesc.OffsetFactor, fxEvent);

                light.RadiusInner = stageDesc.InnerRadius;
                light.RadiusOuter = stageDesc.OuterRadius;
                light.Intensity   = stageDesc.Intensity;

                this.period = stageDesc.Period;
                this.looped = looped;

                instance.rw.LightSet.OmniLights.Add(light);

                UpdatePeriodIntensity();
                UpdateLightStyle();
            }
Esempio n. 14
0
        public static Vector3 GetDirection(FXDirection dir, float factor, FXEvent fxEvent)
        {
            var m = Matrix.RotationQuaternion(fxEvent.Rotation);

            switch (dir)
            {
            case FXDirection.LocalUp: return(m.Up * factor);

            case FXDirection.LocalDown: return(m.Down * factor);

            case FXDirection.LocalLeft: return(m.Left * factor);

            case FXDirection.LocalRight: return(m.Right * factor);

            case FXDirection.LocalForward: return(m.Forward * factor);

            case FXDirection.LocalBackward: return(m.Backward * factor);

            default: return(Vector3.Zero);
            }
        }
Esempio n. 15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="fxEvent"></param>
 /// <param name="spriteIndex"></param>
 /// <param name="delay"></param>
 /// <param name="period"></param>
 /// <param name="sleep"></param>
 /// <param name="count"></param>
 /// <param name="emit"></param>
 public ParticleStage(FXInstance instance, FXParticleStage stageDesc, FXEvent fxEvent, bool looped) : base(instance)
 {
     this.stage       = stageDesc;
     this.looped      = looped;
     this.spriteIndex = instance.fxPlayback.GetSpriteIndex(stageDesc.Sprite);
 }
Esempio n. 16
0
 public FXInstance CreateFXInstance(FXPlayback fxPlayback, FXEvent fxEvent, bool looped)
 {
     return(new FXInstance(fxPlayback, fxEvent, this, looped));
 }
Esempio n. 17
0
 /// <summary>
 /// Updates internal stage state.
 /// </summary>
 /// <param name="dt"></param>
 public abstract void Update(float dt, FXEvent fxEvent);