A little more restructuring

This commit is contained in:
Eric-Paul Ickhorn 2023-10-17 16:37:19 +02:00
parent 3a017e678e
commit 14d560dbf5
21 changed files with 69 additions and 44 deletions

View File

@ -7,6 +7,6 @@ gcc -g3 -o dependencies/build/glad.o \
-I dependencies/include/ -Wall
gcc -g3 -o techneck.elf \
code/source-c/*.c code/source-c/entity/*.c code/source-c/utility/*.c code/source-c/physics/*.c dependencies/build/glad.o \
code/source-c/*.c code/source-c/entity/*.c code/source-c/utility/*.c code/source-c/world/*.c code/source-c/world/generator/*.c code/source-c/physics/*.c dependencies/build/glad.o \
-I dependencies/include -I code/source-c/ -lGL -lSDL2 -lm -Wall

View File

@ -1,7 +1,7 @@
#include <entity/registration.h>
#include <chunk_pool.h>
#include <chunk.h>
#include <world.h>
#include <world/chunk_pool.h>
#include <world/chunk.h>
#include <world/world.h>
#include <state.h>
#include <glad/glad.h>
@ -31,7 +31,10 @@ void tc_create_chunk_entity(tc_entity_s *entity, void *userdata)
void tc_delete_chunk_entity(tc_entity_s *entity)
{
tc_chunk_s *chunk = entity->specific;
tc_chunk_s *chunk = entity->specific;
tc_world_s *world = chunk->location.world;
tc_run_hooklist(&world->on_chunk_delete, entity);
if(chunk->vao != 0) glDeleteVertexArrays(1, &chunk->vao);
if(chunk->vbo != 0) glDeleteBuffers(1, &chunk->vbo);

View File

@ -2,8 +2,8 @@
#ifndef TC_ENTITY_H
#define TC_ENTITY_H
#include "utility/location.h"
#include "utility/utility.h"
#include <utility/location.h>
#include <utility/utility.h>
typedef struct tc_interval tc_interval_s;
typedef struct tc_entity_event tc_entity_event_s;

View File

@ -2,7 +2,7 @@
#ifndef TC_ENTITY_REGISTRATION_H
#define TC_ENTITY_REGISTRATION_H
#include "../entity.h"
#include <entity/entity.h>
void tc_register_chunk_entity ();
void tc_register_player_entity ();

View File

@ -1,6 +1,6 @@
#include "state.h"
#include "world.h"
#include "entity/registration.h"
#include <state.h>
#include <world/world.h>
#include <entity/registration.h>
#include <SDL2/SDL.h>

View File

@ -21,6 +21,8 @@ void tc_add_physics_object(tc_physics_simulation_s *simulation, tc_physics_entit
void tc_add_physics_object_to(tc_physics_entity_s *container, tc_physics_entity_s *object)
{
if(container != NULL) object->super = container;
if((container->value.group.num_entities+1)
>=
container->value.group.entities_capacity
@ -76,7 +78,7 @@ i32_t tc_physics_find_entity_in_group(tc_physics_entity_s *group, tc_physics_ent
i32_t index = 0;
while(index < group->value.group.num_entities)
{
if(entity->super->value.group.entities[group->value.group.num_entities]
if(group->value.group.entities[group->value.group.num_entities]
==
entity
) return index;
@ -99,15 +101,18 @@ void tc_remove_physics_entity(tc_physics_entity_s *entity)
{
if(entity->super == NULL) return;
tc_free_physics_entity(entity);
// Fill up the gap created inside the entities-array.
i32_t index = 0;
if((index = tc_physics_find_entity_in_group(entity->super, entity)) == -1) return;
tc_physics_entity_s *super = entity->super;
entity->super->value.group.entities[index] =
entity->super->value.group.entities[entity->super->value.group.num_entities-1];
i32_t index = 0;
if((index = tc_physics_find_entity_in_group(super, entity)) == -1) return;
super->value.group.entities[index] =
super->value.group.entities[super->value.group.num_entities-1];
--super->value.group.num_entities;
tc_free_physics_entity(entity);
}

View File

@ -6,7 +6,7 @@
#include <physics/primitives.h>
#include <utility/utility.h>
#include <entity.h>
#include <entity/entity.h>
typedef struct tc_physics_entity tc_physics_entity_s;
typedef struct tc_entity_physics_attributes tc_entity_physics_attributes_s;

View File

@ -8,9 +8,9 @@
#include <assets.h>
#include <shaders.h>
#include <entity.h>
#include <entity/entity.h>
#include <blocks.h>
#include <world.h>
#include <world/world.h>
#include <utility/utility.h>
typedef struct tc_camera

View File

@ -1,4 +1,4 @@
#include "world.h"
#include <utility/utility.h>
int tc_perlin_permutation[] = {
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225,

View File

@ -1,4 +1,4 @@
#include <chunk.h>
#include <world/chunk.h>
#include <glad/glad.h>
#include <stddef.h>

View File

@ -3,7 +3,7 @@
#define TC_CHUNK_H
#include <utility/location.h>
#include <entity.h>
#include <entity/entity.h>
typedef struct tc_chunk tc_chunk_s;
typedef struct tc_chunkloader tc_chunkloader_s;

View File

@ -3,7 +3,7 @@
#define TC_CHUNK_POOL_H
#include <utility/utility.h>
#include <chunk.h>
#include <world/chunk.h>
typedef struct tc_chunk_pool tc_chunk_pool_s;
typedef struct tc_chunk_pool_entry tc_chunk_pool_entry_s;

View File

@ -1,5 +1,6 @@
#include "world.h"
#include "entity.h"
#include <world/world.h>
#include <entity/entity.h>
#include <state.h>
#include <stdlib.h>
#include <stdio.h>
@ -95,7 +96,6 @@ void tc_chunklist_add_item(tc_chunklist_s *list, tc_entity_s *chunk)
new_entry.entity = chunk;
new_entry.next = list->first;
(*list->first_free) = new_entry;
list->first = list->first_free;
// Link everything together
@ -104,6 +104,7 @@ void tc_chunklist_add_item(tc_chunklist_s *list, tc_entity_s *chunk)
list->first_free->previous = NULL;
// Finally assign it
list->first = list->first_free;
list->first_free = tc_chunklist_find_first_free(list);
}
@ -152,13 +153,13 @@ void tc_delete_chunkloader(tc_chunkloader_s loader)
bool_t tc_coord_is_within_loaders_range(tc_chunkloader_s *loader, tc_vec3i_s coord)
{
if(coord.x < (loader->center.grid_coords.x - loader->extent.x / 2)) return FALSE;
if(coord.y < (loader->center.grid_coords.y - loader->extent.y / 2)) return FALSE;
if(coord.z < (loader->center.grid_coords.z - loader->extent.z / 2)) return FALSE;
if(coord.x < ((loader->center.grid_coords.x - loader->extent.x / 2)-1)) return FALSE;
if(coord.y < ((loader->center.grid_coords.y - loader->extent.y / 2)-1)) return FALSE;
if(coord.z < ((loader->center.grid_coords.z - loader->extent.z / 2)-1)) return FALSE;
if(coord.x > (loader->center.grid_coords.x + loader->extent.x / 2)) return FALSE;
if(coord.y > (loader->center.grid_coords.y + loader->extent.y / 2)) return FALSE;
if(coord.z > (loader->center.grid_coords.z + loader->extent.z / 2)) return FALSE;
if(coord.x > ((loader->center.grid_coords.x + loader->extent.x / 2)+1)) return FALSE;
if(coord.y > ((loader->center.grid_coords.y + loader->extent.y / 2)+1)) return FALSE;
if(coord.z > ((loader->center.grid_coords.z + loader->extent.z / 2)+1)) return FALSE;
return TRUE;
}
@ -181,7 +182,9 @@ void tc_unload_chunk_at(tc_chunkloader_s *loader, tc_chunk_location_s location)
if(entity == NULL) return;
tc_chunk_s *chunk = entity->specific;
tc_world_s *world = location.world;
tc_run_hooklist(&world->on_chunk_unload, entity);
--chunk->refcounter;
if(chunk->refcounter < 1)

View File

@ -1,4 +1,4 @@
#include "world.h"
#include <world/world.h>
bool_t tc_generate_default_terrain_chunk(tc_worldgen_s *gen, tc_chunk_s *chunk)
{

View File

@ -1,4 +1,4 @@
#include <world.h>
#include <world/world.h>
#include <state.h>
#include <stdlib.h>
@ -48,6 +48,9 @@ tc_chunkloader_s tc_create_spawn_loader(tc_world_s *world)
tc_chunkloader_s loader = tc_create_chunkloader(loader_location);
loader.is_rendered = TRUE;
loader.extent.x = 9.0f;
loader.extent.z = 9.0f;
loader.extent.y = 3.0f;
return loader;
}
@ -59,6 +62,7 @@ tc_world_s * tc_new_world(tc_worldgen_s *generator)
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_unload = tc_new_hooklist(16);
world->on_chunk_update = tc_new_hooklist(16);
world->worldgen = &tc_default_terrain_generator_g;
world->num_loaders = 1;

View File

@ -8,9 +8,9 @@
#include <hook.h>
#include <physics/simulation.h>
#include <utility/math.h>
#include <entity.h>
#include <chunk.h>
#include <chunk_pool.h>
#include <entity/entity.h>
#include <world/chunk.h>
#include <world/chunk_pool.h>
#define UPDATE_DISTANCE 2
@ -52,8 +52,9 @@ struct tc_world
tc_hooklist_s on_chunk_create;
tc_hooklist_s before_chunk_generate;
tc_hooklist_s after_chunk_generate;
tc_hooklist_s on_chunk_delete;
tc_hooklist_s on_chunk_update;
tc_hooklist_s on_chunk_unload;
tc_hooklist_s on_chunk_delete;
};
extern tc_worldgen_s tc_default_terrain_generator_g;

View File

@ -1,10 +1,11 @@
#include <world.h>
#include <world/world.h>
#include <stddef.h> // For NULL
#include <stdio.h>
void tc_initialize_chunk_physics(tc_entity_s *chunk_entity, void *userdata)
{
/*
tc_chunk_s *chunk = chunk_entity->specific;
tc_world_s *world = chunk->location.world;
tc_physics_simulation_s *simulation = world->physics;
@ -40,13 +41,21 @@ void tc_initialize_chunk_physics(tc_entity_s *chunk_entity, void *userdata)
tc_add_physics_object(world->physics, chunk_body);
tc_set_pointer_for_entity(chunk_entity, "physics_body", chunk_body);
*/
}
void tc_free_chunk_physics(tc_entity_s *chunk_entity, void *userdata)
{
tc_physics_entity_s *body =
tc_get_pointer_from_entity(chunk_entity, "physics_body");
tc_remove_physics_entity(body);
}
void tc_create_world_physics(tc_world_s *world, void *userdata)
{
world->physics = tc_new_physics_simulation();
tc_add_to_hooklist(&world->on_chunk_create, (tc_fn_hook) tc_initialize_chunk_physics, NULL);
tc_add_to_hooklist(&world->on_chunk_update, (tc_fn_hook) tc_initialize_chunk_physics, NULL);
// tc_add_to_hooklist(&world->on_chunk_update, (tc_fn_hook) tc_initialize_chunk_physics, NULL);
tc_add_to_hooklist(&world->on_chunk_delete, (tc_fn_hook) tc_free_chunk_physics, NULL);
}