Minor cleanup / Tick reset fix
This commit is contained in:
@@ -2,89 +2,49 @@ package mindustry.world.modules;
|
||||
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
/** @deprecated why is it a module? literally two booleans, why did I think it was a good idea? yay, more pointers???
|
||||
* the braindead java "make everything a separate class" mentality
|
||||
* */
|
||||
@Deprecated
|
||||
public class ConsumeModule extends BlockModule{
|
||||
private boolean valid, optionalValid;
|
||||
private final Building entity;
|
||||
private final Building build;
|
||||
|
||||
public ConsumeModule(Building entity){
|
||||
this.entity = entity;
|
||||
public ConsumeModule(Building build){
|
||||
this.build = build;
|
||||
}
|
||||
|
||||
public BlockStatus status(){
|
||||
if(entity.enabledControlTime > 0 && !entity.enabled){
|
||||
return BlockStatus.logicDisable;
|
||||
}
|
||||
|
||||
if(!entity.shouldConsume()){
|
||||
return BlockStatus.noOutput;
|
||||
}
|
||||
|
||||
if(!valid || !entity.productionValid()){
|
||||
return BlockStatus.noInput;
|
||||
}
|
||||
|
||||
return BlockStatus.active;
|
||||
return build.status();
|
||||
}
|
||||
|
||||
public void update(){
|
||||
//everything is valid when cheating
|
||||
if(entity.cheating()){
|
||||
valid = optionalValid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
boolean prevValid = valid();
|
||||
valid = true;
|
||||
optionalValid = true;
|
||||
boolean docons = entity.shouldConsume() && entity.productionValid();
|
||||
|
||||
for(Consume cons : entity.block.consumes.all){
|
||||
if(cons.isOptional()) continue;
|
||||
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||
cons.update(entity);
|
||||
}
|
||||
|
||||
valid &= cons.valid(entity);
|
||||
}
|
||||
|
||||
for(Consume cons : entity.block.consumes.optionals){
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||
cons.update(entity);
|
||||
}
|
||||
|
||||
optionalValid &= cons.valid(entity);
|
||||
}
|
||||
build.updateConsumption();
|
||||
}
|
||||
|
||||
public void trigger(){
|
||||
for(Consume cons : entity.block.consumes.all){
|
||||
cons.trigger(entity);
|
||||
}
|
||||
build.consume();
|
||||
}
|
||||
|
||||
public boolean valid(){
|
||||
return valid && entity.shouldConsume() && entity.enabled;
|
||||
return build.consValid();
|
||||
}
|
||||
|
||||
public boolean canConsume(){
|
||||
return valid && entity.enabled;
|
||||
return build.canConsume();
|
||||
}
|
||||
|
||||
public boolean optionalValid(){
|
||||
return valid() && optionalValid && entity.enabled;
|
||||
return build.consOptionalValid();
|
||||
}
|
||||
|
||||
//hahahahahahahahahaha
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
write.bool(valid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read){
|
||||
valid = read.bool();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,51 +39,51 @@ public class ItemModule extends BlockModule{
|
||||
System.arraycopy(other.items, 0, items, 0, items.length);
|
||||
}
|
||||
|
||||
public void update(boolean showFlow){
|
||||
if(showFlow){
|
||||
//update the flow at 30fps at most
|
||||
if(flowTimer.get(1, pollScl)){
|
||||
public void updateFlow(){
|
||||
//update the flow at N fps at most
|
||||
if(flowTimer.get(1, pollScl)){
|
||||
|
||||
if(flow == null){
|
||||
if(cacheFlow == null || cacheFlow.length != 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();
|
||||
if(flow == null){
|
||||
if(cacheFlow == null || cacheFlow.length != items.length){
|
||||
cacheFlow = new WindowedMean[items.length];
|
||||
for(int i = 0; i < items.length; i++){
|
||||
cacheFlow[i] = new WindowedMean(windowSize);
|
||||
}
|
||||
|
||||
Arrays.fill(displayFlow, -1);
|
||||
|
||||
flow = cacheFlow;
|
||||
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();
|
||||
}
|
||||
|
||||
boolean updateFlow = flowTimer.get(30);
|
||||
Arrays.fill(displayFlow, -1);
|
||||
|
||||
for(int i = 0; i < items.length; i++){
|
||||
flow[i].add(cacheSums[i]);
|
||||
if(cacheSums[i] > 0){
|
||||
cacheBits.set(i);
|
||||
}
|
||||
cacheSums[i] = 0;
|
||||
flow = cacheFlow;
|
||||
}
|
||||
|
||||
if(updateFlow){
|
||||
displayFlow[i] = flow[i].hasEnoughData() ? flow[i].mean() / pollScl : -1;
|
||||
}
|
||||
boolean updateFlow = flowTimer.get(30);
|
||||
|
||||
for(int i = 0; i < items.length; i++){
|
||||
flow[i].add(cacheSums[i]);
|
||||
if(cacheSums[i] > 0){
|
||||
cacheBits.set(i);
|
||||
}
|
||||
cacheSums[i] = 0;
|
||||
|
||||
if(updateFlow){
|
||||
displayFlow[i] = flow[i].hasEnoughData() ? flow[i].mean() / pollScl : -1;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
flow = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void stopFlow(){
|
||||
flow = null;
|
||||
}
|
||||
|
||||
public int length(){
|
||||
return items.length;
|
||||
}
|
||||
|
||||
@@ -22,57 +22,53 @@ public class LiquidModule extends BlockModule{
|
||||
|
||||
private float[] liquids = new float[content.liquids().size];
|
||||
private Liquid current = content.liquid(0);
|
||||
private float total, smoothLiquid;
|
||||
private float total;
|
||||
|
||||
private @Nullable WindowedMean[] flow;
|
||||
|
||||
public void update(boolean showFlow){
|
||||
smoothLiquid = Mathf.lerpDelta(smoothLiquid, currentAmount(), 0.1f);
|
||||
|
||||
if(showFlow){
|
||||
|
||||
if(flowTimer.get(1, pollScl)){
|
||||
|
||||
if(flow == null){
|
||||
if(cacheFlow == null || cacheFlow.length != liquids.length){
|
||||
cacheFlow = new WindowedMean[liquids.length];
|
||||
for(int i = 0; i < liquids.length; i++){
|
||||
cacheFlow[i] = new WindowedMean(windowSize);
|
||||
}
|
||||
cacheSums = new float[liquids.length];
|
||||
displayFlow = new float[liquids.length];
|
||||
}else{
|
||||
for(int i = 0; i < liquids.length; i++){
|
||||
cacheFlow[i].reset();
|
||||
}
|
||||
Arrays.fill(cacheSums, 0);
|
||||
cacheBits.clear();
|
||||
public void updateFlow(){
|
||||
if(flowTimer.get(1, pollScl)){
|
||||
if(flow == null){
|
||||
if(cacheFlow == null || cacheFlow.length != liquids.length){
|
||||
cacheFlow = new WindowedMean[liquids.length];
|
||||
for(int i = 0; i < liquids.length; i++){
|
||||
cacheFlow[i] = new WindowedMean(windowSize);
|
||||
}
|
||||
|
||||
Arrays.fill(displayFlow, -1);
|
||||
|
||||
flow = cacheFlow;
|
||||
cacheSums = new float[liquids.length];
|
||||
displayFlow = new float[liquids.length];
|
||||
}else{
|
||||
for(int i = 0; i < liquids.length; i++){
|
||||
cacheFlow[i].reset();
|
||||
}
|
||||
Arrays.fill(cacheSums, 0);
|
||||
cacheBits.clear();
|
||||
}
|
||||
|
||||
boolean updateFlow = flowTimer.get(30);
|
||||
Arrays.fill(displayFlow, -1);
|
||||
|
||||
for(int i = 0; i < liquids.length; i++){
|
||||
flow[i].add(cacheSums[i]);
|
||||
if(cacheSums[i] > 0){
|
||||
cacheBits.set(i);
|
||||
}
|
||||
cacheSums[i] = 0;
|
||||
flow = cacheFlow;
|
||||
}
|
||||
|
||||
if(updateFlow){
|
||||
displayFlow[i] = flow[i].hasEnoughData() ? flow[i].mean() / pollScl : -1;
|
||||
}
|
||||
boolean updateFlow = flowTimer.get(30);
|
||||
|
||||
for(int i = 0; i < liquids.length; i++){
|
||||
flow[i].add(cacheSums[i]);
|
||||
if(cacheSums[i] > 0){
|
||||
cacheBits.set(i);
|
||||
}
|
||||
cacheSums[i] = 0;
|
||||
|
||||
if(updateFlow){
|
||||
displayFlow[i] = flow[i].hasEnoughData() ? flow[i].mean() / pollScl : -1;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
flow = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void stopFlow(){
|
||||
flow = null;
|
||||
}
|
||||
|
||||
/** @return current liquid's flow rate in u/s; any value < 0 means 'not ready'. */
|
||||
public float getFlowRate(Liquid liquid){
|
||||
return flow == null ? -1f : displayFlow[liquid.id] * 60;
|
||||
@@ -82,10 +78,6 @@ public class LiquidModule extends BlockModule{
|
||||
return flow != null && cacheBits.get(liquid.id);
|
||||
}
|
||||
|
||||
public float smoothAmount(){
|
||||
return smoothLiquid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated There is no good reason to check the total amount of liquids of a block.
|
||||
* Use of this method is almost certainly a bug; currentAmount() is probably what you want instead.
|
||||
|
||||
Reference in New Issue
Block a user