Add worldgen sources
This commit is contained in:
14
include/noise.h
Normal file
14
include/noise.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef WORLDGEN_NOISE_H
|
||||
#define WORLDGEN_NOISE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
int perm[512];
|
||||
} simplex_noise;
|
||||
|
||||
void simplex_init(simplex_noise *noise, uint32_t seed);
|
||||
double simplex_noise2(simplex_noise *noise, double x, double y);
|
||||
double simplex_noise3(simplex_noise *noise, double x, double y, double z);
|
||||
|
||||
#endif
|
||||
41
include/worldgen.h
Normal file
41
include/worldgen.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef WORLDGEN_H
|
||||
#define WORLDGEN_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "noise.h"
|
||||
|
||||
#define CHUNK_SIZE 16
|
||||
#define CHUNK_HEIGHT 256
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
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 {
|
||||
simplex_noise noise;
|
||||
int sea_level;
|
||||
int world_seed;
|
||||
} worldgen_ctx;
|
||||
|
||||
void worldgen_init(worldgen_ctx *ctx, int world_seed, int sea_level);
|
||||
void worldgen_generate_chunk(worldgen_ctx *ctx, int chunk_x, int chunk_z, chunk_data *out);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user