Recursive mechanical grid initially working
This commit is contained in:
parent
c668057295
commit
1c832ea241
7 changed files with 28 additions and 47 deletions
|
@ -48,5 +48,5 @@ trait TNodeMechanical extends INode with IVectorWorld
|
|||
*
|
||||
* @param torque - force at an angle
|
||||
*/
|
||||
def rotate(torque: Double)
|
||||
def rotate(torque: Double, angularVelocity : Double)
|
||||
}
|
|
@ -48,7 +48,7 @@ class TileMotor extends TileAdvanced(Material.iron) with TElectric with TSpatial
|
|||
|
||||
if (mechRatio > 0)
|
||||
{
|
||||
mechNode.rotate(deltaPower)
|
||||
mechNode.rotate(deltaPower, deltaPower / mechRatio)
|
||||
//TODO: Resist DC energy
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util
|
|||
|
||||
import codechicken.lib.vec.{Cuboid6, Vector3}
|
||||
import codechicken.microblock.FaceMicroClass
|
||||
import codechicken.multipart.ControlKeyModifer
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
|
@ -41,8 +40,8 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
|||
if (getMultiBlock.isPrimary)
|
||||
UpdateTicker.world.enqueue(() => if (world != null) sendPacket(1))
|
||||
|
||||
// if (mechanicalNode.angularVelocity == 0)
|
||||
// UpdateTicker.world.enqueue(() => if (world != null) sendPacket(2))
|
||||
// if (mechanicalNode.angularVelocity == 0)
|
||||
// UpdateTicker.world.enqueue(() => if (world != null) sendPacket(2))
|
||||
}
|
||||
|
||||
mechanicalNode.onGridReconstruct = () => if (world != null && !world.isRemote) sendPacket(2)
|
||||
|
@ -57,7 +56,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
|||
if (manualCrankTime > 0)
|
||||
{
|
||||
//A punch his around 5000 Newtons
|
||||
mechanicalNode.rotate((if (isClockwiseCrank) 2 else -2) * manualCrankTime)
|
||||
mechanicalNode.rotate((if (isClockwiseCrank) 2 else -2) * manualCrankTime, (if (isClockwiseCrank) 2 else -2) * manualCrankTime)
|
||||
manualCrankTime -= 1
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,51 +52,30 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
|||
getNodes.foreach(
|
||||
n =>
|
||||
{
|
||||
n.prevTorque = n.torque
|
||||
n.prevAngularVelocity = n.angularVelocity
|
||||
|
||||
n._torque = 0
|
||||
n._angularVelocity = 0
|
||||
}
|
||||
)
|
||||
|
||||
getNodes.filter(n => n.bufferTorque != 0 && n.bufferAngularVelocity != 0).foreach(n => recurse(Seq(n)))
|
||||
getNodes.filter(n => n.bufferTorque != 0 && n.bufferAngularVelocity != 0).foreach(n => recurse(deltaTime, Seq(n)))
|
||||
|
||||
/*
|
||||
//Find all nodes that are currently producing energy
|
||||
val inputs = getNodes.filter(n => n.bufferTorque != 0)
|
||||
|
||||
//Calculate the total input equivalent torque
|
||||
val inputTorque = inputs
|
||||
.map(n => n.bufferTorque * (if (spinMap(n)) 1 else -1))
|
||||
.foldLeft(0D)(_ + _)
|
||||
|
||||
val deltaTorque = if (inputTorque != 0) Math.max(Math.abs(inputTorque) - load * deltaTime, 0) * inputTorque / Math.abs(inputTorque) else 0
|
||||
|
||||
|
||||
//Set torque and angular velocity of all nodes
|
||||
getNodes.foreach(
|
||||
n =>
|
||||
{
|
||||
val prevTorque = n.torque
|
||||
val prevAngularVelocity = n.angularVelocity
|
||||
|
||||
val inversion = if (spinMap(n)) 1 else -1
|
||||
n._torque = deltaTorque * inversion
|
||||
val angularAcceleration = deltaTorque / n.radius
|
||||
n._angularVelocity = angularAcceleration * deltaTime * inversion
|
||||
|
||||
if (Math.abs(n.torque - prevTorque) > 0)
|
||||
if (n.prevTorque != n.torque)
|
||||
n.onTorqueChanged()
|
||||
|
||||
if (Math.abs(n.angularVelocity - prevAngularVelocity) > 0)
|
||||
if (n.prevAngularVelocity != n.angularVelocity)
|
||||
n.onVelocityChanged()
|
||||
|
||||
//Clear buffers
|
||||
n.bufferTorque = n.bufferDefaultTorque
|
||||
})
|
||||
*/
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
def recurse(passed: Seq[NodeMechanical])
|
||||
def recurse(deltaTime: Double, passed: Seq[NodeMechanical])
|
||||
{
|
||||
val curr = passed(passed.size - 1)
|
||||
|
||||
|
@ -104,20 +83,20 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
|||
{
|
||||
val prev = passed(passed.size - 2)
|
||||
val ratio = curr.radius / prev.radius
|
||||
val invert = if (curr.inverseRotation(prev)) 1 else -1
|
||||
curr._torque += passed(0).torque * ratio * invert
|
||||
curr._angularVelocity += passed(0).angularVelocity / ratio * invert
|
||||
val invert = if (curr.inverseRotation(prev)) -1 else 1
|
||||
curr._torque += prev.torque * ratio * invert
|
||||
curr._angularVelocity += prev.angularVelocity / ratio * invert
|
||||
}
|
||||
else
|
||||
{
|
||||
curr._torque += curr.bufferTorque
|
||||
curr._angularVelocity += curr.bufferAngularVelocity
|
||||
curr._angularVelocity += curr.bufferAngularVelocity * deltaTime
|
||||
curr.bufferTorque = 0
|
||||
curr.bufferAngularVelocity = 0
|
||||
}
|
||||
|
||||
if (curr.power > 0)
|
||||
curr.connections.foreach(c => recurse(passed :+ c))
|
||||
curr.connections.filter(!passed.contains(_)).foreach(c => recurse(deltaTime, passed :+ c))
|
||||
}
|
||||
|
||||
override def continueUpdate = getNodes.size > 0
|
||||
|
|
|
@ -19,6 +19,9 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
|||
protected[grid] var _torque = 0D
|
||||
protected[grid] var _angularVelocity = 0D
|
||||
|
||||
protected[grid] var prevTorque = 0D
|
||||
protected[grid] var prevAngularVelocity = 0D
|
||||
|
||||
/**
|
||||
* Gets the angular velocity of the mechanical device from a specific side
|
||||
*
|
||||
|
@ -73,7 +76,7 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
|||
return prevAngle
|
||||
}
|
||||
|
||||
override def rotate(torque: Double)
|
||||
override def rotate(torque: Double, angularVelocity : Double)
|
||||
{
|
||||
bufferTorque += torque
|
||||
bufferAngularVelocity += torque
|
||||
|
|
|
@ -58,7 +58,7 @@ class TileWaterTurbine extends TileTurbine
|
|||
{
|
||||
if (powerTicks > 0)
|
||||
{
|
||||
getMultiBlock.get.mechanicalNode.rotate(getWaterPower)
|
||||
getMultiBlock.get.mechanicalNode.rotate(getWaterPower, getWaterPower / 100)
|
||||
powerTicks -= 1
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ class TileWaterTurbine extends TileTurbine
|
|||
powerTicks = 20
|
||||
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
|
||||
worldObj.setBlock(xCoord, yCoord - 1, zCoord, Blocks.flowing_water)
|
||||
getMultiBlock.get.mechanicalNode.rotate(10000)
|
||||
getMultiBlock.get.mechanicalNode.rotate(10000, 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,12 +95,12 @@ class TileWaterTurbine extends TileTurbine
|
|||
|
||||
if (getDirection.offsetX != 0)
|
||||
{
|
||||
getMultiBlock.get.mechanicalNode.rotate(if (invert) -1 else 1 * Math.abs(getWaterPower * vector.z * (7 - metadata) / 7f))
|
||||
getMultiBlock.get.mechanicalNode.rotate(if (invert) -1 else 1 * Math.abs(getWaterPower * vector.z * (7 - metadata) / 7f), 10)
|
||||
powerTicks = 20
|
||||
}
|
||||
if (getDirection.offsetZ != 0)
|
||||
{
|
||||
getMultiBlock.get.mechanicalNode.rotate(if (invert) -1 else 1 * Math.abs(getWaterPower * vector.x * (7 - metadata) / 7f))
|
||||
getMultiBlock.get.mechanicalNode.rotate(if (invert) -1 else 1 * Math.abs(getWaterPower * vector.x * (7 - metadata) / 7f), 10)
|
||||
powerTicks = 20
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ class TileWindTurbine extends TileTurbine with IBoilHandler
|
|||
else
|
||||
{
|
||||
//This is a horizontal turbine
|
||||
getMultiBlock.get.mechanicalNode.rotate(if (gasTank.getFluid != null) gasTank.drain(gasTank.getFluidAmount, true).amount else 0 * 1000 * Settings.steamMultiplier)
|
||||
getMultiBlock.get.mechanicalNode.rotate(if (gasTank.getFluid != null) gasTank.drain(gasTank.getFluidAmount, true).amount else 0 * 1000 * Settings.steamMultiplier, 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue