Skip to content

Commit

Permalink
Merge commit 'bc2a51508f36c6ee21437a6b5b200fba7c660bbb'
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Dec 11, 2023
2 parents 92f00c6 + bc2a515 commit 49120c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class LocomotiveDiesel extends Locomotive {

private float soundThrottle;
private float relativeRPM;
private float internalBurn = 0;
private int turnOnOffDelay = 0;

Expand Down Expand Up @@ -163,7 +163,7 @@ public double getAppliedTractiveEffort(Speed speed) {
double efficiency = 0.82; // Similar to a *lot* of imperial references
double speed_M_S = (Math.abs(speed.metric())/3.6);
double maxPowerAtSpeed = maxPower_W * efficiency / Math.max(0.001, speed_M_S);
return maxPowerAtSpeed * getThrottle() * getReverser();
return maxPowerAtSpeed * relativeRPM * getReverser();
}
return 0;
}
Expand All @@ -176,13 +176,13 @@ public void onTick() {
turnOnOffDelay -= 1;
}

float absThrottle = Math.abs(this.getThrottle());
if (this.relativeRPM > absThrottle) {
this.relativeRPM -= Math.min(0.01f, this.relativeRPM - absThrottle);
} else if (this.relativeRPM < absThrottle) {
this.relativeRPM += Math.min(0.01f, absThrottle - this.relativeRPM);
}
if (getWorld().isClient) {
float absThrottle = Math.abs(this.getThrottle());
if (this.soundThrottle > absThrottle) {
this.soundThrottle -= Math.min(0.01f, this.soundThrottle - absThrottle);
} else if (this.soundThrottle < absThrottle) {
this.soundThrottle += Math.min(0.01f, absThrottle - this.soundThrottle);
}
return;
}

Expand Down Expand Up @@ -261,8 +261,8 @@ public void onDissassemble() {
setTurnedOn(false);
}

public float getSoundThrottle() {
return soundThrottle;
public float getRelativeRPM() {
return relativeRPM;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ protected void effects(LocomotiveDiesel stock) {
: 0);
if (idle != null) {
if (stock.isRunning()) {
float volume = Math.max(0.1f, stock.getSoundThrottle());
float volume = Math.max(0.1f, stock.getRelativeRPM());
float pitchRange = stock.getDefinition().getEnginePitchRange();
float pitch = (1-pitchRange) + stock.getSoundThrottle() * pitchRange;
float pitch = (1-pitchRange) + stock.getRelativeRPM() * pitchRange;
if (running == null) {
// Simple
idle.effects(stock, volume, pitch);
} else {
boolean isThrottledUp = stock.getSoundThrottle() > 0.01;
boolean isThrottledUp = stock.getRelativeRPM() > 0.01;
float fade = runningFade.getOrDefault(stock.getUUID(), 0f);
fade += 0.05f * (isThrottledUp ? 1 : -1);
fade = Math.min(Math.max(fade, 0), 1);
Expand Down

0 comments on commit 49120c3

Please sign in to comment.