本文整理汇总了Golang中github.com/runningwild/cgf.Engine.Kill方法的典型用法代码示例。如果您正苦于以下问题:Golang Engine.Kill方法的具体用法?Golang Engine.Kill怎么用?Golang Engine.Kill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/runningwild/cgf.Engine
的用法示例。
在下文中一共展示了Engine.Kill方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: mainLoop
func mainLoop(engine *cgf.Engine, mode string) {
defer engine.Kill()
var profile_output *os.File
var contention_output *os.File
var num_mem_profiles int
// ui.AddChild(base.MakeConsole())
ticker := time.Tick(time.Millisecond * 17)
ui := g2.Make(0, 0, wdx, wdy)
ui.AddChild(&game.GameWindow{Engine: engine, Dims: g2.Dims{wdx - 50, wdy - 50}}, g2.AnchorDeadCenter)
ui.AddChild(g2.MakeConsole(wdx-50, wdy-50), g2.AnchorDeadCenter)
// side0Index := gin.In().BindDerivedKeyFamily("Side0", gin.In().MakeBindingFamily(gin.Key1, []gin.KeyIndex{gin.EitherControl}, []bool{true}))
// side1Index := gin.In().BindDerivedKeyFamily("Side1", gin.In().MakeBindingFamily(gin.Key2, []gin.KeyIndex{gin.EitherControl}, []bool{true}))
// side2Index := gin.In().BindDerivedKeyFamily("Side2", gin.In().MakeBindingFamily(gin.Key3, []gin.KeyIndex{gin.EitherControl}, []bool{true}))
// side0Key := gin.In().GetKeyFlat(side0Index, gin.DeviceTypeAny, gin.DeviceIndexAny)
// side1Key := gin.In().GetKeyFlat(side1Index, gin.DeviceTypeAny, gin.DeviceIndexAny)
// side2Key := gin.In().GetKeyFlat(side2Index, gin.DeviceTypeAny, gin.DeviceIndexAny)
defer ui.StopEventListening()
for {
<-ticker
if gin.In().GetKey(gin.AnyEscape).FramePressCount() != 0 {
return
}
start := time.Now()
sys.Think()
start = time.Now()
render.Queue(func() {
ui.Draw()
})
render.Queue(func() {
start = time.Now()
sys.SwapBuffers()
})
render.Purge()
start = time.Now()
// TODO: Replace the 'P' key with an appropriate keybind
var err error
if gin.In().GetKey(gin.AnyKeyP).FramePressCount() > 0 {
if profile_output == nil {
profile_output, err = os.Create(filepath.Join(datadir, "cpu.prof"))
if err == nil {
err = pprof.StartCPUProfile(profile_output)
if err != nil {
base.Log().Printf("Unable to start CPU profile: %v\n", err)
profile_output.Close()
profile_output = nil
}
base.Log().Printf("cpu prof: %v\n", profile_output)
} else {
base.Log().Printf("Unable to start CPU profile: %v\n", err)
}
} else {
pprof.StopCPUProfile()
profile_output.Close()
profile_output = nil
}
}
if gin.In().GetKey(gin.AnyKeyL).FramePressCount() > 0 {
if contention_output == nil {
contention_output, err = os.Create(filepath.Join(datadir, "contention.prof"))
if err == nil {
runtime.SetBlockProfileRate(1)
base.Log().Printf("contention prof: %v\n", contention_output)
} else {
base.Log().Printf("Unable to start contention profile: %v\n", err)
}
} else {
pprof.Lookup("block").WriteTo(contention_output, 0)
contention_output.Close()
contention_output = nil
}
}
// TODO: Replace the 'M' key with an appropriate keybind
if gin.In().GetKey(gin.AnyKeyM).FramePressCount() > 0 {
f, err := os.Create(filepath.Join(datadir, fmt.Sprintf("mem.%d.prof", num_mem_profiles)))
if err != nil {
base.Error().Printf("Unable to write mem profile: %v", err)
}
pprof.WriteHeapProfile(f)
f.Close()
num_mem_profiles++
}
}
}