use constants better
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
pub mod magic_numbers;
|
||||
pub mod constants;
|
||||
use bevy::prelude::*;
|
||||
use bevy_platform::collections::HashSet;
|
||||
use bevy_platform::sync::Mutex;
|
||||
@@ -11,7 +11,7 @@ use std::hash::{Hash, Hasher};
|
||||
|
||||
use crate::{
|
||||
constants::{SEED, TILE_SIZE},
|
||||
world::generation::forestry::magic_numbers::{
|
||||
world::generation::forestry::constants::{
|
||||
TREE_LEAF_BASE_RADIUS, TREE_LEAF_RADIUS_OFFSET, TREE_LEAF_RADIUS_VARIATION,
|
||||
TREE_MIN_DISTANCE_TILES, TREE_SPAWN_CHANCE, TREE_TRUNK_EXTRA_HEIGHT, TREE_TRUNK_MIN_HEIGHT,
|
||||
},
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// Forestry
|
||||
/// Minimum distance between tree trunks in tile units. Prevents overlapping canopies.
|
||||
pub const TREE_MIN_DISTANCE_TILES: f32 = 7.0;
|
||||
/// 1-in-N chance per eligible grass tile of spawning a tree.
|
||||
@@ -1,4 +1,4 @@
|
||||
pub mod magic_numbers;
|
||||
pub mod constants;
|
||||
use bevy::prelude::*;
|
||||
use bevy::tasks::AsyncComputeTaskPool;
|
||||
use bevy_platform::time::Instant;
|
||||
@@ -10,15 +10,15 @@ use crate::entities::item::drop_table::DropTableRegistry;
|
||||
use crate::{
|
||||
config::TileRegistry,
|
||||
constants::{SEED, TILE_SIZE},
|
||||
world::generation::terrain::magic_numbers::{
|
||||
world::generation::terrain::constants::{
|
||||
CAVE_DEPTH_THRESHOLD, CAVE_NOISE_FREQUENCY, CAVE_ROCK_THRESHOLD, CAVE_VOID_THRESHOLD,
|
||||
TERRAIN_AMPLITUDE_PERSISTENCE, TERRAIN_BASE_FREQUENCY,
|
||||
TERRAIN_FREQUENCY_LACUNARITY, TERRAIN_HEIGHT_SCALE,
|
||||
TERRAIN_AMPLITUDE_PERSISTENCE, TERRAIN_BASE_FREQUENCY, TERRAIN_FREQUENCY_LACUNARITY,
|
||||
TERRAIN_HEIGHT_SCALE,
|
||||
},
|
||||
world::{
|
||||
tiles::{ChunkData, FloorTileData, TileMap},
|
||||
ChunkForrestryEvent, ChunkMap, ChunkTerrainEvent, TileOcclusionEvent,
|
||||
CHUNK_SIZE, Z_ABOVE, Z_BELOW,
|
||||
ChunkForrestryEvent, ChunkMap, ChunkTerrainEvent, TileOcclusionEvent, CHUNK_SIZE, Z_ABOVE,
|
||||
Z_BELOW,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -68,7 +68,7 @@ pub fn generate_surface_terrain(x: i32, y: i32) -> f32 {
|
||||
amplitude *= TERRAIN_AMPLITUDE_PERSISTENCE;
|
||||
frequency *= TERRAIN_FREQUENCY_LACUNARITY;
|
||||
}
|
||||
(noise_value * TERRAIN_HEIGHT_SCALE as f64) as f32
|
||||
(noise_value * TERRAIN_HEIGHT_SCALE) as f32
|
||||
}
|
||||
|
||||
/// Async terrain generation - runs on AsyncComputeTaskPool.
|
||||
@@ -156,21 +156,21 @@ fn generate_terrain_blob(chunk_pos: IVec2) -> TerrainBlob {
|
||||
tile.can_stand_in,
|
||||
tile.can_stand_on,
|
||||
tile.astar_weight,
|
||||
);
|
||||
} else {
|
||||
let tile = registry.floor("dirt");
|
||||
tile_updates.push((
|
||||
pos_ivec,
|
||||
FloorTileData::new(
|
||||
tile.id,
|
||||
tile.can_stand_in,
|
||||
tile.can_stand_on,
|
||||
tile.transparent,
|
||||
tile.astar_weight,
|
||||
[0; 8],
|
||||
DropTableRegistry::global_get("dirt"),
|
||||
),
|
||||
));
|
||||
);
|
||||
} else {
|
||||
let tile = registry.floor("dirt");
|
||||
tile_updates.push((
|
||||
pos_ivec,
|
||||
FloorTileData::new(
|
||||
tile.id,
|
||||
tile.can_stand_in,
|
||||
tile.can_stand_on,
|
||||
tile.transparent,
|
||||
tile.astar_weight,
|
||||
[0; 8],
|
||||
DropTableRegistry::global_get("dirt"),
|
||||
),
|
||||
));
|
||||
chunk_data.set_floor_tile(
|
||||
local_x,
|
||||
local_y,
|
||||
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
// Terrain generation
|
||||
/// Noise frequency for the coarsest octave of surface terrain height.
|
||||
pub const TERRAIN_BASE_FREQUENCY: f64 = 0.008;
|
||||
/// Amplitude multiplier per noise octave (persistence). 0.6 = moderate detail.
|
||||
@@ -6,7 +5,7 @@ pub const TERRAIN_AMPLITUDE_PERSISTENCE: f64 = 0.6;
|
||||
/// Frequency multiplier per noise octave (lacunarity).
|
||||
pub const TERRAIN_FREQUENCY_LACUNARITY: f64 = 1.8;
|
||||
/// Scale applied to summed octave noise to set terrain height range in tile units.
|
||||
pub const TERRAIN_HEIGHT_SCALE: f32 = 2.5;
|
||||
pub const TERRAIN_HEIGHT_SCALE: f64 = 2.5;
|
||||
/// Noise frequency for cave generation (applied to all three axes).
|
||||
pub const CAVE_NOISE_FREQUENCY: f64 = 0.05;
|
||||
/// Cave noise value below which a tile becomes open air.
|
||||
@@ -17,7 +17,7 @@ use bevy::prelude::*;
|
||||
|
||||
use crate::constants::ITILE_SIZE;
|
||||
use crate::world::chunks::{CHUNK_SIZE, Z_ABOVE, Z_BELOW};
|
||||
use crate::world::tiles::magic_numbers::ASTAR_DEFAULT_WEIGHT;
|
||||
use crate::world::tiles::constants::ASTAR_DEFAULT_WEIGHT;
|
||||
|
||||
/// Number of z-levels in a chunk (Z_BELOW + Z_ABOVE + 1 for inclusive range).
|
||||
/// Terrain generation uses -Z_BELOW..=Z_ABOVE (inclusive at both ends).
|
||||
@@ -274,7 +274,7 @@ impl ChunkData {
|
||||
self.stand_in_fixture.fill(0);
|
||||
self.stand_on_fixture.fill(0);
|
||||
self.tile_ids.fill(0);
|
||||
// MAGIC ASTAR_DEFAULT_WEIGHT matches normal grass/traversable tile weight — cleared
|
||||
// ASTAR_DEFAULT_WEIGHT matches normal grass/traversable tile weight — cleared
|
||||
// chunks present as passable rather than impassable walls to pathfinding.
|
||||
self.astar_weights.fill(ASTAR_DEFAULT_WEIGHT);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Tiles
|
||||
/// Default A* weight returned for out-of-bounds or unloaded positions.
|
||||
/// Matches normal traversable tile weight so pathfinding degrades gracefully.
|
||||
pub const ASTAR_DEFAULT_WEIGHT: u8 = 100;
|
||||
@@ -1,6 +1,6 @@
|
||||
pub mod benchmark;
|
||||
pub mod chunk_data;
|
||||
pub mod magic_numbers;
|
||||
pub mod constants;
|
||||
pub mod rendering;
|
||||
pub mod tile_changed;
|
||||
pub mod tilemap;
|
||||
|
||||
@@ -35,7 +35,7 @@ use super::chunk_data::ChunkData;
|
||||
use crate::constants::ITILE_SIZE;
|
||||
use crate::entities::item::drop_table::DropTable;
|
||||
use crate::world::chunks::{world_to_chunk, CHUNK_SIZE, Z_ABOVE, Z_BELOW};
|
||||
use crate::world::tiles::magic_numbers::ASTAR_DEFAULT_WEIGHT;
|
||||
use crate::world::tiles::constants::ASTAR_DEFAULT_WEIGHT;
|
||||
|
||||
/// Packed floor tile data for efficient storage. ~35 bytes vs 76 bytes tuple.
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::constants::{ITILE_SIZE, TILE_PIXELS, TILE_SIZE};
|
||||
use crate::game::ZIndex;
|
||||
use crate::world::chunks::{CHUNK_SIZE, CHUNK_SIZE_TILE, Z_BELOW, Z_TOTAL};
|
||||
use crate::world::textures::TilemapTileset;
|
||||
use crate::world::tiles::magic_numbers::{BYTES_PER_MB, Z_CHANGE_HISTORY_LEN};
|
||||
use crate::world::tiles::constants::{BYTES_PER_MB, Z_CHANGE_HISTORY_LEN};
|
||||
use crate::world::tiles::{FloorTileData, TileMap};
|
||||
|
||||
pub const LAYER_FLOOR: u8 = 0;
|
||||
@@ -140,7 +140,7 @@ fn tile_for_depth(real_index: u16, z_diff: i32) -> TileData {
|
||||
}
|
||||
|
||||
fn is_tile_visible_at_z(tile_data: &FloorTileData, z_index: usize) -> bool {
|
||||
// MAGIC u8::MAX + 1; z_index stored as u8 in layer key so this is out-of-range
|
||||
// u8::MAX + 1; z_index stored as u8 in layer key so this is out-of-range
|
||||
if z_index >= 256 {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user