Skip to content

Commit d5e76a8

Browse files
committed
Add the initial framework for megastructures
To provide something to test with, an option has been added to scatter a random assortment of horospheres throughout the world.
1 parent bbf0a7e commit d5e76a8

File tree

6 files changed

+764
-7
lines changed

6 files changed

+764
-7
lines changed

common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ license = "Apache-2.0 OR Zlib"
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12+
arrayvec = "0.7.6"
1213
blake3 = "1.3.3"
1314
serde = { version = "1.0.104", features = ["derive"] }
1415
nalgebra = { workspace = true, features = ["serde-serialize"] }

common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub mod lru_slab;
2525
mod margins;
2626
pub mod math;
2727
pub mod node;
28+
pub mod peer_traverser;
2829
mod plane;
2930
pub mod proto;
3031
mod sim_config;

common/src/node.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::lru_slab::SlotId;
1111
use crate::proto::{BlockUpdate, Position, SerializedVoxelData};
1212
use crate::voxel_math::{ChunkDirection, CoordAxis, CoordSign, Coords};
1313
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};
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

3030
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+
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)]
213235
pub 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

Comments
 (0)