package electrosphere.game.cell; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtil; import electrosphere.main.Globals; import electrosphere.renderer.Model; import electrosphere.renderer.ModelUtils; import electrosphere.renderer.ShaderProgram; import electrosphere.util.Utilities; import org.joml.Vector3f; /** * * @author satellite */ public class DrawCell { float[][] drawArray; int drawWidth; int cellX; int cellY; int cellWidth; Entity modelEntity; ShaderProgram program; public DrawCell(float[][] drawArray, int drawWidth, int cellX, int cellY, int cellWidth, ShaderProgram program){ this.drawArray = drawArray; this.drawWidth = drawWidth; this.cellX = cellX; this.cellY = cellY; this.cellWidth = cellWidth; this.program = program; } /** * Generates a drawable entity based on this chunk * @param stride The stride between indices used to generate "sparse" meshes */ public void generateDrawableEntity(int stride){ if(modelEntity != null){ Globals.entityManager.deregisterEntity(modelEntity); } Model terrainModel = ModelUtils.createTerrainModelPrecomputedShader(drawArray, program, stride); modelEntity = EntityUtil.spawnDrawableEntity(terrainModel); // System.out.println("New cell @ " + cellX * cellWidth + "," + cellY * cellWidth); EntityUtil.getEntityPosition(modelEntity).set(new Vector3f(cellX * cellWidth, 0, cellY * cellWidth)); } public void retireCell(){ EntityUtil.cleanUpDrawableEntity(modelEntity); } }