bsnes/higan/target-bsnes/program/utility.cpp

112 lines
3.5 KiB
C++
Raw Normal View History

auto Program::initializeVideoDriver() -> void {
video = Video::create(settings["Video/Driver"].text());
video->setContext(presentation->viewport.handle());
video->setExclusive(false);
video->setBlocking(settings["Video/Blocking"].boolean());
Update to v106r27 release. byuu says: Changelog: - nall: merged Path::config() and Path::local() to Path::userData() - ~/.local/share or %appdata or ~/Library/ApplicationSupport - higan, bsnes: render main window icon onto viewport instead of canvas - should hopefully fix a brief flickering glitch that appears on Windows - icarus: improved Super Famicom heuristics for Starfox / Starwing RAM - ruby/Direct3D: handle viewport size changes in lock() instead of output() - fixes icon disappearing when resizing main window - hiro/Windows: remove WS_DISABLED from StatusBar to fix window resize grip - this is experimental: I initially used WS_DISABLED to work around a focus bug - yet trying things now, said bug seems(?) to have gone away at some point ... - bsnes: added advanced settings panel with real-time driver change support I'd like feedback on the real-time driver change, for possible consideration into adding this to higan as well. Some drivers just crash, it's a fact of life. The ASIO driver in particular likes to crash inside the driver itself, without any error messages ever returned to try and catch. When you try to change a driver with a game loaded, it gives you a scary warning, asking if you want to proceed. When you change a driver, it sets a crash flag, and if the driver crashes while initializing, then restarting bsnes will disable the errant driver. If it fails in a recoverable way, then it sets the driver to “None” and warns you that the driver cannot be used. What I'm thinking of further adding is to call emulator→save() to write out the save RAM contents beforehand (although the periodic auto-saving RAM will handle this anyway when it's enabled), and possibly it might be wise to capture an emulator save state, although those can't be taken without advancing the emulator to the next frame, so that might not be a good idea. I'm also thinking we should show some kind of message somewhere when a driver is set to “None”. The status bar can be hidden, so perhaps on the title bar? Or maybe just a warning on startup that a driver is set to “None”.
2018-05-25 08:02:38 +00:00
if(video->ready()) {
presentation->clearViewport();
updateVideoShader();
}
video->onUpdate([&](uint width, uint height) {
if(!emulator->loaded()) presentation->clearViewport();
});
}
auto Program::initializeAudioDriver() -> void {
audio = Audio::create(settings["Audio/Driver"].text());
audio->setContext(presentation->viewport.handle());
audio->setExclusive(false);
audio->setBlocking(settings["Audio/Blocking"].boolean());
if(!audio->availableDevices().find(settings["Audio/Device"].text())) {
settings["Audio/Device"].setValue(audio->availableDevices()(0));
}
audio->setDevice(settings["Audio/Device"].text());
if(!audio->availableFrequencies().find(settings["Audio/Frequency"].real())) {
settings["Audio/Frequency"].setValue(audio->availableFrequencies()(0));
}
audio->setFrequency(settings["Audio/Frequency"].real());
if(!audio->availableLatencies().find(settings["Audio/Latency"].natural())) {
settings["Audio/Latency"].setValue(audio->availableLatencies()(0));
}
audio->setLatency(settings["Audio/Latency"].natural());
audio->setChannels(2);
}
auto Program::initializeInputDriver() -> void {
input = Input::create(settings["Input/Driver"].text());
input->setContext(presentation->viewport.handle());
}
auto Program::updateVideoShader() -> void {
if(settings["Video/Driver"].text() == "OpenGL"
&& settings["Video/Shader"].text() != "None"
&& settings["Video/Shader"].text() != "Blur"
) {
video->setSmooth(false);
video->setShader(settings["Video/Shader"].text());
} else {
video->setSmooth(settings["Video/Shader"].text() == "Blur");
video->setShader("");
}
}
auto Program::connectDevices() -> void {
for(auto& port : emulator->ports) {
auto path = string{"Emulator/", port.name}.replace(" ", "");
auto name = settings(path).text();
for(auto& device : port.devices) {
if(device.name == name) {
emulator->connect(port.id, device.id);
break;
}
}
}
}
auto Program::applyHacks() -> void {
bool fastPPU = settingsWindow->advanced.fastPPUOption.checked();
bool fastDSP = settingsWindow->advanced.fastDSPOption.checked();
auto label = superNintendo.label;
if(label == "AIR STRIKE PATROL" || label == "DESERT FIGHTER") fastPPU = false;
if(label == "KOUSHIEN_2") fastDSP = false;
emulator->set("Fast PPU", fastPPU);
emulator->set("Fast DSP", fastDSP);
}
auto Program::showMessage(string text) -> void {
statusTime = chrono::timestamp();
statusMessage = text;
}
auto Program::updateMessage() -> void {
uint64 currentTime = chrono::timestamp();
string text;
if((currentTime - statusTime) <= 2) {
text = statusMessage;
} else if(!emulator->loaded()) {
text = "No game loaded";
} else if(presentation->pauseEmulation.checked()) {
text = "Paused";
} else if(!focused() && settingsWindow->input.pauseEmulation.checked()) {
text = "Paused";
} else {
text = statusText;
}
if(text != presentation->statusBar.text()) {
presentation->statusBar.setText(text);
}
}
auto Program::focused() -> bool {
//exclusive mode creates its own top-level window: presentation window will not have focus
if(video->exclusive()) return true;
if(presentation && presentation->focused()) return true;
return false;
}