Esempio n. 1
0
        public void Apply(Mat src)
        {
            using (ResourceTracker t = new ResourceTracker())
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                Size srcSize = src.Size();

                //todo: 只对脸部进行亮肤https://blog.csdn.net/cnbloger/article/details/77949949
                //https://blog.csdn.net/skyqsdyy/article/details/89467143
                //todo: 对src进行美颜、瘦脸、亮肤等。只要控制在一帧50ms之内即可。
                Mat matMask = t.NewMat(srcSize, MatType.CV_8UC1, new Scalar(0));
                RenderGreenScreenMask(src, matMask);
                //the area is by integer instead of double, so that it can improve the performance of comparision of areas
                int minBlockArea = (int)(srcSize.Width * srcSize.Height * this.MinBlockPercent);
                var contoursExternalForeground = Cv2.FindContoursAsArray(matMask, RetrievalModes.External, ContourApproximationModes.ApproxNone)
                                                 .Select(c => new { contour = c, Area = (int)Cv2.ContourArea(c) })
                                                 .Where(c => c.Area >= minBlockArea)
                                                 .OrderByDescending(c => c.Area).Take(5).Select(c => c.contour);
                //contoursExternalForeground = contoursExternalForeground.Select(c=>Cv2.ApproxPolyDP(c,0.5,true));

                //a new Mat used for rendering the selected Contours
                var matMaskForeground = t.NewMat(srcSize, MatType.CV_8UC1, new Scalar(0));
                //thickness: -1 means filling the inner space
                matMaskForeground.DrawContours(contoursExternalForeground, -1, new Scalar(255),
                                               thickness: -1);

                //matInternalHollow is the inner Hollow parts of body part.
                var matInternalHollow = t.NewMat(srcSize, MatType.CV_8UC1, new Scalar(0));
                Cv2.BitwiseXor(matMaskForeground, matMask, matInternalHollow);

                int minHollowArea = (int)(minBlockArea * 0.5);//the lower size limitation of InternalHollow is less than minBlockArea, because InternalHollows are smaller
                //find the Contours of Internal Hollow
                var contoursInternalHollow = Cv2.FindContoursAsArray(matInternalHollow, RetrievalModes.External, ContourApproximationModes.ApproxNone)
                                             .Select(c => new { contour = c, Area = Cv2.ContourArea(c) })
                                             .Where(c => c.Area >= minHollowArea)
                                             .OrderByDescending(c => c.Area).Take(10).Select(c => c.contour);
                //draw hollows
                foreach (var c in contoursInternalHollow)
                {
                    matMaskForeground.FillConvexPoly(c, new Scalar(0));
                }

                var element = t.T(Cv2.GetStructuringElement(MorphShapes.Cross, new Size(3, 3)));
                //smooth the edge of matMaskForeground
                Cv2.MorphologyEx(matMaskForeground, matMaskForeground, MorphTypes.Close,
                                 element, iterations: 6);
                Cv2.GaussianBlur(matMaskForeground, matMaskForeground, new Size(3, 3), 0, 0);

                var foreground = t.NewMat(src.Size(), MatType.CV_8UC4, new Scalar(0));
                ZackCVHelper.AddAlphaChannel(src, foreground, matMaskForeground);
                //resize the _backgroundImage to the same size of src
                Cv2.Resize(_backgroundImage, src, src.Size());

                //draw foreground(people) on the backgroundimage
                ZackCVHelper.DrawOverlay(src, foreground);
                Debug.WriteLine($"5:{sw.ElapsedMilliseconds}");
            }
        }
Esempio n. 2
0
 static bool Prefix(ResourceTracker __instance)
 {
     if (Enumerable.Range(70, 15).Contains((int)CraftData.GetTechType(__instance.gameObject)))
     {
         __instance.overrideTechType = TechType.None;
     }
     return(true);
 }
Esempio n. 3
0
        public static void Clear()
        {
            textures.ForEach(tex => tex.Dispose());

            Palette             = Palette.CreateDefault();
            textures            = new ResourceTracker <Texture>();
            loadedImages        = new ResourceTracker <RgbaImage>();
            missingTextureNames = new HashSet <UpperString>();
        }
