Skip to content

E2 optimization examples

Deyan Dobromirov edited this page Jul 23, 2020 · 6 revisions

Optimization example for number num driven pistons markers

The internal sign-timed functionality calculates the piston reaction forces trigger just like the described function function number doPiston(A, R) with the difference that force condition is a separate function assigned during piston creation. The E2 interpreter setups the B and IF values only once and uses them in the dedicated conditions A > 0, A < 0, and A = 0.

For better performance consider combining pistons with the same initialization parameters. To do that please take a look at T4 and T9 their both top origin crankshaft angle is at 0 degrees, so you can simply do T9 = T4. When using the piston timing generation library, the example above can be optimized easily.

If you need to take this thing further please take a look at piston ID tuples 1 > 6, 4 > 2, 3 > 5. Since these tuples are 180 degrees apart, finally you can end up with only 3 timings as (+/-)180, +120 and -120. You can do T8 = -T1 (As T8 is bind to timing 6), T4 = -T2 and T5 = -T3.

Congratulations! Now you have a W18 engine with only 3 timings!
You can play around with this system using the W18 Napier Lion engine dupe here.

Optimization example for vector vec driven pistons markers

First of all, you can see how to create vector driven pistons that use cross-product timings, that give the same result as sinewave timing but are less hungry for your E2 chip performance. A typical code example can be found here, where the global axis, marker, and base entity are used for the given E2 chip, so the piston allocation can be created via a unique key and a dedicated marker vector. The same optimization rules apply here as well, regarding the different data type, as a vector can encode direction and magnitude. Opposite vectors will result in negating the piston force, as well as pistons with the same marker vector having the exact same output force. The vector equivalent E2 can be found here.