Simplify the game interface

This commit is contained in:
bloeys
2022-07-02 21:21:59 +04:00
parent 901d8e2b5e
commit e1bf0697fc
3 changed files with 33 additions and 42 deletions

View File

@ -3,6 +3,7 @@ package engine
import (
"runtime"
"github.com/bloeys/nmage/asserts"
"github.com/bloeys/nmage/input"
"github.com/bloeys/nmage/renderer"
"github.com/bloeys/nmage/timing"
@ -11,6 +12,10 @@ import (
"github.com/veandco/go-sdl2/sdl"
)
var (
isInited = false
)
type Window struct {
SDLWin *sdl.Window
GlCtx sdl.GLContext
@ -96,6 +101,8 @@ func (w *Window) Destroy() error {
func Init() error {
isInited = true
runtime.LockOSThread()
timing.Init()
err := initSDL()
@ -139,6 +146,7 @@ func CreateOpenGLWindowCentered(title string, width, height int32, flags WindowF
func createWindow(title string, x, y, width, height int32, flags WindowFlags, rend renderer.Render) (*Window, error) {
asserts.T(isInited, "engine.Init was not called!")
if x == -1 && y == -1 {
x = sdl.WINDOWPOS_CENTERED
y = sdl.WINDOWPOS_CENTERED
@ -186,6 +194,8 @@ func initOpenGL() error {
}
func SetVSync(enabled bool) {
asserts.T(isInited, "engine.Init was not called!")
if enabled {
sdl.GLSetSwapInterval(1)
} else {