# ~~Managing Voxel Water~~ (now with vids and source)

This topic is 2564 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I'm working on a Textured Voxel engine (C++ OpenGL) with game-play similar to http://chir.ag/stuff/sand/ but in 3d.
Basically a Particle (Voxel) reaction sandbox.

I'm not really having trouble at code as much as figuring out how it should work.

EDIT: Problem has changed check post #11.

<Old Method>
Before each water block had it's own amount. Then it just checked if the adjacent block had less, if so then it gave it 1/5 of it's water.

<New Method>
Now I am recoding the water part of the engine so that the water stays level, to make it more smooth and better looking.

My game is structured as follows:

The World is made of multuple chunks.
Each chunk having a 16x16x16 array of blocks.
Each chunk now has multiple LiquidBodys or lists of water.
Each liquidBody has one Water level so all blocks share this (average amount of all blocks in list to stay proportional)

Here is a Visual of my current problem:

The problem is, sometimes the player can create a liquid body in one chunk and then have it connected to a liquid body in another.
Since the liquid bodys are contained in the chunks I cant just add another chunks blocks to the others list.
All that they have to share really are the WaterLevels.
I was thinking linking thier waterLevels somehow. However this will not work with more than 2 chunks, because as seen on the right
side of the map the linking would form a circle, this may be even worse with trees.

I guess this is one of those cases where you have to come up with an out of the box solution.

Does anyone have any ideas?

##### Share on other sites
What is the problem exactly? Why are you not able to allow this? What harm does it cause if players do this?
Why cant you store the water exactly as you store the ground? Do you have a problem when the ground between the grids connects? If not, then why would water cause a problem?

##### Share on other sites
The water is added to the list so that when the waterLevel changes all the blocks are updated very quickly, because they must keep the same waterLevel.
The LiquidBody's are allocated by the Chunks. So the problem is getting one chunk's Liquid Body to update ones that are touching in other chunks.

##### Share on other sites
if you can detect when multiple liquid bodies get connected just average their levels an apply that value to all of them.

##### Share on other sites
Treat water just like land. If you want to make sure the surrounding water has the same level, then when ever a water block is created, do a check of the surrounding blocks to make sure they are the same level as the one being inserted. Then continue these checks until all the water is the same level. This will require a couple of extra checks, but how often are people going to insert water? There shouldn't be a problem with a few hundred extra iterations of a loop that is going to be called once every minute.

If this function is going to be called every game loop, then you can be concerned about it, but for insertions such as this, optimization should be last on the list of things to do because it doesn't matter how much you optimize it, there will be absolutely no noticeable difference in speed.

##### Share on other sites

If this function is going to be called every game loop, then you can be concerned about it, but for insertions such as this, optimization should be last on the list of things to do because it doesn't matter how much you optimize it, there will be absolutely no noticeable difference in speed.
[/quote]

I have the water working as you mention right now, I'm trying to get away from that.
It does get very slow once you have alot moving,
Also causes major problems when they place 2x2 water blocks and 3 have 5/5 water and the other 3 4/5.
The problem is the time it takes to update per step increases exponentially.

This is really hard to explain, I have the game online so anyone can try it out, it's here:

Registering for a beta account is required though, the invite code is "bl0ck" without quotes ofcourse.

The best way to see this is to create a path of water from the ocean threw the land. You can place lava to turn the water to steam at the end of the path, so it will keep requiring updates.

##### Share on other sites
How are you calculating the water level?

##### Share on other sites

How are you calculating the water level?

 //Init waterLevel=0.0f; //New block added //amount = amount of new block waterLevel = ((waterLevel*(list.size()-1))+amount)/list.size(); //same as waterlevel = amount/Blocks 

##### Share on other sites
I really fail to understand your problem. When you connect two or more liquid bodies you just add up more level to those who has less and remove from those who have more. If your problem is iterating your blocks at the time of adding/removing large amounts make that operation a task that runs over various iterations.

• 11
• 20
• 12
• 10
• 38
• ### Forum Statistics

• Total Topics
631400
• Total Posts
2999862
×