Fixed warnings

This commit is contained in:
Eric-Paul Ickhorn 2023-10-14 16:48:09 +02:00
parent 9ed734c860
commit 03ae44ae58
6 changed files with 20 additions and 63 deletions

View File

@ -42,8 +42,8 @@ struct tc_image
uint32_t x; // Only used if this is a subimage
uint32_t y; // Only used if this is a subimage
uint32_t width;
uint32_t height;
int32_t width;
int32_t height;
void *pixels;
};

View File

@ -3,29 +3,16 @@
#include <stdlib.h>
#include <stdio.h>
void tc_on_each_chunkloader(tc_world_s *world, bool (*fn_do)(tc_chunkloader_s *loader, void *userdata), void *userdata)
void tc_add_chunk_to_loader(tc_chunkloader_s *chunkloader, tc_chunk_s *chunk)
{
for(uint32_t loader_index = 0; loader_index < world->num_loaders; ++loader_index)
if(fn_do(&world->loaders[loader_index], userdata)) return;
}
void tc_on_each_loaded_chunk(tc_world_s *world, bool (*fn_do)(tc_chunk_s *chunk, void *userdata), void *userdata)
if(chunkloader->num_chunks >= chunkloader->chunks_capacity)
{
for(uint32_t loader_index = 0; loader_index < world->num_loaders; ++loader_index)
for(uint32_t chunk_index = 0; chunk_index < world->loaders[loader_index].num_chunks; ++chunk_index)
if(fn_do(world->loaders[loader_index].chunks[chunk_index], userdata)) return;
chunkloader->chunks_capacity *= 2;
chunkloader->chunks = realloc(chunkloader->chunks, sizeof(tc_chunk_s) * chunkloader->chunks_capacity);
}
void tc_on_each_chunk_of_loader(tc_chunkloader_s *loader, bool (*fn_do)(tc_chunk_s *chunk, void *userdata), void *userdata)
{
uint32_t chunk_index = 0;
while(chunk_index < loader->num_chunks)
{
if(fn_do(loader->chunks[chunk_index], userdata)) return;
++chunk_index;
chunkloader->chunks[chunkloader->num_chunks] = chunk;
++chunkloader->num_chunks;
}
}
bool tc_coord_is_within_loaders_range(tc_chunkloader_s *loader, tc_vec3i_s coord)
{
@ -102,7 +89,6 @@ void tc_reload_chunk(tc_world_s *world, tc_vec3i_s coord)
void tc_remove_loaders_chunk(tc_chunkloader_s *loader, uint32_t index)
{
tc_vec3i_s position = loader->chunks[index]->position;
tc_free_chunk(loader->world, loader->chunks[index]);
if(loader->num_chunks != 0)
@ -173,4 +159,3 @@ void tc_update_world(tc_world_s *world)
++world_update_tick;
}
// TODO: Set center chunk

View File

@ -86,7 +86,7 @@ struct tc_entity_registry
tc_entity_registry_s tc_init_entity_registry ();
void tc_register_entity_type (tc_entity_type_s type);
tc_entity_type_s * tc_get_entity_type_from_name (char *name);
tc_entity_type_s * tc_get_entity_type_with_name (char *name);
tc_entity_s * tc_create_entity (char *type);
void tc_spawn_entity (tc_entity_s *entity, tc_location_s location);

View File

@ -28,13 +28,15 @@ tc_shader_program_s tc_make_shader_program(char *vertex_path, char *fragment_pat
int fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
int len_vertex_source = 0;
char *vertex_source = load_file(vertex_path, &len_vertex_source);
const char *vertex_source = load_file(vertex_path, &len_vertex_source);
const char *const *vsource = &vertex_source;
int len_fragment_source = 0;
char *fragment_source = load_file(fragment_path, &len_fragment_source);
const char *fragment_source = load_file(fragment_path, &len_fragment_source);
const char *const *fsource = &fragment_source;
glShaderSource(vertex_shader, 1, &vertex_source, &len_vertex_source);
glShaderSource(fragment_shader, 1, &fragment_source, &len_fragment_source);
glShaderSource(vertex_shader, 1, vsource, &len_vertex_source);
glShaderSource(fragment_shader, 1, fsource, &len_fragment_source);
glCompileShader(vertex_shader);
glCompileShader(fragment_shader);

View File

@ -94,26 +94,9 @@ void tc_set_block_in_chunk(
void tc_draw_world(tc_world_s *world)
{
tc_on_each_loaded_chunk(world, tc_draw_chunk, world);
}
/*
void tc_add_chunk(tc_world_s *world, tc_chunk_s *chunk)
{
if(world->num_chunks >= world->chunks_capacity)
{
world->chunks_capacity *= 2;
world->chunks = realloc(world->chunks, sizeof(tc_chunk_s *) * world->chunks_capacity);
}
world->chunks[world->num_chunks] = chunk;
++world->num_chunks;
}
*/
void tc_setup_terrain(tc_world_s *world)
{
// TODO
for(uint32_t loader_index = 0; loader_index < world->num_loaders; ++loader_index)
for(uint32_t chunk_index = 0; chunk_index < world->loaders[loader_index].num_chunks; ++chunk_index)
tc_draw_chunk(world->loaders[loader_index].chunks[chunk_index], world);
}
tc_chunkloader_s tc_create_chunkloader(tc_world_s *world)
@ -133,17 +116,6 @@ tc_chunkloader_s tc_create_chunkloader(tc_world_s *world)
return loader;
}
void tc_add_chunk_to_loader(tc_chunkloader_s *chunkloader, tc_chunk_s *chunk)
{
if(chunkloader->num_chunks >= chunkloader->chunks_capacity)
{
chunkloader->chunks_capacity *= 2;
chunkloader->chunks = realloc(chunkloader->chunks, sizeof(tc_chunk_s) * chunkloader->chunks_capacity);
}
chunkloader->chunks[chunkloader->num_chunks] = chunk;
++chunkloader->num_chunks;
}
tc_chunkloader_s tc_create_spawn_loader(tc_world_s *world)
{
tc_chunkloader_s loader = tc_create_chunkloader(world);
@ -158,15 +130,11 @@ tc_world_s * tc_new_world(tc_worldgen_s *generator)
tc_world_s *world = calloc(sizeof(tc_world_s), 1);
world->pool = tc_new_chunk_pool(512);
world->worldgen = &tc_default_terrain_generator_g;
// world->center_chunk = tc_new_chunk(world, 0, 0, 0);
// world->load_radius = 3;
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_upload_chunk(world->center_chunk);
return world;
}

View File

@ -113,9 +113,11 @@ void tc_set_block_in_chunk(
uint32_t tc_count_chunk_vertices (tc_chunk_s *chunk);
void tc_meshize_chunk (tc_chunk_s *chunk);
void tc_upload_chunk (tc_chunk_s *chunk);
bool tc_generate_default_terrain_chunk (tc_worldgen_s *gen, tc_chunk_s *chunk);
void tc_add_chunk_to_loader (tc_chunkloader_s *chunkloader, tc_chunk_s *chunk);
tc_chunk_s * tc_load_chunk_at (tc_world_s *world, int32_t x, int32_t y, int32_t z);
tc_chunk_s * tc_get_loaded_chunk_at (tc_world_s *world, int32_t x, int32_t y, int32_t z);
bool tc_chunk_is_loaded (tc_world_s *world, int32_t x, int32_t y, int32_t z);