mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added Terrain type to scene
This commit is contained in:
parent
bd561dd1aa
commit
41b6672743
@ -4,6 +4,7 @@ members = [
|
||||
"client",
|
||||
"server",
|
||||
"voxygen",
|
||||
"world",
|
||||
]
|
||||
|
||||
[profile.dev]
|
||||
|
@ -6,5 +6,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
common = { package = "veloren-common", path = "../common" }
|
||||
world = { package = "veloren-world", path = "../world" }
|
||||
|
||||
specs = "0.14"
|
||||
vek = "0.9"
|
||||
|
@ -1,8 +1,16 @@
|
||||
// Standard
|
||||
use std::time::Duration;
|
||||
|
||||
// Internal
|
||||
use common::state::State;
|
||||
// Library
|
||||
use specs::Entity as EcsEntity;
|
||||
use vek::*;
|
||||
|
||||
// Project
|
||||
use common::{
|
||||
state::State,
|
||||
terrain::TerrainChunk,
|
||||
};
|
||||
use world::World;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
@ -17,7 +25,11 @@ pub struct Input {
|
||||
pub struct Client {
|
||||
state: State,
|
||||
|
||||
// TODO: Add "meta" state here
|
||||
player: Option<EcsEntity>,
|
||||
|
||||
// Testing
|
||||
world: World,
|
||||
pub chunk: Option<TerrainChunk>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
@ -25,9 +37,21 @@ impl Client {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state: State::new(),
|
||||
|
||||
player: None,
|
||||
|
||||
// Testing
|
||||
world: World::new(),
|
||||
chunk: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO: Get rid of this
|
||||
pub fn with_test_state(mut self) -> Self {
|
||||
self.chunk = Some(self.world.generate_chunk(Vec3::zero()));
|
||||
self
|
||||
}
|
||||
|
||||
/// Get a reference to the client's game state.
|
||||
pub fn state(&self) -> &State { &self.state }
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
pub enum BiomeKind {
|
||||
Void,
|
||||
Grassland,
|
||||
Ocean,
|
||||
Mountain,
|
||||
|
@ -1,35 +1,47 @@
|
||||
pub mod block;
|
||||
pub mod biome;
|
||||
|
||||
// Reexports
|
||||
pub use self::{
|
||||
block::Block,
|
||||
biome::BiomeKind,
|
||||
};
|
||||
|
||||
// Library
|
||||
use vek::*;
|
||||
|
||||
// Crate
|
||||
use crate::{
|
||||
vol::VolSize,
|
||||
volumes::vol_map::VolMap,
|
||||
volumes::{
|
||||
vol_map::VolMap,
|
||||
chunk::Chunk,
|
||||
},
|
||||
};
|
||||
|
||||
// Local
|
||||
use self::{
|
||||
block::Block,
|
||||
biome::BiomeKind,
|
||||
};
|
||||
// TerrainChunkSize
|
||||
|
||||
// ChunkSize
|
||||
pub struct TerrainChunkSize;
|
||||
|
||||
pub struct ChunkSize;
|
||||
|
||||
impl VolSize for ChunkSize {
|
||||
impl VolSize for TerrainChunkSize {
|
||||
const SIZE: Vec3<u32> = Vec3 { x: 32, y: 32, z: 32 };
|
||||
}
|
||||
|
||||
// ChunkMeta
|
||||
// TerrainChunkMeta
|
||||
|
||||
pub struct ChunkMeta {
|
||||
pub struct TerrainChunkMeta {
|
||||
biome: BiomeKind,
|
||||
}
|
||||
|
||||
// TerrainMap
|
||||
impl TerrainChunkMeta {
|
||||
pub fn void() -> Self {
|
||||
Self {
|
||||
biome: BiomeKind::Void,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type TerrainMap = VolMap<Block, ChunkSize, ChunkMeta>;
|
||||
// Terrain type aliases
|
||||
|
||||
pub type TerrainChunk = Chunk<Block, TerrainChunkSize, TerrainChunkMeta>;
|
||||
pub type TerrainMap = VolMap<Block, TerrainChunkSize, TerrainChunkMeta>;
|
||||
|
@ -105,4 +105,12 @@ impl<V: Vox, S: VolSize, M> VolMap<V, S, M> {
|
||||
chunks: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, key: Vec3<i32>, chunk: Chunk<V, S, M>) -> Option<Chunk<V, S, M>> {
|
||||
self.chunks.insert(key, chunk)
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, key: &Vec3<i32>) -> Option<Chunk<V, S, M>> {
|
||||
self.chunks.remove(key)
|
||||
}
|
||||
}
|
||||
|
@ -6,5 +6,6 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
common = { package = "veloren-common", path = "../common" }
|
||||
world = { package = "veloren-world", path = "../world" }
|
||||
|
||||
specs = "0.14"
|
||||
|
@ -3,6 +3,7 @@ use std::time::Duration;
|
||||
|
||||
// Internal
|
||||
use common::state::State;
|
||||
use world::World;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
@ -15,6 +16,7 @@ pub struct Input {
|
||||
|
||||
pub struct Server {
|
||||
state: State,
|
||||
world: World,
|
||||
|
||||
// TODO: Add "meta" state here
|
||||
}
|
||||
@ -24,15 +26,20 @@ impl Server {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state: State::new(),
|
||||
world: World::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a reference to the client's game state.
|
||||
/// Get a reference to the server's game state.
|
||||
pub fn state(&self) -> &State { &self.state }
|
||||
|
||||
/// Get a mutable reference to the client's game state.
|
||||
/// Get a mutable reference to the server's game state.
|
||||
pub fn state_mut(&mut self) -> &mut State { &mut self.state }
|
||||
|
||||
/// Get a reference to the server's world.
|
||||
pub fn world(&self) -> &World { &self.world }
|
||||
/// Get a mutable reference to the server's world.
|
||||
pub fn world_mut(&mut self) -> &mut World { &mut self.world }
|
||||
|
||||
/// Execute a single server tick, handle input and update the game state by the given duration
|
||||
pub fn tick(&mut self, input: Input, dt: Duration) -> Result<(), Error> {
|
||||
// This tick function is the centre of the Veloren universe. Most server-side things are
|
||||
|
@ -19,6 +19,7 @@ impl Animation for RunAnimation {
|
||||
) {
|
||||
let wave = (time as f32 * 12.0).sin();
|
||||
let wave_fast = (time as f32 * 6.0).sin();
|
||||
let wave_dip = (wave_fast.abs() - 0.5).abs();
|
||||
|
||||
skeleton.head.offset = Vec3::unit_z() * 13.0;
|
||||
skeleton.head.ori = Quaternion::rotation_z(wave * 0.3);
|
||||
@ -32,15 +33,15 @@ impl Animation for RunAnimation {
|
||||
skeleton.shorts.offset = Vec3::unit_z() * 4.0;
|
||||
skeleton.shorts.ori = Quaternion::rotation_z(wave * 0.1);
|
||||
|
||||
skeleton.l_hand.offset = Vec3::new(-7.5, wave * 5.0, 9.0);
|
||||
skeleton.r_hand.offset = Vec3::new(7.5, -wave * 5.0, 9.0);
|
||||
skeleton.l_hand.offset = Vec3::new(-6.0 - wave_dip * 6.0, wave * 5.0, 11.0 - wave_dip * 6.0);
|
||||
skeleton.r_hand.offset = Vec3::new(6.0 + wave_dip * 6.0, -wave * 5.0, 11.0 - wave_dip * 6.0);
|
||||
|
||||
skeleton.l_foot.offset = Vec3::new(-3.5, 2.0 - wave * 8.0, 3.5 - (wave_fast.abs() - 0.5).abs() * 4.0);
|
||||
skeleton.l_foot.offset = Vec3::new(-3.5, 1.0 - wave * 8.0, 3.5 - wave_dip * 4.0);
|
||||
skeleton.l_foot.ori = Quaternion::rotation_x(-wave + 1.0);
|
||||
skeleton.r_foot.offset = Vec3::new(3.5, 2.0 + wave * 8.0, 3.5 - (wave_fast.abs() - 0.5).abs() * 4.0);
|
||||
skeleton.r_foot.offset = Vec3::new(3.5, 1.0 + wave * 8.0, 3.5 - wave_dip * 4.0);
|
||||
skeleton.r_foot.ori = Quaternion::rotation_x(wave + 1.0);
|
||||
|
||||
skeleton.back.offset = Vec3::new(-8.0, 5.0, 16.0);
|
||||
skeleton.back.offset = Vec3::new(-9.0, 5.0, 18.0);
|
||||
skeleton.back.ori = Quaternion::rotation_y(2.5);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,8 @@ impl Camera {
|
||||
}
|
||||
}
|
||||
|
||||
/// Compute the transformation matrices (view matrix and projection matrix) for the camera.
|
||||
/// Compute the transformation matrices (view matrix and projection matrix) and position of the
|
||||
/// camera.
|
||||
pub fn compute_dependents(&self) -> (Mat4<f32>, Mat4<f32>, Vec3<f32>) {
|
||||
let view_mat = Mat4::<f32>::identity()
|
||||
* Mat4::translation_3d(-Vec3::unit_z() * self.dist)
|
||||
|
@ -1,5 +1,6 @@
|
||||
pub mod camera;
|
||||
pub mod figure;
|
||||
pub mod terrain;
|
||||
|
||||
// Library
|
||||
use vek::*;
|
||||
@ -33,6 +34,7 @@ use crate::{
|
||||
use self::{
|
||||
camera::Camera,
|
||||
figure::Figure,
|
||||
terrain::Terrain,
|
||||
};
|
||||
|
||||
// TODO: Don't hard-code this
|
||||
@ -44,9 +46,11 @@ struct Skybox {
|
||||
}
|
||||
|
||||
pub struct Scene {
|
||||
camera: Camera,
|
||||
globals: Consts<Globals>,
|
||||
camera: Camera,
|
||||
|
||||
skybox: Skybox,
|
||||
terrain: Terrain,
|
||||
|
||||
test_figure: Figure<CharacterSkeleton>,
|
||||
}
|
||||
@ -58,12 +62,13 @@ fn load_segment(filename: &'static str) -> Segment {
|
||||
|
||||
impl Scene {
|
||||
/// Create a new `Scene` with default parameters.
|
||||
pub fn new(renderer: &mut Renderer) -> Self {
|
||||
pub fn new(renderer: &mut Renderer, client: &Client) -> Self {
|
||||
Self {
|
||||
camera: Camera::new(),
|
||||
globals: renderer
|
||||
.create_consts(&[Globals::default()])
|
||||
.unwrap(),
|
||||
camera: Camera::new(),
|
||||
|
||||
skybox: Skybox {
|
||||
model: renderer
|
||||
.create_model(&create_skybox_mesh())
|
||||
@ -72,6 +77,7 @@ impl Scene {
|
||||
.create_consts(&[SkyboxLocals::default()])
|
||||
.unwrap(),
|
||||
},
|
||||
terrain: Terrain::new(),
|
||||
|
||||
test_figure: Figure::new(
|
||||
renderer,
|
||||
@ -129,6 +135,9 @@ impl Scene {
|
||||
)])
|
||||
.expect("Failed to update global constants");
|
||||
|
||||
// Maintain terrain GPU data
|
||||
self.terrain.maintain_gpu_data(renderer);
|
||||
|
||||
// TODO: Don't do this here
|
||||
RunAnimation::update_skeleton(
|
||||
&mut self.test_figure.skeleton,
|
||||
@ -147,6 +156,9 @@ impl Scene {
|
||||
&self.skybox.locals,
|
||||
);
|
||||
|
||||
// Render terrain
|
||||
self.terrain.render(renderer, &self.globals);
|
||||
|
||||
// Render the test figure
|
||||
self.test_figure.render(renderer, &self.globals);
|
||||
}
|
||||
|
52
voxygen/src/scene/terrain.rs
Normal file
52
voxygen/src/scene/terrain.rs
Normal file
@ -0,0 +1,52 @@
|
||||
// Standard
|
||||
use std::collections::HashMap;
|
||||
|
||||
// Library
|
||||
use vek::*;
|
||||
|
||||
// Crate
|
||||
use crate::{
|
||||
Error,
|
||||
render::{
|
||||
Consts,
|
||||
Globals,
|
||||
Mesh,
|
||||
Model,
|
||||
Renderer,
|
||||
TerrainPipeline,
|
||||
TerrainLocals,
|
||||
},
|
||||
};
|
||||
|
||||
struct TerrainChunk {
|
||||
// GPU data
|
||||
model: Model<TerrainPipeline>,
|
||||
locals: Consts<TerrainLocals>,
|
||||
}
|
||||
|
||||
pub struct Terrain {
|
||||
chunks: HashMap<Vec3<i32>, TerrainChunk>,
|
||||
}
|
||||
|
||||
impl Terrain {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
chunks: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maintain_gpu_data(&mut self, renderer: &mut Renderer) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
pub fn render(&self, renderer: &mut Renderer, globals: &Consts<Globals>) {
|
||||
/*
|
||||
renderer.render_terrain_chunk(
|
||||
&self.model,
|
||||
globals,
|
||||
&self.locals,
|
||||
&self.bone_consts,
|
||||
);
|
||||
*/
|
||||
}
|
||||
}
|
@ -33,10 +33,11 @@ pub struct SessionState {
|
||||
impl SessionState {
|
||||
/// Create a new `SessionState`
|
||||
pub fn new(renderer: &mut Renderer) -> Self {
|
||||
let client = Client::new().with_test_state(); // <--- TODO: Remove this
|
||||
Self {
|
||||
// Create a scene for this session. The scene handles visible elements of the game world
|
||||
scene: Scene::new(renderer),
|
||||
client: Client::new(),
|
||||
scene: Scene::new(renderer, &client),
|
||||
client,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
3
world/.gitignore
vendored
Normal file
3
world/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
9
world/Cargo.toml
Normal file
9
world/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "veloren-world"
|
||||
version = "0.1.0"
|
||||
authors = ["Joshua Barretto <joshua.s.barretto@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
common = { package = "veloren-common", path = "../common" }
|
||||
vek = "0.9"
|
29
world/src/lib.rs
Normal file
29
world/src/lib.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// Library
|
||||
use vek::*;
|
||||
|
||||
// Project
|
||||
use common::{
|
||||
vol::Vox,
|
||||
terrain::{
|
||||
Block,
|
||||
TerrainChunk,
|
||||
TerrainChunkMeta,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Other(String),
|
||||
}
|
||||
|
||||
pub struct World;
|
||||
|
||||
impl World {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
pub fn generate_chunk(&self, pos: Vec3<i32>) -> TerrainChunk {
|
||||
TerrainChunk::filled(Block::empty(), TerrainChunkMeta::void())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user