Skip to content

Commit

Permalink
Separate external forces into Linear and Angular (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
millennIumAMbiguity authored Oct 11, 2023
1 parent a0b9076 commit 8fe9a0b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ object EurekaConfig {
class Server {

@JsonSchema(description = "Movement power per engine when heated fully")
val enginePower: Float = 2000000f
val enginePowerLinear: Float = 2000000f

@JsonSchema(description = "Movement power per engine with minimal heat")
val minEnginePower: Float = 10000f
val enginePowerLinearMin: Float = 10000f

@JsonSchema(description = "Turning power per engine when heated fully")
val engineTurnPower = 1f
val enginePowerAngular = 1.0f

@JsonSchema(description = "Turning power per engine when minimal heat")
val enginePowerAngularMin = 0.0f

@JsonSchema(description = "The amount of heat a engine loses per tick")
val engineHeatLoss = 0.01f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ class EngineBlockEntity(pos: BlockPos, state: BlockState) :
effectiveHeat = heat / 100f
}

eurekaShipControl.power += lerp(
EurekaConfig.SERVER.minEnginePower,
EurekaConfig.SERVER.enginePower,
eurekaShipControl.powerLinear += lerp(
EurekaConfig.SERVER.enginePowerLinearMin,
EurekaConfig.SERVER.enginePowerLinear,
effectiveHeat,
)

eurekaShipControl.powerAngular += lerp(
EurekaConfig.SERVER.enginePowerAngularMin,
EurekaConfig.SERVER.enginePowerAngular,
effectiveHeat,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class EurekaShipControl : ShipForcesInducer, ServerTickListener {
@JsonIgnore
internal var ship: ServerShip? = null

private var extraForce = 0.0
private var extraForceLinear = 0.0
private var extraForceAngular = 0.0

var aligning = false
var disassembling = false // Disassembling also affects position
private var physConsumption = 0f
Expand Down Expand Up @@ -213,8 +215,7 @@ class EurekaShipControl : ShipForcesInducer, ServerTickListener {
}.coerceIn(0.5, EurekaConfig.SERVER.maxSizeForTurnSpeedPenalty)

val maxLinearAcceleration = EurekaConfig.SERVER.turnAcceleration
val maxLinearSpeed = EurekaConfig.SERVER.turnSpeed +
extraForce / EurekaConfig.SERVER.enginePower * EurekaConfig.SERVER.engineTurnPower
val maxLinearSpeed = EurekaConfig.SERVER.turnSpeed + extraForceAngular

// acceleration = alpha * r
// therefore: maxAlpha = maxAcceleration / r
Expand Down Expand Up @@ -278,8 +279,8 @@ class EurekaShipControl : ShipForcesInducer, ServerTickListener {
val extraForceNeeded = Vector3d(idealForwardForce).sub(baseForwardForce)
val actualExtraForce = Vector3d(baseForwardForce)

if (extraForce != 0.0) {
actualExtraForce.fma(min(extraForce / extraForceNeeded.length(), 1.0), extraForceNeeded)
if (extraForceLinear != 0.0) {
actualExtraForce.fma(min(extraForceLinear / extraForceNeeded.length(), 1.0), extraForceNeeded)
}

physShip.applyInvariantForce(actualExtraForce)
Expand Down Expand Up @@ -321,7 +322,8 @@ class EurekaShipControl : ShipForcesInducer, ServerTickListener {
seatedPlayer?.displayClientMessage(TranslatableComponent(cruiseKey), true)
}

var power = 0.0
var powerLinear = 0.0
var powerAngular = 0.0
var anchors = 0 // Amount of anchors
set(v) {
field = v; deleteIfEmpty()
Expand Down Expand Up @@ -368,8 +370,12 @@ class EurekaShipControl : ShipForcesInducer, ServerTickListener {
}

override fun onServerTick() {
extraForce = power
power = 0.0
extraForceLinear = powerLinear
powerLinear = 0.0

extraForceAngular = powerAngular
powerAngular = 0.0;

consumed = physConsumption * /* should be physics ticks based*/ 0.1f
physConsumption = 0.0f
}
Expand Down

0 comments on commit 8fe9a0b

Please sign in to comment.