vabold / Kinoko

A reimplementation of Mario Kart Wii's physics engine in C++
MIT License
46 stars 10 forks source link

Create an alignment function for `EGG::Stream` to handle padding bytes #129

Open vabold opened 4 months ago

vabold commented 4 months ago

It would look something like this:

    s32 align(s32 alignment = 4);

    template <ParseableType T>
    s32 align() {
        return align(sizeof(T));
    }

The non-template version takes in an s32 alignment. If the alignment is positive, it rounds up. For completion, if the alignment is negative, it rounds down. The return value is the change in m_index as a result. It has a default parameter of 4; we typically target 32-bit files, so we assume that struct alignment is 4.

The template version would align to the nearest valid index for a given parseable type. We ensure that it's a parseable type, as if we are aligning for a struct, the non-template version should be used instead.