Esempio n. 4
0
 static void BeautyIt(Mat src)
 {
     using (ResourceTracker t = new ResourceTracker())
     {
         Mat dst = t.NewMat();
         Cv2.BilateralFilter(src, dst, 15, 35, 35);
         dst.CopyTo(src);
     }
 }
        public static void Collect_Prefix(TimeCapsule __instance)
        {
            ResourceTracker resourceTracker = __instance.gameObject.GetComponent <ResourceTracker>();

            if (resourceTracker != null)
            {
                resourceTracker.Unregister();
            }
        }
        public override GameObject GetGameObject()
        {
            if (processedPrefab is null)
            {
                GameObject prefab     = Main.assetBundle.LoadAsset <GameObject>("TechPistol.prefab");
                GameObject gameObject = GameObject.Instantiate(prefab);
                gameObject.SetActive(false);
                prefab.SetActive(false);

                gameObject.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
                gameObject.transform.localPosition   += Vector3.up * 2;

                Renderer[] componentsInChildren = gameObject.transform.Find("HandGun").gameObject.GetComponentsInChildren <Renderer>();
                foreach (Renderer renderer in componentsInChildren)
                {
                    if (renderer.name.StartsWith("Gun") || renderer.name.StartsWith("Target"))
                    {
                        Texture emissionMap = renderer.material.GetTexture("_EmissionMap");
                        Texture specMap     = renderer.material.GetTexture("_MetallicGlossMap");

                        renderer.material.shader = Shader.Find("MarmosetUBER");
                        renderer.material.EnableKeyword("MARMO_EMISSION");
                        renderer.material.EnableKeyword("MARMO_SPECMAP");
                        renderer.material.SetTexture(ShaderPropertyID._Illum, emissionMap);
                        renderer.material.SetTexture(ShaderPropertyID._SpecTex, specMap);
                        renderer.material.SetColor("_GlowColor", new Color(1f, 1f, 1f));
                        renderer.material.SetFloat(ShaderPropertyID._GlowStrength, 1f);
                        renderer.material.SetFloat(ShaderPropertyID._GlowStrengthNight, 1f);
                    }
                }

                GameObject.Destroy(gameObject.transform.Find(PistolBehaviour.GunMain + "/ModeChange")?.gameObject);
                GameObject.Destroy(gameObject.transform.Find(PistolBehaviour.Point)?.gameObject);
                GameObject.Destroy(gameObject.GetComponent <PistolBehaviour>());
                GameObject.Destroy(gameObject.GetComponent <EnergyMixin>());
                GameObject.Destroy(gameObject.GetComponent <VFXFabricating>());

                PrefabIdentifier prefabIdentifier = gameObject.GetComponent <PrefabIdentifier>();
                prefabIdentifier.ClassId = this.ClassID;
                gameObject.GetComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.VeryFar;
                gameObject.GetComponent <TechTag>().type = this.TechType;

                Pickupable pickupable = gameObject.GetComponent <Pickupable>();
                pickupable.isPickupable = false;

                ResourceTracker resourceTracker = gameObject.EnsureComponent <ResourceTracker>();
                resourceTracker.prefabIdentifier = prefabIdentifier;
                resourceTracker.techType         = this.TechType;
                resourceTracker.overrideTechType = TechType.Fragment;
                resourceTracker.rb         = gameObject.GetComponent <Rigidbody>();
                resourceTracker.pickupable = pickupable;

                processedPrefab = gameObject;
            }
            return(processedPrefab);
        }
        private GameObject PreparePrefab(GameObject thisPrefab)
        {
            if (thisPrefab == null)
            {
                Log.LogError("ModifyInstantiatedPrefab called with null prefab!");
                return(null);
            }

            var obj = GameObject.Instantiate(thisPrefab);

            MeshRenderer[]        meshRenderers        = obj.GetAllComponentsInChildren <MeshRenderer>();
            SkinnedMeshRenderer[] skinnedMeshRenderers = obj.GetAllComponentsInChildren <SkinnedMeshRenderer>();
            Color powerGlideColour = PowerglideBehaviour.PowerGlideColour;

            foreach (MeshRenderer mr in meshRenderers)
            {
                // MeshRenderers have the third-person mesh, apparently?
                if (mr.name.Contains("SeaGlide_01_damaged"))
                {
                    mr.material.color = powerGlideColour;
                }
            }

            foreach (SkinnedMeshRenderer smr in skinnedMeshRenderers)
            {
                if (smr.name.Contains("SeaGlide_geo"))
                {
                    smr.material.color = powerGlideColour;
                }
            }

            PrefabIdentifier prefabIdentifier = obj.EnsureComponent <PrefabIdentifier>();

            prefabIdentifier.ClassId = this.ClassID;
            obj.EnsureComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.VeryFar;
            obj.EnsureComponent <TechTag>().type = this.TechType;

            Pickupable pickupable = obj.EnsureComponent <Pickupable>();

            pickupable.isPickupable = false;

            ResourceTracker resourceTracker = obj.EnsureComponent <ResourceTracker>();

            resourceTracker.prefabIdentifier = prefabIdentifier;
            typeof(ResourceTracker).GetField("techType", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(resourceTracker, this.TechType);
            //resourceTracker.techType = this.TechType;
            resourceTracker.overrideTechType = TechType.Fragment;
            resourceTracker.techType         = Main.GetModTechType("PowerglideFragment");
            resourceTracker.rb         = obj.GetComponent <Rigidbody>();
            resourceTracker.pickupable = pickupable;

            ModPrefabCache.AddPrefab(obj, false); // This doesn't actually do any caching, but it does disable the prefab without "disabling" it - the prefab doesn't show up in the world [as with SetActive(false)]
            // but it can still be instantiated. [unlike with SetActive(false)]

            return(obj);
        }
        public static void Start_Postfix(TimeCapsule __instance)
        {
            ResourceTracker resourceTracker = __instance.gameObject.EnsureComponent <ResourceTracker>();

            resourceTracker.prefabIdentifier = __instance.GetComponent <PrefabIdentifier>();
            resourceTracker.techType         = TechType.TimeCapsule;
            resourceTracker.overrideTechType = TechType.TimeCapsule;
            resourceTracker.rb         = __instance.gameObject.GetComponent <Rigidbody>();
            resourceTracker.pickupable = __instance.gameObject.GetComponent <Pickupable>();
        }
        public static void PostUnregister(ref ResourceTracker __instance)
        {
            string uniqueId = (string)uniqueIdInfo.GetValue(__instance);

            if (!string.IsNullOrEmpty(uniqueId))
            {
                IdToGameObjectDict.Remove(uniqueId);
                IdToTechTypeDict.Remove(uniqueId);
                IdToResourceNameDict.Remove(uniqueId);
            }
        }
Esempio n. 10
0
        public static void Postfix(ResourceTracker __instance)
        {
            TechType techType = (TechType)__instance.GetPrivateField("techType");

            if (techType == TechType.UraniniteCrystal)
            {
                __instance.gameObject.AddIfNeedComponent <Radiation_UraniniteCrystal>();

                Main.PrintLOG($"Radiation_UraniniteCrystal component added to gameobject: {__instance.gameObject.name}");
            }
        }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        ResourceTracker myScript = (ResourceTracker)target;

        if (GUILayout.Button("SetUpSheet"))
        {
            myScript.GatherData();
        }
    }
    private void RefreshCharts()
    {
        float time = GameClock.Instance.GetTime();
        float num  = 3000f;

        foreach (KeyValuePair <Tag, GameObject> categoryRow in categoryRows)
        {
            HierarchyReferences component         = categoryRow.Value.GetComponent <HierarchyReferences>();
            ResourceTracker     resourceStatistic = TrackerTool.Instance.GetResourceStatistic(ClusterManager.Instance.activeWorldId, categoryRow.Key);
            if (resourceStatistic != null)
            {
                SparkLayer             reference = component.GetReference <SparkLayer>("Chart");
                Tuple <float, float>[] array     = resourceStatistic.ChartableData(num);
                if (array.Length != 0)
                {
                    reference.graph.axis_x.max_value = array[array.Length - 1].first;
                }
                else
                {
                    reference.graph.axis_x.max_value = 0f;
                }
                reference.graph.axis_x.min_value = time - num;
                reference.RefreshLine(array, "resourceAmount");
            }
            else
            {
                DebugUtil.DevLogError("DevError: No tracker found for resource category " + categoryRow.Key);
            }
        }
        foreach (KeyValuePair <Tag, GameObject> resourceRow in resourceRows)
        {
            HierarchyReferences component          = resourceRow.Value.GetComponent <HierarchyReferences>();
            ResourceTracker     resourceStatistic2 = TrackerTool.Instance.GetResourceStatistic(ClusterManager.Instance.activeWorldId, resourceRow.Key);
            if (resourceStatistic2 != null)
            {
                SparkLayer             reference2 = component.GetReference <SparkLayer>("Chart");
                Tuple <float, float>[] array2     = resourceStatistic2.ChartableData(num);
                if (array2.Length != 0)
                {
                    reference2.graph.axis_x.max_value = array2[array2.Length - 1].first;
                }
                else
                {
                    reference2.graph.axis_x.max_value = 0f;
                }
                reference2.graph.axis_x.min_value = time - num;
                reference2.RefreshLine(array2, "resourceAmount");
            }
            else
            {
                DebugUtil.DevLogError("DevError: No tracker found for resource " + resourceRow.Key);
            }
        }
    }
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            if (processedPrefab == null)
            {
                CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SeaglideFragment);
                yield return(task);

                GameObject prefab = GameObject.Instantiate(task.GetResult());

                MeshRenderer[]        meshRenderers        = prefab.GetAllComponentsInChildren <MeshRenderer>();
                SkinnedMeshRenderer[] skinnedMeshRenderers = prefab.GetAllComponentsInChildren <SkinnedMeshRenderer>();
                Color powerGlideColour = new Color(PowerglideEquipable.PowerglideColourR, PowerglideEquipable.PowerglideColourG, PowerglideEquipable.PowerglideColourB);

                foreach (MeshRenderer mr in meshRenderers)
                {
                    // MeshRenderers have the third-person mesh, apparently?
                    if (mr.name.Contains("SeaGlide_01_damaged"))
                    {
                        mr.material.color = powerGlideColour;
                    }
                }

                foreach (SkinnedMeshRenderer smr in skinnedMeshRenderers)
                {
                    if (smr.name.Contains("SeaGlide_geo"))
                    {
                        smr.material.color = powerGlideColour;
                    }
                }

                PrefabIdentifier prefabIdentifier = prefab.GetComponent <PrefabIdentifier>();
                prefabIdentifier.ClassId = this.ClassID;
                prefab.GetComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.VeryFar;
                prefab.EnsureComponent <TechTag>().type            = this.TechType;

                Pickupable pickupable = prefab.GetComponent <Pickupable>();
                pickupable.isPickupable = false;

                ResourceTracker resourceTracker = prefab.EnsureComponent <ResourceTracker>();
                resourceTracker.prefabIdentifier = prefabIdentifier;
                typeof(ResourceTracker).GetField("techType", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(resourceTracker, this.TechType);
                //resourceTracker.techType = this.TechType;
                resourceTracker.overrideTechType = TechType.Fragment;
                resourceTracker.rb         = prefab.GetComponent <Rigidbody>();
                resourceTracker.pickupable = pickupable;

                prefab.SetActive(true);
                processedPrefab = prefab;
                ModPrefabCache.AddPrefab(processedPrefab, false); // This doesn't actually do any caching, but it does disable the prefab without "disabling" it - the prefab doesn't show up in the world [as with SetActive(false)]
                // but it can still be instantiated. [unlike with SetActive(false)]
            }

            gameObject.Set(processedPrefab);
        }
