diff options
Diffstat (limited to 'src/ru/olamedia/olacraft/scene/GameScene.java')
-rw-r--r-- | src/ru/olamedia/olacraft/scene/GameScene.java | 177 |
1 files changed, 113 insertions, 64 deletions
diff --git a/src/ru/olamedia/olacraft/scene/GameScene.java b/src/ru/olamedia/olacraft/scene/GameScene.java index 86b9574..e5655c9 100644 --- a/src/ru/olamedia/olacraft/scene/GameScene.java +++ b/src/ru/olamedia/olacraft/scene/GameScene.java @@ -11,8 +11,6 @@ import javax.media.opengl.glu.GLUquadric; import org.ode4j.ode.DBody; -import com.jogamp.opengl.util.PMVMatrix; - import ru.olamedia.Options; import ru.olamedia.game.GameTime; import ru.olamedia.liveEntity.LiveEntity; @@ -25,18 +23,19 @@ import ru.olamedia.olacraft.weapon.Bullet; import ru.olamedia.olacraft.weapon.BulletScene; import ru.olamedia.olacraft.world.block.Block; import ru.olamedia.olacraft.world.blockTypes.AbstractBlockType; +import ru.olamedia.olacraft.world.blockTypes.DirtBlockType; import ru.olamedia.olacraft.world.blockTypes.GrassBlockType; +import ru.olamedia.olacraft.world.blockTypes.GravelBlockType; +import ru.olamedia.olacraft.world.blockTypes.StoneBlockType; import ru.olamedia.olacraft.world.chunk.BlockSlice; +import ru.olamedia.olacraft.world.chunk.Chunk; import ru.olamedia.olacraft.world.chunk.ChunkSlice; -import ru.olamedia.olacraft.world.chunk.ChunkUnavailableException; +import ru.olamedia.olacraft.world.location.BlockLocation; import ru.olamedia.olacraft.world.provider.WorldProvider; import ru.olamedia.player.Player; -import ru.olamedia.vbo.VBO; public class GameScene { - private PMVMatrix matrix; - private HashMap<Integer, LiveEntity> liveEntities = new HashMap<Integer, LiveEntity>(); WorldProvider provider; private int renderDistance = Options.renderDistance; @@ -44,8 +43,6 @@ public class GameScene { private BulletScene bullets = new BulletScene(); private GamePhysicsWorld physics = new GamePhysicsWorld(); - private VBO testObject; - private boolean isInitialized = false; BlockSlice viewSlice; public GameTime time = new GameTime(); @@ -81,13 +78,18 @@ public class GameScene { time.init(); registerTextures(); viewport = new joglViewport(drawable); - testObject = new VBO(drawable); } private void registerTextures() { AbstractBlockType t; t = new GrassBlockType(); - t.register(); + t.register(provider); + t = new StoneBlockType(); + t.register(provider); + t = new DirtBlockType(); + t.register(provider); + t = new GravelBlockType(); + t.register(provider); } /** @@ -107,7 +109,7 @@ public class GameScene { blockRenderer = new ChunkRenderer(viewSlice); } - ChunkRenderer blockRenderer = new ChunkRenderer(viewSlice); + public ChunkRenderer blockRenderer = new ChunkRenderer(viewSlice); GLU glu = new GLU(); public void registerLiveEntity(LiveEntity entity) { @@ -136,7 +138,7 @@ public class GameScene { return liveEntities; } - Block nearestBlock = null; + public Block nearestBlock = null; public void tick() { time.tick(); @@ -146,12 +148,18 @@ public class GameScene { // bullets.update(Game.instance.getDelta()); physics.getWorld().step(Game.instance.getDelta()); BlockSlice pickSlice = new BlockSlice(provider, 10, 10, 10); - pickSlice.setCenter(player.getCameraX(), player.getCameraY(), player.getCameraZ()); - nearestBlock = pickSlice.getNearest(Game.instance.camera); + if (null != player) { + if (player.isOrientationChanged || Game.instance.camera.isOrientationChanged) { + player.isOrientationChanged = false; + Game.instance.camera.isOrientationChanged = false; + pickSlice.setCenter(player.getCameraX(), player.getCameraY(), player.getCameraZ()); + nearestBlock = pickSlice.getNearest(Game.instance.camera); + } + } } public void render(GLAutoDrawable drawable) { - if (!Game.instance.isRunning()) { + if (null == player || !Game.instance.isRunning()) { // not running, just clear screen GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); @@ -169,30 +177,33 @@ public class GameScene { gl.glPushAttrib(GL2.GL_ALL_ATTRIB_BITS); Game.instance.camera.setUp(drawable); // RENDER SUN - gl.glPushAttrib(GL2.GL_ALL_ATTRIB_BITS); - gl.glEnable(GL2.GL_BLEND); // Enable Blending - gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE); // Set Blending Mode To - // Mix Based On SRC - // Alpha - GLUquadric sun = glu.gluNewQuadric(); - glu.gluQuadricDrawStyle(sun, GLU.GLU_FILL); - glu.gluQuadricNormals(sun, GLU.GLU_SMOOTH); - gl.glPushMatrix(); - gl.glTranslatef(time.sun.getX() + player.getCameraX(), time.sun.getY(), time.sun.getZ() + player.getCameraZ()); - gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL); - gl.glColor4f(1, 1, 1, 0.02f); - glu.gluSphere(sun, 100f, 10, 10); - glu.gluSphere(sun, 90f, 10, 10); - glu.gluSphere(sun, 80f, 10, 10); - glu.gluSphere(sun, 70f, 10, 10); - glu.gluSphere(sun, 60f, 10, 10); - glu.gluSphere(sun, 50f, 10, 10); - glu.gluSphere(sun, 40f, 10, 10); - glu.gluSphere(sun, 35f, 10, 10); - gl.glColor4f(1, 1, 1, 1f); - glu.gluSphere(sun, 30f, 10, 10); - gl.glPopMatrix(); - gl.glPopAttrib(); + // gl.glPushAttrib(GL2.GL_ALL_ATTRIB_BITS); + // gl.glEnable(GL2.GL_BLEND); // Enable Blending + // gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE); // Set Blending Mode To + // // Mix Based On SRC + // // Alpha + // GLUquadric sun = glu.gluNewQuadric(); + // glu.gluQuadricDrawStyle(sun, GLU.GLU_FILL); + // glu.gluQuadricNormals(sun, GLU.GLU_SMOOTH); + // gl.glPushMatrix(); + // gl.glTranslatef(time.sun.getX() + player.getCameraX(), + // time.sun.getY(), time.sun.getZ() + player.getCameraZ()); + // gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL); + // gl.glColor4f(1, 1, 1, 0.02f); + // gl.glColor4f((float) 251 / 255, (float) 255 / 255, (float) 228 / 255, + // 0.02f); + // glu.gluSphere(sun, 100f, 10, 10); + // glu.gluSphere(sun, 90f, 10, 10); + // glu.gluSphere(sun, 80f, 10, 10); + // glu.gluSphere(sun, 70f, 10, 10); + // glu.gluSphere(sun, 60f, 10, 10); + // glu.gluSphere(sun, 50f, 10, 10); + // glu.gluSphere(sun, 40f, 10, 10); + // glu.gluSphere(sun, 35f, 10, 10); + // gl.glColor4f(1, 1, 1, 1f); + // glu.gluSphere(sun, 30f, 10, 10); + // gl.glPopMatrix(); + // gl.glPopAttrib(); viewSlice.setCenter((int) Game.instance.camera.getX(), (int) Game.instance.camera.getY(), (int) Game.instance.camera.getZ()); @@ -212,7 +223,7 @@ public class GameScene { // gl.glFogf(GL2.GL_FOG_DENSITY, 0.002f); // new float[] { 49f / 255f, 119f / 255f, 243f / 255f } // gl.glFogfv(GL2.GL_FOG_COLOR, new float[] { 1, 1, 1, 0.2f }, 0); - blockRenderer.render(drawable); + blockRenderer.render(); gl.glPopAttrib(); // RENDER ANYTHING ELSE gl.glPushAttrib(GL2.GL_ALL_ATTRIB_BITS); @@ -227,6 +238,11 @@ public class GameScene { gl.glPopMatrix(); } gl.glPopAttrib(); + if (nearestBlock != null) { + gl.glPushAttrib(GL2.GL_ALL_ATTRIB_BITS); + nearestBlock.renderFrame(); + gl.glPopAttrib(); + } // bullets.render(drawable); gl.glPopMatrix(); @@ -273,35 +289,68 @@ public class GameScene { // inventoryRenderer.render(drawable); } - viewport.drawText("avg fps: " + (int) Game.timer.getAvgFps(), 10, height - 20); - viewport.drawText("fps: " + (int) Game.timer.getFps(), 10, height - 35); + viewport.drawText("rad: " + Options.renderDistance, 10, height - 20); + viewport.drawText("avg fps: " + (int) Game.timer.getAvgFps(), 10, height - 35); + viewport.drawText("fps: " + (int) Game.timer.getFps(), 10, height - 50); MemoryUsage heap = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); viewport.drawText("mem: " + (heap.getUsed() / (1024 * 1024)) + "/" + (heap.getMax() / (1024 * 1024)), 10, - height - 50); - - viewport.drawText("y: " + Game.instance.player.getY(), width - msz - 10, height - msz - 20); - viewport.drawText("y: " + Game.instance.player.getCameraY() + " (cam)", width - msz - 10, height - msz - 30); - viewport.drawText("x: " + Game.instance.player.getX(), width - msz - 10, height - msz - 40); - viewport.drawText("z: " + Game.instance.player.getZ(), width - msz - 10, height - msz - 50); - viewport.drawText("players: " + liveEntities.size(), width - msz - 10, height - msz - 70); - viewport.drawText("bullets: " + getBulletsCount(), width - msz - 10, height - msz - 95); - viewport.drawText("y velocity: " + player.velocity.y + " y accel: " + player.acceleration.y + " inJump: " - + player.inJump + " onGround: " + player.onGround, width - msz - 350 - 10, height - msz - 110); - viewport.drawText("rdistance: " + renderDistance, width - msz - 10, height - msz - 155); - - ChunkSlice cs = viewSlice.getChunkSlice(); - viewport.drawText("slice x: " + cs.getX() + ".." + (cs.getX() + cs.getWidth() - 1) + " y: " + cs.getY() + ".." - + (cs.getY() + cs.getHeight() - 1) + " z: " + cs.getZ() + ".." + (cs.getZ() + cs.getDepth() - 1), width - - msz * 2 - 10, height - msz - 170); - viewport.drawText("time: " + time.getDateTimeString(), width - msz * 2 - 10, height - msz - 185); - if (nearestBlock != null) { - viewport.drawText("block: " + nearestBlock.getX() + ":" + nearestBlock.getY() + ":" + nearestBlock.getZ() - + " d " + nearestBlock.getDistance(Game.instance.camera), width - msz * 2 - 10, height - msz - 200); - } + height - 65); + // + // viewport.drawText("y: " + Game.instance.player.getY(), width - msz - + // 10, height - msz - 20); + // viewport.drawText("y: " + Game.instance.player.getCameraY() + + // " (cam)", width - msz - 10, height - msz - 30); + // viewport.drawText("x: " + Game.instance.player.getX(), width - msz - + // 10, height - msz - 40); + // viewport.drawText("z: " + Game.instance.player.getZ(), width - msz - + // 10, height - msz - 50); + // viewport.drawText("players: " + liveEntities.size(), width - msz - + // 10, height - msz - 70); + // viewport.drawText("bullets: " + getBulletsCount(), width - msz - 10, + // height - msz - 95); + // viewport.drawText("y velocity: " + player.velocity.y + " y accel: " + + // player.acceleration.y + " inJump: " + // + player.inJump + " onGround: " + player.onGround, width - msz - 350 + // - 10, height - msz - 110); + // viewport.drawText("rdistance: " + Options.renderDistance, width - msz + // - 10, height - msz - 155); + + // ChunkSlice cs = viewSlice.getChunkSlice(); + // viewport.drawText("slice x: " + cs.getX() + ".." + (cs.getX() + + // cs.getWidth() - 1) + " y: " + cs.getY() + ".." + // + (cs.getY() + cs.getHeight() - 1) + " z: " + cs.getZ() + ".." + + // (cs.getZ() + cs.getDepth() - 1), width + // - msz * 2 - 10, height - msz - 170); + // viewport.drawText("time: " + time.getDateTimeString(), width - msz * + // 2 - 10, height - msz - 185); + // if (nearestBlock != null) { + // viewport.drawText("pick: " + nearestBlock.getX() + "," + + // nearestBlock.getY() + "," + nearestBlock.getZ() + // + " d " + nearestBlock.getDistance(Game.instance.camera), width - msz + // * 2 - 10, height - msz - 200); + // viewport.drawText( + // "edge: " + nearestBlock.location.isChunkEdge() + " left " + + // nearestBlock.location.isChunkLeftEdge(), + // width - msz * 2 - 10, height - msz - 210); + // } + + // BlockLocation camloc = player.getCameraBlockLocation(); + // viewport.drawText("cam chunk: " + camloc.getChunkLocation(), width - + // 200 - msz * 2 - 10, height - msz - 225); + // Chunk camc = + // viewSlice.getChunkSlice().getChunk(camloc.getChunkLocation()); + // viewport.drawText("cam chunk: " + camc.isMeshCostructed + " mesh: " + + // camc.mesh, width - 200 - msz * 2 - 10, + // height - msz - 235); + // viewport.drawText( + // "chunk available: " + camc.isAvailable() + " chunk empty: " + // + (camc.isAvailable() ? camc.isEmpty() : "unknown"), width - 200 - + // msz * 2 - 10, height - msz + // - 245); gl.glPopAttrib(); gl.glPopMatrix(); - gl.glFlush(); + // gl.glFlush(); } public Player getPlayer() { |