/// <summary>
        /// Renders all tiles in a given scale
        /// </summary>
        /// <param name="scaleindex">The scale to render</param>
        /// <param name="group">The name of the baselayer group</param>
        public void RenderScale(int scaleindex, string group)
        {
            m_parent.InvokeBeginRendering(this, group, scaleindex);

            if (!m_parent.Cancel)
            {
                int rows          = (int)m_dimensions[scaleindex][0];
                int cols          = (int)m_dimensions[scaleindex][1];
                int rowTileOffset = (int)m_dimensions[scaleindex][2];
                int colTileOffset = (int)m_dimensions[scaleindex][3];

                //If the MaxExtents are different from the actual bounds, we need a start offset offset

                using (var settings = new RenderThreads(this, m_parent, m_scaleindexmap[scaleindex], group, m_tileSetResourceID, rows, cols, rowTileOffset, colTileOffset, m_parent.Config.RandomizeTileSequence))
                {
                    settings.RunAndWait();

                    if (settings.TileSet.Count != 0 && !m_parent.Cancel)
                    {
                        throw new Exception(Strings.TS_ThreadFailureError);
                    }
                }
            }

            m_parent.InvokeFinishRendering(this, group, scaleindex);
        }
Ejemplo n.º 2
0
        public void RunAndWait()
        {
            ThreadPool.QueueUserWorkItem(QueueFiller);
            for (int i = 0; i < _parent.Config.ThreadCount; i++)
            {
                ThreadPool.QueueUserWorkItem(ThreadRender);
            }

            bool completed = false;

            while (!completed)
            {
                EventPassing eventToRaise = null;
                while (true)
                {
                    lock (_syncLock)
                    {
                        if (_raiseEvents.Count > 0)
                        {
                            eventToRaise = _raiseEvents.Dequeue();
                        }
                    }

                    if (eventToRaise == null)
                    {
                        //No more events
                        break;
                    }
                    else
                    {
                        switch (eventToRaise.Type)
                        {
                        case EventPassing.EventType.Begin:
                            _parent.InvokeBeginRendering(
                                _invoker,
                                _group,
                                _scale,
                                eventToRaise.Row,
                                eventToRaise.Col);
                            break;

                        case EventPassing.EventType.Finish:
                            _parent.InvokeFinishRendering(
                                _invoker,
                                _group,
                                _scale,
                                eventToRaise.Row,
                                eventToRaise.Col);
                            break;

                        case EventPassing.EventType.Error:
                            eventToRaise.Result = _parent.InvokeError(
                                _invoker,
                                _group,
                                _scale,
                                eventToRaise.Row,
                                eventToRaise.Col,
                                eventToRaise.Exception);
                            break;

                        default:
                            //Not translated, because it is an internal error that should never happen
                            throw new Exception("Bad event type");     //NOXLATE
                        }
                        eventToRaise.Event.Set();
                        eventToRaise = null;
                    }
                }

                lock (_syncLock)
                {
                    if (_completeFlag == 0 && _raiseEvents.Count == 0)
                    {
                        completed = true;
                    }
                }

                if (!completed)
                {
                    _event.WaitOne(5 * 1000, true);
                }
            }
        }