コード例 #1
0
ファイル: GCompiler.cs プロジェクト: jwl317/GSharp
        /// <summary>
        /// 소스를 빌드하여 컴파일된 파일을 생성합니다.
        /// </summary>
        /// <param name="path">컴파일된 파일을 생성할 경로입니다.</param>
        /// <param name="isExecutable">실행 파일 형태로 컴파일 할지 여부를 설정합니다.</param>
        public GCompilerResults Build(string path, bool isEmbedded = false, bool isCompressed = false)
        {
            parameters.OutputAssembly  = path;
            parameters.CompilerOptions = "/platform:x86 /target:winexe";
            parameters.EmbeddedResources.Clear();
            string fullSource = ConvertToFullSource(Source, isEmbedded, isCompressed);

            foreach (string dll in References)
            {
                if (File.Exists(dll))
                {
                    string target = dll;
                    if (isCompressed && Path.GetFileNameWithoutExtension(target) != "GSharp.Compressor")
                    {
                        var tempFileName     = Path.GetTempFileName();
                        var targetCompressed = Path.GetTempPath() + $"{Path.GetFileNameWithoutExtension(target)}.pak";

                        if (!Path.GetTempPath().StartsWith(Path.GetDirectoryName(target)))
                        {
                            File.Copy(target, tempFileName, true);
                        }

                        GCompressor.Compress(tempFileName, targetCompressed);
                        target = targetCompressed;
                    }

                    if (isEmbedded)
                    {
                        parameters.EmbeddedResources.Add(target);
                    }
                    else
                    {
                        var destination = $@"{Path.GetDirectoryName(path)}\{Path.GetFileName(target)}";
                        if (target != destination)
                        {
                            File.Copy(target, destination, true);
                        }
                    }
                }
            }

            foreach (string directory in Dependencies)
            {
                if (Directory.Exists(directory))
                {
                    CopyDirectory(directory, Path.GetDirectoryName(path), true);
                }
            }

            GCompilerResults results = new GCompilerResults
            {
                Source  = fullSource,
                Results = provider.CompileAssemblyFromSource(parameters, fullSource)
            };

            return(results);
        }
コード例 #2
0
        internal void Serialize()
        {
            int[]   protoIndices = new int[Instances.Count];
            float[] positions    = new float[Instances.Count * 3];
            float[] rotations    = new float[Instances.Count * 4];
            float[] scales       = new float[Instances.Count * 3];
            for (int i = 0; i < Instances.Count; ++i)
            {
                GGrassInstance grass = Instances[i];
                protoIndices[i] = grass.PrototypeIndex;

                positions[i * 3 + 0] = grass.Position.x;
                positions[i * 3 + 1] = grass.Position.y;
                positions[i * 3 + 2] = grass.Position.z;

                rotations[i * 4 + 0] = grass.Rotation.x;
                rotations[i * 4 + 1] = grass.Rotation.y;
                rotations[i * 4 + 2] = grass.Rotation.z;
                rotations[i * 4 + 3] = grass.Rotation.w;

                scales[i * 3 + 0] = grass.Scale.x;
                scales[i * 3 + 1] = grass.Scale.y;
                scales[i * 3 + 2] = grass.Scale.z;
            }

            prototypeIndexSerializeData = new byte[Buffer.ByteLength(protoIndices)];
            Buffer.BlockCopy(protoIndices, 0, prototypeIndexSerializeData, 0, prototypeIndexSerializeData.Length);
            prototypeIndexSerializeData = GCompressor.Compress(prototypeIndexSerializeData);

            positionSerializeData = new byte[Buffer.ByteLength(positions)];
            Buffer.BlockCopy(positions, 0, positionSerializeData, 0, positionSerializeData.Length);
            positionSerializeData = GCompressor.Compress(positionSerializeData);

            rotationSerializeData = new byte[Buffer.ByteLength(rotations)];
            Buffer.BlockCopy(rotations, 0, rotationSerializeData, 0, rotationSerializeData.Length);
            rotationSerializeData = GCompressor.Compress(rotationSerializeData);

            scaleSerializeData = new byte[Buffer.ByteLength(scales)];
            Buffer.BlockCopy(scales, 0, scaleSerializeData, 0, scaleSerializeData.Length);
            scaleSerializeData = GCompressor.Compress(scaleSerializeData);
        }