Piero V.

Back to Rust again

In 2010 I tried to program a video game with a friend for the first time. And it was our first time with C++, too. Of course, it was C++2003 since C++11 was the new-not-yet-stable thing.

I must say that our approach was quite naive. For example, we thought we would always play the game on a LAN. Thus, we never worried about lag compensation.

Now, a few years have passed, and I have learned a thing or two, even though I still have to finish a game project.

So, at the beginning of this year, this friend pushed me to learn Rust, and I decided to learn it through game development again.

At a certain point, I decided to use a physics engine, and I found Rapier. I was especially interested in its determinism to finally implement a lag compensation mechanism. But I did not understand how to use it correctly. Only recently, I understood it favors an approach similar to functional programming, whereas I was trying an OOP-like approach. This also led to fights with the borrow checker. So, because of these problems and my usual decrease in interest and focus, I left yet another project incomplete.

In many years as a programmer, first, as a hobby, then as a computer/telecommunication engineering university student, and finally, as a professional, I had never heard about functional programming. I stumbled upon it while studying for my Engineering state exam a few weeks ago (maybe, the only good thing of preparing that exam). I immediately found it interesting and started thinking about my Rust game project again.

Basically, my idea is that if I can manage to write the update functions to take the previous state, clone it, update it and return it, going back and forward in ticks should become easy.

Also, in these months, Rapier implemented a kinematic character controller. That is a complete game-changer (pun intended 😄️): this component is as important as difficult to get right.

Rapier’s needs to be integrated because it lacks the management of vertical movements, like jump and gravity. Still, it deals with obstacles, slopes, snapping to the ground, and stairs… which is a lot, to be frank. So, I am very happy it has been developed and extremely excited at the idea of playing with it.

A guy called Nicholas Maltbie wrote a character controller for Unity and provided a lot of documentation. For example, he suggests to implement “coyote time” to make jumping less punishing. Another great idea he implemented is jump-buffering: if a player hits the jump button before reaching the ground but does it within 2 or 3 frames, the jump should be executed anyway.

So, I went back to programming my project, and I also tried OpenGL with Rust. I must say OpenGL is not a great API, but Rust makes it even more terrible with too many unsafes 😅️.

But still, I am curious to see when I will be fed up and stop this time 😂️.