Esempio n. 14
0
        /// <summary>
        /// Initializes the service relationships.
        /// </summary>
        protected virtual void Initialise()
        {
            PayloadSerializer.Start();
            ResourceTracker.Start();

            Scheduler.Collector = Collector;
            Scheduler.Start();

            ResourceTracker.Collector      = Collector;
            ResourceTracker.SharedServices = SharedService;
            ResourceTracker.Start();
        }
        /// <summary>
        /// Initializes the service relationships.
        /// </summary>
        protected virtual void Initialise()
        {
            ServiceHandlers?.Start();
            ResourceTracker.Start();

            Scheduler.Collector = Collector;
            Scheduler.Start();

            ResourceTracker.Collector      = Collector;
            ResourceTracker.SharedServices = SharedService;
            ResourceTracker.Start();
        }
        static void untrack(ResourceTracker rt)
        {
            if (!rt)
            {
                return;
            }
            $"DebrisTracker: object untracked {rt.name}".logDbg();
            trackedDebris.Remove(rt.prefabIdentifier.Id);

            rt.Unregister();
            Object.Destroy(rt);
        }
        public static void Start()
        {
            IPEndPoint      address       = new IPEndPoint(0);
            Configuration   configuration = new Configuration();
            ResourceTracker instance      = new TestResourceTrackerPBClientImpl.ResourceTrackerTestImpl
                                                ();

            server = RpcServerFactoryPBImpl.Get().GetServer(typeof(ResourceTracker), instance
                                                            , address, configuration, null, 1);
            server.Start();
            client = (ResourceTracker)RpcClientFactoryPBImpl.Get().GetClient(typeof(ResourceTracker
                                                                                    ), 1, NetUtils.GetConnectAddress(server), configuration);
        }
