forums.PPSSPP.org
Code Suggestion - Printable Version

+- forums.PPSSPP.org (https://forums.ppsspp.org)
+-- Forum: PPSSPP - Playstation Portable Simulator Suitable for Playing Portably (/forumdisplay.php?fid=1)
+--- Forum: Development (/forumdisplay.php?fid=3)
+--- Thread: Code Suggestion (/showthread.php?tid=9474)



Code Suggestion - Young - 02-19-2014 09:03 AM

void PSPDpad::ProcessTouch(float x, float y, bool down) in GamepadEmu.cpp

.
.
.
bool fourWay = g_Config.bDisableDpadDiagonals || rad < 0.7f;
if (down) {
if (fourWay) {
/*int direction = (int)(floorf((atan2f(dy, dx) / (2 * M_PI) * 4) + 0.5f)) & 3;
switch (direction) {
case 0: ctrlMask |= CTRL_RIGHT; break;
case 1: ctrlMask |= CTRL_DOWN; break;
case 2: ctrlMask |= CTRL_LEFT; break;
case 3: ctrlMask |= CTRL_UP; break;
}*/

int maskL1Flag = CTRL_DOWN | CTRL_LEFT;
int maskL2Flag = CTRL_RIGHT | CTRL_DOWN;

if (dy < dx) maskL1Flag = CTRL_RIGHT | CTRL_UP;
if (dy < -dx) maskL2Flag = CTRL_LEFT | CTRL_UP;

ctrlMask = maskL1Flag & maskL2Flag;

// 4 way pad
} else {
// 8 way pad
/*int direction = (int)(floorf((atan2f(dy, dx) / (2 * M_PI) * 8) + 0.5f)) & 7;
switch (direction) {
case 0: ctrlMask |= CTRL_RIGHT; break;
case 1: ctrlMask |= CTRL_RIGHT | CTRL_DOWN; break;
case 2: ctrlMask |= CTRL_DOWN; break;
case 3: ctrlMask |= CTRL_DOWN | CTRL_LEFT; break;
case 4: ctrlMask |= CTRL_LEFT; break;
case 5: ctrlMask |= CTRL_UP | CTRL_LEFT; break;
case 6: ctrlMask |= CTRL_UP; break;
case 7: ctrlMask |= CTRL_UP | CTRL_RIGHT; break;
}*/

int maskL1Flag = CTRL_DOWN;
int maskL2Flag = CTRL_RIGHT;
int maskL3Flag = CTRL_LEFT;
int maskL4Flag = CTRL_DOWN;

if (dy < -dx * 0.41421356f) maskL1Flag = CTRL_UP; //tan 22.5(degree) = 0.4142135623730950488016887242097
if (dy < -dx * 2.41421436f) maskL2Flag = CTRL_LEFT; //tan 67.5(degree) = 2.4142135623730950488016887242097
if (dy < dx * 2.41421436f) maskL3Flag = CTRL_RIGHT;
if (dy < dx * 0.41421356f) maskL4Flag = CTRL_UP;

ctrlMask = (maskL1Flag & maskL4Flag) + (maskL2Flag & maskL3Flag);

}
}
.
.
.
i don't know how to use 'git' thing cuz i'm not a programmer
i'm just a math teacher


RE: Code Suggestion - Raimoo - 02-19-2014 09:46 AM

Maybe this post might be helpfull:

http://forums.ppsspp.org/showthread.php?tid=5231&highlight=Compiling

Compiling is much easier with MVSE2013... you can use it to test if it will work with emu.

also you can request a pull if its successfull at github


RE: Code Suggestion - Young - 02-19-2014 06:27 PM

Thanks for your repling, Raimoo

That post is exactly what I need to know


RE: Code Suggestion - Bigpet - 02-20-2014 07:26 PM

Mathmatically that may be more efficient and it will probably run faster but honstly this is not a bottleneck and the old code seems way more readable to me from a programmer perspective. But of course Herik can decide whether he likes your code better than what we have.


RE: Code Suggestion - Apology11 - 02-25-2014 06:24 PM

If you want to suggest this to the Developers, it would be better to create an account on github.com and create a new issue here:

https://github.com/hrydgard/ppsspp/issues?direction=desc&sort=updated&state=open