GCC is very very picky about switch statements.

This commit is contained in:
Ben "root" Anderson
2013-10-25 03:59:55 -05:00
parent 0123a24dd1
commit 7608c814e4
@@ -52,7 +52,7 @@ static BOOL CALLBACK EnumDevicesCallback( const DIDEVICEINSTANCE *pdidInstance,
switch( device.type ) switch( device.type )
{ {
case device.JOYSTICK: case DIDevice::JOYSTICK:
if( g_iNumJoysticks == NUM_JOYSTICKS ) if( g_iNumJoysticks == NUM_JOYSTICKS )
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
@@ -60,11 +60,11 @@ static BOOL CALLBACK EnumDevicesCallback( const DIDEVICEINSTANCE *pdidInstance,
g_iNumJoysticks++; g_iNumJoysticks++;
break; break;
case device.KEYBOARD: case DIDevice::KEYBOARD:
device.dev = DEVICE_KEYBOARD; device.dev = DEVICE_KEYBOARD;
break; break;
case device.MOUSE: case DIDevice::MOUSE:
device.dev = DEVICE_MOUSE; device.dev = DEVICE_MOUSE;
break; break;
} }
@@ -285,7 +285,7 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
{ {
default: default:
FAIL_M(ssprintf("Unsupported DI device type: %i", device.type)); FAIL_M(ssprintf("Unsupported DI device type: %i", device.type));
case device.KEYBOARD: case DIDevice::KEYBOARD:
{ {
unsigned char keys[256]; unsigned char keys[256];
@@ -306,7 +306,7 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
} }
} }
break; break;
case device.JOYSTICK: case DIDevice::JOYSTICK:
{ {
DIJOYSTATE state; DIJOYSTATE state;
@@ -322,50 +322,38 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
switch(in.type) switch(in.type)
{ {
case in.BUTTON: case input_t::BUTTON:
{ {
DeviceInput di( dev, enum_add2(JOY_BUTTON_1, in.num), !!state.rgbButtons[in.ofs - DIJOFS_BUTTON0], tm ); DeviceInput di( dev, enum_add2(JOY_BUTTON_1, in.num), !!state.rgbButtons[in.ofs - DIJOFS_BUTTON0], tm );
ButtonPressed( di ); ButtonPressed( di );
break; break;
} }
case in.AXIS: case input_t::AXIS:
{ {
DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid; DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid;
int val = 0; int val = 0;
switch( in.ofs ) switch( in.ofs )
{ if( in.ofs == DIJOFS_X )
case DIJOFS_X: neg = JOY_LEFT; pos = JOY_RIGHT; { neg = JOY_LEFT; pos = JOY_RIGHT; val = state.lX; }
val = state.lX; else if( in.ofs == DIJOFS_Y )
break; { neg = JOY_UP; pos = JOY_DOWN; val = state.lY; }
case DIJOFS_Y: neg = JOY_UP; pos = JOY_DOWN; else if( in.ofs == DIJOFS_Z )
val = state.lY; { neg = JOY_Z_UP; pos = JOY_Z_DOWN; val = state.lZ; }
break; else if( in.ofs == DIJOFS_RX )
case DIJOFS_Z: neg = JOY_Z_UP; pos = JOY_Z_DOWN; { neg = JOY_ROT_LEFT; pos = JOY_ROT_RIGHT; val = state.lRx; }
val = state.lZ; else if( in.ofs == DIJOFS_RY )
break; { neg = JOY_ROT_UP; pos = JOY_ROT_DOWN; val = state.lRy; }
case DIJOFS_RX: neg = JOY_ROT_LEFT; pos = JOY_ROT_RIGHT; else if( in.ofs == DIJOFS_RZ )
val = state.lRx; { neg = JOY_ROT_Z_UP; pos = JOY_ROT_Z_DOWN; val = state.lRz; }
break; else if( in.ofs == DIJOFS_SLIDER(0) )
case DIJOFS_RY: neg = JOY_ROT_UP; pos = JOY_ROT_DOWN; { neg = JOY_AUX_1; pos = JOY_AUX_2; val = state.rglSlider[0]; }
val = state.lRy; else if( in.ofs == DIJOFS_SLIDER(1) )
break; { neg = JOY_AUX_3; pos = JOY_AUX_4; val = state.rglSlider[1]; }
case DIJOFS_RZ: neg = JOY_ROT_Z_UP; pos = JOY_ROT_Z_DOWN; else LOG->MapLog( "unknown input",
val = state.lRz;
break;
case DIJOFS_SLIDER(0):
neg = JOY_AUX_1; pos = JOY_AUX_2;
val = state.rglSlider[0];
break;
case DIJOFS_SLIDER(1):
neg = JOY_AUX_3; pos = JOY_AUX_4;
val = state.rglSlider[1];
break;
default: LOG->MapLog( "unknown input",
"Controller '%s' is returning an unknown joystick offset, %i", "Controller '%s' is returning an unknown joystick offset, %i",
device.m_sName.c_str(), in.ofs ); device.m_sName.c_str(), in.ofs );
continue;
}
if( neg != DeviceButton_Invalid ) if( neg != DeviceButton_Invalid )
{ {
float l = SCALE( int(val), 0.0f, 100.0f, 0.0f, 1.0f ); float l = SCALE( int(val), 0.0f, 100.0f, 0.0f, 1.0f );
@@ -376,7 +364,7 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
break; break;
} }
case in.HAT: case input_t::HAT:
if( in.num == 0 ) if( in.num == 0 )
{ {
const int pos = TranslatePOV( state.rgdwPOV[in.ofs - DIJOFS_POV(0)] ); const int pos = TranslatePOV( state.rgdwPOV[in.ofs - DIJOFS_POV(0)] );
@@ -391,7 +379,7 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
} }
} }
break; break;
case device.MOUSE: case DIDevice::MOUSE:
// Not 100% perfect (or tested much) yet. -aj // Not 100% perfect (or tested much) yet. -aj
DIMOUSESTATE state; DIMOUSESTATE state;
@@ -410,27 +398,21 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
switch(in.type) switch(in.type)
{ {
case in.BUTTON: case input_t::BUTTON:
{ {
DeviceInput di( dev, enum_add2(MOUSE_LEFT, in.num), !!state.rgbButtons[in.ofs - DIMOFS_BUTTON0], tm ); DeviceInput di( dev, enum_add2(MOUSE_LEFT, in.num), !!state.rgbButtons[in.ofs - DIMOFS_BUTTON0], tm );
ButtonPressed( di ); ButtonPressed( di );
break; break;
} }
case in.AXIS: case input_t::AXIS:
{ {
DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid; DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid;
int val = 0; int val = 0;
switch( in.ofs ) if( in.ofs == DIMOFS_X )
{ { neg = MOUSE_X_LEFT; pos = MOUSE_X_RIGHT; val = state.lX; }
case DIMOFS_X: else if( in.ofs == DIMOFS_Y )
neg = MOUSE_X_LEFT; pos = MOUSE_X_RIGHT; { neg = MOUSE_Y_UP; pos = MOUSE_Y_DOWN; val = state.lY; }
val = state.lX; else if( in.ofs == DIMOFS_Z )
break;
case DIMOFS_Y:
neg = MOUSE_Y_UP; pos = MOUSE_Y_DOWN;
val = state.lY;
break;
case DIMOFS_Z:
{ {
neg = MOUSE_WHEELDOWN; pos = MOUSE_WHEELUP; neg = MOUSE_WHEELDOWN; pos = MOUSE_WHEELUP;
val = state.lZ; val = state.lZ;
@@ -455,12 +437,9 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
ButtonPressed( DeviceInput(dev, pos, 0, tm) ); ButtonPressed( DeviceInput(dev, pos, 0, tm) );
} }
} }
break; else LOG->MapLog( "unknown input",
default: LOG->MapLog( "unknown input",
"Mouse '%s' is returning an unknown mouse offset, %i", "Mouse '%s' is returning an unknown mouse offset, %i",
device.m_sName.c_str(), in.ofs ); device.m_sName.c_str(), in.ofs );
continue;
}
break; break;
} }
} }
@@ -513,31 +492,28 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
switch( in.type ) switch( in.type )
{ {
case in.KEY: case input_t::KEY:
ButtonPressed( DeviceInput(dev, (DeviceButton) in.num, !!(evtbuf[i].dwData & 0x80), tm) ); ButtonPressed( DeviceInput(dev, (DeviceButton) in.num, !!(evtbuf[i].dwData & 0x80), tm) );
break; break;
case in.BUTTON: case input_t::BUTTON:
if(dev == DEVICE_MOUSE) if(dev == DEVICE_MOUSE)
{ {
DeviceButton mouseInput = DeviceButton_Invalid; DeviceButton mouseInput = DeviceButton_Invalid;
switch(in.ofs)
{ if( in.ofs == DIMOFS_BUTTON0 ) mouseInput = MOUSE_LEFT;
case DIMOFS_BUTTON0: mouseInput = MOUSE_LEFT; break; else if( in.ofs == DIMOFS_BUTTON1 ) mouseInput = MOUSE_RIGHT;
case DIMOFS_BUTTON1: mouseInput = MOUSE_RIGHT; break; else if( in.ofs == DIMOFS_BUTTON2 ) mouseInput = MOUSE_MIDDLE;
case DIMOFS_BUTTON2: mouseInput = MOUSE_MIDDLE; break; else LOG->MapLog( "unknown input",
default: LOG->MapLog( "unknown input",
"Mouse '%s' is returning an unknown mouse offset [button], %i", "Mouse '%s' is returning an unknown mouse offset [button], %i",
device.m_sName.c_str(), in.ofs ); device.m_sName.c_str(), in.ofs );
continue;
}
ButtonPressed( DeviceInput(dev, mouseInput, !!evtbuf[i].dwData, tm) ); ButtonPressed( DeviceInput(dev, mouseInput, !!evtbuf[i].dwData, tm) );
} }
else else
ButtonPressed( DeviceInput(dev, enum_add2(JOY_BUTTON_1, in.num), !!evtbuf[i].dwData, tm) ); ButtonPressed( DeviceInput(dev, enum_add2(JOY_BUTTON_1, in.num), !!evtbuf[i].dwData, tm) );
break; break;
case in.AXIS: case input_t::AXIS:
{ {
DeviceButton up = DeviceButton_Invalid, down = DeviceButton_Invalid; DeviceButton up = DeviceButton_Invalid, down = DeviceButton_Invalid;
if(dev == DEVICE_MOUSE) if(dev == DEVICE_MOUSE)
@@ -548,15 +524,10 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
// convert screen coordinates to client // convert screen coordinates to client
ScreenToClient(GraphicsWindow::GetHwnd(), &cursorPos); ScreenToClient(GraphicsWindow::GetHwnd(), &cursorPos);
switch(in.ofs) if( in.ofs == DIMOFS_X ) INPUTFILTER->UpdateCursorLocation((float)cursorPos.x,(float)cursorPos.y);
else if( in.ofs == DIMOFS_Y ) INPUTFILTER->UpdateCursorLocation((float)cursorPos.x,(float)cursorPos.y);
else if( in.ofs == DIMOFS_Z )
{ {
case DIMOFS_X:
INPUTFILTER->UpdateCursorLocation((float)cursorPos.x,(float)cursorPos.y);
break;
case DIMOFS_Y:
INPUTFILTER->UpdateCursorLocation((float)cursorPos.x,(float)cursorPos.y);
break;
case DIMOFS_Z:
// positive values: WheelUp // positive values: WheelUp
// negative values: WheelDown // negative values: WheelDown
INPUTFILTER->UpdateMouseWheel(l); INPUTFILTER->UpdateMouseWheel(l);
@@ -596,31 +567,25 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
ButtonPressed( diDown ); ButtonPressed( diDown );
} }
} }
break; }
default: LOG->MapLog( "unknown input", else LOG->MapLog( "unknown input",
"Mouse '%s' is returning an unknown mouse offset [axis], %i", "Mouse '%s' is returning an unknown mouse offset [axis], %i",
device.m_sName.c_str(), in.ofs ); device.m_sName.c_str(), in.ofs );
continue;
}
} }
else else
{
switch(in.ofs)
{ {
// joystick // joystick
case DIJOFS_X: up = JOY_LEFT; down = JOY_RIGHT; break; if( in.ofs == DIJOFS_X ) { up = JOY_LEFT; down = JOY_RIGHT; }
case DIJOFS_Y: up = JOY_UP; down = JOY_DOWN; break; else if( in.ofs == DIJOFS_Y ) { up = JOY_UP; down = JOY_DOWN; }
case DIJOFS_Z: up = JOY_Z_UP; down = JOY_Z_DOWN; break; else if( in.ofs == DIJOFS_Z ) { up = JOY_Z_UP; down = JOY_Z_DOWN; }else if( in.ofs == DIJOFS_RX ) { up = JOY_ROT_UP; down = JOY_ROT_DOWN; }
case DIJOFS_RX: up = JOY_ROT_UP; down = JOY_ROT_DOWN; break; else if( in.ofs == DIJOFS_RY ) { up = JOY_ROT_LEFT; down = JOY_ROT_RIGHT; }
case DIJOFS_RY: up = JOY_ROT_LEFT; down = JOY_ROT_RIGHT; break; else if( in.ofs == DIJOFS_RZ ) { up = JOY_ROT_Z_UP; down = JOY_ROT_Z_DOWN; }
case DIJOFS_RZ: up = JOY_ROT_Z_UP; down = JOY_ROT_Z_DOWN; break; else if( in.ofs == DIJOFS_SLIDER(0) ) { up = JOY_AUX_1; down = JOY_AUX_2; }
case DIJOFS_SLIDER(0): up = JOY_AUX_1; down = JOY_AUX_2; break; else if( in.ofs == DIJOFS_SLIDER(1) ) { up = JOY_AUX_3; down = JOY_AUX_4; }
case DIJOFS_SLIDER(1): up = JOY_AUX_3; down = JOY_AUX_4; break; else LOG->MapLog( "unknown input",
default: LOG->MapLog( "unknown input",
"Controller '%s' is returning an unknown joystick offset, %i", "Controller '%s' is returning an unknown joystick offset, %i",
device.m_sName.c_str(), in.ofs ); device.m_sName.c_str(), in.ofs );
continue;
}
float l = SCALE( int(evtbuf[i].dwData), 0.0f, 100.0f, 0.0f, 1.0f ); float l = SCALE( int(evtbuf[i].dwData), 0.0f, 100.0f, 0.0f, 1.0f );
ButtonPressed( DeviceInput(dev, up, max(-l,0), tm) ); ButtonPressed( DeviceInput(dev, up, max(-l,0), tm) );
ButtonPressed( DeviceInput(dev, down, max(+l,0), tm) ); ButtonPressed( DeviceInput(dev, down, max(+l,0), tm) );
@@ -628,7 +593,7 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
break; break;
} }
case in.HAT: case input_t::HAT:
{ {
const int pos = TranslatePOV( evtbuf[i].dwData ); const int pos = TranslatePOV( evtbuf[i].dwData );
ButtonPressed( DeviceInput(dev, JOY_HAT_UP, !!(pos & HAT_UP_MASK), tm) ); ButtonPressed( DeviceInput(dev, JOY_HAT_UP, !!(pos & HAT_UP_MASK), tm) );