Esempio n. 18
0
        public static void Postfix(Creature __instance)
        {
            TechType techType = CraftData.GetTechType(__instance.gameObject);

            if (techType == TechType.SeaDragon)
            {
                ResourceTracker resourceTracker = __instance.gameObject.EnsureComponent <ResourceTracker>();
                resourceTracker.prefabIdentifier = __instance.gameObject.GetComponent <PrefabIdentifier>();
                resourceTracker.techType         = TechType.SeaDragon;
                resourceTracker.overrideTechType = TechType.SeaDragon;
                resourceTracker.rb         = __instance.gameObject.GetComponent <Rigidbody>();
                resourceTracker.pickupable = __instance.gameObject.GetComponent <Pickupable>();
            }
        }
        public override GameObject GetGameObject()
        {
            GameObjectClone = CraftData.InstantiateFromPrefab(FragmentTemplate);

            ResourceTracker resourceTracker = GameObjectClone.GetComponent <ResourceTracker>();

            resourceTracker.overrideTechType = TechType.Fragment;

            //GameObjectClone.EnsureComponent<FragmentTracker>();

            ModifyGameObject();

            return(GameObjectClone);
        }
Esempio n. 20
0
            public PortScannerManager(IPAddress hostIP, UInt16 minPort, UInt16 maxPort,
                                      UInt16 maxThreads, TimeSpan timeout, UInt32 sleepTime)
            {
                this.hostIP     = hostIP;
                this.minPort    = minPort;
                this.maxPort    = maxPort;
                this.maxThreads = maxThreads;
                this.timeout    = timeout;
                this.sleepTime  = sleepTime;

                this.threadTracker = new ResourceTracker(maxThreads);

                this.portStatus = new Boolean[maxPort - minPort + 1];
            }
Esempio n. 21
0
        public static string ScriptInclude(this AjaxHelper helper, params string[] url)
        {
            var tracker = new ResourceTracker(helper.ViewContext.HttpContext);

            var sb = new StringBuilder();
            foreach (var item in url)
            {
                if (!tracker.Contains(item))
                {
                    tracker.Add(item);
                    sb.AppendFormat("<script type='text/javascript' src='{0}'></script>", item);
                    sb.AppendLine();
                }
            }
            return sb.ToString();
        }
Esempio n. 22
0
        public override GameObject GetGameObject()
        {
            GameObject prefab = Resources.Load <GameObject>("WorldEntities/Natural/drillable/DrillableSulphur");

            prefab.SetActive(false);
            GameObject obj = GameObject.Instantiate(prefab);

            obj.EnsureComponent <TechTag>().type             = this.TechType;
            obj.EnsureComponent <PrefabIdentifier>().classId = this.ClassID;
            obj.EnsureComponent <SkyApplier>().enabled       = true;
            ResourceTracker rt = obj.EnsureComponent <ResourceTracker>();

            rt.overrideTechType = TechType.Sulphur;
            rt.techType         = TechType.Sulphur;

            obj.SetActive(true);
            return(obj);
        }
Esempio n. 23
0
        public static string DynamicCssInclude(this AjaxHelper helper, string url)
        {
            var tracker = new ResourceTracker(helper.ViewContext.HttpContext);
            if (tracker.Contains(url))
                return String.Empty;

            var sb = new StringBuilder();
            sb.AppendLine("<script type='text/javascript'>");
            sb.AppendLine("var link=document.createElement('link')");
            sb.AppendLine("link.setAttribute('rel', 'stylesheet');");
            sb.AppendLine("link.setAttribute('type', 'text/css');");
            sb.AppendFormat("link.setAttribute('href', '{0}');", url);
            sb.AppendLine();
            sb.AppendLine("var head = document.getElementsByTagName('head')[0];");
            sb.AppendLine("head.appendChild(link);");
            sb.AppendLine("</script>");
            return sb.ToString();
        }
Esempio n. 24
0
        public static void Postfix(Pickupable pickupable)
        {
            if (newgame && Main.config.Hardcore && !Utils.GetContinueMode() && pickupable.GetTechType() != TechType.FireExtinguisher)
            {
                CoroutineHost.StartCoroutine(GiveHardcoreScanner());
                newgame = false;
                SMLHelper.V2.Handlers.IngameMenuHandler.RegisterOnQuitEvent(() => newgame = true);
            }

            TechType techType = pickupable.GetTechType();

            PDAScanner.EntryData entryData  = PDAScanner.GetEntryData(techType);
            GameObject           gameObject = pickupable.gameObject;

            if (Main.config.ScanOnPickup && Inventory.main.container.Contains(TechType.Scanner) && entryData != null)
            {
                if (!PDAScanner.GetPartialEntryByKey(techType, out PDAScanner.Entry entry))
                {
                    entry = PDAScanner.Add(techType, 1);
                }
                if (entry != null)
                {
                    PDAScanner.partial.Remove(entry);
                    PDAScanner.complete.Add(entry.techType);
                    PDAScanner.NotifyRemove(entry);
                    PDAScanner.Unlock(entryData, true, true, true);
                    KnownTech.Add(techType, false);
                    if (gameObject != null)
                    {
                        gameObject.SendMessage("OnScanned", null, SendMessageOptions.DontRequireReceiver);
                    }
#if SN1
                    ResourceTracker.UpdateFragments();
#endif
                }
            }

            if (!Main.config.Hardcore && entryData == null)
            {
                KnownTech.Add(techType, true);
            }
        }
