添加仿真panic恢复,使用slog打印
This commit is contained in:
parent
47f78cb54d
commit
e779734672
|
@ -1,10 +1,26 @@
|
|||
package debug
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/yohamta/donburi"
|
||||
"github.com/yohamta/donburi/features/debug"
|
||||
"joylink.club/ecs"
|
||||
)
|
||||
|
||||
func PrintEntityCounts(w ecs.World) {
|
||||
debug.PrintEntityCounts(w)
|
||||
type EntityCounts = debug.EntityCounts
|
||||
|
||||
func GetEntityCounts(w donburi.World) []EntityCounts {
|
||||
return debug.GetEntityCounts(w)
|
||||
}
|
||||
|
||||
// 打印所有实体数量
|
||||
func SPrintEntityCounts(w donburi.World) string {
|
||||
var out bytes.Buffer
|
||||
out.WriteString("Entity Counts:\n")
|
||||
for _, c := range GetEntityCounts(w) {
|
||||
out.WriteString(c.String())
|
||||
out.WriteString("\n")
|
||||
}
|
||||
out.WriteString("\n")
|
||||
return out.String()
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
|||
module joylink.club/ecs
|
||||
|
||||
go 1.20
|
||||
go 1.21
|
||||
|
||||
require github.com/yohamta/donburi v1.3.8
|
||||
|
||||
|
|
9
world.go
9
world.go
|
@ -2,6 +2,7 @@ package ecs
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
|
@ -173,6 +174,12 @@ func (w *world) executeTodos() {
|
|||
}
|
||||
}
|
||||
func (w *world) run() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
slog.Error("世界运行异常:", "stacks", err)
|
||||
w.state = Error
|
||||
}
|
||||
}()
|
||||
for {
|
||||
if w.state == Error {
|
||||
// 世界错误,关闭世界
|
||||
|
@ -204,6 +211,6 @@ func (w *world) run() {
|
|||
w.times += w.speed
|
||||
}
|
||||
// dt := time.Since(start)
|
||||
// fmt.Println("仿真系统执行耗时:", dt.Milliseconds(), "ms")
|
||||
// slog.Info("仿真系统执行耗时:" + dt.Milliseconds() + "ms")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue