示例#1
0
 public void Update()
 {
     _stopwatch.Restart();
     lock (_instances)
     {
         foreach (var x in _instances.Values)
         {
             x.Update();
         }
     }
     _elementUpdateTimeValue.Set(_stopwatch.ElapsedMilliseconds);
 }
示例#2
0
        private void OnRenderFrame()
        {
            //Logging.Debug("Entering RenderFrame");
            if (_isRendering || _formLoading || WindowState == FormWindowState.Minimized)
            {
                return;
            }
            UpdateStatusDistance(_camera.Position.Z);
            _isRendering = true;
            _sw.Restart();
            var perspective = CreatePerspective();

            if (VixenSystem.Elements.ElementsHaveState)
            {
                //Logging.Debug("Elements have state.");
                _sw2.Restart();
                UpdateShapePoints();
                _pointsUpdate.Set(_sw2.ElapsedMilliseconds);
                var mvp = Matrix4.Identity * _camera.ViewMatrix * perspective;
                lock (ContextLock)
                {
                    glControl.MakeCurrent();
                    ClearScreen();
                    _sw2.Restart();
                    _background.Draw(perspective, _camera.ViewMatrix);
                    _backgroundDraw.Set(_sw2.ElapsedMilliseconds);
                    _sw2.Restart();
                    DrawPoints(mvp);
                    _pointsDraw.Set(_sw2.ElapsedMilliseconds);
                    glControl.SwapBuffers();
                    glControl.Context.MakeCurrent(null);
                }
            }
            else
            {
                lock (ContextLock)
                {
                    glControl.MakeCurrent();
                    ClearScreen();
                    _sw2.Restart();
                    _background.Draw(perspective, _camera.ViewMatrix);
                    _backgroundDraw.Set(_sw2.ElapsedMilliseconds);
                    glControl.SwapBuffers();
                    glControl.Context.MakeCurrent(null);
                }
            }
            _isRendering = false;
            _previewUpdate.Set(_sw.ElapsedMilliseconds);
            UpdateFrameRate();
            //Logging.Debug("Exiting RenderFrame");
        }
示例#3
0
        public HashSet <Guid> UpdateCacheCompileContext(TimeSpan time)
        {
            HashSet <Guid> elementsAffected = null;

            _stopwatch.Restart();
            try
            {
                elementsAffected = _preCachingSequenceContext.UpdateElementStates(time);
            } catch (Exception ee)
            {
                Logging.ErrorException(ee.Message, ee);
            }
            _contextUpdateTimeValue.Set(_stopwatch.ElapsedMilliseconds);
            return(elementsAffected);
        }
示例#4
0
        public void Update()
        {
            _updateStopwatch.Restart();

            try
            {
                if (commands == null)
                {
                    commands = new ICommand[OutputCount];
                }
                _outputMediator.LockOutputs();

                for (int i = 0; i < OutputCount; i++)
                {
                    commands[i] = GenerateOutputCommand(Outputs[i]);
                }
                ControllerModule.UpdateState(0, commands);
            }
            catch (Exception e)
            {
                Logging.Error(e, "An error ocuered outputing data for controller {0}", Name);
            }
            finally
            {
                _outputMediator.UnlockOutputs();
            }

            _updateTimeValue.Set(_updateStopwatch.ElapsedMilliseconds);
            _updateStopwatch.Stop();
        }
示例#5
0
        public ConcurrentDictionary <string, TimeSpan> Update()
        {
            var res = new ConcurrentDictionary <string, TimeSpan>();

            _stopwatch.Restart();
            lock (_instances)
            {
                _contextUpdateWaitValue.Set(_stopwatch.ElapsedMilliseconds);

                _instances.Values.AsParallel().ForAll(context =>
                                                      //foreach( var context in _instances.Values)
                {
                    try {
                        // Get a snapshot time value for this update.
                        TimeSpan contextTime = context.GetTimeSnapshot();
                        res.TryAdd(context.Name, contextTime);
                        IEnumerable <Guid> affectedElements = context.UpdateElementStates(contextTime);
                        //Could possibly return affectedElements so only affected outputs
                        //are updated.  The controller would have to maintain state so those
                        //outputs could be updated and the whole state sent out.
                    } catch (Exception ee) {
                        Logging.ErrorException(ee.Message, ee);
                    }
                });
                //}
                _contextUpdateTimeValue.Set(_stopwatch.ElapsedMilliseconds);
            }
            return(res);
        }
