Skip to content

Commit

Permalink
Allow switching between average and instant fuel consumption [P]
Browse files Browse the repository at this point in the history
  • Loading branch information
Mc-Pain committed Dec 5, 2022
1 parent 56725cc commit d8f224c
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The UI is extremely minimalistic and there are only a few controls used to inter
| Space + Scroll | Fine throttle adjustment |
| 1, 2, 3, 4, 5 | Simulation time warp |
| Tab | Change screen |
| P | Toggle Average/Instant fuel consumption |

### Using the RPM hold
The RPM hold feature will hold the engine at a specific RPM and also measure the engine's horsepower and torque at that RPM. You can enable RPM hold by pressing the `H` key. **You must then enable the dynomometer** (press the `D` key) in order for the RPM hold to take effect. To change the hold speed, hold the `G` key and scroll with the mouse wheel. The RPM hold will be shown on the `DYNO. SPEED` gauge in the lower left of the screen.
Expand Down
9 changes: 9 additions & 0 deletions include/fuel_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ class FuelCluster : public UiElement {
Engine *m_engine;
Simulator *m_simulator;

double m_fuelConsumedOld;
double m_deltaFuel;

double m_distanceOld;
double m_deltaDist;

bool m_instantConsumption;

private:
double getTotalVolumeFuelConsumed() const;

};

