use constants better

This commit is contained in:
2026-03-21 17:51:05 +00:00
parent f96c71b61b
commit cabe944f1b
19 changed files with 47 additions and 52 deletions
@@ -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;
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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;
@@ -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,
};
+4 -4
View File
@@ -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,
+1 -1
View File
@@ -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::*;
@@ -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.
+1 -1
View File
@@ -1,4 +1,4 @@
pub mod constants;
pub mod digging;
pub mod magic_numbers;
pub mod occupancy;
pub mod pathfinding;
+2 -2
View File
@@ -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)