84 lines
2.4 KiB
C
84 lines
2.4 KiB
C
#include <world.h>
|
|
#include <state.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
void tc_add_chunk_to_loader(tc_chunkloader_s *loader, tc_entity_s *entity);
|
|
|
|
|
|
tc_worldgen_s tc_default_terrain_generator_g;
|
|
void tc_init_world_generators()
|
|
{
|
|
tc_default_terrain_generator_g.name = "Default Terrain Generator";
|
|
tc_default_terrain_generator_g.fn_generate_chunk = &tc_generate_default_terrain_chunk;
|
|
}
|
|
|
|
|
|
void tc_init_worlds()
|
|
{
|
|
tc_init_chunk_pool(256);
|
|
tc_init_world_generators();
|
|
}
|
|
|
|
|
|
|
|
void tc_set_block_in_chunk(
|
|
tc_chunk_s *chunk,
|
|
uint8_t x, uint8_t y, uint8_t z,
|
|
tc_block_s block
|
|
) {
|
|
chunk->blocks[x][y][z] = block.type_identifier;
|
|
}
|
|
|
|
void tc_draw_world(tc_world_s *world)
|
|
{
|
|
for(u32_t loader_index = 0; loader_index < world->num_loaders; ++loader_index)
|
|
{
|
|
if(world->loaders[loader_index].is_rendered) tc_draw_chunkloader_zone(&world->loaders[loader_index]);
|
|
}
|
|
}
|
|
|
|
tc_chunkloader_s tc_create_spawn_loader(tc_world_s *world)
|
|
{
|
|
tc_chunk_location_s loader_location;
|
|
loader_location.world = world;
|
|
loader_location.grid_coords.x = 0.0f;
|
|
loader_location.grid_coords.y = 0.0f;
|
|
loader_location.grid_coords.z = 0.0f;
|
|
|
|
tc_chunkloader_s loader = tc_create_chunkloader(loader_location);
|
|
loader.is_rendered = TRUE;
|
|
|
|
return loader;
|
|
}
|
|
|
|
tc_world_s * tc_new_world(tc_worldgen_s *generator)
|
|
{
|
|
tc_world_s *world = calloc(sizeof(tc_world_s), 1);
|
|
world->on_chunk_create = tc_new_hooklist(16);
|
|
world->before_chunk_generate = tc_new_hooklist(16);
|
|
world->after_chunk_generate = tc_new_hooklist(16);
|
|
world->on_chunk_delete = tc_new_hooklist(16);
|
|
world->on_chunk_update = tc_new_hooklist(16);
|
|
world->worldgen = &tc_default_terrain_generator_g;
|
|
world->num_loaders = 1;
|
|
world->loaders = malloc(sizeof(tc_chunkloader_s) * world->num_loaders);
|
|
world->loaders[0] = tc_create_spawn_loader(world);
|
|
world->spawn_loader = &world->loaders[0];
|
|
|
|
tc_add_to_hooklist(&world->after_chunk_generate, (tc_fn_hook) tc_meshize_chunk, NULL);
|
|
|
|
tc_run_hooklist(&tc_game_state_g.on_world_create, world);
|
|
|
|
tc_update_world(world);
|
|
|
|
return world;
|
|
}
|
|
|
|
void tc_unload_world(tc_world_s *world)
|
|
{
|
|
tc_delete_chunkloader(*world->spawn_loader);
|
|
free(world);
|
|
}
|
|
|