program.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "../lucia.hpp"
  2. #include "platform.cpp"
  3. #include "load.cpp"
  4. #include "states.cpp"
  5. #include "rewind.cpp"
  6. #include "status.cpp"
  7. #include "utility.cpp"
  8. #include "drivers.cpp"
  9. Program program;
  10. auto Program::create() -> void {
  11. ares::platform = this;
  12. videoDriverUpdate();
  13. audioDriverUpdate();
  14. inputDriverUpdate();
  15. driverSettings.videoRefresh();
  16. driverSettings.audioRefresh();
  17. driverSettings.inputRefresh();
  18. if(startGameLoad) {
  19. if(auto emulator = identify(startGameLoad)) {
  20. if(load(emulator, startGameLoad)) {
  21. if(startFullScreen) videoFullScreenToggle();
  22. }
  23. }
  24. }
  25. }
  26. auto Program::main() -> void {
  27. if(Application::modal()) {
  28. ruby::audio.clear();
  29. return;
  30. }
  31. updateMessage();
  32. inputManager.poll();
  33. inputManager.pollHotkeys();
  34. bool defocused = driverSettings.inputDefocusPause.checked() && !ruby::video.fullScreen() && !presentation.focused();
  35. if(emulator && defocused) message.text = "Paused";
  36. if(!emulator || paused || defocused) {
  37. ruby::audio.clear();
  38. usleep(20 * 1000);
  39. return;
  40. }
  41. rewindRun();
  42. if(!runAhead || fastForwarding || rewinding) {
  43. emulator->interface->run();
  44. } else {
  45. ares::setRunAhead(true);
  46. emulator->interface->run();
  47. auto state = emulator->interface->serialize(false);
  48. ares::setRunAhead(false);
  49. emulator->interface->run();
  50. state.setMode(serializer::Mode::Load);
  51. emulator->interface->unserialize(state);
  52. }
  53. if(settings.general.autoSaveMemory) {
  54. static uint64_t previousTime = chrono::timestamp();
  55. uint64_t currentTime = chrono::timestamp();
  56. if(currentTime - previousTime >= 30) {
  57. previousTime = currentTime;
  58. emulator->save();
  59. }
  60. }
  61. memoryEditor.liveRefresh();
  62. graphicsViewer.liveRefresh();
  63. propertiesViewer.liveRefresh();
  64. }
  65. auto Program::quit() -> void {
  66. unload();
  67. presentation.setVisible(false); //makes quitting the emulator feel more responsive
  68. Application::processEvents();
  69. Application::quit();
  70. ruby::video.reset();
  71. ruby::audio.reset();
  72. ruby::input.reset();
  73. }