Git Product home page Git Product logo

Comments (5)

snake-biscuits avatar snake-biscuits commented on June 28, 2024

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!

from bsp_tool.

snake-biscuits avatar snake-biscuits commented on June 28, 2024

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

from bsp_tool.

snake-biscuits avatar snake-biscuits commented on June 28, 2024

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

from bsp_tool.

snake-biscuits avatar snake-biscuits commented on June 28, 2024

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

from bsp_tool.

snake-biscuits avatar snake-biscuits commented on June 28, 2024

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

from bsp_tool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.