GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Skip sending chunks which failed to load - see #71 · feather-rs/feather@1da7838

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • server/src
    • chunk_logic.rs
    • entity
      • chunk.rs
    • player
      • movement.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎server/src/chunk_logic.rs‎

Copy file name to clipboardExpand all lines: server/src/chunk_logic.rs
+15-4Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,25 @@ pub struct ChunkLoadEvent {
3939
pub pos: ChunkPosition,
4040
}
4141

42+
/// Event which is triggered when a chunk fails to load.
43+
#[derive(Debug, Clone, Copy)]
44+
pub struct ChunkLoadFailEvent {
45+
pub pos: ChunkPosition,
46+
}
47+
4248
/// System for receiving loaded chunks from the chunk worker thread.
4349
pub struct ChunkLoadSystem;
4450

4551
impl<'a> System<'a> for ChunkLoadSystem {
4652
type SystemData = (
4753
Write<'a, ChunkMap>,
4854
Write<'a, EventChannel<ChunkLoadEvent>>,
55+
Write<'a, EventChannel<ChunkLoadFailEvent>>,
4956
Read<'a, ChunkWorkerHandle>,
5057
);
5158

5259
fn run(&mut self, data: Self::SystemData) {
53-
let (mut chunk_map, mut events, handle) = data;
60+
let (mut chunk_map, mut load_events, mut fail_events, handle) = data;
5461

5562
while let Ok((pos, result)) = handle.receiver.try_recv() {
5663
match result {
@@ -59,13 +66,15 @@ impl<'a> System<'a> for ChunkLoadSystem {
5966

6067
// Trigger event
6168
let event = ChunkLoadEvent { pos };
62-
events.single_write(event);
69+
load_events.single_write(event);
6370

6471
trace!("Loaded chunk at {:?}", pos);
6572
}
6673
Err(err) => {
6774
// TODO generate chunk if it didn't exist
6875
warn!("Failed to load chunk at {:?}: {}", pos, err);
76+
let event = ChunkLoadFailEvent { pos };
77+
fail_events.single_write(event);
6978
}
7079
}
7180
}
@@ -431,13 +440,15 @@ mod tests {
431440
let pos = ChunkPosition::new(0, 0);
432441
send2.send((pos, Ok(Chunk::new(pos)))).unwrap();
433442

434-
let event_channel = EventChannel::<ChunkLoadEvent>::new();
443+
let load_event_channel = EventChannel::<ChunkLoadEvent>::new();
444+
let fail_event_channel = EventChannel::<ChunkLoadFailEvent>::new();
435445

436446
let mut system = ChunkLoadSystem;
437447
let mut world = World::new();
438448
world.insert(chunk_map);
439449
world.insert(handle);
440-
world.insert(event_channel);
450+
world.insert(load_event_channel);
451+
world.insert(fail_event_channel);
441452

442453
system.run_now(&world);
443454

Collapse file

‎server/src/entity/chunk.rs‎

Copy file name to clipboardExpand all lines: server/src/entity/chunk.rs
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ impl ChunkEntities {
4343
/// May panic in some cases if the entity is not contained
4444
/// within the given chunk.
4545
pub fn remove_from_chunk(&mut self, chunk: ChunkPosition, entity: Entity) {
46-
let vec = self.0.get_mut(&chunk).unwrap();
47-
48-
let (index, _) = vec.iter().enumerate().find(|x| *x.1 == entity).unwrap();
46+
let vec = match self.0.get_mut(&chunk) {
47+
Some(vec) => vec,
48+
_ => return,
49+
};
50+
51+
let (index, _) = match vec.iter().enumerate().find(|x| *x.1 == entity) {
52+
Some(index) => index,
53+
None => return,
54+
};
4955
vec.swap_remove(index);
5056

5157
if vec.is_empty() {
Collapse file

‎server/src/player/movement.rs‎

Copy file name to clipboardExpand all lines: server/src/player/movement.rs
+16-12Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use shrev::{EventChannel, ReaderId};
88
use specs::storage::{BTreeStorage, ComponentEvent};
99
use specs::{
1010
BitSet, Component, Entities, Entity, Join, LazyUpdate, ParJoin, Read, ReadStorage, System,
11-
World, Write, WriteStorage,
11+
WorldExt, Write, WriteStorage,
1212
};
13-
use specs::{SystemData, WorldExt};
1413

1514
use feather_core::network::cast_packet;
1615
use feather_core::network::packet::implementation::{
@@ -22,7 +21,7 @@ use feather_core::world::{ChunkMap, ChunkPosition, Position};
2221

2322
use crate::chunk_logic::{
2423
load_chunk, ChunkHolderComponent, ChunkHolderReleaseEvent, ChunkHolders, ChunkLoadEvent,
25-
ChunkWorkerHandle,
24+
ChunkLoadFailEvent, ChunkWorkerHandle,
2625
};
2726
use crate::config::Config;
2827
use crate::entity::PositionComponent;
@@ -278,6 +277,7 @@ impl<'a> System<'a> for ChunkCrossSystem {
278277
#[derive(Default)]
279278
pub struct ChunkSendSystem {
280279
load_event_reader: Option<ReaderId<ChunkLoadEvent>>,
280+
fail_event_reader: Option<ReaderId<ChunkLoadFailEvent>>,
281281
}
282282

283283
impl<'a> System<'a> for ChunkSendSystem {
@@ -286,10 +286,11 @@ impl<'a> System<'a> for ChunkSendSystem {
286286
ReadStorage<'a, NetworkComponent>,
287287
Read<'a, ChunkMap>,
288288
Read<'a, EventChannel<ChunkLoadEvent>>,
289+
Read<'a, EventChannel<ChunkLoadFailEvent>>,
289290
);
290291

291292
fn run(&mut self, data: Self::SystemData) {
292-
let (mut pendings, netcomps, chunk_map, load_events) = data;
293+
let (mut pendings, netcomps, chunk_map, load_events, fail_events) = data;
293294

294295
for event in load_events.read(&mut self.load_event_reader.as_mut().unwrap()) {
295296
// TODO perhaps this is slightly inefficient?
@@ -306,16 +307,19 @@ impl<'a> System<'a> for ChunkSendSystem {
306307
}
307308
});
308309
}
309-
}
310310

311-
fn setup(&mut self, world: &mut World) {
312-
Self::SystemData::setup(world);
313-
self.load_event_reader = Some(
314-
world
315-
.fetch_mut::<EventChannel<ChunkLoadEvent>>()
316-
.register_reader(),
317-
);
311+
for event in fail_events.read(self.fail_event_reader.as_mut().unwrap()) {
312+
(&mut pendings).par_join().for_each(|pending| {
313+
if pending.contains(&event.pos) {
314+
// The chunk failed to load - skip sending it.
315+
// See issue #71
316+
pending.remove(&event.pos);
317+
}
318+
});
319+
}
318320
}
321+
322+
setup_impl!(load_event_reader, fail_event_reader);
319323
}
320324

321325
/// System for sending the Unload Chunk packet when the time comes.

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.