Exemplo n.º 1
0
        } = new string[5];                                         // X,Y,AreaSideLength,TDBPath,DEMPath

        // as base game doesn't contain a full System.XML.LINQ namespace and the .NET 4.8 is easier to work with,
        // other external process was created for TDB parsing
        internal void ProcessTDBExternally()
        {
            UnityEngine.Debug.Log(modDirectory);
            var psi = new ProcessStartInfo();

            psi.FileName               = $"{modDirectory}GMLParserPL.exe";
            psi.CreateNoWindow         = true;
            psi.RedirectStandardOutput = true;
            psi.RedirectStandardInput  = true;
            psi.RedirectStandardError  = true;
            psi.UseShellExecute        = false;

            psi.Arguments = "\"" + Arguments[0] + "\"" + " " + "\"" + Arguments[1] + "\"" + " " + "\"" + Arguments[2] + "\""
                            + " " + "\"" + Arguments[3] + "\"";
            var p = new Process();

            p.StartInfo = psi;
            p.Start();

            NetFactory      netFactory      = new NetFactory();
            BuildingFactory buildingFactory = new BuildingFactory();
            PropFactory     propFactory     = new PropFactory();
            ResourceFactory resourceFactory = new ResourceFactory();
            TreeFactory     treeFactory     = new TreeFactory();
            WaterFactory    waterFactory    = new WaterFactory();

            waterFactory.SetSeaLevelTo0();

            while (!p.StandardOutput.EndOfStream)
            {
                string line = p.StandardOutput.ReadLine();
                SelectFactory(line, netFactory, buildingFactory, propFactory, resourceFactory, treeFactory, waterFactory);
            }
            netFactory.UpdateSegments();

            UnityEngine.Debug.Log("TDB loaded");
            UnityEngine.Debug.Log($"Buildings loaded/called/max: {buildingFactory.Temp}/{timesBuildingUsed}/{BuildingManager.MAX_BUILDING_COUNT}");
            UnityEngine.Debug.Log($"Segments loaded/called/max: {netFactory.TempS}/{timesNetUsed}/{NetManager.MAX_SEGMENT_COUNT}");
            UnityEngine.Debug.Log($"Net nodes loaded/max: {netFactory.TempN}/{NetManager.MAX_NODE_COUNT}");
            UnityEngine.Debug.Log($"Props loaded/called/max: {propFactory.Temp}/{timesPropUsed}/{PropManager.MAX_PROP_COUNT}");
            UnityEngine.Debug.Log($"Trees loaded/called/max: {treeFactory.Temp}/{timesTreeUsed}/{TreeManager.MAX_TREE_COUNT}");
            UnityEngine.Debug.Log($"Resources loaded/called: {resourceFactory.Temp}/{timesResourceUsed}");
            UnityEngine.Debug.Log($"Resources loaded/called: {waterFactory.Temp}/{timesWaterUsed}");
        }
Exemplo n.º 2
0
        // as DEM couldn't be transfered via pipes or MMF and was cousing troubles in async, another process was created
        internal void ProcessDEMExternally()
        {
            var psi = new ProcessStartInfo();

            psi.FileName               = $"{modDirectory}ASCIIParserPL.exe";
            psi.CreateNoWindow         = true;
            psi.RedirectStandardOutput = true;
            psi.RedirectStandardInput  = true;
            psi.RedirectStandardError  = true;
            psi.UseShellExecute        = false;

            psi.Arguments = "\"" + Arguments[0] + "\"" + " " + "\"" + Arguments[1] + "\"" + " " + "\"" + Arguments[4] + "\"";
            var p = new Process();

            p.StartInfo = psi;
            p.Start();

            TerrainFactory terrainFactory = new TerrainFactory();
            WaterFactory   waterFactory   = new WaterFactory();

            waterFactory.SetSeaLevelTo0();

            while (!p.StandardOutput.EndOfStream)
            {
                string        line      = p.StandardOutput.ReadLine();
                List <string> arguments = line.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();

                if (arguments[0] == "Terrain")
                {
                    byte[] map = System.Convert.FromBase64String(arguments[1]);
                    terrainFactory.SetTerrain(map);
                    UnityEngine.Debug.Log("DEM imported");
                }
                if (arguments[0] == "Error")
                {
                    UnityEngine.Debug.Log(arguments[1]);
                }
            }
        }