optimizations, hide RF buffer from redstone engines

This commit is contained in:
asiekierka 2015-06-29 15:44:51 +02:00
parent abdcda3068
commit fa0677449e
6 changed files with 81 additions and 42 deletions

View file

@ -109,12 +109,21 @@ public class TileEngineWood extends TileEngineBase implements IRedstoneEngine {
return 10;
}
// TODO: HACK
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return false;
}
@Override
public int getEnergyStored(ForgeDirection side) {
return 0;
}
@Override
public int getMaxEnergyStored(ForgeDirection side) {
return 0;
}
@Override
protected void sendPower() {
if (progressPart == 2 && !hasSent) {

View file

@ -64,7 +64,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
protected HashSet<Integer> builtEntities = new HashSet<Integer>();
private HashMap<BuilderItemMetaPair, List<BuildingSlotBlock>> buildList = new HashMap<BuilderItemMetaPair, List<BuildingSlotBlock>>();
private Multiset<Integer> buildStageOccurences = HashMultiset.create();
private int[] buildStageOccurences;
private LinkedList<BuildingSlotEntity> entityList = new LinkedList<BuildingSlotEntity>();
private LinkedList<BuildingSlot> postProcessing = new LinkedList<BuildingSlot>();
private BuildingSlotMapIterator iterator;
@ -268,8 +268,8 @@ public class BptBuilderBlueprint extends BptBuilderBase {
private int getBuildListCount() {
int out = 0;
for (int i = 0; i < 4; i++) {
out += buildStageOccurences.count(i);
for (int i = 0; i < buildStageOccurences.length; i++) {
out += buildStageOccurences[i];
}
return out;
}
@ -297,7 +297,14 @@ public class BptBuilderBlueprint extends BptBuilderBase {
buildList.put(imp, new ArrayList<BuildingSlotBlock>());
}
buildList.get(imp).add(b);
buildStageOccurences.add(b.buildStage);
if (buildStageOccurences == null) {
buildStageOccurences = new int[Math.max(4, b.buildStage + 1)];
} else if (buildStageOccurences.length <= b.buildStage) {
int[] newBSO = new int[b.buildStage + 1];
System.arraycopy(buildStageOccurences, 0, newBSO, 0, buildStageOccurences.length);
buildStageOccurences = newBSO;
}
buildStageOccurences[b.buildStage]++;
}
}
@ -340,7 +347,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
boolean skipped = false;
for (int i = 0; i < slot.buildStage; i++) {
if (buildStageOccurences.count(i) > 0) {
if (buildStageOccurences[i] > 0) {
iterator.skipList();
skipped = true;
break;

View file

@ -22,7 +22,7 @@ public class BuildingSlotMapIterator {
private static final int MAX_PER_ITEM = 80;
private final Map<BuilderItemMetaPair, List<BuildingSlotBlock>> slots;
private final Set<BuilderItemMetaPair> availablePairs = new HashSet<BuilderItemMetaPair>();
private final Multiset<Integer> buildStageOccurences;
private final int[] buildStageOccurences;
private final boolean isCreative;
private Iterator<BuilderItemMetaPair> impIterator;
private BuilderItemMetaPair pair;
@ -30,7 +30,7 @@ public class BuildingSlotMapIterator {
private int position, returnsThisCurrent;
public BuildingSlotMapIterator(Map<BuilderItemMetaPair, List<BuildingSlotBlock>> slots, TileAbstractBuilder builder,
Multiset<Integer> buildStageOccurences) {
int[] buildStageOccurences) {
this.slots = slots;
this.impIterator = slots.keySet().iterator();
this.buildStageOccurences = buildStageOccurences;
@ -82,7 +82,7 @@ public class BuildingSlotMapIterator {
}
public void remove() {
buildStageOccurences.remove(current.get(position).buildStage);
buildStageOccurences[current.get(position).buildStage]--;
current.set(position, null);
}

View file

@ -14,9 +14,11 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.LongHashMap;
import net.minecraft.world.World;
import net.minecraft.world.WorldSavedData;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@ -34,15 +36,15 @@ import buildcraft.api.robots.RobotManager;
public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
protected World world;
protected HashMap<StationIndex, DockingStation> stations = new HashMap<StationIndex, DockingStation>();
protected final HashMap<StationIndex, DockingStation> stations = new HashMap<StationIndex, DockingStation>();
private long nextRobotID = Long.MIN_VALUE;
private HashMap<Long, EntityRobot> robotsLoaded = new HashMap<Long, EntityRobot>();
private HashMap<ResourceId, Long> resourcesTaken = new HashMap<ResourceId, Long>();
private HashMap<Long, HashSet<ResourceId>> resourcesTakenByRobot = new HashMap<Long, HashSet<ResourceId>>();
private HashMap<Long, HashSet<StationIndex>> stationsTakenByRobot = new HashMap<Long, HashSet<StationIndex>>();
private final LongHashMap robotsLoaded = new LongHashMap();
private final HashSet<EntityRobot> robotsLoadedSet = new HashSet<EntityRobot>();
private final HashMap<ResourceId, Long> resourcesTaken = new HashMap<ResourceId, Long>();
private final LongHashMap resourcesTakenByRobot = new LongHashMap();
private final LongHashMap stationsTakenByRobot = new LongHashMap();
public RobotRegistry(String id) {
super(id);
@ -64,11 +66,30 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
if (robot.getRobotId() == EntityRobotBase.NULL_ROBOT_ID) {
((EntityRobot) robot).setUniqueRobotId(getNextRobotId());
}
if (robotsLoaded.containsKey(robot.getRobotId())) {
if (robotsLoaded.containsItem(robot.getRobotId())) {
BCLog.logger.warn("Robot with id %d was not unregistered properly", robot.getRobotId());
}
robotsLoaded.put(robot.getRobotId(), (EntityRobot) robot);
addRobotLoaded((EntityRobot) robot);
}
private HashSet<ResourceId> getResourcesTakenByRobot(long robotId) {
return (HashSet<ResourceId>) resourcesTakenByRobot.getValueByKey(robotId);
}
private HashSet<StationIndex> getStationsTakenByRobot(long robotId) {
return (HashSet<StationIndex>) stationsTakenByRobot.getValueByKey(robotId);
}
private void addRobotLoaded(EntityRobot robot) {
robotsLoaded.add(robot.getRobotId(), robot);
robotsLoadedSet.add(robot);
}
private void removeRobotLoaded(EntityRobot robot) {
robotsLoaded.remove(robot.getRobotId());
robotsLoadedSet.remove(robot);
}
@Override
@ -76,7 +97,7 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
markDirty();
releaseResources(robot, true);
robotsLoaded.remove(robot.getRobotId());
removeRobotLoaded((EntityRobot) robot);
}
@Override
@ -84,13 +105,13 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
markDirty();
releaseResources(robot, false, true);
robotsLoaded.remove(robot.getRobotId());
removeRobotLoaded((EntityRobot) robot);
}
@Override
public EntityRobot getLoadedRobot(long id) {
if (robotsLoaded.containsKey(id)) {
return robotsLoaded.get(id);
if (robotsLoaded.containsItem(id)) {
return (EntityRobot) robotsLoaded.getValueByKey(id);
} else {
return null;
}
@ -109,7 +130,7 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
long robotId = resourcesTaken.get(resourceId);
if (robotsLoaded.containsKey(robotId) && !robotsLoaded.get(robotId).isDead) {
if (robotsLoaded.containsItem(robotId) && !((EntityRobot) robotsLoaded.getValueByKey(robotId)).isDead) {
return robotId;
} else {
// If the robot is either not loaded or dead, the resource is not
@ -123,10 +144,10 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
public synchronized EntityRobot robotTaking(ResourceId resourceId) {
long robotId = robotIdTaking(resourceId);
if (robotId == EntityRobotBase.NULL_ROBOT_ID || !robotsLoaded.containsKey(robotId)) {
if (robotId == EntityRobotBase.NULL_ROBOT_ID || !robotsLoaded.containsItem(robotId)) {
return null;
} else {
return robotsLoaded.get(robotId);
return (EntityRobot) robotsLoaded.getValueByKey(robotId);
}
}
@ -148,11 +169,11 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
if (!resourcesTaken.containsKey(resourceId)) {
resourcesTaken.put(resourceId, robotId);
if (!resourcesTakenByRobot.containsKey(robotId)) {
resourcesTakenByRobot.put(robotId, new HashSet<ResourceId>());
if (!resourcesTakenByRobot.containsItem(robotId)) {
resourcesTakenByRobot.add(robotId, new HashSet<ResourceId>());
}
resourcesTakenByRobot.get(robotId).add(resourceId);
getResourcesTakenByRobot(robotId).add(resourceId);
resourceId.taken(robotId);
@ -173,7 +194,7 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
if (resourcesTaken.containsKey(resourceId)) {
long robotId = resourcesTaken.get(resourceId);
resourcesTakenByRobot.get(resourcesTaken.get(resourceId)).remove(resourceId);
getResourcesTakenByRobot(robotId).remove(resourceId);
resourcesTaken.remove(resourceId);
resourceId.released(robotId);
}
@ -191,8 +212,8 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
private synchronized void releaseResources(EntityRobotBase robot, boolean forceAll, boolean resetEntities) {
markDirty();
if (resourcesTakenByRobot.containsKey(robot.getRobotId())) {
HashSet<ResourceId> resourceSet = (HashSet<ResourceId>) resourcesTakenByRobot.get(robot.getRobotId())
if (resourcesTakenByRobot.containsItem(robot.getRobotId())) {
HashSet<ResourceId> resourceSet = (HashSet<ResourceId>) getResourcesTakenByRobot(robot.getRobotId())
.clone();
for (ResourceId id : resourceSet) {
@ -202,8 +223,8 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
resourcesTakenByRobot.remove(robot.getRobotId());
}
if (stationsTakenByRobot.containsKey(robot.getRobotId())) {
HashSet<StationIndex> stationSet = (HashSet<StationIndex>) stationsTakenByRobot.get(robot.getRobotId())
if (stationsTakenByRobot.containsItem(robot.getRobotId())) {
HashSet<StationIndex> stationSet = (HashSet<StationIndex>) getStationsTakenByRobot(robot.getRobotId())
.clone();
for (StationIndex s : stationSet) {
@ -271,8 +292,8 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
station.robotTaking().setMainStation(null);
}
} else if (station.robotIdTaking() != EntityRobotBase.NULL_ROBOT_ID) {
if (stationsTakenByRobot.get(station.robotIdTaking()) != null) {
stationsTakenByRobot.get(station.robotIdTaking()).remove(index);
if (stationsTakenByRobot.containsItem(station.robotIdTaking())) {
getStationsTakenByRobot(station.robotIdTaking()).remove(index);
}
}
@ -282,17 +303,17 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
@Override
public synchronized void take(DockingStation station, long robotId) {
if (!stationsTakenByRobot.containsKey(robotId)) {
stationsTakenByRobot.put(robotId, new HashSet<StationIndex>());
if (!stationsTakenByRobot.containsItem(robotId)) {
stationsTakenByRobot.add(robotId, new HashSet<StationIndex>());
}
stationsTakenByRobot.get(robotId).add(new StationIndex(station));
getStationsTakenByRobot(robotId).add(new StationIndex(station));
}
@Override
public synchronized void release(DockingStation station, long robotId) {
if (stationsTakenByRobot.containsKey(robotId)) {
stationsTakenByRobot.get(robotId).remove(new StationIndex(station));
if (stationsTakenByRobot.containsItem(robotId)) {
getStationsTakenByRobot(robotId).remove(new StationIndex(station));
}
}
@ -376,7 +397,7 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
@SubscribeEvent
public void onChunkUnload(ChunkEvent.Unload e) {
if (e.world == this.world) {
for (EntityRobot robot : new ArrayList<EntityRobot>(robotsLoaded.values())) {
for (EntityRobot robot : new ArrayList<EntityRobot>(robotsLoadedSet)) {
if (!e.world.loadedEntityList.contains(robot)) {
robot.onChunkUnload();
}

View file

@ -1,5 +1,6 @@
package buildcraft.silicon;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
@ -228,7 +229,7 @@ public class TilePackager extends TileBuildCraft implements ISidedInventory {
}
// STEP 3b: Remote
Map<ForgeDirection, IInventory> invs = new HashMap<ForgeDirection, IInventory>();
Map<ForgeDirection, IInventory> invs = new EnumMap<ForgeDirection, IInventory>(ForgeDirection.class);
if (filteredReqsToFulfill > 0 || missingCount > 0) {
for (int i = 2; i < 6; i++) {
TileEntity neighbor = getTile(ForgeDirection.getOrientation(i));

View file

@ -4,6 +4,7 @@ import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;
import com.google.common.collect.EnumMultiset;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
@ -303,7 +304,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
int testAmount = flowRate;
// Move liquid from the center to the output sides
Multiset<ForgeDirection> realDirections = HashMultiset.create(6);
Multiset<ForgeDirection> realDirections = EnumMultiset.create(ForgeDirection.class);
for (ForgeDirection direction : directions) {
if (transferState[direction.ordinal()] == TransferState.Output) {
realDirections.add(direction);