On 9/29/2018 at 7:32 PM, Strewya said:The last quote i understand is a main loop that updates arrays of objects.
So how does it work? Do you updates arrays of Player, Monsters, Projectiles, CondumableItem etc, or do you update arrays of PhysicsData, InputData, CollisionData, RenderData, etc?
EC/ECS add this unnecessary restriction that objects are either an Entity or a Component. Entities have no logic and simply act as lifetime scopes for components, and a event router or service locator. Components have logic and data (or in ECS, the logic is moved to a System) but are banned from using composition themselves (i.e. They cannot own their own sub components), which is just silly. There's no need for a framework that supposedly encourages composition to put limits on composition.
In OO, if you have a class with some logic (a component or system), then your main loop (or a sub loop) can interact with it. Yes, this could means your main loop has "for each movable in the scene, add velocity * dt to position". If you have a class with no logic and is just a lifetime scope for its members (what ECS would call an Entity), then your main loop doesn't need to interact with it. e.g. If the main loop is already updating Moveables, and my entity has-a Movable, then my entity doesn't need an Update method which updates its member Movable.
As for the entity being a communication hub (event router or service locator), typically in OO you just plug objects together directly. e.g. If I make a new "entity" that has a position and sprite "component", and the sprite needs to read the position data, and the scene will update the "component" arrays in the appropriate order, you might have some code like:
MyWidget::MyWidget(Scene& scene)
: m_position(scene)
, m_sprite(scene, m_position)
{}
Now the sprite can read the position (no need for bloated parent->GetComponent<Position>() implicit service locator nonsense) via the explicit connection that we've created. These "components" can register themselves to type-specific lists in the scene, so there's no need for polymorphism or virtual functions anywhere. The flow of control, the flow of data, and the order of mutations can all be easily reasoned about (which means easy to multi-thread). Also no need for globals/singletons as the scene connections are explicit, so you can easily have multiple scenes if you like.
I'm a bit flippant with my "just write good code" shtick... But all of the above is just "normal" programming practice. Writing a massive service locator framework, plus the code to use it, so you can skip a few lines of normal explicit initialization logic seems crazy to me... especially when explicit connections are (IMHO) superior to implicit connections!
If you throw out the bloated frameworks, EC style would basically mean: only ever use two layers of composition. Structures can't contain structures,unless the only thing it does is contain structures (and none of those structures contain structures). You can only ever use one member variable of a particular type. In a structure that contains structures, all member variables must be the name of the type, e.g. Foo foo. This makes finding the appropriate components straightforward.
.... This is a ridiculous collection of programming advice... and the starting point of the talk (the simple EC framework) is not OO style code. It's built according to some made up "EC" paradigm, not according to the decades of OO paradigm advice. So the talk is actually ECS vs EC, not ECS vs OO.
ECS is better, but still contains a whole load of very silly restrictions that serve no positive use. It's worthwhile studying the paradigm that ECS is cloned from and using the general ideas without their bloated/restrictive dogmatic frameworks.
If EC is a perversion of OO, then ECS is a perversion of relational. It's extremely worthwhile to actually study how OO and relational are actually meant to be used.
9 hours ago, Randy Gaul said:@Hodgman So how's the blog post/code sample coming along? I've been eager to see it
I wrote a few pages on the weekend, but it seems half complete... maybe next weekend