@@ -11,8 +11,8 @@ use crate::lru_slab::SlotId;
11
11
use crate :: proto:: { BlockUpdate , Position , SerializedVoxelData } ;
12
12
use crate :: voxel_math:: { ChunkDirection , CoordAxis , CoordSign , Coords } ;
13
13
use 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 } ;
16
16
17
17
/// Unique identifier for a single chunk (1/20 of a dodecahedron) in the graph
18
18
#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
@@ -28,21 +28,43 @@ impl ChunkId {
28
28
}
29
29
30
30
impl 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
+
31
52
/// Returns the NodeState for the given node, panicking if it isn't initialized.
32
53
#[ inline]
33
54
pub fn node_state ( & self , node_id : NodeId ) -> & NodeState {
34
55
self [ node_id] . state . as_ref ( ) . unwrap ( )
35
56
}
36
57
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
39
60
pub fn ensure_node_state ( & mut self , node_id : NodeId ) {
40
61
if self [ node_id] . state . is_some ( ) {
41
62
return ;
42
63
}
43
64
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 ( ) ) ;
46
68
}
47
69
48
70
let node_state = NodeState :: new ( self , node_id) ;
@@ -211,6 +233,7 @@ impl IndexMut<ChunkId> for Graph {
211
233
/// used for rendering, is stored here.
212
234
#[ derive( Default ) ]
213
235
pub struct Node {
236
+ pub partial_state : Option < PartialNodeState > ,
214
237
pub state : Option < NodeState > ,
215
238
/// We can only populate chunks which lie within a cube of populated nodes, so nodes on the edge
216
239
/// of the graph always have some `Fresh` chunks.
0 commit comments