diff --git a/src/projectzombie/Main.java b/src/projectzombie/Main.java index 90c482b..2c0a725 100755 --- a/src/projectzombie/Main.java +++ b/src/projectzombie/Main.java @@ -72,6 +72,10 @@ public class Main Tiles.init(); LayerGenerators.init(); + // Create the display + window = new DisplayWindow("Project Zombie"); + window.init(); + // Load the resources Resources.loadResources(); @@ -83,26 +87,21 @@ public class Main AudioSources.init(); Sounds.init(); - // Create the mainloop - mainloop = new MainloopManager(MainloopEventHandler.MAINLOOP_EVENT_HANDLER); - mainloop.register(MainloopEventHandler.MAINLOOP_EVENT_HANDLER); - mainloop.register(ChunkEventHandler.CHUNK_EVENT_HANDLER); - mainloop.register(DisplayStatsEventHandler.DISPLAY_STATS_EVENT_HANDLER); - mainloop.register(JoystickCallback.JOYSTICK_CALLBACK); - mainloop.register(new GameTimer()); - mainloop.register(new KeyCallback()); - mainloop.register(new NoSleep()); - mainloop.register(new MainloopHelpers()); - - // Create the display - window = new DisplayWindow("Project Zombie"); - window.init(); - // Initialize the gamepad JoystickCallback.JOYSTICK_CALLBACK.init(); - // Initialise the entities + // Create the mainloop + mainloop = new MainloopManager(MainloopEventHandler.MAINLOOP_EVENT_HANDLER); + mainloop.register(DisplayStatsEventHandler.DISPLAY_STATS_EVENT_HANDLER); + mainloop.register(MainloopEventHandler.MAINLOOP_EVENT_HANDLER); mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER); + mainloop.register(ChunkEventHandler.CHUNK_EVENT_HANDLER); + mainloop.register(JoystickCallback.JOYSTICK_CALLBACK); + mainloop.register(new MainloopHelpers()); + mainloop.register(new KeyCallback()); + mainloop.register(new GameTimer()); + mainloop.register(new NoSleep()); + mainloop.register(window); // Start the mainloop menu = new MenuMain(); diff --git a/src/projectzombie/audio/AudioObject.java b/src/projectzombie/audio/AudioObject.java index 91ac956..e7e1ffd 100755 --- a/src/projectzombie/audio/AudioObject.java +++ b/src/projectzombie/audio/AudioObject.java @@ -21,8 +21,10 @@ import org.lwjgl.stb.STBVorbis; import org.lwjgl.system.MemoryStack; import projectzombie.Main; +import projectzombie.display.Camera; import projectzombie.resources.Resource; import gl_engine.MathHelpers; +import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; @@ -30,6 +32,7 @@ public class AudioObject { int bufferPointer; Resource resource; + boolean error; int channels; int sample_rate; int output; @@ -38,6 +41,7 @@ public class AudioObject { // Store the argument values this.resource = resource; + this.error = false; } public void init() @@ -51,6 +55,11 @@ public class AudioObject ByteBuffer resource_buffer = resource.getByteBuffer(); ShortBuffer audio = STBVorbis.stb_vorbis_decode_memory(resource_buffer, channels_buf, sample_rate_buf); + if(audio == null) { + error = true; + return; + } + // Get the channels and the sample rate channels = channels_buf.get(); sample_rate = sample_rate_buf.get(); @@ -65,6 +74,7 @@ public class AudioObject // Send the data to OpenAL bufferPointer = alGenBuffers(); + alBufferData(bufferPointer, format, audio, sample_rate); // Free some c buffers @@ -74,28 +84,19 @@ public class AudioObject public void play(Vec3d pos, double volume) { - // Get the player pos - Vec2d p_pos = Main.player.pos; - - // Convert the angle to radians - double angle_r = Math.toRadians(Main.player.angle + 90); - - // Calculate the translation - double x = ( pos.x - p_pos.x ); - double y = ( pos.y - p_pos.y ); - double z = pos.z; + if(error) { + return; + } // Calculate the rotation - Vec2d rotated = MathHelpers.rotate2(new Vec2d(x, y), -angle_r); - x = rotated.x; - y = rotated.y; + Vec3d vec = Matrix4.multiply(Camera.camera.getMatrix(), pos); // Play the sound with a new source int source = AudioSources.getSource(); alSourceStop(source); alSourcei(source, AL_BUFFER, bufferPointer); alSourcef(source, AL_GAIN, (float)volume); - alSource3f(source, AL_POSITION, (float)x, (float)y, (float)z); + alSource3f(source, AL_POSITION, (float)vec.x, (float)vec.y, (float)vec.z); alSourcePlay(source); } } diff --git a/src/projectzombie/display/Camera.java b/src/projectzombie/display/Camera.java index 0a6669c..51bf666 100755 --- a/src/projectzombie/display/Camera.java +++ b/src/projectzombie/display/Camera.java @@ -1,24 +1,30 @@ package projectzombie.display; import gl_engine.matrix.Matrix4; +import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; +import projectzombie.Main; public class Camera { public double angle = 45; - public int renderDistance; + public int renderDistance = 3; private Matrix4 matrix; public static Camera camera; - public Camera(Vec3d pos) + public Camera() { Matrix4 identity = Matrix4.identity(); + Vec2d pos = Main.player.pos; + angle = Main.player.angle; - identity = Matrix4.multiply(identity, Matrix4.translate(pos.x, 0, pos.y)); + identity = Matrix4.multiply(identity, Matrix4.translate(-pos.x, 0, -pos.y)); identity = Matrix4.multiply(identity, Matrix4.rotate(angle, 0, 1, 0)); identity = Matrix4.multiply(identity, Matrix4.rotate(-50, 1, 0, 0)); - identity = Matrix4.multiply(identity, Matrix4.translate(0, 0, -8)); + identity = Matrix4.multiply(identity, Matrix4.translate(0, 0, -12)); + + matrix = identity; } public Matrix4 getMatrix() { diff --git a/src/projectzombie/display/DisplayRender.java b/src/projectzombie/display/DisplayRender.java index b778fff..8a0d583 100755 --- a/src/projectzombie/display/DisplayRender.java +++ b/src/projectzombie/display/DisplayRender.java @@ -12,13 +12,16 @@ import static org.lwjgl.opengl.GL11.glMatrixMode; import static org.lwjgl.opengl.GL11.glViewport; import org.lwjgl.opengl.GL; +import org.lwjgl.opengl.GL33; import org.lwjgl.system.MemoryStack; +import gl_engine.graphics.GraphicsShader; import gl_engine.matrix.Matrix4; import projectzombie.Main; import projectzombie.display.lighting.DynamicLighting; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.gl.GlHelpers; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; @@ -29,10 +32,6 @@ public class DisplayRender { public static void render(int w, int h) { - // Set the width and the height - Main.window.setWidth(w); - Main.window.setHeight(h); - // Setup GL and clear the colour glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, w, h); @@ -41,24 +40,35 @@ public class DisplayRender { if(ChunkEventHandler.loaded) { - // Create the projection matrix - Matrix4 projection = Matrix4.projection((double)w / (double)h, 45, 1, 32); - EntityPlayer player = Main.player; - Camera camera = new Camera(new Vec3d(player.pos.x, 0, player.pos.y)); + Camera camera = new Camera(); Camera.camera = camera; + // Create the projection matrix + Matrix4 projection = Matrix4.projection((double)w / (double)h, 45, 0.1, 1000); + Matrix4 rotated = Matrix4.rotate(-camera.angle, 0, 1, 0); + // Process all the light sources - DynamicLighting.update(); + //DynamicLighting.update(); + + Main.window.environmentRenderer.use(); + GL33.glUniformMatrix4fv(Main.window.glsl_camera, true, camera.getMatrix().getArray()); + GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, projection.getArray()); + GL33.glUniformMatrix4fv(Main.window.glsl_rotated, true, rotated.getArray()); // Render the world and the player Main.world.render(camera); player.chunk = Main.world.getLayer().getChunk(player.pos); - player.doRender(player.pos, camera); + + Model model = player.getModel(); + Matrix4 matrix = Matrix4.translate(player.pos.x, 0, player.pos.y); + GL33.glUniformMatrix4fv(Main.window.glsl_model, true, matrix.getArray()); + model.bind(); + model.render(); } } // Render the user interface - DisplayRenderUI.render(); + //DisplayRenderUI.render(); } } diff --git a/src/projectzombie/display/DisplayRenderUI.java b/src/projectzombie/display/DisplayRenderUI.java index b559250..841680c 100755 --- a/src/projectzombie/display/DisplayRenderUI.java +++ b/src/projectzombie/display/DisplayRenderUI.java @@ -19,7 +19,7 @@ public class DisplayRenderUI public static void render() { - double s = GlHelpers.getScale() / 10.0; + /*double s = GlHelpers.getScale() / 10.0; // Get some text settings Vec2d text_size = new Vec2d(0.5, 0.5); @@ -186,6 +186,6 @@ public class DisplayRenderUI } // Render the loaded menu - Main.menu.render(); + Main.menu.render();*/ } } diff --git a/src/projectzombie/display/DisplayWindow.java b/src/projectzombie/display/DisplayWindow.java index 385dc34..383f4df 100755 --- a/src/projectzombie/display/DisplayWindow.java +++ b/src/projectzombie/display/DisplayWindow.java @@ -9,10 +9,15 @@ import java.nio.IntBuffer; import org.lwjgl.BufferUtils; import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL; +import org.lwjgl.opengl.GL33; import gl_engine.graphics.GraphicsHelpers; +import gl_engine.graphics.GraphicsShader; +import gl_engine.matrix.Matrix4; import mainloop.task.IMainloopTask; import projectzombie.Main; +import projectzombie.init.Models; +import projectzombie.init.Resources; import projectzombie.input.CursorEnterCallback; import projectzombie.input.CursorPosCallback; import projectzombie.input.JoystickCallback; @@ -33,6 +38,13 @@ public class DisplayWindow implements IMainloopTask private boolean fullscreen = true; private boolean mouseVisibility_last = false; + public GraphicsShader environmentRenderer; + + public int glsl_model; + public int glsl_projection; + public int glsl_rotated; + public int glsl_camera; + public int getWidth() { return this.width; } @@ -72,7 +84,7 @@ public class DisplayWindow implements IMainloopTask window = GraphicsHelpers.initWindow("Project Zombie", width, height, monitor); // Make the context current - GLFW.glfwMakeContextCurrent(this.window); + //GLFW.glfwMakeContextCurrent(this.window); // Set the key handlers GLFW.glfwSetCursorPosCallback(this.window, new CursorPosCallback()); @@ -87,10 +99,17 @@ public class DisplayWindow implements IMainloopTask GLFW.glfwSetInputMode(this.window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN); // Show the window - GLFW.glfwShowWindow(this.window); + //GLFW.glfwShowWindow(this.window); - // Register the display event loop - Main.mainloop.register(this); + GL33.glEnable(GL33.GL_DEPTH_TEST); + + environmentRenderer = new GraphicsShader("/resources/shader/environmentRenderer"); + environmentRenderer.use(); + + glsl_model = GL33.glGetUniformLocation(environmentRenderer.program, "model"); + glsl_camera = GL33.glGetUniformLocation(environmentRenderer.program, "camera"); + glsl_rotated = GL33.glGetUniformLocation(environmentRenderer.program, "rotated"); + glsl_projection = GL33.glGetUniformLocation(environmentRenderer.program, "projection"); } public void render() @@ -99,16 +118,21 @@ public class DisplayWindow implements IMainloopTask int w[] = {0}; int h[] = {0}; GLFW.glfwGetFramebufferSize(this.window, w, h); + width = w[0]; + height = h[0]; + + // Bind the texture atlas + Resources.ATLAS.bind(); // Render everything DisplayRender.render(w[0], h[0]); // Check if the matrix count is ok - GlHelpers.checkMatrixCount(); + //GlHelpers.checkMatrixCount(); // Swap the framebuffers and poll events - this.swapBuffers(); - this.pollEvents(); + GLFW.glfwSwapBuffers(window); + GLFW.glfwPollEvents(); } public void toggleFullscreen() { @@ -132,14 +156,6 @@ public class DisplayWindow implements IMainloopTask } } - public void swapBuffers() { - GLFW.glfwSwapBuffers(this.window); - } - - public void pollEvents() { - GLFW.glfwPollEvents(); - } - public boolean shouldClose() { return GLFW.glfwWindowShouldClose(this.window); } diff --git a/src/projectzombie/display/bossbar/BossBars.java b/src/projectzombie/display/bossbar/BossBars.java index 9c531ee..efccaaf 100755 --- a/src/projectzombie/display/bossbar/BossBars.java +++ b/src/projectzombie/display/bossbar/BossBars.java @@ -20,7 +20,7 @@ public class BossBars public static void render() { - TextureReference health_fg = Models.UI_HEALTH_FG; + /*TextureReference health_fg = Models.UI_HEALTH_FG; TextureReference health_bg = Models.UI_HEALTH_BG; ArrayList toRemove = new ArrayList(); @@ -54,6 +54,6 @@ public class BossBars for(IBossBar bossbar : toRemove) { bossbars.remove(bossbar); - } + }*/ } } diff --git a/src/projectzombie/display/lighting/TileLighting.java b/src/projectzombie/display/lighting/TileLighting.java index 9181142..33bc2c2 100755 --- a/src/projectzombie/display/lighting/TileLighting.java +++ b/src/projectzombie/display/lighting/TileLighting.java @@ -32,10 +32,10 @@ public class TileLighting implements IMainloopTask cx + MathHelpers.floor(player.pos.x / 16), cy + MathHelpers.floor(player.pos.y / 16)); Chunk chunk = layer.chunks.get(cpos); - if(chunk.light_dirty) { + /*if(chunk.light_dirty) { chunk.light_dirty = false; dirty = true; - } + }*/ } } diff --git a/src/projectzombie/entity/EntityItem.java b/src/projectzombie/entity/EntityItem.java index 6a60f71..29ccc36 100755 --- a/src/projectzombie/entity/EntityItem.java +++ b/src/projectzombie/entity/EntityItem.java @@ -134,7 +134,7 @@ public class EntityItem extends Entity @Override public Model getModel() { - return Models.ITEM_NONE; + return stack.item.getModel(stack.meta); } diff --git a/src/projectzombie/entity/particle/ParticleBreak.java b/src/projectzombie/entity/particle/ParticleBreak.java index 7bf6467..89b3478 100755 --- a/src/projectzombie/entity/particle/ParticleBreak.java +++ b/src/projectzombie/entity/particle/ParticleBreak.java @@ -7,7 +7,6 @@ import projectzombie.entity.EntityParticle; import projectzombie.init.Models; import projectzombie.model.Model; import projectzombie.settings.SettingQuality; -import projectzombie.tiles.TileVertical; import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.texture.IHasTexture; import projectzombie.util.gl.texture.TextureReference; @@ -52,9 +51,7 @@ public class ParticleBreak extends EntityParticle int height = 1; - if(s.tile instanceof TileVertical) { - height = MathHelpers.floor(((TileVertical)s.tile).size.y); - } + for(int i=0;i<50 * height;i++) { chunk.spawnEntity(new ParticleBreak(pos.copy(), s)); @@ -98,12 +95,6 @@ public class ParticleBreak extends EntityParticle double angle = RandomHelpers.randrange(rand, 360); - if(ts.tile instanceof TileVertical) { - TileVertical ts_v = (TileVertical) ts.tile; - - height = RandomHelpers.randrange(rand, 0, MathHelpers.floor(ts_v.size.y)); - } - Vec2d side_v = MathHelpers.moveTowards2(0.01, Math.toRadians(angle)); velocity = new Vec3d( side_v.x, side_v.y, @@ -170,7 +161,7 @@ public class ParticleBreak extends EntityParticle @Override public Model getModel() { - return Models.ENTITY_NONE; + return Models.PARTICLE_BULLET; } diff --git a/src/projectzombie/init/Models.java b/src/projectzombie/init/Models.java index 68492e5..c0304de 100755 --- a/src/projectzombie/init/Models.java +++ b/src/projectzombie/init/Models.java @@ -4,8 +4,10 @@ import java.util.ArrayList; import org.lwjgl.opengl.GL; +import gl_engine.vec.Vec2d; import projectzombie.display.DisplayWindow; import projectzombie.model.Model; +import projectzombie.model.ModelEmpty; import projectzombie.model.ModelGui; import projectzombie.model.ModelRandom; import projectzombie.model.ModelTile; @@ -16,15 +18,13 @@ import projectzombie.util.gl.texture.TextureReferenceRandom; public class Models { - public static final Model TILE_NONE = new ModelTile(Resources.ATLAS.get("NONE")); - public static final Model ENTITY_NONE = new ModelTile(Resources.ATLAS.get("NONE")); - public static final Model ITEM_NONE = new ModelTile(Resources.ATLAS.get("NONE")); + public static final Model EMPTY = new ModelEmpty(); public static final Model TILE_GRASS = new ModelTile(Resources.ATLAS.get("/tile/grass.png")); public static final Model TILE_SAND = new ModelTile(Resources.ATLAS.get("/tile/sand.png")); public static final Model TILE_STONE = new ModelTile(Resources.ATLAS.get("/tile/stone.png")); public static final Model TILE_DIRT = new ModelTile(Resources.ATLAS.get("/tile/dirt.png")); - public static final Model TILE_TREE = new ModelVertical(Resources.ATLAS.get("/tile/tree.png")); + public static final Model TILE_TREE = new ModelVertical(Resources.ATLAS.get("/tile/tree.png"), new Vec2d(1, 4)); public static final Model TILE_ROCK = new ModelVertical(Resources.ATLAS.get("/tile/rock.png")); public static final Model TILE_LADDER = new ModelVertical(Resources.ATLAS.get("/tile/ladder.png")); public static final Model TILE_PORTAL = new ModelVertical(Resources.ATLAS.get("/tile/portal.png")); diff --git a/src/projectzombie/init/Tiles.java b/src/projectzombie/init/Tiles.java index 39a76a8..941e8f4 100755 --- a/src/projectzombie/init/Tiles.java +++ b/src/projectzombie/init/Tiles.java @@ -21,7 +21,6 @@ import projectzombie.tiles.TileVoid; import projectzombie.tiles.TileWall; import projectzombie.tiles.TileWallUnbreakable; import projectzombie.tiles.TileWater; -import projectzombie.tiles.TileWaterFlow; public class Tiles { @@ -50,7 +49,6 @@ public class Tiles register(LAVA); register(WATER); register(LAVA_FLOW); - register(WATER_FLOW); register(LADDER); register(PORTAL_DOWN); register(WALL); @@ -71,7 +69,6 @@ public class Tiles public static final Tile LAVA = new TileLava(); public static final Tile WATER = new TileWater(); public static final Tile LAVA_FLOW = new TileLavaFlow(); - public static final Tile WATER_FLOW = new TileWaterFlow(); public static final Tile LADDER = new TileLadder(); public static final Tile PORTAL_DOWN = new TilePortalDown(); public static final Tile WALL = new TileWall(); diff --git a/src/projectzombie/items/Item.java b/src/projectzombie/items/Item.java index 71f8b06..c3071bc 100755 --- a/src/projectzombie/items/Item.java +++ b/src/projectzombie/items/Item.java @@ -4,6 +4,7 @@ import projectzombie.entity.Entity; import projectzombie.entity.EntityInventory; import projectzombie.entity.player.EntityPlayer; import projectzombie.inventory.Inventory; +import projectzombie.model.Model; import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.math.ItemStack; @@ -11,23 +12,11 @@ import gl_engine.vec.Vec2d; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; -public class Item +public abstract class Item { public TextureReference texture; public int id; - public void render(Vec2d pos, Vec2d size) - { - GlHelpers.begin(); - - texture.texCoord(0, 1); GlHelpers.vertex2(pos.x+size.x , pos.y ); - texture.texCoord(0, 0); GlHelpers.vertex2(pos.x+size.x , pos.y+size.y ); - texture.texCoord(1, 0); GlHelpers.vertex2(pos.x , pos.y+size.y ); - texture.texCoord(1, 1); GlHelpers.vertex2(pos.x , pos.y ); - - GlHelpers.end(); - } - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { stack.count -= 1; } @@ -40,6 +29,8 @@ public class Item return 0; } + public abstract Model getModel(short meta); + public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity) { // Update the stacks count diff --git a/src/projectzombie/items/ItemAmmo.java b/src/projectzombie/items/ItemAmmo.java index 882c148..9b43217 100755 --- a/src/projectzombie/items/ItemAmmo.java +++ b/src/projectzombie/items/ItemAmmo.java @@ -3,6 +3,7 @@ package projectzombie.items; import projectzombie.entity.Entity; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -10,9 +11,9 @@ import projectzombie.world.layer.Layer; public class ItemAmmo extends Item { - public ItemAmmo() { - - this.texture = Models.ITEM_AMMO_BOX; + @Override + public Model getModel(short meta) { + return Models.ITEM_AMMO_BOX; } @Override diff --git a/src/projectzombie/items/ItemDefenceUpgrade.java b/src/projectzombie/items/ItemDefenceUpgrade.java index cec5ced..fab0996 100755 --- a/src/projectzombie/items/ItemDefenceUpgrade.java +++ b/src/projectzombie/items/ItemDefenceUpgrade.java @@ -3,6 +3,7 @@ package projectzombie.items; import projectzombie.Main; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -10,9 +11,9 @@ import projectzombie.world.layer.Layer; public class ItemDefenceUpgrade extends Item { - public ItemDefenceUpgrade() { - - this.texture = Models.ITEM_DEFENCE_UPGRADE; + @Override + public Model getModel(short meta) { + return Models.ITEM_DEFENCE_UPGRADE; } @Override diff --git a/src/projectzombie/items/ItemEmpty.java b/src/projectzombie/items/ItemEmpty.java index 34acf5e..285a6ed 100755 --- a/src/projectzombie/items/ItemEmpty.java +++ b/src/projectzombie/items/ItemEmpty.java @@ -2,6 +2,7 @@ package projectzombie.items; import projectzombie.entity.Entity; import projectzombie.entity.player.EntityPlayer; +import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import gl_engine.vec.Vec2d; import projectzombie.world.chunk.Chunk; @@ -22,7 +23,8 @@ public class ItemEmpty extends Item } @Override - public void render(Vec2d pos, Vec2d size) { + public Model getModel(short meta) { + return null; } } diff --git a/src/projectzombie/items/ItemFlare.java b/src/projectzombie/items/ItemFlare.java index 53097c6..24cc6fa 100755 --- a/src/projectzombie/items/ItemFlare.java +++ b/src/projectzombie/items/ItemFlare.java @@ -3,6 +3,7 @@ package projectzombie.items; import projectzombie.entity.EntityFlare; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -10,9 +11,9 @@ import projectzombie.world.layer.Layer; public class ItemFlare extends Item { - public ItemFlare() { - - this.texture = Models.ENTITY_FLARE; + @Override + public Model getModel(short meta) { + return Models.ENTITY_FLARE; } @Override diff --git a/src/projectzombie/items/ItemGrapplingHook.java b/src/projectzombie/items/ItemGrapplingHook.java index db1f186..16df8da 100755 --- a/src/projectzombie/items/ItemGrapplingHook.java +++ b/src/projectzombie/items/ItemGrapplingHook.java @@ -3,6 +3,7 @@ package projectzombie.items; import projectzombie.entity.EntityGrapplingHook; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import gl_engine.MathHelpers; import gl_engine.vec.Vec2d; @@ -12,9 +13,9 @@ import projectzombie.world.layer.Layer; public class ItemGrapplingHook extends Item { - public ItemGrapplingHook() { - - this.texture = Models.ITEM_GRAPPLING_HOOK; + @Override + public Model getModel(short meta) { + return Models.ITEM_GRAPPLING_HOOK; } @Override diff --git a/src/projectzombie/items/ItemGunUpgrade.java b/src/projectzombie/items/ItemGunUpgrade.java index 6e93492..6028f13 100755 --- a/src/projectzombie/items/ItemGunUpgrade.java +++ b/src/projectzombie/items/ItemGunUpgrade.java @@ -3,6 +3,7 @@ package projectzombie.items; import projectzombie.Main; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -10,9 +11,9 @@ import projectzombie.world.layer.Layer; public class ItemGunUpgrade extends Item { - public ItemGunUpgrade() { - - this.texture = Models.ITEM_GUN_UPGRADE; + @Override + public Model getModel(short meta) { + return Models.ITEM_GUN_UPGRADE; } @Override diff --git a/src/projectzombie/items/ItemHealthPotion.java b/src/projectzombie/items/ItemHealthPotion.java index b4ac348..6abdf73 100755 --- a/src/projectzombie/items/ItemHealthPotion.java +++ b/src/projectzombie/items/ItemHealthPotion.java @@ -2,6 +2,7 @@ package projectzombie.items; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -9,9 +10,9 @@ import projectzombie.world.layer.Layer; public class ItemHealthPotion extends Item { - public ItemHealthPotion() { - - this.texture = Models.ITEM_HEALTH_POTION; + @Override + public Model getModel(short meta) { + return Models.ITEM_HEALTH_POTION; } @Override diff --git a/src/projectzombie/items/ItemLantern.java b/src/projectzombie/items/ItemLantern.java index 79530cd..8dc3175 100755 --- a/src/projectzombie/items/ItemLantern.java +++ b/src/projectzombie/items/ItemLantern.java @@ -3,6 +3,7 @@ package projectzombie.items; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; import projectzombie.init.Tiles; +import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import gl_engine.MathHelpers; import gl_engine.vec.Vec2i; @@ -12,9 +13,9 @@ import projectzombie.world.layer.Layer; public class ItemLantern extends Item { - public ItemLantern() { - - this.texture = Models.TILE_LANTERN; + @Override + public Model getModel(short meta) { + return Models.TILE_LANTERN; } @Override diff --git a/src/projectzombie/items/ItemRock.java b/src/projectzombie/items/ItemRock.java index 0b6bd03..7727bde 100755 --- a/src/projectzombie/items/ItemRock.java +++ b/src/projectzombie/items/ItemRock.java @@ -2,6 +2,7 @@ package projectzombie.items; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -9,9 +10,9 @@ import projectzombie.world.layer.Layer; public class ItemRock extends Item { - public ItemRock() { - - this.texture = Models.TILE_ROCK; + @Override + public Model getModel(short meta) { + return Models.ITEM_ROCK; } @Override diff --git a/src/projectzombie/items/ItemSpawn.java b/src/projectzombie/items/ItemSpawn.java index 32c185a..4a824eb 100755 --- a/src/projectzombie/items/ItemSpawn.java +++ b/src/projectzombie/items/ItemSpawn.java @@ -6,9 +6,8 @@ import gl_engine.vec.Vec2d; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; -public class ItemSpawn extends Item +public abstract class ItemSpawn extends Item { - @Override public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { super.onPlayerAction(stack, layer, chunk, player); @@ -19,7 +18,4 @@ public class ItemSpawn extends Item public void spawnEntity(Layer layer, Chunk chunk, Vec2d pos) { } - - - } diff --git a/src/projectzombie/items/ItemTnt.java b/src/projectzombie/items/ItemTnt.java index 13a8399..ce9332c 100755 --- a/src/projectzombie/items/ItemTnt.java +++ b/src/projectzombie/items/ItemTnt.java @@ -3,18 +3,18 @@ package projectzombie.items; import projectzombie.entity.EntityTnt; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.math.ItemStack; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; public class ItemTnt extends Item { - - public ItemTnt() { - - this.texture = Models.ENTITY_TNT; + @Override + public Model getModel(short meta) { + return Models.ENTITY_TNT; } - + @Override public String getName(short meta) { return "TNT"; diff --git a/src/projectzombie/items/spawner/ItemSpawnZombie.java b/src/projectzombie/items/spawner/ItemSpawnZombie.java index e537732..8d3a8cb 100755 --- a/src/projectzombie/items/spawner/ItemSpawnZombie.java +++ b/src/projectzombie/items/spawner/ItemSpawnZombie.java @@ -3,6 +3,7 @@ package projectzombie.items.spawner; import projectzombie.entity.EntityZombie; import projectzombie.init.Models; import projectzombie.items.ItemSpawn; +import projectzombie.model.Model; import gl_engine.vec.Vec2d; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -10,9 +11,9 @@ import projectzombie.world.layer.Layer; public class ItemSpawnZombie extends ItemSpawn { - public ItemSpawnZombie() { - - this.texture = Models.ENTITY_ZOMBIE_B; + @Override + public Model getModel(short meta) { + return Models.ENTITY_ZOMBIE_B; } @Override diff --git a/src/projectzombie/menu/gui/Button.java b/src/projectzombie/menu/gui/Button.java index 16a954f..d6625c7 100755 --- a/src/projectzombie/menu/gui/Button.java +++ b/src/projectzombie/menu/gui/Button.java @@ -3,9 +3,11 @@ package projectzombie.menu.gui; import projectzombie.Main; import projectzombie.init.Models; import projectzombie.input.InputMode; +import projectzombie.model.Model; import projectzombie.text.Text; import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.texture.TextureReference; +import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec2d; public class Button implements GUIComponent, GUISelectable @@ -33,10 +35,8 @@ public class Button implements GUIComponent, GUISelectable } @Override - public void render(Vec2d mousePos) { - GlHelpers.pushMatrix(); - GlHelpers.translate2(pos.x, pos.y); - + public void render(Vec2d mousePos) + { double m = 3; double w = textSize.x * m * 8; double h = textSize.x * m / 2; @@ -63,37 +63,24 @@ public class Button implements GUIComponent, GUISelectable wt = -w/2; } - TextureReference tex; + Model model; boolean mouseHover = InputMode.Controller ? this.selected : this.checkMouseHover(mousePos); if(mouseHover) { - tex = Models.BUTTON_HOVER; + model = Models.BUTTON_HOVER; } else { - tex = Models.BUTTON; + model = Models.BUTTON; } - GlHelpers.color4(1, 1, 1, 1); - GlHelpers.begin(); - { - tex.texCoord(0, 0); GlHelpers.vertex2(w1, -h); - tex.texCoord(1, 0); GlHelpers.vertex2(w2, -h); - tex.texCoord(1, 1); GlHelpers.vertex2(w2, h); - tex.texCoord(0, 1); GlHelpers.vertex2(w1, h); - } - GlHelpers.end(); + Matrix4 matrix = Matrix4.translate(pos.x, pos.y, 0); - GlHelpers.translate2( - (-textSize.x * text.length() / 2 + wt)/GlHelpers.getAspectRatio(), - -textSize.y / 2 - ); + model.bind(); if(mouseHover) { - GlHelpers.color3(0.8, 0.8, 0.8); + //GlHelpers.color3(0.8, 0.8, 0.8); } else { - GlHelpers.color3(0.68, 0.68, 0.68); + //GlHelpers.color3(0.68, 0.68, 0.68); } Text.render(text, textSize); - - GlHelpers.popMatrix(); } @Override diff --git a/src/projectzombie/model/Model.java b/src/projectzombie/model/Model.java index c23f6f6..e123695 100644 --- a/src/projectzombie/model/Model.java +++ b/src/projectzombie/model/Model.java @@ -5,11 +5,14 @@ import gl_engine.texture.TextureRef3D; import static org.lwjgl.opengl.GL33.*; +import org.lwjgl.opengl.GL33; + public abstract class Model { int vao, size; boolean loaded = false; private static final int SIZE = 9; + private float[] verticies; public int getSize() { return size; @@ -19,6 +22,10 @@ public abstract class Model protected abstract float[] getVerticies(); protected abstract TextureRef3D[] getTextures(); + public float[] getLoadedVerticies() { + return verticies; + } + public void bind() { if(loaded) { @@ -27,7 +34,7 @@ public abstract class Model else { - float[] verticies = this.getVerticies(); + verticies = this.getVerticies(); TextureRef3D[] refs = this.getTextures(); if(verticies.length % SIZE != 0 || refs.length * 3 != verticies.length / SIZE) { @@ -53,10 +60,20 @@ public abstract class Model glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, verticies, GL_STATIC_DRAW); - glVertexAttribPointer(0, SIZE, GL_FLOAT, false, Float.BYTES * SIZE, 0); + glVertexAttribPointer(0, 3, GL_FLOAT, false, Float.BYTES * SIZE, 0); glEnableVertexAttribArray(0); + glVertexAttribPointer(1, 3, GL_FLOAT, false, Float.BYTES * SIZE, Float.BYTES * 3); + glEnableVertexAttribArray(1); + + glVertexAttribPointer(2, 3, GL_FLOAT, false, Float.BYTES * SIZE, Float.BYTES * 6); + glEnableVertexAttribArray(2); + loaded = true; } } + + public void render() { + GL33.glDrawArrays(GL33.GL_TRIANGLES, 0, getSize()); + } } \ No newline at end of file diff --git a/src/projectzombie/model/ModelEmpty.java b/src/projectzombie/model/ModelEmpty.java new file mode 100644 index 0000000..3bf8dbe --- /dev/null +++ b/src/projectzombie/model/ModelEmpty.java @@ -0,0 +1,32 @@ +package projectzombie.model; + +import gl_engine.texture.TextureRef3D; + +public class ModelEmpty extends Model +{ + @Override + protected TextureRef3D[] getTextures() { + return new TextureRef3D[0]; + } + + @Override + protected float[] getVerticies() { + return new float[0]; + } + + @Override + public void bind() {} + + @Override + public int getSize() { + return 0; + } + + @Override + public void render() {} + + @Override + public float[] getLoadedVerticies() { + return new float[0]; + } +} diff --git a/src/projectzombie/resources/Resource.java b/src/projectzombie/resources/Resource.java index 4079579..06fae45 100755 --- a/src/projectzombie/resources/Resource.java +++ b/src/projectzombie/resources/Resource.java @@ -17,6 +17,10 @@ public class Resource return "/resources/"+path; } + public String getPath() { + return filePath(path); + } + public Resource(String path) { // Set the specified data diff --git a/src/projectzombie/tiles/TileSand.java b/src/projectzombie/tiles/TileSand.java index 216c2f2..e9ab9ec 100755 --- a/src/projectzombie/tiles/TileSand.java +++ b/src/projectzombie/tiles/TileSand.java @@ -1,12 +1,14 @@ package projectzombie.tiles; import projectzombie.init.Models; +import projectzombie.model.Model; -public class TileSand extends TileFlat +public class TileSand extends Tile { - public TileSand() { - super(Models.TILE_SAND); + @Override + public Model getModel(byte meta) { + return Models.TILE_SAND; } } \ No newline at end of file diff --git a/src/projectzombie/tiles/TileStone.java b/src/projectzombie/tiles/TileStone.java index 7dfc131..d530b1d 100755 --- a/src/projectzombie/tiles/TileStone.java +++ b/src/projectzombie/tiles/TileStone.java @@ -1,12 +1,14 @@ package projectzombie.tiles; import projectzombie.init.Models; +import projectzombie.model.Model; -public class TileStone extends TileFlatFaded +public class TileStone extends Tile { - public TileStone() { - super(Models.TILE_STONE); + @Override + public Model getModel(byte meta) { + return Models.TILE_STONE; } } diff --git a/src/projectzombie/tiles/TileTree.java b/src/projectzombie/tiles/TileTree.java index 8d4ec29..597257f 100755 --- a/src/projectzombie/tiles/TileTree.java +++ b/src/projectzombie/tiles/TileTree.java @@ -1,16 +1,15 @@ package projectzombie.tiles; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.math.TileState; import gl_engine.vec.Vec2d; -public class TileTree extends TileVertical implements TileBulletBreakable +public class TileTree extends Tile implements TileBulletBreakable { public TileTree() { - super(Models.TILE_TREE, new Vec2d(1, 4)); // Set some settings - this.opaqueTile = true; this.tileSolid = true; this.tileHitbox = 0.3; } @@ -25,4 +24,9 @@ public class TileTree extends TileVertical implements TileBulletBreakable return 35; } + @Override + public Model getModel(byte meta) { + return Models.TILE_TREE; + } + } diff --git a/src/projectzombie/tiles/TileVoid.java b/src/projectzombie/tiles/TileVoid.java index 45c1f7c..0b78f64 100755 --- a/src/projectzombie/tiles/TileVoid.java +++ b/src/projectzombie/tiles/TileVoid.java @@ -1,5 +1,8 @@ package projectzombie.tiles; +import projectzombie.init.Models; +import projectzombie.model.Model; + public class TileVoid extends Tile { public TileVoid() { @@ -8,5 +11,10 @@ public class TileVoid extends Tile { this.tileSolid = false; this.tileWalkable = true; } + + @Override + public Model getModel(byte meta) { + return Models.EMPTY; + } } diff --git a/src/projectzombie/tiles/TileWall.java b/src/projectzombie/tiles/TileWall.java index 883e525..8c494eb 100755 --- a/src/projectzombie/tiles/TileWall.java +++ b/src/projectzombie/tiles/TileWall.java @@ -1,13 +1,13 @@ package projectzombie.tiles; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.math.TileState; -public class TileWall extends TileFlat +public class TileWall extends Tile { public TileWall() { - super(Models.TILE_WALL); this.tileWalkable = false; this.tileSolid = true; @@ -21,4 +21,9 @@ public class TileWall extends TileFlat return 1/2.0; } + @Override + public Model getModel(byte meta) { + return Models.TILE_WALL; + } + } diff --git a/src/projectzombie/tiles/TileWater.java b/src/projectzombie/tiles/TileWater.java index 050009d..e6b93bc 100755 --- a/src/projectzombie/tiles/TileWater.java +++ b/src/projectzombie/tiles/TileWater.java @@ -4,6 +4,7 @@ import projectzombie.display.Camera; import projectzombie.entity.Entity; import projectzombie.entity.particle.ParticleWater; import projectzombie.init.Models; +import projectzombie.model.Model; import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.TileState; import gl_engine.vec.Vec2d; @@ -11,24 +12,14 @@ import gl_engine.vec.Vec2i; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; -public class TileWater extends TileFlat +public class TileWater extends Tile { public TileWater() { - super(Models.TILE_WATER); this.slowness = 0.5; - this.rotates = true; this.unbreakable = true; } - @Override - public void render(Vec2d pos, Camera camera, TileState state) { - GlHelpers.pushMatrix(); - GlHelpers.translate3(0, 0, 0.001); - super.render(pos, camera, state); - GlHelpers.popMatrix(); - } - @Override public void onWalkedOn(Chunk chunk, Layer layer, Vec2i pos, Entity entity, TileState state) { @@ -40,5 +31,10 @@ public class TileWater extends TileFlat layer.spawnEntity(new ParticleWater(entity.pos.copy())); } } + + @Override + public Model getModel(byte meta) { + return Models.TILE_WATER; + } } diff --git a/src/projectzombie/tiles/TileWaterFlow.java b/src/projectzombie/tiles/TileWaterFlow.java deleted file mode 100755 index e3c0d93..0000000 --- a/src/projectzombie/tiles/TileWaterFlow.java +++ /dev/null @@ -1,26 +0,0 @@ -package projectzombie.tiles; - -import projectzombie.display.Camera; -import projectzombie.init.Models; -import projectzombie.util.gl.GlHelpers; -import projectzombie.util.math.TileState; -import gl_engine.vec.Vec2d; - -public class TileWaterFlow extends TileFlat -{ - - public TileWaterFlow() { - super(Models.TILE_WATER_FLOW); - - this.unbreakable = true; - } - - @Override - public void render(Vec2d pos, Camera camera, TileState state) { - GlHelpers.pushMatrix(); - GlHelpers.translate3(0, 0, 0.001); - super.render(pos, camera, state); - GlHelpers.popMatrix(); - } - -} diff --git a/src/projectzombie/world/chunk/Chunk.java b/src/projectzombie/world/chunk/Chunk.java index 75d1c2a..5116ec6 100755 --- a/src/projectzombie/world/chunk/Chunk.java +++ b/src/projectzombie/world/chunk/Chunk.java @@ -4,20 +4,25 @@ import java.util.ArrayList; import java.util.Random; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL33; import bdf.classes.IBdfClassManager; import bdf.types.BdfArray; import bdf.types.BdfNamedList; import bdf.types.BdfObject; +import projectzombie.Main; import projectzombie.display.Camera; import projectzombie.entity.Entity; import projectzombie.entity.EntityAlive; import projectzombie.entity.EntityKillWithParticles; import projectzombie.entity.particle.ParticleBreak; +import projectzombie.init.Models; import projectzombie.init.Tiles; +import projectzombie.model.Model; import projectzombie.tiles.Tile; import projectzombie.util.gl.GlHelpers; import gl_engine.MathHelpers; +import gl_engine.matrix.Matrix4; import projectzombie.util.math.TileState; import projectzombie.util.math.random.RandomHelpers; import gl_engine.range.Range2i; @@ -48,8 +53,21 @@ public class Chunk implements IBdfClassManager public ArrayList entities = new ArrayList(); private Layer layer; public Vec2i c_pos; - public boolean dirty; - public boolean light_dirty; + private boolean dirty; + private boolean light_dirty; + + public boolean isDirty() + { + if(entities.size() > 0) { + return true; + } + + return dirty; + } + + public void clearDirty() { + dirty = false; + } @Override public void BdfClassLoad(BdfObject bdf) @@ -152,66 +170,31 @@ public class Chunk implements IBdfClassManager public void render(Camera camera) { - // Loop over all the tiles - for(int i=0;i getNearbyEntities(Vec2d pos, double distance) diff --git a/src/projectzombie/world/chunk/ChunkEmpty.java b/src/projectzombie/world/chunk/ChunkEmpty.java index 90c0912..b4fabdb 100755 --- a/src/projectzombie/world/chunk/ChunkEmpty.java +++ b/src/projectzombie/world/chunk/ChunkEmpty.java @@ -155,4 +155,13 @@ public class ChunkEmpty extends Chunk @Override public void setDaylightLevel(double light, Vec2i pos) { } + + @Override + public void clearDirty() { + } + + @Override + public boolean isDirty() { + return false; + } } diff --git a/src/projectzombie/world/layer/Layer.java b/src/projectzombie/world/layer/Layer.java index 4a783d7..f429167 100755 --- a/src/projectzombie/world/layer/Layer.java +++ b/src/projectzombie/world/layer/Layer.java @@ -222,7 +222,7 @@ public class Layer implements IBdfClassManager Chunk chunk = new Chunk(this, pos, rand); chunks.set(pos, chunk); layergen.generateChunk(chunk, this, new Random(cseed), pos); - chunk.dirty = false; + chunk.clearDirty(); } } @@ -230,7 +230,7 @@ public class Layer implements IBdfClassManager { // Store the chunk if its a dirty chunk Chunk chunk = chunks.get(pos); - if(chunk.dirty) { + if(chunk.isDirty()) { dirty_chunks.set(pos, chunk); } @@ -321,7 +321,7 @@ public class Layer implements IBdfClassManager for(Map2DElement chunk : chunks) { if(dirty_chunks.contains(chunk.pos)) continue; - if(!chunk.o.dirty) + if(!chunk.o.isDirty()) continue; BdfNamedList chunk_nl = new BdfNamedList(); diff --git a/src/resources/shader/environmentRenderer.vsh b/src/resources/shader/environmentRenderer.vsh index 3db5acb..1db5b81 100644 --- a/src/resources/shader/environmentRenderer.vsh +++ b/src/resources/shader/environmentRenderer.vsh @@ -1,46 +1,28 @@ #version 330 -layout (location = 0) in float[9] vertices; +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aTex; +layout (location = 2) in vec3 aFlags; out vec3 pTexture; uniform mat4 projection; uniform mat4 model; uniform mat4 camera; -uniform float cameraAngle; - -mat4 rotate(float angle, float x, float y, float z) -{ - mat4 result = mat4(1); - - float csin = sin(angle); - float ccos = cos(angle); - float iccos = 1 - ccos; - - result[0][0] = ccos + x * x * iccos; - result[0][1] = x * y * iccos - z * csin; - result[0][2] = x * z * iccos + y * csin; - result[1][0] = y * x * iccos + z * csin; - result[1][1] = ccos + y * y * iccos; - result[1][2] = y * z * iccos - x * csin; - result[2][0] = z * x * iccos - y * csin; - result[2][1] = z * y * iccos + x * csin; - result[2][2] = ccos + z * z * iccos; - result[3][3] = 1; - - return result; -} +uniform mat4 rotated; void main() { - int type = int(vertices[8]); + int type = int(aFlags.z); - mat4 do_rotation = rotate(cameraAngle, 0, 1, 0); + float animate_count = aFlags.x; + float animate_speed = aFlags.y; + + mat4 do_rotation = rotated; mat4 no_rotation = mat4(1); - gl_Position = vec4(vertices[0], vertices[1], vertices[2], 1) * - (type == 1 ? do_rotation : no_rotation) * model * camera * projection; + gl_Position = vec4(aPos, 1) * (type == 1 ? do_rotation : no_rotation) * model * camera * projection; - pTexture = vec3(vertices[3], vertices[4], vertices[5]); + pTexture = vec3(aTex.x, aTex.y, aTex.z); } \ No newline at end of file