1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

physics (ticking) works

This commit is contained in:
mat 2023-01-15 22:53:29 -06:00
parent 89cee81276
commit 3dc910f079
6 changed files with 30 additions and 18 deletions

19
Cargo.lock generated
View file

@ -73,7 +73,7 @@ version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833"
dependencies = [
"concurrent-queue 2.0.0",
"concurrent-queue 2.1.0",
"event-listener",
"futures-core",
]
@ -99,7 +99,7 @@ checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b"
dependencies = [
"async-lock",
"async-task",
"concurrent-queue 2.0.0",
"concurrent-queue 2.1.0",
"fastrand",
"futures-lite",
"slab",
@ -283,6 +283,7 @@ dependencies = [
"azalea-world",
"bevy_app",
"bevy_ecs",
"bevy_time",
"derive_more",
"env_logger",
"futures",
@ -783,9 +784,9 @@ dependencies = [
[[package]]
name = "concurrent-queue"
version = "2.0.0"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b"
checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e"
dependencies = [
"crossbeam-utils",
]
@ -2323,9 +2324,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.22.0"
version = "1.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3"
checksum = "38a54aca0c15d014013256222ba0ebed095673f89345dd79119d912eb561b7a8"
dependencies = [
"autocfg",
"bytes",
@ -2338,7 +2339,7 @@ dependencies = [
"signal-hook-registry",
"socket2",
"tokio-macros",
"winapi",
"windows-sys 0.42.0",
]
[[package]]
@ -2378,9 +2379,9 @@ dependencies = [
[[package]]
name = "toml"
version = "0.5.9"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f"
dependencies = [
"serde",
]

View file

@ -22,6 +22,7 @@ azalea-registry = {path = "../azalea-registry", version = "0.5.0"}
azalea-world = {path = "../azalea-world", version = "0.5.0"}
bevy_app = {version = "0.9.1", default-features = false}
bevy_ecs = {version = "0.9.1", default-features = false}
bevy_time = "0.9.1"
derive_more = {version = "0.99.17", features = ["deref", "deref_mut"]}
futures = "0.3.25"
iyes_loopless = "0.9.1"

View file

@ -6,10 +6,11 @@ use crate::{
movement::{local_player_ai_step, send_position, sprint_listener, walk_listener},
packet_handling::{self, PacketHandlerPlugin},
plugins::PluginStates,
Account, PlayerInfo,
Account, PlayerInfo, StartSprintEvent, StartWalkEvent,
};
use azalea_auth::{game_profile::GameProfile, sessionserver::SessionServerError};
use azalea_physics::PhysicsPlugin;
use azalea_protocol::{
connect::{Connection, ConnectionError},
packets::{
@ -39,6 +40,7 @@ use bevy_ecs::{
query::WorldQuery,
schedule::{IntoSystemDescriptor, Schedule, Stage, SystemSet},
};
use bevy_time::TimePlugin;
use iyes_loopless::prelude::*;
use log::{debug, error};
use parking_lot::{Mutex, RwLock};
@ -496,6 +498,10 @@ pub fn start_ecs(
// you might be able to just drop the lock or put it in its own scope to fix
let mut app = App::new();
app.add_event::<StartWalkEvent>()
.add_event::<StartSprintEvent>();
app.add_fixed_timestep(Duration::from_millis(50), "tick");
app.add_fixed_timestep_system_set(
"tick",
@ -517,6 +523,8 @@ pub fn start_ecs(
app.add_system(death_event.after("tick").after("packet"));
app.add_plugin(PacketHandlerPlugin);
app.add_plugin(EntityPlugin);
app.add_plugin(PhysicsPlugin);
app.add_plugin(TimePlugin); // from bevy_time
app.init_resource::<WorldContainer>();

View file

@ -128,7 +128,6 @@ pub fn update_in_loaded_chunk(
mut commands: bevy_ecs::system::Commands,
query: Query<(Entity, &LocalPlayer, &entity::Position)>,
) {
println!("update_in_loaded_chunk");
for (entity, local_player, position) in &query {
let player_chunk_pos = ChunkPos::from(position);
let in_loaded_chunk = local_player

View file

@ -253,7 +253,6 @@ pub fn local_player_ai_step(
With<LocalPlayerInLoadedChunk>,
>,
) {
println!("local_player_ai_step");
for (
local_player,
mut physics_state,

View file

@ -9,11 +9,12 @@ use azalea_world::{
metadata::Sprinting, move_relative, Attributes, Entity, Jumping, Physics, Position,
WorldName,
},
World, WorldContainer,
Local, World, WorldContainer,
};
use bevy_app::Plugin;
use bevy_ecs::{
event::{EventReader, EventWriter},
query::With,
schedule::IntoSystemDescriptor,
system::Res,
};
@ -119,7 +120,8 @@ fn travel(
/// stuff.
pub fn ai_step(
mut query: Query<
(Entity, &mut Physics, &Jumping),
(Entity, &mut Physics, Option<&Jumping>),
With<Local>,
// TODO: ai_step should only run for players in loaded chunks
// With<LocalPlayerInLoadedChunk> maybe there should be an InLoadedChunk/InUnloadedChunk
// component?
@ -140,11 +142,13 @@ pub fn ai_step(
physics.delta.z = 0.;
}
if **jumping {
// TODO: jumping in liquids and jump delay
if let Some(jumping) = jumping {
if **jumping {
// TODO: jumping in liquids and jump delay
if physics.on_ground {
force_jump_events.send(ForceJumpEvent(entity));
if physics.on_ground {
force_jump_events.send(ForceJumpEvent(entity));
}
}
}