Lets talk ice. and how to implement it

Hi all, i woke up this morning in a fey mood :stuck_out_tongue:
and since the netherlands is burning to a chrisp because we have too little rain:

lets talk ice.

stonehearth doesnt have it, but i feel it should.

how could we acomplish the freezing over of water when winter hits?

the “cleanest” way i could think up was have some form of script run when winter hits, look at the topmost blocks of water that can see the sky, drain the water from those blocks and replace them with a minable “ice” block.

same but in reverse for when the ice has to melt again. (and assume it was a FULL block of water)
(bonus points would be making the process a transfer over time so as not to overload the system by changing 10.000 blocks at once…)

this way

  • it would only run the check at the start of every applicable season: acceptable amounts of stutter (4x per in game year max)
  • if water froze over, but you still wanted to see some for aesthetic reasons you could chop out some blocks, on melting, because the the game would assume all ice blocks are filled with water, the first time around your lakes level may decrease slightly. but next time it freezes over and you -dont- mine it it would recover. should ballance out in my idea.

how to do it this way: lua wizardry beyond me @RepeatPan level? maybe :stuck_out_tongue:

i had thought up a hacky slapdash way in which lakes would have to spawn with the top layer filled with “fake air” blocks with no collission that would spawn water on their spawn, and in winter drain the water and change in collor to ice and turn solid.
(downside would be no building on lakes because the fake air blocks are in the way) so thats not much of a sollution.

5 Likes

no clue about what you’d do about the actual implementation for the rest of it, but this part is pretty easy AFAIK – just give each chunk a chance to freeze/melt in the appropriate cycle, and have any chunks which haven’t melted/frozen yet keep trying to do so once every n ticks (in-game hourly, daily, or whatever.)

Not only does it break up the load on the processor (assuming you have the chance to freeze/melt happen first – if the dice roll comes back “no”, then that chunk doesn’t need to be included in the freeze/thaw calculation), it also gives a pleasant and believable effect where water freezes slowly and in patches just like IRL.

2 Likes

Well I know there is some way to check if a block can see the sky, and I assume some code could be borrowed from the dry and wet stones… But I have less then no idea how to do this across the entire map

Can you check adjacent blocks? Another way to do freeze the water in iterations could then work by not only looking for water blocks seeing the sky but also beeing adjacent to non-water blocks (including ice blocks). This way a lake would freeze from the shore to the center.

3 Likes

Would make it look good, but would take a bunch more checks, and also multiple times because the situation would change once some blocks got turned into ice. Pretty, but probably a resource hog
(I remember back when Minecraft got developed and not run I to the ground by M$ they ran In to the same things)

A problem (or at least a design decision that needs some thinking) is how the ice should react to changing water levels. If you drain a lake when it’s frozen, should the ice stay in place? It could form some pretty cool ice caves, but what it only parts of it is frozen? What if a piece of ice don’t have any connection to the shore? Should it still stay in place as a flying block? If it’s done with terrain blocks it will.

i’d say yes. when summer/spring hits and it melts the water will jsut fall down and and fill the gap.

unlikely to happen naturally (water will equalise its level, ice will keep that level. if you get floating ice its 99% sure man made, and thus not our problem.) simply put: no flying water, no flying ice.
it -might- happen on waterfalls now i think about it but not sure.

So, random thought I had…

Is it better to make ice a terrain, or an entity?

Having it as a terrain allows really awesome landmarks, makes mining the ice quite easy to sort out, and is probably less CPU-intensive (at least once the ice has been generated.) On the other hand though, it requires more systems to add and remove terrain – landmarks are probably a good place to start since they add and remove terrain already.

On the other hand, making the ice an entity (much like trees) has its own set of pros and cons. The biggest pros I can think of are that there’s more precedent for working with entities in the scenario editor (it’s possible to do the same with terrain, but there are less use-cases and we don’t know the limits of the system yet); and that it would allow more detailed/interesting ice (transparency for one, and you’d have the option of using a variety of ice models or sticking with simple blocks which mimic the terrain.) The down-sides include likely more processor use, the fact that you’d have to “harvest” the ice to mine it, and the fact that it wouldn’t count as terrain for things like placing zones or planting things on it (although this doesn’t sound like a bad thing TBH… you wouldn’t want to plant farms or herd animals on an ice lake any more than you’d try to plant a tree on one lol.)

Another benefit of entities over terrain is that they can be transformed into other entities – which might solve the melting problem. When it “melts” the ice could turn into a sort of temporary wet stone, or even a summon stone where the summoned terrain is simply a large cube/volume of water.

2 Likes

most defnitly terrain. it cant be one entitiy (irregular shapes)
and having the world covered with a trillion ice-entitiy-blocks would cause too many damn problems (not least of which the mouse-over-outline…)

the landmark system can just put down a “block” of water. or even a half block. so there is your melting.
code wise to turn ice to water it would the the worlds largest CTRL-F replace :’),
funilly enough if we did the same sky check there, and a player would have covered the ice from the sun, it would stay ice. ice sculptures could be made by clever building of moulds and covers.

ice caves could be done too, frozen year round (landmark system, easy mode once we have ice). (good for cold storage)?

3 Likes

I just thought I’d throw a thought out there, as it popped into my head wandering through this. I’m not a modder (I want to, but I don’t want to dive into a pile of resource material without someone to guide me), however. I wanted to make sure you guys keep in mind wetstones in this whole equation. If someone has build a waterfall and river that flows through their town and have a drystone at the end… What happens if parts of that freeze? The wetstone overflows and spills water everywhere, not only creating unnecessary ice blocks in the process, but making a pretty huge mess until spring time rolls back around. If I may make a suggestion in all of this, the easiest way to bypass this would be to make wetstones stop work once the winter (or freeze season) rolls around, and then start working again in mid-spring or summer (so the ice has time to fully melt if it is still blocking off your channels. Of course there are other ways to bypass this and I’m sure you’ll figure something out. :stuck_out_tongue:

1 Like

Good idea!

(also, I’m usually game for helping people make/mod their first item, that usually teaches them enough to teach themselves more :))

There were various reasons why Frostfeast did not incorporate ice:

  • It’s not possible, or was not possible, to have translucent terrain blocks. For me, this is a deal breaker. Ice isn’t just some glittery, blue-ish stuff, it’s supposed to be transparent.
  • Because water bodies are all cuboids, you would have to perform (expensive) checks on what cuboid is actually the top-most body, and which one is touching air. Not all water freezes to ice, only the top layer. This could be done, but:
  • There need to be various re-checks on where ice should be. If you drain a lake, for example, periodically the ice should re-form, and existing ice may drop lower as a result. However, the dropping bit is complicated, as is the re-checks.
  • What happens if you pour water onto ice? It either increases the thickness of the layer, or it flows through and lifts the layer up. Both are non-trivial to implement in a nice way.
  • What about heat sources? Frostfeast had a concept of heat sources, and it would be weird to not honour them for ice. We didn’t for the terrain because we could, somehow, pretend that it was generally devoid of color due to the light, and because of engine limitations. If you had dynamic, growing water, players would expect the water to disappear because of heat, too.

All in all, given the engine limitations and the bad performance to start with, I didn’t think it was viable, or possible, to have an implementation of ice that’s up to my standards. And as with quite a few features for Frostfeast, it was therefore canned.

3 Likes

@RepeatPan

In response to transparency, @DaniAngione made a glassworks mod with some form of this, though he also has a coremod to go with it, so it might have taken extensive work for all I know. We may be able to talk to him about that

In terms of freezing the top layer of ice… As stated, I’m not a modder, but I have a bit of programming-ish… Something I’ve noticed in-game is that the most bodies of water are not full ‘cuboid’ in the top layer, there is almost always some amount that is less than a full block on the top:

In my mind, when I think of how the water physics in this game work, (which I could be completely off, so bear with me) when a lake is filling up, it would have to check the block below it to see if there is a water block or a solid block… If the water block takes up the entirety of the space it’s provided, then it would be treated like a normal block and the new water would sit on top of it… Now… If this is how, or somewhat similar to how it works… All of this does not matter in the creation of ice, however… It simply paves way for the following:
If water blocks can check if water blocks below them are ‘full’ that means water blocks may have some form of ‘value’ we could exploit to reduce the checks. Specifically, if a water block has a value that is less than full, then it’s probably a top layer block and can freeze. Now if there is a way to keep track of this value so it unfreezes the same amount of water, I dunno.

