Skip to content

Commit

Permalink
Improve allocation on read
Browse files Browse the repository at this point in the history
  • Loading branch information
unitoftime committed Jan 6, 2025
1 parent 4bbe9d7 commit 5e7af48
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 12 additions & 2 deletions bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,24 @@ func (b *Bundler) Clear() {
// return bun.Set[comp.CompId()]
// }

func (bun *Bundler) Read(comp Component) (Component, bool) {
func readBundle[T Component](bun *Bundler) (T, bool) {
var comp T
compId := comp.CompId()

if !bun.Set[compId] {
return comp, false // Was not set
}
return bun.Components[compId], true
return bun.Components[compId].(*box[T]).val, true
}

// func (bun *Bundler) Read(comp Component) (Component, bool) {
// compId := comp.CompId()
// if !bun.Set[compId] {
// return comp, false // Was not set
// }
// return bun.Components[compId], true
// }

// func (bun *Bundler) Remove(comp Component) {
// compId := comp.id()
// bun.archMask.removeComponent(compId)
Expand Down
11 changes: 8 additions & 3 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ func (e EntityCommand) Id() Id {
// }
func ReadComp[T Component](e EntityCommand) (T, bool) {
var t T
comp, ok := e.cmd.bundler.Read(t)
// comp, ok := e.cmd.bundler.Read(t)
// if ok {
// box := comp.(*box[T])
// return box.val, true
// }

comp, ok := readBundle[T](e.cmd.bundler)
if ok {
box := comp.(*box[T])
return box.val, true
return comp, true
}
return t, false
}
Expand Down

0 comments on commit 5e7af48

Please sign in to comment.