Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code generation for nested send nodes #5

Open
absolutedogy opened this issue Sep 9, 2024 · 0 comments
Open

Code generation for nested send nodes #5

absolutedogy opened this issue Sep 9, 2024 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@absolutedogy
Copy link
Contributor

When we are reading the fields for an entity mapping, some fields will have shared names which at first pass looks confusing as an object can't have two "m_vecX" assigned to it.

However, this is because they are directly assigned nested values, which are determined by the send node for the item.

For example consider the following field on "CBodyComponentBaseAnimGraph"

{
    "Name": "m_vecX",
    "SendNode": "m_skeletonInstance.m_vecOrigin"
}

When we dump this field to the class definition JSON schema it will be represented as

"Fields": {
    "m_skeletonInstance": {
      "m_vecOrigin": {
        "m_cellX": {
          "Path": 0,
          "Type": "UInt16",
          "NetworkTyppe": "uint16"
        }
}

This also leads to a situation where we have multiple fields called "m_cellX" but they are actually being mapped to objects within the base object.

It might seem like this should be handled by a sub mapping, but the reality is that these are not sub entities but just objects within the base object that have direct mappings to them, so we are only given a single value in the field path assigning to them but need to look at the nested field.

As well this nested object will have to actually be generated as part of the class definition generation code.

So when parsing this entity it should produce a generated class that looks something like this.

public class CBodyComponentBaseAnimGraph{

    public m_skeletonInstanceDef m_skeletonInstance { get; set; } = new();


    public override UpdateProperty(ReadOnlySpan<byte> path, object value){
        switch(path[0]){
            case 0:
                m_skeletonInstance.m_vecOrigin.m_cellX = (short)value;
            break;
        }

    }
    public class m_skeletonInstanceDef{
        public m_vecOriginDef m_vecOrigin { get;set; } = new();

        public class m_vecOriginDef{
            public ushort m_cellX { get; set; }
        }
    }
}

Note that for this iteration of the project, because code gen is easy to make repeated code like sub classes without much effort, just having the send nodes treated as sub classes even if it might be a "shared" type is going to be the path forward.

In future iterations there should be some sort of context that gets kept during generation to track the creation of nested send nodes, but this is a more complicated task and there are other improvements to handle before that becomes a pressing issue.

@absolutedogy absolutedogy added the help wanted Extra attention is needed label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant