Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Data-Driven Programming #7

Open
ldo opened this issue Jan 21, 2022 · 0 comments
Open

Data-Driven Programming #7

ldo opened this issue Jan 21, 2022 · 0 comments

Comments

@ldo
Copy link

ldo commented Jan 21, 2022

There are ways to make some of the code less tedious to read and write, by putting repetitive stuff into tables. For example, in WMB_Header.__init__(), the extraction of the bulk of the header fields could be reworked into something like

for field, conv, size in \
    (
        ("unknown08", to_int, 4),
        ("flags", to_int, 4),
        ("bounding_box1", to_float, 4),
        ("bounding_box2", to_float, 4),
        ("bounding_box3", to_float, 4),
        ("bounding_box4", to_float, 4),
        ("bounding_box5", to_float, 4),
        ("bounding_box6", to_float, 4),
        ("boneArrayOffset", to_int, 4),
        ("boneCount", to_int, 4),
        ("unknownChunk1Offset", to_int, 4),
        ("unknownChunk1DataCount", to_int, 4),
        ("vertexGroupArrayOffset", to_int, 4),
        ("vertexGroupCount", to_int, 4),
        ("meshArrayOffset", to_int, 4),
        ("meshCount", to_int, 4),
        ("meshGroupInfoArrayHeaderOffset", to_int, 4),
        ("meshGroupInfoArrayCount", to_int, 4),
        ("colTreeNodesOffset", to_int, 4),
        ("colTreeNodesCount", to_int, 4),
        ("boneMapOffset", to_int, 4),
        ("boneMapCount", to_int, 4),
        ("bonesetOffset", to_int, 4),
        ("bonesetCount", to_int, 4),
        ("materialArrayOffset", to_int, 4),
        ("materialCount", to_int, 4),
        ("meshGroupOffset", to_int, 4),
        ("meshGroupCount", to_int, 4),
        ("offsetMeshMaterials", to_int, 4),
        ("numMeshMaterials", to_int, 4),
        ("unknownWorldDataArrayOffset", to_int, 4),
        ("unknownWorldDataArrayCount", to_int, 4),
        ("unknown8C", to_int, 4),
    ) \
:
    setattr(self, field, conv(wmb_fp.read(size)))
#end for

Anyway, you get the idea.

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

No branches or pull requests

1 participant