Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit d5dbf62

Browse files
remove debug lines, remove unnecessary format proc, add procs to readme
1 parent 90f4bbc commit d5dbf62

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ To get additional features, pass a list to `--features`, for example `--features
8888
8989
The default features are:
9090
* acreplace: Aho-Corasick string matching and replacement.
91+
* binary_space_partition: Function to generate "rooms" more or less evenly distributed over a given area.
9192
* cellularnoise: Function to generate cellular automata-based noise.
9293
* dmi: DMI manipulations which are impossible from within BYOND.
9394
Used by the asset cache subsystem to improve load times.
@@ -97,6 +98,7 @@ The default features are:
9798
* json: Function to check JSON validity.
9899
* log: Faster log output.
99100
* noise: 2d Perlin noise.
101+
* random_room_placement: Function to generate "rooms" randomly placed in a given area, only taking care to not overlap one another.
100102
* sql: Asynchronous MySQL/MariaDB client library.
101103
* time: High-accuracy time measuring.
102104
* toml: TOML parser.

src/binary_space_partition.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::{fmt, cmp};
2-
use std::fmt::Write;
32
use rand::distributions::WeightedIndex;
43
use rand::prelude::*;
54
use rand::rngs::StdRng;
@@ -16,11 +15,9 @@ struct BspLevel {
1615

1716

1817
byond_fn!(fn bsp_generate(width, height, hash, map_subsection_min_size, map_subsection_min_room_width, map_subsection_min_room_height) {
19-
match bsp_gen(width, height, hash, map_subsection_min_size, map_subsection_min_room_width, map_subsection_min_room_height) {
20-
Ok(s) => Some(s),
21-
Err(e) => Some(format!("{e}"))
22-
}
18+
bsp_gen(width, height, hash, map_subsection_min_size, map_subsection_min_room_width, map_subsection_min_room_height).ok()
2319
});
20+
2421
fn bsp_gen(width_as_str: &str,
2522
height_as_str: &str,
2623
hash_as_str: &str,
@@ -34,6 +31,7 @@ fn bsp_gen(width_as_str: &str,
3431
let mut map_subsection_min_size = map_subsection_min_size_as_str.parse::<i32>()?;
3532
let map_subsection_min_room_width = map_subsection_min_room_width_as_str.parse::<i32>()?;
3633
let map_subsection_min_room_height = map_subsection_min_room_height_as_str.parse::<i32>()?;
34+
3735
if map_subsection_min_size < map_subsection_min_room_width || map_subsection_min_size < map_subsection_min_room_height{
3836
map_subsection_min_size = cmp::max(map_subsection_min_room_width, map_subsection_min_room_height) + 1
3937
}
@@ -44,14 +42,7 @@ fn bsp_gen(width_as_str: &str,
4442

4543
let level = BspLevel::new(width, height, &mut rng, map_subsection_min_size, map_subsection_min_room_width, map_subsection_min_room_height);
4644

47-
let mut string = String::new();
48-
for room in &level.all_rooms {
49-
let serialized = serde_json::to_string(&room).unwrap();
50-
let _ = write!(string, "{}", serialized);
51-
//println!("serialized = {}", serialized);
52-
}
53-
54-
Ok(format!("{}",serde_json::to_string(&level.all_rooms)?))
45+
Ok(serde_json::to_string(&level.all_rooms)?)
5546
}
5647

5748
impl BspLevel {

src/random_room_placement.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::fmt;
2-
use std::fmt::Write;
32
use rand::distributions::WeightedIndex;
43
use rand::prelude::*;
54
use rand::rngs::StdRng;
@@ -12,11 +11,9 @@ struct RandomRoomLevel {
1211
}
1312

1413
byond_fn!(fn random_room_generate(width, height, desired_room_count, hash) {
15-
match random_room_gen(width, height, desired_room_count, hash) {
16-
Ok(s) => Some(s),
17-
Err(e) => Some(format!("{e}"))
18-
}
14+
random_room_gen(width, height, desired_room_count, hash).ok()
1915
});
16+
2017
fn random_room_gen(width_as_str: &str,
2118
height_as_str: &str,
2219
desired_room_count_as_str: &str,
@@ -35,14 +32,7 @@ fn random_room_gen(width_as_str: &str,
3532

3633
let level = RandomRoomLevel::new(width, height, desired_room_count, &mut rng);
3734

38-
39-
let mut string = String::new();
40-
for room in &level.all_rooms {
41-
let serialized = serde_json::to_string(&room).unwrap();
42-
let _ = write!(string, "{}", serialized);
43-
}
44-
45-
Ok(format!("{}",serde_json::to_string(&level.all_rooms)?))
35+
Ok(serde_json::to_string(&level.all_rooms)?)
4636
}
4737

4838
impl RandomRoomLevel {

0 commit comments

Comments
 (0)