mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 23:25:40 +12:00
Merge branch 'master' into metal2
This commit is contained in:
commit
d459f9c1c3
5 changed files with 91 additions and 15 deletions
|
@ -44,7 +44,6 @@ struct EmulatorConfig {
|
||||||
|
|
||||||
bool enableRenderdoc = false;
|
bool enableRenderdoc = false;
|
||||||
bool printAppVersion = true;
|
bool printAppVersion = true;
|
||||||
bool appVersionOnWindow = false;
|
|
||||||
|
|
||||||
bool chargerPlugged = true;
|
bool chargerPlugged = true;
|
||||||
// Default to 3% battery to make users suffer
|
// Default to 3% battery to make users suffer
|
||||||
|
@ -54,6 +53,24 @@ struct EmulatorConfig {
|
||||||
std::filesystem::path defaultRomPath = "";
|
std::filesystem::path defaultRomPath = "";
|
||||||
std::filesystem::path filePath;
|
std::filesystem::path filePath;
|
||||||
|
|
||||||
|
// Frontend window settings
|
||||||
|
struct WindowSettings {
|
||||||
|
static constexpr int defaultX = 200;
|
||||||
|
static constexpr int defaultY = 200;
|
||||||
|
static constexpr int defaultWidth = 800;
|
||||||
|
static constexpr int defaultHeight = 240 * 2;
|
||||||
|
|
||||||
|
bool rememberPosition = false; // Remember window position & size
|
||||||
|
bool showAppVersion = false;
|
||||||
|
|
||||||
|
int x = defaultX;
|
||||||
|
int y = defaultY;
|
||||||
|
int width = defaultHeight;
|
||||||
|
int height = defaultHeight;
|
||||||
|
};
|
||||||
|
|
||||||
|
WindowSettings windowSettings;
|
||||||
|
|
||||||
EmulatorConfig(const std::filesystem::path& path);
|
EmulatorConfig(const std::filesystem::path& path);
|
||||||
void load();
|
void load();
|
||||||
void save();
|
void save();
|
||||||
|
|
|
@ -43,7 +43,21 @@ void EmulatorConfig::load() {
|
||||||
defaultRomPath = toml::find_or<std::string>(general, "DefaultRomPath", "");
|
defaultRomPath = toml::find_or<std::string>(general, "DefaultRomPath", "");
|
||||||
|
|
||||||
printAppVersion = toml::find_or<toml::boolean>(general, "PrintAppVersion", true);
|
printAppVersion = toml::find_or<toml::boolean>(general, "PrintAppVersion", true);
|
||||||
appVersionOnWindow = toml::find_or<toml::boolean>(general, "AppVersionOnWindow", false);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.contains("Window")) {
|
||||||
|
auto windowResult = toml::expect<toml::value>(data.at("Window"));
|
||||||
|
if (windowResult.is_ok()) {
|
||||||
|
auto window = windowResult.unwrap();
|
||||||
|
|
||||||
|
windowSettings.showAppVersion = toml::find_or<toml::boolean>(window, "AppVersionOnWindow", false);
|
||||||
|
windowSettings.rememberPosition = toml::find_or<toml::boolean>(window, "RememberWindowPosition", false);
|
||||||
|
|
||||||
|
windowSettings.x = toml::find_or<toml::integer>(window, "WindowPosX", WindowSettings::defaultX);
|
||||||
|
windowSettings.y = toml::find_or<toml::integer>(window, "WindowPosY", WindowSettings::defaultY);
|
||||||
|
windowSettings.width = toml::find_or<toml::integer>(window, "WindowWidth", WindowSettings::defaultWidth);
|
||||||
|
windowSettings.height = toml::find_or<toml::integer>(window, "WindowHeight", WindowSettings::defaultHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +147,13 @@ void EmulatorConfig::save() {
|
||||||
data["General"]["UsePortableBuild"] = usePortableBuild;
|
data["General"]["UsePortableBuild"] = usePortableBuild;
|
||||||
data["General"]["DefaultRomPath"] = defaultRomPath.string();
|
data["General"]["DefaultRomPath"] = defaultRomPath.string();
|
||||||
data["General"]["PrintAppVersion"] = printAppVersion;
|
data["General"]["PrintAppVersion"] = printAppVersion;
|
||||||
data["General"]["AppVersionOnWindow"] = appVersionOnWindow;
|
|
||||||
|
data["Window"]["AppVersionOnWindow"] = windowSettings.showAppVersion;
|
||||||
|
data["Window"]["RememberWindowPosition"] = windowSettings.rememberPosition;
|
||||||
|
data["Window"]["WindowPosX"] = windowSettings.x;
|
||||||
|
data["Window"]["WindowPosY"] = windowSettings.y;
|
||||||
|
data["Window"]["WindowWidth"] = windowSettings.width;
|
||||||
|
data["Window"]["WindowHeight"] = windowSettings.height;
|
||||||
|
|
||||||
data["GPU"]["EnableShaderJIT"] = shaderJitEnabled;
|
data["GPU"]["EnableShaderJIT"] = shaderJitEnabled;
|
||||||
data["GPU"]["Renderer"] = std::string(Renderer::typeToString(rendererType));
|
data["GPU"]["Renderer"] = std::string(Renderer::typeToString(rendererType));
|
||||||
|
|
|
@ -662,7 +662,7 @@ void FragmentGenerator::compileLUTLookup(std::string& shader, const PICA::Fragme
|
||||||
case 4: shader += "lut_lookup_delta = dot(light_vector, lightSources[" + std ::to_string(lightID) + "].spotlightDirection);\n"; break;
|
case 4: shader += "lut_lookup_delta = dot(light_vector, lightSources[" + std ::to_string(lightID) + "].spotlightDirection);\n"; break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Helpers::warn("Shadergen: Unimplemented LUT select");
|
Helpers::warn("Shadergen: Unimplemented LUT select %d", inputID);
|
||||||
shader += "lut_lookup_delta = 1.0;\n";
|
shader += "lut_lookup_delta = 1.0;\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,13 +99,23 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (emu->getConfig().appVersionOnWindow) {
|
// Handle UI configs before setting up the emulator thread
|
||||||
|
{
|
||||||
|
auto& config = emu->getConfig();
|
||||||
|
auto& windowSettings = config.windowSettings;
|
||||||
|
|
||||||
|
if (windowSettings.showAppVersion) {
|
||||||
setWindowTitle("Alber v" PANDA3DS_VERSION);
|
setWindowTitle("Alber v" PANDA3DS_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (emu->getConfig().printAppVersion) {
|
if (windowSettings.rememberPosition) {
|
||||||
|
setGeometry(windowSettings.x, windowSettings.y, windowSettings.width, config.windowSettings.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.printAppVersion) {
|
||||||
printf("Welcome to Panda3DS v%s!\n", PANDA3DS_VERSION);
|
printf("Welcome to Panda3DS v%s!\n", PANDA3DS_VERSION);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The emulator graphics context for the thread should be initialized in the emulator thread due to how GL contexts work
|
// The emulator graphics context for the thread should be initialized in the emulator thread due to how GL contexts work
|
||||||
emuThread = std::thread([this]() {
|
emuThread = std::thread([this]() {
|
||||||
|
@ -224,6 +234,15 @@ void MainWindow::closeEvent(QCloseEvent *event) {
|
||||||
if (emuThread.joinable()) {
|
if (emuThread.joinable()) {
|
||||||
emuThread.join();
|
emuThread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cache window position/size in config file to restore next time
|
||||||
|
const QRect& windowGeometry = geometry();
|
||||||
|
auto& windowConfig = emu->getConfig().windowSettings;
|
||||||
|
|
||||||
|
windowConfig.x = windowGeometry.x();
|
||||||
|
windowConfig.y = windowGeometry.y();
|
||||||
|
windowConfig.width = windowGeometry.width();
|
||||||
|
windowConfig.height = windowGeometry.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup when the main window closes
|
// Cleanup when the main window closes
|
||||||
|
|
|
@ -35,18 +35,28 @@ FrontendSDL::FrontendSDL() : keyboardMappings(InputMappings::defaultKeyboardMapp
|
||||||
needOpenGL = needOpenGL || (config.rendererType == RendererType::OpenGL);
|
needOpenGL = needOpenGL || (config.rendererType == RendererType::OpenGL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char* windowTitle = config.appVersionOnWindow ? ("Alber v" PANDA3DS_VERSION) : "Alber";
|
const char* windowTitle = config.windowSettings.showAppVersion ? ("Alber v" PANDA3DS_VERSION) : "Alber";
|
||||||
if (config.printAppVersion) {
|
if (config.printAppVersion) {
|
||||||
printf("Welcome to Panda3DS v%s!\n", PANDA3DS_VERSION);
|
printf("Welcome to Panda3DS v%s!\n", PANDA3DS_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply window size settings if the appropriate option is enabled
|
||||||
|
if (config.windowSettings.rememberPosition) {
|
||||||
|
windowWidth = config.windowSettings.width;
|
||||||
|
windowHeight = config.windowSettings.height;
|
||||||
|
} else {
|
||||||
|
windowWidth = 400;
|
||||||
|
windowHeight = 480;
|
||||||
|
}
|
||||||
|
emu.setOutputSize(windowWidth, windowHeight);
|
||||||
|
|
||||||
if (needOpenGL) {
|
if (needOpenGL) {
|
||||||
// Demand 3.3 core for software renderer, or 4.1 core for OpenGL renderer (max available on MacOS)
|
// Demand 3.3 core for software renderer, or 4.1 core for OpenGL renderer (max available on MacOS)
|
||||||
// MacOS gets mad if we don't explicitly demand a core profile
|
// MacOS gets mad if we don't explicitly demand a core profile
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, config.rendererType == RendererType::Software ? 3 : 4);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, config.rendererType == RendererType::Software ? 3 : 4);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, config.rendererType == RendererType::Software ? 3 : 1);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, config.rendererType == RendererType::Software ? 3 : 1);
|
||||||
window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
if (window == nullptr) {
|
if (window == nullptr) {
|
||||||
Helpers::panic("Window creation failed: %s", SDL_GetError());
|
Helpers::panic("Window creation failed: %s", SDL_GetError());
|
||||||
|
@ -66,7 +76,9 @@ FrontendSDL::FrontendSDL() : keyboardMappings(InputMappings::defaultKeyboardMapp
|
||||||
|
|
||||||
#ifdef PANDA3DS_ENABLE_VULKAN
|
#ifdef PANDA3DS_ENABLE_VULKAN
|
||||||
if (config.rendererType == RendererType::Vulkan) {
|
if (config.rendererType == RendererType::Vulkan) {
|
||||||
window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 480, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
|
window = SDL_CreateWindow(
|
||||||
|
windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE
|
||||||
|
);
|
||||||
|
|
||||||
if (window == nullptr) {
|
if (window == nullptr) {
|
||||||
Helpers::warn("Window creation failed: %s", SDL_GetError());
|
Helpers::warn("Window creation failed: %s", SDL_GetError());
|
||||||
|
@ -108,10 +120,18 @@ void FrontendSDL::run() {
|
||||||
namespace Keys = HID::Keys;
|
namespace Keys = HID::Keys;
|
||||||
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT: {
|
||||||
printf("Bye :(\n");
|
printf("Bye :(\n");
|
||||||
programRunning = false;
|
programRunning = false;
|
||||||
|
|
||||||
|
// Remember window position & size for future runs
|
||||||
|
auto& windowSettings = emu.getConfig().windowSettings;
|
||||||
|
// Note: For the time being we currently don't actually apply the x/y positions to the window, and center it instead
|
||||||
|
// This is subject to change in the future, so let's save the x/y positions to the config file anyways
|
||||||
|
SDL_GetWindowPosition(window, &windowSettings.x, &windowSettings.y);
|
||||||
|
SDL_GetWindowSize(window, &windowSettings.width, &windowSettings.height);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
case SDL_KEYDOWN: {
|
case SDL_KEYDOWN: {
|
||||||
if (emu.romType == ROMType::None) break;
|
if (emu.romType == ROMType::None) break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue