just making sure the repo is up to date
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
|
#+feature dynamic-literals
|
||||||
package game
|
package game
|
||||||
|
|
||||||
import "core:math/noise"
|
|
||||||
import "core:math"
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
|
import "core:math"
|
||||||
|
import "core:math/noise"
|
||||||
|
|
||||||
BIOME_SCALE : f64 : 1
|
BIOME_SCALE: f64 : 1
|
||||||
|
|
||||||
biome_list := map[u32]Biome {
|
biome_list := map[u32]Biome {
|
||||||
0 = grasslands_biome,
|
0 = grasslands_biome,
|
||||||
@@ -21,11 +22,11 @@ BiomeType :: enum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Biome :: struct {
|
Biome :: struct {
|
||||||
id:u32,
|
id: u32,
|
||||||
name: string,
|
name: string,
|
||||||
type: BiomeType,
|
type: BiomeType,
|
||||||
fauna_color: [4]u8,
|
fauna_color: [4]u8,
|
||||||
valid_structures: [dynamic]u32
|
valid_structures: [dynamic]u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define biome constants
|
// Define biome constants
|
||||||
@@ -34,7 +35,7 @@ grasslands_biome := Biome {
|
|||||||
name = "Grasslands",
|
name = "Grasslands",
|
||||||
type = .GRASSLAND,
|
type = .GRASSLAND,
|
||||||
fauna_color = {50, 120, 25, 255},
|
fauna_color = {50, 120, 25, 255},
|
||||||
valid_structures = {}
|
valid_structures = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
forest_biome := Biome {
|
forest_biome := Biome {
|
||||||
@@ -42,7 +43,7 @@ forest_biome := Biome {
|
|||||||
name = "Forest",
|
name = "Forest",
|
||||||
type = .FOREST,
|
type = .FOREST,
|
||||||
fauna_color = {30, 80, 20, 255},
|
fauna_color = {30, 80, 20, 255},
|
||||||
valid_structures = {}
|
valid_structures = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
desert_biome := Biome {
|
desert_biome := Biome {
|
||||||
@@ -50,7 +51,7 @@ desert_biome := Biome {
|
|||||||
name = "Desert",
|
name = "Desert",
|
||||||
type = .DESERT,
|
type = .DESERT,
|
||||||
fauna_color = {200, 180, 100, 255},
|
fauna_color = {200, 180, 100, 255},
|
||||||
valid_structures = {}
|
valid_structures = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
lake_biome := Biome {
|
lake_biome := Biome {
|
||||||
@@ -58,10 +59,10 @@ lake_biome := Biome {
|
|||||||
name = "Lake",
|
name = "Lake",
|
||||||
type = .LAKE,
|
type = .LAKE,
|
||||||
fauna_color = {0, 50, 150, 255},
|
fauna_color = {0, 50, 150, 255},
|
||||||
valid_structures = {}
|
valid_structures = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
get_biome_from_id :: proc(id:u32) -> Biome {
|
get_biome_from_id :: proc(id: u32) -> Biome {
|
||||||
return biome_list[id]
|
return biome_list[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,23 +79,37 @@ get_biome_type :: proc(world_pos: Vec2i, seed: i64) -> Biome {
|
|||||||
temperature_seed := seed + 30000
|
temperature_seed := seed + 30000
|
||||||
|
|
||||||
// Generate base continent shapes
|
// Generate base continent shapes
|
||||||
continent := noise.noise_2d(continent_seed, {f64(world_pos.x) * continent_scale, f64(world_pos.y) * continent_scale})
|
continent := noise.noise_2d(
|
||||||
|
continent_seed,
|
||||||
|
{f64(world_pos.x) * continent_scale, f64(world_pos.y) * continent_scale},
|
||||||
|
)
|
||||||
// Amplify to get more defined continents
|
// Amplify to get more defined continents
|
||||||
continent = math.pow(continent * 0.5 + 0.5, 1.5) * 2.0 - 1.0
|
continent = math.pow(continent * 0.5 + 0.5, 1.5) * 2.0 - 1.0
|
||||||
|
|
||||||
// Generate regional variations
|
// Generate regional variations
|
||||||
region := noise.noise_2d(region_seed, {f64(world_pos.x) * region_scale, f64(world_pos.y) * region_scale})
|
region := noise.noise_2d(
|
||||||
|
region_seed,
|
||||||
|
{f64(world_pos.x) * region_scale, f64(world_pos.y) * region_scale},
|
||||||
|
)
|
||||||
|
|
||||||
// Generate moisture and temperature maps for biome determination
|
// Generate moisture and temperature maps for biome determination
|
||||||
moisture := noise.noise_2d(moisture_seed, {f64(world_pos.x) * region_scale, f64(world_pos.y) * region_scale})
|
moisture := noise.noise_2d(
|
||||||
temperature := noise.noise_2d(temperature_seed, {f64(world_pos.x) * region_scale, f64(world_pos.y) * region_scale})
|
moisture_seed,
|
||||||
|
{f64(world_pos.x) * region_scale, f64(world_pos.y) * region_scale},
|
||||||
|
)
|
||||||
|
temperature := noise.noise_2d(
|
||||||
|
temperature_seed,
|
||||||
|
{f64(world_pos.x) * region_scale, f64(world_pos.y) * region_scale},
|
||||||
|
)
|
||||||
|
|
||||||
// Adjust temperature to create larger hot regions
|
// Adjust temperature to create larger hot regions
|
||||||
// This skews the distribution to have more areas with higher temperature
|
// This skews the distribution to have more areas with higher temperature
|
||||||
// temperature = math.pow(temperature * 0.5 + 0.5, 0.8) * 2.0 - 1.0
|
// temperature = math.pow(temperature * 0.5 + 0.5, 0.8) * 2.0 - 1.0
|
||||||
|
|
||||||
// Local variations (small details)
|
// Local variations (small details)
|
||||||
local_var := noise.noise_2d(seed, {f64(world_pos.x) * local_scale, f64(world_pos.y) * local_scale}) * 0.1
|
local_var :=
|
||||||
|
noise.noise_2d(seed, {f64(world_pos.x) * local_scale, f64(world_pos.y) * local_scale}) *
|
||||||
|
0.1
|
||||||
|
|
||||||
// Combine all factors with proper weighting
|
// Combine all factors with proper weighting
|
||||||
elevation := continent * 0.7 + region * 0.3 + local_var
|
elevation := continent * 0.7 + region * 0.3 + local_var
|
||||||
@@ -123,16 +138,18 @@ get_biome_type :: proc(world_pos: Vec2i, seed: i64) -> Biome {
|
|||||||
|
|
||||||
// Improved chunk generation that considers neighboring chunks
|
// Improved chunk generation that considers neighboring chunks
|
||||||
generate_chunk :: proc(pos: Vec2i, seed: i64) -> Chunk {
|
generate_chunk :: proc(pos: Vec2i, seed: i64) -> Chunk {
|
||||||
chunk := Chunk{position = pos}
|
chunk := Chunk {
|
||||||
|
position = pos,
|
||||||
|
}
|
||||||
|
|
||||||
// Store the biome for this chunk for consistency
|
// Store the biome for this chunk for consistency
|
||||||
chunk_center := Vec2i{pos.x * CHUNK_SIZE + CHUNK_SIZE/2, pos.y * CHUNK_SIZE + CHUNK_SIZE/2}
|
chunk_center := Vec2i{pos.x * CHUNK_SIZE + CHUNK_SIZE / 2, pos.y * CHUNK_SIZE + CHUNK_SIZE / 2}
|
||||||
biome := get_biome_type(chunk_center, seed)
|
biome := get_biome_type(chunk_center, seed)
|
||||||
chunk.biome_id = biome.id
|
chunk.biome_id = biome.id
|
||||||
|
|
||||||
// Generate each tile, allowing for biome blending at edges
|
// Generate each tile, allowing for biome blending at edges
|
||||||
for x in 0..<CHUNK_SIZE {
|
for x in 0 ..< CHUNK_SIZE {
|
||||||
for y in 0..<CHUNK_SIZE {
|
for y in 0 ..< CHUNK_SIZE {
|
||||||
world_x := pos.x * CHUNK_SIZE + x
|
world_x := pos.x * CHUNK_SIZE + x
|
||||||
world_y := pos.y * CHUNK_SIZE + y
|
world_y := pos.y * CHUNK_SIZE + y
|
||||||
world_pos := Vec2i{world_x, world_y}
|
world_pos := Vec2i{world_x, world_y}
|
||||||
@@ -175,8 +192,14 @@ generate_tile :: proc(pos: Vec2i, seed: i64, biome: Biome) -> Tile {
|
|||||||
small_scale := 0.20
|
small_scale := 0.20
|
||||||
|
|
||||||
large_noise := noise.noise_2d(seed, {f64(pos.x) * large_scale, f64(pos.y) * large_scale})
|
large_noise := noise.noise_2d(seed, {f64(pos.x) * large_scale, f64(pos.y) * large_scale})
|
||||||
medium_noise := noise.noise_2d(seed + 5000, {f64(pos.x) * medium_scale, f64(pos.y) * medium_scale})
|
medium_noise := noise.noise_2d(
|
||||||
small_noise := noise.noise_2d(seed + 10000, {f64(pos.x) * small_scale, f64(pos.y) * small_scale})
|
seed + 5000,
|
||||||
|
{f64(pos.x) * medium_scale, f64(pos.y) * medium_scale},
|
||||||
|
)
|
||||||
|
small_noise := noise.noise_2d(
|
||||||
|
seed + 10000,
|
||||||
|
{f64(pos.x) * small_scale, f64(pos.y) * small_scale},
|
||||||
|
)
|
||||||
|
|
||||||
// Combine noise at different scales
|
// Combine noise at different scales
|
||||||
combined_noise := large_noise * 0.6 + medium_noise * 0.3 + small_noise * 0.1
|
combined_noise := large_noise * 0.6 + medium_noise * 0.3 + small_noise * 0.1
|
||||||
@@ -202,7 +225,6 @@ generate_tile :: proc(pos: Vec2i, seed: i64, biome: Biome) -> Tile {
|
|||||||
return nothing_tile
|
return nothing_tile
|
||||||
}
|
}
|
||||||
case .DESERT:
|
case .DESERT:
|
||||||
|
|
||||||
cactus_noise := medium_noise * 0.5 + 0.5 // Normalize to 0-1
|
cactus_noise := medium_noise * 0.5 + 0.5 // Normalize to 0-1
|
||||||
|
|
||||||
if cactus_noise > 0.8 && hash_value > 0.65 {
|
if cactus_noise > 0.8 && hash_value > 0.65 {
|
||||||
@@ -223,5 +245,3 @@ generate_tile :: proc(pos: Vec2i, seed: i64, biome: Biome) -> Tile {
|
|||||||
return nothing_tile
|
return nothing_tile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user