mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-29 09:10:08 -06:00
Merge branch 'master' into no-more-context-mess
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QMenuBar>
|
||||
@ -57,9 +58,11 @@
|
||||
#include "EmuSettingsDialog.h"
|
||||
#include "InputConfig/InputConfigDialog.h"
|
||||
#include "VideoSettingsDialog.h"
|
||||
#include "CameraSettingsDialog.h"
|
||||
#include "AudioSettingsDialog.h"
|
||||
#include "FirmwareSettingsDialog.h"
|
||||
#include "PathSettingsDialog.h"
|
||||
#include "MPSettingsDialog.h"
|
||||
#include "WifiSettingsDialog.h"
|
||||
#include "InterfaceSettingsDialog.h"
|
||||
#include "ROMInfoDialog.h"
|
||||
@ -80,6 +83,7 @@
|
||||
#include "SPU.h"
|
||||
#include "Wifi.h"
|
||||
#include "Platform.h"
|
||||
#include "LocalMP.h"
|
||||
#include "Config.h"
|
||||
|
||||
#include "Savestate.h"
|
||||
@ -88,6 +92,7 @@
|
||||
|
||||
#include "ROMManager.h"
|
||||
#include "ArchiveUtil.h"
|
||||
#include "CameraManager.h"
|
||||
|
||||
// TODO: uniform variable spelling
|
||||
|
||||
@ -104,6 +109,7 @@ bool videoSettingsDirty;
|
||||
|
||||
SDL_AudioDeviceID audioDevice;
|
||||
int audioFreq;
|
||||
bool audioMuted;
|
||||
SDL_cond* audioSync;
|
||||
SDL_mutex* audioSyncLock;
|
||||
|
||||
@ -114,10 +120,13 @@ u32 micExtBufferWritePos;
|
||||
u32 micWavLength;
|
||||
s16* micWavBuffer;
|
||||
|
||||
CameraManager* camManager[2];
|
||||
bool camStarted[2];
|
||||
|
||||
const struct { int id; float ratio; const char* label; } aspectRatios[] =
|
||||
{
|
||||
{ 0, 1, "4:3 (native)" },
|
||||
{ 4, (16.f / 10) / (4.f / 3), "16:10 (3DS)"},
|
||||
{ 4, (5.f / 3) / (4.f / 3), "5:3 (3DS)"},
|
||||
{ 1, (16.f / 9) / (4.f / 3), "16:9" },
|
||||
{ 2, (21.f / 9) / (4.f / 3), "21:9" },
|
||||
{ 3, 0, "window" }
|
||||
@ -126,6 +135,7 @@ const struct { int id; float ratio; const char* label; } aspectRatios[] =
|
||||
void micCallback(void* data, Uint8* stream, int len);
|
||||
|
||||
|
||||
|
||||
void audioCallback(void* data, Uint8* stream, int len)
|
||||
{
|
||||
len /= (sizeof(s16) * 2);
|
||||
@ -141,7 +151,7 @@ void audioCallback(void* data, Uint8* stream, int len)
|
||||
SDL_CondSignal(audioSync);
|
||||
SDL_UnlockMutex(audioSyncLock);
|
||||
|
||||
if (num_in < 1)
|
||||
if ((num_in < 1) || audioMuted)
|
||||
{
|
||||
memset(stream, 0, len*sizeof(s16)*2);
|
||||
return;
|
||||
@ -161,6 +171,23 @@ void audioCallback(void* data, Uint8* stream, int len)
|
||||
Frontend::AudioOut_Resample(buf_in, num_in, (s16*)stream, len, Config::AudioVolume);
|
||||
}
|
||||
|
||||
void audioMute()
|
||||
{
|
||||
int inst = Platform::InstanceID();
|
||||
audioMuted = false;
|
||||
|
||||
switch (Config::MPAudioMode)
|
||||
{
|
||||
case 1: // only instance 1
|
||||
if (inst > 0) audioMuted = true;
|
||||
break;
|
||||
|
||||
case 2: // only currently focused instance
|
||||
if (!mainWindow->isActiveWindow()) audioMuted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void micOpen()
|
||||
{
|
||||
@ -700,7 +727,11 @@ void EmuThread::run()
|
||||
if (winUpdateFreq < 1)
|
||||
winUpdateFreq = 1;
|
||||
|
||||
sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget);
|
||||
int inst = Platform::InstanceID();
|
||||
if (inst == 0)
|
||||
sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget);
|
||||
else
|
||||
sprintf(melontitle, "[%d/%.0f] melonDS (%d)", fps, fpstarget, inst+1);
|
||||
changeWindowTitle(melontitle);
|
||||
}
|
||||
}
|
||||
@ -715,7 +746,11 @@ void EmuThread::run()
|
||||
|
||||
EmuStatus = EmuRunning;
|
||||
|
||||
sprintf(melontitle, "melonDS " MELONDS_VERSION);
|
||||
int inst = Platform::InstanceID();
|
||||
if (inst == 0)
|
||||
sprintf(melontitle, "melonDS " MELONDS_VERSION);
|
||||
else
|
||||
sprintf(melontitle, "melonDS (%d)", inst+1);
|
||||
changeWindowTitle(melontitle);
|
||||
|
||||
SDL_Delay(75);
|
||||
@ -942,7 +977,7 @@ void ScreenHandler::screenSetupLayout(int w, int h)
|
||||
QSize ScreenHandler::screenGetMinSize(int factor = 1)
|
||||
{
|
||||
bool isHori = (Config::ScreenRotation == 1 || Config::ScreenRotation == 3);
|
||||
int gap = Config::ScreenGap;
|
||||
int gap = Config::ScreenGap * factor;
|
||||
|
||||
int w = 256 * factor;
|
||||
int h = 192 * factor;
|
||||
@ -976,9 +1011,9 @@ QSize ScreenHandler::screenGetMinSize(int factor = 1)
|
||||
else // hybrid
|
||||
{
|
||||
if (isHori)
|
||||
return QSize(h+gap+h, 3*w +(4*gap) / 3);
|
||||
return QSize(h+gap+h, 3*w + (int)ceil((4*gap) / 3.0));
|
||||
else
|
||||
return QSize(3*w +(4*gap) / 3, h+gap+h);
|
||||
return QSize(3*w + (int)ceil((4*gap) / 3.0), h+gap+h);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1406,6 +1441,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||
setWindowTitle("melonDS " MELONDS_VERSION);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setAcceptDrops(true);
|
||||
setFocusPolicy(Qt::ClickFocus);
|
||||
|
||||
int inst = Platform::InstanceID();
|
||||
|
||||
QMenuBar* menubar = new QMenuBar();
|
||||
{
|
||||
@ -1538,19 +1576,30 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||
actEnableCheats->setCheckable(true);
|
||||
connect(actEnableCheats, &QAction::triggered, this, &MainWindow::onEnableCheats);
|
||||
|
||||
actSetupCheats = menu->addAction("Setup cheat codes");
|
||||
actSetupCheats->setMenuRole(QAction::NoRole);
|
||||
connect(actSetupCheats, &QAction::triggered, this, &MainWindow::onSetupCheats);
|
||||
//if (inst == 0)
|
||||
{
|
||||
actSetupCheats = menu->addAction("Setup cheat codes");
|
||||
actSetupCheats->setMenuRole(QAction::NoRole);
|
||||
connect(actSetupCheats, &QAction::triggered, this, &MainWindow::onSetupCheats);
|
||||
|
||||
menu->addSeparator();
|
||||
actROMInfo = menu->addAction("ROM info");
|
||||
connect(actROMInfo, &QAction::triggered, this, &MainWindow::onROMInfo);
|
||||
menu->addSeparator();
|
||||
actROMInfo = menu->addAction("ROM info");
|
||||
connect(actROMInfo, &QAction::triggered, this, &MainWindow::onROMInfo);
|
||||
|
||||
actRAMInfo = menu->addAction("RAM search");
|
||||
connect(actRAMInfo, &QAction::triggered, this, &MainWindow::onRAMInfo);
|
||||
actRAMInfo = menu->addAction("RAM search");
|
||||
connect(actRAMInfo, &QAction::triggered, this, &MainWindow::onRAMInfo);
|
||||
|
||||
actTitleManager = menu->addAction("Manage DSi titles");
|
||||
connect(actTitleManager, &QAction::triggered, this, &MainWindow::onOpenTitleManager);
|
||||
actTitleManager = menu->addAction("Manage DSi titles");
|
||||
connect(actTitleManager, &QAction::triggered, this, &MainWindow::onOpenTitleManager);
|
||||
}
|
||||
|
||||
{
|
||||
menu->addSeparator();
|
||||
QMenu* submenu = menu->addMenu("Multiplayer");
|
||||
|
||||
actMPNewInstance = submenu->addAction("Launch new instance");
|
||||
connect(actMPNewInstance, &QAction::triggered, this, &MainWindow::onMPNewInstance);
|
||||
}
|
||||
}
|
||||
{
|
||||
QMenu* menu = menubar->addMenu("Config");
|
||||
@ -1559,7 +1608,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||
connect(actEmuSettings, &QAction::triggered, this, &MainWindow::onOpenEmuSettings);
|
||||
|
||||
#ifdef __APPLE__
|
||||
QAction* actPreferences = menu->addAction("Preferences...");
|
||||
actPreferences = menu->addAction("Preferences...");
|
||||
connect(actPreferences, &QAction::triggered, this, &MainWindow::onOpenEmuSettings);
|
||||
actPreferences->setMenuRole(QAction::PreferencesRole);
|
||||
#endif
|
||||
@ -1570,18 +1619,24 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||
actVideoSettings = menu->addAction("Video settings");
|
||||
connect(actVideoSettings, &QAction::triggered, this, &MainWindow::onOpenVideoSettings);
|
||||
|
||||
actCameraSettings = menu->addAction("Camera settings");
|
||||
connect(actCameraSettings, &QAction::triggered, this, &MainWindow::onOpenCameraSettings);
|
||||
|
||||
actAudioSettings = menu->addAction("Audio settings");
|
||||
connect(actAudioSettings, &QAction::triggered, this, &MainWindow::onOpenAudioSettings);
|
||||
|
||||
actMPSettings = menu->addAction("Multiplayer settings");
|
||||
connect(actMPSettings, &QAction::triggered, this, &MainWindow::onOpenMPSettings);
|
||||
|
||||
actWifiSettings = menu->addAction("Wifi settings");
|
||||
connect(actWifiSettings, &QAction::triggered, this, &MainWindow::onOpenWifiSettings);
|
||||
|
||||
actInterfaceSettings = menu->addAction("Interface settings");
|
||||
connect(actInterfaceSettings, &QAction::triggered, this, &MainWindow::onOpenInterfaceSettings);
|
||||
|
||||
actFirmwareSettings = menu->addAction("Firmware settings");
|
||||
connect(actFirmwareSettings, &QAction::triggered, this, &MainWindow::onOpenFirmwareSettings);
|
||||
|
||||
actInterfaceSettings = menu->addAction("Interface settings");
|
||||
connect(actInterfaceSettings, &QAction::triggered, this, &MainWindow::onOpenInterfaceSettings);
|
||||
|
||||
actPathSettings = menu->addAction("Path settings");
|
||||
connect(actPathSettings, &QAction::triggered, this, &MainWindow::onOpenPathSettings);
|
||||
|
||||
@ -1737,6 +1792,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||
|
||||
resize(Config::WindowWidth, Config::WindowHeight);
|
||||
|
||||
if (Config::FirmwareUsername == "Arisotura")
|
||||
actMPNewInstance->setText("Fart");
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
QPoint screenCenter = screen()->availableGeometry().center();
|
||||
QRect frameGeo = frameGeometry();
|
||||
@ -1816,6 +1874,19 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||
|
||||
actLimitFramerate->setChecked(Config::LimitFPS);
|
||||
actAudioSync->setChecked(Config::AudioSync);
|
||||
|
||||
if (inst > 0)
|
||||
{
|
||||
actEmuSettings->setEnabled(false);
|
||||
actVideoSettings->setEnabled(false);
|
||||
actMPSettings->setEnabled(false);
|
||||
actWifiSettings->setEnabled(false);
|
||||
actInterfaceSettings->setEnabled(false);
|
||||
|
||||
#ifdef __APPLE__
|
||||
actPreferences->setEnabled(false);
|
||||
#endif // __APPLE__
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -2005,6 +2076,16 @@ void MainWindow::dropEvent(QDropEvent* event)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::focusInEvent(QFocusEvent* event)
|
||||
{
|
||||
audioMute();
|
||||
}
|
||||
|
||||
void MainWindow::focusOutEvent(QFocusEvent* event)
|
||||
{
|
||||
audioMute();
|
||||
}
|
||||
|
||||
void MainWindow::onAppStateChanged(Qt::ApplicationState state)
|
||||
{
|
||||
if (state == Qt::ApplicationInactive)
|
||||
@ -2677,6 +2758,23 @@ void MainWindow::onOpenTitleManager()
|
||||
TitleManagerDialog* dlg = TitleManagerDialog::openDlg(this);
|
||||
}
|
||||
|
||||
void MainWindow::onMPNewInstance()
|
||||
{
|
||||
//QProcess::startDetached(QApplication::applicationFilePath());
|
||||
QProcess newinst;
|
||||
newinst.setProgram(QApplication::applicationFilePath());
|
||||
newinst.setArguments(QApplication::arguments().mid(1, QApplication::arguments().length()-1));
|
||||
|
||||
#ifdef __WIN32__
|
||||
newinst.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments *args)
|
||||
{
|
||||
args->flags |= CREATE_NEW_CONSOLE;
|
||||
});
|
||||
#endif
|
||||
|
||||
newinst.startDetached();
|
||||
}
|
||||
|
||||
void MainWindow::onOpenEmuSettings()
|
||||
{
|
||||
emuThread->emuPause();
|
||||
@ -2737,6 +2835,27 @@ void MainWindow::onOpenVideoSettings()
|
||||
connect(dlg, &VideoSettingsDialog::updateVideoSettings, this, &MainWindow::onUpdateVideoSettings);
|
||||
}
|
||||
|
||||
void MainWindow::onOpenCameraSettings()
|
||||
{
|
||||
emuThread->emuPause();
|
||||
|
||||
camStarted[0] = camManager[0]->isStarted();
|
||||
camStarted[1] = camManager[1]->isStarted();
|
||||
if (camStarted[0]) camManager[0]->stop();
|
||||
if (camStarted[1]) camManager[1]->stop();
|
||||
|
||||
CameraSettingsDialog* dlg = CameraSettingsDialog::openDlg(this);
|
||||
connect(dlg, &CameraSettingsDialog::finished, this, &MainWindow::onCameraSettingsFinished);
|
||||
}
|
||||
|
||||
void MainWindow::onCameraSettingsFinished(int res)
|
||||
{
|
||||
if (camStarted[0]) camManager[0]->start();
|
||||
if (camStarted[1]) camManager[1]->start();
|
||||
|
||||
emuThread->emuUnpause();
|
||||
}
|
||||
|
||||
void MainWindow::onOpenAudioSettings()
|
||||
{
|
||||
AudioSettingsDialog* dlg = AudioSettingsDialog::openDlg(this);
|
||||
@ -2811,6 +2930,22 @@ void MainWindow::onAudioSettingsFinished(int res)
|
||||
micOpen();
|
||||
}
|
||||
|
||||
void MainWindow::onOpenMPSettings()
|
||||
{
|
||||
emuThread->emuPause();
|
||||
|
||||
MPSettingsDialog* dlg = MPSettingsDialog::openDlg(this);
|
||||
connect(dlg, &MPSettingsDialog::finished, this, &MainWindow::onMPSettingsFinished);
|
||||
}
|
||||
|
||||
void MainWindow::onMPSettingsFinished(int res)
|
||||
{
|
||||
audioMute();
|
||||
LocalMP::SetRecvTimeout(Config::MPRecvTimeout);
|
||||
|
||||
emuThread->emuUnpause();
|
||||
}
|
||||
|
||||
void MainWindow::onOpenWifiSettings()
|
||||
{
|
||||
emuThread->emuPause();
|
||||
@ -2821,12 +2956,6 @@ void MainWindow::onOpenWifiSettings()
|
||||
|
||||
void MainWindow::onWifiSettingsFinished(int res)
|
||||
{
|
||||
if (Wifi::MPInited)
|
||||
{
|
||||
Platform::MP_DeInit();
|
||||
Platform::MP_Init();
|
||||
}
|
||||
|
||||
Platform::LAN_DeInit();
|
||||
Platform::LAN_Init();
|
||||
|
||||
@ -3081,7 +3210,7 @@ bool MelonApplication::event(QEvent *event)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
srand(time(NULL));
|
||||
srand(time(nullptr));
|
||||
|
||||
qputenv("QT_SCALE_FACTOR", "1");
|
||||
|
||||
@ -3139,6 +3268,7 @@ int main(int argc, char** argv)
|
||||
SANITIZE(Config::ScreenAspectBot, 0, 4);
|
||||
#undef SANITIZE
|
||||
|
||||
audioMuted = false;
|
||||
audioSync = SDL_CreateCond();
|
||||
audioSyncLock = SDL_CreateMutex();
|
||||
|
||||
@ -3164,11 +3294,17 @@ int main(int argc, char** argv)
|
||||
|
||||
micDevice = 0;
|
||||
|
||||
|
||||
memset(micExtBuffer, 0, sizeof(micExtBuffer));
|
||||
micExtBufferWritePos = 0;
|
||||
micWavBuffer = nullptr;
|
||||
|
||||
camStarted[0] = false;
|
||||
camStarted[1] = false;
|
||||
camManager[0] = new CameraManager(0, 640, 480, true);
|
||||
camManager[1] = new CameraManager(1, 640, 480, true);
|
||||
camManager[0]->setXFlip(Config::Camera[0].XFlip);
|
||||
camManager[1]->setXFlip(Config::Camera[1].XFlip);
|
||||
|
||||
ROMManager::EnableCheats(Config::EnableCheats != 0);
|
||||
|
||||
Frontend::Init_Audio(audioFreq);
|
||||
@ -3192,6 +3328,8 @@ int main(int argc, char** argv)
|
||||
emuThread->start();
|
||||
emuThread->emuPause();
|
||||
|
||||
audioMute();
|
||||
|
||||
QObject::connect(&melon, &QApplication::applicationStateChanged, mainWindow, &MainWindow::onAppStateChanged);
|
||||
|
||||
if (argc > 1)
|
||||
@ -3219,6 +3357,9 @@ int main(int argc, char** argv)
|
||||
|
||||
if (micWavBuffer) delete[] micWavBuffer;
|
||||
|
||||
delete camManager[0];
|
||||
delete camManager[1];
|
||||
|
||||
Config::Save();
|
||||
|
||||
SDL_Quit();
|
||||
@ -3249,7 +3390,8 @@ int CALLBACK WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdsho
|
||||
|
||||
if (argv_w) LocalFree(argv_w);
|
||||
|
||||
/*if (AttachConsole(ATTACH_PARENT_PROCESS))
|
||||
//if (AttachConsole(ATTACH_PARENT_PROCESS))
|
||||
/*if (AllocConsole())
|
||||
{
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
freopen("CONOUT$", "w", stderr);
|
||||
|
Reference in New Issue
Block a user