2018-12-27 21:36:34 +00:00
|
|
|
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
|
|
|
|
2018-12-27 21:36:34 +00:00
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
|
|
)
|
|
|
|
|
2019-01-07 01:00:19 +00:00
|
|
|
var platfromState struct {
|
2019-01-01 00:52:53 +00:00
|
|
|
sdlIsInit bool
|
2018-12-28 17:26:05 +00:00
|
|
|
}
|
|
|
|
|
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:
|
2019-01-07 01:00:19 +00:00
|
|
|
if _, err := windowProcessEvent(event); err != nil {
|
2018-12-31 21:40:02 +00:00
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 01:00:19 +00:00
|
|
|
run, err := windowAdvance()
|
|
|
|
if !run {
|
|
|
|
WindowDestroy()
|
2018-12-27 22:35:06 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 01:00:19 +00:00
|
|
|
return run, err
|
2018-12-27 22:35:06 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 01:00:19 +00:00
|
|
|
func platformInit() error {
|
|
|
|
if platfromState.sdlIsInit {
|
|
|
|
return nil
|
2019-01-01 00:52:53 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 01:00:19 +00:00
|
|
|
runtime.LockOSThread()
|
2018-12-28 17:26:05 +00:00
|
|
|
|
2019-01-07 01:00:19 +00:00
|
|
|
log.Println("sdl init")
|
|
|
|
if err := sdl.Init(sdl.INIT_VIDEO); err != nil {
|
|
|
|
return err
|
2018-12-28 17:26:05 +00:00
|
|
|
}
|
2018-12-31 21:40:02 +00:00
|
|
|
|
2019-01-07 01:00:19 +00:00
|
|
|
platfromState.sdlIsInit = true
|
2018-12-31 21:40:02 +00:00
|
|
|
return nil
|
2018-12-28 17:26:05 +00:00
|
|
|
}
|