Files
enter_the_fog/source_code/block_module/block/block.h
2026-03-26 14:46:39 -05:00

52 lines
1.7 KiB
C

#ifndef block_h
#define block_h
#include <stdint.h>
#include <raylib.h>
typedef enum block_id_struct {
block_air = 0,
block_dirt = 1,
block_grass = 2,
block_stone = 3,
block_wood = 4,
block_type_count
} block_id_struct;
typedef struct block_render_data_struct {
struct Color color;
bool is_transparent;
struct {
uint8_t top;
uint8_t bottom;
uint8_t front;
uint8_t back;
uint8_t left;
uint8_t right;
} texture;
} block_render_data_struct;
/**
* Retrieves the rendering data and metadata for a specific block identifier.
* * This function acts as a safe accessor for the global block library. It
* performs bounds checking on the provided identifier to ensure it exists
* within the library's memory range. If the identifier is invalid or
* out of bounds, it returns the data for 'block_air' as a safe default
* to prevent segmentation faults or undefined rendering behavior.
* * @param id_to_look_up The unique identifier of the block to retrieve.
* @return The rendering data structure corresponding to the block identifier.
*/
block_render_data_struct get_block_data(block_id_struct id_to_look_up);
/**
* Calculates the texture coordinates (UVs) for a specific face of a block.
* This function maps a block's texture index to a 2D position within a 16x16
* texture atlas and handles the V-axis inversion required for OpenGL.
*/
void get_block_face_texture_coordinates(block_id_struct block_id,
int32_t face_direction,
float texture_coordinates[4][2]);
#endif