From f8163f93c0d7cf585ea7d9a57ef717fd25ddf9ef Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 29 May 2022 14:22:22 +0900 Subject: [PATCH] internal/glfwwin: refactoring --- internal/glfwwin/dummy.c | 22 +++++++++++++ internal/glfwwin/microsoftgdk_windows.go | 42 +++++++++++------------- 2 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 internal/glfwwin/dummy.c diff --git a/internal/glfwwin/dummy.c b/internal/glfwwin/dummy.c new file mode 100644 index 000000000..9937918cd --- /dev/null +++ b/internal/glfwwin/dummy.c @@ -0,0 +1,22 @@ +// Copyright 2022 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 ignore +// +build ignore + +#include + +__declspec(dllexport) __cdecl uint32_t XSystemGetDeviceType(void) { + return 0; +} diff --git a/internal/glfwwin/microsoftgdk_windows.go b/internal/glfwwin/microsoftgdk_windows.go index 1857c5618..4edccbab4 100644 --- a/internal/glfwwin/microsoftgdk_windows.go +++ b/internal/glfwwin/microsoftgdk_windows.go @@ -17,34 +17,30 @@ package glfwwin -// This file does not include the headers of Microsoft GDK in order to compile easier. -// In order to compile this, create a dummy DLL with empty implementations like below, -// and link it. -// -// #include -// __declspec(dllexport) __cdecl uint32_t XSystemGetDeviceType(void) { -// return 0; -// } -// // Unfortunately, some functions like XSystemGetDeviceType is not implemented in a DLL, // so LoadLibrary is not available. - -// typedef enum { -// Unknown = 0x00, -// Pc = 0x01, -// XboxOne = 0x02, -// XboxOneS = 0x03, -// XboxOneX = 0x04, -// XboxOneXDevkit = 0x05, -// XboxScarlettLockhart = 0x06, -// XboxScarlettAnaconda = 0x07, -// XboxScarlettDevkit = 0x08, -// } XSystemDeviceType; // -// XSystemDeviceType XSystemGetDeviceType(void); +// When creating a c-archive file with the build tag microsoftgdk, create a dummy DLL +// from dummy.c, and link it. + +// #include +// +// uint32_t XSystemGetDeviceType(void); import "C" +const ( + _XSystemDeviceType_Unknown = 0x00 + _XSystemDeviceType_Pc = 0x01 + _XSystemDeviceType_XboxOne = 0x02 + _XSystemDeviceType_XboxOneS = 0x03 + _XSystemDeviceType_XboxOneX = 0x04 + _XSystemDeviceType_XboxOneXDevkit = 0x05 + _XSystemDeviceType_XboxScarlettLockhart = 0x06 + _XSystemDeviceType_XboxScarlettAnaconda = 0x07 + _XSystemDeviceType_XboxScarlettDevkit = 0x08 +) + func isXbox() bool { t := C.XSystemGetDeviceType() - return t != C.Unknown && t != C.Pc + return t != _XSystemDeviceType_Unknown && t != _XSystemDeviceType_Pc }