skypjack / entt

Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more
https://github.com/skypjack/entt/wiki
MIT License
9.6k stars 844 forks source link

Handling large tilemap #1139

Closed pawelKapl closed 1 month ago

pawelKapl commented 1 month ago

Hey!

Currently i am working on tilemap based 2D/3D game, where world is made of voxels, something conceptually similiar to Core Keeper. The thing is that i want to be able to handle quite large maps. The obvious choice is to divide scene into smaller chunks, so i will render & calculate only the closest ones - pretty cliche.

Up until now i was using a single EnTT registry per scene, and it worked quite well. Now i need to implement this chunking mechanism, and i have no idea how to do it. The only ways i can see is to:

What do you suggest? EnTT is awesome and its pretty easy to use in a simple scenarios, however each time i am trying to dig deeper into its guts and functionalities i am being pushed away...

skypjack commented 1 month ago

Do you plan to run all systems on all chunks no matter what or, for example, you want to run full power on central and surrounding chunks while you run less systems as you get far from the player position?

pawelKapl commented 1 month ago

Yeah so second option, chunk with player and surrounding chunks - most probably all the calculations like physics, ai, rendering etc. Other chunks - most probably no operations at all, or almost no operations. Thanks for such quick response!

skypjack commented 1 month ago

You can also have a local registry and a global one for things like the player, an inventory and so on. There isn't the right answer, just a bunch of approaches that work fine. Your use case should guide you then. 🙂

pawelKapl commented 1 month ago

Yeah, good point. I could create one global scene registry, for handling stuff like player, craft, inventory, this registry would also probably keep references to chunks being part of a particular scene. So in systems i would most probably do smth like:

for (auto chunk : globalRegistry.view<Chunk>())
       if (chunk.loaded) chunk.registry.get<Tile/Decoration/Item>().doStuff();
skypjack commented 1 month ago

Another possibility, yeah. I think your question was answered. 🙂

pawelKapl commented 1 month ago

Yeah, thanks a LOT, apparently needed someone to just confirm that my ideas are not out of this planet! ;)

skypjack commented 1 month ago

You're welcome. The discord server is another good place for that in case. 👍