示例#1
0
文件: App.cs 项目: razluta/jazz2
        private static void Application_Idle(object sender, EventArgs e)
        {
            Application.Idle -= Application_Idle;

            // Trigger global event loop idle event.
            OnEventLoopIdling();

            // Perform some global operations, if no modal dialog is open
            if (mainWindow.Visible && mainWindow.CanFocus)
            {
                // Trigger global editor idle event.
                OnEditorIdling();

                // Trigger autosave after a while

                /*if (autosaveFrequency != AutosaveFrequency.Disabled) {
                 *  TimeSpan timeSinceLastAutosave = DateTime.Now - autosaveLast;
                 *  if ((autosaveFrequency == AutosaveFrequency.OneHour && timeSinceLastAutosave.TotalMinutes > 60) ||
                 *      (autosaveFrequency == AutosaveFrequency.ThirtyMinutes && timeSinceLastAutosave.TotalMinutes > 30) ||
                 *      (autosaveFrequency == AutosaveFrequency.TenMinutes && timeSinceLastAutosave.TotalMinutes > 10)) {
                 *      SaveAllProjectData();
                 *      autosaveLast = DateTime.Now;
                 *  }
                 * }*/
            }

            // Update Duality engine
            var watch = new System.Diagnostics.Stopwatch();

            while (AppStillIdle)
            {
                watch.Restart();
                if (!isSuspended)
                {
                    bool fixedSingleStep = /*Sandbox.TakeSingleStep()*/ true;
                    try {
                        DualityApp.EditorUpdate(
                            editorObjects.ActiveObjects.Concat(updateObjects),
                            fixedSingleStep /*|| (Sandbox.State == SandboxState.Playing && !Sandbox.IsFreezed)*/,
                            fixedSingleStep);
                        updateObjects.Clear();
                    } catch (Exception exception) {
                        Console.WriteLine("An error occurred during a core update: {0}", /*LogFormat.Exception(*/ exception /*)*/);
                    }
                    OnUpdatingEngine();
                }

                // Perform a buffer swap
                PerformBufferSwap();

                // Give the processor a rest if we have the time, don't use 100% CPU
                while (watch.Elapsed.TotalSeconds < 0.01d)
                {
                    // Sleep a little
                    System.Threading.Thread.Sleep(1);
                    // App wants to do something? Stop waiting.
                    if (!AppStillIdle)
                    {
                        break;
                    }
                }
            }

            Application.Idle += Application_Idle;
        }