Browse Source

ps3: add pad support for the PS3, without plug/unplug detection for now.

legacy
Sam Hocevar sam 12 years ago
parent
commit
c36a5fe78f
2 changed files with 66 additions and 25 deletions
  1. +65
    -24
      src/platform/ps3/ps3input.cpp
  2. +1
    -1
      src/platform/ps3/ps3input.h

+ 65
- 24
src/platform/ps3/ps3input.cpp View File

@@ -39,6 +39,8 @@ class Ps3InputData
friend class Ps3Input; friend class Ps3Input;


#if defined __CELLOS_LV2__ #if defined __CELLOS_LV2__
Array<int, Stick *> m_joysticks;

vec2 mousepos; vec2 mousepos;
ivec3 mousebuttons; ivec3 mousebuttons;


@@ -53,7 +55,7 @@ class Ps3InputData
*/ */


Ps3Input::Ps3Input() Ps3Input::Ps3Input()
: data(new Ps3InputData())
: m_data(new Ps3InputData())
{ {
#if defined __CELLOS_LV2__ #if defined __CELLOS_LV2__
int32_t ret = cellPadInit(NUM_PADS); int32_t ret = cellPadInit(NUM_PADS);
@@ -66,16 +68,33 @@ Ps3Input::Ps3Input()
int tmp; int tmp;
ret = cellSysutilGetSystemParamInt( ret = cellSysutilGetSystemParamInt(
CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN, &tmp); CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN, &tmp);
data->circle_validates =
m_data->circle_validates =
(ret == CELL_OK && tmp == CELL_SYSUTIL_ENTER_BUTTON_ASSIGN_CIRCLE); (ret == CELL_OK && tmp == CELL_SYSUTIL_ENTER_BUTTON_ASSIGN_CIRCLE);


for (int i = 0; i < NUM_PADS; i++) for (int i = 0; i < NUM_PADS; i++)
for (int j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
cellPadFilterIIRInit(&data->filter_sos[i][j],
cellPadFilterIIRInit(&m_data->filter_sos[i][j],
CELL_PADFILTER_IIR_CUTOFF_2ND_LPF_BT_010); CELL_PADFILTER_IIR_CUTOFF_2ND_LPF_BT_010);


data->mousepos = vec2(320.0f, 240.0f);
data->mousebuttons = ivec3(0, 0, 0);
/* Try to detect connected pads. We should do this each frame. */
CellPadInfo2 pad_info2;
ret = cellPadGetInfo2(&pad_info2);
if (ret == CELL_PAD_OK)
{
for (int i = 0; i < NUM_PADS; i++)
{
if (!(pad_info2.port_status[i] & CELL_PAD_STATUS_CONNECTED))
continue;

Stick *stick = Input::CreateStick();
stick->SetAxisCount(4);
stick->SetButtonCount(16);
m_data->m_joysticks.Push(i, stick);
}
}

m_data->mousepos = vec2(320.0f, 240.0f);
m_data->mousebuttons = ivec3(0, 0, 0);


m_gamegroup = GAMEGROUP_BEFORE; m_gamegroup = GAMEGROUP_BEFORE;
#endif #endif
@@ -91,49 +110,71 @@ void Ps3Input::TickGame(float seconds)
if (ret != CELL_PAD_OK) if (ret != CELL_PAD_OK)
return; return;


for (int i = 0; i < NUM_PADS; i++)
for (int i = 0; i < m_data->m_joysticks.Count(); i++)
{ {
if (!(pad_info2.port_status[i] & CELL_PAD_STATUS_CONNECTED))
int j = m_data->m_joysticks[i].m1;

if (!(pad_info2.port_status[j] & CELL_PAD_STATUS_CONNECTED))
continue; continue;


/* Propagate all buttons */
uint16_t bitmap1 = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_DIGITAL1];
for (int k = 0; k < 8; k++)
m_data->m_joysticks[i].m2->SetButton(k, bitmap1 & (1 << k));
uint16_t bitmap2 = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_DIGITAL2];
for (int k = 0; k < 8; k++)
m_data->m_joysticks[i].m2->SetButton(8 + k, bitmap2 & (1 << k));

/* Get Pad status. If the data hasn't changed since the last call, /* Get Pad status. If the data hasn't changed since the last call,
* data->pad[i].len will be 0 but we carry on anyway. */
ret = cellPadGetData(i, &data->pad_data[i]);
* data->pad[j].len will be 0 but we carry on anyway. */
ret = cellPadGetData(j, &m_data->pad_data[j]);
if (ret != CELL_PAD_OK) if (ret != CELL_PAD_OK)
continue; continue;


/* Right stick moves the mouse */
if (!(pad_info2.system_info & CELL_PAD_INFO_INTERCEPTED)) if (!(pad_info2.system_info & CELL_PAD_INFO_INTERCEPTED))
{ {
int x = data->pad_data[i].button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X];
int y = data->pad_data[i].button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X + 1];
int x = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X];
int y = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X + 1];
int x2 = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X];
int y2 = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X + 1];

