Split global DirectInput interface into 3 interfaces in Mouse, Keyboard and Controller
This commit is contained in:
parent
8099826ab7
commit
7bd59ed27d
|
@ -45,9 +45,6 @@
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#undef DIRECTINPUT_VERSION
|
|
||||||
#define DIRECTINPUT_VERSION 0x0500
|
|
||||||
#include <dinput.h>
|
|
||||||
#include "extgl.h"
|
#include "extgl.h"
|
||||||
|
|
||||||
#ifdef _PRIVATE_WINDOW_H_
|
#ifdef _PRIVATE_WINDOW_H_
|
||||||
|
@ -57,7 +54,6 @@
|
||||||
|
|
||||||
extern HWND hwnd; // Handle to the window
|
extern HWND hwnd; // Handle to the window
|
||||||
extern HDC hdc; // Device context
|
extern HDC hdc; // Device context
|
||||||
extern LPDIRECTINPUT lpdi; // DirectInput
|
|
||||||
extern bool isFullScreen; // Whether we're fullscreen or not
|
extern bool isFullScreen; // Whether we're fullscreen or not
|
||||||
extern bool isMinimized; // Whether we're minimized or not
|
extern bool isMinimized; // Whether we're minimized or not
|
||||||
extern bool isFocused; // Whether we're focused or not
|
extern bool isFocused; // Whether we're focused or not
|
||||||
|
|
|
@ -51,6 +51,9 @@
|
||||||
|
|
||||||
#define KEYBOARD_BUFFER_SIZE 50
|
#define KEYBOARD_BUFFER_SIZE 50
|
||||||
|
|
||||||
|
extern HINSTANCE dll_handle; // Handle to the LWJGL dll
|
||||||
|
|
||||||
|
static LPDIRECTINPUT lpdi = NULL; // DirectInput
|
||||||
static LPDIRECTINPUTDEVICE lpdiKeyboard = NULL;
|
static LPDIRECTINPUTDEVICE lpdiKeyboard = NULL;
|
||||||
static bool translationEnabled;
|
static bool translationEnabled;
|
||||||
|
|
||||||
|
@ -64,6 +67,13 @@ static bool useUnicode;
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
|
||||||
(JNIEnv * env, jclass clazz)
|
(JNIEnv * env, jclass clazz)
|
||||||
{
|
{
|
||||||
|
// Create input
|
||||||
|
HRESULT ret = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL);
|
||||||
|
if (ret != DI_OK && ret != DIERR_BETADIRECTINPUTVERSION) {
|
||||||
|
throwException(env, "Failed to create DirectInput");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
translationEnabled = false;
|
translationEnabled = false;
|
||||||
// Check to see if we're already initialized
|
// Check to see if we're already initialized
|
||||||
if (lpdiKeyboard != NULL) {
|
if (lpdiKeyboard != NULL) {
|
||||||
|
@ -98,7 +108,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
|
||||||
dipropdw.dwData = KEYBOARD_BUFFER_SIZE;
|
dipropdw.dwData = KEYBOARD_BUFFER_SIZE;
|
||||||
lpdiKeyboard->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph);
|
lpdiKeyboard->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph);
|
||||||
|
|
||||||
HRESULT ret = lpdiKeyboard->Acquire();
|
ret = lpdiKeyboard->Acquire();
|
||||||
if(FAILED(ret)) {
|
if(FAILED(ret)) {
|
||||||
printfDebug("Failed to acquire keyboard\n");
|
printfDebug("Failed to acquire keyboard\n");
|
||||||
}
|
}
|
||||||
|
@ -118,6 +128,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nDestroy
|
||||||
lpdiKeyboard->Release();
|
lpdiKeyboard->Release();
|
||||||
lpdiKeyboard = NULL;
|
lpdiKeyboard = NULL;
|
||||||
}
|
}
|
||||||
|
// Release DirectInput
|
||||||
|
if (lpdi != NULL) {
|
||||||
|
printfDebug("Destroying directinput\n");
|
||||||
|
lpdi->Release();
|
||||||
|
lpdi = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -43,10 +43,12 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#undef DIRECTINPUT_VERSION
|
#undef DIRECTINPUT_VERSION
|
||||||
#define DIRECTINPUT_VERSION 0x0300
|
#define DIRECTINPUT_VERSION 0x0300
|
||||||
|
#include <dinput.h>
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "common_tools.h"
|
#include "common_tools.h"
|
||||||
#include <dinput.h>
|
|
||||||
|
|
||||||
|
extern HINSTANCE dll_handle; // Handle to the LWJGL dll
|
||||||
|
static LPDIRECTINPUT lpdi = NULL; // DirectInput
|
||||||
static LPDIRECTINPUTDEVICE mDIDevice; // DI Device instance
|
static LPDIRECTINPUTDEVICE mDIDevice; // DI Device instance
|
||||||
static int mButtoncount = 0; // Temporary buttoncount
|
static int mButtoncount = 0; // Temporary buttoncount
|
||||||
static bool mHaswheel; // Temporary wheel check
|
static bool mHaswheel; // Temporary wheel check
|
||||||
|
@ -92,11 +94,12 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetButtonCount(JNIEnv *, jcla
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nCreate(JNIEnv *env, jclass clazz) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nCreate(JNIEnv *env, jclass clazz) {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
// assert that Direct Input has been created
|
// Create input
|
||||||
if(lpdi == NULL) {
|
HRESULT ret = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL);
|
||||||
throwException(env, "Please create the window before initializing input devices");
|
if (ret != DI_OK && ret != DIERR_BETADIRECTINPUTVERSION) {
|
||||||
return;
|
throwException(env, "Failed to create DirectInput");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* skip enumeration, since we only want system mouse */
|
/* skip enumeration, since we only want system mouse */
|
||||||
CreateMouse();
|
CreateMouse();
|
||||||
|
@ -313,18 +316,24 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nGrabMouse
|
||||||
/**
|
/**
|
||||||
* Shutdown DI
|
* Shutdown DI
|
||||||
*/
|
*/
|
||||||
void ShutdownMouse() {
|
static void ShutdownMouse() {
|
||||||
// release device
|
// release device
|
||||||
if (mDIDevice != NULL) {
|
if (mDIDevice != NULL) {
|
||||||
mDIDevice->Unacquire();
|
mDIDevice->Unacquire();
|
||||||
mDIDevice->Release();
|
mDIDevice->Release();
|
||||||
mDIDevice = NULL;
|
mDIDevice = NULL;
|
||||||
}
|
}
|
||||||
|
// Release DirectInput
|
||||||
|
if (lpdi != NULL) {
|
||||||
|
printfDebug("Destroying directinput\n");
|
||||||
|
lpdi->Release();
|
||||||
|
lpdi = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Enumerates the capabilities of the Mouse attached to the system
|
* Enumerates the capabilities of the Mouse attached to the system
|
||||||
*/
|
*/
|
||||||
void EnumerateMouseCapabilities() {
|
static void EnumerateMouseCapabilities() {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = mDIDevice->EnumObjects(EnumMouseObjectsCallback, NULL, DIDFT_ALL);
|
hr = mDIDevice->EnumObjects(EnumMouseObjectsCallback, NULL, DIDFT_ALL);
|
||||||
if FAILED(hr) {
|
if FAILED(hr) {
|
||||||
|
@ -345,7 +354,7 @@ void EnumerateMouseCapabilities() {
|
||||||
/**
|
/**
|
||||||
* Callback from EnumObjects. Called for each "object" on the Mouse.
|
* Callback from EnumObjects. Called for each "object" on the Mouse.
|
||||||
*/
|
*/
|
||||||
BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
|
static BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
|
||||||
printfDebug("found %s\n", lpddoi->tszName);
|
printfDebug("found %s\n", lpddoi->tszName);
|
||||||
if(lpddoi->guidType == GUID_Button) {
|
if(lpddoi->guidType == GUID_Button) {
|
||||||
mButtoncount++;
|
mButtoncount++;
|
||||||
|
@ -362,7 +371,7 @@ BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID
|
||||||
/**
|
/**
|
||||||
* Creates the specified device as a Mouse
|
* Creates the specified device as a Mouse
|
||||||
*/
|
*/
|
||||||
void CreateMouse() {
|
static void CreateMouse() {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = lpdi->CreateDevice(GUID_SysMouse, &mDIDevice, NULL);
|
hr = lpdi->CreateDevice(GUID_SysMouse, &mDIDevice, NULL);
|
||||||
if FAILED(hr) {
|
if FAILED(hr) {
|
||||||
|
@ -376,7 +385,7 @@ void CreateMouse() {
|
||||||
/**
|
/**
|
||||||
* Sets up the Mouse properties
|
* Sets up the Mouse properties
|
||||||
*/
|
*/
|
||||||
void SetupMouse() {
|
static void SetupMouse() {
|
||||||
// set Mouse data format
|
// set Mouse data format
|
||||||
if(mDIDevice->SetDataFormat(&c_dfDIMouse) != DI_OK) {
|
if(mDIDevice->SetDataFormat(&c_dfDIMouse) != DI_OK) {
|
||||||
printfDebug("SetDataFormat failed\n");
|
printfDebug("SetDataFormat failed\n");
|
||||||
|
|
|
@ -49,7 +49,6 @@ static bool oneShotInitialised = false; // Registers the LWJGL window class
|
||||||
HWND hwnd = NULL; // Handle to the window
|
HWND hwnd = NULL; // Handle to the window
|
||||||
HDC hdc = NULL; // Device context
|
HDC hdc = NULL; // Device context
|
||||||
HGLRC hglrc = NULL; // OpenGL context
|
HGLRC hglrc = NULL; // OpenGL context
|
||||||
LPDIRECTINPUT lpdi = NULL; // DirectInput
|
|
||||||
static bool isFullScreen = false; // Whether we're fullscreen or not
|
static bool isFullScreen = false; // Whether we're fullscreen or not
|
||||||
static bool isMinimized = false; // Whether we're minimized or not
|
static bool isMinimized = false; // Whether we're minimized or not
|
||||||
static bool isFocused = false; // whether we're focused or not
|
static bool isFocused = false; // whether we're focused or not
|
||||||
|
@ -190,46 +189,12 @@ static int findPixelFormat(JNIEnv *env, int bpp, int alpha, int depth, int stenc
|
||||||
|
|
||||||
return iPixelFormat;
|
return iPixelFormat;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Create DirectInput.
|
|
||||||
* Returns true for success, or false for failure
|
|
||||||
*/
|
|
||||||
static bool createDirectInput(JNIEnv *env)
|
|
||||||
{
|
|
||||||
// Create input
|
|
||||||
HRESULT ret = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL);
|
|
||||||
if (ret != DI_OK && ret != DIERR_BETADIRECTINPUTVERSION ) {
|
|
||||||
switch (ret) {
|
|
||||||
case DIERR_INVALIDPARAM :
|
|
||||||
throwException(env, "Failed to create DirectInput - Invalid parameter\n");
|
|
||||||
break;
|
|
||||||
case DIERR_OLDDIRECTINPUTVERSION :
|
|
||||||
throwException(env, "Failed to create DirectInput - Old Version\n");
|
|
||||||
break;
|
|
||||||
case DIERR_OUTOFMEMORY :
|
|
||||||
throwException(env, "Failed to create DirectInput - Out Of Memory\n");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throwException(env, "Failed to create DirectInput - Unknown failure\n");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Close the window
|
* Close the window
|
||||||
*/
|
*/
|
||||||
static void closeWindow()
|
static void closeWindow()
|
||||||
{
|
{
|
||||||
// Release DirectInput
|
|
||||||
if (lpdi != NULL) {
|
|
||||||
printfDebug("Destroying directinput\n");
|
|
||||||
lpdi->Release();
|
|
||||||
lpdi = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Release device context
|
// Release device context
|
||||||
if (hdc != NULL && hwnd != NULL) {
|
if (hdc != NULL && hwnd != NULL) {
|
||||||
printfDebug("Releasing DC\n");
|
printfDebug("Releasing DC\n");
|
||||||
|
@ -551,13 +516,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!createDirectInput(env)) {
|
|
||||||
// Close the window
|
|
||||||
closeWindow();
|
|
||||||
extgl_Close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ShowWindow(hwnd, SW_SHOW);
|
ShowWindow(hwnd, SW_SHOW);
|
||||||
UpdateWindow(hwnd);
|
UpdateWindow(hwnd);
|
||||||
SetForegroundWindow(hwnd);
|
SetForegroundWindow(hwnd);
|
||||||
|
|
Loading…
Reference in New Issue