Procházet zdrojové kódy

ps3: get rid of the useless and convoluted padutil dependency; the

standard pad API is perfect for us.
legacy
Sam Hocevar sam před 13 roky
rodič
revize
b77f25b7ff
2 změnil soubory, kde provedl 62 přidání a 20 odebrání
  1. +1
    -1
      src/Makefile.am
  2. +61
    -19
      src/ps3input.cpp

+ 1
- 1
src/Makefile.am Zobrazit soubor

@@ -16,7 +16,7 @@ liblol_a_SOURCES = \
\
eglapp.cpp eglapp.h \
\
ps3app.cpp ps3app.h \
ps3app.cpp ps3app.h ps3input.cpp ps3input.h \
\
shader/shader.cpp shader/shader.h \
\


+ 61
- 19
src/ps3input.cpp Zobrazit soubor

@@ -12,16 +12,24 @@
# include "config.h"
#endif

#include <cstdlib>

#if defined __CELLOS_LV2__
# include <padutil.h>
# include <cell/pad.h>
# include <cell/padfilter.h>
# include <sysutil/sysutil_sysparam.h>
#endif

#include "core.h"
#include "ps3input.h"

using namespace std;

namespace lol
{

static int const NUM_PADS = 7; /* CellPadUtil also has 7 */

/*
* PS3 Input implementation class
*/
@@ -32,6 +40,9 @@ class Ps3InputData

vec2 mousepos;
vec3i mousebuttons;

CellPadFilterIIRSos filter_sos[NUM_PADS][4];
bool circle_validates;
};

/*
@@ -42,10 +53,23 @@ Ps3Input::Ps3Input()
: data(new Ps3InputData())
{
#if defined __CELLOS_LV2__
cellPadUtilPadInit();
cellPadUtilSetSensorMode(true);
cellPadUtilSetPressMode(true);
cellPadUtilSetSensorFilter(CELL_PADFILTER_IIR_CUTOFF_2ND_LPF_BT_010);
int32_t ret = cellPadInit(NUM_PADS);
if (ret != CELL_OK && ret != CELL_PAD_ERROR_ALREADY_INITIALIZED)
{
Log::Error("could not initialise PS3 pad library\n");
exit(1);
}

int tmp;
ret = cellSysutilGetSystemParamInt(
CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN, &tmp);
data->circle_validates =
(ret == CELL_OK && tmp == CELL_SYSUTIL_ENTER_BUTTON_ASSIGN_CIRCLE);

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

data->mousepos = vec2(320.0f, 240.0f);
data->mousebuttons = vec3i(0, 0, 0);
@@ -59,28 +83,46 @@ void Ps3Input::TickGame(float deltams)
Entity::TickGame(deltams);

#if defined __CELLOS_LV2__
cellPadUtilUpdate();
CellPadInfo2 pad_info2;
int32_t ret = cellPadGetInfo2(&pad_info2);
if (ret != CELL_PAD_OK)
return;

int pad = cellPadUtilGetFirstConnectedPad();
if (pad >= 0)
for (int i = 0; i < NUM_PADS; i++)
{
CellPadUtilAxis axis = cellPadUtilGetAxisValue(pad, CELL_UTIL_ANALOG_RIGHT);
vec2 delta(4e-3f * (abs(axis.x - 127) < 16 ? 0 : axis.x - 127),
-4e-3f * (abs(axis.y - 127) < 16 ? 0 : axis.y - 127));
data->mousepos += delta * deltams;
Input::SetMousePos((vec2i)data->mousepos);

// L1 for mouse button
uint32_t paddata = cellPadUtilGetDigitalData(pad);
int but = cellPadUtilDigitalButtonPressed(paddata, CELL_UTIL_BUTTON_L1)
|| cellPadUtilDigitalButtonPressed(paddata, CELL_UTIL_BUTTON_R1);
if (!(pad_info2.port_status[i] & CELL_PAD_STATUS_CONNECTED))
continue;

CellPadData pad_data;
ret = cellPadGetData(i, &pad_data);
if (ret != CELL_PAD_OK || pad_data.len == 0)
continue;

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

data->mousebuttons.x = but;

/* Right stick moves the mouse */
if (!(pad_info2.system_info & CELL_PAD_INFO_INTERCEPTED))
{
int x = pad_data.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X];
int y = pad_data.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X + 1];
vec2 delta(4e-3f * (abs(x - 127) < 16 ? 0 : x - 127),
-4e-3f * (abs(y - 127) < 16 ? 0 : y - 127));
data->mousepos += delta * deltams;
Input::SetMousePos((vec2i)data->mousepos);
}

/* Only handle the first pad we meet */
break;
}
#endif
}


Načítá se…
Zrušit
Uložit