Replace GamePartBlueprint.Namespace and GamePartBlueprint.Name with GamePartBlueprint.Type

Issue #10263 wontfix
John Snail created an issue

From what I can tell, these variables are only ever used to call ModManager.ResolveType, which is quite wasteful since it could just be called and stored when they’re initialized. For example, this snippet from GameObjectFactory.LoadBakedXML would go from:

foreach (KeyValuePair<string, ObjectBlueprintLoader.ObjectBlueprintXMLChildNode> item2 in node.NamedNodes("mutation"))
{
    GamePartBlueprint gamePartBlueprint2 = new GamePartBlueprint("XRL.World.Parts.Mutation", item2.Key);
    gamePartBlueprint2.Name = item2.Value.Name;
    gamePartBlueprint2.Parameters = item2.Value.Attributes;
    gameObjectBlueprint.Mutations[gamePartBlueprint2.Name] = gamePartBlueprint2;
}

to:

foreach (KeyValuePair<string, ObjectBlueprintLoader.ObjectBlueprintXMLChildNode> item2 in node.NamedNodes("mutation"))
{
    Type type = ModManager.ResolveType("XRL.World.Parts.Mutation." + item2.Key);
    if (type == null) // move null check out of GameObjectFactory.CreateObject
    {
        MetricsManager.LogError("Unknown mutation " + text);
        continue;
    }
    GamePartBlueprint gamePartBlueprint2 = new GamePartBlueprint(type); // constructor would be changed to set GamePartBlueprint.Type to this value, or instead take the concatenated string and call ModManager.ResolveType directly in the constructor
    gameObjectBlueprint.Mutations[item2.Key] = gamePartBlueprint2; // maybe change the dictionary to use Type keys instead? not sure if it'd be slower
}

Comments (1)

  1. Log in to comment