Techneck/code/source-c/world/chunk.h

96 lines
3.2 KiB
C

#ifndef TC_CHUNK_H
#define TC_CHUNK_H
#include <utility/location.h>
#include <entity/entity.h>
typedef struct tc_chunk tc_chunk_s;
typedef struct tc_chunkloader tc_chunkloader_s;
struct tc_chunk
{
void *pool_entry;
tc_chunk_location_s location;
u32_t blocks[32][32][32];
i32_t refcounter;
u32_t num_vertices;
f32_t *vertex_positions;
f32_t *vertex_uvs;
u32_t vao;
u32_t vbo;
bool_t is_renderable;
};
// tc_load_chunk_at: Looks if there's a chunk already loaded at 'location' and gets it if
// there is one. If it isn't loaded, this function will return NULL. The reference counter
// will be increased.
tc_entity_s * tc_load_chunk_at (tc_chunk_location_s location);
// tc_unload_chunk_at: Looks if there's a chunk already loaded at 'location' and decreases
// the reference counter by one, possibly free'ing the chunk and its related structures.
void tc_unload_chunk_at (tc_chunkloader_s *loader, tc_chunk_location_s location);
bool_t tc_chunk_is_loaded (tc_chunk_location_s location);
void tc_meshize_chunk (tc_chunk_s *chunk);
void tc_upload_chunk (tc_chunk_s *chunk);
typedef struct tc_chunklist_entry tc_chunklist_entry_s;
typedef struct tc_chunklist tc_chunklist_s;
struct tc_chunklist_entry
{
tc_chunklist_entry_s *next;
tc_chunklist_entry_s *previous;
tc_entity_s *entity;
};
struct tc_chunklist
{
tc_chunklist_entry_s *first;
tc_chunklist_entry_s *first_free;
u32_t capacity;
tc_chunklist_entry_s *entries;
};
tc_chunklist_s tc_create_chunklist (u32_t capacity);
void tc_delete_chunklist (tc_chunklist_s list);
// tc_chunklist_remove_item: Adds a chunk to the chunklist.
// THIS FUNCTION DOES NOT UPDATE THE REFERENCE COUNTER OF THE CHUNK!
void tc_chunklist_add_item (tc_chunklist_s *list, tc_entity_s *chunk);
// tc_chunklist_remove_item: Removes a chunk from the chunklist.
// THIS FUNCTION DOES NOT UPDATE THE REFERENCE COUNTER OF THE CHUNK!
void tc_chunklist_remove_item (tc_chunklist_s *list, tc_entity_s *chunk);
tc_entity_s * tc_chunklist_find_chunk_at (tc_chunklist_s *list, tc_chunk_location_s location);
struct tc_chunkloader
{
tc_chunk_location_s center;
tc_vec3i_s extent;
tc_chunklist_s chunklist;
bool_t needs_reload;
bool_t is_rendered;
};
tc_chunkloader_s tc_create_chunkloader (tc_chunk_location_s location);
void tc_delete_chunkloader (tc_chunkloader_s chunkloader);
void tc_draw_chunkloader_zone (tc_chunkloader_s *loader);
#endif // TC_CHUNK_H