From 8b7b29a233ac4eb3468d4af9c7b990d0c0c253a8 Mon Sep 17 00:00:00 2001 From: emu_kidid Date: Tue, 7 Nov 2023 16:36:40 +1030 Subject: [PATCH] - Add deflicker option (issue #17) --- Gamecube/GamecubeMain.cpp | 3 +++ Gamecube/libgui/GraphicsGX.cpp | 8 +++++++ Gamecube/libgui/GraphicsGX.h | 1 + Gamecube/menu/MainFrame.cpp | 1 + Gamecube/menu/SettingsFrame.cpp | 40 ++++++++++++++++++++++++++------- Gamecube/wiiSXconfig.h | 7 ++++++ 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/Gamecube/GamecubeMain.cpp b/Gamecube/GamecubeMain.cpp index b9e05207..6b574489 100644 --- a/Gamecube/GamecubeMain.cpp +++ b/Gamecube/GamecubeMain.cpp @@ -90,6 +90,7 @@ char frameSkip; extern char audioEnabled; char volume; char reverb; +char deflicker; char showFPSonScreen; char printToScreen; char menuActive; @@ -141,6 +142,7 @@ static struct { { { "Audio", &audioEnabled, AUDIO_DISABLE, AUDIO_ENABLE }, { "Volume", &volume, VOLUME_LOUDEST, VOLUME_LOW }, { "Reverb", &reverb, REVERB_DISABLE, REVERB_ENABLE }, + { "Deflicker", &deflicker, DEFLICKER_DISABLE, DEFLICKER_ENABLE }, { "FPS", &showFPSonScreen, FPS_HIDE, FPS_SHOW }, // { "Debug", &printToScreen, DEBUG_HIDE, DEBUG_SHOW }, { "ScreenMode", &screenMode, SCREENMODE_4x3, SCREENMODE_16x9_PILLARBOX }, @@ -180,6 +182,7 @@ void loadSettings(int argc, char *argv[]) audioEnabled = 1; // Audio volume = VOLUME_MEDIUM; reverb = REVERB_ENABLE; + deflicker = DEFLICKER_ENABLE; #ifdef RELEASE showFPSonScreen = 0; // Don't show FPS on Screen #else diff --git a/Gamecube/libgui/GraphicsGX.cpp b/Gamecube/libgui/GraphicsGX.cpp index 948f0b20..14281306 100644 --- a/Gamecube/libgui/GraphicsGX.cpp +++ b/Gamecube/libgui/GraphicsGX.cpp @@ -20,6 +20,7 @@ #include #include "GraphicsGX.h" +#include "../wiiSXconfig.h" extern "C" unsigned int usleep(unsigned int us); void video_mode_init(GXRModeObj *rmode, u32 *fb1, u32 *fb2, u32 *fb3); @@ -502,4 +503,11 @@ float Graphics::getCurrentTransparency(int index) return val; } +void Graphics::setInGameVMode() { + // Set deflicker + GX_SetCopyFilter(vmode->aa,vmode->sample_pattern,deflicker ? GX_TRUE : GX_FALSE,vmode->vfilter); + + // TODO: eventually change video mode for sync here too +} + } //namespace menu diff --git a/Gamecube/libgui/GraphicsGX.h b/Gamecube/libgui/GraphicsGX.h index c9aaa145..a674a4d6 100644 --- a/Gamecube/libgui/GraphicsGX.h +++ b/Gamecube/libgui/GraphicsGX.h @@ -63,6 +63,7 @@ class Graphics void popTransparency(); void setTransparency(float f); float getTransparency(); + void setInGameVMode(); private: void applyCurrentColor(); diff --git a/Gamecube/menu/MainFrame.cpp b/Gamecube/menu/MainFrame.cpp index 6f72f875..45469e5d 100644 --- a/Gamecube/menu/MainFrame.cpp +++ b/Gamecube/menu/MainFrame.cpp @@ -246,6 +246,7 @@ void Func_PlayGame() #ifdef DEBUGON _break(); #endif + menu::Gui::getInstance().gfx->setInGameVMode(); go(); #ifdef DEBUGON _break(); diff --git a/Gamecube/menu/SettingsFrame.cpp b/Gamecube/menu/SettingsFrame.cpp index 6048cd31..d2e50e7a 100644 --- a/Gamecube/menu/SettingsFrame.cpp +++ b/Gamecube/menu/SettingsFrame.cpp @@ -73,6 +73,8 @@ void Func_ScreenForce16_9(); void Func_DitheringNone(); void Func_DitheringDefault(); void Func_DitheringAlways(); +void Func_DeflickerOff(); +void Func_DeflickerOn(); void Func_ConfigureInput(); void Func_ConfigureButtons(); @@ -118,12 +120,12 @@ void resumeAudio(void); void resumeInput(void); } #define NUM_TAB_BUTTONS 5 -#define NUM_FRAME_TEXTBOXES 20 +#define NUM_FRAME_TEXTBOXES 21 #define TAB_Y_POS 30 #define TAB_Y_LABEL_PAD 28.0 #define TAB_Y_ENTRY_START 100 -#define TAB_Y_ENTRY_INC 70 -#define BTN_HEIGHT 56 +#define TAB_Y_ENTRY_INC 60 +#define BTN_HEIGHT 48 /* General Tab: @@ -139,6 +141,7 @@ Limit FPS: Auto; Off; xxx Frame Skip: On; Off Screen Mode: 4:3; 16:9 Dithering: None; Game Dependent; Always +Deflicker: On/Off Input Tab: Assign Controllers (assign player->pad) @@ -191,6 +194,8 @@ enum BUTTON_IDS { BTN_DITHER_NONE, BTN_DITHER_DEFAULT, BTN_DITHER_ALWAYS, + BTN_DEFLICKER_ON, + BTN_DEFLICKER_OFF, BTN_CONF_INPUT, BTN_CONF_BTN_MAP, @@ -256,6 +261,8 @@ struct LabelResources {BTN_DITHER_NONE, "None"}, {BTN_DITHER_DEFAULT, "Default"}, {BTN_DITHER_ALWAYS, "Always"}, + {BTN_DEFLICKER_ON, "On"}, + {BTN_DEFLICKER_OFF, "Off"}, {BTN_CONF_INPUT, "Assign"}, {BTN_CONF_BTN_MAP, "Map"}, @@ -307,6 +314,7 @@ enum LABEL_IDS { LBL_VIDEO_FRAMESKIP, LBL_VIDEO_SCREENMODE, LBL_VIDEO_DITHER, + LBL_VIDEO_DEFLICKER, // Input LBL_INPUT_CONF_INPUT, LBL_INPUT_CONT_TYPE, @@ -338,6 +346,7 @@ LabelResources RES_LBL[LABEL_GROUPS_END] = {LBL_VIDEO_FRAMESKIP, "Frame Skip"}, {LBL_VIDEO_SCREENMODE, "Screen Mode"}, {LBL_VIDEO_DITHER, "Dithering"}, + {LBL_VIDEO_DEFLICKER, "Deflicker"}, // Input {LBL_INPUT_CONF_INPUT, "Configure Input"}, {LBL_INPUT_CONT_TYPE, "PSX Controller Type"}, @@ -383,7 +392,7 @@ struct SettingsButtonInfo { NULL, BTN_A_SEL, 440.0, 70.0, BTN_DYNAREC, BTN_BIOS_NO, BTN_SD, BTN_HLE, Func_BiosSelectUSB, TAB_GENERAL, LBL_GENERAL_BIOS, BTN_USB }, // Bios: USB { NULL, BTN_A_SEL, 295.0, 75.0, BTN_HLE, BTN_EXEC_BIOS, BTN_BIOS_NO, BTN_BIOS_NO, Func_BootBiosYes, TAB_GENERAL, LBL_GENERAL_BOOT_BIOS, BTN_BIOS_YES }, // Boot Thru Bios: Yes { NULL, BTN_A_SEL, 380.0, 75.0, BTN_SD, BTN_EXEC_BIOS, BTN_BIOS_YES, BTN_BIOS_YES, Func_BootBiosNo, TAB_GENERAL, LBL_GENERAL_BOOT_BIOS, BTN_BIOS_NO }, // Boot Thru Bios: No - { NULL, BTN_A_NRM, 295.0, 130.0, BTN_BIOS_YES, BTN_SAVE_SETTING_USB, -1, -1, Func_ExecuteBios, TAB_GENERAL, LBL_GENERAL_EXEC_BIOS, BTN_EXEC_BIOS }, // Execute Bios + { NULL, BTN_A_NRM, 295.0, 130.0, BTN_BIOS_YES, BTN_SAVE_SETTING_SD, -1, -1, Func_ExecuteBios, TAB_GENERAL, LBL_GENERAL_EXEC_BIOS, BTN_EXEC_BIOS }, // Execute Bios { NULL, BTN_A_NRM, 295.0, 55.0, BTN_EXEC_BIOS, BTN_TAB_GENERAL, BTN_SAVE_SETTING_USB, BTN_SAVE_SETTING_USB, Func_SaveSettingsSD, TAB_GENERAL, LBL_GENERAL_SAVE, BTN_SAVE_SETTING_SD }, // Save Settings: SD { NULL, BTN_A_NRM, 360.0, 70.0, BTN_EXEC_BIOS, BTN_TAB_GENERAL, BTN_SAVE_SETTING_SD, BTN_SAVE_SETTING_SD, Func_SaveSettingsUSB, TAB_GENERAL, LBL_GENERAL_SAVE, BTN_SAVE_SETTING_USB }, // Save Settings: USB //Buttons for Video Tab @@ -396,9 +405,11 @@ struct SettingsButtonInfo { NULL, BTN_A_SEL, 230.0, 75.0, BTN_FSKIP_ON, BTN_DITHER_NONE, BTN_SM_F_16_9, BTN_SM_16_9, Func_ScreenMode4_3, TAB_VIDEO, LBL_VIDEO_SCREENMODE, BTN_SM_4_3 }, // ScreenMode: 4:3 { NULL, BTN_A_SEL, 325.0, 75.0, BTN_FSKIP_ON, BTN_DITHER_DEFAULT, BTN_SM_4_3, BTN_SM_F_16_9, Func_ScreenMode16_9, TAB_VIDEO, LBL_VIDEO_SCREENMODE, BTN_SM_16_9 }, // ScreenMode: 16:9 { NULL, BTN_A_SEL, 420.0, 155.0, BTN_FSKIP_OFF, BTN_DITHER_ALWAYS, BTN_SM_16_9, BTN_SM_4_3, Func_ScreenForce16_9, TAB_VIDEO, LBL_VIDEO_SCREENMODE, BTN_SM_F_16_9 }, // ScreenMode: Force 16:9 - { NULL, BTN_A_SEL, 230.0, 75.0, BTN_SM_4_3, BTN_TAB_VIDEO, BTN_DITHER_ALWAYS, BTN_DITHER_DEFAULT, Func_DitheringNone, TAB_VIDEO, LBL_VIDEO_DITHER, BTN_DITHER_NONE }, // Dithering: None - { NULL, BTN_A_SEL, 325.0, 110.0, BTN_SM_16_9, BTN_TAB_VIDEO, BTN_DITHER_NONE, BTN_DITHER_ALWAYS, Func_DitheringDefault, TAB_VIDEO, LBL_VIDEO_DITHER, BTN_DITHER_DEFAULT }, // Dithering: Game Dependent - { NULL, BTN_A_SEL, 455.0, 110.0, BTN_SM_F_16_9, BTN_TAB_VIDEO, BTN_DITHER_DEFAULT, BTN_DITHER_NONE, Func_DitheringAlways, TAB_VIDEO, LBL_VIDEO_DITHER, BTN_DITHER_ALWAYS }, // Dithering: Always + { NULL, BTN_A_SEL, 230.0, 75.0, BTN_SM_4_3, BTN_DEFLICKER_ON, BTN_DITHER_ALWAYS, BTN_DITHER_DEFAULT, Func_DitheringNone, TAB_VIDEO, LBL_VIDEO_DITHER, BTN_DITHER_NONE }, // Dithering: None + { NULL, BTN_A_SEL, 325.0, 110.0, BTN_SM_16_9, BTN_DEFLICKER_ON, BTN_DITHER_NONE, BTN_DITHER_ALWAYS, Func_DitheringDefault, TAB_VIDEO, LBL_VIDEO_DITHER, BTN_DITHER_DEFAULT }, // Dithering: Game Dependent + { NULL, BTN_A_SEL, 455.0, 110.0, BTN_SM_F_16_9, BTN_DEFLICKER_OFF, BTN_DITHER_DEFAULT, BTN_DITHER_NONE, Func_DitheringAlways, TAB_VIDEO, LBL_VIDEO_DITHER, BTN_DITHER_ALWAYS }, // Dithering: Always + { NULL, BTN_A_SEL, 325.0, 75.0, BTN_DITHER_DEFAULT, BTN_TAB_VIDEO, BTN_DEFLICKER_OFF, BTN_DEFLICKER_OFF, Func_DeflickerOn, TAB_VIDEO, LBL_VIDEO_DEFLICKER, BTN_DEFLICKER_ON }, // Deflicker: On + { NULL, BTN_A_SEL, 420.0, 75.0, BTN_DITHER_DEFAULT, BTN_TAB_VIDEO, BTN_DEFLICKER_ON, BTN_DEFLICKER_ON, Func_DeflickerOff, TAB_VIDEO, LBL_VIDEO_DEFLICKER, BTN_DEFLICKER_OFF }, // Deflicker: Off //Buttons for Input Tab { NULL, BTN_A_NRM, 285.0, 140.0, BTN_TAB_INPUT, BTN_PAD_STANDARD, BTN_CONF_BTN_MAP, BTN_CONF_BTN_MAP, Func_ConfigureInput, TAB_INPUT, LBL_INPUT_CONF_INPUT, BTN_CONF_INPUT }, // Configure Input Assignment { NULL, BTN_A_NRM, 435.0, 110.0, BTN_TAB_INPUT, BTN_PAD_STANDARD, BTN_CONF_INPUT, BTN_CONF_INPUT, Func_ConfigureButtons, TAB_INPUT, LBL_INPUT_CONF_INPUT, BTN_CONF_BTN_MAP }, // Configure Button Mappings @@ -446,6 +457,7 @@ struct SettingsTextBoxInfo { NULL, 190.0, TAB_VIDEO, LBL_VIDEO_FRAMESKIP }, // Frame Skip: On/Off { NULL, 130.0, TAB_VIDEO, LBL_VIDEO_SCREENMODE }, // ScreenMode: 4x3/16x9/Force16x9 { NULL, 130.0, TAB_VIDEO, LBL_VIDEO_DITHER }, // Dithering: None/Game Dependent/Always + { NULL, 190.0, TAB_VIDEO, LBL_VIDEO_DEFLICKER }, // Deflicker: On/Off //TextBoxes for Input Tab { NULL, 145.0, TAB_INPUT, LBL_INPUT_CONF_INPUT }, // blank. { NULL, 145.0, TAB_INPUT, LBL_INPUT_CONT_TYPE }, // PSX Controller Type: Analog/Digital/Gun @@ -634,7 +646,7 @@ void SettingsFrame::activateSubmenu(int submenu) { FRAME_BUTTONS[i].button->setVisible(true); FRAME_BUTTONS[i].button->setNextFocus(menu::Focus::DIRECTION_DOWN, GetButtonById(BTN_SHOW_FPS_ON)); - FRAME_BUTTONS[i].button->setNextFocus(menu::Focus::DIRECTION_UP, GetButtonById(BTN_DITHER_NONE)); + FRAME_BUTTONS[i].button->setNextFocus(menu::Focus::DIRECTION_UP, GetButtonById(BTN_DEFLICKER_ON)); FRAME_BUTTONS[i].button->setActive(true); } SetVisibleLabelsForTab(TAB_VIDEO); @@ -646,6 +658,7 @@ void SettingsFrame::activateSubmenu(int submenu) SelectBtnInGroup((frameSkip == FRAMESKIP_ENABLE) ? BTN_FSKIP_ON : BTN_FSKIP_OFF, LBL_VIDEO_FRAMESKIP); SelectBtnInGroup((screenMode == SCREENMODE_4x3) ? BTN_SM_4_3 : ((screenMode == SCREENMODE_16x9) ? BTN_SM_16_9 : BTN_SM_F_16_9), LBL_VIDEO_SCREENMODE); SelectBtnInGroup((useDithering == USEDITHER_NONE) ? BTN_DITHER_NONE : ((useDithering == USEDITHER_DEFAULT) ? BTN_DITHER_DEFAULT : BTN_DITHER_ALWAYS), LBL_VIDEO_DITHER); + SelectBtnInGroup((deflicker == DEFLICKER_DISABLE) ? BTN_DEFLICKER_OFF : BTN_DEFLICKER_ON, LBL_VIDEO_DEFLICKER); break; case SUBMENU_INPUT: setDefaultFocus(FRAME_BUTTONS[2].button); @@ -1099,6 +1112,17 @@ void Func_DitheringAlways() useDithering = USEDITHER_ALWAYS; } +void Func_DeflickerOff() +{ + SelectBtnInGroup(BTN_DEFLICKER_OFF, LBL_VIDEO_DEFLICKER); + deflicker = DEFLICKER_DISABLE; +} + +void Func_DeflickerOn() +{ + SelectBtnInGroup(BTN_DEFLICKER_ON, LBL_VIDEO_DEFLICKER); + deflicker = DEFLICKER_ENABLE; +} void Func_ConfigureInput() { diff --git a/Gamecube/wiiSXconfig.h b/Gamecube/wiiSXconfig.h index 50a62275..be2bd27c 100644 --- a/Gamecube/wiiSXconfig.h +++ b/Gamecube/wiiSXconfig.h @@ -39,6 +39,13 @@ enum ConfigReverb REVERB_ENABLE }; +extern char deflicker; +enum ConfigDeflicker +{ + DEFLICKER_DISABLE=0, + DEFLICKER_ENABLE +}; + extern char volume; enum iVolume {