mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-09-11 08:15:35 +03:00
Cleaned up generation filter code
This commit is contained in:
parent
b59b839029
commit
c209528271
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,6 +20,7 @@ logs/
|
||||
/server/build/
|
||||
/test_files/
|
||||
/annotations/build/
|
||||
/desktop-sdl/build/
|
||||
/android/assets/mindustry-maps/
|
||||
/android/assets/mindustry-saves/
|
||||
/core/assets/gifexport/
|
||||
|
@ -5,17 +5,18 @@ import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.Pixmap.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.async.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.editor.generation.*;
|
||||
import io.anuke.mindustry.editor.generation.GenerateFilter.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.graphics.*;
|
||||
import io.anuke.mindustry.io.*;
|
||||
import io.anuke.mindustry.maps.filters.*;
|
||||
import io.anuke.mindustry.maps.filters.GenerateFilter.*;
|
||||
import io.anuke.mindustry.ui.*;
|
||||
import io.anuke.mindustry.ui.dialogs.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
@ -262,12 +263,12 @@ public class MapGenerateDialog extends FloatingDialog{
|
||||
}
|
||||
|
||||
for(GenerateFilter filter : filters){
|
||||
input.setFilter(filter, editor.width(), editor.height(), 1, (x, y) -> dset(editor.tile(x, y)));
|
||||
input.begin(filter, editor.width(), editor.height(), (x, y) -> dset(editor.tile(x, y)));
|
||||
//write to buffer
|
||||
for(int x = 0; x < editor.width(); x++){
|
||||
for(int y = 0; y < editor.height(); y++){
|
||||
Tile tile = editor.tile(x, y);
|
||||
input.begin(editor, x, y, tile.floor(), tile.block(), tile.overlay());
|
||||
input.apply(x, y, tile.floor(), tile.block(), tile.overlay());
|
||||
filter.apply(input);
|
||||
writeTiles[x][y].set(input.floor, input.block, input.ore, tile.getTeam(), tile.rotation());
|
||||
}
|
||||
@ -318,13 +319,13 @@ public class MapGenerateDialog extends FloatingDialog{
|
||||
}
|
||||
|
||||
for(GenerateFilter filter : copy){
|
||||
input.setFilter(filter, pixmap.getWidth(), pixmap.getHeight(), scaling, (x, y) -> buffer1[x][y]);
|
||||
input.begin(filter, editor.width(), editor.height(), (x, y) -> buffer1[Mathf.clamp(x / scaling, 0, pixmap.getWidth()-1)][Mathf.clamp(y / scaling, 0, pixmap.getHeight()-1)]);
|
||||
//read from buffer1 and write to buffer2
|
||||
for(int px = 0; px < pixmap.getWidth(); px++){
|
||||
for(int py = 0; py < pixmap.getHeight(); py++){
|
||||
int x = px * scaling, y = py * scaling;
|
||||
GenTile tile = buffer1[px][py];
|
||||
input.begin(editor, x, y, content.block(tile.floor), content.block(tile.block), content.block(tile.ore));
|
||||
input.apply(x, y, content.block(tile.floor), content.block(tile.block), content.block(tile.ore));
|
||||
filter.apply(input);
|
||||
buffer2[px][py].set(input.floor, input.block, input.ore, Team.all[tile.team], tile.rotation);
|
||||
}
|
||||
@ -389,6 +390,5 @@ public class MapGenerateDialog extends FloatingDialog{
|
||||
void set(Tile other){
|
||||
set(other.floor(), other.block(), other.overlay(), other.getTeam(), other.rotation());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package io.anuke.mindustry.editor.generation;
|
||||
package io.anuke.mindustry.maps.filters;
|
||||
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.BlockOption;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.BlockOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
import static io.anuke.mindustry.editor.generation.FilterOption.floorsOnly;
|
||||
import static io.anuke.mindustry.maps.filters.FilterOption.floorsOnly;
|
||||
|
||||
public class BlendFilter extends GenerateFilter{
|
||||
float radius = 2f;
|
||||
@ -32,7 +32,7 @@ public class BlendFilter extends GenerateFilter{
|
||||
for(int y = -rad; y <= rad; y++){
|
||||
if(Mathf.dst2(x, y) > rad*rad) continue;
|
||||
|
||||
if(in.tile((in.x + x) / in.scaling, (in.y + y) / in.scaling).floor == flooronto.id){
|
||||
if(in.tile(in.x + x, in.y + y).floor == flooronto.id){
|
||||
found = true;
|
||||
break outer;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package io.anuke.mindustry.editor.generation;
|
||||
package io.anuke.mindustry.maps.filters;
|
||||
|
||||
import io.anuke.mindustry.editor.MapGenerateDialog.GenTile;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
@ -18,7 +18,7 @@ public class DistortFilter extends GenerateFilter{
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
GenTile tile = in.tile(in.x / (in.scaling) + (noise(in.x, in.y, scl, mag) - mag / 2f) / in.scaling, in.y / (in.scaling) + (noise(in.x, in.y + o, scl, mag) - mag / 2f) / in.scaling);
|
||||
GenTile tile = in.tile(in.x + noise(in.x, in.y, scl, mag) - mag / 2f, in.y + noise(in.x, in.y + o, scl, mag) - mag / 2f);
|
||||
|
||||
in.floor = content.block(tile.floor);
|
||||
if(!content.block(tile.block).synthetic() && !in.block.synthetic()) in.block = content.block(tile.block);
|
@ -1,15 +1,16 @@
|
||||
package io.anuke.mindustry.editor.generation;
|
||||
package io.anuke.mindustry.maps.filters;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.scene.style.TextureRegionDrawable;
|
||||
import io.anuke.arc.scene.ui.Slider;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Block.Icon;
|
||||
import io.anuke.arc.scene.style.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.mindustry.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.ui.dialogs.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.Block.*;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.updateEditorOnChange;
|
@ -1,16 +1,14 @@
|
||||
package io.anuke.mindustry.editor.generation;
|
||||
package io.anuke.mindustry.maps.filters;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.util.Pack;
|
||||
import io.anuke.arc.util.noise.RidgedPerlin;
|
||||
import io.anuke.arc.util.noise.Simplex;
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.editor.MapEditor;
|
||||
import io.anuke.mindustry.editor.MapGenerateDialog.GenTile;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.noise.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.editor.MapGenerateDialog.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
|
||||
public abstract class GenerateFilter{
|
||||
protected transient float o = (float)(Math.random() * 10000000.0);
|
||||
@ -19,11 +17,38 @@ public abstract class GenerateFilter{
|
||||
|
||||
public FilterOption[] options;
|
||||
|
||||
public final void apply(GenerateInput in){
|
||||
this.in = in;
|
||||
apply();
|
||||
//remove extra ores on liquids
|
||||
if(((Floor)in.floor).isLiquid){
|
||||
in.ore = Blocks.air;
|
||||
}
|
||||
}
|
||||
|
||||
/** sets up the options; this is necessary since the constructor can't access subclass variables. */
|
||||
protected void options(FilterOption... options){
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/** apply the actual filter on the input */
|
||||
protected abstract void apply();
|
||||
|
||||
//draw any additional guides
|
||||
/** draw any additional guides */
|
||||
public void draw(Image image){}
|
||||
|
||||
/** localized display name */
|
||||
public String name(){
|
||||
return Core.bundle.get("filter." + getClass().getSimpleName().toLowerCase().replace("filter", ""), getClass().getSimpleName().replace("Filter", ""));
|
||||
}
|
||||
|
||||
/** set the seed to a random number */
|
||||
public void randomize(){
|
||||
seed = Mathf.random(99999999);
|
||||
}
|
||||
|
||||
//utility generation functions
|
||||
|
||||
protected float noise(float x, float y, float scl, float mag){
|
||||
return (float)in.noise.octaveNoise2D(1f, 0f, 1f / scl, x + o, y + o) * mag;
|
||||
}
|
||||
@ -36,46 +61,29 @@ public abstract class GenerateFilter{
|
||||
return in.pnoise.getValue((int)(x + o), (int)(y + o), 1f / scl) * mag;
|
||||
}
|
||||
|
||||
public void randomize(){
|
||||
seed = Mathf.random(99999999);
|
||||
}
|
||||
|
||||
protected float chance(){
|
||||
return Mathf.randomSeed(Pack.longInt(in.x, in.y + (int)o));
|
||||
}
|
||||
|
||||
public void options(FilterOption... options){
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public String name(){
|
||||
return Core.bundle.get("filter." + getClass().getSimpleName().toLowerCase().replace("filter", ""), getClass().getSimpleName().replace("Filter", ""));
|
||||
}
|
||||
|
||||
public final void apply(GenerateInput in){
|
||||
this.in = in;
|
||||
apply();
|
||||
//remove extra ores on liquids
|
||||
if(((Floor)in.floor).isLiquid){
|
||||
in.ore = Blocks.air;
|
||||
}
|
||||
}
|
||||
|
||||
/** an input for generating at a certain coordinate. should only be instantiated once. */
|
||||
public static class GenerateInput{
|
||||
/** input floor */
|
||||
public Floor srcfloor;
|
||||
/** input block */
|
||||
public Block srcblock;
|
||||
/** input overlay */
|
||||
public Block srcore;
|
||||
public int x, y, width, height, scaling;
|
||||
/** input size parameters */
|
||||
public int x, y, width, height;
|
||||
|
||||
public MapEditor editor;
|
||||
/** output parameters */
|
||||
public Block floor, block, ore;
|
||||
|
||||
Simplex noise = new Simplex();
|
||||
RidgedPerlin pnoise = new RidgedPerlin(0, 1);
|
||||
TileProvider buffer;
|
||||
|
||||
public void begin(MapEditor editor, int x, int y, Block floor, Block block, Block ore){
|
||||
this.editor = editor;
|
||||
public void apply(int x, int y, Block floor, Block block, Block ore){
|
||||
this.floor = this.srcfloor = (Floor)floor;
|
||||
this.block = this.srcblock = block;
|
||||
this.ore = srcore = ore;
|
||||
@ -83,11 +91,10 @@ public abstract class GenerateFilter{
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void setFilter(GenerateFilter filter, int width, int height, int scaling, TileProvider buffer){
|
||||
public void begin(GenerateFilter filter, int width, int height, TileProvider buffer){
|
||||
this.buffer = buffer;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.scaling = scaling;
|
||||
noise.setSeed(filter.seed);
|
||||
pnoise.setSeed((int)(filter.seed + 1));
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package io.anuke.mindustry.editor.generation;
|
||||
package io.anuke.mindustry.maps.filters;
|
||||
|
||||
import io.anuke.arc.collection.IntArray;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.editor.MapGenerateDialog.GenTile;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.SliderOption;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
@ -28,7 +28,7 @@ public class MedianFilter extends GenerateFilter{
|
||||
for(int y = -rad; y <= rad; y++){
|
||||
if(Mathf.dst2(x, y) > rad*rad) continue;
|
||||
|
||||
GenTile tile = in.tile((in.x + x) / in.scaling, (in.y + y) / in.scaling);
|
||||
GenTile tile = in.tile(in.x + x, in.y + y);
|
||||
blocks.add(tile.block);
|
||||
floors.add(tile.floor);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package io.anuke.mindustry.editor.generation;
|
||||
package io.anuke.mindustry.maps.filters;
|
||||
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
@ -7,7 +7,7 @@ import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.editor.MapGenerateDialog.*;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.*;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.*;
|
||||
import io.anuke.mindustry.graphics.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
@ -29,7 +29,7 @@ public class MirrorFilter extends GenerateFilter{
|
||||
v1.add(in.width/2f, in.height/2f);
|
||||
v2.add(in.width/2f, in.height/2f);
|
||||
|
||||
v3.set(in.x / in.scaling, in.y / in.scaling);
|
||||
v3.set(in.x, in.y);
|
||||
|
||||
if(!left(v1, v2, v3)){
|
||||
mirror(v3, v1.x, v1.y, v2.x, v2.y);
|
@ -1,12 +1,12 @@
|
||||
package io.anuke.mindustry.editor.generation;
|
||||
package io.anuke.mindustry.maps.filters;
|
||||
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.BlockOption;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.BlockOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
import static io.anuke.mindustry.editor.generation.FilterOption.floorsOnly;
|
||||
import static io.anuke.mindustry.editor.generation.FilterOption.wallsOnly;
|
||||
import static io.anuke.mindustry.maps.filters.FilterOption.floorsOnly;
|
||||
import static io.anuke.mindustry.maps.filters.FilterOption.wallsOnly;
|
||||
|
||||
public class NoiseFilter extends GenerateFilter{
|
||||
float scl = 40, threshold = 0.5f, octaves = 3f, falloff = 0.5f;
|
@ -1,11 +1,11 @@
|
||||
package io.anuke.mindustry.editor.generation;
|
||||
package io.anuke.mindustry.maps.filters;
|
||||
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
import static io.anuke.mindustry.editor.generation.FilterOption.BlockOption;
|
||||
import static io.anuke.mindustry.editor.generation.FilterOption.oresOnly;
|
||||
import static io.anuke.mindustry.maps.filters.FilterOption.BlockOption;
|
||||
import static io.anuke.mindustry.maps.filters.FilterOption.oresOnly;
|
||||
|
||||
public class OreFilter extends GenerateFilter{
|
||||
public float scl = 50, threshold = 0.72f, octaves = 3f, falloff = 0.4f;
|
@ -1,12 +1,12 @@
|
||||
package io.anuke.mindustry.editor.generation;
|
||||
package io.anuke.mindustry.maps.filters;
|
||||
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.BlockOption;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.BlockOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
import static io.anuke.mindustry.editor.generation.FilterOption.floorsOnly;
|
||||
import static io.anuke.mindustry.editor.generation.FilterOption.wallsOnly;
|
||||
import static io.anuke.mindustry.maps.filters.FilterOption.floorsOnly;
|
||||
import static io.anuke.mindustry.maps.filters.FilterOption.wallsOnly;
|
||||
|
||||
public class RiverNoiseFilter extends GenerateFilter{
|
||||
float scl = 40, threshold = 0f, threshold2 = 0.1f;
|
@ -1,11 +1,11 @@
|
||||
package io.anuke.mindustry.editor.generation;
|
||||
package io.anuke.mindustry.maps.filters;
|
||||
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.BlockOption;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.BlockOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
import static io.anuke.mindustry.editor.generation.FilterOption.*;
|
||||
import static io.anuke.mindustry.maps.filters.FilterOption.*;
|
||||
|
||||
public class ScatterFilter extends GenerateFilter{
|
||||
float chance = 0.1f;
|
@ -1,13 +1,13 @@
|
||||
package io.anuke.mindustry.editor.generation;
|
||||
package io.anuke.mindustry.maps.filters;
|
||||
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.BlockOption;
|
||||
import io.anuke.mindustry.editor.generation.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.BlockOption;
|
||||
import io.anuke.mindustry.maps.filters.FilterOption.SliderOption;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
import static io.anuke.mindustry.editor.generation.FilterOption.floorsOnly;
|
||||
import static io.anuke.mindustry.editor.generation.FilterOption.wallsOnly;
|
||||
import static io.anuke.mindustry.maps.filters.FilterOption.floorsOnly;
|
||||
import static io.anuke.mindustry.maps.filters.FilterOption.wallsOnly;
|
||||
|
||||
public class TerrainFilter extends GenerateFilter{
|
||||
float scl = 40, threshold = 0.9f, octaves = 3f, falloff = 0.5f, magnitude = 1f, circleScl = 2.1f;
|
||||
@ -28,7 +28,7 @@ public class TerrainFilter extends GenerateFilter{
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
float noise = noise(in.x, in.y, scl, magnitude, octaves, falloff) + Mathf.dst((float)in.x / in.editor.width(), (float)in.y / in.editor.height(), 0.5f, 0.5f) * circleScl;
|
||||
float noise = noise(in.x, in.y, scl, magnitude, octaves, falloff) + Mathf.dst((float)in.x / in.width, (float)in.y / in.height, 0.5f, 0.5f) * circleScl;
|
||||
|
||||
in.floor = floor;
|
||||
in.ore = Blocks.air;
|
Loading…
Reference in New Issue
Block a user