Categories: GuidesValheim

Chunked and threaded saving

Disclaimer: this post gets technical. I do not claim to know how the current implementation works, I was just thinking about how I would implement it.

With any game with building elements like this, the saving process can become a challenge to optimize. Players are virtually unlimited in the modifications they can make, and all of that has to be recorded. I'm a big proponent of changing the terrain manipulation to a data centered design instead of an object oriented one (and I love OOP). The challenge with that would be that you then have to save out the bitmaps containing all player made changes. It is sort of a trade off; an increase in initial memory requirements and save operations in exchange for scalability of player manipulations.

So how do we reduce those upfront costs? This got me thinking about how the game saves. It would appear that the whole world is saved down into one file, a process which takes longer the more manipulations takes place. What if the was saved in chunks? Any chunk that had active simulation (that is a player was close enough for things to happen) would be flagged dirty until the next save event. That way only the dirty chunks would have to save. So your network of bases wouldn't need to update its saved state while you are out exploring for an hour, because the game knows you haven't touched them.

Additionally, this opens up the possibility for threading. If the process is already divided by chunk, those can be executed on separate threads (you only want one thread doing the writing, but the rest can format the data and queue up the commands). The chunks that are being simulated still need to be saved from the main thread so that data errors do not occur, but for inactive areas that have been visited since the last save this may produce speed-ups. While I presented the idea as a solution to the volume of data that would be used for bitmap terrain manipulation, it would be just as applicable to the current implementation.

Anyway, this has just been a rough idea. If anyone with more experience with this sort of thing could chime in, I would be interested in the input. I do a lot of Unity dev, but not really big open world stuff with a lot of state to save. So I find this problem interesting and refreshing.

Gamer

Share
Published by
Gamer

Recent Posts

Ledx have been so hard for me this wipe

Not being able to craft them sucks. Especially when everyone I talk to about it…

11 months ago

My interesting and unfortunate Gwent life

First I'd like to say I absolutely love this game it's quality. Basically I first…

12 months ago

Teacher Tuesday 12/Dec/2023 – ask your questions here!

Welcome to Teacher Tuesday, a thread where anyone can ask any type of question without…

12 months ago

This games balance is confusing

I’m kind of new/returning to gwent I played beta and obviously it’s a lot lot…

12 months ago

Summary of 10 Days of Draws from Chaffee’s Bundles

Level 1 Bag (Free with Atmosphere Level 2) 6 small consumable (First Aid, Repair, Fire…

12 months ago

Why is my crew at 135%?

Here's my crew - T34-85M - for the life of me I cant figure out…

12 months ago