/// <summary>
        ///   Generates the contents of the source code files to write.
        /// </summary>
        /// <param name="componentInfos">Data about all available entity components.</param>
        /// <returns>Contents and names of the source code files to write.</returns>
        public CodeGenFile[] Generate(ComponentInfo[] componentInfos)
        {
            // Generate methods for initializing components from dictionaries.
            var codeGenFiles =
                componentInfos.Where(info => info.generateMethods && !info.isSingletonComponent)
                    .Select(
                        info =>
                            new CodeGenFile
                            {
                                fileName = info.fullTypeName + ClassFileNameSuffix,
                                fileContent = AddDefaultPoolCode(info).ToUnixLineEndings()
                            })
                    .ToList();

            // Generate methods for creating entities and adding components from blueprints.
            codeGenFiles.Add(
                new CodeGenFile
                {
                    fileName = "BlueprintPoolExtensions",
                    fileContent =
                        AddBlueprintPoolCode(componentInfos.Where(info => info.generateMethods)).ToUnixLineEndings()
                });

            return codeGenFiles.ToArray();
        }
コード例 #2
0
 public CodeGenFile[] Generate(ComponentInfo[] componentInfos) {
     return componentInfos
         .Where(info => info.generateMethods)
         .Select(info => new CodeGenFile {
             fileName = info.fullTypeName + CLASS_SUFFIX,
             fileContent = generateComponentExtension(info).ToUnixLineEndings()
         }).ToArray();
 }
コード例 #3
0
 public CodeGenFile[] Generate(ComponentInfo[] componentInfos)
 {
     var generatorName = GetType().FullName;
     return componentInfos
         .Where(info => info.generateMethods)
         .Select(info => new CodeGenFile(
             info.fullTypeName + "GeneratedExtension",
             generateComponentExtension(info),
             generatorName
         )).ToArray();
 }
コード例 #4
0
        static Dictionary<string, ComponentInfo[]> getLookupTagToComponentInfosMap(ComponentInfo[] componentInfos) {
            var currentIndex = 0;
            var orderedComponentInfoToLookupTagsMap = componentInfos
                .Where(info => info.generateIndex)
                .ToDictionary(info => info, info => info.ComponentLookupTags())
                .OrderByDescending(kv => kv.Value.Length);

            return orderedComponentInfoToLookupTagsMap
                .Aggregate(new Dictionary<string, ComponentInfo[]>(), (map, kv) => {
                    var info = kv.Key;
                    var lookupTags = kv.Value;
                    var incrementIndex = false;
                    foreach (var lookupTag in lookupTags) {
                        if (!map.ContainsKey(lookupTag)) {
                            map.Add(lookupTag, new ComponentInfo[componentInfos.Length]);
                        }

                        var infos = map[lookupTag];
                        if (lookupTags.Length == 1) {
                            // Component has only one lookupTag. Insert at next free slot.
                            for (int i = 0; i < infos.Length; i++) {
                                if (infos[i] == null) {
                                    infos[i] = info;
                                    break;
                                }
                            }
                        } else {
                            // Component has multiple lookupTags. Set at current index in all lookups.
                            infos[currentIndex] = info;
                            incrementIndex = true;
                        }
                    }
                    if (incrementIndex) {
                        currentIndex++;
                    }
                    return map;
                });
        }
コード例 #5
0
        static Dictionary<string, ComponentInfo[]> getLookupTagToComponentInfosMap(ComponentInfo[] componentInfos)
        {
            var currentIndex = 0;

            // order componentInfos by context count
            var orderedComponentInfoToLookupTagsMap = componentInfos
                .Where(info => info.generateIndex)
                .ToDictionary(info => info, info => info.ComponentLookupTags())
                .OrderByDescending(kv => kv.Value.Length);

            var lookupTagToComponentInfosMap = orderedComponentInfoToLookupTagsMap
                .Aggregate(new Dictionary<string, ComponentInfo[]>(), (map, kv) => {
                    var info = kv.Key;
                    var lookupTags = kv.Value;
                    var componentIsAssignedToMultipleContexts = lookupTags.Length > 1;
                    var incrementIndex = false;
                    foreach(var lookupTag in lookupTags) {
                        if(!map.ContainsKey(lookupTag)) {
                            map.Add(lookupTag, new ComponentInfo[componentInfos.Length]);
                        }

                        var infos = map[lookupTag];
                        if(componentIsAssignedToMultipleContexts) {
                            // Component has multiple lookupTags. Set at current index in all lookups.
                            infos[currentIndex] = info;
                            incrementIndex = true;
                        } else {
                            // Component has only one lookupTag. Insert at next free slot.
                            for(int i = 0; i < infos.Length; i++) {
                                if(infos[i] == null) {
                                    infos[i] = info;
                                    break;
                                }
                            }
                        }
                    }
                    if(incrementIndex) {
                        currentIndex++;
                    }

                    return map;
                });

            foreach(var key in lookupTagToComponentInfosMap.Keys.ToArray()) {
                var infoList = lookupTagToComponentInfosMap[key].ToList();
                while(infoList.Count != 0) {
                    var last = infoList.Count - 1;
                    if(infoList[last] == null) {
                        infoList.RemoveAt(last);
                    } else {
                        break;
                    }
                }
                lookupTagToComponentInfosMap[key] = infoList.ToArray();
            }

            return lookupTagToComponentInfosMap;
        }