mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Better formatting
Former-commit-id: 22b83b6dd5ad145a39b236436a019c6b172787d7
This commit is contained in:
parent
3697c47e33
commit
15d1a789d6
@ -5,7 +5,7 @@ use vek::*;
|
||||
pub enum InputEvent {
|
||||
Jump,
|
||||
Attack,
|
||||
Respawn,
|
||||
RequestRespawn,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use specs::{Component, NullStorage, FlaggedStorage, VecStorage};
|
||||
use specs::{Component, FlaggedStorage, NullStorage, VecStorage};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Player {
|
||||
@ -19,7 +19,6 @@ impl Component for Player {
|
||||
type Storage = FlaggedStorage<Self, VecStorage<Self>>;
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
pub struct Respawn;
|
||||
impl Component for Respawn {
|
||||
|
@ -6,7 +6,7 @@ use vek::*;
|
||||
use crate::{
|
||||
comp::{
|
||||
phys::{Dir, ForceUpdate, Pos, Vel},
|
||||
Actions, Animation, AnimationInfo, Respawn, InputEvent, Inputs, Stats,
|
||||
Actions, Animation, AnimationInfo, InputEvent, Inputs, Respawn, Stats,
|
||||
},
|
||||
state::{DeltaTime, Time},
|
||||
terrain::TerrainMap,
|
||||
@ -135,18 +135,17 @@ impl<'a> System<'a> for Sys {
|
||||
},
|
||||
);
|
||||
}
|
||||
for (entity, inputs) in (
|
||||
&entities,
|
||||
&mut inputs,
|
||||
)
|
||||
.join()
|
||||
{
|
||||
for (entity, inputs) in (&entities, &mut inputs).join() {
|
||||
// Handle event-based inputs
|
||||
for event in inputs.events.drain(..) {
|
||||
match event {
|
||||
InputEvent::Attack => {
|
||||
// Attack delay
|
||||
if let (Some(pos), Some(dir), Some(action)) = (positions.get(entity), directions.get(entity), actions.get_mut(entity)) {
|
||||
if let (Some(pos), Some(dir), Some(action)) = (
|
||||
positions.get(entity),
|
||||
directions.get(entity),
|
||||
actions.get_mut(entity),
|
||||
) {
|
||||
for (b, pos_b, mut stat_b, mut vel_b) in
|
||||
(&entities, &positions, &mut stats, &mut velocities).join()
|
||||
{
|
||||
@ -163,7 +162,7 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
}
|
||||
}
|
||||
InputEvent::Respawn => {
|
||||
InputEvent::RequestRespawn => {
|
||||
respawns.insert(entity, Respawn);
|
||||
}
|
||||
InputEvent::Jump => {}
|
||||
|
@ -207,7 +207,7 @@ impl Server {
|
||||
)
|
||||
.join()
|
||||
.map(|(entity, _)| entity)
|
||||
.collect::<Vec<EcsEntity>>();
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for entity in todo_kill {
|
||||
self.state
|
||||
@ -237,7 +237,10 @@ impl Server {
|
||||
for entity in todo_respawn {
|
||||
if let Some(client) = self.clients.get_mut(&entity) {
|
||||
client.allow_state(ClientState::Character);
|
||||
self.state.ecs_mut().write_storage::<comp::Respawn>().remove(entity);
|
||||
self.state
|
||||
.ecs_mut()
|
||||
.write_storage::<comp::Respawn>()
|
||||
.remove(entity);
|
||||
self.state.write_component(entity, comp::Stats::default());
|
||||
self.state.write_component(entity, comp::Actions::default());
|
||||
self.state
|
||||
@ -245,7 +248,8 @@ impl Server {
|
||||
.write_storage::<comp::phys::Pos>()
|
||||
.get_mut(entity)
|
||||
.map(|pos| pos.0.z += 100.0);
|
||||
self.state.write_component(entity, comp::phys::Vel(Vec3::zero()));
|
||||
self.state
|
||||
.write_component(entity, comp::phys::Vel(Vec3::zero()));
|
||||
self.state.write_component(entity, comp::phys::ForceUpdate);
|
||||
}
|
||||
}
|
||||
@ -641,7 +645,6 @@ impl Server {
|
||||
.ecs_mut()
|
||||
.write_storage::<comp::phys::ForceUpdate>()
|
||||
.clear();
|
||||
|
||||
}
|
||||
|
||||
pub fn generate_chunk(&mut self, key: Vec2<i32>) {
|
||||
|
@ -12,7 +12,6 @@ use crate::{
|
||||
};
|
||||
use client::Client;
|
||||
use common::{
|
||||
msg::ClientState,
|
||||
assets,
|
||||
comp::{
|
||||
self,
|
||||
@ -24,6 +23,7 @@ use common::{
|
||||
},
|
||||
figure::Segment,
|
||||
msg,
|
||||
msg::ClientState,
|
||||
};
|
||||
use dot_vox::DotVoxData;
|
||||
use specs::{Component, Entity as EcsEntity, Join, VecStorage};
|
||||
@ -458,26 +458,28 @@ impl FigureMgr {
|
||||
let tick = client.get_tick();
|
||||
let ecs = client.state().ecs();
|
||||
|
||||
for (entity, actor, _) in (&ecs.entities(), &ecs.read_storage::<comp::Actor>(), &ecs.read_storage::<comp::Actions>()).join() {
|
||||
// Check if player is alive
|
||||
|
||||
{
|
||||
match actor {
|
||||
comp::Actor::Character { body, .. } => {
|
||||
if let Some((locals, bone_consts)) = match body {
|
||||
Body::Humanoid(_) => self
|
||||
.character_states
|
||||
.get(&entity)
|
||||
.map(|state| (state.locals(), state.bone_consts())),
|
||||
Body::Quadruped(_) => self
|
||||
.quadruped_states
|
||||
.get(&entity)
|
||||
.map(|state| (state.locals(), state.bone_consts())),
|
||||
} {
|
||||
let model = self.model_cache.get_or_create_model(renderer, *body, tick);
|
||||
for (entity, actor, _) in (
|
||||
&ecs.entities(),
|
||||
&ecs.read_storage::<comp::Actor>(),
|
||||
&ecs.read_storage::<comp::Actions>(),
|
||||
)
|
||||
.join()
|
||||
{
|
||||
match actor {
|
||||
comp::Actor::Character { body, .. } => {
|
||||
if let Some((locals, bone_consts)) = match body {
|
||||
Body::Humanoid(_) => self
|
||||
.character_states
|
||||
.get(&entity)
|
||||
.map(|state| (state.locals(), state.bone_consts())),
|
||||
Body::Quadruped(_) => self
|
||||
.quadruped_states
|
||||
.get(&entity)
|
||||
.map(|state| (state.locals(), state.bone_consts())),
|
||||
} {
|
||||
let model = self.model_cache.get_or_create_model(renderer, *body, tick);
|
||||
|
||||
renderer.render_figure(model, globals, locals, bone_consts);
|
||||
}
|
||||
renderer.render_figure(model, globals, locals, bone_consts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,20 +117,11 @@ impl PlayState for SessionState {
|
||||
let mut clock = Clock::new();
|
||||
self.client.borrow_mut().reset_terrain();
|
||||
|
||||
// Load a few chunks. TODO: Remove this.
|
||||
/*
|
||||
for x in -6..7 {
|
||||
for y in -6..7 {
|
||||
for z in -1..2 {
|
||||
self.client.borrow_mut().load_chunk(Vec3::new(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Game loop
|
||||
let mut current_client_state = self.client.borrow().get_client_state();
|
||||
while let ClientState::Pending | ClientState::Character | ClientState::Dead = current_client_state {
|
||||
while let ClientState::Pending | ClientState::Character | ClientState::Dead =
|
||||
current_client_state
|
||||
{
|
||||
let alive = self.client.borrow().get_client_state() == ClientState::Character;
|
||||
|
||||
// Handle window events.
|
||||
@ -150,10 +141,10 @@ impl PlayState for SessionState {
|
||||
self.input_events.push(comp::InputEvent::Attack);
|
||||
}
|
||||
false => {
|
||||
self.input_events.push(comp::InputEvent::Respawn);
|
||||
self.input_events.push(comp::InputEvent::RequestRespawn);
|
||||
}
|
||||
_ => unreachable!()
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
// Movement key pressed
|
||||
Event::KeyDown(Key::MoveForward) if alive => self.key_state.up = true,
|
||||
Event::KeyDown(Key::MoveBack) if alive => self.key_state.down = true,
|
||||
|
Loading…
Reference in New Issue
Block a user