#How to type a slice of slices?
18 messages · Page 1 of 1 (latest)
no =, and you need to give T a type constraint, even if it's any
ah ok. sorry, i havent touched go in a while
type Archetype[T any] struct {
world World
signature []uint64
components [][]T
edges map[uint64]Archetype
}
so like this?
sure
so it made me add any like this
type Archetype[T any] struct {
world World
signature []uint64
components [][]T
edges map[uint64]Archetype[any]
}
does the any hear mean the archetype will be of type any or that it can take any archetype
cause i really want the latter
i guess so, but it wont be the same type as that archetype
each archetype will have a set of components, each of a generic type
hmmm. i think i did that wrong then
so let me explain the purpose of this, that might help.
I want to create an archetypal ecs, and this struct represents all the entities that own the same types of components.
ie, if we had an archetype of entities that had string and int64:
- the signature would have those 2 component ids
- the components would be an array with a slice of int64 and a slice of string
should i perhaps use a map for the components instead of an array?
If you calll components [][]any, whenever you refer to the components through the Archetype, at runtime, the program will not know which are the strings and which are the int64's at that point. You would have to cast the any as an int or a string and somehow keep track of which is which. If the elements in the two slices are a key value pair then you'd probably wanna use a map[string]int64 or something like that. But also you might already know that. Sorry if this doesn't help
no, thats great! thank you