parent
e8d554d69d
commit
6032c0328e
2 changed files with 33 additions and 118 deletions
|
@ -21,9 +21,11 @@ package appeng.hooks;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -49,7 +51,6 @@ import appeng.core.AppEng;
|
|||
import appeng.core.sync.packets.PacketPaintedEntity;
|
||||
import appeng.crafting.CraftingJob;
|
||||
import appeng.me.Grid;
|
||||
import appeng.me.NetworkList;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.util.IWorldCallable;
|
||||
import appeng.util.Platform;
|
||||
|
@ -118,7 +119,7 @@ public class TickHandler
|
|||
{
|
||||
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
this.getRepo().networks.add( grid );
|
||||
this.getRepo().addNetwork( grid );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +127,7 @@ public class TickHandler
|
|||
{
|
||||
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
this.getRepo().networks.remove( grid );
|
||||
this.getRepo().removeNetwork( grid );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,6 +148,7 @@ public class TickHandler
|
|||
{
|
||||
final LinkedList<IGridNode> toDestroy = new LinkedList<>();
|
||||
|
||||
this.getRepo().updateNetworks();
|
||||
for( final Grid g : this.getRepo().networks )
|
||||
{
|
||||
for( final IGridNode n : g.getNodes() )
|
||||
|
@ -218,6 +220,7 @@ public class TickHandler
|
|||
}
|
||||
|
||||
// tick networks.
|
||||
this.getRepo().updateNetworks();
|
||||
for( final Grid g : this.getRepo().networks )
|
||||
{
|
||||
g.update();
|
||||
|
@ -295,12 +298,37 @@ public class TickHandler
|
|||
|
||||
private Queue<AEBaseTile> tiles = new LinkedList<>();
|
||||
|
||||
private Collection<Grid> networks = new NetworkList();
|
||||
private Set<Grid> networks = new HashSet<>();
|
||||
private Set<Grid> toAdd = new HashSet<>();
|
||||
private Set<Grid> toRemove = new HashSet<>();
|
||||
|
||||
private void clear()
|
||||
{
|
||||
this.tiles = new LinkedList<>();
|
||||
this.networks = new NetworkList();
|
||||
this.networks = new HashSet<>();
|
||||
this.toAdd = new HashSet<>();
|
||||
this.toRemove = new HashSet<>();
|
||||
}
|
||||
|
||||
private synchronized void addNetwork( Grid g )
|
||||
{
|
||||
this.toAdd.add( g );
|
||||
this.toRemove.remove( g );
|
||||
}
|
||||
|
||||
private synchronized void removeNetwork( Grid g )
|
||||
{
|
||||
this.toRemove.add( g );
|
||||
this.toAdd.remove( g );
|
||||
}
|
||||
|
||||
private synchronized void updateNetworks()
|
||||
{
|
||||
this.networks.removeAll( this.toRemove );
|
||||
this.toRemove.clear();
|
||||
|
||||
this.networks.addAll( this.toAdd );
|
||||
this.toAdd.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.me;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Test if copy was actually necessary.
|
||||
*/
|
||||
public class NetworkList implements Collection<Grid>
|
||||
{
|
||||
|
||||
private List<Grid> networks = new LinkedList<>();
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.networks.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.networks.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains( final Object o )
|
||||
{
|
||||
return this.networks.contains( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Grid> iterator()
|
||||
{
|
||||
return this.networks.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray()
|
||||
{
|
||||
return this.networks.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray( final T[] a )
|
||||
{
|
||||
return this.networks.toArray( a );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add( final Grid e )
|
||||
{
|
||||
return this.networks.add( e );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove( final Object o )
|
||||
{
|
||||
return this.networks.remove( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll( final Collection<?> c )
|
||||
{
|
||||
return this.networks.containsAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll( final Collection<? extends Grid> c )
|
||||
{
|
||||
return this.networks.addAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll( final Collection<?> c )
|
||||
{
|
||||
return this.networks.removeAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll( final Collection<?> c )
|
||||
{
|
||||
return this.networks.retainAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
this.networks = new LinkedList<>();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue