Initial rv1 beta merge.

This commit is contained in:
AlgorithmX2
2014-09-13 15:12:47 -05:00
58 changed files with 754 additions and 210 deletions
+11
View File
@@ -11,6 +11,9 @@ import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.pathing.IPathingGrid;
import appeng.api.util.IReadOnlyCollection;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.features.AEFeature;
import appeng.me.pathfinding.IPathItem;
import appeng.util.Platform;
import appeng.util.ReadOnlyCollection;
@@ -34,7 +37,15 @@ public class GridConnection implements IGridConnection, IPathItem
GridNode b = (GridNode) bNode;
if ( Platform.securityCheck( a, b ) )
{
if ( AEConfig.instance.isFeatureEnabled( AEFeature.LogSecurityAudits ) )
{
AELog.info( "Audit Failed 1: " + a.getGridBlock().getLocation() );
AELog.info( "Audit Failed 2: " + b.getGridBlock().getLocation() );
}
throw new FailedConnection();
}
if ( a == null || b == null )
throw new GridException( "Connection Forged Between null enties." );
+3 -6
View File
@@ -295,8 +295,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
emitableItems.clear();
// update the stuff that was in the list...
for (IAEItemStack out : oldItems.keySet())
sg.postAlterationOfStoredItems( StorageChannel.ITEMS, out, new BaseActionSource() );
sg.postAlterationOfStoredItems( StorageChannel.ITEMS, oldItems.keySet(), new BaseActionSource() );
// re-create list..
for (ICraftingProvider cp : providers)
@@ -324,10 +323,9 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
// make them immutable
for (Entry<IAEItemStack, Set<ICraftingPatternDetails>> e : tmpCraft.entrySet())
{
craftableItems.put( e.getKey(), ImmutableSortedSet.copyOf( e.getValue() ) );
sg.postAlterationOfStoredItems( StorageChannel.ITEMS, e.getKey(), new BaseActionSource() );
}
sg.postAlterationOfStoredItems( StorageChannel.ITEMS, craftableItems.keySet(), new BaseActionSource() );
}
@Override
@@ -438,7 +436,6 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
if ( cpu.isActive() && !cpu.isBusy() && cpu.getAvailableStorage() >= job.getByteTotal() )
{
validCpusClusters.add( cpu );
break;
}
}
+11 -2
View File
@@ -384,8 +384,17 @@ public class EnergyGridCache implements IEnergyGrid
tickInjectionPerTick = 0;
// power information.
double drained = extractAEPower( getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG );
boolean currentlyHasPower = drained >= drainPerTick - 0.001;
boolean currentlyHasPower = false;
if ( drainPerTick > 0.0001 )
{
double drained = extractAEPower( getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG );
currentlyHasPower = drained >= drainPerTick - 0.001;
}
else
{
currentlyHasPower = extractAEPower( 0.1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0;
}
// ticks since change..
if ( currentlyHasPower == hasPower )
+72 -36
View File
@@ -3,6 +3,7 @@ package appeng.me.cache;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import appeng.api.AEApi;
import appeng.api.networking.IGrid;
@@ -63,21 +64,66 @@ public class GridStorageCache implements IStorageGrid
fluidMonitor.onTick();
}
private class CellChangeTrackerRecord
{
final StorageChannel channel;
final int up_or_down;
final IItemList list;
final BaseActionSource src;
public CellChangeTrackerRecord(StorageChannel channel, int i, IMEInventoryHandler<? extends IAEStack> h, BaseActionSource actionSrc) {
this.channel = channel;
this.up_or_down = i;
this.src = actionSrc;
if ( channel == StorageChannel.ITEMS )
this.list = ((IMEInventoryHandler<IAEItemStack>) h).getAvailableItems( AEApi.instance().storage().createItemList() );
else if ( channel == StorageChannel.FLUIDS )
this.list = ((IMEInventoryHandler<IAEFluidStack>) h).getAvailableItems( AEApi.instance().storage().createFluidList() );
else
this.list = null;
}
public void applyChanges()
{
postChangesToNetwork( channel, up_or_down, list, src );
}
};
private class CellChangeTracker
{
List<CellChangeTrackerRecord> data = new LinkedList();
public void postChanges(StorageChannel channel, int i, IMEInventoryHandler<? extends IAEStack> h, BaseActionSource actionSrc)
{
data.add( new CellChangeTrackerRecord( channel, i, h, actionSrc ) );
}
public void applyChanges()
{
for (CellChangeTrackerRecord rec : data)
rec.applyChanges();
}
};
@Override
public void registerCellProvider(ICellProvider provider)
{
inactiveCellProviders.add( provider );
addCellProvider( provider );
addCellProvider( provider, new CellChangeTracker() ).applyChanges();
}
@Override
public void unregisterCellProvider(ICellProvider provider)
{
removeCellProvider( provider );
removeCellProvider( provider, new CellChangeTracker() ).applyChanges();
inactiveCellProviders.remove( provider );
}
public void addCellProvider(ICellProvider cc)
public CellChangeTracker addCellProvider(ICellProvider cc, CellChangeTracker tracker)
{
if ( inactiveCellProviders.contains( cc ) )
{
@@ -90,17 +136,19 @@ public class GridStorageCache implements IStorageGrid
for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ))
{
postChanges( StorageChannel.ITEMS, 1, h.getAvailableItems( AEApi.instance().storage().createItemList() ), actionSrc );
tracker.postChanges( StorageChannel.ITEMS, 1, h, actionSrc );
}
for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ))
{
postChanges( StorageChannel.FLUIDS, 1, h.getAvailableItems( AEApi.instance().storage().createFluidList() ), actionSrc );
tracker.postChanges( StorageChannel.FLUIDS, 1, h, actionSrc );
}
}
return tracker;
}
public void removeCellProvider(ICellProvider cc)
public CellChangeTracker removeCellProvider(ICellProvider cc, CellChangeTracker tracker)
{
if ( activeCellProviders.contains( cc ) )
{
@@ -113,14 +161,16 @@ public class GridStorageCache implements IStorageGrid
for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ))
{
postChanges( StorageChannel.ITEMS, -1, h.getAvailableItems( AEApi.instance().storage().createItemList() ), actionSrc );
tracker.postChanges( StorageChannel.ITEMS, -1, h, actionSrc );
}
for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ))
{
postChanges( StorageChannel.FLUIDS, -1, h.getAvailableItems( AEApi.instance().storage().createFluidList() ), actionSrc );
tracker.postChanges( StorageChannel.FLUIDS, -1, h, actionSrc );
}
}
return tracker;
}
@MENetworkEventSubscribe
@@ -133,6 +183,8 @@ public class GridStorageCache implements IStorageGrid
ll.addAll( inactiveCellProviders );
ll.addAll( activeCellProviders );
CellChangeTracker tracker = new CellChangeTracker();
for (ICellProvider cc : ll)
{
boolean Active = true;
@@ -147,13 +199,15 @@ public class GridStorageCache implements IStorageGrid
}
if ( Active )
addCellProvider( cc );
addCellProvider( cc, tracker );
else
removeCellProvider( cc );
removeCellProvider( cc, tracker );
}
itemMonitor.forceUpdate();
fluidMonitor.forceUpdate();
tracker.applyChanges();
}
@Override
@@ -164,7 +218,7 @@ public class GridStorageCache implements IStorageGrid
ICellContainer cc = (ICellContainer) machine;
myGrid.postEvent( new MENetworkCellArrayUpdate() );
removeCellProvider( cc );
removeCellProvider( cc, new CellChangeTracker() ).applyChanges();
inactiveCellProviders.remove( cc );
}
@@ -189,7 +243,7 @@ public class GridStorageCache implements IStorageGrid
myGrid.postEvent( new MENetworkCellArrayUpdate() );
if ( node.isActive() )
addCellProvider( cc );
addCellProvider( cc, new CellChangeTracker() ).applyChanges();
}
if ( machine instanceof IStackWatcherHost )
@@ -227,33 +281,15 @@ public class GridStorageCache implements IStorageGrid
}
}
private void postChanges(StorageChannel chan, int up_or_down, IItemList availableItems, BaseActionSource src)
private void postChangesToNetwork(StorageChannel chan, int up_or_down, IItemList availableItems, BaseActionSource src)
{
switch (chan)
{
case FLUIDS:
for (IAEFluidStack fs : ((IItemList<IAEFluidStack>) availableItems))
{
if ( up_or_down > 0 )
fluidMonitor.postChange( fs, src );
else
{
fs.setStackSize( -fs.getStackSize() );
fluidMonitor.postChange( fs, src );
}
}
fluidMonitor.postChange( up_or_down > 0, (IItemList<IAEFluidStack>) availableItems, src );
break;
case ITEMS:
for (IAEItemStack fs : ((IItemList<IAEItemStack>) availableItems))
{
if ( up_or_down > 0 )
itemMonitor.postChange( fs, src );
else
{
fs.setStackSize( -fs.getStackSize() );
itemMonitor.postChange( fs, src );
}
}
itemMonitor.postChange( up_or_down > 0, (IItemList<IAEItemStack>) availableItems, src );
break;
default:
}
@@ -274,12 +310,12 @@ public class GridStorageCache implements IStorageGrid
}
@Override
public void postAlterationOfStoredItems(StorageChannel chan, IAEStack input, BaseActionSource src)
public void postAlterationOfStoredItems(StorageChannel chan, Iterable<? extends IAEStack> input, BaseActionSource src)
{
if ( chan == StorageChannel.ITEMS )
itemMonitor.postChange( (IAEItemStack) input, src );
itemMonitor.postChange( true, (Iterable<IAEItemStack>) input, src );
else if ( chan == StorageChannel.FLUIDS )
fluidMonitor.postChange( (IAEFluidStack) input, src );
fluidMonitor.postChange( true, (Iterable<IAEFluidStack>) input, src );
}
@Override
+32 -19
View File
@@ -47,9 +47,14 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
}
final static public LinkedList depth = new LinkedList();
@Override
protected void postChange(T diff, BaseActionSource src)
protected void postChangesToListeners(Iterable<T> changes, BaseActionSource src)
{
postChange( true, changes, src );
}
protected void postChange(boolean Add, Iterable<T> changes, BaseActionSource src)
{
if ( depth.contains( this ) )
return;
@@ -57,28 +62,36 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
depth.push( this );
sendEvent = true;
super.postChange( diff, src );
notifyListenersOfChange( changes, src );
if ( myGridCache.interestManager.containsKey( diff ) )
IItemList<T> myStorageList = getStorageList();
for (T changedItem : changes)
{
Set<ItemWatcher> list = myGridCache.interestManager.get( diff );
if ( !list.isEmpty() )
{
IItemList<T> myStorageList = getStorageList();
T diffrence = changedItem;
IAEStack fullStack = myStorageList.findPrecise( diff );
if ( fullStack == null )
if ( !Add && changedItem != null )
(diffrence = changedItem.copy()).setStackSize( -changedItem.getStackSize() );
if ( myGridCache.interestManager.containsKey( changedItem ) )
{
Set<ItemWatcher> list = myGridCache.interestManager.get( changedItem );
if ( !list.isEmpty() )
{
fullStack = diff.copy();
fullStack.setStackSize( 0 );
IAEStack fullStack = myStorageList.findPrecise( changedItem );
if ( fullStack == null )
{
fullStack = changedItem.copy();
fullStack.setStackSize( 0 );
}
myGridCache.interestManager.enableTransactions();
for (ItemWatcher iw : list)
iw.getHost().onStackChange( myStorageList, fullStack, diffrence, src, getChannel() );
myGridCache.interestManager.disableTransactions();
}
myGridCache.interestManager.enableTransactions();
for (ItemWatcher iw : list)
iw.getHost().onStackChange( myStorageList, fullStack, diff, src, getChannel() );
myGridCache.interestManager.disableTransactions();
}
}
+48 -34
View File
@@ -3,6 +3,9 @@ package appeng.me.cache;
import java.util.HashMap;
import java.util.PriorityQueue;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.util.ReportedException;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
@@ -52,45 +55,56 @@ public class TickManagerCache implements ITickManager
@Override
public void onUpdateTick()
{
currentTick++;
while (!upcomingTicks.isEmpty())
TickTracker tt = null;
try
{
TickTracker tt = upcomingTicks.peek();
int diff = (int) (currentTick - tt.lastTick);
if ( diff >= tt.current_rate )
currentTick++;
while (!upcomingTicks.isEmpty())
{
// remove tt..
upcomingTicks.poll();
TickRateModulation mod = tt.gt.tickingRequest( tt.node, diff );
switch (mod)
tt = upcomingTicks.peek();
int diff = (int) (currentTick - tt.lastTick);
if ( diff >= tt.current_rate )
{
case FASTER:
tt.setRate( tt.current_rate - 2 );
break;
case IDLE:
tt.setRate( tt.request.maxTickRate );
break;
case SAME:
break;
case SLEEP:
sleepDevice( tt.node );
break;
case SLOWER:
tt.setRate( tt.current_rate + 1 );
break;
case URGENT:
tt.setRate( 0 );
break;
default:
break;
// remove tt..
upcomingTicks.poll();
TickRateModulation mod = tt.gt.tickingRequest( tt.node, diff );
switch (mod)
{
case FASTER:
tt.setRate( tt.current_rate - 2 );
break;
case IDLE:
tt.setRate( tt.request.maxTickRate );
break;
case SAME:
break;
case SLEEP:
sleepDevice( tt.node );
break;
case SLOWER:
tt.setRate( tt.current_rate + 1 );
break;
case URGENT:
tt.setRate( 0 );
break;
default:
break;
}
if ( awake.containsKey( tt.node ) )
addToQueue( tt );
}
if ( awake.containsKey( tt.node ) )
addToQueue( tt );
else
return; // done!
}
else
return; // done!
}
catch( Throwable t )
{
CrashReport crashreport = CrashReport.makeCrashReport(t, "Ticking GridNode");
CrashReportCategory crashreportcategory = crashreport.makeCategory( tt.gt.getClass().getSimpleName() + " being ticked." );
tt.addEntityCrashInfo(crashreportcategory);
throw new ReportedException(crashreport);
}
}
+23
View File
@@ -1,9 +1,12 @@
package appeng.me.cache.helpers;
import net.minecraft.crash.CrashReportCategory;
import appeng.api.networking.IGridNode;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.util.DimensionalCoord;
import appeng.me.cache.TickManagerCache;
import appeng.parts.AEBasePart;
public class TickTracker implements Comparable<TickTracker>
{
@@ -50,4 +53,24 @@ public class TickTracker implements Comparable<TickTracker>
int ts_nextTick = (int) ((t.lastTick - host.getCurrentTick()) + t.current_rate);
return nextTick - ts_nextTick;
}
public void addEntityCrashInfo(CrashReportCategory crashreportcategory)
{
if ( gt instanceof AEBasePart )
{
AEBasePart part = (AEBasePart)gt;
part.addEntityCrashInfo( crashreportcategory );
}
crashreportcategory.addCrashSection( "CurrentTickRate", current_rate );
crashreportcategory.addCrashSection( "MinTickRate", request.minTickRate );
crashreportcategory.addCrashSection( "MaxTickRate", request.maxTickRate );
crashreportcategory.addCrashSection( "MachineType", gt.getClass().getName() );
crashreportcategory.addCrashSection( "GridBlockType", node.getGridBlock().getClass().getName() );
crashreportcategory.addCrashSection( "ConnectedSides", node.getConnectedSides() );
DimensionalCoord dc = node.getGridBlock().getLocation();
if ( dc != null )
crashreportcategory.addCrashSection( "Location", dc );
}
};
@@ -54,6 +54,7 @@ import appeng.tile.crafting.TileCraftingTile;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import cpw.mods.fml.common.FMLCommonHandler;
@@ -76,6 +77,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
boolean waiting = false;
private boolean isComplete = true;
int usedOps[] = new int[3];
Map<ICraftingPatternDetails, TaskProgress> tasks = new HashMap<ICraftingPatternDetails, TaskProgress>();
IItemList<IAEItemStack> waitingFor = AEApi.instance().storage().createItemList();
@@ -106,16 +109,18 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
{
Iterator<Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = getListeners();
ImmutableList<IAEItemStack> single = null;
// protect integrity
if ( i.hasNext() )
diff = diff.copy();
single = ImmutableList.of( diff.copy() );
while (i.hasNext())
{
Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> o = i.next();
IMEMonitorHandlerReceiver<IAEItemStack> recv = o.getKey();
if ( recv.isValid( o.getValue() ) )
recv.postChange( null, diff, src );
recv.postChange( null, single, src );
else
i.remove();
}
@@ -492,8 +497,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
IItemList<IAEItemStack> list;
getListOfItem( list = AEApi.instance().storage().createItemList(), CraftingItemList.ALL );
for (IAEItemStack g : list)
postChange( g, machineSrc );
for (IAEItemStack is : list)
postChange( is, machineSrc );
isComplete = true;
myLastLink = null;
@@ -539,14 +544,21 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
if ( waiting || tasks.isEmpty() ) // nothing to do here...
return;
remainingOperations = accelerator + 1;
remainingOperations = accelerator + 1 - (usedOps[0] + usedOps[1] + usedOps[2]);
int started = remainingOperations;
do
if ( remainingOperations > 0 )
{
didsomething = false;
executeCrafting( eg, cc );
do
{
didsomething = false;
executeCrafting( eg, cc );
}
while (didsomething && remainingOperations > 0);
}
while (didsomething && remainingOperations > 0);
usedOps[2] = usedOps[1];
usedOps[1] = usedOps[0];
usedOps[0] = started - remainingOperations;
if ( remainingOperations > 0 && didsomething == false )
waiting = true;
@@ -1091,4 +1103,11 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
return wat != null && wat.getStackSize() > 0;
}
public void breakCluster()
{
TileCraftingTile t = getCore();
if ( t != null )
t.breakCluster();
}
}
+27
View File
@@ -93,4 +93,31 @@ public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> imple
}
}
}
public boolean isPreformatted()
{
return ! myPartitionList.isEmpty();
}
public boolean isFuzzy()
{
return myPartitionList instanceof FuzzyPriorityList;
}
@Override
public IncludeExclude getIncludeExcludeMode()
{
return myWhitelist;
}
public int getStatusForCell()
{
int val = getCellInv().getStatusForCell();
if ( val == 1 && isPreformatted() )
val = 2;
return val;
}
}
+10 -4
View File
@@ -2,6 +2,7 @@ package appeng.me.storage;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.TreeMap;
@@ -163,6 +164,8 @@ public class MEMonitorIInventory implements IMEInventory<IAEItemStack>, IMEMonit
{
boolean changed = false;
LinkedList<IAEItemStack> changes = new LinkedList<IAEItemStack>();
list.resetStatus();
for (ItemSlot is : adaptor)
{
@@ -178,12 +181,12 @@ public class MEMonitorIInventory implements IMEInventory<IAEItemStack>, IMEMonit
if ( old != null && old.aeStack != null )
{
old.aeStack.setStackSize( -old.aeStack.getStackSize() );
postDiffrence( old.aeStack );
changes.add( old.aeStack );
}
if ( cis != null && cis.aeStack != null )
{
postDiffrence( cis.aeStack );
changes.add( cis.aeStack );
list.add( cis.aeStack );
}
@@ -208,12 +211,15 @@ public class MEMonitorIInventory implements IMEInventory<IAEItemStack>, IMEMonit
IAEItemStack a = stack.copy();
a.setStackSize( diff );
postDiffrence( a );
changes.add( a );
changed = true;
}
}
}
if ( !changes.isEmpty() )
postDiffrence( changes );
return changed ? TickRateModulation.URGENT : TickRateModulation.SLOWER;
}
@@ -228,7 +234,7 @@ public class MEMonitorIInventory implements IMEInventory<IAEItemStack>, IMEMonit
return !Platform.isSameItemPrecise( a, b );
}
private void postDiffrence(IAEItemStack a)
private void postDiffrence(Iterable<IAEItemStack> a)
{
// AELog.info( a.getItemStack().getUnlocalizedName() + " @ " + a.getStackSize() );
if ( a != null )
+1 -1
View File
@@ -90,7 +90,7 @@ public class MEMonitorPassthu<T extends IAEStack<T>> extends MEPassthru<T> imple
}
@Override
public void postChange(IBaseMonitor<T> monitor, T change, BaseActionSource source)
public void postChange(IBaseMonitor<T> monitor, Iterable<T> change, BaseActionSource source)
{
Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = listeners.entrySet().iterator();
while (i.hasNext())