Skip to content

Commit 0dca475

Browse files
fix(hyperion): general arrow heading (#671)
still need to fix initial yaw/pitch
1 parent 37ad0fd commit 0dca475

File tree

23 files changed

+292
-111
lines changed

23 files changed

+292
-111
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,30 @@ incremental = true
1515
[workspace]
1616
members = [
1717
'crates/bvh-region',
18+
'crates/geometry',
1819
'crates/hyperion',
20+
'crates/hyperion-clap',
21+
'crates/hyperion-command',
1922
'crates/hyperion-crafting',
2023
'crates/hyperion-event-macros',
24+
'crates/hyperion-gui',
2125
'crates/hyperion-inventory',
26+
'crates/hyperion-item',
2227
'crates/hyperion-minecraft-proto',
2328
'crates/hyperion-nerd-font',
2429
'crates/hyperion-palette',
30+
'crates/hyperion-permission',
2531
'crates/hyperion-proto',
2632
'crates/hyperion-proxy',
33+
'crates/hyperion-rank-tree',
2734
'crates/hyperion-scheduled',
2835
'crates/hyperion-stats',
2936
'crates/hyperion-text',
3037
'crates/hyperion-utils',
31-
'events/tag',
32-
'crates/hyperion-permission',
33-
'crates/hyperion-clap',
34-
'crates/hyperion-command',
35-
'crates/hyperion-rank-tree',
36-
'crates/hyperion-item',
37-
'crates/geometry',
3838
'crates/simd-utils',
39-
'crates/system-order',
4039
'crates/spatial',
40+
'crates/system-order',
41+
'events/tag',
4142
]
4243
resolver = '2'
4344

@@ -121,6 +122,9 @@ version = '1.0.0-beta.7'
121122
[workspace.dependencies.divan]
122123
git = 'https://github.com/nvzqz/divan'
123124

125+
[workspace.dependencies.hyperion-gui]
126+
path = 'crates/hyperion-gui'
127+
124128
[workspace.dependencies.flate2]
125129
default-features = false
126130
version = '1.0.30'

crates/hyperion-clap/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub trait MinecraftCommand: Parser + CommandPermission {
7777

7878
let mut bundle = DataBundle::new(compose, system);
7979
bundle.add_packet(&chat).unwrap();
80-
bundle.send(*stream).unwrap();
80+
bundle.unicast(*stream).unwrap();
8181

8282
false
8383
}

crates/hyperion-proto/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[dependencies]
44
rkyv = {workspace = true}
5+
glam = {workspace = true}
56

67
[lints]
78
workspace = true

crates/hyperion-proto/src/shared.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use glam::I16Vec2;
12
use rkyv::{Archive, Deserialize, Serialize};
23

34
#[derive(Archive, Deserialize, Serialize, Clone, Copy, PartialEq, Debug)]
@@ -13,3 +14,12 @@ impl ChunkPosition {
1314
Self { x, z }
1415
}
1516
}
17+
18+
impl From<I16Vec2> for ChunkPosition {
19+
fn from(value: I16Vec2) -> Self {
20+
Self {
21+
x: value.x,
22+
z: value.y,
23+
}
24+
}
25+
}

