From 5e7af48a06269b0909577c9724b536d9fe721c12 Mon Sep 17 00:00:00 2001 From: Jacob <2606873+unitoftime@users.noreply.github.com> Date: Sun, 5 Jan 2025 19:47:38 -0500 Subject: [PATCH] Improve allocation on read --- bundle.go | 14 ++++++++++++-- command.go | 11 ++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/bundle.go b/bundle.go index 2fa8af8..e6b6b39 100644 --- a/bundle.go +++ b/bundle.go @@ -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) diff --git a/command.go b/command.go index 0ea5391..b6213d8 100644 --- a/command.go +++ b/command.go @@ -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 }