Updated the math library to use faster math functions, started working
on biomes and temperature
This commit is contained in:
parent
a0d6d87dcf
commit
321d07ceb6
|
|
@ -3,6 +3,7 @@ package projectzombie;
|
|||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import gl_engine.MathHelpers;
|
||||
import mainloop.manager.MainloopManager;
|
||||
import projectzombie.audio.AudioEngine;
|
||||
import projectzombie.audio.AudioSources;
|
||||
|
|
@ -62,6 +63,9 @@ public class Main
|
|||
|
||||
public static void main(String[] args) throws IOException
|
||||
{
|
||||
// Initialize math
|
||||
MathHelpers.init();
|
||||
|
||||
worker = new Worker();
|
||||
worker.start();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package projectzombie.display.lighting;
|
||||
package projectzombie.display;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL33;
|
||||
|
||||
import bdf.types.BdfNamedList;
|
||||
|
|
@ -12,7 +13,6 @@ import gl_engine.range.Range2i;
|
|||
import gl_engine.vec.Vec2d;
|
||||
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;
|
||||
|
|
@ -20,7 +20,7 @@ import projectzombie.world.chunk.Chunk;
|
|||
import projectzombie.world.chunk.ChunkEventHandler;
|
||||
import projectzombie.world.layer.Layer;
|
||||
|
||||
public class TileLighting
|
||||
public class DisplayLighting
|
||||
{
|
||||
private static class Lighting {
|
||||
float[] p;
|
||||
|
|
@ -48,10 +48,10 @@ public class TileLighting
|
|||
}
|
||||
|
||||
private synchronized static void setLighting(Lighting lighting) {
|
||||
TileLighting.lighting = lighting;
|
||||
DisplayLighting.lighting = lighting;
|
||||
}
|
||||
|
||||
public TileLighting() {
|
||||
public DisplayLighting() {
|
||||
lightmap = GL33.glGenTextures();
|
||||
}
|
||||
|
||||
|
|
@ -255,9 +255,29 @@ public class TileLighting
|
|||
}
|
||||
}
|
||||
|
||||
ByteBuffer pixels_b = BufferUtils.createByteBuffer(pixels.length);
|
||||
|
||||
for(int i=0;i<pixels.length;i++) {
|
||||
pixels_b.put(i, (byte)(pixels[i]*255));
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
if(lighting_last_x != lighting.w || lighting_last_y != lighting.h)
|
||||
{
|
||||
GL33.glTexImage2D(GL33.GL_TEXTURE_2D, 0, GL33.GL_RGB,
|
||||
lighting.w, lighting.h, 0, GL33.GL_RGB, GL33.GL_UNSIGNED_BYTE, pixels_b);
|
||||
|
||||
lighting_last_x = lighting.w;
|
||||
lighting_last_y = lighting.h;
|
||||
}
|
||||
|
||||
else {
|
||||
GL33.glTexSubImage2D(GL33.GL_TEXTURE_2D, 0, 0, 0,
|
||||
lighting.w, lighting.h, GL33.GL_RGB, GL33.GL_UNSIGNED_BYTE, pixels_b);
|
||||
}
|
||||
|
||||
GL33.glGenerateMipmap(GL33.GL_TEXTURE_2D);
|
||||
|
||||
// Set the texture location data
|
||||
|
|
@ -300,6 +320,15 @@ public class TileLighting
|
|||
lighting.x = x;
|
||||
lighting.y = y;
|
||||
|
||||
Layer layer = Main.world.getLayer();
|
||||
|
||||
for(int x2=0;x2<lighting.w;x2++) {
|
||||
for(int y2=0;y2<lighting.h;y2++) {
|
||||
double temp = layer.layergen.getTemperatureStatic(layer, new Vec2d(x2 + lighting.x * 16, y2 + lighting.y * 16));
|
||||
pixels[(x2 + y2 * lighting.w) * 3 + 0] = (float)temp;
|
||||
}
|
||||
}
|
||||
|
||||
setLighting(lighting);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ import org.lwjgl.opengl.GL33;
|
|||
import gl_engine.graphics.GraphicsHelpers;
|
||||
import gl_engine.graphics.GraphicsShader;
|
||||
import mainloop.task.IMainloopTask;
|
||||
import projectzombie.display.lighting.TileLighting;
|
||||
import projectzombie.init.Resources;
|
||||
import projectzombie.input.CursorEnterCallback;
|
||||
import projectzombie.input.CursorPosCallback;
|
||||
|
|
@ -135,7 +134,7 @@ public class DisplayWindow implements IMainloopTask
|
|||
height = h[0];
|
||||
|
||||
environmentRenderer.use();
|
||||
TileLighting.updateLighting();
|
||||
DisplayLighting.updateLighting();
|
||||
|
||||
// Bind the texture atlas
|
||||
GL33.glActiveTexture(GL33.GL_TEXTURE0);
|
||||
|
|
@ -143,7 +142,7 @@ public class DisplayWindow implements IMainloopTask
|
|||
|
||||
// Bind the lightmap
|
||||
GL33.glActiveTexture(GL33.GL_TEXTURE1);
|
||||
GL33.glBindTexture(GL33.GL_TEXTURE_2D, TileLighting.lightmap);
|
||||
GL33.glBindTexture(GL33.GL_TEXTURE_2D, DisplayLighting.lightmap);
|
||||
|
||||
// Render everything
|
||||
DisplayRender.render(w[0], h[0]);
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
package projectzombie.display.lighting;
|
||||
|
||||
import gl_engine.MathHelpers;
|
||||
import gl_engine.vec.Vec2d;
|
||||
import gl_engine.vec.Vec2i;
|
||||
import projectzombie.util.math.map.IMap2D;
|
||||
import projectzombie.util.math.map.Map2D;
|
||||
import projectzombie.world.chunk.Chunk;
|
||||
|
||||
public class ChunkLightingCollection implements IMap2D<ChunkLightingTemp>
|
||||
{
|
||||
private Map2D<ChunkLightingTemp> chunks = new Map2D<ChunkLightingTemp>(this);
|
||||
|
||||
public final int RENDER_DISTANCE = Chunk.RENDER_DISTANCE;
|
||||
|
||||
@Override
|
||||
public ChunkLightingTemp getEmpty(Vec2i pos) {
|
||||
return new ChunkLightingTemp();
|
||||
}
|
||||
|
||||
private Vec2i getChunkPosFromPos(Vec2i pos) {
|
||||
return this.getChunkPosFromPos(new Vec2d(pos.x, pos.y));
|
||||
}
|
||||
|
||||
private Vec2i getChunkPosFromPos(Vec2d pos) {
|
||||
return new Vec2i(
|
||||
MathHelpers.floor(pos.x / (double)Chunk.CHUNK_SIZE.mx),
|
||||
MathHelpers.floor(pos.y / (double)Chunk.CHUNK_SIZE.my));
|
||||
}
|
||||
|
||||
public ChunkLightingTemp getChunkwCPos(Vec2i cpos) {
|
||||
if(!chunks.contains(cpos)) {
|
||||
ChunkLightingTemp chunk = new ChunkLightingTemp();
|
||||
chunks.set(cpos, chunk);
|
||||
return chunk;
|
||||
} else {
|
||||
return chunks.get(cpos);
|
||||
}
|
||||
}
|
||||
|
||||
public ChunkLightingTemp getChunk(Vec2i pos) {
|
||||
return getChunkwCPos(getChunkPosFromPos(pos));
|
||||
}
|
||||
|
||||
public ChunkLightingTemp getChunk(Vec2d pos) {
|
||||
return getChunkwCPos(getChunkPosFromPos(pos));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
package projectzombie.display.lighting;
|
||||
|
||||
import gl_engine.vec.Vec2i;
|
||||
import projectzombie.world.chunk.Chunk;
|
||||
|
||||
public class ChunkLightingTemp
|
||||
{
|
||||
private byte lighting_daylight[] = new byte[Chunk.CHUNK_INDEX];
|
||||
private byte lighting_light[] = new byte[Chunk.CHUNK_INDEX];
|
||||
|
||||
public ChunkLightingTemp() {
|
||||
for(int i=0;i<Chunk.CHUNK_INDEX;i++) {
|
||||
lighting_daylight[i] = 0;
|
||||
lighting_light[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDaylightLevel(double v, Vec2i pos) {
|
||||
setDaylightLevel(v, pos.getId(Chunk.CHUNK_SIZE));
|
||||
}
|
||||
|
||||
public void setDaylightLevel(double v, int id) {
|
||||
lighting_daylight[id] = (byte)(v * Byte.MAX_VALUE);
|
||||
}
|
||||
|
||||
public void setLightLevel(double v, Vec2i pos) {
|
||||
setLightLevel(v, pos.getId(Chunk.CHUNK_SIZE));
|
||||
}
|
||||
|
||||
public void setLightLevel(double v, int id) {
|
||||
lighting_light[id] = (byte)(v * Byte.MAX_VALUE);
|
||||
}
|
||||
|
||||
public double getDaylightLevel(Vec2i pos) {
|
||||
return getDaylightLevel(pos.getId(Chunk.CHUNK_SIZE));
|
||||
}
|
||||
|
||||
public double getDaylightLevel(int id) {
|
||||
return lighting_daylight[id] / (double)Byte.MAX_VALUE;
|
||||
}
|
||||
|
||||
public double getLightLevel(Vec2i pos) {
|
||||
return getLightLevel(pos.getId(Chunk.CHUNK_SIZE));
|
||||
}
|
||||
|
||||
public double getLightLevel(int id) {
|
||||
return lighting_light[id] / (double)Byte.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
package projectzombie.display.lighting;
|
||||
|
||||
import gl_engine.MathHelpers;
|
||||
import gl_engine.vec.Vec2i;
|
||||
import projectzombie.Main;
|
||||
import projectzombie.entity.Entity;
|
||||
import projectzombie.entity.player.EntityPlayer;
|
||||
import projectzombie.util.math.TileState;
|
||||
import projectzombie.world.chunk.Chunk;
|
||||
import projectzombie.world.chunk.ChunkEventHandler;
|
||||
import projectzombie.world.layer.Layer;
|
||||
|
||||
public class DynamicLighting
|
||||
{
|
||||
public static int lightingMode = 0;
|
||||
|
||||
public static void update()
|
||||
{
|
||||
if(!ChunkEventHandler.loaded) return;
|
||||
int r = Chunk.RENDER_DISTANCE;
|
||||
Layer layer = Main.world.getLayer();
|
||||
EntityPlayer player = Main.player;
|
||||
|
||||
// Copy every light source from the tile light sources
|
||||
for(int cx=-r;cx<=r;cx++) {
|
||||
for(int cy=-r;cy<=r;cy++)
|
||||
{
|
||||
// Get the chunk position and the chunk
|
||||
Chunk chunk = layer.chunks.get(new Vec2i(
|
||||
MathHelpers.floor(player.pos.x / 16) + cx,
|
||||
MathHelpers.floor(player.pos.y / 16) + cy));
|
||||
|
||||
// Loop over all the tiles
|
||||
for(int x=0;x<16;x++) {
|
||||
for(int y=0;y<16;y++)
|
||||
{
|
||||
// Reset the tiles light
|
||||
int id = new Vec2i(x, y).getId(Chunk.CHUNK_SIZE);
|
||||
chunk.setDynamicLightLevel(chunk.getLightLevel(id), id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loop over every entity to scan for light sources
|
||||
for(int cx=-r;cx<=r;cx++) {
|
||||
for(int cy=-r;cy<=r;cy++)
|
||||
{
|
||||
// Loop over all the entities
|
||||
Vec2i cpos = new Vec2i(
|
||||
cx + MathHelpers.floor(player.pos.x / 16),
|
||||
cy + MathHelpers.floor(player.pos.y / 16));
|
||||
Chunk chunk = layer.chunks.get(cpos);
|
||||
|
||||
// Create all the entity light sources
|
||||
for(Entity e : chunk.entities)
|
||||
{
|
||||
// Does this entity emit light
|
||||
if(e.emitsLight)
|
||||
{
|
||||
// Create some light
|
||||
addLightToTiles(layer, new Vec2i(
|
||||
MathHelpers.floor(e.pos.x),
|
||||
MathHelpers.floor(e.pos.y)),
|
||||
e.getLightLevel());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Does the player emit light
|
||||
if(player.emitsLight) {
|
||||
addLightToTiles(layer, new Vec2i(
|
||||
MathHelpers.floor(player.pos.x),
|
||||
MathHelpers.floor(player.pos.y)),
|
||||
player.getLightLevel());
|
||||
}
|
||||
}
|
||||
|
||||
private static void addLightToTiles(Layer layer, Vec2i lpos, double light)
|
||||
{
|
||||
if(
|
||||
MathHelpers.floor(lpos.squareDistance(new Vec2i(
|
||||
MathHelpers.floor(Main.player.pos.x),
|
||||
MathHelpers.floor(Main.player.pos.y))) / 16)
|
||||
> Chunk.RENDER_DISTANCE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the light pos id
|
||||
int lid = lpos.getId(Chunk.CHUNK_SIZE);
|
||||
|
||||
// Get the light dissipation amount
|
||||
Chunk chunk = layer.getChunk(lpos);
|
||||
TileState bt = chunk.getBackTile(lid);
|
||||
TileState ft = chunk.getFrontTile(lid);
|
||||
|
||||
double light_dissipation = MathHelpers.biggest(
|
||||
bt.tile.getLightDissipation(bt),
|
||||
ft.tile.getLightDissipation(ft));
|
||||
|
||||
// Calculate the light level
|
||||
double light_tile = chunk.getDynamicLightLevel(lid);
|
||||
if(light <= light_tile) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Merge the light and the light tile values
|
||||
chunk.setDynamicLightLevel(light, lid);
|
||||
|
||||
// Get all the adjacent positions of the light tiles to flow onto
|
||||
Vec2i positions[] = {
|
||||
new Vec2i(lpos.x+1, lpos.y),
|
||||
new Vec2i(lpos.x-1, lpos.y),
|
||||
new Vec2i(lpos.x, lpos.y+1),
|
||||
new Vec2i(lpos.x, lpos.y-1)
|
||||
};
|
||||
|
||||
// Add the light to all the adjacent positions
|
||||
for(Vec2i position : positions) {
|
||||
addLightToTiles(layer, position, light - light_dissipation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ import gl_engine.vec.Vec2d;
|
|||
import gl_engine.vec.Vec2i;
|
||||
import mainloop.task.IMainloopTask;
|
||||
import projectzombie.Main;
|
||||
import projectzombie.display.lighting.TileLighting;
|
||||
import projectzombie.display.DisplayLighting;
|
||||
import projectzombie.entity.Entity;
|
||||
import projectzombie.entity.EntityAlive;
|
||||
import projectzombie.entity.EntityBullet;
|
||||
|
|
@ -136,7 +136,7 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
|
|||
|
||||
if(chunk != null && chunk.c_pos != null && (last_chunk == null || !chunk.c_pos.equal(last_chunk))) {
|
||||
last_chunk = chunk.c_pos;
|
||||
TileLighting.setDirty();
|
||||
DisplayLighting.setDirty();
|
||||
}
|
||||
|
||||
if(dead) return;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package projectzombie.init;
|
|||
import gl_engine.vec.Vec2d;
|
||||
import projectzombie.model.Model;
|
||||
import projectzombie.model.ModelEmpty;
|
||||
import projectzombie.model.ModelGrass;
|
||||
import projectzombie.model.ModelGui;
|
||||
import projectzombie.model.ModelItem;
|
||||
import projectzombie.model.ModelRandom;
|
||||
|
|
@ -13,7 +14,7 @@ public class Models
|
|||
{
|
||||
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_GRASS = new ModelGrass();
|
||||
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"));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
package projectzombie.model;
|
||||
|
||||
import gl_engine.texture.TextureRef3D;
|
||||
import projectzombie.init.Resources;
|
||||
|
||||
public class ModelGrass extends Model
|
||||
{
|
||||
private static final TextureRef3D GRASS = Resources.ATLAS.get("/tile/grass.png");
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getIndicies() {
|
||||
return new int[] {
|
||||
0, 1, 2,
|
||||
2, 3, 0,
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getVerticies()
|
||||
{
|
||||
return new float[] {
|
||||
0.5f, 0, 0.5f, 1, 1, 0, GRASS.sy, GRASS.ey, 0, 0, 0, 1, 1, 0x100,
|
||||
0.5f, 0, -0.5f, 1, 0, 0, GRASS.sy, GRASS.ey, 0, 0, 0, 1, 1, 0x100,
|
||||
-0.5f, 0, -0.5f, 0, 0, 0, GRASS.sy, GRASS.ey, 0, 0, 0, 1, 1, 0x100,
|
||||
-0.5f, 0, 0.5f, 0, 1, 0, GRASS.sy, GRASS.ey, 0, 0, 0, 1, 1, 0x100,
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndexSize() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRef3D[] getTextures()
|
||||
{
|
||||
return new TextureRef3D[] {
|
||||
GRASS, GRASS, GRASS, GRASS
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ public class TileState
|
|||
|
||||
public Tile tile;
|
||||
public byte meta;
|
||||
public Vec3d light;
|
||||
public double light;
|
||||
|
||||
public TileState(Tile tile, byte meta) {
|
||||
this.tile = tile;
|
||||
|
|
@ -21,7 +21,7 @@ public class TileState
|
|||
this(tile, (byte)meta);
|
||||
}
|
||||
|
||||
public TileState withLightLevel(Vec3d level) {
|
||||
public TileState withLightLevel(double level) {
|
||||
TileState ts = new TileState(tile, meta);
|
||||
ts.light = level;
|
||||
return ts;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.nio.ByteBuffer;
|
|||
import bdf.data.BdfDatabase;
|
||||
import bdf.types.BdfNamedList;
|
||||
import bdf.types.BdfObject;
|
||||
import projectzombie.display.lighting.TileLighting;
|
||||
import projectzombie.display.DisplayLighting;
|
||||
|
||||
public class Worker extends Thread
|
||||
{
|
||||
|
|
@ -103,7 +103,7 @@ public class Worker extends Thread
|
|||
switch(nl.get("task").getString())
|
||||
{
|
||||
case "light":
|
||||
TileLighting.updateLighting(bdf);
|
||||
DisplayLighting.updateLighting(bdf);
|
||||
break;
|
||||
default:
|
||||
Thread.sleep(10);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import bdf.types.BdfNamedList;
|
|||
import bdf.types.BdfObject;
|
||||
import projectzombie.Main;
|
||||
import projectzombie.display.Camera;
|
||||
import projectzombie.display.lighting.TileLighting;
|
||||
import projectzombie.display.DisplayLighting;
|
||||
import projectzombie.entity.player.EntityPlayer;
|
||||
import projectzombie.time.GameTimer;
|
||||
import projectzombie.world.chunk.ChunkEventHandler;
|
||||
|
|
@ -34,8 +34,8 @@ public class World implements IBdfClassManager
|
|||
public void setLayer(int id)
|
||||
{
|
||||
ChunkEventHandler.loaded = false;
|
||||
TileLighting.clearLighting();
|
||||
TileLighting.setDirty();
|
||||
DisplayLighting.clearLighting();
|
||||
DisplayLighting.setDirty();
|
||||
|
||||
this.loaded = layers.get(id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,9 +46,8 @@ public class Chunk implements IBdfClassManager
|
|||
private Tile tiles_front[] = new Tile[CHUNK_INDEX];
|
||||
private byte tiles_front_meta[] = new byte[CHUNK_INDEX];
|
||||
private byte tiles_back_meta[] = new byte[CHUNK_INDEX];
|
||||
private byte tiles_lighting[] = new byte[CHUNK_INDEX];
|
||||
private byte tiles_lighting_dynamic[] = new byte[CHUNK_INDEX];
|
||||
private byte tiles_lighting_daylight[] = new byte[CHUNK_INDEX];
|
||||
private byte tiles_lighting_src[] = new byte[CHUNK_INDEX];
|
||||
private byte tiles_lighting_day[] = new byte[CHUNK_INDEX];
|
||||
public ArrayList<Entity> entities = new ArrayList<Entity>();
|
||||
private Layer layer;
|
||||
public Vec2i c_pos;
|
||||
|
|
@ -96,14 +95,14 @@ public class Chunk implements IBdfClassManager
|
|||
byte[] mb = nl.get("mb").getByteArray();
|
||||
byte[] mf = nl.get("mf").getByteArray();
|
||||
|
||||
for(int i=0;i<CHUNK_INDEX;i++) {
|
||||
for(int i=0;i<CHUNK_INDEX;i++)
|
||||
{
|
||||
tiles_back[i] = Tiles.tiles.get(tb[i]);
|
||||
tiles_front[i] = Tiles.tiles.get(tf[i]);
|
||||
tiles_back_meta[i] = mb[i];
|
||||
tiles_front_meta[i] = mf[i];
|
||||
tiles_lighting[i] = 0;
|
||||
tiles_lighting_daylight[i] = 0;
|
||||
tiles_lighting_dynamic[i] = 0;
|
||||
tiles_lighting_src[i] = 0;
|
||||
tiles_lighting_day[i] = 0;
|
||||
}
|
||||
|
||||
// Load all the entities
|
||||
|
|
@ -177,9 +176,8 @@ public class Chunk implements IBdfClassManager
|
|||
tiles_front_meta[i] = 0;
|
||||
|
||||
// Set the light level to 0
|
||||
tiles_lighting[i] = 0;
|
||||
tiles_lighting_daylight[i] = 0;
|
||||
tiles_lighting_dynamic[i] = 0;
|
||||
tiles_lighting_src[i] = 0;
|
||||
tiles_lighting_day[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -408,7 +406,7 @@ public class Chunk implements IBdfClassManager
|
|||
{
|
||||
// Send back the back tile
|
||||
TileState ts = new TileState(this.tiles_back[id], this.tiles_back_meta[id]);
|
||||
ts.light = getRGBLightLevel(id);
|
||||
ts.light = MathHelpers.biggest(getLightLevel(id), getDaylightLevel(id));
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
|
@ -427,27 +425,10 @@ public class Chunk implements IBdfClassManager
|
|||
{
|
||||
// Send back the front tile
|
||||
TileState ts = new TileState(this.tiles_front[id], this.tiles_front_meta[id]);
|
||||
ts.light = getRGBLightLevel(id);
|
||||
ts.light = MathHelpers.biggest(getLightLevel(id), getDaylightLevel(id));
|
||||
return ts;
|
||||
}
|
||||
|
||||
public Vec3d getRGBLightLevel(Vec2i tpos) {
|
||||
return getRGBLightLevel(tpos.getId(CHUNK_SIZE));
|
||||
}
|
||||
|
||||
public Vec3d getRGBLightLevel(int id)
|
||||
{
|
||||
double daylight_level = this.getDaylightLevel(id);
|
||||
Vec3d light = this.layer.layergen.getLightLevel().getColor(daylight_level);
|
||||
|
||||
double light_level = this.getDynamicLightLevel(id);
|
||||
if(light_level > light.x) light.x = light_level;
|
||||
if(light_level > light.y) light.y = light_level;
|
||||
if(light_level > light.z) light.z = light_level;
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
public void breakBackTile(Vec2i pos)
|
||||
{
|
||||
TileState ts = getBackTile(pos);
|
||||
|
|
@ -471,7 +452,7 @@ public class Chunk implements IBdfClassManager
|
|||
}
|
||||
|
||||
public double getLightLevel(int id) {
|
||||
return tiles_lighting[id] / (double)Byte.MAX_VALUE;
|
||||
return tiles_lighting_src[id] / (double)Byte.MAX_VALUE;
|
||||
}
|
||||
|
||||
public double getLightLevel(Vec2i pos)
|
||||
|
|
@ -486,7 +467,7 @@ public class Chunk implements IBdfClassManager
|
|||
}
|
||||
|
||||
public double getDaylightLevel(int id) {
|
||||
return tiles_lighting_daylight[id] / (double)Byte.MAX_VALUE;
|
||||
return tiles_lighting_day[id] / (double)Byte.MAX_VALUE;
|
||||
}
|
||||
|
||||
public double getDaylightLevel(Vec2i pos)
|
||||
|
|
@ -501,7 +482,7 @@ public class Chunk implements IBdfClassManager
|
|||
}
|
||||
|
||||
public void setLightLevel(double light, int id) {
|
||||
this.tiles_lighting[id] = (byte)(light * Byte.MAX_VALUE);
|
||||
this.tiles_lighting_src[id] = (byte)(light * Byte.MAX_VALUE);
|
||||
}
|
||||
|
||||
public void setLightLevel(double light, Vec2i pos)
|
||||
|
|
@ -516,7 +497,7 @@ public class Chunk implements IBdfClassManager
|
|||
}
|
||||
|
||||
public void setDaylightLevel(double light, int id) {
|
||||
this.tiles_lighting_daylight[id] = (byte)(light * Byte.MAX_VALUE);
|
||||
this.tiles_lighting_day[id] = (byte)(light * Byte.MAX_VALUE);
|
||||
}
|
||||
|
||||
public void setDaylightLevel(double light, Vec2i pos)
|
||||
|
|
@ -530,36 +511,6 @@ public class Chunk implements IBdfClassManager
|
|||
setDaylightLevel(light, id);
|
||||
}
|
||||
|
||||
public double getDynamicLightLevel(int id) {
|
||||
return tiles_lighting_dynamic[id] / (double)Byte.MAX_VALUE;
|
||||
}
|
||||
|
||||
public double getDynamicLightLevel(Vec2i pos)
|
||||
{
|
||||
// Get the id
|
||||
Vec2i cpos = new Vec2i(0, 0);
|
||||
cpos.x = MathHelpers.mod(pos.x, CHUNK_SIZE.mx);
|
||||
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
||||
int id = cpos.getId(CHUNK_SIZE);
|
||||
|
||||
return getDynamicLightLevel(id);
|
||||
}
|
||||
|
||||
public void setDynamicLightLevel(double light, int id) {
|
||||
this.tiles_lighting_dynamic[id] = (byte)(light * Byte.MAX_VALUE);
|
||||
}
|
||||
|
||||
public void setDynamicLightLevel(double light, Vec2i pos)
|
||||
{
|
||||
// Get the id
|
||||
Vec2i cpos = new Vec2i(0, 0);
|
||||
cpos.x = MathHelpers.mod(pos.x, CHUNK_SIZE.mx);
|
||||
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
||||
int id = cpos.getId(CHUNK_SIZE);
|
||||
|
||||
setDynamicLightLevel(light, id);
|
||||
}
|
||||
|
||||
public void killEntity(Entity e)
|
||||
{
|
||||
if(e instanceof EntityKillWithParticles) {
|
||||
|
|
|
|||
|
|
@ -25,16 +25,6 @@ public class ChunkEmpty extends Chunk
|
|||
public void BdfClassSave(BdfObject bdf) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3d getRGBLightLevel(int id) {
|
||||
return new Vec3d(0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3d getRGBLightLevel(Vec2i tpos) {
|
||||
return new Vec3d(0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Camera camera) {}
|
||||
|
||||
|
|
@ -117,21 +107,12 @@ public class ChunkEmpty extends Chunk
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getDynamicLightLevel(int id) {
|
||||
return 0;
|
||||
public boolean isLightDirty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDynamicLightLevel(Vec2i pos) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDynamicLightLevel(double light, int id) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDynamicLightLevel(double light, Vec2i pos) {
|
||||
public void resetLightDirty() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import gl_engine.MathHelpers;
|
|||
import gl_engine.vec.Vec2i;
|
||||
import mainloop.task.IMainloopTask;
|
||||
import projectzombie.Main;
|
||||
import projectzombie.display.lighting.TileLighting;
|
||||
import projectzombie.display.DisplayLighting;
|
||||
import projectzombie.util.math.map.Map2DElement;
|
||||
import projectzombie.world.layer.Layer;
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ public class ChunkEventHandler implements IMainloopTask
|
|||
}
|
||||
}
|
||||
|
||||
TileLighting.update();
|
||||
DisplayLighting.update();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import projectzombie.init.LayerGenerators;
|
|||
import projectzombie.util.math.TileState;
|
||||
import projectzombie.util.math.map.Map2D;
|
||||
import projectzombie.util.math.map.Map2DElement;
|
||||
import projectzombie.util.math.random.OpenSimplexNoise;
|
||||
import projectzombie.world.chunk.Chunk;
|
||||
import projectzombie.world.layer.layergen.LayerGen;
|
||||
|
||||
|
|
@ -24,6 +25,7 @@ public class Layer implements IBdfClassManager
|
|||
{
|
||||
public Map2D<Chunk> chunks;
|
||||
private Map2D<Chunk> dirty_chunks;
|
||||
public OpenSimplexNoise[] noise_gens;
|
||||
public LayerGen layergen;
|
||||
private Random rand;
|
||||
public long lseed;
|
||||
|
|
@ -39,6 +41,8 @@ public class Layer implements IBdfClassManager
|
|||
this.lseed = this.rand.nextLong();
|
||||
this.chunks = new Map2D<Chunk>(layergen);
|
||||
this.dirty_chunks = new Map2D<Chunk>(layergen);
|
||||
|
||||
this.layergen.init(this);
|
||||
}
|
||||
|
||||
public Layer(BdfObject bdf) {
|
||||
|
|
@ -161,24 +165,6 @@ public class Layer implements IBdfClassManager
|
|||
chunks.get(c_pos).setLightLevel(light, pos);
|
||||
}
|
||||
|
||||
public double getDynamicLightLevel(Vec2i pos)
|
||||
{
|
||||
// Get the chunk pos
|
||||
Vec2i c_pos = getChunkPosFromPos(pos);
|
||||
|
||||
// Get the chunks front tile
|
||||
return chunks.get(c_pos).getDynamicLightLevel(pos);
|
||||
}
|
||||
|
||||
public void setDynamicLightLevel(double light, Vec2i pos)
|
||||
{
|
||||
// Get the chunk pos
|
||||
Vec2i c_pos = getChunkPosFromPos(pos);
|
||||
|
||||
// Get the chunks front tile
|
||||
chunks.get(c_pos).setDynamicLightLevel(light, pos);
|
||||
}
|
||||
|
||||
public double getDaylightLevel(Vec2i pos)
|
||||
{
|
||||
// Get the chunk pos
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package projectzombie.world.layer.layergen;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import gl_engine.vec.Vec2d;
|
||||
import gl_engine.vec.Vec2i;
|
||||
import projectzombie.util.math.ColorRange;
|
||||
import projectzombie.util.math.TileState;
|
||||
|
|
@ -15,10 +16,16 @@ public abstract class LayerGen implements IMap2D<Chunk>
|
|||
public boolean destroyOnLeave = false;
|
||||
|
||||
public abstract void generateChunk(Chunk chunk, Layer layer, Random rand, Vec2i pos);
|
||||
public abstract double getTemperatureStatic(Layer layer, Vec2d pos);
|
||||
public abstract double getTemperatureDynamic(Layer layer, Vec2d pos);
|
||||
public abstract void spawnEntities(Layer layer, Random rand);
|
||||
public abstract TileState getTileDestroyed();
|
||||
public abstract ColorRange getLightLevel();
|
||||
|
||||
public void init(Layer layer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getEmpty(Vec2i pos) {
|
||||
return Chunk.CHUNK_EMPTY;
|
||||
|
|
|
|||
|
|
@ -114,5 +114,15 @@ public class LayerGenBossArena extends LayerGen implements LayerGenRememberPlaye
|
|||
RandomHelpers.randrange(rand, -size + 2, size - 2),
|
||||
RandomHelpers.randrange(rand, -size + 2, size - 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTemperatureStatic(Layer layer, Vec2d pos) {
|
||||
return 0.8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTemperatureDynamic(Layer layer, Vec2d pos) {
|
||||
return 0.8;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,5 +118,15 @@ public class LayerGenCaves extends LayerGen
|
|||
public ColorRange getLightLevel() {
|
||||
return new ColorRange(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTemperatureStatic(Layer layer, Vec2d pos) {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTemperatureDynamic(Layer layer, Vec2d pos) {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package projectzombie.world.layer.layergen;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import gl_engine.MathHelpers;
|
||||
import gl_engine.vec.Vec2d;
|
||||
import gl_engine.vec.Vec2i;
|
||||
import gl_engine.vec.Vec3d;
|
||||
|
|
@ -20,6 +21,34 @@ import projectzombie.world.layer.Layer;
|
|||
public class LayerGenEarth extends LayerGen
|
||||
{
|
||||
|
||||
@Override
|
||||
public double getTemperatureStatic(Layer layer, Vec2d pos)
|
||||
{
|
||||
// Get the noise generator
|
||||
OpenSimplexNoise terrain_noise = layer.noise_gens[0];
|
||||
return MathHelpers.map(terrain_noise.eval(pos.x/64.0, pos.y/64.0), -1, 1, 0, 0.7);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTemperatureDynamic(Layer layer, Vec2d pos)
|
||||
{
|
||||
// Get the noise generator
|
||||
double light = (getEarthLight() + 1) * 0.2;
|
||||
OpenSimplexNoise terrain_noise = layer.noise_gens[0];
|
||||
return MathHelpers.map(terrain_noise.eval(pos.x/64.0, pos.y/64.0), -1, 1, light, 0.5 + light);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Layer layer) {
|
||||
super.init(layer);
|
||||
|
||||
Random rand = new Random(layer.lseed);
|
||||
|
||||
layer.noise_gens = new OpenSimplexNoise[] {
|
||||
new OpenSimplexNoise(rand.nextLong()),
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(Chunk chunk, Layer layer, Random rand, Vec2i c_pos)
|
||||
{
|
||||
|
|
@ -31,38 +60,25 @@ public class LayerGenEarth extends LayerGen
|
|||
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my));
|
||||
|
||||
// Get the noise generator
|
||||
Random rand_seed = new Random(layer.lseed);
|
||||
OpenSimplexNoise noisegen_n = new OpenSimplexNoise(rand_seed.nextLong());
|
||||
OpenSimplexNoise noise_terrain = layer.noise_gens[0];
|
||||
|
||||
// Loop over the layer dimensions and create land
|
||||
for(int x=0;x<Chunk.CHUNK_SIZE.mx;x++) {
|
||||
for(int y=0;y<Chunk.CHUNK_SIZE.my;y++)
|
||||
{
|
||||
// Get the x and y in the world
|
||||
int cx = x + c_pos.x * Chunk.CHUNK_SIZE.mx;
|
||||
int cy = y + c_pos.y * Chunk.CHUNK_SIZE.my;
|
||||
Vec2d pos = new Vec2d(c_pos.x * 16 + x, c_pos.y * 16 + y);
|
||||
double n = noise_terrain.eval(pos.x / 64.0, pos.y / 64.0);
|
||||
|
||||
// Get the noise value and the position vector
|
||||
double noise_n = (noisegen_n.eval(cx/10.0, cy/10.0) + 1) * 50;
|
||||
Vec2i pos = new Vec2i(x, y);
|
||||
|
||||
// Terrain generation
|
||||
if(noise_n < 40) {
|
||||
chunk.setFrontTile(Tiles.WATER.getDefaultState(), pos);
|
||||
chunk.setBackTile(Tiles.DIRT.getDefaultState(), pos);
|
||||
if(n < -0.5) {
|
||||
chunk.setBackTile(Tiles.SAND.getDefaultState(), pos.toInt());
|
||||
}
|
||||
|
||||
else if(noise_n < 70) chunk.setBackTile(Tiles.GRASS.getDefaultState(), pos);
|
||||
else if(noise_n < 85) chunk.setBackTile(Tiles.DIRT.getDefaultState(), pos);
|
||||
else chunk.setBackTile(Tiles.WALL.getDefaultState(), pos);
|
||||
else if(n > 0.5) {
|
||||
chunk.setBackTile(Tiles.DIRT.getDefaultState(), pos.toInt());
|
||||
}
|
||||
|
||||
// Tree and rock generation
|
||||
if(!chunk.getBackTile(pos).tile.tileSolid && noise_n >= 40) {
|
||||
if(rand.nextDouble() > 0.9) chunk.setFrontTile(new TileState(Tiles.TREE,
|
||||
(short)RandomHelpers.randrange(rand, Short.MAX_VALUE)), pos);
|
||||
else if(rand.nextDouble() > 0.99) chunk.setFrontTile(new TileState(Tiles.ROCK,
|
||||
(short)RandomHelpers.randrange(rand, Short.MAX_VALUE)), pos);
|
||||
else chunk.setFrontTile(Tiles.VOID.getDefaultState(), pos);
|
||||
else {
|
||||
chunk.setBackTile(Tiles.GRASS.getDefaultState(), pos.toInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -104,7 +120,7 @@ public class LayerGenEarth extends LayerGen
|
|||
}
|
||||
|
||||
private double getEarthLight() {
|
||||
return Math.sin(GameTimer.getTime() / 7200.0);
|
||||
return MathHelpers.sin(GameTimer.getTime() / 7200.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -160,5 +160,15 @@ public class LayerGenLavaCaves extends LayerGen
|
|||
public ColorRange getLightLevel() {
|
||||
return new ColorRange(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTemperatureStatic(Layer layer, Vec2d pos) {
|
||||
return 0.7;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTemperatureDynamic(Layer layer, Vec2d pos) {
|
||||
return 0.7;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ in vec3 pPos;
|
|||
in vec3 pTexture;
|
||||
in vec3 pLightMapPos;
|
||||
|
||||
flat in int pFlags;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform sampler3D atlas;
|
||||
|
|
@ -18,6 +20,9 @@ uniform vec2 lightmap_size;
|
|||
uniform vec2 tex_cut;
|
||||
uniform vec4 color;
|
||||
|
||||
uniform vec3 color_grass_min;
|
||||
uniform vec3 color_grass_max;
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -44,8 +49,12 @@ void main()
|
|||
|
||||
vec3 light_day = mapVec(scaleLight(light.r), 0, 1, lighting_day_low, lighting_day_high);
|
||||
vec3 light_src = vec3(1, 1, 1) * (scaleLight(light.g) - abs(pLightMapPos.y) * 0.1);
|
||||
|
||||
vec4 color_white = vec4(1, 1, 1, 1);
|
||||
vec4 color_grass = vec4(mapVec(light.b, 0, 1, color_grass_min, color_grass_max), 1);
|
||||
|
||||
FragColor = texture(atlas, pTexture) * color * vec4(biggest(light_day, light_src), 1);
|
||||
FragColor = texture(atlas, pTexture) * (mod(pFlags >> 2, 1) == 1 ? color_grass : color_white) *
|
||||
color * vec4(biggest(light_day, light_src), 1);
|
||||
|
||||
discard(FragColor.a == 0 || (pPos.x > tex_cut.y && tex_cut.x > 0.5));
|
||||
}
|
||||
|
|
@ -7,10 +7,11 @@ layout (location = 3) in vec3 aChunkOffset;
|
|||
layout (location = 4) in vec3 aFlags;
|
||||
|
||||
out vec3 pLightMapPos;
|
||||
out vec3 pLighting;
|
||||
out vec3 pTexture;
|
||||
out vec3 pPos;
|
||||
|
||||
flat out int pFlags;
|
||||
|
||||
uniform mat4 projection;
|
||||
uniform mat4 model;
|
||||
uniform mat4 rotated;
|
||||
|
|
@ -61,5 +62,6 @@ void main()
|
|||
pLightMapPos = pos.xyz;
|
||||
|
||||
pTexture = vec3(aTex.x, getTexY(), aTex.z);
|
||||
pFlags = type;
|
||||
pPos = aPos;
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 996 B After Width: | Height: | Size: 2.9 KiB |
Loading…
Reference in New Issue