Skip to content

Genericifying the trace -> replay code #23

Open
@greggman

Description

@greggman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions