remove cmake SDL_JOYSTICK and SDL_FORCEFEEDBACK options
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@7864 30fe4595-0a0c-4342-8851-515496e4dcbd
This commit is contained in:
parent
cb8cf6c756
commit
1cfab5829a
|
@ -246,14 +246,6 @@ The Speed Dreams Team.
|
|||
Enable debug symbols even in Release builds (def: OFF)
|
||||
(see http://sourceforge.net/p/speed-dreams/tickets/356).
|
||||
|
||||
- OPTION_SDL_JOYSTICK:BOOL :
|
||||
Use SDL to read the joystick. (def: ON)
|
||||
Set to OFF to use PLIB for joystick input.
|
||||
|
||||
- OPTION_SDL_FORCEFEEDBACK:BOOL :
|
||||
Enable SDL Haptics for forcefeedback effects (def: ON)
|
||||
Requires OPTION_SDL_JOYSTICK to be ON
|
||||
|
||||
- OPTION_WEBSERVER:BOOL :
|
||||
Enable the WIP Webserver/Laplogger (def: ON)
|
||||
(see http://sourceforge.net/p/speed-dreams/tickets/912).
|
||||
|
|
|
@ -82,9 +82,6 @@ MACRO(ADD_SD_COMPILE_OPTIONS)
|
|||
|
||||
SET(OPTION_HUDDEBUG false CACHE BOOL "Build with HUD Debug in OsgGraph")
|
||||
|
||||
SET(OPTION_SDL_JOYSTICK true CACHE BOOL "Use SDL for Joystick instead of PLIB")
|
||||
CMAKE_DEPENDENT_OPTION(OPTION_SDL_FORCEFEEDBACK "Use SDL2 Haptics" true "OPTION_SDL_JOYSTICK" false)
|
||||
|
||||
SET(OPTION_WEBSERVER true CACHE BOOL "Build with WebServer functionality")
|
||||
|
||||
SET(OPTION_CLIENT_SERVER false CACHE BOOL "Build with Client/Server network architecture")
|
||||
|
@ -198,14 +195,6 @@ MACRO(ADD_SD_COMPILE_OPTIONS)
|
|||
ADD_DEFINITIONS(-DUNLOAD_SSGGRAPH)
|
||||
ENDIF(OPTION_UNLOAD_SSGGRAPH)
|
||||
|
||||
IF(OPTION_SDL_JOYSTICK)
|
||||
ADD_DEFINITIONS(-DSDL_JOYSTICK)
|
||||
ENDIF(OPTION_SDL_JOYSTICK)
|
||||
|
||||
IF(OPTION_SDL_FORCEFEEDBACK)
|
||||
ADD_DEFINITIONS(-DSDL_FORCEFEEDBACK)
|
||||
ENDIF(OPTION_SDL_FORCEFEEDBACK)
|
||||
|
||||
IF(OPTION_WEBSERVER)
|
||||
ADD_DEFINITIONS(-DWEBSERVER)
|
||||
ENDIF(OPTION_WEBSERVER)
|
||||
|
|
|
@ -28,14 +28,6 @@
|
|||
#include <stdio.h>
|
||||
#include <cstring>
|
||||
|
||||
//#ifndef SDL_JOYSTICK
|
||||
//#ifdef __APPLE__
|
||||
//#include <js.h>
|
||||
//#else
|
||||
//#include <plib/js.h>
|
||||
//#endif
|
||||
//#endif
|
||||
|
||||
#include <portability.h>
|
||||
|
||||
#include "tgfclient.h"
|
||||
|
@ -133,20 +125,14 @@ static int gfmaxKey = sizeof(GfKey) / sizeof(GfKey[0]);
|
|||
static int gfctrlJoyPresent = GFCTRL_JOY_UNTESTED;
|
||||
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
static SDL_Joystick *Joysticks[GFCTRL_JOY_NUMBER] = {NULL};
|
||||
static tCtrlJoyInfo *joyInfoCopy = NULL;
|
||||
//static tCtrlJoyInfo joyInfo;
|
||||
#if SDL_FORCEFEEDBACK
|
||||
static SDL_Haptic *Haptics[GFCTRL_JOY_NUMBER] = {NULL};
|
||||
static SDL_HapticEffect cfx[GFCTRL_JOY_NUMBER];
|
||||
static unsigned int cfx_timeout[GFCTRL_JOY_NUMBER];
|
||||
static unsigned int rfx_timeout[GFCTRL_JOY_NUMBER];
|
||||
static int id[GFCTRL_JOY_NUMBER];
|
||||
#endif
|
||||
#else
|
||||
static jsJoystick *Joysticks[GFCTRL_JOY_NUMBER] = {NULL};
|
||||
#endif
|
||||
|
||||
|
||||
/** Get a control reference by its name
|
||||
|
@ -291,24 +277,6 @@ GfctrlGetNameByRef(int type, int index)
|
|||
void
|
||||
gfctrlJoyInit(void)
|
||||
{
|
||||
#ifndef SDL_JOYSTICK
|
||||
gfctrlJoyPresent = GFCTRL_JOY_NONE;
|
||||
|
||||
for (int index = 0; index < GFCTRL_JOY_NUMBER; index++) {
|
||||
if (!Joysticks[index]) {
|
||||
Joysticks[index] = new jsJoystick(index);
|
||||
}
|
||||
|
||||
// Don't configure the joystick if it doesn't work
|
||||
if (Joysticks[index]->notWorking()) {
|
||||
delete Joysticks[index];
|
||||
Joysticks[index] = 0;
|
||||
} else {
|
||||
gfctrlJoyPresent = GFCTRL_JOY_PRESENT;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#if SDL_FORCEFEEDBACK
|
||||
memset(&cfx, 0, sizeof(cfx));
|
||||
|
||||
for(int i = 0;i<GFCTRL_JOY_NUMBER;i++)
|
||||
|
@ -317,9 +285,6 @@ gfctrlJoyInit(void)
|
|||
}
|
||||
|
||||
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) < 0) {
|
||||
#else
|
||||
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) {
|
||||
#endif
|
||||
GfLogError("Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
gfctrlJoyPresent = GFCTRL_JOY_UNTESTED;
|
||||
return;
|
||||
|
@ -337,7 +302,6 @@ gfctrlJoyInit(void)
|
|||
// Don't configure the joystick if it doesn't work
|
||||
if (Joysticks[index] == NULL) {
|
||||
GfLogError("Couldn't open joystick %d: %s\n", index, SDL_GetError());
|
||||
#if SDL_FORCEFEEDBACK
|
||||
} else {
|
||||
cfx_timeout[index] = 0;
|
||||
rfx_timeout[index] = 0;
|
||||
|
@ -360,13 +324,10 @@ gfctrlJoyInit(void)
|
|||
else
|
||||
gfctrlJoyRumble(index, 0.5);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SDL_FORCEFEEDBACK
|
||||
void
|
||||
gfctrlJoyConstantForce(int index, int level, int dir)
|
||||
{
|
||||
|
@ -412,31 +373,20 @@ gfctrlJoyRumble(int index, float level)
|
|||
|
||||
rfx_timeout[index] = SDL_GetTicks() + 100;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Shutdown time.
|
||||
void
|
||||
gfctrlJoyShutdown(void)
|
||||
{
|
||||
if (gfctrlJoyPresent != GFCTRL_JOY_UNTESTED)
|
||||
#ifndef SDL_JOYSTICK
|
||||
|
||||
for (int index = 0; index < GFCTRL_JOY_NUMBER; index++)
|
||||
delete Joysticks[index];
|
||||
|
||||
|
||||
#else
|
||||
for (int index = 0; index < gfctrlJoyPresent; index++) {
|
||||
SDL_JoystickClose(Joysticks[index]);
|
||||
Joysticks[index] = NULL;
|
||||
#if SDL_FORCEFEEDBACK
|
||||
if (Haptics[index]) {
|
||||
SDL_HapticClose(Haptics[index]);
|
||||
Haptics[index] = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
gfctrlJoyPresent = GFCTRL_JOY_UNTESTED;
|
||||
}
|
||||
|
||||
|
@ -456,9 +406,7 @@ GfctrlJoyCreate(void)
|
|||
|
||||
tCtrlJoyInfo* joyInfo = (tCtrlJoyInfo *)calloc(1, sizeof(tCtrlJoyInfo));
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
joyInfoCopy = joyInfo;
|
||||
#endif
|
||||
|
||||
return joyInfo;
|
||||
}
|
||||
|
@ -483,16 +431,12 @@ GfctrlJoyRelease(tCtrlJoyInfo *joyInfo)
|
|||
int
|
||||
GfctrlJoyIsAnyPresent(void)
|
||||
{
|
||||
#if SDL_JOYSTICK
|
||||
if (gfctrlJoyPresent == 0)
|
||||
#else
|
||||
if (gfctrlJoyPresent == GFCTRL_JOY_UNTESTED)
|
||||
#endif
|
||||
gfctrlJoyInit();
|
||||
|
||||
return gfctrlJoyPresent;
|
||||
}
|
||||
#if SDL_JOYSTICK
|
||||
|
||||
int
|
||||
GfctrlSDL2JoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
|
||||
{
|
||||
|
@ -550,7 +494,7 @@ GfctrlSDL2JoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Get the current state of the joysticks
|
||||
@ingroup ctrl
|
||||
@param joyInfo Target joystick structure
|
||||
|
@ -561,48 +505,9 @@ GfctrlSDL2JoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
|
|||
int
|
||||
GfctrlJoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK
|
||||
return GfctrlSDL2JoyGetCurrentStates(joyInfo);
|
||||
#else
|
||||
int ind;
|
||||
int i;
|
||||
int b;
|
||||
unsigned int mask;
|
||||
|
||||
if (gfctrlJoyPresent == GFCTRL_JOY_PRESENT) {
|
||||
for (ind = 0; ind < GFCTRL_JOY_NUMBER; ind++) {
|
||||
if (Joysticks[ind]) {
|
||||
Joysticks[ind]->read(&b, &(joyInfo->ax[GFCTRL_JOY_MAX_AXES * ind]));
|
||||
|
||||
/* Joystick buttons */
|
||||
for (i = 0, mask = 1; i < GFCTRL_JOY_MAX_BUTTONS; i++, mask *= 2) {
|
||||
if (((b & mask) != 0) && ((joyInfo->oldb[ind] & mask) == 0)) {
|
||||
joyInfo->edgeup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 1;
|
||||
} else {
|
||||
joyInfo->edgeup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 0;
|
||||
}
|
||||
if (((b & mask) == 0) && ((joyInfo->oldb[ind] & mask) != 0)) {
|
||||
joyInfo->edgedn[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 1;
|
||||
} else {
|
||||
joyInfo->edgedn[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 0;
|
||||
}
|
||||
if ((b & mask) != 0) {
|
||||
joyInfo->levelup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 1;
|
||||
} else {
|
||||
joyInfo->levelup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 0;
|
||||
}
|
||||
}
|
||||
joyInfo->oldb[ind] = b;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
void
|
||||
GfctrlJoySetAxis(int joy, int axis, float value)
|
||||
{
|
||||
|
@ -635,7 +540,6 @@ GfctrlJoySetButton(int joy, int button, int value)
|
|||
joyInfoCopy->levelup[GFCTRL_JOY_MAX_BUTTONS * joy + button] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Initialize the mouse control
|
||||
@ingroup ctrl
|
||||
|
|
|
@ -44,11 +44,8 @@ class GfuiEventLoop::Private
|
|||
void (*cbMouseMotion)(int x, int y);
|
||||
void (*cbMousePassiveMotion)(int x, int y);
|
||||
void (*cbMouseWheel)(int x, int y, unsigned int direction);
|
||||
#if SDL_JOYSTICK
|
||||
void (*cbJoystickAxis)(int joy, int axis, float value);
|
||||
void (*cbJoystickButton)(int joy, int button, int value);
|
||||
#endif
|
||||
|
||||
void (*cbDisplay)(void);
|
||||
void (*cbReshape)(int width, int height);
|
||||
|
||||
|
@ -58,9 +55,7 @@ class GfuiEventLoop::Private
|
|||
|
||||
GfuiEventLoop::Private::Private()
|
||||
: cbMouseButton(0), cbMouseMotion(0), cbMousePassiveMotion(0), cbMouseWheel(0),
|
||||
#if SDL_JOYSTICK
|
||||
cbJoystickAxis(0), cbJoystickButton(0),
|
||||
#endif
|
||||
cbDisplay(0), cbReshape(0), bRedisplay(false)
|
||||
{
|
||||
}
|
||||
|
@ -126,7 +121,6 @@ void GfuiEventLoop::injectMouseWheelEvent(int x, int y, unsigned int direction)
|
|||
_pPrivate->cbMouseWheel(x, y, direction);
|
||||
}
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
void GfuiEventLoop::injectJoystickAxisEvent(int joy, int axis, float value)
|
||||
{
|
||||
if (_pPrivate->cbJoystickAxis)
|
||||
|
@ -138,7 +132,6 @@ void GfuiEventLoop::injectJoystickButtonEvent(int joy, int button, int value)
|
|||
if (_pPrivate->cbJoystickButton)
|
||||
_pPrivate->cbJoystickButton(joy, button, value);
|
||||
}
|
||||
#endif
|
||||
|
||||
// The event loop itself.
|
||||
void GfuiEventLoop::operator()()
|
||||
|
@ -210,7 +203,6 @@ void GfuiEventLoop::operator()()
|
|||
postQuit();
|
||||
break;
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
case SDL_JOYAXISMOTION:
|
||||
injectJoystickAxisEvent(event.jaxis.which, event.jaxis.axis, (float) event.jaxis.value / 32768);
|
||||
break;
|
||||
|
@ -222,7 +214,7 @@ void GfuiEventLoop::operator()()
|
|||
case SDL_JOYBUTTONUP:
|
||||
injectJoystickButtonEvent(event.jbutton.which, event.jbutton.button, 0);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
forceRedisplay();
|
||||
break;
|
||||
|
@ -266,7 +258,7 @@ void GfuiEventLoop::setRedisplayCB(void (*func)(void))
|
|||
{
|
||||
_pPrivate->cbDisplay = func;
|
||||
}
|
||||
#if SDL_JOYSTICK
|
||||
|
||||
void GfuiEventLoop::setJoystickAxisCB(void (*func)(int joy, int axis, float value))
|
||||
{
|
||||
_pPrivate->cbJoystickAxis = func;
|
||||
|
@ -276,7 +268,6 @@ void GfuiEventLoop::setJoystickButtonCB(void (*func)(int joy, int button, int va
|
|||
{
|
||||
_pPrivate->cbJoystickButton = func;
|
||||
}
|
||||
#endif
|
||||
|
||||
void GfuiEventLoop::setReshapeCB(void (*func)(int width, int height))
|
||||
{
|
||||
|
|
|
@ -37,11 +37,7 @@
|
|||
# pragma warning (disable:4251) // class XXX needs a DLL interface ...
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) && !defined(USE_MACPORTS)
|
||||
# include <js.h>
|
||||
#else
|
||||
# include <plib/js.h>
|
||||
#endif
|
||||
#include <climits>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
|
@ -656,20 +652,12 @@ typedef struct
|
|||
|
||||
#define GFCTRL_JOY_NUMBER 8 /* Max number of managed joysticks */
|
||||
#define GFCTRL_JOY_MAX_BUTTONS 32 /* Size of integer so don't change please */
|
||||
#if SDL_JOYSTICK
|
||||
#define GFCTRL_JOY_MAX_AXES 12
|
||||
#else
|
||||
#define GFCTRL_JOY_MAX_AXES _JS_MAX_AXES
|
||||
#endif
|
||||
|
||||
/** Joystick Information Structure */
|
||||
typedef struct
|
||||
{
|
||||
#if SDL_JOYSTICK
|
||||
int oldb[GFCTRL_JOY_MAX_BUTTONS * GFCTRL_JOY_NUMBER];
|
||||
#else
|
||||
int oldb[GFCTRL_JOY_NUMBER];
|
||||
#endif
|
||||
float ax[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER]; /**< Axis values */
|
||||
int edgeup[GFCTRL_JOY_MAX_BUTTONS * GFCTRL_JOY_NUMBER]; /**< Button transition from down (pressed) to up */
|
||||
int edgedn[GFCTRL_JOY_MAX_BUTTONS * GFCTRL_JOY_NUMBER]; /**< Button transition from up to down */
|
||||
|
@ -680,14 +668,10 @@ TGFCLIENT_API int GfctrlJoyIsAnyPresent(void);
|
|||
TGFCLIENT_API tCtrlJoyInfo* GfctrlJoyCreate(void);
|
||||
TGFCLIENT_API void GfctrlJoyRelease(tCtrlJoyInfo* joyInfo);
|
||||
TGFCLIENT_API int GfctrlJoyGetCurrentStates(tCtrlJoyInfo* joyInfo);
|
||||
#if SDL_JOYSTICK
|
||||
#if SDL_FORCEFEEDBACK
|
||||
TGFCLIENT_API void gfctrlJoyConstantForce(int index, int level, int dir);
|
||||
TGFCLIENT_API void gfctrlJoyRumble(int index, float level);
|
||||
#endif
|
||||
TGFCLIENT_API void GfctrlJoySetAxis(int joy, int axis, float value);
|
||||
TGFCLIENT_API void GfctrlJoySetButton(int joy, int button, int value);
|
||||
#endif
|
||||
|
||||
|
||||
/** Mouse information structure */
|
||||
|
@ -736,13 +720,11 @@ class TGFCLIENT_API GfuiEventLoop : public GfEventLoop
|
|||
//! Set the "mouse wheel moved" callback function.
|
||||
void setMouseWheelCB(void (*func)(int x, int y, unsigned int direction));
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
//! Set the "joystick axis moved" callback function.
|
||||
void setJoystickAxisCB(void (*func)(int joy, int axis, float value));
|
||||
|
||||
//! Set the "joystick button pressed" callback function.
|
||||
void setJoystickButtonCB(void (*func)(int joy, int button, int value));
|
||||
#endif
|
||||
|
||||
//! Set the "redisplay/refresh" callback function.
|
||||
void setRedisplayCB(void (*func)(void));
|
||||
|
@ -771,13 +753,11 @@ class TGFCLIENT_API GfuiEventLoop : public GfEventLoop
|
|||
//! Process a mouse wheel event.
|
||||
void injectMouseWheelEvent(int x, int y, unsigned int direction);
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
//! Process a joystick axis event.
|
||||
void injectJoystickAxisEvent(int joy, int axis, float value);
|
||||
|
||||
//! Process a joystick button event.
|
||||
void injectJoystickButtonEvent(int joy, int button, int value);
|
||||
#endif
|
||||
|
||||
//! Process a redisplay event.
|
||||
void redisplay();
|
||||
|
|
|
@ -121,15 +121,8 @@ static tCmdDispInfo CmdDispInfo[] = {
|
|||
{ GEAR_MODE_AUTO | GEAR_MODE_SEQ | GEAR_MODE_GRID | GEAR_MODE_HBOX } // DASHBOARD DEC
|
||||
};
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
static tCtrlJoyInfo joyInfo;// = NULL;
|
||||
static tCtrlJoyInfo joyCenter;
|
||||
#else
|
||||
static jsJoystick *Joystick[GFCTRL_JOY_NUMBER];
|
||||
static float JoyAxis[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER];
|
||||
static float JoyAxisCenter[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER];
|
||||
static int JoyButtons[GFCTRL_JOY_NUMBER];
|
||||
#endif
|
||||
|
||||
static float SteerSensVal;
|
||||
static float DeadZoneVal;
|
||||
|
@ -217,15 +210,7 @@ static void
|
|||
onQuit(void *prevMenu)
|
||||
{
|
||||
/* Release joysticks */
|
||||
#if SDL_JOYSTICK
|
||||
// GfctrlJoyRelease(joyInfo);
|
||||
#else
|
||||
for (int jsInd = 0; jsInd < GFCTRL_JOY_NUMBER; jsInd++)
|
||||
if (Joystick[jsInd]) {
|
||||
delete Joystick[jsInd];
|
||||
Joystick[jsInd] = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Back to previous screen */
|
||||
GfuiScreenActivate(prevMenu);
|
||||
|
@ -356,13 +341,8 @@ getMovedAxis(int joy_number)
|
|||
float maxDiff = 0.3;
|
||||
|
||||
for (i = GFCTRL_JOY_MAX_AXES * joy_number; i < GFCTRL_JOY_MAX_AXES * (joy_number+1); i++) {
|
||||
#if SDL_JOYSTICK
|
||||
if (maxDiff < fabs(joyInfo.ax[i] - joyCenter.ax[i])) {
|
||||
maxDiff = fabs(joyInfo.ax[i] - joyCenter.ax[i]);
|
||||
#else
|
||||
if (maxDiff < fabs(JoyAxis[i] - JoyAxisCenter[i])) {
|
||||
maxDiff = fabs(JoyAxis[i] - JoyAxisCenter[i]);
|
||||
#endif
|
||||
Index = i;
|
||||
}
|
||||
}
|
||||
|
@ -382,10 +362,6 @@ getMovedAxis(int joy_number)
|
|||
static void
|
||||
IdleWaitForInput(void)
|
||||
{
|
||||
#ifndef SDL_JOYSTICK
|
||||
int mask;
|
||||
int b;
|
||||
#endif
|
||||
int i;
|
||||
int index;
|
||||
const char *str;
|
||||
|
@ -425,14 +401,8 @@ IdleWaitForInput(void)
|
|||
}
|
||||
|
||||
/* Check for a Joystick button pressed */
|
||||
#if SDL_JOYSTICK
|
||||
GfctrlJoyGetCurrentStates(&joyInfo);
|
||||
#endif
|
||||
for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
|
||||
#ifndef SDL_JOYSTICK
|
||||
if (Joystick[index]) {
|
||||
Joystick[index]->read(&b, &JoyAxis[index * GFCTRL_JOY_MAX_AXES]);
|
||||
#endif
|
||||
|
||||
/* check for joystick movement as well */
|
||||
axis = getMovedAxis(index);
|
||||
|
@ -440,29 +410,16 @@ IdleWaitForInput(void)
|
|||
/* Allow a little extra time to detect button */
|
||||
if (axis != -1 && Cmd[CurrentCmd].pref != HM_ATT_JOY_REQ_AXIS) {
|
||||
GfSleep(0.3);
|
||||
#if SDL_JOYSTICK
|
||||
GfctrlJoyGetCurrentStates(&joyInfo);
|
||||
#else
|
||||
Joystick[index]->read(&b, &JoyAxis[index * GFCTRL_JOY_MAX_AXES]);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Joystick buttons */
|
||||
#if SDL_JOYSTICK
|
||||
for (i = 0; i < GFCTRL_JOY_MAX_BUTTONS; i++) {
|
||||
if (joyInfo.levelup[i + GFCTRL_JOY_MAX_BUTTONS * index]) {
|
||||
#else
|
||||
for (i = 0, mask = 1; i < 32; i++, mask *= 2) {
|
||||
if (((b & mask) != 0) && ((JoyButtons[index] & mask) == 0)) {
|
||||
#endif
|
||||
/* Allow a little extra time to detect axis movement */
|
||||
if (axis == -1 && Cmd[CurrentCmd].pref != HM_ATT_JOY_REQ_BUT) {
|
||||
GfSleep(0.3);
|
||||
#if SDL_JOYSTICK
|
||||
GfctrlJoyGetCurrentStates(&joyInfo);
|
||||
#else
|
||||
Joystick[index]->read(&b, &JoyAxis[index * GFCTRL_JOY_MAX_AXES]);
|
||||
#endif
|
||||
axis = getMovedAxis(index);
|
||||
}
|
||||
|
||||
|
@ -476,11 +433,7 @@ IdleWaitForInput(void)
|
|||
if (Cmd[CurrentCmd].pref >= HM_ATT_JOY_PREF_ANY)
|
||||
Cmd[CurrentCmd].pref ++;
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
Cmd[CurrentCmd].butIgnore = i + GFCTRL_JOY_MAX_BUTTONS * index;
|
||||
#else
|
||||
Cmd[CurrentCmd].butIgnore = i + 32 * index;
|
||||
#endif
|
||||
|
||||
goto configure_for_joy_axis;
|
||||
}
|
||||
|
@ -496,26 +449,15 @@ IdleWaitForInput(void)
|
|||
/* Button i fired */
|
||||
GfuiApp().eventLoop().setRecomputeCB(0);
|
||||
InputWaited = 0;
|
||||
#if SDL_JOYSTICK
|
||||
str = GfctrlGetNameByRef(GFCTRL_TYPE_JOY_BUT, i + GFCTRL_JOY_MAX_BUTTONS * index);
|
||||
Cmd[CurrentCmd].ref.index = i + GFCTRL_JOY_MAX_BUTTONS * index;
|
||||
#else
|
||||
str = GfctrlGetNameByRef(GFCTRL_TYPE_JOY_BUT, i + 32 * index);
|
||||
Cmd[CurrentCmd].ref.index = i + 32 * index;
|
||||
#endif
|
||||
Cmd[CurrentCmd].ref.type = GFCTRL_TYPE_JOY_BUT;
|
||||
GfuiButtonSetText (ScrHandle, Cmd[CurrentCmd].Id, str);
|
||||
GfuiApp().eventLoop().postRedisplay();
|
||||
#ifndef SDL_JOYSTICK
|
||||
JoyButtons[index] = b;
|
||||
#endif
|
||||
updateButtonText();
|
||||
return;
|
||||
}
|
||||
}
|
||||
#ifndef SDL_JOYSTICK
|
||||
JoyButtons[index] = b;
|
||||
#endif
|
||||
|
||||
/* Axis movement detected without button */
|
||||
if (axis != -1) {
|
||||
|
@ -546,9 +488,6 @@ configure_for_joy_axis:
|
|||
updateButtonText();
|
||||
return;
|
||||
}
|
||||
#ifndef SDL_JOYSTICK
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Let CPU take breath (and fans stay at low and quiet speed) */
|
||||
|
@ -587,15 +526,8 @@ onPush(void *vi)
|
|||
GfctrlMouseGetCurrentState(&MouseInfo);
|
||||
|
||||
/* Read initial joysticks status */
|
||||
#if SDL_JOYSTICK
|
||||
GfctrlJoyGetCurrentStates(&joyInfo);
|
||||
memcpy(&joyCenter, &joyInfo, sizeof(joyCenter));
|
||||
#else
|
||||
for (int index = 0; index < GFCTRL_JOY_NUMBER; index++)
|
||||
if (Joystick[index])
|
||||
Joystick[index]->read(&JoyButtons[index], &JoyAxis[index * GFCTRL_JOY_MAX_AXES]);
|
||||
memcpy(JoyAxisCenter, JoyAxis, sizeof(JoyAxisCenter));
|
||||
#endif
|
||||
|
||||
/* Now, wait for input device actions */
|
||||
GfuiApp().eventLoop().setRecomputeCB(IdleWaitForInput);
|
||||
|
@ -604,24 +536,8 @@ onPush(void *vi)
|
|||
static void
|
||||
onActivate(void * /* dummy */)
|
||||
{
|
||||
#if SDL_JOYSTICK
|
||||
//joyInfo = GfctrlJoyCreate();
|
||||
GfctrlJoyGetCurrentStates(&joyInfo);
|
||||
#else
|
||||
// Create and test joysticks ; only keep the up and running ones.
|
||||
for (int jsInd = 0; jsInd < GFCTRL_JOY_NUMBER; jsInd++) {
|
||||
if (!Joystick[jsInd])
|
||||
Joystick[jsInd] = new jsJoystick(jsInd);
|
||||
if (Joystick[jsInd]->notWorking()) {
|
||||
/* don't configure the joystick */
|
||||
delete Joystick[jsInd];
|
||||
Joystick[jsInd] = 0;
|
||||
} else {
|
||||
GfOut("Detected joystick #%d type '%s' %d axes\n",
|
||||
jsInd, Joystick[jsInd]->getName(), Joystick[jsInd]->getNumAxes());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ReloadValues) {
|
||||
|
||||
|
@ -701,12 +617,6 @@ ControlMenuInit(void *prevMenu, void *prefHdle, unsigned index, tGearChangeMode
|
|||
|
||||
PrevScrHandle = prevMenu;
|
||||
|
||||
#ifndef SDL_JOYSTICK
|
||||
/* Initialize joysticks array */
|
||||
for (int jsInd = 0; jsInd < GFCTRL_JOY_NUMBER; jsInd++)
|
||||
Joystick[jsInd] = 0;
|
||||
#endif
|
||||
|
||||
/* Create screen */
|
||||
ScrHandle = GfuiScreenCreate((float*)NULL, NULL, onActivate, NULL, (tfuiCallback)NULL, 1);
|
||||
|
||||
|
|
|
@ -59,15 +59,8 @@ static tCmdInfo *Cmd;
|
|||
static int MaxCmd;
|
||||
|
||||
// Joystick info.
|
||||
#if SDL_JOYSTICK
|
||||
static tCtrlJoyInfo joyInfo;// = NULL;
|
||||
static tCtrlJoyInfo joyCenter;
|
||||
#else
|
||||
static jsJoystick* Joystick[GFCTRL_JOY_NUMBER];
|
||||
static float JoyAxis[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER];
|
||||
static float JoyAxisCenter[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER];
|
||||
static int JoyButtons[GFCTRL_JOY_NUMBER];
|
||||
#endif
|
||||
|
||||
// Menu screen handle.
|
||||
static void *ScrHandle = NULL;
|
||||
|
@ -99,16 +92,7 @@ static void
|
|||
onNext(void * /* dummy */)
|
||||
{
|
||||
/* Release up and running joysticks */
|
||||
#if SDL_JOYSTICK
|
||||
//GfctrlJoyRelease(joyInfo);
|
||||
#else
|
||||
int index;
|
||||
for (index = 0; index < GFCTRL_JOY_NUMBER; index++)
|
||||
if (Joystick[index]) {
|
||||
delete Joystick[index];
|
||||
Joystick[index] = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Back to previous screen */
|
||||
if (CalState == NbCalSteps && NextMenuHandle != NULL)
|
||||
|
@ -184,11 +168,7 @@ JoyCalAutomaton(void)
|
|||
switch (CalState) {
|
||||
case 0:
|
||||
/* Grab snapshot of 'NULL' position */
|
||||
#if SDL_JOYSTICK
|
||||
memcpy(&joyCenter, &joyInfo, sizeof(joyCenter));
|
||||
#else
|
||||
memcpy(JoyAxisCenter, JoyAxis, sizeof(JoyAxisCenter));
|
||||
#endif
|
||||
|
||||
advanceStep();
|
||||
break;
|
||||
|
@ -198,11 +178,7 @@ JoyCalAutomaton(void)
|
|||
AtobList = (linked_item_t*)malloc(sizeof(linked_item_t));
|
||||
AtobList->next = NULL;
|
||||
AtobList->command = -1;
|
||||
#if SDL_JOYSTICK
|
||||
AtobList->value = joyCenter.ax[AtobAxis];
|
||||
#else
|
||||
AtobList->value = JoyAxisCenter[AtobAxis];
|
||||
#endif
|
||||
|
||||
CalState = 2;
|
||||
|
||||
|
@ -213,11 +189,7 @@ JoyCalAutomaton(void)
|
|||
|
||||
new_in_list = (linked_item_t*)malloc(sizeof(linked_item_t));
|
||||
new_in_list->command = AtobCount;
|
||||
#if SDL_JOYSTICK
|
||||
new_in_list->value = joyInfo.ax[AtobAxis];
|
||||
#else
|
||||
new_in_list->value = JoyAxis[AtobAxis];
|
||||
#endif
|
||||
|
||||
if (new_in_list->value < item_in_list->value) {
|
||||
/* insert first position*/
|
||||
|
@ -290,7 +262,6 @@ static void
|
|||
Idle2(void)
|
||||
{
|
||||
int index;
|
||||
#if SDL_JOYSTICK
|
||||
/* Check for activity on Joystick buttons */
|
||||
GfctrlJoyGetCurrentStates(&joyInfo);
|
||||
for (index = 0; index < GFCTRL_JOY_NUMBER * GFCTRL_JOY_MAX_BUTTONS; index++) {
|
||||
|
@ -307,35 +278,6 @@ Idle2(void)
|
|||
GfuiApp().eventLoop().postRedisplay();
|
||||
return;
|
||||
}
|
||||
#else
|
||||
int mask;
|
||||
int b, i;
|
||||
|
||||
|
||||
for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
|
||||
if (Joystick[index]) {
|
||||
Joystick[index]->read(&b, &JoyAxis[index * GFCTRL_JOY_MAX_AXES]);
|
||||
|
||||
/* Joystick buttons */
|
||||
for (i = 0, mask = 1; i < 32; i++, mask *= 2) {
|
||||
if (((b & mask) != 0) && ((JoyButtons[index] & mask) == 0)) {
|
||||
/* Check whether to ignore */
|
||||
if(Cmd[CalState + CmdOffset].butIgnore == i + 32 * index)
|
||||
break;
|
||||
|
||||
/* Button fired */
|
||||
JoyCalAutomaton();
|
||||
if (CalState >= NbCalSteps) {
|
||||
GfuiApp().eventLoop().setRecomputeCB(0);
|
||||
}
|
||||
GfuiApp().eventLoop().postRedisplay();
|
||||
JoyButtons[index] = b;
|
||||
return;
|
||||
}
|
||||
}
|
||||
JoyButtons[index] = b;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Let CPU take breath (and fans stay at low and quite speed) */
|
||||
|
@ -348,21 +290,8 @@ onActivate(void * /* dummy */)
|
|||
{
|
||||
int i;
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
//joyInfo = GfctrlJoyCreate();
|
||||
GfctrlJoyGetCurrentStates(&joyInfo);
|
||||
#else
|
||||
int index;
|
||||
// Create and test joysticks ; only keep the up and running ones.
|
||||
for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
|
||||
Joystick[index] = new jsJoystick(index);
|
||||
if (Joystick[index]->notWorking()) {
|
||||
/* don't configure the joystick */
|
||||
delete Joystick[index];
|
||||
Joystick[index] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
CalState = 0;
|
||||
AtobAxis = GFCTRL_JOY_NUMBER * GFCTRL_JOY_MAX_AXES;
|
||||
|
@ -385,14 +314,6 @@ onActivate(void * /* dummy */)
|
|||
GfuiApp().eventLoop().setRecomputeCB(Idle2);
|
||||
GfuiApp().eventLoop().postRedisplay();
|
||||
|
||||
#ifndef SDL_JOYSTICK
|
||||
for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
|
||||
if (Joystick[index]) {
|
||||
Joystick[index]->read(&JoyButtons[index], &JoyAxis[index * GFCTRL_JOY_MAX_AXES]); /* initial value */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
GfuiEnable(ScrHandle, CancelBut, GFUI_ENABLE);
|
||||
if (DoneBut)
|
||||
GfuiEnable(ScrHandle, DoneBut, GFUI_DISABLE);
|
||||
|
|
|
@ -64,15 +64,8 @@ static tCmdInfo *Cmd;
|
|||
static int MaxCmd;
|
||||
|
||||
// Joystick info.
|
||||
#if SDL_JOYSTICK
|
||||
static tCtrlJoyInfo joyInfo;// = NULL;
|
||||
static tCtrlJoyInfo joyCenter;
|
||||
#else
|
||||
static jsJoystick* Joystick[GFCTRL_JOY_NUMBER];
|
||||
static float JoyAxis[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER];
|
||||
static float JoyAxisCenter[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER];
|
||||
static int JoyButtons[GFCTRL_JOY_NUMBER];
|
||||
#endif
|
||||
|
||||
// Menu screen handle.
|
||||
static void *ScrHandle = NULL;
|
||||
|
@ -95,18 +88,7 @@ static int DoneBut = 0;;
|
|||
static void
|
||||
onNext(void * /* dummy */)
|
||||
{
|
||||
#if SDL_JOYSTICK
|
||||
// GfctrlJoyRelease(joyInfo);
|
||||
#else
|
||||
int index;
|
||||
|
||||
/* Release up and running joysticks */
|
||||
for (index = 0; index < GFCTRL_JOY_NUMBER; index++)
|
||||
if (Joystick[index]) {
|
||||
delete Joystick[index];
|
||||
Joystick[index] = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Back to previous screen */
|
||||
if (CalState == NbCalSteps && NextMenuHandle != NULL)
|
||||
|
@ -132,22 +114,13 @@ JoyCalAutomaton(void)
|
|||
|
||||
switch (CalState) {
|
||||
case 0:
|
||||
#if SDL_JOYSTICK
|
||||
memcpy(&joyCenter, &joyInfo, sizeof(joyCenter));
|
||||
#else
|
||||
memcpy(JoyAxisCenter, JoyAxis, sizeof(JoyAxisCenter));
|
||||
#endif
|
||||
advanceStep();
|
||||
break;
|
||||
case 1:
|
||||
axis = Cmd[CalState + CmdOffset].ref.index;
|
||||
#if SDL_JOYSTICK
|
||||
Cmd[CalState + CmdOffset].min = joyCenter.ax[axis];
|
||||
Cmd[CalState + CmdOffset].max = joyInfo.ax[axis];
|
||||
#else
|
||||
Cmd[CalState + CmdOffset].min = JoyAxisCenter[axis];
|
||||
Cmd[CalState + CmdOffset].max = JoyAxis[axis];
|
||||
#endif
|
||||
|
||||
// record the polarity of the turn action
|
||||
if (Cmd[CalState + CmdOffset].max >= Cmd[CalState + CmdOffset].min)
|
||||
|
@ -155,34 +128,21 @@ JoyCalAutomaton(void)
|
|||
else
|
||||
Cmd[CalState + CmdOffset].pow = -1.0;
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
sprintf(buf, "%.2f", joyInfo.ax[axis]);
|
||||
#else
|
||||
sprintf(buf, "%.2f", JoyAxis[axis]);
|
||||
#endif
|
||||
GfuiLabelSetText(ScrHandle, LabMinId[0], buf);
|
||||
advanceStep();
|
||||
break;
|
||||
case 2:
|
||||
axis = Cmd[CalState + CmdOffset].ref.index;
|
||||
#if SDL_JOYSTICK
|
||||
Cmd[CalState + CmdOffset].min = joyCenter.ax[axis];
|
||||
Cmd[CalState + CmdOffset].max = joyInfo.ax[axis];
|
||||
#else
|
||||
Cmd[CalState + CmdOffset].min = JoyAxisCenter[axis];
|
||||
Cmd[CalState + CmdOffset].max = JoyAxis[axis];
|
||||
#endif
|
||||
|
||||
// record the polarity of the turn action
|
||||
if (Cmd[CalState + CmdOffset].max >= Cmd[CalState + CmdOffset].min)
|
||||
Cmd[CalState + CmdOffset].pow = 1.0;
|
||||
else
|
||||
Cmd[CalState + CmdOffset].pow = -1.0;
|
||||
#if SDL_JOYSTICK
|
||||
sprintf(buf, "%.2f", joyInfo.ax[axis]);
|
||||
#else
|
||||
sprintf(buf, "%.2f", JoyAxis[axis]);
|
||||
#endif
|
||||
GfuiLabelSetText(ScrHandle, LabMaxId[0], buf);
|
||||
advanceStep();
|
||||
break;
|
||||
|
@ -190,25 +150,12 @@ JoyCalAutomaton(void)
|
|||
case 4:
|
||||
case 5:
|
||||
axis = Cmd[CalState + CmdOffset].ref.index;
|
||||
#if SDL_JOYSTICK
|
||||
Cmd[CalState + CmdOffset].min = joyCenter.ax[axis];
|
||||
Cmd[CalState + CmdOffset].max = joyInfo.ax[axis];
|
||||
#else
|
||||
Cmd[CalState + CmdOffset].min = JoyAxisCenter[axis];
|
||||
Cmd[CalState + CmdOffset].max = JoyAxis[axis];
|
||||
#endif
|
||||
Cmd[CalState + CmdOffset].pow = 1.0;
|
||||
#if SDL_JOYSTICK
|
||||
sprintf(buf, "%.2f", joyCenter.ax[axis]);
|
||||
#else
|
||||
sprintf(buf, "%.2f", JoyAxisCenter[axis]);
|
||||
#endif
|
||||
GfuiLabelSetText(ScrHandle, LabMinId[CalState - 2], buf);
|
||||
#if SDL_JOYSTICK
|
||||
sprintf(buf, "%.2f", joyInfo.ax[axis]);
|
||||
#else
|
||||
sprintf(buf, "%.2f", JoyAxis[axis]);
|
||||
#endif
|
||||
GfuiLabelSetText(ScrHandle, LabMaxId[CalState - 2], buf);
|
||||
advanceStep();
|
||||
|
||||
|
@ -231,7 +178,6 @@ static void
|
|||
Idle2(void)
|
||||
{
|
||||
int index;
|
||||
#if SDL_JOYSTICK
|
||||
/* Check for activity on Joystick buttons */
|
||||
GfctrlJoyGetCurrentStates(&joyInfo);
|
||||
for (index = 0; index < GFCTRL_JOY_NUMBER * GFCTRL_JOY_MAX_BUTTONS; index++) {
|
||||
|
@ -248,35 +194,6 @@ Idle2(void)
|
|||
GfuiApp().eventLoop().postRedisplay();
|
||||
return;
|
||||
}
|
||||
#else
|
||||
int mask;
|
||||
int b, i;
|
||||
|
||||
|
||||
for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
|
||||
if (Joystick[index]) {
|
||||
Joystick[index]->read(&b, &JoyAxis[index * GFCTRL_JOY_MAX_AXES]);
|
||||
|
||||
/* Joystick buttons */
|
||||
for (i = 0, mask = 1; i < 32; i++, mask *= 2) {
|
||||
if (((b & mask) != 0) && ((JoyButtons[index] & mask) == 0)) {
|
||||
/* Check whether to ignore */
|
||||
if(Cmd[CalState + CmdOffset].butIgnore == i + 32 * index)
|
||||
break;
|
||||
|
||||
/* Button fired */
|
||||
JoyCalAutomaton();
|
||||
if (CalState >= NbCalSteps) {
|
||||
GfuiApp().eventLoop().setRecomputeCB(0);
|
||||
}
|
||||
GfuiApp().eventLoop().postRedisplay();
|
||||
JoyButtons[index] = b;
|
||||
return;
|
||||
}
|
||||
}
|
||||
JoyButtons[index] = b;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Let CPU take breath (and fans stay at low and quite speed) */
|
||||
|
@ -289,34 +206,13 @@ onActivate(void * /* dummy */)
|
|||
{
|
||||
int i;
|
||||
int step;
|
||||
#if SDL_JOYSTICK
|
||||
//joyInfo = GfctrlJoyCreate();
|
||||
GfctrlJoyGetCurrentStates(&joyInfo);
|
||||
#else
|
||||
int index;
|
||||
|
||||
// Create and test joysticks ; only keep the up and running ones.
|
||||
for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
|
||||
Joystick[index] = new jsJoystick(index);
|
||||
if (Joystick[index]->notWorking()) {
|
||||
/* don't configure the joystick */
|
||||
delete Joystick[index];
|
||||
Joystick[index] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
CalState = 0;
|
||||
GfuiLabelSetText(ScrHandle, InstId, Instructions[CalState]);
|
||||
GfuiApp().eventLoop().setRecomputeCB(Idle2);
|
||||
GfuiApp().eventLoop().postRedisplay();
|
||||
#ifndef SDL_JOYSTICK
|
||||
for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
|
||||
if (Joystick[index]) {
|
||||
Joystick[index]->read(&JoyButtons[index], &JoyAxis[index * GFCTRL_JOY_MAX_AXES]); /* initial value */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < NbMaxCalAxis; i++) {
|
||||
if (i > 0) {
|
||||
|
|
Loading…
Reference in New Issue