Adjusted the way how load works

This commit is contained in:
Calclavia 2014-11-13 21:11:00 +08:00
parent 03e04b3ae3
commit 8b7ae367e6
3 changed files with 30 additions and 26 deletions

View file

@ -29,7 +29,7 @@ import resonantinduction.mechanical.mech.PartMechanical
class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
{
var isClockwiseCrank: Boolean = true
var manualCrankTime = 0D
var manualCrankTime = 0
var multiBlockRadius: Int = 1
/** Multiblock */
val multiBlock = new GearMultiBlockHandler(this)
@ -53,8 +53,9 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
{
if (manualCrankTime > 0)
{
//A punch his around 5000 Newtons
mechanicalNode.rotate(if (isClockwiseCrank) 50 else -50)
manualCrankTime -= 0.1
manualCrankTime -= 1
}
}
@ -75,8 +76,8 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
}
isClockwiseCrank = player.isSneaking
getMultiBlock.get.manualCrankTime = 40
getMultiBlock.get.manualCrankTime = 2
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, Reference.prefix + "gearCrank", 0.5f, 0.9f + world.rand.nextFloat * 0.2f)
player.addExhaustion(0.01f)
return true

View file

@ -19,7 +19,7 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
*/
val spinMap = mutable.WeakHashMap.empty[NodeMechanical, Boolean]
private var friction = 0D
private var load = 0D
/**
* Rebuild the node list starting from the first node and recursively iterating through its connections.
@ -29,7 +29,7 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
super.reconstruct(first)
UpdateTicker.addUpdater(this)
friction = getNodes.map(n => n.getLoad).foldLeft(0D)(_ + _)
load = getNodes.map(n => n.getLoad).foldLeft(0D)(_ + _)
}
override protected def populateNode(node: NodeMechanical, prev: NodeMechanical)
@ -54,32 +54,31 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
//Calculate the total input equivalent torque
val inputTorque = inputs
.map(n => n.bufferTorque * (if (spinMap(n)) 1 else -1))
.foldLeft(0D)(_ + _)
.map(n => n.bufferTorque * (if (spinMap(n)) 1 else -1))
.foldLeft(0D)(_ + _)
val deltaTorque = inputTorque - friction * inputTorque
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
getNodes.foreach(n =>
{
val prevTorque = n.torque
val prevAngularVelocity = n.angularVelocity
val inversion = if (spinMap(n)) 1 else -1
n.torque = deltaTorque * n.ratio * inversion
val angularAcceleration = deltaTorque / n.momentOfInertia
n.angularVelocity = angularAcceleration / n.ratio * deltaTime * inversion
val inversion = if (spinMap(n)) 1 else -1
n.torque = deltaTorque * n.ratio * inversion
val angularAcceleration = deltaTorque / n.momentOfInertia
n.angularVelocity = angularAcceleration / n.ratio * deltaTime * inversion
if (Math.abs(prevTorque - n.torque) >= 0.1)
n.onTorqueChanged()
if (Math.abs(prevTorque - n.torque) >= 0.1)
n.onTorqueChanged()
if (Math.abs(prevAngularVelocity - n.angularVelocity) >= 0.1)
n.onVelocityChanged()
if (Math.abs(prevAngularVelocity - n.angularVelocity) >= 0.01)
n.onVelocityChanged()
//Clear buffers
n.bufferTorque = 0
})
//Clear buffers
n.bufferTorque = 0
})
}
}

View file

@ -26,9 +26,9 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
protected[grid] var bufferTorque = 0D
/**
* A percentage value indicating how much friction the loss.
* The mechanical load
*/
var load = 0.1D
var load = 10D
/**
* Angle calculations
@ -70,6 +70,10 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
//Moment of inertia = m * r ^ 2
def momentOfInertia = 1d
/**
* The mechanical load
* @return Torque in Newton meters per second
*/
def getLoad = load
override def rotate(torque: Double)