package main

import (
	"github.com/veandco/go-sdl2/sdl"
	"zworld/engine"
	"zworld/engine/core/zlog"
	"zworld/engine/render/vulkan/instance"
	"zworld/engine/rule"
	"zworld/engine/window"
	"zworld/plugin/objloader"
)

func main() {
	w := engine.NewWorld(nil,
		engine.FTimeRuleOption(&rule.FTimeRule{}),
		engine.FActorRuleOption(&rule.FActorRule{}),
		engine.FRenderRuleOption(&rule.FRenderRule{}))
	err, mesh := objloader.LoadObj("asset/model/sphere.obj")
	zlog.Infof("err", err, len(mesh.Positions))
	win := window.NewSDLWindow(640, 720)
	err = win.CreateWindow()
	if err != nil {
		zlog.Infof("err", err)
	}
	vulkan := instance.New("test", win, window.CreateLoaderFromSDL)
	vulkan.EnumeratePhysicalDevices()
	err = vulkan.Init()
	if err != nil {
		zlog.Infof("err", err)
		return
	}
appLoop:
	for true {
		for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch event.(type) {
			case *sdl.QuitEvent:
				break appLoop
			}
		}
		err := vulkan.DrawFrame()
		if err != nil {
			zlog.Infof("err", err)
			break appLoop
		}
	}

	_, err = vulkan.WaitIdle()
	zlog.Infof("err", err)
	for i := 1; i < 100; i++ {
		w.Tick()
	}
}
