Search in sources :

Example 1 with ParticleData

use of io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleData in project chunkstories by Hugobros3.

the class ClientParticlesRenderer method spawnParticleAtPositionWithVelocity.

public void spawnParticleAtPositionWithVelocity(String particleTypeName, Vector3dc location, Vector3dc velocity) {
    ParticleTypeHandler particleType = store.getParticleType(particleTypeName);
    if (particleType == null || location == null)
        return;
    ParticleData particleData = particleType.createNew(world, (float) (double) location.x(), (float) (double) location.y(), (float) (double) location.z());
    if (velocity != null && particleData instanceof ParticleDataWithVelocity)
        ((ParticleDataWithVelocity) particleData).setVelocity(new Vector3f((float) velocity.x(), (float) velocity.y(), (float) velocity.z()));
    addParticle(particleType, particleData);
}
Also used : ParticleData(io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleData) ParticleDataWithVelocity(io.xol.chunkstories.api.particles.ParticleDataWithVelocity) ParticleTypeHandler(io.xol.chunkstories.api.particles.ParticleTypeHandler) Vector3f(org.joml.Vector3f)

Example 2 with ParticleData

use of io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleData in project chunkstories by Hugobros3.

the class ClientParticlesRenderer method updatePhysics.

public void updatePhysics() {
    for (ParticleTypeHandler particleType : particles.keySet()) {
        Iterator<ParticleData> iterator = particles.get(particleType).iterator();
        ParticleData p;
        while (iterator.hasNext()) {
            p = iterator.next();
            if (p != null) {
                particleType.forEach_Physics(world, p);
                if (p.isDed())
                    iterator.remove();
            } else
                iterator.remove();
        }
    }
}
Also used : ParticleData(io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleData) ParticleTypeHandler(io.xol.chunkstories.api.particles.ParticleTypeHandler)

Example 3 with ParticleData

use of io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleData in project chunkstories by Hugobros3.

the class ClientParticlesRenderer method renderParticles.

public void renderParticles(RenderingInterface renderingInterface) {
    // For all present particles types
    for (ParticleTypeHandler particleTypeHandler : particles.keySet()) {
        String renderPass = particleTypeHandler.getType().getRenderPass();
        if (!renderingInterface.getCurrentPass().name.equals(renderPass))
            continue;
        // Don't bother rendering empty sets
        if (particles.get(particleTypeHandler).size() > 0) {
            Iterator<ParticleData> iterator = particles.get(particleTypeHandler).iterator();
            boolean haveTextureCoordinates = false;
            ParticleTypeRenderer renderer = getRendererForType(particleTypeHandler);
            renderer.beginRenderingForType(renderingInterface);
            textureCoordinatesBuffer.clear();
            particlesPositionsBuffer.clear();
            // Some stuff don't wanna be rendered, so don't
            boolean actuallyRenderThatStuff = !renderPass.equals("lights");
            int elementsInDrawBuffer = 0;
            while (iterator.hasNext()) {
                // Iterate over dem particles
                ParticleData p = iterator.next();
                // Check we don't have a null particle
                if (p != null) {
                    renderer.forEach_Rendering(renderingInterface, p);
                    if (p.isDed())
                        iterator.remove();
                } else {
                    iterator.remove();
                    continue;
                }
                if (!actuallyRenderThatStuff)
                    continue;
                // If > 60k elements, buffer is full, draw it
                if (elementsInDrawBuffer >= 60000) {
                    drawBuffers(renderingInterface, elementsInDrawBuffer, haveTextureCoordinates);
                    elementsInDrawBuffer = 0;
                }
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                // Second triangle
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                particlesPositionsBuffer.put((float) p.x());
                particlesPositionsBuffer.put((float) p.y());
                particlesPositionsBuffer.put((float) p.z());
                // TODO No this sucks. Delet dis.
                if (p instanceof ParticleDataWithTextureCoordinates) {
                    haveTextureCoordinates = true;
                    ParticleDataWithTextureCoordinates texCoords = (ParticleDataWithTextureCoordinates) p;
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXTopRight());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYTopRight());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXTopLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYTopLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXBottomLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYBottomLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXBottomLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYBottomLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXTopRight());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYTopRight());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateXTopLeft());
                    textureCoordinatesBuffer.put(texCoords.getTextureCoordinateYBottomLeft());
                }
                elementsInDrawBuffer += 6;
            }
            // Draw the stuff
            if (elementsInDrawBuffer > 0) {
                drawBuffers(renderingInterface, elementsInDrawBuffer, haveTextureCoordinates);
                elementsInDrawBuffer = 0;
            }
        }
    }
    // We done here
    renderingInterface.getRenderTargetManager().setDepthMask(true);
    renderingInterface.setBlendMode(BlendMode.DISABLED);
// return totalDrawn;
}
Also used : ParticleData(io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleData) ParticleTypeRenderer(io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleTypeRenderer) ParticleTypeHandler(io.xol.chunkstories.api.particles.ParticleTypeHandler) ParticleDataWithTextureCoordinates(io.xol.chunkstories.api.particles.ParticleDataWithTextureCoordinates)

Aggregations

ParticleTypeHandler (io.xol.chunkstories.api.particles.ParticleTypeHandler)3 ParticleData (io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleData)3 ParticleDataWithTextureCoordinates (io.xol.chunkstories.api.particles.ParticleDataWithTextureCoordinates)1 ParticleDataWithVelocity (io.xol.chunkstories.api.particles.ParticleDataWithVelocity)1 ParticleTypeRenderer (io.xol.chunkstories.api.particles.ParticleTypeHandler.ParticleTypeRenderer)1 Vector3f (org.joml.Vector3f)1