Esempio n. 25
0
        internal static void PostFix(ref ResourceTracker __instance)
        {
            bool isDataBox = __instance.overrideTechType == TechType.Databox || __instance.techType == TechType.Databox;

            if (!isDataBox)
            {
                return; // Not a data box, early exit
            }
            BlueprintHandTarget blueprint = __instance.GetComponentInParent <BlueprintHandTarget>();

            if (blueprint == null)
            {
                return; // safety check, but shouldn't happen
            }
            if (!blueprint.used)
            {
                return;                   // blueprint still unused
            }
            __instance.OnBreakResource(); // call this to invoke the "Unregister" method
        }
Esempio n. 26
0
        public static GameObject GetPrefabForTechTypePatch(GameObject __result, TechType techType, bool verbose = true)
        {
            Logger.Log(Logger.Level.Debug, $"GetPrefabForTechTypePatch running: TechType {techType.ToString()}");
            if (Main.config.NewScannables.Contains(techType))
            {
                Logger.Log(Logger.Level.Debug, $"Found TechType in NewScannables list");
                if (__result.GetComponent <ResourceTracker>() == null)
                {
                    Logger.Log(Logger.Level.Debug, $"No existing ResourceTracker found");
                    ResourceTracker rt = __result.EnsureComponent <ResourceTracker>();
                    if (rt != null)
                    {
                        Logger.Log(Logger.Level.Debug, $"Added new ResourceTracker");
                        rt = __result.EnsureComponent <ResourceTracker>();
                        rt.prefabIdentifier = __result.GetComponent <PrefabIdentifier>();
                        rt.techType         = TechType.SeaDragon;
                        rt.overrideTechType = TechType.SeaDragon;
                        rt.rb         = __result.GetComponent <Rigidbody>();
                        rt.pickupable = __result.GetComponent <Pickupable>();
                    }
                }
            }
            else if (Main.config.NonScannables.Contains(techType))
            {
                Logger.Log(Logger.Level.Debug, $"Found TechType in NonScannables list");
                ResourceTracker rt = __result.GetComponent <ResourceTracker>();
                if (rt != null)
                {
                    Logger.Log(Logger.Level.Debug, $"Attempting to destroy existing ResourceTracker");
                    UnityEngine.Object.Destroy(rt);
                }
                else
                {
                    Logger.Log(Logger.Level.Debug, $"No ResourceTracker found in prefab");
                }
            }

            return(__result);
        }
Esempio n. 27
0
 /// <exception cref="System.Exception"/>
 protected override void ServiceStart()
 {
     // NodeManager is the last service to start, so NodeId is available.
     this.nodeId               = this.context.GetNodeId();
     this.httpPort             = this.context.GetHttpPort();
     this.nodeManagerVersionId = YarnVersionInfo.GetVersion();
     try
     {
         // Registration has to be in start so that ContainerManager can get the
         // perNM tokens needed to authenticate ContainerTokens.
         this.resourceTracker = GetRMClient();
         RegisterWithRM();
         base.ServiceStart();
         StartStatusUpdater();
     }
     catch (Exception e)
     {
         string errorMessage = "Unexpected error starting NodeStatusUpdater";
         Log.Error(errorMessage, e);
         throw new YarnRuntimeException(e);
     }
 }
