Move Direction and BlockVertex into better locations
This commit is contained in:
parent
fdfdfa71e2
commit
0855424e52
|
@ -3,13 +3,13 @@ use std::thread;
|
|||
use std::sync::mpsc;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::io::Write;
|
||||
use byteorder::{WriteBytesExt, NativeEndian};
|
||||
use world;
|
||||
use world::block;
|
||||
use render;
|
||||
use resources;
|
||||
use model;
|
||||
use types::bit::Set;
|
||||
use types::Direction;
|
||||
|
||||
const NUM_WORKERS: usize = 8;
|
||||
|
||||
|
@ -286,187 +286,3 @@ impl CullInfo {
|
|||
self.0 |= 1 << (from.index() * 6 + to.index());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Direction {
|
||||
Invalid,
|
||||
Up,
|
||||
Down,
|
||||
North,
|
||||
South,
|
||||
West,
|
||||
East,
|
||||
}
|
||||
|
||||
impl Direction {
|
||||
pub fn all() -> Vec<Direction> {
|
||||
vec![
|
||||
Direction::Up, Direction::Down,
|
||||
Direction::North, Direction::South,
|
||||
Direction::West, Direction::East,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn from_string(val: &str) -> Direction {
|
||||
match val {
|
||||
"up" => Direction::Up,
|
||||
"down" => Direction::Down,
|
||||
"north" => Direction::North,
|
||||
"south" => Direction::South,
|
||||
"west" => Direction::West,
|
||||
"east" => Direction::East,
|
||||
_ => Direction::Invalid,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opposite(&self) -> Direction {
|
||||
match *self {
|
||||
Direction::Up => Direction::Down,
|
||||
Direction::Down => Direction::Up,
|
||||
Direction::North => Direction::South,
|
||||
Direction::South => Direction::North,
|
||||
Direction::West => Direction::East,
|
||||
Direction::East => Direction::West,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_verts(&self) -> &'static [BlockVertex; 4] {
|
||||
match *self {
|
||||
Direction::Up => PRECOMPUTED_VERTS[0],
|
||||
Direction::Down => PRECOMPUTED_VERTS[1],
|
||||
Direction::North => PRECOMPUTED_VERTS[2],
|
||||
Direction::South => PRECOMPUTED_VERTS[3],
|
||||
Direction::West => PRECOMPUTED_VERTS[4],
|
||||
Direction::East => PRECOMPUTED_VERTS[5],
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_offset(&self) -> (i32, i32, i32) {
|
||||
match *self {
|
||||
Direction::Up => (0, 1, 0),
|
||||
Direction::Down => (0, -1, 0),
|
||||
Direction::North => (0, 0, -1),
|
||||
Direction::South => (0, 0, 1),
|
||||
Direction::West => (-1, 0, 0),
|
||||
Direction::East => (1, 0, 0),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_string(&self) -> &'static str {
|
||||
match *self {
|
||||
Direction::Up => "up",
|
||||
Direction::Down => "down",
|
||||
Direction::North => "north",
|
||||
Direction::South => "south",
|
||||
Direction::West => "west",
|
||||
Direction::East => "east",
|
||||
Direction::Invalid => "invalid",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn index(&self) -> usize {
|
||||
match *self {
|
||||
Direction::Up => 0,
|
||||
Direction::Down => 1,
|
||||
Direction::North => 2,
|
||||
Direction::South => 3,
|
||||
Direction::West => 4,
|
||||
Direction::East => 5,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const PRECOMPUTED_VERTS: [&'static [BlockVertex; 4]; 6] = [
|
||||
&[ // Up
|
||||
BlockVertex::base(0.0, 1.0, 0.0, 0, 0),
|
||||
BlockVertex::base(1.0, 1.0, 0.0, 1, 0),
|
||||
BlockVertex::base(0.0, 1.0, 1.0, 0, 1),
|
||||
BlockVertex::base(1.0, 1.0, 1.0, 1, 1),
|
||||
],
|
||||
&[ // Down
|
||||
BlockVertex::base(0.0, 0.0, 0.0, 0, 1),
|
||||
BlockVertex::base(0.0, 0.0, 1.0, 0, 0),
|
||||
BlockVertex::base(1.0, 0.0, 0.0, 1, 1),
|
||||
BlockVertex::base(1.0, 0.0, 1.0, 1, 0),
|
||||
],
|
||||
&[ // North
|
||||
BlockVertex::base(0.0, 0.0, 0.0, 1, 1),
|
||||
BlockVertex::base(1.0, 0.0, 0.0, 0, 1),
|
||||
BlockVertex::base(0.0, 1.0, 0.0, 1, 0),
|
||||
BlockVertex::base(1.0, 1.0, 0.0, 0, 0),
|
||||
],
|
||||
&[ // South
|
||||
BlockVertex::base(0.0, 0.0, 1.0, 0, 1),
|
||||
BlockVertex::base(0.0, 1.0, 1.0, 0, 0),
|
||||
BlockVertex::base(1.0, 0.0, 1.0, 1, 1),
|
||||
BlockVertex::base(1.0, 1.0, 1.0, 1, 0),
|
||||
],
|
||||
&[ // West
|
||||
BlockVertex::base(0.0, 0.0, 0.0, 0, 1),
|
||||
BlockVertex::base(0.0, 1.0, 0.0, 0, 0),
|
||||
BlockVertex::base(0.0, 0.0, 1.0, 1, 1),
|
||||
BlockVertex::base(0.0, 1.0, 1.0, 1, 0),
|
||||
],
|
||||
&[ // East
|
||||
BlockVertex::base(1.0, 0.0, 0.0, 1, 1),
|
||||
BlockVertex::base(1.0, 0.0, 1.0, 0, 1),
|
||||
BlockVertex::base(1.0, 1.0, 0.0, 1, 0),
|
||||
BlockVertex::base(1.0, 1.0, 1.0, 0, 0),
|
||||
],
|
||||
];
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BlockVertex {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub z: f32,
|
||||
pub tx: u16,
|
||||
pub ty: u16,
|
||||
pub tw: u16,
|
||||
pub th: u16,
|
||||
pub toffsetx: i16,
|
||||
pub toffsety: i16,
|
||||
pub tatlas: i16,
|
||||
pub r: u8,
|
||||
pub g: u8,
|
||||
pub b: u8,
|
||||
pub block_light: u16,
|
||||
pub sky_light: u16,
|
||||
}
|
||||
|
||||
impl BlockVertex {
|
||||
const fn base(x: f32, y: f32, z: f32, tx: i16, ty: i16) -> BlockVertex {
|
||||
BlockVertex {
|
||||
x: x, y: y, z: z,
|
||||
tx: 0, ty: 0, tw: 0, th: 0,
|
||||
toffsetx: tx, toffsety: ty, tatlas: 0,
|
||||
r: 0, g: 0, b: 0,
|
||||
block_light: 0, sky_light: 0,
|
||||
}
|
||||
}
|
||||
pub fn write<W: Write>(&self, w: &mut W) {
|
||||
let _ = w.write_f32::<NativeEndian>(self.x);
|
||||
let _ = w.write_f32::<NativeEndian>(self.y);
|
||||
let _ = w.write_f32::<NativeEndian>(self.z);
|
||||
let _ = w.write_u16::<NativeEndian>(self.tx);
|
||||
let _ = w.write_u16::<NativeEndian>(self.ty);
|
||||
let _ = w.write_u16::<NativeEndian>(self.tw);
|
||||
let _ = w.write_u16::<NativeEndian>(self.th);
|
||||
let _ = w.write_i16::<NativeEndian>(self.toffsetx);
|
||||
let _ = w.write_i16::<NativeEndian>(self.toffsety);
|
||||
let _ = w.write_i16::<NativeEndian>(self.tatlas);
|
||||
let _ = w.write_i16::<NativeEndian>(0);
|
||||
let _ = w.write_u8(self.r);
|
||||
let _ = w.write_u8(self.g);
|
||||
let _ = w.write_u8(self.b);
|
||||
let _ = w.write_u8(255);
|
||||
let _ = w.write_u16::<NativeEndian>(self.block_light);
|
||||
let _ = w.write_u16::<NativeEndian>(self.sky_light);
|
||||
let _ = w.write_u16::<NativeEndian>(0);
|
||||
let _ = w.write_u16::<NativeEndian>(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
use std::io::Write;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use world::{self, block};
|
||||
use chunk_builder::Direction;
|
||||
use types::Direction;
|
||||
use render;
|
||||
|
||||
pub fn render_liquid<W: Write>(textures: Arc<RwLock<render::TextureManager>>,lava: bool, snapshot: &world::Snapshot, x: i32, y: i32, z: i32, buf: &mut W) -> usize {
|
||||
|
|
|
@ -4,11 +4,12 @@ pub mod liquid;
|
|||
use std::sync::{Arc, RwLock};
|
||||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
use byteorder::{WriteBytesExt, NativeEndian};
|
||||
use resources;
|
||||
use render;
|
||||
use world;
|
||||
use world::block::TintType;
|
||||
use chunk_builder::{self, Direction};
|
||||
use types::Direction;
|
||||
use serde_json;
|
||||
|
||||
use std::hash::BuildHasherDefault;
|
||||
|
@ -732,7 +733,7 @@ struct Model {
|
|||
struct Face {
|
||||
cull_face: Direction,
|
||||
facing: Direction,
|
||||
vertices: Vec<chunk_builder::BlockVertex>,
|
||||
vertices: Vec<BlockVertex>,
|
||||
vertices_texture: Vec<render::Texture>,
|
||||
indices: usize,
|
||||
shade: bool,
|
||||
|
@ -892,3 +893,96 @@ fn calculate_light(snapshot: &world::Snapshot, orig_x: i32, orig_y: i32, orig_z:
|
|||
|
||||
((((block_light * 4000) / count) as u16), (((sky_light * 4000) / count) as u16))
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub const PRECOMPUTED_VERTS: [&'static [BlockVertex; 4]; 6] = [
|
||||
&[ // Up
|
||||
BlockVertex::base(0.0, 1.0, 0.0, 0, 0),
|
||||
BlockVertex::base(1.0, 1.0, 0.0, 1, 0),
|
||||
BlockVertex::base(0.0, 1.0, 1.0, 0, 1),
|
||||
BlockVertex::base(1.0, 1.0, 1.0, 1, 1),
|
||||
],
|
||||
&[ // Down
|
||||
BlockVertex::base(0.0, 0.0, 0.0, 0, 1),
|
||||
BlockVertex::base(0.0, 0.0, 1.0, 0, 0),
|
||||
BlockVertex::base(1.0, 0.0, 0.0, 1, 1),
|
||||
BlockVertex::base(1.0, 0.0, 1.0, 1, 0),
|
||||
],
|
||||
&[ // North
|
||||
BlockVertex::base(0.0, 0.0, 0.0, 1, 1),
|
||||
BlockVertex::base(1.0, 0.0, 0.0, 0, 1),
|
||||
BlockVertex::base(0.0, 1.0, 0.0, 1, 0),
|
||||
BlockVertex::base(1.0, 1.0, 0.0, 0, 0),
|
||||
],
|
||||
&[ // South
|
||||
BlockVertex::base(0.0, 0.0, 1.0, 0, 1),
|
||||
BlockVertex::base(0.0, 1.0, 1.0, 0, 0),
|
||||
BlockVertex::base(1.0, 0.0, 1.0, 1, 1),
|
||||
BlockVertex::base(1.0, 1.0, 1.0, 1, 0),
|
||||
],
|
||||
&[ // West
|
||||
BlockVertex::base(0.0, 0.0, 0.0, 0, 1),
|
||||
BlockVertex::base(0.0, 1.0, 0.0, 0, 0),
|
||||
BlockVertex::base(0.0, 0.0, 1.0, 1, 1),
|
||||
BlockVertex::base(0.0, 1.0, 1.0, 1, 0),
|
||||
],
|
||||
&[ // East
|
||||
BlockVertex::base(1.0, 0.0, 0.0, 1, 1),
|
||||
BlockVertex::base(1.0, 0.0, 1.0, 0, 1),
|
||||
BlockVertex::base(1.0, 1.0, 0.0, 1, 0),
|
||||
BlockVertex::base(1.0, 1.0, 1.0, 0, 0),
|
||||
],
|
||||
];
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BlockVertex {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub z: f32,
|
||||
pub tx: u16,
|
||||
pub ty: u16,
|
||||
pub tw: u16,
|
||||
pub th: u16,
|
||||
pub toffsetx: i16,
|
||||
pub toffsety: i16,
|
||||
pub tatlas: i16,
|
||||
pub r: u8,
|
||||
pub g: u8,
|
||||
pub b: u8,
|
||||
pub block_light: u16,
|
||||
pub sky_light: u16,
|
||||
}
|
||||
|
||||
impl BlockVertex {
|
||||
const fn base(x: f32, y: f32, z: f32, tx: i16, ty: i16) -> BlockVertex {
|
||||
BlockVertex {
|
||||
x: x, y: y, z: z,
|
||||
tx: 0, ty: 0, tw: 0, th: 0,
|
||||
toffsetx: tx, toffsety: ty, tatlas: 0,
|
||||
r: 0, g: 0, b: 0,
|
||||
block_light: 0, sky_light: 0,
|
||||
}
|
||||
}
|
||||
pub fn write<W: Write>(&self, w: &mut W) {
|
||||
let _ = w.write_f32::<NativeEndian>(self.x);
|
||||
let _ = w.write_f32::<NativeEndian>(self.y);
|
||||
let _ = w.write_f32::<NativeEndian>(self.z);
|
||||
let _ = w.write_u16::<NativeEndian>(self.tx);
|
||||
let _ = w.write_u16::<NativeEndian>(self.ty);
|
||||
let _ = w.write_u16::<NativeEndian>(self.tw);
|
||||
let _ = w.write_u16::<NativeEndian>(self.th);
|
||||
let _ = w.write_i16::<NativeEndian>(self.toffsetx);
|
||||
let _ = w.write_i16::<NativeEndian>(self.toffsety);
|
||||
let _ = w.write_i16::<NativeEndian>(self.tatlas);
|
||||
let _ = w.write_i16::<NativeEndian>(0);
|
||||
let _ = w.write_u8(self.r);
|
||||
let _ = w.write_u8(self.g);
|
||||
let _ = w.write_u8(self.b);
|
||||
let _ = w.write_u8(255);
|
||||
let _ = w.write_u16::<NativeEndian>(self.block_light);
|
||||
let _ = w.write_u16::<NativeEndian>(self.sky_light);
|
||||
let _ = w.write_u16::<NativeEndian>(0);
|
||||
let _ = w.write_u16::<NativeEndian>(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,3 +21,98 @@ pub use self::metadata::*;
|
|||
pub mod bit;
|
||||
pub mod nibble;
|
||||
pub mod hash;
|
||||
|
||||
use model::{PRECOMPUTED_VERTS, BlockVertex};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Direction {
|
||||
Invalid,
|
||||
Up,
|
||||
Down,
|
||||
North,
|
||||
South,
|
||||
West,
|
||||
East,
|
||||
}
|
||||
|
||||
impl Direction {
|
||||
pub fn all() -> Vec<Direction> {
|
||||
vec![
|
||||
Direction::Up, Direction::Down,
|
||||
Direction::North, Direction::South,
|
||||
Direction::West, Direction::East,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn from_string(val: &str) -> Direction {
|
||||
match val {
|
||||
"up" => Direction::Up,
|
||||
"down" => Direction::Down,
|
||||
"north" => Direction::North,
|
||||
"south" => Direction::South,
|
||||
"west" => Direction::West,
|
||||
"east" => Direction::East,
|
||||
_ => Direction::Invalid,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opposite(&self) -> Direction {
|
||||
match *self {
|
||||
Direction::Up => Direction::Down,
|
||||
Direction::Down => Direction::Up,
|
||||
Direction::North => Direction::South,
|
||||
Direction::South => Direction::North,
|
||||
Direction::West => Direction::East,
|
||||
Direction::East => Direction::West,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_verts(&self) -> &'static [BlockVertex; 4] {
|
||||
match *self {
|
||||
Direction::Up => PRECOMPUTED_VERTS[0],
|
||||
Direction::Down => PRECOMPUTED_VERTS[1],
|
||||
Direction::North => PRECOMPUTED_VERTS[2],
|
||||
Direction::South => PRECOMPUTED_VERTS[3],
|
||||
Direction::West => PRECOMPUTED_VERTS[4],
|
||||
Direction::East => PRECOMPUTED_VERTS[5],
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_offset(&self) -> (i32, i32, i32) {
|
||||
match *self {
|
||||
Direction::Up => (0, 1, 0),
|
||||
Direction::Down => (0, -1, 0),
|
||||
Direction::North => (0, 0, -1),
|
||||
Direction::South => (0, 0, 1),
|
||||
Direction::West => (-1, 0, 0),
|
||||
Direction::East => (1, 0, 0),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_string(&self) -> &'static str {
|
||||
match *self {
|
||||
Direction::Up => "up",
|
||||
Direction::Down => "down",
|
||||
Direction::North => "north",
|
||||
Direction::South => "south",
|
||||
Direction::West => "west",
|
||||
Direction::East => "east",
|
||||
Direction::Invalid => "invalid",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn index(&self) -> usize {
|
||||
match *self {
|
||||
Direction::Up => 0,
|
||||
Direction::Down => 1,
|
||||
Direction::North => 2,
|
||||
Direction::South => 3,
|
||||
Direction::West => 4,
|
||||
Direction::East => 5,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,8 @@ impl World {
|
|||
}
|
||||
|
||||
pub fn compute_render_list(&mut self, renderer: &mut render::Renderer) {
|
||||
use chunk_builder::{self, Direction};
|
||||
use chunk_builder;
|
||||
use types::Direction;
|
||||
use cgmath::Vector;
|
||||
use std::collections::VecDeque;
|
||||
self.render_list.clear();
|
||||
|
|
Loading…
Reference in New Issue