internal/ui: use -overlay to provide the implementation for Nintendo Switch

Updates #2372
This commit is contained in:
Hajime Hoshi 2023-01-01 01:16:52 +09:00
parent 58692f6d85
commit afbd1aebf1
6 changed files with 80 additions and 38 deletions

View File

@ -20,9 +20,7 @@
extern "C" void ebitengine_UpdateGamepads() {}
extern "C" int ebitengine_GetGamepadCount() {
return 0;
}
extern "C" int ebitengine_GetGamepadCount() { return 0; }
extern "C" void ebitengine_GetGamepads(struct Gamepad *gamepads) {}

View File

@ -32,10 +32,6 @@ package nintendosdk
// void EbitenGetScreenSize(int* width, int* height);
// void EbitenBeginFrame();
// void EbitenEndFrame();
//
// // Input
// int EbitenGetTouchNum();
// void EbitenGetTouches(struct Touch* touches);
import "C"
type Touch struct {
@ -61,27 +57,3 @@ func BeginFrame() {
func EndFrame() {
C.EbitenEndFrame()
}
var cTouches []C.struct_Touch
func AppendTouches(touches []Touch) []Touch {
n := int(C.EbitenGetTouchNum())
cTouches = cTouches[:0]
if cap(cTouches) < n {
cTouches = append(cTouches, make([]C.struct_Touch, n)...)
} else {
cTouches = cTouches[:n]
}
if n > 0 {
C.EbitenGetTouches(&cTouches[0])
}
for _, t := range cTouches {
touches = append(touches, Touch{
ID: int(t.id),
X: int(t.x),
Y: int(t.y),
})
}
return touches
}

View File

@ -0,0 +1,25 @@
// Copyright 2023 The Ebitengine 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.
//go:build nintendosdk
// The actual implementaiton will be provided by -overlay.
#include "input_nintendosdk.h"
extern "C" void ebitengine_UpdateTouches() {}
extern "C" int ebitengine_GetTouchCount() { return 0; }
extern "C" void ebitengine_GetTouches(struct Touch *touches) {}

View File

@ -16,22 +16,33 @@
package ui
import (
"github.com/hajimehoshi/ebiten/v2/internal/nintendosdk"
)
// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all
// #cgo darwin LDFLAGS: -Wl,-undefined,dynamic_lookup
//
// #include "input_nintendosdk.h"
import "C"
func (u *userInterfaceImpl) updateInputState() {
C.ebitengine_UpdateTouches()
u.nativeTouches = u.nativeTouches[:0]
u.nativeTouches = nintendosdk.AppendTouches(u.nativeTouches)
if n := int(C.ebitengine_GetTouchCount()); n > 0 {
if cap(u.nativeTouches) < n {
u.nativeTouches = make([]C.struct_Touch, n)
} else {
u.nativeTouches = u.nativeTouches[:n]
}
C.ebitengine_GetTouches(&u.nativeTouches[0])
}
for i := range u.inputState.Touches {
u.inputState.Touches[i].Valid = false
}
for i, t := range u.nativeTouches {
x, y := u.context.clientPositionToLogicalPosition(float64(t.X), float64(t.Y), deviceScaleFactor)
x, y := u.context.clientPositionToLogicalPosition(float64(t.x), float64(t.y), deviceScaleFactor)
u.inputState.Touches[i] = Touch{
Valid: true,
ID: TouchID(t.ID),
ID: TouchID(t.id),
X: int(x),
Y: int(y),
}

View File

@ -0,0 +1,33 @@
// Copyright 2023 The Ebitengine 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.
//go:build nintendosdk
struct Touch {
int id;
int x;
int y;
};
#ifdef __cplusplus
extern "C" {
#endif
void ebitengine_UpdateTouches();
int ebitengine_GetTouchCount();
void ebitengine_GetTouches(struct Touch* touches);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@ -16,6 +16,9 @@
package ui
// #include "input_nintendosdk.h"
import "C"
import (
"runtime"
@ -55,7 +58,7 @@ type userInterfaceImpl struct {
context *context
inputState InputState
nativeTouches []nintendosdk.Touch
nativeTouches []C.struct_Touch
}
func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {