场景创建何时被触发

场景被创建发生在房间被创建时。

在 NewRoom() -> room.Start() -> this.Scene.Init(this) 开始整个场景的搭建工作。

func (this *Room) Start() bool {
    // ...(省略无关代码)
    // 按大小初始化房间大小
    this.Scene.Init(this)
    // ...(省略无关代码)
}

项目中创建场景代码分析 - Scene.go

func (this *Scene) Init(room IRoom) {
    this.room = room

    this.mapConfig = conf.GetMapConfigById(this.SceneID())
    this.scenePhysic = physic.NewScenePhysic()
    this.Players = make(map[uint64]*plr.ScenePlayer)
    this.SceneBallHelper.Init(this.mapConfig.Size)
    this.LoadMap()
    for i := 0; i < this.cellNumX*this.cellNumY; i++ {
        this.cells = append(this.cells, cll.NewCell(i))
    }
    this.reset()
}

主要包括创建下面的内容:

  • 创建物理层( this.scenePhysic = physic.NewScenePhysic() )
  • 创建静态障碍物分布( this.LoadMap() )
  • 创建Cell( this.cells = append(this.cells, cll.NewCell(i)) )
  • 创建食物、动态障碍物分布( this.reset() )

如何表示测试场景

服务器端,编码特点上,通常都是逻辑,比较难测试全面。

因此需要某些具象化的辅助测试。

这样在服务器端与客户端联调代码前,能把低级错误、或某些明显的错误给修掉。

py_guiclient场景表现示例

图1

如图,这样可以清晰的知道场景构建是否有错误。

借助简单的辅助工具,先走通一遍流程。这样可以让自己的代码在与客户端联调时的更顺利开展。

results matching ""

    No results matching ""