Hello, I have some components that are registered in storage by the template.
Each component gets a unique id that I need to use in the group filter.
template reg(t: typedesc, size = 256) =
var storage {.used.} = newStorage[t]size
var id = idComponentNext
idComponentNext.inc()
proc getId*(_: typedesc[t]): int {.inline.} = id
proc getStorage(_: typedesc[t]): var Storage[t] {.inline.} =
storage
proc getComponent(self: ent, _: typedesc[t]): ptr t {.inline.} =
addr storage.components[self.id]
type
Group = ref object of RootObj
entities*: seq[ent]
filter*: array[256, bool] #ids
type
ComponentMotion = object
x, y: float
ComponentObject = object
name: string
proc newGroup(types: varargs[int]): Group =
result = new(Group)
result.entities = newSeq[ent](256)
for i in 0..types.high:
result.filter[i] = true
reg ComponentMotion
reg ComponentObject
var groupAlly = newGroup(getId(ComponentMotion), getId(ComponentObject))
Run
I'd like to make a group initialization less verbose, something like:
reg GroupAlly, [ComponentMotion,ComponentObject] # ids of the
ComponentMotion and ComponentObject are passed to the filter of the group
Run
What's the best way to achieve that?