mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
Add ebitenmobileview package for internal usage
This is a preparation for the ebitenmobile command.
This commit is contained in:
parent
d469084fd3
commit
c93075d1dc
76
mobile/ebitenmobileview/ebitenmobileview.go
Normal file
76
mobile/ebitenmobileview/ebitenmobileview.go
Normal file
@ -0,0 +1,76 @@
|
||||
// Copyright 2016 Hajime Hoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package ebitenmobileview offers functions for OpenGL/Metal view of mobiles.
|
||||
//
|
||||
// The functions are not intended for public usages, and there is no guarantee of
|
||||
// backward compatibility.
|
||||
package ebitenmobileview
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
)
|
||||
|
||||
var (
|
||||
// mobileMutex is a mutex required for each function.
|
||||
// For example, on Android, Update can be called from a different thread:
|
||||
// https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer
|
||||
mobileMutex sync.Mutex
|
||||
)
|
||||
|
||||
func Run(width, height int, scale float64, title string) {
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
if updateFunc == nil {
|
||||
panic("ebitenmobileview: SetUpdateFunc must be called before Run")
|
||||
}
|
||||
start(updateFunc, width, height, scale, title)
|
||||
}
|
||||
|
||||
func Update() error {
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
return update()
|
||||
}
|
||||
|
||||
func UpdateTouchesOnAndroid(action int, id int, x, y int) {
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
updateTouchesOnAndroid(action, id, x, y)
|
||||
}
|
||||
|
||||
func UpdateTouchesOnIOS(phase int, ptr int64, x, y int) {
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
updateTouchesOnIOSImpl(phase, ptr, x, y)
|
||||
}
|
||||
|
||||
var updateFunc func(*ebiten.Image) error
|
||||
|
||||
func SetUpdateFunc(f func(*ebiten.Image) error) {
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
updateFunc = f
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
// +build !android
|
||||
// +build !ios
|
||||
|
||||
package mobile
|
||||
package ebitenmobileview
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten"
|
@ -14,7 +14,7 @@
|
||||
|
||||
// +build android ios
|
||||
|
||||
package mobile
|
||||
package ebitenmobileview
|
||||
|
||||
import (
|
||||
"errors"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package mobile
|
||||
package ebitenmobileview
|
||||
|
||||
func updateTouchesOnAndroid(action int, id int, x, y int) {
|
||||
switch action {
|
@ -14,7 +14,7 @@
|
||||
|
||||
// +build ios
|
||||
|
||||
package mobile
|
||||
package ebitenmobileview
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -14,7 +14,7 @@
|
||||
|
||||
// +build android ios
|
||||
|
||||
package mobile
|
||||
package ebitenmobileview
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/uidriver/mobile"
|
@ -21,17 +21,8 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
)
|
||||
|
||||
var (
|
||||
// mobileMutex is a mutex required for each function.
|
||||
// For example, on Android, Update can be called from a different thread:
|
||||
// https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer
|
||||
mobileMutex sync.Mutex
|
||||
"github.com/hajimehoshi/ebiten/mobile/ebitenmobileview"
|
||||
)
|
||||
|
||||
// Start starts the game and returns immediately.
|
||||
@ -44,10 +35,8 @@ var (
|
||||
//
|
||||
// Start always returns nil as of 1.5.0-alpha.
|
||||
func Start(f func(*ebiten.Image) error, width, height int, scale float64, title string) error {
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
start(f, width, height, scale, title)
|
||||
ebitenmobileview.SetUpdateFunc(f)
|
||||
ebitenmobileview.Run(width, height, scale, title)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -64,13 +53,7 @@ func Start(f func(*ebiten.Image) error, width, height int, scale float64, title
|
||||
//
|
||||
// Update returns error when 1) OpenGL error happens, or 2) f in Start returns error samely as ebiten.Run.
|
||||
func Update() error {
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
return update()
|
||||
return ebitenmobileview.Update()
|
||||
}
|
||||
|
||||
// UpdateTouchesOnAndroid updates the touch state on Android.
|
||||
@ -107,10 +90,7 @@ func Update() error {
|
||||
//
|
||||
// For more details, see https://github.com/hajimehoshi/ebiten/wiki/Android.
|
||||
func UpdateTouchesOnAndroid(action int, id int, x, y int) {
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
updateTouchesOnAndroid(action, id, x, y)
|
||||
ebitenmobileview.UpdateTouchesOnAndroid(action, id, x, y)
|
||||
}
|
||||
|
||||
// UpdateTouchesOnIOS updates the touch state on iOS.
|
||||
@ -151,8 +131,9 @@ func UpdateTouchesOnAndroid(action int, id int, x, y int) {
|
||||
//
|
||||
// For more details, see https://github.com/hajimehoshi/ebiten/wiki/iOS.
|
||||
func UpdateTouchesOnIOS(phase int, ptr int64, x, y int) {
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
updateTouchesOnIOSImpl(phase, ptr, x, y)
|
||||
ebitenmobileview.UpdateTouchesOnIOS(phase, ptr, x, y)
|
||||
}
|
||||
|
||||
func SetUpdateFunc(f func(*ebiten.Image) error) {
|
||||
ebitenmobileview.SetUpdateFunc(f)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user