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

Genericifying the trace -> replay code #23

Open
greggman opened this issue Dec 30, 2022 · 0 comments
Open

Genericifying the trace -> replay code #23

greggman opened this issue Dec 30, 2022 · 0 comments

Comments

@greggman
Copy link
Collaborator

There's lots of trace data that's like

{
   someField: number;
   someOtherField: number;
   textureSerial: number;
}

And there is code that converts textureSerial: number to texture: someReplayTexture

It made me wonder if there would be any benefit from trying to make that code just scan every trace object for xxxSerial and then do auto convert. Something like

function deserilize(traceObject, replay) {
    const kSerial = 'Serial';
    for (const [key, value] of Object.entries(traceObject)) {
         if (Array.isArray(value)) {
             for (const elem of value) {
                 if (typeof elem === 'object') {
                     deserialize(elem, replay);
                 }
             }
         } else if (typeof value === 'object') {
             deserialize(value, replay)
         } else if (key.endsWith(kSerial)) {
             const type = key.substring(0, key.length - kSerial.length);
             traceObject[type] = replay[`${type}s`][value];
             delete traceObject[key];  // probably needs to be moved out of loop
         }
    }
}

I don't know if that would be generic enough or if there'd be so many exceptions it's not worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant