55 lines
1.2 KiB
C

#ifndef CHUNK_H
#define CHUNK_H
#include <stdbool.h>
#include <GL/gl.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "utils.h"
typedef struct {
GLuint tid;
SDL_Surface *surface;
int type;
} Type_surface;
typedef enum {
BLOCKTYPE_AIR,
BLOCKTYPE_GRASS,
BLOCKTYPE_DIRT,
BLOCKTYPE_STONE,
BLOCKTYPE_COUNT,
} Block_type;
typedef struct
{
Block_type type;
bool visible;
} Block;
typedef struct {
vec3f start_pos;
Block blocks[CHUNK_MAX_X][CHUNK_MAX_Y][CHUNK_MAX_Z];
GLuint id;
} Chunk;
typedef struct
{
unsigned int chunk_count;
Chunk *chunks;
Type_surface *textures;
unsigned int texture_count;
} ChunkManager;
bool chunk_is_block_neighboring_block(Chunk* chunk, vec3i pos);
void chunk_set_blocks_visibility(Chunk* chunk);
void chunk_create_displayl(ChunkManager *cm, Chunk *chunk);
void chunk_render(Chunk* chunk);
void chunk_update(ChunkManager* cm, Chunk *chunk);
void draw_cube(ChunkManager *cm, Block_type type, float x, float y, float z, float s);
bool is_block(Block b);
int chunk_get_current_chunk_index(ChunkManager *cm, vec3f pos);
GLuint get_texture(ChunkManager *cm, Block_type type);
#endif