#endif /* ATG_ENGINE_SIM_FUEL_CLUSTER_H */
2 changes: 2 additions & 0 deletions include/right_gauge_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class RightGaugeCluster : public UiElement {
void setUnits();
double getManifoldPressureWithUnits(double ambientPressure);

void toggleInstantConsumption() { m_fuelCluster->m_instantConsumption = !m_fuelCluster->m_instantConsumption; }

Simulator *m_simulator;

private:
Expand Down
4 changes: 4 additions & 0 deletions include/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Simulator {
int getSimulationFrequency() const { return m_simulationFrequency; }

double getTimestep() const { return 1.0 / m_simulationFrequency; }
double getSinceLastUpdate() const { return m_sinceLastUpdate; }
void resetSinceLastUpdate() { m_sinceLastUpdate = 0.0; }

void setTargetSynthesizerLatency(double latency) { m_targetSynthesizerLatency = latency; }
double getTargetSynthesizerLatency() const { return m_targetSynthesizerLatency; }
Expand Down Expand Up @@ -107,6 +109,8 @@ class Simulator {
double m_physicsProcessingTime;

int m_simulationFrequency;
double m_elapsedTime;
double m_sinceLastUpdate;

double m_targetSynthesizerLatency;
double m_simulationSpeed;
Expand Down
4 changes: 4 additions & 0 deletions src/engine_sim_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,10 @@ void EngineSimApplication::processEngineInput() {
m_targetClutchPressure = 1.0;
}

if (m_engine.ProcessKeyDown(ysKey::Code::P)) {
m_rightGaugeCluster->toggleInstantConsumption();
}

m_targetClutchPressure = clamp(m_targetClutchPressure);

double clutchRC = 0.001;
Expand Down
92 changes: 77 additions & 15 deletions src/fuel_cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
FuelCluster::FuelCluster() {
m_engine = nullptr;
m_simulator = nullptr;

m_fuelConsumedOld = 0.0;
m_distanceOld = 0.0;
m_instantConsumption = false;
}

FuelCluster::~FuelCluster() {
Expand Down Expand Up @@ -66,26 +70,84 @@ void FuelCluster::render() {
const double travelledDistance = (m_simulator->getVehicle() != nullptr)
? m_simulator->getVehicle()->getTravelledDistance()
: 0.0;
const double mpg = units::convert(travelledDistance, units::mile) / fuelConsumed_gallons;

ss = std::stringstream();
ss << std::setprecision(2) << std::fixed;
ss << mpg << " MPG";
if (m_simulator->getSinceLastUpdate() > 1.0) {
m_deltaFuel = fuelConsumed - m_fuelConsumedOld;
m_fuelConsumedOld = fuelConsumed;

const Bounds mpgBounds = grid.get(bodyBounds, 0, 6);
drawText(ss.str(), mpgBounds, 16.0f, Bounds::lm);
m_deltaDist = travelledDistance - m_distanceOld;
m_distanceOld = travelledDistance;

const double lp100km = (travelledDistance != 0)
? units::convert(fuelConsumed, units::L)
/ (units::convert(travelledDistance, units::km) / 100.0)
: 0;
m_simulator->resetSinceLastUpdate();
}

ss = std::stringstream();
ss << std::setprecision(2) << std::fixed;
ss << ((lp100km > 100.0) ? 100.0 : lp100km) << " L/100 KM";
if (!m_instantConsumption) {
const double mpg = units::convert(travelledDistance, units::mile) / fuelConsumed_gallons;

ss = std::stringstream();
ss << std::setprecision(2) << std::fixed;
ss << mpg << " MPG";

const Bounds mpgBounds = grid.get(bodyBounds, 0, 6);
drawText(ss.str(), mpgBounds, 16.0f, Bounds::lm);

const double lp100km = (travelledDistance != 0)
? units::convert(fuelConsumed, units::L)
/ (units::convert(travelledDistance, units::km) / 100.0)
: 0;

ss = std::stringstream();
ss << std::setprecision(2) << std::fixed;
ss << ((lp100km > 100.0) ? 100.0 : lp100km) << " L/100 KM";

const Bounds lp100kmBounds = grid.get(bodyBounds, 0, 7);
drawText(ss.str(), lp100kmBounds, 12.0f, Bounds::lm);
} else {
const double speed = (m_simulator->getVehicle() != nullptr)
? m_simulator->getVehicle()->getSpeed()
: 0.0;

const double delta_gal = units::convert(m_deltaFuel, units::gal);
const double delta_l = units::convert(m_deltaFuel, units::L);

if (units::convert(speed, units::km / units::hour) < 8.0) {
const double galh = delta_gal * 3600;

ss = std::stringstream();
ss << std::setprecision(2) << std::fixed;
ss << galh << " GAL/H";

const Bounds mpgBounds = grid.get(bodyBounds, 0, 6);
drawText(ss.str(), mpgBounds, 16.0f, Bounds::lm);

const double lh = delta_l * 3600;

ss = std::stringstream();
ss << std::setprecision(2) << std::fixed;
ss << lh << " L/H";

const Bounds lp100kmBounds = grid.get(bodyBounds, 0, 7);
drawText(ss.str(), lp100kmBounds, 12.0f, Bounds::lm);
} else {
const double mpg = units::convert(m_deltaDist, units::mile) / delta_gal;

ss = std::stringstream();
ss << std::setprecision(2) << std::fixed;
ss << mpg << " MPG";

const Bounds mpgBounds = grid.get(bodyBounds, 0, 6);
drawText(ss.str(), mpgBounds, 16.0f, Bounds::lm);

const double lp100km = 100 * delta_l / units::convert(m_deltaDist, units::km);

ss = std::stringstream();
ss << std::setprecision(2) << std::fixed;
ss << ((lp100km > 100.0) ? 100.0 : lp100km) << " L/100 KM";

const Bounds lp100kmBounds = grid.get(bodyBounds, 0, 7);
drawText(ss.str(), lp100kmBounds, 12.0f, Bounds::lm);
const Bounds lp100kmBounds = grid.get(bodyBounds, 0, 7);
drawText(ss.str(), lp100kmBounds, 12.0f, Bounds::lm);
}
}

UiElement::render();
}
Expand Down
7 changes: 7 additions & 0 deletions src/simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Simulator::Simulator() {
m_filteredEngineSpeed = 0.0;
m_dynoTorqueSamples = nullptr;
m_lastDynoTorqueSample = 0;

m_elapsedTime = 0.0;
m_sinceLastUpdate = 0.0;
}

Simulator::~Simulator() {
Expand Down Expand Up @@ -149,7 +152,11 @@ bool Simulator::simulateStep() {
writeToSynthesizer();

++m_currentIteration;

m_elapsedTime += timestep;
m_sinceLastUpdate += timestep;
return true;

}

double Simulator::getTotalExhaustFlow() const {
Expand Down

0 comments on commit d8f224c

Please sign in to comment.