Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Refactor menu input testing (works with joypads now)
Browse files Browse the repository at this point in the history
  • Loading branch information
idle-z committed Jun 30, 2018
1 parent edee5c2 commit 2d44206
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 87 deletions.
2 changes: 1 addition & 1 deletion Makefile.nx
Expand Up @@ -50,7 +50,7 @@ APP_ICON := $(DEVKITPRO)/libnx/default_icon.jpg
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
DEFINES += -DSWITCH -D__AARCH64__ -DNO_EXCEPTIONS -DJOYPAD_CONTROLS -DDEBUG_FILE=\"debug.txt\"
DEFINES += -DSWITCH -D__AARCH64__ -DNO_EXCEPTIONS -DJOYPAD_CONTROLS # -DDEBUG_FILE=\"debug.txt\"

ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE

Expand Down
10 changes: 3 additions & 7 deletions TODO.MD
@@ -1,17 +1,13 @@
# Refactoring
Redo menu input; the duplication is disgusting.
Change build/startup to use ROMFS for resources
Introduce a new directory structure?
Upstream changes?

# Upgrades
Controller-friendly text input
Build in Joycon-oriented default profiles
To SDL2

# Triage
Settings don't seem to be saving
Are settings saving correctly?
Do we detect joystick hotplugs? Particularly relevant given how Switch controllers work.

# Broken
Only main menu works
Out-of-menu controls seem random?
Entering a text entry menu leaves no way to return
31 changes: 19 additions & 12 deletions src/game/controller/commonController.cpp
Expand Up @@ -12,35 +12,42 @@ CommonController::CommonController()

bool CommonController::process()
{
bool ret = true;

if(gfx.testAnyInputOnce(AnyBack))
{
ret = false;
}

int newFrameSkip = 0;
if(gfx.testSDLKeyOnce(SDL_SCANCODE_1))
if(gfx.testAnyInputOnce(AnyNumOne))
newFrameSkip = 1;
else if(gfx.testSDLKeyOnce(SDL_SCANCODE_2))
else if(gfx.testAnyInputOnce(AnyNumTwo))
newFrameSkip = 2;
else if(gfx.testSDLKeyOnce(SDL_SCANCODE_3))
else if(gfx.testAnyInputOnce(AnyNumThree))
newFrameSkip = 4;
else if(gfx.testSDLKeyOnce(SDL_SCANCODE_4))
else if(gfx.testAnyInputOnce(AnyNumFour))
newFrameSkip = 8;
else if(gfx.testSDLKeyOnce(SDL_SCANCODE_5))
else if(gfx.testAnyInputOnce(AnyNumFive))
newFrameSkip = 16;
else if(gfx.testSDLKeyOnce(SDL_SCANCODE_6))
else if(gfx.testAnyInputOnce(AnyNumSix))
newFrameSkip = 32;
else if(gfx.testSDLKeyOnce(SDL_SCANCODE_7))
else if(gfx.testAnyInputOnce(AnyNumSeven))
newFrameSkip = 64;
else if(gfx.testSDLKeyOnce(SDL_SCANCODE_8))
else if(gfx.testAnyInputOnce(AnyNumEight))
newFrameSkip = 128;
else if(gfx.testSDLKeyOnce(SDL_SCANCODE_9))
else if(gfx.testAnyInputOnce(AnyNumNine))
newFrameSkip = 256;
else if(gfx.testSDLKeyOnce(SDL_SCANCODE_0))
else if(gfx.testAnyInputOnce(AnyNumZero))
newFrameSkip = 512;

if(newFrameSkip)
{
inverseFrameSkip = (gfx.testSDLKey(SDL_SCANCODE_RCTRL) || gfx.testSDLKey(SDL_SCANCODE_LCTRL));
inverseFrameSkip = gfx.testAnyInput(AnyInverse);
frameSkip = newFrameSkip;
}

++cycles;

return true;
return ret;
}
8 changes: 6 additions & 2 deletions src/game/controller/localController.cpp
Expand Up @@ -149,6 +149,8 @@ void LocalController::focus()

bool LocalController::process()
{
bool ret = true;

if(state == StateWeaponSelection)
{
if(ws->processFrame())
Expand Down Expand Up @@ -199,7 +201,9 @@ bool LocalController::process()
}
}

//CommonController::process();
ret = CommonController::process();
if(!ret)
changeState(StateGameEnded);

if(goingToMenu)
{
Expand All @@ -225,7 +229,7 @@ bool LocalController::process()
}
}

return true;
return ret;
}

void LocalController::draw(Renderer& renderer, bool useSpectatorViewports)
Expand Down
2 changes: 1 addition & 1 deletion src/game/controller/replayController.cpp
Expand Up @@ -69,7 +69,7 @@ bool ReplayController::process()
{
if(state == StateGame || state == StateGameEnded)
{
if(gfx.testSDLKeyOnce(SDL_SCANCODE_R))
if(gfx.testAnyInputOnce(AnyReset))
{
*game = *initialGame;
game->postClone(*initialGame, true);
Expand Down
11 changes: 5 additions & 6 deletions src/game/controller/stats_presenter.cpp
Expand Up @@ -399,24 +399,23 @@ void presentStats(NormalStatsRecorder& recorder, Game& game)
gfx.flip();
gfx.process();

if (gfx.testSDLKey(SDL_SCANCODE_DOWN))
if (gfx.testAnyInput(AnyDown))
{
destOffset = destOffset - 10;
}
else if (gfx.testSDLKey(SDL_SCANCODE_UP))
else if (gfx.testAnyInput(AnyUp))
{
destOffset = std::min(destOffset + 10.0, 0.0);
}
else if (gfx.testSDLKeyOnce(SDL_SCANCODE_RIGHT))
else if (gfx.testAnyInputOnce(AnyRight))
{
destPane = std::min(destPane + 1.0, 1.0);
}
else if (gfx.testSDLKeyOnce(SDL_SCANCODE_LEFT))
else if (gfx.testAnyInputOnce(AnyLeft))
{
destPane = std::max(destPane - 1.0, -1.0);
}
else if (gfx.testSDLKey(SDL_SCANCODE_RETURN) ||
gfx.testSDLKey(SDL_SCANCODE_ESCAPE))
else if (gfx.testAnyInput(AnyConfirm))
{
break;
}
Expand Down

0 comments on commit 2d44206

Please sign in to comment.