<html><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">I am currently working on a simple 2D game engine using raylib, all good.<div>I'm implementing a tweening library based on -the- easing equations by Robert Penner.<div><br></div><div>The ones I need I have implemented, but I don't think I will need the complete set. On implementing the easeInBounce, easeOutBounce and easeInOutBounce, using this as my guide, the raylib Rust easing source: <a href="https://docs.rs/raylib/latest/src/raylib/ease.rs.html#242-256">https://docs.rs/raylib/latest/src/raylib/ease.rs.html#242-256</a> , I noticed that there are some constants which I decided I didn't want to have to recalculate at run time.</div><div><br></div><div>In a game loop, anything you can do to save pointless repetition means more rendering time between frames.</div><div><br></div><div>This MIGHT be over eager optimisation I guess as all I am doing at the moment is a simple proof-of-concept for a 2D engine which I will then port over as the core of my transpiler IDE I have started.</div><div><br></div><div>Here is what I ended up for as the implementation of easeOutBounce, I decided to use the apostrophe naming rule so that the code reads like the source code, and I also did this because I wasn't really sure what those constants are for, I have a rough idea but I couldn't decide on an effectively communicable name for the source so I opted to call them what they do!</div><div><br></div><div><br></div><div><div><font face="Courier New">tween_(bounce_out, Time, Range, Duration) = V :-</font></div><div><font face="Courier New"> Percent = Time / Duration,</font></div><div><font face="Courier New"> ( if Percent < '1 / 2.75' then</font></div><div><font face="Courier New"> V = Range * n1 * Percent * Percent</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New"> else if Percent < '2 / 2.75' then</font></div><div><font face="Courier New"> Td1 = Percent - '1.5 / 2.75',</font></div><div><font face="Courier New"> V = Range * ( n1 * Td1 * Td1 +0.75 )</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New"> else if Percent < '2.5 / 2.75' then</font></div><div><font face="Courier New"> Td1 = Percent - '2.25 / 2.75',</font></div><div><font face="Courier New"> V = Range * ( n1 * Td1 * Td1 +0.9375 )</font></div><div><font face="Courier New"> else</font></div><div><font face="Courier New"> Td1 = Percent - '2.625 / 2.75',</font></div><div><font face="Courier New"> V = Range * ( n1 * Td1 * Td1 + 0.984375 )</font></div><div><font face="Courier New"> ),</font></div><div><font face="Courier New"> trace [io(!IO)] (</font></div><div><font face="Courier New"> io.format("bounce_out: %f\n", [f(V)], !IO)</font></div><div><font face="Courier New"> ).</font></div></div><div><font face="Courier New"><br></font></div><div><font face=".SF NS">The above code then make suse of the following constants, I read somewhere that small functions are automatically inlined (but not 100% sure I read it) so I explicitly made then inlined, the idea being that at runtime, referential transparency would be applied, like in Haskell...</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New"><br></font></div><div><div><font face="Courier New"> % Bounce constants.</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">:- pragma inline(func(n1/0)).</font></div><div><font face="Courier New">:- func n1 = (float::out) is det.</font></div><div><font face="Courier New">n1 = 7.5625.</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">:- pragma inline(func(d1/0)).</font></div><div><font face="Courier New">:- func d1 = (float::out) is det.</font></div><div><font face="Courier New">d1 = 2.75.</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">:- pragma inline(func('1.5 / 2.75'/0)).</font></div><div><font face="Courier New">:- func '1.5 / 2.75' = (float::out) is det.</font></div><div><font face="Courier New">'1.5 / 2.75' = 0.5454.</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">:- pragma inline(func('1 / 2.75'/0)).</font></div><div><font face="Courier New">:- func '1 / 2.75' = (float::out) is det.</font></div><div><font face="Courier New">'1 / 2.75' = 0.3636.</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">:- pragma inline(func('2 / 2.75'/0)).</font></div><div><font face="Courier New">:- func '2 / 2.75' = (float::out) is det.</font></div><div><font face="Courier New">'2 / 2.75' = 0.7272.</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">:- pragma inline(func('2.25 / 2.75'/0)).</font></div><div><font face="Courier New">:- func '2.25 / 2.75' = (float::out) is det.</font></div><div><font face="Courier New">'2.25 / 2.75' = 0.8181.</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">:- pragma inline(func('2.5 / 2.75'/0)).</font></div><div><font face="Courier New">:- func '2.5 / 2.75' = (float::out) is det.</font></div><div><font face="Courier New">'2.5 / 2.75' = 0.909.</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">:- pragma inline(func('2.625 / 2.75'/0)).</font></div><div><font face="Courier New">:- func '2.625 / 2.75' = (float::out) is det.</font></div><div><font face="Courier New">'2.625 / 2.75' = 0.9545.</font></div></div><div><br></div><div>My question is simple this: is what I have done 'ok' or is it a diabolical insult to all that as beautiful and holy in the Mercury world?</div></div><div>Could I have used some other aspect / feature of the language?</div><div><br></div><div>Thanks</div><div>Sean</div><div><br></div></body></html>