115 lines
2.9 KiB
C
115 lines
2.9 KiB
C
#ifndef WORLDGEN_H
|
|
#define WORLDGEN_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include "noise.h"
|
|
|
|
#define CHUNK_SIZE 16
|
|
#define CHUNK_HEIGHT 256
|
|
#define WORLDGEN_HEIGHT_CACHE_SIZE 32768
|
|
|
|
enum BlockId {
|
|
BLOCK_BEDROCK = 0,
|
|
BLOCK_STONE = 1,
|
|
BLOCK_DIRT = 2,
|
|
BLOCK_GRASS = 3,
|
|
BLOCK_WATER = 4,
|
|
BLOCK_AIR = 5,
|
|
BLOCK_OAK_LOG = 6,
|
|
BLOCK_OAK_LEAVES = 7,
|
|
BLOCK_BIRCH_LOG = 8,
|
|
BLOCK_BIRCH_LEAVES = 9,
|
|
BLOCK_COAL = 10,
|
|
BLOCK_SAND = 11,
|
|
BLOCK_GRAVEL = 12,
|
|
BLOCK_SNOW = 13,
|
|
BLOCK_TALL_GRASS = 14,
|
|
BLOCK_WILDFLOWER = 15,
|
|
BLOCK_COPPER_ORE = 16,
|
|
BLOCK_IRON_ORE = 17,
|
|
BLOCK_GOLD_ORE = 18,
|
|
BLOCK_REDSTONE_ORE = 19,
|
|
BLOCK_LAPIS_ORE = 20,
|
|
BLOCK_DIAMOND_ORE = 21,
|
|
BLOCK_OAK_PLANKS = 22,
|
|
BLOCK_SPRUCE_PLANKS = 23,
|
|
BLOCK_OAK_LOG_X = 24,
|
|
BLOCK_OAK_LOG_Z = 25,
|
|
BLOCK_SPRUCE_LOG_X = 26,
|
|
BLOCK_SPRUCE_LOG_Z = 27,
|
|
BLOCK_GLASS_PANE = 28,
|
|
BLOCK_GLASS = 29,
|
|
BLOCK_SPRUCE_DOOR_S_LOWER = 30,
|
|
BLOCK_SPRUCE_DOOR_S_UPPER = 31,
|
|
BLOCK_SPRUCE_DOOR_N_LOWER = 32,
|
|
BLOCK_SPRUCE_DOOR_N_UPPER = 33,
|
|
BLOCK_SPRUCE_DOOR_W_LOWER = 34,
|
|
BLOCK_SPRUCE_DOOR_W_UPPER = 35,
|
|
BLOCK_SPRUCE_DOOR_E_LOWER = 36,
|
|
BLOCK_SPRUCE_DOOR_E_UPPER = 37,
|
|
BLOCK_SPRUCE_STAIRS_E = 38,
|
|
BLOCK_SPRUCE_STAIRS_W = 39,
|
|
BLOCK_LADDER_N = 40,
|
|
BLOCK_LADDER_S = 41,
|
|
BLOCK_LADDER_W = 42,
|
|
BLOCK_LADDER_E = 43,
|
|
BLOCK_SMOOTH_STONE = 44,
|
|
BLOCK_STONE_BRICKS = 45,
|
|
BLOCK_BLACKSTONE = 46,
|
|
BLOCK_IRON_BARS = 47,
|
|
BLOCK_STONE_BRICK_STAIRS_E = 48,
|
|
BLOCK_STONE_BRICK_STAIRS_W = 49,
|
|
BLOCK_STONE_BRICK_STAIRS_N = 50,
|
|
BLOCK_STONE_BRICK_STAIRS_S = 51,
|
|
BLOCK_DANDELION = 52,
|
|
BLOCK_AZURE_BLUET = 53,
|
|
BLOCK_OXEYE_DAISY = 54,
|
|
BLOCK_CORNFLOWER = 55,
|
|
BLOCK_LILY_OF_THE_VALLEY = 56,
|
|
BLOCK_FERN = 57,
|
|
BLOCK_CLAY = 58,
|
|
BLOCK_SEAGRASS = 59
|
|
};
|
|
|
|
struct trail_segment;
|
|
|
|
typedef struct {
|
|
int chunk_x;
|
|
int chunk_z;
|
|
uint16_t heightmap[CHUNK_SIZE][CHUNK_SIZE];
|
|
uint16_t blocks[CHUNK_HEIGHT][CHUNK_SIZE][CHUNK_SIZE];
|
|
} chunk_data;
|
|
|
|
typedef struct {
|
|
int x;
|
|
int z;
|
|
int value;
|
|
uint8_t valid;
|
|
} worldgen_height_cache_entry;
|
|
|
|
typedef struct {
|
|
simplex_noise noise;
|
|
int sea_level;
|
|
int world_seed;
|
|
int enable_trails;
|
|
int enable_wall;
|
|
int wall_min_x, wall_max_x, wall_min_z, wall_max_z;
|
|
int snow_line;
|
|
struct trail_segment *trail_segments;
|
|
size_t trail_segment_count;
|
|
size_t trail_segment_cap;
|
|
int prepass_done;
|
|
int prepass_min_x, prepass_max_x, prepass_min_z, prepass_max_z;
|
|
worldgen_height_cache_entry height_cache[WORLDGEN_HEIGHT_CACHE_SIZE];
|
|
} worldgen_ctx;
|
|
|
|
void worldgen_init(worldgen_ctx *ctx, int world_seed, int sea_level, int snow_line);
|
|
void worldgen_generate_chunk(worldgen_ctx *ctx, int chunk_x, int chunk_z, chunk_data *out);
|
|
void worldgen_prepass(worldgen_ctx *ctx, int min_x, int max_x, int min_z, int max_z);
|
|
void worldgen_free_trails(worldgen_ctx *ctx);
|
|
int worldgen_debug_biome(worldgen_ctx *ctx, int x, int z);
|
|
double worldgen_debug_redwood_mask(worldgen_ctx *ctx, int x, int z);
|
|
|
|
#endif
|