Controls are working now

This commit is contained in:
Dante Leoncini 2026-05-03 00:43:51 -03:00
parent e0107274a5
commit 6d7e068d03

View file

@ -39,8 +39,8 @@
#include "Timer.h" #include "Timer.h"
//debug //debug
//#include <e32cons.h> #include <e32cons.h>
//LOCAL_D CConsoleBase* console; LOCAL_D CConsoleBase* console;
psGlobalType psGlobal; psGlobalType psGlobal;
@ -75,6 +75,11 @@ static float virtualLeftStickY = 0.0f;
static float virtualRightStickX = 0.0f; static float virtualRightStickX = 0.0f;
static float virtualRightStickY = 0.0f; static float virtualRightStickY = 0.0f;
/*static bool dpadLeft = false;
static bool dpadRight = false;
static bool dpadUp = false;
static bool dpadDown = false;*/
static TInt tickPeriod; static TInt tickPeriod;
static uint32 cyclesPerMS; static uint32 cyclesPerMS;
@ -147,16 +152,13 @@ void CapturePad(int padID) {
RsPadButtonStatus bs; RsPadButtonStatus bs;
bs.padID = padID; bs.padID = padID;
/*RsPadEventHandler(rsPADBUTTONUP, (void *)&bs);{ RsPadEventHandler(rsPADBUTTONUP, (void *)&bs);{
if (CPad::m_bMapPadOneToPadTwo) if (CPad::m_bMapPadOneToPadTwo)
bs.padID = 1; bs.padID = 1;
RsPadEventHandler(rsPADBUTTONUP, (void *)&bs); RsPadEventHandler(rsPADBUTTONUP, (void *)&bs);
RsPadEventHandler(rsPADBUTTONDOWN, (void *)&bs); RsPadEventHandler(rsPADBUTTONDOWN, (void *)&bs);
}*/ }
// solo avisar que hubo input
RsPadEventHandler(rsPADBUTTONDOWN, &bs);
CPad *pad = CPad::GetPad(0); CPad *pad = CPad::GetPad(0);
pad->PCTempJoyState.LeftStickX = (int32)(virtualLeftStickX * 128.0f); pad->PCTempJoyState.LeftStickX = (int32)(virtualLeftStickX * 128.0f);
@ -249,6 +251,73 @@ RwBool IsForegroundApp() {
return foreground; return foreground;
} }
static int MapScanCode(TInt aScanCode, TInt aModifiers) {
switch (aScanCode) {
case EStdKeyLeftArrow:
if (aModifiers & EModifierRotateBy90) {
return JOY_DPAD_UP;
}
if (aModifiers & EModifierRotateBy180) {
return JOY_DPAD_RIGHT;
}
if (aModifiers & EModifierRotateBy270) {
return JOY_DPAD_DOWN;
}
return JOY_DPAD_LEFT;
case EStdKeyRightArrow:
if (aModifiers & EModifierRotateBy90) {
return JOY_DPAD_DOWN;
}
if (aModifiers & EModifierRotateBy180) {
return JOY_DPAD_LEFT;
}
if (aModifiers & EModifierRotateBy270) {
return JOY_DPAD_UP;
}
return JOY_DPAD_RIGHT;
case EStdKeyUpArrow:
if (aModifiers & EModifierRotateBy90) {
return JOY_DPAD_RIGHT;
}
if (aModifiers & EModifierRotateBy180) {
return JOY_DPAD_DOWN;
}
if (aModifiers & EModifierRotateBy270) {
return JOY_DPAD_LEFT;
}
return JOY_DPAD_UP;
case EStdKeyDownArrow:
if (aModifiers & EModifierRotateBy90) {
return JOY_DPAD_LEFT;
}
if (aModifiers & EModifierRotateBy180) {
return JOY_DPAD_UP;
}
if (aModifiers & EModifierRotateBy270) {
return JOY_DPAD_RIGHT;
}
return JOY_DPAD_DOWN;
case 'z':
case 'Z':
return JOY_B;
case 'x':
case 'X':
return JOY_X;
case 'c':
case 'C':
return JOY_A;
case EStdKeySpace:
case ' ':
return JOY_START;
case EStdKeyEnter:
case EStdKeyNkpEnter:
case EStdKeyDevice3:
return JOY_Y;
}
return -1;
}
class CCContainer : public CCoeControl { class CCContainer : public CCoeControl {
public: public:
CAknAppUi* iAppUi; CAknAppUi* iAppUi;
@ -341,8 +410,8 @@ public:
} }
void ConstructL(const TRect& aRect, CAknAppUi* aAppUi) { void ConstructL(const TRect& aRect, CAknAppUi* aAppUi) {
/*console = Console::NewL(_L("RE3 Debug"), TSize(KConsFullScreen, KConsFullScreen)); console = Console::NewL(_L("RE3 Debug"), TSize(KConsFullScreen, KConsFullScreen));
console->Printf(_L("Console iniciada\n"));*/ console->Printf(_L("Console iniciada\n"));
iAppUi = aAppUi; iAppUi = aAppUi;
CreateWindowL(); CreateWindowL();
@ -552,50 +621,49 @@ public:
} }
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType){ TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType){
// 1. Ignorar la repetición automática de teclas. Solo nos importa cuando se presiona o se suelta.
if (aType != EEventKeyDown && aType != EEventKeyUp) {
return EKeyWasConsumed;
}
bool pressed = (aType == EEventKeyDown); bool pressed = (aType == EEventKeyDown);
TUint scan = aKeyEvent.iScanCode; TUint scan = aKeyEvent.iScanCode;
/*if(console){ if(console){
console->Printf(_L("Scan: %d Type: %d\n"), aKeyEvent.iScanCode, aType); console->Printf(_L("Scan: %d Type: %d Pressed: %d\n"), scan, aType, pressed);
}*/ }
switch(scan) // Variables estáticas para permitir movimiento en diagonal sin que se anulen entre sí
{ static bool keyUp = false, keyDown = false, keyLeft = false, keyRight = false;
// Flechas (DPAD)
case 16: // arriba
virtualButtons[JOY_DPAD_UP] = pressed;
break;
case 17: // abajo
virtualButtons[JOY_DPAD_DOWN] = pressed;
break;
case 14: // izquierda
virtualButtons[JOY_DPAD_LEFT] = pressed;
break;
case 15: // derecha
virtualButtons[JOY_DPAD_RIGHT] = pressed;
break;
// OK → X (PlayStation) switch(scan){
// 2. Mapear flechas al Left Stick (Movimiento del personaje/auto)
case 16: keyUp = pressed; break; // Arriba
case 17: keyDown = pressed; break; // Abajo
case 14: keyLeft = pressed; break; // Izquierda
case 15: keyRight = pressed; break; // Derecha
// OK → X (PlayStation) / Entrar / Salto
case 167: // OK case 167: // OK
case 3: // Enter (algunos devices) case 3: // Enter (algunos devices)
virtualButtons[JOY_X] = pressed; virtualButtons[JOY_X] = pressed;
break; break;
// Softkeys // Softkeys
/*case 164: // softkey izquierdo case 164: // softkey izquierdo
virtualButtons[JOY_SELECT] = pressed; virtualButtons[JOY_START] = pressed;
break;*/ break;
case 165: // softkey derecho case 165: // softkey derecho
virtualButtons[JOY_START] = pressed; virtualButtons[JOY_START] = pressed;
break; break;
// Num keypad → botones // Num keypad → botones de acción (Acelerar, frenar, robar auto)
case 49: virtualButtons[JOY_X] = pressed; break; // 1 case 49: virtualButtons[JOY_X] = pressed; break; // 1 (Cuadrado / Salto/Freno)
case 50: virtualButtons[JOY_B] = pressed; break; // 2 (circulo) case 50: virtualButtons[JOY_B] = pressed; break; // 2 (Circulo / Disparo)
case 51: virtualButtons[JOY_Y] = pressed; break; // 3 (triangulo) case 51: virtualButtons[JOY_Y] = pressed; break; // 3 (Triangulo / Robar auto)
case 52: virtualButtons[JOY_A] = pressed; break; // 4 (cuadrado) case 52: virtualButtons[JOY_A] = pressed; break; // 4 (Cruz / Correr/Acelerar)
// Gatillos // Gatillos (Cambio de armas, mirar atrás)
case 53: virtualButtons[JOY_LB] = pressed; break; // 5 case 53: virtualButtons[JOY_LB] = pressed; break; // 5
case 54: virtualButtons[JOY_RB] = pressed; break; // 6 case 54: virtualButtons[JOY_RB] = pressed; break; // 6
case 55: virtualButtons[JOY_LB] = pressed; break; // 7 case 55: virtualButtons[JOY_LB] = pressed; break; // 7
@ -605,6 +673,11 @@ public:
return EKeyWasNotConsumed; return EKeyWasNotConsumed;
} }
// Calcular la posición final del joystick virtual basado en las teclas presionadas
// Esto da como resultado -1.0f, 0.0f, o 1.0f
virtualLeftStickY = (keyDown ? 1.0f : 0.0f) - (keyUp ? 1.0f : 0.0f);
virtualLeftStickX = (keyRight ? 1.0f : 0.0f) - (keyLeft ? 1.0f : 0.0f);
return EKeyWasConsumed; return EKeyWasConsumed;
} }
}; };