mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Cleaned code
Former-commit-id: fd4ef550ff58f621a129901d142d80266fbbc534
This commit is contained in:
parent
49cdd95c84
commit
3d14d791cf
@ -1,4 +1,4 @@
|
|||||||
use specs::{Component, VecStorage, Entity as EcsEntity};
|
use specs::{Component, Entity as EcsEntity, VecStorage};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
@ -19,17 +19,15 @@ impl<'a> System<'a> for Sys {
|
|||||||
for (mut agent, pos, mut control) in (&mut agents, &positions, &mut controls).join() {
|
for (mut agent, pos, mut control) in (&mut agents, &positions, &mut controls).join() {
|
||||||
match agent {
|
match agent {
|
||||||
Agent::Wanderer(bearing) => {
|
Agent::Wanderer(bearing) => {
|
||||||
*bearing += Vec2::new(
|
*bearing += Vec2::new(rand::random::<f32>() - 0.5, rand::random::<f32>() - 0.5)
|
||||||
rand::random::<f32>() - 0.5,
|
* 0.1
|
||||||
rand::random::<f32>() - 0.5,
|
|
||||||
) * 0.1
|
|
||||||
- *bearing * 0.01
|
- *bearing * 0.01
|
||||||
- pos.0 * 0.0002;
|
- pos.0 * 0.0002;
|
||||||
|
|
||||||
if bearing.magnitude_squared() != 0.0 {
|
if bearing.magnitude_squared() != 0.0 {
|
||||||
control.move_dir = bearing.normalized();
|
control.move_dir = bearing.normalized();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Agent::Pet { target, offset } => {
|
Agent::Pet { target, offset } => {
|
||||||
// Run towards target
|
// Run towards target
|
||||||
match positions.get(*target) {
|
match positions.get(*target) {
|
||||||
@ -48,18 +46,17 @@ impl<'a> System<'a> for Sys {
|
|||||||
} else {
|
} else {
|
||||||
Vec2::zero()
|
Vec2::zero()
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
_ => control.move_dir = Vec2::zero(),
|
_ => control.move_dir = Vec2::zero(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change offset occasionally
|
// Change offset occasionally
|
||||||
if rand::random::<f32>() < 0.003 {
|
if rand::random::<f32>() < 0.003 {
|
||||||
*offset = Vec2::new(
|
*offset =
|
||||||
rand::random::<f32>() - 0.5,
|
Vec2::new(rand::random::<f32>() - 0.5, rand::random::<f32>() - 0.5)
|
||||||
rand::random::<f32>() - 0.5,
|
* 10.0;
|
||||||
) * 10.0;
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,7 @@
|
|||||||
|
|
||||||
use crate::Server;
|
use crate::Server;
|
||||||
use common::{comp, msg::ServerMsg};
|
use common::{comp, msg::ServerMsg};
|
||||||
use specs::{
|
use specs::{Builder, Entity as EcsEntity, Join};
|
||||||
Join,
|
|
||||||
Entity as EcsEntity,
|
|
||||||
Builder,
|
|
||||||
};
|
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
@ -198,15 +194,23 @@ fn handle_pet(server: &mut Server, entity: EcsEntity, args: String, action: &Cha
|
|||||||
let mut current = entity;
|
let mut current = entity;
|
||||||
|
|
||||||
for _ in 0..1 {
|
for _ in 0..1 {
|
||||||
current = server.create_npc(comp::Character::random())
|
current = server
|
||||||
|
.create_npc(comp::Character::random())
|
||||||
.with(comp::Control::default())
|
.with(comp::Control::default())
|
||||||
.with(comp::Agent::Pet{ target: current, offset: Vec2::zero() })
|
.with(comp::Agent::Pet {
|
||||||
|
target: current,
|
||||||
|
offset: Vec2::zero(),
|
||||||
|
})
|
||||||
.with(pos)
|
.with(pos)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
server.clients.notify(entity, ServerMsg::Chat("Pet spawned!".to_owned()));
|
server
|
||||||
},
|
.clients
|
||||||
None => server.clients.notify(entity, ServerMsg::Chat("You have no position!".to_owned())),
|
.notify(entity, ServerMsg::Chat("Pet spawned!".to_owned()));
|
||||||
|
}
|
||||||
|
None => server
|
||||||
|
.clients
|
||||||
|
.notify(entity, ServerMsg::Chat("You have no position!".to_owned())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,10 +139,7 @@ impl Server {
|
|||||||
state.write_component(entity, comp::phys::ForceUpdate);
|
state.write_component(entity, comp::phys::ForceUpdate);
|
||||||
|
|
||||||
// Set initial animation
|
// Set initial animation
|
||||||
state.write_component(
|
state.write_component(entity, comp::AnimationHistory::new(Animation::Idle));
|
||||||
entity,
|
|
||||||
comp::AnimationHistory::new(Animation::Idle),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Tell the client his request was successful
|
// Tell the client his request was successful
|
||||||
client.notify(ServerMsg::StateAnswer(Ok(ClientState::Character)));
|
client.notify(ServerMsg::StateAnswer(Ok(ClientState::Character)));
|
||||||
@ -227,7 +224,9 @@ impl Server {
|
|||||||
.join()
|
.join()
|
||||||
{
|
{
|
||||||
let chunk_pos = self.state.terrain().pos_key(pos.0.map(|e| e as i32));
|
let chunk_pos = self.state.terrain().pos_key(pos.0.map(|e| e as i32));
|
||||||
let dist = Vec2::from(chunk_pos - key).map(|e: i32| e.abs()).reduce_max();
|
let dist = Vec2::from(chunk_pos - key)
|
||||||
|
.map(|e: i32| e.abs())
|
||||||
|
.reduce_max();
|
||||||
min_dist = min_dist.min(dist);
|
min_dist = min_dist.min(dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
mod ui;
|
|
||||||
mod scene;
|
mod scene;
|
||||||
|
mod ui;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
session::SessionState,
|
session::SessionState,
|
||||||
@ -8,9 +8,9 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use client::{self, Client};
|
use client::{self, Client};
|
||||||
use common::{clock::Clock, msg::ClientMsg};
|
use common::{clock::Clock, msg::ClientMsg};
|
||||||
|
use scene::Scene;
|
||||||
use std::{cell::RefCell, rc::Rc, time::Duration};
|
use std::{cell::RefCell, rc::Rc, time::Duration};
|
||||||
use ui::CharSelectionUi;
|
use ui::CharSelectionUi;
|
||||||
use scene::Scene;
|
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
const FPS: u64 = 60;
|
const FPS: u64 = 60;
|
||||||
@ -87,10 +87,12 @@ impl PlayState for CharSelectionState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Maintain the scene
|
// Maintain the scene
|
||||||
self.scene.maintain(global_state.window.renderer_mut(), &self.client.borrow());
|
self.scene
|
||||||
|
.maintain(global_state.window.renderer_mut(), &self.client.borrow());
|
||||||
|
|
||||||
// Render the scene
|
// Render the scene
|
||||||
self.scene.render(global_state.window.renderer_mut(), &self.client.borrow());
|
self.scene
|
||||||
|
.render(global_state.window.renderer_mut(), &self.client.borrow());
|
||||||
|
|
||||||
// Draw the UI to the screen
|
// Draw the UI to the screen
|
||||||
self.char_selection_ui
|
self.char_selection_ui
|
||||||
|
@ -1,36 +1,20 @@
|
|||||||
use vek::*;
|
|
||||||
use client::Client;
|
|
||||||
use common::{
|
|
||||||
comp::Character,
|
|
||||||
figure::Segment,
|
|
||||||
};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
anim::{
|
||||||
|
character::{CharacterSkeleton, IdleAnimation},
|
||||||
|
Animation, Skeleton,
|
||||||
|
},
|
||||||
render::{
|
render::{
|
||||||
Renderer,
|
create_pp_mesh, create_skybox_mesh, Consts, FigurePipeline, Globals, Model,
|
||||||
Consts,
|
PostProcessLocals, PostProcessPipeline, Renderer, SkyboxLocals, SkyboxPipeline,
|
||||||
Globals,
|
|
||||||
Model,
|
|
||||||
SkyboxLocals,
|
|
||||||
SkyboxPipeline,
|
|
||||||
create_skybox_mesh,
|
|
||||||
PostProcessLocals,
|
|
||||||
PostProcessPipeline,
|
|
||||||
create_pp_mesh,
|
|
||||||
FigurePipeline,
|
|
||||||
},
|
},
|
||||||
scene::{
|
scene::{
|
||||||
camera::Camera,
|
camera::Camera,
|
||||||
figure::{FigureModelCache, FigureState},
|
figure::{FigureModelCache, FigureState},
|
||||||
},
|
},
|
||||||
anim::{
|
|
||||||
Skeleton,
|
|
||||||
Animation,
|
|
||||||
character::{
|
|
||||||
CharacterSkeleton,
|
|
||||||
IdleAnimation,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
use client::Client;
|
||||||
|
use common::{comp::Character, figure::Segment};
|
||||||
|
use vek::*;
|
||||||
|
|
||||||
struct Skybox {
|
struct Skybox {
|
||||||
model: Model<SkyboxPipeline>,
|
model: Model<SkyboxPipeline>,
|
||||||
@ -76,7 +60,9 @@ impl Scene {
|
|||||||
figure_model_cache: FigureModelCache::new(),
|
figure_model_cache: FigureModelCache::new(),
|
||||||
figure_state: FigureState::new(renderer, CharacterSkeleton::new()),
|
figure_state: FigureState::new(renderer, CharacterSkeleton::new()),
|
||||||
|
|
||||||
backdrop_model: renderer.create_model(&FigureModelCache::load_mesh("knight.vox", Vec3::zero())).unwrap(),
|
backdrop_model: renderer
|
||||||
|
.create_model(&FigureModelCache::load_mesh("knight.vox", Vec3::zero()))
|
||||||
|
.unwrap(),
|
||||||
backdrop_state: FigureState::new(renderer, CharacterSkeleton::new()),
|
backdrop_state: FigureState::new(renderer, CharacterSkeleton::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,11 +71,8 @@ impl Scene {
|
|||||||
self.camera.set_focus_pos(Vec3::unit_z() * 1.75);
|
self.camera.set_focus_pos(Vec3::unit_z() * 1.75);
|
||||||
self.camera.update(client.state().get_time());
|
self.camera.update(client.state().get_time());
|
||||||
self.camera.set_distance(4.0);
|
self.camera.set_distance(4.0);
|
||||||
self.camera.set_orientation(Vec3::new(
|
self.camera
|
||||||
client.state().get_time() as f32 * 0.2,
|
.set_orientation(Vec3::new(client.state().get_time() as f32 * 0.2, 0.3, 0.0));
|
||||||
0.3,
|
|
||||||
0.0,
|
|
||||||
));
|
|
||||||
|
|
||||||
let (view_mat, proj_mat, cam_pos) = self.camera.compute_dependents(client);
|
let (view_mat, proj_mat, cam_pos) = self.camera.compute_dependents(client);
|
||||||
|
|
||||||
@ -116,7 +99,8 @@ impl Scene {
|
|||||||
);
|
);
|
||||||
self.figure_state.skeleton_mut().interpolate(&tgt_skeleton);
|
self.figure_state.skeleton_mut().interpolate(&tgt_skeleton);
|
||||||
|
|
||||||
self.figure_state.update(renderer, Vec3::zero(), -Vec3::unit_y());
|
self.figure_state
|
||||||
|
.update(renderer, Vec3::zero(), -Vec3::unit_y());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&mut self, renderer: &mut Renderer, client: &Client) {
|
pub fn render(&mut self, renderer: &mut Renderer, client: &Client) {
|
||||||
|
@ -246,7 +246,8 @@ impl FigureMgr {
|
|||||||
state.update(renderer, pos.0, dir.0);
|
state.update(renderer, pos.0, dir.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.states.retain(|entity, _| ecs.entities().is_alive(*entity));
|
self.states
|
||||||
|
.retain(|entity, _| ecs.entities().is_alive(*entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(
|
pub fn render(
|
||||||
@ -261,7 +262,9 @@ impl FigureMgr {
|
|||||||
for (entity, &character) in (&ecs.entities(), &ecs.read_storage::<comp::Character>()).join()
|
for (entity, &character) in (&ecs.entities(), &ecs.read_storage::<comp::Character>()).join()
|
||||||
{
|
{
|
||||||
if let Some(state) = self.states.get(&entity) {
|
if let Some(state) = self.states.get(&entity) {
|
||||||
let model = self.model_cache.get_or_create_model(renderer, character, tick);
|
let model = self
|
||||||
|
.model_cache
|
||||||
|
.get_or_create_model(renderer, character, tick);
|
||||||
renderer.render_figure(model, globals, &state.locals(), state.bone_consts());
|
renderer.render_figure(model, globals, &state.locals(), state.bone_consts());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,7 @@ pub mod camera;
|
|||||||
pub mod figure;
|
pub mod figure;
|
||||||
pub mod terrain;
|
pub mod terrain;
|
||||||
|
|
||||||
use dot_vox;
|
use self::{camera::Camera, figure::FigureMgr, terrain::Terrain};
|
||||||
use vek::*;
|
|
||||||
use common::{comp, figure::Segment};
|
|
||||||
use client::Client;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
anim::{
|
anim::{
|
||||||
character::{CharacterSkeleton, RunAnimation},
|
character::{CharacterSkeleton, RunAnimation},
|
||||||
@ -18,7 +15,10 @@ use crate::{
|
|||||||
},
|
},
|
||||||
window::Event,
|
window::Event,
|
||||||
};
|
};
|
||||||
use self::{camera::Camera, figure::FigureMgr, terrain::Terrain};
|
use client::Client;
|
||||||
|
use common::{comp, figure::Segment};
|
||||||
|
use dot_vox;
|
||||||
|
use vek::*;
|
||||||
|
|
||||||
// TODO: Don't hard-code this
|
// TODO: Don't hard-code this
|
||||||
const CURSOR_PAN_SCALE: f32 = 0.005;
|
const CURSOR_PAN_SCALE: f32 = 0.005;
|
||||||
|
Loading…
Reference in New Issue
Block a user