1
\$\begingroup\$

I am making a 2d block based sandbox game like terraria.

I'm trying to think where is the better place to store water in, data structure wise.

That is, to store it in the block world array, or to store it in its own sparse data structure. Does doing this have any benefits?

If I store it in the world array I have to store the fluid level (which would be like 16 levels possible). The other way I could simply have a fluid cell struct or something.

It might make things more clear separating it, but not sure if it would possibly affect performance either way.

In a game like this, the simulation is of course usually done via cellular automata (just in case that affects which data structuring I should use)

\$\endgroup\$
  • \$\begingroup\$ What do you mean by 16 levels possible? \$\endgroup\$ – jgallant Jun 21 '16 at 11:26
  • \$\begingroup\$ Tiles are 16x16px, so I'd want 16 levels of water. That part isn't really important though, point in not sure about is to store water in the block array, and end up using a "per block flags" which might have something like how much water is there, or if it's not water..some other data. Or to separate it entirely from the block world. They seem to each have their trade offs ,with separating making it potentially cleaner. Not sure if it could improve performance though. \$\endgroup\$ – Fruatis Jun 21 '16 at 15:57
  • 1
    \$\begingroup\$ You can store a float value in your tile class (0 to 1) and then draw the water based on this value. (You would scale the sprite down based on water value contained in the tile). \$\endgroup\$ – jgallant Jun 21 '16 at 15:58
  • \$\begingroup\$ Float is too big. We're talking each tile has maybe 5 bytes, one of which can be used for water level or any other future block levels some block I add may need to store(can't think of any right now tho). Anyways that's not the issue. Bit manipulationis easy, I'm just not sure if fluids belong in the world block array or if they should he separate,which might make things like multithreading easier, or something. \$\endgroup\$ – Fruatis Jun 21 '16 at 16:00
-1
\$\begingroup\$

Gonna go with manipulating bits to store it in the world array like most do. We'll see if it has its trade offs

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.