Exemple #1
0
        void Update()
        {
            if (!updateAutomatically && !_isPerformingManualUpdate)
            {
                return;
            }

            // prepare threads
            if (multithreaded)
            {
                if (_threadPool == null)
                {
                    _threadPool = new FogOfWarThreadPool();
                }

                // do some thread maintenance
                threads = Mathf.Clamp(threads, 2, 8);
                _threadPool.maxThreads = threads;
                _threadPool.Clean();
            }
            else if (_threadPool != null)
            {
                _threadPool.StopAllThreads();
                _threadPool = null;
            }

            _stopwatch.Reset();
            _stopwatch.Start();

            // draw unit shapes
            ProcessUnits(_stopwatch);

            // compile final texture
            _timeSinceLastUpdate += Time.deltaTime;
            CompileFinalTexture(ref _timeSinceLastUpdate, true);

            _stopwatch.Stop();
        }
Exemple #2
0
        void Update()
        {
            // prepare threads
            if (multithreaded)
            {
                if (_threadPool == null)
                {
                    _threadPool = new FogOfWarThreadPool();
                }
                threads = Mathf.Clamp(threads, 2, 8);
                _threadPool.maxThreads = threads;
                _threadPool.Clean();
            }
            else if (_threadPool != null)
            {
                _threadPool.StopAllThreads();
                _threadPool = null;
            }

            _stopwatch.Reset();
            _stopwatch.Start();

            // draw shapes
            ProcessUnits();

            // compile final texture
            _timeSinceLastUpdate += Time.deltaTime;
            if (_currentUnitProcessing >= FogOfWarUnit.registeredUnits.Count && (!multithreaded || _threadPool.hasAllFinished))
            {
                _drawer.GetValues(_fogValuesCopy);
                _currentUnitProcessing = 0;

                // prepare texture
                if (fogTexture == null)
                {
                    fogTexture            = new Texture2D(mapResolution.x, mapResolution.y, TextureFormat.Alpha8, false);
                    fogTexture.wrapMode   = TextureWrapMode.Clamp;
                    fogTexture.filterMode = filterMode;
                }
                else if (fogTexture.width != mapResolution.x || fogTexture.height != mapResolution.y)
                {
                    fogTexture.Resize(mapResolution.x, mapResolution.y, TextureFormat.Alpha8, false);
                }
                else
                {
                    fogTexture.filterMode = filterMode;
                }
                fogTexture.LoadRawTextureData(_fogValuesCopy);
                fogTexture.Apply();

                // apply blur
                _finalFogTexture = _blur.Apply(fogTexture, mapResolution, blurAmount, blurIterations, blurType);

                // fade in fog
                _fadeAmount += fadeSpeed * _timeSinceLastUpdate;
                byte fadebytes = (byte)(_fadeAmount * 255);
                if (fadebytes > 0)
                {
                    _drawer.Fade((byte)(partialFogAmount * 255), fadebytes);
                    _fadeAmount -= fadebytes / 255.0f;
                }

                _timeSinceLastUpdate = 0;

                if (!_isFirstProcessingFrame)
                {
                    ProcessUnits();
                }
                _isFirstProcessingFrame = true;
            }
            else
            {
                _isFirstProcessingFrame = false;
            }

            _stopwatch.Stop();
        }