예제 #1
0
    private static void PostCompile(AscensionCompilerOperation op, ManualResetEvent evnt, string postArgs)
    {
        Process p = new Process();

        p.StartInfo.FileName  = MonoPath;
        p.StartInfo.Arguments = postArgs;

        p.EnableRaisingEvents              = true;
        p.StartInfo.CreateNoWindow         = true;
        p.StartInfo.UseShellExecute        = false;
        p.StartInfo.RedirectStandardError  = true;
        p.StartInfo.RedirectStandardOutput = true;

        p.ErrorDataReceived  += ErrorDataReceived;
        p.OutputDataReceived += OutputDataReceived;

        p.Exited += (s, ea) =>
        {
            // we are done
            evnt.Set();

            // continue
            EditorSaver.Invoke(() =>
            {
                if (p.ExitCode == 0)
                {
                    CompilationDone(op);
                }
            });
        };

        p.Start();
        p.BeginErrorReadLine();
        p.BeginOutputReadLine();
    }
예제 #2
0
    private static void RunCSharpCompilerOld(AscensionCompilerOperation op, ManualResetEvent evnt)
    {
#if DEBUG
        const string CMD_ARGS =
            "\"{0}\" -out:\"{1}\" {2} -platform:anycpu -target:library -debug+ -optimize- -warn:{3} ";
#else
        const string CMD_ARGS = "\"{0}\" -out:\"{1}\" {2} -platform:anycpu -target:library -debug- -optimize+ -warn:{3} ";
#endif

        string args = CMD_ARGS;

        if (Core.IsDebugMode)
        {
            args += "-define:DEBUG ";
        }

        if (IsUnity5)
        {
            args += "-sdk:2 ";
        }

        string preCompArguments = string.Format(args + CombinedScripts, CsharpCompilerPath, AscensionPrecompileAssemblyPath,
                                                PreAssemblyReferencesList, Mathf.Clamp(RuntimeSettings.Instance.compilationWarnLevel, 0, 4));

        string postCompArguments = string.Format(args + SourceFileList, CsharpCompilerPath, AscensionUserAssemblyPath,
                                                 PostAssemblyReferencesList, Mathf.Clamp(RuntimeSettings.Instance.compilationWarnLevel, 0, 4));

        PreCompile(op, evnt, preCompArguments, postCompArguments);
    }
예제 #3
0
    private static void PreCompile(AscensionCompilerOperation op, ManualResetEvent evnt, string preArgs, string postArgs)
    {
        Process p = new Process();

        p.StartInfo.FileName               = MonoPath;
        p.StartInfo.Arguments              = preArgs;
        p.EnableRaisingEvents              = true;
        p.StartInfo.CreateNoWindow         = true;
        p.StartInfo.UseShellExecute        = false;
        p.StartInfo.RedirectStandardError  = true;
        p.StartInfo.RedirectStandardOutput = true;

        p.ErrorDataReceived  += ErrorDataReceived;
        p.OutputDataReceived += OutputDataReceived;

        p.Exited += (s, ea) =>
        {
            if (p.ExitCode == 0)
            {
                PostCompile(op, evnt, postArgs);

                Debug.Log("Pre-compile finished!");
            }
        };

        p.Start();
        p.BeginErrorReadLine();
        p.BeginOutputReadLine();
    }
예제 #4
0
    private static void CompilationDone(AscensionCompilerOperation op)
    {
        AssetDatabase.ImportAsset(AscensionUserAssemblyAsset, ImportAssetOptions.ForceUpdate);

        Debug.Log("AscensionCompiler: Success!");

        EditorPrefs.SetInt("ASCENSION_UNCOMPILED_COUNT", 0);
        EditorPrefs.SetBool(SceneLauncher.COMPILE_SETTING, false);
    }
예제 #5
0
    static void RunCSharpCompiler(AscensionCompilerOperation op, ManualResetEvent evnt)
    {
#if DEBUG
        const string CMD_ARGS = "\"{0}\" -out:\"{1}\" {2} -platform:anycpu -target:library -debug+ -optimize- -warn:{3} ";
#else
        const string CMD_ARGS = "\"{0}\" -out:\"{1}\" {2} -platform:anycpu -target:library -debug- -optimize+ -warn:{3} ";
#endif

        string args = CMD_ARGS;

        if (Core.IsDebugMode)
        {
            args += "-define:DEBUG ";
        }

        if (IsUnity5)
        {
            args += "-sdk:2 ";
        }


        Process p = new Process();
        p.StartInfo.FileName  = MonoPath;
        p.StartInfo.Arguments = string.Format(args + SourceFileList, CsharpCompilerPath, AscensionUserAssemblyPath, AssemblyReferencesList, Mathf.Clamp(RuntimeSettings.Instance.compilationWarnLevel, 0, 4));

        p.EnableRaisingEvents              = true;
        p.StartInfo.CreateNoWindow         = true;
        p.StartInfo.UseShellExecute        = false;
        p.StartInfo.RedirectStandardError  = true;
        p.StartInfo.RedirectStandardOutput = true;

        p.ErrorDataReceived  += ErrorDataReceived;
        p.OutputDataReceived += OutputDataReceived;

        p.Exited += (s, ea) => {
            // we are done
            evnt.Set();

            // continue
            EditorSaver.Invoke(() => {
                if (p.ExitCode == 0)
                {
                    CompilationDone(op);
                }
            });
        };

        p.Start();
        p.BeginErrorReadLine();
        p.BeginOutputReadLine();
    }
