zdandoh / ecs

Golang ECS library using go generate
MIT License
5 stars 0 forks source link

No codegen for unset of a component #7

Closed delaneyj closed 10 months ago

delaneyj commented 10 months ago

:point_up:

It seems like

func (e Entity) UnsetPosition() {
    if !e.Alive() {
        return
    }

    entities[e.id>>entityPageBits][e.id%entityPageSize].components[0] &= ^uint64(1)
}

Would be basically the right format and fast since you are using "dumb" slices as the backing store

zdandoh commented 10 months ago

Is this different from RemoveX? https://github.com/zdandoh/ecs/blob/master/codegen/ecs/component.go.templ#L34

delaneyj commented 10 months ago

Lol, the codegen is tiny and I missed it... though the setting to zero isn't needed since when you add you are providing a new one

zdandoh commented 10 months ago

Yep, seems ok to remove. Done

zdandoh commented 10 months ago

Had to re-add the zeroing, if you don't zero you don't clear out any pointers that might have been heap allocated by the user and they can't be GC'd.