/* Propagate all axes */
m_data->m_joysticks[i].m2->SetAxis(0, (x - 127) / 127.0f);
m_data->m_joysticks[i].m2->SetAxis(1, (y - 127) / 127.0f);
m_data->m_joysticks[i].m2->SetAxis(2, (x2 - 127) / 127.0f);
m_data->m_joysticks[i].m2->SetAxis(3, (y2 - 127) / 127.0f);

/* Right stick moves the mouse FIXME: deprecated */
vec2 delta(4.f * (abs(x - 127) < 16 ? 0 : x - 127), vec2 delta(4.f * (abs(x - 127) < 16 ? 0 : x - 127),
-4.f * (abs(y - 127) < 16 ? 0 : y - 127)); -4.f * (abs(y - 127) < 16 ? 0 : y - 127));
data->mousepos += delta * seconds;
Input::SetMousePos((ivec2)data->mousepos);
m_data->mousepos += delta * seconds;
Input::SetMousePos((ivec2)m_data->mousepos);
} }


/* L1 or R1 for mouse button */
int but = (data->pad_data[i].button[CELL_PAD_BTN_OFFSET_DIGITAL2]
/* L1 or R1 for mouse button FIXME: deprecated */
int but = (m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_DIGITAL2]
& CELL_PAD_CTRL_L1) & CELL_PAD_CTRL_L1)
|| (data->pad_data[i].button[CELL_PAD_BTN_OFFSET_DIGITAL2]
|| (m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_DIGITAL2]
& CELL_PAD_CTRL_R1); & CELL_PAD_CTRL_R1);
if (but && !data->mousebuttons.x)
if (but && !m_data->mousebuttons.x)
Input::SetMouseButton(0); Input::SetMouseButton(0);
else if (!but && data->mousebuttons.x)
else if (!but && m_data->mousebuttons.x)
Input::UnsetMouseButton(0); Input::UnsetMouseButton(0);


data->mousebuttons.x = but;

/* Only handle the first pad we meet */
break;
m_data->mousebuttons.x = but;
} }
#endif #endif
} }


Ps3Input::~Ps3Input() Ps3Input::~Ps3Input()
{ {
delete data;
#if defined __CELLOS_LV2__
for (int i = 0; i < m_data->m_joysticks.Count(); ++i)
{
Input::DestroyStick(m_data->m_joysticks[0].m2);
}
#endif
delete m_data;
} }


} /* namespace lol */ } /* namespace lol */


+ 1
- 1
src/platform/ps3/ps3input.h View File

@@ -33,7 +33,7 @@ protected:
virtual void TickGame(float seconds); virtual void TickGame(float seconds);


private: private:
Ps3InputData *data;
Ps3InputData *m_data;
}; };


} /* namespace lol */ } /* namespace lol */


Loading…
Cancel
Save