diff --git a/src/32x/Window_32x.c b/src/32x/Window_32x.c index 808b8b3f2..31ded0f45 100644 --- a/src/32x/Window_32x.c +++ b/src/32x/Window_32x.c @@ -110,6 +110,8 @@ static const BindMapping pad_defaults[BIND_COUNT] = { [BIND_HOTBAR_RIGHT] = { CCPAD_4, CCPAD_RIGHT } }; +void Gamepads_PreInit(void) { } + void Gamepads_Init(void) { Input.Sources |= INPUT_SOURCE_GAMEPAD; } diff --git a/src/3ds/Window_3DS.c b/src/3ds/Window_3DS.c index 7a11c5764..b7c7e0013 100644 --- a/src/3ds/Window_3DS.c +++ b/src/3ds/Window_3DS.c @@ -153,10 +153,12 @@ static const BindMapping defaults_3ds[BIND_COUNT] = { }; static Result irrst_result; +void Gamepads_PreInit(void) { + irrst_result = irrstInit(); +} void Gamepads_Init(void) { Input.Sources = INPUT_SOURCE_GAMEPAD; - irrst_result = irrstInit(); } static void HandleButtons(int port, u32 mods) { diff --git a/src/UWP/Window_UWP.cpp b/src/UWP/Window_UWP.cpp index 71d942edb..eefc83764 100644 --- a/src/UWP/Window_UWP.cpp +++ b/src/UWP/Window_UWP.cpp @@ -116,9 +116,9 @@ void Window_ProcessEvents(float delta) { dispatcher.ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); } -void Gamepads_Init(void) { +void Gamepads_PreInit(void) { } -} +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/VirtualDialog.h b/src/VirtualDialog.h index d47f0c06c..8e7909a0d 100644 --- a/src/VirtualDialog.h +++ b/src/VirtualDialog.h @@ -11,12 +11,12 @@ static cc_bool dlg_close; static cc_bool VirtualDialog_InputHook(int key, struct InputDevice* device) { return true; } static void VirtualDialog_OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* device) { - Platform_LogConst("AAAA"); dlg_close = true; } struct LogPosition { struct Bitmap* bmp; int x, y; }; -#define BEG_X 10 +#define VD_BEG_X 10 +#define VD_LINE_SPACE 20 static void PlotOnscreen(int x, int y, void* ctx) { struct LogPosition* pos = ctx; @@ -31,30 +31,33 @@ static void PlotOnscreen(int x, int y, void* ctx) { static int DrawText(const char* msg, struct Bitmap* bmp, int y) { struct LogPosition pos; pos.bmp = bmp; - pos.x = BEG_X; + pos.x = VD_BEG_X; pos.y = y; while (*msg) { - if (pos.x + 20 >= bmp->width) { - pos.x = BEG_X; - pos.y += 20; + char c = *msg; + if (pos.x + 20 >= bmp->width || c == '\n') { + pos.x = VD_BEG_X; + pos.y += VD_LINE_SPACE; } - pos.x += FallbackFont_Plot((cc_uint8)*msg, PlotOnscreen, 1, &pos); + if (c != '\n') { pos.x += FallbackFont_Plot((cc_uint8)c, PlotOnscreen, 1, &pos); } msg++; } return pos.y; } -#define DLG_TICK_INTERVAL 50 +#define VD_TICK_INTERVAL 50 +#define VD_MAX_ITERS (5000 / VD_TICK_INTERVAL) + static void VirtualDialog_Show(const char* title, const char* msg) { struct Bitmap bmp; Platform_LogConst(title); Platform_LogConst(msg); if (!LBackend_FB.bmp.scan0) { - Window_AllocFramebuffer(&bmp, Window_Main.Width, Window_Main.Height); + Window_AllocFramebuffer(&bmp, DisplayInfo.Width, DisplayInfo.Height); } else { bmp = LBackend_FB.bmp; } @@ -64,9 +67,9 @@ static void VirtualDialog_Show(const char* title, const char* msg) { Context2D_Clear(&ctx, BitmapCol_Make(50, 50, 50, 255), 0, 0, bmp.width, bmp.height); - const char* ipt_msg = "Press any button to continue"; + const char* ipt_msg = "Press any button to continue (or wait 5 seconds)"; dlg_close = false; - int y = 30; + int y = max(30, bmp.height / 2 - 50); y = DrawText(title, &bmp, y); y = DrawText(msg, &bmp, y + 20); @@ -77,14 +80,18 @@ static void VirtualDialog_Show(const char* title, const char* msg) { Event_Register_(&InputEvents.Down2, NULL, VirtualDialog_OnInputDown); Rect2D rect = { 0, 0, bmp.width, bmp.height }; + cc_bool has_window = Window_Main.Exists; - while (Window_Main.Exists && !dlg_close) + for (int i = 0; !dlg_close && i < VD_MAX_ITERS; i++) { - Window_ProcessEvents(1.0f / DLG_TICK_INTERVAL); - Gamepads_Process( 1.0f / DLG_TICK_INTERVAL); + Window_ProcessEvents(1.0f / VD_TICK_INTERVAL); + Gamepads_Process( 1.0f / VD_TICK_INTERVAL); Window_DrawFramebuffer(rect, &bmp); - Thread_Sleep(DLG_TICK_INTERVAL); + Thread_Sleep(VD_TICK_INTERVAL); + + // Window_ProcessEvents processed an app exit event + if (has_window && !Window_Main.Exists) break; } Context2D_Clear(&ctx, BitmapCol_Make(40, 40, 40, 255), diff --git a/src/Window.h b/src/Window.h index 232cdb6d7..6f96a7d49 100644 --- a/src/Window.h +++ b/src/Window.h @@ -139,6 +139,8 @@ void Window_RequestClose(void); /* Processes all pending window messages/events. */ void Window_ProcessEvents(float delta); +/* Initialises necessary state before initing platform and loading options */ +void Gamepads_PreInit(void); /* Initialises state for gamepad/joystick input. */ void Gamepads_Init(void); /* Processes all pending gamepad/joystick input. */ diff --git a/src/Window_BeOS.cpp b/src/Window_BeOS.cpp index 65478dcd6..a926ea9db 100644 --- a/src/Window_BeOS.cpp +++ b/src/Window_BeOS.cpp @@ -549,9 +549,9 @@ void Window_ProcessEvents(float delta) { } } -void Gamepads_Init(void) { +void Gamepads_PreInit(void) { } -} +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/Window_MacClassic.c b/src/Window_MacClassic.c index 43a62cdc7..9fb0bdf16 100644 --- a/src/Window_MacClassic.c +++ b/src/Window_MacClassic.c @@ -386,9 +386,9 @@ void Window_ProcessEvents(float delta) { } } -void Gamepads_Init(void) { +void Gamepads_PreInit(void) { } -} +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/Window_N64.c b/src/Window_N64.c index 5e848a3a4..e48cec5ed 100644 --- a/src/Window_N64.c +++ b/src/Window_N64.c @@ -120,9 +120,12 @@ static const BindMapping defaults_n64[BIND_COUNT] = { [BIND_SET_SPAWN] = { CCPAD_START }, }; +void Gamepads_PreInit(void) { + joypad_init(); +} + void Gamepads_Init(void) { Input.Sources |= INPUT_SOURCE_GAMEPAD; - joypad_init(); } static void HandleButtons(int port, joypad_buttons_t btns) { diff --git a/src/Window_OS2.c b/src/Window_OS2.c index dd5ee7a25..f57905e39 100644 --- a/src/Window_OS2.c +++ b/src/Window_OS2.c @@ -604,6 +604,8 @@ void Window_DisableRawMouse(void) { DefaultDisableRawMouse(); } +void Gamepads_PreInit(void) { } + void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/Window_SDL2.c b/src/Window_SDL2.c index cbf9d6f03..5ae44d130 100644 --- a/src/Window_SDL2.c +++ b/src/Window_SDL2.c @@ -473,7 +473,9 @@ void Window_DisableRawMouse(void) { #include "ExtMath.h" static SDL_GameController* controllers[INPUT_MAX_GAMEPADS]; -static void LoadControllers(void) { +void Gamepads_PreInit(void) { } + +void Gamepads_Init(void) { for (int i = 0, port = 0; i < SDL_NumJoysticks() && port < INPUT_MAX_GAMEPADS; i++) { if (!SDL_IsGameController(i)) continue; @@ -484,10 +486,6 @@ static void LoadControllers(void) { } } -void Gamepads_Init(void) { - LoadControllers(); -} - static void ProcessGamepadButtons(int port, SDL_GameController* gp) { Gamepad_SetButton(port, CCPAD_1, SDL_GameControllerGetButton(gp, SDL_CONTROLLER_BUTTON_A)); Gamepad_SetButton(port, CCPAD_2, SDL_GameControllerGetButton(gp, SDL_CONTROLLER_BUTTON_B)); diff --git a/src/Window_SDL3.c b/src/Window_SDL3.c index d33004a12..da5a98973 100644 --- a/src/Window_SDL3.c +++ b/src/Window_SDL3.c @@ -502,7 +502,9 @@ void Window_DisableRawMouse(void) { #include "ExtMath.h" static SDL_Gamepad* controllers[INPUT_MAX_GAMEPADS]; -static void LoadControllers(void) { +void Gamepads_PreInit(void) { } + +void Gamepads_Init(void) { int count = 0; SDL_JoystickID* joysticks = SDL_GetGamepads(&count); @@ -514,10 +516,6 @@ static void LoadControllers(void) { SDL_free(joysticks); } -void Gamepads_Init(void) { - LoadControllers(); -} - static void ProcessGamepadButtons(int port, SDL_Gamepad* gp) { Gamepad_SetButton(port, CCPAD_1, SDL_GetGamepadButton(gp, SDL_GAMEPAD_BUTTON_SOUTH)); Gamepad_SetButton(port, CCPAD_2, SDL_GetGamepadButton(gp, SDL_GAMEPAD_BUTTON_EAST)); diff --git a/src/Window_Terminal.c b/src/Window_Terminal.c index 1ede3c179..9919d008f 100644 --- a/src/Window_Terminal.c +++ b/src/Window_Terminal.c @@ -490,9 +490,9 @@ void Window_ProcessEvents(float delta) { ProcessConsoleEvents(delta); } -void Gamepads_Init(void) { +void Gamepads_PreInit(void) { } -} +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/Window_Win.c b/src/Window_Win.c index bb834eae7..6b520f745 100644 --- a/src/Window_Win.c +++ b/src/Window_Win.c @@ -602,9 +602,9 @@ void Window_ProcessEvents(float delta) { } } -void Gamepads_Init(void) { +void Gamepads_PreInit(void) { } -} +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/Window_WinCE.c b/src/Window_WinCE.c index f853744a2..ace2b31f2 100644 --- a/src/Window_WinCE.c +++ b/src/Window_WinCE.c @@ -550,9 +550,9 @@ void Window_ProcessEvents(float delta) { } } -void Gamepads_Init(void) { +void Gamepads_PreInit(void) { } -} +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/Window_X11.c b/src/Window_X11.c index 61726521a..6cdb4eda5 100644 --- a/src/Window_X11.c +++ b/src/Window_X11.c @@ -851,9 +851,9 @@ void Window_ProcessEvents(float delta) { } } -void Gamepads_Init(void) { +void Gamepads_PreInit(void) { } -} +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/Window_cocoa.m b/src/Window_cocoa.m index 3ce19870b..9168088d2 100644 --- a/src/Window_cocoa.m +++ b/src/Window_cocoa.m @@ -606,9 +606,9 @@ void Window_ProcessEvents(float delta) { } } -void Gamepads_Init(void) { +void Gamepads_PreInit(void) { } -} +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/Window_ios.m b/src/Window_ios.m index a89ab036b..580bcdd40 100644 --- a/src/Window_ios.m +++ b/src/Window_ios.m @@ -333,9 +333,9 @@ void Window_ProcessEvents(float delta) { } while (res == kCFRunLoopRunHandledSource); } -void Gamepads_Init(void) { +void Gamepads_PreInit(void) { } -} +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/amiga/Window_Amiga.c b/src/amiga/Window_Amiga.c index 38a7806ba..3843530e3 100644 --- a/src/amiga/Window_Amiga.c +++ b/src/amiga/Window_Amiga.c @@ -83,9 +83,10 @@ void Window_RequestClose(void) { void Window_ProcessEvents(float delta) { } -void Gamepads_Init(void) { -} +void Gamepads_PreInit(void) { } + +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/android/Window_Android.c b/src/android/Window_Android.c index 8990d7cd8..5f6e3e211 100644 --- a/src/android/Window_Android.c +++ b/src/android/Window_Android.c @@ -361,9 +361,9 @@ void Window_ProcessEvents(float delta) { Java_ICall_Void(env, JAVA_processEvents, NULL); } -void Gamepads_Init(void) { +void Gamepads_PreInit(void) { } -} +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/atari_st/Window_Atari.c b/src/atari_st/Window_Atari.c index 1314f558e..00233162c 100644 --- a/src/atari_st/Window_Atari.c +++ b/src/atari_st/Window_Atari.c @@ -94,7 +94,9 @@ void Window_UpdateRawMouse(void) { } /*########################################################################################################################* *-------------------------------------------------------Gamepads----------------------------------------------------------* -*#########################################################################################################################*/ +*#########################################################################################################################*/ +void Gamepads_PreInit(void) { } + void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/dreamcast/Window_Dreamcast.c b/src/dreamcast/Window_Dreamcast.c index e5822ebf5..a64668171 100644 --- a/src/dreamcast/Window_Dreamcast.c +++ b/src/dreamcast/Window_Dreamcast.c @@ -245,6 +245,8 @@ static const BindMapping defaults_dc[BIND_COUNT] = { [BIND_SCREENSHOT] = { CCPAD_3 }, }; +void Gamepads_PreInit(void) { } + void Gamepads_Init(void) { Input.Sources |= INPUT_SOURCE_GAMEPAD; } diff --git a/src/gba/Window_GBA.c b/src/gba/Window_GBA.c index ca7df6f6a..44381f1d4 100644 --- a/src/gba/Window_GBA.c +++ b/src/gba/Window_GBA.c @@ -102,6 +102,8 @@ static const BindMapping pad_defaults[BIND_COUNT] = { [BIND_HOTBAR_RIGHT] = { CCPAD_L, CCPAD_RIGHT } }; +void Gamepads_PreInit(void) { } + void Gamepads_Init(void) { Input.Sources |= INPUT_SOURCE_GAMEPAD; } diff --git a/src/gcwii/Platform_Gamecube.c b/src/gcwii/Platform_Gamecube.c index d69021905..666e73dfd 100644 --- a/src/gcwii/Platform_Gamecube.c +++ b/src/gcwii/Platform_Gamecube.c @@ -101,7 +101,7 @@ static void InitSockets(void) { if (ret >= 0) { Platform_Log3("Network ip: %c, gw: %c, mask %c", localip, gateway, netmask); } else { - Platform_Log1("Network setup failed: %i", &ret); + Logger_SimpleWarn(ret, "setting up network"); net_supported = false; } } diff --git a/src/gcwii/Platform_Wii.c b/src/gcwii/Platform_Wii.c index 3b0979512..fe41c591a 100644 --- a/src/gcwii/Platform_Wii.c +++ b/src/gcwii/Platform_Wii.c @@ -97,7 +97,7 @@ cc_result Socket_GetLastError(cc_socket s) { static void InitSockets(void) { int ret = net_init(); - Platform_Log1("Network setup result: %i", &ret); + if (ret) Logger_SimpleWarn(ret, "setting up network"); } diff --git a/src/gcwii/Window_GCWii.c b/src/gcwii/Window_GCWii.c index fd9eb5f95..9f0c07409 100644 --- a/src/gcwii/Window_GCWii.c +++ b/src/gcwii/Window_GCWii.c @@ -11,6 +11,7 @@ #include "../Graphics.h" #include "../Options.h" #include "../VirtualKeyboard.h" +#include "../VirtualDialog.h" #include #if defined HW_RVL @@ -62,16 +63,16 @@ void Window_PreInit(void) { SYS_SetPowerCallback(OnPowerOff); #endif InitVideo(); -} -void Window_Init(void) { DisplayInfo.Width = cur_mode->fbWidth; DisplayInfo.Height = cur_mode->xfbHeight; DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - - Window_Main.Width = cur_mode->fbWidth; - Window_Main.Height = cur_mode->xfbHeight; +} + +void Window_Init(void) { + Window_Main.Width = DisplayInfo.Width; + Window_Main.Height = DisplayInfo.Height; Window_Main.Focused = true; Window_Main.Exists = true; @@ -91,7 +92,6 @@ void Window_Init(void) { void Window_Free(void) { } void Window_Create2D(int width, int height) { - needsFBUpdate = true; Window_Main.Is3D = false; } @@ -358,9 +358,7 @@ void Window_DisableRawMouse(void) { Input.RawMode = false; } /*########################################################################################################################* *-------------------------------------------------------Gamepads----------------------------------------------------------* *#########################################################################################################################*/ -void Gamepads_Init(void) { - Input.Sources |= INPUT_SOURCE_GAMEPAD; - +void Gamepads_PreInit(void) { #if defined HW_RVL WPAD_Init(); for (int i = 0; i < 4; i++) @@ -369,6 +367,10 @@ void Gamepads_Init(void) { PAD_Init(); } +void Gamepads_Init(void) { + Input.Sources |= INPUT_SOURCE_GAMEPAD; +} + #if defined HW_RVL static const BindMapping default_nunchuck[BIND_COUNT] = { [BIND_FORWARD] = { CCPAD_CUP, 0 }, @@ -522,6 +524,8 @@ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; + + needsFBUpdate = true; } // TODO: Get rid of this complexity and use the 3D API instead.. @@ -608,11 +612,8 @@ int Window_IsObscured(void) { return 0; } void Window_Show(void) { } void Window_SetSize(int width, int height) { } - void Window_ShowDialog(const char* title, const char* msg) { - /* TODO implement */ - Platform_LogConst(title); - Platform_LogConst(msg); + VirtualDialog_Show(title, msg); } cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) { diff --git a/src/main_impl.h b/src/main_impl.h index e1fae6896..b18301f26 100644 --- a/src/main_impl.h +++ b/src/main_impl.h @@ -126,6 +126,7 @@ static void SetupProgram(int argc, char** argv) { CrashHandler_Install(); Logger_Hook(); Window_PreInit(); + Gamepads_PreInit(); Platform_Init(); res = Platform_SetDefaultCurrentDirectory(argc, argv); diff --git a/src/msdos/Window_MSDOS.c b/src/msdos/Window_MSDOS.c index 013f0a05c..752a720c9 100644 --- a/src/msdos/Window_MSDOS.c +++ b/src/msdos/Window_MSDOS.c @@ -255,9 +255,9 @@ void Window_ProcessEvents(float delta) { Keyboard_UpdateState(delta); } -void Gamepads_Init(void) { +void Gamepads_PreInit(void) { } -} +void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/nds/Window_NDS.c b/src/nds/Window_NDS.c index 662692249..37379467a 100644 --- a/src/nds/Window_NDS.c +++ b/src/nds/Window_NDS.c @@ -170,14 +170,14 @@ void Window_PreInit(void) { Window_Main.Is3D = 210; // So SetupVideo still runs SetupVideo(false); setBrightness(2, 0); -} -void Window_Init(void) { DisplayInfo.Width = SCREEN_WIDTH; DisplayInfo.Height = SCREEN_HEIGHT; DisplayInfo.ScaleX = 0.5f; DisplayInfo.ScaleY = 0.5f; - +} + +void Window_Init(void) { Window_Main.Width = DisplayInfo.Width; Window_Main.Height = DisplayInfo.Height; Window_Main.Focused = true; @@ -274,6 +274,8 @@ static const BindMapping defaults_nds[BIND_COUNT] = { [BIND_HOTBAR_LEFT] = { CCPAD_2, CCPAD_LEFT }, [BIND_HOTBAR_RIGHT] = { CCPAD_2, CCPAD_RIGHT } }; + +void Gamepads_PreInit(void) { } void Gamepads_Init(void) { Input.Sources |= INPUT_SOURCE_GAMEPAD; diff --git a/src/ps1/Window_PS1.c b/src/ps1/Window_PS1.c index ff3f50226..13a8368d8 100644 --- a/src/ps1/Window_PS1.c +++ b/src/ps1/Window_PS1.c @@ -162,15 +162,17 @@ static const BindMapping pad_defaults[BIND_COUNT] = { static char pad_buff[2][34]; -void Gamepads_Init(void) { - Input.Sources |= INPUT_SOURCE_GAMEPAD; - +void Gamepads_PreInit(void) { // http://lameguy64.net/tutorials/pstutorials/chapter1/4-controllers.html InitPAD(&pad_buff[0][0], 34, &pad_buff[1][0], 34); pad_buff[0][0] = pad_buff[0][1] = 0xff; pad_buff[1][0] = pad_buff[1][1] = 0xff; StartPAD(); ChangeClearPAD(0); +} + +void Gamepads_Init(void) { + Input.Sources |= INPUT_SOURCE_GAMEPAD; Input_DisplayNames[CCPAD_1] = "CIRCLE"; Input_DisplayNames[CCPAD_2] = "CROSS"; diff --git a/src/ps2/Window_PS2.c b/src/ps2/Window_PS2.c index 207e93312..5fe513635 100644 --- a/src/ps2/Window_PS2.c +++ b/src/ps2/Window_PS2.c @@ -252,12 +252,14 @@ static const BindMapping defaults_ps2[BIND_COUNT] = { static char padBuf0[256] __attribute__((aligned(64))); static char padBuf1[256] __attribute__((aligned(64))); -void Gamepads_Init(void) { - Input.Sources |= INPUT_SOURCE_GAMEPAD; - +void Gamepads_PreInit(void) { padInit(0); padPortOpen(0, 0, padBuf0); padPortOpen(1, 0, padBuf1); +} + +void Gamepads_Init(void) { + Input.Sources |= INPUT_SOURCE_GAMEPAD; Input_DisplayNames[CCPAD_1] = "CIRCLE"; Input_DisplayNames[CCPAD_2] = "CROSS"; diff --git a/src/ps3/Window_PS3.c b/src/ps3/Window_PS3.c index cab179107..1856541e9 100644 --- a/src/ps3/Window_PS3.c +++ b/src/ps3/Window_PS3.c @@ -296,9 +296,12 @@ static padInfo pad_info; static padData pad_data[MAX_PORT_NUM]; static cc_bool circle_main; +void Gamepads_PreInit(void) { + ioPadInit(MAX_PORT_NUM); +} + void Gamepads_Init(void) { Input.Sources |= INPUT_SOURCE_GAMEPAD; - ioPadInit(MAX_PORT_NUM); int ret = 0; sysUtilGetSystemParamInt(SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN, &ret); diff --git a/src/ps4/Window_PS4.c b/src/ps4/Window_PS4.c index ea91398e8..3ff855cf4 100644 --- a/src/ps4/Window_PS4.c +++ b/src/ps4/Window_PS4.c @@ -88,6 +88,8 @@ void Window_DisableRawMouse(void) { Input.RawMode = false; } /*########################################################################################################################* *-------------------------------------------------------Gamepads----------------------------------------------------------* *#########################################################################################################################*/ +void Gamepads_PreInit(void) { } + void Gamepads_Init(void) { Input.Sources |= INPUT_SOURCE_GAMEPAD; } diff --git a/src/psp/Window_PSP.c b/src/psp/Window_PSP.c index 001a9cbc9..b157c3346 100644 --- a/src/psp/Window_PSP.c +++ b/src/psp/Window_PSP.c @@ -103,11 +103,13 @@ static const BindMapping defaults_psp[BIND_COUNT] = { [BIND_HOTBAR_RIGHT] = { CCPAD_ZR } }; -void Gamepads_Init(void) { - Input.Sources |= INPUT_SOURCE_GAMEPAD; - +void Gamepads_PreInit(void) { sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); +} + +void Gamepads_Init(void) { + Input.Sources |= INPUT_SOURCE_GAMEPAD; Input_DisplayNames[CCPAD_1] = "CIRCLE"; Input_DisplayNames[CCPAD_2] = "CROSS"; diff --git a/src/psvita/Window_PSVita.c b/src/psvita/Window_PSVita.c index 3543bfb9b..d8f1d917b 100644 --- a/src/psvita/Window_PSVita.c +++ b/src/psvita/Window_PSVita.c @@ -159,11 +159,13 @@ static const BindMapping defaults_vita[BIND_COUNT] = { }; static cc_bool circle_main; +void Gamepads_PreInit(void) { + sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG); +} + void Gamepads_Init(void) { Input.Sources |= INPUT_SOURCE_GAMEPAD; - sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG); - SceAppUtilInitParam init_param = { 0 }; SceAppUtilBootParam boot_param = { 0 }; sceAppUtilInit(&init_param, &boot_param); diff --git a/src/saturn/Window_Saturn.c b/src/saturn/Window_Saturn.c index 0ab0d61c4..62563e094 100644 --- a/src/saturn/Window_Saturn.c +++ b/src/saturn/Window_Saturn.c @@ -112,9 +112,12 @@ static const BindMapping saturn_defaults[BIND_COUNT] = { [BIND_DELETE_BLOCK] = { CCPAD_R }, }; +void Gamepads_PreInit(void) { + smpc_peripheral_init(); +} + void Gamepads_Init(void) { Input.Sources |= INPUT_SOURCE_GAMEPAD; - smpc_peripheral_init(); Input_DisplayNames[CCPAD_1] = "A"; Input_DisplayNames[CCPAD_2] = "B"; diff --git a/src/switch/Window_Switch.c b/src/switch/Window_Switch.c index bf22d0c5b..29a746677 100644 --- a/src/switch/Window_Switch.c +++ b/src/switch/Window_Switch.c @@ -167,6 +167,8 @@ static const BindMapping defaults_switch[BIND_COUNT] = { [BIND_HOTBAR_RIGHT] = { CCPAD_ZR } }; +void Gamepads_PreInit(void) { } + void Gamepads_Init(void) { Input.Sources |= INPUT_SOURCE_GAMEPAD; } diff --git a/src/symbian/Window_Symbian.cpp b/src/symbian/Window_Symbian.cpp index 6a47daa97..28e80c840 100644 --- a/src/symbian/Window_Symbian.cpp +++ b/src/symbian/Window_Symbian.cpp @@ -905,6 +905,8 @@ void Window_DisableRawMouse(void) { Input.RawMode = false; } +void Gamepads_PreInit(void) { } + void Gamepads_Init(void) { } void Gamepads_Process(float delta) { } diff --git a/src/webclient/Window_Web.c b/src/webclient/Window_Web.c index 40773a361..3d2a69391 100644 --- a/src/webclient/Window_Web.c +++ b/src/webclient/Window_Web.c @@ -568,6 +568,8 @@ static void Cursor_DoSetVisible(cc_bool visible) { /*########################################################################################################################* *-------------------------------------------------------Gamepads----------------------------------------------------------* *#########################################################################################################################*/ +void Gamepads_PreInit(void) { } + void Gamepads_Init(void) { /* Devices can't be detected until first time a button is pressed */ } diff --git a/src/wiiu/Window_WiiU.c b/src/wiiu/Window_WiiU.c index f4f461ad7..d31895173 100644 --- a/src/wiiu/Window_WiiU.c +++ b/src/wiiu/Window_WiiU.c @@ -156,13 +156,15 @@ void Window_DisableRawMouse(void) { Input.RawMode = false; } static VPADStatus vpadStatus; static KPADStatus kpads[4]; -void Gamepads_Init(void) { - Input.Sources |= INPUT_SOURCE_GAMEPAD; - +void Gamepads_PreInit(void) { KPADInit(); VPADInit(); } +void Gamepads_Init(void) { + Input.Sources |= INPUT_SOURCE_GAMEPAD; +} + static void ProcessKPadButtons(int port, int mods) { Gamepad_SetButton(port, CCPAD_L, mods & WPAD_BUTTON_1); Gamepad_SetButton(port, CCPAD_R, mods & WPAD_BUTTON_2); diff --git a/src/xbox/Window_Xbox.c b/src/xbox/Window_Xbox.c index 7b01263b4..1892efb5b 100644 --- a/src/xbox/Window_Xbox.c +++ b/src/xbox/Window_Xbox.c @@ -146,9 +146,7 @@ static void OnDeviceChanged(xid_dev_t *xid_dev__, int status__) { xid_ctrl = NULL; } -void Gamepads_Init(void) { - Input.Sources |= INPUT_SOURCE_GAMEPAD; - +void Gamepads_PreInit(void) { #ifndef CC_BUILD_CXBX usbh_core_init(); usbh_xid_init(); @@ -158,6 +156,10 @@ void Gamepads_Init(void) { #endif } +void Gamepads_Init(void) { + Input.Sources |= INPUT_SOURCE_GAMEPAD; +} + // https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_gamepad // NOTE: Analog buttons use dedicated field rather than being part of dButtons #define XINPUT_GAMEPAD_DPAD_UP 0x0001 diff --git a/src/xbox360/Window_Xbox360.c b/src/xbox360/Window_Xbox360.c index 9dd7fbf3b..467335f22 100644 --- a/src/xbox360/Window_Xbox360.c +++ b/src/xbox360/Window_Xbox360.c @@ -104,12 +104,14 @@ static const BindMapping defaults_xbox360[BIND_COUNT] = { [BIND_HOTBAR_RIGHT] = { CCPAD_ZR } }; -void Gamepads_Init(void) { - Input.Sources |= INPUT_SOURCE_GAMEPAD; - +void Gamepads_PreInit(void) { usb_init(); usb_do_poll(); } + +void Gamepads_Init(void) { + Input.Sources |= INPUT_SOURCE_GAMEPAD; +} /* struct controller_data_s {