mirror of
https://github.com/bloeys/nmage.git
synced 2025-12-29 05:18:21 +00:00
Improve assert+imporve error messages when adding comps
This commit is contained in:
@ -1,8 +1,6 @@
|
|||||||
package assert
|
package assert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/bloeys/nmage/consts"
|
"github.com/bloeys/nmage/consts"
|
||||||
"github.com/bloeys/nmage/logging"
|
"github.com/bloeys/nmage/logging"
|
||||||
)
|
)
|
||||||
@ -10,6 +8,6 @@ import (
|
|||||||
func T(check bool, msg string, args ...any) {
|
func T(check bool, msg string, args ...any) {
|
||||||
|
|
||||||
if consts.Debug && !check {
|
if consts.Debug && !check {
|
||||||
logging.ErrLog.Panicln("Assert failed:", fmt.Sprintf(msg, args...))
|
logging.ErrLog.Panicf("Assert failed: "+msg, args...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ type Comp interface {
|
|||||||
|
|
||||||
func AddComp[T Comp](e *Entity, c T) {
|
func AddComp[T Comp](e *Entity, c T) {
|
||||||
|
|
||||||
assert.T(!HasComp[T](e), "Entity with id %v already has component with name %s", e.ID, c.Name())
|
assert.T(!HasComp[T](e), "Entity with id '%v' already has component of type '%T'", e.ID, c)
|
||||||
|
|
||||||
e.Comps = append(e.Comps, c)
|
e.Comps = append(e.Comps, c)
|
||||||
c.Init(e)
|
c.Init(e)
|
||||||
|
|||||||
@ -76,6 +76,7 @@ func (r *Registry) GetEntity(id EntityHandle) *Entity {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FreeEntity calls Destroy on all the entities components, resets the component list, resets the entity flags, then ads this entity to the free list
|
||||||
func (r *Registry) FreeEntity(id EntityHandle) {
|
func (r *Registry) FreeEntity(id EntityHandle) {
|
||||||
|
|
||||||
e := r.GetEntity(id)
|
e := r.GetEntity(id)
|
||||||
|
|||||||
11
main.go
11
main.go
@ -88,20 +88,15 @@ func Test() {
|
|||||||
e1 := lvl.Registry.NewEntity()
|
e1 := lvl.Registry.NewEntity()
|
||||||
|
|
||||||
trComp := entity.GetComp[*TransformComp](e1)
|
trComp := entity.GetComp[*TransformComp](e1)
|
||||||
fmt.Println("Got comp 1:", trComp)
|
fmt.Println("Get comp before adding any:", trComp)
|
||||||
|
|
||||||
e1.Comps = append(e1.Comps, &TransformComp{
|
entity.AddComp(e1, &TransformComp{
|
||||||
Pos: gglm.NewVec3(0, 0, 0),
|
Pos: gglm.NewVec3(0, 0, 0),
|
||||||
Rot: gglm.NewQuatEulerXYZ(0, 0, 0),
|
Rot: gglm.NewQuatEulerXYZ(0, 0, 0),
|
||||||
Scale: gglm.NewVec3(0, 0, 0),
|
Scale: gglm.NewVec3(0, 0, 0),
|
||||||
}, &TransformComp{
|
|
||||||
Pos: gglm.NewVec3(0, 0, 0),
|
|
||||||
Rot: gglm.NewQuatEulerXYZ(0, 0, 0),
|
|
||||||
Scale: gglm.NewVec3(1, 1, 1),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
trComp = entity.GetComp[*TransformComp](e1)
|
trComp = entity.GetComp[*TransformComp](e1)
|
||||||
fmt.Println("Got comp 2:", trComp)
|
fmt.Println("Get transform comp:", trComp)
|
||||||
|
|
||||||
fmt.Printf("Entity: %+v\n", e1)
|
fmt.Printf("Entity: %+v\n", e1)
|
||||||
fmt.Printf("Entity: %+v\n", lvl.Registry.NewEntity())
|
fmt.Printf("Entity: %+v\n", lvl.Registry.NewEntity())
|
||||||
|
|||||||
Reference in New Issue
Block a user