Engine RPM Curves (Devlog #3)

After refactoring my engine audio implementation, I decided that It would be beneficial to have variables exposed on the two different ship classes that would allow me to adjust properties such as RPM curve and interpolation rate.

I began by researching for methods to transform a given X value into its appropriate Y value along a defined slope. This lead me to a comment by Ângelo Polotto outlining a solution for this exact transformation. With some minor adaptations, I was able to use this function to transform a linear value to one along a SQRT curve (See more below).

Jupyter Notebook and Matplotlib were essential in testing different curve functions before implementing them in C++. Jupyter Notebook is an interactive web-based platform that allows me to write and execute Python code, using this with the Matplot library I was able to compare different curve functions such as linear, quadratic, exponential, logarithmic to evaluate their appropriateness for and RPM curve. (Huge thanks to Tadej Lahovnik for helping me with the learning process).

After testing various functions, I decided that (as previously mentioned) a SQRT curve was most appropriate. After ensuring the function was sound and operated as expected within my range of possible values, I translated the Python code into C++ to be integrated with the rest of my methods in the ShipAudio class.

Implementation into my existing RPM update function was very straight forward, just assigning the “SpeedRTPCValue” variable to a conditional operator between two variations of this new transformation method. In the case the engine was in a “OnLoad” state, the RPM curve would be set to the one defined in the relevant Ship class, otherwise the curve was set to linear for a consistent “OffLoad” RPM ramp down.