Esempio n. 1
0
        public override void Connect(ServerInfo serverInfo)
        {
            if (Connected)
            {
                throw new ProtocolException("Connection error: Already connected to server.");
            }

            foreach (var modAPI in ModAPIs)
            {
                modAPI.OnConnect(serverInfo);
            }


            // -- Connect to server.
            Stream.Connect(serverInfo.Address.IP, serverInfo.Address.Port);

            // -- Begin data reading.
            if (ReadThread != null && ReadThread.IsRunning)
            {
                throw new ProtocolException("Connection error: Thread already running.");
            }
            else
            {
                ReadThread = ThreadWrapper.Create(ReadCycle);
                ReadThread.IsBackground = true;
                ReadThread.Name         = "PacketReaderThread";
                ReadThread.Start();
            }
        }
        public ManagedThreadPool(int maxThreads)
        {
            _maxThreads = maxThreads;

            _queue             = new BlockingCollection <ThreadTaskInfo>();
            _workerThreads     = new ThreadWrapper[_maxThreads];
            _cancelTS          = new CancellationTokenSource();
            _activeThreadCount = 0;

            for (int i = 0; i < _maxThreads; i++)
            {
                _workerThreads[i] = ThreadWrapper.Create(ProcessQueue, _cancelTS.Token);
            }
        }
        private void CalcAverageColor(Action <object> OnComplete)
        {
            if (SrcTexture == null)
            {
                return;
            }

            Texture2D tex = (Texture2D)SrcTexture;

            if (tex != null)
            {
                var pixels = tex.GetPixels();

                ThreadWrapper.Create(
                    () =>
                {
                    float r_avg = 0;
                    float g_avg = 0;
                    float b_avg = 0;
                    foreach (var c in pixels)
                    {
                        r_avg += c.r;
                        g_avg += c.g;
                        b_avg += c.b;
                    }

                    r_avg /= pixels.Length;
                    g_avg /= pixels.Length;
                    b_avg /= pixels.Length;

                    float rgb_avg = (r_avg + g_avg + b_avg) / 3f;

                    return(new Color(r: r_avg / rgb_avg,
                                     g: g_avg / rgb_avg,
                                     b: b_avg / rgb_avg));
                },
                    OnComplete,
                    (error) =>
                {
                    Debug.Log("Error : " + error);
                }
                    );
            }
        }
Esempio n. 4
0
        public override void SetupMaterial()
        {
            if (SrcTexture == null)
            {
                return;
            }

            Texture2D tex = (Texture2D)SrcTexture;

            if (tex != null)
            {
                var pixels = tex.GetPixels32();

                ThreadWrapper.Create(
                    () =>
                {
                    var histogramm = new RGBHistogramm();
                    histogramm.AddColors(pixels);
                    histogramm.CalculateCDFValues();
                    var count = pixels.Length;

                    for (int i = 0; i < count; i++)
                    {
                        pixels[i] = histogramm.AligementedColor2RGB(pixels[i], count);
                    }

                    return(pixels);
                },
                    (processedPixeles) =>
                {
                    tex.SetPixels32((Color32[])processedPixeles);
                    tex.Apply();
                },
                    (error) =>
                {
                    Debug.Log("Error : " + error);
                }
                    );
            }
        }