Skip to content

Commit

Permalink
Adds component registration without specifying IDs specifically
Browse files Browse the repository at this point in the history
  • Loading branch information
imthatgin committed Apr 1, 2024
1 parent e38326a commit 09c58f6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions esync/esync_shared.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package esync

import (
"github.com/leap-fish/necs/typeid"
"github.com/leap-fish/necs/typemapper"
"github.com/yohamta/donburi"
"github.com/yohamta/donburi/filter"
Expand Down Expand Up @@ -45,6 +46,20 @@ func RegisterComponent(id uint, component any, ctype donburi.IComponentType) err
return nil
}

// AutoRegister registers a component by using typeID instead of manually defined IDs.
// This is experimental, and can produce duplicates for some types.
func AutoRegister(component any, ctype donburi.IComponentType) error {
typ := reflect.TypeOf(component)
id := typeid.GetTypeId(typ)
err := Mapper.RegisterType(id, typ)
if err != nil {
return err
}
registered[typ] = ctype

return nil
}

// FindByNetworkId performs an "Each" query over network entities to find one with a matching ID.
func FindByNetworkId(world donburi.World, networkId NetworkId) donburi.Entity {
var found donburi.Entity
Expand Down

0 comments on commit 09c58f6

Please sign in to comment.