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

83 lines
2.1 KiB
C
Raw Normal View History

2023-10-11 08:10:06 +00:00
#ifndef TC_WORLD_H
#define TC_WORLD_H
#include <stdbool.h>
#include <blocks.h>
2023-10-15 12:41:53 +00:00
#include <hook.h>
#include <physics/simulation.h>
#include <utility/math.h>
2023-10-17 14:37:19 +00:00
#include <entity/entity.h>
#include <world/chunk.h>
#include <world/chunk_pool.h>
2023-10-11 08:10:06 +00:00
2023-10-14 08:47:21 +00:00
#define UPDATE_DISTANCE 2
2023-10-11 08:10:06 +00:00
typedef struct tc_block tc_block_s;
typedef struct tc_world tc_world_s;
2023-10-12 16:52:05 +00:00
2023-10-17 11:25:02 +00:00
typedef struct tc_worldgen tc_worldgen_s;
struct tc_worldgen {
2023-10-11 08:10:06 +00:00
char *name;
2023-10-17 11:25:02 +00:00
bool_t (*fn_generate_chunk) (tc_worldgen_s *gen, tc_chunk_s *chunk);
2023-10-11 08:10:06 +00:00
};
struct tc_block
{
2023-10-15 12:41:53 +00:00
u32_t type_identifier;
tc_vec3f_s position;
tc_vec3f_s rotation;
2023-10-11 08:10:06 +00:00
};
2023-10-12 16:52:05 +00:00
struct tc_world
{
tc_chunk_pool_s *pool;
2023-10-11 08:10:06 +00:00
tc_worldgen_s *worldgen;
2023-10-15 12:41:53 +00:00
u32_t num_loaders;
2023-10-12 16:52:05 +00:00
tc_chunkloader_s *loaders;
2023-10-14 08:47:21 +00:00
tc_chunkloader_s *spawn_loader;
tc_physics_simulation_s *physics;
2023-10-15 12:41:53 +00:00
tc_hooklist_s on_chunk_create;
2023-10-17 11:25:02 +00:00
tc_hooklist_s before_chunk_generate;
2023-10-15 12:41:53 +00:00
tc_hooklist_s after_chunk_generate;
tc_hooklist_s on_chunk_update;
2023-10-17 14:37:19 +00:00
tc_hooklist_s on_chunk_unload;
tc_hooklist_s on_chunk_delete;
2023-10-11 08:10:06 +00:00
};
2023-10-12 16:52:05 +00:00
extern tc_worldgen_s tc_default_terrain_generator_g;
void tc_init_worlds ();
2023-10-11 08:10:06 +00:00
void tc_draw_world (tc_world_s *world);
2023-10-12 16:52:05 +00:00
tc_world_s * tc_new_world (tc_worldgen_s *generator);
2023-10-15 09:51:45 +00:00
tc_chunk_s * tc_new_chunk (tc_world_s *world, i32_t x, i32_t y, i32_t z); // must be integers
2023-10-11 08:10:06 +00:00
void tc_set_block_in_chunk(
tc_chunk_s *chunk,
2023-10-15 09:51:45 +00:00
u8_t x, u8_t y, u8_t z,
2023-10-11 08:10:06 +00:00
tc_block_s block
);
2023-10-12 16:52:05 +00:00
void tc_update_world (tc_world_s *world);
2023-10-17 11:25:02 +00:00
void tc_unload_world (tc_world_s *world);
2023-10-12 16:52:05 +00:00
2023-10-17 11:25:02 +00:00
bool_t tc_generate_default_terrain_chunk (tc_worldgen_s *gen, tc_chunk_s *chunk);
2023-10-12 16:52:05 +00:00
2023-10-15 12:41:53 +00:00
void tc_create_world_physics (tc_world_s *world, void *userdata);
2023-10-11 08:10:06 +00:00
#endif