r/howdidtheycodeit • • Jun 07 '22
Question How do space games handle the scale without loading screens?
I can think of a few examples of Space games with seamless planetary landings. (No Man's Sky, Elite, Space Engineers, Starlink.) How do these games handle the scale involved with having a large map that feels like the surface of a planet, but then allowing players to move to what is essentially a much, much, larger map around the planet?
I've seen some references to techniques used in this, such as: scaling by powers, and floating point operations. The explanations tended to dive into the maths and lose me pretty quickly. But I was wondering if there's a general approach that someone could ELI5 for me?
56
u/SoapyMargherita Jun 07 '22
A couple of things from my very vague knowledge:
3
u/shengch Jun 07 '22
Sebastian lague has a short series his process making a little game where you fly around the planet delivering items to cities.
He goes over how to optimise everything.
But that's for actual modelled planets like earth where we know what it should look like.
Games like elite use procedural techniques to load information as you approach locations, so not everything is stored in memory at once.
2
u/scifanstudios Jun 12 '22
For my game i created a separate coordinate system with a float value as meters and separated km, miokm and lightyears. The camera stays near the 0,0,0 coordinate. Behind that area they will logarithm scaled and moved closer, so its the same look for the player, but is actually closer in the scene, to prevent floating point rounding jumpings.
I have not yet needed to handle far away objects like small spaceships far away on another planet, but i think i will keep in one scene and spawn or remove entities/gameobjects from the scene, if they get visible.
15
u/Nephophobic Jun 07 '22 edited Jun 07 '22
Regarding seamless loading of huge objects (think planets), it's very similar to how Google Earth does it. Basically the whole surface is a huge spherical quadtree (in most implementations), and the details are streamed when they're needed.
I implemented a terrain renderer using CDLOD, for which you can find two reference implementations (one of which is streamed) as well as the whitepaper here. Note that both projects can be compiled using Visual Studio but it requires some native libraries and you'll need to tinker with the include directories/linker settings in Visual Studio.
Then once you get the general concept between CDLOD (which is "simply" quadtrees, vertices morphing, and LOD selection), you can apply it to planetary shapes.
There are a lot of implementations/blogposts online, with either CDLOD or Chunked LOD (which is another method I didn't cover in this comment) :
But before trying to implement anything for spherical/planetary things, I'd recommend implementing the algorithms for plain old flat terrains, because it can honestly be overwhelming to implement, and making things spherical can only complicate things.
21
u/farox Jun 07 '22
There are some good answers here on how those are generated, but just to add on how they do it without loading screens... they don't necessarily.
A lot of times what you see in games as something different is actually a loading screen. For example in 1st or 3rd person game when you have to crawl or squeeze through some space, simply pushing a button to move forward, the game uses that slow down to load the next section.
Same for No Mans Sky, all the fancy animations of entering atmosphere or traveling in space when you vision gets warped, that gives the game time to figure out what to load and render next.
That is besides content streaming etc. Just to say, there is a whole lot of smoke and mirrors.
A little bit more mathy stuff... with a regular floating point number you can address a space of a few kilometers. With 64bit you can address a space a bit larger than our inner solar system. (up to the asteroid belt, IIRC).
So one thing that games (and applications that work at scale) do is using a floating origin, where you decouple the space you're in right now from the general universe. So the player has their own coordinate system and you calculate between that and the rest of the universe.
Based on a true story, Netflix actually did a Series on a start up based on some of these ideas: https://www.netflix.com/title/81074012
9
u/nvec ProProgrammer Jun 07 '22
There was a similar question a while back where I put a fairly long reply on how I'd build a space system.
For procedural planets in NMS and similar the technique is similar in that it's all based on chunks which can be generated at different detail levels as needed, and then forgotten about when they're not. These rely on noise functions which are similar to random number generators with one important difference- if you want the 100th number then an RNG will need to generate all 100 numbers but a noise function can just jump straight to 100th without needing to calculate the others. Combined with some filtering this gives results such as Perlin noise lets you create a random-looking organic 2d/3d grid which can then be the basis of building a tile, and as noise functions can jump straight to any number you can create only the tiles you need on-demanmd without needing to compute those before it in the sequence which is exactly what you need when you want to render only the tiles round the player.
2d noise functions can easily be used for things such as heightmaps, while a 3d noise function modified by distance to planet centre will give a decent bumpy planet with some caves, adjust the noise functions and the way they're combined and you'll get different types of planet.
There's a nice GDC talk about noise functions here, and if you're interested in trying things out there's an Open Source noise library written by a No Man's Sky developer here.
1
u/[deleted] Jun 07 '22 edited Jun 07 '22
Thank you, everyone. Some really interesting and helpful replies!
It's good to know about the asset streaming / loading on demand. Can anyone also explain about space constraints?
As in: you have a maximum map size, realistically. How do games make a whole planet fit into that, and then make that whole planet actually part of an even bigger meta-map that is space?
5
u/Ikaron Jun 07 '22
Additionally to what others have said:
LODs.
There is a representation of a planet that is really inaccurate (no plants, very rough terrain, simplified rendering) which can be loaded/rendered blazing fast so in a "space view" where the camera is far away/the planets look really small, it looks good enough and hundreds of those planets can be loaded/rendered quickly.
Additionally, the planets will be split up into small sections or "chunks". Every chunk has multiple LODs again, and all chunks can be rendered at any LOD independent from any other.
Now, as you travel towards a planet, the strategy could be to first load an inaccurate (but better than the planet view) LOD of all chunks and then load the highest quality one of the chunk the space ship lands in, then, over time, load more and more chunks surrounding the player in high quality (streaming as mentioned before). Depending on gameplay it could also make sense to load the landing chunk in medium quality first, then highest, then start loading medium quality chunks around. Or maybe an area of multiple chunks close to the player that all need to be high quality. The strategy you choose here determines how much popping you see at which sort of disk speeds, how much RAM and VRAM your game requires, how many processor cycles you "waste" on loading and unloading things, the visual quality, difficulty of build process, etc. etc. It is the biggest decision in this regard.
Note that you can always render a low-quality LOD while the higher quality one is still loading. It's usually better to show a low-quality section of the world right away that later gets refined than having the player travel through a black void.
To reduce popping, LODs can usually be faded depending on what implementation you use. It is always caused when suddenly you move from a distance to where one LOD is required to one where a different LOD is required. So you can either have a "transition distance band" during which you fade between the two based on distance, or you could have hard changes that fade over time, say one second, instead (This also fixed popping caused by slow loading of high quality LODs). Or a mix of both.
5
u/onebit Jun 07 '22 edited Jun 07 '22
valheim makes the area around the player active. only stuff in that radius is updated. when you go back to your crops you think it was growing because they store the time and when you come back it "grows".
in the active area of the map only the terrain within the view distance is rendered and only objects in that radius have physics applied. building and animals outside the radius go to sleep so to speak.
however, valheim cheats! when you go through the portal it's a loading screen. this is because there's too much new data to stream in and players would think it's weird when terrain and structures start warping in around them.
2
u/Soundless_Pr Jun 07 '22
A short and simple analogy:
Consider how Youtube or Netflix works. You don't need to have the whole video downloaded to watch it, you only need to have the portion that is currently playing to be downloaded. This is media streaming.
Games do it similarly by asset streaming. Only the assets in your character's immediate vicinity are loaded from disk to RAM. When your character moves, the assets that are further away are unloaded and the assets in the new area are loaded in asynchronously while you're playing.
3
u/Syracus_ Jun 07 '22
The general approach is to use procedural generation to create the map at runtime. You don't need a loading screen because you are constantly loading small parts of the map in the background as you traverse it, as opposed to loading it all at once at the start, which would be impossible for a map even close to planet-sized.
The problem with this approach is optimization, as you need to handle the constant procedural generation and dynamic loading on top of the regular game logic.
The basic principle of this type of "infinite" procedural generation is to separate your map into small chunks, and to only keep a few chunks around the player loaded. As the player moves, chunks behind him are unloaded, while new chunks are generated and loaded in front of him. This is how Minecraft and most procedurally generated 2D games do it. There is nothing particularly tricky with this method. You simply need the time it takes the player to cross a chunk to be higher than the time it takes for the next chunk to load.
When it comes to space games in particular, they have more requirements, because of the transition from ground to space. They usually need 64-bit precision for the coordinates in the world, and to use extensively levels of details (they don't load half the planet's chunks when you look at it from space, you are just looking at a lower level of detail, and as you get closer they transition to higher levels of details).
2
u/Loiuy123_ Jun 07 '22
!RemindMe 24h
1
u/EgOrZA Aug 05 '24
The flying is loading you just dont see a 'loading screen'
-1
u/megablast Jun 07 '22
Space is mostly empty.
Vector graphics are tiny amount of data.
Most of it is tiny variations on themes. So planets are very similar with different land masses created by a single number. Different environments created by a single number. Etc.
um what??