Source File
resources.go
Belonging Package
github.com/mlange-42/ark/ecs
package ecsimport ()// Resources manage a world's resources. Access it using [World.Resources].//// Although this type provides an ID-based API, the recommended usage is via [Resource].type Resources struct {registry registryresources []any}// newResources creates a new Resources manager.func newResources() Resources {return Resources{registry: newRegistry(),resources: make([]any, maskTotalBits),}}// Add a resource to the world.// The resource should always be a pointer.//// Panics if there is already a resource of the given type.//// See [Resource.Add] for the recommended type-safe way.func ( *Resources) ( ResID, any) {if .resources[.id] != nil {panic(fmt.Sprintf("Resource of ID %d was already added (type %v)", .id, reflect.TypeOf()))}.resources[.id] =}// Remove a resource from the world.//// Panics if there is no resource of the given type.//// See [Resource.Remove] for the recommended type-safe way.func ( *Resources) ( ResID) {if .resources[.id] == nil {panic(fmt.Sprintf("Resource of ID %d is not present", .id))}.resources[.id] = nil}// Get returns a pointer to the resource of the given type.//// Returns nil if there is no such resource.//// See [Resource.Get] for the recommended type-safe way.func ( *Resources) ( ResID) any {return .resources[.id]}// Has returns whether the world has the given resource.//// See [Resource.Has] for the recommended type-safe way.func ( *Resources) ( ResID) bool {return .resources[.id] != nil}// reset removes all resources.func ( *Resources) () {for := range .resources {.resources[] = nil}}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |