Remove dependency with DirectInput and delete winput.c file.

This commit is contained in:
David Capello 2010-10-17 23:43:08 -03:00
parent a877d52048
commit 9e4972fc53
6 changed files with 3 additions and 304 deletions

View File

@ -157,10 +157,9 @@ endif()
if(WIN32) if(WIN32)
find_package(DDraw) find_package(DDraw)
find_package(DInput)
find_package(DXGuid) find_package(DXGuid)
if(NOT DDRAW_FOUND OR NOT DINPUT_FOUND OR NOT DXGUID_FOUND) if(NOT DDRAW_FOUND OR NOT DXGUID_FOUND)
if(MSVC) if(MSVC)
message(FATAL_ERROR message(FATAL_ERROR
"DirectX required for Windows port. You might need to add DirectX include and lib directories to your INCLUDE and LIB environment variables.") "DirectX required for Windows port. You might need to add DirectX include and lib directories to your INCLUDE and LIB environment variables.")
@ -174,7 +173,6 @@ if(WIN32)
include_directories(SYSTEM include_directories(SYSTEM
${DDRAW_INCLUDE_DIR} ${DDRAW_INCLUDE_DIR}
${DINPUT_INCLUDE_DIR}
${DXGUID_INCLUDE_DIR} ${DXGUID_INCLUDE_DIR}
) )
@ -184,7 +182,6 @@ if(WIN32)
gdi32 gdi32
comdlg32 comdlg32
ole32 ole32
${DINPUT_LIBRARIES}
${DDRAW_LIBRARIES} ${DDRAW_LIBRARIES}
${DXGUID_LIBRARIES} ${DXGUID_LIBRARIES}
winmm winmm

View File

@ -1,34 +0,0 @@
# - Find DirectInput
# Find the DirectInput includes and libraries
#
# DINPUT_INCLUDE_DIR - where to find dinput.h
# DINPUT_LIBRARIES - List of libraries when using dinput.
# DINPUT_FOUND - True if dinput found.
if(DINPUT_INCLUDE_DIR)
# Already in cache, be silent
set(DINPUT_FIND_QUIETLY TRUE)
endif(DINPUT_INCLUDE_DIR)
find_path(DINPUT_INCLUDE_DIR dinput.h
PATH $ENV{DXSDK_DIR}/Include
)
find_library(DINPUT_LIBRARY
NAMES dinput8
PATHS "$ENV{DXSDK_DIR}/Lib/$ENV{PROCESSOR_ARCHITECTURE}"
)
# Handle the QUIETLY and REQUIRED arguments and set DINPUT_FOUND to TRUE if
# all listed variables are TRUE.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(DINPUT DEFAULT_MSG
DINPUT_INCLUDE_DIR DINPUT_LIBRARY)
if(DINPUT_FOUND)
set(DINPUT_LIBRARIES ${DINPUT_LIBRARY})
else(DINPUT_FOUND)
set(DINPUT_LIBRARIES)
endif(DINPUT_FOUND)
mark_as_advanced(DINPUT_INCLUDE_DIR DINPUT_LIBRARY)

View File

@ -106,7 +106,6 @@ set(ALLEGRO_SRC_WIN_FILES
src/win/wfile.c src/win/wfile.c
src/win/wgdi.c src/win/wgdi.c
src/win/wgfxdrv.c src/win/wgfxdrv.c
src/win/winput.c
src/win/wkeybd.c src/win/wkeybd.c
src/win/wmouse.c src/win/wmouse.c
src/win/wsystem.c src/win/wsystem.c

View File

@ -109,18 +109,6 @@ AL_FUNC(int, wnd_call_proc, (int (*proc)(void)));
AL_FUNC(void, wnd_schedule_proc, (int (*proc)(void))); AL_FUNC(void, wnd_schedule_proc, (int (*proc)(void)));
/* input routines */
AL_VAR(int, _win_input_events);
AL_ARRAY(HANDLE, _win_input_event_id);
AL_FUNCPTRARRAY(void, _win_input_event_handler, (void));
AL_FUNC(void, _win_input_init, (int need_thread));
AL_FUNC(void, _win_input_exit, (void));
AL_FUNC(int, _win_input_register_event, (HANDLE event_id, void (*event_handler)(void)));
AL_FUNC(void, _win_input_unregister_event, (HANDLE event_id));
/* mouse routines */ /* mouse routines */
AL_VAR(HCURSOR, _win_hcursor); AL_VAR(HCURSOR, _win_hcursor);
AL_FUNC(int, mouse_set_syscursor, (void)); AL_FUNC(int, mouse_set_syscursor, (void));

View File

@ -1,226 +0,0 @@
/* ______ ___ ___
* /\ _ \ /\_ \ /\_ \
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
* /\____/
* \_/__/
*
* Input management functions.
*
* By Eric Botcazou.
*
* See readme.txt for copyright information.
*/
#include "allegro.h"
#include "allegro/internal/aintern.h"
#include "allegro/platform/aintwin.h"
#ifndef SCAN_DEPEND
#include <process.h>
#endif
#ifndef ALLEGRO_WINDOWS
#error something is wrong with the makefile
#endif
#define PREFIX_I "al-winput INFO: "
#define PREFIX_W "al-winput WARNING: "
#define PREFIX_E "al-winput ERROR: "
#define MAX_EVENTS 8
/* input thread event queue */
int _win_input_events;
HANDLE _win_input_event_id[MAX_EVENTS];
void (*_win_input_event_handler[MAX_EVENTS])(void);
/* pending event waiting for being processed */
static HANDLE pending_event_id;
static void (*pending_event_handler)(void);
/* internal input thread management */
static HANDLE ack_event = NULL;
static int reserved_events = 0;
static int input_need_thread = FALSE;
static HANDLE input_thread = NULL;
/* input_thread_proc: [input thread]
* Thread function that handles the input when there is
* no dedicated window thread because the library has
* been attached to an external window.
*/
static void input_thread_proc(LPVOID unused)
{
int result;
_win_thread_init();
_TRACE(PREFIX_I "input thread starts\n");
/* event loop */
while (TRUE) {
result = WaitForMultipleObjects(_win_input_events, _win_input_event_id, FALSE, INFINITE);
if (result == WAIT_OBJECT_0 + 2)
break; /* thread suicide */
else if ((result >= WAIT_OBJECT_0) && (result < WAIT_OBJECT_0 + _win_input_events))
(*_win_input_event_handler[result - WAIT_OBJECT_0])();
}
_TRACE(PREFIX_I "input thread exits\n");
_win_thread_exit();
}
/* register_pending_event: [input thread]
* Registers effectively the pending event.
*/
static void register_pending_event(void)
{
/* add the pending event to the queue */
_win_input_event_id[_win_input_events] = pending_event_id;
_win_input_event_handler[_win_input_events] = pending_event_handler;
/* adjust the size of the queue */
_win_input_events++;
/* acknowledge the registration */
SetEvent(ack_event);
}
/* unregister_pending_event: [input thread]
* Unregisters effectively the pending event.
*/
static void unregister_pending_event(void)
{
int i, found = -1;
/* look for the pending event in the event queue */
for (i=reserved_events; i<_win_input_events; i++) {
if (_win_input_event_id[i] == pending_event_id) {
found = i;
break;
}
}
if (found >= 0) {
/* shift the queue to the left */
for (i=found; i<_win_input_events-1; i++) {
_win_input_event_id[i] = _win_input_event_id[i+1];
_win_input_event_handler[i] = _win_input_event_handler[i+1];
}
/* adjust the size of the queue */
_win_input_events--;
}
/* acknowledge the unregistration */
SetEvent(ack_event);
}
/* _win_input_register_event: [primary thread]
* Adds an event to the input thread event queue.
*/
int _win_input_register_event(HANDLE event_id, void (*event_handler)(void))
{
if (_win_input_events == MAX_EVENTS)
return -1;
/* record the event */
pending_event_id = event_id;
pending_event_handler = event_handler;
/* create the input thread if none */
if (input_need_thread && !input_thread)
input_thread = (HANDLE) _beginthread(input_thread_proc, 0, NULL);
/* ask the input thread to register the pending event */
SetEvent(_win_input_event_id[0]);
/* wait for the input thread to acknowledge */
WaitForSingleObject(ack_event, INFINITE);
_TRACE(PREFIX_I "1 input event registered (total = %d)\n", _win_input_events-reserved_events);
return 0;
}
/* _win_input_unregister_event: [primary thread]
* Removes an event from the input thread event queue.
*/
void _win_input_unregister_event(HANDLE event_id)
{
/* record the event */
pending_event_id = event_id;
/* ask the input thread to unregister the pending event */
SetEvent(_win_input_event_id[1]);
/* wait for the input thread to acknowledge */
WaitForSingleObject(ack_event, INFINITE);
/* kill the input thread if no more event */
if (input_need_thread && (_win_input_events == reserved_events)) {
SetEvent(_win_input_event_id[2]); /* thread suicide */
input_thread = NULL;
}
_TRACE(PREFIX_I "1 input event unregistered (total = %d)\n", _win_input_events-reserved_events);
}
/* _win_input_init: [primary thread]
* Initializes the module.
*/
void _win_input_init(int need_thread)
{
_win_input_event_id[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
_win_input_event_handler[0] = register_pending_event;
_win_input_event_id[1] = CreateEvent(NULL, FALSE, FALSE, NULL);
_win_input_event_handler[1] = unregister_pending_event;
if (need_thread) {
input_need_thread = TRUE;
_win_input_event_id[2] = CreateEvent(NULL, FALSE, FALSE, NULL);
reserved_events = 3;
}
else {
input_need_thread = FALSE;
reserved_events = 2;
}
_win_input_events = reserved_events;
ack_event = CreateEvent(NULL, FALSE, FALSE, NULL);
}
/* _win_input_exit: [primary thread]
* Shuts down the module.
*/
void _win_input_exit(void)
{
int i;
for (i=0; i<reserved_events; i++)
CloseHandle(_win_input_event_id[i]);
_win_input_events = 0;
CloseHandle(ack_event);
}

View File

@ -472,7 +472,6 @@ static HWND create_directx_window(void)
*/ */
static void wnd_thread_proc(HANDLE setup_event) static void wnd_thread_proc(HANDLE setup_event)
{ {
int result;
MSG msg; MSG msg;
_win_thread_init(); _win_thread_init();
@ -491,24 +490,8 @@ static void wnd_thread_proc(HANDLE setup_event)
SetEvent(setup_event); SetEvent(setup_event);
/* message loop */ /* message loop */
while (TRUE) { while (GetMessage(&msg, NULL, 0, 0))
result = MsgWaitForMultipleObjects(_win_input_events, _win_input_event_id, FALSE, INFINITE, QS_ALLINPUT); DispatchMessage(&msg);
if ((result >= WAIT_OBJECT_0) && (result < WAIT_OBJECT_0 + _win_input_events)) {
/* one of the registered events is in signaled state */
(*_win_input_event_handler[result - WAIT_OBJECT_0])();
}
else if (result == WAIT_OBJECT_0 + _win_input_events) {
/* messages are waiting in the queue */
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (GetMessage(&msg, NULL, 0, 0)) {
DispatchMessage(&msg);
}
else {
goto End;
}
}
}
}
End: End:
_TRACE(PREFIX_I "window thread exits\n"); _TRACE(PREFIX_I "window thread exits\n");
@ -535,9 +518,6 @@ int init_directx_window(void)
msg_suicide = RegisterWindowMessage("Allegro window suicide"); msg_suicide = RegisterWindowMessage("Allegro window suicide");
if (user_wnd) { if (user_wnd) {
/* initializes input module and requests dedicated thread */
_win_input_init(TRUE);
/* hook the user window */ /* hook the user window */
user_wnd_proc = (WNDPROC) SetWindowLong(user_wnd, GWL_WNDPROC, (long)directx_wnd_proc); user_wnd_proc = (WNDPROC) SetWindowLong(user_wnd, GWL_WNDPROC, (long)directx_wnd_proc);
if (!user_wnd_proc) if (!user_wnd_proc)
@ -555,9 +535,6 @@ int init_directx_window(void)
wnd_height = win_rect.r.bottom - win_rect.r.top; wnd_height = win_rect.r.bottom - win_rect.r.top;
} }
else { else {
/* initializes input module without dedicated thread */
_win_input_init(FALSE);
/* create window thread */ /* create window thread */
events[0] = CreateEvent(NULL, FALSE, FALSE, NULL); /* acknowledges that thread is up */ events[0] = CreateEvent(NULL, FALSE, FALSE, NULL); /* acknowledges that thread is up */
events[1] = (HANDLE) _beginthread(wnd_thread_proc, 0, events[0]); events[1] = (HANDLE) _beginthread(wnd_thread_proc, 0, events[0]);
@ -613,8 +590,6 @@ void exit_directx_window(void)
DeleteCriticalSection(&gfx_crit_sect); DeleteCriticalSection(&gfx_crit_sect);
_win_input_exit();
window_is_initialized = FALSE; window_is_initialized = FALSE;
} }