lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Aug 2, 2019 at 5:18 PM Coda Highland wrote:
ECS is an inherently object-oriented technique,

Apparently you don't understand what ECS is.

 
the ID-based technique exists specifically to enable an object-oriented technique to be implemented in languages that don't make it easy to write object-oriented code.

No.
ECS is not an "OOP for languages that don't have native OOP support"

 
you've scattered the contents of things around instead of keeping related information together.

Yes, from OOP's point of view ECS looks like "OMG! All the things are scattered!"
The key difference is: OOP is class-centric, ECS is "system"-centric (a "system" is a code which doesn't belong to any class).
Probably you have been programming OOP for too long, so that you have failed to unstick your brains from OOP to make a mental jump to ECS approach.
You didn't catch the main idea of ECS: all logic is being done by "systems" simultaneously for all objects,
that's why we "scatter" objects' properties instead of storing them inside objects.

This is the code you have written in another post, it's pure OOP objects-centric code:
>     function update(dt)
>       for _, entity in pairs(all_entities) do
>         if entity.update then entity:update(dt) end
>         for _, trait in pairs(entity) do
>           if trait.update then trait:update(entity, dt) end
>         end
>       end
>     end
The code organized in such way that it doesn't have a possibility to efficiently implement an interaction between objects (for example, between a bullet and a monster).
In ECS such interactions would be implemented with a separate "system".

And a "trait" in your code is just an a collection of initialization functions
(yes, the only thing OOP could do well enough is to create and destroy objects, all the other logic is beyond OOP)

Sorry, but what you call "object-oriented ECS" is not an ECS ;-)