Exemplo n.º 1
0
 public void SleepOrNot(ISpread <string> spread, string tasko, int posInLoop)
 {
     if (FMachineGun[0])
     {
         if (posInLoop < (spread.Count() - 1))
         {
             alreadySleeping = true;
             MakeTaskWait(tasko);
         }
     }
 }
Exemplo n.º 2
0
        public void Evaluate(int spreadmax)
        {
            if (FInClient.IsConnected)
            {
                if (FClient == null && FInClient[0] != null)
                {
                    FClient = FInClient[0];
                    FClient.MqttMsgPublished += FClient_MqttMsgPublished;
                }
                if (FClient != null && FInClient[0] == null)
                {
                    FClient.MqttMsgPublished -= FClient_MqttMsgPublished;
                    FClient = null;
                }

                if (FClient != null && FClient.IsConnected && FInTopic.Count() > 0 && FInMessage.Count() > 0)
                {
                    for (int i = 0; i < spreadmax; i++)
                    {
                        if (FInSend[i])
                        {
                            if (FInTopic[i].Contains("/#") || FInTopic[i].Contains("/*"))
                            {
                                FMessageStatusQueue.Enqueue("Topic at slice " + i.ToString() + " contains illegal characters for publishing");
                            }
                            else
                            {
                                //Converting incoming stream into byte[] and publishing it
                                using (MemoryStream ms = new MemoryStream())
                                {
                                    FInMessage[i].CopyTo(ms);
                                    var packetId = FClient.Publish(FInTopic[i], ms.ToArray(), (byte)FInQoS[i], FInRetained[i]);
                                    FPublishStatus.Add(packetId);
                                }
                            }
                        }
                        if (FInRemoveRetained[i])
                        {
                            FClient.Publish(FInTopic[i], new byte[] { }, (byte)0, true);
                        }
                    }
                }
            }

            if (FMessageStatusQueue.Count > 0)
            {
                FOutMessageStatus.AssignFrom(FMessageStatusQueue.ToArray());
                FMessageStatusQueue.Clear();
            }
        }
        public void Evaluate(int SpreadMax)
        {
            var sprmax = SetSliceCount();

            for (int i = sprmax - 1; i >= 0; i--)
            {
                if (FOut[i] == null)
                {
                    FOut[i] = CreateObject(i);
                }
                else if (FOut.Count(o => o?.Equals(FOut[i]) ?? false) > 1)
                {
                    FOut[i] = CreateObject(i);
                }
                var obj = FOut[i];
                UpdateObject(obj, i);
            }
        }
Exemplo n.º 4
0
        public static void UpdateBlobs(ISpread <Blob> allBlobs, ISpread <Blob> currentBlobs, int id)
        {
            Debug.WriteLine(allBlobs.SliceCount + " " + currentBlobs.SliceCount);
            for (var i = 0; i < currentBlobs.Count(); i++)
            {
                var found = false;

                for (var j = 0; j < allBlobs.Count(); j++)
                {
                    //Check if blob exists
                    if (currentBlobs[i].Id != allBlobs[j].Id)
                    {
                        continue;
                    }

                    //Check if blob not hited another object
                    if (allBlobs[j].HitId > 0 && allBlobs[j].HitId != id)
                    {
                        continue;
                    }

//					if (currentBlobs.SliceCount > 2)
//					{
//						Debug.WriteLine(allBlobs);
//					}

                    currentBlobs[i] = allBlobs[j];
                    found           = true;
                    break;
                }

                if (!found)
                {
                    currentBlobs.RemoveAt(i);
                }
            }
        }
Exemplo n.º 5
0
        public static void UpdateBlobs(ISpread<Blob> allBlobs, ISpread<Blob> currentBlobs, int id)
        {
            for (var i = 0; i < currentBlobs.Count(); i++)
            {
                var found = false;

                for (var j = 0; j < allBlobs.Count(); j++)
                {
                    //Check if blob exists
                    if (currentBlobs[i].Id != allBlobs[j].Id) continue;

                    //Check if blob not hited another object
                    //TODO: Find, if this needed or not.
                    //if(allBlobs[j].HitId > 0 && allBlobs[j].HitId != id) continue;

                    currentBlobs[i] = allBlobs[j];
                    found = true;
                    break;
                }

                if(!found) currentBlobs.RemoveAt(i);
            }
        }
Exemplo n.º 6
0
        public static Vector2D FindCentroid(ISpread<Blob> blobs)
        {
            var summ = new Vector2D();

            return blobs.Aggregate(summ, (current, blob) => current + blob.Position) / blobs.Count();
        }
Exemplo n.º 7
0
        public static Vector2D FindCentroid(ISpread <Blob> blobs)
        {
            var summ = new Vector2D();

            return(blobs.Aggregate(summ, (current, blob) => current + blob.Position) / blobs.Count());
        }
Exemplo n.º 8
0
        public void Evaluate(int SpreadMax)
        {
            if (FWrite[0])
            {
                FOutSucess[0] = false;

                StringBuilder sb = new StringBuilder();

                sb.AppendLine("o Object1");

                foreach (var vert in FVert)
                {
                    sb.Append("v ");
                    sb.Append(vert.x.ToString("0.0000", CultureInfo.InvariantCulture) + " ");
                    sb.Append(vert.y.ToString("0.0000", CultureInfo.InvariantCulture) + " ");
                    sb.Append((-vert.z).ToString("0.0000", CultureInfo.InvariantCulture));
                    sb.AppendLine();
                }

                sb.AppendLine();

                foreach (var norm in FNormal)
                {
                    sb.Append("vn ");
                    sb.Append(norm.x.ToString("0.0000", CultureInfo.InvariantCulture) + " ");
                    sb.Append(norm.y.ToString("0.0000", CultureInfo.InvariantCulture) + " ");
                    sb.Append((-norm.z).ToString("0.0000", CultureInfo.InvariantCulture));
                    sb.AppendLine();
                }

                sb.AppendLine();

                foreach (var uv in FUV)
                {
                    sb.Append("vt ");
                    sb.Append(uv.x.ToString("0.0000", CultureInfo.InvariantCulture) + " ");
                    sb.Append((1 - uv.y).ToString("0.0000", CultureInfo.InvariantCulture));
                    sb.AppendLine();
                }

                sb.AppendLine();

                sb.Append("g Default");
                sb.AppendLine();



                for (int i = 1; i < FVert.Count() + 1; i += 3)
                {
                    sb.Append("f ");

                    sb.Append((i + 2).ToString(CultureInfo.InvariantCulture) + "/");
                    sb.Append((i + 2).ToString(CultureInfo.InvariantCulture) + "/");
                    sb.Append((i + 2).ToString(CultureInfo.InvariantCulture) + " ");

                    sb.Append((i + 1).ToString(CultureInfo.InvariantCulture) + "/");
                    sb.Append((i + 1).ToString(CultureInfo.InvariantCulture) + "/");
                    sb.Append((i + 1).ToString(CultureInfo.InvariantCulture) + " ");

                    sb.Append(i.ToString(CultureInfo.InvariantCulture) + "/");
                    sb.Append(i.ToString(CultureInfo.InvariantCulture) + "/");
                    sb.Append(i.ToString(CultureInfo.InvariantCulture));

                    sb.AppendLine();
                }

                try
                {
                    StreamWriter sw = new StreamWriter(FPath[0], false, System.Text.Encoding.UTF8);
                    sw.Write(sb);
                    sw.Close();

                    FOutSucess[0] = true;
                    FOutDebug[0]  = sb.ToString();
                }
                catch (Exception e)
                {
                    FOutSucess[0] = false;
                    FOutDebug[0]  = e.Message;
                }
            }
        }
Exemplo n.º 9
0
        public static void UpdateBlobs(ISpread<Blob> allBlobs, ISpread<Blob> currentBlobs, int id)
        {
            Debug.WriteLine(allBlobs.SliceCount + " " + currentBlobs.SliceCount);
            for (var i = 0; i < currentBlobs.Count(); i++)
            {
                var found = false;

                for (var j = 0; j < allBlobs.Count(); j++)
                {
                    //Check if blob exists
                    if (currentBlobs[i].Id != allBlobs[j].Id) continue;

                    //Check if blob not hited another object
                    if(allBlobs[j].HitId > 0 && allBlobs[j].HitId != id) continue;

            //					if (currentBlobs.SliceCount > 2)
            //					{
            //						Debug.WriteLine(allBlobs);
            //					}

                    currentBlobs[i] = allBlobs[j];
                    found = true;
                    break;
                }

                if(!found) currentBlobs.RemoveAt(i);
            }
        }