示例#6
0
        public static ConcurrentDictionary <string, TimeSpan> UpdateState(out bool allowed)
        {
            if (_stopwatch == null)
            {
                initInstrumentation();
            }
            long nowMs = _stopwatch.ElapsedMilliseconds;

            lock (lockObject) {
                long lockMs      = _stopwatch.ElapsedMilliseconds - nowMs;
                bool allowUpdate = _UpdateAdjudicator.PetitionForUpdate();
                if (allowUpdate)
                {
                    lastSnapshots = VixenSystem.Contexts.Update();
                    VixenSystem.Elements.Update();
                    VixenSystem.Filters.Update();
                    _systemAllowedBlockTime.Set(lockMs);
                    _systemAllowedUpdateTime.Set(_stopwatch.ElapsedMilliseconds - nowMs - lockMs);
                }
                else
                {
                    _systemDeniedBlockTime.Set(lockMs);
                    _systemDeniedUpdateTime.Set(_stopwatch.ElapsedMilliseconds - nowMs - lockMs);
                }
                lastMs  = nowMs;
                allowed = allowUpdate;
                return(lastSnapshots);
            }
        }
示例#7
0
        protected override void Update()
        {
            var sw = Stopwatch.StartNew();

            try {
                // displayForm.Scene.ElementStates = ElementStates;
                //if the Preview form style changes re-setup the form
                //if ((UseGDIPreviewRendering && !isGdiVersion) || (!UseGDIPreviewRendering && isGdiVersion) || displayForm == null) {
                //	SetupPreviewForm();
                //	isGdiVersion = UseGDIPreviewRendering;
                //	Stop();
                //	Start();
                //}

                //if (!UseGDIPreviewRendering) {
                //	((VixenPreviewDisplayD2D)displayForm).Scene.Update(/*ElementStates*/);
                //}
                //else {
                //	if (UseOldPreview)
                //		((VixenPreviewDisplay)displayForm).PreviewControl.ProcessUpdateParallel(/*ElementStates*/);
                //	else
                displayForm.UpdatePreview();
                //}
            }
            catch (Exception e) {
                Logging.Error("Exception in preview update {0} - {1}", e.Message, e.StackTrace);
                //Console.WriteLine(e.ToString());
            }
            _updateTimeValue.Set(sw.ElapsedMilliseconds);
        }
示例#8
0
 public void Update()
 {
     _stopwatch.Restart();
     lock (_updateLock)
     {
         Parallel.ForEach(_rootFilters, _UpdateFilterBranch);
     }
     _filterUpdateTimeValue.Set(_stopwatch.ElapsedMilliseconds);
 }
        private void _WaitOnSignal(IOutputDeviceUpdateSignaler signaler)
        {
            long timeBeforeSignal = _localTime.ElapsedMilliseconds;

            signaler.RaiseSignal();
            //_updateSignalerSync.WaitOne();

            long timeAfterSignal = _localTime.ElapsedMilliseconds;

            _sleepTimeActualValue.Set(timeAfterSignal - timeBeforeSignal);
        }
示例#10
0
        protected override void Update()
        {
            var sw = Stopwatch.StartNew();

            try {
                _displayForm.UpdatePreview();
            }
            catch (Exception e) {
                Logging.Error("Exception in preview update {0} - {1}", e.Message, e.StackTrace);
            }
            _updateTimeValue.Set(sw.ElapsedMilliseconds);
        }
示例#11
0
        public void ClearStates()
        {
            _stopwatch.Restart();
            lock (_instances)
            {
                //_instances.Values.AsParallel().ForAll(x => x.Update());
                foreach (var x in _instances.Values)
                {
                    x.ClearStates();
                }

                _elementClearTimeValue.Set(_stopwatch.ElapsedMilliseconds);
            }
        }
