I may have used ai for some of the proc gen..
This commit is contained in:
@@ -13,15 +13,16 @@ WORLD_DATA_PATH :: "data/worlds"
|
||||
World :: struct {
|
||||
data_dir: string,
|
||||
chunks: map[Vec2i]Chunk,
|
||||
seed: u32
|
||||
seed: i64
|
||||
}
|
||||
|
||||
Chunk :: struct #packed {
|
||||
position: Vec2i,
|
||||
tiles: [CHUNK_SIZE][CHUNK_SIZE]Tile,
|
||||
biome_id:u32,
|
||||
}
|
||||
|
||||
create_world :: proc(name:string, seed:u32) -> World {
|
||||
create_world :: proc(name:string, seed:i64) -> World {
|
||||
data_dir := fmt.tprintf("%v/%v", WORLD_DATA_PATH, name)
|
||||
if !os.is_dir(data_dir) {
|
||||
fmt.printfln("Data dir: %v does not exist", data_dir)
|
||||
@@ -40,7 +41,7 @@ create_world :: proc(name:string, seed:u32) -> World {
|
||||
}
|
||||
}
|
||||
|
||||
load_world :: proc(name:string, seed:u32) -> World {
|
||||
load_world :: proc(name:string, seed:i64) -> World {
|
||||
dir := fmt.tprintf("%v/%v", WORLD_DATA_PATH, name)
|
||||
if !os.is_dir(dir) {
|
||||
panic("Couldnt load world")
|
||||
@@ -89,6 +90,9 @@ save_chunk :: proc(c:^Chunk, w:^World) {
|
||||
}
|
||||
}
|
||||
|
||||
// Biome ID
|
||||
for byte in transmute([size_of(u32)]u8)c.biome_id {append(&data, byte)}
|
||||
|
||||
err := os.write_entire_file_or_err(filename, data[:])
|
||||
|
||||
}
|
||||
@@ -138,6 +142,10 @@ load_chunk :: proc(pos:Vec2i, w:^World) -> Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
// Load Biome ID
|
||||
mem.copy(transmute([^]u8)&chunk.biome_id, &data[offset], size_of(u32))
|
||||
offset += size_of(u32)
|
||||
|
||||
return chunk
|
||||
|
||||
}
|
||||
@@ -150,42 +158,6 @@ unload_chunk :: proc(pos:Vec2i, w:^World) {
|
||||
}
|
||||
}
|
||||
|
||||
generate_chunk :: proc(pos:Vec2i, seed:u32) -> Chunk {
|
||||
chunk := Chunk {position = pos}
|
||||
|
||||
for x in 0..<CHUNK_SIZE {
|
||||
for y in 0..<CHUNK_SIZE {
|
||||
world_x := pos.x * CHUNK_SIZE + x
|
||||
world_y := pos.y * CHUNK_SIZE + y
|
||||
|
||||
chunk.tiles[x][y] = generate_tile(world_x, world_y, seed)
|
||||
}
|
||||
}
|
||||
|
||||
return chunk
|
||||
}
|
||||
|
||||
generate_tile :: proc(x, y: int, seed: u32) -> Tile {
|
||||
base_noise := hash_noise(x, y, seed)
|
||||
cluster_noise := hash_noise(x / 3, y / 3, seed + 12345) // Larger scale noise for clusters
|
||||
|
||||
if base_noise < 0.70 {
|
||||
return nothing_tile
|
||||
} else if base_noise < 0.85 {
|
||||
return grass_tile
|
||||
} else if base_noise < 0.95 {
|
||||
if cluster_noise > 0.5 { // Favor trees in cluster regions
|
||||
return tree_tile
|
||||
}
|
||||
return grass_tile
|
||||
} else {
|
||||
if cluster_noise > 0.4 { // Only allow ponds in certain areas
|
||||
return water_tile
|
||||
}
|
||||
return nothing_tile
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
get_chunk :: proc(w:^World, chunk_pos:Vec2i) -> ^Chunk {
|
||||
chunk, exists := w.chunks[chunk_pos]
|
||||
|
||||
Reference in New Issue
Block a user