Skip to content

Commit 6252237

Browse files
authored
feat: add LAN network games. (#737)
Work-in-progress, but pushing my code anyway.
1 parent 15081c4 commit 6252237

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2424
-1103
lines changed

Cargo.lock

+721-33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+24-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ version = "0.6.1"
1111
members = [".", "core"]
1212

1313
[features]
14-
default = ["render"]
15-
render = ["bevy/x11", "bevy/png", "bevy/filesystem_watcher", "bevy/bevy_gilrs"]
14+
default = []
15+
# Enable to simulate horrible network latency/slowness
16+
debug-network-slowdown = ["async-timer", "turborand"]
1617

1718
[dependencies]
1819
anyhow = "1.0.58"
@@ -55,6 +56,13 @@ unic-langid = "0.9.0"
5556
puffin_egui = "0.19.0"
5657
puffin = "0.14.3"
5758
peg = "0.8.0"
59+
downcast-rs = "1.2.0"
60+
async-timer = { version = "0.2.10", optional = true }
61+
62+
[dependencies.turborand]
63+
features = ["atomic"]
64+
version = "0.9"
65+
optional = true
5866

5967
[dependencies.bevy]
6068
default-features = false
@@ -68,6 +76,19 @@ web-sys = { version = "0.3", features = ["Window", "Location", "Storage"] }
6876
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
6977
bevy_dylib = "0.9.1"
7078
mimalloc = { version = "0.1.32", default-features = false }
79+
# Networking deps
80+
ggrs = { version = "0.9.3", features = ["sync-send"] }
81+
bitfield = "0.14.0"
82+
numquant = "0.2.0"
83+
mdns-sd = { version = "0.7.1", default-features = false }
84+
quinn = { version = "0.9.3", default-features = false }
85+
quinn_runtime_bevy = "0.1.0"
86+
smallvec = "1.10.0"
87+
rcgen = "0.10.0"
88+
rustls = { version = "0.20.7", features = ["dangerous_configuration", "quic"] }
89+
postcard = { version = "1.0.4", features = ["alloc"] }
90+
bytes = "1.4.0"
91+
ping-rs = "0.1.2"
7192

7293
# Optimize dependencies even in development
7394
[profile.dev.package."*"]
@@ -94,7 +115,7 @@ codegen-units = 1 # Improved rapier physics perf, so it might help other stuf
94115
lto = true
95116

96117
[patch.crates-io]
97-
bevy_simple_tilemap = { git = "https://github.com/forbjok/bevy_simple_tilemap.git" }
118+
bevy_simple_tilemap = { git = "https://github.com/forbjok/bevy_simple_tilemap.git", rev = "963d447fa1fd2d6f89228106275b7086840be762" }
98119

99120
bones_lib = { git = "https://github.com/fishfolk/bones" }
100121
bones_bevy_asset = { git = "https://github.com/fishfolk/bones" }

assets/locales/en-US/en-US.ftl.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ resources:
44
- menu.ftl
55
- debug-tools.ftl
66

7-
- matchmaking.ftl
7+
- network-game.ftl
88
- settings.ftl
99
- editor.ftl
1010
- player-select.ftl
1111
- map-select.ftl
1212

13-
- controls.ftl
13+
- controls.ftl

assets/locales/en-US/menu.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Menu Pages
22
local-game = Local Game
3+
network-game = Network Game
4+
lan-game = LAN Game
35
online-game = Online Game
46
main-menu = Main Menu
57
map-editor = Map Editor
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
lan = LAN
2+
online = Online
3+
host = Host
4+
join = Join
5+
servers = Servers
6+
players = Players
7+
no-servers = No Servers
8+
server-name = Server Name
9+
start-server = Start Server
10+
stop-server = Stop Server
11+
fish-fight = Fish Fight
112
configure-match = Configure Match
213
player-count = Player Count
314
search-for-match = Search for Match
415
connecting = Connecting...
16+
joining = Joining...
517
connected-and-querying = Connected
618
waiting-for-players = Waiting for Players: { $current } / { $total }
719
match-ready = Match Ready!
8-
error = Error
20+
error = Error

core/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type_ulid = "0.1"
1111

1212
bytemuck = { version = "1.12.3", features = ["derive"] }
1313
csscolorparser = "0.6.2"
14-
glam = { version = "0.22.0", features = ["bytemuck"] }
14+
glam = { version = "0.22.0", features = ["bytemuck", "libm"] }
1515
hex = "0.4.3"
1616
humantime-serde = "1"
1717
nalgebra = { version = "0.32", features = ["convert-glam022"] }
@@ -21,6 +21,7 @@ rapier2d = { version = "0.17.1", features = ["enhanced-determinism", "deb
2121
serde = { version = "1.0.152", features = ["derive"] }
2222
tracing = "0.1.37"
2323
petgraph = { version = "0.6", features = ["graphmap"], default-features = false }
24+
indexmap = "1.9.3"
2425

2526
[dependencies.bevy]
2627
default-features = false

core/src/attachment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::prelude::*;
44

5-
pub fn install(session: &mut GameSession) {
5+
pub fn install(session: &mut CoreSession) {
66
session
77
.stages
88
.add_system_to_stage(CoreStage::Last, update_player_body_attachments)

core/src/bullet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
prelude::*,
44
};
55

6-
pub fn install(session: &mut GameSession) {
6+
pub fn install(session: &mut CoreSession) {
77
session
88
.stages
99
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/camera.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::prelude::*;
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::Last, camera_controller);

core/src/damage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::prelude::*;
44

5-
pub fn install(session: &mut GameSession) {
5+
pub fn install(session: &mut CoreSession) {
66
session
77
.stages
88
.add_system_to_stage(CoreStage::PostUpdate, kill_players_in_damage_region);

core/src/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::prelude::*;
22
use rapier2d::prelude as rapier;
33

4-
pub fn install(session: &mut GameSession) {
4+
pub fn install(session: &mut CoreSession) {
55
session
66
.stages
77
.add_system_to_stage(CoreStage::Last, debug_render_colliders)

core/src/editor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{map::z_depth_for_map_layer, prelude::*};
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::PreUpdate, handle_editor_input);

core/src/elements.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct DehydrateOutOfBounds(pub Entity);
3636
#[ulid = "01GP421CHN323T2614F19PA5E9"]
3737
pub struct ElementHandle(pub Handle<ElementMeta>);
3838

39-
pub fn install(session: &mut GameSession) {
39+
pub fn install(session: &mut CoreSession) {
4040
session
4141
.stages
4242
.add_system_to_stage(CoreStage::First, handle_out_of_bounds_items);

core/src/elements/crab.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{prelude::*, random::GlobalRng};
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/crate_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{physics::collisions::TileCollisionKind, prelude::*};
22

33
use std::time::Duration;
44

5-
pub fn install(session: &mut GameSession) {
5+
pub fn install(session: &mut CoreSession) {
66
session
77
.stages
88
.add_system_to_stage(CoreStage::PreUpdate, hydrate_crates)

core/src/elements/decoration.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::prelude::*;
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::First, hydrate);

core/src/elements/fish_school.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time::Duration;
22

33
use crate::{prelude::*, random::GlobalRng};
44

5-
pub fn install(session: &mut GameSession) {
5+
pub fn install(session: &mut CoreSession) {
66
session
77
.stages
88
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/grenade.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::prelude::*;
22
use std::time::Duration;
33

4-
pub fn install(session: &mut GameSession) {
4+
pub fn install(session: &mut CoreSession) {
55
session
66
.stages
77
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/kick_bomb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::prelude::*;
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/mine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::prelude::*;
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/musket.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time::Duration;
22

33
use crate::prelude::*;
44

5-
pub fn install(session: &mut GameSession) {
5+
pub fn install(session: &mut CoreSession) {
66
session
77
.stages
88
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/player_spawner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{prelude::*, MAX_PLAYERS};
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::First, hydrate)

core/src/elements/slippery.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::prelude::*;
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/slippery_seaweed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::prelude::*;
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/snail.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22

33
use crate::prelude::*;
44

5-
pub fn install(session: &mut GameSession) {
5+
pub fn install(session: &mut CoreSession) {
66
session
77
.stages
88
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/sproinger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::prelude::*;
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/stomp_boots.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::prelude::*;
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/sword.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{damage::DamageRegion, prelude::*};
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/elements/urchin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::prelude::*;
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::PreUpdate, hydrate)

core/src/input.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{prelude::*, MAX_PLAYERS};
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session.world.init_resource::<PlayerInputs>();
55
}
66

@@ -61,7 +61,7 @@ pub struct PlayerControl {
6161
}
6262

6363
/// The editor inputs that a player may make.
64-
#[derive(Clone, Debug)]
64+
#[derive(Clone, Debug, Serialize, Deserialize)]
6565
pub enum EditorInput {
6666
/// Spawn an element onto the map.
6767
SpawnElement {

core/src/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::prelude::*;
22

3-
pub fn install(session: &mut GameSession) {
3+
pub fn install(session: &mut CoreSession) {
44
session
55
.stages
66
.add_system_to_stage(CoreStage::Last, grab_items)

core/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub mod bevy_prelude {
1414
crate::{
1515
input::EditorInput,
1616
metadata::*,
17-
session::{GameSession, GameSessionInfo, GameSessionPlayerInfo},
17+
session::{CoreSession, CoreSessionInfo, GameSessionPlayerInfo},
1818
MAX_PLAYERS,
1919
},
2020
bones_lib::prelude as bones,
@@ -38,16 +38,15 @@ pub mod physics;
3838
pub mod player;
3939
pub mod random;
4040
pub mod session;
41-
pub mod testing;
4241
pub mod utils;
4342

4443
/// The target fixed frames-per-second that the game sumulation runs at.
4544
pub const FPS: f32 = 60.0;
4645
pub const MAX_PLAYERS: usize = 4;
4746

4847
/// Install game modules into the session.
49-
pub fn install_modules(session: &mut session::GameSession) {
50-
testing::install(session);
48+
pub fn install_modules(session: &mut session::CoreSession) {
49+
bones_lib::install(&mut session.stages);
5150
physics::install(session);
5251
input::install(session);
5352
map::install(session);

core/src/lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::time::Duration;
44

55
use crate::{prelude::*, FPS};
66

7-
pub fn install(session: &mut GameSession) {
7+
pub fn install(session: &mut CoreSession) {
88
session
99
.stages
1010
.add_system_to_stage(CoreStage::PostUpdate, lifetime_system)

core/src/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use ::bevy::utils::HashSet;
77

88
use crate::prelude::{collisions::TileCollisionKind, *};
99

10-
pub fn install(session: &mut GameSession) {
10+
pub fn install(session: &mut CoreSession) {
1111
session
1212
.stages
1313
.add_system_to_stage(CoreStage::First, spawn_map)

0 commit comments

Comments
 (0)