mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-13 01:07:30 +07:00
More accurate resource display / Server fix
This commit is contained in:
@ -267,6 +267,7 @@ project(":server"){
|
|||||||
|
|
||||||
dependencies{
|
dependencies{
|
||||||
compile project(":core")
|
compile project(":core")
|
||||||
|
compile arcModule("natives:natives-box2d-desktop")
|
||||||
compile arcModule("backends:backend-headless")
|
compile arcModule("backends:backend-headless")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -907,7 +907,7 @@ public class Blocks implements ContentList{
|
|||||||
requirements(Category.distribution, ItemStack.with(Items.copper, 1, Items.lead, 1, Items.titanium, 1));
|
requirements(Category.distribution, ItemStack.with(Items.copper, 1, Items.lead, 1, Items.titanium, 1));
|
||||||
health = 65;
|
health = 65;
|
||||||
speed = 0.08f;
|
speed = 0.08f;
|
||||||
displayedSpeed = 10f;
|
displayedSpeed = 11f;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
plastaniumConveyor = new StackConveyor("plastanium-conveyor"){{
|
plastaniumConveyor = new StackConveyor("plastanium-conveyor"){{
|
||||||
|
@ -823,13 +823,13 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
if(items != null){
|
if(items != null){
|
||||||
table.row();
|
table.row();
|
||||||
table.table(l -> {
|
table.table(l -> {
|
||||||
Bits presence = new Bits(content.items().size);
|
Bits current = new Bits();
|
||||||
l.left();
|
l.left();
|
||||||
|
|
||||||
Runnable rebuild = () -> {
|
Runnable rebuild = () -> {
|
||||||
l.clearChildren();
|
l.clearChildren();
|
||||||
for(Item item : content.items()){
|
for(Item item : content.items()){
|
||||||
if(items.flownBits() != null && items.flownBits().get(item.id)){
|
if(items.hasFlowItem(item)){
|
||||||
l.image(item.icon(Cicon.small)).padRight(3f);
|
l.image(item.icon(Cicon.small)).padRight(3f);
|
||||||
l.label(() -> items.getFlowRate(item) < 0 ? "..." : Strings.fixed(items.getFlowRate(item), 1) + ps).color(Color.lightGray);
|
l.label(() -> items.getFlowRate(item) < 0 ? "..." : Strings.fixed(items.getFlowRate(item), 1) + ps).color(Color.lightGray);
|
||||||
l.row();
|
l.row();
|
||||||
@ -839,9 +839,11 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
|
|
||||||
rebuild.run();
|
rebuild.run();
|
||||||
l.update(() -> {
|
l.update(() -> {
|
||||||
if(items.flownBits() != null && !presence.equals(items.flownBits())){
|
for(Item item : content.items()){
|
||||||
presence.set(items.flownBits());
|
if(items.hasFlowItem(item) && !current.get(item.id)){
|
||||||
rebuild.run();
|
current.set(item.id);
|
||||||
|
rebuild.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2,8 +2,8 @@ package mindustry.world.modules;
|
|||||||
|
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
|
import arc.util.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
|
|
||||||
@ -12,39 +12,71 @@ import java.util.*;
|
|||||||
import static mindustry.Vars.content;
|
import static mindustry.Vars.content;
|
||||||
|
|
||||||
public class ItemModule extends BlockModule{
|
public class ItemModule extends BlockModule{
|
||||||
private static final int windowSize = 10;
|
private static final int windowSize = 60 * 5;
|
||||||
|
private static WindowedMean[] cacheFlow;
|
||||||
|
private static float[] cacheSums;
|
||||||
|
private static float[] displayFlow;
|
||||||
|
private static Bits cacheBits = new Bits();
|
||||||
|
private static Interval flowTimer = new Interval(1);
|
||||||
|
|
||||||
protected int[] items = new int[content.items().size];
|
protected int[] items = new int[content.items().size];
|
||||||
protected int total;
|
protected int total;
|
||||||
protected int takeRotation;
|
protected int takeRotation;
|
||||||
|
|
||||||
private @Nullable WindowedMean[] flow;
|
private @Nullable WindowedMean[] flow;
|
||||||
private @Nullable Bits flownIds;
|
|
||||||
|
|
||||||
public void update(boolean showFlow){
|
public void update(boolean showFlow){
|
||||||
if(showFlow){
|
if(showFlow){
|
||||||
if(flow == null){
|
if(flow == null){
|
||||||
flow = new WindowedMean[items.length];
|
if(cacheFlow == null || cacheFlow.length != items.length){
|
||||||
flownIds = new Bits(items.length);
|
cacheFlow = new WindowedMean[items.length];
|
||||||
|
for(int i = 0; i < items.length; i++){
|
||||||
|
cacheFlow[i] = new WindowedMean(windowSize);
|
||||||
|
}
|
||||||
|
cacheSums = new float[items.length];
|
||||||
|
displayFlow = new float[items.length];
|
||||||
|
}else{
|
||||||
|
for(int i = 0; i < items.length; i++){
|
||||||
|
cacheFlow[i].reset();
|
||||||
|
}
|
||||||
|
Arrays.fill(cacheSums, 0);
|
||||||
|
cacheBits.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
Arrays.fill(displayFlow, -1);
|
||||||
|
|
||||||
|
flow = cacheFlow;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean updateFlow = flowTimer.get(30);
|
||||||
|
|
||||||
|
for(int i = 0; i < items.length; i++){
|
||||||
|
flow[i].addValue(cacheSums[i]);
|
||||||
|
if(cacheSums[i] > 0){
|
||||||
|
cacheBits.set(i);
|
||||||
|
}
|
||||||
|
cacheSums[i] = 0;
|
||||||
|
|
||||||
|
if(updateFlow){
|
||||||
|
displayFlow[i] = flow[i].hasEnoughData() ? flow[i].getMean() : -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
flow = null;
|
flow = null;
|
||||||
flownIds = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return a specific item's flow rate in items/s; any value < 0 means not ready.*/
|
/** @return a specific item's flow rate in items/s; any value < 0 means not ready.*/
|
||||||
public float getFlowRate(Item item){
|
public float getFlowRate(Item item){
|
||||||
if(flow == null || flow[item.id] == null || flow[item.id].getValueCount() <= 2){
|
if(flow == null) return -1f;
|
||||||
return - 1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO this isn't very accurate
|
return displayFlow[item.id] * 60;
|
||||||
return 60f / ((flow[item.id].getLatest() - flow[item.id].getOldest()) / (flow[item.id].getValueCount() - 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Bits flownBits(){
|
public boolean hasFlowItem(Item item){
|
||||||
return flownIds;
|
if(flow == null) return false;
|
||||||
|
|
||||||
|
return cacheBits.get(item.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void each(ItemConsumer cons){
|
public void each(ItemConsumer cons){
|
||||||
@ -142,19 +174,20 @@ public class ItemModule extends BlockModule{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void add(Item item, int amount){
|
public void add(Item item, int amount){
|
||||||
items[item.id] += amount;
|
add(item.id, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void add(int item, int amount){
|
||||||
|
items[item] += amount;
|
||||||
total += amount;
|
total += amount;
|
||||||
if(flow != null){
|
if(flow != null){
|
||||||
if(flow[item.id] == null) flow[item.id] = new WindowedMean(windowSize);
|
cacheSums[item] += amount;
|
||||||
flow[item.id].addValue(Time.time());
|
|
||||||
flownIds.set(item.id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAll(ItemModule items){
|
public void addAll(ItemModule items){
|
||||||
for(int i = 0; i < items.items.length; i++){
|
for(int i = 0; i < items.items.length; i++){
|
||||||
this.items[i] += items.items[i];
|
add(i, items.items[i]);
|
||||||
total += items.items[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +45,6 @@ task dist(type: Jar){
|
|||||||
exclude("zones/**")
|
exclude("zones/**")
|
||||||
exclude("icons/**")
|
exclude("icons/**")
|
||||||
exclude("bundles/**")
|
exclude("bundles/**")
|
||||||
if(!versionModifier.contains("steam")){
|
|
||||||
exclude("**.dll", "**.so", "**.dylib")
|
|
||||||
}
|
|
||||||
|
|
||||||
manifest{
|
manifest{
|
||||||
attributes 'Main-Class': project.mainClassName
|
attributes 'Main-Class': project.mainClassName
|
||||||
|
Reference in New Issue
Block a user