예제 #6
0
 private static void CompileAssemblyInfo(AscensionCompilerOperation op)
 {
     using (AscensionSourceFile file = new AscensionSourceFile(op.assemblyInfoFilePath))
     {
         file.EmitLine("using System.Reflection;");
         file.EmitLine("using System.Runtime.CompilerServices;");
         file.EmitLine("using System.Runtime.InteropServices;");
         file.EmitLine();
         file.EmitLine("[assembly: AssemblyTitle(\"Ascension.Data\")]");
         file.EmitLine("[assembly: Guid(\"bd29ff3d-20fc-49ac-8303-459b4d662c04\")]");
         file.EmitLine("[assembly: AssemblyVersion(\"0.5.0.0\")]");
         file.EmitLine("[assembly: AssemblyFileVersion(\"0.0.0.0\")]");
     }
 }
예제 #7
0
    public static void Run(AscensionCompilerOperation op, bool emitAssemblyInfo = true)
    {
        CompileMaps(op);
        CompilePrefabs(op);
        CompileNetwork(op);

        //Should we emit the assembly info?
        if (emitAssemblyInfo)
        {
            CompileAssemblyInfo(op);
        }

        op.project.GenerateCode(op.projectFilePath);
    }
예제 #8
0
    public static ManualResetEvent CodeEmit()
    {
        ManualResetEvent evnt = new ManualResetEvent(false);

        try
        {
            // create path if it doesn't exist
            Directory.CreateDirectory(AscensionDataPath);

            // setup compiler options
            AscensionCompilerOperation op = new AscensionCompilerOperation();
            op.projectFilePath = ProjectFile;
            op.project         = File.Exists("Assets/__ASCENSION__/Networking/Resources/User/project.bytes")
                ? File.ReadAllBytes("Assets/__ASCENSION__/Networking/Resources/User/project.bytes").ToObject <Project>()
                : new Project();

            // network config
            op.networkFilePath      = NetworkFile;
            op.assemblyInfoFilePath = AssemblyInfoFile;

            // maps config
            op.scenesFilePath  = MapsFile;
            op.prefabsFilePath = PrefabsFile;

            // run code emitter
            AscensionCompiler.Run(op, false);

            // we are done
            evnt.Set();

            // continue
            EditorSaver.Invoke(() =>
            {
                EmissionDone(op);
            });
        }
        catch (Exception exn)
        {
            evnt.Set();
            Debug.LogException(exn);
        }

        return(evnt);
    }
예제 #9
0
    private static void CompilePrefabs(AscensionCompilerOperation op)
    {
        if (PrefabDatabase.Instance.DatabaseMode == PrefabDatabaseMode.AutomaticScan)
        {
            UpdatePrefabsDatabase();
        }

        for (int i = 1; i < PrefabDatabase.Instance.Prefabs.Length; ++i)
        {
            if (PrefabDatabase.Instance.Prefabs[i])
            {
                GameObject      go     = PrefabDatabase.Instance.Prefabs[i];
                AscensionEntity entity = go.GetComponent <AscensionEntity>();

                if (entity && entity.SceneGuid != UniqueId.None)
                {
                    entity.sceneGuid = "";

                    EditorUtility.SetDirty(go);
                    EditorUtility.SetDirty(entity);
                    AssetDatabase.SaveAssets();
                }
            }
        }

        using (AscensionSourceFile file = new AscensionSourceFile(op.prefabsFilePath))
        {
            file.EmitScope("public static class AscensionPrefabs", () =>
            {
                for (int i = 1; i < PrefabDatabase.Instance.Prefabs.Length; ++i)
                {
                    GameObject prefab = PrefabDatabase.Instance.Prefabs[i];

                    if (prefab)
                    {
                        file.EmitLine(
                            "public static readonly Ascension.Networking.PrefabId {0} = new Ascension.Networking.PrefabId({1});",
                            prefab.name.CSharpIdentifier(), prefab.GetComponent <AscensionEntity>().prefabId);
                    }
                }
            });
        }
    }
    private static void CompileNetwork(AscensionCompilerOperation op)
    {
        using (AscensionSourceFile file = new AscensionSourceFile(op.networkFilePath))
        {
            file.EmitScope("namespace Ascension.Networking.Data", () =>
            {
                file.EmitScope("public static class AscensionNetworkInternalUser", () =>
                {
                    file.EmitScope("public static void EnvironmentSetup()", () =>
                    {
                        EmitRegisterFactory(file, op.project.Structs.Select(x => new ObjectDecorator(x)));
                        EmitRegisterFactory(file, op.project.Commands.Select(x => new CommandDecorator(x)));
                        EmitRegisterFactory(file, op.project.Events.Select(x => new EventDecorator(x)));
                        EmitRegisterFactory(file, op.project.States.Select(x => new StateDecorator(x)));
                    });

                    file.EmitScope("public static void EnvironmentReset()", () => { });
                });
            });
        }
    }
