lazarus/platform/platform.go

49 lines
721 B
Go
Raw Normal View History

package platform
import (
2019-01-01 01:10:45 +00:00
"log"
2018-12-27 22:35:06 +00:00
"runtime"
2018-12-27 21:59:35 +00:00
"github.com/veandco/go-sdl2/sdl"
)
var platfromState struct {
2019-01-01 00:52:53 +00:00
sdlIsInit bool
}
2018-12-31 21:40:02 +00:00
func Advance() (bool, error) {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch event.(type) {
case *sdl.QuitEvent:
return false, nil
default:
if _, err := windowProcessEvent(event); err != nil {
2018-12-31 21:40:02 +00:00
return false, err
}
}
}
run, err := windowAdvance()
if !run {
WindowDestroy()
2018-12-27 22:35:06 +00:00
}
return run, err
2018-12-27 22:35:06 +00:00
}
func platformInit() error {
if platfromState.sdlIsInit {
return nil
2019-01-01 00:52:53 +00:00
}
runtime.LockOSThread()
log.Println("sdl init")
if err := sdl.Init(sdl.INIT_VIDEO); err != nil {
return err
}
2018-12-31 21:40:02 +00:00
platfromState.sdlIsInit = true
2018-12-31 21:40:02 +00:00
return nil
}