pick 97420a31d The big reformat of 2020
This commit is contained in:
+483
-576
File diff suppressed because it is too large
Load Diff
+535
-629
File diff suppressed because it is too large
Load Diff
+191
-234
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.me.cache;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -56,294 +55,252 @@ import appeng.me.helpers.MachineSource;
|
||||
import appeng.me.storage.ItemWatcher;
|
||||
import appeng.me.storage.NetworkInventoryHandler;
|
||||
|
||||
public class GridStorageCache implements IStorageGrid {
|
||||
|
||||
public class GridStorageCache implements IStorageGrid
|
||||
{
|
||||
private final IGrid myGrid;
|
||||
private final HashSet<ICellProvider> activeCellProviders = new HashSet<>();
|
||||
private final HashSet<ICellProvider> inactiveCellProviders = new HashSet<>();
|
||||
private final SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
|
||||
private final GenericInterestManager<ItemWatcher> interestManager = new GenericInterestManager<>(this.interests);
|
||||
private final HashMap<IGridNode, IStackWatcher> watchers = new HashMap<>();
|
||||
private Map<IStorageChannel<? extends IAEStack>, NetworkInventoryHandler<?>> storageNetworks;
|
||||
private Map<IStorageChannel<? extends IAEStack>, NetworkMonitor<?>> storageMonitors;
|
||||
|
||||
private final IGrid myGrid;
|
||||
private final HashSet<ICellProvider> activeCellProviders = new HashSet<>();
|
||||
private final HashSet<ICellProvider> inactiveCellProviders = new HashSet<>();
|
||||
private final SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
|
||||
private final GenericInterestManager<ItemWatcher> interestManager = new GenericInterestManager<>( this.interests );
|
||||
private final HashMap<IGridNode, IStackWatcher> watchers = new HashMap<>();
|
||||
private Map<IStorageChannel<? extends IAEStack>, NetworkInventoryHandler<?>> storageNetworks;
|
||||
private Map<IStorageChannel<? extends IAEStack>, NetworkMonitor<?>> storageMonitors;
|
||||
public GridStorageCache(final IGrid g) {
|
||||
this.myGrid = g;
|
||||
this.storageNetworks = new IdentityHashMap<>();
|
||||
this.storageMonitors = new IdentityHashMap<>();
|
||||
|
||||
public GridStorageCache( final IGrid g )
|
||||
{
|
||||
this.myGrid = g;
|
||||
this.storageNetworks = new IdentityHashMap<>();
|
||||
this.storageMonitors = new IdentityHashMap<>();
|
||||
AEApi.instance().storage().storageChannels()
|
||||
.forEach(channel -> this.storageMonitors.put(channel, new NetworkMonitor<>(this, channel)));
|
||||
}
|
||||
|
||||
AEApi.instance().storage().storageChannels().forEach( channel -> this.storageMonitors.put( channel, new NetworkMonitor<>( this, channel ) ) );
|
||||
}
|
||||
@Override
|
||||
public void onUpdateTick() {
|
||||
this.storageMonitors.forEach((channel, monitor) -> monitor.onTick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateTick()
|
||||
{
|
||||
this.storageMonitors.forEach( ( channel, monitor ) -> monitor.onTick() );
|
||||
}
|
||||
@Override
|
||||
public void removeNode(final IGridNode node, final IGridHost machine) {
|
||||
if (machine instanceof ICellContainer) {
|
||||
final ICellContainer cc = (ICellContainer) machine;
|
||||
final CellChangeTracker tracker = new CellChangeTracker();
|
||||
|
||||
@Override
|
||||
public void removeNode( final IGridNode node, final IGridHost machine )
|
||||
{
|
||||
if( machine instanceof ICellContainer )
|
||||
{
|
||||
final ICellContainer cc = (ICellContainer) machine;
|
||||
final CellChangeTracker tracker = new CellChangeTracker();
|
||||
this.removeCellProvider(cc, tracker);
|
||||
this.inactiveCellProviders.remove(cc);
|
||||
this.getGrid().postEvent(new MENetworkCellArrayUpdate());
|
||||
|
||||
this.removeCellProvider( cc, tracker );
|
||||
this.inactiveCellProviders.remove( cc );
|
||||
this.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
tracker.applyChanges();
|
||||
}
|
||||
|
||||
tracker.applyChanges();
|
||||
}
|
||||
if (machine instanceof IStackWatcherHost) {
|
||||
final IStackWatcher myWatcher = this.watchers.get(machine);
|
||||
|
||||
if( machine instanceof IStackWatcherHost )
|
||||
{
|
||||
final IStackWatcher myWatcher = this.watchers.get( machine );
|
||||
if (myWatcher != null) {
|
||||
myWatcher.reset();
|
||||
this.watchers.remove(machine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( myWatcher != null )
|
||||
{
|
||||
myWatcher.reset();
|
||||
this.watchers.remove( machine );
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void addNode(final IGridNode node, final IGridHost machine) {
|
||||
if (machine instanceof ICellContainer) {
|
||||
final ICellContainer cc = (ICellContainer) machine;
|
||||
this.inactiveCellProviders.add(cc);
|
||||
|
||||
@Override
|
||||
public void addNode( final IGridNode node, final IGridHost machine )
|
||||
{
|
||||
if( machine instanceof ICellContainer )
|
||||
{
|
||||
final ICellContainer cc = (ICellContainer) machine;
|
||||
this.inactiveCellProviders.add( cc );
|
||||
this.getGrid().postEvent(new MENetworkCellArrayUpdate());
|
||||
|
||||
this.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
if (node.isActive()) {
|
||||
final CellChangeTracker tracker = new CellChangeTracker();
|
||||
|
||||
if( node.isActive() )
|
||||
{
|
||||
final CellChangeTracker tracker = new CellChangeTracker();
|
||||
this.addCellProvider(cc, tracker);
|
||||
tracker.applyChanges();
|
||||
}
|
||||
}
|
||||
|
||||
this.addCellProvider( cc, tracker );
|
||||
tracker.applyChanges();
|
||||
}
|
||||
}
|
||||
if (machine instanceof IStackWatcherHost) {
|
||||
final IStackWatcherHost swh = (IStackWatcherHost) machine;
|
||||
final ItemWatcher iw = new ItemWatcher(this, swh);
|
||||
this.watchers.put(node, iw);
|
||||
swh.updateWatcher(iw);
|
||||
}
|
||||
}
|
||||
|
||||
if( machine instanceof IStackWatcherHost )
|
||||
{
|
||||
final IStackWatcherHost swh = (IStackWatcherHost) machine;
|
||||
final ItemWatcher iw = new ItemWatcher( this, swh );
|
||||
this.watchers.put( node, iw );
|
||||
swh.updateWatcher( iw );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onSplit(final IGridStorage storageB) {
|
||||
|
||||
@Override
|
||||
public void onSplit( final IGridStorage storageB )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onJoin(final IGridStorage storageB) {
|
||||
|
||||
@Override
|
||||
public void onJoin( final IGridStorage storageB )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void populateGridStorage(final IGridStorage storage) {
|
||||
|
||||
@Override
|
||||
public void populateGridStorage( final IGridStorage storage )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
public <T extends IAEStack<T>> IMEInventoryHandler<T> getInventoryHandler(IStorageChannel<T> channel) {
|
||||
return (IMEInventoryHandler<T>) this.storageNetworks.computeIfAbsent(channel, this::buildNetworkStorage);
|
||||
}
|
||||
|
||||
public <T extends IAEStack<T>> IMEInventoryHandler<T> getInventoryHandler( IStorageChannel<T> channel )
|
||||
{
|
||||
return (IMEInventoryHandler<T>) this.storageNetworks.computeIfAbsent( channel, this::buildNetworkStorage );
|
||||
}
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
|
||||
return (IMEMonitor<T>) this.storageMonitors.get(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory( IStorageChannel<T> channel )
|
||||
{
|
||||
return (IMEMonitor<T>) this.storageMonitors.get( channel );
|
||||
}
|
||||
private CellChangeTracker addCellProvider(final ICellProvider cc, final CellChangeTracker tracker) {
|
||||
if (this.inactiveCellProviders.contains(cc)) {
|
||||
this.inactiveCellProviders.remove(cc);
|
||||
this.activeCellProviders.add(cc);
|
||||
|
||||
private CellChangeTracker addCellProvider( final ICellProvider cc, final CellChangeTracker tracker )
|
||||
{
|
||||
if( this.inactiveCellProviders.contains( cc ) )
|
||||
{
|
||||
this.inactiveCellProviders.remove( cc );
|
||||
this.activeCellProviders.add( cc );
|
||||
final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource((IActionHost) cc)
|
||||
: new BaseActionSource();
|
||||
|
||||
final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource( (IActionHost) cc ) : new BaseActionSource();
|
||||
this.storageMonitors.forEach((channel, monitor) -> {
|
||||
for (final IMEInventoryHandler<?> h : cc.getCellArray(channel)) {
|
||||
tracker.postChanges(channel, 1, h, actionSrc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.storageMonitors.forEach( ( channel, monitor ) ->
|
||||
{
|
||||
for( final IMEInventoryHandler<?> h : cc.getCellArray( channel ) )
|
||||
{
|
||||
tracker.postChanges( channel, 1, h, actionSrc );
|
||||
}
|
||||
} );
|
||||
}
|
||||
return tracker;
|
||||
}
|
||||
|
||||
return tracker;
|
||||
}
|
||||
private CellChangeTracker removeCellProvider(final ICellProvider cc, final CellChangeTracker tracker) {
|
||||
if (this.activeCellProviders.contains(cc)) {
|
||||
this.activeCellProviders.remove(cc);
|
||||
this.inactiveCellProviders.add(cc);
|
||||
|
||||
private CellChangeTracker removeCellProvider( final ICellProvider cc, final CellChangeTracker tracker )
|
||||
{
|
||||
if( this.activeCellProviders.contains( cc ) )
|
||||
{
|
||||
this.activeCellProviders.remove( cc );
|
||||
this.inactiveCellProviders.add( cc );
|
||||
final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource((IActionHost) cc)
|
||||
: new BaseActionSource();
|
||||
|
||||
final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource( (IActionHost) cc ) : new BaseActionSource();
|
||||
this.storageMonitors.forEach((channel, monitor) -> {
|
||||
for (final IMEInventoryHandler<IAEItemStack> h : cc.getCellArray(channel)) {
|
||||
tracker.postChanges(channel, -1, h, actionSrc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.storageMonitors.forEach( ( channel, monitor ) ->
|
||||
{
|
||||
for( final IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( channel ) )
|
||||
{
|
||||
tracker.postChanges( channel, -1, h, actionSrc );
|
||||
}
|
||||
} );
|
||||
}
|
||||
return tracker;
|
||||
}
|
||||
|
||||
return tracker;
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void cellUpdate(final MENetworkCellArrayUpdate ev) {
|
||||
this.storageNetworks.clear();
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void cellUpdate( final MENetworkCellArrayUpdate ev )
|
||||
{
|
||||
this.storageNetworks.clear();
|
||||
final List<ICellProvider> ll = new ArrayList<ICellProvider>();
|
||||
ll.addAll(this.inactiveCellProviders);
|
||||
ll.addAll(this.activeCellProviders);
|
||||
|
||||
final List<ICellProvider> ll = new ArrayList<ICellProvider>();
|
||||
ll.addAll( this.inactiveCellProviders );
|
||||
ll.addAll( this.activeCellProviders );
|
||||
final CellChangeTracker tracker = new CellChangeTracker();
|
||||
|
||||
final CellChangeTracker tracker = new CellChangeTracker();
|
||||
for (final ICellProvider cc : ll) {
|
||||
boolean active = true;
|
||||
|
||||
for( final ICellProvider cc : ll )
|
||||
{
|
||||
boolean active = true;
|
||||
if (cc instanceof IActionHost) {
|
||||
final IGridNode node = ((IActionHost) cc).getActionableNode();
|
||||
if (node != null && node.isActive()) {
|
||||
active = true;
|
||||
} else {
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
|
||||
if( cc instanceof IActionHost )
|
||||
{
|
||||
final IGridNode node = ( (IActionHost) cc ).getActionableNode();
|
||||
if( node != null && node.isActive() )
|
||||
{
|
||||
active = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
if (active) {
|
||||
this.addCellProvider(cc, tracker);
|
||||
} else {
|
||||
this.removeCellProvider(cc, tracker);
|
||||
}
|
||||
}
|
||||
|
||||
if( active )
|
||||
{
|
||||
this.addCellProvider( cc, tracker );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.removeCellProvider( cc, tracker );
|
||||
}
|
||||
}
|
||||
this.storageMonitors.forEach((channel, monitor) -> monitor.forceUpdate());
|
||||
|
||||
this.storageMonitors.forEach( ( channel, monitor ) -> monitor.forceUpdate() );
|
||||
tracker.applyChanges();
|
||||
}
|
||||
|
||||
tracker.applyChanges();
|
||||
}
|
||||
private <T extends IAEStack<T>, C extends IStorageChannel<T>> void postChangesToNetwork(final C chan,
|
||||
final int upOrDown, final IItemList<T> availableItems, final IActionSource src) {
|
||||
this.storageMonitors.get(chan).postChange(upOrDown > 0, (Iterable) availableItems, src);
|
||||
}
|
||||
|
||||
private <T extends IAEStack<T>, C extends IStorageChannel<T>> void postChangesToNetwork( final C chan, final int upOrDown, final IItemList<T> availableItems, final IActionSource src )
|
||||
{
|
||||
this.storageMonitors.get( chan ).postChange( upOrDown > 0, (Iterable) availableItems, src );
|
||||
}
|
||||
private <T extends IAEStack<T>, C extends IStorageChannel<T>> NetworkInventoryHandler<T> buildNetworkStorage(
|
||||
final C chan) {
|
||||
final SecurityCache security = this.getGrid().getCache(ISecurityGrid.class);
|
||||
|
||||
private <T extends IAEStack<T>, C extends IStorageChannel<T>> NetworkInventoryHandler<T> buildNetworkStorage( final C chan )
|
||||
{
|
||||
final SecurityCache security = this.getGrid().getCache( ISecurityGrid.class );
|
||||
final NetworkInventoryHandler<T> storageNetwork = new NetworkInventoryHandler<>(chan, security);
|
||||
|
||||
final NetworkInventoryHandler<T> storageNetwork = new NetworkInventoryHandler<>( chan, security );
|
||||
for (final ICellProvider cc : this.activeCellProviders) {
|
||||
for (final IMEInventoryHandler<T> h : cc.getCellArray(chan)) {
|
||||
storageNetwork.addNewStorage(h);
|
||||
}
|
||||
}
|
||||
|
||||
for( final ICellProvider cc : this.activeCellProviders )
|
||||
{
|
||||
for( final IMEInventoryHandler<T> h : cc.getCellArray( chan ) )
|
||||
{
|
||||
storageNetwork.addNewStorage( h );
|
||||
}
|
||||
}
|
||||
return storageNetwork;
|
||||
}
|
||||
|
||||
return storageNetwork;
|
||||
}
|
||||
@Override
|
||||
public void postAlterationOfStoredItems(final IStorageChannel<?> chan, final Iterable<? extends IAEStack<?>> input,
|
||||
final IActionSource src) {
|
||||
this.storageMonitors.get(chan).postChange(true, (Iterable) input, src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postAlterationOfStoredItems( final IStorageChannel<?> chan, final Iterable<? extends IAEStack<?>> input, final IActionSource src )
|
||||
{
|
||||
this.storageMonitors.get( chan ).postChange( true, (Iterable) input, src );
|
||||
}
|
||||
@Override
|
||||
public void registerCellProvider(final ICellProvider provider) {
|
||||
this.inactiveCellProviders.add(provider);
|
||||
this.addCellProvider(provider, new CellChangeTracker()).applyChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCellProvider( final ICellProvider provider )
|
||||
{
|
||||
this.inactiveCellProviders.add( provider );
|
||||
this.addCellProvider( provider, new CellChangeTracker() ).applyChanges();
|
||||
}
|
||||
@Override
|
||||
public void unregisterCellProvider(final ICellProvider provider) {
|
||||
this.removeCellProvider(provider, new CellChangeTracker()).applyChanges();
|
||||
this.inactiveCellProviders.remove(provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterCellProvider( final ICellProvider provider )
|
||||
{
|
||||
this.removeCellProvider( provider, new CellChangeTracker() ).applyChanges();
|
||||
this.inactiveCellProviders.remove( provider );
|
||||
}
|
||||
public GenericInterestManager<ItemWatcher> getInterestManager() {
|
||||
return this.interestManager;
|
||||
}
|
||||
|
||||
public GenericInterestManager<ItemWatcher> getInterestManager()
|
||||
{
|
||||
return this.interestManager;
|
||||
}
|
||||
IGrid getGrid() {
|
||||
return this.myGrid;
|
||||
}
|
||||
|
||||
IGrid getGrid()
|
||||
{
|
||||
return this.myGrid;
|
||||
}
|
||||
private class CellChangeTrackerRecord<T extends IAEStack<T>> {
|
||||
|
||||
private class CellChangeTrackerRecord<T extends IAEStack<T>>
|
||||
{
|
||||
final IStorageChannel<T> channel;
|
||||
final int up_or_down;
|
||||
final IItemList<T> list;
|
||||
final IActionSource src;
|
||||
|
||||
final IStorageChannel<T> channel;
|
||||
final int up_or_down;
|
||||
final IItemList<T> list;
|
||||
final IActionSource src;
|
||||
public CellChangeTrackerRecord(final IStorageChannel<T> channel, final int i, final IMEInventoryHandler<T> h,
|
||||
final IActionSource actionSrc) {
|
||||
this.channel = channel;
|
||||
this.up_or_down = i;
|
||||
this.src = actionSrc;
|
||||
|
||||
public CellChangeTrackerRecord( final IStorageChannel<T> channel, final int i, final IMEInventoryHandler<T> h, final IActionSource actionSrc )
|
||||
{
|
||||
this.channel = channel;
|
||||
this.up_or_down = i;
|
||||
this.src = actionSrc;
|
||||
this.list = h.getAvailableItems(channel.createList());
|
||||
}
|
||||
|
||||
this.list = h.getAvailableItems( channel.createList() );
|
||||
}
|
||||
public void applyChanges() {
|
||||
GridStorageCache.this.postChangesToNetwork(this.channel, this.up_or_down, this.list, this.src);
|
||||
}
|
||||
}
|
||||
|
||||
public void applyChanges()
|
||||
{
|
||||
GridStorageCache.this.postChangesToNetwork( this.channel, this.up_or_down, this.list, this.src );
|
||||
}
|
||||
}
|
||||
private class CellChangeTracker<T extends IAEStack<T>> {
|
||||
|
||||
private class CellChangeTracker<T extends IAEStack<T>>
|
||||
{
|
||||
final List<CellChangeTrackerRecord<T>> data = new ArrayList<>();
|
||||
|
||||
final List<CellChangeTrackerRecord<T>> data = new ArrayList<>();
|
||||
public void postChanges(final IStorageChannel<T> channel, final int i, final IMEInventoryHandler<T> h,
|
||||
final IActionSource actionSrc) {
|
||||
this.data.add(new CellChangeTrackerRecord<T>(channel, i, h, actionSrc));
|
||||
}
|
||||
|
||||
public void postChanges( final IStorageChannel<T> channel, final int i, final IMEInventoryHandler<T> h, final IActionSource actionSrc )
|
||||
{
|
||||
this.data.add( new CellChangeTrackerRecord<T>( channel, i, h, actionSrc ) );
|
||||
}
|
||||
|
||||
public void applyChanges()
|
||||
{
|
||||
for( final CellChangeTrackerRecord<T> rec : this.data )
|
||||
{
|
||||
rec.applyChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void applyChanges() {
|
||||
for (final CellChangeTrackerRecord<T> rec : this.data) {
|
||||
rec.applyChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+189
-238
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.me.cache;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
@@ -45,291 +44,243 @@ import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.storage.ItemWatcher;
|
||||
|
||||
public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T> {
|
||||
@Nonnull
|
||||
private static final Deque<NetworkMonitor<?>> GLOBAL_DEPTH = Queues.newArrayDeque();
|
||||
|
||||
public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
{
|
||||
@Nonnull
|
||||
private static final Deque<NetworkMonitor<?>> GLOBAL_DEPTH = Queues.newArrayDeque();
|
||||
@Nonnull
|
||||
private final GridStorageCache myGridCache;
|
||||
@Nonnull
|
||||
private final IStorageChannel<T> myChannel;
|
||||
@Nonnull
|
||||
private final IItemList<T> cachedList;
|
||||
@Nonnull
|
||||
private final Map<IMEMonitorHandlerReceiver<T>, Object> listeners;
|
||||
|
||||
@Nonnull
|
||||
private final GridStorageCache myGridCache;
|
||||
@Nonnull
|
||||
private final IStorageChannel<T> myChannel;
|
||||
@Nonnull
|
||||
private final IItemList<T> cachedList;
|
||||
@Nonnull
|
||||
private final Map<IMEMonitorHandlerReceiver<T>, Object> listeners;
|
||||
private boolean sendEvent = false;
|
||||
private boolean hasChanged = false;
|
||||
@Nonnegative
|
||||
private int localDepthSemaphore = 0;
|
||||
|
||||
private boolean sendEvent = false;
|
||||
private boolean hasChanged = false;
|
||||
@Nonnegative
|
||||
private int localDepthSemaphore = 0;
|
||||
public NetworkMonitor(final GridStorageCache cache, final IStorageChannel<T> chan) {
|
||||
this.myGridCache = cache;
|
||||
this.myChannel = chan;
|
||||
this.cachedList = chan.createList();
|
||||
this.listeners = new HashMap<>();
|
||||
}
|
||||
|
||||
public NetworkMonitor( final GridStorageCache cache, final IStorageChannel<T> chan )
|
||||
{
|
||||
this.myGridCache = cache;
|
||||
this.myChannel = chan;
|
||||
this.cachedList = chan.createList();
|
||||
this.listeners = new HashMap<>();
|
||||
}
|
||||
@Override
|
||||
public void addListener(final IMEMonitorHandlerReceiver<T> l, final Object verificationToken) {
|
||||
this.listeners.put(l, verificationToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener( final IMEMonitorHandlerReceiver<T> l, final Object verificationToken )
|
||||
{
|
||||
this.listeners.put( l, verificationToken );
|
||||
}
|
||||
@Override
|
||||
public boolean canAccept(final T input) {
|
||||
return this.getHandler().canAccept(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept( final T input )
|
||||
{
|
||||
return this.getHandler().canAccept( input );
|
||||
}
|
||||
@Override
|
||||
public T extractItems(final T request, final Actionable mode, final IActionSource src) {
|
||||
if (mode == Actionable.SIMULATE) {
|
||||
return this.getHandler().extractItems(request, mode, src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems( final T request, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
if( mode == Actionable.SIMULATE )
|
||||
{
|
||||
return this.getHandler().extractItems( request, mode, src );
|
||||
}
|
||||
this.localDepthSemaphore++;
|
||||
final T leftover = this.getHandler().extractItems(request, mode, src);
|
||||
this.localDepthSemaphore--;
|
||||
|
||||
this.localDepthSemaphore++;
|
||||
final T leftover = this.getHandler().extractItems( request, mode, src );
|
||||
this.localDepthSemaphore--;
|
||||
if (this.localDepthSemaphore == 0) {
|
||||
this.monitorDifference(request.copy(), leftover, true, src);
|
||||
}
|
||||
|
||||
if( this.localDepthSemaphore == 0 )
|
||||
{
|
||||
this.monitorDifference( request.copy(), leftover, true, src );
|
||||
}
|
||||
return leftover;
|
||||
}
|
||||
|
||||
return leftover;
|
||||
}
|
||||
@Override
|
||||
public AccessRestriction getAccess() {
|
||||
return this.getHandler().getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getAccess()
|
||||
{
|
||||
return this.getHandler().getAccess();
|
||||
}
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems(final IItemList<T> out) {
|
||||
return this.getHandler().getAvailableItems(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems( final IItemList<T> out )
|
||||
{
|
||||
return this.getHandler().getAvailableItems( out );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<T> getChannel() {
|
||||
return this.getHandler().getChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<T> getChannel()
|
||||
{
|
||||
return this.getHandler().getChannel();
|
||||
}
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.getHandler().getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return this.getHandler().getPriority();
|
||||
}
|
||||
@Override
|
||||
public int getSlot() {
|
||||
return this.getHandler().getSlot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlot()
|
||||
{
|
||||
return this.getHandler().getSlot();
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public IItemList<T> getStorageList() {
|
||||
if (this.hasChanged) {
|
||||
this.hasChanged = false;
|
||||
this.cachedList.resetStatus();
|
||||
return this.getAvailableItems(this.cachedList);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IItemList<T> getStorageList()
|
||||
{
|
||||
if( this.hasChanged )
|
||||
{
|
||||
this.hasChanged = false;
|
||||
this.cachedList.resetStatus();
|
||||
return this.getAvailableItems( this.cachedList );
|
||||
}
|
||||
return this.cachedList;
|
||||
}
|
||||
|
||||
return this.cachedList;
|
||||
}
|
||||
@Override
|
||||
public T injectItems(final T input, final Actionable mode, final IActionSource src) {
|
||||
if (mode == Actionable.SIMULATE) {
|
||||
return this.getHandler().injectItems(input, mode, src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems( final T input, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
if( mode == Actionable.SIMULATE )
|
||||
{
|
||||
return this.getHandler().injectItems( input, mode, src );
|
||||
}
|
||||
this.localDepthSemaphore++;
|
||||
final T leftover = this.getHandler().injectItems(input, mode, src);
|
||||
this.localDepthSemaphore--;
|
||||
|
||||
this.localDepthSemaphore++;
|
||||
final T leftover = this.getHandler().injectItems( input, mode, src );
|
||||
this.localDepthSemaphore--;
|
||||
if (this.localDepthSemaphore == 0) {
|
||||
this.monitorDifference(input.copy(), leftover, false, src);
|
||||
}
|
||||
|
||||
if( this.localDepthSemaphore == 0 )
|
||||
{
|
||||
this.monitorDifference( input.copy(), leftover, false, src );
|
||||
}
|
||||
return leftover;
|
||||
}
|
||||
|
||||
return leftover;
|
||||
}
|
||||
@Override
|
||||
public boolean isPrioritized(final T input) {
|
||||
return this.getHandler().isPrioritized(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritized( final T input )
|
||||
{
|
||||
return this.getHandler().isPrioritized( input );
|
||||
}
|
||||
@Override
|
||||
public void removeListener(final IMEMonitorHandlerReceiver<T> l) {
|
||||
this.listeners.remove(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener( final IMEMonitorHandlerReceiver<T> l )
|
||||
{
|
||||
this.listeners.remove( l );
|
||||
}
|
||||
@Override
|
||||
public boolean validForPass(final int i) {
|
||||
return this.getHandler().validForPass(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validForPass( final int i )
|
||||
{
|
||||
return this.getHandler().validForPass( i );
|
||||
}
|
||||
@Nullable
|
||||
private IMEInventoryHandler<T> getHandler() {
|
||||
return this.myGridCache.getInventoryHandler(this.myChannel);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private IMEInventoryHandler<T> getHandler()
|
||||
{
|
||||
return this.myGridCache.getInventoryHandler( this.myChannel );
|
||||
}
|
||||
private Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> getListeners() {
|
||||
return this.listeners.entrySet().iterator();
|
||||
}
|
||||
|
||||
private Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> getListeners()
|
||||
{
|
||||
return this.listeners.entrySet().iterator();
|
||||
}
|
||||
private T monitorDifference(final IAEStack<T> original, final T leftOvers, final boolean extraction,
|
||||
final IActionSource src) {
|
||||
final T diff = original.copy();
|
||||
|
||||
private T monitorDifference( final IAEStack<T> original, final T leftOvers, final boolean extraction, final IActionSource src )
|
||||
{
|
||||
final T diff = original.copy();
|
||||
if (extraction) {
|
||||
diff.setStackSize(leftOvers == null ? 0 : -leftOvers.getStackSize());
|
||||
} else if (leftOvers != null) {
|
||||
diff.decStackSize(leftOvers.getStackSize());
|
||||
}
|
||||
|
||||
if( extraction )
|
||||
{
|
||||
diff.setStackSize( leftOvers == null ? 0 : -leftOvers.getStackSize() );
|
||||
}
|
||||
else if( leftOvers != null )
|
||||
{
|
||||
diff.decStackSize( leftOvers.getStackSize() );
|
||||
}
|
||||
if (diff.getStackSize() != 0) {
|
||||
this.postChangesToListeners(ImmutableList.of(diff), src);
|
||||
}
|
||||
|
||||
if( diff.getStackSize() != 0 )
|
||||
{
|
||||
this.postChangesToListeners( ImmutableList.of( diff ), src );
|
||||
}
|
||||
return leftOvers;
|
||||
}
|
||||
|
||||
return leftOvers;
|
||||
}
|
||||
private void notifyListenersOfChange(final Iterable<T> diff, final IActionSource src) {
|
||||
this.hasChanged = true;
|
||||
final Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.getListeners();
|
||||
|
||||
private void notifyListenersOfChange( final Iterable<T> diff, final IActionSource src )
|
||||
{
|
||||
this.hasChanged = true;
|
||||
final Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.getListeners();
|
||||
while (i.hasNext()) {
|
||||
final Entry<IMEMonitorHandlerReceiver<T>, Object> o = i.next();
|
||||
final IMEMonitorHandlerReceiver<T> receiver = o.getKey();
|
||||
if (receiver.isValid(o.getValue())) {
|
||||
receiver.postChange(this, diff, src);
|
||||
} else {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while( i.hasNext() )
|
||||
{
|
||||
final Entry<IMEMonitorHandlerReceiver<T>, Object> o = i.next();
|
||||
final IMEMonitorHandlerReceiver<T> receiver = o.getKey();
|
||||
if( receiver.isValid( o.getValue() ) )
|
||||
{
|
||||
receiver.postChange( this, diff, src );
|
||||
}
|
||||
else
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void postChangesToListeners(final Iterable<T> changes, final IActionSource src) {
|
||||
this.postChange(true, changes, src);
|
||||
}
|
||||
|
||||
private void postChangesToListeners( final Iterable<T> changes, final IActionSource src )
|
||||
{
|
||||
this.postChange( true, changes, src );
|
||||
}
|
||||
protected void postChange(final boolean add, final Iterable<T> changes, final IActionSource src) {
|
||||
if (this.localDepthSemaphore > 0 || GLOBAL_DEPTH.contains(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
protected void postChange( final boolean add, final Iterable<T> changes, final IActionSource src )
|
||||
{
|
||||
if( this.localDepthSemaphore > 0 || GLOBAL_DEPTH.contains( this ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
GLOBAL_DEPTH.push(this);
|
||||
this.localDepthSemaphore++;
|
||||
|
||||
GLOBAL_DEPTH.push( this );
|
||||
this.localDepthSemaphore++;
|
||||
this.sendEvent = true;
|
||||
|
||||
this.sendEvent = true;
|
||||
this.notifyListenersOfChange(changes, src);
|
||||
|
||||
this.notifyListenersOfChange( changes, src );
|
||||
for (final T changedItem : changes) {
|
||||
T difference = changedItem;
|
||||
|
||||
for( final T changedItem : changes )
|
||||
{
|
||||
T difference = changedItem;
|
||||
if (!add && changedItem != null) {
|
||||
difference = changedItem.copy();
|
||||
difference.setStackSize(-changedItem.getStackSize());
|
||||
}
|
||||
|
||||
if( !add && changedItem != null )
|
||||
{
|
||||
difference = changedItem.copy();
|
||||
difference.setStackSize( -changedItem.getStackSize() );
|
||||
}
|
||||
if (this.myGridCache.getInterestManager().containsKey(changedItem)) {
|
||||
final Collection<ItemWatcher> list = this.myGridCache.getInterestManager().get(changedItem);
|
||||
|
||||
if( this.myGridCache.getInterestManager().containsKey( changedItem ) )
|
||||
{
|
||||
final Collection<ItemWatcher> list = this.myGridCache.getInterestManager().get( changedItem );
|
||||
if (!list.isEmpty()) {
|
||||
IAEStack<T> fullStack = this.getStorageList().findPrecise(changedItem);
|
||||
|
||||
if( !list.isEmpty() )
|
||||
{
|
||||
IAEStack<T> fullStack = this.getStorageList().findPrecise( changedItem );
|
||||
if (fullStack == null) {
|
||||
fullStack = changedItem.copy();
|
||||
fullStack.setStackSize(0);
|
||||
}
|
||||
|
||||
if( fullStack == null )
|
||||
{
|
||||
fullStack = changedItem.copy();
|
||||
fullStack.setStackSize( 0 );
|
||||
}
|
||||
this.myGridCache.getInterestManager().enableTransactions();
|
||||
|
||||
this.myGridCache.getInterestManager().enableTransactions();
|
||||
for (final ItemWatcher iw : list) {
|
||||
iw.getHost().onStackChange(this.getStorageList(), fullStack, difference, src,
|
||||
this.getChannel());
|
||||
}
|
||||
|
||||
for( final ItemWatcher iw : list )
|
||||
{
|
||||
iw.getHost().onStackChange( this.getStorageList(), fullStack, difference, src, this.getChannel() );
|
||||
}
|
||||
this.myGridCache.getInterestManager().disableTransactions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.myGridCache.getInterestManager().disableTransactions();
|
||||
}
|
||||
}
|
||||
}
|
||||
final NetworkMonitor<?> last = GLOBAL_DEPTH.pop();
|
||||
this.localDepthSemaphore--;
|
||||
|
||||
final NetworkMonitor<?> last = GLOBAL_DEPTH.pop();
|
||||
this.localDepthSemaphore--;
|
||||
if (last != this) {
|
||||
throw new IllegalStateException("Invalid Access to Networked Storage API detected.");
|
||||
}
|
||||
}
|
||||
|
||||
if( last != this )
|
||||
{
|
||||
throw new IllegalStateException( "Invalid Access to Networked Storage API detected." );
|
||||
}
|
||||
}
|
||||
void forceUpdate() {
|
||||
this.hasChanged = true;
|
||||
|
||||
void forceUpdate()
|
||||
{
|
||||
this.hasChanged = true;
|
||||
final Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.getListeners();
|
||||
while (i.hasNext()) {
|
||||
final Entry<IMEMonitorHandlerReceiver<T>, Object> o = i.next();
|
||||
final IMEMonitorHandlerReceiver<T> receiver = o.getKey();
|
||||
|
||||
final Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.getListeners();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
final Entry<IMEMonitorHandlerReceiver<T>, Object> o = i.next();
|
||||
final IMEMonitorHandlerReceiver<T> receiver = o.getKey();
|
||||
if (receiver.isValid(o.getValue())) {
|
||||
receiver.onListUpdate();
|
||||
} else {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( receiver.isValid( o.getValue() ) )
|
||||
{
|
||||
receiver.onListUpdate();
|
||||
}
|
||||
else
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onTick()
|
||||
{
|
||||
if( this.sendEvent )
|
||||
{
|
||||
this.sendEvent = false;
|
||||
this.myGridCache.getGrid().postEvent( new MENetworkStorageEvent( this, this.myChannel ) );
|
||||
}
|
||||
}
|
||||
void onTick() {
|
||||
if (this.sendEvent) {
|
||||
this.sendEvent = false;
|
||||
this.myGridCache.getGrid().postEvent(new MENetworkStorageEvent(this, this.myChannel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+135
-181
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.me.cache;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
@@ -40,221 +39,176 @@ import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.parts.p2p.PartP2PTunnel;
|
||||
import appeng.parts.p2p.PartP2PTunnelME;
|
||||
|
||||
public class P2PCache implements IGridCache {
|
||||
private static final TunnelCollection<PartP2PTunnel> NULL_COLLECTION = new TunnelCollection<PartP2PTunnel>(null,
|
||||
null);
|
||||
|
||||
public class P2PCache implements IGridCache
|
||||
{
|
||||
private static final TunnelCollection<PartP2PTunnel> NULL_COLLECTION = new TunnelCollection<PartP2PTunnel>( null, null );
|
||||
private final IGrid myGrid;
|
||||
private final HashMap<Short, PartP2PTunnel> inputs = new HashMap<>();
|
||||
private final Multimap<Short, PartP2PTunnel> outputs = LinkedHashMultimap.create();
|
||||
private final Random frequencyGenerator;
|
||||
|
||||
private final IGrid myGrid;
|
||||
private final HashMap<Short, PartP2PTunnel> inputs = new HashMap<>();
|
||||
private final Multimap<Short, PartP2PTunnel> outputs = LinkedHashMultimap.create();
|
||||
private final Random frequencyGenerator;
|
||||
public P2PCache(final IGrid g) {
|
||||
this.myGrid = g;
|
||||
this.frequencyGenerator = new Random(g.hashCode());
|
||||
}
|
||||
|
||||
public P2PCache( final IGrid g )
|
||||
{
|
||||
this.myGrid = g;
|
||||
this.frequencyGenerator = new Random( g.hashCode() );
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void bootComplete(final MENetworkBootingStatusChange bootStatus) {
|
||||
final ITickManager tm = this.myGrid.getCache(ITickManager.class);
|
||||
for (final PartP2PTunnel me : this.inputs.values()) {
|
||||
if (me instanceof PartP2PTunnelME) {
|
||||
tm.wakeDevice(me.getGridNode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void bootComplete( final MENetworkBootingStatusChange bootStatus )
|
||||
{
|
||||
final ITickManager tm = this.myGrid.getCache( ITickManager.class );
|
||||
for( final PartP2PTunnel me : this.inputs.values() )
|
||||
{
|
||||
if( me instanceof PartP2PTunnelME )
|
||||
{
|
||||
tm.wakeDevice( me.getGridNode() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void bootComplete(final MENetworkPowerStatusChange power) {
|
||||
final ITickManager tm = this.myGrid.getCache(ITickManager.class);
|
||||
for (final PartP2PTunnel me : this.inputs.values()) {
|
||||
if (me instanceof PartP2PTunnelME) {
|
||||
tm.wakeDevice(me.getGridNode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void bootComplete( final MENetworkPowerStatusChange power )
|
||||
{
|
||||
final ITickManager tm = this.myGrid.getCache( ITickManager.class );
|
||||
for( final PartP2PTunnel me : this.inputs.values() )
|
||||
{
|
||||
if( me instanceof PartP2PTunnelME )
|
||||
{
|
||||
tm.wakeDevice( me.getGridNode() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onUpdateTick() {
|
||||
|
||||
@Override
|
||||
public void onUpdateTick()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void removeNode(final IGridNode node, final IGridHost machine) {
|
||||
if (machine instanceof PartP2PTunnel) {
|
||||
if (machine instanceof PartP2PTunnelME) {
|
||||
if (!node.hasFlag(GridFlags.REQUIRE_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNode( final IGridNode node, final IGridHost machine )
|
||||
{
|
||||
if( machine instanceof PartP2PTunnel )
|
||||
{
|
||||
if( machine instanceof PartP2PTunnelME )
|
||||
{
|
||||
if( !node.hasFlag( GridFlags.REQUIRE_CHANNEL ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
final PartP2PTunnel t = (PartP2PTunnel) machine;
|
||||
// AELog.info( "rmv-" + (t.output ? "output: " : "input: ") + t.freq );
|
||||
|
||||
final PartP2PTunnel t = (PartP2PTunnel) machine;
|
||||
// AELog.info( "rmv-" + (t.output ? "output: " : "input: ") + t.freq );
|
||||
if (t.isOutput()) {
|
||||
this.outputs.remove(t.getFrequency(), t);
|
||||
} else {
|
||||
this.inputs.remove(t.getFrequency());
|
||||
}
|
||||
|
||||
if( t.isOutput() )
|
||||
{
|
||||
this.outputs.remove( t.getFrequency(), t );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.inputs.remove( t.getFrequency() );
|
||||
}
|
||||
this.updateTunnel(t.getFrequency(), !t.isOutput(), false);
|
||||
}
|
||||
}
|
||||
|
||||
this.updateTunnel( t.getFrequency(), !t.isOutput(), false );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void addNode(final IGridNode node, final IGridHost machine) {
|
||||
if (machine instanceof PartP2PTunnel) {
|
||||
if (machine instanceof PartP2PTunnelME) {
|
||||
if (!node.hasFlag(GridFlags.REQUIRE_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode( final IGridNode node, final IGridHost machine )
|
||||
{
|
||||
if( machine instanceof PartP2PTunnel )
|
||||
{
|
||||
if( machine instanceof PartP2PTunnelME )
|
||||
{
|
||||
if( !node.hasFlag( GridFlags.REQUIRE_CHANNEL ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
final PartP2PTunnel t = (PartP2PTunnel) machine;
|
||||
// AELog.info( "add-" + (t.output ? "output: " : "input: ") + t.freq );
|
||||
|
||||
final PartP2PTunnel t = (PartP2PTunnel) machine;
|
||||
// AELog.info( "add-" + (t.output ? "output: " : "input: ") + t.freq );
|
||||
if (t.isOutput()) {
|
||||
this.outputs.put(t.getFrequency(), t);
|
||||
} else {
|
||||
this.inputs.put(t.getFrequency(), t);
|
||||
}
|
||||
|
||||
if( t.isOutput() )
|
||||
{
|
||||
this.outputs.put( t.getFrequency(), t );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.inputs.put( t.getFrequency(), t );
|
||||
}
|
||||
this.updateTunnel(t.getFrequency(), !t.isOutput(), false);
|
||||
}
|
||||
}
|
||||
|
||||
this.updateTunnel( t.getFrequency(), !t.isOutput(), false );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onSplit(final IGridStorage storageB) {
|
||||
|
||||
@Override
|
||||
public void onSplit( final IGridStorage storageB )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onJoin(final IGridStorage storageB) {
|
||||
|
||||
@Override
|
||||
public void onJoin( final IGridStorage storageB )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void populateGridStorage(final IGridStorage storage) {
|
||||
|
||||
@Override
|
||||
public void populateGridStorage( final IGridStorage storage )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
private void updateTunnel(final short freq, final boolean updateOutputs, final boolean configChange) {
|
||||
for (final PartP2PTunnel p : this.outputs.get(freq)) {
|
||||
if (configChange) {
|
||||
p.onTunnelConfigChange();
|
||||
}
|
||||
p.onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
private void updateTunnel( final short freq, final boolean updateOutputs, final boolean configChange )
|
||||
{
|
||||
for( final PartP2PTunnel p : this.outputs.get( freq ) )
|
||||
{
|
||||
if( configChange )
|
||||
{
|
||||
p.onTunnelConfigChange();
|
||||
}
|
||||
p.onTunnelNetworkChange();
|
||||
}
|
||||
final PartP2PTunnel in = this.inputs.get(freq);
|
||||
if (in != null) {
|
||||
if (configChange) {
|
||||
in.onTunnelConfigChange();
|
||||
}
|
||||
in.onTunnelNetworkChange();
|
||||
}
|
||||
}
|
||||
|
||||
final PartP2PTunnel in = this.inputs.get( freq );
|
||||
if( in != null )
|
||||
{
|
||||
if( configChange )
|
||||
{
|
||||
in.onTunnelConfigChange();
|
||||
}
|
||||
in.onTunnelNetworkChange();
|
||||
}
|
||||
}
|
||||
public void updateFreq(final PartP2PTunnel t, final short newFrequency) {
|
||||
if (this.outputs.containsValue(t)) {
|
||||
this.outputs.remove(t.getFrequency(), t);
|
||||
}
|
||||
|
||||
public void updateFreq( final PartP2PTunnel t, final short newFrequency )
|
||||
{
|
||||
if( this.outputs.containsValue( t ) )
|
||||
{
|
||||
this.outputs.remove( t.getFrequency(), t );
|
||||
}
|
||||
if (this.inputs.containsValue(t)) {
|
||||
this.inputs.remove(t.getFrequency());
|
||||
}
|
||||
|
||||
if( this.inputs.containsValue( t ) )
|
||||
{
|
||||
this.inputs.remove( t.getFrequency() );
|
||||
}
|
||||
t.setFrequency(newFrequency);
|
||||
|
||||
t.setFrequency( newFrequency );
|
||||
if (t.isOutput()) {
|
||||
this.outputs.put(t.getFrequency(), t);
|
||||
} else {
|
||||
this.inputs.put(t.getFrequency(), t);
|
||||
}
|
||||
|
||||
if( t.isOutput() )
|
||||
{
|
||||
this.outputs.put( t.getFrequency(), t );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.inputs.put( t.getFrequency(), t );
|
||||
}
|
||||
// AELog.info( "update-" + (t.output ? "output: " : "input: ") + t.freq );
|
||||
this.updateTunnel(t.getFrequency(), t.isOutput(), true);
|
||||
this.updateTunnel(t.getFrequency(), !t.isOutput(), true);
|
||||
}
|
||||
|
||||
// AELog.info( "update-" + (t.output ? "output: " : "input: ") + t.freq );
|
||||
this.updateTunnel( t.getFrequency(), t.isOutput(), true );
|
||||
this.updateTunnel( t.getFrequency(), !t.isOutput(), true );
|
||||
}
|
||||
public short newFrequency() {
|
||||
short newFrequency;
|
||||
int cycles = 0;
|
||||
|
||||
public short newFrequency()
|
||||
{
|
||||
short newFrequency;
|
||||
int cycles = 0;
|
||||
do {
|
||||
newFrequency = (short) this.frequencyGenerator.nextInt(1 << 16);
|
||||
cycles++;
|
||||
} while (newFrequency == 0 || this.inputs.containsKey(newFrequency));
|
||||
|
||||
do
|
||||
{
|
||||
newFrequency = (short) this.frequencyGenerator.nextInt( 1 << 16 );
|
||||
cycles++;
|
||||
}
|
||||
while( newFrequency == 0 || this.inputs.containsKey( newFrequency ) );
|
||||
if (cycles > 25) {
|
||||
AELog.debug("Generating a new P2P frequency '%1$d' took %2$d cycles", newFrequency, cycles);
|
||||
}
|
||||
|
||||
if( cycles > 25 )
|
||||
{
|
||||
AELog.debug( "Generating a new P2P frequency '%1$d' took %2$d cycles", newFrequency, cycles );
|
||||
}
|
||||
return newFrequency;
|
||||
}
|
||||
|
||||
return newFrequency;
|
||||
}
|
||||
public TunnelCollection<PartP2PTunnel> getOutputs(final short freq, final Class<? extends PartP2PTunnel> c) {
|
||||
final PartP2PTunnel in = this.inputs.get(freq);
|
||||
|
||||
public TunnelCollection<PartP2PTunnel> getOutputs( final short freq, final Class<? extends PartP2PTunnel> c )
|
||||
{
|
||||
final PartP2PTunnel in = this.inputs.get( freq );
|
||||
if (in == null) {
|
||||
return NULL_COLLECTION;
|
||||
}
|
||||
|
||||
if( in == null )
|
||||
{
|
||||
return NULL_COLLECTION;
|
||||
}
|
||||
final TunnelCollection<PartP2PTunnel> out = this.inputs.get(freq).getCollection(this.outputs.get(freq), c);
|
||||
|
||||
final TunnelCollection<PartP2PTunnel> out = this.inputs.get( freq ).getCollection( this.outputs.get( freq ), c );
|
||||
if (out == null) {
|
||||
return NULL_COLLECTION;
|
||||
}
|
||||
|
||||
if( out == null )
|
||||
{
|
||||
return NULL_COLLECTION;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public PartP2PTunnel getInput( final short freq )
|
||||
{
|
||||
return this.inputs.get( freq );
|
||||
}
|
||||
public PartP2PTunnel getInput(final short freq) {
|
||||
return this.inputs.get(freq);
|
||||
}
|
||||
}
|
||||
|
||||
+258
-331
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.me.cache;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
@@ -29,6 +28,8 @@ import java.util.Set;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridBlock;
|
||||
@@ -47,8 +48,6 @@ import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.core.stats.IAdvancementTrigger;
|
||||
import appeng.me.GridConnection;
|
||||
import appeng.me.GridNode;
|
||||
@@ -59,395 +58,323 @@ import appeng.me.pathfinding.IPathItem;
|
||||
import appeng.me.pathfinding.PathSegment;
|
||||
import appeng.tile.networking.TileController;
|
||||
|
||||
public class PathGridCache implements IPathingGrid {
|
||||
|
||||
public class PathGridCache implements IPathingGrid
|
||||
{
|
||||
private final List<PathSegment> active = new ArrayList<>();
|
||||
private final Set<TileController> controllers = new HashSet<>();
|
||||
private final Set<IGridNode> requireChannels = new HashSet<>();
|
||||
private final Set<IGridNode> blockDense = new HashSet<>();
|
||||
private final IGrid myGrid;
|
||||
private int channelsInUse = 0;
|
||||
private int channelsByBlocks = 0;
|
||||
private double channelPowerUsage = 0.0;
|
||||
private boolean recalculateControllerNextTick = true;
|
||||
private boolean updateNetwork = true;
|
||||
private boolean booting = false;
|
||||
private ControllerState controllerState = ControllerState.NO_CONTROLLER;
|
||||
private int ticksUntilReady = 20;
|
||||
private int lastChannels = 0;
|
||||
private HashSet<IPathItem> semiOpen = new HashSet<>();
|
||||
|
||||
private final List<PathSegment> active = new ArrayList<>();
|
||||
private final Set<TileController> controllers = new HashSet<>();
|
||||
private final Set<IGridNode> requireChannels = new HashSet<>();
|
||||
private final Set<IGridNode> blockDense = new HashSet<>();
|
||||
private final IGrid myGrid;
|
||||
private int channelsInUse = 0;
|
||||
private int channelsByBlocks = 0;
|
||||
private double channelPowerUsage = 0.0;
|
||||
private boolean recalculateControllerNextTick = true;
|
||||
private boolean updateNetwork = true;
|
||||
private boolean booting = false;
|
||||
private ControllerState controllerState = ControllerState.NO_CONTROLLER;
|
||||
private int ticksUntilReady = 20;
|
||||
private int lastChannels = 0;
|
||||
private HashSet<IPathItem> semiOpen = new HashSet<>();
|
||||
public PathGridCache(final IGrid g) {
|
||||
this.myGrid = g;
|
||||
}
|
||||
|
||||
public PathGridCache( final IGrid g )
|
||||
{
|
||||
this.myGrid = g;
|
||||
}
|
||||
@Override
|
||||
public void onUpdateTick() {
|
||||
if (this.recalculateControllerNextTick) {
|
||||
this.recalcController();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateTick()
|
||||
{
|
||||
if( this.recalculateControllerNextTick )
|
||||
{
|
||||
this.recalcController();
|
||||
}
|
||||
if (this.updateNetwork) {
|
||||
if (!this.booting) {
|
||||
this.myGrid.postEvent(new MENetworkBootingStatusChange());
|
||||
}
|
||||
|
||||
if( this.updateNetwork )
|
||||
{
|
||||
if( !this.booting )
|
||||
{
|
||||
this.myGrid.postEvent( new MENetworkBootingStatusChange() );
|
||||
}
|
||||
this.booting = true;
|
||||
this.updateNetwork = false;
|
||||
this.setChannelsInUse(0);
|
||||
|
||||
this.booting = true;
|
||||
this.updateNetwork = false;
|
||||
this.setChannelsInUse( 0 );
|
||||
if (!AEConfig.instance().isFeatureEnabled(AEFeature.CHANNELS)) {
|
||||
final int used = this.calculateRequiredChannels();
|
||||
|
||||
if( !AEConfig.instance().isFeatureEnabled( AEFeature.CHANNELS ) )
|
||||
{
|
||||
final int used = this.calculateRequiredChannels();
|
||||
final int nodes = this.myGrid.getNodes().size();
|
||||
this.ticksUntilReady = 20 + Math.max(0, nodes / 100 - 20);
|
||||
this.setChannelsByBlocks(nodes * used);
|
||||
this.setChannelPowerUsage(this.getChannelsByBlocks() / 128.0);
|
||||
|
||||
final int nodes = this.myGrid.getNodes().size();
|
||||
this.ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
|
||||
this.setChannelsByBlocks( nodes * used );
|
||||
this.setChannelPowerUsage( this.getChannelsByBlocks() / 128.0 );
|
||||
this.myGrid.getPivot().beginVisit(new AdHocChannelUpdater(used));
|
||||
} else if (this.controllerState == ControllerState.NO_CONTROLLER) {
|
||||
final int requiredChannels = this.calculateRequiredChannels();
|
||||
int used = requiredChannels;
|
||||
if (requiredChannels > 8) {
|
||||
used = 0;
|
||||
}
|
||||
|
||||
this.myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) );
|
||||
}
|
||||
else if( this.controllerState == ControllerState.NO_CONTROLLER )
|
||||
{
|
||||
final int requiredChannels = this.calculateRequiredChannels();
|
||||
int used = requiredChannels;
|
||||
if( requiredChannels > 8 )
|
||||
{
|
||||
used = 0;
|
||||
}
|
||||
final int nodes = this.myGrid.getNodes().size();
|
||||
this.setChannelsInUse(used);
|
||||
|
||||
final int nodes = this.myGrid.getNodes().size();
|
||||
this.setChannelsInUse( used );
|
||||
this.ticksUntilReady = 20 + Math.max(0, nodes / 100 - 20);
|
||||
this.setChannelsByBlocks(nodes * used);
|
||||
this.setChannelPowerUsage(this.getChannelsByBlocks() / 128.0);
|
||||
|
||||
this.ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
|
||||
this.setChannelsByBlocks( nodes * used );
|
||||
this.setChannelPowerUsage( this.getChannelsByBlocks() / 128.0 );
|
||||
this.myGrid.getPivot().beginVisit(new AdHocChannelUpdater(used));
|
||||
} else if (this.controllerState == ControllerState.CONTROLLER_CONFLICT) {
|
||||
this.ticksUntilReady = 20;
|
||||
this.myGrid.getPivot().beginVisit(new AdHocChannelUpdater(0));
|
||||
} else {
|
||||
final int nodes = this.myGrid.getNodes().size();
|
||||
this.ticksUntilReady = 20 + Math.max(0, nodes / 100 - 20);
|
||||
final HashSet<IPathItem> closedList = new HashSet<>();
|
||||
this.semiOpen = new HashSet<>();
|
||||
|
||||
this.myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) );
|
||||
}
|
||||
else if( this.controllerState == ControllerState.CONTROLLER_CONFLICT )
|
||||
{
|
||||
this.ticksUntilReady = 20;
|
||||
this.myGrid.getPivot().beginVisit( new AdHocChannelUpdater( 0 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
final int nodes = this.myGrid.getNodes().size();
|
||||
this.ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
|
||||
final HashSet<IPathItem> closedList = new HashSet<>();
|
||||
this.semiOpen = new HashSet<>();
|
||||
// myGrid.getPivot().beginVisit( new AdHocChannelUpdater( 0 )
|
||||
// );
|
||||
for (final IGridNode node : this.myGrid.getMachines(TileController.class)) {
|
||||
closedList.add((IPathItem) node);
|
||||
for (final IGridConnection gcc : node.getConnections()) {
|
||||
final GridConnection gc = (GridConnection) gcc;
|
||||
if (!(gc.getOtherSide(node).getMachine() instanceof TileController)) {
|
||||
final List<IPathItem> open = new ArrayList<>();
|
||||
closedList.add(gc);
|
||||
open.add(gc);
|
||||
gc.setControllerRoute((GridNode) node, true);
|
||||
this.active.add(new PathSegment(this, open, this.semiOpen, closedList));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// myGrid.getPivot().beginVisit( new AdHocChannelUpdater( 0 )
|
||||
// );
|
||||
for( final IGridNode node : this.myGrid.getMachines( TileController.class ) )
|
||||
{
|
||||
closedList.add( (IPathItem) node );
|
||||
for( final IGridConnection gcc : node.getConnections() )
|
||||
{
|
||||
final GridConnection gc = (GridConnection) gcc;
|
||||
if( !( gc.getOtherSide( node ).getMachine() instanceof TileController ) )
|
||||
{
|
||||
final List<IPathItem> open = new ArrayList<>();
|
||||
closedList.add( gc );
|
||||
open.add( gc );
|
||||
gc.setControllerRoute( (GridNode) node, true );
|
||||
this.active.add( new PathSegment( this, open, this.semiOpen, closedList ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!this.active.isEmpty() || this.ticksUntilReady > 0) {
|
||||
final Iterator<PathSegment> i = this.active.iterator();
|
||||
while (i.hasNext()) {
|
||||
final PathSegment pat = i.next();
|
||||
if (pat.step()) {
|
||||
pat.setDead(true);
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if( !this.active.isEmpty() || this.ticksUntilReady > 0 )
|
||||
{
|
||||
final Iterator<PathSegment> i = this.active.iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
final PathSegment pat = i.next();
|
||||
if( pat.step() )
|
||||
{
|
||||
pat.setDead( true );
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
this.ticksUntilReady--;
|
||||
|
||||
this.ticksUntilReady--;
|
||||
if (this.active.isEmpty() && this.ticksUntilReady <= 0) {
|
||||
if (this.controllerState == ControllerState.CONTROLLER_ONLINE) {
|
||||
final Iterator<TileController> controllerIterator = this.controllers.iterator();
|
||||
if (controllerIterator.hasNext()) {
|
||||
final TileController controller = controllerIterator.next();
|
||||
controller.getGridNode(AEPartLocation.INTERNAL).beginVisit(new ControllerChannelUpdater());
|
||||
}
|
||||
}
|
||||
|
||||
if( this.active.isEmpty() && this.ticksUntilReady <= 0 )
|
||||
{
|
||||
if( this.controllerState == ControllerState.CONTROLLER_ONLINE )
|
||||
{
|
||||
final Iterator<TileController> controllerIterator = this.controllers.iterator();
|
||||
if( controllerIterator.hasNext() )
|
||||
{
|
||||
final TileController controller = controllerIterator.next();
|
||||
controller.getGridNode( AEPartLocation.INTERNAL ).beginVisit( new ControllerChannelUpdater() );
|
||||
}
|
||||
}
|
||||
// check for achievements
|
||||
this.achievementPost();
|
||||
|
||||
// check for achievements
|
||||
this.achievementPost();
|
||||
this.booting = false;
|
||||
this.setChannelPowerUsage(this.getChannelsByBlocks() / 128.0);
|
||||
this.myGrid.postEvent(new MENetworkBootingStatusChange());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.booting = false;
|
||||
this.setChannelPowerUsage( this.getChannelsByBlocks() / 128.0 );
|
||||
this.myGrid.postEvent( new MENetworkBootingStatusChange() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void removeNode(final IGridNode gridNode, final IGridHost machine) {
|
||||
if (machine instanceof TileController) {
|
||||
this.controllers.remove(machine);
|
||||
this.recalculateControllerNextTick = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNode( final IGridNode gridNode, final IGridHost machine )
|
||||
{
|
||||
if( machine instanceof TileController )
|
||||
{
|
||||
this.controllers.remove( machine );
|
||||
this.recalculateControllerNextTick = true;
|
||||
}
|
||||
final EnumSet<GridFlags> flags = gridNode.getGridBlock().getFlags();
|
||||
|
||||
final EnumSet<GridFlags> flags = gridNode.getGridBlock().getFlags();
|
||||
if (flags.contains(GridFlags.REQUIRE_CHANNEL)) {
|
||||
this.requireChannels.remove(gridNode);
|
||||
}
|
||||
|
||||
if( flags.contains( GridFlags.REQUIRE_CHANNEL ) )
|
||||
{
|
||||
this.requireChannels.remove( gridNode );
|
||||
}
|
||||
if (flags.contains(GridFlags.CANNOT_CARRY_COMPRESSED)) {
|
||||
this.blockDense.remove(gridNode);
|
||||
}
|
||||
|
||||
if( flags.contains( GridFlags.CANNOT_CARRY_COMPRESSED ) )
|
||||
{
|
||||
this.blockDense.remove( gridNode );
|
||||
}
|
||||
this.repath();
|
||||
}
|
||||
|
||||
this.repath();
|
||||
}
|
||||
@Override
|
||||
public void addNode(final IGridNode gridNode, final IGridHost machine) {
|
||||
if (machine instanceof TileController) {
|
||||
this.controllers.add((TileController) machine);
|
||||
this.recalculateControllerNextTick = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode( final IGridNode gridNode, final IGridHost machine )
|
||||
{
|
||||
if( machine instanceof TileController )
|
||||
{
|
||||
this.controllers.add( (TileController) machine );
|
||||
this.recalculateControllerNextTick = true;
|
||||
}
|
||||
final EnumSet<GridFlags> flags = gridNode.getGridBlock().getFlags();
|
||||
|
||||
final EnumSet<GridFlags> flags = gridNode.getGridBlock().getFlags();
|
||||
if (flags.contains(GridFlags.REQUIRE_CHANNEL)) {
|
||||
this.requireChannels.add(gridNode);
|
||||
}
|
||||
|
||||
if( flags.contains( GridFlags.REQUIRE_CHANNEL ) )
|
||||
{
|
||||
this.requireChannels.add( gridNode );
|
||||
}
|
||||
if (flags.contains(GridFlags.CANNOT_CARRY_COMPRESSED)) {
|
||||
this.blockDense.add(gridNode);
|
||||
}
|
||||
|
||||
if( flags.contains( GridFlags.CANNOT_CARRY_COMPRESSED ) )
|
||||
{
|
||||
this.blockDense.add( gridNode );
|
||||
}
|
||||
this.repath();
|
||||
}
|
||||
|
||||
this.repath();
|
||||
}
|
||||
@Override
|
||||
public void onSplit(final IGridStorage storageB) {
|
||||
|
||||
@Override
|
||||
public void onSplit( final IGridStorage storageB )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onJoin(final IGridStorage storageB) {
|
||||
|
||||
@Override
|
||||
public void onJoin( final IGridStorage storageB )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void populateGridStorage(final IGridStorage storage) {
|
||||
|
||||
@Override
|
||||
public void populateGridStorage( final IGridStorage storage )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
private void recalcController() {
|
||||
this.recalculateControllerNextTick = false;
|
||||
final ControllerState old = this.controllerState;
|
||||
|
||||
private void recalcController()
|
||||
{
|
||||
this.recalculateControllerNextTick = false;
|
||||
final ControllerState old = this.controllerState;
|
||||
if (this.controllers.isEmpty()) {
|
||||
this.controllerState = ControllerState.NO_CONTROLLER;
|
||||
} else {
|
||||
final IGridNode startingNode = this.controllers.iterator().next().getGridNode(AEPartLocation.INTERNAL);
|
||||
if (startingNode == null) {
|
||||
this.controllerState = ControllerState.CONTROLLER_CONFLICT;
|
||||
return;
|
||||
}
|
||||
|
||||
if( this.controllers.isEmpty() )
|
||||
{
|
||||
this.controllerState = ControllerState.NO_CONTROLLER;
|
||||
}
|
||||
else
|
||||
{
|
||||
final IGridNode startingNode = this.controllers.iterator().next().getGridNode( AEPartLocation.INTERNAL );
|
||||
if( startingNode == null )
|
||||
{
|
||||
this.controllerState = ControllerState.CONTROLLER_CONFLICT;
|
||||
return;
|
||||
}
|
||||
final DimensionalCoord dc = startingNode.getGridBlock().getLocation();
|
||||
final ControllerValidator cv = new ControllerValidator(dc.x, dc.y, dc.z);
|
||||
|
||||
final DimensionalCoord dc = startingNode.getGridBlock().getLocation();
|
||||
final ControllerValidator cv = new ControllerValidator( dc.x, dc.y, dc.z );
|
||||
startingNode.beginVisit(cv);
|
||||
|
||||
startingNode.beginVisit( cv );
|
||||
if (cv.isValid() && cv.getFound() == this.controllers.size()) {
|
||||
this.controllerState = ControllerState.CONTROLLER_ONLINE;
|
||||
} else {
|
||||
this.controllerState = ControllerState.CONTROLLER_CONFLICT;
|
||||
}
|
||||
}
|
||||
|
||||
if( cv.isValid() && cv.getFound() == this.controllers.size() )
|
||||
{
|
||||
this.controllerState = ControllerState.CONTROLLER_ONLINE;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.controllerState = ControllerState.CONTROLLER_CONFLICT;
|
||||
}
|
||||
}
|
||||
if (old != this.controllerState) {
|
||||
this.myGrid.postEvent(new MENetworkControllerChange());
|
||||
}
|
||||
}
|
||||
|
||||
if( old != this.controllerState )
|
||||
{
|
||||
this.myGrid.postEvent( new MENetworkControllerChange() );
|
||||
}
|
||||
}
|
||||
private int calculateRequiredChannels() {
|
||||
this.semiOpen.clear();
|
||||
|
||||
private int calculateRequiredChannels()
|
||||
{
|
||||
this.semiOpen.clear();
|
||||
int depth = 0;
|
||||
for (final IGridNode nodes : this.requireChannels) {
|
||||
if (!this.semiOpen.contains(nodes)) {
|
||||
final IGridBlock gb = nodes.getGridBlock();
|
||||
final EnumSet<GridFlags> flags = gb.getFlags();
|
||||
|
||||
int depth = 0;
|
||||
for( final IGridNode nodes : this.requireChannels )
|
||||
{
|
||||
if( !this.semiOpen.contains( nodes ) )
|
||||
{
|
||||
final IGridBlock gb = nodes.getGridBlock();
|
||||
final EnumSet<GridFlags> flags = gb.getFlags();
|
||||
if (flags.contains(GridFlags.COMPRESSED_CHANNEL) && !this.blockDense.isEmpty()) {
|
||||
return 9;
|
||||
}
|
||||
|
||||
if( flags.contains( GridFlags.COMPRESSED_CHANNEL ) && !this.blockDense.isEmpty() )
|
||||
{
|
||||
return 9;
|
||||
}
|
||||
depth++;
|
||||
|
||||
depth++;
|
||||
if (flags.contains(GridFlags.MULTIBLOCK)) {
|
||||
final IGridMultiblock gmb = (IGridMultiblock) gb;
|
||||
final Iterator<IGridNode> i = gmb.getMultiblockNodes();
|
||||
while (i.hasNext()) {
|
||||
this.semiOpen.add((IPathItem) i.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( flags.contains( GridFlags.MULTIBLOCK ) )
|
||||
{
|
||||
final IGridMultiblock gmb = (IGridMultiblock) gb;
|
||||
final Iterator<IGridNode> i = gmb.getMultiblockNodes();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
this.semiOpen.add( (IPathItem) i.next() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return depth;
|
||||
}
|
||||
|
||||
return depth;
|
||||
}
|
||||
private void achievementPost() {
|
||||
if (this.lastChannels != this.getChannelsInUse() && AEConfig.instance().isFeatureEnabled(AEFeature.CHANNELS)) {
|
||||
final IAdvancementTrigger currentBracket = this.getAchievementBracket(this.getChannelsInUse());
|
||||
final IAdvancementTrigger lastBracket = this.getAchievementBracket(this.lastChannels);
|
||||
if (currentBracket != lastBracket && currentBracket != null) {
|
||||
for (final IGridNode n : this.requireChannels) {
|
||||
PlayerEntity player = AEApi.instance().registries().players().findPlayer(n.getPlayerID());
|
||||
if (player instanceof ServerPlayerEntity) {
|
||||
currentBracket.trigger((ServerPlayerEntity) player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastChannels = this.getChannelsInUse();
|
||||
}
|
||||
|
||||
private void achievementPost()
|
||||
{
|
||||
if( this.lastChannels != this.getChannelsInUse() && AEConfig.instance().isFeatureEnabled( AEFeature.CHANNELS ) )
|
||||
{
|
||||
final IAdvancementTrigger currentBracket = this.getAchievementBracket( this.getChannelsInUse() );
|
||||
final IAdvancementTrigger lastBracket = this.getAchievementBracket( this.lastChannels );
|
||||
if( currentBracket != lastBracket && currentBracket != null )
|
||||
{
|
||||
for( final IGridNode n : this.requireChannels )
|
||||
{
|
||||
PlayerEntity player = AEApi.instance().registries().players().findPlayer( n.getPlayerID() );
|
||||
if( player instanceof ServerPlayerEntity )
|
||||
{
|
||||
currentBracket.trigger( (ServerPlayerEntity) player );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastChannels = this.getChannelsInUse();
|
||||
}
|
||||
private IAdvancementTrigger getAchievementBracket(final int ch) {
|
||||
if (ch < 8) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private IAdvancementTrigger getAchievementBracket( final int ch )
|
||||
{
|
||||
if( ch < 8 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (ch < 128) {
|
||||
return AppEng.instance().getAdvancementTriggers().getNetworkApprentice();
|
||||
}
|
||||
|
||||
if( ch < 128 )
|
||||
{
|
||||
return AppEng.instance().getAdvancementTriggers().getNetworkApprentice();
|
||||
}
|
||||
if (ch < 2048) {
|
||||
return AppEng.instance().getAdvancementTriggers().getNetworkEngineer();
|
||||
}
|
||||
|
||||
if( ch < 2048 )
|
||||
{
|
||||
return AppEng.instance().getAdvancementTriggers().getNetworkEngineer();
|
||||
}
|
||||
return AppEng.instance().getAdvancementTriggers().getNetworkAdmin();
|
||||
}
|
||||
|
||||
return AppEng.instance().getAdvancementTriggers().getNetworkAdmin();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
void updateNodReq(final MENetworkChannelChanged ev) {
|
||||
final IGridNode gridNode = ev.node;
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
void updateNodReq( final MENetworkChannelChanged ev )
|
||||
{
|
||||
final IGridNode gridNode = ev.node;
|
||||
if (gridNode.getGridBlock().getFlags().contains(GridFlags.REQUIRE_CHANNEL)) {
|
||||
this.requireChannels.add(gridNode);
|
||||
} else {
|
||||
this.requireChannels.remove(gridNode);
|
||||
}
|
||||
|
||||
if( gridNode.getGridBlock().getFlags().contains( GridFlags.REQUIRE_CHANNEL ) )
|
||||
{
|
||||
this.requireChannels.add( gridNode );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.requireChannels.remove( gridNode );
|
||||
}
|
||||
this.repath();
|
||||
}
|
||||
|
||||
this.repath();
|
||||
}
|
||||
@Override
|
||||
public boolean isNetworkBooting() {
|
||||
return !this.booting && !this.active.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNetworkBooting()
|
||||
{
|
||||
return !this.booting && !this.active.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public ControllerState getControllerState() {
|
||||
return this.controllerState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ControllerState getControllerState()
|
||||
{
|
||||
return this.controllerState;
|
||||
}
|
||||
@Override
|
||||
public void repath() {
|
||||
// clean up...
|
||||
this.active.clear();
|
||||
|
||||
@Override
|
||||
public void repath()
|
||||
{
|
||||
// clean up...
|
||||
this.active.clear();
|
||||
this.setChannelsByBlocks(0);
|
||||
this.updateNetwork = true;
|
||||
}
|
||||
|
||||
this.setChannelsByBlocks( 0 );
|
||||
this.updateNetwork = true;
|
||||
}
|
||||
double getChannelPowerUsage() {
|
||||
return this.channelPowerUsage;
|
||||
}
|
||||
|
||||
double getChannelPowerUsage()
|
||||
{
|
||||
return this.channelPowerUsage;
|
||||
}
|
||||
private void setChannelPowerUsage(final double channelPowerUsage) {
|
||||
this.channelPowerUsage = channelPowerUsage;
|
||||
}
|
||||
|
||||
private void setChannelPowerUsage( final double channelPowerUsage )
|
||||
{
|
||||
this.channelPowerUsage = channelPowerUsage;
|
||||
}
|
||||
public int getChannelsByBlocks() {
|
||||
return this.channelsByBlocks;
|
||||
}
|
||||
|
||||
public int getChannelsByBlocks()
|
||||
{
|
||||
return this.channelsByBlocks;
|
||||
}
|
||||
public void setChannelsByBlocks(final int channelsByBlocks) {
|
||||
this.channelsByBlocks = channelsByBlocks;
|
||||
}
|
||||
|
||||
public void setChannelsByBlocks( final int channelsByBlocks )
|
||||
{
|
||||
this.channelsByBlocks = channelsByBlocks;
|
||||
}
|
||||
public int getChannelsInUse() {
|
||||
return this.channelsInUse;
|
||||
}
|
||||
|
||||
public int getChannelsInUse()
|
||||
{
|
||||
return this.channelsInUse;
|
||||
}
|
||||
|
||||
public void setChannelsInUse( final int channelsInUse )
|
||||
{
|
||||
this.channelsInUse = channelsInUse;
|
||||
}
|
||||
public void setChannelsInUse(final int channelsInUse) {
|
||||
this.channelsInUse = channelsInUse;
|
||||
}
|
||||
}
|
||||
|
||||
+99
-132
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.me.cache;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
@@ -41,162 +40,130 @@ import appeng.api.networking.security.ISecurityProvider;
|
||||
import appeng.core.worlddata.WorldData;
|
||||
import appeng.me.GridNode;
|
||||
|
||||
public class SecurityCache implements ISecurityGrid {
|
||||
|
||||
public class SecurityCache implements ISecurityGrid
|
||||
{
|
||||
private final IGrid myGrid;
|
||||
private final List<ISecurityProvider> securityProvider = new ArrayList<>();
|
||||
private final HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms = new HashMap<>();
|
||||
private long securityKey = -1;
|
||||
|
||||
private final IGrid myGrid;
|
||||
private final List<ISecurityProvider> securityProvider = new ArrayList<>();
|
||||
private final HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms = new HashMap<>();
|
||||
private long securityKey = -1;
|
||||
public SecurityCache(final IGrid g) {
|
||||
this.myGrid = g;
|
||||
}
|
||||
|
||||
public SecurityCache( final IGrid g )
|
||||
{
|
||||
this.myGrid = g;
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void updatePermissions(final MENetworkSecurityChange ev) {
|
||||
this.playerPerms.clear();
|
||||
if (this.securityProvider.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void updatePermissions( final MENetworkSecurityChange ev )
|
||||
{
|
||||
this.playerPerms.clear();
|
||||
if( this.securityProvider.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.securityProvider.get(0).readPermissions(this.playerPerms);
|
||||
}
|
||||
|
||||
this.securityProvider.get( 0 ).readPermissions( this.playerPerms );
|
||||
}
|
||||
public long getSecurityKey() {
|
||||
return this.securityKey;
|
||||
}
|
||||
|
||||
public long getSecurityKey()
|
||||
{
|
||||
return this.securityKey;
|
||||
}
|
||||
@Override
|
||||
public void onUpdateTick() {
|
||||
|
||||
@Override
|
||||
public void onUpdateTick()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void removeNode(final IGridNode gridNode, final IGridHost machine) {
|
||||
if (machine instanceof ISecurityProvider) {
|
||||
this.securityProvider.remove(machine);
|
||||
this.updateSecurityKey();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNode( final IGridNode gridNode, final IGridHost machine )
|
||||
{
|
||||
if( machine instanceof ISecurityProvider )
|
||||
{
|
||||
this.securityProvider.remove( machine );
|
||||
this.updateSecurityKey();
|
||||
}
|
||||
}
|
||||
private void updateSecurityKey() {
|
||||
final long lastCode = this.securityKey;
|
||||
|
||||
private void updateSecurityKey()
|
||||
{
|
||||
final long lastCode = this.securityKey;
|
||||
if (this.securityProvider.size() == 1) {
|
||||
this.securityKey = this.securityProvider.get(0).getSecurityKey();
|
||||
} else {
|
||||
this.securityKey = -1;
|
||||
}
|
||||
|
||||
if( this.securityProvider.size() == 1 )
|
||||
{
|
||||
this.securityKey = this.securityProvider.get( 0 ).getSecurityKey();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.securityKey = -1;
|
||||
}
|
||||
if (lastCode != this.securityKey) {
|
||||
this.getGrid().postEvent(new MENetworkSecurityChange());
|
||||
for (final IGridNode n : this.getGrid().getNodes()) {
|
||||
((GridNode) n).setLastSecurityKey(this.securityKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( lastCode != this.securityKey )
|
||||
{
|
||||
this.getGrid().postEvent( new MENetworkSecurityChange() );
|
||||
for( final IGridNode n : this.getGrid().getNodes() )
|
||||
{
|
||||
( (GridNode) n ).setLastSecurityKey( this.securityKey );
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void addNode(final IGridNode gridNode, final IGridHost machine) {
|
||||
if (machine instanceof ISecurityProvider) {
|
||||
this.securityProvider.add((ISecurityProvider) machine);
|
||||
this.updateSecurityKey();
|
||||
} else {
|
||||
((GridNode) gridNode).setLastSecurityKey(this.securityKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode( final IGridNode gridNode, final IGridHost machine )
|
||||
{
|
||||
if( machine instanceof ISecurityProvider )
|
||||
{
|
||||
this.securityProvider.add( (ISecurityProvider) machine );
|
||||
this.updateSecurityKey();
|
||||
}
|
||||
else
|
||||
{
|
||||
( (GridNode) gridNode ).setLastSecurityKey( this.securityKey );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onSplit(final IGridStorage destinationStorage) {
|
||||
|
||||
@Override
|
||||
public void onSplit( final IGridStorage destinationStorage )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onJoin(final IGridStorage sourceStorage) {
|
||||
|
||||
@Override
|
||||
public void onJoin( final IGridStorage sourceStorage )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void populateGridStorage(final IGridStorage destinationStorage) {
|
||||
|
||||
@Override
|
||||
public void populateGridStorage( final IGridStorage destinationStorage )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return this.securityProvider.size() == 1 && this.securityProvider.get(0).isSecurityEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable()
|
||||
{
|
||||
return this.securityProvider.size() == 1 && this.securityProvider.get( 0 ).isSecurityEnabled();
|
||||
}
|
||||
@Override
|
||||
public boolean hasPermission(final PlayerEntity player, final SecurityPermissions perm) {
|
||||
Preconditions.checkNotNull(player);
|
||||
Preconditions.checkNotNull(perm);
|
||||
|
||||
@Override
|
||||
public boolean hasPermission( final PlayerEntity player, final SecurityPermissions perm )
|
||||
{
|
||||
Preconditions.checkNotNull( player );
|
||||
Preconditions.checkNotNull( perm );
|
||||
final GameProfile profile = player.getGameProfile();
|
||||
final int playerID = WorldData.instance().playerData().getMePlayerId(profile);
|
||||
|
||||
final GameProfile profile = player.getGameProfile();
|
||||
final int playerID = WorldData.instance().playerData().getMePlayerId( profile );
|
||||
return this.hasPermission(playerID, perm);
|
||||
}
|
||||
|
||||
return this.hasPermission( playerID, perm );
|
||||
}
|
||||
@Override
|
||||
public boolean hasPermission(final int playerID, final SecurityPermissions perm) {
|
||||
if (this.isAvailable()) {
|
||||
final EnumSet<SecurityPermissions> perms = this.playerPerms.get(playerID);
|
||||
|
||||
@Override
|
||||
public boolean hasPermission( final int playerID, final SecurityPermissions perm )
|
||||
{
|
||||
if( this.isAvailable() )
|
||||
{
|
||||
final EnumSet<SecurityPermissions> perms = this.playerPerms.get( playerID );
|
||||
if (perms == null) {
|
||||
if (playerID == -1) // no default?
|
||||
{
|
||||
return false;
|
||||
} else {
|
||||
return this.hasPermission(-1, perm);
|
||||
}
|
||||
}
|
||||
|
||||
if( perms == null )
|
||||
{
|
||||
if( playerID == -1 ) // no default?
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.hasPermission( -1, perm );
|
||||
}
|
||||
}
|
||||
return perms.contains(perm);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return perms.contains( perm );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public int getOwner() {
|
||||
if (this.isAvailable()) {
|
||||
return this.securityProvider.get(0).getOwner();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOwner()
|
||||
{
|
||||
if( this.isAvailable() )
|
||||
{
|
||||
return this.securityProvider.get( 0 ).getOwner();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public IGrid getGrid()
|
||||
{
|
||||
return this.myGrid;
|
||||
}
|
||||
public IGrid getGrid() {
|
||||
return this.myGrid;
|
||||
}
|
||||
}
|
||||
|
||||
+149
-177
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.me.cache;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -37,223 +36,196 @@ import appeng.me.cluster.implementations.SpatialPylonCluster;
|
||||
import appeng.tile.spatial.TileSpatialIOPort;
|
||||
import appeng.tile.spatial.TileSpatialPylon;
|
||||
|
||||
public class SpatialPylonCache implements ISpatialCache {
|
||||
|
||||
public class SpatialPylonCache implements ISpatialCache
|
||||
{
|
||||
private final IGrid myGrid;
|
||||
private long powerRequired = 0;
|
||||
private double efficiency = 0.0;
|
||||
private DimensionalCoord captureMin;
|
||||
private DimensionalCoord captureMax;
|
||||
private boolean isValid = false;
|
||||
private List<TileSpatialIOPort> ioPorts = new ArrayList<>();
|
||||
private HashMap<SpatialPylonCluster, SpatialPylonCluster> clusters = new HashMap<>();
|
||||
|
||||
private final IGrid myGrid;
|
||||
private long powerRequired = 0;
|
||||
private double efficiency = 0.0;
|
||||
private DimensionalCoord captureMin;
|
||||
private DimensionalCoord captureMax;
|
||||
private boolean isValid = false;
|
||||
private List<TileSpatialIOPort> ioPorts = new ArrayList<>();
|
||||
private HashMap<SpatialPylonCluster, SpatialPylonCluster> clusters = new HashMap<>();
|
||||
public SpatialPylonCache(final IGrid g) {
|
||||
this.myGrid = g;
|
||||
}
|
||||
|
||||
public SpatialPylonCache( final IGrid g )
|
||||
{
|
||||
this.myGrid = g;
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void bootingRender(final MENetworkBootingStatusChange c) {
|
||||
this.reset(this.myGrid);
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void bootingRender( final MENetworkBootingStatusChange c )
|
||||
{
|
||||
this.reset( this.myGrid );
|
||||
}
|
||||
private void reset(final IGrid grid) {
|
||||
|
||||
private void reset( final IGrid grid )
|
||||
{
|
||||
this.clusters = new HashMap<>();
|
||||
this.ioPorts = new ArrayList<>();
|
||||
|
||||
this.clusters = new HashMap<>();
|
||||
this.ioPorts = new ArrayList<>();
|
||||
for (final IGridNode gm : grid.getMachines(TileSpatialIOPort.class)) {
|
||||
this.ioPorts.add((TileSpatialIOPort) gm.getMachine());
|
||||
}
|
||||
|
||||
for( final IGridNode gm : grid.getMachines( TileSpatialIOPort.class ) )
|
||||
{
|
||||
this.ioPorts.add( (TileSpatialIOPort) gm.getMachine() );
|
||||
}
|
||||
final IReadOnlyCollection<IGridNode> set = grid.getMachines(TileSpatialPylon.class);
|
||||
for (final IGridNode gm : set) {
|
||||
if (gm.meetsChannelRequirements()) {
|
||||
final SpatialPylonCluster c = ((TileSpatialPylon) gm.getMachine()).getCluster();
|
||||
if (c != null) {
|
||||
this.clusters.put(c, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final IReadOnlyCollection<IGridNode> set = grid.getMachines( TileSpatialPylon.class );
|
||||
for( final IGridNode gm : set )
|
||||
{
|
||||
if( gm.meetsChannelRequirements() )
|
||||
{
|
||||
final SpatialPylonCluster c = ( (TileSpatialPylon) gm.getMachine() ).getCluster();
|
||||
if( c != null )
|
||||
{
|
||||
this.clusters.put( c, c );
|
||||
}
|
||||
}
|
||||
}
|
||||
this.captureMax = null;
|
||||
this.captureMin = null;
|
||||
this.isValid = true;
|
||||
|
||||
this.captureMax = null;
|
||||
this.captureMin = null;
|
||||
this.isValid = true;
|
||||
int pylonBlocks = 0;
|
||||
for (final SpatialPylonCluster cl : this.clusters.values()) {
|
||||
if (this.captureMax == null) {
|
||||
this.captureMax = cl.getMax().copy();
|
||||
}
|
||||
if (this.captureMin == null) {
|
||||
this.captureMin = cl.getMin().copy();
|
||||
}
|
||||
|
||||
int pylonBlocks = 0;
|
||||
for( final SpatialPylonCluster cl : this.clusters.values() )
|
||||
{
|
||||
if( this.captureMax == null )
|
||||
{
|
||||
this.captureMax = cl.getMax().copy();
|
||||
}
|
||||
if( this.captureMin == null )
|
||||
{
|
||||
this.captureMin = cl.getMin().copy();
|
||||
}
|
||||
pylonBlocks += cl.tileCount();
|
||||
|
||||
pylonBlocks += cl.tileCount();
|
||||
this.captureMin.x = Math.min(this.captureMin.x, cl.getMin().x);
|
||||
this.captureMin.y = Math.min(this.captureMin.y, cl.getMin().y);
|
||||
this.captureMin.z = Math.min(this.captureMin.z, cl.getMin().z);
|
||||
|
||||
this.captureMin.x = Math.min( this.captureMin.x, cl.getMin().x );
|
||||
this.captureMin.y = Math.min( this.captureMin.y, cl.getMin().y );
|
||||
this.captureMin.z = Math.min( this.captureMin.z, cl.getMin().z );
|
||||
this.captureMax.x = Math.max(this.captureMax.x, cl.getMax().x);
|
||||
this.captureMax.y = Math.max(this.captureMax.y, cl.getMax().y);
|
||||
this.captureMax.z = Math.max(this.captureMax.z, cl.getMax().z);
|
||||
}
|
||||
|
||||
this.captureMax.x = Math.max( this.captureMax.x, cl.getMax().x );
|
||||
this.captureMax.y = Math.max( this.captureMax.y, cl.getMax().y );
|
||||
this.captureMax.z = Math.max( this.captureMax.z, cl.getMax().z );
|
||||
}
|
||||
double maxPower = 0;
|
||||
double minPower = 0;
|
||||
if (this.hasRegion()) {
|
||||
this.isValid = this.captureMax.x - this.captureMin.x > 1 && this.captureMax.y - this.captureMin.y > 1
|
||||
&& this.captureMax.z - this.captureMin.z > 1;
|
||||
|
||||
double maxPower = 0;
|
||||
double minPower = 0;
|
||||
if( this.hasRegion() )
|
||||
{
|
||||
this.isValid = this.captureMax.x - this.captureMin.x > 1 && this.captureMax.y - this.captureMin.y > 1 && this.captureMax.z - this.captureMin.z > 1;
|
||||
for (final SpatialPylonCluster cl : this.clusters.values()) {
|
||||
switch (cl.getCurrentAxis()) {
|
||||
case X:
|
||||
|
||||
for( final SpatialPylonCluster cl : this.clusters.values() )
|
||||
{
|
||||
switch( cl.getCurrentAxis() )
|
||||
{
|
||||
case X:
|
||||
this.isValid = this.isValid
|
||||
&& ((this.captureMax.y == cl.getMin().y || this.captureMin.y == cl.getMax().y)
|
||||
|| (this.captureMax.z == cl.getMin().z || this.captureMin.z == cl.getMax().z))
|
||||
&& ((this.captureMax.y == cl.getMax().y || this.captureMin.y == cl.getMin().y)
|
||||
|| (this.captureMax.z == cl.getMax().z || this.captureMin.z == cl.getMin().z));
|
||||
|
||||
this.isValid = this.isValid && ( ( this.captureMax.y == cl.getMin().y || this.captureMin.y == cl
|
||||
.getMax().y ) || ( this.captureMax.z == cl.getMin().z || this.captureMin.z == cl.getMax().z ) ) && ( ( this.captureMax.y == cl
|
||||
.getMax().y || this.captureMin.y == cl
|
||||
.getMin().y ) || ( this.captureMax.z == cl.getMax().z || this.captureMin.z == cl.getMin().z ) );
|
||||
break;
|
||||
case Y:
|
||||
|
||||
break;
|
||||
case Y:
|
||||
this.isValid = this.isValid
|
||||
&& ((this.captureMax.x == cl.getMin().x || this.captureMin.x == cl.getMax().x)
|
||||
|| (this.captureMax.z == cl.getMin().z || this.captureMin.z == cl.getMax().z))
|
||||
&& ((this.captureMax.x == cl.getMax().x || this.captureMin.x == cl.getMin().x)
|
||||
|| (this.captureMax.z == cl.getMax().z || this.captureMin.z == cl.getMin().z));
|
||||
|
||||
this.isValid = this.isValid && ( ( this.captureMax.x == cl.getMin().x || this.captureMin.x == cl
|
||||
.getMax().x ) || ( this.captureMax.z == cl.getMin().z || this.captureMin.z == cl.getMax().z ) ) && ( ( this.captureMax.x == cl
|
||||
.getMax().x || this.captureMin.x == cl
|
||||
.getMin().x ) || ( this.captureMax.z == cl.getMax().z || this.captureMin.z == cl.getMin().z ) );
|
||||
break;
|
||||
case Z:
|
||||
|
||||
break;
|
||||
case Z:
|
||||
this.isValid = this.isValid
|
||||
&& ((this.captureMax.y == cl.getMin().y || this.captureMin.y == cl.getMax().y)
|
||||
|| (this.captureMax.x == cl.getMin().x || this.captureMin.x == cl.getMax().x))
|
||||
&& ((this.captureMax.y == cl.getMax().y || this.captureMin.y == cl.getMin().y)
|
||||
|| (this.captureMax.x == cl.getMax().x || this.captureMin.x == cl.getMin().x));
|
||||
|
||||
this.isValid = this.isValid && ( ( this.captureMax.y == cl.getMin().y || this.captureMin.y == cl
|
||||
.getMax().y ) || ( this.captureMax.x == cl.getMin().x || this.captureMin.x == cl.getMax().x ) ) && ( ( this.captureMax.y == cl
|
||||
.getMax().y || this.captureMin.y == cl
|
||||
.getMin().y ) || ( this.captureMax.x == cl.getMax().x || this.captureMin.x == cl.getMin().x ) );
|
||||
break;
|
||||
case UNFORMED:
|
||||
this.isValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case UNFORMED:
|
||||
this.isValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
final int reqX = this.captureMax.x - this.captureMin.x;
|
||||
final int reqY = this.captureMax.y - this.captureMin.y;
|
||||
final int reqZ = this.captureMax.z - this.captureMin.z;
|
||||
final int requirePylonBlocks = Math.max(6, ((reqX * reqZ + reqX * reqY + reqY * reqZ) * 3) / 8);
|
||||
|
||||
final int reqX = this.captureMax.x - this.captureMin.x;
|
||||
final int reqY = this.captureMax.y - this.captureMin.y;
|
||||
final int reqZ = this.captureMax.z - this.captureMin.z;
|
||||
final int requirePylonBlocks = Math.max( 6, ( ( reqX * reqZ + reqX * reqY + reqY * reqZ ) * 3 ) / 8 );
|
||||
this.efficiency = (double) pylonBlocks / (double) requirePylonBlocks;
|
||||
|
||||
this.efficiency = (double) pylonBlocks / (double) requirePylonBlocks;
|
||||
if (this.efficiency > 1.0) {
|
||||
this.efficiency = 1.0;
|
||||
}
|
||||
if (this.efficiency < 0.0) {
|
||||
this.efficiency = 0.0;
|
||||
}
|
||||
|
||||
if( this.efficiency > 1.0 )
|
||||
{
|
||||
this.efficiency = 1.0;
|
||||
}
|
||||
if( this.efficiency < 0.0 )
|
||||
{
|
||||
this.efficiency = 0.0;
|
||||
}
|
||||
minPower = (double) reqX * (double) reqY * reqZ * AEConfig.instance().getSpatialPowerMultiplier();
|
||||
maxPower = Math.pow(minPower, AEConfig.instance().getSpatialPowerExponent());
|
||||
}
|
||||
|
||||
minPower = (double) reqX * (double) reqY * reqZ * AEConfig.instance().getSpatialPowerMultiplier();
|
||||
maxPower = Math.pow( minPower, AEConfig.instance().getSpatialPowerExponent() );
|
||||
}
|
||||
final double affective_efficiency = Math.pow(this.efficiency, 0.25);
|
||||
this.powerRequired = (long) (affective_efficiency * minPower + (1.0 - affective_efficiency) * maxPower);
|
||||
|
||||
final double affective_efficiency = Math.pow( this.efficiency, 0.25 );
|
||||
this.powerRequired = (long) ( affective_efficiency * minPower + ( 1.0 - affective_efficiency ) * maxPower );
|
||||
for (final SpatialPylonCluster cl : this.clusters.values()) {
|
||||
final boolean myWasValid = cl.isValid();
|
||||
cl.setValid(this.isValid);
|
||||
if (myWasValid != this.isValid) {
|
||||
cl.updateStatus(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final SpatialPylonCluster cl : this.clusters.values() )
|
||||
{
|
||||
final boolean myWasValid = cl.isValid();
|
||||
cl.setValid( this.isValid );
|
||||
if( myWasValid != this.isValid )
|
||||
{
|
||||
cl.updateStatus( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean hasRegion() {
|
||||
return this.captureMin != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRegion()
|
||||
{
|
||||
return this.captureMin != null;
|
||||
}
|
||||
@Override
|
||||
public boolean isValidRegion() {
|
||||
return this.hasRegion() && this.isValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidRegion()
|
||||
{
|
||||
return this.hasRegion() && this.isValid;
|
||||
}
|
||||
@Override
|
||||
public DimensionalCoord getMin() {
|
||||
return this.captureMin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getMin()
|
||||
{
|
||||
return this.captureMin;
|
||||
}
|
||||
@Override
|
||||
public DimensionalCoord getMax() {
|
||||
return this.captureMax;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getMax()
|
||||
{
|
||||
return this.captureMax;
|
||||
}
|
||||
@Override
|
||||
public long requiredPower() {
|
||||
return this.powerRequired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long requiredPower()
|
||||
{
|
||||
return this.powerRequired;
|
||||
}
|
||||
@Override
|
||||
public float currentEfficiency() {
|
||||
return (float) this.efficiency * 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float currentEfficiency()
|
||||
{
|
||||
return (float) this.efficiency * 100;
|
||||
}
|
||||
@Override
|
||||
public void onUpdateTick() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateTick()
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void removeNode(final IGridNode node, final IGridHost machine) {
|
||||
|
||||
@Override
|
||||
public void removeNode( final IGridNode node, final IGridHost machine )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void addNode(final IGridNode node, final IGridHost machine) {
|
||||
|
||||
@Override
|
||||
public void addNode( final IGridNode node, final IGridHost machine )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onSplit(final IGridStorage storageB) {
|
||||
|
||||
@Override
|
||||
public void onSplit( final IGridStorage storageB )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onJoin(final IGridStorage storageB) {
|
||||
|
||||
@Override
|
||||
public void onJoin( final IGridStorage storageB )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void populateGridStorage(final IGridStorage storage) {
|
||||
|
||||
@Override
|
||||
public void populateGridStorage( final IGridStorage storage )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+154
-186
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.me.cache;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
@@ -38,232 +37,201 @@ import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.me.cache.helpers.TickTracker;
|
||||
|
||||
public class TickManagerCache implements ITickManager {
|
||||
|
||||
public class TickManagerCache implements ITickManager
|
||||
{
|
||||
private final IGrid myGrid;
|
||||
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 PriorityQueue<TickTracker> upcomingTicks = new PriorityQueue<>();
|
||||
|
||||
private final IGrid myGrid;
|
||||
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 PriorityQueue<TickTracker> upcomingTicks = new PriorityQueue<>();
|
||||
private long currentTick = 0;
|
||||
|
||||
private long currentTick = 0;
|
||||
public TickManagerCache(final IGrid g) {
|
||||
this.myGrid = g;
|
||||
}
|
||||
|
||||
public TickManagerCache( final IGrid g )
|
||||
{
|
||||
this.myGrid = g;
|
||||
}
|
||||
public long getCurrentTick() {
|
||||
return this.currentTick;
|
||||
}
|
||||
|
||||
public long getCurrentTick()
|
||||
{
|
||||
return this.currentTick;
|
||||
}
|
||||
public long getAvgNanoTime(final IGridNode node) {
|
||||
TickTracker tt = this.awake.get(node);
|
||||
|
||||
public long getAvgNanoTime( final IGridNode node )
|
||||
{
|
||||
TickTracker tt = this.awake.get( node );
|
||||
if (tt == null) {
|
||||
tt = this.sleeping.get(node);
|
||||
}
|
||||
|
||||
if( tt == null )
|
||||
{
|
||||
tt = this.sleeping.get( node );
|
||||
}
|
||||
if (tt == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( tt == null )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return tt.getAvgNanos();
|
||||
}
|
||||
|
||||
return tt.getAvgNanos();
|
||||
}
|
||||
@Override
|
||||
public void onUpdateTick() {
|
||||
TickTracker tt = null;
|
||||
|
||||
@Override
|
||||
public void onUpdateTick()
|
||||
{
|
||||
TickTracker tt = null;
|
||||
try {
|
||||
this.currentTick++;
|
||||
|
||||
try
|
||||
{
|
||||
this.currentTick++;
|
||||
while (!this.upcomingTicks.isEmpty()) {
|
||||
tt = this.upcomingTicks.peek();
|
||||
|
||||
while( !this.upcomingTicks.isEmpty() )
|
||||
{
|
||||
tt = this.upcomingTicks.peek();
|
||||
// Stop once it reaches a TickTracker running at a later tick
|
||||
if (tt.getNextTick() > this.currentTick) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Stop once it reaches a TickTracker running at a later tick
|
||||
if( tt.getNextTick() > this.currentTick )
|
||||
{
|
||||
break;
|
||||
}
|
||||
this.upcomingTicks.poll();
|
||||
|
||||
this.upcomingTicks.poll();
|
||||
final int diff = (int) (this.currentTick - tt.getLastTick());
|
||||
final TickRateModulation mod = tt.getGridTickable().tickingRequest(tt.getNode(), diff);
|
||||
|
||||
final int diff = (int) ( this.currentTick - tt.getLastTick() );
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
final CrashReport crashreport = CrashReport.makeCrashReport(t, "Ticking GridNode");
|
||||
final CrashReportCategory crashreportcategory = crashreport
|
||||
.makeCategory(tt.getGridTickable().getClass().getSimpleName() + " being ticked.");
|
||||
tt.addEntityCrashInfo(crashreportcategory);
|
||||
throw new ReportedException(crashreport);
|
||||
}
|
||||
}
|
||||
|
||||
if( this.awake.containsKey( tt.getNode() ) )
|
||||
{
|
||||
this.addToQueue( tt );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
final CrashReport crashreport = CrashReport.makeCrashReport( t, "Ticking GridNode" );
|
||||
final CrashReportCategory crashreportcategory = crashreport.makeCategory( tt.getGridTickable().getClass().getSimpleName() + " being ticked." );
|
||||
tt.addEntityCrashInfo( crashreportcategory );
|
||||
throw new ReportedException( crashreport );
|
||||
}
|
||||
}
|
||||
private void addToQueue(final TickTracker tt) {
|
||||
tt.setLastTick(this.currentTick);
|
||||
this.upcomingTicks.add(tt);
|
||||
}
|
||||
|
||||
private void addToQueue( final TickTracker tt )
|
||||
{
|
||||
tt.setLastTick( this.currentTick );
|
||||
this.upcomingTicks.add( tt );
|
||||
}
|
||||
@Override
|
||||
public void removeNode(final IGridNode gridNode, final IGridHost machine) {
|
||||
if (machine instanceof IGridTickable) {
|
||||
this.alertable.remove(gridNode);
|
||||
this.sleeping.remove(gridNode);
|
||||
this.awake.remove(gridNode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNode( final IGridNode gridNode, final IGridHost machine )
|
||||
{
|
||||
if( machine instanceof IGridTickable )
|
||||
{
|
||||
this.alertable.remove( gridNode );
|
||||
this.sleeping.remove( gridNode );
|
||||
this.awake.remove( gridNode );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void addNode(final IGridNode gridNode, final IGridHost machine) {
|
||||
if (machine instanceof IGridTickable) {
|
||||
final IGridTickable tickable = ((IGridTickable) machine);
|
||||
final TickingRequest tr = tickable.getTickingRequest(gridNode);
|
||||
|
||||
@Override
|
||||
public void addNode( final IGridNode gridNode, final IGridHost machine )
|
||||
{
|
||||
if( machine instanceof IGridTickable )
|
||||
{
|
||||
final IGridTickable tickable = ( (IGridTickable) machine );
|
||||
final TickingRequest tr = tickable.getTickingRequest( gridNode );
|
||||
Preconditions.checkNotNull(tr);
|
||||
|
||||
Preconditions.checkNotNull( tr );
|
||||
final TickTracker tt = new TickTracker(tr, gridNode, (IGridTickable) machine, this.currentTick, this);
|
||||
|
||||
final TickTracker tt = new TickTracker( tr, gridNode, (IGridTickable) machine, this.currentTick, this );
|
||||
if (tr.canBeAlerted) {
|
||||
this.alertable.put(gridNode, tt);
|
||||
}
|
||||
|
||||
if( tr.canBeAlerted )
|
||||
{
|
||||
this.alertable.put( gridNode, tt );
|
||||
}
|
||||
if (tr.isSleeping) {
|
||||
this.sleeping.put(gridNode, tt);
|
||||
} else {
|
||||
this.awake.put(gridNode, tt);
|
||||
this.addToQueue(tt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( tr.isSleeping )
|
||||
{
|
||||
this.sleeping.put( gridNode, tt );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.awake.put( gridNode, tt );
|
||||
this.addToQueue( tt );
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onSplit(final IGridStorage storageB) {
|
||||
|
||||
@Override
|
||||
public void onSplit( final IGridStorage storageB )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onJoin(final IGridStorage storageB) {
|
||||
|
||||
@Override
|
||||
public void onJoin( final IGridStorage storageB )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void populateGridStorage(final IGridStorage storage) {
|
||||
|
||||
@Override
|
||||
public void populateGridStorage( final IGridStorage storage )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean alertDevice(final IGridNode node) {
|
||||
Preconditions.checkNotNull(node);
|
||||
|
||||
@Override
|
||||
public boolean alertDevice( final IGridNode node )
|
||||
{
|
||||
Preconditions.checkNotNull( node );
|
||||
final TickTracker tt = this.alertable.get(node);
|
||||
if (tt == null) {
|
||||
return false;
|
||||
}
|
||||
// throw new RuntimeException(
|
||||
// "Invalid alerted device, this node is not marked as alertable, or part of
|
||||
// this grid." );
|
||||
|
||||
final TickTracker tt = this.alertable.get( node );
|
||||
if( tt == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// throw new RuntimeException(
|
||||
// "Invalid alerted device, this node is not marked as alertable, or part of this grid." );
|
||||
// set to awake, this is for sanity.
|
||||
this.sleeping.remove(node);
|
||||
this.awake.put(node, tt);
|
||||
|
||||
// set to awake, this is for sanity.
|
||||
this.sleeping.remove( node );
|
||||
this.awake.put( node, tt );
|
||||
// configure sort.
|
||||
tt.setLastTick(tt.getLastTick() - tt.getRequest().maxTickRate);
|
||||
tt.setCurrentRate(tt.getRequest().minTickRate);
|
||||
|
||||
// configure sort.
|
||||
tt.setLastTick( tt.getLastTick() - tt.getRequest().maxTickRate );
|
||||
tt.setCurrentRate( tt.getRequest().minTickRate );
|
||||
// prevent dupes and tick build up.
|
||||
this.upcomingTicks.remove(tt);
|
||||
this.upcomingTicks.add(tt);
|
||||
|
||||
// prevent dupes and tick build up.
|
||||
this.upcomingTicks.remove( tt );
|
||||
this.upcomingTicks.add( tt );
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean sleepDevice(final IGridNode node) {
|
||||
Preconditions.checkNotNull(node);
|
||||
|
||||
@Override
|
||||
public boolean sleepDevice( final IGridNode node )
|
||||
{
|
||||
Preconditions.checkNotNull( node );
|
||||
if (this.awake.containsKey(node)) {
|
||||
final TickTracker gt = this.awake.get(node);
|
||||
this.awake.remove(node);
|
||||
this.sleeping.put(node, gt);
|
||||
|
||||
if( this.awake.containsKey( node ) )
|
||||
{
|
||||
final TickTracker gt = this.awake.get( node );
|
||||
this.awake.remove( node );
|
||||
this.sleeping.put( node, gt );
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean wakeDevice(final IGridNode node) {
|
||||
Preconditions.checkNotNull(node);
|
||||
|
||||
@Override
|
||||
public boolean wakeDevice( final IGridNode node )
|
||||
{
|
||||
Preconditions.checkNotNull( node );
|
||||
if (this.sleeping.containsKey(node)) {
|
||||
final TickTracker gt = this.sleeping.get(node);
|
||||
this.sleeping.remove(node);
|
||||
this.awake.put(node, gt);
|
||||
this.upcomingTicks.remove(gt);
|
||||
this.addToQueue(gt);
|
||||
|
||||
if( this.sleeping.containsKey( node ) )
|
||||
{
|
||||
final TickTracker gt = this.sleeping.get( node );
|
||||
this.sleeping.remove( node );
|
||||
this.awake.put( node, gt );
|
||||
this.upcomingTicks.remove( gt );
|
||||
this.addToQueue( gt );
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-17
@@ -18,27 +18,21 @@
|
||||
|
||||
package appeng.me.cache.helpers;
|
||||
|
||||
|
||||
import appeng.api.networking.IGridConnection;
|
||||
|
||||
public class ConnectionWrapper {
|
||||
|
||||
public class ConnectionWrapper
|
||||
{
|
||||
private IGridConnection connection;
|
||||
|
||||
private IGridConnection connection;
|
||||
public ConnectionWrapper(final IGridConnection gc) {
|
||||
this.setConnection(gc);
|
||||
}
|
||||
|
||||
public ConnectionWrapper( final IGridConnection gc )
|
||||
{
|
||||
this.setConnection( gc );
|
||||
}
|
||||
public IGridConnection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
public IGridConnection getConnection()
|
||||
{
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
public void setConnection( final IGridConnection connection )
|
||||
{
|
||||
this.connection = connection;
|
||||
}
|
||||
public void setConnection(final IGridConnection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
}
|
||||
+36
-48
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.me.cache.helpers;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
@@ -27,62 +26,51 @@ import appeng.api.networking.IGridNode;
|
||||
import appeng.parts.p2p.PartP2PTunnelME;
|
||||
import appeng.util.IWorldCallable;
|
||||
|
||||
public class Connections implements IWorldCallable<Void> {
|
||||
|
||||
public class Connections implements IWorldCallable<Void>
|
||||
{
|
||||
private final HashMap<IGridNode, TunnelConnection> connections = new HashMap<>();
|
||||
private final PartP2PTunnelME me;
|
||||
private boolean create = false;
|
||||
private boolean destroy = false;
|
||||
|
||||
private final HashMap<IGridNode, TunnelConnection> connections = new HashMap<>();
|
||||
private final PartP2PTunnelME me;
|
||||
private boolean create = false;
|
||||
private boolean destroy = false;
|
||||
public Connections(final PartP2PTunnelME o) {
|
||||
this.me = o;
|
||||
}
|
||||
|
||||
public Connections( final PartP2PTunnelME o )
|
||||
{
|
||||
this.me = o;
|
||||
}
|
||||
@Override
|
||||
public Void call(final World world) throws Exception {
|
||||
this.me.updateConnections(this);
|
||||
|
||||
@Override
|
||||
public Void call( final World world ) throws Exception
|
||||
{
|
||||
this.me.updateConnections( this );
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public void markDestroy() {
|
||||
this.setCreate(false);
|
||||
this.setDestroy(true);
|
||||
}
|
||||
|
||||
public void markDestroy()
|
||||
{
|
||||
this.setCreate( false );
|
||||
this.setDestroy( true );
|
||||
}
|
||||
public void markCreate() {
|
||||
this.setCreate(true);
|
||||
this.setDestroy(false);
|
||||
}
|
||||
|
||||
public void markCreate()
|
||||
{
|
||||
this.setCreate( true );
|
||||
this.setDestroy( false );
|
||||
}
|
||||
public HashMap<IGridNode, TunnelConnection> getConnections() {
|
||||
return this.connections;
|
||||
}
|
||||
|
||||
public HashMap<IGridNode, TunnelConnection> getConnections()
|
||||
{
|
||||
return this.connections;
|
||||
}
|
||||
public boolean isCreate() {
|
||||
return this.create;
|
||||
}
|
||||
|
||||
public boolean isCreate()
|
||||
{
|
||||
return this.create;
|
||||
}
|
||||
private void setCreate(final boolean create) {
|
||||
this.create = create;
|
||||
}
|
||||
|
||||
private void setCreate( final boolean create )
|
||||
{
|
||||
this.create = create;
|
||||
}
|
||||
public boolean isDestroy() {
|
||||
return this.destroy;
|
||||
}
|
||||
|
||||
public boolean isDestroy()
|
||||
{
|
||||
return this.destroy;
|
||||
}
|
||||
|
||||
private void setDestroy( final boolean destroy )
|
||||
{
|
||||
this.destroy = destroy;
|
||||
}
|
||||
private void setDestroy(final boolean destroy) {
|
||||
this.destroy = destroy;
|
||||
}
|
||||
}
|
||||
|
||||
+71
-88
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.me.cache.helpers;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
@@ -30,113 +29,97 @@ import appeng.api.util.DimensionalCoord;
|
||||
import appeng.me.cache.TickManagerCache;
|
||||
import appeng.parts.AEBasePart;
|
||||
|
||||
public class TickTracker implements Comparable<TickTracker> {
|
||||
|
||||
public class TickTracker implements Comparable<TickTracker>
|
||||
{
|
||||
private final TickingRequest request;
|
||||
private final IGridTickable gt;
|
||||
private final IGridNode node;
|
||||
|
||||
private final TickingRequest request;
|
||||
private final IGridTickable gt;
|
||||
private final IGridNode node;
|
||||
private final long LastFiveTicksTime = 0;
|
||||
|
||||
private final long LastFiveTicksTime = 0;
|
||||
private long lastTick;
|
||||
private int currentRate;
|
||||
|
||||
private long lastTick;
|
||||
private int currentRate;
|
||||
public TickTracker(final TickingRequest req, final IGridNode node, final IGridTickable gt, final long currentTick,
|
||||
final TickManagerCache tickManagerCache) {
|
||||
this.request = req;
|
||||
this.gt = gt;
|
||||
this.node = node;
|
||||
this.setCurrentRate((req.minTickRate + req.maxTickRate) / 2);
|
||||
this.setLastTick(currentTick);
|
||||
}
|
||||
|
||||
public TickTracker( final TickingRequest req, final IGridNode node, final IGridTickable gt, final long currentTick, final TickManagerCache tickManagerCache )
|
||||
{
|
||||
this.request = req;
|
||||
this.gt = gt;
|
||||
this.node = node;
|
||||
this.setCurrentRate( ( req.minTickRate + req.maxTickRate ) / 2 );
|
||||
this.setLastTick( currentTick );
|
||||
}
|
||||
public long getAvgNanos() {
|
||||
return (this.LastFiveTicksTime / 5);
|
||||
}
|
||||
|
||||
public long getAvgNanos()
|
||||
{
|
||||
return( this.LastFiveTicksTime / 5 );
|
||||
}
|
||||
@Override
|
||||
public int compareTo(@Nonnull final TickTracker t) {
|
||||
int next = Long.compare(this.getNextTick(), t.getNextTick());
|
||||
|
||||
@Override
|
||||
public int compareTo( @Nonnull final TickTracker t )
|
||||
{
|
||||
int next = Long.compare( this.getNextTick(), t.getNextTick() );
|
||||
if (next != 0) {
|
||||
return next;
|
||||
}
|
||||
|
||||
if( next != 0 )
|
||||
{
|
||||
return next;
|
||||
}
|
||||
int last = Long.compare(this.getLastTick(), t.getLastTick());
|
||||
|
||||
int last = Long.compare( this.getLastTick(), t.getLastTick() );
|
||||
if (last != 0) {
|
||||
return last;
|
||||
}
|
||||
|
||||
if( last != 0 )
|
||||
{
|
||||
return last;
|
||||
}
|
||||
return Integer.compare(this.getCurrentRate(), t.getCurrentRate());
|
||||
|
||||
return Integer.compare( this.getCurrentRate(), t.getCurrentRate() );
|
||||
}
|
||||
|
||||
}
|
||||
public void addEntityCrashInfo(final CrashReportCategory crashreportcategory) {
|
||||
if (this.getGridTickable() instanceof AEBasePart) {
|
||||
final AEBasePart part = (AEBasePart) this.getGridTickable();
|
||||
part.addEntityCrashInfo(crashreportcategory);
|
||||
}
|
||||
|
||||
public void addEntityCrashInfo( final CrashReportCategory crashreportcategory )
|
||||
{
|
||||
if( this.getGridTickable() instanceof AEBasePart )
|
||||
{
|
||||
final AEBasePart part = (AEBasePart) this.getGridTickable();
|
||||
part.addEntityCrashInfo( crashreportcategory );
|
||||
}
|
||||
crashreportcategory.addDetail("CurrentTickRate", this.getCurrentRate());
|
||||
crashreportcategory.addDetail("MinTickRate", this.getRequest().minTickRate);
|
||||
crashreportcategory.addDetail("MaxTickRate", this.getRequest().maxTickRate);
|
||||
crashreportcategory.addDetail("MachineType", this.getGridTickable().getClass().getName());
|
||||
crashreportcategory.addDetail("GridBlockType", this.getNode().getGridBlock().getClass().getName());
|
||||
crashreportcategory.addDetail("ConnectedSides", this.getNode().getConnectedSides());
|
||||
|
||||
crashreportcategory.addDetail( "CurrentTickRate", this.getCurrentRate() );
|
||||
crashreportcategory.addDetail( "MinTickRate", this.getRequest().minTickRate );
|
||||
crashreportcategory.addDetail( "MaxTickRate", this.getRequest().maxTickRate );
|
||||
crashreportcategory.addDetail( "MachineType", this.getGridTickable().getClass().getName() );
|
||||
crashreportcategory.addDetail( "GridBlockType", this.getNode().getGridBlock().getClass().getName() );
|
||||
crashreportcategory.addDetail( "ConnectedSides", this.getNode().getConnectedSides() );
|
||||
final DimensionalCoord dc = this.getNode().getGridBlock().getLocation();
|
||||
if (dc != null) {
|
||||
crashreportcategory.addDetail("Location", dc);
|
||||
}
|
||||
}
|
||||
|
||||
final DimensionalCoord dc = this.getNode().getGridBlock().getLocation();
|
||||
if( dc != null )
|
||||
{
|
||||
crashreportcategory.addDetail( "Location", dc );
|
||||
}
|
||||
}
|
||||
public int getCurrentRate() {
|
||||
return this.currentRate;
|
||||
}
|
||||
|
||||
public int getCurrentRate()
|
||||
{
|
||||
return this.currentRate;
|
||||
}
|
||||
public void setCurrentRate(final int currentRate) {
|
||||
this.currentRate = Math.min(this.getRequest().maxTickRate,
|
||||
Math.max(this.getRequest().minTickRate, currentRate));
|
||||
}
|
||||
|
||||
public void setCurrentRate( final int currentRate )
|
||||
{
|
||||
this.currentRate = Math.min( this.getRequest().maxTickRate, Math.max( this.getRequest().minTickRate, currentRate ) );
|
||||
}
|
||||
public long getNextTick() {
|
||||
return this.lastTick + this.currentRate;
|
||||
}
|
||||
|
||||
public long getNextTick()
|
||||
{
|
||||
return this.lastTick + this.currentRate;
|
||||
}
|
||||
public long getLastTick() {
|
||||
return this.lastTick;
|
||||
}
|
||||
|
||||
public long getLastTick()
|
||||
{
|
||||
return this.lastTick;
|
||||
}
|
||||
public void setLastTick(final long lastTick) {
|
||||
this.lastTick = lastTick;
|
||||
}
|
||||
|
||||
public void setLastTick( final long lastTick )
|
||||
{
|
||||
this.lastTick = lastTick;
|
||||
}
|
||||
public IGridNode getNode() {
|
||||
return this.node;
|
||||
}
|
||||
|
||||
public IGridNode getNode()
|
||||
{
|
||||
return this.node;
|
||||
}
|
||||
public IGridTickable getGridTickable() {
|
||||
return this.gt;
|
||||
}
|
||||
|
||||
public IGridTickable getGridTickable()
|
||||
{
|
||||
return this.gt;
|
||||
}
|
||||
|
||||
public TickingRequest getRequest()
|
||||
{
|
||||
return this.request;
|
||||
}
|
||||
public TickingRequest getRequest() {
|
||||
return this.request;
|
||||
}
|
||||
}
|
||||
|
||||
+29
-40
@@ -18,59 +18,48 @@
|
||||
|
||||
package appeng.me.cache.helpers;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.parts.p2p.PartP2PTunnel;
|
||||
import appeng.util.iterators.NullIterator;
|
||||
|
||||
public class TunnelCollection<T extends PartP2PTunnel> implements Iterable<T> {
|
||||
|
||||
public class TunnelCollection<T extends PartP2PTunnel> implements Iterable<T>
|
||||
{
|
||||
private final Class clz;
|
||||
private Collection<T> tunnelSources;
|
||||
|
||||
private final Class clz;
|
||||
private Collection<T> tunnelSources;
|
||||
public TunnelCollection(final Collection<T> src, final Class c) {
|
||||
this.tunnelSources = src;
|
||||
this.clz = c;
|
||||
}
|
||||
|
||||
public TunnelCollection( final Collection<T> src, final Class c )
|
||||
{
|
||||
this.tunnelSources = src;
|
||||
this.clz = c;
|
||||
}
|
||||
public void setSource(final Collection<T> c) {
|
||||
this.tunnelSources = c;
|
||||
}
|
||||
|
||||
public void setSource( final Collection<T> c )
|
||||
{
|
||||
this.tunnelSources = c;
|
||||
}
|
||||
public boolean isEmpty() {
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
if (this.tunnelSources == null) {
|
||||
return new NullIterator<>();
|
||||
}
|
||||
return new TunnelIterator<>(this.tunnelSources, this.clz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator()
|
||||
{
|
||||
if( this.tunnelSources == null )
|
||||
{
|
||||
return new NullIterator<>();
|
||||
}
|
||||
return new TunnelIterator<>( this.tunnelSources, this.clz );
|
||||
}
|
||||
public boolean matches(final Class<? extends PartP2PTunnel> c) {
|
||||
return this.clz == c;
|
||||
}
|
||||
|
||||
public boolean matches( final Class<? extends PartP2PTunnel> c )
|
||||
{
|
||||
return this.clz == c;
|
||||
}
|
||||
public Class<? extends PartP2PTunnel> getClz() {
|
||||
return this.clz;
|
||||
}
|
||||
|
||||
public Class<? extends PartP2PTunnel> getClz()
|
||||
{
|
||||
return this.clz;
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return this.tunnelSources == null ? 0 : this.tunnelSources.size();
|
||||
}
|
||||
public int size() {
|
||||
return this.tunnelSources == null ? 0 : this.tunnelSources.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
-19
@@ -18,30 +18,24 @@
|
||||
|
||||
package appeng.me.cache.helpers;
|
||||
|
||||
|
||||
import appeng.api.networking.IGridConnection;
|
||||
import appeng.parts.p2p.PartP2PTunnelME;
|
||||
|
||||
public class TunnelConnection {
|
||||
|
||||
public class TunnelConnection
|
||||
{
|
||||
private final PartP2PTunnelME tunnel;
|
||||
private final IGridConnection c;
|
||||
|
||||
private final PartP2PTunnelME tunnel;
|
||||
private final IGridConnection c;
|
||||
public TunnelConnection(final PartP2PTunnelME t, final IGridConnection con) {
|
||||
this.tunnel = t;
|
||||
this.c = con;
|
||||
}
|
||||
|
||||
public TunnelConnection( final PartP2PTunnelME t, final IGridConnection con )
|
||||
{
|
||||
this.tunnel = t;
|
||||
this.c = con;
|
||||
}
|
||||
public IGridConnection getConnection() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public IGridConnection getConnection()
|
||||
{
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public PartP2PTunnelME getTunnel()
|
||||
{
|
||||
return this.tunnel;
|
||||
}
|
||||
public PartP2PTunnelME getTunnel() {
|
||||
return this.tunnel;
|
||||
}
|
||||
}
|
||||
+32
-42
@@ -18,57 +18,47 @@
|
||||
|
||||
package appeng.me.cache.helpers;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.parts.p2p.PartP2PTunnel;
|
||||
|
||||
public class TunnelIterator<T extends PartP2PTunnel> implements Iterator<T> {
|
||||
|
||||
public class TunnelIterator<T extends PartP2PTunnel> implements Iterator<T>
|
||||
{
|
||||
private final Iterator<T> wrapped;
|
||||
private final Class targetType;
|
||||
private T Next;
|
||||
|
||||
private final Iterator<T> wrapped;
|
||||
private final Class targetType;
|
||||
private T Next;
|
||||
public TunnelIterator(final Collection<T> tunnelSources, final Class clz) {
|
||||
this.wrapped = tunnelSources.iterator();
|
||||
this.targetType = clz;
|
||||
this.findNext();
|
||||
}
|
||||
|
||||
public TunnelIterator( final Collection<T> tunnelSources, final Class clz )
|
||||
{
|
||||
this.wrapped = tunnelSources.iterator();
|
||||
this.targetType = clz;
|
||||
this.findNext();
|
||||
}
|
||||
private void findNext() {
|
||||
while (this.Next == null && this.wrapped.hasNext()) {
|
||||
this.Next = this.wrapped.next();
|
||||
if (!this.targetType.isInstance(this.Next)) {
|
||||
this.Next = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void findNext()
|
||||
{
|
||||
while( this.Next == null && this.wrapped.hasNext() )
|
||||
{
|
||||
this.Next = this.wrapped.next();
|
||||
if( !this.targetType.isInstance( this.Next ) )
|
||||
{
|
||||
this.Next = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
this.findNext();
|
||||
return this.Next != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
this.findNext();
|
||||
return this.Next != null;
|
||||
}
|
||||
@Override
|
||||
public T next() {
|
||||
final T tmp = this.Next;
|
||||
this.Next = null;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next()
|
||||
{
|
||||
final T tmp = this.Next;
|
||||
this.Next = null;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
// no.
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
// no.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user