Added EMC Contractor multithreading

This commit is contained in:
Calclavia 2013-08-05 17:20:08 -04:00
parent 78bc4a666a
commit de0ad48a2d
3 changed files with 77 additions and 9 deletions

View file

@ -96,6 +96,7 @@ public class ResonantInduction
private static final int BLOCK_ID_PREFIX = 3200;
/** Item ID by Horfius */
private static final int ITEM_ID_PREFIX = 20150;
public static int MAX_CONTRACTOR_DISTANCE = 200;
private static int NEXT_BLOCK_ID = BLOCK_ID_PREFIX;
private static int NEXT_ITEM_ID = ITEM_ID_PREFIX;
@ -132,6 +133,7 @@ public class ResonantInduction
// Config
POWER_PER_COAL = (float) CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Coal Wattage", POWER_PER_COAL).getDouble(POWER_PER_COAL);
SOUND_FXS = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Tesla Sound FXs", SOUND_FXS).getBoolean(SOUND_FXS);
MAX_CONTRACTOR_DISTANCE = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Max EM Contractor Path", MAX_CONTRACTOR_DISTANCE).getInt(MAX_CONTRACTOR_DISTANCE);
TileEntityEMContractor.ACCELERATION = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Item Acceleration", TileEntityEMContractor.ACCELERATION).getDouble(TileEntityEMContractor.ACCELERATION);
TileEntityEMContractor.MAX_REACH = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Reach", TileEntityEMContractor.MAX_REACH).getInt(TileEntityEMContractor.MAX_REACH);

View file

@ -0,0 +1,47 @@
/**
*
*/
package resonantinduction.contractor;
import resonantinduction.base.Vector3;
/**
* @author Calclavia
*
*/
public class ThreadPathfinding extends Thread
{
private boolean isCompleted = false;
private PathfinderEMContractor pathfinder;
private Vector3 start;
public ThreadPathfinding(PathfinderEMContractor pathfinder, Vector3 start)
{
this.pathfinder = pathfinder;
this.start = start;
this.setPriority(Thread.MIN_PRIORITY);
}
public ThreadPathfinding find()
{
this.run();
return this;
}
@Override
public void run()
{
this.pathfinder.find(this.start);
this.isCompleted = true;
}
public PathfinderEMContractor getPath()
{
if (this.isCompleted)
{
return this.pathfinder;
}
return null;
}
}

View file

@ -50,6 +50,10 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
*/
public boolean suck = true;
/**
* Pathfinding
*/
private ThreadPathfinding thread;
private PathfinderEMContractor pathfinder;
private Set<EntityItem> pathfindingTrackers = new HashSet<EntityItem>();
private TileEntityEMContractor linked;
@ -124,6 +128,17 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
}
}
if (this.thread != null)
{
PathfinderEMContractor newPath = this.thread.getPath();
if (newPath != null)
{
this.pathfinder = newPath;
this.thread = null;
}
}
if (!this.suck)
{
if (this.linked != null && !this.linked.isInvalid())
@ -514,17 +529,21 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
public void updatePath()
{
this.pathfinder = null;
if (this.linked != null)
if (this.thread == null)
{
Vector3 start = new Vector3(this).translate(new Vector3(this.getDirection()));
Vector3 target = new Vector3(this.linked).translate(new Vector3(this.linked.getDirection()));
if (TileEntityEMContractor.canBePath(this.worldObj, start, new Vector3(this.linked)) && TileEntityEMContractor.canBePath(this.worldObj, target, new Vector3(this.linked)))
if (this.linked != null)
{
this.pathfinder = new PathfinderEMContractor(this.worldObj, target);
this.pathfinder.find(start);
Vector3 start = new Vector3(this).translate(new Vector3(this.getDirection()));
Vector3 target = new Vector3(this.linked).translate(new Vector3(this.linked.getDirection()));
if (start.distance(target) < ResonantInduction.MAX_CONTRACTOR_DISTANCE)
{
if (TileEntityEMContractor.canBePath(this.worldObj, start, new Vector3(this.linked)) && TileEntityEMContractor.canBePath(this.worldObj, target, new Vector3(this.linked)))
{
this.thread = new ThreadPathfinding(new PathfinderEMContractor(this.worldObj, target), start);
this.thread.start();
}
}
}
}
}