func (q *QmlDebugDrawer) StartUp(config types.JGameObject) {
	defer debug.Trace().UnTrace()

	qml.RegisterTypes("SqclDebugDrawExtensions", 1, 0, []qml.TypeSpec{{
		Init: func(r *GoBox, obj qml.Object) {
			r.Object = obj
		},
	}})

	cfg := config.Comp("graphics.Config").(*Config)
	file := `
import QtQuick 2.0
import SqclDebugDrawExtensions 1.0

Item {
    property var box : Component {
        Rectangle {
            opacity: 0.5;
            width: 100; height: 100;
            border.width:5;
            border.color:"blue";
        }
    }
}
    `
	component, err := cfg.Engine.LoadString("file.qml", strings.TrimSpace(file))
	if err != nil {
		panic(err)
	}
	q.Comp = component.Create(nil)
	q.engine = cfg.Engine
	q.window = cfg.Window
}
Example #2
0
func (c *GoQmlRect) Paint(p *qml.Painter) {
	defer debug.Trace().UnTrace()

	gl := GL.API(p)

	trans := c.R.Owner().Comp("physics.Transform").(*physics.Transform)
	c.Set("x", trans.X)
	c.Set("y", trans.Y)
	width := float32(c.Int("width"))
	height := float32(c.Int("height"))

	gl.Enable(GL.BLEND)
	gl.BlendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA)
	gl.Color4f(1.0, 1.0, 1.0, 0.8)
	gl.Begin(GL.QUADS)
	gl.Vertex2f(0, 0)
	gl.Vertex2f(width, 0)
	gl.Vertex2f(width, height)
	gl.Vertex2f(0, height)
	gl.End()

	gl.LineWidth(2.5)
	gl.Color4f(0.0, 0.0, 0.0, 1.0)
	gl.Begin(GL.LINES)
	gl.Vertex2f(0, 0)
	gl.Vertex2f(width, height)
	gl.Vertex2f(width, 0)
	gl.Vertex2f(0, height)
	gl.End()
}
func (q *QmlDebugDrawer) AddLine(goc types.JGameObject, x1, y1, x2, y2 int) {
	defer debug.Trace().UnTrace()

	if q.Object == nil {
		q.Object = &GoBox{x1: x1, y1: y1, x2: x2, y2: y2}
		q.Object.Init()
		q.goc = goc

		input := core.Core.Manager("QmlInputMngr").(types.JManager)
		// TODO: how to unregister specific message?
		// tracker := goc.Register("collision", input, func(e event.Data) {
		goc.Register("collision", input, func(e event.Data) {
			border := q.Object.Property("border").(qml.Object)
			red := color.RGBA{255, 0, 0, 255}
			if border.Color("color") == red {
				border.Set("color", "blue")
			} else {
				border.Set("color", "red")
			}
		})
		// goc.Unregister(tracker)
		// tracker.Unlink()
	} else {
		q.Object.Deinit()
		q.Object = nil
	}
}
func (c *GoBox) Init() {
	defer debug.Trace().UnTrace()

	grfx := core.Core.Manager("QmlDebugDrawer").(*QmlDebugDrawer)
	c.Object = grfx.Comp.Object("box").Create(nil)

	c.Set("parent", grfx.window.Root())
}
Example #5
0
func (q *QmlInputMngr) StartUp(config types.JGameObject) {
	defer debug.Trace().UnTrace()
	// cfg := config.Comp("input.Config").(*input.Config)

	q.Register("register_input_comp", core.Core.RootSpace, func(e event.Data) {
		q.registerInputHandler(e.(*InputHandler))
	})
}
func (c *InputHandler) movePlayer(x, y int) {
	defer debug.Trace().UnTrace()

	trans := c.Owner().Comp("physics.Transform").(*physics.Transform)
	trans.X += (10 * x)
	trans.Y += (10 * y)

	debug.Msg(trans.X, trans.Y)
}
func (q *QmlDebugDrawer) EndFrame() {
	defer debug.Trace().UnTrace()

	if q.Object != nil {
		trans := q.goc.Comp("physics.Transform").(*physics.Transform)
		q.Object.Set("x", trans.X)
		q.Object.Set("y", trans.Y)
	}
}
Example #8
0
func (t *Transform) Init() {
	defer debug.Trace().UnTrace()

	input := core.Core.Manager("QmlInputMngr").(types.JManager)

	t.Owner().Register("debug_draw", input, func(e event.Data) {
		t.DebugDraw()
	})
}
Example #9
0
func (q *QmlGrfxMngr) EndFrame() {
	defer debug.Trace().UnTrace()

	if q.r != nil {
		trans := q.r.Owner().Comp("physics.Transform").(*physics.Transform)
		q.r.Set("x", trans.X)
		q.r.Set("y", trans.Y)
		// 	// qml.Changed(q.r, fieldAddr)
	}
}
Example #10
0
func (q *QmlGrfxMngr) StartUp(config types.JGameObject) {
	defer debug.Trace().UnTrace()

	types := []qml.TypeSpec{
		{
			Init: func(r *GoQmlRect, obj qml.Object) {
				defer debug.Trace().UnTrace()
				r.Object = obj
			},
		},
	}
	qml.RegisterTypes("GoExtensions", 1, 0, types)

	cfg := config.Comp("graphics.Config").(*Config)
	q.engine = cfg.Engine
	q.window = cfg.Window
	q.window.Set("width", cfg.W)
	q.window.Set("height", cfg.H)
}
Example #11
0
func (c *core) StartUp(config JGameObjectHandle) {
	defer debug.Trace().UnTrace()

	for _, m := range c.managers {
		m.StartUp(config)
	}

	for _, s := range c.spaces {
		s.Init()
	}
}
Example #12
0
func (c *core) ShutDown() {
	defer debug.Trace().UnTrace()

	for i := len(c.spaces) - 1; i >= 0; i-- {
		c.spaces[i].DeInit()
	}

	for i := len(c.managers) - 1; i >= 0; i-- {
		c.managers[i].ShutDown()
	}
}
Example #13
0
// HandleKey handles keyboard events
func (q *QmlInputMngr) HandleKey(key int, shift_mod, ctrl_mod, alt_mod bool) {
	defer debug.Trace().UnTrace()

	switch keycodes.Keycode(key) {
	case keycodes.Key_None:
		// do nothing
	case keycodes.Key_Alt, keycodes.Key_Shift, keycodes.Key_Control:
		debug.Msg(keycodes.Keycode(key))
		debug.Msg()
	default:
		// TODO(jemorgan): move this logic into input system
		switch key {
		case keycodes.Key_Right:
			q.Dispatch("move_right", nil)
			return
		case keycodes.Key_Left:
			q.Dispatch("move_left", nil)
			return
		case keycodes.Key_Up:
			q.Dispatch("move_up", nil)
			return
		case keycodes.Key_Down:
			q.Dispatch("move_down", nil)
			return
		case keycodes.Key_D:
			q.Dispatch("debug_draw", nil)
		case keycodes.Key_F:
			q.Dispatch("collision", nil)
		}

		if shift_mod && key != keycodes.Key_Shift {
			debug.Msg("shift+")
		}
		if ctrl_mod && key != keycodes.Key_Control {
			debug.Msg("ctrl+")
		}
		if alt_mod && key != keycodes.Key_Alt {
			debug.Msg("alt+")
		}
		debug.Msg(keycodes.Keycode(key))
		debug.Msg()
	}

	if shift_mod && key == keycodes.Key_Q {
		os.Exit(1)
	}
	// if key == keycodes.Key_T {
	//     ctrl.Timer.Set("running", true)
	// }
}
Example #14
0
func (c *GoRect) Init() {
	defer debug.Trace().UnTrace()

	grfx := core.Core.Manager("QmlGrfxMngr").(*QmlGrfxMngr)
	grfx.r = c
	component, err := grfx.engine.LoadFile("file3.qml")
	if err != nil {
		panic(err)
	}
	c.Object = component.Create(nil)
	obj := c.Object.Interface().(*GoQmlRect)
	obj.R = c
	obj.Test = "what"

	c.Set("parent", grfx.window.Root())
}
Example #15
0
// LoadConfig is needed as a backdoor to factory not being inititalized
func LoadConfig(file string) types.JGameObject {
	defer debug.Trace().UnTrace()

	data, err := support.OpenFile(file)
	if err != nil {
		debug.Fatal("Failed to open Config file: " + file)
	}

	holder, err := support.ReadData(data)
	if err != nil {
		debug.Fatal("Failed to read in Config file: " + file)
		return nil
	}

	goc := types.JGoc{}
	serialization.SerializeInPlace(&goc, holder)
	return &goc
}
Example #16
0
// s := f.Create(f1, Name("space"))
// goc1 := f.Create(f2, Owner(s), Name("goc1"))
// goc2 := f.Create(f2, Owner(s), Dispatcher(d))
func (f *Factory) Create(file string, opts ...FactoryOpt) types.JGameObject {
	defer debug.Trace().UnTrace()

	// read in game object data

	data, err := support.OpenFile(file)
	if err != nil {
		debug.Fatal("OpenFile (", file, "):", err)
	}

	holder, err := support.ReadData(data)
	if err != nil {
		debug.Fatal("ReadData (", file, "):", err)
	}

	m := holder.(map[string]interface{})
	typename, found := m["Type"]
	if !found {
		debug.Fatal("'Type' member not found in holder")
	}
	obj := serialization.FactoryFunc(typename.(string)).(types.JGameObject)
	serialization.SerializeInPlace(obj, holder)

	// apply options to game object
	for _, opt := range opts {
		opt(obj)
	}

	// check for transform, check for dispatcher, name etc

	if obj.Name() == "" {
		obj.SetName(fmt.Sprint("obj", len(f.ObjList)))
	}

	// add game object to factory

	f.ObjList = append(f.ObjList, obj)
	return obj
	// h := types.JGameObject{id: len(f.ObjList)}
	// f.NameMap[obj.Name()] = h
	// return h
}
Example #17
0
// s := f.Create(f1, Name("space"))
// goc1 := f.Create(f2, Owner(s), Name("goc1"))
// goc2 := f.Create(f2, Owner(s), Dispatcher(d))
func (f *Factory) Create(file string, opts ...FactoryOpt) JGameObjectHandle {
	defer debug.Trace().UnTrace()

	// read in game object data

	data, err := support.OpenFile(file)
	if err != nil {
		support.LogFatal("Failed to open Config file: " + file)
	}

	holder, err := support.ReadData(data)
	if err != nil {
		support.LogFatal("Failed to read in Config file: " + file)
		return nil
	}

	m := v.(map[string]interface{})
	typename, err := m["Type"]
	if err != nil {
		log.Panic(err)
	}
	obj := factoryFunc(typename.(string))
	SerializeInPlace(obj, holder)

	// apply options to game object
	for _, opt := range opts {
		opt(obj)
	}

	// check for transform, check for dispatcher, name etc

	if obj.Name() == "" {
		obj.SetName(fmt.Sprint("obj", len(f.ObjList)))
	}

	// add game object to factory

	f.ObjList = append(f.ObjList, obj)
	h := JGameObjectHandle{id: len(f.ObjList)}
	f.NameMap[obj.Name()] = h
	return h
}
func (c *InputHandler) Init() {
	defer debug.Trace().UnTrace()

	core.Core.RootSpace.Dispatch("register_input_comp", c)

	input := core.Core.Manager("QmlInputMngr").(*QmlInputMngr)

	c.Owner().Register("move_left", input, func(e event.Data) {
		c.movePlayer(-1, 0)
	})
	c.Owner().Register("move_right", input, func(e event.Data) {
		c.movePlayer(1, 0)
	})
	c.Owner().Register("move_down", input, func(e event.Data) {
		c.movePlayer(0, 1)
	})
	c.Owner().Register("move_up", input, func(e event.Data) {
		c.movePlayer(0, -1)
	})
}
Example #19
0
func (c *core) Step() {
	defer debug.Trace().UnTrace()

	if c.TimeStamp.IsZero() {
		c.TimeStamp = time.Now()
	}

	if dt := time.Since(c.TimeStamp); dt >= 16*time.Millisecond {
		fmt.Println("frame:", c.CurrFrame)
		c.CurrFrame++

		for _, mgr := range c.managers {
			mgr.BeginFrame()
			defer mgr.EndFrame()
		}

		for _, spc := range c.spaces {
			spc.Update(float32(dt))
		}
		fmt.Println()
	}
}
Example #20
0
func (c *core) Step() {
	defer debug.Trace().UnTrace()

	c.TimeStamp = time.Now()
	dt := time.Since(c.TimeStamp)
	// if dt < 16*time.Millisecond { return }
	debug.Msg()
	debug.Msg("frame:", c.CurrFrame)
	debug.Log("dt:", dt)
	c.CurrFrame++

	for _, mgr := range c.managers {
		mgr.BeginFrame()
		defer mgr.EndFrame()
	}

	for _, spc := range c.spaces {
		spc.Update(dt)
	}

	debug.Msg()
	// }
}
Example #21
0
func (f *Factory) BeginFrame() {
	defer debug.Trace().UnTrace()

}
Example #22
0
func (q *QmlGrfxMngr) ShutDown() {
	defer debug.Trace().UnTrace()
}
Example #23
0
func (q *QmlDebugDrawer) BeginFrame() {
	defer debug.Trace().UnTrace()
}
Example #24
0
func (q *QmlDebugDrawer) ShutDown() {
	defer debug.Trace().UnTrace()
}
Example #25
0
func (c *GoBox) Deinit() {
	defer debug.Trace().UnTrace()
	debug.Msg(c.x1, c.y1, c.x2, c.y2)
	c.Destroy()
}
Example #26
0
func (f *Factory) MarkObjectForDeletion(types.JGameObject) {
	defer debug.Trace().UnTrace()

}
Example #27
0
func (f *Factory) endOfFrameCleanup() {
	defer debug.Trace().UnTrace()
}
Example #28
0
func (f *Factory) ShutDown() {
	defer debug.Trace().UnTrace()

}
Example #29
0
func (f *Factory) StartUp(config types.JGameObject) {
	defer debug.Trace().UnTrace()

}
Example #30
0
func (q *QmlGrfxMngr) BeginFrame() {
	defer debug.Trace().UnTrace()
}