use of io.xol.chunkstories.api.particles.ParticleTypeHandler in project chunkstories by Hugobros3.
the class ParticlesTypesStore method loadParticlesFile.
private void loadParticlesFile(Asset f) {
if (f == null)
return;
try (BufferedReader reader = new BufferedReader(f.reader())) {
String line = "";
while ((line = reader.readLine()) != null) {
if (line.startsWith("#")) {
// It's a comment, ignore.
} else {
if (line.startsWith("end")) {
logger().warn("Syntax error in file : " + f + " : ");
continue;
}
String[] splitted = line.split(" ");
if (splitted.length == 2 && splitted[0].startsWith("particle")) {
// int id = Integer.parseInt(splitted[2]);
String particleName = splitted[1];
try {
ParticleTypeDefinitionImplementation type = new ParticleTypeDefinitionImplementation(this, particleName, reader);
ParticleTypeHandler handler = type.handler();
particleTypesByName.put(particleName, handler);
// particleTypesById.put(id, handler);
} catch (IllegalParticleDeclarationException e) {
this.store.getContext().logger().error("Could not load particle type " + particleName + " : \n" + e.getMessage());
e.printStackTrace();
}
}
}
}
} catch (IOException e) {
logger().warn(e.getMessage());
}
}
use of io.xol.chunkstories.api.particles.ParticleTypeHandler 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);
}
use of io.xol.chunkstories.api.particles.ParticleTypeHandler 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();
}
}
}
use of io.xol.chunkstories.api.particles.ParticleTypeHandler 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;
}
Aggregations