diff --git a/assets/common/sprite_behavior_manifest.ron b/assets/common/sprite_behavior_manifest.ron index b177df6344..a461253f92 100644 --- a/assets/common/sprite_behavior_manifest.ron +++ b/assets/common/sprite_behavior_manifest.ron @@ -1,65 +1,4 @@ SpriteBehaviorManifest( - solid_height: { - // Beware: the height *must* be <= `MAX_HEIGHT` or the collision system will not - // properly detect it! - Tomato: 1.65, - LargeCactus: 2.5, - Scarecrow: 3.0, - Turnip: 0.36, - Pumpkin: 0.81, - Cabbage: 0.45, - Chest: 1.09, - StreetLamp: 2.65, - Carrot: 0.18, - Radish: 0.18, - FireBowlGround: 0.55, - // TODO: Uncomment this when we have a way to open doors - // Door: 3.0, - Bed: 1.54, - Bench: 0.5, - ChairSingle: 0.5, - ChairDouble: 0.5, - CoatRack: 2.36, - Crate: 0.90, - DrawerSmall: 1.0, - DrawerMedium: 2.0, - DrawerLarge: 2.0, - DungeonWallDecor: 1.0, - Planter: 1.09, - TableSide: 1.27, - TableDining: 1.45, - TableDouble: 1.45, - WardrobeSingle: 3.0, - WardrobeDouble: 3.0, - Pot: 0.90, - Mud: 0.36, - ChestBuried: 0.91, - StonyCoral: 1.4, - // TODO: Find suitable heights. - BarrelCactus: 1.0, - RoundCactus: 1.0, - ShortCactus: 1.0, - MedFlatCactus: 1.0, - ShortFlatCactus: 1.0, - Apple: 1.0, - Velorite: 1.0, - VeloriteFrag: 1.0, - Coconut: 1.0, - StreetLampTall: 1.0, - Window1: 1.0, - Window2: 1.0, - Window3: 1.0, - Window4: 1.0, - DropGate: 1.0, - // TODO: Figure out if this should be solid or not. - Shelf: 1.0, - Lantern: 0.9, - CraftingBench: 1.18, - Forge: 2.7, - Cauldron: 1.27, - Anvil: 1.1, - CookingPot: 1.36, - }, collectible_id: { Apple: Item("common.items.food.apple"), Mushroom: Item("common.items.food.mushroom"), diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index 55aab54009..c016811fe0 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -93,6 +93,11 @@ impl<'a> TryFrom<&'a str> for BlockKind { #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct Block { kind: BlockKind, + /// If `kind.is_filled()` is true, attr is to be interpreted as 8 bit rgb + /// data. Otherwise: + /// - `attr[0]` contains the `SpriteKind` of the sprite in this block + /// - `attr[1]` contains the bit pattern `xxxxxyyy`, where x is a plant + /// growth stage from 0-31, and y is an orientation from 0-7. attr: [u8; 3], } diff --git a/common/src/terrain/sprite.rs b/common/src/terrain/sprite.rs index 306a34612f..713ea3c6b1 100644 --- a/common/src/terrain/sprite.rs +++ b/common/src/terrain/sprite.rs @@ -188,11 +188,68 @@ pub struct GrowthSpec { impl SpriteKind { pub fn solid_height(&self) -> Option { - SPRITE_BEHAVIOR_MANIFEST - .read() - .solid_height - .get(self) - .copied() + // Beware: the height *must* be <= `MAX_HEIGHT` or the collision system will not + // properly detect it! + Some(match self { + SpriteKind::Tomato => 1.65, + SpriteKind::LargeCactus => 2.5, + SpriteKind::Scarecrow => 3.0, + SpriteKind::Turnip => 0.36, + SpriteKind::Pumpkin => 0.81, + SpriteKind::Cabbage => 0.45, + SpriteKind::Chest => 1.09, + SpriteKind::StreetLamp => 2.65, + SpriteKind::Carrot => 0.18, + SpriteKind::Radish => 0.18, + SpriteKind::FireBowlGround => 0.55, + // TODO: Uncomment this when we have a way to open doors + // SpriteKind::Door => 3.0, + SpriteKind::Bed => 1.54, + SpriteKind::Bench => 0.5, + SpriteKind::ChairSingle => 0.5, + SpriteKind::ChairDouble => 0.5, + SpriteKind::CoatRack => 2.36, + SpriteKind::Crate => 0.90, + SpriteKind::DrawerSmall => 1.0, + SpriteKind::DrawerMedium => 2.0, + SpriteKind::DrawerLarge => 2.0, + SpriteKind::DungeonWallDecor => 1.0, + SpriteKind::Planter => 1.09, + SpriteKind::TableSide => 1.27, + SpriteKind::TableDining => 1.45, + SpriteKind::TableDouble => 1.45, + SpriteKind::WardrobeSingle => 3.0, + SpriteKind::WardrobeDouble => 3.0, + SpriteKind::Pot => 0.90, + SpriteKind::Mud => 0.36, + SpriteKind::ChestBuried => 0.91, + SpriteKind::StonyCoral => 1.4, + // TODO => Find suitable heights. + SpriteKind::BarrelCactus => 1.0, + SpriteKind::RoundCactus => 1.0, + SpriteKind::ShortCactus => 1.0, + SpriteKind::MedFlatCactus => 1.0, + SpriteKind::ShortFlatCactus => 1.0, + SpriteKind::Apple => 1.0, + SpriteKind::Velorite => 1.0, + SpriteKind::VeloriteFrag => 1.0, + SpriteKind::Coconut => 1.0, + SpriteKind::StreetLampTall => 1.0, + SpriteKind::Window1 => 1.0, + SpriteKind::Window2 => 1.0, + SpriteKind::Window3 => 1.0, + SpriteKind::Window4 => 1.0, + SpriteKind::DropGate => 1.0, + // TODO: Figure out if this should be solid or not. + SpriteKind::Shelf => 1.0, + SpriteKind::Lantern => 0.9, + SpriteKind::CraftingBench => 1.18, + SpriteKind::Forge => 2.7, + SpriteKind::Cauldron => 1.27, + SpriteKind::Anvil => 1.1, + SpriteKind::CookingPot => 1.36, + _ => return None, + }) } pub fn is_collectible(&self) -> bool { @@ -315,6 +372,8 @@ pub struct PlantGrowthData { struct PlantGrowthPerKind { // TODO: if we made use of the assumption that chunks are 32x32xk voxels, we could pack // positions into 10+log_2(k) bits instead of using the whole 12 bytes that a Vec3 uses + // (don't make this optimization unless needed, and not without double-checking with zesterer + // about the best place to document what needs to be changed for handling larger chunk sizes). positions: Vec>, growth_amounts: Vec, last_growth_tick: f32, diff --git a/common/state/src/state.rs b/common/state/src/state.rs index 5a26c75822..26e611b2c0 100644 --- a/common/state/src/state.rs +++ b/common/state/src/state.rs @@ -81,9 +81,9 @@ impl TerrainChanges { } } -pub fn insert_terrain_chunk<'a>( - terrain_grid: &mut specs::WriteExpect<'a, TerrainGrid>, - terrain_changes: &mut specs::Write<'a, TerrainChanges>, +pub fn insert_terrain_chunk( + terrain_grid: &mut TerrainGrid, + terrain_changes: &mut TerrainChanges, key: Vec2, chunk: Arc, new_hook: impl FnOnce(), @@ -407,8 +407,8 @@ impl State { /// Insert the provided chunk into this state's terrain. pub fn insert_chunk(&mut self, key: Vec2, chunk: Arc) { insert_terrain_chunk( - &mut self.ecs.write_resource::().into(), - &mut self.ecs.write_resource::().into(), + &mut self.ecs.write_resource::(), + &mut self.ecs.write_resource::(), key, chunk, || (),