本文整理汇总了Golang中github.com/runningwild/glop/render.Queue函数的典型用法代码示例。如果您正苦于以下问题:Golang Queue函数的具体用法?Golang Queue怎么用?Golang Queue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Queue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
sys := system.Make(gos.GetSystemInterface())
sys.Startup()
render.Init()
render.Queue(func() {
initWindow(sys, 800, 600)
})
font := loadDictionary("skia.dict")
fmt.Fprintf(log, "Font: %v", font)
for true {
sys.Think()
render.Queue(func() {
// gl.Color4ub(0, 255, 255, 255)
// gl.Begin(gl.QUADS)
// gl.Vertex2d(100, 100)
// gl.Vertex2d(500, 100)
// gl.Vertex2d(500, 150)
// gl.Vertex2d(100, 150)
// gl.End()
font.SetFontColor(1, 1, 1)
font.RenderString("TEST", 100, 100, 100)
sys.SwapBuffers()
})
render.Purge()
if gin.In().GetKey(gin.AnyEscape).FramePressCount() > 0 {
break
}
}
}
示例2: main
func main() {
sys.Startup()
err := gl.Init()
if err != nil {
base.Error().Fatalf("%v", err)
}
render.Init()
render.Queue(func() {
sys.CreateWindow(10, 10, wdx, wdy)
sys.EnableVSync(true)
})
base.InitShaders()
runtime.GOMAXPROCS(10)
sys.Think()
console := base.MakeConsole(wdx, wdy)
controllers := getPlayers(console)
base.Log().Printf("%v\n", controllers)
go server.Main()
base.LoadAllDictionaries()
client, err := game.MakeClient("127.0.0.1", 1231)
if err != nil {
base.Error().Printf("Unable to connect to server: %v\n", err)
return
}
mainLoop(client, controllers, console)
}
示例3: Scavenger
// Launch this in its own go-routine if you want to occassionally
// delete textures that haven't been used in a while.
func (m *Manager) Scavenger() {
var unused []string
for {
time.Sleep(time.Minute)
unused = unused[0:0]
m.mutex.RLock()
for s, d := range m.registry {
if generation-d.accessed >= 2 {
unused = append(unused, s)
}
}
m.mutex.RUnlock()
m.mutex.Lock()
generation++
if len(unused) == 0 {
m.mutex.Unlock()
continue
}
var unused_data []*Data
for _, s := range unused {
unused_data = append(unused_data, m.registry[s])
m.deleted[s] = m.registry[s]
delete(m.registry, s)
}
render.Queue(func() {
for _, d := range unused_data {
gl.DeleteTextures(1, (*gl.Uint)(&d.texture))
d.texture = 0
}
})
m.mutex.Unlock()
}
}
示例4: main
func main() {
runtime.GOMAXPROCS(2)
sys := system.Make(gos.GetSystemInterface())
sys.Startup()
game := Game{}
var lb LevelBlueprint
loadJson(filepath.Join(base.DataDir(), "1p_basic_level.json"), &lb)
if len(lb.Players) == 0 || len(lb.Walls) == 0 {
panic(fmt.Sprintf("Invalid level config: %d players and %d walls.",
len(lb.Players), len(lb.Walls)))
}
engine, _ := cgf.NewLocalEngine(&game, int(Config.FrameTime*1000), nil)
engine.ApplyEvent(&NewLevelEvent{&lb})
render.Init()
render.Queue(func() {
initWindow(sys, Config.WindowWidth, Config.WindowHeight)
})
render.Purge()
ticker := time.Tick(time.Millisecond * time.Duration(Config.FrameTime*1000))
for true {
<-ticker
LocalThink(sys, engine, &game)
if gin.In().GetKey(gin.AnyEscape).FramePressCount() > 0 {
break
}
}
}
示例5: main
func main() {
defer base.StackCatcher()
sys.Startup()
err := gl.Init()
if err != nil {
base.Error().Fatalf("%v", err)
}
render.Init()
render.Queue(func() {
sys.CreateWindow(10, 10, wdx, wdy)
sys.EnableVSync(true)
})
base.InitShaders()
runtime.GOMAXPROCS(10)
sys.Think()
base.LoadAllDictionaries()
if Version() != "standard" {
engine := debugHookup(Version())
mainLoop(engine, "standard")
} else {
// TODO: Reimplement standard hookup
}
}
示例6: getPlayers
func getPlayers(console *base.Console) []gin.DeviceId {
var ct controllerTracker
gin.In().RegisterEventListener(&ct)
defer gin.In().UnregisterEventListener(&ct)
ticker := time.Tick(time.Millisecond * 17)
start := time.Time{}
readyDuration := time.Second * 2
for start.IsZero() || time.Now().Sub(start) < readyDuration {
<-ticker
sys.Think()
if ct.Ready() && start.IsZero() {
start = time.Now()
}
if !ct.Ready() {
start = time.Time{}
}
render.Queue(func() {
defer console.Draw(0, 0, wdx, wdy)
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Disable(gl.DEPTH_TEST)
gui.SetFontColor(1, 1, 1, 1)
gl.Disable(gl.TEXTURE_2D)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(gl.Double(0), gl.Double(wdx), gl.Double(wdy), gl.Double(0), 1000, -1000)
gl.ClearColor(0, 0, 0, 1)
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
base.GetDictionary("crackin").RenderString(fmt.Sprintf("Num players: %d", len(ct.ids)), float64(wdx)/2, 300, 0, 100, gui.Center)
base.GetDictionary("crackin").RenderString(fmt.Sprintf("Num ready: %d", ct.NumReady()), float64(wdx)/2, 400, 0, 100, gui.Center)
if !start.IsZero() {
base.GetDictionary("crackin").RenderString(fmt.Sprintf("Starting in %2.2f", (readyDuration-time.Now().Sub(start)).Seconds()), float64(wdx)/2, 500, 0, 100, gui.Center)
}
})
render.Queue(func() {
sys.SwapBuffers()
})
render.Purge()
}
var devices []gin.DeviceId
for id := range ct.ids {
devices = append(devices, id)
}
return devices
}
示例7: mainLoop
func mainLoop(client sgf.ClientEngine, controllers []gin.DeviceId, console *base.Console) {
client.MakeRequest(game.Join{Rebels: make([]*game.RebelPlayer, 2)})
ticker := time.Tick(time.Millisecond * 17)
render.Queue(func() {
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
})
for {
<-ticker
if gin.In().GetKey(gin.AnyEscape).FramePressCount() != 0 {
return
}
sys.Think()
render.Queue(func() {
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Disable(gl.DEPTH_TEST)
gui.SetFontColor(1, 1, 1, 1)
gl.Disable(gl.TEXTURE_2D)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(gl.Double(0), gl.Double(wdx), gl.Double(wdy), gl.Double(0), 1000, -1000)
gl.ClearColor(0, 0, 0, 1)
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
base.GetDictionary("crackin").RenderString("Waiting on some nubs", float64(wdx)/2, 300, 0, 100, gui.Center)
})
client.RLock()
g := client.Game().(*game.Game)
mode := g.Mode
client.RUnlock()
if mode == game.ModeWaiting {
} else if mode == game.ModeProgram {
programLoop(client, controllers, console)
} else if mode == game.ModeRun {
}
render.Queue(func() {
sys.SwapBuffers()
})
render.Purge()
}
}
示例8: setupGlStuff
// Sets up anything that wouldn't have been loaded from disk, including
// all opengl data, and sets up finalizers for that data.
func (d *Dictionary) setupGlStuff() {
d.dlists = make(map[string]uint32)
d.strs = make(map[string]strBuffer)
d.pars = make(map[string]strBuffer)
// TODO: This finalizer is untested
runtime.SetFinalizer(d, func(d *Dictionary) {
render.Queue(func() {
for _, v := range d.dlists {
gl.DeleteLists(gl.Uint(v), 1)
}
})
})
render.Queue(func() {
gl.Enable(gl.TEXTURE_2D)
gl.GenTextures(1, (*gl.Uint)(&d.texture))
gl.BindTexture(gl.TEXTURE_2D, gl.Uint(d.texture))
gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1)
gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
gl.TexImage2D(
gl.TEXTURE_2D,
0,
gl.ALPHA,
gl.Sizei(d.data.Dx),
gl.Sizei(d.data.Dy),
0,
gl.ALPHA,
gl.UNSIGNED_BYTE,
gl.Pointer(&d.data.Pix[0]))
gl.Disable(gl.TEXTURE_2D)
})
}
示例9: loadRoutine
func (s *sheet) loadRoutine() {
ready := make(chan bool, 1)
pixer := make(chan []byte)
for load := range s.load_chan {
if load {
go s.compose(pixer)
go func() {
render.Queue(func() {
s.makeTexture(pixer)
ready <- true
})
}()
} else {
go func() {
<-ready
render.Queue(func() {
gl.DeleteTextures(1, &s.texture)
s.texture = 0
})
}()
}
}
}
示例10: LocalThink
func LocalThink(sys system.System, engine *cgf.Engine, game *Game) {
sys.Think()
engine.Pause()
// We might have no level if the event has not gone through yet.
if game.Level != nil {
render.Queue(func() {
game.Render()
sys.SwapBuffers()
})
game.Level.LocalThink(sys, engine)
}
render.Purge()
engine.Unpause()
}
示例11: LoadDictionary
func LoadDictionary(r io.Reader) (*Dictionary, error) {
init_once.Do(func() {
render.Queue(func() {
err := render.RegisterShader("glop.font", []byte(font_vertex_shader), []byte(font_fragment_shader))
if err != nil {
panic(err)
}
})
render.Purge()
})
var d Dictionary
err := gob.NewDecoder(r).Decode(&d.data)
if err != nil {
return nil, err
}
d.setupGlStuff()
return &d, nil
}
示例12: LoadSprite
func (m *Manager) LoadSprite(path string) (*Sprite, error) {
// We can't run this during an init() function because it will get queued to
// run before the opengl context is created, so we just check here and run
// it if we haven't run it before.
gen_tex_once.Do(func() {
render.Queue(func() {
gl.Enable(gl.TEXTURE_2D)
gl.GenTextures(1, &error_texture)
gl.BindTexture(gl.TEXTURE_2D, error_texture)
gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
pink := []byte{255, 0, 255, 255}
gl.TexImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
1,
1,
0,
gl.RGBA,
gl.UNSIGNED_INT,
gl.Pointer(&pink[0]))
})
})
path = filepath.Clean(path)
err := m.loadSharedSprite(path)
if err != nil {
return nil, err
}
var s Sprite
m.mutex.Lock()
s.shared = m.shared[path]
m.mutex.Unlock()
s.anim_node = s.shared.anim_start
s.state_node = s.shared.state_start
return &s, nil
}
示例13: setupTextureList
func setupTextureList() {
textureListSync.Do(func() {
render.Queue(func() {
textureList = gl.GenLists(1)
gl.NewList(textureList, gl.COMPILE)
gl.Begin(gl.QUADS)
gl.TexCoord2d(0, -1)
gl.Vertex2i(0, 0)
gl.TexCoord2d(0, 0)
gl.Vertex2i(0, 1)
gl.TexCoord2d(1, 0)
gl.Vertex2i(1, 1)
gl.TexCoord2d(1, -1)
gl.Vertex2i(1, 0)
gl.End()
gl.EndList()
})
})
}
示例14: main
func main() {
defer base.StackCatcher()
fmt.Printf("sys.Startup()...")
sys.Startup()
fmt.Printf("successful.\n")
fmt.Printf("gl.Init()...")
err := gl.Init()
fmt.Printf("successful.\n")
if err != nil {
base.Error().Fatalf("%v", err)
}
fmt.Printf("render.Init()...")
render.Init()
fmt.Printf("successful.\n")
render.Queue(func() {
fmt.Printf("sys.CreateWindow()...")
sys.CreateWindow(10, 10, wdx, wdy)
fmt.Printf("successful.\n")
sys.EnableVSync(true)
})
base.InitShaders()
runtime.GOMAXPROCS(10)
fmt.Printf("sys.Think()...")
sys.Think()
fmt.Printf("successful.\n")
base.LoadAllDictionaries()
if Version() != "standard" {
engine, local := debugHookup(Version())
mainLoop(engine, local, "standard")
} else {
standardHookup()
}
}
示例15: main
func main() {
fmt.Printf("%v\n", key_map)
sys.Startup()
err := gl.Init()
if err != nil {
panic(err)
}
render.Init()
render.Queue(func() {
sys.CreateWindow(10, 10, wdx, wdy)
sys.EnableVSync(true)
err := gl.Init()
if err != nil {
panic(err)
}
})
base.InitShaders()
runtime.GOMAXPROCS(2)
ui, err = gui.Make(gin.In(), gui.Dims{wdx, wdy}, filepath.Join(datadir, "fonts", "skia.ttf"))
if err != nil {
panic(err)
}
sys.Think()
for false && len(sys.GetActiveDevices()[gin.DeviceTypeController]) < 2 {
time.Sleep(time.Millisecond * 100)
sys.Think()
}
var ids []int
var engine *cgf.Engine
var room game.Room
err = base.LoadJson(filepath.Join(base.GetDataDir(), "rooms/basic.json"), &room)
if err != nil {
panic(err)
}
if IsHost() {
sys.Think()
var g game.Game
g.Rng = cmwc.MakeGoodCmwc()
g.Rng.SeedWithDevRand()
g.Dx = 900
g.Dy = 600
g.Friction = 0.97
g.Friction_lava = 0.85
g.Room = room
var p game.Player
p.Color.R = 255
err := json.NewDecoder(bytes.NewBuffer([]byte(`
{
"Base": {
"Max_turn": 0.07,
"Max_acc": 0.2,
"Mass": 750,
"Max_rate": 10,
"Influence": 75,
"Health": 1000
},
"Dynamic": {
"Health": 1000
}
}
`))).Decode(&p.Stats)
if err != nil {
panic(err)
}
Nx := 2
Ny := 1
p.X = float64(g.Dx-Nx)/2 - 200
p.Y = float64(g.Dy-Ny)/2 - 200
for x := 0; x < Nx; x++ {
for y := 0; y < Ny; y++ {
p.X += float64(x * 25)
p.Y += float64(y * 25)
p.Gid++
// p.Mass += float64(x+y) * 150
p.Processes = make(map[int]game.Process)
temp := p
ids = append(ids, g.AddEnt(&temp))
// p.Mass -= float64(x+y) * 150
p.X -= float64(x * 25)
p.Y -= float64(y * 25)
}
}
g.Ents[0].(*game.Player).X = 500
g.Ents[0].(*game.Player).Y = 300
g.Ents[1].(*game.Player).X = 550
g.Ents[1].(*game.Player).Y = 300
g.SetLocalData()
d := sys.GetActiveDevices()
base.Log().Printf("%v\n", d)
n := 0
base.Log().Printf("%v\n", d[gin.DeviceTypeController])
for _, index := range d[gin.DeviceTypeController] {
// panic("ASD")
g.SetLocalPlayer(g.Ents[n].(*game.Player), index)
n++
if n > 2 {
break
//.........这里部分代码省略.........