Better HN
topnewbestaskshowjobs
Log inSign up

ajmmertens

103 karma · joined Dec 29, 2018 (7y ago) · 50 submissions

Submissions

1.

How to build fast hierarchies for game objects using data oriented design(ajmmertens.medium.com ↗)

10 points · by ajmmertens · 5mo ago · discuss

2.

Building an ECS #3: Storage in Pictures(ajmmertens.medium.com ↗)

11 points · by ajmmertens · 2y ago · discuss

comment 2y ago · link · parent

Judging by the system & component names this looks to be pretty well designed tbh. There are a lot of systems for sure, but considering this is a city simulator that's kind of expected.

comment 2y ago · link · parent

> I bet the current design passes and queries data all over the place, very redundantly

That's not how ECS works. A system has one or more queries that provide it direct access to the data. There's no passing around of queries or data.

comment 3y ago · link · parent

The query engine works on top of an Entity Component System (ECS) storage that stores entities and their data in cache coherent (SoA - https://en.wikipedia.org/wiki/AoS_and_SoA) data structures.

With any kind of database - even in-memory SQLite - there is a query interface between you and the data. In ECS you access data directly, which is at least an order of magnitude faster.

comment 3y ago · link · parent

Or if you want code that's easier to extend, read and don't want to do your own memory management.

Here's a bit of code from that project that generates a monster: https://github.com/tmewett/BrogueCE/blob/master/src/brogue/M...

It just allocates an object per monster, followed by initializing a long list of members that presumably just gets longer as more game systems get added.

The same code in ECS would look a lot simpler, and probably perform better/have better cache locality.

comment 3y ago · link · parent

The same goes for Flecs:

- it has tools like https://github.com/flecs-hub/explorer that work with any Flecs project

- it has builtin support for hierarchies/prefabs and more (https://ajmmertens.medium.com/building-games-in-ecs-with-ent...)

- it has optional support for systems/scheduling

- it has an optional reflection framework

- it has an optional DSL for describing assets/scenes, with an online playground to try it out: https://www.flecs.dev/explorer/?local=true&wasm=https://www....

- and a lot more: https://www.flecs.dev/flecs/md_docs_Quickstart.html#autotoc_...

comment 3y ago · link · parent

The way you frame the question already suggests a solution, and one that indeed doesn't fit ECS that well. That doesn't mean you couldn't design a DAW using ECS, but you'd have to redesign how it works.

For example:

- create custom components for different instruments

- create systems for specific instruments that match the necessary components

- write the result to a common component (e.g. "ChannelOutput")

You could then add components for EQ, effects, routing, ... and introduce systems that match those. The advantage of this approach would be that you end up with a bunch of loosely coupled systems (for instruments, effects, mixing, ...) and an in-memory representation that's cache & parallelization friendly.

One other datapoint would be that Unreal's animation sequencer uses an ECS design, which has a lot of things in common with a DAW.

Glossing over lots of details here, you can't of course design a DAW in one paragraph.

comment 3y ago · link · parent

> but still ECS incurs massive overhead compared to basic arrays of structs

I actually know of quite a few projects that use ECS as the foundation for a low level rendering library precisely because it lets you iterate over a bunch of plain arrays, but with more flexibility.

The overhead of an ECS depends on many things, but if you have lots of entities with similar components, the overhead per entity can be quite small.

comment 3y ago · link · parent

The opposite also applies: don't reinvent the wheel if you want to get something done.

Existing game engines like Unity/Unreal already have builtin solutions for entity management, but if you're (for whatever reason) using something that's more custom you can avoid having to reinvent entity management by using an ECS library. Similar to how you'd use libraries like SDL/bgfx/sokol for graphics.

comment 3y ago · link · parent

I'm definitely not going to argue that you need ECS to do much of anything, but ECS has come long way in the past 4 years from a tool that lets you have lots of entities in a game, to a more generic system for entity management.

Things like entity relationships (https://ajmmertens.medium.com/building-games-in-ecs-with-ent...) introduced features that were already common in existing entity management systems, such as entity hierarchies.

An ECS can also come with a bunch of tools for inspecting entities, monitoring performance or changing components in realtime (https://www.flecs.dev/explorer/). Definitely not something you need to complete a game, but very handy.

comment 3y ago · link · parent

It could be yep. One of the things that makes it a good fit for this use case is that Flecs has a query language that supports things like graph traversal and joins. Combined with either the builtin REST API or some custom protocol you could use it as a realtime in-memory database (which is what I use it for).

comment 3y ago · link · parent

Definitely possible. I know of a project that used an event-based architecture to decide when to run ECS systems.

comment 3y ago · link · parent

The biggest reason for me was to reduce compile times, which got cut into approximately half when I replaced STL containers with simpler custom ones. This starts adding up in large projects, where lots of files end up including the ECS.

comment 3y ago · link · parent

Pretty close, but there's a bit more to it. This post goes over one way an ECS can store data: https://ajmmertens.medium.com/building-an-ecs-2-archetypes-a...

comment 3y ago · link · parent

Whether ECS is complex or not depends a lot on which one you use. I've heard the same thing from a lot of gamedevs that use DOTS, but people in general seem to be pretty happy using Entitas (also a C# ECS that can be used with Unity), Bevy (which is based entirely on ECS) or for that matter Flecs.

17.

Flecs 2.1 is out! A faster, easier to use ECS for C and C++(medium.com ↗)

1 points · by ajmmertens · 6y ago · discuss

18.

Easy C/C++ reflection library without RTTI(github.com ↗)

2 points · by ajmmertens · 6y ago · discuss

19.

Why Storing State Machines in ECS is a bad idea(reddit.com ↗)

2 points · by ajmmertens · 6y ago · discuss

20.

Show HN: Flecs 2.0, an Entity Component System for C and C++ is released(medium.com ↗)

2 points · by ajmmertens · 6y ago · discuss

21.

Why vanilla ECS is not enough(medium.com ↗)

3 points · by ajmmertens · 6y ago · discuss

22.

Show HN: What happens if you combine ECS with inheritance(reddit.com ↗)

1 points · by ajmmertens · 7y ago · discuss

12