Buffer changes from Interest List.
This commit is contained in:
+3
-5
@@ -200,13 +200,11 @@ public class Grid implements IGrid
|
|||||||
|
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
// are ther any nodes left?
|
for (IGridCache gc : caches.values())
|
||||||
if ( pivot != null )
|
|
||||||
{
|
{
|
||||||
for (IGridCache gc : caches.values())
|
// are there any nodes left?
|
||||||
{
|
if ( pivot != null )
|
||||||
gc.onUpdateTick();
|
gc.onUpdateTick();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+3
-1
@@ -25,6 +25,7 @@ import appeng.api.storage.data.IAEFluidStack;
|
|||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IAEStack;
|
import appeng.api.storage.data.IAEStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
|
import appeng.me.helpers.StorageInterestManager;
|
||||||
import appeng.me.storage.ItemWatcher;
|
import appeng.me.storage.ItemWatcher;
|
||||||
import appeng.me.storage.NetworkInventoryHandler;
|
import appeng.me.storage.NetworkInventoryHandler;
|
||||||
|
|
||||||
@@ -34,7 +35,8 @@ import com.google.common.collect.SetMultimap;
|
|||||||
public class GridStorageCache implements IStorageGrid
|
public class GridStorageCache implements IStorageGrid
|
||||||
{
|
{
|
||||||
|
|
||||||
public SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
|
final private SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
|
||||||
|
final public StorageInterestManager interestManager = new StorageInterestManager( interests );
|
||||||
|
|
||||||
final HashSet<ICellContainer> activeCellContainers = new HashSet();
|
final HashSet<ICellContainer> activeCellContainers = new HashSet();
|
||||||
final HashSet<ICellContainer> inactiveCellContainers = new HashSet();
|
final HashSet<ICellContainer> inactiveCellContainers = new HashSet();
|
||||||
|
|||||||
Vendored
+6
-2
@@ -59,9 +59,9 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
|
|||||||
sendEvent = true;
|
sendEvent = true;
|
||||||
super.postChange( diff, src );
|
super.postChange( diff, src );
|
||||||
|
|
||||||
if ( myGridCache.interests.containsKey( diff ) )
|
if ( myGridCache.interestManager.containsKey( diff ) )
|
||||||
{
|
{
|
||||||
Set<ItemWatcher> list = myGridCache.interests.get( diff );
|
Set<ItemWatcher> list = myGridCache.interestManager.get( diff );
|
||||||
if ( !list.isEmpty() )
|
if ( !list.isEmpty() )
|
||||||
{
|
{
|
||||||
IItemList<T> myStorageList = getStorageList();
|
IItemList<T> myStorageList = getStorageList();
|
||||||
@@ -73,8 +73,12 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
|
|||||||
fullStack.setStackSize( 0 );
|
fullStack.setStackSize( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
myGridCache.interestManager.enableTransactions();
|
||||||
|
|
||||||
for (ItemWatcher iw : list)
|
for (ItemWatcher iw : list)
|
||||||
iw.getHost().onStackChange( myStorageList, fullStack, diff, src, getChannel() );
|
iw.getHost().onStackChange( myStorageList, fullStack, diff, src, getChannel() );
|
||||||
|
|
||||||
|
myGridCache.interestManager.disableTransactions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package appeng.me.helpers;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import appeng.api.storage.data.IAEStack;
|
||||||
|
import appeng.me.storage.ItemWatcher;
|
||||||
|
|
||||||
|
import com.google.common.collect.SetMultimap;
|
||||||
|
|
||||||
|
public class StorageInterestManager {
|
||||||
|
|
||||||
|
class SavedTransactions {
|
||||||
|
public final boolean put;
|
||||||
|
public final IAEStack stack;
|
||||||
|
public final ItemWatcher iw;
|
||||||
|
|
||||||
|
public SavedTransactions( boolean putOperation, IAEStack myStack, ItemWatcher watcher )
|
||||||
|
{
|
||||||
|
put = putOperation;
|
||||||
|
stack = myStack;
|
||||||
|
iw = watcher;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final SetMultimap<IAEStack, ItemWatcher> container;
|
||||||
|
private LinkedList<SavedTransactions> transactions = null;
|
||||||
|
|
||||||
|
public StorageInterestManager(SetMultimap<IAEStack, ItemWatcher> interests) {
|
||||||
|
container = interests;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableTransactions()
|
||||||
|
{
|
||||||
|
transactions = new LinkedList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableTransactions()
|
||||||
|
{
|
||||||
|
LinkedList<SavedTransactions> myActions = transactions;
|
||||||
|
transactions = null;
|
||||||
|
|
||||||
|
for ( SavedTransactions t : myActions )
|
||||||
|
{
|
||||||
|
if ( t.put )
|
||||||
|
put( t.stack, t.iw );
|
||||||
|
else
|
||||||
|
remove( t.stack, t.iw );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsKey( IAEStack stack )
|
||||||
|
{
|
||||||
|
return container.containsKey( stack );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ItemWatcher> get( IAEStack stack )
|
||||||
|
{
|
||||||
|
return container.get( stack );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean put( IAEStack stack, ItemWatcher iw )
|
||||||
|
{
|
||||||
|
if ( transactions != null )
|
||||||
|
{
|
||||||
|
transactions.add( new SavedTransactions( true, stack, iw ) );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return container.put( stack, iw );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean remove( IAEStack stack, ItemWatcher iw )
|
||||||
|
{
|
||||||
|
if ( transactions != null )
|
||||||
|
{
|
||||||
|
transactions.add( new SavedTransactions( true, stack, iw ) );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return container.remove( stack, iw );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -42,7 +42,7 @@ public class ItemWatcher implements IStackWatcher
|
|||||||
@Override
|
@Override
|
||||||
public void remove()
|
public void remove()
|
||||||
{
|
{
|
||||||
gsc.interests.remove( myLast, watcher );
|
gsc.interestManager.remove( myLast, watcher );
|
||||||
interestIterator.remove();
|
interestIterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ public class ItemWatcher implements IStackWatcher
|
|||||||
if ( myInterests.contains( e ) )
|
if ( myInterests.contains( e ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return myInterests.add( e.copy() ) && gsc.interests.put( e, this );
|
return myInterests.add( e.copy() ) && gsc.interestManager.put( e, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,7 +88,7 @@ public class ItemWatcher implements IStackWatcher
|
|||||||
Iterator<IAEStack> i = myInterests.iterator();
|
Iterator<IAEStack> i = myInterests.iterator();
|
||||||
while (i.hasNext())
|
while (i.hasNext())
|
||||||
{
|
{
|
||||||
gsc.interests.remove( i.next(), this );
|
gsc.interestManager.remove( i.next(), this );
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ public class ItemWatcher implements IStackWatcher
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(Object o)
|
public boolean remove(Object o)
|
||||||
{
|
{
|
||||||
return myInterests.remove( o ) && gsc.interests.remove( o, this );
|
return myInterests.remove( o ) && gsc.interestManager.remove( (IAEStack)o, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user