Home Artists Posts Import Register

Content

I managed to get the new lake flooding system to a good place. 

The first proof of concept version from last month slowed the game down every time a chunk loaded. In this new version those lag spikes are mostly gone. 

In the previous version water would appear on tiles at specific times regardless of what you placed on the tile, but I wanted to add a way to block the water so that it’s something you can interact with. If you can play with the water then it feels more like part of the game. 

The headline addition is that now water will only spread from the existing water tiles. Isolated puddles need a connecting passage to feed them otherwise if they dry out they stay dry. You can now block flooding with walls, which not only block that tile from being flooded, but also tiles behind the wall if water can’t find its way around. This means you can wall off entire sections with just a line of walls if the water can’t get around either end. If you remove the wall, then the next time there is a flood the water can go through again. The water will also follow a maze like pattern if you build one. 

A combination of technical requirements made this quite challenging because some of them are conflicting incentives. Here are the requirements:

  • Elevation based flooding order

  • Connectivity based flooding

  • Efficient during chunk loading to not cause lag spikes. 

  • Needs to work with incomplete information (e.g. chunk boundaries not loaded).

  • General running efficiency.

  • A smart caching system that doesn't bloat save file size and load times.

  • Placing walls can block flooding and invalidate sections of the cache.

  • Removing walls can also invalidate sections of the cache and enable re-flooding.

  • Needs to handle chunks being added during any part of the flood cycle. 

A lot of those things don't play nicely with each other. I spent quite a while thinking about it (why trying to sleep) for a few nights before getting to the actual code.

I achieved everything I wanted except for maybe the file size which is untested for a full size planet. 

Flooding planets are intended to be smaller, but I don’t know how much smaller they should be. It partly depends on the final map generation and how big the floodable area will be as a % of the landscape. 

Here’s a video of the flooding in action. There’s no smoke and mirrors here, just direct game capture of a new game. 

https://www.youtube.com/watch?v=dx-G-DDsJ0g

Following what happens in the video:

I’ve just started a new Space Exploration game, enabled cheat mode, equipped a thruster suit, and run a command to launch 10 satellites to discover some planets in the system.

During the video I run a command to teleport to Gardinia, which is a planet in the starting system that did not have a surface generated. The surface is generated around the character, so you can see that nothing was prepared ahead of time and all the calculations for flooding are being done in realtime as the chunks are being generated. You can also see the FPS and UPS counters while this is happening. To stress the system I go north west to an area that I know will have a lot of tiles in the floodable height range. 

You can see that the flood waters are receding as the chunks are loading. The waters recede purely based on elevation so even if an area gets cut off from the main lake the water is absorbed into the earth or evaporates.

As the water returns I wall off 2 areas on the western edge of the large lake. One section of wall encloses an area of floodable land which will be protected because it’s walled from all sides. Just to the north of that I block a valley with a line of wall, which won’t get flooded even though it’s an open wall because the land on either side is too high. 

Then I move north to watch the water spill into a canyon. As the water is rising it can only flood areas of a certain elevation so usually the progress is slow. The canyon is higher elevation in the middle so when it spills over that it can spread rapidly into the depression on the other side. 

Then I return to the western edge and confirm that the walled areas were protected.

Next I wall off the canyon to show that a huge area can be blocked from flooding with a small wall, and continue to wall off some other areas. I also make a U shaped barrier to show that because these walls don’t go to the edge of the floodable area, the water will go around them. 

Next I start to make a little maze for the water to follow, showing that it doesn’t just follow its original flood path.

Then I increase the game speed to 4x to see the floods happen faster. The ups is steady at 240.

Then I break the dam into the northern flood region to make another maze and the flood waters rush in.

Next I put the game speed to 100x to see what the max ups is. It fluctuates between 1060 and 780. This is a fairly small area of loaded map, however the whole cycle is currently set to 1 minute (in 1x speed) but really it would be cycling once every 10 minutes or more so the real UPS impact would be much lower. 

Finally, I start flying around trying to show new areas being added to the already running system. I find an area that’s generated white the flood waters are rising and the flooding won’t continue across that border until the next flood cycle, so I hang around to confirm that it corrects itself in the next flood.


Files

Comments

Andreas

So awesome! Tidal stream generators?! Battery which gets some charge whenever a nearby tile changes type

Sasa

Seeing this actually run in the Factorio engine is a wow moment on par with my first spaceship. Hot damn.