Ignore:
Timestamp:
Aug 20, 2011, 1:35:15 AM (8 years ago)
Author:
sam
Message:

ps3: get rid of the useless and convoluted padutil dependency; the
standard pad API is perfect for us.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ps3input.cpp

    r838 r839  
    1313#endif
    1414
     15#include <cstdlib>
     16
    1517#if defined __CELLOS_LV2__
    16 #   include <padutil.h>
     18#   include <cell/pad.h>
     19#   include <cell/padfilter.h>
     20#   include <sysutil/sysutil_sysparam.h>
    1721#endif
    1822
     
    2024#include "ps3input.h"
    2125
     26using namespace std;
     27
    2228namespace lol
    2329{
     30
     31static int const NUM_PADS = 7; /* CellPadUtil also has 7 */
    2432
    2533/*
     
    3341    vec2 mousepos;
    3442    vec3i mousebuttons;
     43
     44    CellPadFilterIIRSos filter_sos[NUM_PADS][4];
     45    bool circle_validates;
    3546};
    3647
     
    4354{
    4455#if defined __CELLOS_LV2__
    45     cellPadUtilPadInit();
    46     cellPadUtilSetSensorMode(true);
    47     cellPadUtilSetPressMode(true);
    48     cellPadUtilSetSensorFilter(CELL_PADFILTER_IIR_CUTOFF_2ND_LPF_BT_010);
     56    int32_t ret = cellPadInit(NUM_PADS);
     57    if (ret != CELL_OK && ret != CELL_PAD_ERROR_ALREADY_INITIALIZED)
     58    {
     59        Log::Error("could not initialise PS3 pad library\n");
     60        exit(1);
     61    }
     62
     63    int tmp;
     64    ret = cellSysutilGetSystemParamInt(
     65                        CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN, &tmp);
     66    data->circle_validates =
     67            (ret == CELL_OK && tmp == CELL_SYSUTIL_ENTER_BUTTON_ASSIGN_CIRCLE);
     68
     69    for (int i = 0; i < NUM_PADS; i++)
     70        for (int j = 0; j < 4; j++)
     71            cellPadFilterIIRInit(&data->filter_sos[i][j],
     72                                 CELL_PADFILTER_IIR_CUTOFF_2ND_LPF_BT_010);
    4973
    5074    data->mousepos = vec2(320.0f, 240.0f);
     
    6084
    6185#if defined __CELLOS_LV2__
    62     cellPadUtilUpdate();
     86    CellPadInfo2 pad_info2;
     87    int32_t ret = cellPadGetInfo2(&pad_info2);
     88    if (ret != CELL_PAD_OK)
     89        return;
    6390
    64     int pad = cellPadUtilGetFirstConnectedPad();
    65     if (pad >= 0)
     91    for (int i = 0; i < NUM_PADS; i++)
    6692    {
    67         CellPadUtilAxis axis = cellPadUtilGetAxisValue(pad, CELL_UTIL_ANALOG_RIGHT);
    68         vec2 delta(4e-3f * (abs(axis.x - 127) < 16 ? 0 : axis.x - 127),
    69                    -4e-3f * (abs(axis.y - 127) < 16 ? 0 : axis.y - 127));
    70         data->mousepos += delta * deltams;
    71         Input::SetMousePos((vec2i)data->mousepos);
     93        if (!(pad_info2.port_status[i] & CELL_PAD_STATUS_CONNECTED))
     94            continue;
    7295
    73         // L1 for mouse button
    74         uint32_t paddata = cellPadUtilGetDigitalData(pad);
    75         int but = cellPadUtilDigitalButtonPressed(paddata, CELL_UTIL_BUTTON_L1)
    76                || cellPadUtilDigitalButtonPressed(paddata, CELL_UTIL_BUTTON_R1);
    77        
     96        CellPadData pad_data;
     97        ret = cellPadGetData(i, &pad_data);
     98        if (ret != CELL_PAD_OK || pad_data.len == 0)
     99            continue;
     100
     101        /* L1 or R1 for mouse button */
     102        int but = (pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2]
     103                                                          == CELL_PAD_CTRL_L1)
     104               || (pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2]
     105                                                          == CELL_PAD_CTRL_R1);
    78106        if (but && !data->mousebuttons.x)
    79107            Input::SetMouseButton(0);
     
    82110
    83111        data->mousebuttons.x = but;
     112
     113        /* Right stick moves the mouse */
     114        if (!(pad_info2.system_info & CELL_PAD_INFO_INTERCEPTED))
     115        {
     116            int x = pad_data.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X];
     117            int y = pad_data.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X + 1];
     118            vec2 delta(4e-3f * (abs(x - 127) < 16 ? 0 : x - 127),
     119                       -4e-3f * (abs(y - 127) < 16 ? 0 : y - 127));
     120            data->mousepos += delta * deltams;
     121            Input::SetMousePos((vec2i)data->mousepos);
     122        }
     123
     124        /* Only handle the first pad we meet */
     125        break;
    84126    }
    85127#endif
Note: See TracChangeset for help on using the changeset viewer.