Nobody understands templates?

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Tue Mar 4 17:16:31 PST 2014


On 3/4/2014 7:42 PM, bearophile wrote:
> Nick Sabalausky:
>
>> - Lumping all data/functionality for a single "object" instance into
>> the same physical chunk of memory causes problems for parallelization.
>> And that's increasingly problematic on modern processors which work
>> best when operating as "streaming-data processors". (See
>> "Entity/Component Systems"[1] - There are good reasons videogame
>> development has mostly switched from OOP to entity/component systems.)
>
> Sometimes OOP is handy, for GUIs and other situations, but if today a
> more horizontal placement of fields is more efficient when high
> performance is needed, then perhaps a creative programmer has to find
> the courage to step out of his/her/hir language constraints to invent a
> better language. Is it possible to invent a language more fit for this
> different kind of data layout?
>

I don't think it's necessary to go as far as creating a new language. An 
entity-system in a low-level-capable language gives you enough power to 
control layouts however appropriate, and using them is pretty easy.

It seems intimidating at first, but it's really just like a relational 
DB: You have a unique ident for each "object" (ie, what an OO system 
would call an instantiated object, but in this case called an "entity"). 
And then all the data associated with the "object/entity" is stored in 
various tables/structs/whatever (in this case, called "components") with 
the entity's unique identifier being the primary key for each 
table/component. Functionality operates on a particular table/component, 
or a set of specific tables/components, either on a row-at-a-time basis 
or as the whole table as an aggregate.

Note that this imposes very little, if any, requirements on in-memory 
layouts, so things can be laid out however desired - possibly even with 
per-platform topologies thanks to the magic of metaprogramming. In any 
case, metaprogramming can help abstract away many of the internal 
memory-layout details.

Playing around with the Unity3D editor, and it's tutorial videos, can 
help grok the usage and modeling power of entities (like any good modern 
game engine, it uses an entity-based design). Although, FWIW, I'm not 
convinced Unity3D's design is able to *fully* take advantage of all the 
potential performance benefits of an entity system (mostly because of 
its CLR-based scripting and black-box closed-source engine).

But, I admit, I have wondered if a language could aid the creation/usage 
of entity systems with some special language features.



More information about the Digitalmars-d-learn mailing list