Former-commit-id: 4fd53e02969d9d044367d81640a2975043c6953a
This commit is contained in:
Joshua Barretto 2019-05-12 22:34:20 +01:00
parent 761c6e9cf8
commit 216819ca92
7 changed files with 58 additions and 51 deletions

View File

@ -137,10 +137,7 @@ pub enum Body {
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Actor {
Character {
name: String,
body: Body,
},
Character { name: String, body: Body },
}
impl Component for Actor {

View File

@ -1,13 +1,13 @@
pub mod agent;
pub mod actor;
pub mod agent;
pub mod phys;
pub mod player;
// Reexports
pub use agent::{Agent, Control};
pub use actor::Actor;
pub use actor::Animation;
pub use actor::AnimationHistory;
pub use actor::HumanoidBody;
pub use actor::Body;
pub use actor::Actor;
pub use actor::HumanoidBody;
pub use agent::{Agent, Control};
pub use player::Player;

View File

@ -191,14 +191,25 @@ fn handle_pet(server: &mut Server, entity: EcsEntity, args: String, action: &Cha
.read_component_cloned::<comp::phys::Pos>(entity)
{
Some(pos) => {
server.create_npc("Bungo".to_owned(), comp::Body::Humanoid(comp::HumanoidBody::random()))
server
.create_npc(
"Bungo".to_owned(),
comp::Body::Humanoid(comp::HumanoidBody::random()),
)
.with(comp::Control::default())
.with(comp::Agent::Pet{ target: entity, offset: Vec2::zero() })
.with(comp::Agent::Pet {
target: entity,
offset: Vec2::zero(),
})
.with(pos)
.build();
server.clients.notify(entity, ServerMsg::Chat("Spawned pet!".to_owned()));
},
None => server.clients.notify(entity, ServerMsg::Chat("You have no position!".to_owned())),
server
.clients
.notify(entity, ServerMsg::Chat("Spawned pet!".to_owned()));
}
None => server
.clients
.notify(entity, ServerMsg::Chat("You have no position!".to_owned())),
}
}

View File

@ -80,10 +80,13 @@ impl Server {
};
for i in 0..4 {
this.create_npc("Tobermory".to_owned(), comp::Body::Humanoid(comp::HumanoidBody::random()))
.with(comp::Control::default())
.with(comp::Agent::Wanderer(Vec2::zero()))
.build();
this.create_npc(
"Tobermory".to_owned(),
comp::Body::Humanoid(comp::HumanoidBody::random()),
)
.with(comp::Control::default())
.with(comp::Agent::Wanderer(Vec2::zero()))
.build();
}
Ok(this)
@ -121,10 +124,7 @@ impl Server {
.with(comp::phys::Vel(Vec3::zero()))
.with(comp::phys::Dir(Vec3::unit_y()))
.with(comp::AnimationHistory::new(comp::Animation::Idle))
.with(comp::Actor::Character {
name,
body,
})
.with(comp::Actor::Character { name, body })
}
pub fn create_player_character(
@ -134,10 +134,13 @@ impl Server {
name: String,
body: comp::HumanoidBody,
) {
state.write_component(entity, comp::Actor::Character {
name,
body: comp::Body::Humanoid(body),
});
state.write_component(
entity,
comp::Actor::Character {
name,
body: comp::Body::Humanoid(body),
},
);
state.write_component(entity, comp::phys::Pos(Vec3::new(0.0, 0.0, 64.0)));
state.write_component(entity, comp::phys::Vel(Vec3::zero()));
state.write_component(entity, comp::phys::Dir(Vec3::unit_y()));
@ -145,10 +148,7 @@ impl Server {
state.write_component(entity, comp::phys::ForceUpdate);
// Set initial animation
state.write_component(
entity,
comp::AnimationHistory::new(comp::Animation::Idle),
);
state.write_component(entity, comp::AnimationHistory::new(comp::Animation::Idle));
// Tell the client his request was successful
client.notify(ServerMsg::StateAnswer(Ok(ClientState::Character)));

View File

@ -1,9 +1,3 @@
use vek::*;
use client::Client;
use common::{
comp::HumanoidBody,
figure::Segment,
};
use crate::{
anim::{
character::{CharacterSkeleton, IdleAnimation},
@ -18,6 +12,9 @@ use crate::{
figure::{FigureModelCache, FigureState},
},
};
use client::Client;
use common::{comp::HumanoidBody, figure::Segment};
use vek::*;
struct Skybox {
model: Model<SkyboxPipeline>,

View File

@ -8,10 +8,8 @@ use crate::{
window::Window,
};
use common::comp::{
actor::{Belt, BodyType, Chest, Foot, Hand, Head, Pants, Race, Weapon},
HumanoidBody,
actor::{
Belt, Chest, Foot, BodyType, Hand, Head, Pants, Race, Weapon,
},
};
use conrod_core::{
color,

View File

@ -14,9 +14,8 @@ use common::{
assets,
comp::{
self,
Body,
HumanoidBody,
actor::{Belt, Chest, Foot, Hand, Head, Pants, Weapon},
Body, HumanoidBody,
},
figure::Segment,
msg,
@ -252,10 +251,9 @@ impl FigureMgr {
match actor {
comp::Actor::Character { body, .. } => match body {
Body::Humanoid(body) => {
let state = self
.states
.entry(entity)
.or_insert_with(|| FigureState::new(renderer, CharacterSkeleton::new()));
let state = self.states.entry(entity).or_insert_with(|| {
FigureState::new(renderer, CharacterSkeleton::new())
});
let target_skeleton = match animation_history.current {
comp::Animation::Idle => IdleAnimation::update_skeleton(
@ -278,7 +276,7 @@ impl FigureMgr {
state.skeleton.interpolate(&target_skeleton);
state.update(renderer, pos.0, dir.0);
},
}
// TODO: Non-humanoid bodies
},
// TODO: Non-character actors
@ -298,14 +296,20 @@ impl FigureMgr {
let tick = client.get_tick();
let ecs = client.state().ecs();
for (entity, actor) in (&ecs.entities(), &ecs.read_storage::<comp::Actor>()).join()
{
for (entity, actor) in (&ecs.entities(), &ecs.read_storage::<comp::Actor>()).join() {
match actor {
comp::Actor::Character { body, .. } => match body {
Body::Humanoid(body) => if let Some(state) = self.states.get(&entity) {
let model = self.model_cache.get_or_create_model(renderer, *body, tick);
renderer.render_figure(model, globals, &state.locals(), state.bone_consts());
},
Body::Humanoid(body) => {
if let Some(state) = self.states.get(&entity) {
let model = self.model_cache.get_or_create_model(renderer, *body, tick);
renderer.render_figure(
model,
globals,
&state.locals(),
state.bone_consts(),
);
}
}
// TODO: Non-humanoid bodies
},
// TODO: Non-character actors