Share your repls and programming experiences

← Back to all posts
A little simulation of sand particles in a terminal
axelduch (21)

Prototype to make later on a game in a terminal, sandbox like.
It should be working with most compilers, for linux, mac etc.

To see it working you should go to the follow the link to the code and

open a terminal (ctrl + shift + p) and "open shell"

theangryepicbanana (1536)

Looks pretty cool however you could change your code a bit. If you have multiple members/variables of the same exact type, you can just do int a, b, c instead of int a; int b; int c;. Also, why do unsigned _:1 instead of bool _? Seems a bit odd. Lastly, you can use the puts function instead of printf if you just need to print a string with a newline.

axelduch (21)

@theangryepicbanana I organized my variables by "topic", x and y are of the topic "abstract position", screen_x and screen_y are about "rasterized position", it's really just a personal choice.
Also, I am using bitfield instead of bool inside this struct because there will be more flags added soon, for memory packing purposes I intend to keep it that way. In my local environment I am spawning 200 000 particles, and this amount of storage is significantly reduced when storing bitfields contiguously when memory is properly aligned. Althgouh I will use puts instead, thanks for the feedback!

theangryepicbanana (1536)

@axelduch ye no problem. Looked pretty solid so I decided to look at how you made it. very nice stuff