Skip to content

Commit

Permalink
build tag for vulkan uses go-vulkan's glfw3.3
Browse files Browse the repository at this point in the history
and use sync.Once in exit so we don't close a closed channel
  • Loading branch information
Noofbiz committed Jan 2, 2019
1 parent 3dcba6e commit 8072e4e
Show file tree
Hide file tree
Showing 7 changed files with 581 additions and 10 deletions.
2 changes: 1 addition & 1 deletion common/mouse.go
Expand Up @@ -178,7 +178,7 @@ func (m *MouseSystem) Remove(basic ecs.BasicEntity) {
func (m *MouseSystem) Update(dt float32) {
// Translate Mouse.X and Mouse.Y into "game coordinates"
switch engo.CurrentBackEnd {
case engo.BackEndGLFW, engo.BackEndSDL:
case engo.BackEndGLFW, engo.BackEndSDL, engo.BackEndVulkan:
m.mouseX = engo.Input.Mouse.X*m.camera.Z() + (m.camera.X()-(engo.GameWidth()/2)*m.camera.Z())/engo.GetGlobalScale().X
m.mouseY = engo.Input.Mouse.Y*m.camera.Z() + (m.camera.Y()-(engo.GameHeight()/2)*m.camera.Z())/engo.GetGlobalScale().Y
case engo.BackEndMobile:
Expand Down
7 changes: 6 additions & 1 deletion engo.go
Expand Up @@ -22,6 +22,8 @@ const (
BackEndSDL
// BackEndHeadless does not use a window manager for the backend
BackEndHeadless
// BackEndVulkan uses glfw 3.3 from vulkan-go and vulkan as a render surface
BackEndVulkan
)

var (
Expand All @@ -40,6 +42,7 @@ var (
opts RunOptions
resetLoopTicker = make(chan bool, 1)
closeGame = make(chan struct{})
closeGameOnce sync.Once
gameWidth, gameHeight float32
windowWidth, windowHeight float32
canvasWidth, canvasHeight float32
Expand Down Expand Up @@ -262,7 +265,9 @@ func ScaleOnResize() bool {

// Exit is the safest way to close your game, as `engo` will correctly attempt to close all windows, handlers and contexts
func Exit() {
close(closeGame)
closeGameOnce.Do(func() {
close(closeGame)
})
}

// GameWidth returns the current game width
Expand Down
7 changes: 3 additions & 4 deletions engo_glfw.go
@@ -1,5 +1,5 @@
// +build darwin,!arm,!arm64 linux windows
// +build !ios,!android,!netgo,!sdl,!headless
// +build !ios,!android,!netgo,!sdl,!headless,!vulkan

package engo

Expand Down Expand Up @@ -209,10 +209,9 @@ func CreateWindow(title string, width, height int, fullscreen bool, msaa int) {
// it's like KeyCallback, but for specific characters instead of keys...?
// responder.Type(char)
})

Window.SetCloseCallback(func(Window *glfw.Window) {
go func() {
closeGame <- struct{}{}
}()
Exit()
})
}

Expand Down
4 changes: 1 addition & 3 deletions engo_sdl.go
Expand Up @@ -130,9 +130,7 @@ func RunIteration() {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch e := event.(type) {
case *sdl.QuitEvent:
go func() {
closeGame <- struct{}{}
}()
Exit()
case *sdl.KeyboardEvent:
key := Key(e.Keysym.Sym)
if e.GetType() == sdl.KEYUP {
Expand Down

0 comments on commit 8072e4e

Please sign in to comment.