本文整理匯總了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++
}
}
}