Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional optimization passes and rework I/O considerations #123

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 80 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ The folowing options are available at the toplevel (under no header):
| `block_in_hitbox` | Allow placing blocks inside of players (hitbox logic is simplified) | true |
| `auto_redpiler` | Use redpiler automatically | true |

To change the plot size edit the constants defined in [plot/mod.rs](./crates/core/src/plot/mod.rs).
To change the plot size edit the constants defined in [core/src/plot/mod.rs](./crates/core/src/plot/mod.rs).
Non-I/O redstone components may be optimized away when using redpiler optimizations, prevent this by adding them to [core/build.rs](./crates/core/build.rs).

### LuckPerms

Expand Down Expand Up @@ -89,6 +90,7 @@ server_context = "global"
| `/redpiler compile` | `/rp c` | Manually starts redpiler compilation. Available flags: --io-only --optimize --export (or in short: -I -O -E) |
| `/redpiler reset` | `/rp r` | Stops redpiler. |
| `/toggleautorp` | None | Toggles automatic redpiler compilation. |
| `/toggleioonly` | None | Toggles whether to visually update non-IO redstone components. (Also forces --io-only) |
| `/stop` | None | Stops the server. |

### Plot Ownership
Expand Down
6 changes: 6 additions & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ harness = false
name = "chungus"
harness = false

[build-dependencies]
phf = { version = "0.11", default-features = false }
phf_codegen = "0.11"
mchprs_blocks = { path = "../blocks" }

[dependencies]
mchprs_proc_macros = { path = "../proc_macros" }
toml = "0.7"
Expand Down Expand Up @@ -46,6 +51,7 @@ once_cell = "1.14.0"
smallvec = "1.9.0"
petgraph = "0.6"
rustc-hash = "1.1"
phf = { version = "0.11", features = ["macros"] }
redpiler_graph = { path = "../redpiler_graph" }
mchprs_save_data = { path = "../save_data" }
mchprs_blocks = { path = "../blocks" }
Expand Down
75 changes: 75 additions & 0 deletions crates/core/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::env;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;

use mchprs_blocks::blocks::Block;

/// This build script generates perfect hash sets to match certain types of blocks.
/// In non standard cases you may add components to the appropiate match statements.
fn main() {
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("block_filters.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());

let mut input_set = phf_codegen::Set::<u32>::new();
let mut output_set = phf_codegen::Set::<u32>::new();
let mut changing_set = phf_codegen::Set::<u32>::new();

// Magic number, not sure how many total block states there are, but 2^16 should hopefully be enough
for id in 0..65536 {
let block = Block::from_id(id);

// Matches all blocks that should be considered as input components
match block {
Block::Lever { .. } | Block::StoneButton { .. } | Block::StonePressurePlate { .. } => {
input_set.entry(id);
}
_ => {}
}

// Matches all blocks that should be considered as output components
match block {
Block::RedstoneLamp { .. } | Block::IronTrapdoor { .. } => {
output_set.entry(id);
}
_ => {}
}

// Matches all blocks that may change state (active redstone components)
match block {
Block::RedstoneWire { .. }
| Block::Lever { .. }
| Block::StoneButton { .. }
| Block::RedstoneTorch { .. }
| Block::RedstoneWallTorch { .. }
| Block::RedstoneRepeater { .. }
| Block::RedstoneLamp { .. }
| Block::RedstoneComparator { .. }
| Block::Observer { .. }
| Block::StonePressurePlate { .. }
| Block::IronTrapdoor { .. } => {
changing_set.entry(id);
}
_ => {}
}
}

write!(
&mut file,
"pub static INPUT_BLOCKS: phf::Set<u32> = {};\n",
input_set.build()
)
.unwrap();
write!(
&mut file,
"pub static OUTPUT_BLOCKS: phf::Set<u32> = {};\n",
output_set.build()
)
.unwrap();
write!(
&mut file,
"pub static CHANGING_BLOCKS: phf::Set<u32> = {};\n",
changing_set.build()
)
.unwrap();
}
Loading
Loading