Added liquid-item junction
This commit is contained in:
@@ -8,6 +8,7 @@ import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.input.GestureDetector;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import com.badlogic.gdx.utils.reflect.Constructor;
|
||||
|
||||
@@ -466,7 +467,9 @@ public class Control extends Module{
|
||||
runWave();
|
||||
}
|
||||
|
||||
long time = TimeUtils.nanoTime();
|
||||
Entities.update();
|
||||
if(Timers.get("profileeu", profileTime)) Profiler.entityUpdate = TimeUtils.timeSinceNanos(time);
|
||||
}
|
||||
|
||||
if(!android){
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import static io.anuke.mindustry.Vars.profileTime;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.badlogic.gdx.graphics.profiling.GLProfiler;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
|
||||
import io.anuke.mindustry.GameState.State;
|
||||
import io.anuke.mindustry.io.Formatter;
|
||||
@@ -53,6 +56,7 @@ public class Mindustry extends ModuleCore {
|
||||
|
||||
@Override
|
||||
public void render(){
|
||||
long time = TimeUtils.nanoTime();
|
||||
|
||||
try{
|
||||
super.render();
|
||||
@@ -67,5 +71,7 @@ public class Mindustry extends ModuleCore {
|
||||
}
|
||||
|
||||
Inputs.update();
|
||||
|
||||
if(Timers.get("profilet", profileTime)) Profiler.total = TimeUtils.timeSinceNanos(time);
|
||||
}
|
||||
}
|
||||
|
||||
9
core/src/io/anuke/mindustry/Profiler.java
Normal file
9
core/src/io/anuke/mindustry/Profiler.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
public class Profiler{
|
||||
public static long total;
|
||||
public static long draw;
|
||||
public static long blockDraw;
|
||||
public static long entityDraw;
|
||||
public static long entityUpdate;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.profiling.GLProfiler;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
|
||||
import io.anuke.mindustry.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
@@ -112,8 +113,10 @@ public class Renderer extends RendererModule{
|
||||
if(Gdx.graphics.getWidth() / Core.cameraScale % 2 == 1){
|
||||
camera.position.add(-0.5f, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
long time = TimeUtils.nanoTime();
|
||||
drawDefault();
|
||||
if(Timers.get("profiled", profileTime)) Profiler.draw = TimeUtils.timeSinceNanos(time);
|
||||
|
||||
if(Vars.debug && Vars.debugGL && Timers.get("profile", 60)){
|
||||
UCore.log("shaders: " + GLProfiler.shaderSwitches,
|
||||
@@ -135,8 +138,13 @@ public class Renderer extends RendererModule{
|
||||
Graphics.surface("shield");
|
||||
Graphics.surface();
|
||||
|
||||
long time = TimeUtils.nanoTime();
|
||||
renderTiles();
|
||||
if(Timers.get("profilebd", profileTime)) Profiler.blockDraw = TimeUtils.timeSinceNanos(time);
|
||||
|
||||
time = TimeUtils.nanoTime();
|
||||
Entities.draw();
|
||||
if(Timers.get("profileed", profileTime)) Profiler.entityDraw = TimeUtils.timeSinceNanos(time);
|
||||
|
||||
drawShield();
|
||||
|
||||
@@ -237,11 +245,13 @@ public class Renderer extends RendererModule{
|
||||
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2) + 2;
|
||||
|
||||
boolean noshadows = Settings.getBool("noshadows");
|
||||
|
||||
|
||||
boolean drawTiles = true;
|
||||
|
||||
//0 = shadows
|
||||
//1 = normal blocks
|
||||
//2 = over blocks
|
||||
for(int l = (noshadows ? 1 : 0); l < 3; l++){
|
||||
for(int l = (noshadows ? 1 : 0); l < (drawTiles ? 3 : 0); l++){
|
||||
if(l == 0){
|
||||
Graphics.surface("shadow");
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class UI extends SceneModule{
|
||||
Draw.color();
|
||||
|
||||
TextureRegion back = Draw.region("background");
|
||||
float backscl = 5;
|
||||
float backscl = 5.5f;
|
||||
|
||||
Core.batch.draw(back, w/2 - back.getRegionWidth()*backscl/2, h/2 - back.getRegionHeight()*backscl/2,
|
||||
back.getRegionWidth()*backscl, back.getRegionHeight()*backscl);
|
||||
@@ -505,6 +505,30 @@ public class UI extends SceneModule{
|
||||
row();
|
||||
new label("[red]DEBUG MODE").scale(0.5f).left();
|
||||
}}.end();
|
||||
|
||||
new table(){{
|
||||
atop();
|
||||
new table("button"){{
|
||||
defaults().left().growX();
|
||||
atop();
|
||||
aleft();
|
||||
new label((StringSupplier)()->"[red]total: "
|
||||
+ String.format("%.1f", (float)Profiler.total/Profiler.total*100f)+ "% - " + Profiler.total).left();
|
||||
row();
|
||||
new label((StringSupplier)()->"[yellow]draw: "
|
||||
+ String.format("%.1f", (float)Profiler.draw/Profiler.total*100f)+ "% - " + Profiler.draw).left();
|
||||
row();
|
||||
new label((StringSupplier)()->"[green]blockDraw: "
|
||||
+ String.format("%.1f", (float)Profiler.blockDraw/Profiler.total*100f)+ "% - " + Profiler.blockDraw).left();
|
||||
row();
|
||||
new label((StringSupplier)()->"[blue]entityDraw: "
|
||||
+ String.format("%.1f", (float)Profiler.entityDraw/Profiler.total*100f)+ "% - " + Profiler.entityDraw).left();
|
||||
row();
|
||||
new label((StringSupplier)()->"[purple]entityUpdate: "
|
||||
+ String.format("%.1f", (float)Profiler.entityUpdate/Profiler.total*100f)+ "% - " + Profiler.entityUpdate).left();
|
||||
row();
|
||||
}}.width(400f).end();
|
||||
}}.end();
|
||||
}
|
||||
|
||||
//respawn background table
|
||||
|
||||
@@ -33,6 +33,8 @@ public class Vars{
|
||||
//TODO named save slots, possibly with a scroll dialog
|
||||
public static final int saveSlots = 4;
|
||||
|
||||
public static final int profileTime = 30;
|
||||
|
||||
//only if smoothCamera
|
||||
public static boolean snapCamera = true;
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ public enum Recipe{
|
||||
conduit(distribution, DistributionBlocks.conduit, stack(Item.steel, 1)),
|
||||
liquidrouter(distribution, DistributionBlocks.liquidrouter, stack(Item.steel, 2)),
|
||||
liquidjunction(distribution, DistributionBlocks.liquidjunction, stack(Item.steel, 2)),
|
||||
liquiditemjunction(distribution, DistributionBlocks.liquiditemjunction, stack(Item.steel, 1), stack(Item.iron, 1)),
|
||||
sorter(distribution, DistributionBlocks.sorter, stack(Item.steel, 2)),
|
||||
|
||||
turret(weapon, WeaponBlocks.turret, stack(Item.stone, 4)),
|
||||
|
||||
@@ -58,7 +58,7 @@ public class LevelDialog extends FloatingDialog{
|
||||
hide();
|
||||
Vars.control.playMap(selectedMap);
|
||||
});
|
||||
image.getImageCell().size(images);
|
||||
image.getImageCell().size(images).units(Unit.dp);
|
||||
maps.add(image).width(170).pad(4f).units(Unit.dp);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,8 +113,7 @@ public class Block{
|
||||
|
||||
/**
|
||||
* Tries to put this item into a nearby container, if there are no available
|
||||
* containers, it gets added to the block's inventory.
|
||||
*/
|
||||
* containers, it gets added to the block's inventory.*/
|
||||
protected void offloadNear(Tile tile, Item item){
|
||||
int i = tile.dump;
|
||||
int pdump = tile.dump;
|
||||
@@ -194,7 +193,7 @@ public class Block{
|
||||
|
||||
public void draw(Tile tile){
|
||||
//note: multiblocks do not support rotation
|
||||
if(width == 1 && height == 1){
|
||||
if(!isMultiblock()){
|
||||
Draw.rect(name(), tile.worldx(), tile.worldy(), rotate ? tile.rotation * 90 : 0);
|
||||
}else{
|
||||
//if multiblock, make sure to draw even block sizes offset, since the core block is at the BOTTOM LEFT
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.world;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
@@ -95,9 +94,9 @@ public class Generator{
|
||||
}
|
||||
|
||||
//preformance debugging
|
||||
if(Vector2.dst(pixmap.getWidth()/2, pixmap.getHeight()/2, x, y) < 30){
|
||||
//if(Vector2.dst(pixmap.getWidth()/2, pixmap.getHeight()/2, x, y) < 30){
|
||||
// block = Mathf.choose(ProductionBlocks.stonedrill, DistributionBlocks.conveyor);
|
||||
}
|
||||
//}
|
||||
|
||||
World.tile(x, y).setBlock(block);
|
||||
World.tile(x, y).setFloor(floor);
|
||||
|
||||
@@ -114,7 +114,7 @@ public class Tile{
|
||||
|
||||
public boolean breakable(){
|
||||
if(link == 0){
|
||||
return (block.destructible || block.breakable);
|
||||
return (block.destructible || block.breakable || block.update);
|
||||
}else{
|
||||
return getLinked().breakable();
|
||||
}
|
||||
|
||||
@@ -41,6 +41,11 @@ public class DistributionBlocks{
|
||||
},
|
||||
liquidjunction = new LiquidJunction("liquidjunction"){
|
||||
|
||||
},
|
||||
liquiditemjunction = new LiquidItemJunction("liquiditemjunction"){
|
||||
{
|
||||
formalName = "liquid-item junction";
|
||||
}
|
||||
},
|
||||
powerbooster = new PowerBooster("powerbooster"){
|
||||
{
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class LiquidItemJunction extends LiquidBlock{
|
||||
|
||||
public LiquidItemJunction(String name) {
|
||||
super(name);
|
||||
rotate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
Draw.rect(name(), tile.worldx(), tile.worldy(), tile.rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
int dir = source.relativeTo(tile.x, tile.y);
|
||||
dir = (dir+4)%4;
|
||||
Tile to = tile.getNearby()[dir];
|
||||
|
||||
((LiquidBlock)to.block()).handleLiquid(to, tile, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile dest, Tile source, Liquid liquid, float amount){
|
||||
int dir = source.relativeTo(dest.x, dest.y);
|
||||
dir = (dir+4)%4;
|
||||
|
||||
if(dir % 2 == 0) return false;
|
||||
|
||||
Tile to = dest.getNearby()[dir];
|
||||
return to != null && to.block() != this && to.block() instanceof LiquidBlock &&
|
||||
((LiquidBlock)to.block()).acceptLiquid(to, dest, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
int dir = source.relativeTo(tile.x, tile.y);
|
||||
Tile to = tile.getNearby()[dir];
|
||||
|
||||
Timers.run(15, ()->{
|
||||
if(to == null || to.entity == null) return;
|
||||
to.block().handleItem(item, to, tile);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||
int dir = source.relativeTo(dest.x, dest.y);
|
||||
|
||||
if(dir % 2 == 1) return false;
|
||||
|
||||
Tile to = dest.getNearby()[dir];
|
||||
return to != null && to.block().acceptItem(item, to, dest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description(){
|
||||
return "Serves as a junction for items and liquids.";
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,6 @@ public class Drill extends Block{
|
||||
public Drill(String name) {
|
||||
super(name);
|
||||
update = true;
|
||||
//update = false;
|
||||
//destructible = true;
|
||||
solid = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user