Skip to content

Commit

Permalink
add other controller types, bump wii to sdl2
Browse files Browse the repository at this point in the history
  • Loading branch information
vgmoose committed Mar 16, 2024
1 parent 064db44 commit bac5c87
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ INCLUDES += libs/chesto/libs/resinfs/include
endif

# for sdl2 platforms (wiiu or pc or switch targets) use sdl font cache
ifeq ($(filter-out wiiu pc switch,$(MAKECMDGOALS)),)
ifeq ($(filter-out wiiu pc wii switch,$(MAKECMDGOALS)),)
SOURCES += $(CHESTO_DIR)/libs/SDL_FontCache
VPATH += $(CHESTO_DIR)/libs/SDL_FontCache
endif
Expand Down
6 changes: 3 additions & 3 deletions helpers/Makefile.wii
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
include $(HELPERS)/Makefile.sdl1
include $(HELPERS)/Makefile.sdl2
include $(DEVKITPPC)/wii_rules

CFLAGS += -g -O2 -Wall $(MACHDEP) -DUSE_RAMFS -DUSE_FILE32API -DWII -DNETWORK_MOCK
CFLAGS += -g -O2 -Wall $(MACHDEP) -DUSE_RAMFS -DUSE_FILE32API -DWII
LDFLAGS += -g $(MACHDEP) -Wl,-Map,$(notdir $@).map

LIBS += -lfat -lwiiuse -lbte -laesnd -logc -lwiikeyboard
LIBS += -lcurl -lmbedtls -lmbedx509 -lmbedcrypto -lwiisocket -lmodplug -lopusfile -lopus -lmpg123 -lvorbisidec -logg -lfat -lwiiuse -lbte -laesnd -logc -lwiikeyboard -lharfbuzz -lfreetype -DNETWORK_MOCK

BUILD := build_wii
LIBDIRS := $(DEVKITPRO)/portlibs/wii $(DEVKITPRO)/portlibs/ppc
Expand Down
61 changes: 59 additions & 2 deletions src/InputEvents.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include "InputEvents.hpp"
#include "RootDisplay.hpp"
#include <string>
#include <map>

int TOTAL_BUTTONS = 18;

// computer key mappings
CST_Keycode key_buttons[] = { SDLK_a, SDLK_b, SDLK_x, SDLK_y, SDLK_UP, SDLK_DOWN, SDLK_LEFT, SDLK_RIGHT, SDLK_RETURN, SDLK_l, SDLK_r, SDLK_z, SDLK_BACKSPACE, SDLK_UP, SDLK_DOWN, SDLK_q };

#ifndef SDL1
SDL_GameControllerButton pad_buttons[] = { SDL_A, SDL_B, SDL_X, SDL_Y, SDL_UP, SDL_DOWN, SDL_LEFT, SDL_RIGHT, SDL_PLUS, SDL_L, SDL_R, SDL_ZL, SDL_MINUS, SDL_UP_STICK, SDL_DOWN_STICK, SDL_LEFT_STICK, SDL_RIGHT_STICK, SDL_ZR };
SDL_GameControllerButton pad_buttons[] = { SDL_A, SDL_B, SDL_X, SDL_Y, SDL_UP, SDL_DOWN, SDL_LEFT, SDL_RIGHT, SDL_PLUS, SDL_L, SDL_R, SDL_ZL, SDL_MINUS, SDL_UP_STICK, SDL_DOWN_STICK, SDL_LEFT_STICK, SDL_RIGHT_STICK, SDL_ZR, };
#else
int pad_buttons[] = { 1, 2, 3, 4, 0, 0, 0, 0, 8, 5, 6, 5, 7 };
#define SDL_FINGERDOWN SDL_MOUSEBUTTONDOWN
Expand All @@ -20,11 +22,66 @@ int pad_buttons[] = { 1, 2, 3, 4, 0, 0, 0, 0, 8, 5, 6, 5, 7 };
#endif

// our own "buttons" that correspond to the above SDL ones
unsigned int ie_buttons[] = { A_BUTTON, B_BUTTON, X_BUTTON, Y_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, START_BUTTON, L_BUTTON, R_BUTTON, ZL_BUTTON, SELECT_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, ZR_BUTTON };
unsigned int nintendo_buttons[] = { A_BUTTON, B_BUTTON, X_BUTTON, Y_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, START_BUTTON, L_BUTTON, R_BUTTON, ZL_BUTTON, SELECT_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, ZR_BUTTON };

unsigned int* ie_buttons = nintendo_buttons;

// human readable lowercase names for the buttons (used by the UI)
std::string nintendoButtonNames[] = { "a", "b", "x", "y", "up", "down", "left", "right", "plus", "l", "r", "zl", "minus", "up", "down", "left", "right", "zr" };

// human readable lowercase keyboard buttons
std::string keyButtonNames[] = { "a", "b", "x", "y", "up", "down", "left", "right", "return", "l", "r", "z", "backspace", "up", "down", "left", "right", "q" };

// wii remote (alone) buttons, a smaller set of actions
// (buttons that aren't available will need to be pressed using IR sensor)
unsigned int wii_buttons[] = { A_BUTTON, B_BUTTON, L_BUTTON, R_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, START_BUTTON, 0, 0, 0, SELECT_BUTTON, 0, 0, 0, 0, 0 };

