Exemplo n.º 1
0
Arquivo: main.go Projeto: bmatsuo/rex
func main() {
	background := context.Background()
	demo := NewDemo()

	// initialize the room server and launch the discovery server.
	config := &room.ServerConfig{
		Room: clidemo.Room,
		Bus:  room.NewBus(background, demo),
		Addr: room.BestAddr(),
	}
	if config.Addr == "" {
		log.Printf("[WARN] Unable to locate a good address for binding")
	}
	server, err := StartServer(config)
	if err != nil {
		log.Printf("[FATAL] Unable to initialize server: %v", err)
		os.Exit(1)
	}
	go RunDiscovery(background, server)

	// interactive applications will have their main loop occupied drawing and
	// handling events.  here we just wait for forever for the server to
	// terminate.
	err = server.Wait()
	if err != nil {
		log.Printf("[FATAL] Server terminated: %v", err)
		return
	}
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: bmatsuo/rex
// ServerMain performs the main routine for the demo server.
func ServerMain(a app.App) {
	background := context.Background()
	remotePt = make(chan rexdemo.RemotePoint, 1)
	demo = NewDemo()

	// initialize the room server and launch the discovery server.
	bestAddr := room.BestAddr()
	if bestAddr != "" {
		log.Printf("[WARN] Unable to locate a good address for binding")
	}
	config := &room.ServerConfig{
		Room: rexdemo.Room,
		Bus:  room.NewBus(background, demo),
		Addr: bestAddr,
	}
	server, err := StartServer(config)
	if err != nil {
		log.Printf("[FATAL] Unable to initialize server: %v", err)
		os.Exit(1)
	}
	go func() {
		err = server.Wait()
		if err != nil {
			log.Printf("[FATAL] Server terminated: %v", err)
			return
		}
	}()
	go RunDiscovery(background, server)

	var glctx gl.Context
	var sz size.Event
	for e := range a.Events() {
		select {
		case pt := <-remotePt:
			touchX = float32(pt.X * float64(sz.WidthPx))
			touchY = float32(pt.Y * float64(sz.HeightPx))
		default:
		}
		switch e := a.Filter(e).(type) {
		case lifecycle.Event:
			switch e.Crosses(lifecycle.StageVisible) {
			case lifecycle.CrossOn:
				glctx, _ = e.DrawContext.(gl.Context)
				onStart(glctx)
				a.Send(paint.Event{})
			case lifecycle.CrossOff:
				onStop(glctx)
				glctx = nil
			}
		case size.Event:
			sz = e
			touchX = float32(sz.WidthPx / 2)
			touchY = float32(sz.HeightPx / 2)
		case paint.Event:
			if glctx == nil || e.External {
				// As we are actively painting as fast as
				// we can (usually 60 FPS), skip any paint
				// events sent by the system.
				continue
			}

			onPaint(glctx, sz)
			a.Publish()
			// Drive the animation by preparing to paint the next frame
			// after this one is shown.
			a.Send(paint.Event{})
		case touch.Event:
			touchX = e.X
			touchY = e.Y
		}
	}
}