2021-12-17 07:03:23 +01:00
|
|
|
// Copyright 2021 The Ebiten Authors
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2022-08-12 05:40:23 +02:00
|
|
|
//go:build nintendosdk
|
2021-12-17 07:03:23 +01:00
|
|
|
|
2022-02-06 08:08:22 +01:00
|
|
|
package ui
|
2021-12-17 07:03:23 +01:00
|
|
|
|
2023-01-01 16:55:35 +01:00
|
|
|
// #include "init_nintendosdk.h"
|
2022-12-31 17:16:52 +01:00
|
|
|
// #include "input_nintendosdk.h"
|
|
|
|
import "C"
|
|
|
|
|
2021-12-17 07:03:23 +01:00
|
|
|
import (
|
2023-01-03 13:12:10 +01:00
|
|
|
stdcontext "context"
|
2023-08-30 14:02:04 +02:00
|
|
|
"image"
|
2021-12-17 07:03:23 +01:00
|
|
|
"runtime"
|
2023-01-21 16:04:30 +01:00
|
|
|
"sync"
|
2021-12-17 07:03:23 +01:00
|
|
|
|
2023-01-03 13:12:10 +01:00
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
2022-03-21 16:02:37 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
2022-03-22 15:33:21 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
2023-01-03 13:12:10 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
2021-12-17 07:03:23 +01:00
|
|
|
)
|
|
|
|
|
2022-06-16 19:10:29 +02:00
|
|
|
type graphicsDriverCreatorImpl struct{}
|
2022-03-22 15:33:21 +01:00
|
|
|
|
2022-07-30 19:56:16 +02:00
|
|
|
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
|
|
|
graphics, err := g.newOpenGL()
|
|
|
|
return graphics, GraphicsLibraryOpenGL, err
|
2022-03-22 15:33:21 +01:00
|
|
|
}
|
|
|
|
|
2022-06-16 19:10:29 +02:00
|
|
|
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
2022-11-13 07:25:22 +01:00
|
|
|
return opengl.NewGraphics()
|
2022-03-22 15:33:21 +01:00
|
|
|
}
|
|
|
|
|
2022-06-17 04:39:43 +02:00
|
|
|
func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {
|
|
|
|
return nil, nil
|
2022-03-25 11:43:32 +01:00
|
|
|
}
|
|
|
|
|
2022-06-16 19:10:29 +02:00
|
|
|
func (*graphicsDriverCreatorImpl) newMetal() (graphicsdriver.Graphics, error) {
|
|
|
|
return nil, nil
|
2022-03-22 15:33:21 +01:00
|
|
|
}
|
|
|
|
|
2021-12-17 07:03:23 +01:00
|
|
|
const deviceScaleFactor = 1
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
}
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
type userInterfaceImpl struct {
|
2022-03-21 16:02:37 +01:00
|
|
|
graphicsDriver graphicsdriver.Graphics
|
|
|
|
|
2022-12-16 10:34:14 +01:00
|
|
|
context *context
|
|
|
|
inputState InputState
|
2022-12-31 17:16:52 +01:00
|
|
|
nativeTouches []C.struct_Touch
|
2023-01-01 16:55:35 +01:00
|
|
|
|
|
|
|
egl egl
|
2023-01-03 13:12:10 +01:00
|
|
|
|
|
|
|
mainThread *thread.OSThread
|
|
|
|
renderThread *thread.OSThread
|
2023-01-21 16:04:30 +01:00
|
|
|
|
|
|
|
m sync.Mutex
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-14 20:58:29 +02:00
|
|
|
func (u *UserInterface) init() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (u *UserInterface) Run(game Game, options *RunOptions) error {
|
2022-04-01 10:59:44 +02:00
|
|
|
u.context = newContext(game)
|
2022-12-09 06:07:04 +01:00
|
|
|
g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}, options.GraphicsLibrary)
|
2022-03-22 15:33:21 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
u.graphicsDriver = g
|
2023-01-01 16:55:35 +01:00
|
|
|
|
2023-01-03 11:23:38 +01:00
|
|
|
n := C.ebitengine_Initialize()
|
2023-01-01 16:55:35 +01:00
|
|
|
if err := u.egl.init(n); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
initializeProfiler()
|
|
|
|
|
2023-01-03 13:12:10 +01:00
|
|
|
u.mainThread = thread.NewOSThread()
|
|
|
|
u.renderThread = thread.NewOSThread()
|
|
|
|
graphicscommand.SetRenderThread(u.renderThread)
|
|
|
|
|
|
|
|
ctx, cancel := stdcontext.WithCancel(stdcontext.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
var wg errgroup.Group
|
|
|
|
|
|
|
|
// Run the render thread.
|
|
|
|
wg.Go(func() error {
|
|
|
|
defer cancel()
|
|
|
|
_ = u.renderThread.Loop(ctx)
|
|
|
|
return nil
|
|
|
|
})
|
2023-01-01 16:55:35 +01:00
|
|
|
|
2023-01-03 13:12:10 +01:00
|
|
|
// Run the game thread.
|
|
|
|
wg.Go(func() error {
|
|
|
|
defer cancel()
|
2021-12-17 07:03:23 +01:00
|
|
|
|
2023-01-03 13:12:10 +01:00
|
|
|
u.renderThread.Call(func() {
|
|
|
|
u.egl.makeContextCurrent()
|
|
|
|
})
|
|
|
|
|
|
|
|
for {
|
|
|
|
recordProfilerHeartbeat()
|
|
|
|
|
2023-07-29 19:25:10 +02:00
|
|
|
if err := u.context.updateFrame(u.graphicsDriver, float64(C.kScreenWidth), float64(C.kScreenHeight), deviceScaleFactor, u, func() {
|
|
|
|
u.egl.swapBuffers()
|
|
|
|
}); err != nil {
|
2023-01-03 13:12:10 +01:00
|
|
|
return err
|
|
|
|
}
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
2023-01-03 13:12:10 +01:00
|
|
|
})
|
2021-12-17 07:03:23 +01:00
|
|
|
|
2023-01-03 13:12:10 +01:00
|
|
|
// Run the main thread.
|
|
|
|
_ = u.mainThread.Loop(ctx)
|
|
|
|
if err := wg.Wait(); err != nil {
|
|
|
|
return err
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
2023-01-03 13:12:10 +01:00
|
|
|
return nil
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) DeviceScaleFactor() float64 {
|
2021-12-17 07:03:23 +01:00
|
|
|
return deviceScaleFactor
|
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) IsFocused() bool {
|
2021-12-17 07:03:23 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) ScreenSizeInFullscreen() (int, int) {
|
2021-12-17 07:03:23 +01:00
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (u *UserInterface) readInputState(inputState *InputState) {
|
2023-01-21 16:04:30 +01:00
|
|
|
u.m.Lock()
|
|
|
|
defer u.m.Unlock()
|
|
|
|
u.inputState.copyAndReset(inputState)
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) CursorMode() CursorMode {
|
2022-02-06 09:43:52 +01:00
|
|
|
return CursorModeHidden
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) SetCursorMode(mode CursorMode) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) CursorShape() CursorShape {
|
2022-02-06 09:43:52 +01:00
|
|
|
return CursorShapeDefault
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) SetCursorShape(shape CursorShape) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) IsFullscreen() bool {
|
2021-12-17 07:03:23 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) SetFullscreen(fullscreen bool) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) IsRunnableOnUnfocused() bool {
|
2021-12-17 07:03:23 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-15 09:10:13 +02:00
|
|
|
func (*UserInterface) FPSMode() FPSModeType {
|
|
|
|
return FPSModeVsyncOn
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*UserInterface) SetFPSMode(mode FPSModeType) {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) ScheduleFrame() {
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (*UserInterface) Window() Window {
|
2022-05-31 19:09:10 +02:00
|
|
|
return &nullWindow{}
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
2022-09-25 17:34:11 +02:00
|
|
|
|
2023-08-30 14:02:04 +02:00
|
|
|
type Monitor struct{}
|
|
|
|
|
|
|
|
var theMonitor = &Monitor{}
|
|
|
|
|
|
|
|
func (m *Monitor) Bounds() image.Rectangle {
|
|
|
|
// TODO: This should return the available viewport dimensions.
|
|
|
|
return image.Rectangle{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Monitor) Name() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (u *UserInterface) AppendMonitors(mons []*Monitor) []*Monitor {
|
2023-08-30 14:02:04 +02:00
|
|
|
return append(mons, theMonitor)
|
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (u *UserInterface) Monitor() *Monitor {
|
2023-08-30 14:02:04 +02:00
|
|
|
return theMonitor
|
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (u *UserInterface) beginFrame() {
|
2022-09-25 17:34:11 +02:00
|
|
|
}
|
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (u *UserInterface) endFrame() {
|
2022-09-25 17:34:11 +02:00
|
|
|
}
|
2022-12-09 13:23:41 +01:00
|
|
|
|
2023-10-14 19:51:23 +02:00
|
|
|
func (u *UserInterface) updateIconIfNeeded() error {
|
2023-04-19 17:56:08 +02:00
|
|
|
return nil
|
2022-12-29 15:48:53 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 13:23:41 +01:00
|
|
|
func IsScreenTransparentAvailable() bool {
|
|
|
|
return false
|
|
|
|
}
|