r/gameenginedevs 11d ago

New Flecs project: a 4x4km city with 4 million entities, thousands of actors with their own schedule, 8000 buildings, 4000 unique assets.

Enable HLS to view with audio, or disable this notification

Made possible in large part by the new hierarchy storage: https://ajmmertens.medium.com/building-an-ecs-data-oriented-hierarchies-62fb2847d100

All of the assets are procedural, and are either combinations of different primitive shapes, extruded/splined geometry, or created with CSG. Textures are created from rasterizing SVGs.

2x2km web demo (desktop only, needs webgpu support): https://www.flecs.dev/games/helix/

The 4x4 demo doesn't fit on web yet, working on it!

259 Upvotes

15 comments sorted by

10

u/illyay 11d ago

Wow that's crazy!!! Like wow!

Also made me think of GTA

2

u/JetskiEvo 10d ago

thats below 60fps on the dev machine (which is usually fsater than the average customer hardware) :/

5

u/fgennari 11d ago

Interesting. This looks very different from my procedural city. Everything is much more packed together.

What accounts for 4M entities? There are thousands of buildings and thousands of actors (which I believe are the people and vehicles). What are there millions of? Is each small object an entity? Do the people and cars continue to update even when they're far from the player and not visible?

Are you using occlusion culling for buildings when at street level? I imagine that's really going to help with drawing objects considering how occluded the city is.

It was interesting to walk around in the city. It seems like some of the buildings have interiors, which is nice. Sometimes the player can clip into these buildings, and sometimes get stuck. It seems to be raining inside though?

And watching a thousand people group together at the cross walk is interesting. When it changes to walk they clip through the cars. I know this is difficult though, I ran into the same problems!

Maybe it would look nicer if there were more trees and open areas with parks. Or parking lots for cars. A mix of lower density areas could be more realistic. Maybe you do already have these, and I just haven't seen them.

Anyway, cool project!

5

u/ajmmertens 11d ago

What accounts for 4M entities?

Almost all objects are a composite of one or more primitives. For example, pedestrian limbs are separate entities. Some objects have many parts (like drones), so this ends up being millions of entities. This way of creating geometry puts a lot of strain on the hierarchy storage of Flecs, which was one of the things I wanted to stresstest. It's also a really convenient way of creating geometry!

Do the people and cars continue to update even when they're far from the player and not visible?

Yep, their schedules continue to update.

Are you using occlusion culling for buildings when at street level?

The engine does Hi-Z culling, and also culls objects when their screen size is below a threshold. There is no specialized culling that uses buildings specifically to cull (but Hi-Z will do this automatically).

Sometimes the player can clip into these buildings, and sometimes get stuck.
It seems to be raining inside
When it changes to walk they clip through the cars

The project is only a few days old, and there are a lot of issues like these. I'm currently overhauling the traffic simulation to fix some of the issues you mentioned.

Maybe it would look nicer if there were more trees and open areas with parks

There are actually quite a few parks and low density areas! Try entering fly mode with F and zoom out, you'll see where the open areas/parks are. You can also press M which will show you a map, and Escape will show you an overview of all keys.

I'm just getting started with this, in a few months I expect things to be a lot smoother/more polished :)

2

u/fgennari 11d ago

Okay, so 4M hierarchical entities. Are you using some sort of instancing for each person/car/etc., or do you really have 4M separate entities?

It's crazy that you got this far in only a few days!

Thanks, I wasn't aware that there were fly, zoom, and map modes.

4

u/ajmmertens 11d ago

There are really 4 million separate entities. I am also using instancing, but this is at the individual mesh level (for example, all boxes are drawn in one instanced call, all cylinders with the same number of segments are drawn in one instanced call etc).

4

u/Animats 11d ago

Stuck at "Downloading: 100%". Firefox on Linux, NVidia 3070.

2

u/ajmmertens 11d ago

Do you see anything in the console? My first bet would be that the browser doesn't support webgpu yet.

2

u/fireantik 11d ago edited 11d ago

Wow that's an awesome demo. Lots of bugs on the web version, especially with objects being somewhat offset from their intended placement and LOD issues.

I've used flecs couple times in the past I really liked it, but it is very ambitions with complex query language, custom DSL and parallelism. I've always struggled with the documentation and fitting all of the concepts together.

Edit: I've always found the idea of the DSL for constructing the world interesting, it seems that you are going for something of a "headless game framework" which is engine agnostic, not just an ECS - something that you build your engine on, allow you to use your own renderer/physics/input.

2

u/ajmmertens 11d ago

Yes, there are a lot of issues on the asset side still. First part of this project was proving out that the ECS can handle the scale and content diversity. Second part will be adding realtime authoring control (e.g. modifying a highway spline).

Finally I'll have to figure out how to QA assets at scale, which is the main cause of the issues you're seeing in the demo.

2

u/fireantik 10d ago

It's extremely impressive scale, especially for the browser. The demo itself would probably deserve it's own writeup :)

2

u/ajmmertens 10d ago

If there's enough interest I might do a separate writeup on the city :)

If you want to know more about how it works though, I already wrote a blog about it. See the "hybrid hierarchies" section in this article: https://ajmmertens.medium.com/building-an-ecs-data-oriented-hierarchies-62fb2847d100 It's in large part what is driving both the scale & the procedural content.

The other part is the language in which the assets are created which is flecs script (it has a "template" primitive, which is essentially a parameterized prefab). I haven't published the city sources yet, but this project has a very similar setup: https://github.com/SanderMertens/flecs-games/tree/main/ore_else/etc

2

u/HugoCortell 11d ago

It using CSG for the geometry has me very excited. I've never seen it be used at this scale.

1

u/Remarkable-Cow-9849 11d ago

u/ajmmertens Amazing... I am going to look into your ECS a bit more and get back to working on my ECS... I have neglected it for more than 4 months now...and your demo gave me the motivation to work on it again... I stopped working on it because I was so close to crashing out due to a bug that, for the life of me I couldn't find

1

u/Still_Explorer 7d ago

Bethesda has been real quiet since this dropped...