func Example_core() {
	actOut = nil
	core := New()

	Mgr1 := &TestManager{name: "Mgr1", comp: "TestMgr1InitComponent"}
	Mgr2 := &TestManager{name: "Mgr2", comp: "TestMgr2InitComponent"}

	CoreFactoryFunc = func(name string) interface{} {
		var comp interface{}
		switch name {
		default:
			support.LogFatal("unknown component: %s", name)
		case "TestMgr1InitComponent":
			comp = &TestMgr1InitComponent{}
		case "TestMgr2InitComponent":
			comp = &TestMgr2InitComponent{}
		}
		return comp
	}

	core.RegisterManager(Mgr1)
	core.RegisterManager(Mgr2)

	cfg := LoadConfig("C:/Users/jmorgan/Sandbox/golang/rsrc/test/json/objects/kernel/TestCore.jrm")

	Spc1 := &TestSpace{name: "Spc1"}
	Spc2 := &TestSpace{name: "Spc2"}
	core.RegisterSpace(Spc1)
	core.RegisterSpace(Spc2)

	core.StartUp(cfg)

	core.State = Stopped
	core.Run()

	core.ShutDown()

	// sort.Reverse(sort.StringSlice(actOut))
	for _, s := range actOut {
		fmt.Println(s)
	}
	// Output:
	//
	// Mgr1 StartUp()
	// Mgr1 got config
	// Mgr2 StartUp()
	// Mgr2 got config
	// Spc1 Init()
	// Spc2 Init()
	// Mgr1 BeginFrame()
	// Mgr2 BeginFrame()
	// Spc1 Update()
	// Spc2 Update()
	// Mgr2 EndFrame()
	// Mgr1 EndFrame()
	// Spc2 DeInit()
	// Spc1 DeInit()
	// Mgr2 ShutDown()
	// Mgr1 ShutDown()
}
Example #2
0
// LoadConfig serialize in a GameObject from a text file.
func LoadConfig(file string) GameObject {
	defer debug.Trace().UnTrace()

	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
	}

	goc := Goc{}
	SerializeInPlace(&goc, holder)
	return &goc
}
Example #3
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 {
		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)
	return obj
	// h := types.JGameObject{id: len(f.ObjList)}
	// f.NameMap[obj.Name()] = h
	// return h
}
Example #4
0
func TestCore_Managers(t *testing.T) {
	core := New()

	// Test Setup
	Mgr1 := &TestManager{name: "Mgr1", comp: "TestMgr1InitComponent"}
	Mgr2 := &TestManager{name: "Mgr2", comp: "TestMgr2InitComponent"}

	CoreFactoryFunc = func(name string) interface{} {
		var comp interface{}
		switch name {
		default:
			support.LogFatal("unknown component: %s", name)
		case "TestMgr1InitComponent":
			comp = &TestMgr1InitComponent{}
		case "TestMgr2InitComponent":
			comp = &TestMgr2InitComponent{}
		}
		return comp
	}

	core.RegisterManager(Mgr1)
	core.RegisterManager(Mgr2)

	cfg := LoadConfig("C:/Users/jmorgan/Sandbox/golang/rsrc/test/json/objects/kernel/TestCore.jrm")

	// Testing Core.StartUp()
	actOut = nil
	expOut := []string{
		"Mgr1 StartUp()",
		"Mgr1 got config",
		"Mgr2 StartUp()",
		"Mgr2 got config",
	}
	core.StartUp(cfg)
	test.AssertEQ(t, len(expOut), len(actOut), "Length of actOut and expOut aren't equal. "+fmt.Sprintf("\n\t\tactOut: %v", actOut))
	for i, s := range actOut {
		test.ExpectEQ(t, expOut[i], s, fmt.Sprintf("With test %d: Initialization order was wrong.", i))
	}

	// Testing Core.Run()
	actOut = nil
	expOut = []string{
		"Mgr1 BeginFrame()",
		"Mgr2 BeginFrame()",
		"Mgr2 EndFrame()",
		"Mgr1 EndFrame()",
	}
	core.State = Stopped
	core.Run()
	test.AssertEQ(t, len(expOut), len(actOut), "Length of actOut and expOut aren't equal.")
	for i, s := range actOut {
		test.ExpectEQ(t, expOut[i], s, fmt.Sprintf("With test %d: Frame Update order was wrong.", i))
	}

	// Testing Core.ShutDown()
	actOut = nil
	expOut = []string{
		"Mgr2 ShutDown()",
		"Mgr1 ShutDown()",
	}
	core.ShutDown()
	test.AssertEQ(t, len(expOut), len(actOut), "Length of actOut and expOut aren't equal.")
	for i, s := range actOut {
		test.ExpectEQ(t, expOut[i], s, fmt.Sprintf("With test %d: DeInitialization order was wrong.", i))
	}
}