Skip to content

Commit

Permalink
Added info cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
ange-yaghi committed Jul 14, 2022
1 parent 5d39b3d commit cd207ca
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ add_executable(engine-sim-app WIN32
src/firing_order_display.cpp
src/load_simulation_cluster.cpp
src/mixer_cluster.cpp
src/info_cluster.cpp

# Include files
include/delta.h
Expand Down Expand Up @@ -178,6 +179,7 @@ add_executable(engine-sim-app WIN32
include/firing_order_display.h
include/load_simulation_cluster.h
include/mixer_cluster.h
include/info_cluster.h
)

target_link_libraries(engine-sim-app
Expand Down
Binary file modified assets/assets.blend
Binary file not shown.
Binary file modified assets/assets.dia
Binary file not shown.
Binary file modified assets/assets.ysce
Binary file not shown.
8 changes: 8 additions & 0 deletions include/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "combustion_chamber.h"
#include "units.h"

#include <string>

class Engine : public Part {
public:
struct FuelParameters {
Expand All @@ -32,6 +34,8 @@ class Engine : public Part {
int ExhaustSystemCount;
int IntakeCount;

std::string Name;

double StarterTorque = units::torque(90.0, units::ft_lb);
double StarterSpeed = units::rpm(200);
double Redline = units::rpm(6500);
Expand All @@ -46,6 +50,8 @@ class Engine : public Part {
void initialize(const Parameters &params);
virtual void destroy();

std::string getName() const { return m_name; }

virtual Crankshaft *getOutputCrankshaft() const;
virtual void setThrottle(double throttle);
virtual double getThrottle() const;
Expand Down Expand Up @@ -85,6 +91,8 @@ class Engine : public Part {
const FuelParameters &getFuel() const { return m_fuel; }

protected:
std::string m_name;

Crankshaft *m_crankshafts;
int m_crankshaftCount;

Expand Down
2 changes: 2 additions & 0 deletions include/engine_sim_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "performance_cluster.h"
#include "load_simulation_cluster.h"
#include "mixer_cluster.h"
#include "info_cluster.h"

#include "delta.h"
#include "dtv.h"
Expand Down Expand Up @@ -108,6 +109,7 @@ class EngineSimApplication {
PerformanceCluster *m_performanceCluster;
LoadSimulationCluster *m_loadSimulationCluster;
MixerCluster *m_mixerCluster;
InfoCluster *m_infoCluster;

bool m_paused;

Expand Down
31 changes: 31 additions & 0 deletions include/info_cluster.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef ATG_ENGINE_SIM_INFO_CLUSTER_H
#define ATG_ENGINE_SIM_INFO_CLUSTER_H

#include "ui_element.h"

#include "engine.h"

#include <string>

class InfoCluster : public UiElement {
public:
InfoCluster();
virtual ~InfoCluster();

virtual void initialize(EngineSimApplication *app);
virtual void destroy();

virtual void update(float dt);
virtual void render();

void setEngine(Engine *engine) { m_engine = engine; }
void setLogMessage(const std::string &logMessage) { m_logMessage = logMessage; }
std::string getLogMessage() const { return m_logMessage; }

protected:
Engine *m_engine;

std::string m_logMessage;
};

#endif /* ATG_ENGINE_SIM_INFO_CLUSTER_H */
11 changes: 11 additions & 0 deletions include/ui_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class UiElement {

void resetShader();

void drawModel(
dbasic::ModelAsset *model,
const ysVector &color,
const Point &p,
const Point &scale = { 1.0f, 1.0f });
void drawFrame(
const Bounds &bounds,
float thickness,
Expand All @@ -90,6 +95,12 @@ class UiElement {
const Bounds &bounds,
float height,
const Point &ref = Bounds::tl);
void drawAlignedText(
const std::string &s,
const Bounds &bounds,
float height,
const Point &ref = Bounds::tl,
const Point &refText = Bounds::tl);
void drawCenteredText(
const std::string &s,
const Bounds &bounds,
Expand Down
4 changes: 3 additions & 1 deletion include/ui_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ struct Bounds {
return { m0.componentMin(b.m0), m1.componentMax(b.m1) };
}

void move(const Point &delta) {
Bounds move(const Point &delta) {
m0 += delta;
m1 += delta;

return *this;
}

void setPosition(const Point &pos, const Point &ref = tl) {
Expand Down
1 change: 1 addition & 0 deletions include/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace units {
extern constexpr double mL = cc;
extern constexpr double L = mL * 1000.0;
extern constexpr double cubic_feet = foot * foot * foot;
extern constexpr double cubic_inches = inch * inch * inch;
extern constexpr double gal = 3.785411784 * L;

// Molecular
Expand Down
3 changes: 3 additions & 0 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <assert.h>

Engine::Engine() {
m_name = "";

m_crankshafts = nullptr;
m_cylinderBanks = nullptr;
m_heads = nullptr;
Expand Down Expand Up @@ -48,6 +50,7 @@ void Engine::initialize(const Parameters &params) {
m_starterTorque = params.StarterTorque;
m_starterSpeed = params.StarterSpeed;
m_redline = params.Redline;
m_name = params.Name;

m_fuel = params.Fuel;

Expand Down
102 changes: 73 additions & 29 deletions src/engine_sim_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ EngineSimApplication::EngineSimApplication() {
m_performanceCluster = nullptr;
m_loadSimulationCluster = nullptr;
m_mixerCluster = nullptr;
m_infoCluster = nullptr;

m_oscillatorSampleOffset = 0;
m_gameWindowHeight = 256;
Expand Down Expand Up @@ -136,6 +137,7 @@ void EngineSimApplication::initialize() {
m_textRenderer.SetFont(m_engine.GetConsole()->GetFont());

Engine::Parameters engineParams;
engineParams.Name = "Chev. 454 V8";
engineParams.CylinderBanks = 2;
engineParams.CylinderCount = 8;
engineParams.CrankshaftCount = 1;
Expand Down Expand Up @@ -520,6 +522,9 @@ void EngineSimApplication::initialize() {
m_mixerCluster = m_uiManager.getRoot()->addElement<MixerCluster>();
m_mixerCluster->setSimulator(&m_simulator);

m_infoCluster = m_uiManager.getRoot()->addElement<InfoCluster>();
m_infoCluster->setEngine(&m_iceEngine);

m_audioBuffer.initialize(44100, 44100);
m_audioBuffer.m_writePointer = (int)(44100 * 0.1);

Expand Down Expand Up @@ -566,29 +571,31 @@ void EngineSimApplication::process(float frame_dt) {
const double cylinderPressure = m_simulator.getEngine()->getChamber(0)->m_system.pressure()
+ m_simulator.getEngine()->getChamber(0)->m_system.dynamicPressure(-1.0, 0.0);

m_oscCluster->getTotalExhaustFlowOscilloscope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getTotalExhaustFlow() / m_simulator.getTimestep());
m_oscCluster->getCylinderPressureScope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(constants::pi),
std::sqrt(cylinderPressure));
m_oscCluster->getExhaustFlowOscilloscope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getEngine()->getChamber(0)->getLastTimestepExhaustFlow() / m_simulator.getTimestep());
m_oscCluster->getIntakeFlowOscilloscope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getEngine()->getChamber(0)->getLastTimestepIntakeFlow() / m_simulator.getTimestep());
m_oscCluster->getCylinderMoleculesScope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getEngine()->getChamber(0)->m_system.n());
m_oscCluster->getExhaustValveLiftOscilloscope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getEngine()->getChamber(0)->getCylinderHead()->exhaustValveLift(
m_simulator.getEngine()->getChamber(0)->getPiston()->getCylinderIndex()));
m_oscCluster->getIntakeValveLiftOscilloscope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getEngine()->getChamber(0)->getCylinderHead()->intakeValveLift(
m_simulator.getEngine()->getChamber(0)->getPiston()->getCylinderIndex()));
if (m_simulator.getCurrentIteration() % 2 == 0) {
m_oscCluster->getTotalExhaustFlowOscilloscope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getTotalExhaustFlow() / m_simulator.getTimestep());
m_oscCluster->getCylinderPressureScope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(constants::pi),
std::sqrt(cylinderPressure));
m_oscCluster->getExhaustFlowOscilloscope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getEngine()->getChamber(0)->getLastTimestepExhaustFlow() / m_simulator.getTimestep());
m_oscCluster->getIntakeFlowOscilloscope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getEngine()->getChamber(0)->getLastTimestepIntakeFlow() / m_simulator.getTimestep());
m_oscCluster->getCylinderMoleculesScope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getEngine()->getChamber(0)->m_system.n());
m_oscCluster->getExhaustValveLiftOscilloscope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getEngine()->getChamber(0)->getCylinderHead()->exhaustValveLift(
m_simulator.getEngine()->getChamber(0)->getPiston()->getCylinderIndex()));
m_oscCluster->getIntakeValveLiftOscilloscope()->addDataPoint(
m_simulator.getEngine()->getCrankshaft(0)->getCycleAngle(),
m_simulator.getEngine()->getChamber(0)->getCylinderHead()->intakeValveLift(
m_simulator.getEngine()->getChamber(0)->getPiston()->getCylinderIndex()));
}
}

auto proc_t1 = std::chrono::steady_clock::now();
Expand Down Expand Up @@ -708,14 +715,9 @@ void EngineSimApplication::run() {

updateScreenSizeStability();

if (m_engine.ProcessKeyDown(ysKey::Code::Space)
&& m_engine.GetGameWindow()->IsActive())
{
//m_paused = !m_paused;
}

if (m_engine.ProcessKeyDown(ysKey::Code::F)) {
m_engine.GetGameWindow()->SetWindowStyle(ysWindow::WindowStyle::Fullscreen);
m_infoCluster->setLogMessage("Entered fullscreen mode");
}

bool fineControlInUse = false;
Expand All @@ -729,6 +731,8 @@ void EngineSimApplication::run() {

m_simulator.getSynthesizer()->setAudioParameters(audioParams);
fineControlInUse = true;

m_infoCluster->setLogMessage("[Z] - Set volume to " + std::to_string(audioParams.Volume));
}
else if (m_engine.IsKeyDown(ysKey::Code::X)) {
const double rate = fineControlMode
Expand All @@ -740,6 +744,8 @@ void EngineSimApplication::run() {

m_simulator.getSynthesizer()->setAudioParameters(audioParams);
fineControlInUse = true;

m_infoCluster->setLogMessage("[X] - Set convolution level to " + std::to_string(audioParams.Convolution));
}
else if (m_engine.IsKeyDown(ysKey::Code::C)) {
const double rate = fineControlMode
Expand All @@ -751,6 +757,8 @@ void EngineSimApplication::run() {

m_simulator.getSynthesizer()->setAudioParameters(audioParams);
fineControlInUse = true;

m_infoCluster->setLogMessage("[C] - Set high freq. gain to " + std::to_string(audioParams.dF_F_mix));
}
else if (m_engine.IsKeyDown(ysKey::Code::V)) {
const double rate = fineControlMode
Expand All @@ -762,6 +770,8 @@ void EngineSimApplication::run() {

m_simulator.getSynthesizer()->setAudioParameters(audioParams);
fineControlInUse = true;

m_infoCluster->setLogMessage("[V] - Set low freq. noise to " + std::to_string(audioParams.AirNoise));
}
else if (m_engine.IsKeyDown(ysKey::Code::B)) {
const double rate = fineControlMode
Expand All @@ -773,8 +783,11 @@ void EngineSimApplication::run() {

m_simulator.getSynthesizer()->setAudioParameters(audioParams);
fineControlInUse = true;

m_infoCluster->setLogMessage("[B] - Set high freq. noise to " + std::to_string(audioParams.InputSampleNoise));
}

const double prevTargetThrottle = targetThrottle;
targetThrottle = fineControlMode ? targetThrottle : 1.0;
if (m_engine.IsKeyDown(ysKey::Code::Q)) {
targetThrottle = 0.99;
Expand All @@ -792,12 +805,21 @@ void EngineSimApplication::run() {
targetThrottle = std::fmax(0.0, std::fmin(1.0, targetThrottle - mouseWheelDelta * 0.0001));
}

if (prevTargetThrottle != targetThrottle) {
m_infoCluster->setLogMessage("Throttle set to " + std::to_string(targetThrottle));
}

throttle = targetThrottle * 0.5 + 0.5 * throttle;

m_iceEngine.setThrottle(throttle);

if (m_engine.ProcessKeyDown(ysKey::Code::D)) {
m_simulator.m_dyno.m_enabled = !m_simulator.m_dyno.m_enabled;

const std::string msg = m_simulator.m_dyno.m_enabled
? "DYNOMOMETER ENABLED"
: "DYNOMOMETER DISABLED";
m_infoCluster->setLogMessage(msg);
}

if (m_simulator.m_dyno.m_enabled) {
Expand All @@ -819,28 +841,49 @@ void EngineSimApplication::run() {

m_simulator.m_dyno.m_rotationSpeed = m_dynoSpeed + units::rpm(1000);

const bool prevStarterEnabled = m_simulator.m_starterMotor.m_enabled;
if (m_engine.IsKeyDown(ysKey::Code::S)) {
m_simulator.m_starterMotor.m_enabled = true;
}
else {
m_simulator.m_starterMotor.m_enabled = false;
}

if (prevStarterEnabled != m_simulator.m_starterMotor.m_enabled) {
const std::string msg = m_simulator.m_starterMotor.m_enabled
? "STARTER ENABLED"
: "STARTER DISABLED";
m_infoCluster->setLogMessage(msg);
}

if (m_engine.ProcessKeyDown(ysKey::Code::A)) {
m_simulator.getEngine()->getIgnitionModule()->m_enabled =
!m_simulator.getEngine()->getIgnitionModule()->m_enabled;

const std::string msg = m_simulator.getEngine()->getIgnitionModule()->m_enabled
? "IGNITION ENABLED"
: "IGNITION DISABLED";
m_infoCluster->setLogMessage(msg);
}

if (m_engine.ProcessKeyDown(ysKey::Code::Up)) {
m_simulator.getTransmission()->changeGear(m_simulator.getTransmission()->getGear() + 1);

m_infoCluster->setLogMessage(
"UPSHIFTED TO " + std::to_string(m_simulator.getTransmission()->getGear()));
}
else if (m_engine.ProcessKeyDown(ysKey::Code::Down)) {
m_simulator.getTransmission()->changeGear(m_simulator.getTransmission()->getGear() - 1);

m_infoCluster->setLogMessage(
"DOWNSHIFTED TO " + std::to_string(m_simulator.getTransmission()->getGear()));
}

double newClutchPressure = 1.0;
if (m_engine.IsKeyDown(ysKey::Code::Shift)) {
newClutchPressure = 0.0;

m_infoCluster->setLogMessage("CLUTCH DEPRESSED");
}

double clutchRC = 0.001;
Expand Down Expand Up @@ -997,6 +1040,7 @@ void EngineSimApplication::renderScene() {
grid1x3.v_cells = 3;
grid1x3.h_cells = 1;
m_mixerCluster->m_bounds = grid1x3.get(grid3x3.get(windowBounds, 0, 0), 0, 2);
m_infoCluster->m_bounds = grid1x3.get(grid3x3.get(windowBounds, 0, 0), 0, 0, 1, 2);

m_geometryGenerator.reset();

Expand Down
Loading

0 comments on commit cd207ca

Please sign in to comment.