Regardless, this, if it is plausible, could reduce the checks as its not looking for anything specific or special, just water blocks that are less than one.

In response to heat sources… Is there a way we can ‘Minecraft’ it? If ice is near a light, it melts?

Is any of this plausible, or am I just blabbering?

My Glassworks mod applies transparency to objects, however. Not terrain blocks :merry:
So RepeatPan’s point remains. I think it should be possible, however, by creating a new voxel terrain block shader. Would be a lot of work, however.

3 Likes

Hmm so if ANY of this is going to work, that’s Basicly going to be needed because as @RepeatPan said: semi transparency or bust.

2 Likes

I know semi-transparency is required, but I have a question.
Lets act like we didn’t care about transparency, which we all do :P. Would it be possible to turn the ‘ice’ block into the same color as the ‘water’ block?
Secondly… I’m guessing water is not considered a voxel? Cuz it’s transparent?
Or… Hmmm. Bear with me My thought process is really janky
What if ice was it’s own form of ‘water’? Is that possible? Like, a makeshift fluid block?
I ask this because, if it i possible, maybe we can still do this by turning the less-than-one water blocks into an ice block with the same value… If we could edit water properties, maybe we could even make it seem solid in the eyes of a hearthling?

Entities can be transparent, but the terrain cannot. It’s sadly very limited.

I’ve said cuboid, I’ve never said that it had to be full voxels. The water is using a custom renderer, so it can have partial blocks in height. I’m not sure if the terrain itself actually forces you to go full blocks either. But they’re still cuboids: If you had, say, an L-shaped water body, there would be a least two cuboids - depending on how they were formed, and if they were merged. I haven’t dug into the hydrology service that deep.

The hydrology was based on two premises: Bodies, and channels. Bodies are cuboids of water, which have a defined size in a 2D plane, and a height. The height varies with the volume of water that’s inside. Channels move water from A to B.

So yes, while they can find out what’s below, this means quite literally searching for an entity below that has a water component. I’m not saying it’s impossible, but it’s not exactly nice on the performance.

The same applies to a Minecraft approach too. Minecraft just has to check if the voxels next to it are of a ceratin type, then melt it. Although it looks like it, SH is not voxel based. Water bodies are entities, freely placed wherever. Searching for water bodies (or ice bodies) nearby would mean iterating through the whole terrain - repeatedly.

I mean, it’s plausible, it’s doable, but the effort to implement it, the constraints you have to work against, and the likely performance impact it would have all mean that to me, it’s not worth pursuing.

FF15 was way before there was any kind of glittering, so it might be possible now with a translucent shader. However, this also (likely) means that it’s either a full block of ice, or none - nothing in-between (unlike water bodies themselves are).

Water is rendered specially using shaders. I don’t think there are many, if any, ways to influence terrain rendering in a significant way. Anything that has to do with rendering was usually neglected when it came to APIs. For Frostfeast, for example, I’d really have liked to have influence on the cubemitters - the colder your hearthlings got, the more visible the breathe becomes.

You might be able to make it as an entity, yes, but I’m not sure if the pathfinder would like that. I would assume it’s optimised on terrain operations, not entity “bridges”. It basically means you have a lot of entities with a lot of colliders, and I’m not sure what the performance on that would be.

2 Likes

There is one huge reason why ice is a no-no.

  1. Wait for the lake to freeze.
  2. Built a castle on ice.
  3. Wait for the lake to thaw.
1 Like

Thanks for clearing a lot of that up for me. As stated, I don’t know a lot on how the game functions, I’m just throwing thoughts out there and seeing if they tumble.

Yeah, no worries. There’s a few things SH does differently than usual games though. If you have the time, I recommend checking out the hydrology service’s lua (if it’s still called that). I think the code was documented last time I saw it, and it wasn’t too hard to follow either.

For weird reasons, I think the water in SH is still an odd one. It’s seemingly well done, has features and behaviours you wouldn’t expect (or normally find) in such games, and was done quite early on.

1 Like