示例#12
0
文件: Execution.cs 项目: thorhs/vixen
        public static ConcurrentDictionary <string, TimeSpan> UpdateState(out bool allowed)
        {
            if (_stopwatch == null)
            {
                initInstrumentation();
            }
            long nowMs = _stopwatch.ElapsedMilliseconds;

            lock (lockObject) {
                long lockMs      = _stopwatch.ElapsedMilliseconds - nowMs;
                bool allowUpdate = _UpdateAdjudicator.PetitionForUpdate();
                if (allowUpdate)
                {
                    HashSet <Guid> elementsAffected = VixenSystem.Contexts.Update();
                    if (elementsAffected.Any())
                    {
                        VixenSystem.Elements.Update(elementsAffected);
                        lastUpdateClearedStates = false;
                        if (VixenSystem.OutputControllers.Any(x => x.IsRunning))
                        {
                            //Only update the filter chain if we have a controller running
                            VixenSystem.Filters.Update();
                        }
                    }
                    else if (!lastUpdateClearedStates)
                    {
                        //No need to sample all the contexts as we were just told there are no elements effected.
                        VixenSystem.Elements.ClearStates();
                        lastUpdateClearedStates = true;
                        if (VixenSystem.OutputControllers.Any(x => x.IsRunning))
                        {
                            //Only update the filter chain if we have a controller running
                            VixenSystem.Filters.Update();
                        }
                    }

                    _systemAllowedBlockTime.Set(lockMs);
                    _systemAllowedUpdateTime.Set(_stopwatch.ElapsedMilliseconds - nowMs - lockMs);
                }
                else
                {
                    _systemDeniedBlockTime.Set(lockMs);
                    _systemDeniedUpdateTime.Set(_stopwatch.ElapsedMilliseconds - nowMs - lockMs);
                }
                lastMs  = nowMs;
                allowed = allowUpdate;
                return(lastSnapshots);
            }
        }
示例#13
0
        public void Update()
        {
            _stopwatch.Restart();
            lock (_updateLock)
            {
                _filterUpdateWaitValue.Set(_stopwatch.ElapsedMilliseconds);

                //_rootFilters.AsParallel().ForAll(_UpdateFilterBranch);
                foreach (var x in _rootFilters)
                {
                    _UpdateFilterBranch(x);
                }

                _filterUpdateTimeValue.Set(_stopwatch.ElapsedMilliseconds);
            }
        }
示例#14
0
        public void Update()
        {
            _updateStopwatch.Restart();

            try
            {
                if (commands == null)
                {
                    commands = new ICommand[OutputCount];
                }
                _outputMediator.LockOutputs();

                if (OutputCount > 15000)
                {
                    Parallel.For(0, OutputCount, _parallelOptions, () => ControllerModule.DataPolicyFactory.CreateDataPolicy(), (x, loopState, dataPolicy) =>
                    {
                        var o       = Outputs[x].State;
                        commands[x] = o?.Value != null ? dataPolicy.GenerateCommand(o) : null;
                        return(dataPolicy);
                    }, x => { });                //nothing to do but let the datapolicy expire
                }
                else
                {
                    for (int x = 0; x < OutputCount; x++)
                    {
                        var o = Outputs[x].State;
                        commands[x] = o?.Value != null?_dataPolicy.GenerateCommand(o) : null;
                    }
                }


                ControllerModule.UpdateState(0, commands);
            }
            catch (Exception e)
            {
                Logging.Error(e, "An error occurred outputting data for controller {0}", Name);
            }
            finally
            {
                _outputMediator.UnlockOutputs();
            }

            _updateTimeValue.Set(_updateStopwatch.ElapsedMilliseconds);
            _updateStopwatch.Stop();
        }
示例#15
0
        private void _ThreadFunc()
        {
            // Thread main loop
            try {
                IOutputDeviceUpdateSignaler signaler = _CreateOutputDeviceUpdateSignaler();

                while (_threadState != ExecutionState.Stopping)
                {
                    long nowMs = _localTime.ElapsedMilliseconds;
                    long dtMs  = nowMs - _lastMs;
                    _intervalDeltaValue.Set(Math.Abs(OutputDevice.UpdateInterval - dtMs));
                    _lastMs = nowMs;

                    bool allowed = false;
                    Execution.UpdateState(out allowed);
                    long execMs = _localTime.ElapsedMilliseconds - nowMs;

                    _UpdateOutputDevice();

                    if (allowed)
                    {
                        _executionTimeValue.Set(execMs);
                    }

                    // wait for the next go 'round
                    _WaitOnSignal(signaler);
                    _WaitOnPause();
                }

                _threadState = ExecutionState.Stopped;
                _finished.Set();
            }
            catch (Exception ex) {
                // Do this before calling OnError so that we can be in the stopped state.
                // Otherwise, we'll have a deadlock as the event causes a shutdown which
                // waits for the thread to end.
                _threadState = ExecutionState.Stopped;
                _finished.Set();

                Logging.Error(ex, string.Format("Controller {0} error", OutputDevice.Name));
                OnError();
            }
        }
