mirror of
https://github.com/libretro/ppsspp.git
synced 2025-01-26 11:16:13 +00:00
Remove unused pad_buttons and old virtual_input.
GamepadEmu does this now.
This commit is contained in:
parent
549169ad7f
commit
02855e7abb
@ -909,8 +909,6 @@ add_library(native STATIC
|
||||
ext/native/ui/view.h
|
||||
ext/native/ui/viewgroup.cpp
|
||||
ext/native/ui/viewgroup.h
|
||||
ext/native/ui/virtual_input.cpp
|
||||
ext/native/ui/virtual_input.h
|
||||
ext/native/util/hash/hash.cpp
|
||||
ext/native/util/hash/hash.h
|
||||
ext/native/util/random/rng.h
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "base/NativeApp.h"
|
||||
#include "base/timeutil.h"
|
||||
#include "math/math_util.h"
|
||||
#include "ui/virtual_input.h"
|
||||
#include "ui/ui_context.h"
|
||||
|
||||
static u32 GetButtonColor() {
|
||||
|
@ -44,7 +44,6 @@ inline static void ExecuteInputPoll() {
|
||||
// If that becomes an issue, maybe should poll to a copy of inputstate and only hold the lock while
|
||||
// copying that one to the real one?
|
||||
std::lock_guard<std::mutex> guard(input_state.lock);
|
||||
input_state.pad_buttons = 0;
|
||||
input_state.pad_lstick_x = 0;
|
||||
input_state.pad_lstick_y = 0;
|
||||
input_state.pad_rstick_x = 0;
|
||||
|
@ -90,7 +90,6 @@ LOCAL_SRC_FILES :=\
|
||||
ui/ui_screen.cpp \
|
||||
ui/ui_context.cpp \
|
||||
ui/screen.cpp \
|
||||
ui/virtual_input.cpp \
|
||||
util/text/utf8.cpp \
|
||||
util/text/parsers.cpp \
|
||||
util/text/wrap_text.cpp \
|
||||
|
@ -346,30 +346,8 @@ int System_GetPropertyInt(SystemProperty prop) {
|
||||
|
||||
InputState input_state;
|
||||
|
||||
static const int legacyKeyMap[] {
|
||||
NKCODE_X, //A
|
||||
NKCODE_S, //B
|
||||
NKCODE_Z, //X
|
||||
NKCODE_A, //Y
|
||||
NKCODE_W, //LBUMPER
|
||||
NKCODE_Q, //RBUMPER
|
||||
NKCODE_1, //START
|
||||
NKCODE_2, //SELECT
|
||||
NKCODE_DPAD_UP, //UP
|
||||
NKCODE_DPAD_DOWN, //DOWN
|
||||
NKCODE_DPAD_LEFT, //LEFT
|
||||
NKCODE_DPAD_RIGHT, //RIGHT
|
||||
0, //MENU (SwipeDown)
|
||||
NKCODE_ESCAPE, //BACK
|
||||
NKCODE_I, //JOY UP
|
||||
NKCODE_K, //JOY DOWN
|
||||
NKCODE_J, //JOY LEFT
|
||||
NKCODE_L, //JOY RIGHT
|
||||
};
|
||||
|
||||
void SimulateGamepad(const uint8_t *keys, InputState *input) {
|
||||
// Legacy key mapping.
|
||||
input->pad_buttons = 0;
|
||||
input->pad_lstick_x = 0;
|
||||
input->pad_lstick_y = 0;
|
||||
input->pad_rstick_x = 0;
|
||||
@ -683,7 +661,6 @@ int main(int argc, char *argv[]) {
|
||||
int framecount = 0;
|
||||
float t = 0;
|
||||
float lastT = 0;
|
||||
uint32_t pad_buttons = 0; // legacy pad buttons
|
||||
while (true) {
|
||||
input_state.accelerometer_valid = false;
|
||||
input_state.mouse_valid = true;
|
||||
@ -743,11 +720,6 @@ int main(int argc, char *argv[]) {
|
||||
key.keyCode = mapped->second;
|
||||
key.deviceId = DEVICE_ID_KEYBOARD;
|
||||
NativeKey(key);
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(legacyKeyMap); i++) {
|
||||
if (legacyKeyMap[i] == key.keyCode)
|
||||
pad_buttons |= 1 << i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_KEYUP:
|
||||
@ -762,10 +734,6 @@ int main(int argc, char *argv[]) {
|
||||
key.keyCode = mapped->second;
|
||||
key.deviceId = DEVICE_ID_KEYBOARD;
|
||||
NativeKey(key);
|
||||
for (int i = 0; i < ARRAY_SIZE(legacyKeyMap); i++) {
|
||||
if (legacyKeyMap[i] == key.keyCode)
|
||||
pad_buttons &= ~(1 << i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_TEXTINPUT:
|
||||
@ -876,7 +844,6 @@ int main(int argc, char *argv[]) {
|
||||
break;
|
||||
const uint8_t *keys = SDL_GetKeyboardState(NULL);
|
||||
SimulateGamepad(keys, &input_state);
|
||||
input_state.pad_buttons = pad_buttons;
|
||||
UpdateInputState(&input_state, true);
|
||||
UpdateRunLoop(&input_state);
|
||||
if (g_QuitRequested)
|
||||
|
@ -114,12 +114,8 @@ void ButtonTracker::Process(const KeyInput &input) {
|
||||
ButtonTracker g_buttonTracker;
|
||||
|
||||
void UpdateInputState(InputState *input, bool merge) {
|
||||
uint32_t btns = g_buttonTracker.Update();
|
||||
input->pad_buttons = merge ? (input->pad_buttons | btns) : btns;
|
||||
input->pad_buttons_down = (input->pad_last_buttons ^ input->pad_buttons) & input->pad_buttons;
|
||||
input->pad_buttons_up = (input->pad_last_buttons ^ input->pad_buttons) & input->pad_last_buttons;
|
||||
}
|
||||
|
||||
void EndInputState(InputState *input) {
|
||||
input->pad_last_buttons = input->pad_buttons;
|
||||
}
|
||||
|
||||
|
@ -127,20 +127,12 @@ struct InputState {
|
||||
// Lock this whenever you access the data in this struct.
|
||||
mutable std::mutex lock;
|
||||
InputState()
|
||||
: pad_buttons(0),
|
||||
pad_last_buttons(0),
|
||||
pad_buttons_down(0),
|
||||
pad_buttons_up(0),
|
||||
mouse_valid(false),
|
||||
: mouse_valid(false),
|
||||
accelerometer_valid(false) {
|
||||
memset(pointer_down, 0, sizeof(pointer_down));
|
||||
}
|
||||
|
||||
// Gamepad style input. For ease of use.
|
||||
int pad_buttons; // bitfield
|
||||
int pad_last_buttons;
|
||||
int pad_buttons_down; // buttons just pressed this frame
|
||||
int pad_buttons_up; // buttons just pressed last frame
|
||||
float pad_lstick_x;
|
||||
float pad_lstick_y;
|
||||
float pad_rstick_x;
|
||||
|
@ -280,7 +280,6 @@
|
||||
<ClInclude Include="ui\ui_screen.h" />
|
||||
<ClInclude Include="ui\view.h" />
|
||||
<ClInclude Include="ui\viewgroup.h" />
|
||||
<ClInclude Include="ui\virtual_input.h" />
|
||||
<ClInclude Include="util\random\rng.h" />
|
||||
<ClInclude Include="util\text\parsers.h" />
|
||||
<ClInclude Include="util\text\shiftjis.h" />
|
||||
@ -742,7 +741,6 @@
|
||||
<ClCompile Include="ui\ui_screen.cpp" />
|
||||
<ClCompile Include="ui\view.cpp" />
|
||||
<ClCompile Include="ui\viewgroup.cpp" />
|
||||
<ClCompile Include="ui\virtual_input.cpp" />
|
||||
<ClCompile Include="util\hash\hash.cpp" />
|
||||
<ClCompile Include="util\text\parsers.cpp" />
|
||||
<ClCompile Include="util\text\utf8.cpp" />
|
||||
|
@ -146,9 +146,6 @@
|
||||
<ClInclude Include="util\random\rng.h">
|
||||
<Filter>util</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ui\virtual_input.h">
|
||||
<Filter>ui</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="math\curves.h">
|
||||
<Filter>math</Filter>
|
||||
</ClInclude>
|
||||
@ -415,9 +412,6 @@
|
||||
<ClCompile Include="math\lin\plane.cpp">
|
||||
<Filter>math</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ui\virtual_input.cpp">
|
||||
<Filter>ui</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="math\curves.cpp">
|
||||
<Filter>math</Filter>
|
||||
</ClCompile>
|
||||
|
@ -4,7 +4,6 @@ set(SRCS
|
||||
view.cpp
|
||||
viewgroup.cpp
|
||||
screen.cpp
|
||||
virtual_input.cpp
|
||||
)
|
||||
|
||||
set(SRCS ${SRCS})
|
||||
|
@ -1,167 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "gfx_es2/draw_buffer.h"
|
||||
#include "gfx/texture_atlas.h"
|
||||
#include "input/input_state.h"
|
||||
#include "virtual_input.h"
|
||||
|
||||
TouchButton::TouchButton(const Atlas *atlas, int imageIndex, int overlayImageIndex, int button, int rotationAngle, bool mirror_h)
|
||||
: atlas_(atlas), imageIndex_(imageIndex), overlayImageIndex_(overlayImageIndex), button_(button), mirror_h_(mirror_h)
|
||||
{
|
||||
memset(pointerDown, 0, sizeof(pointerDown));
|
||||
w_ = atlas_->images[imageIndex_].w;
|
||||
h_ = atlas_->images[imageIndex_].h;
|
||||
rotationAngle_ = (float)rotationAngle * 3.1415927 / 180.0f;
|
||||
isDown_ = false;
|
||||
}
|
||||
|
||||
void TouchButton::update(InputState &input_state)
|
||||
{
|
||||
bool down = false;
|
||||
for (int i = 0; i < MAX_POINTERS; i++) {
|
||||
if (input_state.pointer_down[i] && isInside(input_state.pointer_x[i], input_state.pointer_y[i]))
|
||||
down = true;
|
||||
}
|
||||
|
||||
if (down)
|
||||
input_state.pad_buttons |= button_;
|
||||
|
||||
isDown_ = (input_state.pad_buttons & button_) != 0;
|
||||
}
|
||||
|
||||
void TouchButton::draw(DrawBuffer &db, uint32_t color, uint32_t colorOverlay)
|
||||
{
|
||||
float scale = 1.0f;
|
||||
if (isDown_) {
|
||||
color |= 0xFF000000;
|
||||
colorOverlay |= 0xFF000000;
|
||||
scale = 2.0f;
|
||||
}
|
||||
scale *= scale_;
|
||||
// We only mirror background
|
||||
db.DrawImageRotated(imageIndex_, x_ + w_*scale_/2, y_ + h_*scale_/2, scale, rotationAngle_, color, mirror_h_);
|
||||
if (overlayImageIndex_ != -1)
|
||||
db.DrawImageRotated(overlayImageIndex_, x_ + w_*scale_/2, y_ + h_*scale_/2, scale, rotationAngle_, colorOverlay);
|
||||
}
|
||||
|
||||
TouchCrossPad::TouchCrossPad(const Atlas *atlas, int arrowIndex, int overlayIndex)
|
||||
: atlas_(atlas), arrowIndex_(arrowIndex), overlayIndex_(overlayIndex), down_(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TouchCrossPad::update(InputState &input_state)
|
||||
{
|
||||
float stick_size_ = radius_ * 2;
|
||||
float inv_stick_size = 1.0f / (stick_size_ * scale_);
|
||||
const float deadzone = 0.17f;
|
||||
|
||||
for (int i = 0; i < MAX_POINTERS; i++) {
|
||||
if (input_state.pointer_down[i]) {
|
||||
float dx = (input_state.pointer_x[i] - x_) * inv_stick_size;
|
||||
float dy = (input_state.pointer_y[i] - y_) * inv_stick_size;
|
||||
float rad = sqrtf(dx*dx+dy*dy);
|
||||
if (rad < deadzone || rad > 1.0f)
|
||||
continue;
|
||||
|
||||
if (dx == 0 && dy == 0)
|
||||
continue;
|
||||
|
||||
int direction = (int)(floorf((atan2f(dy, dx) / (2 * M_PI) * 8) + 0.5f)) & 7;
|
||||
|
||||
input_state.pad_buttons &= ~(PAD_BUTTON_LEFT | PAD_BUTTON_RIGHT | PAD_BUTTON_UP | PAD_BUTTON_DOWN);
|
||||
switch (direction) {
|
||||
case 0: input_state.pad_buttons |= PAD_BUTTON_RIGHT; break;
|
||||
case 1: input_state.pad_buttons |= PAD_BUTTON_RIGHT | PAD_BUTTON_DOWN; break;
|
||||
case 2: input_state.pad_buttons |= PAD_BUTTON_DOWN; break;
|
||||
case 3: input_state.pad_buttons |= PAD_BUTTON_DOWN | PAD_BUTTON_LEFT; break;
|
||||
case 4: input_state.pad_buttons |= PAD_BUTTON_LEFT; break;
|
||||
case 5: input_state.pad_buttons |= PAD_BUTTON_UP | PAD_BUTTON_LEFT; break;
|
||||
case 6: input_state.pad_buttons |= PAD_BUTTON_UP; break;
|
||||
case 7: input_state.pad_buttons |= PAD_BUTTON_UP | PAD_BUTTON_RIGHT; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
down_ = input_state.pad_buttons & (PAD_BUTTON_LEFT | PAD_BUTTON_RIGHT | PAD_BUTTON_UP | PAD_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
void TouchCrossPad::draw(DrawBuffer &db, uint32_t color, uint32_t colorOverlay)
|
||||
{
|
||||
static const float xoff[4] = {1, 0, -1, 0};
|
||||
static const float yoff[4] = {0, 1, 0, -1};
|
||||
static const int dir[4] = {PAD_BUTTON_RIGHT, PAD_BUTTON_DOWN, PAD_BUTTON_LEFT, PAD_BUTTON_UP};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
float x = x_ + xoff[i] * scale_ * radius_;
|
||||
float y = y_ + yoff[i] * scale_ * radius_;
|
||||
float angle = i * M_PI / 2;
|
||||
float imgScale = (down_ & dir[i]) ? scale_ * 2 : scale_;
|
||||
db.DrawImageRotated(arrowIndex_, x, y, imgScale, angle + PI, color, false);
|
||||
if (overlayIndex_ != -1)
|
||||
db.DrawImageRotated(overlayIndex_, x, y, imgScale, angle + PI, colorOverlay);
|
||||
}
|
||||
}
|
||||
|
||||
TouchStick::TouchStick(const Atlas *atlas, int bgImageIndex, int stickImageIndex, int stick)
|
||||
: atlas_(atlas), bgImageIndex_(bgImageIndex), stickImageIndex_(stickImageIndex), stick_(stick)
|
||||
{
|
||||
stick_size_ = atlas_->images[bgImageIndex].w / 3.5f;
|
||||
memset(dragging_, 0, sizeof(dragging_));
|
||||
memset(lastPointerDown_, 0, sizeof(lastPointerDown_));
|
||||
}
|
||||
|
||||
void TouchStick::update(InputState &input_state)
|
||||
{
|
||||
float inv_stick_size = 1.0f / (stick_size_ * scale_);
|
||||
for (int i = 0; i < MAX_POINTERS; i++) {
|
||||
if (input_state.pointer_down[i]) {
|
||||
float dx = (input_state.pointer_x[i] - stick_x_) * inv_stick_size;
|
||||
float dy = (input_state.pointer_y[i] - stick_y_) * inv_stick_size;
|
||||
// Ignore outside box
|
||||
if (!dragging_[i] && (fabsf(dx) > 1.4f || fabsf(dy) > 1.4f))
|
||||
goto skip;
|
||||
if (!lastPointerDown_[i] && (fabsf(dx) < 1.4f && fabsf(dy) < 1.4f)) {
|
||||
dragging_[i] = true;
|
||||
}
|
||||
if (!dragging_[i])
|
||||
goto skip;
|
||||
|
||||
// Do not clamp to a circle! The PSP has nearly square range!
|
||||
|
||||
// Old code to clamp to a circle
|
||||
// float len = sqrtf(dx * dx + dy * dy);
|
||||
// if (len > 1.0f) {
|
||||
// dx /= len;
|
||||
// dy /= len;
|
||||
//}
|
||||
|
||||
// Still need to clamp to a square
|
||||
dx = std::min(1.0f, std::max(-1.0f, dx));
|
||||
dy = std::min(1.0f, std::max(-1.0f, dy));
|
||||
|
||||
if (stick_ == 0) {
|
||||
input_state.pad_lstick_x = dx;
|
||||
input_state.pad_lstick_y = -dy;
|
||||
} else if (stick_ == 1) {
|
||||
input_state.pad_rstick_x = dx;
|
||||
input_state.pad_rstick_y = -dy;
|
||||
}
|
||||
|
||||
} else {
|
||||
dragging_[i] = false;
|
||||
}
|
||||
skip:
|
||||
lastPointerDown_[i] = input_state.pointer_down[i];
|
||||
}
|
||||
|
||||
stick_delta_x_ = input_state.pad_lstick_x;
|
||||
stick_delta_y_ = -input_state.pad_lstick_y;
|
||||
}
|
||||
|
||||
void TouchStick::draw(DrawBuffer &db, uint32_t color)
|
||||
{
|
||||
if (bgImageIndex_ != -1)
|
||||
db.DrawImage(bgImageIndex_, stick_x_, stick_y_, 1.0f * scale_, color, ALIGN_CENTER);
|
||||
db.DrawImage(stickImageIndex_, stick_x_ + stick_delta_x_ * stick_size_ * scale_, stick_y_ + stick_delta_y_ * stick_size_ * scale_, 1.0f * scale_, color, ALIGN_CENTER);
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "math/math_util.h"
|
||||
#include "gfx/texture_atlas.h"
|
||||
|
||||
class DrawBuffer;
|
||||
|
||||
// Multitouch-enabled emulation of a hardware button.
|
||||
// Many of these can be pressed simultaneously with multitouch.
|
||||
// (any finger will work, simultaneously with other virtual button/stick actions).
|
||||
class TouchButton
|
||||
{
|
||||
public:
|
||||
TouchButton(const Atlas *atlas, int imageIndex, int overlayImageIndex, int button, int rotationAngle = 0, bool mirror_h = false);
|
||||
|
||||
void update(InputState &input_state);
|
||||
void draw(DrawBuffer &db, uint32_t color, uint32_t colorOverlay);
|
||||
|
||||
void setPos(float x, float y, float scale = 1.0f) {
|
||||
scale_ = scale;
|
||||
x_ = x - w_ * scale / 2;
|
||||
y_ = y - h_ * scale / 2;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual bool isInside(float px, float py) const
|
||||
{
|
||||
float margin = 5.0f;
|
||||
return px >= x_ - margin * scale_ && py >= y_ - margin * scale_ && px <= x_ + (w_ + margin) * scale_ && py <= y_ + (h_ + margin) * scale_;
|
||||
}
|
||||
|
||||
const Atlas *atlas_;
|
||||
|
||||
int imageIndex_;
|
||||
int overlayImageIndex_;
|
||||
int button_;
|
||||
float rotationAngle_;
|
||||
bool mirror_h_;
|
||||
|
||||
float x_, y_;
|
||||
float w_;
|
||||
float h_;
|
||||
float scale_;
|
||||
|
||||
bool isDown_;
|
||||
|
||||
// TODO: simplify into flags.
|
||||
bool pointerDown[MAX_POINTERS];
|
||||
};
|
||||
|
||||
// 4-in-one directional pad, with support for single touch diagonals.
|
||||
class TouchCrossPad
|
||||
{
|
||||
public:
|
||||
TouchCrossPad(const Atlas *atlas, int arrowIndex, int overlayIndex);
|
||||
|
||||
void update(InputState &input_state);
|
||||
void draw(DrawBuffer &db, uint32_t color, uint32_t colorOverlay);
|
||||
|
||||
void setPos(float x, float y, float radius, float scale = 1.0f) {
|
||||
x_ = x;
|
||||
y_ = y;
|
||||
radius_ = radius;
|
||||
scale_ = scale;
|
||||
}
|
||||
|
||||
private:
|
||||
const Atlas *atlas_;
|
||||
|
||||
float x_;
|
||||
float y_;
|
||||
float radius_;
|
||||
float scale_;
|
||||
|
||||
int arrowIndex_;
|
||||
int overlayIndex_;
|
||||
int down_;
|
||||
};
|
||||
|
||||
|
||||
// Multi-touch enabled virtual joystick
|
||||
// Many of these can be used simultaneously with multitouch.
|
||||
// (any finger will work, simultaneously with other virtual button/stick actions).
|
||||
class TouchStick
|
||||
{
|
||||
public:
|
||||
TouchStick(const Atlas *atlas, int bgImageIndex, int stickImageIndex, int stick);
|
||||
|
||||
void update(InputState &input_state);
|
||||
void draw(DrawBuffer &db, uint32_t color);
|
||||
|
||||
void setPos(float x, float y, float scale = 1.0f) {
|
||||
stick_x_ = x;
|
||||
stick_y_ = y;
|
||||
scale_ = scale;
|
||||
}
|
||||
|
||||
private:
|
||||
const Atlas *atlas_;
|
||||
int bgImageIndex_;
|
||||
int stickImageIndex_;
|
||||
int stick_;
|
||||
int stick_size_;
|
||||
float stick_x_;
|
||||
float stick_y_;
|
||||
float scale_;
|
||||
bool dragging_[MAX_POINTERS];
|
||||
bool lastPointerDown_[MAX_POINTERS];
|
||||
|
||||
// maintained for drawing only
|
||||
float stick_delta_x_;
|
||||
float stick_delta_y_;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user