Working on armbot program updating

This commit is contained in:
Robert 2013-12-26 11:13:24 -05:00
parent 8901c6f297
commit 54d39e7901
7 changed files with 31 additions and 27 deletions

View file

@ -47,13 +47,13 @@ public class ProgramHelper
}
if (this.currentTask != null)
{
System.out.println("[ProgramHelper]Updating task:" + this.currentTask.toString());
if (!this.hasTaskBeenCalled)
{
this.hasTaskBeenCalled = true;
if (this.currentTask instanceof IProcessTask)
{
re = ((IProcessTask) this.currentTask).onMethodCalled();
System.out.println("[ProgramHelper]OnCall:" + re.toString());
if (re == ProcessReturn.DONE)
{
this.nextTask = true;

View file

@ -9,6 +9,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import universalelectricity.api.vector.Vector2;
import com.builtbroken.assemblyline.api.coding.ILogicTask;
import com.builtbroken.assemblyline.api.coding.IProgram;
import com.builtbroken.assemblyline.api.coding.IProgrammableMachine;
import com.builtbroken.assemblyline.api.coding.ITask;
@ -85,6 +86,14 @@ public class Program implements IProgram
{
this.currentTask.refresh();
}
if (this.currentTask instanceof ILogicTask)
{
if (((ILogicTask) this.currentTask).getExitPoint() != null)
{
this.currentTask = ((ILogicTask) this.currentTask).getExitPoint();
this.currentPos = new Vector2(this.currentTask.getCol(), this.currentTask.getRow() + 1);
}
}
return this.currentTask;
}

View file

@ -183,7 +183,7 @@ public abstract class TaskBase implements ITask
@Override
public String toString()
{
return "COMMAND[" + super.toString() + "]:" + this.methodName;
return "Task[" + this.methodName + "]:";
}
@Override

View file

@ -24,6 +24,7 @@ import com.builtbroken.assemblyline.api.coding.ProgramHelper;
import com.builtbroken.assemblyline.armbot.command.TaskGOTO;
import com.builtbroken.assemblyline.armbot.command.TaskReturn;
import com.builtbroken.assemblyline.armbot.command.TaskRotateBy;
import com.builtbroken.assemblyline.armbot.command.TaskRotateTo;
import com.builtbroken.assemblyline.machine.TileEntityAssembly;
import com.builtbroken.assemblyline.machine.encoder.ItemDisk;
import com.builtbroken.common.Pair;
@ -68,9 +69,9 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
super(20);
programHelper = new ProgramHelper(this).setMemoryLimit(20);
Program program = new Program();
program.setTaskAt(0, 0, new TaskRotateBy(90, 0));
program.setTaskAt(0, 0, new TaskRotateTo(90, 0));
program.setTaskAt(0, 1, new TaskReturn());
program.setTaskAt(0, 1, new TaskGOTO(0, 0));
program.setTaskAt(0, 2, new TaskGOTO(0, 0));
programHelper.setProgram(program);
}
@ -106,10 +107,10 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
if (this.isFunctioning())
{
if (!this.worldObj.isRemote)
float preYaw = this.rotationYaw, prePitch = this.rotationPitch;
if (!this.worldObj.isRemote && this.ticks % 3 == 0)
{
this.programHelper.onUpdate(this.worldObj, new Vector3(this));
float preYaw = this.rotationYaw, prePitch = this.rotationPitch;
if (this.rotationYaw != preYaw || this.rotationPitch != prePitch)
{
this.sendRotationPacket();
@ -313,7 +314,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
public void sendRotationPacket()
{
PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getPacket(this.getChannel(), "arbotRotation", this.rotationYaw, this.rotationPitch), worldObj, new Vector3(this).translate(new Vector3(.5f, 1f, .5f)), 40);
PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getPacket(this.getChannel(), "arbotRotation", this.rotationYaw, this.rotationPitch, this.actualYaw, this.actualPitch), worldObj, new Vector3(this).translate(new Vector3(.5f, 1f, .5f)), 40);
}
@Override
@ -334,6 +335,8 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
{
this.rotationYaw = dis.readFloat();
this.rotationPitch = dis.readFloat();
this.actualYaw = dis.readFloat();
this.actualPitch = dis.readFloat();
return true;
}
}

View file

@ -21,6 +21,7 @@ public class TaskReturn extends TaskBaseArmbot
if (this.rotateToCommand == null)
{
this.rotateToCommand = new TaskRotateTo(0, 0);
this.rotateToCommand.setProgram(this.program);
this.rotateToCommand.onMethodCalled();
}
return this.rotateToCommand.onUpdate();
@ -32,12 +33,6 @@ public class TaskReturn extends TaskBaseArmbot
this.rotateToCommand.terminated();
}
@Override
public String toString()
{
return "RETURN";
}
@Override
public TaskBaseProcess clone()
{

View file

@ -81,7 +81,7 @@ public class TaskRotateBy extends TaskBaseArmbot
@Override
public String toString()
{
return super.toString() + " " + Float.toString(this.deltaYaw) + " " + Float.toString(this.deltaPitch);
return super.toString() + " Yaw:" + Integer.toString(this.targetRotationYaw) + " Pitch:" + Integer.toString(this.targetRotationPitch);
}
@Override

View file

@ -17,23 +17,19 @@ import com.builtbroken.minecraft.helpers.MathHelper;
* @author DarkGuardsman */
public class TaskRotateTo extends TaskBaseArmbot
{
int targetRotationYaw = 0, targetRotationPitch = 0, currentRotationYaw, currentRotationPitch;
int targetRotationYaw = 0, targetRotationPitch = 0;
public TaskRotateTo()
{
super("RotateTo");
this.args.add(new ArgumentIntData("yaw", 0, 360, 0));
this.args.add(new ArgumentIntData("pitch", 0, 360, 0));
this.UV = new Vector2(100, 80);
this(0, 0);
}
public TaskRotateTo(int yaw, int pitch)
{
this();
this.targetRotationYaw = yaw;
this.targetRotationPitch = pitch;
this.setArg("yaw", yaw);
this.setArg("pitch", pitch);
super("RotateTo");
this.args.add(new ArgumentIntData("yaw", yaw, 360, 0));
this.args.add(new ArgumentIntData("pitch", pitch, 360, 0));
this.UV = new Vector2(100, 80);
}
@Override
@ -54,8 +50,9 @@ public class TaskRotateTo extends TaskBaseArmbot
if (super.onUpdate() == ProcessReturn.CONTINUE)
{
((IArmbot) this.program.getMachine()).moveArmTo(this.targetRotationYaw, this.targetRotationPitch);
return Math.abs(((IArmbot) this.program.getMachine()).getRotation().y - this.targetRotationPitch) > 0 && Math.abs(((IArmbot) this.program.getMachine()).getRotation().x - this.targetRotationYaw) > 0 ? ProcessReturn.CONTINUE : ProcessReturn.DONE;
int deltaYaw = Math.abs(((IArmbot) this.program.getMachine()).getRotation().intY() - this.targetRotationPitch);
int deltaPitch = Math.abs(((IArmbot) this.program.getMachine()).getRotation().intX() - this.targetRotationYaw);
return deltaYaw > 0 && deltaPitch > 0 ? ProcessReturn.CONTINUE : ProcessReturn.DONE;
}
return ProcessReturn.GENERAL_ERROR;
}
@ -63,7 +60,7 @@ public class TaskRotateTo extends TaskBaseArmbot
@Override
public String toString()
{
return super.toString() + " " + Float.toString(this.targetRotationYaw) + " " + Float.toString(this.targetRotationPitch);
return super.toString() + " Yaw:" + Integer.toString(this.targetRotationYaw) + " Pitch:" + Integer.toString(this.targetRotationPitch);
}
@Override