Optimize the types used for blocks.

Reduces the size of a block from 16 bytes -> 8 bytes on my 64 bit machine.
This commit is contained in:
Thinkofname 2016-04-09 13:48:42 +01:00
parent bb82798ab8
commit a7c586b2e9
2 changed files with 32 additions and 32 deletions

View File

@ -415,7 +415,7 @@ define_blocks! {
TreeVariant::Acacia, TreeVariant::Acacia,
TreeVariant::DarkOak TreeVariant::DarkOak
], ],
stage: i32 = [0, 1], stage: u8 = [0, 1],
}, },
data Some(variant.plank_data() | ((stage as usize) << 3)), data Some(variant.plank_data() | ((stage as usize) << 3)),
material material::NON_SOLID, material material::NON_SOLID,
@ -430,7 +430,7 @@ define_blocks! {
} }
FlowingWater { FlowingWater {
props { props {
level: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], level: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data Some(level as usize), data Some(level as usize),
material Material { material Material {
@ -442,7 +442,7 @@ define_blocks! {
} }
Water { Water {
props { props {
level: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], level: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data Some(level as usize), data Some(level as usize),
material Material { material Material {
@ -454,7 +454,7 @@ define_blocks! {
} }
FlowingLava { FlowingLava {
props { props {
level: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], level: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data Some(level as usize), data Some(level as usize),
material Material { material Material {
@ -467,7 +467,7 @@ define_blocks! {
} }
Lava { Lava {
props { props {
level: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], level: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data Some(level as usize), data Some(level as usize),
material Material { material Material {
@ -954,7 +954,7 @@ define_blocks! {
} }
Fire { Fire {
props { props {
age: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], age: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
up: bool = [false, true], up: bool = [false, true],
north: bool = [false, true], north: bool = [false, true],
south: bool = [false, true], south: bool = [false, true],
@ -1024,7 +1024,7 @@ define_blocks! {
south: RedstoneSide = [RedstoneSide::None, RedstoneSide::Side, RedstoneSide::Up], south: RedstoneSide = [RedstoneSide::None, RedstoneSide::Side, RedstoneSide::Up],
west: RedstoneSide = [RedstoneSide::None, RedstoneSide::Side, RedstoneSide::Up], west: RedstoneSide = [RedstoneSide::None, RedstoneSide::Side, RedstoneSide::Up],
east: RedstoneSide = [RedstoneSide::None, RedstoneSide::Side, RedstoneSide::Up], east: RedstoneSide = [RedstoneSide::None, RedstoneSide::Side, RedstoneSide::Up],
power: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], power: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data { data {
if north == RedstoneSide::None && south == RedstoneSide::None if north == RedstoneSide::None && south == RedstoneSide::None
@ -1070,7 +1070,7 @@ define_blocks! {
} }
Wheat { Wheat {
props { props {
age: i32 = [0, 1, 2, 3, 4, 5, 6, 7], age: u8 = [0, 1, 2, 3, 4, 5, 6, 7],
}, },
data Some(age as usize), data Some(age as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -1080,7 +1080,7 @@ define_blocks! {
} }
Farmland { Farmland {
props { props {
moisture: i32 = [0, 1, 2, 3, 4, 5, 6, 7], moisture: u8 = [0, 1, 2, 3, 4, 5, 6, 7],
}, },
data Some(moisture as usize), data Some(moisture as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -1401,7 +1401,7 @@ define_blocks! {
} }
SnowLayer { SnowLayer {
props { props {
layers: i32 = [1, 2, 3, 4, 5, 6, 7, 8], layers: u8 = [1, 2, 3, 4, 5, 6, 7, 8],
}, },
data Some(layers as usize - 1), data Some(layers as usize - 1),
material material::NON_SOLID, material material::NON_SOLID,
@ -1427,7 +1427,7 @@ define_blocks! {
} }
Cactus { Cactus {
props { props {
age: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], age: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data Some(age as usize), data Some(age as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -1444,7 +1444,7 @@ define_blocks! {
} }
Reeds { Reeds {
props { props {
age: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], age: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data Some(age as usize), data Some(age as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -1553,7 +1553,7 @@ define_blocks! {
} }
Cake { Cake {
props { props {
bites: i32 = [0, 1, 2, 3, 4, 5, 6], bites: u8 = [0, 1, 2, 3, 4, 5, 6],
}, },
data Some(bites as usize), data Some(bites as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -1566,7 +1566,7 @@ define_blocks! {
} }
RepeaterUnpowered { RepeaterUnpowered {
props { props {
delay: i32 = [1, 2, 3, 4], delay: u8 = [1, 2, 3, 4],
facing: Direction = [ facing: Direction = [
Direction::North, Direction::North,
Direction::South, Direction::South,
@ -1586,7 +1586,7 @@ define_blocks! {
} }
RepeaterPowered { RepeaterPowered {
props { props {
delay: i32 = [1, 2, 3, 4], delay: u8 = [1, 2, 3, 4],
facing: Direction = [ facing: Direction = [
Direction::North, Direction::North,
Direction::South, Direction::South,
@ -1784,7 +1784,7 @@ define_blocks! {
} }
PumpkinStem { PumpkinStem {
props { props {
age: i32 = [0, 1, 2, 3, 4, 5, 6, 7], age: u8 = [0, 1, 2, 3, 4, 5, 6, 7],
facing: Direction = [ facing: Direction = [
Direction::Up, Direction::Up,
Direction::North, Direction::North,
@ -1820,7 +1820,7 @@ define_blocks! {
} }
MelonStem { MelonStem {
props { props {
age: i32 = [0, 1, 2, 3, 4, 5, 6, 7], age: u8 = [0, 1, 2, 3, 4, 5, 6, 7],
facing: Direction = [ facing: Direction = [
Direction::Up, Direction::Up,
Direction::North, Direction::North,
@ -2024,7 +2024,7 @@ define_blocks! {
} }
NetherWart { NetherWart {
props { props {
age: i32 = [0, 1, 2, 3], age: u8 = [0, 1, 2, 3],
}, },
data Some(age as usize), data Some(age as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -2064,7 +2064,7 @@ define_blocks! {
} }
Cauldron { Cauldron {
props { props {
level: i32 = [0, 1, 2, 3], level: u8 = [0, 1, 2, 3],
}, },
data Some(level as usize), data Some(level as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -2188,7 +2188,7 @@ define_blocks! {
} }
Cocoa { Cocoa {
props { props {
age: i32 = [0, 1, 2], age: u8 = [0, 1, 2],
facing: Direction = [ facing: Direction = [
Direction::North, Direction::North,
Direction::South, Direction::South,
@ -2475,7 +2475,7 @@ define_blocks! {
FlowerPotVariant::Oxeye, FlowerPotVariant::Oxeye,
FlowerPotVariant::Dandelion FlowerPotVariant::Dandelion
], ],
legacy_data: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], legacy_data: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data if contents == FlowerPotVariant::Empty { Some(legacy_data as usize) } else { None }, data if contents == FlowerPotVariant::Empty { Some(legacy_data as usize) } else { None },
material material::NON_SOLID, material material::NON_SOLID,
@ -2483,7 +2483,7 @@ define_blocks! {
} }
Carrots { Carrots {
props { props {
age: i32 = [0, 1, 2, 3, 4, 5, 6, 7], age: u8 = [0, 1, 2, 3, 4, 5, 6, 7],
}, },
data Some(age as usize), data Some(age as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -2493,7 +2493,7 @@ define_blocks! {
} }
Potatoes { Potatoes {
props { props {
age: i32 = [0, 1, 2, 3, 4, 5, 6, 7], age: u8 = [0, 1, 2, 3, 4, 5, 6, 7],
}, },
data Some(age as usize), data Some(age as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -2560,7 +2560,7 @@ define_blocks! {
} }
Anvil { Anvil {
props { props {
damage: i32 = [0, 1, 2], damage: u8 = [0, 1, 2],
facing: Direction = [ facing: Direction = [
Direction::North, Direction::North,
Direction::South, Direction::South,
@ -2604,7 +2604,7 @@ define_blocks! {
} }
LightWeightedPressurePlate { LightWeightedPressurePlate {
props { props {
power: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], power: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data Some(power as usize), data Some(power as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -2614,7 +2614,7 @@ define_blocks! {
} }
HeavyWeightedPressurePlate { HeavyWeightedPressurePlate {
props { props {
power: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], power: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data Some(power as usize), data Some(power as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -2668,7 +2668,7 @@ define_blocks! {
} }
DaylightDetector { DaylightDetector {
props { props {
power: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], power: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data Some(power as usize), data Some(power as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -3096,7 +3096,7 @@ define_blocks! {
} }
DaylightDetectorInverted { DaylightDetectorInverted {
props { props {
power: i32 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], power: u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
}, },
data Some(power as usize), data Some(power as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -3613,7 +3613,7 @@ define_blocks! {
} }
ChorusFlower { ChorusFlower {
props { props {
age: i32 = [0, 1, 2, 3, 4, 5], age: u8 = [0, 1, 2, 3, 4, 5],
}, },
data Some(age as usize), data Some(age as usize),
material material::NON_SOLID, material material::NON_SOLID,
@ -3692,7 +3692,7 @@ define_blocks! {
} }
Beetroots { Beetroots {
props { props {
age: i32 = [0, 1, 2, 3], age: u8 = [0, 1, 2, 3],
}, },
data Some(age as usize), data Some(age as usize),
material material::NON_SOLID, material material::NON_SOLID,

View File

@ -127,14 +127,14 @@ fn average_liquid_level(
fn get_water_level(snapshot: &world::Snapshot, x: i32, y: i32, z: i32) -> Option<i32> { fn get_water_level(snapshot: &world::Snapshot, x: i32, y: i32, z: i32) -> Option<i32> {
match snapshot.get_block(x, y, z) { match snapshot.get_block(x, y, z) {
block::Block::Water{level} | block::Block::FlowingWater{level} => Some(level), block::Block::Water{level} | block::Block::FlowingWater{level} => Some(level as i32),
_ => None, _ => None,
} }
} }
fn get_lava_level(snapshot: &world::Snapshot, x: i32, y: i32, z: i32) -> Option<i32> { fn get_lava_level(snapshot: &world::Snapshot, x: i32, y: i32, z: i32) -> Option<i32> {
match snapshot.get_block(x, y, z) { match snapshot.get_block(x, y, z) {
block::Block::Lava{level} | block::Block::FlowingLava{level} => Some(level), block::Block::Lava{level} | block::Block::FlowingLava{level} => Some(level as i32),
_ => None, _ => None,
} }
} }