├── .github └── workflows │ └── cmake.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── CMakeSettings.json ├── LICENSE ├── README.md ├── art └── assets.blend ├── assets ├── assets.dia ├── assets.ysce ├── engines │ ├── H22A.mr │ ├── Mini_N14.mr │ ├── Mini_N14_flow.mr │ ├── VQ25DE.mr │ ├── atg-video-1 │ │ ├── 01_honda_trx520.mr │ │ ├── 02_kohler_ch750.mr │ │ ├── 03_harley_davidson_shovelhead.mr │ │ ├── 04_hayabusa.mr │ │ ├── 05_honda_vtec.mr │ │ ├── 06_subaru_ej25.mr │ │ ├── 07_audi_i5.mr │ │ ├── 08_radial_5.mr │ │ ├── README.md │ │ └── radial.mr │ ├── atg-video-2 │ │ ├── 01_subaru_ej25_eh.mr │ │ ├── 02_subaru_ej25_uh.mr │ │ ├── 03_2jz.mr │ │ ├── 03_2jz_gearbox.mr │ │ ├── 03_2jz_gearbox_vvt.mr │ │ ├── 04_60_degree_v6.mr │ │ ├── 05_odd_fire_v6.mr │ │ ├── 06_even_fire_v6.mr │ │ ├── 07_gm_ls.mr │ │ ├── 08_ferrari_f136_v8.mr │ │ ├── 09_radial_9.mr │ │ ├── 10_lfa_v10.mr │ │ ├── 11_merlin_v12.mr │ │ ├── 12_ferrari_412_t2.mr │ │ ├── README.md │ │ └── radial.mr │ ├── audi │ │ └── i5.mr │ ├── bmw │ │ └── M52B28.mr │ ├── chevrolet │ │ ├── chev_truck_454.mr │ │ └── engine_03_for_e1.mr │ └── kohler │ │ └── kohler_ch750.mr ├── main.mr ├── part-library │ ├── part_library.mr │ └── parts │ │ ├── cam_lobes.mr │ │ ├── camshafts.mr │ │ ├── heads.mr │ │ ├── ignition_modules.mr │ │ └── intakes.mr ├── sound-library │ ├── archive │ │ ├── engine_01.wav │ │ ├── engine_02.wav │ │ ├── engine_03.wav │ │ ├── engine_04.wav │ │ ├── test_engine.wav │ │ ├── test_engine_01_16.wav │ │ ├── test_engine_02_16.wav │ │ ├── test_engine_03_16.wav │ │ ├── test_engine_04_16.wav │ │ ├── test_engine_05_16.wav │ │ ├── test_engine_06_16.wav │ │ ├── test_engine_07_16.wav │ │ ├── test_engine_08_16.wav │ │ ├── test_engine_09_16.wav │ │ ├── test_engine_10_16.wav │ │ ├── test_engine_11_16.wav │ │ ├── test_engine_12_16.wav │ │ ├── test_engine_13_16.wav │ │ ├── test_engine_14_eq_adjusted_16.wav │ │ ├── test_engine_15_eq_adjusted_16.wav │ │ ├── test_engine_16.wav │ │ ├── test_engine_16_eq_adjusted_16.wav │ │ ├── test_engine_17.wav │ │ └── test_engine_18.wav │ └── smooth │ │ ├── smooth_01.wav │ │ ├── smooth_02.wav │ │ ├── smooth_03.wav │ │ ├── smooth_04.wav │ │ ├── smooth_05.wav │ │ ├── smooth_06.wav │ │ ├── smooth_07.wav │ │ ├── smooth_08.wav │ │ ├── smooth_09.wav │ │ ├── smooth_10.wav │ │ ├── smooth_11.wav │ │ ├── smooth_12.wav │ │ ├── smooth_13.wav │ │ ├── smooth_14.wav │ │ ├── smooth_15.wav │ │ ├── smooth_16.wav │ │ ├── smooth_17.wav │ │ ├── smooth_18.wav │ │ ├── smooth_19.wav │ │ ├── smooth_20.wav │ │ ├── smooth_21.wav │ │ ├── smooth_22.wav │ │ ├── smooth_23.wav │ │ ├── smooth_24.wav │ │ ├── smooth_25.wav │ │ ├── smooth_26.wav │ │ ├── smooth_27.wav │ │ ├── smooth_28.wav │ │ ├── smooth_29.wav │ │ ├── smooth_30.wav │ │ ├── smooth_31.wav │ │ ├── smooth_32.wav │ │ ├── smooth_33.wav │ │ ├── smooth_34.wav │ │ ├── smooth_35.wav │ │ ├── smooth_36.wav │ │ ├── smooth_37.wav │ │ ├── smooth_38.wav │ │ ├── smooth_39.wav │ │ ├── smooth_40.wav │ │ ├── smooth_41.wav │ │ ├── smooth_42.wav │ │ ├── smooth_43.wav │ │ ├── smooth_44.wav │ │ ├── smooth_45.wav │ │ ├── smooth_46.wav │ │ ├── smooth_47.wav │ │ ├── smooth_48.wav │ │ └── smooth_49.wav └── themes │ ├── amateur.mr │ ├── bubble_gum.mr │ ├── default.mr │ ├── minimalistic.mr │ ├── night_vision.mr │ └── paper.mr ├── configuration └── delta.conf ├── dependencies ├── CMakeLists.txt ├── discord │ ├── CMakeLists.txt │ ├── Discord.cpp │ ├── Discord.h │ ├── LICENSE │ ├── discord_register.h │ ├── discord_rpc.h │ └── lib │ │ └── discord-rpc.lib └── submodules │ └── CMakeLists.txt ├── design └── engine_sim_layout.png ├── docs └── public │ └── screenshots │ └── screenshot_v01.png ├── es ├── actions │ └── actions.mr ├── constants │ ├── constants.mr │ └── units.mr ├── engine_sim.mr ├── infrastructure │ └── infrastructure.mr ├── objects │ └── objects.mr ├── part-library │ ├── part_library.mr │ └── parts │ │ ├── cam_lobes.mr │ │ ├── camshafts.mr │ │ ├── heads.mr │ │ ├── ignition_modules.mr │ │ └── intakes.mr ├── settings │ └── application_settings.mr ├── sound-library │ ├── archive │ │ ├── test_engine_14_eq_adjusted_16.wav │ │ ├── test_engine_15_eq_adjusted_16.wav │ │ └── test_engine_16_eq_adjusted_16.wav │ ├── impulse_responses.mr │ ├── new │ │ ├── mild_exhaust.wav │ │ ├── mild_exhaust_reverb.wav │ │ ├── minimal_muffling_01.wav │ │ ├── minimal_muffling_02.wav │ │ └── minimal_muffling_03.wav │ ├── sharp │ │ └── sharp_01.wav │ └── smooth │ │ └── smooth_39.wav ├── types │ ├── atomic_types.mr │ ├── conversions.mr │ └── operations.mr └── utilities │ └── utilities.mr ├── include ├── adaptive_volume_filter.h ├── afr_cluster.h ├── application_settings.h ├── audio_buffer.h ├── butterworth_low_pass_filter.h ├── camshaft.h ├── combustion_chamber.h ├── combustion_chamber_object.h ├── connecting_rod.h ├── connecting_rod_object.h ├── constants.h ├── convolution_filter.h ├── crankshaft.h ├── crankshaft_object.h ├── csv_io.h ├── cylinder_bank.h ├── cylinder_bank_object.h ├── cylinder_head.h ├── cylinder_head_object.h ├── cylinder_pressure_gauge.h ├── cylinder_temperature_gauge.h ├── delay_filter.h ├── delta.h ├── derivative_filter.h ├── direct_throttle_linkage.h ├── dtv.h ├── dynamometer.h ├── engine.h ├── engine_sim_application.h ├── engine_view.h ├── exhaust_system.h ├── feedback_comb_filter.h ├── filter.h ├── firing_order_display.h ├── fuel.h ├── fuel_cluster.h ├── function.h ├── gas_system.h ├── gauge.h ├── gaussian_filter.h ├── geometry_generator.h ├── governor.h ├── ignition_module.h ├── impulse_response.h ├── info_cluster.h ├── intake.h ├── jitter_filter.h ├── labeled_gauge.h ├── lerp_function.h ├── leveling_filter.h ├── load_simulation_cluster.h ├── logging_cluster.h ├── low_pass_filter.h ├── mixer_cluster.h ├── oscilloscope.h ├── oscilloscope_cluster.h ├── part.h ├── performance_cluster.h ├── piston.h ├── piston_engine_simulator.h ├── piston_object.h ├── preemphasis_filter.h ├── right_gauge_cluster.h ├── ring_buffer.h ├── scs.h ├── shaders.h ├── simulation_object.h ├── simulator.h ├── standard_valvetrain.h ├── starter_motor.h ├── synthesizer.h ├── throttle.h ├── throttle_display.h ├── transmission.h ├── turbocharger.h ├── ui_button.h ├── ui_element.h ├── ui_manager.h ├── ui_math.h ├── ui_utilities.h ├── units.h ├── utilities.h ├── valvetrain.h ├── vehicle.h ├── vehicle_drag_constraint.h └── vtec_valvetrain.h ├── scripting ├── include │ ├── actions.h │ ├── camshaft_node.h │ ├── channel_types.h │ ├── compiler.h │ ├── connecting_rod_node.h │ ├── crankshaft_node.h │ ├── cylinder_bank_node.h │ ├── cylinder_head_node.h │ ├── engine_context.h │ ├── engine_node.h │ ├── engine_sim.h │ ├── exhaust_system_node.h │ ├── fuel_node.h │ ├── function_node.h │ ├── ignition_module_node.h │ ├── ignition_wire_node.h │ ├── impulse_response_node.h │ ├── intake_node.h │ ├── language_rules.h │ ├── node.h │ ├── object_reference_node.h │ ├── object_reference_node_output.h │ ├── piranha.h │ ├── piston_node.h │ ├── rod_journal_node.h │ ├── standard_valvetrain_node.h │ ├── throttle_nodes.h │ ├── transmission_node.h │ ├── valvetrain_node.h │ ├── vehicle_node.h │ └── vtec_valvetrain_node.h └── src │ ├── channel_types.cpp │ ├── compiler.cpp │ ├── engine_context.cpp │ └── language_rules.cpp ├── src ├── afr_cluster.cpp ├── audio_buffer.cpp ├── camshaft.cpp ├── combustion_chamber.cpp ├── combustion_chamber_object.cpp ├── connecting_rod.cpp ├── connecting_rod_object.cpp ├── convolution_filter.cpp ├── crankshaft.cpp ├── crankshaft_object.cpp ├── cylinder_bank.cpp ├── cylinder_bank_object.cpp ├── cylinder_head.cpp ├── cylinder_head_object.cpp ├── cylinder_pressure_gauge.cpp ├── cylinder_temperature_gauge.cpp ├── delay_filter.cpp ├── derivative_filter.cpp ├── direct_throttle_linkage.cpp ├── dynamometer.cpp ├── engine.cpp ├── engine_sim_application.cpp ├── engine_view.cpp ├── exhaust_system.cpp ├── feedback_comb_filter.cpp ├── filter.cpp ├── firing_order_display.cpp ├── fuel.cpp ├── fuel_cluster.cpp ├── function.cpp ├── gas_system.cpp ├── gauge.cpp ├── gaussian_filter.cpp ├── geometry_generator.cpp ├── governor.cpp ├── ignition_module.cpp ├── impulse_response.cpp ├── info_cluster.cpp ├── intake.cpp ├── jitter_filter.cpp ├── labeled_gauge.cpp ├── lerp_function.cpp ├── leveling_filter.cpp ├── load_simulation_cluster.cpp ├── logging_cluster.cpp ├── low_pass_filter.cpp ├── main.cpp ├── mixer_cluster.cpp ├── oscilloscope.cpp ├── oscilloscope_cluster.cpp ├── part.cpp ├── performance_cluster.cpp ├── piston.cpp ├── piston_engine_simulator.cpp ├── piston_object.cpp ├── right_gauge_cluster.cpp ├── shaders.cpp ├── simulation_object.cpp ├── simulator.cpp ├── standard_valvetrain.cpp ├── starter_motor.cpp ├── synthesizer.cpp ├── throttle.cpp ├── throttle_display.cpp ├── transmission.cpp ├── turbocharger.cpp ├── ui_button.cpp ├── ui_element.cpp ├── ui_manager.cpp ├── ui_math.cpp ├── ui_utilities.cpp ├── utilities.cpp ├── valvetrain.cpp ├── vehicle.cpp ├── vehicle_drag_constraint.cpp └── vtec_valvetrain.cpp └── test ├── function_test.cpp ├── gas_system_tests.cpp └── synthesizer_tests.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore user's workspace 2 | workspace/ 3 | 4 | # Build directory 5 | build/ 6 | out/ 7 | 8 | # clangd cache and code completion files 9 | .cache 10 | compile_commands.json 11 | 12 | # Blender temporary files 13 | *.blend1 14 | 15 | .vs 16 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "dependencies/submodules/delta-studio"] 2 | path = dependencies/submodules/delta-studio 3 | url = https://github.com/ange-yaghi/delta-studio.git 4 | [submodule "dependencies/submodules/simple-2d-constraint-solver"] 5 | path = dependencies/submodules/simple-2d-constraint-solver 6 | url = https://github.com/ange-yaghi/simple-2d-constraint-solver 7 | [submodule "dependencies/submodules/direct-to-video"] 8 | path = dependencies/submodules/direct-to-video 9 | url = https://github.com/ange-yaghi/direct-to-video 10 | [submodule "dependencies/submodules/csv-io"] 11 | path = dependencies/submodules/csv-io 12 | url = https://github.com/ange-yaghi/csv-io 13 | [submodule "dependencies/submodules/piranha"] 14 | path = dependencies/submodules/piranha 15 | url = https://github.com/ange-yaghi/piranha.git 16 | [submodule "dependencies/submodules/TSCpp"] 17 | path = dependencies/submodules/TSCpp 18 | url = https://github.com/DDev247/TSCpp.git 19 | -------------------------------------------------------------------------------- /CMakeSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "x64-Debug", 5 | "generator": "Ninja", 6 | "configurationType": "Debug", 7 | "inheritEnvironments": [ "msvc_x64_x64" ], 8 | "buildRoot": "${projectDir}\\out\\build\\${name}", 9 | "installRoot": "${projectDir}\\out\\install\\${name}", 10 | "cmakeCommandArgs": "", 11 | "buildCommandArgs": "", 12 | "ctestCommandArgs": "" 13 | }, 14 | { 15 | "name": "x64-Release", 16 | "generator": "Ninja", 17 | "configurationType": "RelWithDebInfo", 18 | "buildRoot": "${projectDir}\\build", 19 | "installRoot": "${projectDir}\\out\\install\\${name}", 20 | "ctestCommandArgs": "", 21 | "inheritEnvironments": [ "msvc_x64_x64" ] 22 | }, 23 | { 24 | "name": "Mingw64-Release", 25 | "generator": "Ninja", 26 | "configurationType": "RelWithDebInfo", 27 | "buildRoot": "${projectDir}\\out\\build\\${name}", 28 | "installRoot": "${projectDir}\\out\\install\\${name}", 29 | "cmakeCommandArgs": "", 30 | "buildCommandArgs": "-v", 31 | "ctestCommandArgs": "", 32 | "inheritEnvironments": [ "mingw_64" ], 33 | "environments": [ 34 | { 35 | "MINGW64_ROOT": "D:/msys64/mingw64", 36 | "BIN_ROOT": "${env.MINGW64_ROOT}/bin", 37 | "FLAVOR": "x86_64-w64-mingw32", 38 | "TOOLSET_VERSION": "9.1.0", 39 | "PATH": "${env.MINGW64_ROOT}/bin;${env.MINGW64_ROOT}/../usr/local/bin;${env.MINGW64_ROOT}/../usr/bin;${env.MINGW64_ROOT}/../bin;${env.PATH}", 40 | "INCLUDE": "${env.INCLUDE};${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION};${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION}/tr1;${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION}/${env.FLAVOR}", 41 | "environment": "mingw_64" 42 | } 43 | ], 44 | "variables": [ 45 | { 46 | "name": "CMAKE_C_COMPILER", 47 | "value": "D:/msys64/mingw64/bin/gcc.exe", 48 | "type": "STRING" 49 | }, 50 | { 51 | "name": "CMAKE_CXX_COMPILER", 52 | "value": "D:/msys64/mingw64/bin/g++.exe", 53 | "type": "STRING" 54 | } 55 | ], 56 | "intelliSenseMode": "linux-gcc-x64" 57 | } 58 | ] 59 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2022 AngeTheGreat (Ange Yaghi) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /art/assets.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/art/assets.blend -------------------------------------------------------------------------------- /assets/assets.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/assets.dia -------------------------------------------------------------------------------- /assets/assets.ysce: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/assets.ysce -------------------------------------------------------------------------------- /assets/engines/atg-video-1/README.md: -------------------------------------------------------------------------------- 1 | ## Engines from *Simulating VTEC, a radial-5 engine and more with my engine simulator (there is sound)* 2 | 3 | This folder contains all the engines from [*Simulating VTEC, a radial-5 engine and more with my engine simulator (there is sound)*](https://youtu.be/WPCMNnM6D0k). Each file contains a node called `main` and it can be used in `main.mr` as follows. 4 | 5 | ``` 6 | import "engines/atg-video-1/" 7 | 8 | main() 9 | ``` 10 | 11 | The following engines are included: 12 | 1. Honda 1-cylinder ATV engine 13 | 2. Kohler Command Pro CH750 14 | 3. Harley Davidson Shovelhead 15 | 4. Hayabusa Inline-4 16 | 5. Honda B18C5 17 | 6. Subaru EJ25 (version 1) 18 | 7. Audi Inline-5 19 | 8. Radial-5 20 | -------------------------------------------------------------------------------- /assets/engines/atg-video-1/radial.mr: -------------------------------------------------------------------------------- 1 | import "engine_sim.mr" 2 | 3 | units units() 4 | constants constants() 5 | label cycle(2 * 360 * units.deg) 6 | 7 | public node radial_head { 8 | input offset; 9 | input lobe_profile; 10 | input chamber_volume: 290 * units.cc; 11 | alias output __head: 12 | generic_small_engine_head( 13 | chamber_volume: chamber_volume, 14 | intake_camshaft: camshaft.intake_cam, 15 | exhaust_camshaft: camshaft.exhaust_cam, 16 | flow_attenuation: 2.0, 17 | intake_runner_cross_section_area: 20.0 * units.cm2, 18 | exhaust_runner_cross_section_area: 20.0 * units.cm2 19 | ); 20 | 21 | radial_camshaft camshaft( 22 | lobe_profile: lobe_profile, 23 | offset: offset 24 | ) 25 | } 26 | 27 | public node radial_camshaft { 28 | input lobe_profile; 29 | input offset; 30 | input intake_lobe_profile: lobe_profile; 31 | input exhaust_lobe_profile: lobe_profile; 32 | input lobe_separation: 114 * units.deg; 33 | input intake_lobe_center: lobe_separation; 34 | input exhaust_lobe_center: lobe_separation; 35 | input advance: 0 * units.deg; 36 | input base_radius: 1.0 * units.inch; 37 | 38 | output intake_cam: _intake_cam; 39 | output exhaust_cam: _exhaust_cam; 40 | 41 | camshaft_parameters params ( 42 | advance: advance, 43 | base_radius: base_radius 44 | ) 45 | 46 | camshaft _intake_cam(params, lobe_profile: intake_lobe_profile) 47 | camshaft _exhaust_cam(params, lobe_profile: exhaust_lobe_profile) 48 | 49 | label rot180(180 * units.deg) 50 | label rot360(360 * units.deg) 51 | 52 | _exhaust_cam 53 | .add_lobe(rot360 - exhaust_lobe_center + offset * cycle) 54 | _intake_cam 55 | .add_lobe(rot360 + intake_lobe_center + offset * cycle) 56 | } 57 | -------------------------------------------------------------------------------- /assets/engines/atg-video-2/README.md: -------------------------------------------------------------------------------- 1 | ## Engines from *Simulating an F1 V12, cross-plane and flat-plane V8s, unequal length headers and more* 2 | 3 | This folder contains all the engines from [*Simulating an F1 V12, cross-plane and flat-plane V8s, unequal length headers and more*](https://youtu.be/NBBwva3NZ6o). Each file contains a node called `main` and it can be used in `main.mr` as follows. 4 | 5 | ``` 6 | import "engines/atg-video-2/" 7 | 8 | main() 9 | ``` 10 | 11 | The following engines are included: 12 | 1. Subaru EJ25 with equal length headers 13 | 2. Subaru EJ25 with unequal length headers 14 | 3. Toyota 2JZ 15 | 4. 60 degree V6 16 | 5. Odd-fire 90 degree V6 17 | 6. Even-fire 90 degree V6 18 | 7. GM LS V8 19 | 8. Ferrari F136 V8 20 | 9. Radial-9 21 | 10. Toyota 1LR-GUE (Lexus LFA) 22 | 11. Merlin V12 23 | 12. Ferrari Tipo 044/1 (Formula 1 V12) 24 | -------------------------------------------------------------------------------- /assets/engines/atg-video-2/radial.mr: -------------------------------------------------------------------------------- 1 | import "engine_sim.mr" 2 | 3 | units units() 4 | constants constants() 5 | label cycle(2 * 360 * units.deg) 6 | 7 | public node radial_head { 8 | input offset; 9 | input lobe_profile; 10 | input chamber_volume: 290 * units.cc; 11 | alias output __head: 12 | generic_small_engine_head( 13 | chamber_volume: chamber_volume, 14 | intake_camshaft: camshaft.intake_cam, 15 | exhaust_camshaft: camshaft.exhaust_cam, 16 | flow_attenuation: 2.0, 17 | intake_runner_cross_section_area: 20.0 * units.cm2, 18 | exhaust_runner_cross_section_area: 20.0 * units.cm2 19 | ); 20 | 21 | radial_camshaft camshaft( 22 | lobe_profile: lobe_profile, 23 | offset: offset 24 | ) 25 | } 26 | 27 | public node radial_camshaft { 28 | input lobe_profile; 29 | input offset; 30 | input intake_lobe_profile: lobe_profile; 31 | input exhaust_lobe_profile: lobe_profile; 32 | input lobe_separation: 114 * units.deg; 33 | input intake_lobe_center: lobe_separation; 34 | input exhaust_lobe_center: lobe_separation; 35 | input advance: 0 * units.deg; 36 | input base_radius: 1.0 * units.inch; 37 | 38 | output intake_cam: _intake_cam; 39 | output exhaust_cam: _exhaust_cam; 40 | 41 | camshaft_parameters params ( 42 | advance: advance, 43 | base_radius: base_radius 44 | ) 45 | 46 | camshaft _intake_cam(params, lobe_profile: intake_lobe_profile) 47 | camshaft _exhaust_cam(params, lobe_profile: exhaust_lobe_profile) 48 | 49 | label rot180(180 * units.deg) 50 | label rot360(360 * units.deg) 51 | 52 | _exhaust_cam 53 | .add_lobe(rot360 - exhaust_lobe_center + offset * cycle) 54 | _intake_cam 55 | .add_lobe(rot360 + intake_lobe_center + offset * cycle) 56 | } 57 | -------------------------------------------------------------------------------- /assets/main.mr: -------------------------------------------------------------------------------- 1 | import "engine_sim.mr" 2 | import "themes/default.mr" 3 | //import "engines/atg-video-1/05_honda_vtec.mr" 4 | import "engines/bmw/M52B28.mr" 5 | //import "engines/atg-video-2/03_2jz_gearbox_vvt.mr" 6 | //import "engines/Mini_N14_flow.mr" 7 | // import "engines/H22A.mr" 8 | 9 | use_default_theme() 10 | main() 11 | -------------------------------------------------------------------------------- /assets/part-library/part_library.mr: -------------------------------------------------------------------------------- 1 | public import "parts/cam_lobes.mr" 2 | public import "parts/camshafts.mr" 3 | public import "parts/heads.mr" 4 | public import "parts/intakes.mr" 5 | public import "parts/ignition_modules.mr" 6 | -------------------------------------------------------------------------------- /assets/part-library/parts/cam_lobes.mr: -------------------------------------------------------------------------------- 1 | private import "engine_sim.mr" 2 | 3 | units units() 4 | 5 | private node add_sym_sample { 6 | input angle; 7 | input lift; 8 | input this; 9 | alias output __out: this; 10 | 11 | this.add_sample(angle * units.deg, lift * units.thou) 12 | this.add_sample(-angle * units.deg, lift * units.thou) 13 | } 14 | 15 | public node stock_454_intake_lobe_profile { 16 | alias output __out: 17 | harmonic_cam_lobe( 18 | duration_at_50_thou: 194 * units.deg, 19 | gamma: 0.8, 20 | lift: 390 * units.thou, 21 | steps: 100 22 | ); 23 | } 24 | 25 | public node stock_454_exhaust_lobe_profile { 26 | alias output __out: 27 | harmonic_cam_lobe( 28 | duration_at_50_thou: 202 * units.deg, 29 | gamma: 0.8, 30 | lift: 409 * units.thou, 31 | steps: 100 32 | ); 33 | } 34 | 35 | public node comp_cams_magnum_11_450_8_lobe_profile { 36 | alias output __out: 37 | harmonic_cam_lobe( 38 | duration_at_50_thou: 232 * units.deg, 39 | gamma: 0.75, 40 | lift: 578 * units.thou, 41 | steps: 100 42 | ); 43 | } 44 | 45 | public node comp_cams_magnum_11_470_8_lobe_profile { 46 | alias output __out: 47 | harmonic_cam_lobe( 48 | duration_at_50_thou: 252 * units.deg, 49 | gamma: 0.8, 50 | lift: 612 * units.thou, 51 | steps: 100 52 | ); 53 | } 54 | -------------------------------------------------------------------------------- /assets/part-library/parts/ignition_modules.mr: -------------------------------------------------------------------------------- 1 | private import "engine_sim.mr" 2 | 3 | units units() 4 | label cycle(2 * 360 * units.deg) 5 | 6 | public node chevy_bbc_distributor { 7 | input wires; 8 | input timing_curve; 9 | input rev_limit: 5500 * units.rpm; 10 | alias output __out: 11 | ignition_module(timing_curve: timing_curve, rev_limit: rev_limit) 12 | .connect_wire(wires.wire1, (0.0 / 8.0) * cycle) 13 | .connect_wire(wires.wire8, (1.0 / 8.0) * cycle) 14 | .connect_wire(wires.wire4, (2.0 / 8.0) * cycle) 15 | .connect_wire(wires.wire3, (3.0 / 8.0) * cycle) 16 | .connect_wire(wires.wire6, (4.0 / 8.0) * cycle) 17 | .connect_wire(wires.wire5, (5.0 / 8.0) * cycle) 18 | .connect_wire(wires.wire7, (6.0 / 8.0) * cycle) 19 | .connect_wire(wires.wire2, (7.0 / 8.0) * cycle); 20 | } 21 | 22 | public node chevy_sbc_distributor { 23 | input wires; 24 | input timing_curve; 25 | input rev_limit: 5500 * units.rpm; 26 | alias output __out: chevy_bbc_distributor( 27 | wires: wires, 28 | timing_curve: timing_curve, 29 | rev_limit: rev_limit 30 | ); 31 | } 32 | 33 | public node vtwin90_distributor { 34 | input wires; 35 | input timing_curve; 36 | input rev_limit: 5500 * units.rpm; 37 | alias output __out: 38 | ignition_module(timing_curve: timing_curve, rev_limit: rev_limit) 39 | .connect_wire(wires.wire1, (0.0 / 8.0) * cycle) 40 | .connect_wire(wires.wire2, (3.0 / 8.0) * cycle); 41 | } 42 | -------------------------------------------------------------------------------- /assets/part-library/parts/intakes.mr: -------------------------------------------------------------------------------- 1 | private import "engine_sim.mr" 2 | 3 | units units() 4 | 5 | public node chevy_bbc_stock_intake { 6 | input carburetor_cfm: 650.0; 7 | input idle_flow_rate_cfm: 1.0; 8 | input idle_throttle_plate_position: 0.975; 9 | input throttle_gamma: 2.0; 10 | 11 | alias output __out: intake; 12 | 13 | intake intake( 14 | plenum_volume: 2.0 * units.L, 15 | plenum_cross_section_area: 100.0 * units.cm2, 16 | intake_flow_rate: k_carb(carburetor_cfm), 17 | idle_flow_rate: k_carb(idle_flow_rate_cfm), 18 | idle_throttle_plate_position: idle_throttle_plate_position, 19 | throttle_gamma: throttle_gamma, 20 | runner_flow_rate: k_carb(300.0), 21 | runner_length: 6.0 * units.inch, 22 | velocity_decay: 1.0 23 | ) 24 | } 25 | 26 | public node performer_rpm_intake { 27 | input carburetor_cfm: 650.0; 28 | input idle_flow_rate_cfm: 1.0; 29 | input idle_throttle_plate_position: 0.975; 30 | input throttle_gamma: 2.0; 31 | 32 | alias output __out: intake; 33 | 34 | intake intake( 35 | plenum_volume: 2.0 * units.L, 36 | plenum_cross_section_area: 100.0 * units.cm2, 37 | intake_flow_rate: k_carb(carburetor_cfm), 38 | idle_flow_rate: k_carb(idle_flow_rate_cfm), 39 | idle_throttle_plate_position: idle_throttle_plate_position, 40 | throttle_gamma: throttle_gamma, 41 | runner_flow_rate: k_carb(500.0), 42 | runner_length: 6.0 * units.inch, 43 | velocity_decay: 0.1 44 | ) 45 | } 46 | -------------------------------------------------------------------------------- /assets/sound-library/archive/engine_01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/engine_01.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/engine_02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/engine_02.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/engine_03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/engine_03.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/engine_04.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/engine_04.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_01_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_01_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_02_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_02_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_03_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_03_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_04_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_04_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_05_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_05_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_06_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_06_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_07_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_07_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_08_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_08_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_09_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_09_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_10_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_10_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_11_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_11_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_12_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_12_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_13_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_13_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_14_eq_adjusted_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_14_eq_adjusted_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_15_eq_adjusted_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_15_eq_adjusted_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_16_eq_adjusted_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_16_eq_adjusted_16.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_17.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_17.wav -------------------------------------------------------------------------------- /assets/sound-library/archive/test_engine_18.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/archive/test_engine_18.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_01.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_02.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_03.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_04.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_04.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_05.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_05.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_06.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_06.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_07.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_07.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_08.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_08.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_09.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_09.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_10.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_10.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_11.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_11.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_12.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_12.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_13.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_13.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_14.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_14.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_15.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_15.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_16.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_17.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_17.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_18.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_18.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_19.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_19.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_20.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_20.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_21.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_21.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_22.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_22.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_23.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_23.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_24.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_24.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_25.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_25.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_26.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_26.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_27.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_27.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_28.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_28.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_29.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_29.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_30.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_30.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_31.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_31.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_32.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_32.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_33.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_33.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_34.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_34.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_35.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_35.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_36.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_36.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_37.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_37.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_38.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_38.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_39.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_39.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_40.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_40.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_41.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_41.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_42.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_42.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_43.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_43.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_44.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_44.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_45.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_45.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_46.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_46.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_47.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_47.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_48.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_48.wav -------------------------------------------------------------------------------- /assets/sound-library/smooth/smooth_49.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/assets/sound-library/smooth/smooth_49.wav -------------------------------------------------------------------------------- /assets/themes/amateur.mr: -------------------------------------------------------------------------------- 1 | import "engine_sim.mr" 2 | 3 | unit_names units() 4 | public node use_amateur_theme { 5 | input start_fullscreen: false; 6 | input speed_units: units.mph; 7 | input pressure_units: units.inHg; 8 | input torque_units: units.lb_ft; 9 | input power_units: units.hp; 10 | 11 | set_application_settings( 12 | start_fullscreen: start_fullscreen, 13 | speed_units: speed_units, 14 | pressure_units: pressure_units, 15 | torque_units:torque_units, 16 | power_units: power_units, 17 | 18 | // Default Color Settings 19 | color_background: 0x000000, 20 | color_foreground: 0xFFFFFF, 21 | color_highlight1: 0xFF0000, 22 | color_highlight2: 0xFFFFFF, 23 | color_shadow: 0x000000, 24 | color_pink: 0xFF00FF, 25 | color_red: 0xFF0000, 26 | color_orange: 0xFF8000, 27 | color_yellow: 0xFFFF00, 28 | color_blue: 0x0000FF, 29 | color_green: 0x00FF00 30 | ) 31 | } 32 | -------------------------------------------------------------------------------- /assets/themes/bubble_gum.mr: -------------------------------------------------------------------------------- 1 | import "engine_sim.mr" 2 | 3 | unit_names units() 4 | public node use_bubble_gum_theme { 5 | input start_fullscreen: false; 6 | input speed_units: units.mph; 7 | input pressure_units: units.inHg; 8 | input torque_units: units.lb_ft; 9 | input power_units: units.hp; 10 | 11 | set_application_settings( 12 | start_fullscreen: start_fullscreen, 13 | speed_units: speed_units, 14 | pressure_units: pressure_units, 15 | torque_units:torque_units, 16 | power_units: power_units, 17 | 18 | // Default Color Settings 19 | color_background: 0xF394BE, 20 | color_foreground: 0xFFFFFF, 21 | color_highlight1: 0xfdeaf2, 22 | color_highlight2: 0xFFFFFF, 23 | color_shadow: 0xF394BE, 24 | color_pink: 0xfad4e5, 25 | color_red: 0xf5a9cb, 26 | color_orange: 0xffd086, 27 | color_yellow: 0xffd0c3, 28 | color_blue: 0xcfd2dc, 29 | color_green: 0xd7f7d2 30 | ) 31 | } 32 | -------------------------------------------------------------------------------- /assets/themes/default.mr: -------------------------------------------------------------------------------- 1 | import "engine_sim.mr" 2 | 3 | unit_names units() 4 | public node use_default_theme { 5 | input start_fullscreen: false; 6 | input speed_units: units.mph; 7 | input pressure_units: units.inHg; 8 | input torque_units: units.lb_ft; 9 | input power_units: units.hp; 10 | 11 | set_application_settings( 12 | start_fullscreen: start_fullscreen, 13 | speed_units: speed_units, 14 | pressure_units: pressure_units, 15 | torque_units: torque_units, 16 | power_units: power_units, 17 | 18 | // Default Color Settings 19 | color_background: 0x0E1012, 20 | color_foreground: 0xFFFFFF, 21 | color_shadow: 0x0E1012, 22 | color_highlight1: 0xEF4545, 23 | color_highlight2: 0xFFFFFF, 24 | color_pink: 0xF394BE, 25 | color_red: 0xEE4445, 26 | color_orange: 0xF4802A, 27 | color_yellow: 0xFDBD2E, 28 | color_blue: 0x77CEE0, 29 | color_green: 0xBDD869 30 | ) 31 | } 32 | -------------------------------------------------------------------------------- /assets/themes/minimalistic.mr: -------------------------------------------------------------------------------- 1 | import "engine_sim.mr" 2 | 3 | unit_names units() 4 | public node use_minimalistic_theme { 5 | input start_fullscreen: false; 6 | input speed_units: units.mph; 7 | input pressure_units: units.inHg; 8 | input torque_units: units.lb_ft; 9 | input power_units: units.hp; 10 | 11 | set_application_settings( 12 | start_fullscreen: start_fullscreen, 13 | speed_units: speed_units, 14 | pressure_units: pressure_units, 15 | torque_units:torque_units, 16 | power_units: power_units, 17 | 18 | // Default Color Settings 19 | color_background: 0x000000, 20 | color_foreground: 0xFFFFFF, 21 | color_highlight1: 0xFFFFFF, 22 | color_highlight2: 0xFFFFFF, 23 | color_shadow: 0x000000, 24 | color_pink: 0xFFFFFF, 25 | color_red: 0xFFFFFF, 26 | color_orange: 0xFFFFFF, 27 | color_yellow: 0xFFFFFF, 28 | color_blue: 0xFFFFFF, 29 | color_green: 0xFFFFFF 30 | ) 31 | } 32 | -------------------------------------------------------------------------------- /assets/themes/night_vision.mr: -------------------------------------------------------------------------------- 1 | import "engine_sim.mr" 2 | 3 | unit_names units() 4 | public node use_night_vision_theme { 5 | input start_fullscreen: false; 6 | input speed_units: units.mph; 7 | input pressure_units: units.inHg; 8 | input torque_units: units.lb_ft; 9 | input power_units: units.hp; 10 | input color: 0x4dff68; 11 | 12 | set_application_settings( 13 | start_fullscreen: start_fullscreen, 14 | speed_units: speed_units, 15 | pressure_units: pressure_units, 16 | torque_units:torque_units, 17 | power_units: power_units, 18 | 19 | // Default Color Settings 20 | color_background: 0x000000, 21 | color_foreground: color, 22 | color_highlight1: color, 23 | color_highlight2: color, 24 | color_shadow: 0x000000, 25 | color_pink: color, 26 | color_red: color, 27 | color_orange: color, 28 | color_yellow: color, 29 | color_blue: color, 30 | color_green: color 31 | ) 32 | } 33 | -------------------------------------------------------------------------------- /assets/themes/paper.mr: -------------------------------------------------------------------------------- 1 | import "engine_sim.mr" 2 | 3 | unit_names units() 4 | public node use_paper_theme { 5 | input start_fullscreen: false; 6 | input speed_units: units.mph; 7 | input pressure_units: units.inHg; 8 | input torque_units: units.lb_ft; 9 | input power_units: units.hp; 10 | input color: 0x63aaff; 11 | 12 | set_application_settings( 13 | start_fullscreen: start_fullscreen, 14 | speed_units: speed_units, 15 | pressure_units: pressure_units, 16 | torque_units:torque_units, 17 | power_units: power_units, 18 | 19 | // Default Color Settings 20 | color_background: 0xf8f2f0, 21 | color_foreground: color, 22 | color_highlight1: color, 23 | color_highlight2: color, 24 | color_shadow: 0xf8f2f0, 25 | color_pink: color, 26 | color_red: color, 27 | color_orange: color, 28 | color_yellow: color, 29 | color_blue: color, 30 | color_green: color 31 | ) 32 | } 33 | -------------------------------------------------------------------------------- /configuration/delta.conf: -------------------------------------------------------------------------------- 1 | /delta 2 | /assets -------------------------------------------------------------------------------- /dependencies/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(submodules) 2 | 3 | if (DISCORD_ENABLED) 4 | add_subdirectory(discord) 5 | endif () 6 | -------------------------------------------------------------------------------- /dependencies/discord/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set_property(TARGET discord PROPERTY FOLDER "discord") 2 | -------------------------------------------------------------------------------- /dependencies/discord/Discord.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * 3 | * File : Discord.h 4 | * Author : SanGawku 5 | * Copyright : SanGawku 6 | * Date : 7/29/2019 7 | * Abstract : Discord 8 | ***************************************************************************** 9 | * 10 | * Desc : Discord rich presence integration 11 | * 12 | *****************************************************************************/ 13 | #ifndef __DISCORD_H__ 14 | #define __DISCORD_H__ 15 | 16 | #include 17 | #include "discord_rpc.h" 18 | #pragma comment(lib, "discord-rpc.lib") 19 | 20 | class CDiscord 21 | { 22 | 23 | public: 24 | 25 | CDiscord(); 26 | virtual ~CDiscord(); 27 | 28 | static bool CreateInstance(); 29 | static void DestroyInstance(); 30 | 31 | static CDiscord* GetInstance() { return m_pInstance; } 32 | 33 | public: 34 | 35 | static void handleDiscordReady(const DiscordUser* connectedUser); 36 | 37 | static void handleDiscordDisconnected(int errcode, const char* message); 38 | 39 | static void handleDiscordError(int errcode, const char* message); 40 | 41 | private: 42 | 43 | void InitDiscord(); 44 | 45 | void UpdatePresence(); 46 | 47 | void ClearPresence(); 48 | 49 | public: 50 | 51 | void UpdateDiscordConnection(); 52 | 53 | void SetUseDiscord(bool bFlag); // if true, then we will use discord and connect to discord 54 | 55 | void SetConnected(bool bFlag); //set connected to discord or not 56 | 57 | void SetStatus(DiscordRichPresence presence, std::string engineName, std::string buildVersion); 58 | 59 | 60 | 61 | private: 62 | 63 | std::string m_state; 64 | 65 | std::string m_engineName; 66 | 67 | bool m_bEnableDiscord; 68 | 69 | bool m_bConnected; 70 | 71 | protected: 72 | 73 | static CDiscord* m_pInstance; 74 | }; 75 | 76 | static CDiscord* GetDiscordManager() 77 | { 78 | return CDiscord::GetInstance(); 79 | }; 80 | 81 | 82 | #endif -------------------------------------------------------------------------------- /dependencies/discord/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 Discord, Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /dependencies/discord/discord_register.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DISCORD_DYNAMIC_LIB) 4 | # if defined(_WIN32) 5 | # if defined(DISCORD_BUILDING_SDK) 6 | # define DISCORD_EXPORT __declspec(dllexport) 7 | # else 8 | # define DISCORD_EXPORT __declspec(dllimport) 9 | # endif 10 | # else 11 | # define DISCORD_EXPORT __attribute__((visibility("default"))) 12 | # endif 13 | #else 14 | # define DISCORD_EXPORT 15 | #endif 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command); 22 | DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /dependencies/discord/lib/discord-rpc.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/dependencies/discord/lib/discord-rpc.lib -------------------------------------------------------------------------------- /dependencies/submodules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(delta-studio) 2 | 3 | set_property(TARGET delta-basic PROPERTY FOLDER "delta") 4 | set_property(TARGET delta-basic-demo PROPERTY FOLDER "delta") 5 | set_property(TARGET delta-core PROPERTY FOLDER "delta") 6 | set_property(TARGET delta-physics PROPERTY FOLDER "delta") 7 | 8 | add_subdirectory(simple-2d-constraint-solver) 9 | 10 | set_property(TARGET simple-2d-constraint-solver PROPERTY FOLDER "scs") 11 | set_property(TARGET simple-2d-constraint-solver-test PROPERTY FOLDER "scs") 12 | 13 | add_subdirectory(csv-io) 14 | 15 | set_property(TARGET csv-io PROPERTY FOLDER "csv-io") 16 | set_property(TARGET csv-io-main PROPERTY FOLDER "csv-io") 17 | set_property(TARGET csv-io-test PROPERTY FOLDER "csv-io") 18 | 19 | if (DTV) 20 | add_subdirectory(direct-to-video) 21 | 22 | set_property(TARGET direct-to-video PROPERTY FOLDER "dtv") 23 | set_property(TARGET direct-to-video PROPERTY FOLDER "dtv") 24 | endif (DTV) 25 | 26 | add_subdirectory(piranha) 27 | 28 | set_property(TARGET piranha PROPERTY FOLDER "piranha") 29 | set_property(TARGET piranha_test PROPERTY FOLDER "piranha") 30 | set_property(TARGET piranha_reference_compiler PROPERTY FOLDER "piranha") 31 | 32 | add_subdirectory (TSCpp) 33 | -------------------------------------------------------------------------------- /design/engine_sim_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/design/engine_sim_layout.png -------------------------------------------------------------------------------- /docs/public/screenshots/screenshot_v01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/docs/public/screenshots/screenshot_v01.png -------------------------------------------------------------------------------- /es/constants/constants.mr: -------------------------------------------------------------------------------- 1 | module { 2 | @name: "Units" 3 | @author: "ATG (Ange Yaghi)" 4 | @copyright: "Copyright 2022, Ange Yaghi" 5 | } 6 | 7 | private import "../types/atomic_types.mr" 8 | private import "../types/conversions.mr" 9 | 10 | public node constants { 11 | output pi: 3.14159265359; 12 | } 13 | -------------------------------------------------------------------------------- /es/engine_sim.mr: -------------------------------------------------------------------------------- 1 | module { 2 | @name: "Engine Simulator Library" 3 | @author: "ATG (Ange Yaghi)" 4 | @copyright: "Copyright 2022, Ange Yaghi" 5 | } 6 | 7 | // Types 8 | public import "types/atomic_types.mr" 9 | public import "types/conversions.mr" 10 | public import "types/operations.mr" 11 | 12 | // Actions 13 | public import "actions/actions.mr" 14 | 15 | // Objects 16 | public import "objects/objects.mr" 17 | 18 | // Constants 19 | public import "constants/constants.mr" 20 | public import "constants/units.mr" 21 | 22 | // Infrastructure 23 | public import "infrastructure/infrastructure.mr" 24 | 25 | // Library 26 | public import "part-library/part_library.mr" 27 | public import "sound-library/impulse_responses.mr" 28 | 29 | // Utilities 30 | public import "utilities/utilities.mr" 31 | 32 | // Application settings 33 | public import "settings/application_settings.mr" 34 | -------------------------------------------------------------------------------- /es/infrastructure/infrastructure.mr: -------------------------------------------------------------------------------- 1 | module { 2 | @name: "Infrastructure" 3 | @author: "ATG (Ange Yaghi)" 4 | @copyright: "Copyright 2022, Ange Yaghi" 5 | } 6 | 7 | public node label { 8 | input in; 9 | alias output _out: in; 10 | } 11 | -------------------------------------------------------------------------------- /es/part-library/part_library.mr: -------------------------------------------------------------------------------- 1 | public import "parts/cam_lobes.mr" 2 | public import "parts/camshafts.mr" 3 | public import "parts/heads.mr" 4 | public import "parts/intakes.mr" 5 | public import "parts/ignition_modules.mr" 6 | -------------------------------------------------------------------------------- /es/part-library/parts/cam_lobes.mr: -------------------------------------------------------------------------------- 1 | private import "engine_sim.mr" 2 | 3 | units units() 4 | 5 | private node add_sym_sample { 6 | input angle; 7 | input lift; 8 | input this; 9 | alias output __out: this; 10 | 11 | this.add_sample(angle * units.deg, lift * units.thou) 12 | this.add_sample(-angle * units.deg, lift * units.thou) 13 | } 14 | 15 | public node stock_454_intake_lobe_profile { 16 | alias output __out: 17 | harmonic_cam_lobe( 18 | duration_at_50_thou: 194 * units.deg, 19 | gamma: 0.8, 20 | lift: 390 * units.thou, 21 | steps: 100 22 | ); 23 | } 24 | 25 | public node stock_454_exhaust_lobe_profile { 26 | alias output __out: 27 | harmonic_cam_lobe( 28 | duration_at_50_thou: 202 * units.deg, 29 | gamma: 0.8, 30 | lift: 409 * units.thou, 31 | steps: 100 32 | ); 33 | } 34 | 35 | public node comp_cams_magnum_11_450_8_lobe_profile { 36 | alias output __out: 37 | harmonic_cam_lobe( 38 | duration_at_50_thou: 232 * units.deg, 39 | gamma: 0.75, 40 | lift: 578 * units.thou, 41 | steps: 100 42 | ); 43 | } 44 | 45 | public node comp_cams_magnum_11_470_8_lobe_profile { 46 | alias output __out: 47 | harmonic_cam_lobe( 48 | duration_at_50_thou: 252 * units.deg, 49 | gamma: 0.8, 50 | lift: 612 * units.thou, 51 | steps: 100 52 | ); 53 | } 54 | -------------------------------------------------------------------------------- /es/part-library/parts/ignition_modules.mr: -------------------------------------------------------------------------------- 1 | private import "engine_sim.mr" 2 | 3 | units units() 4 | label cycle(2 * 360 * units.deg) 5 | 6 | public node chevy_bbc_distributor { 7 | input wires; 8 | input timing_curve; 9 | input rev_limit: 5500 * units.rpm; 10 | alias output __out: 11 | ignition_module(timing_curve: timing_curve, rev_limit: rev_limit) 12 | .connect_wire(wires.wire1, (0.0 / 8.0) * cycle) 13 | .connect_wire(wires.wire8, (1.0 / 8.0) * cycle) 14 | .connect_wire(wires.wire4, (2.0 / 8.0) * cycle) 15 | .connect_wire(wires.wire3, (3.0 / 8.0) * cycle) 16 | .connect_wire(wires.wire6, (4.0 / 8.0) * cycle) 17 | .connect_wire(wires.wire5, (5.0 / 8.0) * cycle) 18 | .connect_wire(wires.wire7, (6.0 / 8.0) * cycle) 19 | .connect_wire(wires.wire2, (7.0 / 8.0) * cycle); 20 | } 21 | 22 | public node chevy_sbc_distributor { 23 | input wires; 24 | input timing_curve; 25 | input rev_limit: 5500 * units.rpm; 26 | alias output __out: chevy_bbc_distributor( 27 | wires: wires, 28 | timing_curve: timing_curve, 29 | rev_limit: rev_limit 30 | ); 31 | } 32 | 33 | public node vtwin90_distributor { 34 | input wires; 35 | input timing_curve; 36 | input rev_limit: 5500 * units.rpm; 37 | alias output __out: 38 | ignition_module(timing_curve: timing_curve, rev_limit: rev_limit) 39 | .connect_wire(wires.wire1, (0.0 / 8.0) * cycle) 40 | .connect_wire(wires.wire2, (3.0 / 8.0) * cycle); 41 | } 42 | 43 | public node single_cylinder_distributor { 44 | input wires; 45 | input timing_curve; 46 | input rev_limit: 5500 * units.rpm; 47 | alias output __out: 48 | ignition_module(timing_curve: timing_curve, rev_limit: rev_limit) 49 | .connect_wire(wires.wire1, (0.0 / 8.0) * cycle); 50 | } 51 | -------------------------------------------------------------------------------- /es/part-library/parts/intakes.mr: -------------------------------------------------------------------------------- 1 | private import "engine_sim.mr" 2 | 3 | units units() 4 | 5 | public node chevy_bbc_stock_intake { 6 | input carburetor_cfm: 650.0; 7 | input idle_flow_rate_cfm: 1.0; 8 | input idle_throttle_plate_position: 0.975; 9 | input throttle_gamma: 2.0; 10 | 11 | alias output __out: intake; 12 | 13 | intake intake( 14 | plenum_volume: 2.0 * units.L, 15 | plenum_cross_section_area: 100.0 * units.cm2, 16 | intake_flow_rate: k_carb(carburetor_cfm), 17 | idle_flow_rate: k_carb(idle_flow_rate_cfm), 18 | idle_throttle_plate_position: idle_throttle_plate_position, 19 | throttle_gamma: throttle_gamma, 20 | runner_flow_rate: k_carb(300.0), 21 | runner_length: 6.0 * units.inch, 22 | velocity_decay: 1.0 23 | ) 24 | } 25 | 26 | public node performer_rpm_intake { 27 | input carburetor_cfm: 650.0; 28 | input idle_flow_rate_cfm: 1.0; 29 | input idle_throttle_plate_position: 0.975; 30 | input throttle_gamma: 2.0; 31 | 32 | alias output __out: intake; 33 | 34 | intake intake( 35 | plenum_volume: 2.0 * units.L, 36 | plenum_cross_section_area: 100.0 * units.cm2, 37 | intake_flow_rate: k_carb(carburetor_cfm), 38 | idle_flow_rate: k_carb(idle_flow_rate_cfm), 39 | idle_throttle_plate_position: idle_throttle_plate_position, 40 | throttle_gamma: throttle_gamma, 41 | runner_flow_rate: k_carb(500.0), 42 | runner_length: 6.0 * units.inch, 43 | velocity_decay: 0.1 44 | ) 45 | } 46 | -------------------------------------------------------------------------------- /es/settings/application_settings.mr: -------------------------------------------------------------------------------- 1 | private import "engine_sim.mr" 2 | 3 | units units() 4 | 5 | public node set_application_settings => __engine_sim__set_application_settings { 6 | input start_fullscreen [bool]: false; 7 | input power_units [string]: "HP"; 8 | input torque_units [string]: "FTLBS"; 9 | input speed_units [string]: "MPH"; 10 | input pressure_units [string]: "INHG"; 11 | input boost_units [string]: "PSI"; 12 | input color_background [int]: 0x0E1012; 13 | input color_foreground [int]: 0xFFFFFF; 14 | input color_shadow [int]: 0x0E1012; 15 | input color_highlight1 [int]: 0xEF4545; 16 | input color_highlight2 [int]: 0xFFFFFF; 17 | input color_pink [int]: 0xF394BE; 18 | input color_red [int]: 0xEE4445; 19 | input color_orange [int]: 0xF4802A; 20 | input color_yellow [int]: 0xFDBD2E; 21 | input color_blue [int]: 0x77CEE0; 22 | input color_green [int]: 0xBDD869; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /es/sound-library/archive/test_engine_14_eq_adjusted_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/es/sound-library/archive/test_engine_14_eq_adjusted_16.wav -------------------------------------------------------------------------------- /es/sound-library/archive/test_engine_15_eq_adjusted_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/es/sound-library/archive/test_engine_15_eq_adjusted_16.wav -------------------------------------------------------------------------------- /es/sound-library/archive/test_engine_16_eq_adjusted_16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/es/sound-library/archive/test_engine_16_eq_adjusted_16.wav -------------------------------------------------------------------------------- /es/sound-library/impulse_responses.mr: -------------------------------------------------------------------------------- 1 | private import "engine_sim.mr" 2 | 3 | public node impulse_response_library { 4 | output default_0: impulse_response(filename: "smooth/smooth_39.wav", volume: 0.001); 5 | 6 | output real_engine_0: 7 | impulse_response(filename: "archive/test_engine_14_eq_adjusted_16.wav", volume: 0.001); 8 | output real_engine_1: 9 | impulse_response(filename: "archive/test_engine_15_eq_adjusted_16.wav", volume: 0.001); 10 | output real_engine_2: 11 | impulse_response(filename: "archive/test_engine_16_eq_adjusted_16.wav", volume: 0.001); 12 | 13 | output sharp_0: 14 | impulse_response(filename: "sharp/sharp_01.wav", volume: 0.001); 15 | 16 | output mild_exhaust_0: 17 | impulse_response(filename: "new/mild_exhaust.wav", volume: 0.01); 18 | output mild_exhaust_0_reverb: 19 | impulse_response(filename: "new/mild_exhaust_reverb.wav", volume: 0.01); 20 | output minimal_muffling_01: 21 | impulse_response(filename: "new/minimal_muffling_01.wav", volume: 0.01); 22 | output minimal_muffling_02: 23 | impulse_response(filename: "new/minimal_muffling_02.wav", volume: 0.01); 24 | output minimal_muffling_03: 25 | impulse_response(filename: "new/minimal_muffling_03.wav", volume: 0.01); 26 | } 27 | -------------------------------------------------------------------------------- /es/sound-library/new/mild_exhaust.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/es/sound-library/new/mild_exhaust.wav -------------------------------------------------------------------------------- /es/sound-library/new/mild_exhaust_reverb.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/es/sound-library/new/mild_exhaust_reverb.wav -------------------------------------------------------------------------------- /es/sound-library/new/minimal_muffling_01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/es/sound-library/new/minimal_muffling_01.wav -------------------------------------------------------------------------------- /es/sound-library/new/minimal_muffling_02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/es/sound-library/new/minimal_muffling_02.wav -------------------------------------------------------------------------------- /es/sound-library/new/minimal_muffling_03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/es/sound-library/new/minimal_muffling_03.wav -------------------------------------------------------------------------------- /es/sound-library/sharp/sharp_01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/es/sound-library/sharp/sharp_01.wav -------------------------------------------------------------------------------- /es/sound-library/smooth/smooth_39.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DDev247/engine-sim/afd8a9f109a2458aaa55dfb2c8e88497b1f58c47/es/sound-library/smooth/smooth_39.wav -------------------------------------------------------------------------------- /es/types/atomic_types.mr: -------------------------------------------------------------------------------- 1 | module { 2 | @name: "Atomic Types" 3 | @author: "ATG (Ange Yaghi)" 4 | @copyright: "Copyright 2022, Ange Yaghi" 5 | } 6 | 7 | // ======================================================== 8 | // Channels 9 | // ======================================================== 10 | 11 | @doc: "Floating-point channel type" 12 | private node float_channel => __engine_sim__float { /* void */ } 13 | 14 | @doc: "String channel type" 15 | private node string_channel => __engine_sim__string { /* void */ } 16 | 17 | @doc: "Integer channel type" 18 | private node int_channel => __engine_sim__int { /* void */ } 19 | 20 | @doc: "Bool channel type" 21 | private node bool_channel => __engine_sim__bool { /* void */ } 22 | 23 | // ======================================================== 24 | // Types 25 | // ======================================================== 26 | 27 | @doc: "Float cast type" 28 | @detail: "Converts anything connected to __in to " 29 | "a float type" 30 | public inline node float { 31 | input __in [::float_channel]: 0.0; 32 | alias output __out [::float_channel]: __in; 33 | } 34 | 35 | @doc: "Integer cast type" 36 | @detail: "Converts anything connected to __in to " 37 | "an integer type" 38 | public inline node int { 39 | input __in [::int_channel]: 0; 40 | alias output __out [::int_channel]: __in; 41 | } 42 | 43 | @doc: "Boolean cast type" 44 | @detail: "Converts anything connected to __in to " 45 | "a boolean type" 46 | public inline node bool { 47 | input __in [::bool_channel]: false; 48 | alias output __out [::bool_channel]: __in; 49 | } 50 | 51 | @doc: "String type" 52 | public inline node string { 53 | input s [::string_channel]: ""; 54 | alias output __out [::string_channel]: s; 55 | } 56 | 57 | // ======================================================== 58 | // Literals 59 | // ======================================================== 60 | 61 | public node literal_string => __engine_sim__literal_string { 62 | alias output __out [::string]; 63 | } 64 | 65 | public node literal_float => __engine_sim__literal_float { 66 | alias output __out [::float]; 67 | } 68 | 69 | public node literal_int => __engine_sim__literal_int { 70 | alias output __out [::int]; 71 | } 72 | 73 | public node literal_bool => __engine_sim__literal_bool { 74 | alias output __out [::bool]; 75 | } 76 | -------------------------------------------------------------------------------- /es/types/conversions.mr: -------------------------------------------------------------------------------- 1 | module { 2 | @name: "Conversions" 3 | @author: "ATG (Ange Yaghi)" 4 | @copyright: "Copyright 2022, Ange Yaghi" 5 | } 6 | 7 | private import "atomic_types.mr" 8 | 9 | // Float conversions 10 | public node int_to_float => __engine_sim__int_to_float { 11 | input __in [int]; 12 | alias output __out [float]; 13 | } 14 | 15 | // String conversions 16 | public node int_to_string => __engine_sim__int_to_string { 17 | input __in [int]; 18 | alias output __out [string]; 19 | } 20 | 21 | // Integer conversions 22 | public node string_to_int => __engine_sim__string_to_int { 23 | input __in [string]; 24 | alias output __out [int]; 25 | } 26 | -------------------------------------------------------------------------------- /es/types/operations.mr: -------------------------------------------------------------------------------- 1 | module { 2 | @name: "Operations" 3 | @author: "ATG (Ange Yaghi)" 4 | @copyright: "Copyright 2022, Ange Yaghi" 5 | } 6 | 7 | private import "atomic_types.mr" 8 | private import "conversions.mr" 9 | 10 | // Float operations 11 | 12 | public node float_negate => __engine_sim__float_negate { 13 | input __in [float]; 14 | alias output __out [float]; 15 | } 16 | 17 | public node float_divide => __engine_sim__float_divide { 18 | input __in0 [float]; 19 | input __in1 [float]; 20 | alias output __out [float]; 21 | } 22 | 23 | public node float_multiply => __engine_sim__float_multiply { 24 | input __in0 [float]; 25 | input __in1 [float]; 26 | alias output __out [float]; 27 | } 28 | 29 | public node float_add => __engine_sim__float_add { 30 | input __in0 [float]; 31 | input __in1 [float]; 32 | alias output __out [float]; 33 | } 34 | 35 | public node float_subtract => __engine_sim__float_subtract { 36 | input __in0 [float]; 37 | input __in1 [float]; 38 | alias output __out [float]; 39 | } 40 | 41 | // String operations 42 | 43 | public node string_add => __engine_sim__string_add { 44 | input __in0 [string]; 45 | input __in1 [string]; 46 | alias output __out [string]; 47 | } 48 | 49 | // Int operations 50 | 51 | public node int_add => __engine_sim__int_add { 52 | input __in0 [int]; 53 | input __in1 [int]; 54 | alias output __out [int]; 55 | } 56 | 57 | public node int_mul => __engine_sim__int_multiply { 58 | input __in0 [int]; 59 | input __in1 [int]; 60 | alias output __out [int]; 61 | } 62 | 63 | public node int_sub => __engine_sim__int_subtract { 64 | input __in0 [int]; 65 | input __in1 [int]; 66 | alias output __out [int]; 67 | } 68 | 69 | public node int_div => __engine_sim__int_divide { 70 | input __in0 [int]; 71 | input __in1 [int]; 72 | alias output __out [int]; 73 | } 74 | 75 | public node int_negate => __engine_sim__int_negate { 76 | input __in [int]; 77 | alias output __out [int]; 78 | } 79 | -------------------------------------------------------------------------------- /es/utilities/utilities.mr: -------------------------------------------------------------------------------- 1 | private import "engine_sim.mr" 2 | 3 | node rod_moment_of_inertia { 4 | input mass; 5 | input length; 6 | alias output __moment: 7 | (1 / 12.0) * mass * length * length; 8 | } 9 | 10 | node disk_moment_of_inertia { 11 | input mass; 12 | input radius; 13 | alias output __moment: 14 | (1 / 2.0) * mass * radius * radius; 15 | } 16 | -------------------------------------------------------------------------------- /include/adaptive_volume_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_ADAPTIVE_VOLUME_FILTER_H 2 | #define ATG_ENGINE_SIM_ADAPTIVE_VOLUME_FILTER_H 3 | 4 | #include "filter.h" 5 | 6 | class AdaptiveVolumeFilter : public Filter { 7 | public: 8 | AdaptiveVolumeFilter(); 9 | virtual ~AdaptiveVolumeFilter(); 10 | 11 | void initialize(int lookahead); 12 | virtual double f(double sample); 13 | virtual void destroy(); 14 | 15 | protected: 16 | double *m_samples; 17 | int m_sampleCount; 18 | int m_lookahead; 19 | }; 20 | 21 | #endif /* ATG_ENGINE_SIM_CONVOLUTION_ADAPTIVE_VOLUME */ 22 | -------------------------------------------------------------------------------- /include/afr_cluster.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_AFR_CLUSTER_H 2 | #define ATG_ENGINE_SIM_AFR_CLUSTER_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "engine.h" 7 | #include "gauge.h" 8 | #include "cylinder_temperature_gauge.h" 9 | #include "cylinder_pressure_gauge.h" 10 | #include "labeled_gauge.h" 11 | #include "throttle_display.h" 12 | 13 | class AfrCluster : public UiElement { 14 | public: 15 | AfrCluster(); 16 | virtual ~AfrCluster(); 17 | 18 | virtual void initialize(EngineSimApplication *app); 19 | virtual void destroy(); 20 | 21 | virtual void update(float dt); 22 | virtual void render(); 23 | 24 | Engine *m_engine; 25 | 26 | protected: 27 | LabeledGauge *m_intakeAfrGauge; 28 | LabeledGauge *m_exhaustAfrGauge; 29 | }; 30 | 31 | #endif /* ATG_ENGINE_SIM_AFR_CLUSTER_H */ 32 | -------------------------------------------------------------------------------- /include/application_settings.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_APPLICATION_SETTINGS_H 2 | #define ATG_ENGINE_SIM_APPLICATION_SETTINGS_H 3 | #include 4 | 5 | struct ApplicationSettings { 6 | bool startFullscreen = false; 7 | std::string powerUnits = "hp"; 8 | std::string torqueUnits = "lb-ft"; 9 | std::string speedUnits = "mph"; 10 | std::string pressureUnits = "inHg"; 11 | std::string boostUnits = "psi"; 12 | 13 | int colorBackground = 0x0E1012; 14 | int colorForeground = 0xFFFFFF; 15 | int colorShadow = 0x0E1012; 16 | int colorHighlight1 = 0xEF4545; 17 | int colorHighlight2 = 0xFFFFFF; 18 | int colorPink = 0xF394BE; 19 | int colorRed = 0xEE4445; 20 | int colorOrange = 0xF4802A; 21 | int colorYellow = 0xFDBD2E; 22 | int colorBlue = 0x77CEE0; 23 | int colorGreen = 0xBDD869; 24 | }; 25 | 26 | #endif /* ATG_ENGINE_SIM_APPLICATION_SETTINGS_H */ 27 | -------------------------------------------------------------------------------- /include/camshaft.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CAMSHAFT_H 2 | #define ATG_ENGINE_SIM_CAMSHAFT_H 3 | 4 | #include "part.h" 5 | 6 | #include "function.h" 7 | #include "units.h" 8 | 9 | class Crankshaft; 10 | class Camshaft : public Part { 11 | public: 12 | struct Parameters { 13 | // Number of lobes 14 | int lobes; 15 | 16 | // Camshaft advance in camshaft degrees 17 | double advance = 0; 18 | 19 | // Corresponding crankshaft 20 | Crankshaft *crankshaft; 21 | 22 | // Lobe profile 23 | Function *lobeProfile; 24 | 25 | // Base radius 26 | double baseRadius = units::distance(600, units::thou); 27 | }; 28 | 29 | public: 30 | Camshaft(); 31 | virtual ~Camshaft(); 32 | 33 | void initialize(const Parameters ¶ms); 34 | virtual void destroy(); 35 | 36 | double valveLift(int lobe) const; 37 | double sampleLobe(double theta) const; 38 | 39 | void setLobeCenterline(int lobe, double crankAngle) { m_lobeAngles[lobe] = crankAngle / 2; } 40 | double getLobeCenterline(int lobe) const { return m_lobeAngles[lobe]; } 41 | 42 | double getAngle() const; 43 | 44 | Function *getLobeProfile() const { return m_lobeProfile; } 45 | double getAdvance() const { return m_advance; } 46 | double getBaseRadius() const { return m_baseRadius; } 47 | 48 | Crankshaft* getCrankshaft() const { return m_crankshaft; } 49 | int getLobes() const { return m_lobes; } 50 | 51 | private: 52 | Crankshaft *m_crankshaft; 53 | Function *m_lobeProfile; 54 | double *m_lobeAngles; 55 | double m_advance; 56 | double m_baseRadius; 57 | int m_lobes; 58 | }; 59 | 60 | #endif /* ATG_ENGINE_SIM_CAMSHAFT_H */ 61 | -------------------------------------------------------------------------------- /include/combustion_chamber_object.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_COMBUSTION_CHAMBER_OBJECT_H 2 | #define ATG_ENGINE_SIM_COMBUSTION_CHAMBER_OBJECT_H 3 | 4 | #include "simulation_object.h" 5 | 6 | #include "combustion_chamber.h" 7 | #include "geometry_generator.h" 8 | 9 | class CombustionChamberObject : public SimulationObject { 10 | public: 11 | CombustionChamberObject(); 12 | virtual ~CombustionChamberObject(); 13 | 14 | virtual void generateGeometry(); 15 | virtual void render(const ViewParameters *view); 16 | virtual void process(float dt); 17 | virtual void destroy(); 18 | 19 | CombustionChamber *m_chamber; 20 | 21 | protected: 22 | GeometryGenerator::GeometryIndices m_indices; 23 | }; 24 | 25 | #endif /* ATG_ENGINE_SIM_COMBUSTION_CHAMBER_OBJECT_H */ 26 | -------------------------------------------------------------------------------- /include/connecting_rod_object.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CONNECTING_ROD_OBJECT_H 2 | #define ATG_ENGINE_SIM_CONNECTING_ROD_OBJECT_H 3 | 4 | #include "simulation_object.h" 5 | 6 | #include "connecting_rod.h" 7 | #include "geometry_generator.h" 8 | 9 | class ConnectingRodObject : public SimulationObject { 10 | public: 11 | ConnectingRodObject(); 12 | virtual ~ConnectingRodObject(); 13 | 14 | virtual void generateGeometry(); 15 | virtual void render(const ViewParameters *view); 16 | virtual void process(float dt); 17 | virtual void destroy(); 18 | 19 | ConnectingRod *m_connectingRod; 20 | 21 | protected: 22 | GeometryGenerator::GeometryIndices 23 | m_connectingRodBody, 24 | m_pins; 25 | }; 26 | 27 | #endif /* ATG_ENGINE_SIM_CONNECTING_ROD_OBJECT_H */ 28 | -------------------------------------------------------------------------------- /include/constants.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CONSTANTS_H 2 | #define ATG_ENGINE_SIM_CONSTANTS_H 3 | 4 | namespace constants { 5 | 6 | extern constexpr double pi = 3.14159265359; 7 | extern constexpr double R = 8.31446261815324; 8 | extern constexpr double root_2 = 1.41421356237309504880168872420969807856967187537694807317667973799; 9 | extern constexpr double e = 2.71828182845904523536028747135266249775724709369995; 10 | 11 | } /* namespace Constants */ 12 | 13 | #endif /* ATG_ENGINE_SIM_CONSTANTS_H */ 14 | -------------------------------------------------------------------------------- /include/convolution_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CONVOLUTION_FILTER_H 2 | #define ATG_ENGINE_SIM_CONVOLUTION_FILTER_H 3 | 4 | #include "filter.h" 5 | 6 | class ConvolutionFilter : public Filter { 7 | public: 8 | ConvolutionFilter(); 9 | virtual ~ConvolutionFilter(); 10 | 11 | void initialize(int samples); 12 | virtual float f(float sample) override; 13 | virtual void destroy(); 14 | 15 | int getSampleCount() const { return m_sampleCount; } 16 | float *getImpulseResponse() { return m_impulseResponse; } 17 | 18 | protected: 19 | float *m_shiftRegister; 20 | int m_shiftOffset; 21 | 22 | float *m_impulseResponse; 23 | int m_sampleCount; 24 | }; 25 | 26 | #endif /* ATG_ENGINE_SIM_CONVOLUTION_FILTER_H */ 27 | -------------------------------------------------------------------------------- /include/crankshaft.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CRANKSHAFT_H 2 | #define ATG_ENGINE_SIM_CRANKSHAFT_H 3 | 4 | #include "part.h" 5 | 6 | class Crankshaft : public Part { 7 | public: 8 | struct Parameters { 9 | double mass; 10 | double flywheelMass; 11 | double momentOfInertia; 12 | double crankThrow; 13 | double pos_x = 0; 14 | double pos_y = 0; 15 | double tdc = 0; 16 | double frictionTorque = 0; 17 | int rodJournals; 18 | }; 19 | 20 | public: 21 | Crankshaft(); 22 | virtual ~Crankshaft(); 23 | 24 | void initialize(const Parameters ¶ms); 25 | virtual void destroy(); 26 | inline int getRodJournalCount() const { return m_rodJournalCount; } 27 | void setRodJournalAngle(int i, double angle); 28 | void getRodJournalPositionLocal(int i, double *x, double *y); 29 | void getRodJournalPositionGlobal(int i, double *x, double *y); 30 | double getRodJournalAngle(int i) { return m_rodJournalAngles[i]; } 31 | 32 | void resetAngle(); 33 | 34 | double getAngle() const; 35 | double getCycleAngle(double offset = 0.0); 36 | 37 | inline double getTdc() const { return m_tdc; } 38 | inline double getThrow() const { return m_throw; } 39 | inline double getMass() const { return m_m; } 40 | inline double getMomentOfInertia() const { return m_I; } 41 | inline double getFlywheelMass() const { return m_flywheelMass; } 42 | inline double getPosX() const { return m_p_x; } 43 | inline double getPosY() const { return m_p_y; } 44 | inline double getFrictionTorque() const { return m_frictionTorque; } 45 | 46 | double m_initialFrictionTorque; 47 | double m_frictionTorque; 48 | double m_throw; 49 | protected: 50 | double *m_rodJournalAngles; 51 | int m_rodJournalCount; 52 | 53 | double m_tdc; 54 | double m_m; 55 | double m_I; 56 | double m_flywheelMass; 57 | double m_p_x; 58 | double m_p_y; 59 | }; 60 | 61 | #endif /* ATG_ENGINE_SIM_CRANKSHAFT_H */ 62 | -------------------------------------------------------------------------------- /include/crankshaft_object.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CRANKSHAFT_OBJECT_H 2 | #define ATG_ENGINE_SIM_CRANKSHAFT_OBJECT_H 3 | 4 | #include "simulation_object.h" 5 | 6 | #include "crankshaft.h" 7 | #include "geometry_generator.h" 8 | 9 | class CrankshaftObject : public SimulationObject { 10 | public: 11 | CrankshaftObject(); 12 | virtual ~CrankshaftObject(); 13 | 14 | virtual void generateGeometry(); 15 | virtual void render(const ViewParameters *view); 16 | virtual void process(float dt); 17 | virtual void destroy(); 18 | 19 | Crankshaft *m_crankshaft; 20 | }; 21 | 22 | #endif /* ATG_ENGINE_SIM_CRANKSHAFT_OBJECT_H */ 23 | -------------------------------------------------------------------------------- /include/csv_io.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CSV_IO_H 2 | #define ATG_ENGINE_SIM_CSV_IO_H 3 | 4 | #include "../dependencies/submodules/csv-io/include/csv_data.h" 5 | 6 | #endif /* ATG_ENGINE_SIM_CSV_IO_H */ 7 | -------------------------------------------------------------------------------- /include/cylinder_bank.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CYLINDER_BANK_H 2 | #define ATG_ENGINE_SIM_CYLINDER_BANK_H 3 | 4 | #include "part.h" 5 | 6 | #include "crankshaft.h" 7 | 8 | class CylinderBank { 9 | public: 10 | struct Parameters { 11 | Crankshaft *crankshaft; 12 | double positionX; 13 | double positionY; 14 | double angle; 15 | double bore; 16 | double deckHeight; 17 | double displayDepth; 18 | int cylinderCount; 19 | int index; 20 | }; 21 | 22 | public: 23 | CylinderBank(); 24 | ~CylinderBank(); 25 | 26 | void initialize(const Parameters ¶ms); 27 | void destroy(); 28 | 29 | void getPositionAboveDeck(double h, double *x, double *y) const; 30 | double boreSurfaceArea() const; 31 | 32 | inline double getAngle() const { return m_angle; } 33 | inline double getBore() const { return m_bore; } 34 | inline double getDeckHeight() const { return m_deckHeight; } 35 | inline int getCylinderCount() const { return m_cylinderCount; } 36 | inline int getIndex() const { return m_index; } 37 | inline double getDx() const { return m_dx; } 38 | inline double getDy() const { return m_dy; } 39 | inline double getX() const { return m_x; } 40 | inline double getY() const { return m_y; } 41 | inline double getDisplayDepth() const { return m_displayDepth; } 42 | 43 | protected: 44 | double m_angle; 45 | double m_bore; 46 | double m_deckHeight; 47 | double m_displayDepth; 48 | int m_cylinderCount; 49 | int m_index; 50 | 51 | double m_dx; 52 | double m_dy; 53 | double m_x; 54 | double m_y; 55 | }; 56 | 57 | #endif /* ATG_ENGINE_SIM_CYLINDER_BANK_H */ 58 | -------------------------------------------------------------------------------- /include/cylinder_bank_object.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CYLINDER_BANK_OBJECT_H 2 | #define ATG_ENGINE_SIM_CYLINDER_BANK_OBJECT_H 3 | 4 | #include "simulation_object.h" 5 | 6 | #include "geometry_generator.h" 7 | #include "cylinder_bank.h" 8 | #include "cylinder_head.h" 9 | 10 | class CylinderBankObject : public SimulationObject { 11 | public: 12 | CylinderBankObject(); 13 | virtual ~CylinderBankObject(); 14 | 15 | virtual void generateGeometry(); 16 | virtual void render(const ViewParameters *view); 17 | virtual void process(float dt); 18 | virtual void destroy(); 19 | 20 | CylinderBank *m_bank; 21 | CylinderHead *m_head; 22 | GeometryGenerator::GeometryIndices m_walls; 23 | }; 24 | 25 | #endif /* ATG_ENGINE_SIM_CYLINDER_BANK_OBJECT_H */ 26 | -------------------------------------------------------------------------------- /include/cylinder_head_object.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CYLINDER_HEAD_OBJECT_H 2 | #define ATG_ENGINE_SIM_CYLINDER_HEAD_OBJECT_H 3 | 4 | #include "simulation_object.h" 5 | 6 | #include "cylinder_head.h" 7 | #include "geometry_generator.h" 8 | #include "engine.h" 9 | 10 | class CylinderHeadObject : public SimulationObject { 11 | public: 12 | CylinderHeadObject(); 13 | virtual ~CylinderHeadObject(); 14 | 15 | virtual void generateGeometry(); 16 | virtual void render(const ViewParameters *view); 17 | virtual void process(float dt); 18 | virtual void destroy(); 19 | 20 | CylinderHead *m_head; 21 | Engine *m_engine; 22 | 23 | protected: 24 | void generateCamshaft( 25 | Camshaft *camshaft, 26 | double padding, 27 | double rollerRadius, 28 | GeometryGenerator::GeometryIndices *indices); 29 | }; 30 | 31 | #endif /* ATG_ENGINE_SIM_CYLINDER_HEAD_OBJECT_H */ 32 | -------------------------------------------------------------------------------- /include/cylinder_pressure_gauge.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_UI_CYLINDER_PRESSURE_GAUGE_H 2 | #define ATG_ENGINE_SIM_UI_CYLINDER_PRESSURE_GAUGE_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "engine.h" 7 | #include "gauge.h" 8 | 9 | class CylinderPressureGauge : public UiElement { 10 | public: 11 | CylinderPressureGauge(); 12 | virtual ~CylinderPressureGauge(); 13 | 14 | virtual void initialize(EngineSimApplication *app); 15 | virtual void destroy(); 16 | 17 | virtual void update(float dt); 18 | virtual void render(); 19 | 20 | Engine *m_engine; 21 | 22 | protected: 23 | std::vector m_gauges; 24 | }; 25 | 26 | #endif /* ATG_ENGINE_SIM_UI_CYLINDER_PRESSURE_GAUGE_H */ 27 | -------------------------------------------------------------------------------- /include/cylinder_temperature_gauge.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CYLINDER_TEMPERATURE_GAUGE_H 2 | #define ATG_ENGINE_SIM_CYLINDER_TEMPERATURE_GAUGE_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "engine.h" 7 | #include "gauge.h" 8 | 9 | class CylinderTemperatureGauge : public UiElement { 10 | public: 11 | CylinderTemperatureGauge(); 12 | virtual ~CylinderTemperatureGauge(); 13 | 14 | virtual void initialize(EngineSimApplication *app); 15 | virtual void destroy(); 16 | 17 | virtual void update(float dt); 18 | virtual void render(); 19 | 20 | Engine *m_engine; 21 | double m_maxTemperature; 22 | double m_minTemperature; 23 | }; 24 | 25 | #endif /* ATG_ENGINE_SIM_CYLINDER_TEMPERATURE_GAUGE_H */ 26 | -------------------------------------------------------------------------------- /include/delay_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_DELAY_FILTER_H 2 | #define ATG_ENGINE_SIM_DELAY_FILTER_H 3 | 4 | #include "filter.h" 5 | 6 | #include "ring_buffer.h" 7 | 8 | #include 9 | 10 | class DelayFilter : public Filter { 11 | public: 12 | DelayFilter() { 13 | m_latencySamples = 0; 14 | } 15 | 16 | virtual ~DelayFilter() { 17 | /* void */ 18 | } 19 | 20 | void initialize(double delay, double audioFrequency) { 21 | const int samples = static_cast(std::round(delay * audioFrequency)); 22 | const int capacity = samples + 32; 23 | 24 | m_history.initialize(capacity); 25 | m_latencySamples = samples; 26 | } 27 | 28 | virtual float f(float sample) override { 29 | return static_cast(fast_f(static_cast(sample))); 30 | } 31 | 32 | inline double fast_f(double sample) { 33 | m_history.write(sample); 34 | 35 | if (m_history.size() <= static_cast(m_latencySamples)) { 36 | return 0; 37 | } 38 | else { 39 | double v; 40 | m_history.readAndRemove(1, &v); 41 | 42 | return v; 43 | } 44 | } 45 | 46 | protected: 47 | int m_latencySamples; 48 | RingBuffer m_history; 49 | }; 50 | 51 | #endif /* ATG_ENGINE_SIM_DELAY_FILTER_H */ 52 | -------------------------------------------------------------------------------- /include/delta.h: -------------------------------------------------------------------------------- 1 | #ifndef DELTA_TEMPLATE_DELTA_INCLUDES_H 2 | #define DELTA_TEMPLATE_DELTA_INCLUDES_H 3 | 4 | #include 5 | #include 6 | 7 | #endif /* DELTA_TEMPLATE_DELTA_INCLUDES_H */ 8 | -------------------------------------------------------------------------------- /include/derivative_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_DERIVATIVE_FILTER_H 2 | #define ATG_ENGINE_SIM_DERIVATIVE_FILTER_H 3 | 4 | #include "filter.h" 5 | 6 | class DerivativeFilter : public Filter { 7 | public: 8 | DerivativeFilter(); 9 | virtual ~DerivativeFilter(); 10 | 11 | virtual float f(float sample) override; 12 | 13 | float m_dt; 14 | 15 | protected: 16 | float m_previous; 17 | }; 18 | 19 | #endif /* ATG_ENGINE_SIM_DERIVATIVE_FILTER_H */ 20 | -------------------------------------------------------------------------------- /include/direct_throttle_linkage.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_DIRECT_THROTTLE_LINKAGE_H 2 | #define ATG_ENGINE_SIM_DIRECT_THROTTLE_LINKAGE_H 3 | 4 | #include "throttle.h" 5 | 6 | class DirectThrottleLinkage : public Throttle { 7 | public: 8 | struct Parameters { 9 | double gamma; 10 | }; 11 | 12 | public: 13 | DirectThrottleLinkage(); 14 | virtual ~DirectThrottleLinkage(); 15 | 16 | void initialize(const Parameters ¶ms); 17 | 18 | virtual void setSpeedControl(double s); 19 | virtual void update(double dt, Engine *engine); 20 | 21 | protected: 22 | double m_gamma; 23 | double m_throttlePosition; 24 | }; 25 | 26 | #endif /* ATG_ENGINE_SIM_DIRECT_THROTTLE_LINKAGE_H */ 27 | -------------------------------------------------------------------------------- /include/dtv.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_DTV_H 2 | #define ATG_ENGINE_SIM_DTV_H 3 | 4 | #include "../dependencies/submodules/direct-to-video/include/dtv.h" 5 | 6 | #endif /* ATG_ENGINE_SIM_DTV_H */ 7 | -------------------------------------------------------------------------------- /include/dynamometer.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_DYNAMOMETER_H 2 | #define ATG_ENGINE_SIM_DYNAMOMETER_H 3 | 4 | #include "scs.h" 5 | 6 | #include "crankshaft.h" 7 | 8 | class Dynamometer : public atg_scs::Constraint { 9 | public: 10 | Dynamometer(); 11 | virtual ~Dynamometer(); 12 | 13 | void connectCrankshaft(Crankshaft *crankshaft); 14 | virtual void calculate(Output *output, atg_scs::SystemState *state); 15 | double getTorque() const; 16 | 17 | double m_rotationSpeed; 18 | double m_ks; 19 | double m_kd; 20 | double m_maxTorque; 21 | 22 | bool m_hold; 23 | bool m_enabled; 24 | }; 25 | 26 | #endif /* ATG_ENGINE_SIM_DYNAMOMETER_H */ 27 | -------------------------------------------------------------------------------- /include/engine_view.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_ENGINE_VIEW_H 2 | #define ATG_ENGINE_SIM_ENGINE_VIEW_H 3 | 4 | #include "ui_element.h" 5 | 6 | class EngineView : public UiElement { 7 | public: 8 | EngineView(); 9 | virtual ~EngineView(); 10 | 11 | virtual void update(float dt); 12 | virtual void render(); 13 | virtual void onMouseDown(const Point &mouseLocal); 14 | virtual void onDrag(const Point &p0, const Point &mouse0, const Point &mouse); 15 | virtual void onMouseScroll(int scroll); 16 | 17 | void setDrawFrame(bool drawFrame) { m_drawFrame = drawFrame; } 18 | void setBounds(const Bounds &bounds); 19 | 20 | Point getCenter() const; 21 | 22 | Point getCameraPosition() const; 23 | float m_zoom; 24 | 25 | protected: 26 | Point m_pan; 27 | Point m_dragStart; 28 | int m_lastScroll; 29 | bool m_drawFrame; 30 | }; 31 | 32 | #endif /* ATG_ENGINE_SIM_ENGINE_VIEW_H */ 33 | -------------------------------------------------------------------------------- /include/exhaust_system.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_EXHAUST_SYSTEM_H 2 | #define ATG_ENGINE_SIM_EXHAUST_SYSTEM_H 3 | 4 | #include "part.h" 5 | 6 | #include "gas_system.h" 7 | #include "impulse_response.h" 8 | 9 | class ExhaustSystem : public Part { 10 | friend class Engine; 11 | 12 | public: 13 | struct Parameters { 14 | double length; 15 | double collectorCrossSectionArea; 16 | double outletFlowRate; 17 | double primaryTubeLength; 18 | double primaryFlowRate; 19 | double velocityDecay; 20 | double audioVolume; 21 | ImpulseResponse *impulseResponse; 22 | }; 23 | 24 | public: 25 | ExhaustSystem(); 26 | virtual ~ExhaustSystem(); 27 | 28 | void initialize(const Parameters ¶ms); 29 | virtual void destroy(); 30 | 31 | void process(double dt); 32 | 33 | inline int getIndex() const { return m_index; } 34 | inline double getLength() const { return m_length; } 35 | inline double getFlow() const { return m_flow; } 36 | inline double getAudioVolume() const { return m_audioVolume; } 37 | inline double getPrimaryFlowRate() const { return m_primaryFlowRate; } 38 | inline double getCollectorCrossSectionArea() const { return m_collectorCrossSectionArea; } 39 | inline double getPrimaryTubeLength() const { return m_primaryTubeLength; } 40 | inline double getVelocityDecay() const { return m_velocityDecay; } 41 | inline ImpulseResponse *getImpulseResponse() const { return m_impulseResponse; } 42 | 43 | inline GasSystem *getSystem() { return &m_system; } 44 | 45 | protected: 46 | GasSystem m_atmosphere; 47 | GasSystem m_system; 48 | 49 | ImpulseResponse *m_impulseResponse; 50 | 51 | double m_length; 52 | double m_primaryTubeLength; 53 | double m_collectorCrossSectionArea; 54 | double m_primaryFlowRate; 55 | double m_outletFlowRate; 56 | double m_audioVolume; 57 | double m_velocityDecay; 58 | int m_index; 59 | 60 | double m_flow; 61 | }; 62 | 63 | #endif /* ATG_ENGINE_SIM_EXHAUST_SYSTEM_H */ 64 | -------------------------------------------------------------------------------- /include/feedback_comb_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_FEEDBACK_COMB_FILTER_H 2 | #define ATG_ENGINE_SIM_FEEDBACK_COMB_FILTER_H 3 | 4 | #include "filter.h" 5 | 6 | class FeedbackCombFilter : public Filter { 7 | public: 8 | FeedbackCombFilter(); 9 | virtual ~FeedbackCombFilter(); 10 | 11 | void initialize(int M); 12 | virtual float f(float sample) override; 13 | virtual void destroy(); 14 | 15 | float a_M; 16 | 17 | protected: 18 | float *m_y; 19 | int m_offset; 20 | 21 | protected: 22 | int M; 23 | }; 24 | 25 | #endif /* ATG_ENGINE_SIM_FEEDBACK_COMB_FILTER_H */ 26 | -------------------------------------------------------------------------------- /include/filter.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_FILTER_H 2 | #define ATG_ENGINE_SIM_FILTER_H 3 | 4 | class Filter { 5 | public: 6 | Filter(); 7 | virtual ~Filter(); 8 | 9 | virtual float f(float sample); 10 | virtual void destroy(); 11 | }; 12 | 13 | #endif /* ATG_ENGINE_SIM_FILTER_H */ 14 | -------------------------------------------------------------------------------- /include/firing_order_display.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_FIRING_ORDER_DISPLAY_H 2 | #define ATG_ENGINE_SIM_FIRING_ORDER_DISPLAY_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "engine.h" 7 | #include "gauge.h" 8 | 9 | class FiringOrderDisplay : public UiElement { 10 | public: 11 | FiringOrderDisplay(); 12 | virtual ~FiringOrderDisplay(); 13 | 14 | virtual void initialize(EngineSimApplication *app); 15 | virtual void destroy(); 16 | 17 | virtual void update(float dt); 18 | virtual void render(); 19 | 20 | Engine *m_engine; 21 | 22 | protected: 23 | int m_cylinderCount; 24 | float *m_cylinderLit; 25 | }; 26 | 27 | #endif /* ATG_ENGINE_SIM_FIRING_ORDER_DISPLAY_H */ 28 | -------------------------------------------------------------------------------- /include/fuel_cluster.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_FUEL_CLUSTER_H 2 | #define ATG_ENGINE_SIM_FUEL_CLUSTER_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "engine.h" 7 | #include "simulator.h" 8 | #include "labeled_gauge.h" 9 | 10 | class FuelCluster : public UiElement { 11 | public: 12 | FuelCluster(); 13 | virtual ~FuelCluster(); 14 | 15 | virtual void initialize(EngineSimApplication *app); 16 | virtual void destroy(); 17 | 18 | virtual void update(float dt); 19 | virtual void render(); 20 | 21 | Engine *m_engine; 22 | Simulator *m_simulator; 23 | 24 | 25 | private: 26 | double getTotalVolumeFuelConsumed() const; 27 | 28 | LabeledGauge* m_pulseWidthGauge; 29 | LabeledGauge* m_sparkAdvanceGauge; 30 | }; 31 | 32 | #endif /* ATG_ENGINE_SIM_FUEL_CLUSTER_H */ 33 | -------------------------------------------------------------------------------- /include/function.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_FUNCTION_H 2 | #define ATG_ENGINE_SIM_FUNCTION_H 3 | 4 | #include "gaussian_filter.h" 5 | 6 | class Function { 7 | protected: 8 | static GaussianFilter *DefaultGaussianFilter; 9 | 10 | public: 11 | Function(); 12 | virtual ~Function(); 13 | 14 | void initialize(int size, double filterRadius, GaussianFilter *filter = nullptr); 15 | void resize(int newCapacity); 16 | void destroy(); 17 | 18 | void setInputScale(double s) { m_inputScale = s; } 19 | void setOutputScale(double s) { m_outputScale = s; } 20 | void addSample(double x, double y); 21 | 22 | double sampleTriangle(double x) const; 23 | double sampleGaussian(double x) const; 24 | double triangle(double x) const; 25 | int closestSample(double x) const; 26 | 27 | bool isOrdered() const; 28 | 29 | void getDomain(double *x0, double *x1); 30 | void getRange(double *y0, double *y1); 31 | 32 | protected: 33 | double *m_x; 34 | double *m_y; 35 | 36 | double m_yMin; 37 | double m_yMax; 38 | double m_inputScale; 39 | double m_outputScale; 40 | 41 | double m_filterRadius; 42 | 43 | int m_capacity; 44 | int m_size; 45 | 46 | GaussianFilter *m_gaussianFilter; 47 | }; 48 | 49 | #endif /* ATG_ENGINE_SIM_FUNCTION_H */ 50 | -------------------------------------------------------------------------------- /include/gauge.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_GAUGE_H 2 | #define ATG_ENGINE_SIM_GAUGE_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include 7 | 8 | class Gauge : public UiElement { 9 | public: 10 | struct Band { 11 | ysVector color = ysMath::Constants::One; 12 | float start = 0.0; 13 | float end = 0.0; 14 | float width = 0.0; 15 | float radial_offset = 0.0f; 16 | float shorten_start = 0.0f; 17 | float shorten_end = 0.0f; 18 | }; 19 | 20 | public: 21 | Gauge(); 22 | virtual ~Gauge(); 23 | 24 | virtual void initialize(EngineSimApplication *app); 25 | virtual void destroy(); 26 | 27 | virtual void update(float dt); 28 | virtual void render(); 29 | 30 | void setBandCount(int bands) { m_bands.resize(bands); } 31 | void setBand(const Band &band, int index) { m_bands[index] = band; } 32 | 33 | float m_value; 34 | float m_thetaMin; 35 | float m_thetaMax; 36 | 37 | int m_min; 38 | int m_max; 39 | int m_maxMinorTick; 40 | float m_gamma; 41 | 42 | int m_minorStep; 43 | int m_majorStep; 44 | 45 | float m_minorTickWidth; 46 | float m_majorTickWidth; 47 | 48 | float m_minorTickLength; 49 | float m_majorTickLength; 50 | 51 | float m_outerRadius; 52 | 53 | float m_needleInnerRadius; 54 | float m_needleOuterRadius; 55 | float m_needleWidth; 56 | 57 | float m_needleMaxVelocity; 58 | float m_needleKs; 59 | float m_needleKd; 60 | 61 | bool m_renderText; 62 | 63 | Point m_center; 64 | 65 | protected: 66 | float m_needlePosition; 67 | float m_needleVelocity; 68 | 69 | protected: 70 | std::vector m_bands; 71 | }; 72 | 73 | #endif /* ATG_ENGINE_SIM_GAUGE_H */ 74 | -------------------------------------------------------------------------------- /include/gaussian_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_GUASSIAN_FILTER_H 2 | #define ATG_ENGINE_SIM_GUASSIAN_FILTER_H 3 | 4 | #include "scs.h" 5 | 6 | #include "crankshaft.h" 7 | 8 | class GaussianFilter { 9 | public: 10 | GaussianFilter(); 11 | ~GaussianFilter(); 12 | 13 | void initialize(double alpha, double radius, int cacheSteps=1024); 14 | double evaluate(double s) const; 15 | 16 | double getRadius() const { return m_radius; } 17 | double getAlpha() const { return m_alpha; } 18 | 19 | protected: 20 | double calculate(double s) const; 21 | void generateCache(); 22 | 23 | protected: 24 | double *m_cache; 25 | 26 | int m_cacheSteps; 27 | double m_radius; 28 | double m_alpha; 29 | 30 | double m_exp_s; 31 | double m_inv_r; 32 | }; 33 | 34 | #endif /* ATG_ENGINE_SIM_GAUSSIAN_FILTER_H */ 35 | -------------------------------------------------------------------------------- /include/governor.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_GOVERNOR_H 2 | #define ATG_ENGINE_SIM_GOVERNOR_H 3 | 4 | #include "throttle.h" 5 | 6 | class Governor : public Throttle { 7 | public: 8 | struct Parameters { 9 | double minSpeed; 10 | double maxSpeed; 11 | double minVelocity; 12 | double maxVelocity; 13 | double k_s; 14 | double k_d; 15 | double gamma; 16 | }; 17 | 18 | public: 19 | Governor(); 20 | virtual ~Governor(); 21 | 22 | void initialize(const Parameters ¶ms); 23 | 24 | virtual void setSpeedControl(double s); 25 | virtual void update(double dt, Engine *engine); 26 | 27 | protected: 28 | double m_minSpeed; 29 | double m_maxSpeed; 30 | double m_minVelocity; 31 | double m_maxVelocity; 32 | double m_k_s; 33 | double m_k_d; 34 | double m_gamma; 35 | 36 | double m_targetSpeed; 37 | 38 | double m_currentThrottle; 39 | double m_velocity; 40 | }; 41 | 42 | #endif /* ATG_ENGINE_SIM_GOVERNOR_H */ 43 | -------------------------------------------------------------------------------- /include/impulse_response.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_IMPULSE_RESPONSE_H 2 | #define ATG_ENGINE_SIM_IMPULSE_RESPONSE_H 3 | 4 | #include 5 | 6 | class ImpulseResponse { 7 | public: 8 | ImpulseResponse(); 9 | virtual ~ImpulseResponse(); 10 | 11 | void initialize(const std::string &filename, double volume); 12 | std::string getFilename() const { return m_filename; } 13 | double getVolume() const { return m_volume; } 14 | 15 | protected: 16 | std::string m_filename; 17 | double m_volume; 18 | }; 19 | 20 | #endif /* ATG_ENGINE_SIM_IMPULSE_RESPONSE_H */ 21 | -------------------------------------------------------------------------------- /include/info_cluster.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_INFO_CLUSTER_H 2 | #define ATG_ENGINE_SIM_INFO_CLUSTER_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "engine.h" 7 | 8 | #include 9 | 10 | class InfoCluster : public UiElement { 11 | public: 12 | InfoCluster(); 13 | virtual ~InfoCluster(); 14 | 15 | virtual void initialize(EngineSimApplication *app); 16 | virtual void destroy(); 17 | 18 | virtual void update(float dt); 19 | virtual void render(); 20 | 21 | void setEngine(Engine *engine) { m_engine = engine; } 22 | void setLogMessage(const std::string &logMessage) { m_logMessage = logMessage; } 23 | std::string getLogMessage() const { return m_logMessage; } 24 | 25 | protected: 26 | Engine *m_engine; 27 | 28 | std::string m_logMessage; 29 | }; 30 | 31 | #endif /* ATG_ENGINE_SIM_INFO_CLUSTER_H */ 32 | -------------------------------------------------------------------------------- /include/jitter_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_JITTER_FILTER_H 2 | #define ATG_ENGINE_SIM_JITTER_FILTER_H 3 | 4 | #include "filter.h" 5 | 6 | #include "butterworth_low_pass_filter.h" 7 | #include "utilities.h" 8 | 9 | #include 10 | 11 | class JitterFilter : public Filter { 12 | public: 13 | JitterFilter(); 14 | virtual ~JitterFilter(); 15 | 16 | void initialize( 17 | int maxJitter, 18 | float noiseCutoffFrequency, 19 | float audioFrequency); 20 | virtual float f(float sample) override; 21 | 22 | __forceinline float fast_f(float sample, float jitterScale = 1.0f) { 23 | m_history[m_offset] = sample; 24 | ++m_offset; 25 | 26 | if (m_offset >= m_maxJitter) { 27 | m_offset = 0; 28 | } 29 | 30 | std::uniform_real_distribution dist( 31 | 0.0f, 32 | static_cast(m_maxJitter - 1)); 33 | 34 | const float s = m_noiseFilter.fast_f(dist(m_generator) * m_jitterScale * jitterScale); 35 | const float s_i_0 = clamp(std::floor(s), 0.0f, static_cast(m_maxJitter - 1)); 36 | const float s_i_1 = clamp(std::ceil(s), 0.0f, static_cast(m_maxJitter - 1)); 37 | 38 | const float s_frac = (s - s_i_0); 39 | 40 | const int i_0 = static_cast(s_i_0) + m_offset; 41 | const int i_1 = static_cast(s_i_1) + m_offset; 42 | 43 | const float v0 = m_history[i_0 >= m_maxJitter ? i_0 - m_maxJitter : i_0]; 44 | const float v1 = m_history[i_1 >= m_maxJitter ? i_1 - m_maxJitter : i_1]; 45 | 46 | return v1 * s_frac + v0 * (1 - s_frac); 47 | } 48 | 49 | inline void setJitterScale(float jitterScale) { m_jitterScale = jitterScale; } 50 | inline float getJitterScale() const { return m_jitterScale; } 51 | 52 | protected: 53 | ButterworthLowPassFilter m_noiseFilter; 54 | 55 | float m_jitterScale; 56 | int m_maxJitter; 57 | int m_offset; 58 | float *m_history; 59 | 60 | std::default_random_engine m_generator; 61 | }; 62 | 63 | #endif /* ATG_ENGINE_SIM_JITTER_FILTER_H */ 64 | -------------------------------------------------------------------------------- /include/labeled_gauge.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_LABELED_GAUGE_H 2 | #define ATG_ENGINE_SIM_LABELED_GAUGE_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "gauge.h" 7 | 8 | #include 9 | 10 | class LabeledGauge : public UiElement { 11 | public: 12 | LabeledGauge(); 13 | virtual ~LabeledGauge(); 14 | 15 | virtual void initialize(EngineSimApplication *app); 16 | virtual void destroy(); 17 | 18 | virtual void update(float dt); 19 | virtual void render(); 20 | 21 | Gauge *m_gauge; 22 | std::string m_title; 23 | 24 | int m_precision; 25 | bool m_spaceBeforeUnit; 26 | std::string m_unit; 27 | 28 | float m_margin = 10.0f; 29 | float m_needleInnerRadius = 0.1f; 30 | float m_needleOuterRadius = 0.7f; 31 | }; 32 | 33 | #endif /* ATG_ENGINE_SIM_LABELED_GAUGE_H */ 34 | -------------------------------------------------------------------------------- /include/lerp_function.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_LERP_FUNCTION_H 2 | #define ATG_ENGINE_SIM_LERP_FUNCTION_H 3 | 4 | #include "function.h" 5 | 6 | class LerpFunction : public Function { 7 | public: 8 | LerpFunction(Function* from, Function* to, float time); 9 | virtual ~LerpFunction(); 10 | 11 | //void initialize(int size, double filterRadius, GaussianFilter *filter = nullptr); 12 | //void destroy(); 13 | 14 | void setInputScale(double s) { m_inputScale = s; } 15 | void setOutputScale(double s) { m_outputScale = s; } 16 | 17 | double sampleTriangle(double x) const; 18 | double sampleGaussian(double x) const; 19 | double triangle(double x) const; 20 | //int closestSample(double x) const; 21 | 22 | inline static float lerp(float a, float b, float f) { 23 | return a * (1.0 - f) + (b * f); 24 | } 25 | 26 | protected: 27 | Function* from; 28 | Function* to; 29 | float time; 30 | }; 31 | 32 | #endif /* ATG_ENGINE_SIM_LERP_FUNCTION_H */ 33 | -------------------------------------------------------------------------------- /include/leveling_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_LEVELING_FILTER_H 2 | #define ATG_ENGINE_SIM_LEVELING_FILTER_H 3 | 4 | #include "filter.h" 5 | 6 | #include "function.h" 7 | 8 | class LevelingFilter : public Filter { 9 | public: 10 | LevelingFilter(); 11 | virtual ~LevelingFilter(); 12 | 13 | virtual float f(float sample); 14 | float getAttenuation() const { return m_attenuation; } 15 | 16 | protected: 17 | float m_peak; 18 | float m_attenuation; 19 | 20 | public: 21 | float p_maxLevel; 22 | float p_minLevel; 23 | float p_target; 24 | }; 25 | 26 | #endif /* ATG_ENGINE_SIM_LEVELING_FILTER_H */ 27 | -------------------------------------------------------------------------------- /include/load_simulation_cluster.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_LOAD_SIMULATION_CLUSTER_H 2 | #define ATG_ENGINE_SIM_LOAD_SIMULATION_CLUSTER_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "simulator.h" 7 | #include "labeled_gauge.h" 8 | 9 | class LoadSimulationCluster : public UiElement { 10 | public: 11 | LoadSimulationCluster(); 12 | virtual ~LoadSimulationCluster(); 13 | 14 | virtual void initialize(EngineSimApplication *app); 15 | virtual void destroy(); 16 | 17 | virtual void update(float dt); 18 | virtual void render(); 19 | void setUnits(); 20 | 21 | void setSimulator(Simulator *simulator) { m_simulator = simulator; } 22 | 23 | private: 24 | Transmission *getTransmission() const { return m_simulator->getTransmission(); } 25 | 26 | protected: 27 | void drawCurrentGear(const Bounds &bounds); 28 | void drawClutchPressureGauge(const Bounds &bounds); 29 | void drawSystemStatus(const Bounds &bounds); 30 | void updateHpAndTorque(float dt); 31 | bool isIgnitionOn() const; 32 | 33 | float m_systemStatusLights[4]; 34 | LabeledGauge *m_dynoSpeedGauge; 35 | LabeledGauge *m_torqueGauge; 36 | LabeledGauge *m_hpGauge; 37 | LabeledGauge *m_clutchPressureGauge; 38 | 39 | double m_filteredHorsepower; 40 | double m_filteredTorque; 41 | 42 | double m_peakHorsepowerRpm; 43 | double m_peakHorsepower; 44 | double m_peakTorqueRpm; 45 | double m_peakTorque; 46 | 47 | std::string m_powerUnits; 48 | std::string m_torqueUnits; 49 | 50 | Simulator *m_simulator; 51 | }; 52 | 53 | #endif /* ATG_ENGINE_SIM_LOAD_SIMULATION_CLUSTER_H */ 54 | -------------------------------------------------------------------------------- /include/logging_cluster.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ATG_ENGINE_SIM_LOGGING_CLUSTER_H 3 | #define ATG_ENGINE_SIM_LOGGING_CLUSTER_H 4 | 5 | #include "ui_element.h" 6 | 7 | #include "simulator.h" 8 | #include "labeled_gauge.h" 9 | 10 | class LoggingCluster : public UiElement { 11 | public: 12 | LoggingCluster(); 13 | virtual ~LoggingCluster(); 14 | 15 | virtual void initialize(EngineSimApplication* app); 16 | virtual void destroy(); 17 | 18 | virtual void update(float dt); 19 | virtual void render(); 20 | }; 21 | 22 | #endif /* ATG_ENGINE_SIM_LOGGING_CLUSTER_H */ 23 | -------------------------------------------------------------------------------- /include/low_pass_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_LOW_PASS_FILTER_H 2 | #define ATG_ENGINE_SIM_LOW_PASS_FILTER_H 3 | 4 | #include "filter.h" 5 | 6 | #include "constants.h" 7 | 8 | class LowPassFilter : public Filter { 9 | public: 10 | LowPassFilter(); 11 | virtual ~LowPassFilter(); 12 | 13 | virtual float f(float sample) override; 14 | 15 | __forceinline float fast_f(float sample) { 16 | const float alpha = m_dt / (m_rc + m_dt); 17 | m_y = alpha * sample + (1 - alpha) * m_y; 18 | 19 | return m_y; 20 | } 21 | 22 | inline void setCutoffFrequency(float f) { 23 | m_rc = 1.0f / (f * 2.0f * static_cast(constants::pi)); 24 | } 25 | 26 | float m_dt; 27 | 28 | protected: 29 | float m_y; 30 | float m_rc; 31 | }; 32 | 33 | #endif /* ATG_ENGINE_SIM_LOW_PASS_FILTER_H */ 34 | -------------------------------------------------------------------------------- /include/mixer_cluster.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_MIXER_CLUSTER_H 2 | #define ATG_ENGINE_SIM_MIXER_CLUSTER_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "engine.h" 7 | #include "gauge.h" 8 | #include "cylinder_temperature_gauge.h" 9 | #include "cylinder_pressure_gauge.h" 10 | #include "labeled_gauge.h" 11 | #include "throttle_display.h" 12 | #include "simulator.h" 13 | 14 | class MixerCluster : public UiElement { 15 | public: 16 | MixerCluster(); 17 | virtual ~MixerCluster(); 18 | 19 | virtual void initialize(EngineSimApplication *app); 20 | virtual void destroy(); 21 | 22 | virtual void update(float dt); 23 | virtual void render(); 24 | 25 | void setSimulator(Simulator *simulator) { m_simulator = simulator; } 26 | 27 | protected: 28 | Simulator *m_simulator; 29 | 30 | protected: 31 | LabeledGauge 32 | *m_volumeGauge, 33 | *m_convolutionGauge, 34 | *m_highFreqFilterGauge, 35 | *m_levelerGauge, 36 | *m_noise0Gauge, 37 | *m_noise1Gauge; 38 | }; 39 | 40 | #endif /* ATG_ENGINE_SIM_MIXER_CLUSTER_H */ 41 | -------------------------------------------------------------------------------- /include/oscilloscope.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_OSCILLOSCOPE_H 2 | #define ATG_ENGINE_SIM_OSCILLOSCOPE_H 3 | 4 | #include "ui_element.h" 5 | 6 | class Oscilloscope : public UiElement { 7 | public: 8 | struct DataPoint { 9 | double x, y; 10 | }; 11 | 12 | public: 13 | Oscilloscope(); 14 | virtual ~Oscilloscope(); 15 | 16 | virtual void initialize(EngineSimApplication *app); 17 | virtual void destroy(); 18 | 19 | virtual void update(float dt); 20 | virtual void render(); 21 | void render(const Bounds &bounds); 22 | 23 | Point dataPointToRenderPosition( 24 | const DataPoint &p, 25 | const Bounds &bounds) const; 26 | 27 | void addDataPoint(double x, double y); 28 | 29 | void setBufferSize(int n); 30 | void reset(); 31 | 32 | double m_xMin; 33 | double m_xMax; 34 | 35 | double m_yMin; 36 | double m_yMax; 37 | 38 | double m_dynamicallyResizeX; 39 | double m_dynamicallyResizeY; 40 | 41 | double m_lineWidth; 42 | bool m_drawReverse; 43 | bool m_drawZero; 44 | 45 | ysVector i_color; 46 | 47 | protected: 48 | DataPoint *m_points; 49 | Point *m_renderBuffer; 50 | int m_writeIndex; 51 | int m_bufferSize; 52 | int m_pointCount; 53 | }; 54 | 55 | #endif /* ATG_ENGINE_SIM_OSCILLOSCOPE_H */ 56 | -------------------------------------------------------------------------------- /include/part.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_PART_H 2 | #define ATG_ENGINE_SIM_PART_H 3 | 4 | #include "scs.h" 5 | 6 | class Part { 7 | public: 8 | Part(); 9 | virtual ~Part(); 10 | 11 | virtual void destroy(); 12 | 13 | atg_scs::RigidBody m_body; 14 | }; 15 | 16 | #endif /* ATG_ENGINE_SIM_PART_H */ 17 | -------------------------------------------------------------------------------- /include/performance_cluster.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_PERFORMANCE_CLUSTER_H 2 | #define ATG_ENGINE_SIM_PERFORMANCE_CLUSTER_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "engine.h" 7 | #include "gauge.h" 8 | #include "cylinder_temperature_gauge.h" 9 | #include "cylinder_pressure_gauge.h" 10 | #include "labeled_gauge.h" 11 | #include "throttle_display.h" 12 | #include "simulator.h" 13 | 14 | class PerformanceCluster : public UiElement { 15 | public: 16 | PerformanceCluster(); 17 | virtual ~PerformanceCluster(); 18 | 19 | virtual void initialize(EngineSimApplication *app); 20 | virtual void destroy(); 21 | 22 | virtual void update(float dt); 23 | virtual void render(); 24 | 25 | void setSimulator(Simulator *simulator) { m_simulator = simulator; } 26 | void addTimePerTimestepSample(double sample); 27 | void addAudioLatencySample(double sample); 28 | void addInputBufferUsageSample(double sample); 29 | 30 | LabeledGauge *m_timePerTimestepGauge; 31 | LabeledGauge *m_fpsGauge; 32 | LabeledGauge *m_simSpeedGauge; 33 | LabeledGauge *m_simulationFrequencyGauge; 34 | LabeledGauge *m_inputSamplesGauge; 35 | LabeledGauge *m_audioLagGauge; 36 | 37 | protected: 38 | double m_timePerTimestep; 39 | 40 | double m_filteredSimulationFrequency; 41 | double m_audioLatency; 42 | double m_inputBufferUsage; 43 | 44 | Simulator *m_simulator; 45 | }; 46 | 47 | #endif /* ATG_ENGINE_SIM_PERFORMANCE_CLUSTER_H */ 48 | -------------------------------------------------------------------------------- /include/piston.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_PISTON_H 2 | #define ATG_ENGINE_SIM_PISTON_H 3 | 4 | #include "part.h" 5 | 6 | class ConnectingRod; 7 | class CylinderBank; 8 | class Piston : public Part { 9 | public: 10 | struct Parameters { 11 | ConnectingRod *Rod; 12 | CylinderBank *Bank; 13 | int CylinderIndex; 14 | 15 | double BlowbyFlowCoefficient; 16 | double CompressionHeight; 17 | double WristPinPosition; 18 | double Displacement; 19 | double mass; 20 | }; 21 | 22 | public: 23 | Piston(); 24 | virtual ~Piston(); 25 | 26 | void initialize(const Parameters ¶ms); 27 | inline void setCylinderConstraint(atg_scs::LineConstraint *constraint); 28 | virtual void destroy(); 29 | 30 | double relativeX() const; 31 | double relativeY() const; 32 | 33 | double calculateCylinderWallForce() const; 34 | inline ConnectingRod *getRod() const { return m_rod; } 35 | inline CylinderBank *getCylinderBank() const { return m_bank; } 36 | inline int getCylinderIndex() const { return m_cylinderIndex; } 37 | inline double getCompressionHeight() const { return m_compressionHeight; } 38 | inline double getDisplacement() const { return m_displacement; } 39 | inline double getWristPinLocation() const { return m_wristPinLocation; } 40 | inline double getMass() const { return m_mass; } 41 | inline double getBlowbyK() const { return m_blowby_k; } 42 | 43 | double m_blowby_k; 44 | double m_initialBlowby; 45 | protected: 46 | ConnectingRod *m_rod; 47 | CylinderBank *m_bank; 48 | atg_scs::LineConstraint *m_cylinderConstraint; 49 | int m_cylinderIndex; 50 | double m_compressionHeight; 51 | double m_displacement; 52 | double m_wristPinLocation; 53 | double m_mass; 54 | }; 55 | 56 | void Piston::setCylinderConstraint(atg_scs::LineConstraint *constraint) { 57 | m_cylinderConstraint = constraint; 58 | } 59 | 60 | #endif /* ATG_ENGINE_SIM_PISTON_H */ 61 | -------------------------------------------------------------------------------- /include/piston_object.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_PISTON_OBJECT_H 2 | #define ATG_ENGINE_SIM_PISTON_OBJECT_H 3 | 4 | #include "simulation_object.h" 5 | 6 | #include "piston.h" 7 | #include "geometry_generator.h" 8 | 9 | class PistonObject : public SimulationObject { 10 | public: 11 | PistonObject(); 12 | virtual ~PistonObject(); 13 | 14 | virtual void generateGeometry(); 15 | virtual void render(const ViewParameters *view); 16 | virtual void process(float dt); 17 | virtual void destroy(); 18 | 19 | Piston *m_piston; 20 | 21 | protected: 22 | GeometryGenerator::GeometryIndices 23 | m_wristPinHole; 24 | }; 25 | 26 | #endif /* ATG_ENGINE_SIM_PISTON_OBJECT_H */ 27 | -------------------------------------------------------------------------------- /include/preemphasis_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_PREEMPHASIS_FILTER_H 2 | #define ATG_ENGINE_SIM_PREEMPHASIS_FILTER_H 3 | 4 | #include "filter.h" 5 | 6 | #include "low_pass_filter.h" 7 | 8 | #include 9 | 10 | class PreemphasisFilter : public Filter { 11 | public: 12 | PreemphasisFilter() { m_lastSample = 0; } 13 | virtual ~PreemphasisFilter() {} 14 | 15 | virtual float f(float sample) override { return fast_f(sample); } 16 | 17 | __forceinline float fast_f(float sample) { 18 | const float s = -0.95f * sample + m_lastSample; 19 | 20 | m_lastSample = sample; 21 | return s; 22 | } 23 | 24 | protected: 25 | float m_lastSample; 26 | }; 27 | 28 | #endif /* ATG_ENGINE_SIM_PREEMPHASIS_FILTER_H */ 29 | -------------------------------------------------------------------------------- /include/right_gauge_cluster.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_RIGHT_GAUGE_CLUSTER_H 2 | #define ATG_ENGINE_SIM_RIGHT_GAUGE_CLUSTER_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "engine.h" 7 | #include "simulator.h" 8 | #include "gauge.h" 9 | #include "firing_order_display.h" 10 | #include "labeled_gauge.h" 11 | #include "throttle_display.h" 12 | #include "afr_cluster.h" 13 | #include "fuel_cluster.h" 14 | 15 | class RightGaugeCluster : public UiElement { 16 | public: 17 | RightGaugeCluster(); 18 | virtual ~RightGaugeCluster(); 19 | 20 | virtual void initialize(EngineSimApplication *app); 21 | virtual void destroy(); 22 | 23 | virtual void update(float dt); 24 | virtual void render(); 25 | 26 | void setEngine(Engine *engine); 27 | void setUnits(); 28 | double getManifoldPressureWithUnits(double ambientPressure); 29 | 30 | Simulator *m_simulator; 31 | 32 | private: 33 | double getRpm() const; 34 | double getRedline() const; 35 | double getSpeed() const; 36 | double getManifoldPressure() const; 37 | 38 | protected: 39 | Engine *m_engine; 40 | 41 | void renderTachSpeedCluster(const Bounds &bounds); 42 | void renderFuelAirCluster(const Bounds &bounds); 43 | 44 | LabeledGauge *m_tachometer; 45 | LabeledGauge *m_speedometer; 46 | LabeledGauge *m_manifoldVacuumGauge; 47 | LabeledGauge *m_intakeCfmGauge; 48 | LabeledGauge *m_volumetricEffGauge; 49 | FuelCluster *m_fuelCluster; 50 | ThrottleDisplay *m_throttleDisplay; 51 | AfrCluster *m_afrCluster; 52 | FiringOrderDisplay *m_combusionChamberStatus; 53 | std::string m_speedUnits; 54 | std::string m_pressureUnits; 55 | bool m_isAbsolute; 56 | }; 57 | 58 | #endif /* ATG_ENGINE_SIM_GAUGE_CLUSTER_H */ 59 | -------------------------------------------------------------------------------- /include/scs.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_SCS_H 2 | #define ATG_ENGINE_SIM_SCS_H 3 | 4 | #include "../dependencies/submodules/simple-2d-constraint-solver/include/scs.h" 5 | 6 | #endif /* ATG_ENGINE_SIM_SCS_H */ 7 | -------------------------------------------------------------------------------- /include/shaders.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_SHADERS_H 2 | #define ATG_ENGINE_SIM_SHADERS_H 3 | 4 | #include "delta.h" 5 | 6 | #include "ui_math.h" 7 | 8 | class Shaders : public dbasic::ShaderBase { 9 | public: 10 | Shaders(); 11 | ~Shaders(); 12 | 13 | ysError Initialize( 14 | dbasic::ShaderSet *shaderSet, 15 | ysRenderTarget *mainRenderTarget, 16 | ysRenderTarget *uiRenderTarget, 17 | ysShaderProgram *shaderProgram, 18 | ysInputLayout *inputLayout); 19 | virtual ysError UseMaterial(dbasic::Material *material); 20 | virtual void SetObjectTransform(const ysMatrix &mat); 21 | virtual void ConfigureModel(float scale, dbasic::ModelAsset *model); 22 | 23 | void SetBaseColor(const ysVector &color); 24 | void ResetBaseColor(); 25 | 26 | dbasic::StageEnableFlags GetRegularFlags() const; 27 | dbasic::StageEnableFlags GetUiFlags() const; 28 | 29 | void CalculateCamera( 30 | float width, 31 | float height, 32 | const Bounds &cameraBounds, 33 | float screenWidth, 34 | float screenHeight, 35 | float angle = 0.0f); 36 | void CalculateUiCamera(float screenWidth, float screenHeight); 37 | 38 | void SetClearColor(const ysVector &col); 39 | 40 | public: 41 | dbasic::ShaderScreenVariables m_screenVariables; 42 | dbasic::ShaderScreenVariables m_uiScreenVariables; 43 | dbasic::ShaderObjectVariables m_objectVariables; 44 | 45 | ysVector m_cameraPosition; 46 | 47 | protected: 48 | dbasic::ShaderStage *m_mainStage; 49 | dbasic::ShaderStage *m_uiStage; 50 | 51 | dbasic::LightingControls m_lightingControls; 52 | }; 53 | 54 | #endif /* ATG_ENGINE_SIM_SHADERS_H */ 55 | -------------------------------------------------------------------------------- /include/simulation_object.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_SIMULATION_OBJECT_H 2 | #define ATG_ENGINE_SIM_SIMULATION_OBJECT_H 3 | 4 | #include "scs.h" 5 | #include "delta.h" 6 | 7 | class Piston; 8 | class CylinderBank; 9 | class EngineSimApplication; 10 | class SimulationObject { 11 | public: 12 | struct ViewParameters { 13 | int Layer0; 14 | int Layer1; 15 | int Sublayer; 16 | }; 17 | 18 | public: 19 | SimulationObject(); 20 | virtual ~SimulationObject(); 21 | 22 | virtual void initialize(EngineSimApplication *app); 23 | virtual void generateGeometry(); 24 | virtual void render(const ViewParameters *settings); 25 | virtual void process(float dt); 26 | virtual void destroy(); 27 | 28 | Piston *getForemostPiston(CylinderBank *bank, int layer); 29 | 30 | protected: 31 | void resetShader(); 32 | void setTransform( 33 | atg_scs::RigidBody *rigidBody, 34 | float scale = 1.0f, 35 | float lx = 0.0f, 36 | float ly = 0.0f, 37 | float theta = 0.0f, 38 | float z = 0.0f); 39 | ysVector tintByLayer(const ysVector &col, int layers) const; 40 | 41 | EngineSimApplication *m_app; 42 | }; 43 | 44 | #endif /* ATG_ENGINE_SIM_SIMULATION_OBJECT_H */ 45 | -------------------------------------------------------------------------------- /include/standard_valvetrain.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_STANDARD_VALVETRAIN_H 2 | #define ATG_ENGINE_SIM_STANDARD_VALVETRAIN_H 3 | 4 | #include "valvetrain.h" 5 | 6 | class StandardValvetrain : public Valvetrain { 7 | public: 8 | struct Parameters { 9 | Camshaft *intakeCamshaft; 10 | Camshaft *exhaustCamshaft; 11 | }; 12 | 13 | public: 14 | StandardValvetrain(); 15 | virtual ~StandardValvetrain(); 16 | 17 | void initialize(const Parameters ¶meters); 18 | 19 | virtual double intakeValveLift(int cylinder) override; 20 | virtual double exhaustValveLift(int cylinder) override; 21 | 22 | virtual Camshaft *getActiveIntakeCamshaft() override; 23 | virtual Camshaft *getActiveExhaustCamshaft() override; 24 | 25 | private: 26 | Camshaft *m_intakeCamshaft; 27 | Camshaft *m_exhaustCamshaft; 28 | }; 29 | 30 | #endif /* ATG_ENGINE_SIM_STANDARD_VALVETRAIN_H */ 31 | -------------------------------------------------------------------------------- /include/starter_motor.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_STARTER_MOTOR_H 2 | #define ATG_ENGINE_SIM_STARTER_MOTOR_H 3 | 4 | #include "scs.h" 5 | 6 | #include "crankshaft.h" 7 | 8 | class StarterMotor : public atg_scs::Constraint { 9 | public: 10 | StarterMotor(); 11 | virtual ~StarterMotor(); 12 | 13 | void connectCrankshaft(Crankshaft *crankshaft); 14 | virtual void calculate(Output *output, atg_scs::SystemState *state); 15 | 16 | double m_ks; 17 | double m_kd; 18 | double m_maxTorque; 19 | double m_rotationSpeed; 20 | bool m_enabled; 21 | }; 22 | 23 | #endif /* ATG_ENGINE_SIM_STARTER_MOTOR_H */ 24 | -------------------------------------------------------------------------------- /include/throttle.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_THROTTLE_H 2 | #define ATG_ENGINE_SIM_THROTTLE_H 3 | 4 | #include "part.h" 5 | 6 | class Engine; 7 | class Throttle { 8 | public: 9 | Throttle(); 10 | virtual ~Throttle(); 11 | 12 | virtual void setSpeedControl(double s); 13 | virtual void update(double dt, Engine *engine); 14 | 15 | inline double getSpeedControl() const { return m_speedControl; } 16 | 17 | protected: 18 | double m_speedControl; 19 | }; 20 | 21 | #endif /* ATG_ENGINE_SIM_THROTTLE_H */ 22 | -------------------------------------------------------------------------------- /include/throttle_display.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_THROTTLE_DISPLAY_H 2 | #define ATG_ENGINE_SIM_THROTTLE_DISPLAY_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include "engine.h" 7 | #include "geometry_generator.h" 8 | 9 | class ThrottleDisplay : public UiElement { 10 | public: 11 | ThrottleDisplay(); 12 | virtual ~ThrottleDisplay(); 13 | 14 | virtual void initialize(EngineSimApplication *app); 15 | virtual void destroy(); 16 | 17 | virtual void update(float dt); 18 | virtual void render(); 19 | 20 | Engine *m_engine; 21 | 22 | protected: 23 | void renderThrottle(const Bounds &bounds); 24 | void renderSpeedControl(const Bounds &bounds); 25 | }; 26 | 27 | #endif /* ATG_ENGINE_SIM_THROTTLE_DISPLAY_H */ 28 | -------------------------------------------------------------------------------- /include/transmission.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_TRANSMISSION_H 2 | #define ATG_ENGINE_SIM_TRANSMISSION_H 3 | 4 | #include "vehicle.h" 5 | #include "engine.h" 6 | #include "scs.h" 7 | 8 | class Transmission { 9 | public: 10 | struct Parameters { 11 | int GearCount; 12 | const double *GearRatios; 13 | double MaxClutchTorque; 14 | }; 15 | 16 | public: 17 | Transmission(); 18 | ~Transmission(); 19 | 20 | void initialize(const Parameters ¶ms); 21 | void update(double dt); 22 | void addToSystem( 23 | atg_scs::RigidBodySystem *system, 24 | atg_scs::RigidBody *rotatingMass, 25 | Vehicle *vehicle, 26 | Engine *engine); 27 | void changeGear(int newGear); 28 | inline int getGear() const { return m_gear; } 29 | inline void setClutchPressure(double pressure) { m_clutchPressure = pressure; } 30 | inline double getClutchPressure() const { return m_clutchPressure; } 31 | 32 | protected: 33 | atg_scs::ClutchConstraint m_clutchConstraint; 34 | atg_scs::RigidBody *m_rotatingMass; 35 | Vehicle *m_vehicle; 36 | 37 | int m_gear; 38 | int m_newGear; 39 | int m_gearCount; 40 | double *m_gearRatios; 41 | double m_maxClutchTorque; 42 | double m_clutchPressure; 43 | }; 44 | 45 | #endif /* ATG_ENGINE_SIM_TRANSMISSION_H */ 46 | -------------------------------------------------------------------------------- /include/turbocharger.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ATG_ENGINE_SIM_TURBOCHARGER_H 3 | #define ATG_ENGINE_SIM_TURBOCHARGER_H 4 | 5 | #include "engine.h" 6 | 7 | class TurboCharger { 8 | public: 9 | TurboCharger(); 10 | ~TurboCharger(); 11 | 12 | void process(float dt); 13 | 14 | // In mBar. 15 | double m_boost = 0.0; 16 | double m_flow = 0.0; 17 | 18 | // In mBar. 19 | double m_wastegate = 700; 20 | 21 | inline void SetEngine(Engine* engine) { m_engine = engine; }; 22 | inline double GetRotorRPM() { return m_rotorRPM; }; 23 | 24 | private: 25 | double m_rotorRPM = 0.0; 26 | 27 | // ? 28 | double m_flowMultiplier = 100.0; 29 | double m_rpmDown = 50; 30 | // Engine RPM 31 | double m_erpmToFlow = 100.0; 32 | // Turbo RPM 33 | double m_rpmToPressure = 0.01; 34 | double m_rpmToFlow = 0.1; 35 | 36 | /* 37 | turbo_flow_mult = 10000 38 | turbo_down = 0.05 39 | 40 | turbo_to_press = 5 41 | turbo_press_to_flow = 5000 42 | turbo_rpm_to_flow = 10000 43 | */ 44 | 45 | Engine* m_engine; 46 | }; 47 | 48 | #endif /* ATG_ENGINE_SIM_TURBOCHARGER_H */ 49 | -------------------------------------------------------------------------------- /include/ui_button.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_UI_BUTTON_H 2 | #define ATG_ENGINE_SIM_UI_BUTTON_H 3 | 4 | #include "ui_element.h" 5 | 6 | class UiButton : public UiElement { 7 | public: 8 | UiButton(); 9 | virtual ~UiButton(); 10 | 11 | virtual void update(float dt); 12 | virtual void render(); 13 | 14 | std::string m_text; 15 | float m_fontSize; 16 | }; 17 | 18 | #endif /* ATG_ENGINE_SIM_UI_BUTTON_H */ 19 | -------------------------------------------------------------------------------- /include/ui_manager.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_UI_MANAGER_H 2 | #define ATG_ENGINE_SIM_UI_MANAGER_H 3 | 4 | #include "ui_element.h" 5 | 6 | #include 7 | 8 | class EngineSimApplication; 9 | class UiManager { 10 | public: 11 | UiManager(); 12 | ~UiManager(); 13 | 14 | void initialize(EngineSimApplication *app); 15 | void destroy(); 16 | 17 | void update(float dt); 18 | void render(); 19 | 20 | UiElement *getRoot() { return &m_root; } 21 | 22 | protected: 23 | UiElement m_root; 24 | 25 | UiElement *m_dragStart; 26 | UiElement *m_hover; 27 | Point m_mouse_p0; 28 | Point m_drag_p0; 29 | 30 | int m_lastMouseScroll; 31 | 32 | protected: 33 | EngineSimApplication *m_app; 34 | }; 35 | 36 | #endif /* ATG_ENGINE_SIM_UI_MANAGER_H */ 37 | -------------------------------------------------------------------------------- /include/ui_utilities.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_UI_UTILITIES_H 2 | #define ATG_ENGINE_SIM_UI_UTILITIES_H 3 | 4 | #include "delta.h" 5 | 6 | ysVector mix(const ysVector &c1, const ysVector &c2, float s); 7 | 8 | #endif /* ATG_ENGINE_SIM_UI_UTILITIES_H */ 9 | -------------------------------------------------------------------------------- /include/utilities.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_UTILITIES_H 2 | #define ATG_ENGINE_SIM_UTILITIES_H 3 | 4 | double modularDistance(double a, double b, double mod = 1.0); 5 | double positiveMod(double x, double mod); 6 | double erfApproximation(double x); 7 | 8 | template 9 | inline t clamp(t x, t x0 = static_cast(0.0), t x1 = static_cast(1.0)) { 10 | if (x <= x0) return x0; 11 | else if (x >= x1) return x1; 12 | else return x; 13 | } 14 | 15 | #endif /* ATG_ENGINE_SIM_UTILITIES_H */ 16 | -------------------------------------------------------------------------------- /include/valvetrain.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_VALVETRAIN_H 2 | #define ATG_ENGINE_SIM_VALVETRAIN_H 3 | 4 | class Camshaft; 5 | class Valvetrain { 6 | public: 7 | Valvetrain(); 8 | virtual ~Valvetrain(); 9 | 10 | virtual double intakeValveLift(int cylinder) = 0; 11 | virtual double exhaustValveLift(int cylinder) = 0; 12 | 13 | virtual Camshaft *getActiveIntakeCamshaft() = 0; 14 | virtual Camshaft *getActiveExhaustCamshaft() = 0; 15 | 16 | bool m_vtecEnabled = false; 17 | float m_vtecPct = 0.0f; 18 | }; 19 | 20 | #endif /* ATG_ENGINE_SIM_VALVETRAIN_H */ 21 | -------------------------------------------------------------------------------- /include/vehicle.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_VEHICLE_H 2 | #define ATG_ENGINE_SIM_VEHICLE_H 3 | 4 | #include "scs.h" 5 | 6 | class Vehicle { 7 | public: 8 | struct Parameters { 9 | double mass; 10 | double dragCoefficient; 11 | double crossSectionArea; 12 | double diffRatio; 13 | double tireRadius; 14 | double rollingResistance; 15 | }; 16 | 17 | public: 18 | Vehicle(); 19 | ~Vehicle(); 20 | 21 | void initialize(const Parameters ¶ms); 22 | void update(double dt); 23 | void addToSystem(atg_scs::RigidBodySystem *system, atg_scs::RigidBody *rotatingMass); 24 | inline double getMass() const { return m_mass; } 25 | inline double getRollingResistance() const { return m_rollingResistance; } 26 | inline double getDragCoefficient() const { return m_dragCoefficient; } 27 | inline double getCrossSectionArea() const { return m_crossSectionArea; } 28 | inline double getDiffRatio() const { return m_diffRatio; } 29 | inline double getTireRadius() const { return m_tireRadius; } 30 | double getSpeed() const; 31 | inline double getTravelledDistance() const { return m_travelledDistance; } 32 | inline void resetTravelledDistance() { m_travelledDistance = 0; } 33 | double linearForceToVirtualTorque(double force) const; 34 | 35 | protected: 36 | atg_scs::RigidBody *m_rotatingMass; 37 | 38 | double m_mass; 39 | double m_dragCoefficient; 40 | double m_crossSectionArea; 41 | double m_diffRatio; 42 | double m_tireRadius; 43 | double m_travelledDistance; 44 | double m_rollingResistance; 45 | }; 46 | 47 | #endif /* ATG_ENGINE_SIM_VEHICLE_H */ 48 | -------------------------------------------------------------------------------- /include/vehicle_drag_constraint.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_VEHICLE_DRAG_CONSTRAINT_H 2 | #define ATG_ENGINE_SIM_VEHICLE_DRAG_CONSTRAINT_H 3 | 4 | #include "scs.h" 5 | 6 | class Vehicle; 7 | class VehicleDragConstraint : public atg_scs::Constraint { 8 | public: 9 | VehicleDragConstraint(); 10 | virtual ~VehicleDragConstraint(); 11 | 12 | void initialize(atg_scs::RigidBody *rotatingMass, Vehicle *vehicle); 13 | 14 | virtual void calculate(Output *output, atg_scs::SystemState *system); 15 | 16 | double m_ks; 17 | double m_kd; 18 | 19 | private: 20 | Vehicle *m_vehicle; 21 | }; 22 | 23 | #endif /* ATG_ENGINE_SIM_VEHICLE_DRAG_CONSTRAINT_H */ 24 | -------------------------------------------------------------------------------- /include/vtec_valvetrain.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_VTEC_STANDARD_VALVETRAIN_H 2 | #define ATG_ENGINE_SIM_VTEC_STANDARD_VALVETRAIN_H 3 | 4 | #include "valvetrain.h" 5 | 6 | class Engine; 7 | class VtecValvetrain : public Valvetrain { 8 | public: 9 | struct Parameters { 10 | double minRpm; 11 | double minSpeed; 12 | double manifoldVacuum; 13 | double minThrottlePosition; 14 | 15 | Camshaft *intakeCamshaft; 16 | Camshaft *exhaustCamshaft; 17 | 18 | Camshaft *vtecIntakeCamshaft; 19 | Camshaft *vtexExhaustCamshaft; 20 | 21 | Engine *engine; 22 | }; 23 | 24 | public: 25 | VtecValvetrain(); 26 | virtual ~VtecValvetrain(); 27 | 28 | void initialize(const Parameters ¶meters); 29 | 30 | virtual double intakeValveLift(int cylinder) override; 31 | virtual double exhaustValveLift(int cylinder) override; 32 | 33 | virtual Camshaft *getActiveIntakeCamshaft() override; 34 | virtual Camshaft *getActiveExhaustCamshaft() override; 35 | 36 | private: 37 | bool isVtecEnabled() const; 38 | 39 | Camshaft *m_intakeCamshaft; 40 | Camshaft *m_exhaustCamshaft; 41 | 42 | Camshaft *m_vtecIntakeCamshaft; 43 | Camshaft *m_vtecExhaustCamshaft; 44 | 45 | Engine *m_engine; 46 | 47 | double m_minRpm; 48 | double m_minSpeed; 49 | double m_manifoldVacuum; 50 | double m_minThrottlePosition; 51 | Camshaft* c; 52 | Camshaft* c2; 53 | }; 54 | 55 | #endif /* ATG_ENGINE_SIM_VTEC_STANDARD_VALVETRAIN_H */ 56 | -------------------------------------------------------------------------------- /scripting/include/camshaft_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_CAMSHAFT_NODE_H 2 | #define ATG_ENGINE_SIM_CAMSHAFT_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "engine_context.h" 7 | #include "function_node.h" 8 | 9 | #include "engine_sim.h" 10 | 11 | #include 12 | #include 13 | 14 | namespace es_script { 15 | 16 | class CamshaftNode : public ObjectReferenceNode { 17 | public: 18 | CamshaftNode() { /* void */ } 19 | virtual ~CamshaftNode() { /* void */ } 20 | 21 | void generate( 22 | Camshaft *camshaft, 23 | Crankshaft *crankshaft, 24 | EngineContext *context) const 25 | { 26 | Camshaft::Parameters parameters = m_parameters; 27 | parameters.crankshaft = crankshaft; 28 | parameters.lobes = (int)m_lobes.size(); 29 | parameters.lobeProfile = m_lobeProfile->generate(context); 30 | 31 | camshaft->initialize(parameters); 32 | 33 | for (int i = 0; i < parameters.lobes; ++i) { 34 | camshaft->setLobeCenterline(i, m_lobes[i]); 35 | } 36 | } 37 | 38 | void addLobe(double lobeCenterline) { 39 | m_lobes.push_back(lobeCenterline); 40 | } 41 | 42 | protected: 43 | virtual void registerInputs() { 44 | addInput("advance", &m_parameters.advance); 45 | addInput("base_radius", &m_parameters.baseRadius); 46 | addInput("lobe_profile", &m_lobeProfile); 47 | 48 | ObjectReferenceNode::registerInputs(); 49 | } 50 | 51 | virtual void _evaluate() { 52 | setOutput(this); 53 | 54 | // Read inputs 55 | readAllInputs(); 56 | 57 | m_parameters.crankshaft = nullptr; 58 | } 59 | 60 | Camshaft::Parameters m_parameters; 61 | FunctionNode *m_lobeProfile = nullptr; 62 | std::vector m_lobes; 63 | }; 64 | 65 | } /* namespace es_script */ 66 | 67 | #endif /* ATG_ENGINE_SIM_CAMSHAFT_NODE_H */ 68 | -------------------------------------------------------------------------------- /scripting/include/compiler.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_COMPILER_H 2 | #define ATG_ENGINE_SIM_COMPILER_H 3 | 4 | #include "language_rules.h" 5 | 6 | #include "engine_sim.h" 7 | #include "piranha.h" 8 | 9 | #include 10 | 11 | namespace es_script { 12 | 13 | class Compiler { 14 | public: 15 | struct Output { 16 | Engine *engine = nullptr; 17 | Vehicle *vehicle = nullptr; 18 | Transmission *transmission = nullptr; 19 | Simulator::Parameters simulatorParameters; 20 | ApplicationSettings applicationSettings; 21 | 22 | std::vector functions; 23 | }; 24 | 25 | private: 26 | static Output *s_output; 27 | 28 | public: 29 | Compiler(); 30 | ~Compiler(); 31 | 32 | static Output *output(); 33 | 34 | void initialize(); 35 | bool compile(const piranha::IrPath &path); 36 | Output execute(); 37 | void destroy(); 38 | 39 | private: 40 | void printError(const piranha::CompilationError *err, std::ofstream &file) const; 41 | 42 | private: 43 | LanguageRules m_rules; 44 | piranha::Compiler *m_compiler; 45 | piranha::NodeProgram m_program; 46 | }; 47 | 48 | } /* namespace es_script */ 49 | 50 | #endif /* ATG_ENGINE_SIM_COMPILER_H */ -------------------------------------------------------------------------------- /scripting/include/engine_sim.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_ENGINE_SIM_H 2 | #define ATG_ENGINE_SIM_ENGINE_SIM_H 3 | 4 | #include "../../include/engine.h" 5 | #include "../../include/crankshaft.h" 6 | #include "../../include/connecting_rod.h" 7 | #include "../../include/cylinder_bank.h" 8 | #include "../../include/piston.h" 9 | #include "../../include/function.h" 10 | #include "../../include/vehicle.h" 11 | #include "../../include/transmission.h" 12 | #include "../../include/simulator.h" 13 | #include "../../include/fuel.h" 14 | #include "../../include/impulse_response.h" 15 | #include "../../include/standard_valvetrain.h" 16 | #include "../../include/vtec_valvetrain.h" 17 | #include "../../include/application_settings.h" 18 | #include "../../include/throttle.h" 19 | #include "../../include/direct_throttle_linkage.h" 20 | #include "../../include/governor.h" 21 | 22 | #endif /* ATG_ENGINE_SIM_ENGINE_SIM_H */ -------------------------------------------------------------------------------- /scripting/include/exhaust_system_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_EXHAUST_SYSTEM_NODE_H 2 | #define ATG_ENGINE_SIM_EXHAUST_SYSTEM_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "engine_context.h" 7 | #include "impulse_response_node.h" 8 | 9 | #include "engine_sim.h" 10 | 11 | namespace es_script { 12 | 13 | class ExhaustSystemNode : public ObjectReferenceNode { 14 | public: 15 | ExhaustSystemNode() { /* void */ } 16 | virtual ~ExhaustSystemNode() { /* void */ } 17 | 18 | ExhaustSystem *generate(EngineContext *context) { 19 | ExhaustSystem *exhaust = context->getExhaust(this); 20 | ExhaustSystem::Parameters parameters = m_parameters; 21 | parameters.impulseResponse = m_impulseResponse->generate(context); 22 | 23 | exhaust->initialize(parameters); 24 | 25 | return exhaust; 26 | } 27 | 28 | protected: 29 | virtual void registerInputs() { 30 | addInput("length", &m_parameters.length); 31 | addInput("collector_cross_section_area", &m_parameters.collectorCrossSectionArea); 32 | addInput("outlet_flow_rate", &m_parameters.outletFlowRate); 33 | addInput("primary_tube_length", &m_parameters.primaryTubeLength); 34 | addInput("primary_flow_rate", &m_parameters.primaryFlowRate); 35 | addInput("audio_volume", &m_parameters.audioVolume); 36 | addInput("velocity_decay", &m_parameters.velocityDecay); 37 | addInput("impulse_response", &m_impulseResponse, InputTarget::Type::Object); 38 | 39 | ObjectReferenceNode::registerInputs(); 40 | } 41 | 42 | virtual void _evaluate() { 43 | setOutput(this); 44 | 45 | // Read inputs 46 | readAllInputs(); 47 | } 48 | 49 | ImpulseResponseNode *m_impulseResponse = nullptr; 50 | ExhaustSystem::Parameters m_parameters; 51 | }; 52 | 53 | } /* namespace es_script */ 54 | 55 | #endif /* ATG_ENGINE_SIM_EXHAUST_SYSTEM_NODE_H */ 56 | -------------------------------------------------------------------------------- /scripting/include/fuel_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_FUEL_NODE_H 2 | #define ATG_ENGINE_SIM_FUEL_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "engine_context.h" 7 | #include "function_node.h" 8 | 9 | #include "engine_sim.h" 10 | 11 | #include 12 | #include 13 | 14 | namespace es_script { 15 | 16 | class FuelNode : public ObjectReferenceNode { 17 | public: 18 | FuelNode() { /* void */ } 19 | virtual ~FuelNode() { /* void */ } 20 | 21 | void generate(Fuel *fuel, EngineContext *context) const { 22 | Fuel::Parameters params = m_parameters; 23 | params.turbulenceToFlameSpeedRatio = 24 | m_turbulenceToFlameSpeedRatio->generate(context); 25 | 26 | fuel->initialize(params); 27 | } 28 | 29 | protected: 30 | virtual void registerInputs() { 31 | addInput( 32 | "turbulence_to_flame_speed_ratio", 33 | &m_turbulenceToFlameSpeedRatio, 34 | InputTarget::Type::Object); 35 | addInput("name", &m_parameters.name); 36 | addInput("molecular_mass", &m_parameters.molecularMass); 37 | addInput("energy_density", &m_parameters.energyDensity); 38 | addInput("density", &m_parameters.density); 39 | addInput("molecular_afr", &m_parameters.molecularAfr); 40 | addInput("max_burning_efficiency", &m_parameters.maxBurningEfficiency); 41 | addInput("burning_efficiency_randomness", &m_parameters.burningEfficiencyRandomness); 42 | addInput("low_efficiency_attenuation", &m_parameters.lowEfficiencyAttenuation); 43 | addInput("max_turbulence_effect", &m_parameters.maxTurbulenceEffect); 44 | addInput("max_dilution_effect", &m_parameters.maxDilutionEffect); 45 | 46 | ObjectReferenceNode::registerInputs(); 47 | } 48 | 49 | virtual void _evaluate() { 50 | setOutput(this); 51 | 52 | // Read inputs 53 | readAllInputs(); 54 | } 55 | 56 | FunctionNode *m_turbulenceToFlameSpeedRatio = nullptr; 57 | Fuel::Parameters m_parameters; 58 | }; 59 | 60 | } /* namespace es_script */ 61 | 62 | #endif /* ATG_ENGINE_SIM_FUEL_NODE_H */ 63 | -------------------------------------------------------------------------------- /scripting/include/function_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_FUNCTION_NODE_H 2 | #define ATG_ENGINE_SIM_FUNCTION_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "engine_context.h" 7 | 8 | #include "engine_sim.h" 9 | 10 | namespace es_script { 11 | 12 | class FunctionNode : public ObjectReferenceNode { 13 | public: 14 | struct Sample { 15 | double x, y; 16 | }; 17 | 18 | public: 19 | FunctionNode() { /* void */ } 20 | virtual ~FunctionNode() { /* void */ } 21 | 22 | void addSample(double x, double y) { 23 | m_samples.push_back({ x, y }); 24 | } 25 | 26 | void setFilterRadius(double filterRadius) { 27 | m_filterRadius = filterRadius; 28 | } 29 | 30 | virtual Function *generate(EngineContext *context) { 31 | Function *existingFunction = context->getFunction(this); 32 | if (existingFunction != nullptr) { 33 | return existingFunction; 34 | } 35 | else { 36 | Function *function = new Function; 37 | function->initialize((int)m_samples.size(), m_filterRadius); 38 | 39 | for (const Sample &sample : m_samples) { 40 | function->addSample(sample.x, sample.y); 41 | } 42 | 43 | context->addFunction(this, function); 44 | return function; 45 | } 46 | } 47 | 48 | protected: 49 | virtual void registerInputs() { 50 | addInput("filter_radius", &m_filterRadius); 51 | 52 | ObjectReferenceNode::registerInputs(); 53 | } 54 | 55 | virtual void _evaluate() { 56 | setOutput(this); 57 | 58 | // Read inputs 59 | readAllInputs(); 60 | } 61 | 62 | std::vector m_samples; 63 | double m_filterRadius = 0.0; 64 | }; 65 | 66 | } /* namespace es_script */ 67 | 68 | #endif /* ATG_ENGINE_SIM_FUNCTION_NODE_H */ 69 | -------------------------------------------------------------------------------- /scripting/include/ignition_wire_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_IGNITION_WIRE_NODE_H 2 | #define ATG_ENGINE_SIM_IGNITION_WIRE_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "engine_context.h" 7 | #include "function_node.h" 8 | 9 | #include "engine_sim.h" 10 | 11 | #include 12 | 13 | namespace es_script { 14 | 15 | class IgnitionWireNode : public ObjectReferenceNode { 16 | public: 17 | using Connection = std::pair; 18 | 19 | public: 20 | IgnitionWireNode() { /* void */ } 21 | virtual ~IgnitionWireNode() { /* void */ } 22 | 23 | void connect(CylinderBankNode *bank, int i) { 24 | m_connections.insert({ bank, i }); 25 | } 26 | 27 | std::set getConnections() const { 28 | return m_connections; 29 | } 30 | 31 | protected: 32 | virtual void registerInputs() { 33 | ObjectReferenceNode::registerInputs(); 34 | } 35 | 36 | virtual void _evaluate() { 37 | setOutput(this); 38 | } 39 | 40 | std::set m_connections; 41 | }; 42 | 43 | } /* namespace es_script */ 44 | 45 | #endif /* ATG_ENGINE_SIM_IGNITION_WIRE_NODE_H */ 46 | -------------------------------------------------------------------------------- /scripting/include/impulse_response_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_IMPULSE_RESPONSE_NODE_H 2 | #define ATG_ENGINE_SIM_IMPULSE_RESPONSE_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "engine_context.h" 7 | #include "impulse_response_node.h" 8 | 9 | #include "engine_sim.h" 10 | 11 | #include 12 | #include 13 | 14 | namespace es_script { 15 | 16 | class ImpulseResponseNode 17 | : public ObjectReferenceNode { 18 | public: 19 | ImpulseResponseNode() { /* void */ } 20 | virtual ~ImpulseResponseNode() { /* void */ } 21 | 22 | ImpulseResponse *generate(EngineContext *context) { 23 | ImpulseResponse *existingIr = context->getImpulseResponse(this); 24 | if (existingIr != nullptr) { 25 | return existingIr; 26 | } 27 | else { 28 | piranha::Path path = m_filename; 29 | piranha::Path parentPath; 30 | m_irStructure->getParentUnit()->getPath().getParentPath(&parentPath); 31 | if (!path.isAbsolute()) { 32 | path = parentPath.append(path); 33 | } 34 | 35 | ImpulseResponse *impulseResponse = new ImpulseResponse; 36 | impulseResponse->initialize( 37 | path.toString(), 38 | m_volume); 39 | 40 | return impulseResponse; 41 | } 42 | } 43 | 44 | protected: 45 | virtual void registerInputs() { 46 | addInput("filename", &m_filename); 47 | addInput("volume", &m_volume); 48 | 49 | ObjectReferenceNode::registerInputs(); 50 | } 51 | 52 | virtual void _evaluate() { 53 | setOutput(this); 54 | 55 | // Read inputs 56 | readAllInputs(); 57 | } 58 | 59 | std::string m_filename = ""; 60 | double m_volume = 1.0; 61 | }; 62 | 63 | } /* namespace es_script */ 64 | 65 | #endif /* ATG_ENGINE_SIM_IMPULSE_RESPONSE_NODE_H */ 66 | -------------------------------------------------------------------------------- /scripting/include/intake_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_INTAKE_NODE_H 2 | #define ATG_ENGINE_SIM_INTAKE_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "engine_context.h" 7 | #include "function_node.h" 8 | 9 | #include "engine_sim.h" 10 | 11 | #include 12 | #include 13 | 14 | namespace es_script { 15 | 16 | class IntakeNode : public ObjectReferenceNode { 17 | public: 18 | IntakeNode() { /* void */ } 19 | virtual ~IntakeNode() { /* void */ } 20 | 21 | Intake *generate(EngineContext *context) { 22 | Intake *intake = context->getIntake(this); 23 | Intake::Parameters parameters = m_parameters; 24 | intake->initialize(parameters); 25 | 26 | return intake; 27 | } 28 | 29 | protected: 30 | virtual void registerInputs() { 31 | addInput("plenum_volume", &m_parameters.volume); 32 | addInput("plenum_cross_section_area", &m_parameters.CrossSectionArea); 33 | addInput("intake_flow_rate", &m_parameters.InputFlowK); 34 | addInput("idle_flow_rate", &m_parameters.IdleFlowK); 35 | addInput("runner_flow_rate", &m_parameters.RunnerFlowRate); 36 | addInput("molecular_afr", &m_parameters.MolecularAfr); 37 | addInput("idle_throttle_plate_position", &m_parameters.IdleThrottlePlatePosition); 38 | addInput("throttle_gamma", &m_throttleGammaUnused); 39 | addInput("runner_length", &m_parameters.RunnerLength); 40 | addInput("velocity_decay", &m_parameters.VelocityDecay); 41 | 42 | ObjectReferenceNode::registerInputs(); 43 | } 44 | 45 | virtual void _evaluate() { 46 | setOutput(this); 47 | 48 | // Read inputs 49 | readAllInputs(); 50 | } 51 | 52 | double m_throttleGammaUnused = 0.0; // Deprecated; to be removed in a future release 53 | Intake::Parameters m_parameters; 54 | }; 55 | 56 | } /* namespace es_script */ 57 | 58 | #endif /* ATG_ENGINE_SIM_INTAKE_NODE_H */ 59 | -------------------------------------------------------------------------------- /scripting/include/language_rules.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_LANGUAGE_RULES_H 2 | #define ATG_ENGINE_SIM_LANGUAGE_RULES_H 3 | 4 | #include "piranha.h" 5 | 6 | namespace es_script { 7 | 8 | class LanguageRules : public piranha::LanguageRules { 9 | public: 10 | LanguageRules(); 11 | ~LanguageRules(); 12 | 13 | protected: 14 | virtual void registerBuiltinNodeTypes(); 15 | }; 16 | 17 | } /* namespace es_script */ 18 | 19 | #endif /* ATG_ENGINE_SIM_LANGUAGE_RULES_H */ 20 | -------------------------------------------------------------------------------- /scripting/include/node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_NODE_H 2 | #define ATG_ENGINE_SIM_NODE_H 3 | 4 | #include "piranha.h" 5 | 6 | #include 7 | #include 8 | 9 | namespace es_script { 10 | 11 | class Node : public piranha::Node { 12 | protected: 13 | struct InputTarget { 14 | enum class Type { 15 | Object, 16 | Atomic 17 | }; 18 | 19 | piranha::pNodeInput *input = nullptr; 20 | void *memoryTarget = nullptr; 21 | Type type = Type::Atomic; 22 | }; 23 | 24 | public: 25 | Node() { 26 | /* void */ 27 | } 28 | 29 | virtual ~Node() { 30 | for (auto i : m_inputMap) { 31 | delete i.second.input; 32 | } 33 | } 34 | 35 | template 36 | T_Out readAtomicInput(const std::string &name) { 37 | T_Out out; 38 | (*m_inputMap[name].input)->fullCompute(&out); 39 | 40 | return out; 41 | } 42 | 43 | void readAllInputs() { 44 | for (auto i : m_inputMap) { 45 | if (i.second.type == InputTarget::Type::Atomic 46 | || i.second.type == InputTarget::Type::Object) 47 | { 48 | (*m_inputMap[i.first].input)->fullCompute(i.second.memoryTarget); 49 | } 50 | } 51 | } 52 | 53 | void addInput( 54 | const std::string &name, 55 | void *target, 56 | InputTarget::Type type = InputTarget::Type::Atomic) 57 | { 58 | m_inputMap[name] = { 59 | new piranha::pNodeInput, 60 | target, 61 | type 62 | }; 63 | } 64 | 65 | virtual void registerInputs() { 66 | for (auto i : m_inputMap) { 67 | registerInput(i.second.input, i.first); 68 | } 69 | } 70 | 71 | private: 72 | std::map m_inputMap; 73 | }; 74 | 75 | } /* namespace es_script */ 76 | 77 | #endif /* ATG_ENGINE_SIM_NODE_H */ 78 | -------------------------------------------------------------------------------- /scripting/include/object_reference_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_OBJECT_REFERENCE_H 2 | #define ATG_ENGINE_SIM_OBJECT_REFERENCE_H 3 | 4 | #include "node.h" 5 | 6 | #include "object_reference_node_output.h" 7 | 8 | namespace es_script { 9 | 10 | template 11 | class ObjectReferenceNode : public Node { 12 | public: 13 | ObjectReferenceNode() { 14 | /* void */ 15 | } 16 | 17 | ~ObjectReferenceNode() { 18 | /* void */ 19 | } 20 | 21 | template 22 | void overrideType() { 23 | m_output.overrideType(LookupChannelType()); 24 | } 25 | 26 | protected: 27 | virtual void registerOutputs() { 28 | setPrimaryOutput("__out"); 29 | registerOutput(&m_output, "__out"); 30 | } 31 | 32 | virtual void _evaluate() { 33 | m_output.setReference(nullptr); 34 | } 35 | 36 | void setOutput(Type *output) { m_output.setReference(output); } 37 | 38 | ObjectReferenceNodeOutput m_output; 39 | }; 40 | 41 | template 42 | using NullReferenceNode = ObjectReferenceNode; 43 | 44 | } /* namespace manta */ 45 | 46 | #endif /* ATG_ENGINE_SIM_OBJECT_REFERENCE_H */ 47 | -------------------------------------------------------------------------------- /scripting/include/object_reference_node_output.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_OBJECT_REFERENCE_NODE_OUTPUT_H 2 | #define ATG_ENGINE_SIM_OBJECT_REFERENCE_NODE_OUTPUT_H 3 | 4 | #include "piranha.h" 5 | 6 | #include "channel_types.h" 7 | 8 | namespace es_script { 9 | 10 | template 11 | class ObjectReferenceNodeOutput : public piranha::NodeOutput { 12 | public: 13 | ObjectReferenceNodeOutput() : NodeOutput(LookupChannelType()) { 14 | m_data = nullptr; 15 | } 16 | 17 | virtual ~ObjectReferenceNodeOutput() { 18 | /* void */ 19 | } 20 | 21 | virtual void fullCompute(void *target) const { 22 | *reinterpret_cast(target) = m_data; 23 | } 24 | 25 | Type *getReference() const { return m_data; } 26 | void setReference(Type *data) { m_data = data; } 27 | 28 | protected: 29 | Type *m_data; 30 | }; 31 | 32 | template 33 | Type *getObject(piranha::pNodeInput input) { 34 | return static_cast *>(input)->getReference(); 35 | } 36 | 37 | } /* namespace manta */ 38 | 39 | #endif /* ATG_ENGINE_SIM_OBJECT_REFERENCE_NODE_OUTPUT_H */ 40 | -------------------------------------------------------------------------------- /scripting/include/piranha.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_PIRANHA_H 2 | #define ATG_ENGINE_SIM_PIRANHA_H 3 | 4 | #include 5 | 6 | #endif /* ATG_ENGINE_SIM_PIRANHA_H */ 7 | -------------------------------------------------------------------------------- /scripting/include/piston_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_PISTON_NODE_H 2 | #define ATG_ENGINE_SIM_PISTON_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "rod_journal_node.h" 7 | #include "piston_node.h" 8 | 9 | #include "engine_sim.h" 10 | 11 | #include 12 | #include 13 | 14 | namespace es_script { 15 | 16 | class PistonNode : public ObjectReferenceNode { 17 | public: 18 | PistonNode() { /* void */ } 19 | virtual ~PistonNode() { /* void */ } 20 | 21 | void generate( 22 | Piston *piston, 23 | ConnectingRod *rod, 24 | CylinderBank *cylinderBank, 25 | int cylinderIndex) const 26 | { 27 | Piston::Parameters params = m_parameters; 28 | params.Bank = cylinderBank; 29 | params.CylinderIndex = cylinderIndex; 30 | params.Rod = rod; 31 | 32 | piston->initialize(params); 33 | } 34 | 35 | protected: 36 | virtual void registerInputs() { 37 | addInput("mass", &m_parameters.mass); 38 | addInput("blowby", &m_parameters.BlowbyFlowCoefficient); 39 | addInput("compression_height", &m_parameters.CompressionHeight); 40 | addInput("wrist_pin_position", &m_parameters.WristPinPosition); 41 | addInput("displacement", &m_parameters.Displacement); 42 | 43 | ObjectReferenceNode::registerInputs(); 44 | } 45 | 46 | virtual void _evaluate() { 47 | setOutput(this); 48 | 49 | // Read inputs 50 | readAllInputs(); 51 | 52 | m_parameters.Bank = nullptr; 53 | m_parameters.Rod = nullptr; 54 | m_parameters.CylinderIndex = 0; 55 | } 56 | 57 | Piston::Parameters m_parameters; 58 | }; 59 | 60 | } /* namespace es_script */ 61 | 62 | #endif /* ATG_ENGINE_SIM_PISTON_NODE_H */ 63 | -------------------------------------------------------------------------------- /scripting/include/rod_journal_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_ROD_JOURNAL_NODE_H 2 | #define ATG_ENGINE_SIM_ROD_JOURNAL_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "engine_sim.h" 7 | 8 | #include 9 | 10 | namespace es_script { 11 | 12 | class CrankshaftNode; 13 | class ConnectingRodNode; 14 | class RodJournalNode : public ObjectReferenceNode { 15 | friend CrankshaftNode; 16 | friend ConnectingRodNode; 17 | 18 | public: 19 | RodJournalNode() { /* void */ } 20 | virtual ~RodJournalNode() { /* void */ } 21 | 22 | double getAngle() const { 23 | return m_angle; 24 | } 25 | 26 | CrankshaftNode *getCrankshaft() const { 27 | return m_crankshaft; 28 | } 29 | 30 | ConnectingRodNode *getRod() const { 31 | return m_rod; 32 | } 33 | 34 | protected: 35 | virtual void registerInputs() { 36 | addInput("angle", &m_angle); 37 | 38 | ObjectReferenceNode::registerInputs(); 39 | } 40 | 41 | virtual void _evaluate() { 42 | setOutput(this); 43 | 44 | // Read inputs 45 | readAllInputs(); 46 | } 47 | 48 | CrankshaftNode *m_crankshaft = nullptr; 49 | ConnectingRodNode *m_rod = nullptr; 50 | double m_angle = 0.0; 51 | }; 52 | 53 | } /* namespace es_script */ 54 | 55 | #endif /* ATG_ENGINE_SIM_ROD_JOURNAL_NODE_H */ 56 | -------------------------------------------------------------------------------- /scripting/include/standard_valvetrain_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_STANDARD_VALVETRAIN_NODE_H 2 | #define ATG_ENGINE_SIM_STANDARD_VALVETRAIN_NODE_H 3 | 4 | #include "valvetrain_node.h" 5 | 6 | #include "camshaft_node.h" 7 | 8 | #include "engine_sim.h" 9 | 10 | namespace es_script { 11 | 12 | class StandardValvetrainNode : public ValvetrainNode { 13 | public: 14 | StandardValvetrainNode() { /* void */ } 15 | virtual ~StandardValvetrainNode() { /* void */ } 16 | 17 | virtual Valvetrain *generate( 18 | EngineContext *context, 19 | Crankshaft *crank) override 20 | { 21 | StandardValvetrain *valvetrain = new StandardValvetrain; 22 | 23 | Camshaft 24 | *intakeCam = new Camshaft(), 25 | *exhaustCam = new Camshaft(); 26 | 27 | m_intakeCamshaft->generate(intakeCam, crank, context); 28 | m_exhaustCamshaft->generate(exhaustCam, crank, context); 29 | 30 | StandardValvetrain::Parameters params; 31 | params.intakeCamshaft = intakeCam; 32 | params.exhaustCamshaft = exhaustCam; 33 | valvetrain->initialize(params); 34 | 35 | return valvetrain; 36 | } 37 | 38 | protected: 39 | virtual void registerInputs() { 40 | addInput("intake_camshaft", &m_intakeCamshaft, InputTarget::Type::Object); 41 | addInput("exhaust_camshaft", &m_exhaustCamshaft, InputTarget::Type::Object); 42 | 43 | ValvetrainNode::registerInputs(); 44 | } 45 | 46 | private: 47 | CamshaftNode *m_intakeCamshaft = nullptr; 48 | CamshaftNode *m_exhaustCamshaft = nullptr; 49 | }; 50 | 51 | } /* namespace es_script */ 52 | 53 | #endif /* ATG_ENGINE_SIM_STANDARD_VALVETRAIN_NODE_H */ 54 | -------------------------------------------------------------------------------- /scripting/include/transmission_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_TRANSMISSION_NODE_H 2 | #define ATG_ENGINE_SIM_TRANSMISSION_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "engine_sim.h" 7 | 8 | #include 9 | 10 | namespace es_script { 11 | 12 | class TransmissionNode : public ObjectReferenceNode { 13 | public: 14 | TransmissionNode() { /* void */ } 15 | virtual ~TransmissionNode() { /* void */ } 16 | 17 | void generate(Transmission *transmission) const { 18 | Transmission::Parameters parameters = m_parameters; 19 | parameters.GearCount = static_cast(m_gears.size()); 20 | parameters.GearRatios = m_gears.data(); 21 | 22 | transmission->initialize(parameters); 23 | } 24 | 25 | void addGear(double ratio) { 26 | m_gears.push_back(ratio); 27 | } 28 | 29 | protected: 30 | virtual void registerInputs() { 31 | addInput("max_clutch_torque", &m_parameters.MaxClutchTorque); 32 | 33 | ObjectReferenceNode::registerInputs(); 34 | } 35 | 36 | virtual void _evaluate() { 37 | setOutput(this); 38 | 39 | // Read inputs 40 | readAllInputs(); 41 | } 42 | 43 | Transmission::Parameters m_parameters; 44 | std::vector m_gears; 45 | }; 46 | 47 | } /* namespace es_script */ 48 | 49 | #endif /* ATG_ENGINE_SIM_TRANSMISSION_NODE_H */ 50 | -------------------------------------------------------------------------------- /scripting/include/valvetrain_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_VALVETRAIN_NODE_H 2 | #define ATG_ENGINE_SIM_VALVETRAIN_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "engine_context.h" 7 | 8 | namespace es_script { 9 | 10 | class ValvetrainNode : public ObjectReferenceNode { 11 | public: 12 | ValvetrainNode() { /* void */ } 13 | virtual ~ValvetrainNode() { /* void */ } 14 | 15 | virtual Valvetrain *generate(EngineContext *context, Crankshaft *crank) = 0; 16 | 17 | protected: 18 | virtual void registerInputs() { 19 | ObjectReferenceNode::registerInputs(); 20 | } 21 | 22 | virtual void _evaluate() { 23 | setOutput(this); 24 | readAllInputs(); 25 | } 26 | }; 27 | 28 | } /* namespace es_script */ 29 | 30 | #endif /* ATG_ENGINE_SIM_VALVETRAIN_NODE_H */ 31 | -------------------------------------------------------------------------------- /scripting/include/vehicle_node.h: -------------------------------------------------------------------------------- 1 | #ifndef ATG_ENGINE_SIM_VEHICLE_NODE_H 2 | #define ATG_ENGINE_SIM_VEHICLE_NODE_H 3 | 4 | #include "object_reference_node.h" 5 | 6 | #include "engine_sim.h" 7 | 8 | namespace es_script { 9 | 10 | class VehicleNode : public ObjectReferenceNode { 11 | public: 12 | VehicleNode() { /* void */ } 13 | virtual ~VehicleNode() { /* void */ } 14 | 15 | void generate(Vehicle *vehicle) const 16 | { 17 | vehicle->initialize(m_parameters); 18 | } 19 | 20 | protected: 21 | virtual void registerInputs() { 22 | addInput("mass", &m_parameters.mass); 23 | addInput("drag_coefficient", &m_parameters.dragCoefficient); 24 | addInput("cross_sectional_area", &m_parameters.crossSectionArea); 25 | addInput("diff_ratio", &m_parameters.diffRatio); 26 | addInput("tire_radius", &m_parameters.tireRadius); 27 | addInput("rolling_resistance", &m_parameters.rollingResistance); 28 | 29 | ObjectReferenceNode::registerInputs(); 30 | } 31 | 32 | virtual void _evaluate() { 33 | setOutput(this); 34 | // Read inputs 35 | readAllInputs(); 36 | 37 | } 38 | 39 | Vehicle::Parameters m_parameters; 40 | }; 41 | 42 | } /* namespace es_script */ 43 | 44 | #endif /* ATG_ENGINE_SIM_VEHICLE_NODE_H */ 45 | -------------------------------------------------------------------------------- /scripting/src/channel_types.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/channel_types.h" 2 | 3 | #define DEFINE_CHANNEL(channel_type) const piranha::ChannelType es_script::ObjectChannel::channel_type(#channel_type); 4 | 5 | DEFINE_CHANNEL(EngineChannel); 6 | DEFINE_CHANNEL(CrankshaftChannel); 7 | DEFINE_CHANNEL(RodJournalChannel); 8 | DEFINE_CHANNEL(ConnectingRodChannel); 9 | DEFINE_CHANNEL(CylinderBankChannel); 10 | DEFINE_CHANNEL(PistonChannel); 11 | DEFINE_CHANNEL(FunctionChannel); 12 | DEFINE_CHANNEL(IntakeChannel); 13 | DEFINE_CHANNEL(ExhaustSystemChannel); 14 | DEFINE_CHANNEL(CylinderHeadChannel); 15 | DEFINE_CHANNEL(CamshaftChannel); 16 | DEFINE_CHANNEL(IgnitionModuleChannel); 17 | DEFINE_CHANNEL(IgnitionWireChannel); 18 | DEFINE_CHANNEL(FuelChannel); 19 | DEFINE_CHANNEL(ImpulseResponseChannel); 20 | DEFINE_CHANNEL(ValvetrainChannel); 21 | DEFINE_CHANNEL(VehicleChannel); 22 | DEFINE_CHANNEL(TransmissionChannel); 23 | DEFINE_CHANNEL(ThrottleChannel); 24 | -------------------------------------------------------------------------------- /src/audio_buffer.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/audio_buffer.h" 2 | 3 | #include 4 | 5 | AudioBuffer::AudioBuffer() { 6 | m_writePointer = 0; 7 | m_sampleRate = 0; 8 | m_samples = nullptr; 9 | m_bufferSize = 0; 10 | m_offsetToSeconds = 0; 11 | } 12 | 13 | AudioBuffer::~AudioBuffer() { 14 | assert(m_samples == nullptr); 15 | } 16 | 17 | void AudioBuffer::initialize(int sampleRate, int bufferSize) { 18 | m_writePointer = 0; 19 | m_sampleRate = sampleRate; 20 | m_samples = new int16_t[bufferSize]; 21 | memset(m_samples, 0, sizeof(int16_t) * bufferSize); 22 | m_bufferSize = bufferSize; 23 | m_offsetToSeconds = 1 / (double)sampleRate; 24 | } 25 | 26 | void AudioBuffer::destroy() { 27 | delete[] m_samples; 28 | 29 | m_samples = nullptr; 30 | m_bufferSize = 0; 31 | } 32 | 33 | bool AudioBuffer::checkForDiscontinuitiy(int threshold) const { 34 | for (int i = 0; i < m_bufferSize - 1; ++i) { 35 | const int i0 = getBufferIndex(i + m_writePointer); 36 | const int i1 = getBufferIndex(i0 + 1); 37 | 38 | if (std::abs(m_samples[i0] - m_samples[i1]) >= threshold) { 39 | return true; 40 | } 41 | } 42 | 43 | return false; 44 | } 45 | -------------------------------------------------------------------------------- /src/camshaft.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/camshaft.h" 2 | 3 | #include "../include/crankshaft.h" 4 | #include "../include/constants.h" 5 | #include "../include/units.h" 6 | 7 | #include 8 | #include 9 | 10 | Camshaft::Camshaft() { 11 | m_crankshaft = nullptr; 12 | m_lobeAngles = nullptr; 13 | m_lobeProfile = nullptr; 14 | m_lobes = 0; 15 | m_advance = 0; 16 | m_baseRadius = 0; 17 | } 18 | 19 | Camshaft::~Camshaft() { 20 | assert(m_lobeAngles == nullptr); 21 | } 22 | 23 | void Camshaft::initialize(const Parameters ¶ms) { 24 | m_lobeAngles = new double[params.lobes]; 25 | memset(m_lobeAngles, 0, sizeof(double) * params.lobes); 26 | 27 | m_lobes = params.lobes; 28 | m_crankshaft = params.crankshaft; 29 | m_lobeProfile = params.lobeProfile; 30 | m_advance = params.advance; 31 | m_baseRadius = params.baseRadius; 32 | } 33 | 34 | void Camshaft::destroy() { 35 | delete[] m_lobeAngles; 36 | m_lobeAngles = nullptr; 37 | 38 | m_lobes = 0; 39 | } 40 | 41 | double Camshaft::valveLift(int lobe) const { 42 | return sampleLobe(getAngle() + m_lobeAngles[lobe]); 43 | } 44 | 45 | double Camshaft::sampleLobe(double theta) const { 46 | double clampedTheta = std::fmod(theta, 2 * constants::pi); 47 | if (clampedTheta < 0) clampedTheta += 2 * constants::pi; 48 | if (clampedTheta >= constants::pi) clampedTheta -= 2 * constants::pi; 49 | 50 | return m_lobeProfile->sampleTriangle(clampedTheta); 51 | } 52 | 53 | double Camshaft::getAngle() const { 54 | const double angle = 55 | std::fmod((m_crankshaft->getAngle() + m_advance) * 0.5, 2 * constants::pi); 56 | return (angle < 0) 57 | ? angle + 2 * constants::pi 58 | : angle; 59 | } 60 | -------------------------------------------------------------------------------- /src/combustion_chamber_object.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/combustion_chamber_object.h" 2 | 3 | #include "../include/cylinder_bank.h" 4 | #include "../include/engine_sim_application.h" 5 | #include "../include/constants.h" 6 | 7 | CombustionChamberObject::CombustionChamberObject() { 8 | m_chamber = nullptr; 9 | } 10 | 11 | CombustionChamberObject::~CombustionChamberObject() { 12 | /* void */ 13 | } 14 | 15 | void CombustionChamberObject::generateGeometry() { 16 | GeometryGenerator *gen = m_app->getGeometryGenerator(); 17 | CylinderHead *head = m_chamber->getCylinderHead(); 18 | CylinderBank *bank = head->getCylinderBank(); 19 | 20 | const float lineWidth = (float)m_chamber->m_flameEvent.travel_x * 2; 21 | double flameTop_x, flameTop_y; 22 | double flameBottom_x, flameBottom_y; 23 | double chamberHeight = head->getCombustionChamberVolume() / bank->boreSurfaceArea(); 24 | 25 | bank->getPositionAboveDeck(chamberHeight, &flameTop_x, &flameTop_y); 26 | bank->getPositionAboveDeck(chamberHeight - m_chamber->m_flameEvent.travel_y, &flameBottom_x, &flameBottom_y); 27 | 28 | GeometryGenerator::Line2dParameters params; 29 | params.lineWidth = lineWidth; 30 | 31 | gen->startShape(); 32 | 33 | params.x0 = (float)flameTop_x; 34 | params.y0 = (float)flameTop_y; 35 | params.x1 = (float)flameBottom_x; 36 | params.y1 = (float)flameBottom_y; 37 | gen->generateLine2d(params); 38 | 39 | gen->endShape(&m_indices); 40 | } 41 | 42 | void CombustionChamberObject::render(const ViewParameters *view) { 43 | resetShader(); 44 | 45 | CylinderHead *head = m_chamber->getCylinderHead(); 46 | CylinderBank *bank = head->getCylinderBank(); 47 | 48 | Piston *frontmostPiston = getForemostPiston(bank, view->Layer0); 49 | if (m_chamber->getPiston() == frontmostPiston) { 50 | if (m_chamber->m_lit) { 51 | m_app->getShaders()->SetBaseColor( 52 | ysMath::Mul( 53 | m_app->getOrange(), 54 | ysMath::LoadVector(1.0f, 1.0f, 1.0f, 0.6f))); 55 | m_app->drawGenerated(m_indices, 0x35); 56 | } 57 | } 58 | } 59 | 60 | void CombustionChamberObject::process(float dt) { 61 | /* void */ 62 | } 63 | 64 | void CombustionChamberObject::destroy() { 65 | /* void */ 66 | } 67 | -------------------------------------------------------------------------------- /src/convolution_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/convolution_filter.h" 2 | 3 | #include 4 | #include 5 | 6 | ConvolutionFilter::ConvolutionFilter() { 7 | m_shiftRegister = nullptr; 8 | m_impulseResponse = nullptr; 9 | 10 | m_shiftOffset = 0; 11 | m_sampleCount = 0; 12 | } 13 | 14 | ConvolutionFilter::~ConvolutionFilter() { 15 | assert(m_shiftRegister == nullptr); 16 | assert(m_impulseResponse == nullptr); 17 | } 18 | 19 | void ConvolutionFilter::initialize(int samples) { 20 | m_sampleCount = samples; 21 | m_shiftOffset = 0; 22 | m_shiftRegister = new float[samples]; 23 | m_impulseResponse = new float[samples]; 24 | 25 | memset(m_shiftRegister, 0, sizeof(float) * samples); 26 | memset(m_impulseResponse, 0, sizeof(float) * samples); 27 | } 28 | 29 | void ConvolutionFilter::destroy() { 30 | delete[] m_shiftRegister; 31 | delete[] m_impulseResponse; 32 | 33 | m_shiftRegister = nullptr; 34 | m_impulseResponse = nullptr; 35 | } 36 | 37 | float ConvolutionFilter::f(float sample) { 38 | m_shiftRegister[m_shiftOffset] = sample; 39 | 40 | float result = 0; 41 | for (int i = 0; i < m_sampleCount - m_shiftOffset; ++i) { 42 | result += m_impulseResponse[i] * m_shiftRegister[i + m_shiftOffset]; 43 | } 44 | 45 | for (int i = m_sampleCount - m_shiftOffset; i < m_sampleCount; ++i) { 46 | result += m_impulseResponse[i] * m_shiftRegister[i - (m_sampleCount - m_shiftOffset)]; 47 | } 48 | 49 | m_shiftOffset = (m_shiftOffset - 1 + m_sampleCount) % m_sampleCount; 50 | 51 | return result; 52 | } 53 | -------------------------------------------------------------------------------- /src/crankshaft.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/crankshaft.h" 2 | 3 | #include "../include/constants.h" 4 | 5 | #include 6 | #include 7 | 8 | Crankshaft::Crankshaft() { 9 | m_rodJournalAngles = nullptr; 10 | m_rodJournalCount = 0; 11 | m_throw = 0.0; 12 | m_m = 0.0; 13 | m_I = 0.0; 14 | m_flywheelMass = 0.0; 15 | m_p_x = m_p_y = 0.0; 16 | m_tdc = 0.0; 17 | m_frictionTorque = 0.0; 18 | } 19 | 20 | Crankshaft::~Crankshaft() { 21 | assert(m_rodJournalAngles == nullptr); 22 | } 23 | 24 | void Crankshaft::initialize(const Parameters ¶ms) { 25 | m_m = params.mass; 26 | m_flywheelMass = params.flywheelMass; 27 | m_I = params.momentOfInertia; 28 | m_throw = params.crankThrow; 29 | m_rodJournalCount = params.rodJournals; 30 | m_rodJournalAngles = new double[m_rodJournalCount]; 31 | m_p_x = params.pos_x; 32 | m_p_y = params.pos_y; 33 | m_tdc = params.tdc; 34 | m_frictionTorque = params.frictionTorque; 35 | m_initialFrictionTorque = params.frictionTorque; 36 | } 37 | 38 | void Crankshaft::destroy() { 39 | if (m_rodJournalAngles != nullptr) delete[] m_rodJournalAngles; 40 | 41 | m_rodJournalAngles = nullptr; 42 | } 43 | 44 | void Crankshaft::getRodJournalPositionLocal(int i, double *x, double *y) { 45 | const double theta = m_rodJournalAngles[i]; 46 | 47 | *x = std::cos(theta) * m_throw; 48 | *y = std::sin(theta) * m_throw; 49 | } 50 | 51 | void Crankshaft::getRodJournalPositionGlobal(int i, double *x, double *y) { 52 | double lx, ly; 53 | getRodJournalPositionLocal(i, &lx, &ly); 54 | 55 | *x = lx + m_body.p_x; 56 | *y = ly + m_body.p_y; 57 | } 58 | 59 | void Crankshaft::resetAngle() { 60 | m_body.theta = std::fmod(m_body.theta, 4 * constants::pi); 61 | } 62 | 63 | void Crankshaft::setRodJournalAngle(int i, double angle) { 64 | assert(i < m_rodJournalCount && i >= 0); 65 | 66 | m_rodJournalAngles[i] = angle; 67 | } 68 | 69 | double Crankshaft::getAngle() const { 70 | return m_body.theta - m_tdc; 71 | } 72 | 73 | double Crankshaft::getCycleAngle(double offset) { 74 | const double wrapped = std::fmod(-getAngle() + offset, 4 * constants::pi); 75 | return (wrapped < 0) 76 | ? wrapped + 4 * constants::pi 77 | : wrapped; 78 | } 79 | -------------------------------------------------------------------------------- /src/cylinder_bank.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/cylinder_bank.h" 2 | 3 | #include "../include/constants.h" 4 | 5 | #include 6 | 7 | CylinderBank::CylinderBank() { 8 | m_angle = 0.0; 9 | m_bore = 0.0; 10 | m_deckHeight = 0.0; 11 | m_cylinderCount = 0; 12 | m_displayDepth = 0.4; 13 | m_index = -1; 14 | 15 | m_dx = m_dy = 0; 16 | m_x = m_y = 0; 17 | } 18 | 19 | CylinderBank::~CylinderBank() { 20 | /* void */ 21 | } 22 | 23 | void CylinderBank::initialize(const Parameters ¶ms) { 24 | m_angle = params.angle; 25 | m_bore = params.bore; 26 | m_deckHeight = params.deckHeight; 27 | m_cylinderCount = params.cylinderCount; 28 | 29 | m_dx = std::cos(m_angle + constants::pi / 2); 30 | m_dy = std::sin(m_angle + constants::pi / 2); 31 | 32 | m_x = params.positionX; 33 | m_y = params.positionY; 34 | 35 | m_displayDepth = params.displayDepth; 36 | 37 | m_index = params.index; 38 | } 39 | 40 | void CylinderBank::destroy() { 41 | /* void */ 42 | } 43 | 44 | void CylinderBank::getPositionAboveDeck(double h, double *x, double *y) const { 45 | *x = m_dx * (m_deckHeight + h) + m_x; 46 | *y = m_dy * (m_deckHeight + h) + m_y; 47 | } 48 | 49 | double CylinderBank::boreSurfaceArea() const { 50 | return constants::pi * m_bore * m_bore / 4.0; 51 | } 52 | -------------------------------------------------------------------------------- /src/delay_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/delay_filter.h" 2 | 3 | -------------------------------------------------------------------------------- /src/derivative_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/derivative_filter.h" 2 | 3 | DerivativeFilter::DerivativeFilter() { 4 | m_previous = 0; 5 | m_dt = 0; 6 | } 7 | 8 | DerivativeFilter::~DerivativeFilter() { 9 | /* void */ 10 | } 11 | 12 | float DerivativeFilter::f(float sample) { 13 | const float temp = m_previous; 14 | m_previous = sample; 15 | 16 | return (sample - temp) / m_dt; 17 | } 18 | -------------------------------------------------------------------------------- /src/direct_throttle_linkage.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/direct_throttle_linkage.h" 2 | 3 | #include "../include/engine.h" 4 | 5 | #include 6 | 7 | DirectThrottleLinkage::DirectThrottleLinkage() { 8 | m_gamma = 1.0; 9 | m_throttlePosition = 1.0; 10 | } 11 | 12 | DirectThrottleLinkage::~DirectThrottleLinkage() { 13 | /* void */ 14 | } 15 | 16 | void DirectThrottleLinkage::initialize(const Parameters ¶ms) { 17 | m_gamma = params.gamma; 18 | } 19 | 20 | void DirectThrottleLinkage::setSpeedControl(double s) { 21 | Throttle::setSpeedControl(s); 22 | m_throttlePosition = 1 - std::pow(s, m_gamma); 23 | } 24 | 25 | void DirectThrottleLinkage::update(double dt, Engine *engine) { 26 | Throttle::update(dt, engine); 27 | engine->setThrottle(m_throttlePosition); 28 | } 29 | -------------------------------------------------------------------------------- /src/dynamometer.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/dynamometer.h" 2 | 3 | #include "../include/units.h" 4 | 5 | #include 6 | 7 | Dynamometer::Dynamometer() : atg_scs::Constraint(1, 1) { 8 | m_rotationSpeed = 0.0; 9 | m_ks = 10.0; 10 | m_kd = 1.0; 11 | m_maxTorque = units::torque(10000.0, units::ft_lb); 12 | 13 | m_enabled = false; 14 | m_hold = false; 15 | } 16 | 17 | Dynamometer::~Dynamometer() { 18 | /* void */ 19 | } 20 | 21 | void Dynamometer::connectCrankshaft(Crankshaft *crankshaft) { 22 | m_bodies[0] = &crankshaft->m_body; 23 | } 24 | 25 | void Dynamometer::calculate(Output *output, atg_scs::SystemState *state) { 26 | output->J[0][0] = 0; 27 | output->J[0][1] = 0; 28 | output->J[0][2] = 1; 29 | 30 | output->J_dot[0][0] = 0; 31 | output->J_dot[0][1] = 0; 32 | output->J_dot[0][2] = 0; 33 | 34 | output->ks[0] = m_ks; 35 | output->kd[0] = m_kd; 36 | 37 | output->C[0] = 0; 38 | 39 | if (m_bodies[0]->v_theta < 0) { 40 | output->v_bias[0] = m_rotationSpeed; 41 | output->limits[0][0] = (m_hold && m_enabled) ? -m_maxTorque : 0.0; 42 | output->limits[0][1] = m_enabled ? m_maxTorque : 0.0; 43 | } 44 | else { 45 | output->v_bias[0] = -m_rotationSpeed; 46 | output->limits[0][0] = m_enabled ? -m_maxTorque : 0.0; 47 | output->limits[0][1] = (m_hold && m_enabled) ? m_maxTorque : 0.0; 48 | } 49 | } 50 | 51 | double Dynamometer::getTorque() const { 52 | return (m_bodies[0]->v_theta > 0) 53 | ? -atg_scs::Constraint::F_t[0][0] 54 | : atg_scs::Constraint::F_t[0][0]; 55 | } 56 | -------------------------------------------------------------------------------- /src/engine_view.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/engine_view.h" 2 | 3 | #include "../include/engine_sim_application.h" 4 | 5 | EngineView::EngineView() { 6 | m_pan = { 0, units::distance(-6, units::inch) }; 7 | m_checkMouse = true; 8 | m_lastScroll = 0; 9 | m_zoom = 1.0f; 10 | m_drawFrame = true; 11 | } 12 | 13 | EngineView::~EngineView() { 14 | /* void */ 15 | } 16 | 17 | void EngineView::update(float dt) { 18 | m_mouseBounds = m_bounds; 19 | } 20 | 21 | void EngineView::render() { 22 | if (m_drawFrame) { 23 | drawFrame(m_bounds, 1.0f, m_app->getForegroundColor(), m_app->getBackgroundColor(), false); 24 | } 25 | } 26 | 27 | void EngineView::onMouseDown(const Point &mouseLocal) { 28 | UiElement::onMouseDown(mouseLocal); 29 | m_dragStart = m_pan; 30 | } 31 | 32 | void EngineView::onDrag(const Point &p0, const Point &mouse0, const Point &mouse) { 33 | const Point delta = mouse - mouse0; 34 | const Point deltaUnits = { 35 | m_app->pixelsToUnits(delta.x), 36 | m_app->pixelsToUnits(delta.y) 37 | }; 38 | 39 | m_pan = m_dragStart + deltaUnits; 40 | } 41 | 42 | void EngineView::onMouseScroll(int scroll) { 43 | const float f = std::powf(2.0, (float)scroll / 500.0f); 44 | 45 | const Point prevCenter = getCenter(); 46 | 47 | m_zoom *= f; 48 | const Point newCenter = getCenter(); 49 | 50 | Point diff = newCenter - prevCenter; 51 | m_pan += diff * m_zoom; 52 | m_dragStart += diff * m_zoom; 53 | } 54 | 55 | void EngineView::setBounds(const Bounds &bounds) { 56 | m_bounds = bounds; 57 | } 58 | 59 | Point EngineView::getCenter() const { 60 | return getCameraPosition(); 61 | } 62 | 63 | Point EngineView::getCameraPosition() const { 64 | return Point(-m_pan / m_zoom); 65 | } 66 | -------------------------------------------------------------------------------- /src/feedback_comb_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/feedback_comb_filter.h" 2 | 3 | #include 4 | 5 | FeedbackCombFilter::FeedbackCombFilter() { 6 | M = 0; 7 | a_M = 1.0; 8 | m_y = nullptr; 9 | m_offset = 0; 10 | } 11 | 12 | FeedbackCombFilter::~FeedbackCombFilter() { 13 | assert(m_y == nullptr); 14 | } 15 | 16 | void FeedbackCombFilter::initialize(int M) { 17 | this->M = M; 18 | m_y = new float[M]; 19 | m_offset = 0; 20 | } 21 | 22 | float FeedbackCombFilter::f(float sample) { 23 | const float y_n_min_M = m_y[m_offset]; 24 | 25 | const float y_n = sample + a_M * y_n_min_M; 26 | 27 | m_y[m_offset] = y_n; 28 | m_offset = (m_offset + 1) % M; 29 | 30 | return y_n; 31 | } 32 | 33 | void FeedbackCombFilter::destroy() { 34 | delete[] m_y; 35 | 36 | m_y = nullptr; 37 | } 38 | -------------------------------------------------------------------------------- /src/filter.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/filter.h" 2 | 3 | Filter::Filter() { 4 | /* void */ 5 | } 6 | 7 | Filter::~Filter() { 8 | /* void */ 9 | } 10 | 11 | float Filter::f(float sample) { 12 | return sample; 13 | } 14 | 15 | void Filter::destroy() { 16 | /* void */ 17 | } 18 | -------------------------------------------------------------------------------- /src/gaussian_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/gaussian_filter.h" 2 | 3 | #include 4 | 5 | GaussianFilter::GaussianFilter() { 6 | m_cache = nullptr; 7 | 8 | m_cacheSteps = 0; 9 | m_radius = 0.0; 10 | m_alpha = 0.0; 11 | 12 | m_exp_s = 0.0; 13 | m_inv_r = 0.0; 14 | } 15 | 16 | GaussianFilter::~GaussianFilter() { 17 | if (m_cache != nullptr) delete[] m_cache; 18 | } 19 | 20 | void GaussianFilter::initialize(double alpha, double radius, int cacheSteps) { 21 | m_cacheSteps = cacheSteps; 22 | 23 | m_alpha = alpha; 24 | m_radius = radius; 25 | 26 | m_exp_s = std::exp(-m_alpha * m_radius * m_radius); 27 | m_inv_r = 1 / m_radius; 28 | 29 | generateCache(); 30 | } 31 | 32 | double GaussianFilter::evaluate(double s) const { 33 | const int actualSteps = m_cacheSteps - 32; 34 | const double s_sample = actualSteps * std::abs(s) * m_inv_r; 35 | const double s0 = std::floor(s_sample); 36 | const double s1 = std::ceil(s_sample); 37 | const double d = s_sample - s0; 38 | 39 | return 40 | (1 - d) * m_cache[(int)s0] 41 | + d * m_cache[(int)s1]; 42 | } 43 | 44 | double GaussianFilter::calculate(double s) const { 45 | return std::max( 46 | 0.0, 47 | std::exp(-m_alpha * s * s) - m_exp_s); 48 | } 49 | 50 | void GaussianFilter::generateCache() { 51 | const int actualSteps = m_cacheSteps - 32; 52 | const double step = 1.0 / actualSteps; 53 | 54 | m_cache = new double[m_cacheSteps]; 55 | for (int i = 0; i <= actualSteps; ++i) { 56 | const double s = i * step * m_radius; 57 | m_cache[i] = calculate(s); 58 | } 59 | 60 | for (int i = actualSteps + 1; i < m_cacheSteps; ++i) { 61 | m_cache[i] = 0.0; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/governor.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/governor.h" 2 | 3 | #include "../include/engine.h" 4 | #include "../include/utilities.h" 5 | 6 | Governor::Governor() { 7 | m_minSpeed = m_maxSpeed = 0; 8 | m_targetSpeed = 0; 9 | m_currentThrottle = 1.0; 10 | m_velocity = 0.0; 11 | m_minVelocity = m_maxVelocity = 0.0; 12 | m_k_s = m_k_d = 0.0; 13 | m_gamma = 1.0; 14 | } 15 | 16 | Governor::~Governor() { 17 | /* void */ 18 | } 19 | 20 | void Governor::initialize(const Parameters ¶ms) { 21 | m_minSpeed = params.minSpeed; 22 | m_maxSpeed = params.maxSpeed; 23 | m_minVelocity = params.minVelocity; 24 | m_maxVelocity = params.maxVelocity; 25 | m_k_s = params.k_s; 26 | m_k_d = params.k_d; 27 | m_gamma = params.gamma; 28 | } 29 | 30 | void Governor::setSpeedControl(double s) { 31 | Throttle::setSpeedControl(s); 32 | 33 | m_targetSpeed = (1 - s) * m_minSpeed + s * m_maxSpeed; 34 | } 35 | 36 | void Governor::update(double dt, Engine *engine) { 37 | const double currentSpeed = engine->getSpeed(); 38 | const double ds = m_targetSpeed * m_targetSpeed - currentSpeed * currentSpeed; 39 | 40 | m_velocity += (dt * -ds * m_k_s - m_velocity * dt * m_k_d); 41 | m_velocity = clamp(m_velocity, m_minVelocity, m_maxVelocity); 42 | 43 | if (std::abs(currentSpeed) < std::abs(0.5 * m_minSpeed)) { 44 | m_velocity = 0; 45 | m_currentThrottle = 1.0; 46 | } 47 | 48 | m_currentThrottle += m_velocity * dt; 49 | m_currentThrottle = clamp(m_currentThrottle); 50 | 51 | engine->setThrottle(1 - std::pow(1 - m_currentThrottle, m_gamma)); 52 | } 53 | -------------------------------------------------------------------------------- /src/impulse_response.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/impulse_response.h" 2 | 3 | ImpulseResponse::ImpulseResponse() { 4 | m_volume = 1.0; 5 | } 6 | 7 | ImpulseResponse::~ImpulseResponse() { 8 | /* void */ 9 | } 10 | 11 | void ImpulseResponse::initialize( 12 | const std::string &filename, 13 | double volume) 14 | { 15 | m_filename = filename; 16 | m_volume = volume; 17 | } 18 | -------------------------------------------------------------------------------- /src/jitter_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/jitter_filter.h" 2 | 3 | JitterFilter::JitterFilter() { 4 | m_history = nullptr; 5 | m_maxJitter = 0; 6 | m_offset = 0; 7 | m_jitterScale = 0.0f; 8 | } 9 | 10 | JitterFilter::~JitterFilter() { 11 | /* void */ 12 | } 13 | 14 | void JitterFilter::initialize( 15 | int maxJitter, 16 | float cutoffFrequency, 17 | float audioFrequency) 18 | { 19 | m_maxJitter = maxJitter; 20 | 21 | m_history = new float[maxJitter]; 22 | m_offset = 0; 23 | memset(m_history, 0, sizeof(float) * maxJitter); 24 | 25 | m_noiseFilter.setCutoffFrequency(cutoffFrequency, audioFrequency); 26 | } 27 | 28 | float JitterFilter::f(float sample) { 29 | return fast_f(sample); 30 | } 31 | -------------------------------------------------------------------------------- /src/labeled_gauge.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/labeled_gauge.h" 2 | 3 | #include "../include/engine_sim_application.h" 4 | 5 | #include 6 | #include 7 | 8 | LabeledGauge::LabeledGauge() { 9 | m_gauge = nullptr; 10 | m_title = ""; 11 | m_precision = 2; 12 | m_unit = ""; 13 | m_spaceBeforeUnit = true; 14 | } 15 | 16 | LabeledGauge::~LabeledGauge() { 17 | /* void */ 18 | } 19 | 20 | void LabeledGauge::initialize(EngineSimApplication *app) { 21 | UiElement::initialize(app); 22 | 23 | m_gauge = addElement(); 24 | m_gauge->m_center = { 0.0f, -20.0f }; 25 | } 26 | 27 | void LabeledGauge::destroy() { 28 | UiElement::destroy(); 29 | } 30 | 31 | void LabeledGauge::update(float dt) { 32 | UiElement::update(dt); 33 | } 34 | 35 | void LabeledGauge::render() { 36 | drawFrame(m_bounds, 1.0, m_app->getForegroundColor(), m_app->getBackgroundColor()); 37 | 38 | const Bounds bounds = m_bounds.inset(m_margin); 39 | const Bounds title = bounds.verticalSplit(1.0f, 0.9f); 40 | const Bounds gaugeBounds = bounds.verticalSplit(0.0f, 0.9f); 41 | 42 | drawCenteredText(m_title, title.inset(10.0f), 24.0f); 43 | 44 | const double value = m_gauge->m_value; 45 | 46 | std::stringstream ss; 47 | ss << std::fixed << std::setprecision(m_precision); 48 | ss << value << ((m_spaceBeforeUnit && m_unit.length() > 0) ? " " : "") << m_unit; 49 | drawAlignedText( 50 | ss.str(), 51 | gaugeBounds.verticalSplit(0.0f, 2 / 8.0f), 52 | gaugeBounds.height() / 8, 53 | Bounds::bm, 54 | Bounds::bm); 55 | 56 | m_gauge->m_bounds = gaugeBounds; 57 | m_gauge->setLocalPosition({ 0, 0 }); 58 | m_gauge->m_outerRadius = std::fmin(gaugeBounds.width(), gaugeBounds.height()) / 2.0f; 59 | m_gauge->m_needleOuterRadius = m_gauge->m_outerRadius * m_needleOuterRadius; 60 | m_gauge->m_needleInnerRadius = -m_gauge->m_outerRadius * m_needleInnerRadius; 61 | 62 | UiElement::render(); 63 | } 64 | -------------------------------------------------------------------------------- /src/lerp_function.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/lerp_function.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | LerpFunction::LerpFunction(Function* from, Function* to, float time) { 9 | m_x = m_y = nullptr; 10 | m_capacity = 0; 11 | m_size = 0; 12 | m_filterRadius = 0; 13 | m_yMin = m_yMax = 0; 14 | m_inputScale = 1.0; 15 | m_outputScale = 1.0; 16 | 17 | if (DefaultGaussianFilter == nullptr) { 18 | DefaultGaussianFilter = new GaussianFilter; 19 | DefaultGaussianFilter->initialize(1.0, 3.0, 1024); 20 | } 21 | 22 | m_gaussianFilter = nullptr; 23 | 24 | this->from = from; 25 | this->to = to; 26 | this->time = time; 27 | } 28 | 29 | LerpFunction::~LerpFunction() { 30 | assert(m_x == nullptr); 31 | assert(m_y == nullptr); 32 | } 33 | 34 | /*void LerpFunction::initialize(int size, double filterRadius, GaussianFilter* filter) { 35 | resize(size); 36 | m_size = 0; 37 | m_filterRadius = filterRadius; 38 | 39 | m_gaussianFilter = (filter != nullptr) 40 | ? filter 41 | : DefaultGaussianFilter; 42 | } 43 | 44 | void LerpFunction::destroy() { 45 | delete[] m_x; 46 | delete[] m_y; 47 | 48 | m_x = nullptr; 49 | m_y = nullptr; 50 | 51 | m_capacity = 0; 52 | m_size = 0; 53 | }*/ 54 | 55 | double LerpFunction::sampleTriangle(double x) const { 56 | return lerp(from->sampleTriangle(x), to->sampleTriangle(x), time); 57 | } 58 | 59 | double LerpFunction::sampleGaussian(double x) const { 60 | return lerp(from->sampleGaussian(x), to->sampleGaussian(x), time); 61 | } 62 | 63 | double LerpFunction::triangle(double x) const { 64 | return lerp(from->triangle(x), to->triangle(x), time); 65 | } 66 | 67 | /*int LerpFunction::closestSample(double x) const { 68 | return (int)lerp(from->closestSample(x), to->closestSample(x), time); 69 | }*/ 70 | -------------------------------------------------------------------------------- /src/leveling_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/leveling_filter.h" 2 | 3 | #include 4 | 5 | LevelingFilter::LevelingFilter() { 6 | m_peak = 30000.0; 7 | m_attenuation = 1.0; 8 | p_target = 30000.0; 9 | p_minLevel = 0.0; 10 | p_maxLevel = 1.0; 11 | } 12 | 13 | LevelingFilter::~LevelingFilter() { 14 | /* void */ 15 | } 16 | 17 | float LevelingFilter::f(float sample) { 18 | m_peak = 0.999f * m_peak; 19 | if (std::abs(sample) > m_peak) { 20 | m_peak = std::abs(sample); 21 | } 22 | 23 | if (m_peak == 0) return 0; 24 | 25 | const float raw_attenuation = p_target / m_peak; 26 | 27 | float attenuation = raw_attenuation; 28 | if (attenuation < p_minLevel) attenuation = p_minLevel; 29 | else if (attenuation > p_maxLevel) attenuation = p_maxLevel; 30 | 31 | m_attenuation = 0.9 * m_attenuation + 0.1 * attenuation; 32 | 33 | return sample * m_attenuation; 34 | } 35 | -------------------------------------------------------------------------------- /src/low_pass_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/low_pass_filter.h" 2 | 3 | LowPassFilter::LowPassFilter() { 4 | m_y = 0; 5 | m_rc = 0; 6 | m_dt = 1 / 44100.0f; 7 | } 8 | 9 | LowPassFilter::~LowPassFilter() { 10 | /* void */ 11 | } 12 | 13 | float LowPassFilter::f(float sample) { 14 | return fast_f(sample); 15 | } 16 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/engine_sim_application.h" 2 | 3 | #include 4 | #include 5 | 6 | int WINAPI WinMain( 7 | _In_ HINSTANCE hInstance, 8 | _In_opt_ HINSTANCE hPrevInstance, 9 | _In_ LPSTR lpCmdLine, 10 | _In_ int nCmdShow) 11 | { 12 | (void)nCmdShow; 13 | (void)lpCmdLine; 14 | (void)hPrevInstance; 15 | 16 | /* 17 | AllocConsole(); 18 | freopen("CONIN$", "r", stdin); 19 | freopen("CONOUT$", "w", stdout); 20 | freopen("CONOUT$", "w", stderr); 21 | */ 22 | 23 | std::string comPort = "COM3"; 24 | 25 | LPWSTR* szArglist; 26 | int nArgs; 27 | int i; 28 | 29 | szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); 30 | if (NULL == szArglist) 31 | { 32 | wprintf(L"CommandLineToArgvW failed\n"); 33 | return 0; 34 | } 35 | else { 36 | for (i = 0; i < nArgs; i++) { 37 | std::wstring s(szArglist[i]); 38 | if (s._Starts_with(L"COM")) { 39 | using convert_typeX = std::codecvt_utf8; 40 | std::wstring_convert converterX; 41 | comPort = converterX.to_bytes(s); 42 | } 43 | printf("%d: %ws\n", i, szArglist[i]); 44 | } 45 | } 46 | 47 | EngineSimApplication application(comPort); 48 | application.initialize((void *)&hInstance, ysContextObject::DeviceAPI::DirectX11); 49 | application.run(); 50 | application.destroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /src/part.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/part.h" 2 | 3 | Part::Part() { 4 | /* void */ 5 | } 6 | 7 | Part::~Part() { 8 | /* void */ 9 | } 10 | 11 | void Part::destroy() { 12 | /* void */ 13 | } 14 | -------------------------------------------------------------------------------- /src/piston.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/piston.h" 2 | 3 | #include "../include/connecting_rod.h" 4 | #include "../include/crankshaft.h" 5 | #include "../include/cylinder_bank.h" 6 | 7 | #include 8 | 9 | Piston::Piston() { 10 | m_rod = nullptr; 11 | m_bank = nullptr; 12 | m_cylinderConstraint = nullptr; 13 | m_cylinderIndex = -1; 14 | m_compressionHeight = 0.0; 15 | m_displacement = 0.0; 16 | m_wristPinLocation = 0.0; 17 | m_mass = 0.0; 18 | m_blowby_k = 0.0; 19 | } 20 | 21 | Piston::~Piston() { 22 | /* void */ 23 | } 24 | 25 | void Piston::initialize(const Parameters ¶ms) { 26 | m_rod = params.Rod; 27 | m_bank = params.Bank; 28 | m_cylinderIndex = params.CylinderIndex; 29 | m_compressionHeight = params.CompressionHeight; 30 | m_displacement = params.Displacement; 31 | m_wristPinLocation = params.WristPinPosition; 32 | m_mass = params.mass; 33 | m_blowby_k = params.BlowbyFlowCoefficient; 34 | m_initialBlowby = params.BlowbyFlowCoefficient; 35 | } 36 | 37 | void Piston::destroy() { 38 | /* void */ 39 | } 40 | 41 | double Piston::relativeX() const { 42 | return m_body.p_x - m_bank->getX(); 43 | } 44 | 45 | double Piston::relativeY() const { 46 | return m_body.p_y - m_bank->getY(); 47 | } 48 | 49 | double Piston::calculateCylinderWallForce() const { 50 | return std::sqrt( 51 | m_cylinderConstraint->F_x[0][0] * m_cylinderConstraint->F_x[0][0] 52 | + m_cylinderConstraint->F_y[0][0] * m_cylinderConstraint->F_y[0][0]); 53 | } 54 | -------------------------------------------------------------------------------- /src/piston_object.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/piston_object.h" 2 | 3 | #include "../include/cylinder_bank.h" 4 | #include "../include/engine_sim_application.h" 5 | 6 | PistonObject::PistonObject() { 7 | m_piston = nullptr; 8 | m_wristPinHole = {}; 9 | } 10 | 11 | PistonObject::~PistonObject() { 12 | /* void */ 13 | } 14 | 15 | void PistonObject::generateGeometry() { 16 | GeometryGenerator *gen = m_app->getGeometryGenerator(); 17 | 18 | GeometryGenerator::Circle2dParameters circleParams; 19 | circleParams.center_x = 0.0f; 20 | circleParams.center_y = (float)m_piston->getWristPinLocation(); 21 | circleParams.maxEdgeLength = m_app->pixelsToUnits(5.0f); 22 | circleParams.radius = (float)(m_piston->getCylinderBank()->getBore() / 10) * 0.75f; 23 | gen->startShape(); 24 | gen->generateCircle2d(circleParams); 25 | gen->endShape(&m_wristPinHole); 26 | } 27 | 28 | void PistonObject::render(const ViewParameters *view) { 29 | const int layer = m_piston->getRod()->getLayer(); 30 | if (layer > view->Layer1 || layer < view->Layer0) return; 31 | 32 | const ysVector col = tintByLayer(m_app->getForegroundColor(), layer - view->Layer0); 33 | const ysVector holeCol = tintByLayer(m_app->getBackgroundColor(), layer - view->Layer0); 34 | 35 | resetShader(); 36 | setTransform( 37 | &m_piston->m_body, 38 | (float)(m_piston->getCylinderBank()->getBore() / 2), 39 | 0.0f, 40 | (float)(-m_piston->getCompressionHeight() - m_piston->getWristPinLocation())); 41 | 42 | m_app->getShaders()->SetBaseColor(col); 43 | m_app->getEngine()->DrawModel( 44 | m_app->getShaders()->GetRegularFlags(), 45 | m_app->getAssetManager()->GetModelAsset("Piston"), 46 | 0x32 - layer); 47 | 48 | setTransform(&m_piston->m_body); 49 | m_app->getShaders()->SetBaseColor(holeCol); 50 | m_app->drawGenerated(m_wristPinHole, 0x32 - layer); 51 | } 52 | 53 | void PistonObject::process(float dt) { 54 | /* void */ 55 | } 56 | 57 | void PistonObject::destroy() { 58 | /* void */ 59 | } 60 | -------------------------------------------------------------------------------- /src/standard_valvetrain.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/standard_valvetrain.h" 2 | 3 | #include "../include/camshaft.h" 4 | 5 | StandardValvetrain::StandardValvetrain() { 6 | m_intakeCamshaft = nullptr; 7 | m_exhaustCamshaft = nullptr; 8 | } 9 | 10 | StandardValvetrain::~StandardValvetrain() { 11 | /* void */ 12 | } 13 | 14 | void StandardValvetrain::initialize(const Parameters ¶ms) { 15 | m_intakeCamshaft = params.intakeCamshaft; 16 | m_exhaustCamshaft = params.exhaustCamshaft; 17 | } 18 | 19 | double StandardValvetrain::intakeValveLift(int cylinder) { 20 | return m_intakeCamshaft->valveLift(cylinder); 21 | } 22 | 23 | double StandardValvetrain::exhaustValveLift(int cylinder) { 24 | return m_exhaustCamshaft->valveLift(cylinder); 25 | } 26 | 27 | Camshaft *StandardValvetrain::getActiveIntakeCamshaft() { 28 | return m_intakeCamshaft; 29 | } 30 | 31 | Camshaft *StandardValvetrain::getActiveExhaustCamshaft() { 32 | return m_exhaustCamshaft; 33 | } 34 | -------------------------------------------------------------------------------- /src/starter_motor.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/starter_motor.h" 2 | 3 | #include "../include/units.h" 4 | 5 | StarterMotor::StarterMotor() : atg_scs::Constraint(1, 1) { 6 | m_ks = 10.0; 7 | m_kd = 1.0; 8 | m_maxTorque = units::torque(80.0, units::ft_lb); 9 | m_rotationSpeed = -units::rpm(200.0); 10 | m_enabled = false; 11 | } 12 | 13 | StarterMotor::~StarterMotor() { 14 | /* void */ 15 | } 16 | 17 | void StarterMotor::connectCrankshaft(Crankshaft *crankshaft) { 18 | m_bodies[0] = &crankshaft->m_body; 19 | } 20 | 21 | void StarterMotor::calculate(Output *output, atg_scs::SystemState *state) { 22 | output->J[0][0] = 0; 23 | output->J[0][1] = 0; 24 | output->J[0][2] = 1; 25 | 26 | output->J_dot[0][0] = 0; 27 | output->J_dot[0][1] = 0; 28 | output->J_dot[0][2] = 0; 29 | 30 | output->ks[0] = m_ks; 31 | output->kd[0] = m_kd; 32 | 33 | output->C[0] = 0; 34 | 35 | output->v_bias[0] = -m_rotationSpeed; 36 | 37 | if (m_rotationSpeed < 0) { 38 | output->limits[0][0] = m_enabled ? -m_maxTorque : 0.0; 39 | output->limits[0][1] = 0.0; 40 | } 41 | else { 42 | output->limits[0][0] = 0.0; 43 | output->limits[0][1] = m_enabled ? m_maxTorque : 0.0; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/throttle.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/throttle.h" 2 | 3 | Throttle::Throttle() { 4 | m_speedControl = 0; 5 | } 6 | 7 | Throttle::~Throttle() { 8 | /* void */ 9 | } 10 | 11 | void Throttle::setSpeedControl(double s) { 12 | m_speedControl = s; 13 | } 14 | 15 | void Throttle::update(double dt, Engine *engine) { 16 | /* void */ 17 | } 18 | -------------------------------------------------------------------------------- /src/turbocharger.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../include/turbocharger.h" 3 | 4 | TurboCharger::TurboCharger() { 5 | m_engine = nullptr; 6 | } 7 | 8 | TurboCharger::~TurboCharger() { 9 | 10 | } 11 | 12 | void TurboCharger::process(float dt) { 13 | /* 14 | 15 | flow = es.engine.ExhaustFlow * turbo_flow_mult 16 | 17 | flow = flow * (es.engine.RPM / turbo_rpm_to_flow) 18 | 19 | if INPUT_L == "true" then 20 | flow = flow * turbo_antilag_flow 21 | end 22 | 23 | turbo_spool = turbo_spool + flow 24 | 25 | if turbo_spool < turbo_max then 26 | turbo_spool = turbo_max 27 | else 28 | turbo_spool = turbo_spool + turbo_down 29 | end 30 | 31 | if turbo_spool > 0.5 then 32 | turbo_spool = 0.5 33 | end 34 | 35 | press = -turbo_spool / turbo_to_press 36 | flow = press * turbo_press_to_flow 37 | 38 | */ 39 | 40 | float flow = 0; 41 | 42 | for (int i = 0; i < m_engine->getExhaustSystemCount(); i++) { 43 | ExhaustSystem* exhaust = m_engine->getExhaustSystem(i); 44 | 45 | float floww = exhaust->getFlow(); 46 | if (floww < 0) 47 | floww = -floww; 48 | 49 | flow += floww; 50 | } 51 | 52 | flow *= m_flowMultiplier; 53 | flow *= (units::toRpm(m_engine->getRpm()) / m_erpmToFlow); 54 | m_rotorRPM += flow; 55 | 56 | if (m_rotorRPM < 0) 57 | m_rotorRPM = 0; 58 | 59 | // calculate boost and flow 60 | m_boost = m_rotorRPM * m_rpmToPressure; 61 | m_flow = m_rotorRPM * m_rpmToFlow; 62 | 63 | if (m_boost >= m_wastegate) { 64 | m_rotorRPM *= 0.95f; 65 | m_boost = m_rotorRPM * m_rpmToPressure; 66 | m_flow = m_rotorRPM * m_rpmToFlow; 67 | } 68 | else { 69 | m_rotorRPM -= m_rpmDown; 70 | m_boost = m_rotorRPM * m_rpmToPressure; 71 | m_flow = m_rotorRPM * m_rpmToFlow; 72 | } 73 | 74 | for (int i = 0; i < m_engine->getIntakeCount(); i++) { 75 | Intake* intake = m_engine->getIntake(i); 76 | //intake->m_boost = m_boost * (1 - m_engine->getThrottle()); 77 | //intake->m_additionalFlow = m_flow * (1 - m_engine->getThrottle()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/ui_button.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/ui_button.h" 2 | 3 | #include "../include/engine_sim_application.h" 4 | #include "../include/ui_utilities.h" 5 | 6 | UiButton::UiButton() { 7 | m_text = ""; 8 | m_fontSize = 12; 9 | m_checkMouse = true; 10 | } 11 | 12 | UiButton::~UiButton() { 13 | /* void */ 14 | } 15 | 16 | void UiButton::update(float dt) { 17 | m_mouseBounds = m_bounds; 18 | } 19 | 20 | void UiButton::render() { 21 | ysVector color = m_app->getBackgroundColor(); 22 | if (isMouseHeld()) { 23 | color = mix(m_app->getBackgroundColor(), m_app->getForegroundColor(), 0.02f); 24 | } 25 | else if (isMouseOver()) { 26 | color = mix(m_app->getBackgroundColor(), m_app->getForegroundColor(), 0.01f); 27 | } 28 | 29 | drawFrame(m_bounds, 1.0, m_app->getForegroundColor(), color); 30 | drawCenteredText(m_text, m_bounds, m_fontSize); 31 | } 32 | -------------------------------------------------------------------------------- /src/ui_math.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/ui_math.h" 2 | 3 | const Point Bounds::center = { 0.5f, 0.5f }; 4 | const Point Bounds::tl = { 0.0f, 1.0f }; 5 | const Point Bounds::tr = { 1.0f, 0.0f }; 6 | const Point Bounds::tm = { 0.5f, 1.0f }; 7 | const Point Bounds::bl = { 0.0f, 0.0f }; 8 | const Point Bounds::br = { 1.0f, 0.0f }; 9 | const Point Bounds::bm = { 0.5f, 0.0f }; 10 | const Point Bounds::lm = { 0.0f, 0.5f }; 11 | const Point Bounds::rm = { 1.0f, 0.5f }; 12 | -------------------------------------------------------------------------------- /src/ui_utilities.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/ui_utilities.h" 2 | 3 | ysVector mix(const ysVector &c1, const ysVector &c2, float s) { 4 | return ysMath::Add( 5 | ysMath::Mul(c1, ysMath::LoadScalar(1 - s)), 6 | ysMath::Mul(c2, ysMath::LoadScalar(s))); 7 | } 8 | -------------------------------------------------------------------------------- /src/utilities.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/utilities.h" 2 | 3 | #include 4 | 5 | double modularDistance(double a0, double b0, double mod) { 6 | double a, b; 7 | if (a0 < b0) { 8 | a = a0; 9 | b = b0; 10 | } 11 | else { 12 | a = b0; 13 | b = a0; 14 | } 15 | 16 | return std::fmin(b - a, a + mod - b); 17 | } 18 | 19 | double positiveMod(double x, double mod) { 20 | if (x < 0) { 21 | x = std::ceil(-x / mod) * mod + x; 22 | } 23 | 24 | return std::fmod(x, mod); 25 | } 26 | 27 | double erfApproximation(double x) { 28 | const double a1 = 0.278393; 29 | const double a2 = 0.230389; 30 | const double a3 = 0.000972; 31 | const double a4 = 0.078108; 32 | 33 | const double x2 = x * x; 34 | const double x3 = x2 * x; 35 | const double x4 = x3 * x; 36 | 37 | const double q = 1 / (1 + a1 * x + a2 * x2 + a3 * x3 + a4 * x4); 38 | const double q2 = q * q; 39 | const double q4 = q2 * q2; 40 | 41 | return 1 - q4; 42 | } 43 | -------------------------------------------------------------------------------- /src/valvetrain.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/valvetrain.h" 2 | 3 | Valvetrain::Valvetrain() { 4 | /* void */ 5 | } 6 | 7 | Valvetrain::~Valvetrain() { 8 | /* void */ 9 | } 10 | -------------------------------------------------------------------------------- /src/vehicle.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/vehicle.h" 2 | 3 | #include 4 | 5 | Vehicle::Vehicle() { 6 | m_rotatingMass = nullptr; 7 | m_mass = 0; 8 | m_dragCoefficient = 0; 9 | m_crossSectionArea = 0; 10 | m_diffRatio = 0; 11 | m_tireRadius = 0; 12 | m_travelledDistance = 0; 13 | m_rollingResistance = 0; 14 | } 15 | 16 | Vehicle::~Vehicle() { 17 | /* void */ 18 | } 19 | 20 | void Vehicle::initialize(const Parameters ¶ms) { 21 | m_mass = params.mass; 22 | m_dragCoefficient = params.dragCoefficient; 23 | m_crossSectionArea = params.crossSectionArea; 24 | m_diffRatio = params.diffRatio; 25 | m_tireRadius = params.tireRadius; 26 | m_rollingResistance = params.rollingResistance; 27 | } 28 | 29 | void Vehicle::update(double dt) { 30 | m_travelledDistance += getSpeed() * dt; 31 | } 32 | 33 | void Vehicle::addToSystem(atg_scs::RigidBodySystem *system, atg_scs::RigidBody *rotatingMass) { 34 | m_rotatingMass = rotatingMass; 35 | } 36 | 37 | double Vehicle::getSpeed() const { 38 | const double E_r = 0.5 * m_rotatingMass->I * m_rotatingMass->v_theta * m_rotatingMass->v_theta; 39 | const double vehicleSpeed = std::sqrt(2 * E_r / m_mass); 40 | 41 | return vehicleSpeed; 42 | 43 | // E_r = 0.5 * I * v_theta^2 44 | // E_k = 0.5 * m * v^2 45 | } 46 | 47 | double Vehicle::linearForceToVirtualTorque(double force) const { 48 | const double rotationToKineticRatio = 49 | std::sqrt(m_rotatingMass->I / m_mass); 50 | return rotationToKineticRatio * force; 51 | } 52 | -------------------------------------------------------------------------------- /src/vehicle_drag_constraint.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/vehicle_drag_constraint.h" 2 | 3 | #include "../include/constants.h" 4 | #include "../include/units.h" 5 | #include "../include/vehicle.h" 6 | 7 | VehicleDragConstraint::VehicleDragConstraint() : Constraint(1, 1) { 8 | m_ks = 10.0; 9 | m_kd = 1.0; 10 | 11 | m_vehicle = nullptr; 12 | } 13 | 14 | VehicleDragConstraint::~VehicleDragConstraint() { 15 | /* void */ 16 | } 17 | 18 | void VehicleDragConstraint::initialize(atg_scs::RigidBody *rotatingMass, Vehicle *vehicle) { 19 | m_bodies[0] = rotatingMass; 20 | m_vehicle = vehicle; 21 | } 22 | 23 | void VehicleDragConstraint::calculate(Output *output, atg_scs::SystemState *system) { 24 | output->C[0] = 0; 25 | 26 | output->J[0][0] = 0.0; 27 | output->J[0][1] = 0.0; 28 | output->J[0][2] = -1.0; 29 | 30 | output->J[0][3] = 0.0; 31 | output->J[0][4] = 0.0; 32 | output->J[0][5] = 1.0; 33 | 34 | output->J_dot[0][0] = 0; 35 | output->J_dot[0][1] = 0; 36 | output->J_dot[0][2] = 0; 37 | 38 | output->J_dot[0][3] = 0; 39 | output->J_dot[0][4] = 0; 40 | output->J_dot[0][5] = 0; 41 | 42 | output->kd[0] = m_kd; 43 | output->ks[0] = m_ks; 44 | 45 | output->v_bias[0] = 0; 46 | 47 | constexpr double airDensity = 48 | units::AirMolecularMass * units::pressure(1.0, units::atm) 49 | / (constants::R * units::celcius(25.0)); 50 | const double v = m_vehicle->getSpeed(); 51 | const double v_squared = v * v; 52 | const double c_d = m_vehicle->getDragCoefficient(); 53 | const double A = m_vehicle->getCrossSectionArea(); 54 | const double rollingResistance = m_vehicle->getRollingResistance(); 55 | 56 | output->limits[0][0] = 57 | -m_vehicle->linearForceToVirtualTorque(rollingResistance + 0.5 * airDensity * v_squared * c_d * A); 58 | output->limits[0][1] = 0; 59 | } 60 | -------------------------------------------------------------------------------- /test/function_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../include/function.h" 4 | 5 | #include 6 | 7 | TEST(FunctionTests, FunctionSanityCheck) { 8 | Function f; 9 | f.initialize(16, 1.0); 10 | f.destroy(); 11 | } 12 | 13 | TEST(FunctionTests, FunctionTriangleFilterTest) { 14 | Function f; 15 | f.initialize(0, 1.0); 16 | for (int i = 0; i < 10; ++i) { 17 | f.addSample((double)i, (double)i * 2); 18 | } 19 | 20 | EXPECT_NEAR(f.sampleTriangle(-1.0), 0.0, 1E-6); 21 | EXPECT_NEAR(f.sampleTriangle(11.0), 18.0, 1E-6); 22 | 23 | for (int i = 0; i < 10; ++i) { 24 | EXPECT_NEAR(f.sampleTriangle((double)i), (double)i * 2, 1E-6); 25 | } 26 | 27 | f.destroy(); 28 | } 29 | 30 | TEST(FunctionTests, FunctionClosestTest) { 31 | Function f; 32 | f.initialize(0, 1.0); 33 | f.addSample(0.0, 1.0); 34 | f.addSample(2.0, 1.0); 35 | f.addSample(3.0, 1.1); 36 | f.addSample(1.0, 1.0); 37 | f.addSample(5.0, 10.0); 38 | f.addSample(4.0, 9.0); 39 | 40 | EXPECT_EQ(f.closestSample(2.4), 2); 41 | EXPECT_EQ(f.closestSample(6.0), 5); 42 | 43 | f.destroy(); 44 | } 45 | 46 | TEST(FunctionTests, FunctionRandomAddTest) { 47 | Function f; 48 | f.initialize(0, 1.0); 49 | 50 | for (int i = 0; i < 1000; ++i) { 51 | f.addSample(rand() % 1000, i); 52 | } 53 | 54 | EXPECT_TRUE(f.isOrdered()); 55 | 56 | f.destroy(); 57 | } 58 | 59 | TEST(FunctionTests, FunctionGaussianTest) { 60 | Function f; 61 | f.initialize(0, 1.0); 62 | f.addSample(0.0, 1.0); 63 | f.addSample(2.0, 1.0); 64 | f.addSample(3.0, 5.0); 65 | f.addSample(1.0, 1.0); 66 | f.addSample(5.0, 10.0); 67 | f.addSample(4.0, 9.0); 68 | 69 | EXPECT_NEAR(f.sampleGaussian(2.0), 1.0, 0.1); 70 | EXPECT_NEAR(f.sampleGaussian(4.0), 9.0, 0.3); 71 | EXPECT_NEAR(f.sampleGaussian(100.0), 10.0, 1E-3); 72 | EXPECT_NEAR(f.sampleGaussian(-100.0), 1.0, 1E-3); 73 | 74 | for (double s = 2.0; s <= 3.0; s += 0.001) { 75 | const double v = f.sampleGaussian(s); 76 | std::cerr << v << "\n"; 77 | } 78 | 79 | f.destroy(); 80 | } 81 | --------------------------------------------------------------------------------