Esempio n. 28
0
        private void TestPbClientFactory()
        {
            IPEndPoint addr = new IPEndPoint(0);

            System.Console.Error.WriteLine(addr.GetHostName() + addr.Port);
            Configuration   conf     = new Configuration();
            ResourceTracker instance = new TestYSCRPCFactories.ResourceTrackerTestImpl(this);

            Org.Apache.Hadoop.Ipc.Server server = null;
            try
            {
                server = RpcServerFactoryPBImpl.Get().GetServer(typeof(ResourceTracker), instance
                                                                , addr, conf, null, 1);
                server.Start();
                System.Console.Error.WriteLine(server.GetListenerAddress());
                System.Console.Error.WriteLine(NetUtils.GetConnectAddress(server));
                ResourceTracker client = null;
                try
                {
                    client = (ResourceTracker)RpcClientFactoryPBImpl.Get().GetClient(typeof(ResourceTracker
                                                                                            ), 1, NetUtils.GetConnectAddress(server), conf);
                }
                catch (YarnRuntimeException e)
                {
                    Sharpen.Runtime.PrintStackTrace(e);
                    NUnit.Framework.Assert.Fail("Failed to create client");
                }
            }
            catch (YarnRuntimeException e)
            {
                Sharpen.Runtime.PrintStackTrace(e);
                NUnit.Framework.Assert.Fail("Failed to create server");
            }
            finally
            {
                server.Stop();
            }
        }
        public static void PreRegister(ref ResourceTracker __instance)
        {
            GameObject go           = __instance.gameObject;
            TechType   gameTechType = (go != null ? CraftData.GetTechType(go) : TechType.None);

            //TechType tt = ((__instance.overrideTechType == TechType.None) ? gameTechType : __instance.overrideTechType);
            if (gameTechType == TechType.Fragment || __instance.overrideTechType == TechType.Fragment)             // We only need to concern ourselves with fragments
            {
                string uniqueId = __instance.prefabIdentifier.Id;
                QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, $"ResourceTrackerPatches.PreRegister() running on ResourceTracker with unique ID {uniqueId}, overrideTechType {__instance.overrideTechType} and techType {gameTechType}");

                if (!string.IsNullOrEmpty(uniqueId))
                {
                    string resourceName = Language.main.Get(gameTechType);
                    QLogger.Log(QLogger.Level.Debug, $"Registering resource names for fragment:\nUnique ID: {uniqueId}\nTechType: {gameTechType.AsString()}\nResource name: {resourceName}");
                    IdToGameObjectDict[uniqueId]   = __instance.gameObject;
                    IdToTechTypeDict[uniqueId]     = gameTechType;
                    IdToResourceNameDict[uniqueId] = resourceName;
                }

                //__instance.overrideTechType = TechType.None;
            }
        }
Esempio n. 30
0
        static void Main(string[] args)
        {
            using (ResourceTracker t = new ResourceTracker())
            {
                Mat   picMat = t.T(Cv2.ImRead("bg.png"));
                Mat   mat1   = t.T(255 - picMat);
                Mat   mat2   = t.T(np.zeros_like(mat1));
                Mat   mat3   = t.NewMat();
                Mat   mat4   = t.T(np.array(new byte[] { 33, 88, 99 }));
                Mat   mat5   = t.T(np.array(33, 88, 99));
                Mat   mat6   = t.T(255 - t.T(picMat * 0.8));
                Mat[] mats1  = t.T(picMat.Split());
                Mat[] mats2  = new Mat[] { mats1[0], mats1[1], mats1[2], t.T(np.zeros_like(picMat)) };
                Cv2.Merge(mats2, mat3);
            }

            using (ResourceTracker t = new ResourceTracker())
            {
                Mat   mat1  = t.NewMat(new Size(100, 100), MatType.CV_8UC3, new Scalar(0));
                Mat   mat3  = t.T(255 - t.T(mat1 * 0.8));
                Mat[] mats1 = t.T(mat3.Split());
                Mat   mat4  = t.NewMat();
                Cv2.Merge(new Mat[] { mats1[0], mats1[1], mats1[2] }, mat4);
            }

            using (ResourceTracker t = new ResourceTracker())
            {
                var img1         = t.T(Cv2.ImRead("bg.png"));
                var img2         = t.T(Cv2.ImRead("2.jpg"));
                var img2_resized = t.T(np.zeros_like(img1));
                Cv2.Resize(img2, img2_resized, img1.Size());
                var        img3 = t.T(np.zeros_like(img1));
                np.where < Vec3b > (img1, img3, p => p.Item0 < 100 || p.Item1 < 100, img1, img2_resized);
                Cv2.ImShow("a", img3);
                Cv2.WaitKey();
            }
        }
