Ejemplo n.º 1
0
        public static void RegularDeleteEntities(PlanetFactory factory, List <int> targetIds)
        {
            var player = GameMain.mainPlayer;

            PlayerAction_Build actionBuild = player.controller.actionBuild;

            using IDisposable toggle = UndoManager.IgnoreAllEvents.On();

            var stopwatch = new HighStopwatch();

            stopwatch.Begin();

            foreach (int objId in targetIds)
            {
                if (factory.entityPool[objId].stationId > 0 && BlueprintTweaksPlugin.excludeStations.Value)
                {
                    continue;
                }

                try
                {
                    DoDismantleObject(actionBuild, objId);
                }
                catch (Exception e)
                {
                    BlueprintTweaksPlugin.logger.LogWarning($"Error while dismantling entity {objId}, message: {e.Message}, stacktrace:\n{e.StackTrace}");
                }
            }

            var durationInS = stopwatch.duration;

            BlueprintTweaksPlugin.logger.LogDebug($"Took {durationInS} s to delete entities");
        }
        private static byte[] PlanetCompute(int planetId) 
        {
            PlanetData planet = GameMain.galaxy.PlanetById(planetId);
            HighStopwatch highStopwatch = new HighStopwatch();
            highStopwatch.Begin();

            // NOTE: The following has been picked-n-mixed from "PlanetModelingManager.PlanetComputeThreadMain()"
            // This method is **costly** - do not run it more than is required!
            // It generates the planet on the host and then sends it to the client

            PlanetAlgorithm planetAlgorithm = PlanetModelingManager.Algorithm(planet);

            if (planet.data == null)
            {
                planet.data = new PlanetRawData(planet.precision);
                planet.modData = planet.data.InitModData(planet.modData);
                planet.data.CalcVerts();
                planet.aux = new PlanetAuxData(planet);
                planetAlgorithm.GenerateTerrain(planet.mod_x, planet.mod_y);
                planetAlgorithm.CalcWaterPercent();

                //Load planet meshes and register callback to unload unneccessary stuff
                planet.wanted = true;
                planet.onLoaded += OnActivePlanetLoaded;
                PlanetModelingManager.modPlanetReqList.Enqueue(planet);

                if (planet.type != EPlanetType.Gas)
                {
                    planetAlgorithm.GenerateVegetables();
                    planetAlgorithm.GenerateVeins(false);
                }
            }

            byte[] data;
            using (BinaryUtils.Writer writer = new BinaryUtils.Writer())
            {
                planet.ExportRuntime(writer.BinaryWriter);
                data = writer.CloseAndGetBytes();
            }
            Log.Info($"Returning terrain for {planet.name} (id:{planet.id} time:{highStopwatch.duration:F4}s)");
            return data;
        }