diff --git a/.classpath b/.classpath
index 9b934e1..344bafb 100755
--- a/.classpath
+++ b/.classpath
@@ -3,7 +3,6 @@
-
@@ -42,5 +41,6 @@
+
diff --git a/src/projectzombie/display/DisplayRender.java b/src/projectzombie/display/DisplayRender.java
index 2a0a8ee..8c9d649 100755
--- a/src/projectzombie/display/DisplayRender.java
+++ b/src/projectzombie/display/DisplayRender.java
@@ -31,8 +31,6 @@ public class DisplayRender
GL33.glUniform3f(Main.window.glsl_day_low, (float)range.min.x, (float)range.min.y, (float)range.min.z);
GL33.glUniform3f(Main.window.glsl_day_high, (float)range.max.x, (float)range.max.y, (float)range.max.z);
- GL33.glUniform3f(Main.window.glsl_src_low, 0, 0, 0);
- GL33.glUniform3f(Main.window.glsl_src_high, 1, 1, 1);
if(Main.menu.doGameRender)
{
@@ -44,13 +42,14 @@ public class DisplayRender
// Create the projection matrix
Matrix4 projection = Matrix4.projection((double)w / (double)h, 45, 0.1, 1000);
+ projection = Matrix4.multiply(camera.getMatrix(), projection);
+
Matrix4 rotated = Matrix4.rotate(-camera.angle, 0, 1, 0);
// Process all the light sources
//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());
GL33.glUniform1i(Main.window.glsl_time, (int)((System.currentTimeMillis() / 10) % 1000));
diff --git a/src/projectzombie/display/DisplayRenderUI.java b/src/projectzombie/display/DisplayRenderUI.java
index df35041..0ade87b 100755
--- a/src/projectzombie/display/DisplayRenderUI.java
+++ b/src/projectzombie/display/DisplayRenderUI.java
@@ -92,11 +92,8 @@ public class DisplayRenderUI
GL33.glUniform3f(Main.window.glsl_day_low, 1, 1, 1);
GL33.glUniform3f(Main.window.glsl_day_high, 1, 1, 1);
- GL33.glUniform3f(Main.window.glsl_src_low, 1, 1, 1);
- GL33.glUniform3f(Main.window.glsl_src_high, 1, 1, 1);
GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, projection.getArray());
- GL33.glUniformMatrix4fv(Main.window.glsl_camera, true, camera.getArray());
GL33.glDisable(GL33.GL_DEPTH_TEST);
diff --git a/src/projectzombie/display/DisplayWindow.java b/src/projectzombie/display/DisplayWindow.java
index 2ff9ac9..39dc5df 100755
--- a/src/projectzombie/display/DisplayWindow.java
+++ b/src/projectzombie/display/DisplayWindow.java
@@ -36,21 +36,16 @@ public class DisplayWindow implements IMainloopTask
public static int fps = 0;
public GraphicsShader environmentRenderer;
- private GraphicsShader lightmapRenderer;
- private int lightmapVao;
public int glsl_color;
public int glsl_tex_cut;
public int glsl_model;
public int glsl_projection;
public int glsl_rotated;
- public int glsl_camera;
public int glsl_time;
public int glsl_day_low;
public int glsl_day_high;
- public int glsl_src_low;
- public int glsl_src_high;
public int glsl_lightmap_offset;
public int glsl_lightmap_size;
@@ -106,6 +101,8 @@ public class DisplayWindow implements IMainloopTask
// Make the cursor invisible
GLFW.glfwSetInputMode(this.window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
+ GLFW.glfwSwapInterval(0);
+
// Show the window
//GLFW.glfwShowWindow(this.window);
@@ -113,7 +110,6 @@ public class DisplayWindow implements IMainloopTask
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");
glsl_time = GL33.glGetUniformLocation(environmentRenderer.program, "time");
@@ -122,8 +118,6 @@ public class DisplayWindow implements IMainloopTask
glsl_day_low = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_day_low");
glsl_day_high = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_day_high");
- glsl_src_low = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_src_low");
- glsl_src_high = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_src_high");
glsl_lightmap_offset = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap_offset");
glsl_lightmap_size = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap_size");
@@ -131,31 +125,8 @@ public class DisplayWindow implements IMainloopTask
int glsl_atlas = GL33.glGetUniformLocation(environmentRenderer.program, "atlas");
int glsl_lightmap = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap");
- GL33.glUniform1ui(glsl_atlas, 1);
- GL33.glUniform1ui(glsl_lightmap, 0);
-
- lightmapRenderer = new GraphicsShader("/resources/shader/lightmapRenderer");
- lightmapRenderer.use();
-
- lightmapVao = GL33.glGenVertexArrays();
- GL33.glBindVertexArray(lightmapVao);
-
- int vbo = GL33.glGenBuffers();
- GL33.glBindBuffer(GL33.GL_ARRAY_BUFFER, vbo);
- GL33.glBufferData(GL33.GL_ARRAY_BUFFER, new float[] {
-
- -0.95f, -0.95f,
- -0.65f, -0.95f,
- -0.65f, -0.65f,
-
- -0.95f, -0.95f,
- -0.95f, -0.65f,
- -0.65f, -0.65f,
-
- }, GL33.GL_STATIC_DRAW);
-
- glVertexAttribPointer(0, 2, GL_FLOAT, false, Float.BYTES * 2, 0);
- glEnableVertexAttribArray(0);
+ GL33.glUniform1i(glsl_atlas, 0);
+ GL33.glUniform1i(glsl_lightmap, 1);
}
public void render()
@@ -168,30 +139,19 @@ public class DisplayWindow implements IMainloopTask
height = h[0];
environmentRenderer.use();
+ TileLighting.updateLighting();
// Bind the texture atlas
- GL33.glActiveTexture(GL33.GL_TEXTURE1);
+ GL33.glActiveTexture(GL33.GL_TEXTURE0);
Resources.ATLAS.bind();
// Bind the lightmap
- GL33.glActiveTexture(GL33.GL_TEXTURE0);
+ GL33.glActiveTexture(GL33.GL_TEXTURE1);
GL33.glBindTexture(GL33.GL_TEXTURE_2D, TileLighting.lightmap);
// Render everything
DisplayRender.render(w[0], h[0]);
- // Check if the matrix count is ok
- //GlHelpers.checkMatrixCount();
-
- lightmapRenderer.use();
-
- GL33.glActiveTexture(GL33.GL_TEXTURE0);
-
- //GL33.glDisable(GL33.GL_DEPTH_TEST);
-
- GL33.glBindVertexArray(lightmapVao);
- GL33.glDrawArrays(GL33.GL_TRIANGLES, 0, 6);
-
// Swap the framebuffers and poll events
GLFW.glfwSwapBuffers(window);
GLFW.glfwPollEvents();
diff --git a/src/projectzombie/display/lighting/TileLighting.java b/src/projectzombie/display/lighting/TileLighting.java
index 323a856..393519c 100755
--- a/src/projectzombie/display/lighting/TileLighting.java
+++ b/src/projectzombie/display/lighting/TileLighting.java
@@ -8,9 +8,11 @@ import org.lwjgl.opengl.GL33;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.MathHelpers;
+import gl_engine.range.Range2i;
import gl_engine.vec.Vec2i;
import projectzombie.Main;
import projectzombie.display.Camera;
+import projectzombie.entity.Entity;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.util.math.TileState;
import projectzombie.world.chunk.Chunk;
@@ -19,29 +21,31 @@ import projectzombie.world.layer.Layer;
public class TileLighting
{
- private static class LightingTask {
- float[] b;
+ private static class Lighting {
+ float[] p;
int w, h;
int x, y;
+
+ private int getID(int x, int y) {
+ return (x + y * w) * 3 + 1;
+ }
}
private static boolean lighting_dirty = false;
public static int lightmap;
- private static LightingTask task;
+ private static Lighting lighting;
public static void setDirty() {
lighting_dirty = true;
}
- public synchronized static LightingTask getTask() {
- LightingTask t = task;
- task = null;
- return t;
+ private synchronized static Lighting getLighting() {
+ return lighting;
}
- public synchronized static void setTask(LightingTask task) {
- TileLighting.task = task;
+ private synchronized static void setLighting(Lighting lighting) {
+ TileLighting.lighting = lighting;
}
public TileLighting() {
@@ -50,21 +54,6 @@ public class TileLighting
public static void update()
{
- {
- LightingTask task = getTask();
-
- if(task != null)
- {
- GL33.glBindTexture(GL33.GL_TEXTURE_2D, lightmap);
- GL33.glTexImage2D(GL33.GL_TEXTURE_2D, 0, GL33.GL_RGB, task.w, task.h, 0, GL33.GL_RGB, GL33.GL_FLOAT, task.b);
- GL33.glGenerateMipmap(GL33.GL_TEXTURE_2D);
-
- Main.window.environmentRenderer.use();
- GL33.glUniform2f(Main.window.glsl_lightmap_offset, task.x * 16 - 1, task.y * 16 - 1);
- GL33.glUniform2f(Main.window.glsl_lightmap_size, task.w, task.h);
- }
- }
-
if(Camera.camera == null) return;
if(!ChunkEventHandler.loaded) return;
Layer layer = Main.world.getLayer();
@@ -140,6 +129,125 @@ public class TileLighting
MathHelpers.floor(player.pos.y / 16) - Chunk.RENDER_DISTANCE);
}
+ private static void calculateLight(Layer layer, Lighting lighting, float[] pixels, int x, int y, float level, boolean ignore)
+ {
+ if(x < 0 || y < 0 || x >= lighting.w || y >= lighting.h) {
+ return;
+ }
+
+ int id = lighting.getID(x, y);
+ float level_current = pixels[id];
+
+ Vec2i tpos = new Vec2i(x + lighting.x * 16, y + lighting.y * 16);
+ int tid = tpos.getId(Chunk.CHUNK_SIZE);
+
+ if(level_current >= level && !ignore) {
+ return;
+ }
+
+ pixels[id] = level;
+
+ Chunk chunk = layer.getChunk(tpos);
+ TileState ft = chunk.getFrontTile(tid);
+ TileState bt = chunk.getBackTile(tid);
+
+ float dissipation = (float)Math.max(ft.tile.getLightDissipation(ft), bt.tile.getLightDissipation(bt));
+ float level_next = level - dissipation;
+
+ int[] adjacent = new int[] {
+ x+1, y+0,
+ x+0, y+1,
+ x-1, y-0,
+ x-0, y-1,
+ };
+
+ for(int i=0;i<8;i+=2) {
+ calculateLight(layer, lighting, pixels, adjacent[i], adjacent[i+1], level_next, false);
+ }
+ }
+
+ public static void updateLighting()
+ {
+ Lighting lighting = getLighting();
+
+ // Copy the pixels
+ float[] pixels = new float[lighting.p.length];
+ for(int i=0;i 1) {
+ level = 1;
+ }
+
+ Vec2i lpos = Main.player.pos.toInt().subtract(new Vec2i(lighting.x * 16, lighting.y * 16));
+
+ calculateLight(layer, lighting, pixels, lpos.x, lpos.y, (float)level, true);
+ }
+
+ for(int cx=-Chunk.RENDER_DISTANCE;cx<=Chunk.RENDER_DISTANCE;cx++) {
+ for(int cy=-Chunk.RENDER_DISTANCE;cy<=Chunk.RENDER_DISTANCE;cy++)
+ {
+ Vec2i cpos = new Vec2i(
+ cx + MathHelpers.floor(Main.player.pos.x / 16),
+ cy + MathHelpers.floor(Main.player.pos.y / 16));
+
+ Chunk chunk = layer.chunks.get(cpos);
+
+ for(Entity entity : chunk.entities)
+ {
+ if(!entity.emitsLight) {
+ continue;
+ }
+
+ double level = entity.getLightLevel();
+
+ if(level <= 0) {
+ continue;
+ }
+
+ if(level > 1) {
+ level = 1;
+ }
+
+ Vec2i lpos = entity.pos.toInt().subtract(new Vec2i(lighting.x * 16, lighting.y * 16));
+
+ calculateLight(layer, lighting, pixels, lpos.x, lpos.y, (float)level, true);
+ }
+ }
+ }
+
+ // Update the texture
+ GL33.glBindTexture(GL33.GL_TEXTURE_2D, lightmap);
+ GL33.glTexImage2D(GL33.GL_TEXTURE_2D, 0, GL33.GL_RGB, lighting.w, lighting.h, 0, GL33.GL_RGB, GL33.GL_FLOAT, pixels);
+ GL33.glGenerateMipmap(GL33.GL_TEXTURE_2D);
+
+ // Set the texture location data
+ GL33.glUniform2f(Main.window.glsl_lightmap_offset, lighting.x * 16 - 0.5f, lighting.y * 16 - 0.5f);
+ GL33.glUniform2f(Main.window.glsl_lightmap_size, lighting.w, lighting.h);
+ }
+
+ public static void clearLighting()
+ {
+ Lighting lighting = new Lighting();
+ lighting.p = new float[3];
+ lighting.w = 1;
+ lighting.h = 1;
+ lighting.x = 0;
+ lighting.y = 0;
+
+ setLighting(lighting);
+ }
+
public static void updateLighting(BdfObject bdf)
{
BdfNamedList nl = bdf.getNamedList();
@@ -156,13 +264,13 @@ public class TileLighting
pixels[i*3+1] = light[i*2+1];
}
- LightingTask task = new LightingTask();
- task.w = width;
- task.h = height;
- task.b = pixels;
- task.x = x;
- task.y = y;
+ Lighting lighting = new Lighting();
+ lighting.p = pixels;
+ lighting.w = width;
+ lighting.h = height;
+ lighting.x = x;
+ lighting.y = y;
- setTask(task);
+ setLighting(lighting);
}
}
diff --git a/src/projectzombie/entity/EntityFlare.java b/src/projectzombie/entity/EntityFlare.java
index 3dd3249..801259f 100755
--- a/src/projectzombie/entity/EntityFlare.java
+++ b/src/projectzombie/entity/EntityFlare.java
@@ -19,12 +19,26 @@ public class EntityFlare extends EntityTnt
public EntityFlare(Vec2d pos, double angle) {
super(pos, angle, 0, 0);
- this.explode_time = 1000;
+ this.explode_time = 2000;
+ this.emitsLight = true;
}
@Override
- public double getLightLevel() {
- return getLightWithHeight(1 - (this.pos.y * (1/12.0))) * ( rand.nextDouble() / 10.0 + 0.9 );
+ public double getLightLevel()
+ {
+ if(this.explode_time > 1950) {
+ return 0;
+ }
+
+ if(this.explode_time > 1900) {
+ return (1950 - this.explode_time) / 50.0;
+ }
+
+ if(this.explode_time < 200) {
+ return this.explode_time / 200.0;
+ }
+
+ return 1;
}
@Override
diff --git a/src/projectzombie/entity/EntityTnt.java b/src/projectzombie/entity/EntityTnt.java
index 31014d1..6043c1f 100755
--- a/src/projectzombie/entity/EntityTnt.java
+++ b/src/projectzombie/entity/EntityTnt.java
@@ -80,7 +80,6 @@ public class EntityTnt extends Entity implements EntityHeight, EntityHoldsEntiti
this.goThroughSolid = false;
this.explode_damage = explode_damage;
this.smoke_particles = new ParticleSpark[100];
- this.emitsLight = true;
// Set to 2.5 seconds
this.explode_time = 250;
@@ -154,11 +153,6 @@ public class EntityTnt extends Entity implements EntityHeight, EntityHoldsEntiti
smoke_particles[dead_particle] = new ParticleSpark(new Vec3d(pos, height + 1));
}
- @Override
- public double getLightLevel() {
- return getLightWithHeight(1 - (this.height * (1/12.0))) * ( rand.nextDouble() / 10.0 + 0.9 );
- }
-
@Override
protected void moveAwayFromSolidEntities(Layer layer) {
}
diff --git a/src/projectzombie/entity/EntityZombie.java b/src/projectzombie/entity/EntityZombie.java
index 85abd09..741c77e 100755
--- a/src/projectzombie/entity/EntityZombie.java
+++ b/src/projectzombie/entity/EntityZombie.java
@@ -111,54 +111,59 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP
walk_scan_cooldown -= 1;
}
- if(
- (walk_direction != null && pos.toInt().equal(walk_direction) &&
- pos.squareDistance(Main.player.pos) > 2) ||
- walk_scan_cooldown < 1 || walking_for > 200)
+ double player_distance = pos.squareDistance(Main.player.pos);
+
+ // Only pathfind if in range of the player
+ if(player_distance < 16)
{
- AStar astar = new AStar(pos.toInt(), 16, new AStarSearcher(layer, crossUnWalkable));
- Vec2i path[] = astar.getPath(Main.player.pos.toInt());
-
- walk_scan_cooldown = 100;
- walking_for = 0;
-
- if(path != null && path.length > 1) {
- walk_direction = path[1];
- } else {
- walk_direction = Main.player.pos.toInt();
+ if(
+ (walk_direction != null && pos.toInt().equal(walk_direction) &&
+ player_distance > 2) || walk_scan_cooldown < 1 || walking_for > 200)
+ {
+ AStar astar = new AStar(pos.toInt(), 16, new AStarSearcher(layer, crossUnWalkable));
+ Vec2i path[] = astar.getPath(Main.player.pos.toInt());
+
+ walk_scan_cooldown = 100;
+ walking_for = 0;
+
+ if(path != null && path.length > 1) {
+ walk_direction = path[1];
+ } else {
+ walk_direction = Main.player.pos.toInt();
+ }
+
+ can_see_player = (path != null);
}
- can_see_player = (path != null);
- }
-
- // Walk towards the player
- if(walk_direction != null)
- {
- double angle = Math.toDegrees(Math.atan2(
- walk_direction.x - (this.pos.x - 0.5) + noise_target_x.eval(time, pos.x/10, pos.y/10),
- walk_direction.y - (this.pos.y - 0.5) + noise_target_y.eval(time, pos.x/10, pos.y/10)));
- this.moveTowards(angle);
-
- walking_for += 1;
- }
-
- if(can_see_player && noise_gun_fire.eval(time, 0) > 0 && !Main.player.dead && !Main.player.in_animation)
- {
- // Get the angle between the player and the zombie
- double angle_fire = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y);
-
- gun_interval += 1;
- gun_interval %= 10;
-
- if(gun_interval == 0)
+ // Walk towards the player
+ if(walk_direction != null)
{
- // Aim the gun at the player
- double angle_gun = Math.toDegrees(angle_fire) + 180;
- angle_gun += noise_gun_angle.eval(time, 0)*20;
+ double angle = Math.toDegrees(Math.atan2(
+ walk_direction.x - (this.pos.x - 0.5) + noise_target_x.eval(time, pos.x/10, pos.y/10),
+ walk_direction.y - (this.pos.y - 0.5) + noise_target_y.eval(time, pos.x/10, pos.y/10)));
+ this.moveTowards(angle);
- // Fire the gun
- int d = (int)(1 + gun_level / 5.0);
- layer.spawnEntity(new EntityBullet(pos.copy(), this, angle_gun, 20*d*d, 60));
+ walking_for += 1;
+ }
+
+ if(can_see_player && noise_gun_fire.eval(time, 0) > 0 && !Main.player.dead && !Main.player.in_animation)
+ {
+ // Get the angle between the player and the zombie
+ double angle_fire = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y);
+
+ gun_interval += 1;
+ gun_interval %= 10;
+
+ if(gun_interval == 0)
+ {
+ // Aim the gun at the player
+ double angle_gun = Math.toDegrees(angle_fire) + 180;
+ angle_gun += noise_gun_angle.eval(time, 0)*20;
+
+ // Fire the gun
+ int d = (int)(1 + gun_level / 5.0);
+ layer.spawnEntity(new EntityBullet(pos.copy(), this, angle_gun, 20*d*d, 60));
+ }
}
}
diff --git a/src/projectzombie/entity/player/EntityPlayer.java b/src/projectzombie/entity/player/EntityPlayer.java
index 21348b3..b8ad4c7 100755
--- a/src/projectzombie/entity/player/EntityPlayer.java
+++ b/src/projectzombie/entity/player/EntityPlayer.java
@@ -107,10 +107,6 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
// Create the inventory
inventory = new Inventory(10);
-
- inventory.addItem(new ItemStack(Items.SPAWN_ZOMBIE, 99, (short)0));
- inventory.addItem(new ItemStack(Items.AMMO, 99, (short)0));
- inventory.addItem(new ItemStack(Items.LANTERN, 99, (short)0));
}
@Override
diff --git a/src/projectzombie/menu/MenuDeath.java b/src/projectzombie/menu/MenuDeath.java
index fbe6dbb..456de90 100755
--- a/src/projectzombie/menu/MenuDeath.java
+++ b/src/projectzombie/menu/MenuDeath.java
@@ -22,7 +22,6 @@ public class MenuDeath extends Menu
this.input = new InputGUI(this.gui);
gui.add(new OverlayBackground());
- gui.add(new LabelPause("You were slain"));
ButtonGroup group = new ButtonGroupPause();
diff --git a/src/projectzombie/menu/MenuGamePause.java b/src/projectzombie/menu/MenuGamePause.java
index cbfc318..5654634 100755
--- a/src/projectzombie/menu/MenuGamePause.java
+++ b/src/projectzombie/menu/MenuGamePause.java
@@ -56,7 +56,7 @@ public class MenuGamePause extends Menu
System.out.println("Time for BdfClassSave: " + (cur - now));
now = cur;
- System.out.println("Size on file: " + bdf.serialize().length());
+ System.out.println("Size on file: " + bdf.serialize().size());
//System.out.println(bdf.serializeHumanReadable());
try {
diff --git a/src/projectzombie/model/Model.java b/src/projectzombie/model/Model.java
index b82c931..d198a87 100644
--- a/src/projectzombie/model/Model.java
+++ b/src/projectzombie/model/Model.java
@@ -20,14 +20,16 @@ import projectzombie.Main;
public abstract class Model
{
- int vao, vbo;
+ int vao, vbo, ibo;
boolean loaded = false;
public static final int SIZE = 14;
// px, py, pz, tx, ty
+ public abstract int[] getIndicies();
public abstract float[] getVerticies();
public abstract TextureRef3D[] getTextures();
public abstract double getHeight();
+ public abstract int getIndexSize();
public abstract int getSize();
private static Model bound = null;
@@ -38,11 +40,12 @@ public abstract class Model
return;
}
+ int[] indicies = this.getIndicies();
float[] verticies = this.getVerticies();
TextureRef3D[] refs = this.getTextures();
- if(verticies.length % SIZE != 0 || refs.length * 3 != verticies.length / SIZE) {
- System.err.println("Invalid model");
+ if(verticies.length % SIZE != 0 || refs.length * SIZE != verticies.length) {
+ System.err.println("Invalid model: " + verticies.length + ", " + refs.length + ", " + indicies.length);
System.exit(1);
return;
}
@@ -51,7 +54,7 @@ public abstract class Model
double k = 0.001;
for(int i=0;i 0.95)
+ if(rand.nextDouble() > 0.9)
{
Entity zombie = new EntityZombie(new Vec2d(
RandomHelpers.randrange(rand, (int)Main.player.pos.x - 128, (int)Main.player.pos.x + 128),
RandomHelpers.randrange(rand, (int)Main.player.pos.y - 128, (int)Main.player.pos.y + 128)));
- if(layer.getBackTile(new Vec2i((int)zombie.pos.x,
- (int)zombie.pos.y)).tile == getTileDestroyed().tile &&
- zombie.pos.squareDistance(Main.player.pos) > 32)
+ boolean exists = false;
+
+ for(Entity e : layer.getChunk(zombie.pos).entities) {
+ if(e.getClass() == zombie.getClass()) {
+ exists = true;
+ break;
+ }
+ }
+
+ if(
+ !exists && layer.getBackTile(new Vec2i((int)zombie.pos.x,
+ (int)zombie.pos.y)).tile == getTileDestroyed().tile &&
+ zombie.pos.squareDistance(Main.player.pos) > 32
+ ) {
layer.spawnEntity(zombie);
+ }
}
}
diff --git a/src/projectzombie/world/layer/layergen/LayerGenEarth.java b/src/projectzombie/world/layer/layergen/LayerGenEarth.java
index 38e2318..da27763 100755
--- a/src/projectzombie/world/layer/layergen/LayerGenEarth.java
+++ b/src/projectzombie/world/layer/layergen/LayerGenEarth.java
@@ -83,8 +83,18 @@ public class LayerGenEarth extends LayerGen
RandomHelpers.randrange(rand, (int)Main.player.pos.x - 128, (int)Main.player.pos.x + 128),
RandomHelpers.randrange(rand, (int)Main.player.pos.y - 128, (int)Main.player.pos.y + 128)));
- if(zombie.pos.squareDistance(Main.player.pos) > 64)
+ boolean exists = false;
+
+ for(Entity e : layer.getChunk(zombie.pos).entities) {
+ if(e.getClass() == zombie.getClass()) {
+ exists = true;
+ break;
+ }
+ }
+
+ if(!exists && zombie.pos.squareDistance(Main.player.pos) > 64) {
layer.spawnEntity(zombie);
+ }
}
}
diff --git a/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java b/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java
index 48f1b9d..29fecaf 100755
--- a/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java
+++ b/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java
@@ -119,21 +119,34 @@ public class LayerGenLavaCaves extends LayerGen
@Override
public void spawnEntities(Layer layer, Random rand)
{
- if(rand.nextDouble() > 0.98)
+ if(rand.nextDouble() > 0.9)
{
Entity zombie = new EntityZombieArmored(new Vec2d(
RandomHelpers.randrange(rand, (int)Main.player.pos.x - 128, (int)Main.player.pos.x + 128),
RandomHelpers.randrange(rand, (int)Main.player.pos.y - 128, (int)Main.player.pos.y + 128)));
- TileState tsb = layer.getBackTile(new Vec2i((int)zombie.pos.x,
- (int)zombie.pos.y));
- TileState tsf = layer.getFrontTile(new Vec2i((int)zombie.pos.x,
- (int)zombie.pos.y));
- if(
- tsb.tile == getTileDestroyed().tile &&
- tsf.tile == Tiles.VOID &&
- zombie.pos.squareDistance(Main.player.pos) > 32) {
- layer.spawnEntity(zombie);
+ boolean exists = false;
+
+ for(Entity e : layer.getChunk(zombie.pos).entities) {
+ if(e.getClass() == zombie.getClass()) {
+ exists = true;
+ break;
+ }
+ }
+
+ if(!exists)
+ {
+ TileState tsb = layer.getBackTile(new Vec2i((int)zombie.pos.x,
+ (int)zombie.pos.y));
+ TileState tsf = layer.getFrontTile(new Vec2i((int)zombie.pos.x,
+ (int)zombie.pos.y));
+
+ if(
+ tsb.tile == getTileDestroyed().tile &&
+ tsf.tile == Tiles.VOID &&
+ zombie.pos.squareDistance(Main.player.pos) > 32) {
+ layer.spawnEntity(zombie);
+ }
}
}
}
diff --git a/src/resources/shader/environmentRenderer.fsh b/src/resources/shader/environmentRenderer.fsh
index 707981f..6064cbc 100644
--- a/src/resources/shader/environmentRenderer.fsh
+++ b/src/resources/shader/environmentRenderer.fsh
@@ -2,16 +2,46 @@
in vec3 pPos;
in vec3 pTexture;
-in vec3 pLighting;
+in vec3 pLightMapPos;
+
out vec4 FragColor;
uniform sampler3D atlas;
+uniform sampler2D lightmap;
+
+uniform vec3 lighting_day_low;
+uniform vec3 lighting_day_high;
+
+uniform vec2 lightmap_offset;
+uniform vec2 lightmap_size;
+
uniform vec2 tex_cut;
uniform vec4 color;
+float map(float x, float in_min, float in_max, float out_min, float out_max) {
+ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
+}
+
+vec3 mapVec(float x, float in_min, float in_max, vec3 out_min, vec3 out_max) {
+ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
+}
+
+vec3 biggest(vec3 a, vec3 b) {
+ return vec3(a.x > b.x ? a.x : b.x,
+ a.y > b.y ? a.y : b.y,
+ a.z > b.z ? a.z : b.z);
+}
+
void main()
{
- FragColor = texture(atlas, pTexture) * color * vec4(pLighting, 1);
+ vec4 light = texture(lightmap, vec2(
+ map(pLightMapPos.x, lightmap_offset.x, lightmap_offset.x + lightmap_size.x, 0, 1),
+ map(pLightMapPos.z, lightmap_offset.y, lightmap_offset.y + lightmap_size.y, 0, 1)));
+
+ vec3 light_day = mapVec(light.r, 0, 1, lighting_day_low, lighting_day_high);
+ vec3 light_src = vec3(1, 1, 1) * (light.g - abs(pLightMapPos.y) * 0.1);
+
+ FragColor = texture(atlas, pTexture) * color * vec4(biggest(light_day, light_src), 1);
discard(FragColor.a == 0 || (pPos.x > tex_cut.y && tex_cut.x > 0.5));
}
\ No newline at end of file
diff --git a/src/resources/shader/environmentRenderer.vsh b/src/resources/shader/environmentRenderer.vsh
index 936b80e..0809d02 100644
--- a/src/resources/shader/environmentRenderer.vsh
+++ b/src/resources/shader/environmentRenderer.vsh
@@ -6,37 +6,20 @@ layout (location = 2) in vec2 aTexY;
layout (location = 3) in vec3 aChunkOffset;
layout (location = 4) in vec3 aFlags;
+out vec3 pLightMapPos;
out vec3 pLighting;
out vec3 pTexture;
out vec3 pPos;
-uniform sampler2D lightmap;
uniform mat4 projection;
uniform mat4 model;
-uniform mat4 camera;
uniform mat4 rotated;
uniform int time;
-uniform vec3 lighting_day_low;
-uniform vec3 lighting_day_high;
-
-uniform vec2 lightmap_offset;
-uniform vec2 lightmap_size;
-
float map(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
-vec3 mapVec(float x, float in_min, float in_max, vec3 out_min, vec3 out_max) {
- return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
-}
-
-vec3 biggest(vec3 a, vec3 b) {
- return vec3(a.x > b.x ? a.x : b.x,
- a.y > b.y ? a.y : b.y,
- a.z > b.z ? a.z : b.z);
-}
-
mat4 translate(vec3 vec)
{
mat4 result = mat4(1);
@@ -48,6 +31,16 @@ mat4 translate(vec3 vec)
return result;
}
+vec3 mapVec(float x, float in_min, float in_max, vec3 out_min, vec3 out_max) {
+ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
+}
+
+vec3 biggest(vec3 a, vec3 b) {
+ return vec3(a.x > b.x ? a.x : b.x,
+ a.y > b.y ? a.y : b.y,
+ a.z > b.z ? a.z : b.z);
+}
+
float getTexY()
{
float animate_count = aFlags.x;
@@ -74,17 +67,9 @@ void main()
vec4 pos = vec4(aPos, 1) * (mod(type, 2) == 1 ? do_rotation : no_rotation) *
translate(aChunkOffset) * model;
- gl_Position = pos * camera * projection;
+ gl_Position = pos * projection;
+ pLightMapPos = pos.xyz;
pTexture = vec3(aTex.x, getTexY(), aTex.z);
pPos = aPos;
-
- vec4 light = texture(lightmap, vec2(
- map(floor(pos.x), lightmap_offset.x, lightmap_offset.x + lightmap_size.x, 0, 1),
- map(floor(pos.z), lightmap_offset.y, lightmap_offset.y + lightmap_size.y, 0, 1)));
-
- vec3 light_day = mapVec(light.r, 0, 1, lighting_day_low, lighting_day_high);
- vec3 light_src = vec3(1, 1, 1) * light.g;
-
- pLighting = biggest(light_day, light_src);
}
\ No newline at end of file
diff --git a/src/resources/shader/lightmapRenderer.vsh b/src/resources/shader/lightmapRenderer.vsh
index 2337d53..226a281 100644
--- a/src/resources/shader/lightmapRenderer.vsh
+++ b/src/resources/shader/lightmapRenderer.vsh
@@ -1,11 +1,12 @@
#version 330
layout (location = 0) in vec2 aPos;
+layout (location = 1) in vec2 aTex;
out vec2 TexCoord;
void main()
{
gl_Position = vec4(aPos, 0, 1);
- TexCoord = aPos;
+ TexCoord = aTex;
}
\ No newline at end of file
diff --git a/worker.jar b/worker.jar
index 74efdd4..fbd1490 100644
Binary files a/worker.jar and b/worker.jar differ