std::string wiiButtonNames[] = { "a", "b", "1", "2", "up", "down", "left", "right", "plus", "", "", "", "minus", "", "", "", "", "" };

// wii remote and nunchuk, separate and more actions (but still not all) available
unsigned int nunchuk_buttons[] = { A_BUTTON, B_BUTTON, L_BUTTON, R_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, START_BUTTON, 0, 0, X_BUTTON, SELECT_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, Y_BUTTON };

std::string nunchukButtonNames[] = { "a", "b", "1", "2", "up", "down", "left", "right", "plus", "", "", "z", "minus", "up", "down", "left", "right", "c" };

// if true, don't count key inputs (PC/usb keyboard) as button events for us
bool InputEvents::bypassKeyEvents = false;

struct GamepadInfo {
unsigned int* buttons;
std::string* names;
std::string prefix;
std::string controller_type;

public:
GamepadInfo(unsigned int* buttons, std::string* names, std::string prefix, std::string controller_type)
: buttons(buttons), names(names), prefix(prefix), controller_type(controller_type) {}
};

// map of controller name to buttons, names, prefix, and controller type
std::map<std::string, GamepadInfo> gamepadMap = {
/* Non-controller types, like keyboard */
{ "Keyboard", GamepadInfo(nullptr, keyButtonNames, "keyboard", "key") },
/* These 5 names are returned by the wiiu SDL2 port */
{ "WiiU Gamepad", GamepadInfo(nintendo_buttons, nintendoButtonNames, "wiiu", "gamepad") },
{ "WiiU Pro Controller", { nintendo_buttons, nintendoButtonNames, "wiiu", "pro" } },
{ "Wii Remote", { wii_buttons, wiiButtonNames, "wii", "remote" } },
{ "Wii Remote and Nunchuk", { nunchuk_buttons, nunchukButtonNames, "wii", "nunchuk" } },
{ "Wii Classic Controller", { nintendo_buttons, nintendoButtonNames, "wii", "classic"} },
/* The switch SDL2 port only returns this string for all controller types*/
{ "Switch Controller", { nintendo_buttons, nintendoButtonNames, "switch", "pro" } },
/* For PC platforms, more specific Switch controller types can be recognized */
// { "Pro Controller", { nintendo_buttons, nintendoButtonNames, "switch" } },
// { "Joy-Con (L)", { nintendo_buttons, nintendoButtonNames, "switch" } },
// { "Joy-Con (R)", { nintendo_buttons, nintendoButtonNames, "switch" } },
// { "Switch Pro Controller", { nintendo_buttons, nintendoButtonNames, "switch" } },
/* Other controller types */
// { "Xbox 360 Controller", { xbox_buttons, xboxButtonNames, "xbox" } },
// { "Xbox One Controller", { xbox_buttons, xboxButtonNames, "xbox" } },
// { "Xbox Series X Controller", { xbox_buttons, xboxButtonNames, "xbox" } },
// { "PS4 Controller", { ps_buttons, psButtonNames, "playstation" } },
// { "PS5 Controller", { ps_buttons, psButtonNames, "playstation" } }
};

InputEvents::InputEvents()
{
#if defined(__WIIU__) && defined(USE_KEYBOARD)
Expand Down
9 changes: 6 additions & 3 deletions src/RootDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ RootDisplay::RootDisplay()
// set platform-specific default background colors, (which can be overridden)
#if defined(__WIIU__)
this->backgroundColor = fromRGB(0x20 - 0x10, 154 - 0x10, 199 - 0x10);
#elif defined(WII)
// the system wii gray
this->backgroundColor = fromRGB(0x8b, 0x8b, 0x8b);
#elif defined(_3DS) || defined(_3DS_MOCK)
this->backgroundColor = fromRGB(30, 30, 30);
#elif defined(SWITCH)
Expand All @@ -67,12 +70,12 @@ RootDisplay::RootDisplay()
#endif

// set starting resolution based on SDL version
#ifndef SDL1
setScreenResolution(1280, 720);
#if defined(WII)
setScreenResolution(640, 480);
#elif defined(_3DS) || defined(_3DS_MOCK)
setScreenResolution(400, 480); // 3ds has a special resolution!
#else
setScreenResolution(840, 640);
setScreenResolution(1280, 720);
#endif

// the main input handler
Expand Down
4 changes: 4 additions & 0 deletions src/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,14 @@ void Texture::render(Element* parent)
CST_RenderCopyRotate(renderer, mTexture, NULL, &rect, this->angle);
}
else if (useColorMask) {
#ifndef SDL1
// render the texture with a mask color (only can darken the texture)
SDL_SetTextureColorMod(mTexture, maskColor.r, maskColor.g, maskColor.b);
#endif
CST_RenderCopy(renderer, mTexture, NULL, &rect);
#ifndef SDL1
SDL_SetTextureColorMod(mTexture, 0xFF, 0xFF, 0xFF);
#endif
} else {
// render the texture normally
CST_RenderCopy(renderer, mTexture, NULL, &rect);
Expand Down

0 comments on commit bac5c87

Please sign in to comment.