コード例 #1
0
ファイル: FLInterpreter.cs プロジェクト: codacy-badger/Byt3
        /// <summary>
        /// Loads the source from file
        /// </summary>
        /// <param name="file"></param>
        /// <param name="channelCount"></param>
        private List <string> LoadSource(string file, int channelCount)
        {
            Logger.Log(DebugChannel.Log | DebugChannel.OpenFL, Verbosity.Level8, "Loading Source..");

            Dictionary <string, bool> defs = new Dictionary <string, bool>();

            for (int i = 0; i < channelCount; i++)
            {
                defs.Add("channel" + i, true);
            }

            List <string> lines = TextProcessorAPI.PreprocessLines(file, defs).ToList();


            for (int i = lines.Count - 1; i >= 0; i--)
            {
                string line = lines[i].Trim();
                if (line.StartsWith(COMMENT_PREFIX))
                {
                    lines.RemoveAt(i); //Remove otherwise emtpty lines after removing comments
                }
                else
                {
                    lines[i] = line.Split(new[] { COMMENT_PREFIX }, StringSplitOptions.None)[0].Trim();
                }
            }

            return(lines);
        }
コード例 #2
0
ファイル: Interpreter.cs プロジェクト: ByteChkR/Minor
        /// <summary>
        /// Loads the source from file
        /// </summary>
        /// <param name="file"></param>
        private static List <string> LoadSource(string file, int channelCount)
        {
            Logger.Log("Loading Source..", DebugChannel.Log | DebugChannel.OpenFL | DebugChannel.IO, 9);

            Dictionary <string, bool> defs = new Dictionary <string, bool>();

            for (int i = 0; i < channelCount; i++)
            {
                defs.Add("channel" + i, true);
            }

            List <string> lines = TextProcessorAPI.PreprocessLines(file, defs).ToList();


            for (int i = lines.Count - 1; i >= 0; i--)
            {
                string line = lines[i].Trim();
                if (line.StartsWith(CommentPrefix))
                {
                    lines.RemoveAt(i); //Remove otherwise emtpty lines after removing comments
                }
                else
                {
                    lines[i] = line.Split(CommentPrefix)[0].Trim();
                }
            }

            return(lines);
        }
コード例 #3
0
        private string Merge(string src, params CLProgram[] progs)
        {
            string source = "";

            IEnumerable <CLProgram> unique = progs.Distinct(new ProgramComparer());

            foreach (CLProgram clProgram in unique)
            {
                source += $"#include {clProgram.FilePath}\n";
            }

            source += src;
            string[] lines   = source.Split('\n');
            string   content = TextProcessorAPI.PreprocessLines(lines, "./", ".cl", new Dictionary <string, bool>())
                               .Unpack("\n");

            return(content);
        }
コード例 #4
0
ファイル: ShaderProgram.cs プロジェクト: ByteChkR/Byt3
        /// <summary>
        /// Tries to Create a Shader from source
        /// </summary>
        /// <param name="subshaders">The source paths of the sub shader</param>
        /// <param name="program">The Program that will be created</param>
        /// <returns></returns>
        public static bool TryCreate(Dictionary <ShaderType, string> subshaders, out ShaderProgram program)
        {
            Dictionary <ShaderType, string> ret = new Dictionary <ShaderType, string>();

            foreach (KeyValuePair <ShaderType, string> subshader in subshaders)
            {
                Logger.Log(DebugChannel.Log | DebugChannel.EngineRendering, "Loading Shader: " + subshader.Value, 7);
                Stream        s       = IOManager.GetStream(subshader.Value);
                TextReader    tr      = new StreamReader(s);
                string        dirName = Path.GetDirectoryName(subshader.Value);
                StringBuilder src     = new StringBuilder();
                string[]      lines   =
                    TextProcessorAPI.PreprocessLines(tr.ReadToEnd().Replace("\r", "").Split('\n'), dirName, Path.GetExtension(subshader.Value), null);
                tr.Close();
                for (int i = 0; i < lines.Length; i++)
                {
                    src.AppendLine(lines[i]);
                }

                ret.Add(subshader.Key, src.ToString());
            }

            return(TryCreateFromSource(ret, out program));
        }
コード例 #5
0
ファイル: LoadSourceStage.cs プロジェクト: Open-FL/OpenFL
        public override LoadSourceStageResult Process(FLParserInput input)
        {
            if (input.Source != null)
            {
                return(new LoadSourceStageResult(
                           input.Filename,
                           input.Source.ToList(),
                           input.MainFile,
                           input.KernelData
                           ));
            }

            Logger.Log(LogType.Log, "Loading Source: " + input.Filename, 1);

            Dictionary <string, bool> defines = input.Defines;


            return(new LoadSourceStageResult(
                       input.Filename,
                       TextProcessorAPI.PreprocessLines(input.Filename, defines).ToList(),
                       input.MainFile,
                       input.KernelData
                       ));
        }
コード例 #6
0
 public override LoadSourceStageResult Process(FLParserInput input)
 {
     Logger.Log(LogType.Log, "Loading Source: " + input.Filename, 2);
     return(new LoadSourceStageResult(input.Filename,
                                      TextProcessorAPI.PreprocessLines(input.Filename, new Dictionary <string, bool>()).ToList()));
 }