Skip to content

Commit

Permalink
Centralizing more code in the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vitor251093 committed Jun 24, 2024
1 parent d43a6c2 commit 0d49c27
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 37 deletions.
17 changes: 15 additions & 2 deletions src/KHDays_Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ using namespace melonDS;

extern int videoRenderer;

bool KHDaysPlugin::isDebugEnabled = false;

int KHDaysPlugin::GameScene = -1;
int KHDaysPlugin::priorGameScene = -1;
int KHDaysPlugin::HUDState = 0;
Expand Down Expand Up @@ -159,9 +161,9 @@ void KHDaysPlugin::hudToggle(melonDS::NDS* nds)
hudRefresh(nds);
}

const char* KHDaysPlugin::getNameByGameScene(int newGameScene)
const char* KHDaysPlugin::getGameSceneName()
{
switch (newGameScene) {
switch (GameScene) {
case gameScene_Intro: return "Game scene: Intro";
case gameScene_MainMenu: return "Game scene: Main menu";
case gameScene_IntroLoadMenu: return "Game scene: Intro load menu";
Expand Down Expand Up @@ -624,6 +626,17 @@ bool KHDaysPlugin::setGameScene(melonDS::NDS* nds, int newGameScene)
return updated;
}

bool KHDaysPlugin::refreshGameScene(melonDS::NDS* nds)
{
int newGameScene = detectGameScene(nds);

if (isDebugEnabled) {
debugLogs(nds, newGameScene);
}

return setGameScene(nds, newGameScene);
}

void KHDaysPlugin::debugLogs(melonDS::NDS* nds, int gameScene)
{
printf("Game scene: %d\n", gameScene);
Expand Down
10 changes: 7 additions & 3 deletions src/KHDays_Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ namespace melonDS
class KHDaysPlugin
{
public:
static bool isDebugEnabled;

static u32 applyCommandMenuInputMask(melonDS::NDS* nds, u32 InputMask, u32 CmdMenuInputMask, u32 PriorCmdMenuInputMask);
static void hudToggle(melonDS::NDS* nds);
static const char* getNameByGameScene(int newGameScene);
static const char* getGameSceneName();
static bool shouldSkipFrame(melonDS::NDS* nds);
static int detectGameScene(melonDS::NDS* nds);
static void setAspectRatio(melonDS::NDS* nds, float aspectRatio);
static bool setGameScene(melonDS::NDS* nds, int newGameScene);
static bool refreshGameScene(melonDS::NDS* nds);
static void debugLogs(melonDS::NDS* nds, int gameScene);
private:
static int GameScene;
Expand All @@ -31,6 +32,9 @@ class KHDaysPlugin

static bool _hasVisible3DOnBottomScreen;

static int detectGameScene(melonDS::NDS* nds);
static bool setGameScene(melonDS::NDS* nds, int newGameScene);

static bool isBufferBlack(unsigned int* buffer);
static bool isTopScreen2DTextureBlack(melonDS::NDS* nds);
static bool isBottomScreen2DTextureBlack(melonDS::NDS* nds);
Expand Down
17 changes: 15 additions & 2 deletions src/KHReCoded_Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ using namespace melonDS;

extern int videoRenderer;

bool KHReCodedPlugin::isDebugEnabled = false;

int KHReCodedPlugin::GameScene = -1;
int KHReCodedPlugin::priorGameScene = -1;
bool KHReCodedPlugin::ShowMap = true;
Expand Down Expand Up @@ -114,9 +116,9 @@ void KHReCodedPlugin::hudToggle(melonDS::NDS* nds)
hudRefresh(nds);
}

const char* KHReCodedPlugin::getNameByGameScene(int newGameScene)
const char* KHReCodedPlugin::getGameSceneName()
{
switch (newGameScene) {
switch (GameScene) {
case gameScene_Intro: return "Game scene: Intro";
case gameScene_MainMenu: return "Game scene: Main menu";
case gameScene_IntroLoadMenu: return "Game scene: Intro load menu";
Expand Down Expand Up @@ -480,6 +482,17 @@ bool KHReCodedPlugin::setGameScene(melonDS::NDS* nds, int newGameScene)
return updated;
}

bool KHReCodedPlugin::refreshGameScene(melonDS::NDS* nds)
{
int newGameScene = detectGameScene(nds);

if (isDebugEnabled) {
debugLogs(nds, newGameScene);
}

return setGameScene(nds, newGameScene);
}

void KHReCodedPlugin::debugLogs(melonDS::NDS* nds, int gameScene)
{
printf("Game scene: %d\n", gameScene);
Expand Down
10 changes: 7 additions & 3 deletions src/KHReCoded_Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ namespace melonDS
class KHReCodedPlugin
{
public:
static bool isDebugEnabled;

static u32 applyCommandMenuInputMask(melonDS::NDS* nds, u32 InputMask, u32 CmdMenuInputMask, u32 PriorCmdMenuInputMask);
static void hudToggle(melonDS::NDS* nds);
static const char* getNameByGameScene(int newGameScene);
static const char* getGameSceneName();
static bool shouldSkipFrame(melonDS::NDS* nds);
static int detectGameScene(melonDS::NDS* nds);
static void setAspectRatio(melonDS::NDS* nds, float aspectRatio);
static bool setGameScene(melonDS::NDS* nds, int newGameScene);
static bool refreshGameScene(melonDS::NDS* nds);
static void debugLogs(melonDS::NDS* nds, int gameScene);
private:
static int GameScene;
Expand All @@ -26,6 +27,9 @@ class KHReCodedPlugin
static bool _had3DOnTopScreen;
static bool _had3DOnBottomScreen;

static int detectGameScene(melonDS::NDS* nds);
static bool setGameScene(melonDS::NDS* nds, int newGameScene);

static bool isBufferBlack(unsigned int* buffer);
static bool isTopScreen2DTextureBlack(melonDS::NDS* nds);
static bool isBottomScreen2DTextureBlack(melonDS::NDS* nds);
Expand Down
33 changes: 17 additions & 16 deletions src/KH_Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ namespace melonDS
class KHPlugin
{
public:
static bool isDebugEnabled() {
if (CartValidator::isDays()) {
return KHDaysPlugin::isDebugEnabled;
}
if (CartValidator::isRecoded()) {
return KHReCodedPlugin::isDebugEnabled;
}
return false;
}

static u32 applyCommandMenuInputMask(melonDS::NDS* nds, u32 InputMask, u32 CmdMenuInputMask, u32 PriorCmdMenuInputMask) {
if (CartValidator::isDays()) {
return KHDaysPlugin::applyCommandMenuInputMask(nds, InputMask, CmdMenuInputMask, PriorCmdMenuInputMask);
Expand All @@ -32,12 +42,12 @@ class KHPlugin
return KHReCodedPlugin::hudToggle(nds);
}
}
static const char* getNameByGameScene(int newGameScene) {
static const char* getGameSceneName() {
if (CartValidator::isDays()) {
return KHDaysPlugin::getNameByGameScene(newGameScene);
return KHDaysPlugin::getGameSceneName();
}
if (CartValidator::isRecoded()) {
return KHReCodedPlugin::getNameByGameScene(newGameScene);
return KHReCodedPlugin::getGameSceneName();
}
return "";
}
Expand All @@ -50,14 +60,14 @@ class KHPlugin
}
return false;
}
static int detectGameScene(melonDS::NDS* nds) {
static bool refreshGameScene(melonDS::NDS* nds) {
if (CartValidator::isDays()) {
return KHDaysPlugin::detectGameScene(nds);
return KHDaysPlugin::refreshGameScene(nds);
}
if (CartValidator::isRecoded()) {
return KHReCodedPlugin::detectGameScene(nds);
return KHReCodedPlugin::refreshGameScene(nds);
}
return -1;
return false;
}
static void setAspectRatio(melonDS::NDS* nds, float aspectRatio) {
if (CartValidator::isDays()) {
Expand All @@ -67,15 +77,6 @@ class KHPlugin
return KHReCodedPlugin::setAspectRatio(nds, aspectRatio);
}
}
static bool setGameScene(melonDS::NDS* nds, int newGameScene) {
if (CartValidator::isDays()) {
return KHDaysPlugin::setGameScene(nds, newGameScene);
}
if (CartValidator::isRecoded()) {
return KHReCodedPlugin::setGameScene(nds, newGameScene);
}
return false;
}
static void debugLogs(melonDS::NDS* nds, int gameScene) {
if (CartValidator::isDays()) {
KHDaysPlugin::debugLogs(nds, gameScene);
Expand Down
14 changes: 3 additions & 11 deletions src/frontend/qt_sdl/EmuThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,20 +695,12 @@ void EmuThread::run()

void EmuThread::refreshGameScene()
{
bool enableDebug = false;

melonDS::NDS& nds = static_cast<melonDS::NDS&>(*NDS);

int newGameScene = KHPlugin::detectGameScene(&nds);

if (enableDebug) {
KHPlugin::debugLogs(&nds, newGameScene);
}

bool updated = KHPlugin::setGameScene(&nds, newGameScene);
if (updated && enableDebug)
bool updated = KHPlugin::refreshGameScene(&nds);
if (updated && KHPlugin::isDebugEnabled())
{
mainWindow->osdAddMessage(0, KHPlugin::getNameByGameScene(newGameScene));
mainWindow->osdAddMessage(0, KHPlugin::getGameSceneName());
}

float aspectTop = (Config::WindowWidth * 1.f) / Config::WindowHeight;
Expand Down

0 comments on commit 0d49c27

Please sign in to comment.