package ecsimport ()// maskTotalBits is the size of a [bitMask] in bits.// It is the maximum number of component types that may exist in any [World].const mask256TotalBits = 256const wordSize = 64// bitMask is a 256 bit bit-mask.type bitMask256 struct { bits [4]uint64// 4x 64 bits of the mask}// newMask creates a new Mask from a list of IDs.// Matches all entities that have the respective components, and potentially further components.func newMask256( ...ID) bitMask256 {varbitMask256for , := range { .Set(.id) }return}// Get reports whether the bit at the given index [ID] is set.func ( *bitMask256) ( uint8) bool { := >> 6 := uint64(1) << ( & 63)return .bits[]& == }// Set sets the state of the bit at the given index.func ( *bitMask256) ( uint8) { := >> 6 := uint64(1) << ( & 63) .bits[] |= }// Clear sets the state of the bit at the given index.func ( *bitMask256) ( uint8) { := >> 6 := uint64(1) << ( & 63) .bits[] &^= }// Not returns the inversion of this mask.func ( *bitMask256) () bitMask256 {returnbitMask256{bits: [4]uint64{^.bits[0], ^.bits[1], ^.bits[2], ^.bits[3]}, }}// OrI calculates the OR of this mask and other in-place.func ( *bitMask256) ( *bitMask256) { .bits[0] |= .bits[0] .bits[1] |= .bits[1] .bits[2] |= .bits[2] .bits[3] |= .bits[3]}// IsZero returns whether no bits are set in the mask.func ( *bitMask256) () bool {return .bits[0] == 0 && .bits[1] == 0 && .bits[2] == 0 && .bits[3] == 0}// Reset the mask setting all bits to false.func ( *bitMask256) () { .bits = [4]uint64{0, 0, 0, 0}}// Contains reports if the other mask is a subset of this mask.func ( *bitMask256) ( *bitMask256) bool { , , , := .bits[0], .bits[1], .bits[2], .bits[3] , , , := .bits[0], .bits[1], .bits[2], .bits[3]return & == && & == && & == && & == }// ContainsAny reports if any bit of the other mask is in this mask.func ( *bitMask256) ( *bitMask256) bool { , , , := .bits[0], .bits[1], .bits[2], .bits[3] , , , := .bits[0], .bits[1], .bits[2], .bits[3]return & != 0 || & != 0 || & != 0 || & != 0}// TotalBitsSet returns how many bits are set in this mask.func ( *bitMask256) () int {returnbits.OnesCount64(.bits[0]) + bits.OnesCount64(.bits[1]) + bits.OnesCount64(.bits[2]) + bits.OnesCount64(.bits[3])}// Equals returns whether two masks are equal.func ( *bitMask256) ( *bitMask256) bool {return .bits == .bits}// toTypes converts a mask to a list of component IDs.func ( *bitMask256) ( *registry) []ID { := .TotalBitsSet() := make([]ID, ) := .Count() := /wordSize + 1 := % wordSize := 0for := range {if .bits[] == 0 {continue } := wordSizeif == -1 { = }for := range { := ID{id: uint8(*wordSize + )}if .Get(.id) { [] = ++ } } }return}
The pages are generated with Goldsv0.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.