Changed level emitters to update only once when they tick

This commit is contained in:
Salomão
2021-03-16 22:58:22 -03:00
parent c58bebc346
commit e364603a5a
2 changed files with 67 additions and 27 deletions
+40 -25
View File
@@ -19,9 +19,9 @@
package appeng.me.cache;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.*;
import appeng.parts.automation.PartLevelEmitter;
import com.google.common.base.Preconditions;
import net.minecraft.crash.CrashReport;
@@ -46,6 +46,7 @@ public class TickManagerCache implements ITickManager
private final HashMap<IGridNode, TickTracker> alertable = new HashMap<>();
private final HashMap<IGridNode, TickTracker> sleeping = new HashMap<>();
private final HashMap<IGridNode, TickTracker> awake = new HashMap<>();
private final HashMap<IGridNode, TickTracker> laterTicker = new HashMap<>();
private final PriorityQueue<TickTracker> upcomingTicks = new PriorityQueue<>();
private long currentTick = 0;
@@ -86,7 +87,7 @@ public class TickManagerCache implements ITickManager
{
this.currentTick++;
while( !this.upcomingTicks.isEmpty() )
while ( !this.upcomingTicks.isEmpty() )
{
tt = this.upcomingTicks.peek();
@@ -99,36 +100,50 @@ public class TickManagerCache implements ITickManager
this.upcomingTicks.poll();
final int diff = (int) ( this.currentTick - tt.getLastTick() );
final TickRateModulation mod = tt.getGridTickable().tickingRequest( tt.getNode(), diff );
switch( mod )
if( tt.getGridTickable() instanceof PartLevelEmitter )
{
laterTicker.put( tt.getNode(), tt );
} else
{
case FASTER:
tt.setCurrentRate( tt.getCurrentRate() - 2 );
break;
case IDLE:
tt.setCurrentRate( tt.getRequest().maxTickRate );
break;
case SAME:
break;
case SLEEP:
this.sleepDevice( tt.getNode() );
break;
case SLOWER:
tt.setCurrentRate( tt.getCurrentRate() + 1 );
break;
case URGENT:
tt.setCurrentRate( 0 );
break;
default:
break;
}
final TickRateModulation mod = tt.getGridTickable().tickingRequest( tt.getNode(), diff );
switch ( mod )
{
case FASTER:
tt.setCurrentRate( tt.getCurrentRate() - 2 );
break;
case IDLE:
tt.setCurrentRate( tt.getRequest().maxTickRate );
break;
case SAME:
break;
case SLEEP:
this.sleepDevice( tt.getNode() );
break;
case SLOWER:
tt.setCurrentRate( tt.getCurrentRate() + 1 );
break;
case URGENT:
tt.setCurrentRate( 0 );
break;
default:
break;
}
}
if( this.awake.containsKey( tt.getNode() ) )
{
this.addToQueue( tt );
}
}
Iterator<Map.Entry<IGridNode, TickTracker>> ltIterator = laterTicker.entrySet().iterator();
while ( ltIterator.hasNext() )
{
Map.Entry<IGridNode, TickTracker> tickTracker = ltIterator.next();
tickTracker.getValue().getGridTickable().tickingRequest( tickTracker.getKey(), 1 );
ltIterator.remove();
}
}
catch( final Throwable t )
{