Game
After Sanctuary

13 hours ago

Devlog #2

World streaming.


Hello Sanctuary seekers,

I thought I'd kick off the devlogs I'll be posting here by telling you a little bit about my world streaming.

This is aimed more at fellow developers who may want to do something similar.

There will be code snippets but I'm not going to share the whole thing.
I don't believe it would be any good to anyone else as full code as it's integrated with my game for my specific use case.

The world is 8km by 8km (currently).
It's made up of a grid of terrain tiles.
I have a development scene where I can edit the terrain, place gameobjects and basically create the world.

When I want to test, I fire off my editor script which collects all the terrain tiles, gameobjects and anything else and packages them all into seperate scenes.

menu.png

It also creates a JSON file which holds information about each scene.

json.png

This is what the WorldStreamer class uses to load and unload these scenes around the player as he/she moves through the world.

Inside the WorldStreamer, we create a dictionary to hold the data in the JSON file in memory, otherwise We would be grabbing the scenes from disk each time they are required (not slow but higher cost).

dict.png

We load in the tile meta data

loaddata.png

and populate the dictionary.

buildindex.png

We start a coroutine to load the initial scenes, passing in the spawn position of the player from the player.

pos.png

At the moment, this loads the player to a random POI. Sounds stupid but I only have 1 POI in the list atm.
I'll probably never use the random POI spawn but it's there if I need to.

Once the initial tiles have loaded around the POI, the scene streamer fires off an event action to let other classes know the game world has loaded.
We also start the scene streaming loop.

event.png

The player spawner listens for this event and spawns the player.
It also fires off it's own event to notify other classes which depend on the player being active in the scene before they can work.

spawnplayer.png

We also register the player with the scene streamer properly so it knows where we are in the world and how far away from origin.
If we get too far away, everything is shifted closer to the origin to avoid floating point calculation errors.
Anything > 3k unity meters from 0,0,0 is ropey at best and glitching happens because the floating point calculations become inaccurate.

The streamer looks for movement and also runs on a timer. but only if the player is moving.

scan.png

It then happily loads and unloads the world around the player.
This is just the basics really, it does other stuff like loading game objects and AI in over time instead of trying to do it all in one frame.
The real cost with activating game objects is the physics so this has to be done carefully otherwise the player will get stutters so I limit the max activations per frame.

activperframe.png

This keeps everything running smooth.
The streaming class also assists with loading into indoor scenes and back out of them into the open world.

I'll probably post more about that in the future.
If you have any questions please feel free to post them in the comments.

Don't forget to join us on discord https://discord.gg/S8cCdyzB

Until next time,

Stay safe.



0 comments

Loading...

Next up

Shoobies leave a sticky trail of mucus in their wake, which can impede movement for any creature that steps in it.

Fan art for Foolish I'm feeling kinda better so I drew this

Here's a peaceful little forest scene for this #screenshotsaturday, from the beginning of the game.

Have a good Boi

Updated the chest in the maze, adding sound, particles and better animation. But what's in the chest?

Just a Pico sprite

Heya! I wanted to show some gameplay progress i made so far. I hope you like it ^^

Back in my art school days I used to ride the 710 COPSA line from Parque Del Plata to Montevideo almost everyday. This is the Marcopolo Viaggio G4 Mercedes Benz model from the late 80s, one of the older bus models that was running on the line.

Regular exercise is key for healthy wings.

Try it out!

https://gamejolt.com/games/AeonNightmares/605184

Today I tackled drawing different variations of facial expressions for one of the main characters in Eden. What do you think of it? :) Eden: https://gamejolt.com/games/Eden/592698