diff --git a/README.md b/README.md index 9ba4c4f..83cbdd1 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,11 @@ src/ ├── config.rs # GameConfig, TileRegistry resources ├── constants.rs # Tile size, structural constants ├── entities/ -│ ├── item/magic_numbers.rs # Item sprite constants +│ ├── item/constants.rs # Item sprite constants │ ├── livestock/ │ ├── sentient/ │ └── shared_systems/ -│ ├── magic_numbers.rs # Pathfinding + dig constants +│ ├── constants.rs # Pathfinding + dig constants │ ├── occupancy.rs │ └── pathfinding.rs ├── game.rs # ZIndex resource, frame timing @@ -24,12 +24,12 @@ src/ └── world/ ├── chunks/ # ChunkMap, chunk loading/unloading, connectivity ├── generation/ - │ ├── forestry/magic_numbers.rs # Tree constants - │ ├── terrain/magic_numbers.rs # Terrain + cave constants + │ ├── forestry/constants.rs # Tree constants + │ ├── terrain/constants.rs # Terrain + cave constants │ ├── forestry.rs │ └── terrain.rs └── tiles/ - ├── magic_numbers.rs # A*, benchmark constants + ├── constants.rs # A*, benchmark constants ├── chunk_data.rs ├── rendering.rs ├── tilemap.rs diff --git a/src/entities/item/magic_numbers.rs b/src/entities/item/constants.rs similarity index 93% rename from src/entities/item/magic_numbers.rs rename to src/entities/item/constants.rs index 12c09f9..de1e158 100644 --- a/src/entities/item/magic_numbers.rs +++ b/src/entities/item/constants.rs @@ -1,3 +1,2 @@ -// Items /// Z offset applied to item sprites to prevent z-fighting with the floor tile below. pub const ITEM_Z_FIGHTING_OFFSET: f32 = 0.1; diff --git a/src/entities/item/drop_table.rs b/src/entities/item/drop_table.rs index c6d5465..7b7be35 100644 --- a/src/entities/item/drop_table.rs +++ b/src/entities/item/drop_table.rs @@ -52,7 +52,7 @@ impl DropTable { } } -// MAGIC Splitmix64-style hash of world SEED + tile position. +// Splitmix64-style hash of world SEED + tile position. // Constants are from the splitmix64 finaliser (Sebastiano Vigna, 2018): // 0x9e3779b97f4a7c15 — fractional bits of the golden ratio (Fibonacci hashing) // 0x6c62272e07bb0142 — high-bit-density prime for y-axis mixing diff --git a/src/entities/item/mod.rs b/src/entities/item/mod.rs index 191a4d7..fc909c7 100644 --- a/src/entities/item/mod.rs +++ b/src/entities/item/mod.rs @@ -1,8 +1,8 @@ +pub mod constants; pub mod container; pub mod core; pub mod decorations; pub mod drop_table; -pub mod magic_numbers; pub mod material; pub mod perishable; pub mod prefabs; diff --git a/src/entities/item/prefabs/misc/misc_prefabs.rs b/src/entities/item/prefabs/misc/misc_prefabs.rs index 56754ae..a014a15 100644 --- a/src/entities/item/prefabs/misc/misc_prefabs.rs +++ b/src/entities/item/prefabs/misc/misc_prefabs.rs @@ -1,6 +1,6 @@ use bevy::prelude::*; -use crate::entities::item::magic_numbers::ITEM_Z_FIGHTING_OFFSET; +use crate::entities::item::constants::ITEM_Z_FIGHTING_OFFSET; use crate::entities::item::{ Item, ItemBundle, ItemDecorations, ItemRotationState, ItemType, Material, Quality, }; diff --git a/src/entities/item/types.rs b/src/entities/item/types.rs index 4f293cf..27f7459 100644 --- a/src/entities/item/types.rs +++ b/src/entities/item/types.rs @@ -46,16 +46,16 @@ impl ItemType { ToolType::Shovel => 1.5, ToolType::Axe => 1.75, ToolType::Hammer => 1.0, - ToolType::Anvil => 50.0, // MAGIC ~50kg — intentionally immovable in practice - ToolType::Furnace => 100.0, // MAGIC ~100kg — structure, not a carried item + ToolType::Anvil => 50.0, // ~50kg — intentionally immovable in practice + ToolType::Furnace => 100.0, // ~100kg — structure, not a carried item }, ItemType::Food(_) => 0.2, ItemType::Drink(_) => 0.3, ItemType::Medicine => 0.1, ItemType::RawMaterial => 0.5, ItemType::Gem => 0.1, - ItemType::Coin => 0.01, // MAGIC ~1g coin, negligible individual weight - ItemType::Container => 1.0, // MAGIC empty container only, not contents + ItemType::Coin => 0.01, // ~1g coin, negligible individual weight + ItemType::Container => 1.0, // empty container only, not contents ItemType::Book => 0.5, ItemType::Toy => 0.2, ItemType::Decoration => 0.3, diff --git a/src/entities/livestock/rabbit.rs b/src/entities/livestock/rabbit.rs index 3f6a6a4..6854209 100644 --- a/src/entities/livestock/rabbit.rs +++ b/src/entities/livestock/rabbit.rs @@ -1,8 +1,8 @@ use crate::config::GameConfig; use crate::constants::*; use crate::entities::shared_components::Ambulatory; +use crate::entities::shared_systems::constants::DEFAULT_DIG_INTERVAL_SECS; use crate::entities::shared_systems::digging::Digger; -use crate::entities::shared_systems::magic_numbers::DEFAULT_DIG_INTERVAL_SECS; use crate::game::SpawnDelay; use crate::world::VisibleGameEntity; use bevy::prelude::*; diff --git a/src/entities/shared_systems/magic_numbers.rs b/src/entities/shared_systems/constants.rs similarity index 97% rename from src/entities/shared_systems/magic_numbers.rs rename to src/entities/shared_systems/constants.rs index cf7a094..f3592f9 100644 --- a/src/entities/shared_systems/magic_numbers.rs +++ b/src/entities/shared_systems/constants.rs @@ -1,4 +1,3 @@ -// Pathfinding + digging /// Number of future path steps validated each tick before an entity moves. pub const PATHFINDER_VALIDATE_STEPS: usize = 3; /// Ticks between path validation checks per entity. diff --git a/src/entities/shared_systems/mod.rs b/src/entities/shared_systems/mod.rs index eb5d2a6..cbb04c8 100644 --- a/src/entities/shared_systems/mod.rs +++ b/src/entities/shared_systems/mod.rs @@ -1,4 +1,4 @@ +pub mod constants; pub mod digging; -pub mod magic_numbers; pub mod occupancy; pub mod pathfinding; diff --git a/src/entities/shared_systems/pathfinding.rs b/src/entities/shared_systems/pathfinding.rs index 8ec0521..4ed2029 100644 --- a/src/entities/shared_systems/pathfinding.rs +++ b/src/entities/shared_systems/pathfinding.rs @@ -63,7 +63,7 @@ use crate::constants::{ ITILE_SIZE, PATHFINDER_HIERARCHICAL_THRESHOLD_CHUNKS, PATHFINDER_MAX_NODES, PATHFINDER_PROVISIONAL_NODE_LIMIT, PIXEL_RATIO, TILE_SIZE, }; -use crate::entities::shared_systems::magic_numbers::{ +use crate::entities::shared_systems::constants::{ CONVOY_DOT_THRESHOLD, ES_DIRECTION_THRESHOLD, HEAD_ON_DOT_THRESHOLD, OCCUPANCY_CROWD_THRESHOLD, PATHFINDER_DIRTY_LOOKAHEAD, PATHFINDER_VALIDATE_STEPS, PATHFINDER_VALIDATION_COOLDOWN, WALK_SPEED_DIVISOR, @@ -1073,7 +1073,7 @@ fn directional_chunk_waypoint( // goal varies per entity (each has a different random wander target). // Together they produce unique spread values for entities even when // heading through the same chunk, without needing to pass entity ID. - // MAGIC Small primes spread entity starting positions across waypoint edge tiles. + // Small primes spread entity starting positions across waypoint edge tiles. // Different values per axis prevent aliasing when positions are on a regular grid. let entropy = (cur_tile.x.unsigned_abs() as usize) .wrapping_mul(1619) diff --git a/src/world/generation/forestry.rs b/src/world/generation/forestry.rs index e9aa6c2..90fcc19 100644 --- a/src/world/generation/forestry.rs +++ b/src/world/generation/forestry.rs @@ -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, }, diff --git a/src/world/generation/forestry/magic_numbers.rs b/src/world/generation/forestry/constants.rs similarity index 98% rename from src/world/generation/forestry/magic_numbers.rs rename to src/world/generation/forestry/constants.rs index 940d726..efd057d 100644 --- a/src/world/generation/forestry/magic_numbers.rs +++ b/src/world/generation/forestry/constants.rs @@ -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. diff --git a/src/world/generation/terrain.rs b/src/world/generation/terrain.rs index ef51b9c..d8fa794 100644 --- a/src/world/generation/terrain.rs +++ b/src/world/generation/terrain.rs @@ -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, diff --git a/src/world/generation/terrain/magic_numbers.rs b/src/world/generation/terrain/constants.rs similarity index 93% rename from src/world/generation/terrain/magic_numbers.rs rename to src/world/generation/terrain/constants.rs index 26fd22e..e3dc0a1 100644 --- a/src/world/generation/terrain/magic_numbers.rs +++ b/src/world/generation/terrain/constants.rs @@ -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. diff --git a/src/world/tiles/chunk_data.rs b/src/world/tiles/chunk_data.rs index 05e48bf..e7118fd 100644 --- a/src/world/tiles/chunk_data.rs +++ b/src/world/tiles/chunk_data.rs @@ -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); } diff --git a/src/world/tiles/magic_numbers.rs b/src/world/tiles/constants.rs similarity index 97% rename from src/world/tiles/magic_numbers.rs rename to src/world/tiles/constants.rs index a5667ad..c822719 100644 --- a/src/world/tiles/magic_numbers.rs +++ b/src/world/tiles/constants.rs @@ -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; diff --git a/src/world/tiles/mod.rs b/src/world/tiles/mod.rs index 8c44aa2..dc41b75 100644 --- a/src/world/tiles/mod.rs +++ b/src/world/tiles/mod.rs @@ -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; diff --git a/src/world/tiles/tilemap.rs b/src/world/tiles/tilemap.rs index 5cd24ef..d564038 100644 --- a/src/world/tiles/tilemap.rs +++ b/src/world/tiles/tilemap.rs @@ -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)] diff --git a/src/world/tiles/tilemap_chunk.rs b/src/world/tiles/tilemap_chunk.rs index d62c130..4c0ec00 100644 --- a/src/world/tiles/tilemap_chunk.rs +++ b/src/world/tiles/tilemap_chunk.rs @@ -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; }