void StartEmulatorThread(mame.cli_frontend frontend) { Debug.Log("Starting Background thread..."); int ret = frontend.execute(new mame.std.vector <string>() { "mcsUnity" }); //Environment.GetCommandLineArgs())); Debug.LogFormat("frontend.execute() returned: {0}", ret); // tell main thread to quit ScheduleExit(); }
void OnGUI() { if (m_guiLabel == null) { m_guiLabel = new GUIStyle(GUI.skin.label); m_guiLabel.padding = new RectOffset(0, 0, 0, 0); } Rect rect = new Rect(0, 0, Screen.width, Screen.height); GUI.DrawTexture(rect, m_win_video_window_unity, ScaleMode.ScaleToFit); if (m_showController) { float areaX = 0; float areaY = 0; float areaW = 230; float buttonH = 20; float spaceHeight = 10; if (IsIOS() || IsAndroid()) { buttonH = 110; } if (m_controllerMenuSelected == ControllerMenus.STATS) { areaW = 500; } GUILayout.BeginArea(new Rect(areaX, areaY, areaW, Screen.height)); GUILayout.BeginVertical(GUI.skin.box); GUILayout.BeginHorizontal(); if (GUILayout.Button("<", GUILayout.Height(buttonH))) { m_controllerMenuSelected = (ControllerMenus)DecrementWithRollover((int)m_controllerMenuSelected, m_controllerMenuText.Length); } if (GUILayout.Button(m_controllerMenuText[(int)m_controllerMenuSelected], GUILayout.Height(buttonH))) { m_controllerMenuSelected = (ControllerMenus)IncrementWithRollover((int)m_controllerMenuSelected, m_controllerMenuText.Length); } if (GUILayout.Button(">", GUILayout.Height(buttonH))) { m_controllerMenuSelected = (ControllerMenus)IncrementWithRollover((int)m_controllerMenuSelected, m_controllerMenuText.Length); } GUILayout.EndHorizontal(); GUILayout.Space(spaceHeight); if (m_controllerMenuSelected == ControllerMenus.NOMENU) { var instance = mame.mame_machine_manager.instance(); var machine = instance != null?instance.machine() : null; var video = machine != null?machine.video() : null; if (video != null) { osd_ticks_t tps = mame.osdcore_global.m_osdcore.osd_ticks_per_second(); double final_real_time = tps == 0 ? 0 : (double)video.m_overall_real_seconds + (double)video.m_overall_real_ticks / (double)tps; double final_emu_time = video.m_overall_emutime.as_double(); double average_speed_percentage = final_real_time == 0 ? 0 : 100 * final_emu_time / final_real_time; string total_time = (video.m_overall_emutime + new mame.attotime(0, mame.attotime.ATTOSECONDS_PER_SECOND / 2)).as_string(2); GUILayout.Label(string.Format("Avg Spd: {0:f2}% ({1} secs) - speed_text: {2}", average_speed_percentage, total_time, video.speed_text()), m_guiLabel); } float fps = 0; float averageFps = 0; if (m_fpsCounter) { fps = m_fpsCounter.Fps; averageFps = m_fpsCounter.AverageFps; } float lowFpsThreshold = 30; float fpsColor = Mathf.Min(1.0f, averageFps / lowFpsThreshold); GUI.color = new Color(1, fpsColor, fpsColor); GUILayout.Label(string.Format("T: {0:f2} F: {1} AVG: {2:f0} FPS: {3:f2}", Time.time, Time.frameCount, averageFps, fps), m_guiLabel); GUI.color = Color.white; if (GUILayout.Button("Start Emulator", GUILayout.Height(buttonH))) { if (m_thread == null) { mcsUnity.osdcore_Unity osdcore = new mcsUnity.osdcore_Unity(); mcsUnity.osd_file_Unity osdfile = new mcsUnity.osd_file_Unity(); mcsUnity.osd_directory_static_Unity osddirectory = new mcsUnity.osd_directory_static_Unity(); mcsUnity.osd_options_Unity options = new mcsUnity.osd_options_Unity(); mcsUnity.osd_interface_Unity osd = new mcsUnity.osd_interface_Unity(options); osd.register_options(); mame.cli_frontend frontend = new mame.cli_frontend(options, osd); mame.osdcore_global.set_osdcore(osdcore); mame.osdfile_global.set_osdfile(osdfile); mame.osdfile_global.set_osddirectory(osddirectory); mame.mame_machine_manager.instance(options, osd); Debug.Log("Starting Emulator..."); m_thread = new Thread(() => SafeExecute(() => StartEmulatorThread(frontend), Handler)); m_thread.IsBackground = true; m_thread.Name = "mame.cli_frontend.execute()"; m_thread.Start(); //new Thread(() => //{ // Debug.Log("Starting Background thread..."); // // Thread.CurrentThread.IsBackground = true; // Thread.CurrentThread.Name = "machine_manager.execute()"; // // int ret = frontend.execute(new List<string>(Environment.GetCommandLineArgs())); // // // tell form that it should close // //form.Invoke((MethodInvoker)delegate { form.Close(); }); // VHUtils.ApplicationQuit(); //}).Start(); } } GUILayout.BeginHorizontal(); if (GUILayout.Button("Q1", GUILayout.Height(buttonH))) { StartCoroutine(SendKey(KeyCode.Alpha5)); } if (GUILayout.Button("S1", GUILayout.Height(buttonH))) { StartCoroutine(SendKey(KeyCode.Alpha1)); } GUILayout.EndHorizontal(); if (GUILayout.Button("Up", GUILayout.Height(buttonH))) { StartCoroutine(SendKey(KeyCode.UpArrow)); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Left", GUILayout.Height(buttonH))) { StartCoroutine(SendKey(KeyCode.LeftArrow)); } if (GUILayout.Button("Right", GUILayout.Height(buttonH))) { StartCoroutine(SendKey(KeyCode.RightArrow)); } GUILayout.EndHorizontal(); if (GUILayout.Button("Down", GUILayout.Height(buttonH))) { StartCoroutine(SendKey(KeyCode.DownArrow)); } if (GUILayout.Button("Fire", GUILayout.Height(buttonH))) { StartCoroutine(SendKey(KeyCode.LeftControl)); } if (GUILayout.Button("Enter", GUILayout.Height(buttonH))) { StartCoroutine(SendKey(KeyCode.Return)); } } else if (m_controllerMenuSelected == ControllerMenus.STATS) { var instance = mame.mame_machine_manager.instance(); var machine = instance != null?instance.machine() : null; var video = machine != null?machine.video() : null; if (video != null) { osd_ticks_t tps = mame.osdcore_global.m_osdcore.osd_ticks_per_second(); double final_real_time = tps == 0 ? 0 : (double)video.m_overall_real_seconds + (double)video.m_overall_real_ticks / (double)tps; double final_emu_time = video.m_overall_emutime.as_double(); double average_speed_percentage = final_real_time == 0 ? 0 : 100 * final_emu_time / final_real_time; string total_time = (video.m_overall_emutime + new mame.attotime(0, mame.attotime.ATTOSECONDS_PER_SECOND / 2)).as_string(2); GUILayout.Label(string.Format("Avg Spd: {0:f2}% ({1} secs) - speed_text: {2}", average_speed_percentage, total_time, video.speed_text()), m_guiLabel); } float fps = 0; float averageFps = 0; if (m_fpsCounter) { fps = m_fpsCounter.Fps; averageFps = m_fpsCounter.AverageFps; } float lowFpsThreshold = 30; float fpsColor = Mathf.Min(1.0f, averageFps / lowFpsThreshold); GUI.color = new Color(1, fpsColor, fpsColor); GUILayout.Label(string.Format("T: {0:f2} F: {1} AVG: {2:f0} FPS: {3:f2}", Time.time, Time.frameCount, averageFps, fps), m_guiLabel); GUI.color = Color.white; GUILayout.Label(string.Format("{0}x{1}x{2} ({3}) {4:f0}dpi", Screen.width, Screen.height, Screen.currentResolution.refreshRate, GetCommonAspectText((float)Screen.width / Screen.height), Screen.dpi), m_guiLabel); GUILayout.Label(string.Format("Unity Version: {0}", Application.unityVersion), m_guiLabel); GUILayout.Label(string.Format("Platform: {0}", Application.platform), m_guiLabel); GUILayout.Label(string.Format("{0}", SystemInfo.operatingSystem), m_guiLabel); GUILayout.Label(string.Format("{0} x {1}", SystemInfo.processorCount, SystemInfo.processorType), m_guiLabel); GUILayout.Label(string.Format("Mem: {0:f1}gb", SystemInfo.systemMemorySize / 1000.0f), m_guiLabel); GUILayout.Label(string.Format("{0} - deviceID: {1}", SystemInfo.graphicsDeviceName, SystemInfo.graphicsDeviceID), m_guiLabel); GUILayout.Label(string.Format("{0} - vendorID: {1}", SystemInfo.graphicsDeviceVendor, SystemInfo.graphicsDeviceVendorID), m_guiLabel); GUILayout.Label(string.Format("{0}", SystemInfo.graphicsDeviceVersion), m_guiLabel); GUILayout.Label(string.Format("VMem: {0}mb", SystemInfo.graphicsMemorySize), m_guiLabel); GUILayout.Label(string.Format("Shader Level: {0:f1}", SystemInfo.graphicsShaderLevel / 10.0f), m_guiLabel); GUILayout.Label(string.Format("Shadows:{0} MT:{2}", SystemInfo.supportsShadows ? "y" : "n", SystemInfo.graphicsMultiThreaded ? "y" : "n"), m_guiLabel); GUILayout.Label(string.Format("deviceUniqueIdentifier: {0}", SystemInfo.deviceUniqueIdentifier), m_guiLabel); GUILayout.Label(string.Format("deviceName: {0}", SystemInfo.deviceName), m_guiLabel); GUILayout.Label(string.Format("deviceModel: {0}", SystemInfo.deviceModel), m_guiLabel); GUILayout.Label(string.Format("deviceType: {0}", SystemInfo.deviceType), m_guiLabel); GUILayout.Label(string.Format("UserName: {0}", System.Environment.UserName), m_guiLabel); GUILayout.Label(string.Format("MonoHeap: {0:N0}", UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong()), m_guiLabel); GUILayout.Label(string.Format("TempAllocator: {0:N0}", UnityEngine.Profiling.Profiler.GetTempAllocatorSize()), m_guiLabel); GUILayout.Label(string.Format("AllocatedMemory: {0:N0}", UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong()), m_guiLabel); GUILayout.Label(string.Format("ReservedMemory: {0:N0}", UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong()), m_guiLabel); GUILayout.Label(string.Format("UnusedReservedMemory: {0:N0}", UnityEngine.Profiling.Profiler.GetTotalUnusedReservedMemoryLong()), m_guiLabel); GUILayout.Label(string.Format("Scene: {0}", UnityEngine.SceneManagement.SceneManager.GetActiveScene().name), m_guiLabel); GUILayout.Label(string.Format("Qual: {0} - {1}", QualitySettings.names[QualitySettings.GetQualityLevel()], QualitySettings.activeColorSpace), m_guiLabel); } else if (m_controllerMenuSelected == ControllerMenus.CONFIG) { GUILayout.Label("Quality:", m_guiLabel); GUILayout.BeginHorizontal(); if (GUILayout.Button("<", GUILayout.Width(areaW * 0.16f))) { QualitySettings.SetQualityLevel(Extensions.Clamp(QualitySettings.GetQualityLevel() - 1, 0, QualitySettings.names.Length - 1)); } GUILayout.Button(string.Format("{0}", QualitySettings.names[QualitySettings.GetQualityLevel()]), GUILayout.Width(areaW * 0.6f)); if (GUILayout.Button(">", GUILayout.Width(areaW * 0.16f))) { QualitySettings.SetQualityLevel(Extensions.Clamp(QualitySettings.GetQualityLevel() + 1, 0, QualitySettings.names.Length - 1)); } GUILayout.EndHorizontal(); GUILayout.Space(spaceHeight); m_timeSlider = GUILayout.HorizontalSlider(m_timeSlider, 0.01f, 3); GUILayout.Label(string.Format("Time: {0}", m_timeSlider), m_guiLabel); } GUILayout.Space(spaceHeight); GUILayout.EndVertical(); GUILayout.EndArea(); Time.timeScale = m_timeSlider; } }