carmineos / rage-toolkit

Other
19 stars 6 forks source link

DataReader/DataWriter handle endianess of unmanaged structs which are not built-in C# types #17

Closed carmineos closed 3 years ago

carmineos commented 3 years ago

Actually blocks like BVHNode, BVHTreeInfo, BoundPrimitive, BoundVertex, BoundMaterial could be used as structs which should improve a lot the read/write speed and as well reduce the required allocations when dealing with #bn files.

The current DataReader/DataWriter implementation from dev/performance branch doesn't support swapping endianess on such structs as they would just swap the whole byte arrays. An idea could be to add an interface which adds a SwapEndianess method and all such struct blocks will have to implement that (to manually swap each own field) if endianess needs to be swapped in DataReader/DataWriter

carmineos commented 3 years ago

Added some methods to reverse endianness of primitive types https://github.com/carmineos/gta-toolkit/commit/68b39d4534a6b968d5ce8aa0e35176667df607fc

Each struct could just implement such interface and handle the reversing itself

public interface IReverseEndianness
{
    void ReverseEndianness();
}