fix(crash): 修复双击闪退——路径基于可执行文件目录解析、崩溃兜底日志、资源入 bin 与安装包
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"mc/internal/block"
|
||||
"mc/internal/camera"
|
||||
"mc/internal/config"
|
||||
"mc/internal/crash"
|
||||
"mc/internal/engine"
|
||||
"mc/internal/font"
|
||||
"mc/internal/game"
|
||||
@@ -28,6 +29,7 @@ import (
|
||||
"mc/internal/mesh"
|
||||
"mc/internal/netclient"
|
||||
"mc/internal/netproto"
|
||||
"mc/internal/paths"
|
||||
"mc/internal/physics"
|
||||
"mc/internal/recipe"
|
||||
"mc/internal/render"
|
||||
@@ -149,7 +151,7 @@ func (a *clientApp) Tick(dt float64) {
|
||||
// 定时存档:30s(存档与持久化.md §2)
|
||||
a.tickCnt++
|
||||
if a.tickCnt%(20*30) == 0 && a.net == nil {
|
||||
if err := save.SaveWorld(a.sess.World, "worlds", "NewWorld", 123456789, int64(a.tickCnt)); err != nil {
|
||||
if err := save.SaveWorld(a.sess.World, paths.Join("worlds"), "NewWorld", 123456789, int64(a.tickCnt)); err != nil {
|
||||
// 日志由调用方输出(避免每次 tick 刷屏)
|
||||
_ = err
|
||||
}
|
||||
@@ -221,13 +223,14 @@ func (a *clientApp) logf(format string, args ...any) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
defer crash.Guard(paths.Join("logs", "crash.log")) // 崩溃兜底:闪退可诊断
|
||||
flag.Parse()
|
||||
|
||||
log, err := logx.New("logs/client.log", logx.LevelInfo)
|
||||
log, err := logx.New(paths.Join("logs", "client.log"), logx.LevelInfo)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg, err := config.Load("config/client.yaml", config.DefaultClient())
|
||||
cfg, err := config.Load(paths.Join("config", "client.yaml"), config.DefaultClient())
|
||||
if err != nil {
|
||||
log.Warnf("配置加载失败,使用默认值:%v", err)
|
||||
}
|
||||
@@ -235,7 +238,7 @@ func main() {
|
||||
|
||||
// 1) 内容包与图集(设计.md §1.3:扫描 mods/ + resourcepacks/)
|
||||
am := assets.New()
|
||||
if err := am.Load("assets", "mods", "resourcepacks"); err != nil {
|
||||
if err := am.Load(paths.Join("assets"), paths.Join("mods"), paths.Join("resourcepacks")); err != nil {
|
||||
log.Warnf("内容包加载失败:%v", err)
|
||||
}
|
||||
log.Infof("已加载 %d 个内容包", len(am.Packs()))
|
||||
@@ -282,15 +285,15 @@ func main() {
|
||||
}
|
||||
|
||||
// 2) 注册表(设计.md §6.1/§6.2 数据驱动)
|
||||
reg, err := block.Load("assets/config/blocks.json")
|
||||
reg, err := block.Load(paths.Join("assets", "config", "blocks.json"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
items, err := item.Load("assets/config/items.json")
|
||||
items, err := item.Load(paths.Join("assets", "config", "items.json"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
recipes, err := recipe.Load("assets/config/recipes.json")
|
||||
recipes, err := recipe.Load(paths.Join("assets", "config", "recipes.json"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -307,8 +310,8 @@ func main() {
|
||||
defer w.Close()
|
||||
|
||||
// 单机存档(存档与持久化.md §3:diff-only 载入,无存档则新建)
|
||||
if _, err := os.Stat("worlds/NewWorld/level.dat"); err == nil {
|
||||
if _, err := save.LoadWorld(w, "worlds", "NewWorld"); err != nil {
|
||||
if _, err := os.Stat(paths.Join("worlds", "NewWorld", "level.dat")); err == nil {
|
||||
if _, err := save.LoadWorld(w, paths.Join("worlds"), "NewWorld"); err != nil {
|
||||
log.Warnf("存档载入失败: %v", err)
|
||||
} else {
|
||||
log.Infof("已载入世界 NewWorld")
|
||||
|
||||
Reference in New Issue
Block a user