Esempio n. 31
0
 private void Awake()
 {
     SharedInstance = this;
 }
        public override GameObject GetGameObject()
        {
            GameObject prefab = GameObject.Instantiate(this.GameObject);

            prefab.name = this.ClassID;

            // Translate
            foreach (Transform tr in prefab.transform)
            {
                tr.localPosition = new Vector3(tr.localPosition.x, tr.localPosition.y + 0.25f, tr.localPosition.z);
            }

            // Update TechTag
            var techTag = prefab.GetComponent <TechTag>();

            if (techTag == null)
            {
                if ((techTag = prefab.GetComponentInChildren <TechTag>()) == null)
                {
                    techTag = prefab.AddComponent <TechTag>();
                }
            }
            techTag.type = this.TechType;

            // Remove unwanted components
            EntityTag entityTag = prefab.GetComponent <EntityTag>();

            if (entityTag != null)
            {
                GameObject.DestroyImmediate(entityTag);
            }
            EcoTarget ecoTarget = prefab.GetComponent <EcoTarget>();

            if (ecoTarget != null)
            {
                GameObject.DestroyImmediate(ecoTarget);
            }
            ResourceTracker resourceTracker = prefab.GetComponent <ResourceTracker>();

            if (resourceTracker != null)
            {
                GameObject.DestroyImmediate(resourceTracker);
            }
            WorldForces worldForces = prefab.GetComponent <WorldForces>();

            if (worldForces != null)
            {
                GameObject.DestroyImmediate(worldForces);
            }

            // Update prefab ID
            var prefabId = prefab.GetComponent <PrefabIdentifier>();

            if (prefabId == null)
            {
                if ((prefabId = prefab.GetComponentInChildren <PrefabIdentifier>()) == null)
                {
                    prefabId = prefab.AddComponent <PrefabIdentifier>();
                }
            }
            prefabId.ClassId = this.ClassID;

            // Remove Cube object to prevent physics
            GameObject cube = prefab.FindChild("Cube");

            if (cube != null)
            {
                GameObject.DestroyImmediate(cube);
            }

            // Remove rigid body to prevent physics bugs
            var rb = prefab.GetComponent <Rigidbody>();

            if (rb != null)
            {
                GameObject.DestroyImmediate(rb);
            }

            // Add box collider
            var collider = prefab.GetComponent <BoxCollider>();

            if (collider == null)
            {
                Collider[] colliders = prefab.GetComponentsInChildren <Collider>();
                if (colliders != null)
                {
                    foreach (Collider c in colliders)
                    {
                        GameObject.DestroyImmediate(c);
                    }
                }
                collider = prefab.AddComponent <BoxCollider>();
            }
            collider.size      = new Vector3(0.7f, 0.7f, 0.7f);
            collider.center    = new Vector3(collider.center.x - 0.15f, collider.center.y + 1.0f, collider.center.z - 1.0f);
            collider.isTrigger = true;

            // We can pick this item
            var pickupable = prefab.GetComponent <Pickupable>();

            if (pickupable == null)
            {
                pickupable = prefab.AddComponent <Pickupable>();
            }
            pickupable.isPickupable = true;
            pickupable.randomizeRotationWhenDropped = true;

            // We can place this item
            prefab.AddComponent <CustomPlaceToolController>();
            var placeTool = prefab.GetComponent <PlaceTool>();

            if (placeTool != null)
            {
                GameObject.DestroyImmediate(placeTool);
            }
            placeTool = prefab.AddComponent <GenericPlaceTool>();
            placeTool.allowedInBase          = true;
            placeTool.allowedOnBase          = true;
            placeTool.allowedOnCeiling       = false;
            placeTool.allowedOnConstructable = true;
            placeTool.allowedOnGround        = true;
            placeTool.allowedOnRigidBody     = true;
            placeTool.allowedOnWalls         = true;
            placeTool.allowedOutside         = ConfigSwitcher.AllowPlaceOutside;
            placeTool.rotationEnabled        = true;
            placeTool.enabled              = true;
            placeTool.hasAnimations        = false;
            placeTool.hasBashAnimation     = false;
            placeTool.hasFirstUseAnimation = false;
            placeTool.mainCollider         = collider;
            placeTool.pickupable           = pickupable;

            // Update sky applier
            PrefabsHelper.ReplaceSkyApplier(prefab, true);

            // Add fabricating animation
            var fabricating = prefab.AddComponent <VFXFabricating>();

            fabricating.localMinY   = -0.2f;
            fabricating.localMaxY   = 0.6f;
            fabricating.posOffset   = new Vector3(0.1f, 0.141f, 0.3f);
            fabricating.eulerOffset = new Vector3(0f, 0f, 0f);
            fabricating.scaleFactor = 0.2f;

            return(prefab);
        }