예제 #11
0
    public static ManualResetEvent Run()
    {
        ManualResetEvent evnt = new ManualResetEvent(false);

        try
        {
            // calculate source dir
            SourceDir = EditorUtils.MakePath(Path.GetDirectoryName(AssetDir), "Temp", "Ascension");

            // ensure temp path exists
            Directory.CreateDirectory(SourceDir);

            // setup compiler options
            AscensionCompilerOperation op = new AscensionCompilerOperation();
            op.projectFilePath = ProjectFileTemp;
            op.project         = File.Exists("Assets/__ASCENSION__/Networking/Resources/User/project.bytes")
                ? File.ReadAllBytes("Assets/__ASCENSION__/Networking/Resources/User/project.bytes").ToObject <Project>()
                : new Project();

            // network config
            op.networkFilePath      = NetworkFileTemp;
            op.assemblyInfoFilePath = AssemblyInfoFileTemp;

            // maps config
            op.scenesFilePath  = MapsFileTemp;
            op.prefabsFilePath = PrefabsFileTemp;

            // run code emitter
            AscensionCompiler.Run(op);
            RunCSharpCompiler(op, evnt);
        }
        catch (Exception exn)
        {
            evnt.Set();
            Debug.LogException(exn);
        }

        return(evnt);
    }
    public static void CompileMaps(AscensionCompilerOperation op)
    {
        List <Scene> scenes = new List <Scene>();

        for (int i = 0; i < EditorBuildSettings.scenes.Length; ++i)
        {
            if (EditorBuildSettings.scenes[i].enabled)
            {
                string name = Path.GetFileNameWithoutExtension(EditorBuildSettings.scenes[i].path);

                scenes.Add(new Scene
                {
                    Name       = name,
                    Identifier = EditorUtils.CSharpIdentifier(name)
                });
            }
        }

        foreach (IGrouping <string, Scene> group in scenes.GroupBy(x => x.Identifier))
        {
            if (group.Count() > 1)
            {
                throw new AscensionException("You have several scenes named '{0}' in the build settings.", group.Key);
            }
        }

        using (AscensionSourceFile file = new AscensionSourceFile(op.scenesFilePath))
        {
            file.EmitLine("using System.Collections.Generic;");
            file.EmitScope("public static class AscensionScenes", () =>
            {
                file.EmitLine(
                    "static public readonly Dictionary<string, int> nameLookup = new Dictionary<string, int>();");
                file.EmitLine(
                    "static public readonly Dictionary<int, string> indexLookup = new Dictionary<int, string>();");

                file.EmitScope("public static void AddScene(short prefix, short id, string name)", () =>
                {
                    file.EmitLine("int index = (prefix << 16) | (int)id;");
                    file.EmitLine("nameLookup.Add(name, index);");
                    file.EmitLine("indexLookup.Add(index, name);");
                });

                file.EmitLine("static public IEnumerable<string> AllScenes { get { return nameLookup.Keys; } }");

                file.EmitScope("static AscensionScenes()", () =>
                {
                    for (int n = 0; n < scenes.Count; ++n)
                    {
                        file.EmitLine("AddScene(0, {1}, \"{0}\");", scenes[n].Name, n);
                    }
                });

                for (int n = 0; n < scenes.Count; ++n)
                {
                    file.EmitLine("public const string {0} = \"{1}\";", scenes[n].Identifier, scenes[n].Name);
                }
            });

            file.EmitScope("namespace Ascension.Networking.Data", () =>
            {
                file.EmitScope("public static class AscensionScenesInternal", () =>
                {
                    file.EmitLine(
                        "static public int GetSceneIndex(string name) { return AscensionScenes.nameLookup[name]; }");
                    file.EmitLine(
                        "static public string GetSceneName(int index) { return AscensionScenes.indexLookup[index]; }");
                });
            });
        }
    }