All Downloads are FREE. Search and download functionalities are using the official Maven repository.

games.rednblack.talos.runtime.ParticleEffectInstancePool Maven / Gradle / Ivy

package games.rednblack.talos.runtime;

import com.badlogic.gdx.utils.Pool;

public class ParticleEffectInstancePool extends Pool {

    private final ParticleEffectDescriptor particleEffectDescriptor;

    public ParticleEffectInstancePool(ParticleEffectDescriptor descriptor) {
        particleEffectDescriptor = descriptor;
    }

    public ParticleEffectInstancePool(ParticleEffectDescriptor descriptor, int initialCapacity) {
        super(initialCapacity);
        particleEffectDescriptor = descriptor;
    }

    public ParticleEffectInstancePool(ParticleEffectDescriptor descriptor, int initialCapacity, int max) {
        super(initialCapacity, max);
        particleEffectDescriptor = descriptor;
    }

    @Override
    protected PooledParticleEffectInstance newObject() {
        PooledParticleEffectInstance particleEffectInstance = new PooledParticleEffectInstance(particleEffectDescriptor);
        particleEffectDescriptor.setEffectReference(particleEffectInstance);

        for(ParticleEmitterDescriptor emitterDescriptor: particleEffectDescriptor.emitterModuleGraphs) {
            particleEffectInstance.addEmitter(emitterDescriptor);
        }

        particleEffectInstance.sortEmitters();

        // create default scope
        particleEffectInstance.setScope(new ScopePayload());

        return particleEffectInstance;
    }

    public ParticleEffectDescriptor getParticleEffectDescriptor() {
        return particleEffectDescriptor;
    }

    @Override
    public void free(PooledParticleEffectInstance object) {
        super.free(object);

        object.reset();
    }

    public class PooledParticleEffectInstance extends ParticleEffectInstance {
        public PooledParticleEffectInstance(ParticleEffectDescriptor particleEffectDescriptor) {
            super(particleEffectDescriptor);
        }

        public void free () {
            ParticleEffectInstancePool.this.free(this);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy