INNER CODE UNIT · Go

Get

yohamta0/donburi-ecs · entry.go:23

func Get[T any](e *Entry, c component.IComponentType) *T {
	return (*T)(e.Component(c))
}

// GetComponents uses reflection to convert the unsafe.Pointers of an entry into its component data instances.
// Note that this is likely to be slow and should not be used in hot paths or if not necessary.
func GetComponents(e *Entry) []any {
	var instances []any
	for _, c := range e.World.StorageAccessor().Archetypes[e.loc.Archetype].ComponentTypes() {
		instances = append(instances, reflect.Indirect(
			reflect.NewAt(c.Typ(), e.Component(c))).Interface(),
		)
	}
	return instances
}

// Add adds the component to the entry.
func Add[T any](e *Entry, c component.IComponentType, component *T) {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…