calc_hooked.c - aalesv/2boost GitHub Wiki

calc_hooked.c

This file contains all 2Boost maps and map pointer structure (also called tables and table pointer structures) for 3D and 2D maps, Lookup tables LUT_3D_UINT for 3D maps lookup and LUT_2D_UINT for 2D maps lookup, and all hooked and service functions except for Speed Density (which are located in speed_density.c).

Maps, map pointer structures and Lookup tables entries are created by macros to minimize errors.

static const table_3d_uint_t * const LUT_3D_UINT[][LUT_COLUMN_COUNT]

Array of pointers. Populated at compile time by macros. LUT_COLUMN_COUNT is constant defined at compile time. Each row contains address of pointer structure to 3D table . Column 0 contains address of ROM pointer structure, column 1 contains address of 2Boost pointer structure for map 1, column 2 contains address of 2Boost pointer structure for map 2, and so on. The last column contains address of 2Boost pointer structure for Overtake map.

static const table_2d_uint_t * const LUT_2D_UINT[][LUT_COLUMN_COUNT]

Array of pointers. Populated at compile time by macros. LUT_COLUMN_COUNT is constant defined at compile time. Each row contains address of pointer structure to 2D table . Column 0 contains address of ROM pointer structure, column 1 contains address of 2Boost pointer structure for map 1, column 2 contains address of 2Boost pointer structure for map 2, and so on. The last column contains address of 2Boost pointer structure for Overtake map.

float calc_3d_uint_to_float_hooked(const float x, const float y, const table_3d_uint_t *tablePointer)

This function replaces the ROM 3D table calculation function. It takes in two float values representing the X and Y axis values, and a pointer to a structure that describes a 3D table with float number axises and 8-bit or 16-bit integer data. The function sets the tablePointer to the result of getPointerFromLut function call. Finally, the function calls the original 3D table calculation function and returns the calculated float Z axis value.

float calc_2d_uint_to_float_hooked(const float x, const table_2d_uint_t *tablePointer)

This function replaces the ROM 2D table calculation function. It takes in a float value representing the X axis value and a pointer to a structure that describes a 2D table with float number axis and 8-bit or 16-bit integer data. The function sets the tablePointer to the result of getPointerFromLut function call. Finally, the function calls the original 2D table calculation function and returns the calculated float Y axis value.

static int getLutRowNumber(const int LUT[][LUT_COLUMN_COUNT], int lutRowCount, int elementToFind)

This is a lookup function that takes in a two-dimensional array of integers, the row count of the Lookup table, and an integer value to look for in the zero column of the Lookup table. LUT_COLUMN_COUNT is the constant defined at compile time. The function iterates through each row of the Lookup table, checking the zero column for the elementToFind value. If the value is found, the function returns the row index. If the value is not found, the function returns -1.

static int getPointerFromLut (const int LUT[][LUT_COLUMN_COUNT], int lutRowCount, int elementToFind)

This is a lookup function that takes in a two-dimensional array of integers, the row count of the Lookup table, and an integer value to look for in the zero column of the Lookup table. LUT_COLUMN_COUNT is the constant defined at compile time. The function first performs a Lookup table lookup by calling getLutRowNumber which returns the index of the table if it is found. If the table is found, the function obtains the current global map switch value, checks this value to prevent array overrun by calling sanitizeLutSecondIndex, and then sets the elementToFind to point to the correct table. Finally, the function returns elementToFind.

static inline uint8 sanitizeLutSecondIndex(uint8 index)

This is a helper function that takes in a uint8 index value and ensures that it does not exceed the maximum index value of the Lookup table. If the index value is greater than the maximum value LUT_COLUMN_COUNT defined at compile time, the function sets the index to 0 and returns the sanitized index value.

This page was created with help of ChatGPT

⚠️ **GitHub.com Fallback** ⚠️