Cleaning up blocks a little bit.

This commit is contained in:
Scetch 2016-04-08 11:30:41 -04:00
parent accf01e1fb
commit 64ec2e4d3b
6 changed files with 515 additions and 994 deletions

File diff suppressed because it is too large Load Diff

View File

@ -30,31 +30,18 @@ pub const SOLID: Material = Material {
};
pub const NON_SOLID: Material = Material {
renderable: true,
never_cull: false,
should_cull_against: false,
force_shade: false,
transparent: false,
absorbed_light: 1,
emitted_light: 0,
..SOLID
};
pub const TRANSPARENT: Material = Material {
renderable: true,
never_cull: false,
should_cull_against: false,
force_shade: false,
transparent: true,
absorbed_light: 1,
emitted_light: 0,
..NON_SOLID
};
pub const LEAVES: Material = Material {
renderable: true,
never_cull: true,
should_cull_against: false,
force_shade: true,
transparent: false,
absorbed_light: 1,
emitted_light: 0,
..NON_SOLID
};

28
shared/src/axis.rs Normal file
View File

@ -0,0 +1,28 @@
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Axis {
Y,
Z,
X,
None
}
impl Axis {
pub fn as_string(&self) -> &'static str {
match *self {
Axis::X => "x",
Axis::Y => "y",
Axis::Z => "z",
Axis::None => "none",
}
}
pub fn index(&self) -> usize {
match *self {
Axis::Y => 0,
Axis::Z => 2,
Axis::X => 1,
Axis::None => 3,
}
}
}

View File

@ -1,8 +1,11 @@
use axis::Axis;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Direction {
Invalid,
Up,
Down,
Up,
North,
South,
West,
@ -12,7 +15,7 @@ pub enum Direction {
impl Direction {
pub fn all() -> Vec<Direction> {
vec![
Direction::Up, Direction::Down,
Direction::Down, Direction::Up,
Direction::North, Direction::South,
Direction::West, Direction::East,
]
@ -20,8 +23,8 @@ impl Direction {
pub fn from_string(val: &str) -> Direction {
match val {
"up" => Direction::Up,
"down" => Direction::Down,
"up" => Direction::Up,
"north" => Direction::North,
"south" => Direction::South,
"west" => Direction::West,
@ -32,8 +35,8 @@ impl Direction {
pub fn opposite(&self) -> Direction {
match *self {
Direction::Up => Direction::Down,
Direction::Down => Direction::Up,
Direction::Up => Direction::Down,
Direction::North => Direction::South,
Direction::South => Direction::North,
Direction::West => Direction::East,
@ -44,8 +47,8 @@ impl Direction {
pub fn clockwise(&self) -> Direction {
match *self {
Direction::Up => Direction::Up,
Direction::Down => Direction::Down,
Direction::Up => Direction::Up,
Direction::East => Direction::South,
Direction::West => Direction::North,
Direction::South => Direction::West,
@ -56,8 +59,8 @@ impl Direction {
pub fn counter_clockwise(&self) -> Direction {
match *self {
Direction::Up => Direction::Up,
Direction::Down => Direction::Down,
Direction::Up => Direction::Up,
Direction::East => Direction::North,
Direction::West => Direction::South,
Direction::South => Direction::East,
@ -68,8 +71,8 @@ impl Direction {
pub fn get_offset(&self) -> (i32, i32, i32) {
match *self {
Direction::Up => (0, 1, 0),
Direction::Down => (0, -1, 0),
Direction::Up => (0, 1, 0),
Direction::North => (0, 0, -1),
Direction::South => (0, 0, 1),
Direction::West => (-1, 0, 0),
@ -80,8 +83,8 @@ impl Direction {
pub fn as_string(&self) -> &'static str {
match *self {
Direction::Up => "up",
Direction::Down => "down",
Direction::Up => "up",
Direction::North => "north",
Direction::South => "south",
Direction::West => "west",
@ -92,8 +95,8 @@ impl Direction {
pub fn index(&self) -> usize {
match *self {
Direction::Up => 0,
Direction::Down => 1,
Direction::Down => 0,
Direction::Up => 1,
Direction::North => 2,
Direction::South => 3,
Direction::West => 4,
@ -101,4 +104,23 @@ impl Direction {
_ => unreachable!(),
}
}
pub fn horizontal_index(&self) -> usize {
match *self {
Direction::North => 2,
Direction::South => 0,
Direction::West => 1,
Direction::East => 3,
_ => unreachable!(),
}
}
pub fn axis(&self) -> Axis {
match *self {
Direction::Down | Direction::Up => Axis::Y,
Direction::North | Direction::South => Axis::Z,
Direction::West | Direction::East => Axis::X,
_ => unreachable!(),
}
}
}

View File

@ -1,4 +1,7 @@
pub mod axis;
pub use axis::Axis;
pub mod direction;
pub use direction::Direction;

View File

@ -32,7 +32,7 @@ use cgmath;
use collision::Aabb;
use sdl2::keyboard::Keycode;
use types::Gamemode;
use shared::Position;
use shared::{Axis, Position};
use format;
mod sun;
@ -230,7 +230,7 @@ impl Server {
if x*x + z*z > 16*16 && rng.gen_weighted_bool(80) {
for i in 0 .. 5 {
server.world.set_block(Position::new(x, h + 1 + i, z), block::Log{ axis: block::Axis::Y, variant: block::TreeVariant::Oak });
server.world.set_block(Position::new(x, h + 1 + i, z), block::Log{ axis: Axis::Y, variant: block::TreeVariant::Oak });
}
for xx in -2 .. 3 {
for zz in -2 .. 3 {