Buttons for toggling buildings/terrain in editor
This commit is contained in:
@@ -154,6 +154,26 @@ public class BlockRenderer{
|
||||
updateDarkness();
|
||||
}
|
||||
|
||||
public void updateShadows(boolean ignoreBuildings, boolean ignoreTerrain){
|
||||
shadows.getTexture().setFilter(TextureFilter.linear, TextureFilter.linear);
|
||||
shadows.resize(world.width(), world.height());
|
||||
shadows.begin();
|
||||
Core.graphics.clear(Color.white);
|
||||
Draw.proj().setOrtho(0, 0, shadows.getWidth(), shadows.getHeight());
|
||||
|
||||
Draw.color(blendShadowColor);
|
||||
|
||||
for(Tile tile : world.tiles){
|
||||
if(tile.block().displayShadow(tile) && (tile.build == null || tile.build.wasVisible) && !(ignoreBuildings && !tile.block().isStatic()) && !(ignoreTerrain && tile.block().isStatic())){
|
||||
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Draw.flush();
|
||||
Draw.color();
|
||||
shadows.end();
|
||||
}
|
||||
|
||||
public void updateDarkness(){
|
||||
darkEvents.clear();
|
||||
dark.getTexture().setFilter(TextureFilter.linear);
|
||||
@@ -303,6 +323,10 @@ public class BlockRenderer{
|
||||
}
|
||||
|
||||
public void processShadows(){
|
||||
processShadows(false, false);
|
||||
}
|
||||
|
||||
public void processShadows(boolean ignoreBuildings, boolean ignoreTerrain){
|
||||
if(!shadowEvents.isEmpty()){
|
||||
Draw.flush();
|
||||
|
||||
@@ -312,7 +336,7 @@ public class BlockRenderer{
|
||||
for(Tile tile : shadowEvents){
|
||||
if(tile == null) continue;
|
||||
//draw white/shadow color depending on blend
|
||||
Draw.color((!tile.block().displayShadow(tile) || (state.rules.fog && tile.build != null && !tile.build.wasVisible)) ? Color.white : blendShadowColor);
|
||||
Draw.color((!tile.block().displayShadow(tile) || (state.rules.fog && tile.build != null && !tile.build.wasVisible) || (ignoreBuildings && !tile.block().isStatic()) || (ignoreTerrain && tile.block().isStatic())) ? Color.white : blendShadowColor);
|
||||
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ public class FloorRenderer{
|
||||
}
|
||||
""");
|
||||
|
||||
Events.on(WorldLoadEvent.class, event -> clearTiles());
|
||||
Events.on(WorldLoadEvent.class, event -> reload());
|
||||
}
|
||||
|
||||
public IndexData getIndexData(){
|
||||
@@ -162,7 +162,7 @@ public class FloorRenderer{
|
||||
if(!Structs.inBounds(x, y, cache)) continue;
|
||||
|
||||
if(cache[x][y].length == 0){
|
||||
cacheChunk(x, y);
|
||||
cacheChunk(x, y, false);
|
||||
}
|
||||
|
||||
ChunkMesh[] chunk = cache[x][y];
|
||||
@@ -193,12 +193,16 @@ public class FloorRenderer{
|
||||
}
|
||||
|
||||
public void checkChanges(){
|
||||
checkChanges(false);
|
||||
}
|
||||
|
||||
public void checkChanges(boolean ignoreWalls){
|
||||
if(recacheSet.size > 0){
|
||||
//recache one chunk at a time
|
||||
IntSetIterator iterator = recacheSet.iterator();
|
||||
while(iterator.hasNext){
|
||||
int chunk = iterator.next();
|
||||
cacheChunk(Point2.x(chunk), Point2.y(chunk));
|
||||
cacheChunk(Point2.x(chunk), Point2.y(chunk), ignoreWalls);
|
||||
}
|
||||
|
||||
recacheSet.clear();
|
||||
@@ -278,13 +282,13 @@ public class FloorRenderer{
|
||||
layer.end();
|
||||
}
|
||||
|
||||
private void cacheChunk(int cx, int cy){
|
||||
private void cacheChunk(int cx, int cy, boolean ignoreWalls){
|
||||
used.clear();
|
||||
|
||||
for(int tilex = Math.max(cx * chunksize - 1, 0); tilex < (cx + 1) * chunksize + 1 && tilex < world.width(); tilex++){
|
||||
for(int tiley = Math.max(cy * chunksize - 1, 0); tiley < (cy + 1) * chunksize + 1 && tiley < world.height(); tiley++){
|
||||
Tile tile = world.rawTile(tilex, tiley);
|
||||
boolean wall = tile.block().cacheLayer != CacheLayer.normal;
|
||||
boolean wall = !ignoreWalls && tile.block().cacheLayer != CacheLayer.normal;
|
||||
|
||||
if(wall){
|
||||
used.add(tile.block().cacheLayer);
|
||||
@@ -310,11 +314,11 @@ public class FloorRenderer{
|
||||
}
|
||||
|
||||
for(CacheLayer layer : used){
|
||||
meshes[layer.id] = cacheChunkLayer(cx, cy, layer);
|
||||
meshes[layer.id] = cacheChunkLayer(cx, cy, layer, ignoreWalls);
|
||||
}
|
||||
}
|
||||
|
||||
private ChunkMesh cacheChunkLayer(int cx, int cy, CacheLayer layer){
|
||||
private ChunkMesh cacheChunkLayer(int cx, int cy, CacheLayer layer, boolean ignoreWalls){
|
||||
vidx = 0;
|
||||
|
||||
Batch current = Core.batch;
|
||||
@@ -333,7 +337,7 @@ public class FloorRenderer{
|
||||
|
||||
if(tile.block().cacheLayer == layer && layer == CacheLayer.walls && !(tile.isDarkened() && tile.data >= 5)){
|
||||
tile.block().drawBase(tile);
|
||||
}else if(floor.cacheLayer == layer && (world.isAccessible(tile.x, tile.y) || tile.block().cacheLayer != CacheLayer.walls || !tile.block().fillsTile)){
|
||||
}else if(floor.cacheLayer == layer && (ignoreWalls || world.isAccessible(tile.x, tile.y) || tile.block().cacheLayer != CacheLayer.walls || !tile.block().fillsTile)){
|
||||
floor.drawBase(tile);
|
||||
}else if(floor.cacheLayer != layer && layer != CacheLayer.walls){
|
||||
floor.drawNonLayer(tile, layer);
|
||||
@@ -355,7 +359,11 @@ public class FloorRenderer{
|
||||
return mesh;
|
||||
}
|
||||
|
||||
public void clearTiles(){
|
||||
public void reload(){
|
||||
reload(false);
|
||||
}
|
||||
|
||||
public void reload(boolean ignoreWalls){
|
||||
//dispose all old meshes
|
||||
if(cache != null){
|
||||
for(var x : cache){
|
||||
@@ -385,7 +393,7 @@ public class FloorRenderer{
|
||||
|
||||
for(int x = 0; x < chunksx; x++){
|
||||
for(int y = 0; y < chunksy; y++){
|
||||
cacheChunk(x, y);
|
||||
cacheChunk(x, y, ignoreWalls);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user