crates/hyperion/src/common/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use tracing::{info, instrument, warn};
1111
pub struct Config {
1212
pub border_diameter: Option<f64>,
1313
pub max_players: i32,
14-
pub view_distance: i32,
14+
pub view_distance: i16,
1515
pub simulation_distance: i32,
1616
pub server_desc: String,
1717
pub spawn: Spawn,

crates/hyperion/src/egress/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ impl Module for EgressModule {
118118
stream.push(io.inner());
119119

120120
let position = hyperion_proto::ChunkPosition {
121-
x: i16::try_from(pos.position.x).unwrap(),
122-
z: i16::try_from(pos.position.y).unwrap(),
121+
x: pos.position.x,
122+
z: pos.position.y,
123123
};
124124

125125
positions.push(position);

crates/hyperion/src/egress/player_join/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn player_join_world(
9494
dimension_names: Cow::Owned(dimension_names),
9595
registry_codec: Cow::Borrowed(registry_codec),
9696
max_players: config.max_players.into(),
97-
view_distance: config.view_distance.into(), // max view distance
97+
view_distance: VarInt(i32::from(config.view_distance)),
9898
simulation_distance: config.simulation_distance.into(),
9999
reduced_debug_info: false,
100100
enable_respawn_screen: false,
@@ -116,8 +116,8 @@ pub fn player_join_world(
116116
let center_chunk = position.to_chunk();
117117

118118
let pkt = play::ChunkRenderDistanceCenterS2c {
119-
chunk_x: center_chunk.x.into(),
120-
chunk_z: center_chunk.y.into(),
119+
chunk_x: VarInt(i32::from(center_chunk.x)),
120+
chunk_z: VarInt(i32::from(center_chunk.y)),
121121
};
122122

123123
bundle.add_packet(&pkt)?;
@@ -362,7 +362,7 @@ pub fn player_join_world(
362362

363363
bundle.add_packet(&command_packet)?;
364364

365-
bundle.send(io)?;
365+
bundle.unicast(io)?;
366366

367367
info!("{name} joined the world");
368368

crates/hyperion/src/egress/sync_chunks.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ use std::cmp::Ordering;
22

33
use derive_more::derive::{Deref, DerefMut};
44
use flecs_ecs::prelude::*;
5-
use glam::IVec2;
5+
use glam::I16Vec2;
6+
use itertools::Itertools;
67
use tracing::error;
78
use valence_protocol::{
8-
ChunkPos,
9+
ChunkPos, VarInt,
910
packets::play::{self},
1011
};
1112

@@ -20,7 +21,7 @@ use crate::{
2021

2122
#[derive(Component, Deref, DerefMut, Default)]
2223
pub struct ChunkSendQueue {
23-
changes: Vec<IVec2>,
24+
changes: Vec<I16Vec2>,
2425
}
2526

2627
#[derive(Component)]
@@ -59,8 +60,8 @@ impl Module for SyncChunksModule {
5960

6061
// center chunk
6162
let center_chunk = play::ChunkRenderDistanceCenterS2c {
62-
chunk_x: current_chunk.x.into(),
63-
chunk_z: current_chunk.y.into(),
63+
chunk_x: VarInt(i32::from(current_chunk.x)),
64+
chunk_z: VarInt(i32::from(current_chunk.y)),
6465
};
6566

6667
if let Err(e) = compose.unicast(&center_chunk, stream_id, system) {
@@ -91,15 +92,14 @@ impl Module for SyncChunksModule {
9192

9293
let removed_chunks = last_sent_range_x
9394
.clone()
94-
.flat_map(|x| last_sent_range_z.clone().map(move |z| IVec2::new(x, z)))
95-
.filter(|pos| {
96-
!current_range_x.contains(&pos.x) || !current_range_z.contains(&pos.y)
97-
});
95+
.cartesian_product(last_sent_range_z.clone())
96+
.filter(|(x, y)| !current_range_x.contains(x) || !current_range_z.contains(y))
97+
.map(|(x, y)| I16Vec2::new(x, y));
9898

9999
let mut bundle = DataBundle::new(compose, system);
100100

101101
for chunk in removed_chunks {
102-
let pos = ChunkPos::new(chunk.x, chunk.y);
102+
let pos = ChunkPos::new(i32::from(chunk.x), i32::from(chunk.y));
103103
let unload_chunk = play::UnloadChunkS2c { pos };
104104

105105
bundle.add_packet(&unload_chunk).unwrap();
@@ -111,13 +111,14 @@ impl Module for SyncChunksModule {
111111
// }
112112
}
113113

114-
bundle.send(stream_id).unwrap();
114+
bundle.unicast(stream_id).unwrap();
115115

116116
let added_chunks = current_range_x
117-
.flat_map(move |x| current_range_z.clone().map(move |z| IVec2::new(x, z)))
118-
.filter(|pos| {
119-
!last_sent_range_x.contains(&pos.x) || !last_sent_range_z.contains(&pos.y)
120-
});
117+
.cartesian_product(current_range_z)
118+
.filter(|(x, y)| {
119+
!last_sent_range_x.contains(x) || !last_sent_range_z.contains(y)
120+
})
121+
.map(|(x, y)| I16Vec2::new(x, y));
121122

122123
let mut num_chunks_added = 0;
123124

@@ -222,7 +223,7 @@ impl Module for SyncChunksModule {
222223
idx -= 1;
223224
}
224225

225-
bundle.send(stream_id).unwrap();
226+
bundle.unicast(stream_id).unwrap();
226227
},
227228
);
228229
}

0 commit comments

Comments
 (0)