示例#16
0
        public void UpdatePreview(/*Vixen.Preview.PreviewElementIntentStates elementStates*/)
        {
            if (!gdiControl.IsUpdating)
            {
                if (!VixenSystem.Elements.ElementsHaveState)
                {
                    if (_needsUpdate)
                    {
                        _needsUpdate = false;
                        gdiControl.BeginUpdate();
                        gdiControl.EndUpdate();
                        gdiControl.Invalidate();
                    }

                    toolStripStatusFPS.Text = "0 fps";
                    return;
                }

                _needsUpdate = true;

                try
                {
                    gdiControl.BeginUpdate();

                    _sw.Restart();
                    Parallel.ForEach(VixenSystem.Elements, UpdateElementPixels);

                    _previewSetPixelsTime.Set(_sw.ElapsedMilliseconds);
                }
                catch (Exception e)
                {
                    Logging.Error(e, e.Message);
                }

                gdiControl.EndUpdate();
                gdiControl.Invalidate();

                toolStripStatusFPS.Text = string.Format("{0} fps", gdiControl.FrameRate.ToString());
            }
        }
        private void _ThreadFunc()
        {
            // Thread main loop
            try {
                IOutputDeviceUpdateSignaler signaler = _CreateOutputDeviceUpdateSignaler();

                while (_threadState != ExecutionState.Stopping)
                {
                    long nowMs = _localTime.ElapsedMilliseconds;
                    long dtMs  = nowMs - _lastMs;
                    _lastMs = nowMs;

                    bool allowed = false;
                    var  lastTS  = Execution.UpdateState(out allowed);
                    long execMs  = _localTime.ElapsedMilliseconds - nowMs;

                    _UpdateOutputDevice();
                    long outputMs = _localTime.ElapsedMilliseconds - nowMs - execMs;

                    // instrumentation counters...
                    _intervalDeltaValue.Set(Math.Abs(OutputDevice.UpdateInterval - dtMs));
                    if (allowed)
                    {
                        _executionTimeValue.Set(execMs);
                    }
                    _updateTimeValue.Set(outputMs);

                    // log stuff after real work is done...

                    // prep a sample info string for later...
                    string sampinfo = "";
                    long   sampMs   = 0;
                    foreach (var name in lastTS.Keys)
                    {
                        if (!name.Contains("System"))
                        {
                            sampMs    = (long)lastTS[name].TotalMilliseconds;
                            sampinfo += String.Format("{0}:{1} ", name, sampMs);
                        }
                    }

                    // our cycle jitter was captured above
                    bool jitter = false;
                    if (Math.Abs(OutputDevice.UpdateInterval - dtMs) > 20)
                    {
                        jitter = true;
                        Logging.Debug("hwt jitter:  {0}: nowMs:{1}, dtMs:{2}", OutputDevice.Name, nowMs, dtMs);
                    }

                    // only worry about state sample jitter if it is running
                    long dtMs2 = 0;
                    if (sampMs > 0)
                    {
                        dtMs2    = sampMs - _lastMs2;
                        _lastMs2 = sampMs;
                        if (Math.Abs(OutputDevice.UpdateInterval - dtMs2) > 20 && sampMs > 0 && dtMs2 > 0)
                        {
                            jitter = true;
                            Logging.Debug("samp jitter:  {0}: sampMs:{1}, dts:{2}",
                                          OutputDevice.Name, sampMs, dtMs2);
                        }
                    }
                    // summary output for all threads of jitter...
                    // change the false in statuslog to true to get a no-preview output each time through..
                    bool statuslog = false && (sampMs > 0 && dtMs2 > 0 && !OutputDevice.Name.Contains("Preview"));
                    if (jitter || statuslog)
                    {
                        Logging.Debug("{0}: nowMs:{1}, dtMs:{2}, execMs:{3}, outMs:{4}, ts:{5}, dts={6}",
                                      OutputDevice.Name, nowMs, dtMs, execMs, outputMs, sampinfo, dtMs2);
                    }

                    // wait for the next go 'round
                    _WaitOnSignal(signaler);
                    _WaitOnPause();
                }

                _threadState = ExecutionState.Stopped;
                _finished.Set();
            }
            catch (Exception ex) {
                // Do this before calling OnError so that we can be in the stopped state.
                // Otherwise, we'll have a deadlock as the event causes a shutdown which
                // waits for the thread to end.
                _threadState = ExecutionState.Stopped;
                _finished.Set();

                Logging.ErrorException(string.Format("Controller {0} error", OutputDevice.Name), ex);
                OnError();
            }
        }