@@ -8,10 +8,11 @@ use crate::collision_math::Ray;
8
8
use crate :: dodeca:: Vertex ;
9
9
use crate :: graph:: { Graph , NodeId } ;
10
10
use crate :: lru_slab:: SlotId ;
11
+ use crate :: peer_traverser:: PeerTraverser ;
11
12
use crate :: proto:: { BlockUpdate , Position , SerializedVoxelData } ;
12
13
use crate :: voxel_math:: { ChunkDirection , CoordAxis , CoordSign , Coords } ;
13
14
use crate :: world:: Material ;
14
- use crate :: worldgen:: NodeState ;
15
+ use crate :: worldgen:: { NodeState , PartialNodeState } ;
15
16
use crate :: { Chunks , margins} ;
16
17
17
18
/// Unique identifier for a single chunk (1/20 of a dodecahedron) in the graph
@@ -28,21 +29,44 @@ impl ChunkId {
28
29
}
29
30
30
31
impl Graph {
32
+ /// Returns the PartialNodeState for the given node, panicking if it isn't initialized.
33
+ #[ inline]
34
+ pub fn partial_node_state ( & self , node_id : NodeId ) -> & PartialNodeState {
35
+ self [ node_id] . partial_state . as_ref ( ) . unwrap ( )
36
+ }
37
+
38
+ /// Initializes the PartialNodeState for the given node if not already initialized,
39
+ /// initializing other nodes' NodeState and PartialNodeState as necessary
40
+ pub fn ensure_partial_node_state ( & mut self , node_id : NodeId ) {
41
+ if self [ node_id] . partial_state . is_some ( ) {
42
+ return ;
43
+ }
44
+
45
+ for ( _, parent) in self . descenders ( node_id) {
46
+ self . ensure_node_state ( parent) ;
47
+ }
48
+
49
+ let partial_node_state = PartialNodeState :: new ( self , node_id) ;
50
+ self [ node_id] . partial_state = Some ( partial_node_state) ;
51
+ }
52
+
31
53
/// Returns the NodeState for the given node, panicking if it isn't initialized.
32
54
#[ inline]
33
55
pub fn node_state ( & self , node_id : NodeId ) -> & NodeState {
34
56
self [ node_id] . state . as_ref ( ) . unwrap ( )
35
57
}
36
58
37
- /// Initializes the NodeState for the given node and all its ancestors if not
38
- /// already initialized.
59
+ /// Initializes the NodeState for the given node if not already initialized,
60
+ /// initializing other nodes' NodeState and PartialNodeState as necessary
39
61
pub fn ensure_node_state ( & mut self , node_id : NodeId ) {
40
62
if self [ node_id] . state . is_some ( ) {
41
63
return ;
42
64
}
43
65
44
- for ( _, parent) in self . descenders ( node_id) {
45
- self . ensure_node_state ( parent) ;
66
+ self . ensure_partial_node_state ( node_id) ;
67
+ let mut peers = PeerTraverser :: new ( node_id) ;
68
+ while let Some ( peer) = peers. ensure_next ( self ) {
69
+ self . ensure_partial_node_state ( peer. node ( ) ) ;
46
70
}
47
71
48
72
let node_state = NodeState :: new ( self , node_id) ;
@@ -211,6 +235,7 @@ impl IndexMut<ChunkId> for Graph {
211
235
/// used for rendering, is stored here.
212
236
#[ derive( Default ) ]
213
237
pub struct Node {
238
+ pub partial_state : Option < PartialNodeState > ,
214
239
pub state : Option < NodeState > ,
215
240
/// We can only populate chunks which lie within a cube of populated nodes, so nodes on the edge
216
241
/// of the graph always have some `Fresh` chunks.
0 commit comments