Game
After Sanctuary

21 days 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 and players who sometimes wonder how the funk this stuff works.

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 SceneStreamer class uses to load and unload these scenes around the player as he/she moves through the world.

I can then load into my test scene which contains the SceneStreamer and other game logic type stuff amongst other things and I can play through the game.

Inside the SceneStreamer, we create a dictionary to hold the data in the JSON file in memory, otherwise We would be grabbing the scenes path 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 PlayerSpawner class.

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 scene 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

Just as Pecaminosa's musicians #improvise this rendition of #LittleSunflower 🌻, so do we improvise with this post you're reading. πŸ˜‚

What's coming out of your own improvs? πŸ€”

#Pecaminosa | #IndieDev | #OST | #Jazz

Finished work on the emotions of a new character for the tank universe

Microsoft Windows XP Unprofessional (windows logo prototype)

Why walk when you can jump?

Rockin the Guitar, an Axe like Guitar I made for my Uni project

Call it 'wrong turn'!🚫 The feeling of running into a house with only one exitπŸšͺ, and being doomed to die. #pixelart #pixelartist #pixelartwork #art #pixel #indiegame #IndieGameDev #indieartist

I worked so hard to get all four of them to the end safely, but then...

Cash Banooca

A few screenshots of the places you'll cross in the Demo of Blu. You can play it today on #gamejolt !

Animation test. Not an actaul conclusion to who wins sonic vs Mario. Just a test animation combo.