@@ -11,8 +11,8 @@ use crate::lru_slab::SlotId;
1111use crate :: proto:: { BlockUpdate , Position , SerializedVoxelData } ;
1212use crate :: voxel_math:: { ChunkDirection , CoordAxis , CoordSign , Coords } ;
1313use crate :: world:: Material ;
14- use crate :: worldgen:: NodeState ;
15- use crate :: { Chunks , margins} ;
14+ use crate :: worldgen:: { NodeState , PartialNodeState } ;
15+ use crate :: { Chunks , margins, peer_traverser } ;
1616
1717/// Unique identifier for a single chunk (1/20 of a dodecahedron) in the graph
1818#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
@@ -28,21 +28,43 @@ impl ChunkId {
2828}
2929
3030impl Graph {
31+ /// Returns the PartialNodeState for the given node, panicking if it isn't initialized.
32+ #[ inline]
33+ pub fn partial_node_state ( & self , node_id : NodeId ) -> & PartialNodeState {
34+ self [ node_id] . partial_state . as_ref ( ) . unwrap ( )
35+ }
36+
37+ /// Initializes the PartialNodeState for the given node if not already initialized,
38+ /// initializing other nodes' NodeState and PartialNodeState as necessary
39+ pub fn ensure_partial_node_state ( & mut self , node_id : NodeId ) {
40+ if self [ node_id] . partial_state . is_some ( ) {
41+ return ;
42+ }
43+
44+ for ( _, parent) in self . descenders ( node_id) {
45+ self . ensure_node_state ( parent) ;
46+ }
47+
48+ let partial_node_state = PartialNodeState :: new ( self , node_id) ;
49+ self [ node_id] . partial_state = Some ( partial_node_state) ;
50+ }
51+
3152 /// Returns the NodeState for the given node, panicking if it isn't initialized.
3253 #[ inline]
3354 pub fn node_state ( & self , node_id : NodeId ) -> & NodeState {
3455 self [ node_id] . state . as_ref ( ) . unwrap ( )
3556 }
3657
37- /// Initializes the NodeState for the given node and all its ancestors if not
38- /// already initialized.
58+ /// Initializes the NodeState for the given node if not already initialized,
59+ /// initializing other nodes' NodeState and PartialNodeState as necessary
3960 pub fn ensure_node_state ( & mut self , node_id : NodeId ) {
4061 if self [ node_id] . state . is_some ( ) {
4162 return ;
4263 }
4364
44- for ( _, parent) in self . descenders ( node_id) {
45- self . ensure_node_state ( parent) ;
65+ self . ensure_partial_node_state ( node_id) ;
66+ for peer in peer_traverser:: ensure_peer_nodes ( self , node_id) {
67+ self . ensure_partial_node_state ( peer. node ( ) ) ;
4668 }
4769
4870 let node_state = NodeState :: new ( self , node_id) ;
@@ -211,6 +233,7 @@ impl IndexMut<ChunkId> for Graph {
211233/// used for rendering, is stored here.
212234#[ derive( Default ) ]
213235pub struct Node {
236+ pub partial_state : Option < PartialNodeState > ,
214237 pub state : Option < NodeState > ,
215238 /// We can only populate chunks which lie within a cube of populated nodes, so nodes on the edge
216239 /// of the graph always have some `Fresh` chunks.
0 commit comments