Changeset 1587


Ignore:
Timestamp:
Jul 6, 2012, 2:14:29 PM (7 years ago)
Author:
sam
Message:

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

Location:
trunk/src/platform/ps3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/platform/ps3/ps3input.cpp

    r1310 r1587  
    4040
    4141#if defined __CELLOS_LV2__
     42    Array<int, Stick *> m_joysticks;
     43
    4244    vec2 mousepos;
    4345    ivec3 mousebuttons;
     
    5456
    5557Ps3Input::Ps3Input()
    56   : data(new Ps3InputData())
     58  : m_data(new Ps3InputData())
    5759{
    5860#if defined __CELLOS_LV2__
     
    6769    ret = cellSysutilGetSystemParamInt(
    6870                        CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN, &tmp);
    69     data->circle_validates =
     71    m_data->circle_validates =
    7072            (ret == CELL_OK && tmp == CELL_SYSUTIL_ENTER_BUTTON_ASSIGN_CIRCLE);
    7173
    7274    for (int i = 0; i < NUM_PADS; i++)
    7375        for (int j = 0; j < 4; j++)
    74             cellPadFilterIIRInit(&data->filter_sos[i][j],
     76            cellPadFilterIIRInit(&m_data->filter_sos[i][j],
    7577                                 CELL_PADFILTER_IIR_CUTOFF_2ND_LPF_BT_010);
    7678
    77     data->mousepos = vec2(320.0f, 240.0f);
    78     data->mousebuttons = ivec3(0, 0, 0);
     79    /* Try to detect connected pads. We should do this each frame. */
     80    CellPadInfo2 pad_info2;
     81    ret = cellPadGetInfo2(&pad_info2);
     82    if (ret == CELL_PAD_OK)
     83    {
     84        for (int i = 0; i < NUM_PADS; i++)
     85        {
     86            if (!(pad_info2.port_status[i] & CELL_PAD_STATUS_CONNECTED))
     87                continue;
     88
     89            Stick *stick = Input::CreateStick();
     90            stick->SetAxisCount(4);
     91            stick->SetButtonCount(16);
     92            m_data->m_joysticks.Push(i, stick);
     93        }
     94    }
     95
     96    m_data->mousepos = vec2(320.0f, 240.0f);
     97    m_data->mousebuttons = ivec3(0, 0, 0);
    7998
    8099    m_gamegroup = GAMEGROUP_BEFORE;
     
    92111        return;
    93112
    94     for (int i = 0; i < NUM_PADS; i++)
     113    for (int i = 0; i < m_data->m_joysticks.Count(); i++)
    95114    {
    96         if (!(pad_info2.port_status[i] & CELL_PAD_STATUS_CONNECTED))
     115        int j = m_data->m_joysticks[i].m1;
     116
     117        if (!(pad_info2.port_status[j] & CELL_PAD_STATUS_CONNECTED))
    97118            continue;
    98119
     120        /* Propagate all buttons */
     121        uint16_t bitmap1 = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_DIGITAL1];
     122        for (int k = 0; k < 8; k++)
     123            m_data->m_joysticks[i].m2->SetButton(k, bitmap1 & (1 << k));
     124        uint16_t bitmap2 = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_DIGITAL2];
     125        for (int k = 0; k < 8; k++)
     126            m_data->m_joysticks[i].m2->SetButton(8 + k, bitmap2 & (1 << k));
     127
    99128        /* Get Pad status. If the data hasn't changed since the last call,
    100          * data->pad[i].len will be 0 but we carry on anyway. */
    101         ret = cellPadGetData(i, &data->pad_data[i]);
     129         * data->pad[j].len will be 0 but we carry on anyway. */
     130        ret = cellPadGetData(j, &m_data->pad_data[j]);
    102131        if (ret != CELL_PAD_OK)
    103132            continue;
    104133
    105         /* Right stick moves the mouse */
    106134        if (!(pad_info2.system_info & CELL_PAD_INFO_INTERCEPTED))
    107135        {
    108             int x = data->pad_data[i].button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X];
    109             int y = data->pad_data[i].button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X + 1];
     136            int x = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X];
     137            int y = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X + 1];
     138            int x2 = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X];
     139            int y2 = m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X + 1];
     140
     141            /* Propagate all axes */
     142            m_data->m_joysticks[i].m2->SetAxis(0, (x - 127) / 127.0f);
     143            m_data->m_joysticks[i].m2->SetAxis(1, (y - 127) / 127.0f);
     144            m_data->m_joysticks[i].m2->SetAxis(2, (x2 - 127) / 127.0f);
     145            m_data->m_joysticks[i].m2->SetAxis(3, (y2 - 127) / 127.0f);
     146
     147            /* Right stick moves the mouse FIXME: deprecated */
    110148            vec2 delta(4.f * (abs(x - 127) < 16 ? 0 : x - 127),
    111149                       -4.f * (abs(y - 127) < 16 ? 0 : y - 127));
    112             data->mousepos += delta * seconds;
    113             Input::SetMousePos((ivec2)data->mousepos);
     150            m_data->mousepos += delta * seconds;
     151            Input::SetMousePos((ivec2)m_data->mousepos);
    114152        }
    115153
    116         /* L1 or R1 for mouse button */
    117         int but = (data->pad_data[i].button[CELL_PAD_BTN_OFFSET_DIGITAL2]
     154        /* L1 or R1 for mouse button FIXME: deprecated */
     155        int but = (m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_DIGITAL2]
    118156                                                          & CELL_PAD_CTRL_L1)
    119                || (data->pad_data[i].button[CELL_PAD_BTN_OFFSET_DIGITAL2]
     157               || (m_data->pad_data[j].button[CELL_PAD_BTN_OFFSET_DIGITAL2]
    120158                                                          & CELL_PAD_CTRL_R1);
    121         if (but && !data->mousebuttons.x)
     159        if (but && !m_data->mousebuttons.x)
    122160            Input::SetMouseButton(0);
    123         else if (!but && data->mousebuttons.x)
     161        else if (!but && m_data->mousebuttons.x)
    124162            Input::UnsetMouseButton(0);
    125163
    126         data->mousebuttons.x = but;
    127 
    128         /* Only handle the first pad we meet */
    129         break;
     164        m_data->mousebuttons.x = but;
    130165    }
    131166#endif
     
    134169Ps3Input::~Ps3Input()
    135170{
    136     delete data;
     171#if defined __CELLOS_LV2__
     172    for (int i = 0; i < m_data->m_joysticks.Count(); ++i)
     173    {
     174        Input::DestroyStick(m_data->m_joysticks[0].m2);
     175    }
     176#endif
     177    delete m_data;
    137178}
    138179
  • trunk/src/platform/ps3/ps3input.h

    r1310 r1587  
    3434
    3535private:
    36     Ps3InputData *data;
     36    Ps3InputData *m_data;
    3737};
    3838
Note: See TracChangeset for help on using the changeset viewer.