ui.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "base/main.moc"
  2. #include "base/loader.moc"
  3. #include "base/htmlviewer.moc"
  4. #include "base/about.moc"
  5. #include "settings/settings.moc"
  6. #include "base/main.cpp"
  7. #include "base/loader.cpp"
  8. #include "base/htmlviewer.cpp"
  9. #include "base/about.cpp"
  10. #include "settings/settings.cpp"
  11. void Application::init() {
  12. if(config.system.crashedOnLastRun == true) {
  13. //emulator crashed on last run, disable all drivers
  14. QMessageBox::warning(0, "bsnes Crash Notification", utf8() <<
  15. "<p><b>Warning:</b><br>bsnes crashed while attempting to initialize device "
  16. "drivers the last time it was run.</p>"
  17. "<p>To prevent this from occurring again, all drivers have been disabled. Please "
  18. "go to Settings->Configuration->Advanced and choose new driver settings, and then "
  19. "restart the emulator for the changes to take effect. <i>Video, audio and input "
  20. "will not work until you do this!</i></p>"
  21. "<p><b>Settings that caused failure on last run:</b><br>"
  22. << "Video driver: " << config.system.video << "<br>"
  23. << "Audio driver: " << config.system.audio << "<br>"
  24. << "Input driver: " << config.system.input << "<br></p>"
  25. );
  26. config.system.video = "None";
  27. config.system.audio = "None";
  28. config.system.input = "None";
  29. }
  30. if(config.system.video == "") config.system.video = video.default_driver();
  31. if(config.system.audio == "") config.system.audio = audio.default_driver();
  32. if(config.system.input == "") config.system.input = input.default_driver();
  33. winMain = new MainWindow;
  34. winMain->setup();
  35. winLoader = new LoaderWindow;
  36. winLoader->setup();
  37. winHtmlViewer = new HtmlViewerWindow;
  38. winHtmlViewer->setup();
  39. winAbout = new AboutWindow;
  40. winAbout->setup();
  41. //window must be onscreen and visible before initializing video interface
  42. utility.updateSystemState();
  43. utility.resizeMainWindow();
  44. utility.updateFullscreenState();
  45. application.processEvents();
  46. winSettings = new SettingsWindow;
  47. winSettings->setup();
  48. //if emulator crashes while initializing drivers, next run will disable them all.
  49. //this will allow user to choose different driver settings.
  50. config.system.crashedOnLastRun = true;
  51. config.save(configFilename);
  52. video.driver(config.system.video);
  53. video.set(Video::Handle, (uintptr_t)winMain->canvas->winId());
  54. if(video.init() == false) {
  55. QMessageBox::warning(0, "bsnes", utf8() <<
  56. "<p><b>Warning:</b> " << config.system.video << " video driver failed to initialize. "
  57. "Video driver has been disabled.</p>"
  58. "<p>Please go to Settings->Configuration->Advanced and choose a different driver, and "
  59. "then restart the emulator for the changes to take effect.</p>"
  60. );
  61. video.driver("None");
  62. video.init();
  63. }
  64. audio.driver(config.system.audio);
  65. audio.set(Audio::Handle, (uintptr_t)winMain->canvas->winId());
  66. audio.set(Audio::Frequency, config.audio.outputFrequency);
  67. audio.set(Audio::Latency, config.audio.latency);
  68. audio.set(Audio::Volume, config.audio.volume);
  69. if(audio.init() == false) {
  70. QMessageBox::warning(0, "bsnes", utf8() <<
  71. "<p><b>Warning:</b> " << config.system.audio << " audio driver failed to initialize. "
  72. "Audio driver has been disabled.</p>"
  73. "<p>Please go to Settings->Configuration->Advanced and choose a different driver, and "
  74. "then restart the emulator for the changes to take effect.</p>"
  75. );
  76. audio.driver("None");
  77. audio.init();
  78. }
  79. input.driver(config.system.input);
  80. input.set(Input::Handle, (uintptr_t)winMain->canvas->winId());
  81. if(input.init() == false) {
  82. QMessageBox::warning(0, "bsnes", utf8() <<
  83. "<p><b>Warning:</b> " << config.system.input << " input driver failed to initialize. "
  84. "Input driver has been disabled.</p>"
  85. "<p>Please go to Settings->Configuration->Advanced and choose a different driver, and "
  86. "then restart the emulator for the changes to take effect.</p>"
  87. );
  88. input.driver("None");
  89. input.init();
  90. }
  91. //didn't crash, note this in the config file now in case a different kind of crash occurs later
  92. config.system.crashedOnLastRun = false;
  93. config.save(configFilename);
  94. inputManager.bind();
  95. inputManager.refresh();
  96. inputManager.refresh();
  97. inputManager.onInput = bind(&Utility::inputEvent, &utility);
  98. utility.updateAvSync();
  99. utility.updateVideoMode();
  100. utility.updateColorFilter();
  101. utility.updateHardwareFilter();
  102. utility.updateSoftwareFilter();
  103. utility.updateEmulationSpeed();
  104. utility.updateControllers();
  105. }