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

DisplacementInfo Neighbours aren’t mapped yet #75

Open
5 of 11 tasks
snake-biscuits opened this issue Dec 14, 2022 · 5 comments
Open
5 of 11 tasks

DisplacementInfo Neighbours aren’t mapped yet #75

snake-biscuits opened this issue Dec 14, 2022 · 5 comments
Assignees
Labels
documentation This issue involves a lack of documentation enhancement New feature or request need test We need to write a test for regression testing slow burn lots of work & will take a long time Source Engine Applies to all Source Engine branch scripts Test Map: Tools: Hammer This test map can be built in Hammer Test Map: Tools: Obscure This test map needs a unique Level Editor / other tool Test Map: Tools: Unknown Haven’t found an editor / compiler Test Map Adding a map to ship with bsp_tool for tests

Comments

@snake-biscuits
Copy link
Owner

snake-biscuits commented Dec 14, 2022

Displacement Neighbour sub-structs aren't mapped yet
They're also nasty to pack / unpack, as they don't match the byte alignment of their parent

Look at #74 & #73 for then arguments in favour of using inheritance to simplify this nightmare
(valve.source.DisplacementInfo can do the black magic and the others can copy)

Test Maps

Enjoy the pain

@snake-biscuits snake-biscuits added enhancement New feature or request documentation This issue involves a lack of documentation slow burn lots of work & will take a long time labels Dec 14, 2022
@snake-biscuits snake-biscuits self-assigned this Dec 14, 2022
@snake-biscuits
Copy link
Owner Author

The Source Engine definitions for ddispinfo_t mess with how C/C++ packs structs to create some oddly aligned structures

Just kidding, everything is padded automatically

/* chaos_bsp.c */
typedef struct { float x, y, z; }  Vector;

struct DispSubNeighbor_t {
    unsigned int   neighbor;
    unsigned char  neighborOrient;
    unsigned char  span;
    unsigned char  neighborSpan;
};

struct DispNeighbor_t {
    struct DispSubNeighbor_t  neighbors[2];
};

struct DispCornerNeighbors_t {
    unsigned int   neighbors[4];
    unsigned char  neighborCount;
};

#define ALLOWEDVERTS_SIZE  10
struct ddispinfo_t {
    Vector                        startPosition;
    int                           m_iDispVertStart;
    int                           m_iDispTriStart;
    int                           power;
    int                           minTess;
    float                         smoothingAngle;
    int                           contents;
    unsigned int                  m_iMapFace;
    int                           m_iLightmapAlphaStart;
    int                           m_iLightmapSamplePositionStart;
    struct DispNeighbor_t         m_EdgeNeighbors[4];
    struct DispCornerNeighbors_t  m_CornerNeighbors[4];
    unsigned int                  m_AllowedVerts[ALLOWEDVERTS_SIZE];
};

int main(int argc, char *argv[]) {
    #define SHOW_SIZE(s)  printf("%32s | %lu\n", #s, sizeof(s))
    SHOW_SIZE(struct DispSubNeighbor_t);
    SHOW_SIZE(struct DispNeighbor_t);
    SHOW_SIZE(struct DispCornerNeighbors_t);
    SHOW_SIZE(struct ddispinfo_t);
    #undef SHOW_SIZE
    return 0;
}
$ ./chaos_bsp.exe
        struct DispSubNeighbor_t | 8
           struct DispNeighbor_t | 16
    struct DispCornerNeighbors_t | 20
              struct ddispinfo_t | 232

So, we only have to add padding members to each child struct & hook up classes
No .from_bytes() & .as_bytes() overrides required!

@snake-biscuits
Copy link
Owner Author

Though I would like to make sure the LumpClasses use inheritance & add num_displacement_vertices & _triangles properties.
If .bsp files can be thought of as SQL tables, I don't see why LumpClasses can't be VIEWs, rather than just TABLEs

@snake-biscuits snake-biscuits added Test Map Adding a map to ship with bsp_tool for tests Test Map: Tools: Hammer This test map can be built in Hammer Test Map: Tools: Unknown Haven’t found an editor / compiler Test Map: Tools: Obscure This test map needs a unique Level Editor / other tool labels Dec 16, 2022
@snake-biscuits snake-biscuits changed the title DisplacementInfo child packing refactor DisplacementInfo Neighbours aren’t mapped yet Dec 17, 2022
@snake-biscuits snake-biscuits added this to the v0.4.0 milestone Jan 25, 2023
@snake-biscuits
Copy link
Owner Author

valve.source.DisplacementInfo neighbours get read with bad alignment, getting garbage values in enums & padding

@snake-biscuits
Copy link
Owner Author

We need more robust testing on how displacements are parsed, especially neighbours
This might require new displacement related methods in valve.source
Just testing for valid start positions & displacement face connections would be a start

valid enum & padding == 0 checks are also relatively simple

@snake-biscuits snake-biscuits added the need test We need to write a test for regression testing label Feb 14, 2023
@snake-biscuits
Copy link
Owner Author

The __repr__ is also really bad, a prettyprint __repr__ for the big displacement neighbours chunk would be really nice
respawn.apex_legends.BVHNode.__repr__ already has a custom __repr__, should make for a good reference

We could even mimic the nice code comment diagrams from the Source SDK

@snake-biscuits snake-biscuits modified the milestones: v0.4.0, v0.5.0 Mar 17, 2023
@snake-biscuits snake-biscuits added the Source Engine Applies to all Source Engine branch scripts label Aug 12, 2023
@snake-biscuits snake-biscuits moved this to Todo: Maps in bsp_tool Test Maps Aug 12, 2023
@snake-biscuits snake-biscuits moved this from Todo: Maps to Todo: Tools in bsp_tool Test Maps Aug 12, 2023
@snake-biscuits snake-biscuits moved this to Todo: Research in bsp_tool Format Coverage Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This issue involves a lack of documentation enhancement New feature or request need test We need to write a test for regression testing slow burn lots of work & will take a long time Source Engine Applies to all Source Engine branch scripts Test Map: Tools: Hammer This test map can be built in Hammer Test Map: Tools: Obscure This test map needs a unique Level Editor / other tool Test Map: Tools: Unknown Haven’t found an editor / compiler Test Map Adding a map to ship with bsp_tool for tests
Projects
Status: Todo: Code
Status: Todo: Research
Status: Todo: Tools
Development

No branches or pull requests

1 participant