Skip to main content

Marker

Struct Marker 

Source
pub struct Marker {
    pub x: u32,
    pub y: u32,
    pub marker_type: MarkerType,
    pub weight: f32,
    pub region_id: Option<u32>,
    pub metadata: HashMap<String, String>,
}
Expand description

A spawn marker for entity placement

Fields§

§x: u32§y: u32§marker_type: MarkerType§weight: f32§region_id: Option<u32>§metadata: HashMap<String, String>

Implementations§

Source§

impl Marker

Source

pub fn new(x: u32, y: u32, marker_type: MarkerType) -> Self

Create a new marker with the given type

Examples found in repository?
examples/phase1_demo.rs (lines 31-35)
16fn demo_hierarchical_markers() {
17    println!("🎯 Demo 1: Hierarchical Marker Types");
18
19    let mut grid = Grid::new(40, 30);
20    algorithms::get("bsp").unwrap().generate(&mut grid, 12345);
21
22    let extractor = SemanticExtractor::for_rooms();
23    let mut rng = Rng::new(12345);
24    let mut semantic = extractor.extract(&grid, &mut rng);
25
26    // Add hierarchical markers manually for demo
27    if let Some(region) = semantic.regions.first() {
28        let (x, y) = region.cells[0];
29
30        // Quest markers
31        semantic.markers.push(Marker::new(
32            x,
33            y,
34            MarkerType::QuestObjective { priority: 1 },
35        ));
36        semantic
37            .markers
38            .push(Marker::new(x + 2, y, MarkerType::QuestStart));
39
40        // Loot markers
41        semantic
42            .markers
43            .push(Marker::new(x, y + 2, MarkerType::LootTier { tier: 3 }));
44        semantic
45            .markers
46            .push(Marker::new(x + 1, y + 2, MarkerType::Treasure));
47
48        // Encounter zones
49        semantic.markers.push(Marker::new(
50            x + 3,
51            y + 1,
52            MarkerType::EncounterZone { difficulty: 5 },
53        ));
54        semantic
55            .markers
56            .push(Marker::new(x + 4, y + 1, MarkerType::BossRoom));
57    }
58
59    // Show marker categories
60    let mut categories = std::collections::HashMap::new();
61    for marker in &semantic.markers {
62        *categories.entry(marker.marker_type.category()).or_insert(0) += 1;
63    }
64
65    for (category, count) in categories {
66        println!("  {} markers: {}", category, count);
67    }
68
69    println!("  Sample markers:");
70    for marker in semantic.markers.iter().take(3) {
71        println!("    {} at ({}, {})", marker.tag(), marker.x, marker.y);
72    }
73    println!();
74}
More examples
Hide additional examples
examples/hierarchical_markers.rs (lines 19-23)
3fn main() {
4    println!("=== Hierarchical Marker Types Demo ===\n");
5
6    // Generate a basic dungeon
7    let mut grid = Grid::new(30, 20);
8    algorithms::get("bsp").unwrap().generate(&mut grid, 12345);
9
10    let extractor = SemanticExtractor::for_rooms();
11    let mut rng = Rng::new(12345);
12    let mut semantic = extractor.extract(&grid, &mut rng);
13
14    // Add hierarchical markers
15    if let Some(region) = semantic.regions.first() {
16        let (x, y) = region.cells[0];
17
18        // Quest markers with priorities
19        semantic.markers.push(Marker::new(
20            x,
21            y,
22            MarkerType::QuestObjective { priority: 1 },
23        ));
24        semantic.markers.push(Marker::new(
25            x + 2,
26            y,
27            MarkerType::QuestObjective { priority: 3 },
28        ));
29        semantic
30            .markers
31            .push(Marker::new(x + 4, y, MarkerType::QuestStart));
32
33        // Loot with different tiers
34        semantic
35            .markers
36            .push(Marker::new(x, y + 2, MarkerType::LootTier { tier: 1 }));
37        semantic
38            .markers
39            .push(Marker::new(x + 2, y + 2, MarkerType::LootTier { tier: 3 }));
40        semantic
41            .markers
42            .push(Marker::new(x + 4, y + 2, MarkerType::Treasure));
43
44        // Encounter zones
45        semantic.markers.push(Marker::new(
46            x,
47            y + 4,
48            MarkerType::EncounterZone { difficulty: 2 },
49        ));
50        semantic
51            .markers
52            .push(Marker::new(x + 2, y + 4, MarkerType::BossRoom));
53        semantic
54            .markers
55            .push(Marker::new(x + 4, y + 4, MarkerType::SafeZone));
56    }
57
58    // Show marker categories and types
59    println!("Generated {} markers:", semantic.markers.len());
60    for marker in &semantic.markers {
61        println!(
62            "  {} at ({}, {}) - Category: {}",
63            marker.tag(),
64            marker.x,
65            marker.y,
66            marker.marker_type.category()
67        );
68    }
69
70    // Group by category
71    let mut categories = std::collections::HashMap::new();
72    for marker in &semantic.markers {
73        *categories.entry(marker.marker_type.category()).or_insert(0) += 1;
74    }
75
76    println!("\nMarker distribution:");
77    for (category, count) in categories {
78        println!("  {}: {} markers", category, count);
79    }
80}
examples/complete_workflow.rs (lines 55-61)
3fn main() {
4    println!("=== Complete Phase 1 & 2 Feature Demo ===\n");
5
6    // Demo: Complete workflow using all new features
7    println!("🏰 Generating Advanced Multi-Feature Dungeon\n");
8
9    // Step 1: Use pipeline template with custom parameters
10    println!("1. Pipeline Template Generation:");
11    let library = TemplateLibrary::new();
12    let template = library.get_template("simple_dungeon").unwrap();
13
14    let mut custom_params = std::collections::HashMap::new();
15    custom_params.insert("seed".to_string(), "12345".to_string());
16
17    let pipeline = template.instantiate(Some(custom_params));
18
19    let mut grid = Grid::new(40, 30);
20    let mut context = PipelineContext::new();
21    let mut rng = Rng::new(12345);
22
23    let result = pipeline.execute(&mut grid, &mut context, &mut rng);
24    println!(
25        "   Template execution: {}",
26        if result.success {
27            "✅ Success"
28        } else {
29            "❌ Failed"
30        }
31    );
32    println!("   Floor tiles: {}", grid.count(|t| t.is_floor()));
33
34    // Step 2: Extract semantic information
35    println!("\n2. Semantic Analysis:");
36    let extractor = SemanticExtractor::for_rooms();
37    let mut semantic = extractor.extract(&grid, &mut rng);
38
39    println!("   Regions found: {}", semantic.regions.len());
40    println!("   Original markers: {}", semantic.markers.len());
41
42    // Step 3: Add hierarchical markers based on regions
43    println!("\n3. Hierarchical Marker Placement:");
44    let mut quest_count = 0;
45    let mut loot_count = 0;
46    let mut encounter_count = 0;
47
48    for (i, region) in semantic.regions.iter().enumerate() {
49        if !region.cells.is_empty() {
50            let (x, y) = region.cells[region.cells.len() / 2]; // Middle of region
51
52            match i % 3 {
53                0 => {
54                    // Quest area
55                    semantic.markers.push(Marker::new(
56                        x,
57                        y,
58                        MarkerType::QuestObjective {
59                            priority: (i % 3 + 1) as u8,
60                        },
61                    ));
62                    quest_count += 1;
63                }
64                1 => {
65                    // Loot area
66                    semantic.markers.push(Marker::new(
67                        x,
68                        y,
69                        MarkerType::LootTier {
70                            tier: (i % 3 + 1) as u8,
71                        },
72                    ));
73                    loot_count += 1;
74                }
75                2 => {
76                    // Encounter area
77                    if i == 2 {
78                        semantic
79                            .markers
80                            .push(Marker::new(x, y, MarkerType::BossRoom));
81                    } else {
82                        semantic.markers.push(Marker::new(
83                            x,
84                            y,
85                            MarkerType::EncounterZone {
86                                difficulty: (i % 5 + 1) as u8,
87                            },
88                        ));
89                    }
90                    encounter_count += 1;
91                }
92                _ => {}
93            }
94        }
95    }
96
97    println!("   Added {} quest markers", quest_count);
98    println!("   Added {} loot markers", loot_count);
99    println!("   Added {} encounter markers", encounter_count);
100
101    // Step 4: Validate with requirements
102    println!("\n4. Requirement Validation:");
103    let mut requirements = SemanticRequirements::none();
104    requirements.min_regions.insert("Hall".to_string(), 1);
105    requirements
106        .required_markers
107        .insert(MarkerType::Custom("PlayerStart".to_string()), 1);
108
109    let validation_result = requirements.validate(&semantic);
110    println!(
111        "   Requirements met: {}",
112        if validation_result {
113            "✅ Yes"
114        } else {
115            "❌ No"
116        }
117    );
118
119    // Step 5: Marker constraints analysis
120    println!("\n5. Marker Constraint Analysis:");
121    let quest_constraints = MarkerConstraints::quest_objective();
122    let loot_constraints = MarkerConstraints::loot();
123
124    println!("   Quest marker constraints:");
125    println!(
126        "     Min distance (same type): {:?}",
127        quest_constraints.min_distance_same
128    );
129    println!(
130        "     Excluded types: {} types",
131        quest_constraints.exclude_types.len()
132    );
133
134    println!("   Loot marker constraints:");
135    println!(
136        "     Min distance (same type): {:?}",
137        loot_constraints.min_distance_same
138    );
139    println!(
140        "     Min distance (any): {:?}",
141        loot_constraints.min_distance_any
142    );
143
144    // Step 6: Multi-floor connectivity simulation
145    println!("\n6. Multi-Floor Connectivity:");
146
147    // Create a second floor based on the first
148    let mut floor2 = Grid::new(40, 30);
149    // Copy some areas from floor 1 to create overlapping regions
150    for y in 5..25 {
151        for x in 5..35 {
152            if grid.get(x, y).is_some_and(|t| t.is_floor()) && rng.random() < 0.6 {
153                floor2.set(x, y, terrain_forge::Tile::Floor);
154            }
155        }
156    }
157
158    let floors = vec![grid.clone(), floor2];
159    let mut connectivity = VerticalConnectivity::new();
160
161    connectivity.analyze_stair_candidates(&floors, 2);
162    connectivity.place_stairs(3);
163
164    println!("   Floor 1 tiles: {}", floors[0].count(|t| t.is_floor()));
165    println!("   Floor 2 tiles: {}", floors[1].count(|t| t.is_floor()));
166    println!(
167        "   Stair candidates: {}",
168        connectivity.stair_candidates.len()
169    );
170    println!("   Stairs placed: {}", connectivity.stairs.len());
171
172    // Step 7: Final summary
173    println!("\n🎯 Generation Summary:");
174    println!("   Grid size: {}x{}", grid.width(), grid.height());
175    println!("   Total floor area: {}", grid.count(|t| t.is_floor()));
176    println!(
177        "   Density: {:.1}%",
178        (grid.count(|t| t.is_floor()) as f32 / (grid.width() * grid.height()) as f32) * 100.0
179    );
180    println!("   Regions: {}", semantic.regions.len());
181    println!("   Total markers: {}", semantic.markers.len());
182
183    // Group markers by category
184    let mut categories = std::collections::HashMap::new();
185    for marker in &semantic.markers {
186        *categories.entry(marker.marker_type.category()).or_insert(0) += 1;
187    }
188
189    println!("   Marker distribution:");
190    for (category, count) in categories {
191        println!("     {}: {}", category, count);
192    }
193
194    println!(
195        "   Pipeline steps executed: {}",
196        context.execution_history().len()
197    );
198    println!("   Multi-floor stairs: {}", connectivity.stairs.len());
199
200    println!("\n✨ Advanced dungeon generation complete!");
201}
Source

pub fn with_tag(x: u32, y: u32, tag: String) -> Self

Create a marker with custom tag (backward compatibility)

Source

pub fn tag(&self) -> String

Get the tag string for this marker (backward compatibility)

Examples found in repository?
examples/bsp_analysis.rs (line 30)
3fn main() {
4    println!("=== BSP Algorithm Analysis ===\n");
5
6    let mut grid = Grid::new(40, 30);
7    algorithms::get("bsp").unwrap().generate(&mut grid, 12345);
8
9    let extractor = SemanticExtractor::for_rooms();
10    let mut rng = Rng::new(12345);
11    let semantic = extractor.extract(&grid, &mut rng);
12
13    println!("Generated map analysis:");
14    println!("  Floor tiles: {}", grid.count(|t| t.is_floor()));
15    println!("  Total regions: {}", semantic.regions.len());
16
17    println!("\nRegion breakdown:");
18    let mut region_counts = std::collections::HashMap::new();
19    for region in &semantic.regions {
20        *region_counts.entry(&region.kind).or_insert(0) += 1;
21    }
22
23    for (kind, count) in &region_counts {
24        println!("  {}: {}", kind, count);
25    }
26
27    println!("\nMarker breakdown:");
28    let mut marker_counts = std::collections::HashMap::new();
29    for marker in &semantic.markers {
30        *marker_counts.entry(marker.tag()).or_insert(0) += 1;
31    }
32
33    for (tag, count) in &marker_counts {
34        println!("  {}: {}", tag, count);
35    }
36}
More examples
Hide additional examples
examples/requirements_demo.rs (line 33)
3fn main() {
4    println!("=== Generate with Requirements Demo ===\n");
5
6    // Create simple requirements that match BSP output
7    let mut requirements = SemanticRequirements::none();
8    requirements.min_regions.insert("Hall".to_string(), 1); // BSP produces "Hall" regions
9    requirements
10        .required_markers
11        .insert(MarkerType::Custom("PlayerStart".to_string()), 1); // BSP produces "PlayerStart"
12
13    println!("Requirements:");
14    println!("  - Minimum 1 Hall region");
15    println!("  - At least 1 PlayerStart marker");
16    println!();
17
18    match generate_with_requirements("bsp", 40, 30, requirements, Some(10), 12345) {
19        Ok((grid, semantic)) => {
20            println!("✅ Successfully generated map meeting requirements!");
21            println!("  Grid size: {}x{}", grid.width(), grid.height());
22            println!("  Floor tiles: {}", grid.count(|t| t.is_floor()));
23            println!("  Total regions: {}", semantic.regions.len());
24
25            // Count Hall regions
26            let hall_count = semantic.regions.iter().filter(|r| r.kind == "Hall").count();
27            println!("  Hall regions: {}", hall_count);
28
29            // Count PlayerStart markers
30            let start_count = semantic
31                .markers
32                .iter()
33                .filter(|m| m.tag() == "PlayerStart")
34                .count();
35            println!("  PlayerStart markers: {}", start_count);
36
37            println!("\nFirst few regions:");
38            for (i, region) in semantic.regions.iter().take(3).enumerate() {
39                println!("  {}: {} ({} cells)", i + 1, region.kind, region.area());
40            }
41        }
42        Err(msg) => {
43            println!("❌ Failed to generate: {}", msg);
44        }
45    }
46}
examples/phase1_demo.rs (line 71)
16fn demo_hierarchical_markers() {
17    println!("🎯 Demo 1: Hierarchical Marker Types");
18
19    let mut grid = Grid::new(40, 30);
20    algorithms::get("bsp").unwrap().generate(&mut grid, 12345);
21
22    let extractor = SemanticExtractor::for_rooms();
23    let mut rng = Rng::new(12345);
24    let mut semantic = extractor.extract(&grid, &mut rng);
25
26    // Add hierarchical markers manually for demo
27    if let Some(region) = semantic.regions.first() {
28        let (x, y) = region.cells[0];
29
30        // Quest markers
31        semantic.markers.push(Marker::new(
32            x,
33            y,
34            MarkerType::QuestObjective { priority: 1 },
35        ));
36        semantic
37            .markers
38            .push(Marker::new(x + 2, y, MarkerType::QuestStart));
39
40        // Loot markers
41        semantic
42            .markers
43            .push(Marker::new(x, y + 2, MarkerType::LootTier { tier: 3 }));
44        semantic
45            .markers
46            .push(Marker::new(x + 1, y + 2, MarkerType::Treasure));
47
48        // Encounter zones
49        semantic.markers.push(Marker::new(
50            x + 3,
51            y + 1,
52            MarkerType::EncounterZone { difficulty: 5 },
53        ));
54        semantic
55            .markers
56            .push(Marker::new(x + 4, y + 1, MarkerType::BossRoom));
57    }
58
59    // Show marker categories
60    let mut categories = std::collections::HashMap::new();
61    for marker in &semantic.markers {
62        *categories.entry(marker.marker_type.category()).or_insert(0) += 1;
63    }
64
65    for (category, count) in categories {
66        println!("  {} markers: {}", category, count);
67    }
68
69    println!("  Sample markers:");
70    for marker in semantic.markers.iter().take(3) {
71        println!("    {} at ({}, {})", marker.tag(), marker.x, marker.y);
72    }
73    println!();
74}
examples/hierarchical_markers.rs (line 63)
3fn main() {
4    println!("=== Hierarchical Marker Types Demo ===\n");
5
6    // Generate a basic dungeon
7    let mut grid = Grid::new(30, 20);
8    algorithms::get("bsp").unwrap().generate(&mut grid, 12345);
9
10    let extractor = SemanticExtractor::for_rooms();
11    let mut rng = Rng::new(12345);
12    let mut semantic = extractor.extract(&grid, &mut rng);
13
14    // Add hierarchical markers
15    if let Some(region) = semantic.regions.first() {
16        let (x, y) = region.cells[0];
17
18        // Quest markers with priorities
19        semantic.markers.push(Marker::new(
20            x,
21            y,
22            MarkerType::QuestObjective { priority: 1 },
23        ));
24        semantic.markers.push(Marker::new(
25            x + 2,
26            y,
27            MarkerType::QuestObjective { priority: 3 },
28        ));
29        semantic
30            .markers
31            .push(Marker::new(x + 4, y, MarkerType::QuestStart));
32
33        // Loot with different tiers
34        semantic
35            .markers
36            .push(Marker::new(x, y + 2, MarkerType::LootTier { tier: 1 }));
37        semantic
38            .markers
39            .push(Marker::new(x + 2, y + 2, MarkerType::LootTier { tier: 3 }));
40        semantic
41            .markers
42            .push(Marker::new(x + 4, y + 2, MarkerType::Treasure));
43
44        // Encounter zones
45        semantic.markers.push(Marker::new(
46            x,
47            y + 4,
48            MarkerType::EncounterZone { difficulty: 2 },
49        ));
50        semantic
51            .markers
52            .push(Marker::new(x + 2, y + 4, MarkerType::BossRoom));
53        semantic
54            .markers
55            .push(Marker::new(x + 4, y + 4, MarkerType::SafeZone));
56    }
57
58    // Show marker categories and types
59    println!("Generated {} markers:", semantic.markers.len());
60    for marker in &semantic.markers {
61        println!(
62            "  {} at ({}, {}) - Category: {}",
63            marker.tag(),
64            marker.x,
65            marker.y,
66            marker.marker_type.category()
67        );
68    }
69
70    // Group by category
71    let mut categories = std::collections::HashMap::new();
72    for marker in &semantic.markers {
73        *categories.entry(marker.marker_type.category()).or_insert(0) += 1;
74    }
75
76    println!("\nMarker distribution:");
77    for (category, count) in categories {
78        println!("  {}: {} markers", category, count);
79    }
80}
Source§

impl Marker

Source

pub fn with_weight(self, weight: f32) -> Self

Source

pub fn with_region(self, region_id: u32) -> Self

Source

pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Trait Implementations§

Source§

impl Clone for Marker

Source§

fn clone(&self) -> Marker

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Marker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Marker

§

impl RefUnwindSafe for Marker

§

impl Send for Marker

§

impl Sync for Marker

§

impl Unpin for Marker

§

impl UnwindSafe for Marker

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V