Quick update today on the Dungeon; I fixed the issue where firing the same Animation would cause it to not remove the emitter from the system (the result being that the particles wouldn’t stop emitting even after the Animation ended).  In order to reduce memory allocations, I don’t put instance-specific variables in the derived keyframe classes.  Or rather, I tried not to 🙂 – I was allocating the particle emitter in the AnimationKeyFrame_Particle.Start function and deallocating it in AnimationKeyFrame_Particle.End.  So two calls to Start would result in two allocations and only one deallocation.  This was fixed by making the abstract AnimationKeyFrame.Start return a derived AnimationKeyFrameInstanceData object, which is then passed to Render and End.  Most keyframe classes ignore this, but the particle one uses it to store the emitter (and system) and delete them in End.

Using that, the AnimationKeyFrame_Particle class is updated as follows:

 public override KeyFrame_InstanceData Start(GameObject performer, GameObject target)
        {
            // Create the per-instance data object to store our particle emitter nad system.
            AnimationKeyFrame_Particle_InstanceData data = new AnimationKeyFrame_Particle_InstanceData();

            // Create the particle system for this keyframe if not already created.
            data.ParticleSystem = new ParticleSystem(this, 10);
            ParticleMgr.Systems.Add(data.ParticleSystem);

            // Spin up a new particle emitter for this instance
            data.ParticleEmitter = new ParticleEmitter(data.ParticleSystem, 10, GameState_InDungeon.MapCellToScreenCoords(performer.Location));
            ParticleMgr.Emitters.Add(data.ParticleEmitter);

            return data;
        }

        public override void End(KeyFrame_InstanceData data, GameObject performer, GameObject target)
        {
            AnimationKeyFrame_Particle_InstanceData myData = data as AnimationKeyFrame_Particle_InstanceData;

            // Tear down our particle emitter
            myData.ParticleSystem.RemoveWhenDone();
            ParticleMgr.RemoveEmitter(myData.ParticleEmitter);
        }

… and the end result is a correctly working Animation system (whew).

Here’s a pic of AoE in action:

No code drop today though; still some bugs in the AoE targeting system.  More impactfully, it has raised some questions about turn timing and animations that I need to think through (specifically: user uses a skill like ice storm (in the picture above) – do the monsters move at the same time as the skill animation fires? after? before? automatically? etc…

Advertisements