Re: Is something like EnTT possible with Nim?
@yglukhov You're comment encouraged me to seek out a better ECS tutorial than the one I read prior to my first ECS(-ish). Thank you for that. The tutorial, for anyone interested, is at: [http://t-machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-1](http://t-machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-1)/
Re: Is something like EnTT possible with Nim?
Thank you for the suggestion, @yglukhov. I'm familiar with ECS and have implemented one before in Go. I wanted to try the same in Nim to help me gain familiarity with the language.
Re: Is something like EnTT possible with Nim?
@stephenwithav it's important to understand the problem ECS solves. ECS is notable for its memory utilization efficiency, gained from cpu-cache-friendly data layout. I'd suggest you read about that before implementing your ECS. But, small spoiler, neither polymorphic objects (interfaces), nor references are the options. At this point, i'd suggest not to consider variant objects either. :)
Re: Is something like EnTT possible with Nim?
Ideally, I'm hoping for something comparable to Golang interfaces. I avoided C since the early '90s due to early compiler incompatibilities. Only recently, in the past few months, have I looked at C/C++ seriously. Thank you for pointing to `variant`. I'm going to look at entt's source more closely and try to find a good equivalent in Nim. (I couldn't seem to make anything useful out of sequtils; Araq, I'm curious as to what you had in mind.)
Re: Is something like EnTT possible with Nim?
> Then I learned this morning that seq[Component] fails. That really should be obvious. A seq in Nim is similar to vectors in C++, that is basically a plain C array that automatically resizes when necessary, where resize is new allocation and copying elements. So all elements must have same type and same size as in C arrays -- as all refs and pointers have the same size, we can have different ref types in a seq and can test for exact type with "of" operator at runtime. Note that we have sum types (objects variants) in Nim.
Re: Is something like EnTT possible with Nim?
I thought I had something good last night: type Position = object x: int y: int type Velocity = object dx: int dy: int dz: int type Component = Position | Velocity proc showProps(p: Position) = echo p.x, ", ", p.y proc showProps(v: Velocity) = echo v.dx, ", ", v.dy, ", ", v.dz let p = Position(x: 9, y: 9) let v = Velocity(dx: 1, dy: 1, dz: 3) showProps(p) showProps(v) Run While tedious, it was good. Then I learned this morning that seq[Component] fails. _sigh_ type Position = object x: int y: int type Velocity = object dx: int dy: int dz: int type Component = Position | Velocity proc showProps(p: Position) = echo p.x, ", ", p.y proc showProps(v: Velocity) = echo v.dx, ", ", v.dy, ", ", v.dz let p = Position(x: 9, y: 9) let v = Velocity(dx: 1, dy: 1, dz: 3) var s: seq[Component] s.add(p) s.add(v) echo s Run
Re: Is something like EnTT possible with Nim?
Thank you, Araq and doofenstein. I'm going to try to develop a VERY simple ECS today in Nim. Somehow, I had totally missed (or forgotten) varargs and set. Those two should help make this first attempt successful.
Re: Is something like EnTT possible with Nim?
Another ECS attempt: [https://github.com/yglukhov/ecs](https://github.com/yglukhov/ecs)
Re: Is something like EnTT possible with Nim?
ha, you might be interested in this ECS implementation, from one of my failed Nim game engine attempts: [https://gist.github.com/RSDuck/6c8caf82aeb88991d440b228b3f32f06](https://gist.github.com/RSDuck/6c8caf82aeb88991d440b228b3f32f06) Note that this is mostly untested. For examples look at the bottom of the file.
Re: Is something like EnTT possible with Nim?
What's hard about `registry.view`? Please look at `sequtils.nim`.
Re: Is something like EnTT possible with Nim?
assign shouldn't be too difficult... just add a subclass of Component to the seq. But filtering for registry.view? I can't figure that one out yet. Templates, maybe?
Is something like EnTT possible with Nim?
Specifically, I'm curious if tuples could take the place of structs, and equivalents for registry.assign and registry.view. I can imagine registry as a seq[int], with each entity being represented by a unique integer, but I don't know how to assign tuples to an int. I really like the ability to filter entities to only those with the specific components of interest. Is there a way to achieve the same in Nim? [EnTT examples](https://github.com/skypjack/entt/blob/master/README.md#code-example)