Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/sdl/core/windows/SDL_gameinput.c
9905 views
1
/*
2
Simple DirectMedia Layer
3
Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
4
5
This software is provided 'as-is', without any express or implied
6
warranty. In no event will the authors be held liable for any damages
7
arising from the use of this software.
8
9
Permission is granted to anyone to use this software for any purpose,
10
including commercial applications, and to alter it and redistribute it
11
freely, subject to the following restrictions:
12
13
1. The origin of this software must not be misrepresented; you must not
14
claim that you wrote the original software. If you use this software
15
in a product, an acknowledgment in the product documentation would be
16
appreciated but is not required.
17
2. Altered source versions must be plainly marked as such, and must not be
18
misrepresented as being the original software.
19
3. This notice may not be removed or altered from any source distribution.
20
*/
21
#include "SDL_internal.h"
22
23
#ifdef HAVE_GAMEINPUT_H
24
25
#include "SDL_windows.h"
26
#include "SDL_gameinput.h"
27
28
#ifdef SDL_PLATFORM_WIN32
29
#include <initguid.h>
30
// {11BE2A7E-4254-445A-9C09-FFC40F006918}
31
DEFINE_GUID(SDL_IID_GameInput, 0x11BE2A7E, 0x4254, 0x445A, 0x9C, 0x09, 0xFF, 0xC4, 0x0F, 0x00, 0x69, 0x18);
32
#endif
33
34
static SDL_SharedObject *g_hGameInputDLL;
35
static IGameInput *g_pGameInput;
36
static int g_nGameInputRefCount;
37
38
bool SDL_InitGameInput(IGameInput **ppGameInput)
39
{
40
if (g_nGameInputRefCount == 0) {
41
g_hGameInputDLL = SDL_LoadObject("gameinput.dll");
42
if (!g_hGameInputDLL) {
43
return false;
44
}
45
46
typedef HRESULT (WINAPI *GameInputCreate_t)(IGameInput * *gameInput);
47
GameInputCreate_t GameInputCreateFunc = (GameInputCreate_t)SDL_LoadFunction(g_hGameInputDLL, "GameInputCreate");
48
if (!GameInputCreateFunc) {
49
SDL_UnloadObject(g_hGameInputDLL);
50
return false;
51
}
52
53
IGameInput *pGameInput = NULL;
54
HRESULT hr = GameInputCreateFunc(&pGameInput);
55
if (FAILED(hr)) {
56
SDL_UnloadObject(g_hGameInputDLL);
57
return WIN_SetErrorFromHRESULT("GameInputCreate failed", hr);
58
}
59
60
#ifdef SDL_PLATFORM_WIN32
61
hr = IGameInput_QueryInterface(pGameInput, &SDL_IID_GameInput, (void **)&g_pGameInput);
62
IGameInput_Release(pGameInput);
63
if (FAILED(hr)) {
64
SDL_UnloadObject(g_hGameInputDLL);
65
return WIN_SetErrorFromHRESULT("GameInput QueryInterface failed", hr);
66
}
67
#else
68
// Assume that the version we get is compatible with the current SDK
69
// If that isn't the case, define the correct GUID for SDL_IID_GameInput above
70
g_pGameInput = pGameInput;
71
#endif
72
}
73
++g_nGameInputRefCount;
74
75
if (ppGameInput) {
76
*ppGameInput = g_pGameInput;
77
}
78
return true;
79
}
80
81
void SDL_QuitGameInput(void)
82
{
83
SDL_assert(g_nGameInputRefCount > 0);
84
85
--g_nGameInputRefCount;
86
if (g_nGameInputRefCount == 0) {
87
if (g_pGameInput) {
88
IGameInput_Release(g_pGameInput);
89
g_pGameInput = NULL;
90
}
91
if (g_hGameInputDLL) {
92
SDL_UnloadObject(g_hGameInputDLL);
93
g_hGameInputDLL = NULL;
94
}
95
}
96
}
97
98
#endif // HAVE_GAMEINPUT_H
99
100