Added prototype planet sector land system

This commit is contained in:
Anuken 2020-01-20 12:05:26 -05:00
parent 01e7397df5
commit 27d6bf067e
17 changed files with 1902 additions and 1734 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 748 B

After

Width:  |  Height:  |  Size: 760 B

Before After
Before After

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 722 KiB

After

Width:  |  Height:  |  Size: 722 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 278 KiB

After

Width:  |  Height:  |  Size: 283 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 261 KiB

After

Width:  |  Height:  |  Size: 261 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 896 KiB

After

Width:  |  Height:  |  Size: 897 KiB

Before After
Before After

View file

@ -55,21 +55,26 @@ public class PlanetMesh{
/** Projects a tile onto a 4-corner square for use in map gen.
* Allocates a new object. Do not call in the main loop. */
public SectorRect projectTile(Ptile tile){
public SectorRect projectTile(Ptile base){
Vec3[] corners = new Vec3[base.corners.length];
for(int i = 0; i < corners.length; i++){
corners[i] = base.corners[i].v.cpy().setLength(radius);
}
Tmp.v33.setZero();
for(Corner c : tile.corners){
Tmp.v33.add(c.v);
for(Vec3 c : corners){
Tmp.v33.add(c);
}
//v33 is now the center of this shape
Vec3 center = Tmp.v33.scl(1f / tile.corners.length).cpy(vec);
Vec3 center = Tmp.v33.scl(1f / corners.length).cpy(vec);
//radius of circle
float radius = Tmp.v33.dst(tile.corners[0].v) * 0.9f;
float radius = Tmp.v33.dst(corners[0]) * 0.9f;
//get plane that these points are on
plane.set(tile.corners[0].v, tile.corners[2].v, tile.corners[4].v);
plane.set(corners[0], corners[2], corners[4]);
Vec3 planeTop = plane.project(center.cpy().add(0f, 1f, 0f)).sub(center).setLength(radius).add(center);
Vec3 planeRight = plane.project(center.cpy().rotate(Vec3.Y, 4f)).sub(center).setLength(radius).add(center);
Vec3 planeRight = plane.project(center.cpy().rotate(Vec3.Y, -4f)).sub(center).setLength(radius).add(center);
return new SectorRect(center, planeTop.sub(center), planeRight.sub(center));
}

View file

@ -7,10 +7,18 @@ import arc.graphics.g3d.*;
import arc.input.*;
import arc.math.geom.*;
import arc.util.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.game.*;
import mindustry.graphics.PlanetGrid.*;
import mindustry.graphics.PlanetMesh.*;
import mindustry.maps.generators.*;
import mindustry.maps.planet.*;
import mindustry.type.*;
import mindustry.world.*;
import static mindustry.Vars.*;
public class PlanetRenderer implements PlanetGenerator{
private final Color outlineColor = Pal.accent.cpy().a(0.7f);
@ -54,7 +62,10 @@ public class PlanetRenderer implements PlanetGenerator{
batch.flush(cam.combined(), Gl.triangleFan);
if(drawnRect){
SectorRect rect = outline.projectTile(tile);
SectorRect rect = planet.mesh.projectTile(tile);
rect.center.scl(outlineRad);
rect.right.scl(outlineRad);
rect.top.scl(outlineRad);
batch.color(Pal.place);
batch.vertex(rect.project(0, 0));
@ -65,6 +76,30 @@ public class PlanetRenderer implements PlanetGenerator{
batch.color(Pal.place);
batch.vertex(rect.project(0, 1));
batch.flush(cam.combined(), Gl.lineLoop);
SectorRect coords = planet.mesh.projectTile(tile);
if(Core.input.keyTap(KeyCode.SPACE)){
logic.reset();
Vars.world.loadGenerator(new Generator(250, 250){
@Override
public void generate(Tiles tiles){
TileGen gen = new TileGen();
tiles.each((x, y) -> {
gen.reset();
Vec3 position = coords.project(x / (float)width, y / (float)height);
planet.generator.generate(position, gen);
tiles.set(x, y, new Tile(x, y, gen.floor, gen.overlay, gen.block));
});
tiles.get(width/2, height/2).setBlock(Blocks.coreShard, Team.sharded);
}
});
state.set(State.playing);
logic.play();
ui.planet.hide();
}
}
}
@ -97,4 +132,9 @@ public class PlanetRenderer implements PlanetGenerator{
public Color getColor(Vec3 position){
return outlineColor;
}
@Override
public void generate(Vec3 position, TileGen tile){
}
}

View file

@ -156,7 +156,7 @@ public abstract class BasicGenerator extends RandomGenerator{
block = tiles.getn(x, y).block();
ore = tiles.getn(x, y).overlay();
r.get(x, y);
tiles.set(x, y, new Tile(x, y, floor.id, ore.id, block.id));
tiles.set(x, y, new Tile(x, y, floor, ore, block));
}
}
}

View file

@ -24,7 +24,7 @@ public abstract class RandomGenerator extends Generator{
block = Blocks.air;
ore = Blocks.air;
generate(x, y);
tiles.set(x, y, new Tile(x, y, floor.id, ore.id, block.id));
tiles.set(x, y, new Tile(x, y, floor, ore, block));
}
}

View file

@ -2,9 +2,10 @@ package mindustry.maps.planet;
import arc.graphics.*;
import arc.math.geom.*;
import mindustry.world.*;
public interface PlanetGenerator{
float getHeight(Vec3 position);
Color getColor(Vec3 position);
//void generate(Vec3 position, Tile tile);
void generate(Vec3 position, TileGen tile);
}

View file

@ -3,15 +3,28 @@ package mindustry.maps.planet;
import arc.graphics.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import arc.util.noise.*;
import mindustry.content.*;
import mindustry.world.*;
public class TestPlanetGenerator implements PlanetGenerator{
Pixmap pix = new Pixmap("planets/colors.png");
Pixmap pix;
Simplex noise = new Simplex();
int waterLevel = 5;
float water = waterLevel / (float)(pix.getHeight());
float water;
float scl = 5f;
Array<Block> blocks = Array.with(Blocks.sporeMoss, Blocks.moss, Blocks.ice, Blocks.snow, Blocks.sand, Blocks.darksand, Blocks.darksandWater, Blocks.darksandTaintedWater);
public TestPlanetGenerator(){
try{
pix = new Pixmap("planets/colors.png");
water = waterLevel / (float)(pix.getHeight());
}catch(Exception ignored){
}
}
@Override
public float getHeight(Vec3 position){
@ -35,6 +48,13 @@ public class TestPlanetGenerator implements PlanetGenerator{
height *= 1.2f;
height = Mathf.clamp(height);
return Tmp.c1.set(pix.getPixel((int)(temp * (pix.getWidth()-1)), (int)((1f-height) * (pix.getHeight()-1))));
Color color = Tmp.c1.set(pix.getPixel((int)(temp * (pix.getWidth()-1)), (int)((1f-height) * (pix.getHeight()-1))));
return blocks.min(c -> color.diff(c.color)).color;
}
@Override
public void generate(Vec3 position, TileGen tile){
Color color = getColor(position);
tile.floor = blocks.min(c -> color.diff(c.color));
}
}

View file

@ -37,17 +37,21 @@ public class Tile implements Position, TargetTrait{
block = floor = overlay = (Floor)Blocks.air;
}
public Tile(int x, int y, int floor, int overlay, int wall){
public Tile(int x, int y, Block floor, Block overlay, Block wall){
this.x = (short)x;
this.y = (short)y;
this.floor = (Floor)content.block(floor);
this.overlay = (Floor)content.block(overlay);
this.block = content.block(wall);
this.floor = (Floor)floor;
this.overlay = (Floor)overlay;
this.block = wall;
//update entity and create it if needed
changed();
}
public Tile(int x, int y, int floor, int overlay, int wall){
this(x, y, content.block(floor), content.block(overlay), content.block(wall));
}
/** Returns this tile's position as a {@link Pos}. */
public int pos(){
return Pos.get(x, y);

View file

@ -0,0 +1,19 @@
package mindustry.world;
import mindustry.content.*;
public class TileGen{
public Block floor;
public Block block ;
public Block overlay;
{
reset();
}
public void reset(){
floor = Blocks.stone;
block = Blocks.air;
overlay = Blocks.air;
}
}

View file

@ -1,5 +1,6 @@
package mindustry.world;
import arc.func.*;
import arc.util.ArcAnnotate.*;
import java.util.*;
@ -16,6 +17,14 @@ public class Tiles implements Iterable<Tile>{
this.height = height;
}
public void each(Intc2 cons){
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
cons.get(x, y);
}
}
}
/** fills this tile set with empty air tiles. */
public void fill(){
for(int i = 0; i < array.length; i++){

View file

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=43de3406deffdbeca22a2ff320362cd0129e2da6
archash=aaa08db6c5024c3213ae83cdbed2da9362eeded0

View file

@ -340,7 +340,7 @@ public class ApplicationTests{
world.beginMapLoad();
for(int x = 0; x < tiles.width(); x++){
for(int y = 0; y < tiles.height(); y++){
tiles.set(x, y, new Tile(x, y, Blocks.stone.id, (byte)0, (byte)0));
tiles.set(x, y, new Tile(x, y, Blocks.stone, Blocks.air, Blocks.air));
}
}
int i = 0;
@ -385,7 +385,7 @@ public class ApplicationTests{
void depositTest(Block block, Item item){
BaseUnit unit = UnitTypes.spirit.create(Team.derelict);
Tile tile = new Tile(0, 0, Blocks.air.id, (byte)0, block.id);
Tile tile = new Tile(0, 0, Blocks.air, Blocks.air, block);
int capacity = tile.block().itemCapacity;
assertNotNull(tile.entity, "Tile should have an entity, but does not: " + tile);