[ prog / sol / mona ]

prog


ECS as a full replacement for OOP

3 2023-01-29 08:51

guy

Trans girl.

Sure it's possible, I don't mind that at all. I like the ECS architectural approach.

Currently ECS is used only for video games, because in the basic implementation it has no encapsulation and there is too little practice around applying it. "Everything global" is fine for video games, where there is a single world. But it gets in the way with a multiverse systems, which have to talk with each other only occasionally and in a controlled way. Still ECS is a superset of OOP and nothing stop people from introducing different kinds of encapsulation, interfacing and types. For some tasks, ECS is slower than the basic OOP, which is more of an optimization hack. But ideally you want everything to be a database table, and if it is a table of XYZ vectors residing in memory, you can process it order of magnitude quicker than a number of sparse XYZ coords each residing in its own objects at a completely different memory location. What is slow is accessing a random field of a random unclassified object, which is rarely done in a well written code. I.e. if you see it in a loop, just iterate over the array instead, and then do join by id with other arrays (akin to SQL joins). Of course, in its most purest form, ECS requires a hashtable, but openhashing tables are basically array, and can be processed as quickly as usual arrays. Furthermore, in scripting languages, like Lua and Python, the language itself overhead will overshadow the ECS table overhead anyway, so why limiting oneself to classic OOP even for basic objects?

9


VIP:

do not edit these